tiangong-kb-ingest
Upload local files or folders into Tiangong KB through the Tiangong AI CLI. Use when a user asks an agent to ingest documents into a KB collection, list uploadable collections, or explain ingest duplicate/status results.
What this skill does
# Tiangong KB Ingest
## Boundary
Use the Tiangong AI CLI for execution through `npx @tiangong-ai/cli@latest` by default, so users do not need a preinstalled CLI. The agent may orchestrate CLI schema, scan, metadata dry-run, and bulk commands, but it must not call backend databases or storage systems directly.
CLI-owned behavior:
- `tiangong-ai kb ingest bulk`
- `tiangong-ai kb ingest bulk scan`
- `tiangong-ai kb ingest metadata dry-run`
- `tiangong-ai kb ingest status`
- `tiangong-ai kb collections list`
- `tiangong-ai kb collections schema`
- SQLite checkpoint and resume
- concurrency/retry
- JSON output
- API key and env handling
Skill-owned behavior:
- choose this workflow when the user wants to upload local files/folders into Tiangong KB
- choose the safest collection selector
- generate a conservative `rule_mode: layered` metadata map from collection schema plus folder scan when the user did not pass `--metadata-map`
- run CLI metadata dry-run before bulk run and pass the generated metadata map into bulk ingest
- explain returned `duplicate`, `existingDocumentId`, document status, job id, request id, and idempotency key
- keep backend secrets and storage/search systems out of the agent workflow
## Short Workflow
1. Confirm the local file or folder path exists.
2. Pick one collection selector:
- prefer `--collection-name` or `TIANGONG_KB_DEFAULT_COLLECTION_NAME` when the user gives a unique display name
- use `--collection-key`, `--collection-path`, or `--collection-id` only when the user provides an exact selector
3. Load dotenv defaults from the target path directory when present:
- for a file, read `.env` from the file's parent directory
- for a folder, read `.env` from that folder
- loaded dotenv values fill only unset environment variables; explicit user
inputs passed as CLI flags take precedence
4. For a first check, run `npx @tiangong-ai/cli@latest kb collections list --json`.
5. For bulk/upload runs without `--metadata-map`, generate `metadata-map.yaml`:
- call CLI collection schema through the Tiangong KB ingest API
- call CLI bulk scan for folder structure
- write a layered metadata map with base filesystem fields plus conservative domain/detector rules
- run CLI metadata dry-run against the generated map
6. Ingest with `npx @tiangong-ai/cli@latest kb ingest bulk <path> --json`; pass `--metadata-map metadata-map.yaml` unless a metadata map is already provided or the user explicitly asks to skip metadata-map generation.
7. For long runs, tune `--window-size`, `--top-up-max`, `--upload-concurrency`, `--retries`, and `--state`; do not add `--max-polls` unless the user explicitly wants a bounded monitoring run.
8. If the user asks to verify later state, use `npx @tiangong-ai/cli@latest kb ingest status <document-id-or-job-id> --json`.
9. Report only current CLI output and backend response fields. Do not infer success from direct database queries.
## Metadata Map Minimum
When generating `metadata-map.yaml`, start from this conservative layered map
and add only collection-specific fields that the schema requires:
```yaml
version: 1
rule_mode: layered
defaults:
source: local_bulk_upload
layers:
- name: base
merge: all
rules:
- name: filesystem
match:
glob: "**/*"
fields:
relative_path:
source: relative_path
filename:
source: filename
filename_stem:
source: filename_stem
ext:
source: ext
path_depth:
source: path_depth
top_dir:
source: top_dir
parent_dir:
source: parent_dir
```
For required schema fields not covered by path rules, add safe defaults under
`defaults`: prefer `other` when it is an enum value, otherwise the first enum
value, `0` for numbers, `false` for booleans, `1970-01-01` for dates, and
`unknown` for strings.
Validate before upload:
```bash
npx @tiangong-ai/cli@latest kb ingest bulk scan /path/to/folder --json
npx @tiangong-ai/cli@latest kb collections schema --collection-key course/thu_humanities --json
npx @tiangong-ai/cli@latest kb ingest metadata dry-run /path/to/folder --metadata-map metadata-map.yaml --json
```
For offline validation with a captured schema, pass
`--schema-file schema.json` to `metadata dry-run`.
## Examples
Upload one file:
```bash
npx @tiangong-ai/cli@latest kb ingest bulk /path/to/document.pdf --json
```
Upload a folder:
```bash
npx @tiangong-ai/cli@latest kb ingest bulk /path/to/folder --upload-concurrency 3 --retries 3 --json
```
Use an existing metadata map:
```bash
npx @tiangong-ai/cli@latest kb ingest bulk /path/to/folder --metadata-map metadata-map.yaml --json
```
Use a metadata map saved at a specific path:
```bash
npx @tiangong-ai/cli@latest kb ingest bulk /path/to/folder --metadata-map course-map.yaml --json
```
List uploadable collections:
```bash
npx @tiangong-ai/cli@latest kb collections list --capability upload --json
```
Read a collection schema through the API:
```bash
npx @tiangong-ai/cli@latest kb collections schema --collection-key course/thu_humanities --json
```
Check document status:
```bash
npx @tiangong-ai/cli@latest kb ingest status <document-id> --json
```
## Result Interpretation
- `duplicate: true`: the backend found an active existing document with the same dedupe identity. Tell the user the upload was treated as duplicate and show `existingDocumentId` when present.
- `duplicate: false` or missing: do not claim dedupe was checked unless the backend response says so.
- `documentId`: use this id for follow-up status checks.
- `status`: explain it as backend state. Terminal states are success/failure/deleted according to the API response; nonterminal states mean processing is still underway.
- `jobId`, `statePath`, `requestId`, `idempotencyKey`, `rawUri`: include them when present because they help support/debugging.
- `metadata-map.yaml`: explain it as a reusable layered rules file. It is not per-file metadata; CLI evaluates the same rule file for each file.
## Safety Boundary
Never ask for or use:
- Supabase URL, anon key, service-role key, email/password, or session cookies
- NAS credentials or raw storage paths
- AWS, Pinecone, or OpenSearch admin credentials
- direct SQL/database queries to verify the current upload
The backend owns authorization, collection permission checks, duplicate detection, raw canonical write, document reservation, parse queueing, and status transitions. Read `references/env.md` only when environment setup or security boundaries matter.
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.