@kweaver-ai/kweaver-sdk 0.7.4 → 0.8.2

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.
Files changed (190) hide show
  1. package/README.md +39 -5
  2. package/README.zh.md +37 -5
  3. package/dist/agent-providers/index.d.ts +7 -0
  4. package/dist/agent-providers/index.js +5 -0
  5. package/dist/agent-providers/prompt-template.d.ts +62 -0
  6. package/dist/agent-providers/prompt-template.js +105 -0
  7. package/dist/agent-providers/prompts/rubric-judge-v1.prompt.md +51 -0
  8. package/dist/agent-providers/prompts/within-trace-synthesizer-v1.prompt.md +60 -0
  9. package/dist/agent-providers/providers/claude-code-subprocess.d.ts +74 -0
  10. package/dist/agent-providers/providers/claude-code-subprocess.js +259 -0
  11. package/dist/agent-providers/providers/stub.d.ts +47 -0
  12. package/dist/agent-providers/providers/stub.js +77 -0
  13. package/dist/agent-providers/registry.d.ts +45 -0
  14. package/dist/agent-providers/registry.js +77 -0
  15. package/dist/agent-providers/types.d.ts +91 -0
  16. package/dist/agent-providers/types.js +25 -0
  17. package/dist/api/agent-chat.js +8 -6
  18. package/dist/api/agent-observability.d.ts +51 -0
  19. package/dist/api/agent-observability.js +108 -0
  20. package/dist/api/context-loader.d.ts +1 -0
  21. package/dist/api/conversations.d.ts +4 -8
  22. package/dist/api/conversations.js +16 -58
  23. package/dist/api/datasources.d.ts +2 -20
  24. package/dist/api/datasources.js +7 -123
  25. package/dist/api/semantic-search.d.ts +5 -0
  26. package/dist/api/semantic-search.js +5 -0
  27. package/dist/api/skills.d.ts +75 -2
  28. package/dist/api/skills.js +108 -12
  29. package/dist/api/trace.d.ts +49 -0
  30. package/dist/api/trace.js +85 -0
  31. package/dist/api/vega.d.ts +53 -0
  32. package/dist/api/vega.js +144 -0
  33. package/dist/cli.js +12 -5
  34. package/dist/commands/agent/mode.d.ts +6 -0
  35. package/dist/commands/agent/mode.js +75 -0
  36. package/dist/commands/agent.js +101 -29
  37. package/dist/commands/bkn-ops.js +12 -6
  38. package/dist/commands/bkn-utils.d.ts +9 -0
  39. package/dist/commands/bkn-utils.js +17 -0
  40. package/dist/commands/context-loader.js +608 -38
  41. package/dist/commands/ds.js +7 -2
  42. package/dist/commands/skill.d.ts +21 -1
  43. package/dist/commands/skill.js +389 -1
  44. package/dist/commands/trace.d.ts +39 -0
  45. package/dist/commands/trace.js +668 -0
  46. package/dist/index.d.ts +2 -2
  47. package/dist/index.js +1 -1
  48. package/dist/resources/bkn.d.ts +5 -0
  49. package/dist/resources/bkn.js +5 -0
  50. package/dist/resources/datasources.js +2 -1
  51. package/dist/resources/skills.d.ts +17 -1
  52. package/dist/resources/skills.js +32 -1
  53. package/dist/trace-ai/diagnose/agent-binding.d.ts +67 -0
  54. package/dist/trace-ai/diagnose/agent-binding.js +257 -0
  55. package/dist/trace-ai/diagnose/builtin-rules/excessive-tool-calls-per-turn.d.ts +2 -0
  56. package/dist/trace-ai/diagnose/builtin-rules/excessive-tool-calls-per-turn.js +15 -0
  57. package/dist/trace-ai/diagnose/builtin-rules/excessive-tool-calls-per-turn.yaml +16 -0
  58. package/dist/trace-ai/diagnose/builtin-rules/llm-response-truncated-no-continue.d.ts +2 -0
  59. package/dist/trace-ai/diagnose/builtin-rules/llm-response-truncated-no-continue.js +44 -0
  60. package/dist/trace-ai/diagnose/builtin-rules/llm-response-truncated-no-continue.yaml +15 -0
  61. package/dist/trace-ai/diagnose/builtin-rules/register.d.ts +1 -0
  62. package/dist/trace-ai/diagnose/builtin-rules/register.js +11 -0
  63. package/dist/trace-ai/diagnose/builtin-rules/retrieval-empty-no-fallback.d.ts +2 -0
  64. package/dist/trace-ai/diagnose/builtin-rules/retrieval-empty-no-fallback.js +29 -0
  65. package/dist/trace-ai/diagnose/builtin-rules/retrieval-empty-no-fallback.yaml +15 -0
  66. package/dist/trace-ai/diagnose/builtin-rules/tool-error-swallowed.d.ts +2 -0
  67. package/dist/trace-ai/diagnose/builtin-rules/tool-error-swallowed.js +45 -0
  68. package/dist/trace-ai/diagnose/builtin-rules/tool-error-swallowed.yaml +15 -0
  69. package/dist/trace-ai/diagnose/builtin-rules/tool-loop-no-state-change.d.ts +2 -0
  70. package/dist/trace-ai/diagnose/builtin-rules/tool-loop-no-state-change.js +38 -0
  71. package/dist/trace-ai/diagnose/builtin-rules/tool-loop-no-state-change.yaml +16 -0
  72. package/dist/trace-ai/diagnose/builtin-rules/tool-retry-intent-mismatch.yaml +68 -0
  73. package/dist/trace-ai/diagnose/index.d.ts +32 -0
  74. package/dist/trace-ai/diagnose/index.js +246 -0
  75. package/dist/trace-ai/diagnose/output-schema-converter.d.ts +24 -0
  76. package/dist/trace-ai/diagnose/output-schema-converter.js +81 -0
  77. package/dist/trace-ai/diagnose/predicate-registry.d.ts +7 -0
  78. package/dist/trace-ai/diagnose/predicate-registry.js +30 -0
  79. package/dist/trace-ai/diagnose/query-extractor.d.ts +14 -0
  80. package/dist/trace-ai/diagnose/query-extractor.js +45 -0
  81. package/dist/trace-ai/diagnose/report-assembler.d.ts +31 -0
  82. package/dist/trace-ai/diagnose/report-assembler.js +100 -0
  83. package/dist/trace-ai/diagnose/report-markdown.d.ts +18 -0
  84. package/dist/trace-ai/diagnose/report-markdown.js +192 -0
  85. package/dist/trace-ai/diagnose/rule-loader.d.ts +11 -0
  86. package/dist/trace-ai/diagnose/rule-loader.js +120 -0
  87. package/dist/trace-ai/diagnose/schemas.d.ts +184 -0
  88. package/dist/trace-ai/diagnose/schemas.js +154 -0
  89. package/dist/trace-ai/diagnose/signal-probe.d.ts +17 -0
  90. package/dist/trace-ai/diagnose/signal-probe.js +39 -0
  91. package/dist/trace-ai/diagnose/synthesizer-agent.d.ts +40 -0
  92. package/dist/trace-ai/diagnose/synthesizer-agent.js +158 -0
  93. package/dist/trace-ai/diagnose/synthesizer-template.d.ts +2 -0
  94. package/dist/trace-ai/diagnose/synthesizer-template.js +49 -0
  95. package/dist/trace-ai/diagnose/trace-shaper.d.ts +3 -0
  96. package/dist/trace-ai/diagnose/trace-shaper.js +73 -0
  97. package/dist/trace-ai/diagnose/types.d.ts +173 -0
  98. package/dist/trace-ai/diagnose/types.js +1 -0
  99. package/dist/trace-ai/eval-set/assertion-evaluator.d.ts +29 -0
  100. package/dist/trace-ai/eval-set/assertion-evaluator.js +100 -0
  101. package/dist/trace-ai/eval-set/builder.d.ts +36 -0
  102. package/dist/trace-ai/eval-set/builder.js +126 -0
  103. package/dist/trace-ai/eval-set/index.d.ts +15 -0
  104. package/dist/trace-ai/eval-set/index.js +10 -0
  105. package/dist/trace-ai/eval-set/output-writer.d.ts +27 -0
  106. package/dist/trace-ai/eval-set/output-writer.js +126 -0
  107. package/dist/trace-ai/eval-set/query-picker.d.ts +37 -0
  108. package/dist/trace-ai/eval-set/query-picker.js +147 -0
  109. package/dist/trace-ai/eval-set/redactor.d.ts +42 -0
  110. package/dist/trace-ai/eval-set/redactor.js +133 -0
  111. package/dist/trace-ai/eval-set/rubric-templates/answer-match-reference.prompt.md +19 -0
  112. package/dist/trace-ai/eval-set/schemas.d.ts +136 -0
  113. package/dist/trace-ai/eval-set/schemas.js +130 -0
  114. package/dist/trace-ai/eval-set/semantic-match-provider.d.ts +33 -0
  115. package/dist/trace-ai/eval-set/semantic-match-provider.js +51 -0
  116. package/dist/trace-ai/eval-set/test-runner.d.ts +34 -0
  117. package/dist/trace-ai/eval-set/test-runner.js +153 -0
  118. package/dist/trace-ai/eval-set/types.d.ts +46 -0
  119. package/dist/trace-ai/eval-set/types.js +8 -0
  120. package/dist/trace-ai/exp/bundle-writer.d.ts +10 -0
  121. package/dist/trace-ai/exp/bundle-writer.js +54 -0
  122. package/dist/trace-ai/exp/claude-binary.d.ts +5 -0
  123. package/dist/trace-ai/exp/claude-binary.js +30 -0
  124. package/dist/trace-ai/exp/coordinator.d.ts +45 -0
  125. package/dist/trace-ai/exp/coordinator.js +203 -0
  126. package/dist/trace-ai/exp/eval-runner.d.ts +14 -0
  127. package/dist/trace-ai/exp/eval-runner.js +47 -0
  128. package/dist/trace-ai/exp/exp-store/abort-signal.d.ts +3 -0
  129. package/dist/trace-ai/exp/exp-store/abort-signal.js +27 -0
  130. package/dist/trace-ai/exp/exp-store/candidate-lineage-yaml.d.ts +4 -0
  131. package/dist/trace-ai/exp/exp-store/candidate-lineage-yaml.js +37 -0
  132. package/dist/trace-ai/exp/exp-store/events-jsonl.d.ts +17 -0
  133. package/dist/trace-ai/exp/exp-store/events-jsonl.js +60 -0
  134. package/dist/trace-ai/exp/exp-store/exp-registry.d.ts +6 -0
  135. package/dist/trace-ai/exp/exp-store/exp-registry.js +41 -0
  136. package/dist/trace-ai/exp/exp-store/index.d.ts +46 -0
  137. package/dist/trace-ai/exp/exp-store/index.js +59 -0
  138. package/dist/trace-ai/exp/exp-store/lock.d.ts +3 -0
  139. package/dist/trace-ai/exp/exp-store/lock.js +73 -0
  140. package/dist/trace-ai/exp/exp-store/mission-md.d.ts +3 -0
  141. package/dist/trace-ai/exp/exp-store/mission-md.js +37 -0
  142. package/dist/trace-ai/exp/exp-store/readme-template.d.ts +5 -0
  143. package/dist/trace-ai/exp/exp-store/readme-template.js +25 -0
  144. package/dist/trace-ai/exp/exp-store/round-yaml.d.ts +3 -0
  145. package/dist/trace-ai/exp/exp-store/round-yaml.js +33 -0
  146. package/dist/trace-ai/exp/index.d.ts +8 -0
  147. package/dist/trace-ai/exp/index.js +238 -0
  148. package/dist/trace-ai/exp/info.d.ts +35 -0
  149. package/dist/trace-ai/exp/info.js +120 -0
  150. package/dist/trace-ai/exp/patch/agent-config.d.ts +1 -0
  151. package/dist/trace-ai/exp/patch/agent-config.js +26 -0
  152. package/dist/trace-ai/exp/patch/index.d.ts +2 -0
  153. package/dist/trace-ai/exp/patch/index.js +13 -0
  154. package/dist/trace-ai/exp/patch/skill.d.ts +1 -0
  155. package/dist/trace-ai/exp/patch/skill.js +24 -0
  156. package/dist/trace-ai/exp/providers/synthesizer-client.d.ts +14 -0
  157. package/dist/trace-ai/exp/providers/synthesizer-client.js +39 -0
  158. package/dist/trace-ai/exp/providers/triage-client.d.ts +19 -0
  159. package/dist/trace-ai/exp/providers/triage-client.js +51 -0
  160. package/dist/trace-ai/exp/schemas.d.ts +147 -0
  161. package/dist/trace-ai/exp/schemas.js +50 -0
  162. package/dist/trace-ai/exp/scoring.d.ts +2 -0
  163. package/dist/trace-ai/exp/scoring.js +46 -0
  164. package/dist/trace-ai/scan/aggregator.d.ts +20 -0
  165. package/dist/trace-ai/scan/aggregator.js +26 -0
  166. package/dist/trace-ai/scan/artifacts/paths.d.ts +12 -0
  167. package/dist/trace-ai/scan/artifacts/paths.js +18 -0
  168. package/dist/trace-ai/scan/artifacts/writer.d.ts +67 -0
  169. package/dist/trace-ai/scan/artifacts/writer.js +96 -0
  170. package/dist/trace-ai/scan/batched-rubric.d.ts +55 -0
  171. package/dist/trace-ai/scan/batched-rubric.js +159 -0
  172. package/dist/trace-ai/scan/cross-trace-synthesizer.d.ts +24 -0
  173. package/dist/trace-ai/scan/cross-trace-synthesizer.js +93 -0
  174. package/dist/trace-ai/scan/index.d.ts +31 -0
  175. package/dist/trace-ai/scan/index.js +390 -0
  176. package/dist/trace-ai/scan/prompts/builtin/cross-trace-synthesizer-v1.prompt.md +44 -0
  177. package/dist/trace-ai/scan/prompts/builtin/rubric-judge-batch-v1.prompt.md +44 -0
  178. package/dist/trace-ai/scan/runner.d.ts +25 -0
  179. package/dist/trace-ai/scan/runner.js +42 -0
  180. package/dist/trace-ai/scan/sampler.d.ts +18 -0
  181. package/dist/trace-ai/scan/sampler.js +81 -0
  182. package/dist/trace-ai/scan/scan-summary-markdown.d.ts +2 -0
  183. package/dist/trace-ai/scan/scan-summary-markdown.js +71 -0
  184. package/dist/trace-ai/scan/scan-summary-schema.d.ts +73 -0
  185. package/dist/trace-ai/scan/scan-summary-schema.js +61 -0
  186. package/dist/trace-ai/scan/single-agent-validator.d.ts +23 -0
  187. package/dist/trace-ai/scan/single-agent-validator.js +42 -0
  188. package/dist/trace-ai/scan/traces-list-parser.d.ts +15 -0
  189. package/dist/trace-ai/scan/traces-list-parser.js +46 -0
  190. package/package.json +14 -4
