knitbrain 0.1.2 → 0.2.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 +66 -23
- package/dist/engine/agents.d.ts +4 -0
- package/dist/engine/agents.js +3 -2
- package/dist/engine/agents.js.map +1 -1
- package/dist/engine/feedback.js +1 -1
- package/dist/engine/feedback.js.map +1 -1
- package/dist/evals.d.ts +53 -0
- package/dist/evals.js +189 -0
- package/dist/evals.js.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -1
- package/dist/learn.d.ts +39 -0
- package/dist/learn.js +289 -0
- package/dist/learn.js.map +1 -0
- package/dist/lib.d.ts +37 -0
- package/dist/lib.js +17 -0
- package/dist/lib.js.map +1 -0
- package/dist/mcp/instructions.d.ts +7 -0
- package/dist/mcp/instructions.js +29 -0
- package/dist/mcp/instructions.js.map +1 -0
- package/dist/mcp/tools.js +47 -12
- package/dist/mcp/tools.js.map +1 -1
- package/dist/optimizer/ast.d.ts +11 -0
- package/dist/optimizer/ast.js +99 -29
- package/dist/optimizer/ast.js.map +1 -1
- package/dist/optimizer/code.js +1 -1
- package/dist/optimizer/code.js.map +1 -1
- package/dist/optimizer/router.d.ts +3 -1
- package/dist/optimizer/router.js +32 -7
- package/dist/optimizer/router.js.map +1 -1
- package/dist/optimizer/structured.d.ts +43 -0
- package/dist/optimizer/structured.js +196 -0
- package/dist/optimizer/structured.js.map +1 -0
- package/dist/optimizer/text.js +38 -7
- package/dist/optimizer/text.js.map +1 -1
- package/dist/optimizer/types.d.ts +4 -2
- package/dist/platforms.d.ts +11 -1
- package/dist/platforms.js +34 -1
- package/dist/platforms.js.map +1 -1
- package/dist/proxy/cache-aligner.d.ts +25 -4
- package/dist/proxy/cache-aligner.js +45 -4
- package/dist/proxy/cache-aligner.js.map +1 -1
- package/dist/proxy/optimize-request.d.ts +10 -0
- package/dist/proxy/optimize-request.js +96 -6
- package/dist/proxy/optimize-request.js.map +1 -1
- package/dist/proxy/server.js +2 -2
- package/dist/proxy/server.js.map +1 -1
- package/dist/server.js +5 -1
- package/dist/server.js.map +1 -1
- package/dist/setup.d.ts +1 -1
- package/dist/setup.js +30 -1
- package/dist/setup.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +11 -2
package/README.md
CHANGED
|
@@ -5,41 +5,58 @@
|
|
|
5
5
|
[](LICENSE)
|
|
6
6
|
[](package.json)
|
|
7
7
|
|
|
8
|
-
> The local-first brain for coding agents: per-project memory, task-tier workflow routing, and lossless context compression — measured
|
|
8
|
+
> The local-first brain for coding agents: per-project memory, task-tier workflow routing, and lossless context compression — measured 48.7% of all tool-result tokens on real sessions, with answer-preservation gates, reproducible with one command.
|
|
9
9
|
|
|
10
10
|
Pure TypeScript. No Python, no native binaries, no network beyond `npm install`.
|
|
11
11
|
|
|
12
12
|
```bash
|
|
13
13
|
npx knitbrain profile # measure what it would save on YOUR real sessions — before installing anything
|
|
14
|
+
npx knitbrain evals # prove the answers survive — same corpus, deterministic judging
|
|
14
15
|
```
|
|
15
16
|
|
|
16
17
|
## The honest number
|
|
17
18
|
|
|
18
19
|
Most tools in this space quote their best workload ("up to 90%!"). We publish the number nobody else does: the **all-inclusive average** — every tool-result token from real coding sessions, *including* the small outputs that pass through uncompressed.
|
|
19
20
|
|
|
20
|
-
**On 3.
|
|
21
|
+
**On 3.33M tokens of tool results from 63 real Claude Code sessions: 48.7% saved overall, lossless.** That denominator includes every tool-result token — even the 0.4M tokens of small outputs that pass through untouched (counting only sizable blocks ≥400 chars, the number is 55.4%). Every original recoverable byte-for-byte.
|
|
21
22
|
|
|
22
23
|
| shape | % of real burn | saved |
|
|
23
24
|
|---|---|---|
|
|
24
|
-
| code & file reads | 47% |
|
|
25
|
-
| repetitive logs |
|
|
26
|
-
| short prose (reports, summaries) |
|
|
27
|
-
| long prose |
|
|
28
|
-
| test output | 6% |
|
|
29
|
-
| JSON | 5% | 65.
|
|
25
|
+
| code & file reads | 47% | 60.3% |
|
|
26
|
+
| repetitive logs | 17% | 70.5% |
|
|
27
|
+
| short prose (reports, summaries) | 16% | 18.0% |
|
|
28
|
+
| long prose | 7% | 69.2% |
|
|
29
|
+
| test output | 6% | 47.4% |
|
|
30
|
+
| JSON | 5% | 65.1% |
|
|
31
|
+
| diffs | 1% | 62.7% |
|
|
30
32
|
|
|
31
33
|
Measured the way others measure — single best-case workloads — we land 60–99% (import graphs 98.9%, whole files 88.8%, body-heavy code 71.6%). But that's not the number you'll feel; the all-inclusive average is.
|
|
32
34
|
|
|
33
35
|
**Don't take our word for any of this.** `knitbrain profile` runs the actual optimizer over your own transcripts (`~/.claude/projects` by default) and prints *your* number. Local only — nothing is uploaded.
|
|
34
36
|
|
|
37
|
+
## Same answers, measured
|
|
38
|
+
|
|
39
|
+
Saving tokens is worthless if the agent loses the answer. `knitbrain evals` checks — on the same real corpus, with deterministic string-containment judging (no LLM judge to flatter us) — that the facts agents act on survive compression:
|
|
40
|
+
|
|
41
|
+
| check | result | gate |
|
|
42
|
+
|---|---|---|
|
|
43
|
+
| error-fidelity — every error/failure line survives in the skeleton | **141/141 = 100%** | 100% |
|
|
44
|
+
| summary-fidelity — test/build result totals survive | **189/189 = 100%** | ≥95% |
|
|
45
|
+
| identifier-fidelity — top-level declared names survive | **314/316 = 99.4%** | ≥99% |
|
|
46
|
+
| round-trip — `⟨ccr:hash⟩` recovers the original byte-for-byte | **2,339/2,339 = 100%** | 100% |
|
|
47
|
+
| never-expand — no compressed block got bigger | **4,505/4,505 = 100%** | 100% |
|
|
48
|
+
|
|
49
|
+
These gates shaped the product: error lines, result summaries, and declarations are *never* elided, by every handler. Holding that line costs about 1 percentage point of savings — we pay it, and publish both numbers. Run `npx knitbrain evals` (exit code 1 on any gate failure) to check on your own transcripts.
|
|
50
|
+
|
|
35
51
|
## Why this and not a point tool
|
|
36
52
|
|
|
37
53
|
Compression-only layers shrink tokens but remember nothing. Memory-only layers remember but burn your window. Knit Brain is one substrate doing both, plus the workflow layer that makes agents use them:
|
|
38
54
|
|
|
39
|
-
- **Memory** — per-project learnings, session handoffs, a knowledge graph (imports/exports/blast-radius), on-demand skills that compound across tasks.
|
|
40
|
-
- **Lossless optimization** — structure-preserving skeletons (JSON keeps its schema
|
|
41
|
-
- **Workflow intelligence** — a deterministic tier classifier (inquiry/trivial/standard/complex) routing how much process a task deserves
|
|
55
|
+
- **Memory** — per-project learnings, session handoffs, a knowledge graph (imports/exports/blast-radius), on-demand skills that compound across tasks, and `knitbrain learn` — offline failure mining that writes corrections from your real sessions into CLAUDE.md.
|
|
56
|
+
- **Lossless optimization** — structure-preserving skeletons (JSON keeps its schema; code keeps its signatures via tree-sitter AST across TypeScript/TSX/JS, Python, Go, Rust, Java, C++, C#, Ruby, PHP, Bash), dedicated handlers for search results, build/test logs, and diffs (error lines always survive), cross-turn dedup of re-sent bulk, sentence anchoring for prose — all reversible through a content-addressed store.
|
|
57
|
+
- **Workflow intelligence** — a deterministic tier classifier (inquiry/trivial/standard/complex) routing how much process a task deserves; complex verdicts carry an explicit ENTER-PLAN-MODE directive the agent follows before touching files; guardrailed agent generation and a shared team board.
|
|
42
58
|
- **Self-healing, not self-confident** — two feedback loops run continuously: TOIN backs off any compression kind that gets over-retrieved, and the classifier shifts its own thresholds after 3 wrong-verdict votes (`knitbrain_record_false_positive`). Wrong tuning costs efficiency, never correctness.
|
|
59
|
+
- **Closed loop, zero config** — the full operating protocol (load session → classify → plan-mode adherence → skills → agents → context discipline → record learning) rides the MCP handshake itself. Any MCP client gets it without a single file of setup; `knitbrain prompt` prints it for platforms that want it in a system prompt.
|
|
43
60
|
|
|
44
61
|
## Architecture
|
|
45
62
|
|
|
@@ -62,10 +79,16 @@ Compression-only layers shrink tokens but remember nothing. Memory-only layers r
|
|
|
62
79
|
▼ /v1/chat/completions)
|
|
63
80
|
┌──────────────────────────────────────────────┐
|
|
64
81
|
│ optimizer router │
|
|
65
|
-
│ json
|
|
66
|
-
│ code
|
|
67
|
-
│
|
|
68
|
-
│
|
|
82
|
+
│ json → schema-preserving skeleton │
|
|
83
|
+
│ code → tree-sitter AST body elision │
|
|
84
|
+
│ (TS/JS · Py · Go · Rust · Java · │
|
|
85
|
+
│ C++ · C# · Ruby · PHP · Bash) │
|
|
86
|
+
│ search → per-file collapse + counts │
|
|
87
|
+
│ logs → errors+summaries kept, runs │
|
|
88
|
+
│ collapsed (races template dedup) │
|
|
89
|
+
│ diffs → headers kept, hunks → ±counts │
|
|
90
|
+
│ prose → sentence anchor (TOIN-gated) │
|
|
91
|
+
│ errors / result lines NEVER elided │
|
|
69
92
|
└────────────────────┬─────────────────────────┘
|
|
70
93
|
▼ skeleton + ⟨ccr:hash⟩
|
|
71
94
|
┌──────────────────────────────────────────────┐ ┌─────────────────┐
|
|
@@ -91,12 +114,16 @@ npm install -g knitbrain
|
|
|
91
114
|
|
|
92
115
|
knitbrain profile # your savings, on your transcripts, before you commit to anything
|
|
93
116
|
|
|
94
|
-
# in your project
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
#
|
|
117
|
+
# in your project — ONE command configures everything (memory, workflow,
|
|
118
|
+
# plan-mode adherence, skills, teams, meter, hooks; non-clobbering):
|
|
119
|
+
knitbrain setup # native integration per platform: Claude Code, Cursor,
|
|
120
|
+
# VS Code + Copilot, Windsurf (+ snippets for Codex,
|
|
121
|
+
# Copilot CLI, Zed — their MCP configs are global)
|
|
98
122
|
|
|
99
123
|
knitbrain dashboard # live local dashboard (127.0.0.1:8790)
|
|
124
|
+
knitbrain learn # mine past sessions for failure→success corrections (--apply writes CLAUDE.md)
|
|
125
|
+
knitbrain evals # answer-preservation gates on your own transcripts
|
|
126
|
+
knitbrain prompt # full operating prompt, for platforms without MCP-instructions support
|
|
100
127
|
|
|
101
128
|
# optional — route LLM requests through the optimizer (API-key setups):
|
|
102
129
|
knitbrain-proxy # listens on 127.0.0.1:8788
|
|
@@ -107,12 +134,27 @@ knitbrain hub # start the team hub (host runs this
|
|
|
107
134
|
knitbrain join <hub-url> <token> <name> # everyone else; postings mirror automatically
|
|
108
135
|
```
|
|
109
136
|
|
|
137
|
+
## Use as a library
|
|
138
|
+
|
|
139
|
+
The same router that powers the proxy and MCP server is importable directly — no server, no config:
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import { createOptimizer } from "knitbrain";
|
|
143
|
+
|
|
144
|
+
const kb = createOptimizer(); // CCR store under ~/.knitbrain/ccr
|
|
145
|
+
const r = kb.compress(bigToolOutput); // detect → route → compress
|
|
146
|
+
console.log(r.savedPct, r.contentType); // e.g. 62.4 "json"
|
|
147
|
+
// r.skeleton → hand to the model; kb.retrieve(r.handle) → exact original, byte-for-byte
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`compress()` is lossless (original always recoverable via the CCR handle) and guarded — if compression doesn't save at least 5%, the original passes through untouched.
|
|
151
|
+
|
|
110
152
|
## If you pay per token
|
|
111
153
|
|
|
112
154
|
Agent loops re-send the entire conversation on every turn, so input tokens dominate the bill — usually by an order of magnitude over output. That makes context the thing worth optimizing:
|
|
113
155
|
|
|
114
|
-
- **The proxy shrinks the request itself, on the wire.** ~
|
|
115
|
-
- **It stacks with provider prompt caching.** CacheAligner keeps the system prefix byte-stable across turns,
|
|
156
|
+
- **The proxy shrinks the request itself, on the wire.** ~49% fewer tool-result tokens means a proportionally smaller input bill on the bulk of every request, every turn, compounding over a session.
|
|
157
|
+
- **It stacks with provider prompt caching.** CacheAligner keeps the system prefix byte-stable across turns: whitespace normalization, volatile lines ("Today's date is …") moved out of the prefix to a marked tail, and — when your client doesn't manage its own — Anthropic `cache_control` breakpoints inserted at the system prompt and the stable history boundary. Cached input reads are ~90% cheaper on Anthropic; OpenAI prefix caching needs exactly the byte-stability this provides. Compression is deterministic, so optimized history prefixes stay stable turn over turn — the two levers stack.
|
|
116
158
|
- **It can never make a request more expensive.** The never-expand guard is enforced by tests: output tokens ≤ input tokens, always.
|
|
117
159
|
- **On a subscription instead?** Same mechanics, different currency: fewer tokens per turn means the context window fills slower — fewer compactions, fewer lost-context restarts, longer useful sessions.
|
|
118
160
|
|
|
@@ -122,9 +164,10 @@ Run `knitbrain profile` to see the percentage on your own workload before believ
|
|
|
122
164
|
|
|
123
165
|
- **Lossless** — every compressed payload recovers byte-for-byte from CCR; the round-trip test gates the build.
|
|
124
166
|
- **Never-expand** — output tokens ≤ input tokens, always.
|
|
167
|
+
- **Errors survive** — error/failure lines, result summaries, and top-level declarations are never elided; `knitbrain evals` gates this at 100%/≥95%/≥99% on real transcripts.
|
|
125
168
|
- **Governance verbatim** — your instructions and protocol/classification text are never skeletonized.
|
|
126
169
|
- **Local-first** — proxy, hub, and dashboard bind `127.0.0.1` by default; nothing leaves your machine.
|
|
127
|
-
- **Reproducible claims** —
|
|
170
|
+
- **Reproducible claims** — the headline numbers come from `knitbrain profile` and `knitbrain evals` on real transcripts, both of which you can run on yours. (`npm run bench` is a CI regression gate: a real-shape suite whose fixture mix mirrors the profiled distribution, with per-shape savings floors and fidelity checks, plus a clearly-labeled best-case suite — fixture numbers are never quoted as real-world savings.)
|
|
128
171
|
|
|
129
172
|
## Development
|
|
130
173
|
|
|
@@ -135,7 +178,7 @@ npm run e2e # built-artifact E2E: stdio session + real-file compression
|
|
|
135
178
|
npm run audit:prod # cold-start proof: clone → install → pack → installed binaries → all 25 tools
|
|
136
179
|
```
|
|
137
180
|
|
|
138
|
-
Current proof status: **
|
|
181
|
+
Current proof status: **195 tests passing**, eval gates PASS on 4,505 real blocks, and the production audit (`audit:prod`) passes — fresh clone, clean install, packed tarball installed into a new project, all 25 tools and both binaries verified working. One opt-in test (live LLM endpoint) requires your own API key: `KNITBRAIN_LIVE_TEST=1 ANTHROPIC_API_KEY=… npm test`.
|
|
139
182
|
|
|
140
183
|
## License
|
|
141
184
|
|
package/dist/engine/agents.d.ts
CHANGED
|
@@ -19,6 +19,10 @@ export interface AgentSpec {
|
|
|
19
19
|
tools?: string[];
|
|
20
20
|
reviewGate?: boolean;
|
|
21
21
|
contextBudget?: number;
|
|
22
|
+
/** Mission brief for THIS task — telegraphic skill body, not a context dump
|
|
23
|
+
* (sub-agents start cold; the brief is their whole task-specific context,
|
|
24
|
+
* so it's optimized prompt-by-prompt like everything else). */
|
|
25
|
+
brief?: string;
|
|
22
26
|
}
|
|
23
27
|
/**
|
|
24
28
|
* Auto-detect candidate domain agents from the knowledge graph: group source
|
package/dist/engine/agents.js
CHANGED
|
@@ -63,10 +63,11 @@ You are the **${spec.name}** agent for this project.
|
|
|
63
63
|
- **Allowed tools:** ${tools}.
|
|
64
64
|
${gate}- **Context budget:** keep your working context under ~${budget} tokens. For large payloads, call \`knitbrain_optimize\` and page originals back with \`knitbrain_retrieve\` only when needed.
|
|
65
65
|
|
|
66
|
-
## How to work
|
|
66
|
+
${spec.brief ? `## Mission brief (telegraphic — full context one retrieve away)\n${spec.brief}\n\n` : ""}## How to work
|
|
67
67
|
1. Ground yourself: \`knitbrain_query_imports\` / \`knitbrain_query_dependents\` before editing.
|
|
68
68
|
2. Make the smallest correct change within scope.
|
|
69
|
-
3.
|
|
69
|
+
3. Post findings to \`knitbrain_team_post\` so the orchestrator and sibling agents see them.
|
|
70
|
+
4. Record non-obvious findings with \`knitbrain_record_learning\`.
|
|
70
71
|
`;
|
|
71
72
|
}
|
|
72
73
|
/** Write a generated agent to the project's .claude/agents directory. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../../src/engine/agents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,wEAAwE;AACxE,MAAM,SAAS,GAAG,iFAAiF,CAAC;
|
|
1
|
+
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../../src/engine/agents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE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Q,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC/F,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IACnD,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,KAAK,CAAC,CAAC;IACzC,IAAI,GAAG,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IACnC,MAAM,GAAG,GAAG,GAAG,IAAI,IAAI,OAAO,CAAC,GAAG,MAAM,CAAC;IACzC,aAAa,CAAC,GAAG,EAAE,qBAAqB,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;IACxD,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACtB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/engine/feedback.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
const KINDS = ["json", "code", "text", "prose"];
|
|
3
|
+
const KINDS = ["json", "code", "text", "prose", "search", "log", "diff"];
|
|
4
4
|
/**
|
|
5
5
|
* TOIN feedback — deterministic, local self-tuning. Because CCR is lossless, a
|
|
6
6
|
* wrong verdict only costs efficiency (more retrievals), never correctness.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feedback.js","sourceRoot":"","sources":["../../src/engine/feedback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,IAAI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C,GAAG,IAAI,CAAC;YAChC,IAAI,EAAE,CAAC;QACT,CAAC;QACD,UAAU,CAAC,MAAM;YACf,MAAM,EAAE,CAAC;YACT,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YACtC,IAAI,CAAC,IAAI;gBAAE,OAAO;YAClB,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC;YAC7B,IAAI,EAAE,CAAC;QACT,CAAC;QACD,UAAU,CAAC,IAAI;YACb,MAAM,EAAE,CAAC;YACT,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;QACD,KAAK;YACH,MAAM,EAAE,CAAC;YACT,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;gBACxB,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;gBAClE,OAAO;oBACL,IAAI;oBACJ,YAAY,EAAE,CAAC,CAAC,YAAY;oBAC5B,UAAU,EAAE,CAAC,CAAC,UAAU;oBACxB,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;oBACxC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC;iBACrB,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/evals.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createFileCCRStore } from "./ccr/store.js";
|
|
2
|
+
/**
|
|
3
|
+
* `knitbrain evals` — answer-preservation, measured, reproducible.
|
|
4
|
+
*
|
|
5
|
+
* The savings number (knitbrain profile) answers "how many tokens?"; this
|
|
6
|
+
* suite answers "same answers?". On REAL transcript blocks it checks that
|
|
7
|
+
* the facts agents actually act on survive compression — with deterministic
|
|
8
|
+
* judging (string containment), not an LLM judge:
|
|
9
|
+
*
|
|
10
|
+
* error-fidelity every error/failure line in a compressed log/text
|
|
11
|
+
* block still appears verbatim in the skeleton
|
|
12
|
+
* identifier-fidelity declared names (function/class/def) in compressed
|
|
13
|
+
* code blocks still appear in the skeleton
|
|
14
|
+
* summary-fidelity numeric result lines ("3 failed | 12 passed")
|
|
15
|
+
* still appear in the skeleton
|
|
16
|
+
* round-trip every skeleton's ⟨ccr:hash⟩ recovers the original
|
|
17
|
+
* byte-for-byte
|
|
18
|
+
* never-expand no compressed block has more tokens than it started
|
|
19
|
+
*
|
|
20
|
+
* Targets are gates, not aspirations: error-fidelity and round-trip must be
|
|
21
|
+
* 100%, identifier-fidelity ≥99%, summary-fidelity ≥95%.
|
|
22
|
+
*/
|
|
23
|
+
export interface EvalReport {
|
|
24
|
+
blocks: number;
|
|
25
|
+
errorLines: {
|
|
26
|
+
total: number;
|
|
27
|
+
preserved: number;
|
|
28
|
+
};
|
|
29
|
+
identifiers: {
|
|
30
|
+
total: number;
|
|
31
|
+
preserved: number;
|
|
32
|
+
};
|
|
33
|
+
summaryLines: {
|
|
34
|
+
total: number;
|
|
35
|
+
preserved: number;
|
|
36
|
+
};
|
|
37
|
+
roundTrip: {
|
|
38
|
+
total: number;
|
|
39
|
+
ok: number;
|
|
40
|
+
};
|
|
41
|
+
neverExpand: {
|
|
42
|
+
total: number;
|
|
43
|
+
ok: number;
|
|
44
|
+
};
|
|
45
|
+
pass: boolean;
|
|
46
|
+
}
|
|
47
|
+
/** Evaluate one block, accumulating into the report. */
|
|
48
|
+
export declare function evalBlock(text: string, ccr: ReturnType<typeof createFileCCRStore>, rep: EvalReport): void;
|
|
49
|
+
/** Gate thresholds — published in the README, enforced here. */
|
|
50
|
+
export declare function gate(rep: EvalReport): boolean;
|
|
51
|
+
export declare function emptyReport(): EvalReport;
|
|
52
|
+
/** Run the suite on real transcripts. Returns the report (pass set). */
|
|
53
|
+
export declare function runEvals(args: string[], log?: (line: string) => void): Promise<EvalReport>;
|
package/dist/evals.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
2
|
+
import { homedir, tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { createReadStream, readdirSync, statSync } from "node:fs";
|
|
5
|
+
import { createInterface } from "node:readline";
|
|
6
|
+
import { createFileCCRStore } from "./ccr/store.js";
|
|
7
|
+
import { ensureAst, astReady } from "./optimizer/ast.js";
|
|
8
|
+
import { compress, stripLineNumbers } from "./optimizer/router.js";
|
|
9
|
+
import { IMPORTANT_LINE } from "./optimizer/structured.js";
|
|
10
|
+
/** Result-summary lines: test/build totals as emitted by runners — not any
|
|
11
|
+
* sentence that happens to contain a number. Summaries live at the END of
|
|
12
|
+
* output, so only the last SUMMARY_WINDOW lines of a block are eligible. */
|
|
13
|
+
const SUMMARY_LINE = /^\s*(Tests?|Test (Suites?|Files)|Suites?|Duration|Time:|Ran \d+|\d+ (passing|failing|pending|tests? (passed|failed)))\b/;
|
|
14
|
+
const SUMMARY_WINDOW = 20;
|
|
15
|
+
/** TOP-LEVEL declarations (column 0, modifiers allowed). Names nested inside
|
|
16
|
+
* function bodies are elided BY DESIGN (that's what body elision is); the
|
|
17
|
+
* promise is that the names an agent navigates by — the API surface — survive. */
|
|
18
|
+
const DECLARATION = /^(?:export\s+|pub(?:\(crate\))?\s+|public\s+|private\s+|protected\s+|static\s+|abstract\s+|final\s+|async\s+|default\s+)*(?:function|class|def|fn|func|interface|trait|impl|struct|enum)\s+([A-Za-z_$][\w$]*)/gm;
|
|
19
|
+
function collectTranscripts(roots) {
|
|
20
|
+
const files = [];
|
|
21
|
+
for (const r of roots) {
|
|
22
|
+
let st;
|
|
23
|
+
try {
|
|
24
|
+
st = statSync(r);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (st.isFile()) {
|
|
30
|
+
files.push(r);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
for (const proj of readdirSync(r)) {
|
|
34
|
+
const pd = join(r, proj);
|
|
35
|
+
try {
|
|
36
|
+
if (!statSync(pd).isDirectory())
|
|
37
|
+
continue;
|
|
38
|
+
for (const f of readdirSync(pd))
|
|
39
|
+
if (f.endsWith(".jsonl"))
|
|
40
|
+
files.push(join(pd, f));
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
/* skip unreadable */
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return files;
|
|
48
|
+
}
|
|
49
|
+
/** Evaluate one block, accumulating into the report. */
|
|
50
|
+
export function evalBlock(text, ccr, rep) {
|
|
51
|
+
const r = compress(text, ccr);
|
|
52
|
+
rep.blocks += 1;
|
|
53
|
+
// never-expand holds for every block, compressed or passed through
|
|
54
|
+
rep.neverExpand.total += 1;
|
|
55
|
+
if (r.skeletonTokens <= r.originalTokens)
|
|
56
|
+
rep.neverExpand.ok += 1;
|
|
57
|
+
if (!r.compressed)
|
|
58
|
+
return; // pass-through preserves everything by definition
|
|
59
|
+
// round-trip losslessness
|
|
60
|
+
rep.roundTrip.total += 1;
|
|
61
|
+
try {
|
|
62
|
+
if (ccr.get(r.handle) === text)
|
|
63
|
+
rep.roundTrip.ok += 1;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
/* counted as failure */
|
|
67
|
+
}
|
|
68
|
+
const kind = r.contentType;
|
|
69
|
+
if (kind === "code") {
|
|
70
|
+
// identifier-fidelity: declared names survive (signatures are kept)
|
|
71
|
+
const names = new Set();
|
|
72
|
+
for (const m of text.matchAll(DECLARATION))
|
|
73
|
+
names.add(m[1]);
|
|
74
|
+
for (const name of names) {
|
|
75
|
+
rep.identifiers.total += 1;
|
|
76
|
+
if (r.skeleton.includes(name))
|
|
77
|
+
rep.identifiers.preserved += 1;
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// error- and summary-fidelity for non-code, non-json shapes (logs, text,
|
|
82
|
+
// prose, …). JSON is excluded: an "Error" string inside a JSON value (a
|
|
83
|
+
// grep pattern, a message field) is data, not a failure event — the JSON
|
|
84
|
+
// handler's own structural guarantees are tested elsewhere. Line-numbered
|
|
85
|
+
// Read output is compared against its stripped content (the skeleton is
|
|
86
|
+
// built from that; the prefixes live in CCR).
|
|
87
|
+
if (kind === "json")
|
|
88
|
+
return;
|
|
89
|
+
const compareText = stripLineNumbers(text) ?? text;
|
|
90
|
+
const lines = compareText.split("\n");
|
|
91
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
92
|
+
const line = lines[i];
|
|
93
|
+
const t = line.trim();
|
|
94
|
+
if (t.length === 0)
|
|
95
|
+
continue;
|
|
96
|
+
if (IMPORTANT_LINE.test(line)) {
|
|
97
|
+
rep.errorLines.total += 1;
|
|
98
|
+
if (r.skeleton.includes(t))
|
|
99
|
+
rep.errorLines.preserved += 1;
|
|
100
|
+
}
|
|
101
|
+
else if (i >= lines.length - SUMMARY_WINDOW && SUMMARY_LINE.test(line)) {
|
|
102
|
+
rep.summaryLines.total += 1;
|
|
103
|
+
if (r.skeleton.includes(t))
|
|
104
|
+
rep.summaryLines.preserved += 1;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const pct = (p, t) => (t === 0 ? "n/a" : `${((p / t) * 100).toFixed(1)}%`);
|
|
109
|
+
/** Gate thresholds — published in the README, enforced here. */
|
|
110
|
+
export function gate(rep) {
|
|
111
|
+
const ratio = (p, t) => (t === 0 ? 1 : p / t);
|
|
112
|
+
return (ratio(rep.errorLines.preserved, rep.errorLines.total) === 1 &&
|
|
113
|
+
ratio(rep.roundTrip.ok, rep.roundTrip.total) === 1 &&
|
|
114
|
+
ratio(rep.neverExpand.ok, rep.neverExpand.total) === 1 &&
|
|
115
|
+
ratio(rep.identifiers.preserved, rep.identifiers.total) >= 0.99 &&
|
|
116
|
+
ratio(rep.summaryLines.preserved, rep.summaryLines.total) >= 0.95);
|
|
117
|
+
}
|
|
118
|
+
export function emptyReport() {
|
|
119
|
+
return {
|
|
120
|
+
blocks: 0,
|
|
121
|
+
errorLines: { total: 0, preserved: 0 },
|
|
122
|
+
identifiers: { total: 0, preserved: 0 },
|
|
123
|
+
summaryLines: { total: 0, preserved: 0 },
|
|
124
|
+
roundTrip: { total: 0, ok: 0 },
|
|
125
|
+
neverExpand: { total: 0, ok: 0 },
|
|
126
|
+
pass: false,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/** Run the suite on real transcripts. Returns the report (pass set). */
|
|
130
|
+
export async function runEvals(args, log = console.log) {
|
|
131
|
+
const roots = args.filter((a) => !a.startsWith("--"));
|
|
132
|
+
const files = collectTranscripts(roots.length > 0 ? roots : [join(homedir(), ".claude", "projects")]);
|
|
133
|
+
log(`[evals] transcripts: ${files.length}`);
|
|
134
|
+
const rep = emptyReport();
|
|
135
|
+
if (files.length === 0) {
|
|
136
|
+
log("[evals] nothing to scan — pass a directory or .jsonl path (default: ~/.claude/projects)");
|
|
137
|
+
return rep;
|
|
138
|
+
}
|
|
139
|
+
await ensureAst();
|
|
140
|
+
log(`[evals] AST parsers: ${astReady() ? "warm" : "unavailable — scanner fallback"}`);
|
|
141
|
+
const store = mkdtempSync(join(tmpdir(), "knitbrain-evals-"));
|
|
142
|
+
const ccr = createFileCCRStore(store);
|
|
143
|
+
try {
|
|
144
|
+
for (const file of files) {
|
|
145
|
+
const rl = createInterface({ input: createReadStream(file), crlfDelay: Infinity });
|
|
146
|
+
for await (const line of rl) {
|
|
147
|
+
let msg;
|
|
148
|
+
try {
|
|
149
|
+
msg = JSON.parse(line);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const content = msg?.message?.content;
|
|
155
|
+
if (!Array.isArray(content))
|
|
156
|
+
continue;
|
|
157
|
+
for (const block of content) {
|
|
158
|
+
if (block.type !== "tool_result")
|
|
159
|
+
continue;
|
|
160
|
+
const raw = block.content;
|
|
161
|
+
const text = typeof raw === "string"
|
|
162
|
+
? raw
|
|
163
|
+
: Array.isArray(raw)
|
|
164
|
+
? raw
|
|
165
|
+
.filter((b) => b.type === "text")
|
|
166
|
+
.map((b) => b.text ?? "")
|
|
167
|
+
.join("\n")
|
|
168
|
+
: "";
|
|
169
|
+
if (text.length < 400)
|
|
170
|
+
continue;
|
|
171
|
+
evalBlock(text, ccr, rep);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
finally {
|
|
177
|
+
rmSync(store, { recursive: true, force: true });
|
|
178
|
+
}
|
|
179
|
+
rep.pass = gate(rep);
|
|
180
|
+
log(`[evals] blocks evaluated: ${rep.blocks} (real tool outputs, no synthetic fixtures)`);
|
|
181
|
+
log(` error-fidelity ${rep.errorLines.preserved}/${rep.errorLines.total} ${pct(rep.errorLines.preserved, rep.errorLines.total)} (gate: 100%)`);
|
|
182
|
+
log(` identifier-fidelity ${rep.identifiers.preserved}/${rep.identifiers.total} ${pct(rep.identifiers.preserved, rep.identifiers.total)} (gate: ≥99%)`);
|
|
183
|
+
log(` summary-fidelity ${rep.summaryLines.preserved}/${rep.summaryLines.total} ${pct(rep.summaryLines.preserved, rep.summaryLines.total)} (gate: ≥95%)`);
|
|
184
|
+
log(` round-trip lossless ${rep.roundTrip.ok}/${rep.roundTrip.total} ${pct(rep.roundTrip.ok, rep.roundTrip.total)} (gate: 100%)`);
|
|
185
|
+
log(` never-expand ${rep.neverExpand.ok}/${rep.neverExpand.total} ${pct(rep.neverExpand.ok, rep.neverExpand.total)} (gate: 100%)`);
|
|
186
|
+
log(`[evals] ${rep.pass ? "PASS" : "FAIL"}`);
|
|
187
|
+
return rep;
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=evals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evals.js","sourceRoot":"","sources":["../src/evals.ts"],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,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACtI,GAAG,CAAC,0BAA0B,GAAG,CAAC,WAAW,CAAC,EAAE,IAAI,GAAG,CAAC,WAAW,CAAC,KAAK,KAAK,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAC9I,GAAG,CAAC,WAAW,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IAC7C,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -42,6 +42,26 @@ async function main() {
|
|
|
42
42
|
await runProfile(process.argv.slice(3));
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
|
+
if (process.argv[2] === "prompt") {
|
|
46
|
+
const { INSTRUCTIONS } = await import("./mcp/instructions.js");
|
|
47
|
+
console.log("# knitbrain — full operating prompt (paste into your platform's system prompt / rules)");
|
|
48
|
+
console.log("");
|
|
49
|
+
console.log(INSTRUCTIONS);
|
|
50
|
+
console.log("");
|
|
51
|
+
console.log("NOTATION: a ⟨ccr:HASH⟩ marker in any output means the exact original is stored locally —");
|
|
52
|
+
console.log("call knitbrain_retrieve with that hash to read it byte-for-byte. Compression is lossless.");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (process.argv[2] === "evals") {
|
|
56
|
+
const { runEvals } = await import("./evals.js");
|
|
57
|
+
const rep = await runEvals(process.argv.slice(3));
|
|
58
|
+
process.exit(rep.pass ? 0 : 1);
|
|
59
|
+
}
|
|
60
|
+
if (process.argv[2] === "learn") {
|
|
61
|
+
const { runLearn } = await import("./learn.js");
|
|
62
|
+
await runLearn(process.argv.slice(3));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
45
65
|
if (process.argv[2] === "dashboard") {
|
|
46
66
|
const [{ createDashboardServer }, { createFileCCRStore }, { createKnowledge }, { createMemory }, { createFeedback }, { createSkillsStore }, { createTeamBoard }, { createMeter }, paths] = await Promise.all([
|
|
47
67
|
import("./dashboard.js"),
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,KAAK,UAAU,IAAI;IACjB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;QAChC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC3B,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC;QAC9B,MAAM,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACrE,MAAM,CAAC,iBAAiB,CAAC;YACzB,MAAM,CAAC,YAAY,CAAC;YACpB,MAAM,CAAC,WAAW,CAAC;SACpB,CAAC,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;QAClE,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,IAAI,IAAI,CAAC,CAAC;QAC/D,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,IAAI,WAAW,CAAC;QAC9D,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE;YAC7B,OAAO,CAAC,GAAG,CAAC,0BAA0B,IAAI,IAAI,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C,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/learn.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `knitbrain learn` — offline failure mining with success correlation.
|
|
3
|
+
*
|
|
4
|
+
* Scans real session transcripts, finds tool calls that FAILED, correlates
|
|
5
|
+
* each failure with what later SUCCEEDED, and emits specific corrections
|
|
6
|
+
* ("X is at b/, not a/" — not "Read failed 5 times"). Dry-run by default;
|
|
7
|
+
* --apply writes a marker-managed section into the project's CLAUDE.md so
|
|
8
|
+
* the next session starts already knowing.
|
|
9
|
+
*/
|
|
10
|
+
interface ToolEvent {
|
|
11
|
+
tool: string;
|
|
12
|
+
input: Record<string, unknown>;
|
|
13
|
+
error: boolean;
|
|
14
|
+
errText: string;
|
|
15
|
+
seq: number;
|
|
16
|
+
}
|
|
17
|
+
export interface Learning {
|
|
18
|
+
category: "paths" | "commands" | "environment" | "large-files";
|
|
19
|
+
text: string;
|
|
20
|
+
/** Occurrences across sessions — more evidence, higher in the list. */
|
|
21
|
+
count: number;
|
|
22
|
+
}
|
|
23
|
+
/** Parse one transcript: ordered tool events (use+result matched by id). */
|
|
24
|
+
export declare function parseSession(file: string): Promise<ToolEvent[]>;
|
|
25
|
+
/** Mine one session's events for failure→success corrections. */
|
|
26
|
+
export declare function mineSession(events: ToolEvent[]): Learning[];
|
|
27
|
+
/** Merge duplicate learnings across sessions, summing evidence counts. */
|
|
28
|
+
export declare function mergeLearnings(all: Learning[]): Learning[];
|
|
29
|
+
/** Render the marker-managed CLAUDE.md section. */
|
|
30
|
+
export declare function renderSection(learnings: Learning[]): string;
|
|
31
|
+
/** Write/replace the marker section in the project's CLAUDE.md. */
|
|
32
|
+
export declare function applyToClaudeMd(projectRoot: string, section: string): string;
|
|
33
|
+
/** Claude Code's transcript-directory slug for a project path. */
|
|
34
|
+
export declare function projectSlug(projectRoot: string): string;
|
|
35
|
+
/** Transcript files for one project (or all projects with --all). */
|
|
36
|
+
export declare function transcriptsFor(projectRoot: string, all: boolean): string[];
|
|
37
|
+
/** CLI entry: `knitbrain learn [--apply] [--all] [--project <path>]`. */
|
|
38
|
+
export declare function runLearn(args: string[], log?: (line: string) => void): Promise<number>;
|
|
39
|
+
export {};
|