@aliyunrds/ctxdb 1.0.6 → 1.0.8-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.internal.md +59 -0
- package/README.md +210 -23
- package/dist/{chunk-BHRWAU3E.js → chunk-24CNB3XJ.js} +2 -2
- package/dist/{chunk-ARZX2RLR.js → chunk-AAZLOCVB.js} +246 -34
- package/dist/{chunk-7EIJB5LA.js → chunk-BBTXHFMD.js} +1 -1
- package/dist/{chunk-L4GVGVOP.js → chunk-CAXRYH6E.js} +235 -43
- package/dist/{chunk-6BB65W5W.js → chunk-HF2CWTRU.js} +2 -2
- package/dist/{chunk-B7JCQL4O.js → chunk-NJJBT52C.js} +1 -1
- package/dist/chunk-R67JELM7.js +20 -0
- package/dist/{chunk-Z6OHSEF2.js → chunk-ULAWTBBC.js} +34 -16
- package/dist/chunk-VIG4SYLU.js +8 -0
- package/dist/{chunk-VHNHVMCA.js → chunk-WSMZOFZQ.js} +3 -3
- package/dist/cli/main.js +1627 -62
- package/dist/hooks/hermes-post-llm-call.js +6 -4
- package/dist/hooks/hermes-pre-llm-call.js +9 -7
- package/dist/hooks/pre-tool-use.js +2 -1
- package/dist/hooks/session-start.js +8 -6
- package/dist/hooks/stop.js +6 -4
- package/dist/hooks/user-prompt-submit.js +8 -6
- package/dist/opencode/index.js +58 -2
- package/dist/setup/skills/contextdb-knowledge/SKILL.md +46 -8
- package/dist/setup/skills/contextdb-memory/SKILL.md +1 -1
- package/dist/workers/version-check.js +3 -1
- package/package.json +6 -2
- /package/dist/{chunk-UEKR2Z3S.js → chunk-5ML4VSXN.js} +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# @ali/ctxdb-internal
|
|
2
|
+
|
|
3
|
+
ContextDB 集团内部版 CLI。它通过浏览器或 Device Code 登录选择 Workspace,自动
|
|
4
|
+
取得当前 Member 的连接凭据,并为 Qoder、QoderWork、QwenWork、Codex、Claude
|
|
5
|
+
Code、OpenCode 和 Hermes 配置 hooks、skills 或插件。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
推荐使用 ContextDB Web 提供的安装命令。手动安装时执行:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install -g @ali/ctxdb-internal@latest \
|
|
13
|
+
--registry https://registry.anpm.alibaba-inc.com
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## 登录与配置 Agent
|
|
17
|
+
|
|
18
|
+
有浏览器的本机终端:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
ctxdb login --server https://contextdb.alibaba-inc.com --agent codex
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
SSH、远程或无头终端:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
ctxdb login --server https://contextdb.alibaba-inc.com \
|
|
28
|
+
--agent codex --device-code
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
登录成功后检查当前连接:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
ctxdb auth status --json
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
一个本地安装只保留一条当前连接,一个 API Key 只属于一个 Workspace。切换
|
|
38
|
+
Workspace 时重新执行 `ctxdb login`;新连接完成后会原子替换本地凭据,并尝试
|
|
39
|
+
吊销由上一次 CLI 登录签发的 Key。
|
|
40
|
+
|
|
41
|
+
## 本地文件
|
|
42
|
+
|
|
43
|
+
- `~/.ctxdb/credentials.json`:当前连接凭据,仅当前用户可读;
|
|
44
|
+
- `~/.ctxdb/ctxdb.json`:Agent 行为配置,不写入 API Key;
|
|
45
|
+
- `~/.ctxdb/logs/`:运行日志与 recall trace,不记录 API Key。
|
|
46
|
+
|
|
47
|
+
不要把 `credentials.json`、API Key、授权码或登录回调 URL 复制到聊天、日志或代码
|
|
48
|
+
仓库。内部版不接受 `ctxdb setup --api-key` 或 `ctxdb setup --base-url`;凭据和
|
|
49
|
+
DATA API 地址均由登录服务提供。
|
|
50
|
+
|
|
51
|
+
## 退出与升级
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
ctxdb logout
|
|
55
|
+
ctxdb update
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`logout` 会吊销当前 CLI 签发的 Key 并删除本地凭据。`update` 会从 Ali NPM 检查
|
|
59
|
+
并安装 `@ali/ctxdb-internal` 的新版本,然后刷新 Agent 集成。
|
package/README.md
CHANGED
|
@@ -11,11 +11,55 @@ Unified access layer for RDS ContextDatabase. One `ctxdb` CLI (memory + KB ops),
|
|
|
11
11
|
| **claude** | ✅ UserPromptSubmit + Stop + SessionStart | `~/.claude/skills/ctxdb/` | hooks-driven (auto capture/recall) |
|
|
12
12
|
| **opencode** | Plugin shim (`~/.config/opencode/plugins/ctxdb.ts`) | `~/.config/opencode/skills/` | in-process plugin (auto capture/recall + KB catalog injection) |
|
|
13
13
|
| **hermes** | ✅ `pre_llm_call` + `post_llm_call` | `~/.hermes/skills/` | shell hooks (auto capture/recall + first-turn warmup) |
|
|
14
|
+
| **workbuddy** | ✅ UserPromptSubmit + Stop + SessionStart | `~/.workbuddy/skills/ctxdb/` | hooks-driven (auto capture/recall); Claude-Code-isomorphic (exec form) |
|
|
14
15
|
|
|
15
|
-
Config and logs live under `~/.ctxdb/`. `~/.ctxdb/ctxdb.json` is one file, but runtime config is isolated per agent under `agents.qoder`, `agents.qoderwork`, `agents.qwenwork`, `agents.codex`, `agents.claude`, `agents.opencode`, and `agents.
|
|
16
|
+
Config and logs live under `~/.ctxdb/`. `~/.ctxdb/ctxdb.json` is one file, but runtime config is isolated per agent under `agents.qoder`, `agents.qoderwork`, `agents.qwenwork`, `agents.codex`, `agents.claude`, `agents.opencode`, `agents.hermes`, and `agents.workbuddy`. (Pre-2026-05-23 installs used `~/.ctxdb.json` at the home root; running `ctxdb setup --agent <name>` migrates the file into the selected agent section.)
|
|
16
17
|
|
|
17
18
|
## Install
|
|
18
19
|
|
|
20
|
+
### Internal browser-login distribution
|
|
21
|
+
|
|
22
|
+
The same source also builds `@ali/ctxdb-internal`. That artifact alone
|
|
23
|
+
adds `ctxdb login --server <url>`, `ctxdb login --device-code`, `ctxdb logout`,
|
|
24
|
+
and `ctxdb auth status`. The default login uses a browser loopback callback;
|
|
25
|
+
`--device-code` supports remote or headless terminals. Both methods discover a
|
|
26
|
+
provider-neutral protocol and use PKCE. The selected Workspace is represented
|
|
27
|
+
by the returned API key, so the CLI does not persist a separate Workspace id.
|
|
28
|
+
|
|
29
|
+
Internal login stores its single active connection in owner-only
|
|
30
|
+
`~/.ctxdb/credentials.json`. It then runs the normal Agent setup lifecycle
|
|
31
|
+
without writing an `api_key` field into the Agent or default profile; an
|
|
32
|
+
existing field in either updated profile is removed. At runtime this managed
|
|
33
|
+
credential overrides the API key and DATA URL in the existing v2
|
|
34
|
+
`~/.ctxdb/ctxdb.json`; `CTXDB_API_KEY` and `CTXDB_BASE_URL` remain the highest
|
|
35
|
+
priority overrides. Re-login replaces the active connection and revokes the
|
|
36
|
+
previous key after setup succeeds. The public `@aliyunrds/ctxdb` build does not
|
|
37
|
+
contain or advertise these commands and continues to use `ctxdb setup` and the
|
|
38
|
+
v2 config exactly as before. Build the internal staging package with
|
|
39
|
+
`pnpm build:internal`.
|
|
40
|
+
|
|
41
|
+
The distinction is a compile-time distribution manifest, not a runtime
|
|
42
|
+
environment-variable or file-existence check. The `public` manifest disables
|
|
43
|
+
`interactiveLogin` and `managedCredentials`; the `internal` manifest enables
|
|
44
|
+
both. The CLI hooks and the separately bundled OpenCode plugin receive the
|
|
45
|
+
same manifest, so installing a public build on a machine that happens to have
|
|
46
|
+
`~/.ctxdb/credentials.json` does not make that build consume the file.
|
|
47
|
+
|
|
48
|
+
Internal users install the package from Ali NPM. The internal version is
|
|
49
|
+
managed independently in `internal-release.json`; it does not inherit the
|
|
50
|
+
public package version.
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
npm install -g @ali/ctxdb-internal@latest \
|
|
54
|
+
--registry https://registry.anpm.alibaba-inc.com
|
|
55
|
+
ctxdb login --server https://contextdb.alibaba-inc.com --agent codex
|
|
56
|
+
ctxdb auth status --json
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The internal tarball bundles `@aliyunrds/ctxdb-shared`, so users install only
|
|
60
|
+
one ContextDB package. `semver` and `yaml` remain normal registry dependencies.
|
|
61
|
+
Maintainers should follow [`INTERNAL_PUBLISH.md`](./INTERNAL_PUBLISH.md).
|
|
62
|
+
|
|
19
63
|
### Recommended: console-generated installer command
|
|
20
64
|
|
|
21
65
|
The customer console supplies the selected Agent and API key to one of two
|
|
@@ -164,9 +208,9 @@ ctxdb setup --agent codex --api-key 'ctxdb-new-...'
|
|
|
164
208
|
ctxdb status --agent codex --json
|
|
165
209
|
```
|
|
166
210
|
|
|
167
|
-
Setup first checks that the target agent home exists (`~/.qoder`, `~/.qoderwork`, `~/.qwenwork`, `~/.codex`, or `~/.
|
|
211
|
+
Setup first checks that the target agent home exists (`~/.qoder`, `~/.qoderwork`, `~/.qwenwork`, `~/.codex`, `~/.claude`, or `~/.workbuddy`; the declared CN variant home also satisfies this check). Setup writes hooks and skills only into homes that already exist, so a CN-only install does not create the international product home, and vice versa. If no home exists, install or start that agent once before running `ctxdb setup --agent <name>`. OpenCode and Hermes are config-dir style: setup creates `~/.config/opencode` / `~/.hermes` when they are missing.
|
|
168
212
|
|
|
169
|
-
For **qoder**, **qoderwork**, **qwenwork**, **codex**, and **
|
|
213
|
+
For **qoder**, **qoderwork**, **qwenwork**, **codex**, **claude**, and **workbuddy**, restart the harness (CLI: just exit + restart; app: Cmd+R or quit/relaunch) so it picks up the new hooks/skill. For **codex**, setup also writes `[features].hooks = true` into `~/.codex/config.toml` (creating the file if missing) — Codex won't fire any hook entries without it. On first use Codex may prompt you to trust the new hook commands. For **opencode**, restart OpenCode so it loads `~/.config/opencode/plugins/ctxdb.ts`. For **hermes**, setup also checks `~/.hermes/shell-hooks-allowlist.json`; it reports setup as incomplete until both ctxdb hook commands are approved.
|
|
170
214
|
|
|
171
215
|
Hermes owns this security allowlist, so ctxdb only checks it and never writes approvals. Approve the ctxdb `pre_llm_call` and `post_llm_call` hooks with:
|
|
172
216
|
|
|
@@ -211,15 +255,15 @@ ctxdb setup
|
|
|
211
255
|
|
|
212
256
|
## What it does
|
|
213
257
|
|
|
214
|
-
For **qoder**, **qoderwork**, **qwenwork**, **codex**, and **
|
|
258
|
+
For **qoder**, **qoderwork**, **qwenwork**, **codex**, **claude**, and **workbuddy**, hooks fire automatically:
|
|
215
259
|
|
|
216
260
|
| Trigger | Hook | What runs |
|
|
217
261
|
|---|---|---|
|
|
218
262
|
| Session starts | `SessionStart` | Build a short cwd/git-signal query, recall relevant memories, and inject warm-up context as `additionalContext` |
|
|
219
263
|
| User submits a prompt | `UserPromptSubmit` | Search `/v3/memories/search/`, format a `<recalled-memories>` block, inject as additional context. **By default only memory is recalled.** Set `recall_knowledge: true` in the selected agent config to also pull KB context into an `<external-knowledge>` block; graph synthesis and document evidence are labeled separately inside that wrapper. Otherwise the recommended path for KB is the agent calling `ctxdb kb search --agent <name>` explicitly when the user asks (see SKILL.md) |
|
|
220
|
-
| Agent finishes its turn | `Stop` | Read transcript, detect KB
|
|
264
|
+
| Agent finishes its turn | `Stop` | Read transcript, detect KB create/update turns and skip capture (so document content doesn't bleed into long-term memory), slice the current turn, sanitize the input, POST to memory store |
|
|
221
265
|
|
|
222
|
-
Implementation note: qoder/Claude consume the JSON `hookSpecificOutput.additionalContext` shape; Codex has been verified on this machine through `~/.codex/hooks.json`, `[features].hooks = true`, and hook audit logs, where non-empty stdout from `UserPromptSubmit`/`SessionStart` is treated as injected context. The same hook core is shared; setup passes `--agent=<name>` so each hook reads its own config section.
|
|
266
|
+
Implementation note: qoder/Claude/WorkBuddy consume the JSON `hookSpecificOutput.additionalContext` shape; Codex has been verified on this machine through `~/.codex/hooks.json`, `[features].hooks = true`, and hook audit logs, where non-empty stdout from `UserPromptSubmit`/`SessionStart` is treated as injected context. The same hook core is shared; setup passes `--agent=<name>` so each hook reads its own config section.
|
|
223
267
|
|
|
224
268
|
For **opencode**, `ctxdb setup --agent opencode` copies the self-contained plugin bundle to `~/.config/opencode/plugins/ctxdb-bundle.js` and writes a re-export shim at `~/.config/opencode/plugins/ctxdb.ts` referencing it via the relative path `./ctxdb-bundle.js` (Bun on Windows can't resolve absolute-path specifiers from a .ts shim). `ctxdb upgrade --agent opencode` re-copies the bundle + refreshes the shim.
|
|
225
269
|
|
|
@@ -227,15 +271,16 @@ For **hermes**, `ctxdb setup --agent hermes` writes two shell hooks under `~/.he
|
|
|
227
271
|
|
|
228
272
|
- `pre_llm_call` maps to recall on each user prompt and first-turn warmup. Hermes does not persist hook context into conversation history, so ctxdb re-injects the KB catalog on every user turn even when `kb_catalog_injection` keeps its default `"session_start"` value; this prevents the catalog from disappearing after turn one.
|
|
229
273
|
- stdout uses Hermes' `{"context":"..."}` protocol.
|
|
230
|
-
- `post_llm_call` captures `extra.user_message` + `extra.assistant_response` without a transcript file, while `extra.conversation_history` supplies current-turn tool calls for the B-3c KB
|
|
274
|
+
- `post_llm_call` captures `extra.user_message` + `extra.assistant_response` without a transcript file, while `extra.conversation_history` supplies current-turn tool calls for the B-3c KB create/update guard.
|
|
231
275
|
|
|
232
276
|
## CLI
|
|
233
277
|
|
|
234
278
|
`ctxdb` ships grouped non-interactive commands:
|
|
235
279
|
|
|
236
280
|
- **Top-level**: `setup` / `status` / `ping` / `debug` / `uninstall` / `update` (`upgrade` alias)
|
|
237
|
-
- **Memory**: `memory add|search|list|get|update|delete`
|
|
238
|
-
- **KB**: `kb upload-text|upload-file|list|documents-list|document-get|search`
|
|
281
|
+
- **Memory**: `memory add|search|list|get|update|delete`, plus the `memory promotion` subgroup (记忆成文): `memory promotion generate|list|get|approve|reject|batch-action|batch-delete|resolve-doubts` and the `memory promotion template list|create|get|update|delete|set-default|clear-default` / `memory promotion settings get|update` sub-subgroups
|
|
282
|
+
- **KB**: `kb upload-text|upload-file|update-text|update-file|list|documents-list|document-get|search`, plus the `kb review` subgroup: `kb review list|get|action|resolve-conflicts|batch-action|batch-delete|delete`, `kb review template list|create|update|delete|get|set-default|clear-default`, `kb review settings get|update`
|
|
283
|
+
|
|
239
284
|
|
|
240
285
|
See `ctxdb --help`.
|
|
241
286
|
|
|
@@ -267,7 +312,7 @@ restores it. `ctxdb status` reports `debug` (effective), `debug_configured`,
|
|
|
267
312
|
`debug_forced`, and `debug_reason` (`non_production_base_url` when forced).
|
|
268
313
|
|
|
269
314
|
Effective debug writes full-fidelity recall records for qoder, qoderwork,
|
|
270
|
-
qwenwork, codex, claude, opencode, and
|
|
315
|
+
qwenwork, codex, claude, opencode, hermes, and workbuddy to
|
|
271
316
|
`~/.ctxdb/logs/recall-trace.jsonl`. The trace contains the complete query,
|
|
272
317
|
complete returned memory/KB candidates, local selected/excluded outcome, and
|
|
273
318
|
the exact context injected into the model. **This can contain sensitive project
|
|
@@ -286,17 +331,72 @@ not be interpreted as a completed `timeout`. Disabling debug stops future
|
|
|
286
331
|
writes but leaves existing trace files available for replay; `ctxdb uninstall
|
|
287
332
|
--purge-logs` removes them.
|
|
288
333
|
|
|
289
|
-
`setup` without `--agent` writes `agents.default` in `~/.ctxdb/ctxdb.json` (CLI-only, no hooks or skills); with `--agent <qoder|qoderwork|qwenwork|codex|claude|opencode|hermes>` it writes agent config and installs hooks/plugins + skills for that harness. Rerunning it repairs integration artifacts and may replace the selected Agent's API key. Memory and KB commands also accept `--agent <name>` so agents use their own config section; when omitted, `CTXDB_AGENT` env wins, otherwise `agents.default` is used. `uninstall` without `--agent` loops every supported agent; with `--agent <name>` it targets just that one. `teardown` is an alias for `uninstall`.
|
|
334
|
+
`setup` without `--agent` writes `agents.default` in `~/.ctxdb/ctxdb.json` (CLI-only, no hooks or skills); with `--agent <qoder|qoderwork|qwenwork|codex|claude|opencode|hermes|workbuddy>` it writes agent config and installs hooks/plugins + skills for that harness. Rerunning it repairs integration artifacts and may replace the selected Agent's API key. Memory and KB commands also accept `--agent <name>` so agents use their own config section; when omitted, `CTXDB_AGENT` env wins, otherwise `agents.default` is used. `uninstall` without `--agent` loops every supported agent; with `--agent <name>` it targets just that one. `teardown` is an alias for `uninstall`.
|
|
290
335
|
|
|
291
336
|
`memory add … --no-infer` stores the text verbatim (skips server-side LLM
|
|
292
337
|
fact-extraction). Use it when the user explicitly asks for a verbatim
|
|
293
338
|
memory ("记住 / 请记忆 / 原文记下"); without `--no-infer` the server may
|
|
294
339
|
rewrite, merge, or skip details.
|
|
295
340
|
|
|
296
|
-
###
|
|
341
|
+
### Memory promotion (记忆成文)
|
|
342
|
+
|
|
343
|
+
The promotion commands live under the Memory group (`ctxdb memory promotion ...`) and cover the server's memory promotion pipeline: turn
|
|
344
|
+
accumulated memories into reviewed knowledge-base documents.
|
|
297
345
|
|
|
298
|
-
|
|
299
|
-
|
|
346
|
+
```sh
|
|
347
|
+
# Task lifecycle
|
|
348
|
+
ctxdb memory promotion generate "<topic>" [--knowledge-base-id=<kb-id>]
|
|
349
|
+
ctxdb memory promotion list [--status=pending_review] [--page=N] [--page-size=N] \
|
|
350
|
+
[--sort-by=quality_score] [--sort-order=asc|desc]
|
|
351
|
+
ctxdb memory promotion get <promotion-id>
|
|
352
|
+
ctxdb memory promotion approve --promotion-id=<id> --knowledge-base-id=<kb-id>
|
|
353
|
+
ctxdb memory promotion reject --promotion-id=<id> [--reason=<text>]
|
|
354
|
+
ctxdb memory promotion batch-action --action=<approve|reject> --ids=<id1,id2,...> \
|
|
355
|
+
[--knowledge-base-id=<kb-id>] [--reason=<text>]
|
|
356
|
+
ctxdb memory promotion batch-delete --ids=<id1,id2,...> # rejected tasks only
|
|
357
|
+
ctxdb memory promotion resolve-doubts --promotion-id=<id> \
|
|
358
|
+
--resolutions-json='[{"index":0,"choice":"<label>","comment":"..."}]' \
|
|
359
|
+
[--title=<title>] [--content=<markdown>]
|
|
360
|
+
|
|
361
|
+
# Document templates (up to 5 per member)
|
|
362
|
+
ctxdb memory promotion template list
|
|
363
|
+
ctxdb memory promotion template create --name=<name> \
|
|
364
|
+
--sections-json='[{"title":"...","guidance":"...","level":1}]' [--is-default]
|
|
365
|
+
ctxdb memory promotion template get|update|delete|set-default <template-id>
|
|
366
|
+
ctxdb memory promotion template clear-default
|
|
367
|
+
|
|
368
|
+
# Auto-ingest settings (current Member in the current Workspace)
|
|
369
|
+
ctxdb memory promotion settings get
|
|
370
|
+
ctxdb memory promotion settings update [--auto-ingest-enabled=<true|false>] \
|
|
371
|
+
[--auto-ingest-threshold=<0..1>] [--default-kb-id=<kb-id> | --clear-default-kb]
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
Notes:
|
|
375
|
+
|
|
376
|
+
- Routes, methods, and parameter names mirror `openapi/data-api.yaml`
|
|
377
|
+
(`/v1/memory_promotions/**`). Batch requests accept at most 50 ids.
|
|
378
|
+
- `approve` and `batch-action --action=approve` require an explicit
|
|
379
|
+
`--knowledge-base-id`; rejecting does not require a target KB.
|
|
380
|
+
- Batch commands print every result and exit 1 if any item failed.
|
|
381
|
+
- `--clear-default-kb` sends an empty `default_kb_id` string, which the
|
|
382
|
+
server interprets as clearing the target (null means unchanged). If
|
|
383
|
+
auto-ingest is enabled, also pass `--auto-ingest-enabled=false` to clear it.
|
|
384
|
+
- Write commands validate required identifiers (promotion/template id,
|
|
385
|
+
batch ids, action) locally and exit 2 without sending a request when
|
|
386
|
+
arguments are missing or invalid.
|
|
387
|
+
- Default output is a compact agent-friendly view (`list` keeps
|
|
388
|
+
decision-relevant row fields; `template list` drops rendered markdown
|
|
389
|
+
and guidance text). `--raw` returns successful server envelopes verbatim
|
|
390
|
+
but still rejects business errors, including string error codes;
|
|
391
|
+
`--json` pretty-prints whichever view is active.
|
|
392
|
+
- `template` / `settings` are second-level subgroups: running
|
|
393
|
+
`ctxdb memory promotion` or `ctxdb memory promotion template` without a subcommand
|
|
394
|
+
lists the available subcommands and exits 2.
|
|
395
|
+
|
|
396
|
+
### KB create/update completion mode
|
|
397
|
+
|
|
398
|
+
`kb upload-text`, `kb upload-file`, `kb update-text`, and `kb update-file`
|
|
399
|
+
return as soon as the service accepts the document. The returned document may still have
|
|
300
400
|
`ingest_status: "processing"`; acceptance does not mean ingestion succeeded.
|
|
301
401
|
|
|
302
402
|
- Add `--wait` when a script needs the previous behavior: poll until ingestion
|
|
@@ -309,23 +409,110 @@ Scripts that relied on implicit terminal polling must migrate to:
|
|
|
309
409
|
```sh
|
|
310
410
|
ctxdb kb upload-text <kb-name> <doc-name> --text="<body>" --wait
|
|
311
411
|
ctxdb kb upload-file <kb-name> <local-path> --wait
|
|
412
|
+
ctxdb kb update-text <document-id> --text="<body>" --wait
|
|
413
|
+
ctxdb kb update-file <document-id> <local-path> --wait
|
|
312
414
|
```
|
|
313
415
|
|
|
416
|
+
### Explicit KB document updates
|
|
417
|
+
|
|
418
|
+
Create and update are separate operations. `upload-text` / `upload-file` use
|
|
419
|
+
create-only POST routes, so an existing logical document produces HTTP 409 and
|
|
420
|
+
is never silently overwritten. `update-text` / `update-file` use PUT and accept
|
|
421
|
+
exactly one locator family: the canonical document ID (preferred), or an
|
|
422
|
+
explicit knowledge-base name + logical document name + optional normalized
|
|
423
|
+
`--file-path`.
|
|
424
|
+
|
|
425
|
+
```sh
|
|
426
|
+
# Preferred: no KB/name/path lookup or reconstruction
|
|
427
|
+
ctxdb kb update-text <document-id> --text="<new-body>"
|
|
428
|
+
ctxdb kb update-file <document-id> <local-path>
|
|
429
|
+
|
|
430
|
+
# Alternative when the exact document ID is unavailable
|
|
431
|
+
ctxdb kb update-text --kb-name=<kb-name> --doc-name=<logical-name> --text="<new-body>" [--file-path=<logical-parent>]
|
|
432
|
+
ctxdb kb update-file <local-path> --kb-name=<kb-name> [--doc-name=<existing-logical-name>] [--file-path=<logical-parent>]
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
Do not combine a positional document ID with `--kb-name`, `--doc-name`, or
|
|
436
|
+
`--file-path`. ID mode derives the existing document's KB and logical metadata
|
|
437
|
+
on the server; a replacement file's basename remains only its physical upload
|
|
438
|
+
filename. Logical-key file mode defaults `--doc-name` to that basename, so pass
|
|
439
|
+
the existing logical name when the replacement basename differs.
|
|
440
|
+
|
|
441
|
+
Every successful update returns the canonical `document.id` and
|
|
442
|
+
`document.knowledge_base_id`. Changed content can replace the input ID, while
|
|
443
|
+
same-content updates may reuse it. Callers must retain the returned ID for the
|
|
444
|
+
next update; `--wait` also polls the returned ID/KB pair rather than caller input.
|
|
445
|
+
|
|
446
|
+
### Knowledge review commands
|
|
447
|
+
|
|
448
|
+
`kb review` covers the Knowledge Review DATA APIs: review-queue handling
|
|
449
|
+
(single/batch actions, conflict resolution, deletion), review-rewrite
|
|
450
|
+
templates, and per-knowledge-base review settings. Every command accepts `--agent`
|
|
451
|
+
(`CTXDB_AGENT`) and `--json`; list/detail commands follow the three-tier
|
|
452
|
+
projection (`kb search` discipline): default prints a minimal agent view,
|
|
453
|
+
`--verbose` adds sourcing/audit fields, `--raw` ships the server envelope
|
|
454
|
+
verbatim. Missing or illegal arguments print usage and exit 2 before any
|
|
455
|
+
request is sent.
|
|
456
|
+
|
|
457
|
+
```sh
|
|
458
|
+
# Review queue (filters are optional; sort by quality score)
|
|
459
|
+
ctxdb kb review list --knowledge-base-id=<kb-id> --review-status=pending --sort-by=confidence_score
|
|
460
|
+
ctxdb kb review get <review-id> [--content-page=N] [--verbose|--raw]
|
|
461
|
+
|
|
462
|
+
# Human actions: confirm | force_accept | accept_rewrite | reject | reject_reupload
|
|
463
|
+
ctxdb kb review action <review-id> --action=confirm
|
|
464
|
+
ctxdb kb review action <review-id> --action=accept_rewrite --edited-content=<text>
|
|
465
|
+
ctxdb kb review resolve-conflicts <review-id> \
|
|
466
|
+
--resolutions='[{"conflict_id":"<id>","resolution":"use_new|keep_old|merge|annotate_divergence"}]'
|
|
467
|
+
|
|
468
|
+
# Batch (up to 50 ids per request; batch-action supports confirm|reject)
|
|
469
|
+
ctxdb kb review batch-action --action=confirm --ids=<id1>,<id2>
|
|
470
|
+
ctxdb kb review batch-delete --ids=<id1>,<id2>
|
|
471
|
+
ctxdb kb review delete <review-id>
|
|
472
|
+
|
|
473
|
+
# Review-rewrite templates (per knowledge base, max 5 per KB)
|
|
474
|
+
ctxdb kb review template list <kb-id>
|
|
475
|
+
ctxdb kb review template create <kb-id> --name=<name> --sections-file=sections.json [--default]
|
|
476
|
+
ctxdb kb review template update <kb-id> <template-id> [--name=<name>] [--sections=<json>] [--default|--no-default]
|
|
477
|
+
ctxdb kb review template get <kb-id> <template-id> [--verbose|--raw]
|
|
478
|
+
ctxdb kb review template set-default <kb-id> <template-id>
|
|
479
|
+
ctxdb kb review template clear-default <kb-id>
|
|
480
|
+
ctxdb kb review template delete <kb-id> <template-id>
|
|
481
|
+
|
|
482
|
+
# Review settings for one knowledge base
|
|
483
|
+
ctxdb kb review settings get <kb-id>
|
|
484
|
+
ctxdb kb review settings update <kb-id> --review-enabled --high-threshold=0.85 --rewrite-enabled --max-rewrite-iterations=3
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
`--sections` / `--sections-file` take a JSON array
|
|
488
|
+
(`[{"level": 1, "title": "...", "guidance": "..."}]`, `level` optional 1-3,
|
|
489
|
+
max 15 sections). `accept_rewrite` falls back to the server-rendered rewrite
|
|
490
|
+
when `--edited-content` is omitted. `kb review template get` on a missing
|
|
491
|
+
template reports `{"found": false}` instead of erroring, matching the server
|
|
492
|
+
contract.
|
|
493
|
+
|
|
314
494
|
### KB file upload policy and large files
|
|
315
495
|
|
|
316
|
-
`kb upload-file`
|
|
496
|
+
`kb upload-file` and `kb update-file` do not maintain a client-side format allowlist or file-size
|
|
317
497
|
table. It validates only that the local path exists, is a readable regular
|
|
318
498
|
file, then lets the service decide whether the format, per-type size, quota,
|
|
319
499
|
and logical document identity are acceptable. Unknown extensions are sent as
|
|
320
500
|
`application/octet-stream`.
|
|
321
501
|
|
|
322
502
|
File bytes are streamed from disk with a known multipart size; the CLI does
|
|
323
|
-
not read the complete file into a Buffer.
|
|
324
|
-
|
|
503
|
+
not read the complete file into a Buffer. Each command attempts its ordinary
|
|
504
|
+
direct endpoint first. If the service returns the dedicated
|
|
325
505
|
`KNOWLEDGE_DIRECT_UPLOAD_REQUIRES_CHUNK` error (`errorCode=6001`) or an
|
|
326
|
-
unstructured HTTP 413, the CLI
|
|
327
|
-
|
|
328
|
-
|
|
506
|
+
unstructured HTTP 413, the CLI automatically uses the chunk init/part/complete
|
|
507
|
+
protocol. Create init uses POST and update init uses PUT; parts, complete, and
|
|
508
|
+
abort stay on POST. Document-ID update init sends the ID and physical filename
|
|
509
|
+
without resolving a KB. Logical-key update init resolves the KB and sends the
|
|
510
|
+
same KB/name/path identity as direct mode.
|
|
511
|
+
|
|
512
|
+
Chunk init and complete accept the release_pre bare response objects. Create
|
|
513
|
+
also accepts the previous `Box.data` init/complete shape during rolling
|
|
514
|
+
deployment; part and abort responses remain Box-wrapped. This response-shape
|
|
515
|
+
compatibility does not fall back from logical-key PUT to an older update contract.
|
|
329
516
|
|
|
330
517
|
The first chunk-routing release intentionally sends init, each part, and
|
|
331
518
|
complete only once. It does not automatically retry timeout, connection-loss,
|
|
@@ -397,7 +584,7 @@ Lives at `~/.ctxdb/ctxdb.json` (co-located with logs at `~/.ctxdb/logs/`). Schem
|
|
|
397
584
|
}
|
|
398
585
|
```
|
|
399
586
|
|
|
400
|
-
Agent selection is driven by `--agent <qoder|qoderwork|qwenwork|codex|claude|opencode|hermes|default>` on every CLI invocation, falling back to `CTXDB_AGENT` env, then to `default`. There is no `default_agent` field — older installs that have one written get it dropped on the next save.
|
|
587
|
+
Agent selection is driven by `--agent <qoder|qoderwork|qwenwork|codex|claude|opencode|hermes|workbuddy|default>` on every CLI invocation, falling back to `CTXDB_AGENT` env, then to `default`. There is no `default_agent` field — older installs that have one written get it dropped on the next save.
|
|
401
588
|
|
|
402
589
|
Field reference:
|
|
403
590
|
|
|
@@ -414,7 +601,7 @@ Field reference:
|
|
|
414
601
|
| `knowledge_top_k` | int | `6` | KB chunks pulled per recall (only effective when `recall_knowledge: true`) |
|
|
415
602
|
| `debug` | bool | `false` | Configured preference for verbose hook logging and full recall tracing. Effective debug is forced on for every final `base_url` outside the exact official-production allowlist; see “Debug control and recall replay”. General logs go to `~/.ctxdb/logs/ctxdb.log`, structured full-content recall records to `~/.ctxdb/logs/recall-trace.jsonl` |
|
|
416
603
|
|
|
417
|
-
Env-var overrides apply to the selected agent config (env wins): `CTXDB_AGENT` / `CTXDB_API_KEY` / `CTXDB_BASE_URL` / `CTXDB_USER_ID` / `CTXDB_AGENT_ID` / `CTXDB_APP_ID`. The last two default to unset — the request body omits `agent_id`/`app_id` entirely; set them only when you want per-agent / per-app scope isolation on the server.
|
|
604
|
+
Env-var overrides apply to the selected agent config (env wins): `CTXDB_AGENT` / `CTXDB_API_KEY` / `CTXDB_BASE_URL` / `CTXDB_USER_ID` / `CTXDB_AGENT_ID` / `CTXDB_APP_ID`. The internal login command additionally reads `CTXDB_LOGIN_SERVER` as its provider-neutral login endpoint. The last two default to unset — the request body omits `agent_id`/`app_id` entirely; set them only when you want per-agent / per-app scope isolation on the server.
|
|
418
605
|
|
|
419
606
|
Hook/plugin escape hatch: set `CTXDB_SKIP_HOOKS=TRUE` on the agent process to make all ctxdb hook entrypoints exit immediately before reading config or calling the API. Direct `ctxdb memory` / `ctxdb kb` / `ctxdb setup` CLI commands are unchanged.
|
|
420
607
|
|
|
@@ -475,7 +662,7 @@ ctxdb uninstall --purge-logs # also deletes ~/.ctxdb/logs/
|
|
|
475
662
|
|
|
476
663
|
### What uninstall does (and doesn't) touch
|
|
477
664
|
|
|
478
|
-
- **Hook entries in `~/.qoder/settings.json`, `~/.qoderwork/settings.json`, `~/.qwenwork/settings.json`, `~/.codex/hooks.json`, `~/.claude/settings.json`, and `~/.hermes/config.yaml`**: stripped precisely by marker (`_ctxdb = @aliyunrds/ctxdb`, plus legacy keys `_ctxdbQoder` / `_ctxdbPackage` and the legacy `@aliyunrds/ctxdb-qoder` value for installs predating the unified marker). Any hooks you added yourself stay. A timestamped `*.bak-ctxdb-<TS>` is written before each modification (rotation keeps the 5 most recent).
|
|
665
|
+
- **Hook entries in `~/.qoder/settings.json`, `~/.qoderwork/settings.json`, `~/.qwenwork/settings.json`, `~/.codex/hooks.json`, `~/.claude/settings.json`, `~/.workbuddy/settings.json`, and `~/.hermes/config.yaml`**: stripped precisely by marker (`_ctxdb = @aliyunrds/ctxdb`, plus legacy keys `_ctxdbQoder` / `_ctxdbPackage` and the legacy `@aliyunrds/ctxdb-qoder` value for installs predating the unified marker). Any hooks you added yourself stay. A timestamped `*.bak-ctxdb-<TS>` is written before each modification (rotation keeps the 5 most recent).
|
|
479
666
|
- **Skill directories**: `~/.<agent>/skills/ctxdb/` for each set-up agent, plus legacy dirs (`ctxdb-qoder`, `rds-ctxdb-qoder`, `qoder-ctxdb`) under `~/.qoder/skills/` from older package names.
|
|
480
667
|
- **`~/.ctxdb/` state**: only with `--purge-config` / `--purge-logs` / `--purge-all`. Defensive: `--purge-all` removes the `~/.ctxdb/` root only if it's empty after the named files are deleted (won't blanket-rm an unknown directory).
|
|
481
668
|
- **`~/.codex/config.toml` `[features].hooks`**: **NOT** reverted. Setup adds `hooks = true` so Codex will fire ctxdb's hook entries; uninstall leaves the flag alone because (a) the user may have wanted it on for non-ctxdb hooks, and (b) it's harmless when `~/.codex/hooks.json` is empty. If you want it off, edit the file by hand.
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import {
|
|
3
3
|
fetchKbCatalogBlock,
|
|
4
4
|
recallTurn
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-WSMZOFZQ.js";
|
|
6
6
|
import {
|
|
7
7
|
debug
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-AAZLOCVB.js";
|
|
9
9
|
|
|
10
10
|
// src/lib/warmup-recall.ts
|
|
11
11
|
import { execSync } from "child_process";
|