@tangle-network/traces 0.23.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -1078
- package/dist/analyst-model-call-JVUOYZ5V.js +20 -0
- package/dist/ask-XLS3VANY.js +39 -0
- package/dist/check-YF6ZHPGG.js +322 -0
- package/dist/chunk-3I4PJ5Q7.js +25 -0
- package/dist/chunk-3T62R7ON.js +5695 -0
- package/dist/chunk-4VKPN432.js +138 -0
- package/dist/chunk-6CLC7DKP.js +492 -0
- package/dist/chunk-7CBV5RJ2.js +535 -0
- package/dist/chunk-B62DOFGI.js +273 -0
- package/dist/chunk-CL3OQOWX.js +407 -0
- package/dist/chunk-DLGAKCQJ.js +782 -0
- package/dist/chunk-DU534HAX.js +263 -0
- package/dist/chunk-GLUDGUGJ.js +232 -0
- package/dist/chunk-J2PM5SVN.js +503 -0
- package/dist/chunk-M3W6TZHQ.js +381 -0
- package/dist/chunk-NH7HCDLB.js +759 -0
- package/dist/chunk-NZ5Y7UEL.js +1217 -0
- package/dist/chunk-O52XK7OB.js +19 -0
- package/dist/chunk-PYH3PL3N.js +62 -0
- package/dist/chunk-RZL5GAWH.js +60 -0
- package/dist/chunk-TR6O4S4T.js +208 -0
- package/dist/chunk-TW43MR5D.js +259 -0
- package/dist/chunk-TYLFUX42.js +228 -0
- package/dist/chunk-UOLRCQHC.js +120 -0
- package/dist/chunk-UVE5ANVV.js +3921 -0
- package/dist/chunk-V2OCGX57.js +53 -0
- package/dist/cli.js +2086 -2050
- package/dist/diff-ZZ6KYBPP.js +16 -0
- package/dist/improvement-OJQ6365E.js +25 -0
- package/dist/index.d.ts +1235 -4357
- package/dist/index.js +53 -1204
- package/dist/live-Y64AJ6MA.js +14 -0
- package/dist/mcp-ZPGTJQYQ.js +85 -0
- package/dist/report-JAMXRTCW.js +338 -0
- package/dist/run-watch-PLWTIRSV.js +649 -0
- package/dist/supervisor-report-RMPLLBGZ.js +29 -0
- package/dist/supervisor-run-context-WO6VOTGV.js +30 -0
- package/dist/upload-R6NMKSGQ.js +20 -0
- package/dist/verify-safe-C5ZXZOZ2.js +8 -0
- package/docs/analyze.md +76 -0
- package/docs/ask.md +88 -0
- package/docs/bundle.md +40 -0
- package/docs/check.md +77 -0
- package/docs/convert.md +44 -0
- package/docs/develop.md +32 -0
- package/docs/diff.md +38 -0
- package/docs/facts.md +114 -0
- package/docs/mcp.md +36 -0
- package/docs/migrate-1.0.md +33 -0
- package/docs/parsers.md +66 -0
- package/docs/release-1.0.0.md +147 -0
- package/docs/sdk.md +77 -0
- package/docs/select.md +70 -0
- package/docs/skills.md +46 -0
- package/docs/upload.md +47 -0
- package/docs/watch-jsonl.v1.example.jsonl +5 -0
- package/docs/watch.md +66 -0
- package/examples/README.md +9 -0
- package/examples/custom-analyst.ts +65 -74
- package/install.sh +22 -2
- package/package.json +8 -7
- package/skills/inspect-agent-traces/SKILL.md +47 -110
- package/dist/chunk-COSWFESO.js +0 -20979
- package/docs/replay-verify.md +0 -123
- package/docs/stream-findings.svg +0 -39
- package/docs/trace-analysts.md +0 -643
- package/examples/custom-backend.ts +0 -21
- package/examples/external-engines.ts +0 -62
- package/examples/improvement-config.mjs +0 -63
- package/examples/observe-and-alert.ts +0 -19
- package/examples/register-harness.ts +0 -26
- package/skills/build-trace-analyst/SKILL.md +0 -76
- package/skills/build-trace-analyst/agents/openai.yaml +0 -4
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Run trace analyzers and PII scrubbers that traces does NOT bundle. You install
|
|
3
|
-
* the tool, traces drives it. Same pattern for any future engine/model.
|
|
4
|
-
*
|
|
5
|
-
* pnpm tsx examples/external-engines.ts
|
|
6
|
-
*/
|
|
7
|
-
import {
|
|
8
|
-
applyRedactor,
|
|
9
|
-
collectSessions,
|
|
10
|
-
commandRedactor,
|
|
11
|
-
haloAnalyzer,
|
|
12
|
-
hodoscopeAnalyzer,
|
|
13
|
-
primeAnalyzer,
|
|
14
|
-
writeOtlpFile,
|
|
15
|
-
} from '@tangle-network/traces'
|
|
16
|
-
|
|
17
|
-
const [batch] = await collectSessions({ harnesses: ['claude-code'], last: 1 })
|
|
18
|
-
if (!batch) {
|
|
19
|
-
console.log('no claude-code sessions found')
|
|
20
|
-
process.exit(0)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// 1) External ANALYZER: emit the OTLP artifact, then run HALO over it as a peer
|
|
24
|
-
// to the built-in analysts. (Install HALO: github.com/context-labs/halo)
|
|
25
|
-
const otlp = await writeOtlpFile(batch.spans, '/tmp/session.otlp.jsonl')
|
|
26
|
-
const halo = haloAnalyzer({
|
|
27
|
-
defaultPrompt: 'diagnose stuck loops and wasted tokens',
|
|
28
|
-
maxDepth: 0,
|
|
29
|
-
maxTurns: 3,
|
|
30
|
-
maxParallel: 1,
|
|
31
|
-
reasoningEffort: 'low',
|
|
32
|
-
})
|
|
33
|
-
const analysis = await halo.analyze(otlp)
|
|
34
|
-
console.log(analysis.ok ? analysis.output : `halo unavailable: ${analysis.error}`)
|
|
35
|
-
|
|
36
|
-
// 2) DISCOVERY ENGINE: sample distinct behavior for human review.
|
|
37
|
-
// Hodoscope requires Python 3.11, uv, and model credentials.
|
|
38
|
-
const discovery = await hodoscopeAnalyzer().analyze(otlp)
|
|
39
|
-
console.log(
|
|
40
|
-
discovery.ok
|
|
41
|
-
? `${discovery.candidates?.length ?? 0} behavior candidates need review`
|
|
42
|
-
: `hodoscope unavailable: ${discovery.error}`,
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
// 3) PRIME ENGINE: one-shot RLM through an OpenAI-compatible bridge (run
|
|
46
|
-
// cli-bridge's prime backend locally, or set TRACES_PRIME_BRIDGE_URL).
|
|
47
|
-
// The full span projection travels inline; findings come back with
|
|
48
|
-
// validated trace:// span evidence.
|
|
49
|
-
const prime = primeAnalyzer({ defaultPrompt: 'find unsupported completion claims' })
|
|
50
|
-
const primeResult = await prime.analyze(otlp)
|
|
51
|
-
console.log(
|
|
52
|
-
primeResult.ok
|
|
53
|
-
? `${primeResult.findings?.length ?? 0} prime finding(s)\n${primeResult.output}`
|
|
54
|
-
: `prime bridge unavailable: ${primeResult.error}`,
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
// 4) External REDACTOR: scrub prose with your own PII model before upload. The
|
|
58
|
-
// command reads a JSON array of strings on stdin and writes the scrubbed array
|
|
59
|
-
// on stdout (a 3-line wrapper adapts openai/privacy-filter's `opf`).
|
|
60
|
-
const redactor = commandRedactor({ command: 'my-pii-scrubber' })
|
|
61
|
-
const { spans, changed } = await applyRedactor(batch.spans, redactor)
|
|
62
|
-
console.log(`scrubbed ${changed} content field(s) across ${spans.length} spans`)
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BYO analyst config for:
|
|
3
|
-
*
|
|
4
|
-
* traces improve --last 5 --config examples/improvement-config.mjs --dir .traces/improvement
|
|
5
|
-
* traces stream --mode agent --config examples/improvement-config.mjs
|
|
6
|
-
*/
|
|
7
|
-
import { buildDefaultAnalystRegistry, makeFinding } from '@tangle-network/traces'
|
|
8
|
-
|
|
9
|
-
const registry = buildDefaultAnalystRegistry()
|
|
10
|
-
|
|
11
|
-
registry.register({
|
|
12
|
-
id: 'example-error-summary',
|
|
13
|
-
description: 'Reports the most frequent error signature in the selected traces.',
|
|
14
|
-
inputKind: 'trace-store',
|
|
15
|
-
cost: { kind: 'deterministic' },
|
|
16
|
-
version: '1.0.0',
|
|
17
|
-
async analyze(store) {
|
|
18
|
-
const overview = await store.getOverview({ has_errors: true })
|
|
19
|
-
const cluster = overview.error_clusters[0]
|
|
20
|
-
if (!cluster) return []
|
|
21
|
-
return [makeFinding({
|
|
22
|
-
analyst_id: 'example-error-summary',
|
|
23
|
-
area: 'tool-use',
|
|
24
|
-
subject: cluster.signature,
|
|
25
|
-
claim: `${cluster.span_count} failed span(s) share the error: ${cluster.status_message_sample}`,
|
|
26
|
-
severity: cluster.span_count >= 3 ? 'high' : 'medium',
|
|
27
|
-
evidence_refs: [{
|
|
28
|
-
kind: 'span',
|
|
29
|
-
uri: `trace://${encodeURIComponent(cluster.exemplar_trace_ids[0])}/span/${encodeURIComponent(cluster.exemplar_span_ids[0])}`,
|
|
30
|
-
excerpt: cluster.status_message_sample,
|
|
31
|
-
}],
|
|
32
|
-
recommended_action: `Fix or change the retry policy for ${cluster.tool_name ?? cluster.span_name ?? 'the failing operation'}.`,
|
|
33
|
-
validation_plan: 'Rerun the same task and confirm this error signature is absent.',
|
|
34
|
-
confidence: 1,
|
|
35
|
-
id_basis: cluster.signature,
|
|
36
|
-
})]
|
|
37
|
-
},
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
export default {
|
|
41
|
-
registry,
|
|
42
|
-
liveAnalysts: [{
|
|
43
|
-
id: 'example-live-claim-check',
|
|
44
|
-
analyze(context) {
|
|
45
|
-
if (!context.actions.some((action) => action.kind === 'claim')) return []
|
|
46
|
-
return [{
|
|
47
|
-
schemaVersion: 1,
|
|
48
|
-
kind: 'traces.live_finding',
|
|
49
|
-
id: `live.example-live-claim-check.${context.session.sessionId}`,
|
|
50
|
-
ruleId: 'example-live-claim-check',
|
|
51
|
-
fingerprint: `example-live-claim-check.${context.session.sessionId}`,
|
|
52
|
-
severity: 'info',
|
|
53
|
-
title: 'Custom live analyst saw a completion claim',
|
|
54
|
-
claim: 'The trace contains a claim-like assistant message.',
|
|
55
|
-
action: 'Keep this custom rule narrow; require evidence before alerting.',
|
|
56
|
-
check: 'Confirm the next stream event includes any required verification signal.',
|
|
57
|
-
evidence: [{ kind: 'metric', label: 'actions', value: String(context.actions.length) }],
|
|
58
|
-
session: context.session,
|
|
59
|
-
observedAt: context.generatedAt,
|
|
60
|
-
}]
|
|
61
|
-
},
|
|
62
|
-
}],
|
|
63
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Live observer → alert. Tails active sessions across all harnesses and fires
|
|
3
|
-
* when an agent gets stuck in a loop. Read-only; Ctrl-C to stop.
|
|
4
|
-
*
|
|
5
|
-
* tsx examples/observe-and-alert.ts
|
|
6
|
-
*/
|
|
7
|
-
import { watchSessions } from '@tangle-network/traces'
|
|
8
|
-
|
|
9
|
-
const controller = new AbortController()
|
|
10
|
-
process.on('SIGINT', () => controller.abort())
|
|
11
|
-
|
|
12
|
-
await watchSessions({
|
|
13
|
-
all: true,
|
|
14
|
-
signal: controller.signal,
|
|
15
|
-
onLoop: (loop) => {
|
|
16
|
-
// Swap console.log for Slack / PagerDuty / your alerter.
|
|
17
|
-
console.log(`[${loop.harness}] ${loop.sessionId.slice(0, 8)} stuck: ${loop.toolName} ×${loop.occurrences}`)
|
|
18
|
-
},
|
|
19
|
-
})
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Add support for a new harness: implement HarnessTraceAdapter (locate + parse),
|
|
3
|
-
* then use it via the `adapters` option. No registry edit and no fork.
|
|
4
|
-
*
|
|
5
|
-
* tsx examples/register-harness.ts
|
|
6
|
-
*/
|
|
7
|
-
import { collectSessions, type HarnessTraceAdapter, span } from '@tangle-network/traces'
|
|
8
|
-
|
|
9
|
-
const myAdapter: HarnessTraceAdapter = {
|
|
10
|
-
harness: 'my-agent',
|
|
11
|
-
async locate() {
|
|
12
|
-
// Discover this harness's session files on disk and return refs.
|
|
13
|
-
return [{ harness: 'my-agent', sessionId: 'demo', path: '/tmp/demo', cwd: null, mtimeMs: Date.now() }]
|
|
14
|
-
},
|
|
15
|
-
async parse(ref) {
|
|
16
|
-
// Project the harness's native log onto normalized OTLP spans.
|
|
17
|
-
const now = new Date().toISOString()
|
|
18
|
-
return [
|
|
19
|
-
span({ traceId: ref.sessionId, spanId: 'root', name: 'session', kind: 'AGENT', startTime: now }),
|
|
20
|
-
span({ traceId: ref.sessionId, spanId: 's1', parentSpanId: 'root', name: 'tool.bash', kind: 'TOOL', startTime: now, tool: 'bash', content: 'ls' }),
|
|
21
|
-
]
|
|
22
|
-
},
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const [batch] = await collectSessions({ adapters: [myAdapter] })
|
|
26
|
-
console.log(`${batch?.spans.length ?? 0} spans from ${batch?.ref.harness}`)
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: build-trace-analyst
|
|
3
|
-
description: Write and calibrate a custom agent-eval trace analyst on real and labeled workflows.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Build a trace analyst
|
|
7
|
-
|
|
8
|
-
Implement one measurable finding that existing analysts do not provide.
|
|
9
|
-
|
|
10
|
-
## Check coverage
|
|
11
|
-
|
|
12
|
-
1. Run maintained analysis on one positive and one clean case.
|
|
13
|
-
2. Call `buildDefaultAnalystRegistry().list()` for batch analysts.
|
|
14
|
-
Check live analysts separately only for `traces stream`.
|
|
15
|
-
3. Search source or public docs once for the target behavior, then decide.
|
|
16
|
-
|
|
17
|
-
Extend an existing analyst when it already emits the target with usable evidence.
|
|
18
|
-
Do not inspect bundled `dist` or `node_modules`.
|
|
19
|
-
|
|
20
|
-
Answer a one-off question with `traces ask --question "<text>"` instead.
|
|
21
|
-
Build an analyst when the question repeats and its answer must be scored, not read.
|
|
22
|
-
|
|
23
|
-
## Implement
|
|
24
|
-
|
|
25
|
-
- Use `Analyst`, `AnalystRegistry`, `TraceAnalysisStore`, and `makeFinding` from `@tangle-network/traces`.
|
|
26
|
-
- Start with `getOverview`; narrow with `queryTraces`, `viewSpans`, or `searchTrace`.
|
|
27
|
-
- Pass `context.signal` through reads and model calls.
|
|
28
|
-
- Return stable `analyst_id`, `area`, `subject`, and `id_basis` values.
|
|
29
|
-
- Cite exact spans as `trace://<trace-id>/span/<span-id>`.
|
|
30
|
-
- Return no finding when evidence is absent.
|
|
31
|
-
- Use `cost.kind: 'deterministic'` only without model calls.
|
|
32
|
-
- For `cost.kind: 'llm'`, use the injected chat client, budget, cancellation, and usage recording.
|
|
33
|
-
- Extend `buildDefaultAnalystRegistry()` unless full replacement is intentional.
|
|
34
|
-
|
|
35
|
-
Use the [custom analyst](../../examples/custom-analyst.ts) and [config](../../examples/improvement-config.mjs) examples rather than adding a wrapper.
|
|
36
|
-
|
|
37
|
-
## Run
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
pnpm tsx examples/custom-analyst.ts --fixture
|
|
41
|
-
pnpm tsx examples/custom-analyst.ts --good-fixture
|
|
42
|
-
traces improve --harness codex --current --latest-turn --workflow \
|
|
43
|
-
--config traces.config.mjs --dir .traces/custom-analyst
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
Inspect every finding and cited span.
|
|
47
|
-
|
|
48
|
-
## Calibrate
|
|
49
|
-
|
|
50
|
-
Use `runAnalystBenchmark` with `registryBenchmarkRunner` from `@tangle-network/agent-eval/analyst`.
|
|
51
|
-
Use AgentRx or CodeTraceBench labels when they match the finding.
|
|
52
|
-
Compare the candidate with a no-findings baseline and relevant maintained or external analysts on identical cases and limits.
|
|
53
|
-
|
|
54
|
-
Two shipped engines are available as comparison arms.
|
|
55
|
-
`--analyzer prime` inlines the whole span projection into one prompt and needs no REPL.
|
|
56
|
-
`--analyzer halo` and `--analyzer hodoscope` drill into the trace with paged tools.
|
|
57
|
-
Compare an inline arm with a paged arm to separate the prompt from the navigation.
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
traces analyze --last 1 --analyzer prime
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Assert the served model, not the requested id.
|
|
64
|
-
A gateway can answer one id with another model, so a panel can report families it never ran.
|
|
65
|
-
Use `assertServedModel` and `assertCrossFamilyServed` from `@tangle-network/agent-eval` before you trust a per-model or cross-family number.
|
|
66
|
-
|
|
67
|
-
Use at least 20 independent cases before comparative statistics.
|
|
68
|
-
Retain every case row and report exact-step recall, precision, F1, root-step accuracy when labeled, citation coverage and validity, clean-case false positives, repeat agreement, failures, latency, calls, all token fields, and known or missing cost.
|
|
69
|
-
|
|
70
|
-
Do not claim quality from fixtures alone.
|
|
71
|
-
Require a fresh task comparison before using findings to change an agent or knowledge base.
|
|
72
|
-
|
|
73
|
-
## Then consider
|
|
74
|
-
|
|
75
|
-
- Use `inspect-agent-traces` to investigate a miss or false positive on its original workflow.
|
|
76
|
-
- Use `calibrate-before-measure` before trusting a new label set or scoring rule.
|