lakonai 0.14.0 → 0.15.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 +16 -11
- package/bin/lakonai.js +9 -0
- package/package.json +1 -1
- package/src/install/platforms.js +1 -1
- package/src/learn.js +48 -0
package/README.md
CHANGED
|
@@ -9,9 +9,11 @@
|
|
|
9
9
|
</p>
|
|
10
10
|
|
|
11
11
|
<p align="center">
|
|
12
|
-
<em>Spartan replies for AI agents
|
|
12
|
+
<em>Spartan replies for AI agents.</em>
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
|
+
<h3 align="center">Speak less. Ship more.</h3>
|
|
16
|
+
|
|
15
17
|
<p align="center">
|
|
16
18
|
<a href="https://www.npmjs.com/package/lakonai"><img src="https://img.shields.io/npm/v/lakonai?color=0F0F0F&label=npm" alt="npm" /></a>
|
|
17
19
|
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-0F0F0F" alt="MIT" /></a>
|
|
@@ -326,20 +328,23 @@ agent's own non-shell Read tool and its full command stream — guarding that to
|
|
|
326
328
|
and auto-learning need a call-rewriting hook, which today only Claude Code
|
|
327
329
|
exposes. Honest matrix:
|
|
328
330
|
|
|
329
|
-
| Agent | Terse rule | Shell filter | Read/Grep guard | Auto-learning
|
|
330
|
-
| ----------- | :--------: | -------------------- | --------------------- |
|
|
331
|
-
| Claude Code | ✅ | ✅ automatic (hook) | ✅ tool + shell |
|
|
332
|
-
| Codex CLI | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) |
|
|
333
|
-
| Cursor | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) |
|
|
334
|
-
| Windsurf | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) |
|
|
335
|
-
| Cline | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) |
|
|
336
|
-
| Gemini CLI | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) |
|
|
331
|
+
| Agent | Terse rule | Shell filter | Read/Grep guard | Auto-learning |
|
|
332
|
+
| ----------- | :--------: | -------------------- | --------------------- | --------------- |
|
|
333
|
+
| Claude Code | ✅ | ✅ automatic (hook) | ✅ tool + shell | ✅ transcript+log |
|
|
334
|
+
| Codex CLI | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) | ✅ from log³ |
|
|
335
|
+
| Cursor | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) | ✅ from log³ |
|
|
336
|
+
| Windsurf | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) | ✅ from log³ |
|
|
337
|
+
| Cline | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) | ✅ from log³ |
|
|
338
|
+
| Gemini CLI | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) | ✅ from log³ |
|
|
337
339
|
|
|
338
340
|
Run `lakonai doctor` to see, per platform, what's actually active on your machine.
|
|
341
|
+
The only thing **not** automatic everywhere is guarding the agent's *own non-shell
|
|
342
|
+
Read tool* — that needs a call-rewriting hook, which today only Claude Code exposes
|
|
343
|
+
(see ²).
|
|
339
344
|
|
|
340
345
|
¹ `lakonai shim` prepends `~/.lakon/shim` to PATH so `ls`/`grep`/`rg`/`ag`/`find`/`cat`/`tree`/`head` filter automatically for any agent that runs them through a shell (opt-in — it edits your shell rc; `git` is excluded for safety). Without it, those commands filter only when the model prefixes `lakonai` itself.
|
|
341
346
|
² The shim refuses junk reads (lockfiles, `node_modules/…`, build artifacts) done through the shell with `cat`/`head`/`tail`/`less` — same deny rules as the Claude Read hook. An agent's *own* internal Read tool (not via the shell) still needs a hook, so capping/blocking it is automatic only on Claude Code. Codex's hook [can't yet rewrite a tool call](https://github.com/openai/codex/issues/18491); Cursor's can deny but not cap; Gemini's `BeforeTool` could (installer planned, pending schema validation against the real CLI).
|
|
342
|
-
³ Auto-learning
|
|
347
|
+
³ Auto-learning runs off `~/.lakon/log.jsonl`, which every `lakonai` call (shim wrappers + rule-prefixed commands) appends to on any agent — so it promotes new heavy commands automatically everywhere, throttled hourly. Claude Code additionally learns from the full session transcript (a wider window). Disable with `LAKON_NO_LEARN=1`.
|
|
343
348
|
|
|
344
349
|
¹ "Claude Code" covers **every** Claude Code frontend — terminal CLI, VS Code extension, JetBrains plugin, desktop app. All read the same `~/.claude/CLAUDE.md` + `~/.claude/settings.json`, so one install lights up all of them.
|
|
345
350
|
|
|
@@ -433,5 +438,5 @@ MIT. See [LICENSE](LICENSE).
|
|
|
433
438
|
---
|
|
434
439
|
|
|
435
440
|
<p align="center">
|
|
436
|
-
<
|
|
441
|
+
<strong>Speak less. Ship more.</strong>
|
|
437
442
|
</p>
|
package/bin/lakonai.js
CHANGED
|
@@ -98,6 +98,15 @@ function runAndFilter(cmd, args) {
|
|
|
98
98
|
filteredTokens: countTokensApprox(filtered),
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
+
// Auto-learning off the universal log (throttled hourly) — runs on EVERY agent,
|
|
102
|
+
// not just Claude Code's transcript. Never let it break the command.
|
|
103
|
+
try {
|
|
104
|
+
require('../src/learn').maybeLearnFromLog((c) => isSupported(c));
|
|
105
|
+
/* istanbul ignore next */
|
|
106
|
+
} catch {
|
|
107
|
+
// learning is best-effort
|
|
108
|
+
}
|
|
109
|
+
|
|
101
110
|
/* istanbul ignore next */
|
|
102
111
|
process.exit(child.status ?? 0);
|
|
103
112
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lakonai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.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",
|
package/src/install/platforms.js
CHANGED
|
@@ -81,7 +81,7 @@ const PLATFORMS = [
|
|
|
81
81
|
/* istanbul ignore next */
|
|
82
82
|
const suffixHook = hookResult.settingsMerged ? '+ PreToolUse hook' : `(hook: ${hookResult.note})`;
|
|
83
83
|
/* istanbul ignore next */
|
|
84
|
-
const suffixCmds = cmds.length ? `+ ${cmds.
|
|
84
|
+
const suffixCmds = cmds.length ? `+ ${cmds.length} slash command${cmds.length > 1 ? 's' : ''}` : '';
|
|
85
85
|
return [rulePath, suffixHook, suffixCmds].filter(Boolean).join(' ');
|
|
86
86
|
},
|
|
87
87
|
uninstall: ({ home }) => {
|
package/src/learn.js
CHANGED
|
@@ -131,6 +131,52 @@ function analyzeTranscript(transcriptPath, isBuiltin) {
|
|
|
131
131
|
promote(stats, isBuiltin);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
// Platform-agnostic learning. The transcript reader above is Claude-Code-only;
|
|
135
|
+
// this learns from `~/.lakon/log.jsonl` instead — populated by EVERY `lakonai`
|
|
136
|
+
// invocation (shim wrappers + rule-prefixed calls) on ANY agent. So auto-learning
|
|
137
|
+
// runs automatically everywhere, not just on Claude. Smaller observation window
|
|
138
|
+
// (only commands routed through lakonai), but no hook required.
|
|
139
|
+
function analyzeLog(isBuiltin) {
|
|
140
|
+
if (process.env.LAKON_NO_LEARN === '1' || process.env.LAKON_NO_TRACK === '1') return;
|
|
141
|
+
let text;
|
|
142
|
+
try {
|
|
143
|
+
text = fs.readFileSync(path.join(lakonHome(), 'log.jsonl'), 'utf8');
|
|
144
|
+
} catch {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const stats = {};
|
|
148
|
+
for (const line of text.split('\n')) {
|
|
149
|
+
if (!line.trim()) continue;
|
|
150
|
+
let e;
|
|
151
|
+
try {
|
|
152
|
+
e = JSON.parse(line);
|
|
153
|
+
} catch {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const cmd = e && typeof e.cmd === 'string' ? e.cmd : null;
|
|
157
|
+
if (!cmd || cmd === 'session' || isBuiltin(cmd)) continue;
|
|
158
|
+
const s = stats[cmd] || { count: 0, tokens: 0 };
|
|
159
|
+
s.count += 1;
|
|
160
|
+
s.tokens += e.raw || 0;
|
|
161
|
+
stats[cmd] = s;
|
|
162
|
+
}
|
|
163
|
+
if (Object.keys(stats).length) promote(stats, isBuiltin);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const LEARN_LOG_TTL_MS = 60 * 60 * 1000; // scan the log at most once per hour
|
|
167
|
+
|
|
168
|
+
// Throttled entry point for the per-call path (runAndFilter): scans the log at
|
|
169
|
+
// most hourly, so learning is automatic on every agent but costs nothing hot.
|
|
170
|
+
function maybeLearnFromLog(isBuiltin, now = Date.now()) {
|
|
171
|
+
if (process.env.LAKON_NO_LEARN === '1' || process.env.LAKON_NO_TRACK === '1') return false;
|
|
172
|
+
const stamp = path.join(lakonHome(), '.learn-log-stamp');
|
|
173
|
+
const last = Number(readJson(stamp, { t: 0 }).t) || 0;
|
|
174
|
+
if (last && now - last < LEARN_LOG_TTL_MS) return false; // last===0 ⇒ never run ⇒ run now
|
|
175
|
+
writeJson(stamp, { t: now });
|
|
176
|
+
analyzeLog(isBuiltin);
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
|
|
134
180
|
let _learnedCache;
|
|
135
181
|
function learnedCommands() {
|
|
136
182
|
if (_learnedCache === undefined) _learnedCache = new Set(readJson(learnedPath(), []));
|
|
@@ -149,6 +195,8 @@ module.exports = {
|
|
|
149
195
|
extractBashUsage,
|
|
150
196
|
promote,
|
|
151
197
|
analyzeTranscript,
|
|
198
|
+
analyzeLog,
|
|
199
|
+
maybeLearnFromLog,
|
|
152
200
|
learnedCommands,
|
|
153
201
|
isLearned,
|
|
154
202
|
_resetCache,
|