@kweaver-ai/kweaver-sdk 0.8.1 → 0.8.3

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 (214) hide show
  1. package/README.md +40 -52
  2. package/README.zh.md +41 -46
  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/context-loader.d.ts +1 -0
  19. package/dist/api/resources.d.ts +94 -0
  20. package/dist/api/resources.js +166 -0
  21. package/dist/api/semantic-search.d.ts +5 -0
  22. package/dist/api/semantic-search.js +5 -0
  23. package/dist/api/skills.d.ts +75 -2
  24. package/dist/api/skills.js +108 -12
  25. package/dist/api/trace.d.ts +5 -0
  26. package/dist/api/trace.js +4 -0
  27. package/dist/cli.js +109 -15
  28. package/dist/client.d.ts +3 -3
  29. package/dist/client.js +5 -5
  30. package/dist/commands/agent/mode.d.ts +6 -0
  31. package/dist/commands/agent/mode.js +75 -0
  32. package/dist/commands/agent-members.js +27 -11
  33. package/dist/commands/agent.js +469 -286
  34. package/dist/commands/auth.js +184 -71
  35. package/dist/commands/bkn-metric.js +37 -16
  36. package/dist/commands/bkn-ops.js +164 -86
  37. package/dist/commands/bkn-query.js +99 -31
  38. package/dist/commands/bkn-schema.d.ts +3 -3
  39. package/dist/commands/bkn-schema.js +127 -86
  40. package/dist/commands/bkn.js +153 -114
  41. package/dist/commands/call.js +23 -13
  42. package/dist/commands/config.js +22 -12
  43. package/dist/commands/context-loader.js +625 -49
  44. package/dist/commands/dataflow.js +14 -6
  45. package/dist/commands/ds.js +52 -30
  46. package/dist/commands/explore.js +18 -15
  47. package/dist/commands/model.js +53 -42
  48. package/dist/commands/resource.d.ts +1 -0
  49. package/dist/commands/{dataview.js → resource.js} +62 -84
  50. package/dist/commands/skill.d.ts +21 -1
  51. package/dist/commands/skill.js +567 -43
  52. package/dist/commands/token.js +11 -0
  53. package/dist/commands/tool.js +46 -29
  54. package/dist/commands/toolbox.js +31 -15
  55. package/dist/commands/trace.d.ts +26 -1
  56. package/dist/commands/trace.js +515 -15
  57. package/dist/commands/vega.js +466 -250
  58. package/dist/help/format.d.ts +65 -0
  59. package/dist/help/format.js +141 -0
  60. package/dist/index.d.ts +5 -5
  61. package/dist/index.js +3 -3
  62. package/dist/resources/bkn.d.ts +5 -0
  63. package/dist/resources/bkn.js +5 -0
  64. package/dist/resources/{dataviews.d.ts → resources.d.ts} +10 -11
  65. package/dist/resources/{dataviews.js → resources.js} +12 -13
  66. package/dist/resources/skills.d.ts +17 -1
  67. package/dist/resources/skills.js +32 -1
  68. package/dist/trace-ai/diagnose/agent-binding.d.ts +67 -0
  69. package/dist/trace-ai/diagnose/agent-binding.js +257 -0
  70. package/dist/trace-ai/diagnose/builtin-rules/tool-retry-intent-mismatch.yaml +68 -0
  71. package/dist/trace-ai/diagnose/index.d.ts +32 -0
  72. package/dist/trace-ai/diagnose/index.js +246 -0
  73. package/dist/trace-ai/diagnose/output-schema-converter.d.ts +24 -0
  74. package/dist/trace-ai/diagnose/output-schema-converter.js +81 -0
  75. package/dist/trace-ai/diagnose/query-extractor.d.ts +14 -0
  76. package/dist/trace-ai/diagnose/query-extractor.js +45 -0
  77. package/dist/trace-ai/diagnose/report-assembler.d.ts +31 -0
  78. package/dist/{trace-core → trace-ai}/diagnose/report-assembler.js +19 -9
  79. package/dist/trace-ai/diagnose/report-markdown.d.ts +18 -0
  80. package/dist/trace-ai/diagnose/report-markdown.js +192 -0
  81. package/dist/{trace-core → trace-ai}/diagnose/rule-loader.js +42 -8
  82. package/dist/{trace-core → trace-ai}/diagnose/schemas.d.ts +77 -2
  83. package/dist/trace-ai/diagnose/schemas.js +154 -0
  84. package/dist/trace-ai/diagnose/signal-probe.d.ts +17 -0
  85. package/dist/trace-ai/diagnose/signal-probe.js +39 -0
  86. package/dist/trace-ai/diagnose/synthesizer-agent.d.ts +40 -0
  87. package/dist/trace-ai/diagnose/synthesizer-agent.js +158 -0
  88. package/dist/{trace-core → trace-ai}/diagnose/trace-shaper.js +1 -0
  89. package/dist/{trace-core → trace-ai}/diagnose/types.d.ts +55 -6
  90. package/dist/trace-ai/eval-set/assertion-evaluator.d.ts +29 -0
  91. package/dist/trace-ai/eval-set/assertion-evaluator.js +100 -0
  92. package/dist/trace-ai/eval-set/builder.d.ts +36 -0
  93. package/dist/trace-ai/eval-set/builder.js +126 -0
  94. package/dist/trace-ai/eval-set/index.d.ts +15 -0
  95. package/dist/trace-ai/eval-set/index.js +10 -0
  96. package/dist/trace-ai/eval-set/output-writer.d.ts +27 -0
  97. package/dist/trace-ai/eval-set/output-writer.js +126 -0
  98. package/dist/trace-ai/eval-set/query-picker.d.ts +37 -0
  99. package/dist/trace-ai/eval-set/query-picker.js +147 -0
  100. package/dist/trace-ai/eval-set/redactor.d.ts +42 -0
  101. package/dist/trace-ai/eval-set/redactor.js +133 -0
  102. package/dist/trace-ai/eval-set/rubric-templates/answer-match-reference.prompt.md +19 -0
  103. package/dist/trace-ai/eval-set/schemas.d.ts +136 -0
  104. package/dist/trace-ai/eval-set/schemas.js +130 -0
  105. package/dist/trace-ai/eval-set/semantic-match-provider.d.ts +33 -0
  106. package/dist/trace-ai/eval-set/semantic-match-provider.js +51 -0
  107. package/dist/trace-ai/eval-set/test-runner.d.ts +34 -0
  108. package/dist/trace-ai/eval-set/test-runner.js +153 -0
  109. package/dist/trace-ai/eval-set/types.d.ts +46 -0
  110. package/dist/trace-ai/eval-set/types.js +8 -0
  111. package/dist/trace-ai/exp/bundle-writer.d.ts +10 -0
  112. package/dist/trace-ai/exp/bundle-writer.js +54 -0
  113. package/dist/trace-ai/exp/claude-binary.d.ts +5 -0
  114. package/dist/trace-ai/exp/claude-binary.js +30 -0
  115. package/dist/trace-ai/exp/coordinator.d.ts +45 -0
  116. package/dist/trace-ai/exp/coordinator.js +203 -0
  117. package/dist/trace-ai/exp/eval-runner.d.ts +14 -0
  118. package/dist/trace-ai/exp/eval-runner.js +47 -0
  119. package/dist/trace-ai/exp/exp-store/abort-signal.d.ts +3 -0
  120. package/dist/trace-ai/exp/exp-store/abort-signal.js +27 -0
  121. package/dist/trace-ai/exp/exp-store/candidate-lineage-yaml.d.ts +4 -0
  122. package/dist/trace-ai/exp/exp-store/candidate-lineage-yaml.js +37 -0
  123. package/dist/trace-ai/exp/exp-store/events-jsonl.d.ts +17 -0
  124. package/dist/trace-ai/exp/exp-store/events-jsonl.js +60 -0
  125. package/dist/trace-ai/exp/exp-store/exp-registry.d.ts +6 -0
  126. package/dist/trace-ai/exp/exp-store/exp-registry.js +41 -0
  127. package/dist/trace-ai/exp/exp-store/index.d.ts +46 -0
  128. package/dist/trace-ai/exp/exp-store/index.js +59 -0
  129. package/dist/trace-ai/exp/exp-store/lock.d.ts +3 -0
  130. package/dist/trace-ai/exp/exp-store/lock.js +73 -0
  131. package/dist/trace-ai/exp/exp-store/mission-md.d.ts +3 -0
  132. package/dist/trace-ai/exp/exp-store/mission-md.js +37 -0
  133. package/dist/trace-ai/exp/exp-store/readme-template.d.ts +5 -0
  134. package/dist/trace-ai/exp/exp-store/readme-template.js +25 -0
  135. package/dist/trace-ai/exp/exp-store/round-yaml.d.ts +3 -0
  136. package/dist/trace-ai/exp/exp-store/round-yaml.js +33 -0
  137. package/dist/trace-ai/exp/index.d.ts +8 -0
  138. package/dist/trace-ai/exp/index.js +238 -0
  139. package/dist/trace-ai/exp/info.d.ts +35 -0
  140. package/dist/trace-ai/exp/info.js +120 -0
  141. package/dist/trace-ai/exp/patch/agent-config.d.ts +1 -0
  142. package/dist/trace-ai/exp/patch/agent-config.js +26 -0
  143. package/dist/trace-ai/exp/patch/index.d.ts +2 -0
  144. package/dist/trace-ai/exp/patch/index.js +13 -0
  145. package/dist/trace-ai/exp/patch/skill.d.ts +1 -0
  146. package/dist/trace-ai/exp/patch/skill.js +24 -0
  147. package/dist/trace-ai/exp/providers/synthesizer-client.d.ts +14 -0
  148. package/dist/trace-ai/exp/providers/synthesizer-client.js +39 -0
  149. package/dist/trace-ai/exp/providers/triage-client.d.ts +19 -0
  150. package/dist/trace-ai/exp/providers/triage-client.js +51 -0
  151. package/dist/trace-ai/exp/schemas.d.ts +147 -0
  152. package/dist/trace-ai/exp/schemas.js +50 -0
  153. package/dist/trace-ai/exp/scoring.d.ts +2 -0
  154. package/dist/trace-ai/exp/scoring.js +46 -0
  155. package/dist/trace-ai/scan/aggregator.d.ts +20 -0
  156. package/dist/trace-ai/scan/aggregator.js +26 -0
  157. package/dist/trace-ai/scan/artifacts/paths.d.ts +12 -0
  158. package/dist/trace-ai/scan/artifacts/paths.js +18 -0
  159. package/dist/trace-ai/scan/artifacts/writer.d.ts +67 -0
  160. package/dist/trace-ai/scan/artifacts/writer.js +96 -0
  161. package/dist/trace-ai/scan/batched-rubric.d.ts +55 -0
  162. package/dist/trace-ai/scan/batched-rubric.js +159 -0
  163. package/dist/trace-ai/scan/cross-trace-synthesizer.d.ts +24 -0
  164. package/dist/trace-ai/scan/cross-trace-synthesizer.js +93 -0
  165. package/dist/trace-ai/scan/index.d.ts +31 -0
  166. package/dist/trace-ai/scan/index.js +390 -0
  167. package/dist/trace-ai/scan/prompts/builtin/cross-trace-synthesizer-v1.prompt.md +44 -0
  168. package/dist/trace-ai/scan/prompts/builtin/rubric-judge-batch-v1.prompt.md +44 -0
  169. package/dist/trace-ai/scan/runner.d.ts +25 -0
  170. package/dist/trace-ai/scan/runner.js +42 -0
  171. package/dist/trace-ai/scan/sampler.d.ts +18 -0
  172. package/dist/trace-ai/scan/sampler.js +81 -0
  173. package/dist/trace-ai/scan/scan-summary-markdown.d.ts +2 -0
  174. package/dist/trace-ai/scan/scan-summary-markdown.js +71 -0
  175. package/dist/trace-ai/scan/scan-summary-schema.d.ts +73 -0
  176. package/dist/trace-ai/scan/scan-summary-schema.js +61 -0
  177. package/dist/trace-ai/scan/single-agent-validator.d.ts +23 -0
  178. package/dist/trace-ai/scan/single-agent-validator.js +42 -0
  179. package/dist/trace-ai/scan/traces-list-parser.d.ts +15 -0
  180. package/dist/trace-ai/scan/traces-list-parser.js +46 -0
  181. package/package.json +2 -2
  182. package/dist/api/dataviews.d.ts +0 -117
  183. package/dist/api/dataviews.js +0 -265
  184. package/dist/commands/dataview.d.ts +0 -8
  185. package/dist/trace-core/diagnose/index.d.ts +0 -9
  186. package/dist/trace-core/diagnose/index.js +0 -104
  187. package/dist/trace-core/diagnose/report-assembler.d.ts +0 -12
  188. package/dist/trace-core/diagnose/schemas.js +0 -94
  189. package/dist/trace-core/diagnose/signal-probe.d.ts +0 -5
  190. package/dist/trace-core/diagnose/signal-probe.js +0 -21
  191. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/excessive-tool-calls-per-turn.d.ts +0 -0
  192. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/excessive-tool-calls-per-turn.js +0 -0
  193. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/excessive-tool-calls-per-turn.yaml +0 -0
  194. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/llm-response-truncated-no-continue.d.ts +0 -0
  195. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/llm-response-truncated-no-continue.js +0 -0
  196. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/llm-response-truncated-no-continue.yaml +0 -0
  197. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/register.d.ts +0 -0
  198. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/register.js +0 -0
  199. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/retrieval-empty-no-fallback.d.ts +0 -0
  200. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/retrieval-empty-no-fallback.js +0 -0
  201. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/retrieval-empty-no-fallback.yaml +0 -0
  202. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-error-swallowed.d.ts +0 -0
  203. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-error-swallowed.js +0 -0
  204. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-error-swallowed.yaml +0 -0
  205. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-loop-no-state-change.d.ts +0 -0
  206. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-loop-no-state-change.js +0 -0
  207. /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-loop-no-state-change.yaml +0 -0
  208. /package/dist/{trace-core → trace-ai}/diagnose/predicate-registry.d.ts +0 -0
  209. /package/dist/{trace-core → trace-ai}/diagnose/predicate-registry.js +0 -0
  210. /package/dist/{trace-core → trace-ai}/diagnose/rule-loader.d.ts +0 -0
  211. /package/dist/{trace-core → trace-ai}/diagnose/synthesizer-template.d.ts +0 -0
  212. /package/dist/{trace-core → trace-ai}/diagnose/synthesizer-template.js +0 -0
  213. /package/dist/{trace-core → trace-ai}/diagnose/trace-shaper.d.ts +0 -0
  214. /package/dist/{trace-core → trace-ai}/diagnose/types.js +0 -0