package/README.md CHANGED
@@ -16,6 +16,26 @@ npm install @kweaver-ai/kweaver-sdk
16
16
 
17
17
  Requires **Node.js >= 22**.
18
18
 
19
+ ## API reference (TypeDoc)
20
+
21
+ Generate HTML from source + TSDoc, then open `docs/reference/typescript-api-html/index.html` (gitignored), or serve locally:
22
+
23
+ HTML reference auto-discovers **`src/resources/*`**, **`src/api/*`**, and **`src/auth/*`** via TypeDoc's `entryPointStrategy: "expand"` (`typedoc.json`), so newly added modules appear without editing the config. The English build uses `README.md` as the cover page; the Chinese build uses `README.zh.md`. **"Defined in"** GitHub links read `gitRevision` from `TYPEDOC_GIT_REVISION` → `GITHUB_SHA` → fallback `"main"`; CI should pin links to the build SHA: `TYPEDOC_GIT_REVISION=$GITHUB_SHA npm run docs`.
24
+
25
+ TypeDoc does **not** ship a single-site EN/ZH toggle. Use two outputs: English UI (default) and Chinese UI strings (`docs:zh`, primarily localizes navigation chrome). API descriptions come from TSDoc and stay English unless you maintain duplicate comments elsewhere.
26
+
27
+ ```bash
28
+ cd packages/typescript
29
+ npm install
30
+ npm run docs # English UI → docs/reference/typescript-api-html/
31
+ npm run docs:serve # generate + serve http://127.0.0.1:8766
32
+ npm run docs:zh # Chinese UI + README.zh.md → docs/reference/typescript-api-html-zh/
33
+ npm run docs:serve:zh # generate + serve http://127.0.0.1:8767
34
+ npm run docs:all # both folders
35
+ ```
36
+
37
+ > Files inside `docs/reference/**` are generated. Edit `packages/typescript/README*.md` and TSDoc comments in source instead — anything copied into `media/` is overwritten on the next build.
38
+
19
39
  ## Quick Start
