@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.
- package/README.md +39 -5
- package/README.zh.md +37 -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/agent-observability.d.ts +51 -0
- package/dist/api/agent-observability.js +108 -0
- package/dist/api/context-loader.d.ts +1 -0
- package/dist/api/conversations.d.ts +4 -8
- package/dist/api/conversations.js +16 -58
- package/dist/api/datasources.d.ts +2 -20
- package/dist/api/datasources.js +7 -123
- 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 +49 -0
- package/dist/api/trace.js +85 -0
- package/dist/api/vega.d.ts +53 -0
- package/dist/api/vega.js +144 -0
- package/dist/cli.js +12 -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/bkn-ops.js +12 -6
- package/dist/commands/bkn-utils.d.ts +9 -0
- package/dist/commands/bkn-utils.js +17 -0
- package/dist/commands/context-loader.js +608 -38
- package/dist/commands/ds.js +7 -2
- package/dist/commands/skill.d.ts +21 -1
- package/dist/commands/skill.js +389 -1
- package/dist/commands/trace.d.ts +39 -0
- package/dist/commands/trace.js +668 -0
- 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/datasources.js +2 -1
- 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/excessive-tool-calls-per-turn.d.ts +2 -0
- package/dist/trace-ai/diagnose/builtin-rules/excessive-tool-calls-per-turn.js +15 -0
- package/dist/trace-ai/diagnose/builtin-rules/excessive-tool-calls-per-turn.yaml +16 -0
- package/dist/trace-ai/diagnose/builtin-rules/llm-response-truncated-no-continue.d.ts +2 -0
- package/dist/trace-ai/diagnose/builtin-rules/llm-response-truncated-no-continue.js +44 -0
- package/dist/trace-ai/diagnose/builtin-rules/llm-response-truncated-no-continue.yaml +15 -0
- package/dist/trace-ai/diagnose/builtin-rules/register.d.ts +1 -0
- package/dist/trace-ai/diagnose/builtin-rules/register.js +11 -0
- package/dist/trace-ai/diagnose/builtin-rules/retrieval-empty-no-fallback.d.ts +2 -0
- package/dist/trace-ai/diagnose/builtin-rules/retrieval-empty-no-fallback.js +29 -0
- package/dist/trace-ai/diagnose/builtin-rules/retrieval-empty-no-fallback.yaml +15 -0
- package/dist/trace-ai/diagnose/builtin-rules/tool-error-swallowed.d.ts +2 -0
- package/dist/trace-ai/diagnose/builtin-rules/tool-error-swallowed.js +45 -0
- package/dist/trace-ai/diagnose/builtin-rules/tool-error-swallowed.yaml +15 -0
- package/dist/trace-ai/diagnose/builtin-rules/tool-loop-no-state-change.d.ts +2 -0
- package/dist/trace-ai/diagnose/builtin-rules/tool-loop-no-state-change.js +38 -0
- package/dist/trace-ai/diagnose/builtin-rules/tool-loop-no-state-change.yaml +16 -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/predicate-registry.d.ts +7 -0
- package/dist/trace-ai/diagnose/predicate-registry.js +30 -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-ai/diagnose/report-assembler.js +100 -0
- package/dist/trace-ai/diagnose/report-markdown.d.ts +18 -0
- package/dist/trace-ai/diagnose/report-markdown.js +192 -0
- package/dist/trace-ai/diagnose/rule-loader.d.ts +11 -0
- package/dist/trace-ai/diagnose/rule-loader.js +120 -0
- package/dist/trace-ai/diagnose/schemas.d.ts +184 -0
- 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-ai/diagnose/synthesizer-template.d.ts +2 -0
- package/dist/trace-ai/diagnose/synthesizer-template.js +49 -0
- package/dist/trace-ai/diagnose/trace-shaper.d.ts +3 -0
- package/dist/trace-ai/diagnose/trace-shaper.js +73 -0
- package/dist/trace-ai/diagnose/types.d.ts +173 -0
- package/dist/trace-ai/diagnose/types.js +1 -0
- 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 +14 -4
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
function rel(p) { return p; }
|
|
2
|
+
export function renderScanSummaryMarkdown(s) {
|
|
3
|
+
const lines = [];
|
|
4
|
+
const scan = s.scan;
|
|
5
|
+
lines.push(`# Trace Diagnose Batch Summary — agent \`${scan.agent_id}\``);
|
|
6
|
+
lines.push("");
|
|
7
|
+
const resumeBanner = scan.resumed_from_partial
|
|
8
|
+
? ` · resumed — ${scan.traces_reused} reused, ${scan.traces_freshly_diagnosed} freshly diagnosed`
|
|
9
|
+
: "";
|
|
10
|
+
lines.push(`> ${scan.trace_count} traces · ${scan.traces_with_findings} with findings · diagnosed ${scan.diagnosed_at} · cli \`${scan.cli_version}\`${resumeBanner}`);
|
|
11
|
+
lines.push("");
|
|
12
|
+
// ── Summary ────────────────────────────────────────────────────────────
|
|
13
|
+
lines.push("## Summary");
|
|
14
|
+
lines.push("");
|
|
15
|
+
if (s.summary === null) {
|
|
16
|
+
lines.push("_Stage-4 synthesizer did not complete; aggregates and per-trace reports are still emitted below._");
|
|
17
|
+
lines.push("");
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
lines.push(`**${s.summary.headline}**`);
|
|
21
|
+
lines.push("");
|
|
22
|
+
if (s.summary.primary_root_cause) {
|
|
23
|
+
const rc = s.summary.primary_root_cause;
|
|
24
|
+
lines.push(`Primary root cause — rules ${rc.rule_ids.map((id) => `\`${id}\``).join(", ")}; target for fix: \`${rc.target_for_fix}\`.`);
|
|
25
|
+
lines.push("");
|
|
26
|
+
lines.push(`> ${rc.description.replace(/\r?\n+/g, " ")}`);
|
|
27
|
+
lines.push("");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// ── Fix priority ───────────────────────────────────────────────────────
|
|
31
|
+
if (s.summary && s.summary.fix_priority.length > 0) {
|
|
32
|
+
lines.push("## Fix priority");
|
|
33
|
+
lines.push("");
|
|
34
|
+
lines.push("| Order | Rule | Affected | Reason |");
|
|
35
|
+
lines.push("|---|---|---|---|");
|
|
36
|
+
s.summary.fix_priority.forEach((p, idx) => {
|
|
37
|
+
lines.push(`| ${idx + 1} | \`${p.rule_id}\` | ${p.affected_trace_count} | ${p.reason.replace(/\|/g, "\\|").replace(/\r?\n/g, " ")} |`);
|
|
38
|
+
});
|
|
39
|
+
lines.push("");
|
|
40
|
+
}
|
|
41
|
+
// ── Cross-rule links ───────────────────────────────────────────────────
|
|
42
|
+
if (s.summary && s.summary.cross_rule_links.length > 0) {
|
|
43
|
+
lines.push("## Cross-rule links");
|
|
44
|
+
lines.push("");
|
|
45
|
+
for (const link of s.summary.cross_rule_links) {
|
|
46
|
+
const ids = link.rule_ids.map((r) => `\`${r}\``).join(" ↔ ");
|
|
47
|
+
lines.push(`- ${ids} — ${link.relation}`);
|
|
48
|
+
}
|
|
49
|
+
lines.push("");
|
|
50
|
+
}
|
|
51
|
+
// ── Aggregates ─────────────────────────────────────────────────────────
|
|
52
|
+
lines.push("## Aggregates");
|
|
53
|
+
lines.push("");
|
|
54
|
+
lines.push("| Rule | Count | high | medium | low |");
|
|
55
|
+
lines.push("|---|---|---|---|---|");
|
|
56
|
+
for (const item of s.aggregates.rule_frequency) {
|
|
57
|
+
lines.push(`| \`${item.rule_id}\` | ${item.count} | ${item.severity_breakdown.high} | ${item.severity_breakdown.medium} | ${item.severity_breakdown.low} |`);
|
|
58
|
+
}
|
|
59
|
+
lines.push("");
|
|
60
|
+
// ── Per-trace index ────────────────────────────────────────────────────
|
|
61
|
+
lines.push("## Per-Trace Reports");
|
|
62
|
+
lines.push("");
|
|
63
|
+
lines.push("| conv_id | trace_id | findings | report |");
|
|
64
|
+
lines.push("|---|---|---|---|");
|
|
65
|
+
for (const item of s.per_trace_index) {
|
|
66
|
+
const mdPath = item.report_path.replace(/\.yaml$/, ".md");
|
|
67
|
+
lines.push(`| \`${item.conversation_id}\` | \`${item.trace_id.slice(0, 16)}…\` | ${item.finding_count} | [yaml](${item.report_path}) / [md](${mdPath}) |`);
|
|
68
|
+
}
|
|
69
|
+
lines.push("");
|
|
70
|
+
return lines.join("\n");
|
|
71
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The `summary` block shape — used both as the embedded field of the full
|
|
4
|
+
* scan-summary report AND as the output schema the Stage-4 cross-trace
|
|
5
|
+
* synthesizer LLM must satisfy.
|
|
6
|
+
*/
|
|
7
|
+
export declare const ScanSummaryShape: z.ZodObject<{
|
|
8
|
+
headline: z.ZodString;
|
|
9
|
+
primary_root_cause: z.ZodNullable<z.ZodObject<{
|
|
10
|
+
rule_ids: z.ZodArray<z.ZodString>;
|
|
11
|
+
description: z.ZodString;
|
|
12
|
+
target_for_fix: z.ZodString;
|
|
13
|
+
}, z.core.$strip>>;
|
|
14
|
+
fix_priority: z.ZodArray<z.ZodObject<{
|
|
15
|
+
rule_id: z.ZodString;
|
|
16
|
+
affected_trace_count: z.ZodNumber;
|
|
17
|
+
reason: z.ZodString;
|
|
18
|
+
}, z.core.$strip>>;
|
|
19
|
+
cross_rule_links: z.ZodArray<z.ZodObject<{
|
|
20
|
+
rule_ids: z.ZodArray<z.ZodString>;
|
|
21
|
+
relation: z.ZodString;
|
|
22
|
+
}, z.core.$strip>>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
export type ScanSummaryShape = z.infer<typeof ScanSummaryShape>;
|
|
25
|
+
export declare const ScanSummarySchema: z.ZodObject<{
|
|
26
|
+
schema_version: z.ZodLiteral<"scan-summary/v1">;
|
|
27
|
+
scan: z.ZodObject<{
|
|
28
|
+
agent_id: z.ZodString;
|
|
29
|
+
trace_count: z.ZodNumber;
|
|
30
|
+
traces_with_findings: z.ZodNumber;
|
|
31
|
+
traces_reused: z.ZodNumber;
|
|
32
|
+
traces_freshly_diagnosed: z.ZodNumber;
|
|
33
|
+
resumed_from_partial: z.ZodBoolean;
|
|
34
|
+
diagnosed_at: z.ZodString;
|
|
35
|
+
cli_version: z.ZodString;
|
|
36
|
+
synthesizer_mode: z.ZodLiteral<"agent">;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
summary: z.ZodNullable<z.ZodObject<{
|
|
39
|
+
headline: z.ZodString;
|
|
40
|
+
primary_root_cause: z.ZodNullable<z.ZodObject<{
|
|
41
|
+
rule_ids: z.ZodArray<z.ZodString>;
|
|
42
|
+
description: z.ZodString;
|
|
43
|
+
target_for_fix: z.ZodString;
|
|
44
|
+
}, z.core.$strip>>;
|
|
45
|
+
fix_priority: z.ZodArray<z.ZodObject<{
|
|
46
|
+
rule_id: z.ZodString;
|
|
47
|
+
affected_trace_count: z.ZodNumber;
|
|
48
|
+
reason: z.ZodString;
|
|
49
|
+
}, z.core.$strip>>;
|
|
50
|
+
cross_rule_links: z.ZodArray<z.ZodObject<{
|
|
51
|
+
rule_ids: z.ZodArray<z.ZodString>;
|
|
52
|
+
relation: z.ZodString;
|
|
53
|
+
}, z.core.$strip>>;
|
|
54
|
+
}, z.core.$strip>>;
|
|
55
|
+
aggregates: z.ZodObject<{
|
|
56
|
+
rule_frequency: z.ZodArray<z.ZodObject<{
|
|
57
|
+
rule_id: z.ZodString;
|
|
58
|
+
count: z.ZodNumber;
|
|
59
|
+
severity_breakdown: z.ZodObject<{
|
|
60
|
+
high: z.ZodNumber;
|
|
61
|
+
medium: z.ZodNumber;
|
|
62
|
+
low: z.ZodNumber;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
}, z.core.$strip>>;
|
|
65
|
+
}, z.core.$strip>;
|
|
66
|
+
per_trace_index: z.ZodArray<z.ZodObject<{
|
|
67
|
+
trace_id: z.ZodString;
|
|
68
|
+
conversation_id: z.ZodString;
|
|
69
|
+
report_path: z.ZodString;
|
|
70
|
+
finding_count: z.ZodNumber;
|
|
71
|
+
}, z.core.$strip>>;
|
|
72
|
+
}, z.core.$strip>;
|
|
73
|
+
export type ScanSummary = z.infer<typeof ScanSummarySchema>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// packages/typescript/src/trace-ai/scan/scan-summary-schema.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
const PrimaryRootCauseShape = z.object({
|
|
4
|
+
rule_ids: z.array(z.string()).min(1),
|
|
5
|
+
description: z.string(),
|
|
6
|
+
target_for_fix: z.string(),
|
|
7
|
+
});
|
|
8
|
+
const FixPriorityItemShape = z.object({
|
|
9
|
+
rule_id: z.string(),
|
|
10
|
+
affected_trace_count: z.number().int().nonnegative(),
|
|
11
|
+
reason: z.string(),
|
|
12
|
+
});
|
|
13
|
+
const CrossRuleLinkShape = z.object({
|
|
14
|
+
rule_ids: z.array(z.string()).min(2),
|
|
15
|
+
relation: z.string(),
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* The `summary` block shape — used both as the embedded field of the full
|
|
19
|
+
* scan-summary report AND as the output schema the Stage-4 cross-trace
|
|
20
|
+
* synthesizer LLM must satisfy.
|
|
21
|
+
*/
|
|
22
|
+
export const ScanSummaryShape = z.object({
|
|
23
|
+
headline: z.string().max(160),
|
|
24
|
+
primary_root_cause: PrimaryRootCauseShape.nullable(),
|
|
25
|
+
fix_priority: z.array(FixPriorityItemShape),
|
|
26
|
+
cross_rule_links: z.array(CrossRuleLinkShape),
|
|
27
|
+
});
|
|
28
|
+
const RuleFrequencyItemShape = z.object({
|
|
29
|
+
rule_id: z.string(),
|
|
30
|
+
count: z.number().int().nonnegative(),
|
|
31
|
+
severity_breakdown: z.object({
|
|
32
|
+
high: z.number().int().nonnegative(),
|
|
33
|
+
medium: z.number().int().nonnegative(),
|
|
34
|
+
low: z.number().int().nonnegative(),
|
|
35
|
+
}),
|
|
36
|
+
});
|
|
37
|
+
const PerTraceIndexItemShape = z.object({
|
|
38
|
+
trace_id: z.string(),
|
|
39
|
+
conversation_id: z.string(),
|
|
40
|
+
report_path: z.string(),
|
|
41
|
+
finding_count: z.number().int().nonnegative(),
|
|
42
|
+
});
|
|
43
|
+
export const ScanSummarySchema = z.object({
|
|
44
|
+
schema_version: z.literal("scan-summary/v1"),
|
|
45
|
+
scan: z.object({
|
|
46
|
+
agent_id: z.string().min(1),
|
|
47
|
+
trace_count: z.number().int().nonnegative(),
|
|
48
|
+
traces_with_findings: z.number().int().nonnegative(),
|
|
49
|
+
traces_reused: z.number().int().nonnegative(),
|
|
50
|
+
traces_freshly_diagnosed: z.number().int().nonnegative(),
|
|
51
|
+
resumed_from_partial: z.boolean(),
|
|
52
|
+
diagnosed_at: z.string(),
|
|
53
|
+
cli_version: z.string(),
|
|
54
|
+
synthesizer_mode: z.literal("agent"),
|
|
55
|
+
}),
|
|
56
|
+
summary: ScanSummaryShape.nullable(),
|
|
57
|
+
aggregates: z.object({
|
|
58
|
+
rule_frequency: z.array(RuleFrequencyItemShape),
|
|
59
|
+
}),
|
|
60
|
+
per_trace_index: z.array(PerTraceIndexItemShape),
|
|
61
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type SingleAgentValidationErrorCode = "empty" | "no-spans" | "mixed";
|
|
2
|
+
export declare class SingleAgentValidationError extends Error {
|
|
3
|
+
readonly code: SingleAgentValidationErrorCode;
|
|
4
|
+
readonly byConvId: ReadonlyMap<string, string | undefined>;
|
|
5
|
+
constructor(code: SingleAgentValidationErrorCode, message: string, byConvId?: ReadonlyMap<string, string | undefined>);
|
|
6
|
+
}
|
|
7
|
+
export interface SingleAgentValidationResult {
|
|
8
|
+
agentId: string;
|
|
9
|
+
checkedConvIds: number;
|
|
10
|
+
}
|
|
11
|
+
export interface FetchSpansResult {
|
|
12
|
+
spans: Array<{
|
|
13
|
+
attributes: Record<string, unknown>;
|
|
14
|
+
}>;
|
|
15
|
+
conversation_id: string;
|
|
16
|
+
}
|
|
17
|
+
export type FetchSpansByConvId = (convId: string) => Promise<FetchSpansResult>;
|
|
18
|
+
/**
|
|
19
|
+
* Verify every conv_id in the batch resolves to spans owned by the same
|
|
20
|
+
* agent_id. Throws SingleAgentValidationError on mismatch with a discrepancy
|
|
21
|
+
* map for the CLI to print.
|
|
22
|
+
*/
|
|
23
|
+
export declare function validateSingleAgent(convIds: string[], fetchSpansById: FetchSpansByConvId): Promise<SingleAgentValidationResult>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export class SingleAgentValidationError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
byConvId;
|
|
4
|
+
constructor(code, message, byConvId = new Map()) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.byConvId = byConvId;
|
|
8
|
+
this.name = "SingleAgentValidationError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function extractAgentId(spans) {
|
|
12
|
+
for (const s of spans) {
|
|
13
|
+
const v = s.attributes["gen_ai.agent.id"];
|
|
14
|
+
if (typeof v === "string" && v.length > 0)
|
|
15
|
+
return v;
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Verify every conv_id in the batch resolves to spans owned by the same
|
|
21
|
+
* agent_id. Throws SingleAgentValidationError on mismatch with a discrepancy
|
|
22
|
+
* map for the CLI to print.
|
|
23
|
+
*/
|
|
24
|
+
export async function validateSingleAgent(convIds, fetchSpansById) {
|
|
25
|
+
if (convIds.length === 0) {
|
|
26
|
+
throw new SingleAgentValidationError("empty", "no conversation_ids supplied");
|
|
27
|
+
}
|
|
28
|
+
const byConvId = new Map();
|
|
29
|
+
for (const convId of convIds) {
|
|
30
|
+
const fetched = await fetchSpansById(convId);
|
|
31
|
+
if (fetched.spans.length === 0) {
|
|
32
|
+
throw new SingleAgentValidationError("no-spans", `conversation_id has no spans: ${convId}`);
|
|
33
|
+
}
|
|
34
|
+
byConvId.set(convId, extractAgentId(fetched.spans));
|
|
35
|
+
}
|
|
36
|
+
const agentIds = new Set(byConvId.values());
|
|
37
|
+
if (agentIds.size > 1 || (agentIds.size === 1 && agentIds.has(undefined))) {
|
|
38
|
+
const lines = [...byConvId.entries()].map(([c, a]) => ` ${c} → ${a ?? "(no agent.id)"}`).join("\n");
|
|
39
|
+
throw new SingleAgentValidationError("mixed", `--traces conversation_ids span multiple agents:\n${lines}`, byConvId);
|
|
40
|
+
}
|
|
41
|
+
return { agentId: [...agentIds][0], checkedConvIds: convIds.length };
|
|
42
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type TracesListErrorCode = "empty" | "file-not-found";
|
|
2
|
+
export declare class TracesListError extends Error {
|
|
3
|
+
readonly code: TracesListErrorCode;
|
|
4
|
+
constructor(code: TracesListErrorCode, message: string);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Parse the `--traces` argument value into an array of conversation_ids.
|
|
8
|
+
* Two forms:
|
|
9
|
+
* - comma-separated: "conv1,conv2,conv3"
|
|
10
|
+
* - @file path: "@/path/to/ids.txt" (one id per line; # comments and blanks ignored)
|
|
11
|
+
*
|
|
12
|
+
* Throws TracesListError with code='empty' for empty result, 'file-not-found'
|
|
13
|
+
* when @file path does not exist.
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseTracesList(arg: string): Promise<string[]>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
export class TracesListError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.name = "TracesListError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Parse the `--traces` argument value into an array of conversation_ids.
|
|
12
|
+
* Two forms:
|
|
13
|
+
* - comma-separated: "conv1,conv2,conv3"
|
|
14
|
+
* - @file path: "@/path/to/ids.txt" (one id per line; # comments and blanks ignored)
|
|
15
|
+
*
|
|
16
|
+
* Throws TracesListError with code='empty' for empty result, 'file-not-found'
|
|
17
|
+
* when @file path does not exist.
|
|
18
|
+
*/
|
|
19
|
+
export async function parseTracesList(arg) {
|
|
20
|
+
if (arg.startsWith("@")) {
|
|
21
|
+
const filePath = arg.slice(1);
|
|
22
|
+
let raw;
|
|
23
|
+
try {
|
|
24
|
+
raw = await fs.readFile(filePath, "utf8");
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
throw new TracesListError("file-not-found", `--traces file not found: ${filePath}`);
|
|
28
|
+
}
|
|
29
|
+
const ids = raw
|
|
30
|
+
.split(/\r?\n/)
|
|
31
|
+
.map((line) => line.trim())
|
|
32
|
+
.filter((line) => line.length > 0 && !line.startsWith("#"));
|
|
33
|
+
if (ids.length === 0) {
|
|
34
|
+
throw new TracesListError("empty", `no conversation_ids found in ${filePath}`);
|
|
35
|
+
}
|
|
36
|
+
return ids;
|
|
37
|
+
}
|
|
38
|
+
const ids = arg
|
|
39
|
+
.split(",")
|
|
40
|
+
.map((s) => s.trim())
|
|
41
|
+
.filter((s) => s.length > 0);
|
|
42
|
+
if (ids.length === 0) {
|
|
43
|
+
throw new TracesListError("empty", "empty --traces value");
|
|
44
|
+
}
|
|
45
|
+
return ids;
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kweaver-ai/kweaver-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "KWeaver TypeScript SDK — CLI tool and programmatic API for knowledge networks and Decision Agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,12 +24,17 @@
|
|
|
24
24
|
],
|
|
25
25
|
"scripts": {
|
|
26
26
|
"dev": "tsx watch src/cli.ts",
|
|
27
|
-
"build": "node node_modules/typescript/bin/tsc -p tsconfig.json && rm -rf dist/templates && cp -R src/templates dist/templates",
|
|
27
|
+
"build": "node node_modules/typescript/bin/tsc -p tsconfig.json && rm -rf dist/templates && cp -R src/templates dist/templates && cp src/trace-ai/diagnose/builtin-rules/*.yaml dist/trace-ai/diagnose/builtin-rules/ && mkdir -p dist/agent-providers/prompts && cp src/agent-providers/prompts/*.prompt.md dist/agent-providers/prompts/ && cp src/trace-ai/diagnose/builtin-rules/*.prompt.md dist/trace-ai/diagnose/builtin-rules/ 2>/dev/null || true && mkdir -p dist/trace-ai/scan/prompts/builtin && cp src/trace-ai/scan/prompts/builtin/*.prompt.md dist/trace-ai/scan/prompts/builtin/ && mkdir -p dist/trace-ai/eval-set/rubric-templates && cp src/trace-ai/eval-set/rubric-templates/*.prompt.md dist/trace-ai/eval-set/rubric-templates/",
|
|
28
28
|
"start": "node ./dist/cli.js",
|
|
29
29
|
"lint": "node node_modules/typescript/bin/tsc --noEmit -p tsconfig.json",
|
|
30
30
|
"test": "node --import tsx --test test/*.test.ts",
|
|
31
31
|
"test:e2e": "node --import tsx --test test/e2e/*.test.ts",
|
|
32
|
-
"prepublishOnly": "npm run build"
|
|
32
|
+
"prepublishOnly": "npm run build",
|
|
33
|
+
"docs": "node scripts/build-docs.mjs",
|
|
34
|
+
"docs:zh": "node scripts/build-docs.mjs --zh",
|
|
35
|
+
"docs:all": "npm run docs && npm run docs:zh",
|
|
36
|
+
"docs:serve": "npm run docs && serve ../../docs/reference/typescript-api-html -p 8766 -n",
|
|
37
|
+
"docs:serve:zh": "npm run docs:zh && serve ../../docs/reference/typescript-api-html-zh -p 8767 -n"
|
|
33
38
|
},
|
|
34
39
|
"keywords": [
|
|
35
40
|
"cli",
|
|
@@ -48,10 +53,13 @@
|
|
|
48
53
|
"node": ">=22"
|
|
49
54
|
},
|
|
50
55
|
"devDependencies": {
|
|
56
|
+
"@types/js-yaml": "^4.0.9",
|
|
51
57
|
"@types/node": "^24.6.0",
|
|
52
58
|
"@types/react": "^19.2.14",
|
|
53
59
|
"@types/yargs": "^17.0.35",
|
|
60
|
+
"serve": "^14.2.5",
|
|
54
61
|
"tsx": "^4.20.5",
|
|
62
|
+
"typedoc": "^0.28.19",
|
|
55
63
|
"typescript": "^5.9.3"
|
|
56
64
|
},
|
|
57
65
|
"dependencies": {
|
|
@@ -63,10 +71,12 @@
|
|
|
63
71
|
"ink": "^6.8.0",
|
|
64
72
|
"ink-spinner": "^5.0.0",
|
|
65
73
|
"ink-text-input": "^6.0.0",
|
|
74
|
+
"js-yaml": "^4.1.1",
|
|
66
75
|
"jszip": "^3.10.1",
|
|
67
76
|
"marked": "^11.2.0",
|
|
68
77
|
"react": "^19.2.4",
|
|
69
78
|
"string-width": "^8.2.0",
|
|
70
|
-
"yargs": "^18.0.0"
|
|
79
|
+
"yargs": "^18.0.0",
|
|
80
|
+
"zod": "^4.4.3"
|
|
71
81
|
}
|
|
72
82
|
}
|