package/README.md CHANGED
@@ -126,23 +126,19 @@ const graph = await client.bkn.querySubgraph("bkn-id", { /* path spec */ });
126
126
  await client.bkn.executeAction("bkn-id", "at-id", { /* params */ });
127
127
  const logs = await client.bkn.listActionLogs("bkn-id");
128
128
 
129
- // Data sources & data views
129
+ // Data sources & vega-backend resources
130
130
  const dsList = await client.datasources.list();
131
131
  const tables = await client.datasources.listTables("ds-id");
132
- const viewId = await client.dataviews.create({ name: "v", datasourceId: "ds-id", table: "orders" });
133
- const views = await client.dataviews.list({ datasourceId: "ds-id" });
134
- const fuzzy = await client.dataviews.find("BOM", { wait: false });
135
- const exact = await client.dataviews.find("orders", {
132
+ const resId = await client.resources.create({ name: "v", datasourceId: "ds-id", table: "orders" });
133
+ const resList = await client.resources.list({ datasourceId: "ds-id" });
134
+ const fuzzy = await client.resources.find("BOM", { wait: false });
135
+ const exact = await client.resources.find("orders", {
136
136
  datasourceId: "ds-id",
137
137
  exact: true,
138
138
  wait: true,
139
139
  });
140
- const dv = await client.dataviews.get(viewId);
141
- const queryRows = await client.dataviews.query(viewId, {
142
- sql: "SELECT id, name FROM orders LIMIT 10",
143
- limit: 10,
144
- needTotal: true,
145
- });
140
+ const res = await client.resources.get(resId);
141
+ const queryRows = await client.resources.query(resId, { limit: 10, needTotal: true });
146
142
 
147
143
  // Dataflow automation (CSV import pipeline, etc.)
148
144
  const result = await client.dataflows.execute({
@@ -165,61 +161,53 @@ const rows = await client.vega.sqlQuery(
165
161
 
166
162
  // Context Loader (MCP search_schema plus generic tools/call)
167
163
  const cl = client.contextLoader(mcpUrl, "bkn-id");
168
- const schema = await cl.searchSchema({ query: "hypertension treatment" });
164
+ const schema = await cl.searchSchema({
165
+ query: "hypertension treatment",
166
+ search_scope: { concept_groups: ["clinical"] },
167
+ });
169
168
  const rawTool = await cl.callTool("search_schema", { query: "hypertension treatment" });
170
169
 
171
170
  // Skills (registry + market + progressive read)
172
171
  const skills = await client.skills.market({ name: "kweaver" });
173
172
  const skillMd = await client.skills.fetchContent("skill-id");
173
+ const draft = await client.skills.updateMetadata("skill-id", {
174
+ name: "Demo",
175
+ description: "Demo skill",
176
+ category: "system",
177
+ });
178
+ const history = await client.skills.history("skill-id");
174
179
  ```
175
180
 
176
- `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`.
181
+ `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`.
182
+
183
+ `client.bkn.knSearch(...)` is deprecated. Use `client.contextLoader(...).searchSchema(...)` for new schema discovery integrations.
177
184
 
178
185
  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.
179
186
 
180
187
  ## CLI Reference
181
188
 
189
+ `kweaver` follows a `gh`-style help layout (see [docs/cli_conventions.md §8](../../docs/cli_conventions.md#8-help-文本格式must)):
190
+
191
+ ```text
192
+ kweaver [--help|-h] # gh-style top-level overview
193
+ kweaver help <command> # forward to <command> --help
194
+ kweaver help all # full per-action signatures (migration fallback)
195
+ kweaver <command> [--help|-h] # subcommand overview + actions
196
+ kweaver <command> <subcommand> [--help|-h] # action-level flags + examples
182
197
  ```
183
- kweaver auth login <url> [--alias name] [--no-auth] [--no-browser] [-u user] [-p pass] [--new-password <pwd>] [--http-signin] [--insecure|-k]
184
- # -u/-p (with or without --http-signin): HTTP POST /oauth2/signin (yields refresh_token). Missing -u/-p are prompted from stdin (password hidden when TTY).
185
- # If the server returns error 401001017 (initial password), TTY users get a prompt to set a new password; non-interactive scripts must pass --new-password <pwd>.
186
- kweaver auth change-password [<url>] [-u <account>] [-o <old>] [-n <new>] [--insecure|-k]
187
- # EACP POST /api/eacp/v1/auth1/modifypassword — no OAuth token required. Omit -o/-n on a TTY to be prompted.
188
- kweaver auth login <url> --client-id ID --client-secret S --refresh-token T (headless login)
189
- kweaver auth export [url|alias] [--json] (export command to run on a headless host)
190
- kweaver auth status / whoami [url|alias] [--json] # whoami: --json; with KWEAVER_BASE_URL+KWEAVER_TOKEN when no ~/.kweaver/ platform
191
- kweaver auth list/use/delete/logout
192
- kweaver config show / list-bd / set-bd <value> # platform business domain — show/list-bd work with KWEAVER_BASE_URL (+ KWEAVER_TOKEN for list-bd)
193
- kweaver token
194
- kweaver ds list/get/delete/tables/connect
195
- kweaver ds import-csv <ds_id> --files <glob> [--table-prefix <p>] [--batch-size 500] [--recreate]
196
- kweaver dataflow list/run/runs/logs
197
- kweaver model llm list/get/add/edit/delete/test/chat/--template
198
- kweaver model small list/get/add/edit/delete/test/embeddings/rerank/--template
199
- kweaver dataview list/find/get/query/delete
200
- kweaver bkn list/get/stats/export/create/update/delete
201
- kweaver bkn create-from-ds <ds_id> --name <name> [--tables t1,t2] [--build]
202
- kweaver bkn create-from-csv <ds_id> --files <glob> --name <name> [--build]
203
- kweaver bkn validate/push/pull
204
- kweaver bkn object-type list/get/create/update/delete/query/properties
205
- kweaver bkn metric list/get/create/search/validate/update/delete/query/dry-run
206
- kweaver bkn relation-type list/get/create/update/delete
207
- kweaver bkn action-type list/query/execute
208
- kweaver bkn subgraph / search
209
- kweaver bkn action-execution get
210
- kweaver bkn action-log list/get/cancel
211
- kweaver agent list/get/create/update/delete/chat/sessions/history/publish/unpublish
212
- kweaver skill list/market/get/register/status/delete/content/read-file/download/install
213
- kweaver vega health/stats/inspect/sql/catalog/resource/connector-type
214
- kweaver context-loader tools|resources|templates|prompts <kn-id>
215
- kweaver context-loader search-schema|tool-call|kn-search|kn-schema-search <kn-id> <query|name> [...]
216
- kweaver context-loader query-object-instance|query-instance-subgraph|get-logic-properties|get-action-info|find-skills <kn-id> ...
217
- kweaver context-loader config set/use/list/show (deprecated; <kn-id> may be omitted to fall back to saved config)
218
- kweaver toolbox create/list/publish/unpublish/delete
219
- kweaver tool upload/list/enable/disable/execute/debug (execute and debug accept --path for OpenAPI path params)
220
- kweaver call <path> [-X METHOD] [-d BODY] [-H header] [-F key=value]
198
+
199
+ Top-level command groups:
200
+
201
+ ```text
202
+ AUTHENTICATION & CONFIG auth · token · config
203
+ DECISION AGENT agent · toolbox · tool
204
+ AI DATA PLATFORM bkn · ds · resource · dataflow · vega · context-loader
205
+ TRACE AI trace
206
+ FOUNDATION call · explore · model · skill · help
221
207
  ```
222
208
 
209
+ For a structured browsable index of every action and flag, run `kweaver help all`.
210
+
223
211
  ### Dataflow CLI examples
224
212
 
225
213
  ```bash
@@ -332,7 +320,7 @@ When `--token` is used, write-disk commands (`auth login` / `logout` / `use` / `
332
320
 
333
321
  `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"`).
334
322
 
335
- `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`.
323
+ `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`.
336
324
 
337
325
  ### TLS Certificate Troubleshooting
338
326
 
package/README.zh.md CHANGED
@@ -124,22 +124,18 @@ const graph = await client.bkn.querySubgraph("bkn-id", { /* 路径规格 */
124
124
  await client.bkn.executeAction("bkn-id", "at-id", { /* 参数 */ });
125
125
  const logs = await client.bkn.listActionLogs("bkn-id");
126
126
 
127
- // 数据源与数据视图
128
- const dsList = await client.datasources.list();
129
- const viewId = await client.dataviews.create({ name: "v", datasourceId: "ds-id", table: "orders" });
130
- const views = await client.dataviews.list({ datasourceId: "ds-id" });
131
- const fuzzy = await client.dataviews.find("BOM", { wait: false });
132
- const exact = await client.dataviews.find("orders", {
127
+ // 数据源 & vega-backend 资源
128
+ const dsList = await client.datasources.list();
129
+ const resId = await client.resources.create({ name: "v", datasourceId: "ds-id", table: "orders" });
130
+ const resList = await client.resources.list({ datasourceId: "ds-id" });
131
+ const fuzzy = await client.resources.find("BOM", { wait: false });
132
+ const exact = await client.resources.find("orders", {
133
133
  datasourceId: "ds-id",
134
134
  exact: true,
135
135
  wait: true,
136
136
  });
137
- const dv = await client.dataviews.get(viewId);
138
- const queryRows = await client.dataviews.query(viewId, {
139
- sql: "SELECT id, name FROM orders LIMIT 10",
140
- limit: 10,
141
- needTotal: true,
142
- });
137
+ const res = await client.resources.get(resId);
138
+ const queryRows = await client.resources.query(resId, { limit: 10, needTotal: true });
143
139
 
144
140
  // Vega — 可观测性与查询
145
141
  const catalogs = await client.vega.listCatalogs();
@@ -156,54 +152,53 @@ const rows = await client.vega.sqlQuery(
156
152
 
157
153
  // Context Loader(MCP search_schema + 通用 tools/call)
158
154
  const cl = client.contextLoader(mcpUrl, "bkn-id");
159
- const schema = await cl.searchSchema({ query: "高血压 治疗" });
155
+ const schema = await cl.searchSchema({
156
+ query: "高血压 治疗",
157
+ search_scope: { concept_groups: ["clinical"] },
158
+ });
160
159
  const rawTool = await cl.callTool("search_schema", { query: "高血压 治疗" });
161
160
 
162
161
  // Skill(注册表/市场/渐进式读取)
163
162
  const skills = await client.skills.market({ name: "kweaver" });
164
163
  const skillMd = await client.skills.fetchContent("skill-id");
164
+ const draft = await client.skills.updateMetadata("skill-id", {
165
+ name: "Demo",
166
+ description: "Demo skill",
167
+ category: "system",
168
+ });
169
+ const history = await client.skills.history("skill-id");
165
170
  ```
166
171
 
167
- `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`。
172
+ `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`。
173
+
174
+ `client.bkn.knSearch(...)` 已过时。新接入的 Schema 发现请使用 `client.contextLoader(...).searchSchema(...)`。
168
175
 
169
176
  需要直接使用 MCP 原生 `tools/call` 时,使用 `callTool(name, args)`。这适用于服务端新增工具但 SDK 尚未提供类型化封装的场景,参数会原样透传。
170
177
 
171
178
  ## 命令速查
172
179
 
180
+ `kweaver` 采用 `gh` 风格 help 布局(详见 [docs/cli_conventions.md §8](../../docs/cli_conventions.md#8-help-文本格式must)):
181
+
182
+ ```text
183
+ kweaver --help # gh 风格顶层概览
184
+ kweaver help <command> # 转发到 `<command> --help`
185
+ kweaver help all # 完整 per-action 签名(迁移期兜底)
186
+ kweaver <command> --help # 子命令概览 + 动作列表
187
+ kweaver <command> <subcommand> --help # 动作级 flag + 示例
173
188
  ```
174
- kweaver auth login <url> [--alias name] [--no-auth] [--no-browser] [-u user] [-p pass] [--new-password <pwd>] [--http-signin] [--insecure|-k]
175
- # -u/-p(无论是否带 --http-signin):HTTP POST /oauth2/signin(可拿 refresh_token);缺失的用户名/密码会从 stdin 提示输入(TTY 下密码隐藏)
176
- # 若服务端返回 401001017(初始密码),交互终端会引导修改;非交互请使用 --new-password <pwd>。
177
- kweaver auth change-password [<url>] [-u <account>] [-o <old>] [-n <new>] [--insecure|-k]
178
- kweaver auth login <url> --client-id ID --client-secret S --refresh-token T (无浏览器登录)
179
- kweaver auth export [url|alias] [--json] (导出在无浏览器机器上运行的命令)
180
- kweaver auth status / whoami [url|alias] [--json] # whoami 支持 --json;无 ~/.kweaver/ 当前平台时可配 KWEAVER_BASE_URL+KWEAVER_TOKEN
181
- kweaver auth list/use/delete/logout
182
- kweaver config show / list-bd / set-bd <value> # 业务域;show/list-bd 在无已保存平台时可与 env 配对
183
- kweaver token
184
- kweaver ds list/get/delete/tables/connect
185
- kweaver dataflow list/run/runs/logs
186
- kweaver model llm list/get/add/edit/delete/test/chat/--template
187
- kweaver model small list/get/add/edit/delete/test/embeddings/rerank/--template
188
- kweaver dataview list/find/get/query/delete
189
- kweaver bkn list/get/stats/export/create/update/delete
190
- kweaver bkn object-type list/get/create/update/delete/query/properties
191
- kweaver bkn metric list/get/create/search/validate/update/delete/query/dry-run
192
- kweaver bkn relation-type list/get/create/update/delete
193
- kweaver bkn action-type list/query/execute
194
- kweaver bkn subgraph
195
- kweaver bkn action-execution get
196
- kweaver bkn action-log list/get/cancel
197
- kweaver agent list/get/chat/sessions/history
198
- kweaver skill list/market/get/register/status/delete/content/read-file/download/install
199
- kweaver vega health|stats|inspect|sql|catalog|resource|connector-type
200
- kweaver context-loader tools|resources|templates|prompts <kn-id>
201
- kweaver context-loader search-schema|tool-call|kn-search|kn-schema-search <kn-id> <query|name> [...]
202
- kweaver context-loader query-object-instance|query-instance-subgraph|get-logic-properties|get-action-info|find-skills <kn-id> ...
203
- kweaver context-loader config set/use/list/show (deprecated;省略 <kn-id> 时回退到已保存配置)
204
- kweaver call <path> [-X METHOD] [-d BODY] [-H header]
189
+
190
+ 顶层命令分组:
191
+
192
+ ```text
193
+ AUTHENTICATION & CONFIG auth · token · config
194
+ DECISION AGENT agent · toolbox · tool
195
+ AI DATA PLATFORM bkn · ds · resource · dataflow · vega · context-loader
196
+ TRACE AI trace
197
+ FOUNDATION call · explore · model · skill · help
205
198
  ```
206
199
 
200
+ 需要查阅每个动作的完整签名(可浏览 / 可 grep)时,运行 `kweaver help all`。
201
+
207
202
  ### Dataflow CLI 示例
208
203
 
209
204
  ```bash
@@ -289,7 +284,7 @@ kweaver --base-url https://platform.example.com --token "$TOK" bkn list
289
284
 
290
285
  `auth whoami` / `auth status` 通过文案区分来源:flag 模式为 `CLI (flag: --token)`,env 模式为 `env (KWEAVER_TOKEN)`(`whoami --json` 为 `"source": "flag"` 与 `"source": "env"`)。
291
286
 
292
- `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` 下整组被禁用。
287
+ `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` 下整组被禁用。
293
288
 
294
289
  ### TLS 证书问题排查
295
290
 
@@ -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
+ }