@retiform-ai/kg
v0.5.4
Published
Upload a folder of documents to Retiform, shared memory for AI agents, signed in as yourself.
Readme
@retiform-ai/kg
Uploads a folder of documents to your tenant on Retiform, shared memory for AI agents, signed in as yourself. It applies the same
rules as the console's Documents page (027 contracts/upload-rules.md). Requires Node.js 22 or later.
npx @retiform-ai/kg upload ./notesThe command uploads to the trial at https://api.retiform.ai. Name another platform with --endpoint, such as the
development environment:
npx @retiform-ai/kg upload ./notes --endpoint https://api.dev.retiform.aiThe first run shows an address and a code. Open the address, check the code, and sign in with your email. Later runs renew that sign-in without asking.
Before it sends anything, the command says where the files go and asks you to confirm:
Uploading to tenant Notes (t-abcdefghijkl) as [email protected] on api.retiform.ai.
Send 10 files to tenant Notes (t-abcdefghijkl) as [email protected] on api.retiform.ai? [y/N]Only y or yes sends. Check the account: a sign-in stored on a shared computer may be someone else's. kg whoami
shows it, and kg logout removes it.
Commands
| Command | Does |
|---|---|
| kg upload <folder-or-file>... [--endpoint <origin>] [--tenant <id>] [--yes] [--dry-run] [--confirm] [--wait] [--json] | uploads Markdown, HTML, plain-text and Word files. PDF files are sent too; the platform reads their pages, within a monthly page limit. With --wait, it then follows each sent document until it is searchable or failed, for up to 10 minutes |
| kg login [--endpoint <origin>] | signs in without uploading |
| kg logout [--endpoint <origin>] | revokes and deletes the stored sign-in |
| kg whoami [--endpoint <origin>] [--json] | shows the signed-in account, its tenant and role, without signing in |
| kg link (--project <id> \| --name <name>) [--endpoint <origin>] [--json] | links a repository for the Retiform plugin for Claude Code |
| kg codex install [--endpoint <origin>] [--dry-run] | gives the Codex CLI the same session start as the plugin |
| kg login --read [--store-file] [--endpoint <origin>] | signs in a second time, to read (#1137); kept apart from the upload sign-in |
| kg recall [--label <l>]... [--topic <t>] [--since <date>] [--tenant-wide] [--session <label>] [--json] | current memory entries, newest first, or ranked by --topic; in a linked repository, the Project's (with --tenant-wide, the tenant's own too) |
| kg context "<question>" [--budget <tokens>] [--session <label>] [--json] | cited passages and entities for a question, within --budget tokens (100 to 16000; 2000 when absent) |
| kg record "<statement>" [--label <l>]... [--session <label>] [--json] | records a memory entry, about the linked Project when there is one |
| kg handoff [--session <label>] [--json] | the newest entry labelled handoff for the linked Project |
--dry-runsigns in, then prints what would be sent and skipped. It sends nothing.--confirmsends again the files that came back needs confirmation, accepting the change it printed for each.--tenantrefuses to send unless you belong to that tenant. Because it names the tenant, the command then sends without asking.--yessends without asking. In a script or CI job, where the command cannot ask, give--yesor--tenant; without either it stops before signing in, and sends nothing.--jsonprints one JSON object per file and a summary object.
Hidden files and folders (any name starting with .) are never read, and are listed as skipped. Sending the same
folder again is safe: unchanged files are reported as unchanged.
Each file becomes the document named by its path. Under a folder you name, that is the folder's name, then the path
inside it: kg upload notes sends notes/a/b.md. A file you name on its own is named by its path from the current
folder, so kg upload specs/*/spec.md from a repository's top folder sends specs/001-x/spec.md and so on, the same
names kg upload specs gives them. A file outside the current folder is named by its file name alone. Two different
files that would get the same name stop the command before anything is sent.
The console's Documents page names files the same way. A folder you choose or drop there gets the names kg upload
gives that folder. Files you choose one by one are named by their file names, as kg names files in the current
folder. Sending the same files once as files and once as a folder makes two sets of documents.
added means Retiform has stored the file. It becomes searchable once processed, usually within a minute. kg's
sign-in can only upload, so it can't follow that processing (#993): the console's Documents page shows when each
document is ready, and kg upload ends with its address.
Builds from source before #785 named a file given on its own by its file name alone. If you uploaded files that way from a subfolder, sending them again now creates new documents under their paths. Delete the old ones on the console's Documents page.
kg link writes .retiform/project.json at the root of the Git repository you run it in, for the Retiform plugin
for Claude Code. Commit the file, and teammates who install the plugin share the same decisions without linking
again. Use --project with the Project you picked through the plugin's link skill, or --name to create a new
Project. It shows your tenant first. If a valid link already exists, it changes nothing.
kg codex install gives OpenAI's Codex CLI the same start to each session as the Retiform plugin gives Claude
Code. It copies the hook into $CODEX_HOME/retiform/ (~/.codex/retiform/ without CODEX_HOME) and adds its entry to
$CODEX_HOME/hooks.json, keeping your other hooks. Running it again replaces only its own entry. It makes no network
call. It then prints the steps left to you: codex mcp add retiform --url https://api.retiform.ai/mcp and codex mcp
login retiform to connect Codex, trusting the hook with /hooks in Codex, and kg link in each repository. With
--dry-run it only says what it would write. A hooks.json that is not a JSON object is left as it is, and the
command stops with exit status 1.
When too many of your documents are still processing, the command says so and waits for them, up to about five minutes for a file, before sending it again. If they are still processing after that, the file fails and the command stops, naming the limit; send the folder again later.
Exit status
| Status | When |
|---|---|
| 0 | every file was added, a new revision, unchanged or skipped |
| 1 | at least one file failed, needs confirmation, or was not sent; or you answered no (nothing sent) |
| 1 | kg link: the platform refused to create the Project, or the file could not be written |
| 1 | kg codex install: hooks.json could not be read or merged (it is left as it is) |
| 2 | the arguments or the folder could not be used, or the command could not ask and had neither --yes nor --tenant (nothing sent) |
| 3 | sign-in, or the platform's configuration, failed (nothing sent) |
Your sign-in
The command keeps only a refresh token, in your system's credential store (Windows Credential Manager, the macOS
Keychain or the Secret Service on Linux), under kg-upload:<sign-in domain>. Where no store is available, it keeps
the token in credentials.json under $XDG_CONFIG_HOME/kg (or ~/.config/kg; %APPDATA%\kg on Windows), readable
by you only, and tells you so. No option or environment variable accepts a token. This sign-in can upload; it cannot
read your documents.
Reading and recording (#1137)
kg recall, kg context and kg handoff need a second sign-in that can only read your tenant. You opt in once per
machine with kg login --read; until then they say so and exit with status 3, and nothing else on the machine can
read. kg record writes with the upload sign-in (kg login), which holds kg:write; the read sign-in cannot write.
Where the platform offers the read sign-in an application of its own (readClientId in its configuration), it signs
in through that one, so it can be switched off without touching uploads. It is kept apart from the upload sign-in, under kg-read:<sign-in domain>, and in the system's
credential store only: where none is available, kg login --read --store-file keeps it in credentials.json as
above, which you must ask for, since anyone who reads that file can read your tenant. kg logout revokes and removes
both sign-ins.
They act as you, not as an agent:
kg recall,kg contextandkg handoffcount against your plan's monthly retrieval calls, as the MCP tools do, and the console's context usage files them under you, not under an agent.kg recordrecords as you. A statement that looks like it holds a credential is refused, as is one past the plan's memory entries.--session <label>(orKG_SESSION_LABEL) declares a session label on each call, 1 to 40 characters ofA-Z a-z 0-9 . _ : -(others are refused, since the platform would drop them), so that a script's entries say where they came from. It is the caller's own text, not verified.
In a repository linked with kg link, they work on that Project; elsewhere, on the tenant. --json prints the
platform's answer; without it, a few readable lines.
License
Apache-2.0 (LICENSE). The bundle includes the console's upload rules (console/src/upload), which ship
under the same license.
Development
npm ci
npm run typecheck
npm test
npm run build # dist/kg.js, bundling ../console/src/upload