@kweaver-ai/kweaver-sdk 0.8.1 → 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.
- package/README.md +19 -5
- package/README.zh.md +19 -5
- package/dist/agent-providers/index.d.ts +7 -0
- package/dist/agent-providers/index.js +5 -0
- package/dist/agent-providers/prompt-template.d.ts +62 -0
- package/dist/agent-providers/prompt-template.js +105 -0
- package/dist/agent-providers/prompts/rubric-judge-v1.prompt.md +51 -0
- package/dist/agent-providers/prompts/within-trace-synthesizer-v1.prompt.md +60 -0
- package/dist/agent-providers/providers/claude-code-subprocess.d.ts +74 -0
- package/dist/agent-providers/providers/claude-code-subprocess.js +259 -0
- package/dist/agent-providers/providers/stub.d.ts +47 -0
- package/dist/agent-providers/providers/stub.js +77 -0
- package/dist/agent-providers/registry.d.ts +45 -0
- package/dist/agent-providers/registry.js +77 -0
- package/dist/agent-providers/types.d.ts +91 -0
- package/dist/agent-providers/types.js +25 -0
- package/dist/api/agent-chat.js +8 -6
- package/dist/api/context-loader.d.ts +1 -0
- package/dist/api/semantic-search.d.ts +5 -0
- package/dist/api/semantic-search.js +5 -0
- package/dist/api/skills.d.ts +75 -2
- package/dist/api/skills.js +108 -12
- package/dist/api/trace.d.ts +5 -0
- package/dist/api/trace.js +4 -0
- package/dist/cli.js +7 -5
- package/dist/commands/agent/mode.d.ts +6 -0
- package/dist/commands/agent/mode.js +75 -0
- package/dist/commands/agent.js +101 -29
- package/dist/commands/context-loader.js +608 -38
- package/dist/commands/skill.d.ts +21 -1
- package/dist/commands/skill.js +389 -1
- package/dist/commands/trace.d.ts +26 -1
- package/dist/commands/trace.js +515 -15
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/resources/bkn.d.ts +5 -0
- package/dist/resources/bkn.js +5 -0
- package/dist/resources/skills.d.ts +17 -1
- package/dist/resources/skills.js +32 -1
- package/dist/trace-ai/diagnose/agent-binding.d.ts +67 -0
- package/dist/trace-ai/diagnose/agent-binding.js +257 -0
- package/dist/trace-ai/diagnose/builtin-rules/tool-retry-intent-mismatch.yaml +68 -0
- package/dist/trace-ai/diagnose/index.d.ts +32 -0
- package/dist/trace-ai/diagnose/index.js +246 -0
- package/dist/trace-ai/diagnose/output-schema-converter.d.ts +24 -0
- package/dist/trace-ai/diagnose/output-schema-converter.js +81 -0
- package/dist/trace-ai/diagnose/query-extractor.d.ts +14 -0
- package/dist/trace-ai/diagnose/query-extractor.js +45 -0
- package/dist/trace-ai/diagnose/report-assembler.d.ts +31 -0
- package/dist/{trace-core → trace-ai}/diagnose/report-assembler.js +19 -9
- package/dist/trace-ai/diagnose/report-markdown.d.ts +18 -0
- package/dist/trace-ai/diagnose/report-markdown.js +192 -0
- package/dist/{trace-core → trace-ai}/diagnose/rule-loader.js +42 -8
- package/dist/{trace-core → trace-ai}/diagnose/schemas.d.ts +77 -2
- package/dist/trace-ai/diagnose/schemas.js +154 -0
- package/dist/trace-ai/diagnose/signal-probe.d.ts +17 -0
- package/dist/trace-ai/diagnose/signal-probe.js +39 -0
- package/dist/trace-ai/diagnose/synthesizer-agent.d.ts +40 -0
- package/dist/trace-ai/diagnose/synthesizer-agent.js +158 -0
- package/dist/{trace-core → trace-ai}/diagnose/trace-shaper.js +1 -0
- package/dist/{trace-core → trace-ai}/diagnose/types.d.ts +55 -6
- package/dist/trace-ai/eval-set/assertion-evaluator.d.ts +29 -0
- package/dist/trace-ai/eval-set/assertion-evaluator.js +100 -0
- package/dist/trace-ai/eval-set/builder.d.ts +36 -0
- package/dist/trace-ai/eval-set/builder.js +126 -0
- package/dist/trace-ai/eval-set/index.d.ts +15 -0
- package/dist/trace-ai/eval-set/index.js +10 -0
- package/dist/trace-ai/eval-set/output-writer.d.ts +27 -0
- package/dist/trace-ai/eval-set/output-writer.js +126 -0
- package/dist/trace-ai/eval-set/query-picker.d.ts +37 -0
- package/dist/trace-ai/eval-set/query-picker.js +147 -0
- package/dist/trace-ai/eval-set/redactor.d.ts +42 -0
- package/dist/trace-ai/eval-set/redactor.js +133 -0
- package/dist/trace-ai/eval-set/rubric-templates/answer-match-reference.prompt.md +19 -0
- package/dist/trace-ai/eval-set/schemas.d.ts +136 -0
- package/dist/trace-ai/eval-set/schemas.js +130 -0
- package/dist/trace-ai/eval-set/semantic-match-provider.d.ts +33 -0
- package/dist/trace-ai/eval-set/semantic-match-provider.js +51 -0
- package/dist/trace-ai/eval-set/test-runner.d.ts +34 -0
- package/dist/trace-ai/eval-set/test-runner.js +153 -0
- package/dist/trace-ai/eval-set/types.d.ts +46 -0
- package/dist/trace-ai/eval-set/types.js +8 -0
- package/dist/trace-ai/exp/bundle-writer.d.ts +10 -0
- package/dist/trace-ai/exp/bundle-writer.js +54 -0
- package/dist/trace-ai/exp/claude-binary.d.ts +5 -0
- package/dist/trace-ai/exp/claude-binary.js +30 -0
- package/dist/trace-ai/exp/coordinator.d.ts +45 -0
- package/dist/trace-ai/exp/coordinator.js +203 -0
- package/dist/trace-ai/exp/eval-runner.d.ts +14 -0
- package/dist/trace-ai/exp/eval-runner.js +47 -0
- package/dist/trace-ai/exp/exp-store/abort-signal.d.ts +3 -0
- package/dist/trace-ai/exp/exp-store/abort-signal.js +27 -0
- package/dist/trace-ai/exp/exp-store/candidate-lineage-yaml.d.ts +4 -0
- package/dist/trace-ai/exp/exp-store/candidate-lineage-yaml.js +37 -0
- package/dist/trace-ai/exp/exp-store/events-jsonl.d.ts +17 -0
- package/dist/trace-ai/exp/exp-store/events-jsonl.js +60 -0
- package/dist/trace-ai/exp/exp-store/exp-registry.d.ts +6 -0
- package/dist/trace-ai/exp/exp-store/exp-registry.js +41 -0
- package/dist/trace-ai/exp/exp-store/index.d.ts +46 -0
- package/dist/trace-ai/exp/exp-store/index.js +59 -0
- package/dist/trace-ai/exp/exp-store/lock.d.ts +3 -0
- package/dist/trace-ai/exp/exp-store/lock.js +73 -0
- package/dist/trace-ai/exp/exp-store/mission-md.d.ts +3 -0
- package/dist/trace-ai/exp/exp-store/mission-md.js +37 -0
- package/dist/trace-ai/exp/exp-store/readme-template.d.ts +5 -0
- package/dist/trace-ai/exp/exp-store/readme-template.js +25 -0
- package/dist/trace-ai/exp/exp-store/round-yaml.d.ts +3 -0
- package/dist/trace-ai/exp/exp-store/round-yaml.js +33 -0
- package/dist/trace-ai/exp/index.d.ts +8 -0
- package/dist/trace-ai/exp/index.js +238 -0
- package/dist/trace-ai/exp/info.d.ts +35 -0
- package/dist/trace-ai/exp/info.js +120 -0
- package/dist/trace-ai/exp/patch/agent-config.d.ts +1 -0
- package/dist/trace-ai/exp/patch/agent-config.js +26 -0
- package/dist/trace-ai/exp/patch/index.d.ts +2 -0
- package/dist/trace-ai/exp/patch/index.js +13 -0
- package/dist/trace-ai/exp/patch/skill.d.ts +1 -0
- package/dist/trace-ai/exp/patch/skill.js +24 -0
- package/dist/trace-ai/exp/providers/synthesizer-client.d.ts +14 -0
- package/dist/trace-ai/exp/providers/synthesizer-client.js +39 -0
- package/dist/trace-ai/exp/providers/triage-client.d.ts +19 -0
- package/dist/trace-ai/exp/providers/triage-client.js +51 -0
- package/dist/trace-ai/exp/schemas.d.ts +147 -0
- package/dist/trace-ai/exp/schemas.js +50 -0
- package/dist/trace-ai/exp/scoring.d.ts +2 -0
- package/dist/trace-ai/exp/scoring.js +46 -0
- package/dist/trace-ai/scan/aggregator.d.ts +20 -0
- package/dist/trace-ai/scan/aggregator.js +26 -0
- package/dist/trace-ai/scan/artifacts/paths.d.ts +12 -0
- package/dist/trace-ai/scan/artifacts/paths.js +18 -0
- package/dist/trace-ai/scan/artifacts/writer.d.ts +67 -0
- package/dist/trace-ai/scan/artifacts/writer.js +96 -0
- package/dist/trace-ai/scan/batched-rubric.d.ts +55 -0
- package/dist/trace-ai/scan/batched-rubric.js +159 -0
- package/dist/trace-ai/scan/cross-trace-synthesizer.d.ts +24 -0
- package/dist/trace-ai/scan/cross-trace-synthesizer.js +93 -0
- package/dist/trace-ai/scan/index.d.ts +31 -0
- package/dist/trace-ai/scan/index.js +390 -0
- package/dist/trace-ai/scan/prompts/builtin/cross-trace-synthesizer-v1.prompt.md +44 -0
- package/dist/trace-ai/scan/prompts/builtin/rubric-judge-batch-v1.prompt.md +44 -0
- package/dist/trace-ai/scan/runner.d.ts +25 -0
- package/dist/trace-ai/scan/runner.js +42 -0
- package/dist/trace-ai/scan/sampler.d.ts +18 -0
- package/dist/trace-ai/scan/sampler.js +81 -0
- package/dist/trace-ai/scan/scan-summary-markdown.d.ts +2 -0
- package/dist/trace-ai/scan/scan-summary-markdown.js +71 -0
- package/dist/trace-ai/scan/scan-summary-schema.d.ts +73 -0
- package/dist/trace-ai/scan/scan-summary-schema.js +61 -0
- package/dist/trace-ai/scan/single-agent-validator.d.ts +23 -0
- package/dist/trace-ai/scan/single-agent-validator.js +42 -0
- package/dist/trace-ai/scan/traces-list-parser.d.ts +15 -0
- package/dist/trace-ai/scan/traces-list-parser.js +46 -0
- package/package.json +2 -2
- package/dist/trace-core/diagnose/index.d.ts +0 -9
- package/dist/trace-core/diagnose/index.js +0 -104
- package/dist/trace-core/diagnose/report-assembler.d.ts +0 -12
- package/dist/trace-core/diagnose/schemas.js +0 -94
- package/dist/trace-core/diagnose/signal-probe.d.ts +0 -5
- package/dist/trace-core/diagnose/signal-probe.js +0 -21
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/excessive-tool-calls-per-turn.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/excessive-tool-calls-per-turn.js +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/excessive-tool-calls-per-turn.yaml +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/llm-response-truncated-no-continue.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/llm-response-truncated-no-continue.js +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/llm-response-truncated-no-continue.yaml +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/register.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/register.js +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/retrieval-empty-no-fallback.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/retrieval-empty-no-fallback.js +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/retrieval-empty-no-fallback.yaml +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-error-swallowed.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-error-swallowed.js +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-error-swallowed.yaml +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-loop-no-state-change.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-loop-no-state-change.js +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/builtin-rules/tool-loop-no-state-change.yaml +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/predicate-registry.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/predicate-registry.js +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/rule-loader.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/synthesizer-template.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/synthesizer-template.js +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/trace-shaper.d.ts +0 -0
- /package/dist/{trace-core → trace-ai}/diagnose/types.js +0 -0
package/README.md
CHANGED
|
@@ -165,15 +165,26 @@ const rows = await client.vega.sqlQuery(
|
|
|
165
165
|
|
|
166
166
|
// Context Loader (MCP search_schema plus generic tools/call)
|
|
167
167
|
const cl = client.contextLoader(mcpUrl, "bkn-id");
|
|
168
|
-
const schema = await cl.searchSchema({
|
|
168
|
+
const schema = await cl.searchSchema({
|
|
169
|
+
query: "hypertension treatment",
|
|
170
|
+
search_scope: { concept_groups: ["clinical"] },
|
|
171
|
+
});
|
|
169
172
|
const rawTool = await cl.callTool("search_schema", { query: "hypertension treatment" });
|
|
170
173
|
|
|
171
174
|
// Skills (registry + market + progressive read)
|
|
172
175
|
const skills = await client.skills.market({ name: "kweaver" });
|
|
173
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");
|
|
174
183
|
```
|
|
175
184
|
|
|
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`.
|
|
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.
|
|
177
188
|
|
|
178
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.
|
|
179
190
|
|
|
@@ -209,10 +220,13 @@ kweaver bkn subgraph / search
|
|
|
209
220
|
kweaver bkn action-execution get
|
|
210
221
|
kweaver bkn action-log list/get/cancel
|
|
211
222
|
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
|
|
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
|
|
213
224
|
kweaver vega health/stats/inspect/sql/catalog/resource/connector-type
|
|
225
|
+
kweaver context-loader help <subcommand>
|
|
214
226
|
kweaver context-loader tools|resources|templates|prompts <kn-id>
|
|
215
|
-
kweaver context-loader search-schema
|
|
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)
|
|
216
230
|
kweaver context-loader query-object-instance|query-instance-subgraph|get-logic-properties|get-action-info|find-skills <kn-id> ...
|
|
217
231
|
kweaver context-loader config set/use/list/show (deprecated; <kn-id> may be omitted to fall back to saved config)
|
|
218
232
|
kweaver toolbox create/list/publish/unpublish/delete
|
|
@@ -332,7 +346,7 @@ When `--token` is used, write-disk commands (`auth login` / `logout` / `use` / `
|
|
|
332
346
|
|
|
333
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"`).
|
|
334
348
|
|
|
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`.
|
|
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`.
|
|
336
350
|
|
|
337
351
|
### TLS Certificate Troubleshooting
|
|
338
352
|
|
package/README.zh.md
CHANGED
|
@@ -156,15 +156,26 @@ const rows = await client.vega.sqlQuery(
|
|
|
156
156
|
|
|
157
157
|
// Context Loader(MCP search_schema + 通用 tools/call)
|
|
158
158
|
const cl = client.contextLoader(mcpUrl, "bkn-id");
|
|
159
|
-
const schema = await cl.searchSchema({
|
|
159
|
+
const schema = await cl.searchSchema({
|
|
160
|
+
query: "高血压 治疗",
|
|
161
|
+
search_scope: { concept_groups: ["clinical"] },
|
|
162
|
+
});
|
|
160
163
|
const rawTool = await cl.callTool("search_schema", { query: "高血压 治疗" });
|
|
161
164
|
|
|
162
165
|
// Skill(注册表/市场/渐进式读取)
|
|
163
166
|
const skills = await client.skills.market({ name: "kweaver" });
|
|
164
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");
|
|
165
174
|
```
|
|
166
175
|
|
|
167
|
-
`searchSchema()` 是 Context Loader MCP `search_schema` 的类型化封装,默认 `response_format` 为 `json`,支持 `query`、`response_format`、`search_scope`、`max_concepts`、`schema_brief`、`enable_rerank
|
|
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(...)`。
|
|
168
179
|
|
|
169
180
|
需要直接使用 MCP 原生 `tools/call` 时,使用 `callTool(name, args)`。这适用于服务端新增工具但 SDK 尚未提供类型化封装的场景,参数会原样透传。
|
|
170
181
|
|
|
@@ -195,10 +206,13 @@ kweaver bkn subgraph
|
|
|
195
206
|
kweaver bkn action-execution get
|
|
196
207
|
kweaver bkn action-log list/get/cancel
|
|
197
208
|
kweaver agent list/get/chat/sessions/history
|
|
198
|
-
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
|
|
199
210
|
kweaver vega health|stats|inspect|sql|catalog|resource|connector-type
|
|
211
|
+
kweaver context-loader help <subcommand>
|
|
200
212
|
kweaver context-loader tools|resources|templates|prompts <kn-id>
|
|
201
|
-
kweaver context-loader search-schema
|
|
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)
|
|
202
216
|
kweaver context-loader query-object-instance|query-instance-subgraph|get-logic-properties|get-action-info|find-skills <kn-id> ...
|
|
203
217
|
kweaver context-loader config set/use/list/show (deprecated;省略 <kn-id> 时回退到已保存配置)
|
|
204
218
|
kweaver call <path> [-X METHOD] [-d BODY] [-H header]
|
|
@@ -289,7 +303,7 @@ kweaver --base-url https://platform.example.com --token "$TOK" bkn list
|
|
|
289
303
|
|
|
290
304
|
`auth whoami` / `auth status` 通过文案区分来源:flag 模式为 `CLI (flag: --token)`,env 模式为 `env (KWEAVER_TOKEN)`(`whoami --json` 为 `"source": "flag"` 与 `"source": "env"`)。
|
|
291
305
|
|
|
292
|
-
`kweaver context-loader` 运行时子命令将 `<kn-id>` 作为第一个位置参数(如 `kweaver context-loader tools <kn-id>`),也支持全局 `--kn-id <id>` / `-k <id>` flag,因此在 stateless
|
|
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` 下整组被禁用。
|
|
293
307
|
|
|
294
308
|
### TLS 证书问题排查
|
|
295
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
|
+
}
|