lakonai 0.8.0 → 0.9.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 +21 -2
- package/bin/lakonai.js +26 -0
- package/package.json +1 -1
- package/src/compress.js +0 -0
- package/src/hooks/prompt-reinforce.js +51 -0
- package/src/install/claude-commands.js +29 -0
- package/src/install/claude-hook.js +13 -1
- package/src/mode.js +47 -0
- package/src/rules/lakonai.md +17 -4
package/README.md
CHANGED
|
@@ -196,6 +196,8 @@ saved: 85%
|
|
|
196
196
|
| `lakonai gain` | Show savings by hour / day / week / month / all-time + session totals |
|
|
197
197
|
| `lakonai inspect <cmd>` | Run once and show raw-vs-filtered (no tracking) |
|
|
198
198
|
| `lakonai reset` | Wipe the savings log |
|
|
199
|
+
| `lakonai mode [lite\|full\|ultra]` | Show or set terse intensity (default `full`) |
|
|
200
|
+
| `lakonai compress <file> [--llm] [--dry-run]` | Shrink a memory `.md` (offline heuristic, or `--llm` via your `claude` CLI) |
|
|
199
201
|
| `lakonai version` / `--version` / `-v` | Print the installed lakonai version |
|
|
200
202
|
|
|
201
203
|
---
|
|
@@ -230,6 +232,23 @@ auto-filter is near-lossless (collapses repeated/blank lines, truncates only
|
|
|
230
232
|
with an announced marker) so it never hides a real error. Disable with
|
|
231
233
|
`LAKON_NO_LEARN=1`.
|
|
232
234
|
|
|
235
|
+
### Terse intensity + per-turn reinforcement
|
|
236
|
+
|
|
237
|
+
`lakonai mode lite|full|ultra` sets how terse the model is (default `full`;
|
|
238
|
+
`ultra` abbreviates and uses arrows for causality). A `UserPromptSubmit` hook
|
|
239
|
+
re-injects the active rule every turn so the model doesn't drift back to verbose
|
|
240
|
+
prose mid-session (opt out `LAKON_NO_REINFORCE=1`). Code, identifiers, paths and
|
|
241
|
+
security warnings stay verbatim at every level.
|
|
242
|
+
|
|
243
|
+
### Compress memory files
|
|
244
|
+
|
|
245
|
+
`lakonai compress <file>` shrinks the markdown an agent reloads every session
|
|
246
|
+
(CLAUDE.md, notes). Default is **offline and near-lossless** (collapses blank
|
|
247
|
+
lines / trailing whitespace, never touches code or words). `--llm` rewrites the
|
|
248
|
+
prose tersely using **your existing `claude` CLI** (`claude --print` — no separate
|
|
249
|
+
API key, no new dependency); `--dry-run` previews the savings. The original is
|
|
250
|
+
backed up to `<file>.bak`.
|
|
251
|
+
|
|
233
252
|
### Read tool guard (Claude Code)
|
|
234
253
|
|
|
235
254
|
The `Read` hook automatically:
|
|
@@ -281,7 +300,7 @@ Each profile gets its own independent install. `lakonai uninstall` / `lakonai re
|
|
|
281
300
|
|
|
282
301
|
| Agent | Scope | What `lakonai install` writes |
|
|
283
302
|
|-----------------|----------|--------------------------------------------------------------------------------------------------------|
|
|
284
|
-
| Claude Code¹ | global | Rule block in `~/.claude/CLAUDE.md` + **
|
|
303
|
+
| Claude Code¹ | global | Rule block in `~/.claude/CLAUDE.md` + **six** hooks in `~/.claude/settings.json` (`PreToolUse`: Bash rewrite + Read guard + Grep guard; `Stop`: session-usage log + auto-learning; `SessionStart`: update notify; `UserPromptSubmit`: per-turn terse reinforcement) + `/lakonai:gain` `/lakonai:reset` `/lakonai:inspect` `/lakonai:commit` `/lakonai:review` slash commands |
|
|
285
304
|
| Codex CLI | global | Rule block in `~/.codex/AGENTS.md` |
|
|
286
305
|
| Gemini CLI | global | Rule block in `~/.gemini/GEMINI.md` |
|
|
287
306
|
| Cursor | project² | `.cursor/rules/lakonai.mdc` in the current dir |
|
|
@@ -358,7 +377,7 @@ npm run test:coverage:check # enforce the coverage threshold
|
|
|
358
377
|
node bin/lakonai.js --help
|
|
359
378
|
```
|
|
360
379
|
|
|
361
|
-
Suite: **
|
|
380
|
+
Suite: **285 tests**. Coverage gate: **100% lines / 100% branches / 100% functions / 100% statements**. Zero runtime dependencies. Node ≥ 18.
|
|
362
381
|
|
|
363
382
|
---
|
|
364
383
|
|
package/bin/lakonai.js
CHANGED
|
@@ -172,6 +172,32 @@ async function main() {
|
|
|
172
172
|
process.stdout.write(ok ? 'lakonai: log cleared\n' : 'lakonai: nothing to clear\n');
|
|
173
173
|
return;
|
|
174
174
|
}
|
|
175
|
+
if (first === 'mode') {
|
|
176
|
+
const { getMode, setMode, MODES } = require('../src/mode');
|
|
177
|
+
if (!rest.length) {
|
|
178
|
+
process.stdout.write(`lakonai mode: ${getMode()}\n`);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const m = setMode(rest[0]);
|
|
182
|
+
process.stdout.write(
|
|
183
|
+
m ? `lakonai mode set to ${m}\n` : `lakonai: unknown mode "${rest[0]}" (use ${MODES.join('/')})\n`
|
|
184
|
+
);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (first === 'compress') {
|
|
188
|
+
const { compressFile } = require('../src/compress');
|
|
189
|
+
const llm = rest.includes('--llm');
|
|
190
|
+
const dryRun = rest.includes('--dry-run');
|
|
191
|
+
const file = rest.find((a) => !a.startsWith('--'));
|
|
192
|
+
if (!file) {
|
|
193
|
+
process.stderr.write('lakonai compress: missing file\n');
|
|
194
|
+
process.exit(2);
|
|
195
|
+
}
|
|
196
|
+
const r = compressFile(file, { llm, dryRun });
|
|
197
|
+
const tail = r.written ? ' [written; backup .bak]' : ' [dry-run]';
|
|
198
|
+
process.stdout.write(`${r.file}: ${r.before} → ${r.after} tokens (-${r.saved}%, ${r.mode})${tail}\n`);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
175
201
|
|
|
176
202
|
runAndFilter(first, rest);
|
|
177
203
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lakonai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
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/compress.js
ADDED
|
Binary file
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// UserPromptSubmit hook: re-injects a short terse-mode reminder every turn.
|
|
5
|
+
// The SessionStart rule is injected once, but competing instructions from other
|
|
6
|
+
// plugins/long conversations make the model drift back to verbose prose. This
|
|
7
|
+
// keeps lakonai's terse rule in the model's attention on each user message.
|
|
8
|
+
// Opt out with LAKON_NO_REINFORCE=1.
|
|
9
|
+
|
|
10
|
+
const { getMode } = require('../mode');
|
|
11
|
+
|
|
12
|
+
const REMINDERS = {
|
|
13
|
+
lite: 'lakonai (lite): no filler/hedging; keep full sentences. Code, security warnings and irreversible-action confirmations: normal prose.',
|
|
14
|
+
full: 'lakonai (full): drop preamble/articles/filler, fragments OK, bullets over prose, keep identifiers/paths/errors verbatim. Code, security warnings and irreversible-action confirmations: normal prose.',
|
|
15
|
+
ultra: 'lakonai (ultra): maximum terseness — abbreviate, arrows for causality (X→Y), drop conjunctions. Code, security warnings and irreversible-action confirmations: normal prose.',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function buildReminder(mode) {
|
|
19
|
+
return REMINDERS[mode] || REMINDERS.full;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* istanbul ignore next */
|
|
23
|
+
async function readStdin() {
|
|
24
|
+
let raw = '';
|
|
25
|
+
process.stdin.setEncoding('utf8');
|
|
26
|
+
for await (const chunk of process.stdin) raw += chunk;
|
|
27
|
+
return raw;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* istanbul ignore next */
|
|
31
|
+
async function main() {
|
|
32
|
+
try {
|
|
33
|
+
await readStdin();
|
|
34
|
+
if (process.env.LAKON_NO_REINFORCE === '1') process.exit(0);
|
|
35
|
+
const response = {
|
|
36
|
+
hookSpecificOutput: {
|
|
37
|
+
hookEventName: 'UserPromptSubmit',
|
|
38
|
+
additionalContext: buildReminder(getMode()),
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
process.stdout.write(JSON.stringify(response));
|
|
42
|
+
process.exit(0);
|
|
43
|
+
} catch {
|
|
44
|
+
process.exit(0);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* istanbul ignore next */
|
|
49
|
+
if (require.main === module) main();
|
|
50
|
+
|
|
51
|
+
module.exports = { buildReminder, REMINDERS };
|
|
@@ -34,6 +34,35 @@ allowed-tools: Bash(lakonai inspect:*), Bash(lakon inspect:*)
|
|
|
34
34
|
---
|
|
35
35
|
|
|
36
36
|
Run \`lakonai inspect $ARGUMENTS\` and show the output verbatim.
|
|
37
|
+
`,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'commit',
|
|
41
|
+
body: `---
|
|
42
|
+
description: Write a terse Conventional Commit for the staged changes.
|
|
43
|
+
allowed-tools: Bash(git diff:*), Bash(git status:*), Bash(git commit:*)
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
Write a commit message in terse lakonai style:
|
|
47
|
+
- Conventional Commits: \`type(scope): subject\`. Subject imperative, ≤50 chars, no trailing period.
|
|
48
|
+
- Drop "this commit does X", "I"/"we", "now"/"currently" — the diff says what changed.
|
|
49
|
+
- Body only for the non-obvious *why*, breaking changes, or migration notes.
|
|
50
|
+
- Reference issues at the end (\`Closes #42\`). No AI attribution lines.
|
|
51
|
+
`,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'review',
|
|
55
|
+
body: `---
|
|
56
|
+
description: Review the current diff with one terse line per finding.
|
|
57
|
+
allowed-tools: Bash(git diff:*), Bash(lakonai git diff:*)
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
Review the diff. One line per finding, terse lakonai style:
|
|
61
|
+
- Format: \`<file>:L<line>: <severity>: <problem>. <fix>.\`
|
|
62
|
+
- Severity prefix: 🔴 bug / 🟡 risk / 🔵 nit / ❓ q.
|
|
63
|
+
- Keep exact line numbers and \`symbol\` names; give a concrete fix and the *why*.
|
|
64
|
+
- Drop "I noticed that…", "It seems…", "You might want to…".
|
|
65
|
+
- Switch to normal prose for security (CVE-class) findings.
|
|
37
66
|
`,
|
|
38
67
|
},
|
|
39
68
|
];
|
|
@@ -36,6 +36,12 @@ const HOOKS = [
|
|
|
36
36
|
event: 'SessionStart',
|
|
37
37
|
matcher: null,
|
|
38
38
|
},
|
|
39
|
+
{
|
|
40
|
+
basename: 'lakon-prompt-reinforce.js',
|
|
41
|
+
src: path.join(__dirname, '..', 'hooks', 'prompt-reinforce.js'),
|
|
42
|
+
event: 'UserPromptSubmit',
|
|
43
|
+
matcher: null,
|
|
44
|
+
},
|
|
39
45
|
];
|
|
40
46
|
|
|
41
47
|
const SUPPORT_FILES = [
|
|
@@ -124,7 +130,13 @@ function installHook(home) {
|
|
|
124
130
|
for (const h of HOOKS) {
|
|
125
131
|
const dest = hookDest(home, h.basename);
|
|
126
132
|
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
127
|
-
|
|
133
|
+
// Launcher: run the packaged hook in place (as the main module) so its
|
|
134
|
+
// relative requires (../filters, ../learn, ../mode) resolve inside the
|
|
135
|
+
// package. A flat copy would break those requires.
|
|
136
|
+
fs.writeFileSync(
|
|
137
|
+
dest,
|
|
138
|
+
`#!/usr/bin/env node\n// lakonai hook launcher (generated)\nrequire('module')._load(${JSON.stringify(h.src)}, null, true);\n`
|
|
139
|
+
);
|
|
128
140
|
fs.chmodSync(dest, 0o755);
|
|
129
141
|
mergeHook(data, h, dest);
|
|
130
142
|
installed.push(dest);
|
package/src/mode.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Terse intensity mode (caveman-style levels), persisted at ~/.lakon/mode.
|
|
4
|
+
// lite — no filler/hedging, keep full sentences
|
|
5
|
+
// full — drop articles/filler/preamble, fragments OK (default)
|
|
6
|
+
// ultra — maximum terseness: abbreviate, arrows for causality, drop conjunctions
|
|
7
|
+
// Resolution order: $LAKON_MODE (if valid) -> ~/.lakon/mode -> 'full'.
|
|
8
|
+
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const os = require('os');
|
|
12
|
+
|
|
13
|
+
const MODES = ['lite', 'full', 'ultra'];
|
|
14
|
+
const DEFAULT_MODE = 'full';
|
|
15
|
+
|
|
16
|
+
/* istanbul ignore next */
|
|
17
|
+
function lakonHome() {
|
|
18
|
+
return process.env.LAKON_HOME || path.join(os.homedir(), '.lakon');
|
|
19
|
+
}
|
|
20
|
+
const modePath = () => path.join(lakonHome(), 'mode');
|
|
21
|
+
|
|
22
|
+
function getMode() {
|
|
23
|
+
const env = process.env.LAKON_MODE;
|
|
24
|
+
if (env && MODES.includes(env)) return env;
|
|
25
|
+
try {
|
|
26
|
+
const m = fs.readFileSync(modePath(), 'utf8').trim();
|
|
27
|
+
if (MODES.includes(m)) return m;
|
|
28
|
+
} catch {
|
|
29
|
+
// no mode file -> default
|
|
30
|
+
}
|
|
31
|
+
return DEFAULT_MODE;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function setMode(mode) {
|
|
35
|
+
if (!MODES.includes(mode)) return null;
|
|
36
|
+
try {
|
|
37
|
+
fs.mkdirSync(lakonHome(), { recursive: true });
|
|
38
|
+
fs.writeFileSync(modePath(), mode);
|
|
39
|
+
return mode;
|
|
40
|
+
/* istanbul ignore next */
|
|
41
|
+
} catch {
|
|
42
|
+
/* istanbul ignore next */
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = { getMode, setMode, MODES, DEFAULT_MODE, modePath };
|
package/src/rules/lakonai.md
CHANGED
|
@@ -11,16 +11,29 @@ You are operating in **lakonai mode** (named for Lakonía — the region of anci
|
|
|
11
11
|
5. **One short line for what you did.** Not a paragraph. The diff speaks for itself.
|
|
12
12
|
6. **Keep precision.** Identifiers, file paths, line numbers, error messages — verbatim. Never compress these.
|
|
13
13
|
|
|
14
|
+
## Intensity levels
|
|
15
|
+
|
|
16
|
+
Set with `lakonai mode <level>` (default `full`). The active level is reinforced
|
|
17
|
+
each turn by a `UserPromptSubmit` hook.
|
|
18
|
+
|
|
19
|
+
- **lite** — no filler/hedging, but keep articles and full sentences. Professional, tight.
|
|
20
|
+
- **full** (default) — drop articles/preamble/filler, fragments OK, bullets over prose.
|
|
21
|
+
- **ultra** — maximum terseness: abbreviate (DB/auth/config), arrows for causality (X → Y), drop conjunctions.
|
|
22
|
+
|
|
23
|
+
Code, identifiers, paths, line numbers and error messages are **always** verbatim, at every level.
|
|
24
|
+
|
|
14
25
|
## When to drop the style (auto-clarity)
|
|
15
26
|
|
|
16
|
-
Switch to normal prose for:
|
|
27
|
+
Switch to normal prose — at any level — for:
|
|
17
28
|
|
|
18
|
-
- Security warnings or destructive-action confirmations
|
|
19
|
-
- Multi-step
|
|
29
|
+
- Security warnings or destructive/irreversible-action confirmations
|
|
30
|
+
- Multi-step sequences where fragment order or an omitted conjunction could be misread
|
|
31
|
+
- Cases where compressing would itself create technical ambiguity
|
|
20
32
|
- The user is confused or repeating the same question
|
|
21
33
|
- The user explicitly asks for an explanation
|
|
22
34
|
|
|
23
|
-
|
|
35
|
+
Code, commit messages and PR descriptions are written normally regardless.
|
|
36
|
+
Resume terse mode after the clear part is done.
|
|
24
37
|
|
|
25
38
|
## Examples
|
|
26
39
|
|