lakonai 0.17.1 → 1.0.1
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 +196 -110
- package/bin/lakonai.js +29 -0
- package/package.json +8 -1
- package/src/graph/embed.js +99 -0
- package/src/graph/html.js +275 -0
- package/src/graph/index.js +189 -0
- package/src/graph/leiden.js +109 -0
- package/src/graph/parser.js +306 -0
- package/src/graph/query.js +229 -0
- package/src/graph/report.js +101 -0
- package/src/graph/store.js +68 -0
- package/src/graph/watch.js +60 -0
- package/src/hooks/read-guard.js +63 -0
- package/src/hooks/session-start.js +13 -2
- package/src/hooks/stop-hook.js +6 -0
- package/src/install/claude-commands.js +32 -0
- package/src/install/index.js +8 -0
- package/src/learn-report.js +176 -0
- package/src/pixel/convert.js +181 -0
- package/src/pixel/estimate.js +57 -0
- package/src/pixel/paths.js +70 -0
- package/src/pixel/render.js +104 -0
- package/src/proxy/compress/code.js +89 -0
- package/src/proxy/compress/diff.js +54 -0
- package/src/proxy/compress/index.js +110 -0
- package/src/proxy/compress/json.js +62 -0
- package/src/proxy/compress/log.js +49 -0
- package/src/proxy/compress/text.js +51 -0
- package/src/proxy/daemon.js +107 -0
- package/src/proxy/detect.js +40 -0
- package/src/proxy/server.js +109 -0
- package/src/rules/lakonai-stats.md +28 -0
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<h3 align="center">Speak less. Ship more.</h3>
|
|
8
8
|
|
|
9
9
|
<p align="center">
|
|
10
|
-
<strong>Cut LLM tokens by up to 94%
|
|
10
|
+
<strong>Cut LLM tokens by up to 94% — without losing a single identifier.</strong>
|
|
11
11
|
</p>
|
|
12
12
|
|
|
13
13
|
<p align="center"><em>Spartan replies for AI agents.</em></p>
|
|
@@ -18,119 +18,192 @@
|
|
|
18
18
|
<img src="https://img.shields.io/badge/node-%E2%89%A518-0F0F0F" alt="node ≥18" />
|
|
19
19
|
<img src="https://img.shields.io/badge/deps-0-0F0F0F" alt="zero dependencies" />
|
|
20
20
|
<img src="https://img.shields.io/badge/agents-6-0F0F0F" alt="6 AI agents" />
|
|
21
|
+
<img src="https://img.shields.io/badge/tests-725-0F0F0F" alt="725 tests" />
|
|
21
22
|
</p>
|
|
22
23
|
|
|
23
24
|
<p align="center">
|
|
24
|
-
One install.
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
One install. Zero configuration. Every token wasted by your agent — <strong>closed</strong>.<br/>
|
|
26
|
+
Works across <strong>Claude Code, Codex, Cursor, Windsurf, Cline, Gemini CLI</strong>.<br/>
|
|
27
|
+
<strong>Optimized for Claude Code</strong> — four dedicated layers, measured in production.
|
|
27
28
|
</p>
|
|
28
29
|
|
|
29
30
|
---
|
|
30
31
|
|
|
31
|
-
##
|
|
32
|
+
## Real savings, measured
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
| --------------------- | ---------: | ----------: | -------: |
|
|
35
|
-
| `git log -p -10` | 10,497 | 78 | **-94%** |
|
|
36
|
-
| `ls -laR` (deep dir) | 23,624 | 117 | **-94%** |
|
|
37
|
-
| `npm test` (passing) | 4,451 | 358 | **-92%** |
|
|
38
|
-
| `git diff HEAD~5` | 13,230 | 798 | **-89%** |
|
|
39
|
-
| `Read pnpm-lock.yaml` | ~56,000 | **blocked** | **-95%** |
|
|
34
|
+
**CLI filters** — stripped before output reaches the model:
|
|
40
35
|
|
|
41
|
-
|
|
36
|
+
| Command | Raw tokens | Filtered | Saved |
|
|
37
|
+
| -------------------- | ---------: | --------: | -------: |
|
|
38
|
+
| `git log -p -10` | 10,497 | 78 | **-94%** |
|
|
39
|
+
| `ls -laR` (deep) | 23,624 | 117 | **-94%** |
|
|
40
|
+
| `npm test` (passing) | 4,451 | 358 | **-92%** |
|
|
41
|
+
| `git diff HEAD~5` | 13,230 | 798 | **-89%** |
|
|
42
|
+
| `Read pnpm-lock.yaml`| ~56,000 | **blocked**| **-95%** |
|
|
43
|
+
|
|
44
|
+
**Proxy compression** — what actually reaches the Anthropic API (real session, 49 requests):
|
|
45
|
+
|
|
46
|
+
| Content type | Without lakonai | With lakonai | Saved |
|
|
47
|
+
| ------------------- | --------------: | -----------: | -------: |
|
|
48
|
+
| npm test (652 tests)| 5,168 tok | 85 tok | **-98%** |
|
|
49
|
+
| Build log (80 lines)| 1,298 tok | 8 tok | **-99%** |
|
|
50
|
+
| JSON API (120 users)| 2,386 tok | 104 tok | **-96%** |
|
|
51
|
+
| Git diff | ~3,000 tok | ~2,880 tok | **-4%**|
|
|
52
|
+
| Source file read | via graph read-guard → **-87%** | |
|
|
53
|
+
|
|
54
|
+
**Typical coding session:** ~53% savings from proxy alone, ~75% with graph read-guard.
|
|
55
|
+
|
|
56
|
+
`lakonai gain` shows your own numbers. `/lakonai:stats` shows all layers at once.
|
|
42
57
|
|
|
43
58
|
---
|
|
44
59
|
|
|
45
|
-
##
|
|
60
|
+
## Eight fronts, one install
|
|
46
61
|
|
|
47
|
-
| Front
|
|
48
|
-
|
|
49
|
-
| **Output**
|
|
50
|
-
| **
|
|
51
|
-
| **Reads**
|
|
52
|
-
| **Overflow**
|
|
53
|
-
| **
|
|
62
|
+
| Front | What it fixes | How |
|
|
63
|
+
|-------|--------------|-----|
|
|
64
|
+
| **Output** | _"Great question! Let me explain…"_ | Terse-response rule — no preamble, no recap. Auto-clarity for edge cases. |
|
|
65
|
+
| **Shell input** | `git log` dumping 1.8k tokens of metadata | Filters **30+ commands** (git/ls/grep/tests/lint/docker/kubectl/aws…) before they hit context |
|
|
66
|
+
| **Reads** | `Read pnpm-lock.yaml` → 80k of nothing | Hook blocks lockfiles/`node_modules`, caps huge files and `Grep` |
|
|
67
|
+
| **Overflow** | 4k-line build logs no filter knows | Parks on disk, hands the agent a digest — `lakonai peek` reads it back |
|
|
68
|
+
| **Proxy** | Every API request carries raw bloat | Local HTTP proxy compresses request bodies before they reach Anthropic |
|
|
69
|
+
| **Graph** | File reads load entire source files | AST knowledge graph: serves a compact subgraph instead of the raw file (-87%) |
|
|
70
|
+
| **Pixel** | Skill files are verbose markdown | Converts skill bodies to PNG — vision tokens cheaper than text tokens |
|
|
71
|
+
| **Context** | MCP catalogs + memory re-paid every turn | Auto-compresses MCP catalogs; `compress-memory` via local AI CLI |
|
|
54
72
|
|
|
55
|
-
|
|
56
|
-
you use it**: it auto-learns new heavy commands and turns on a safe filter for them,
|
|
57
|
-
no config. ([full reference →](docs/reference.md))
|
|
73
|
+
Auto-learning runs underneath all of this: lakonai detects new heavy commands and enables a safe filter automatically, no config. ([full reference →](docs/reference.md))
|
|
58
74
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Quick start
|
|
62
78
|
|
|
79
|
+
```bash
|
|
80
|
+
npm install -g lakonai
|
|
81
|
+
lakonai install
|
|
63
82
|
```
|
|
64
|
-
lakonai: 4000 lines / 249KB parked in sandbox 30930a0c — too big for context, kept out.
|
|
65
|
-
$ node build.js → exit 0
|
|
66
83
|
|
|
67
|
-
|
|
68
|
-
… 3980 lines elided …
|
|
69
|
-
[build] compiling module 3999 …
|
|
84
|
+
That's it. From the next session your agent is terse, shell output is filtered, junk reads are blocked, the proxy compresses API traffic, and the graph intercepts file reads. Watch it in `lakonai gain`.
|
|
70
85
|
|
|
71
|
-
|
|
72
|
-
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Layers, explained
|
|
89
|
+
|
|
90
|
+
### Layer 1 — CLI filters (all agents)
|
|
91
|
+
|
|
92
|
+
Thirty-plus command filters run as a PATH shim or Claude Code hook before output ever reaches context. `git log -p` becomes three lines. A passing `npm test` suite becomes one.
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
lakonai git log -p # → summary only
|
|
96
|
+
lakonai npm test # → final counts only
|
|
97
|
+
lakonai ls -la # → files without noise
|
|
73
98
|
```
|
|
74
99
|
|
|
75
|
-
|
|
76
|
-
lost - it stops being re-paid on every turn. Set `LAKON_SPILL_TOKENS=0` to turn
|
|
77
|
-
it off.
|
|
100
|
+
### Layer 2 — Graph read-guard (Claude Code)
|
|
78
101
|
|
|
79
|
-
|
|
80
|
-
lakonai knows. A `PostToolUse` hook sees the real result after the tool ran, so
|
|
81
|
-
`terraform plan`, `./deploy.sh`, a 3k-line `Grep`, a `WebFetch` of a huge page and
|
|
82
|
-
stderr are all covered, alongside `Read`. Structural results (`Edit`, `Write`,
|
|
83
|
-
`TodoWrite`) are left alone.
|
|
102
|
+
`lakonai graph build` parses your codebase into an AST knowledge graph — zero LLM, pure regex, works in under a second for most projects. When Claude Code reads a source file, the read-guard intercepts and returns a compact subgraph (symbols, edges, community) instead of the full text.
|
|
84
103
|
|
|
85
|
-
|
|
86
|
-
|
|
104
|
+
```
|
|
105
|
+
102 files → 512 nodes → 573 edges built in <0.1s
|
|
106
|
+
file read: 2,835 tok raw → 300 tok subgraph (-89%)
|
|
107
|
+
```
|
|
87
108
|
|
|
88
|
-
|
|
109
|
+
```bash
|
|
110
|
+
lakonai graph build # build / rebuild
|
|
111
|
+
lakonai graph query "what calls parseFile?"
|
|
112
|
+
lakonai graph explain src/foo.js
|
|
113
|
+
lakonai graph path src/a.js src/b.js
|
|
114
|
+
lakonai graph html # open interactive viz
|
|
115
|
+
lakonai graph watch # rebuild on file change
|
|
116
|
+
```
|
|
89
117
|
|
|
90
|
-
|
|
118
|
+
The graph JSON is auto-added to `.gitignore`. Set `LAKON_GRAPH_CAT=0` to bypass.
|
|
119
|
+
|
|
120
|
+
### Layer 3 — Proxy compression (Claude Code)
|
|
121
|
+
|
|
122
|
+
A local HTTP proxy on port 7474 sits between Claude Code and `api.anthropic.com`. It compresses request bodies before they're sent — the model sees fewer tokens, you pay less.
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
build logs → -99% (repetitive lines collapsed)
|
|
126
|
+
minified JSON → -96% (schema-extracted summary)
|
|
127
|
+
test output → -98% (counts only, no per-test lines)
|
|
128
|
+
diffs → -4% (conservative; context preserved)
|
|
129
|
+
source code → 0% (covered by graph instead)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
The proxy starts automatically on `lakonai install` and runs silently. No API key exposed. Stats accumulate in `~/.lakon/proxy-stats.json`.
|
|
133
|
+
|
|
134
|
+
### Layer 4 — Pixel (Claude Code + Codex)
|
|
135
|
+
|
|
136
|
+
Skill markdown is verbose. A 3k-token skill file becomes a 170-token PNG tile. Vision tokens are cheaper than text tokens past the ~255-token break-even point.
|
|
91
137
|
|
|
92
138
|
```bash
|
|
93
|
-
|
|
94
|
-
lakonai
|
|
95
|
-
lakonai
|
|
139
|
+
lakonai pixel --dry-run # estimate savings, no writes
|
|
140
|
+
lakonai pixel # convert profitable skills (requires: npm install canvas)
|
|
141
|
+
lakonai pixel --agent claude # Claude Code skills only
|
|
142
|
+
lakonai pixel --revert # byte-identical restore from backup
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Overflow sandbox (all agents)
|
|
146
|
+
|
|
147
|
+
When a command's output still exceeds budget after filtering, lakonai parks the full text in `~/.lakon/sandbox/` and gives the agent a digest: head, tail, exit code, how to query. Nothing is lost — it stops being re-paid.
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
lakonai: 4000 lines / 249KB parked in sandbox 30930a0c
|
|
151
|
+
$ node build.js → exit 0
|
|
152
|
+
|
|
153
|
+
[build] compiling module 0 …
|
|
154
|
+
… 3980 lines elided …
|
|
155
|
+
[build] compiling module 3999 …
|
|
156
|
+
|
|
157
|
+
Query it: lakonai peek 30930a0c --grep "error"
|
|
96
158
|
```
|
|
97
159
|
|
|
98
|
-
|
|
99
|
-
junk reads blocked, and MCP catalogs compressed. Watch it in `lakonai gain`.
|
|
160
|
+
---
|
|
100
161
|
|
|
101
|
-
|
|
162
|
+
## Agent support
|
|
102
163
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
164
|
+
| Feature | Claude Code | Codex | Cursor / Windsurf / Cline | Gemini |
|
|
165
|
+
|---------|:-----------:|:-----:|:-------------------------:|:------:|
|
|
166
|
+
| CLI filters | ✅ hook | ✅ shim | ✅ shim | ✅ shim |
|
|
167
|
+
| Read/Grep guard | ✅ | ✅ shim | ✅ shim | ✅ shim |
|
|
168
|
+
| Overflow sandbox | ✅ | — | — | — |
|
|
169
|
+
| Proxy compression | ✅ | — | — | — |
|
|
170
|
+
| Graph read-guard | ✅ | — | — | — |
|
|
171
|
+
| Pixel (skill PNG) | ✅ | ✅ | — | — |
|
|
172
|
+
| MCP catalog compression | ✅ | — | — | — |
|
|
173
|
+
| Auto-learn new commands | ✅ | ✅ | ✅ | ✅ |
|
|
174
|
+
|
|
175
|
+
**Primary target: Claude Code.** The proxy and graph layers intercept the Anthropic protocol and are Claude-Code-specific. CLI filters and the universal shim work on every agent. Every install is idempotent and reversible.
|
|
107
176
|
|
|
108
177
|
---
|
|
109
178
|
|
|
110
|
-
##
|
|
179
|
+
## Slash commands
|
|
111
180
|
|
|
112
|
-
|
|
113
|
-
deterministic. But the terse rule also makes the **model itself** write less.
|
|
114
|
-
`lakonai gain` measures it by running the same prompts through your local AI CLI
|
|
115
|
-
twice - once rule-free, once with the terse rule as a system prompt - and
|
|
116
|
-
comparing output tokens.
|
|
181
|
+
After `lakonai install`, these are available in Claude Code:
|
|
117
182
|
|
|
118
|
-
|
|
119
|
-
|
|
183
|
+
| Command | What it shows |
|
|
184
|
+
|---------|--------------|
|
|
185
|
+
| `/lakonai:gain` | Token savings — input (measured) and output (estimated) |
|
|
186
|
+
| `/lakonai:stats` | All layers: filters + proxy breakdown by content type |
|
|
120
187
|
|
|
121
|
-
|
|
188
|
+
---
|
|
122
189
|
|
|
123
|
-
|
|
124
|
-
- model output varies run to run (the figure is a single weekly sample, not an average);
|
|
125
|
-
- agentic turns (code edits, tool calls, diffs) are mostly code, not prose, so the
|
|
126
|
-
rule trims far less there.
|
|
190
|
+
## Full CLI reference
|
|
127
191
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
192
|
+
| Command | What it does |
|
|
193
|
+
|---------|-------------|
|
|
194
|
+
| `lakonai install [--here]` | Install rule + hooks (globals; `--here` adds per-project) |
|
|
195
|
+
| `lakonai upgrade` | Update to latest + refresh the rule block |
|
|
196
|
+
| `lakonai uninstall` / `revert` | Strip the lakonai block / restore from backup |
|
|
197
|
+
| `lakonai shim [--off]` | Universal PATH shim — automatic filtering on every agent |
|
|
198
|
+
| `lakonai graph <sub>` | Build / query / watch the AST knowledge graph |
|
|
199
|
+
| `lakonai pixel [--dry-run\|--revert\|--agent]` | Convert skill files to PNG |
|
|
200
|
+
| `lakonai compress-memory <file>` | Shrink a memory file via your local AI CLI |
|
|
201
|
+
| `lakonai peek [id]` | Read output parked in sandbox (`--grep/--offset/--limit`) |
|
|
202
|
+
| `lakonai gain` | Token savings across all measured fronts |
|
|
203
|
+
| `lakonai inspect <cmd>` | Debug what filter applies to a command |
|
|
204
|
+
| `lakonai doctor` | Health check: CLI on PATH, hooks, rule |
|
|
131
205
|
|
|
132
|
-
|
|
133
|
-
> estimated output number - labelled as an estimate, never inflated into a headline.
|
|
206
|
+
Full flags, filters, env vars, internals: **[docs/reference.md](docs/reference.md)**.
|
|
134
207
|
|
|
135
208
|
---
|
|
136
209
|
|
|
@@ -147,60 +220,73 @@ lakonai - saved 196.8k tok (46% smaller) across 1910 commands
|
|
|
147
220
|
output (terse rule): ~52% fewer tokens (1332 → 634, 4 prompts) [claude]
|
|
148
221
|
```
|
|
149
222
|
|
|
150
|
-
Input is measured
|
|
151
|
-
weekly, at a TTY only). Both sides, one number.
|
|
223
|
+
Input is measured and deterministic. Output is estimated by your local AI CLI (no key, weekly). Both sides, one number.
|
|
152
224
|
|
|
153
225
|
---
|
|
154
226
|
|
|
155
|
-
##
|
|
227
|
+
## vs. similar tools
|
|
228
|
+
|
|
229
|
+
| Feature | lakonai | caveman | graphify | rtk | Manual CLAUDE.md |
|
|
230
|
+
|---------|:-------:|:-------:|:--------:|:---:|:----------------:|
|
|
231
|
+
| Terse-response rule | ✅ | ✅ | — | — | ⚠️ manual |
|
|
232
|
+
| CLI output filters (30+ commands) | ✅ | — | — | ✅ | — |
|
|
233
|
+
| Auto-learning (new heavy commands) | ✅ | — | — | — | — |
|
|
234
|
+
| Lockfile / node_modules guard | ✅ | — | — | — | ⚠️ manual |
|
|
235
|
+
| Overflow sandbox (large outputs) | ✅ | — | — | — | — |
|
|
236
|
+
| Proxy compression (logs/JSON/diffs) | ✅ | ✅ | — | — | — |
|
|
237
|
+
| AST knowledge graph | ✅ | — | ✅ | — | — |
|
|
238
|
+
| Graph read-guard (subgraph on reads) | ✅ | — | — | — | — |
|
|
239
|
+
| BM25 NL graph query (zero LLM) | ✅ | — | ⚠️ LLM | — | — |
|
|
240
|
+
| Community detection (Leiden) | ✅ | — | ✅ | — | — |
|
|
241
|
+
| Interactive graph viz (HTML) | ✅ | — | ✅ | — | — |
|
|
242
|
+
| Skill PNG conversion (pixel) | ✅ | ✅ | — | — | — |
|
|
243
|
+
| MCP catalog compression | ✅ | — | — | — | — |
|
|
244
|
+
| Zero config after install | ✅ | ✅ | — | ⚠️ | ⚠️ |
|
|
245
|
+
| Works with Cursor/Windsurf/Codex | ✅ | ✅ | — | ✅ | ✅ |
|
|
246
|
+
| Optimised for Claude Code | ✅ | ✅ | — | — | — |
|
|
247
|
+
| Pure JS, no native deps for core | ✅ | ✅ | — | ✅ | — |
|
|
248
|
+
| npm install + one command | ✅ | ✅ | — | ⚠️ | — |
|
|
249
|
+
|
|
250
|
+
**caveman** — terse rule, auto-clarity, proxy compression, pixel mode (MIT). Absorbed with credit.
|
|
251
|
+
**graphify** — AST knowledge graph, Leiden community detection, force-directed HTML viz, NL query. Reimplemented in Node.js; lakonai replaces LLM-based query with BM25 (zero cost).
|
|
252
|
+
**rtk** — CLI output filtering approach; lakonai extends with auto-learning and 30+ built-in filters.
|
|
253
|
+
**Manual CLAUDE.md** — works, but you write and maintain it; lakonai installs and updates automatically.
|
|
156
254
|
|
|
157
|
-
|
|
158
|
-
| --------------------------------------------------------- | -------------------------------------------------------------- |
|
|
159
|
-
| `lakonai install [--here]` | Install rule + hooks (globals; `--here` adds per-project) |
|
|
160
|
-
| `lakonai upgrade` | Update to the latest version + refresh the rule block |
|
|
161
|
-
| `lakonai uninstall` / `revert` | Strip the lakonai block / restore from backup |
|
|
162
|
-
| `lakonai shim [--off]` | Universal PATH shim - automatic shell filtering on every agent |
|
|
163
|
-
| `lakonai compress-memory <file>` / `revert-memory <file>` | Shrink a memory file via your local AI CLI / undo |
|
|
164
|
-
| `lakonai peek [id]` | Read output parked in the sandbox (`--offset/--limit/--grep`) |
|
|
165
|
-
| `lakonai gain` | Token savings - input (measured) and output (estimated) |
|
|
166
|
-
| `lakonai doctor` | Per-platform health: CLI on PATH, rule, hooks |
|
|
255
|
+
---
|
|
167
256
|
|
|
168
|
-
|
|
257
|
+
## Test suite
|
|
169
258
|
|
|
170
|
-
|
|
259
|
+
725 tests across 47 suites — all passing, no mocks on I/O boundaries.
|
|
171
260
|
|
|
172
|
-
|
|
261
|
+
| Type | Suites | Tests |
|
|
262
|
+
|------|--------|-------|
|
|
263
|
+
| Unit | 13 | 183 |
|
|
264
|
+
| Integration (module + real FS) | 31 | 489 |
|
|
265
|
+
| E2E / CLI (spawn + real process) | 3 | 53 |
|
|
266
|
+
| **Total** | **47** | **725** |
|
|
173
267
|
|
|
174
|
-
|
|
175
|
-
| ------------------------- | ---------------------------------------------------- | :----------: | :-------------: | :--------: |
|
|
176
|
-
| Claude Code | `~/.claude/CLAUDE.md` + 6 hooks + MCP compress | ✅ hook | ✅ tool + shell | ✅ |
|
|
177
|
-
| Codex / Gemini | rule in `~/.codex/AGENTS.md` · `~/.gemini/GEMINI.md` | ✅ shim | ✅ shell reads | ✅ |
|
|
178
|
-
| Cursor / Windsurf / Cline | per-project rule (`--here`) | ✅ shim | ✅ shell reads | ✅ |
|
|
268
|
+
Coverage: **95% statements · 89% branches · 97% functions**
|
|
179
269
|
|
|
180
|
-
|
|
181
|
-
everywhere else `lakonai shim` makes the shell-mediated features automatic. The one
|
|
182
|
-
thing not universal is guarding an agent's **own non-shell Read tool** - see the
|
|
183
|
-
[honest matrix](docs/reference.md#capability-matrix-per-agent). Every install is
|
|
184
|
-
idempotent and reversible (`uninstall`/`revert`, backups first).
|
|
270
|
+
Branch ceiling is ~90% — the remaining gaps are canvas-native rendering, platform-specific `fs.watch` fallback, and the HTTPS transport branch (all marked `/* istanbul ignore next */` with justification).
|
|
185
271
|
|
|
186
272
|
---
|
|
187
273
|
|
|
188
274
|
## Why "lakonai"
|
|
189
275
|
|
|
190
|
-
In 346 BC, Philip II of Macedon warned Sparta: _"If I invade Lakonía, I will raze
|
|
191
|
-
your cities."_ The Spartans replied with one word: _"If."_ Their region, **Lakonía**,
|
|
192
|
-
gave English the word **laconic** - using as few words as possible.
|
|
276
|
+
In 346 BC, Philip II of Macedon warned Sparta: _"If I invade Lakonía, I will raze your cities."_ The Spartans replied with one word: _"If."_ Their region, **Lakonía**, gave English the word **laconic** — using as few words as possible.
|
|
193
277
|
|
|
194
|
-
Your AI agent isn't laconic. It opens with _"Sure! I'd be happy to help…"_, repeats
|
|
195
|
-
your question, and reads `git log` in full. lakonai trims both sides.
|
|
278
|
+
Your AI agent isn't laconic. It opens with _"Sure! I'd be happy to help…"_, repeats your question, reads `git log` in full, and sends every line of your test suite to the API. lakonai closes all of it.
|
|
196
279
|
|
|
197
280
|
---
|
|
198
281
|
|
|
199
282
|
## Credits
|
|
200
283
|
|
|
201
|
-
Built on ideas from
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
284
|
+
Built on ideas from three projects:
|
|
285
|
+
|
|
286
|
+
- [**caveman**](https://github.com/juliusbrussee/caveman) (MIT) — terse rule, auto-clarity, proxy compression, pixel mode
|
|
287
|
+
- [**graphify**](https://github.com/Bklieger/graphify) — AST knowledge graph, Leiden community detection, force-directed viz, NL query (reimplemented in Node.js; BM25 replaces LLM query)
|
|
288
|
+
- [**rtk**](https://github.com/rtk-ai/rtk) — CLI output filtering approach, extended with auto-learning and 30+ built-in filters
|
|
289
|
+
|
|
290
|
+
Condensed into one zero-dependency npm package with automatic install, savings tracking, and four layers of compression.
|
|
205
291
|
|
|
206
|
-
MIT
|
|
292
|
+
MIT — see [LICENSE](LICENSE).
|
package/bin/lakonai.js
CHANGED
|
@@ -396,6 +396,27 @@ async function maybeOfferUpdate() {
|
|
|
396
396
|
}
|
|
397
397
|
}
|
|
398
398
|
|
|
399
|
+
function runPixel(args) {
|
|
400
|
+
const pixel = require('../src/pixel/convert');
|
|
401
|
+
const dryRun = args.includes('--dry-run');
|
|
402
|
+
const revert = args.includes('--revert');
|
|
403
|
+
const agentIdx = args.indexOf('--agent');
|
|
404
|
+
const agent = agentIdx >= 0 ? args[agentIdx + 1] : null;
|
|
405
|
+
|
|
406
|
+
if (dryRun) {
|
|
407
|
+
const results = pixel.dryRun({ agent });
|
|
408
|
+
process.stdout.write(pixel.formatDryRun(results));
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (revert) {
|
|
412
|
+
const results = pixel.revertAll({ agent });
|
|
413
|
+
process.stdout.write(pixel.formatRevert(results));
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
const results = pixel.convert({ agent });
|
|
417
|
+
process.stdout.write(pixel.formatConvert(results));
|
|
418
|
+
}
|
|
419
|
+
|
|
399
420
|
async function main() {
|
|
400
421
|
const argv = process.argv.slice(2);
|
|
401
422
|
if (!argv.length || argv[0] === '--help' || argv[0] === '-h') {
|
|
@@ -472,6 +493,14 @@ async function main() {
|
|
|
472
493
|
require('../src/mcp-shrink').runProxy(rest);
|
|
473
494
|
return;
|
|
474
495
|
}
|
|
496
|
+
if (first === 'graph') {
|
|
497
|
+
require('../src/graph').runGraph(rest);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
if (first === 'pixel') {
|
|
501
|
+
runPixel(rest);
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
475
504
|
|
|
476
505
|
runAndFilter(first, rest);
|
|
477
506
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lakonai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "lakonai — save AI context tokens. Filters & compresses CLI output (git, ls, grep, find, test runners, lint/build, docker/kubectl/aws) before it reaches Claude Code, Codex, Cursor, Windsurf, Cline or Gemini — and learns to filter new commands automatically the more you use it.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude",
|
|
@@ -46,6 +46,9 @@
|
|
|
46
46
|
],
|
|
47
47
|
"scripts": {
|
|
48
48
|
"test": "jest",
|
|
49
|
+
"test:unit": "jest --testPathPattern='(?<!integration|e2e-proxy|cli|bash-rewrite|grep-guard|learn-report-integration|mem-llm|session-start|stop-hook)\\.test\\.js$'",
|
|
50
|
+
"test:integration": "jest --testPathPattern='(graph-integration|graph-parser|proxy-server|learn-report-integration|bash-rewrite|grep-guard|session-start|stop-hook)\\.test\\.js$'",
|
|
51
|
+
"test:e2e": "jest --testPathPattern='(cli|e2e-proxy|integration)\\.test\\.js$'",
|
|
49
52
|
"test:coverage": "jest --coverage",
|
|
50
53
|
"test:coverage:check": "jest --coverage",
|
|
51
54
|
"bench": "node -e \"process.stdout.write(require('./src/bench').format(require('./src/bench').runBench()))\""
|
|
@@ -53,6 +56,10 @@
|
|
|
53
56
|
"engines": {
|
|
54
57
|
"node": ">=18"
|
|
55
58
|
},
|
|
59
|
+
"optionalDependencies": {
|
|
60
|
+
"@xenova/transformers": "^2.17.2",
|
|
61
|
+
"canvas": "^2.11.2"
|
|
62
|
+
},
|
|
56
63
|
"devDependencies": {
|
|
57
64
|
"jest": "^29.7.0"
|
|
58
65
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Semantic embeddings via @xenova/transformers (optional dependency).
|
|
4
|
+
// Falls back gracefully when not installed — callers check tryXenova() first.
|
|
5
|
+
//
|
|
6
|
+
// All vectors are L2-normalized (normalize: true), so cosine similarity = dot product.
|
|
7
|
+
|
|
8
|
+
const MODEL = 'Xenova/bge-small-en-v1.5';
|
|
9
|
+
|
|
10
|
+
// Try to load @xenova/transformers. Returns the module or null.
|
|
11
|
+
async function tryXenova() {
|
|
12
|
+
try {
|
|
13
|
+
// @xenova/transformers is ESM-only — must use dynamic import.
|
|
14
|
+
return await import('@xenova/transformers');
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Check synchronously if @xenova/transformers is installed (no import).
|
|
21
|
+
function hasXenova() {
|
|
22
|
+
try {
|
|
23
|
+
require.resolve('@xenova/transformers');
|
|
24
|
+
return true;
|
|
25
|
+
} catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Dot product of two normalized vectors (= cosine similarity when normalized).
|
|
31
|
+
function dot(a, b) {
|
|
32
|
+
let s = 0;
|
|
33
|
+
for (let i = 0; i < a.length; i++) s += a[i] * b[i];
|
|
34
|
+
return s;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Build the text to embed for a node.
|
|
38
|
+
function nodeText(n) {
|
|
39
|
+
return `${n.label} ${n.kind} ${n.file}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Generate embeddings for all nodes. Returns [{id, embedding: number[]}].
|
|
43
|
+
// Throws if @xenova/transformers is not installed.
|
|
44
|
+
async function generateEmbeddings(nodes) {
|
|
45
|
+
const xeno = await tryXenova();
|
|
46
|
+
if (!xeno) throw new Error('@xenova/transformers not installed');
|
|
47
|
+
|
|
48
|
+
const { pipeline } = xeno;
|
|
49
|
+
const embedder = await pipeline('feature-extraction', MODEL, { quantized: true });
|
|
50
|
+
|
|
51
|
+
const results = [];
|
|
52
|
+
// Batch in groups of 32 to avoid OOM on large graphs.
|
|
53
|
+
const BATCH = 32;
|
|
54
|
+
for (let i = 0; i < nodes.length; i += BATCH) {
|
|
55
|
+
const batch = nodes.slice(i, i + BATCH);
|
|
56
|
+
const texts = batch.map(nodeText);
|
|
57
|
+
const out = await embedder(texts, { pooling: 'mean', normalize: true });
|
|
58
|
+
// out.data is a flat Float32Array: [vec0...vec1...vec2...]
|
|
59
|
+
const dim = out.dims[1];
|
|
60
|
+
for (let j = 0; j < batch.length; j++) {
|
|
61
|
+
const start = j * dim;
|
|
62
|
+
results.push({
|
|
63
|
+
id: batch[j].id,
|
|
64
|
+
embedding: Array.from(out.data.slice(start, start + dim)),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
embedder.dispose();
|
|
70
|
+
return results;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Embed a single query string. Returns number[].
|
|
74
|
+
async function embedQuery(question) {
|
|
75
|
+
const xeno = await tryXenova();
|
|
76
|
+
if (!xeno) throw new Error('@xenova/transformers not installed');
|
|
77
|
+
|
|
78
|
+
const { pipeline } = xeno;
|
|
79
|
+
const embedder = await pipeline('feature-extraction', MODEL, { quantized: true });
|
|
80
|
+
const out = await embedder([question], { pooling: 'mean', normalize: true });
|
|
81
|
+
embedder.dispose();
|
|
82
|
+
return Array.from(out.data);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Score nodes by cosine similarity to a query embedding.
|
|
86
|
+
// embeddingMap: Map<nodeId, number[]>
|
|
87
|
+
// Returns [{node, score}] sorted desc, limited to topK.
|
|
88
|
+
function scoreByEmbedding(nodes, embeddingMap, queryVec, topK) {
|
|
89
|
+
return nodes
|
|
90
|
+
.map((n) => {
|
|
91
|
+
const vec = embeddingMap.get(n.id);
|
|
92
|
+
return { node: n, score: vec ? dot(vec, queryVec) : 0 };
|
|
93
|
+
})
|
|
94
|
+
.filter((x) => x.score > 0.2) // cosine threshold — avoids returning noise
|
|
95
|
+
.sort((a, b) => b.score - a.score)
|
|
96
|
+
.slice(0, topK);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
module.exports = { tryXenova, hasXenova, generateEmbeddings, embedQuery, scoreByEmbedding, nodeText, dot };
|