20
40
 
21
41
  ### Authenticate
@@ -145,15 +165,26 @@ const rows = await client.vega.sqlQuery(
145
165
 
146
166
  // Context Loader (MCP search_schema plus generic tools/call)
147
167
  const cl = client.contextLoader(mcpUrl, "bkn-id");
148
- const schema = await cl.searchSchema({ query: "hypertension treatment" });
168
+ const schema = await cl.searchSchema({
169
+ query: "hypertension treatment",
170
+ search_scope: { concept_groups: ["clinical"] },
171
+ });
149
172
  const rawTool = await cl.callTool("search_schema", { query: "hypertension treatment" });
150
173
 
151
174
  // Skills (registry + market + progressive read)
152
175
  const skills = await client.skills.market({ name: "kweaver" });
153
176
  const skillMd = await client.skills.fetchContent("skill-id");
177
+ const draft = await client.skills.updateMetadata("skill-id", {
178
+ name: "Demo",
179
+ description: "Demo skill",
180
+ category: "system",
181
+ });
182
+ const history = await client.skills.history("skill-id");
154
183
  ```
155
184
 
156
- `searchSchema()` is the typed wrapper for the Context Loader MCP `search_schema` tool. It defaults `response_format` to `json` and accepts `query`, `response_format`, `search_scope`, `max_concepts`, `schema_brief`, and `enable_rerank`. The parsed response may contain `object_types`, `relation_types`, `action_types`, and `metric_types`.
185
+ `searchSchema()` is the typed wrapper for the Context Loader MCP `search_schema` tool. It defaults `response_format` to `json` and accepts `query`, `response_format`, `search_scope`, `max_concepts`, `schema_brief`, and `enable_rerank`. `search_scope.concept_groups` limits schema discovery to BKN concept group IDs; it is not an instance-data filter. The parsed response may contain `object_types`, `relation_types`, `action_types`, and `metric_types`.
186
+
187
+ `client.bkn.knSearch(...)` is deprecated. Use `client.contextLoader(...).searchSchema(...)` for new schema discovery integrations.
157
188
 
158
189
  Use `callTool(name, args)` when you need native MCP `tools/call` access for newly added server tools before the SDK adds a typed wrapper. Arguments are passed through unchanged.
159
190
 
@@ -189,10 +220,13 @@ kweaver bkn subgraph / search
189
220
  kweaver bkn action-execution get
190
221
  kweaver bkn action-log list/get/cancel
191
222
  kweaver agent list/get/create/update/delete/chat/sessions/history/publish/unpublish
192
- kweaver skill list/market/get/register/status/delete/content/read-file/download/install
223
+ kweaver skill list/market/get/market-get/register/status/delete/update-metadata/update-package/history/republish/publish-history/content/read-file/download/install/management-content/management-read-file/management-download
193
224
  kweaver vega health/stats/inspect/sql/catalog/resource/connector-type
225
+ kweaver context-loader help <subcommand>
194
226
  kweaver context-loader tools|resources|templates|prompts <kn-id>
195
- kweaver context-loader search-schema|tool-call|kn-search|kn-schema-search <kn-id> <query|name> [...]
227
+ kweaver context-loader search-schema <kn-id> <query> [--scope object,relation,action,metric] [--concept-groups ids]
228
+ kweaver context-loader tool-call <kn-id> <name> --args '<json>'
229
+ kweaver context-loader kn-search|kn-schema-search <kn-id> <query> [...] (deprecated; use search-schema)
196
230
  kweaver context-loader query-object-instance|query-instance-subgraph|get-logic-properties|get-action-info|find-skills <kn-id> ...
197
231
  kweaver context-loader config set/use/list/show (deprecated; <kn-id> may be omitted to fall back to saved config)
198
232
  kweaver toolbox create/list/publish/unpublish/delete
@@ -312,7 +346,7 @@ When `--token` is used, write-disk commands (`auth login` / `logout` / `use` / `
312
346
 
313
347
  `auth whoami` / `auth status` distinguish the two stateless modes: `Source: CLI (flag: --token)` for flag mode, `env (KWEAVER_TOKEN)` for env mode (`whoami --json` uses `"source": "flag"` vs `"source": "env"`).
314
348
 
315
- `kweaver context-loader` runtime subcommands accept `<kn-id>` as the first positional (e.g. `kweaver context-loader tools <kn-id>`) or via the global `--kn-id <id>` / `-k <id>` flag, so they work in stateless mode without any saved config. The `context-loader config set|use|list|remove|show` management group is deprecated, prints a warning on use, and is disabled in its entirety under `--token`.
349
+ `kweaver context-loader` runtime subcommands accept `<kn-id>` as the first positional (e.g. `kweaver context-loader tools <kn-id>`) or via the global `--kn-id <id>` / `-k <id>` flag, so they work in stateless mode without any saved config. Use `kweaver context-loader help <subcommand>` or `<subcommand> --help` to inspect arguments before login/network checks. The `context-loader config set|use|list|remove|show` management group is deprecated, prints a warning on use, and is disabled in its entirety under `--token`.
316
350
 
317
351
  ### TLS Certificate Troubleshooting
318
352
 
package/README.zh.md CHANGED
@@ -16,6 +16,24 @@ npm install @kweaver-ai/kweaver-sdk
16
16
 
17
17
  需要 **Node.js >= 22**。
18
18
 
19
+ ## API 参考(TypeDoc)
20
+
21
+ 由源码与 TSDoc 生成 HTML,产物在 `docs/reference/typescript-api-html/index.html`(已 gitignore)。`typedoc.json` 用 **`entryPointStrategy: "expand"`** 自动展开 **`src/resources`**、**`src/api`**、**`src/auth`** 整目录,新增模块无需改配置。英文构建用 `README.md`,中文构建用 `README.zh.md`。**「Defined in」** 链接的 `gitRevision` 取 `TYPEDOC_GIT_REVISION` → `GITHUB_SHA` → 回退 `"main"`;CI 中固定到当前 SHA:`TYPEDOC_GIT_REVISION=$GITHUB_SHA npm run docs`。
22
+
23
+ TypeDoc **不会在同一个站点里提供中英文切换**。做法是生成两套目录:英文界面(默认)与中文界面(**`npm run docs:zh`**),主要翻译导航等界面文案;**API 说明仍以源码里的 TSDoc(英文)为准**。
24
+
25
+ ```bash
26
+ cd packages/typescript
27
+ npm install
28
+ npm run docs # 英文界面 → docs/reference/typescript-api-html/
29
+ npm run docs:serve # 生成并访问 http://127.0.0.1:8766
30
+ npm run docs:zh # 中文界面 + README.zh.md → docs/reference/typescript-api-html-zh/
31
+ npm run docs:serve:zh # 生成并访问 http://127.0.0.1:8767
32
+ npm run docs:all # 两套产物都生成
33
+ ```
34
+
35
+ > `docs/reference/**` 下的所有文件均为生成产物。请编辑 `packages/typescript/README*.md` 与源码 TSDoc 注释;`media/` 下的拷贝在下次构建时会被覆盖。
36
+
19
37
  ## 快速上手
20
38
 
21
39
  ### 认证
@@ -138,15 +156,26 @@ const rows = await client.vega.sqlQuery(
138
156
 
139
157
  // Context Loader(MCP search_schema + 通用 tools/call)
140
158
  const cl = client.contextLoader(mcpUrl, "bkn-id");
141
- const schema = await cl.searchSchema({ query: "高血压 治疗" });
159
+ const schema = await cl.searchSchema({
160
+ query: "高血压 治疗",
161
+ search_scope: { concept_groups: ["clinical"] },
162
+ });
142
163
  const rawTool = await cl.callTool("search_schema", { query: "高血压 治疗" });
143
164
 
144
165
  // Skill(注册表/市场/渐进式读取)
145
166
  const skills = await client.skills.market({ name: "kweaver" });
146
167
  const skillMd = await client.skills.fetchContent("skill-id");
168
+ const draft = await client.skills.updateMetadata("skill-id", {
169
+ name: "Demo",
170
+ description: "Demo skill",
171
+ category: "system",
172
+ });
173
+ const history = await client.skills.history("skill-id");
147
174
  ```
148
175
 
149
- `searchSchema()` 是 Context Loader MCP `search_schema` 的类型化封装,默认 `response_format` 为 `json`,支持 `query`、`response_format`、`search_scope`、`max_concepts`、`schema_brief`、`enable_rerank`。解析后的返回结果可能包含 `object_types`、`relation_types`、`action_types`、`metric_types`。
176
+ `searchSchema()` 是 Context Loader MCP `search_schema` 的类型化封装,默认 `response_format` 为 `json`,支持 `query`、`response_format`、`search_scope`、`max_concepts`、`schema_brief`、`enable_rerank`。`search_scope.concept_groups` 用于按 BKN 概念分组 ID 限定 Schema 发现范围,不是实例数据过滤条件。解析后的返回结果可能包含 `object_types`、`relation_types`、`action_types`、`metric_types`。
177
+
178
+ `client.bkn.knSearch(...)` 已过时。新接入的 Schema 发现请使用 `client.contextLoader(...).searchSchema(...)`。
150
179
 
151
180
  需要直接使用 MCP 原生 `tools/call` 时,使用 `callTool(name, args)`。这适用于服务端新增工具但 SDK 尚未提供类型化封装的场景,参数会原样透传。
152
181
 
@@ -177,10 +206,13 @@ kweaver bkn subgraph
177
206
  kweaver bkn action-execution get
178
207
  kweaver bkn action-log list/get/cancel
179
208
  kweaver agent list/get/chat/sessions/history
180
- kweaver skill list/market/get/register/status/delete/content/read-file/download/install
209
+ kweaver skill list/market/get/market-get/register/status/delete/update-metadata/update-package/history/republish/publish-history/content/read-file/download/install/management-content/management-read-file/management-download
181
210
  kweaver vega health|stats|inspect|sql|catalog|resource|connector-type
211
+ kweaver context-loader help <subcommand>
182
212
  kweaver context-loader tools|resources|templates|prompts <kn-id>
183
- kweaver context-loader search-schema|tool-call|kn-search|kn-schema-search <kn-id> <query|name> [...]
213
+ kweaver context-loader search-schema <kn-id> <query> [--scope object,relation,action,metric] [--concept-groups ids]
214
+ kweaver context-loader tool-call <kn-id> <name> --args '<json>'
215
+ kweaver context-loader kn-search|kn-schema-search <kn-id> <query> [...] (deprecated;请使用 search-schema)
184
216
  kweaver context-loader query-object-instance|query-instance-subgraph|get-logic-properties|get-action-info|find-skills <kn-id> ...
185
217
  kweaver context-loader config set/use/list/show (deprecated;省略 <kn-id> 时回退到已保存配置)
186
218
  kweaver call <path> [-X METHOD] [-d BODY] [-H header]
@@ -271,7 +303,7 @@ kweaver --base-url https://platform.example.com --token "$TOK" bkn list
271
303
 
272
304
  `auth whoami` / `auth status` 通过文案区分来源:flag 模式为 `CLI (flag: --token)`,env 模式为 `env (KWEAVER_TOKEN)`(`whoami --json` 为 `"source": "flag"` 与 `"source": "env"`)。
273
305
 
274
- `kweaver context-loader` 运行时子命令将 `<kn-id>` 作为第一个位置参数(如 `kweaver context-loader tools <kn-id>`),也支持全局 `--kn-id <id>` / `-k <id>` flag,因此在 stateless 模式下可直接使用,无需任何持久化配置。`context-loader config set|use|list|remove|show` 管理子命令已被标记为 deprecated(每次调用打印警告),且在 `--token` 下整组被禁用。
306
+ `kweaver context-loader` 运行时子命令将 `<kn-id>` 作为第一个位置参数(如 `kweaver context-loader tools <kn-id>`),也支持全局 `--kn-id <id>` / `-k <id>` flag,因此在 stateless 模式下可直接使用,无需任何持久化配置。调试参数时可先执行 `kweaver context-loader help <subcommand>` 或 `<subcommand> --help`,这些 help 路径不会触发登录、配置读取或网络请求。`context-loader config set|use|list|remove|show` 管理子命令已被标记为 deprecated(每次调用打印警告),且在 `--token` 下整组被禁用。
275
307
 
276
308
  ### TLS 证书问题排查
277
309
 
@@ -0,0 +1,7 @@
1
+ export * from "./types.js";
2
+ export { AgentRegistry, defaultRegistry } from "./registry.js";
3
+ export { PromptTemplateRegistry, defaultPromptRegistry, render, type PromptTemplate, } from "./prompt-template.js";
4
+ export { StubAgentProvider } from "./providers/stub.js";
5
+ export type { StubAgentProviderOpts, StubResponseFn } from "./providers/stub.js";
6
+ export { ClaudeCodeSubprocessProvider } from "./providers/claude-code-subprocess.js";
7
+ export type { ClaudeCodeSubprocessProviderOpts } from "./providers/claude-code-subprocess.js";
@@ -0,0 +1,5 @@
1
+ export * from "./types.js";
2
+ export { AgentRegistry, defaultRegistry } from "./registry.js";
3
+ export { PromptTemplateRegistry, defaultPromptRegistry, render, } from "./prompt-template.js";
4
+ export { StubAgentProvider } from "./providers/stub.js";
5
+ export { ClaudeCodeSubprocessProvider } from "./providers/claude-code-subprocess.js";
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Tiny prompt template registry — load `.prompt.md` files from a directory,
3
+ * resolve by `builtin:<name>` reference, render with a flat variables map.
4
+ *
5
+ * Why not a templating engine: the templates ship with the SDK, vars are
6
+ * trusted internal data (rule yaml + trace metadata), and the substitution
7
+ * is one-pass `{{key}}` → string. A 30-line implementation beats pulling in
8
+ * Handlebars / Mustache and the security surface they bring.
9
+ */
10
+ export interface PromptTemplate {
11
+ /** `builtin:rubric-judge-v1`, `builtin:within-trace-synthesizer-v1`, etc. */
12
+ ref: string;
13
+ /** Raw template body with `{{var}}` placeholders. */
14
+ body: string;
15
+ /** Absolute path to the source file, kept for debugging. */
16
+ sourcePath: string;
17
+ }
18
+ export declare class PromptTemplateRegistry {
19
+ private byRef;
20
+ has(ref: string): boolean;
21
+ get(ref: string): PromptTemplate;
22
+ list(): string[];
23
+ /**
24
+ * Register a prompt body directly (used by tests; production loads from disk).
25
+ */
26
+ registerInline(ref: string, body: string, sourcePath?: string): void;
27
+ /**
28
+ * Scan a directory for `*.prompt.md` files and register each as
29
+ * `builtin:<basename-without-suffix>`. Skips non-files / non-matching
30
+ * extensions silently — callers can `list()` to confirm what loaded.
31
+ */
32
+ loadBuiltinDir(dir: string): Promise<void>;
33
+ }
34
+ /**
35
+ * Substitute `{{key}}` occurrences with `String(vars[key])`.
36
+ *
37
+ * Unknown keys throw — silent substitution masks template / data drift
38
+ * (e.g. spec rename `tool_name` → `name` would otherwise leave `{{tool_name}}`
39
+ * verbatim in the prompt and the agent would politely answer about its
40
+ * literal value).
41
+ *
42
+ * `vars[key]` of type `object | array` is JSON-stringified with 2-space
43
+ * indent — the common case is "interpolate a JSON evidence blob into a
44
+ * markdown prompt block".
45
+ */
46
+ export declare function render(template: PromptTemplate, vars: Record<string, unknown>): string;
47
+ export declare const defaultPromptRegistry: PromptTemplateRegistry;
48
+ /**
49
+ * Supported output locales for agent-judged natural-language fields.
50
+ * JSON keys, enum values, and span IDs are ALWAYS English regardless of
51
+ * locale — only prose fields (`headline`, `reasoning`, `description`,
52
+ * `reason`, `excerpt`) get localized. This keeps downstream report
53
+ * consumers locale-independent.
54
+ */
55
+ export type AgentOutputLang = 'en' | 'zh';
56
+ /**
57
+ * Render the boilerplate "respond in <language>" instruction injected via
58
+ * the `{{language_instruction}}` placeholder in rubric / synthesizer
59
+ * prompts. English returns "" so the placeholder collapses cleanly —
60
+ * prompts default to English without needing an instruction.
61
+ */
62
+ export declare function languageInstructionFor(lang: AgentOutputLang): string;
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Tiny prompt template registry — load `.prompt.md` files from a directory,
3
+ * resolve by `builtin:<name>` reference, render with a flat variables map.
4
+ *
5
+ * Why not a templating engine: the templates ship with the SDK, vars are
6
+ * trusted internal data (rule yaml + trace metadata), and the substitution
7
+ * is one-pass `{{key}}` → string. A 30-line implementation beats pulling in
8
+ * Handlebars / Mustache and the security surface they bring.
9
+ */
10
+ import fs from "node:fs/promises";
11
+ import path from "node:path";
12
+ export class PromptTemplateRegistry {
13
+ byRef = new Map();
14
+ has(ref) {
15
+ return this.byRef.has(ref);
16
+ }
17
+ get(ref) {
18
+ const tpl = this.byRef.get(ref);
19
+ if (!tpl) {
20
+ throw new Error(`prompt template not registered: '${ref}'; registered refs: [${[...this.byRef.keys()].join(", ") || "(none)"}]`);
21
+ }
22
+ return tpl;
23
+ }
24
+ list() {
25
+ return [...this.byRef.keys()];
26
+ }
27
+ /**
28
+ * Register a prompt body directly (used by tests; production loads from disk).
29
+ */
30
+ registerInline(ref, body, sourcePath = "<inline>") {
31
+ this.byRef.set(ref, { ref, body, sourcePath });
32
+ }
33
+ /**
34
+ * Scan a directory for `*.prompt.md` files and register each as
35
+ * `builtin:<basename-without-suffix>`. Skips non-files / non-matching
36
+ * extensions silently — callers can `list()` to confirm what loaded.
37
+ */
38
+ async loadBuiltinDir(dir) {
39
+ let entries;
40
+ try {
41
+ entries = await fs.readdir(dir, { withFileTypes: true });
42
+ }
43
+ catch (e) {
44
+ const err = e;
45
+ if (err.code === "ENOENT")
46
+ return;
47
+ throw err;
48
+ }
49
+ for (const e of entries) {
50
+ if (!e.isFile())
51
+ continue;
52
+ if (!e.name.endsWith(".prompt.md"))
53
+ continue;
54
+ const filePath = path.join(dir, e.name);
55
+ const body = await fs.readFile(filePath, "utf8");
56
+ const base = e.name.slice(0, -".prompt.md".length);
57
+ this.byRef.set(`builtin:${base}`, { ref: `builtin:${base}`, body, sourcePath: filePath });
58
+ }
59
+ }
60
+ }
61
+ /**
62
+ * Substitute `{{key}}` occurrences with `String(vars[key])`.
63
+ *
64
+ * Unknown keys throw — silent substitution masks template / data drift
65
+ * (e.g. spec rename `tool_name` → `name` would otherwise leave `{{tool_name}}`
66
+ * verbatim in the prompt and the agent would politely answer about its
67
+ * literal value).
68
+ *
69
+ * `vars[key]` of type `object | array` is JSON-stringified with 2-space
70
+ * indent — the common case is "interpolate a JSON evidence blob into a
71
+ * markdown prompt block".
72
+ */
73
+ export function render(template, vars) {
74
+ return template.body.replace(/\{\{\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\}\}/g, (_, key) => {
75
+ if (!(key in vars)) {
76
+ throw new Error(`prompt template '${template.ref}' references unknown variable '{{${key}}}'; provided vars: [${Object.keys(vars).join(", ")}]`);
77
+ }
78
+ const v = vars[key];
79
+ if (v === null || v === undefined)
80
+ return "";
81
+ if (typeof v === "string")
82
+ return v;
83
+ if (typeof v === "number" || typeof v === "boolean")
84
+ return String(v);
85
+ return JSON.stringify(v, null, 2);
86
+ });
87
+ }
88
+ export const defaultPromptRegistry = new PromptTemplateRegistry();
89
+ /**
90
+ * Render the boilerplate "respond in <language>" instruction injected via
91
+ * the `{{language_instruction}}` placeholder in rubric / synthesizer
92
+ * prompts. English returns "" so the placeholder collapses cleanly —
93
+ * prompts default to English without needing an instruction.
94
+ */
95
+ export function languageInstructionFor(lang) {
96
+ if (lang === "zh") {
97
+ return [
98
+ "**Language: respond in Simplified Chinese (简体中文) for all natural-language fields** ",
99
+ "(e.g. `headline`, `reasoning`, `description`, `reason`, `excerpt`). JSON keys, ",
100
+ "enum values (like `severity: high`, `category: stale_results`), and span IDs ",
101
+ "MUST stay in English exactly as specified by the schema — only prose is localized.",
102
+ ].join("");
103
+ }
104
+ return "";
105
+ }
@@ -0,0 +1,51 @@
1
+ # Trace-Diagnose Rubric Judge
2
+
3
+ You are evaluating one rule against one agent trace. Read the rule's
4
+ judge question, the supplied inputs, and reply with a single JSON object
5
+ that satisfies the supplied output schema.
6
+
7
+ ## Rule
8
+ - **rule_id**: `{{rule_id}}`
9
+ - **trace_id**: `{{trace_id}}`
10
+
11
+ ## Judge Question
12
+ {{judge_question}}
13
+
14
+ ## Inputs
15
+ The rule's `inputs` have been resolved from the trace and serialized
16
+ below. Each key matches the rule's `inputs[*].kind`; the value is what
17
+ the binding extracted (string for `extract_from_root_attr`, ordered array
18
+ for `filter_by_kind`, parsed JSON for `literal`). When inputs reference
19
+ spans, each span includes its `spanId` — your `first_violating_step_id`
20
+ must be one of those IDs.
21
+
22
+ ```json
23
+ {{inputs}}
24
+ ```
25
+
26
+ ## Output Schema
27
+ Your reply MUST be a single JSON object matching this schema. No prose,
28
+ no markdown fences, no explanation outside the JSON — the response is
29
+ parsed programmatically and rejected on any deviation.
30
+
31
+ ```json
32
+ {{output_schema}}
33
+ ```
34
+
35
+ {{language_instruction}}
36
+
37
+ ## Output Rules
38
+ 1. `first_violating_step_id` MUST be a real span id from the inputs above
39
+ — the diagnose pipeline correlates rubric findings with symbolic
40
+ findings on this id.
41
+ 2. `reasoning` should be one or two sentences, concrete and pointed at
42
+ evidence in the inputs (cite span ids).
43
+ 3. If `severity` is part of the schema, use the user-facing impact, not
44
+ the agent's internal struggle — a single retry that finished successfully
45
+ is `low` even if the mechanism was wasteful.
46
+ 4. If `confidence` is part of the schema, set it to `low` when the inputs
47
+ don't clearly demonstrate the symptom; `high` when multiple spans
48
+ converge on the same conclusion.
49
+ 5. If the judge question lists categorical options, pick the closest one
50
+ even if it isn't perfect — don't fall through to `other` unless the
51
+ evidence actively rules out every named category.
@@ -0,0 +1,60 @@
1
+ # Within-Trace Synthesizer
2
+
3
+ You are given the findings produced by both pillars of trace diagnosis
4
+ on **one trace** — symbolic (deterministic predicates) and rubric
5
+ (LLM-judged semantic verdicts). Your job is to compose a short narrative
6
+ that helps a developer act on them quickly.
7
+
8
+ ## Trace
9
+ - **trace_id**: `{{trace_id}}`
10
+ - **agent_id**: `{{agent_id}}`
11
+
12
+ ## Findings
13
+ Each finding is one antipattern detected by one rule. `judgmentKind` is
14
+ either `symbolic` (cheap, deterministic) or `rubric` (agent-judged).
15
+ Multiple findings may describe the same incident from different angles —
16
+ your job is to detect those overlaps.
17
+
18
+ ```json
19
+ {{findings}}
20
+ ```
21
+
22
+ ## Output Schema
23
+ Reply with a single JSON object satisfying this schema. No prose, no
24
+ markdown fences — the response is parsed programmatically.
25
+
26
+ ```json
27
+ {{output_schema}}
28
+ ```
29
+
30
+ {{language_instruction}}
31
+
32
+ ## Composition Rules
33
+ 1. **headline** ≤ 160 characters; one sentence; lead with the user-facing
34
+ symptom, not the rule mechanics. ("Agent failed to recognize stale
35
+ retrieval results across 3 retries", not "tool_loop_no_state_change
36
+ fired with loop_count=3".)
37
+ 2. **primary_root_cause** points at the finding(s) that, if fixed, would
38
+ prevent the rest. If two findings describe the same incident (one
39
+ symbolic, one rubric), include both in `finding_ids` and explain the
40
+ relationship in `description`. Set `target_for_fix` to the most
41
+ actionable artifact among the cited findings' `suggested_fix.target`.
42
+ Use `null` only if no finding can plausibly be a root cause (rare).
43
+ 3. **fix_priority** orders ALL findings by what to address first. Severity
44
+ is the default tiebreak; promote a low-severity finding above a
45
+ higher one when the low one is a precondition for the high one (e.g.
46
+ "fix the swallowed tool error first; the truncation that follows
47
+ will go away on its own"). Give a one-line `reason` for each.
48
+ 4. **cross_finding_links** captures relationships:
49
+ - `same_incident`: two findings on the same span sequence, one symbolic
50
+ + one rubric — typical pairing pattern.
51
+ - `cascading`: finding A's symptom directly caused finding B.
52
+ - `redundant`: two rubric judgments produced similar verdicts on
53
+ unrelated symbolic findings — flag for rule pruning.
54
+ - `overlapping_evidence_spans`: spans overlap but the relation is
55
+ unclear; use as a last resort.
56
+ Only include links where you can name a concrete relation; an empty
57
+ `cross_finding_links` array is fine.
58
+ 5. Be concrete: every claim should be traceable to a finding by index.
59
+ If the findings array is empty, headline = "No findings", everything
60
+ else = null / empty arrays.
@@ -0,0 +1,74 @@
1
+ /**
2
+ * AgentProvider that spawns the Claude Code CLI as a one-shot subprocess.
3
+ *
4
+ * $ claude -p --output-format=json --dangerously-skip-permissions <prompt-on-stdin>
5
+ *
6
+ * Why subprocess + the `claude` CLI (vs an HTTP / SDK transport):
7
+ * - Zero remote service dependency for trace-ai diagnose — dogfoods
8
+ * the same CLI the user already authenticates / configures.
9
+ * - One binary to install across user laptops + CI.
10
+ * - `--output-format=json` returns a stable envelope (`{ result: <text> }`)
11
+ * so we can deterministically extract the model's answer.
12
+ *
13
+ * The model's textual response is expected to be JSON matching the
14
+ * caller's `outputSchema`. The provider:
15
+ * 1. spawns the CLI, pipes `prompt` to stdin
16
+ * 2. parses the CLI's stdout envelope (json mode)
17
+ * 3. extracts the inner text, parses it as JSON
18
+ * 4. validates against `outputSchema`
19
+ * 5. on parse / schema failure, retries the *whole* invocation once
20
+ * with a "fix the JSON" suffix appended (bounded; PR-B doesn't
21
+ * do exponential backoff)
22
+ *
23
+ * Failure modes surface as typed `AgentProviderError`:
24
+ * not_available `claude` not on PATH, or `isAvailable()` was false
25
+ * timeout subprocess exceeded timeoutMs
26
+ * transport non-zero exit / no stdout
27
+ * invalid_json envelope parsed but inner text wasn't JSON (after retry)
28
+ * schema_violation inner JSON didn't satisfy outputSchema (after retry)
29
+ */
30
+ import type { AgentProvider, JudgmentRequest, JudgmentResponse, ProviderCapability } from "../types.js";
31
+ export interface ClaudeCodeSubprocessProviderOpts {
32
+ /** Override the binary on PATH (default: 'claude'). */
33
+ binary?: string;
34
+ /** Extra CLI args, prepended before our defaults. */
35
+ extraArgs?: string[];
36
+ /** Default timeout per invoke (ms). Per-call timeoutMs in JudgmentRequest takes precedence. */
37
+ defaultTimeoutMs?: number;
38
+ /** Working directory for the subprocess (default: process.cwd()). */
39
+ cwd?: string;
40
+ /** Environment overrides (merged with process.env). */
41
+ env?: Record<string, string>;
42
+ /** Override `name` reported on the provider (default: 'claude-code'). */
43
+ name?: string;
44
+ /**
45
+ * Map the tier intent on a JudgmentRequest to a concrete claude model name.
46
+ * Defaults: fast='haiku', std='sonnet'. `--model {value}` is appended to
47
+ * spawn args only when `req.tier` is set; undefined tier omits the flag
48
+ * and lets claude CLI pick its own default (preserves PR-B behavior).
49
+ */
50
+ modelByTier?: {
51
+ fast?: string;
52
+ std?: string;
53
+ };
54
+ }
55
+ export declare class ClaudeCodeSubprocessProvider implements AgentProvider {
56
+ readonly name: string;
57
+ readonly capabilities: ReadonlySet<ProviderCapability>;
58
+ private binary;
59
+ private extraArgs;
60
+ private defaultTimeoutMs;
61
+ private cwd;
62
+ private env;
63
+ private availabilityCache;
64
+ private modelByTier;
65
+ constructor(opts?: ClaudeCodeSubprocessProviderOpts);
66
+ /** Visible for testing. Builds the spawn args list including --model when tier is set. */
67
+ buildSpawnArgs(tier: "fast" | "std" | undefined): string[];
68
+ /**
69
+ * Cached for 60s — repeated rubric rules don't each pay the spawn cost
70
+ * of `claude --version`. Cache is per-instance, not process-wide.
71
+ */
72
+ isAvailable(): Promise<boolean>;
73
+ invoke<TOutput>(req: JudgmentRequest<TOutput>): Promise<JudgmentResponse<TOutput>>;
74
+ }