lakonai 0.8.0 → 0.10.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 CHANGED
@@ -196,6 +196,10 @@ 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) |
201
+ | `lakonai doctor` | Per-platform health: CLI on PATH, rule installed, hooks registered |
202
+ | `lakonai shell-init` / `shell-uninit` | Print an opt-in shell wrapper (auto-filter read-only cmds when `LAKON_SHELL=1`) |
199
203
  | `lakonai version` / `--version` / `-v` | Print the installed lakonai version |
200
204
 
201
205
  ---
@@ -230,6 +234,23 @@ auto-filter is near-lossless (collapses repeated/blank lines, truncates only
230
234
  with an announced marker) so it never hides a real error. Disable with
231
235
  `LAKON_NO_LEARN=1`.
232
236
 
237
+ ### Terse intensity + per-turn reinforcement
238
+
239
+ `lakonai mode lite|full|ultra` sets how terse the model is (default `full`;
240
+ `ultra` abbreviates and uses arrows for causality). A `UserPromptSubmit` hook
241
+ re-injects the active rule every turn so the model doesn't drift back to verbose
242
+ prose mid-session (opt out `LAKON_NO_REINFORCE=1`). Code, identifiers, paths and
243
+ security warnings stay verbatim at every level.
244
+
245
+ ### Compress memory files
246
+
247
+ `lakonai compress <file>` shrinks the markdown an agent reloads every session
248
+ (CLAUDE.md, notes). Default is **offline and near-lossless** (collapses blank
249
+ lines / trailing whitespace, never touches code or words). `--llm` rewrites the
250
+ prose tersely using **your existing `claude` CLI** (`claude --print` — no separate
251
+ API key, no new dependency); `--dry-run` previews the savings. The original is
252
+ backed up to `<file>.bak`.
253
+
233
254
  ### Read tool guard (Claude Code)
234
255
 
235
256
  The `Read` hook automatically:
@@ -281,13 +302,34 @@ Each profile gets its own independent install. `lakonai uninstall` / `lakonai re
281
302
 
282
303
  | Agent | Scope | What `lakonai install` writes |
283
304
  |-----------------|----------|--------------------------------------------------------------------------------------------------------|
284
- | Claude Code¹ | global | Rule block in `~/.claude/CLAUDE.md` + **five** hooks in `~/.claude/settings.json` (`PreToolUse`: Bash rewrite + Read guard + Grep guard; `Stop`: session-usage log; `SessionStart`: update notify) + `/lakonai:gain` `/lakonai:reset` `/lakonai:inspect` slash commands |
305
+ | 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
306
  | Codex CLI | global | Rule block in `~/.codex/AGENTS.md` |
286
307
  | Gemini CLI | global | Rule block in `~/.gemini/GEMINI.md` |
287
308
  | Cursor | project² | `.cursor/rules/lakonai.mdc` in the current dir |
288
309
  | Windsurf | project² | `.windsurf/rules/lakonai.md` in the current dir |
289
310
  | Cline | project² | `.clinerules/lakonai.md` in the current dir |
290
311
 
312
+ ### What each agent actually gets (honest capability matrix)
313
+
314
+ The powerful input-side features (shell-output filtering, Read/Grep guards,
315
+ auto-learning, per-turn reinforcement) are **hooks — they run on Claude Code
316
+ only**. Everywhere else, lakonai delivers the terse rule, and shell filtering
317
+ happens by **the model prefixing `lakonai`** (the rule tells it to) or via the
318
+ opt-in `lakonai shell-init` wrapper. Honest matrix:
319
+
320
+ | Agent | Terse rule | Shell filter | Read/Grep guard | Auto-learning | Reinforcement | `/lakonai:*` + subagents |
321
+ |-------------|:---------:|-------------------------|:---------------:|:-------------:|:-------------:|:-------------:|
322
+ | Claude Code | ✅ | ✅ automatic (hook) | ✅ | ✅ | ✅ | ✅ |
323
+ | Codex CLI | ✅ | ⚠️ via rule / shell-init | ❌ | ❌ | ❌ | ❌ |
324
+ | Cursor | ✅ | ⚠️ via rule / shell-init | ❌ (rule) | ❌ | ❌ | ❌ |
325
+ | Windsurf | ✅ | ⚠️ via rule / shell-init | ❌ (rule) | ❌ | ❌ | ❌ |
326
+ | Cline | ✅ | ⚠️ via rule / shell-init | ❌ (rule) | ❌ | ❌ | ❌ |
327
+ | Gemini CLI | ✅ | ⚠️ via rule / shell-init | ❌ (rule) | ❌ | ❌ | ❌ |
328
+
329
+ ⚠️ = the model has to cooperate (prefix `lakonai`) or you opt into the shell
330
+ wrapper. Run `lakonai doctor` to see, per platform, what's actually active on your
331
+ machine.
332
+
291
333
  ¹ "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.
292
334
 
293
335
  ² Project-scoped tools only read rules from the current directory, so `lakonai install` skips them by default to avoid scattering files across your repos. Add `--here` (or use `--project`) when you actually want them in the current dir.
@@ -358,7 +400,7 @@ npm run test:coverage:check # enforce the coverage threshold
358
400
  node bin/lakonai.js --help
359
401
  ```
360
402
 
361
- Suite: **270 tests**. Coverage gate: **100% lines / 100% branches / 100% functions / 100% statements**. Zero runtime dependencies. Node ≥ 18.
403
+ Suite: **294 tests**. Coverage gate: **100% lines / 100% branches / 100% functions / 100% statements**. Zero runtime dependencies. Node ≥ 18.
362
404
 
363
405
  ---
364
406
 
package/bin/lakonai.js CHANGED
@@ -172,6 +172,51 @@ 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
+ }
201
+ if (first === 'doctor') {
202
+ const doctor = require('../src/doctor');
203
+ process.stdout.write(doctor.format(doctor.report()));
204
+ return;
205
+ }
206
+ if (first === 'shell-init') {
207
+ const { snippet } = require('../src/shell');
208
+ process.stdout.write(
209
+ '# Add to your shell profile (~/.bashrc / ~/.zshrc), then set LAKON_SHELL=1\n' +
210
+ '# in the env your agent runs commands in. Experimental — read-only commands only.\n' +
211
+ snippet()
212
+ );
213
+ return;
214
+ }
215
+ if (first === 'shell-uninit') {
216
+ const { MARK_BEGIN, MARK_END } = require('../src/shell');
217
+ process.stdout.write(`Remove the block between\n ${MARK_BEGIN}\n ${MARK_END}\nfrom your shell profile (or unset LAKON_SHELL).\n`);
218
+ return;
219
+ }
175
220
 
176
221
  runAndFilter(first, rest);
177
222
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lakonai",
3
- "version": "0.8.0",
3
+ "version": "0.10.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",
@@ -47,7 +47,10 @@
47
47
  "scripts": {
48
48
  "test": "jest",
49
49
  "test:coverage": "jest --coverage",
50
- "test:coverage:check": "jest --coverage"
50
+ "test:coverage:check": "jest --coverage",
51
+ "bench": "node scripts/bench.js",
52
+ "bench:output": "node scripts/bench-output.js",
53
+ "bench:measure": "node scripts/bench-measure.js"
51
54
  },
52
55
  "engines": {
53
56
  "node": ">=18"
Binary file
package/src/doctor.js ADDED
@@ -0,0 +1,60 @@
1
+ 'use strict';
2
+
3
+ // `lakonai doctor` — per-platform health check: is the CLI on PATH, is the rule
4
+ // installed, and (for Claude Code) are the hooks registered? Gives an honest,
5
+ // per-platform view of what's actually active.
6
+
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const { spawnSync } = require('child_process');
10
+ const platforms = require('./install/platforms');
11
+ const { homedir, claudeConfigDir } = require('./install/paths');
12
+
13
+ // Resolve the `lakonai` binary via PATH (so the agent's shell can call it).
14
+ /* istanbul ignore next -- resolution depends on whether lakonai is globally linked */
15
+ function cliOnPath() {
16
+ const which = process.platform === 'win32' ? 'where' : 'which';
17
+ const r = spawnSync(which, ['lakonai'], { encoding: 'utf8' });
18
+ return r.status === 0 && r.stdout ? r.stdout.trim().split(/\r?\n/)[0] || null : null;
19
+ }
20
+
21
+ function hooksInstalled(home) {
22
+ try {
23
+ const p = path.join(claudeConfigDir(home), 'settings.json');
24
+ const data = JSON.parse(fs.readFileSync(p, 'utf8'));
25
+ return JSON.stringify(data.hooks || {}).includes('lakon-');
26
+ } catch {
27
+ return false;
28
+ }
29
+ }
30
+
31
+ function report(home) {
32
+ const h = home || homedir();
33
+ const rows = platforms.list().map((p) => {
34
+ const row = {
35
+ id: p.id,
36
+ label: p.label,
37
+ detected: !!p.detect(h),
38
+ ruleInstalled: platforms.hasBlock(p.rulePath(h)),
39
+ };
40
+ if (p.hasHooks) row.hooksInstalled = hooksInstalled(h);
41
+ return row;
42
+ });
43
+ return { cli: cliOnPath(), platforms: rows };
44
+ }
45
+
46
+ const mark = (b) => (b ? '✅' : '❌');
47
+
48
+ function format(rep) {
49
+ const lines = ['lakonai doctor', '──────────────'];
50
+ lines.push(`CLI on PATH: ${rep.cli ? `✅ ${rep.cli}` : '❌ not found — run `npm i -g lakonai`'}`);
51
+ lines.push('');
52
+ for (const p of rep.platforms) {
53
+ const bits = [`detected ${mark(p.detected)}`, `rule ${mark(p.ruleInstalled)}`];
54
+ if (p.hooksInstalled !== undefined) bits.push(`hooks ${mark(p.hooksInstalled)}`);
55
+ lines.push(` ${p.label.padEnd(26)} ${bits.join(' ')}`);
56
+ }
57
+ return lines.join('\n') + '\n';
58
+ }
59
+
60
+ module.exports = { report, format, cliOnPath, hooksInstalled };
@@ -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 };
@@ -0,0 +1,100 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { claudeConfigDir } = require('./paths');
6
+
7
+ // Terse subagents (cavecrew-style) that return compact, structured output so a
8
+ // delegation costs the main thread far fewer tokens. Claude Code only.
9
+ const AGENTS = [
10
+ {
11
+ name: 'lakonai-investigator',
12
+ body: `---
13
+ name: lakonai-investigator
14
+ description: Locate code (definitions, callers, uses). Read-only. Returns terse path:line findings.
15
+ tools: Bash, Read, Glob, Grep
16
+ model: haiku
17
+ ---
18
+
19
+ Locate code and report tersely. Output contract:
20
+
21
+ \`\`\`
22
+ path:line — \`symbol\` — note
23
+ totals: N defs, M refs.
24
+ \`\`\`
25
+
26
+ Or \`No match.\` Maximum terseness, symbol-first. No prose, no preamble.
27
+ `,
28
+ },
29
+ {
30
+ name: 'lakonai-builder',
31
+ body: `---
32
+ name: lakonai-builder
33
+ description: Surgical 1-2 file edit with verification. Refuses 3+ file scope. Returns a terse diff summary.
34
+ tools: Bash, Read, Edit
35
+ model: haiku
36
+ ---
37
+
38
+ Make a surgical edit (≤2 files) and verify it. Output contract:
39
+
40
+ \`\`\`
41
+ path:line-range — change ≤10 words.
42
+ verified: re-read OK | mismatch @ path:line.
43
+ \`\`\`
44
+
45
+ Terminal replies when you can't proceed: \`too-big.\` / \`needs-confirm.\` / \`ambiguous.\`
46
+ `,
47
+ },
48
+ {
49
+ name: 'lakonai-reviewer',
50
+ body: `---
51
+ name: lakonai-reviewer
52
+ description: Review a diff/file for bugs. No architecture opinions. One terse line per finding.
53
+ tools: Bash, Read, Grep
54
+ model: haiku
55
+ ---
56
+
57
+ Review for bugs. One line per finding. Output contract:
58
+
59
+ \`\`\`
60
+ path:line: <emoji> <sev>: problem. fix.
61
+ totals: N🔴 N🟡 N🔵 N❓
62
+ \`\`\`
63
+
64
+ Severity: 🔴 bug / 🟡 risk / 🔵 nit / ❓ q. Or \`No issues.\` Switch to prose for
65
+ security (CVE-class) findings.
66
+ `,
67
+ },
68
+ ];
69
+
70
+ function agentsDir(home) {
71
+ return path.join(claudeConfigDir(home), 'agents');
72
+ }
73
+
74
+ function installAgents(home) {
75
+ const dir = agentsDir(home);
76
+ fs.mkdirSync(dir, { recursive: true });
77
+ const written = [];
78
+ for (const a of AGENTS) {
79
+ fs.writeFileSync(path.join(dir, `${a.name}.md`), a.body, 'utf8');
80
+ written.push(a.name);
81
+ }
82
+ return written;
83
+ }
84
+
85
+ function uninstallAgents(home) {
86
+ const dir = agentsDir(home);
87
+ const removed = [];
88
+ for (const a of AGENTS) {
89
+ const p = path.join(dir, `${a.name}.md`);
90
+ try {
91
+ fs.unlinkSync(p);
92
+ removed.push(p);
93
+ } catch {
94
+ /* not installed */
95
+ }
96
+ }
97
+ return removed;
98
+ }
99
+
100
+ module.exports = { installAgents, uninstallAgents, agentsDir, AGENTS };
@@ -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
- fs.copyFileSync(h.src, dest);
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);
@@ -5,6 +5,7 @@ const path = require('path');
5
5
  const { backupFile, restoreAllBackups } = require('./backup');
6
6
  const { installHook, uninstallHook } = require('./claude-hook');
7
7
  const { installCommands, uninstallCommands } = require('./claude-commands');
8
+ const { installAgents, uninstallAgents } = require('./claude-agents');
8
9
  const { claudeConfigDir } = require('./paths');
9
10
 
10
11
  const MARK_BEGIN = '<!-- lakonai:begin -->';
@@ -69,11 +70,14 @@ const PLATFORMS = [
69
70
  id: 'claude-code',
70
71
  label: 'Claude Code',
71
72
  scope: 'global',
73
+ rulePath: (home) => path.join(claudeConfigDir(home), 'CLAUDE.md'),
74
+ hasHooks: true,
72
75
  detect: (home) => !!process.env.CLAUDE_CONFIG_DIR || dirExists(claudeConfigDir(home)),
73
76
  install: ({ home, rule, id }) => {
74
77
  const rulePath = upsertBlock(id, path.join(claudeConfigDir(home), 'CLAUDE.md'), rule);
75
78
  const hookResult = installHook(home);
76
79
  const cmds = installCommands(home);
80
+ installAgents(home);
77
81
  /* istanbul ignore next */
78
82
  const suffixHook = hookResult.settingsMerged ? '+ PreToolUse hook' : `(hook: ${hookResult.note})`;
79
83
  /* istanbul ignore next */
@@ -83,6 +87,7 @@ const PLATFORMS = [
83
87
  uninstall: ({ home }) => {
84
88
  uninstallHook(home);
85
89
  uninstallCommands(home);
90
+ uninstallAgents(home);
86
91
  return stripBlock(path.join(claudeConfigDir(home), 'CLAUDE.md'));
87
92
  },
88
93
  },
@@ -90,6 +95,7 @@ const PLATFORMS = [
90
95
  id: 'codex',
91
96
  label: 'Codex CLI',
92
97
  scope: 'global',
98
+ rulePath: (home) => path.join(home, '.codex', 'AGENTS.md'),
93
99
  detect: (home) => dirExists(path.join(home, '.codex')),
94
100
  install: ({ home, rule, id }) => upsertBlock(id, path.join(home, '.codex', 'AGENTS.md'), rule),
95
101
  uninstall: ({ home }) => stripBlock(path.join(home, '.codex', 'AGENTS.md')),
@@ -98,6 +104,7 @@ const PLATFORMS = [
98
104
  id: 'cursor',
99
105
  label: 'Cursor (per-repo rule)',
100
106
  scope: 'project',
107
+ rulePath: () => path.join(process.cwd(), '.cursor', 'rules', 'lakonai.mdc'),
101
108
  detect: () => fs.existsSync(path.join(process.cwd(), '.cursor')),
102
109
  install: ({ rule, id }) => upsertBlock(id, path.join(process.cwd(), '.cursor', 'rules', 'lakonai.mdc'), rule),
103
110
  uninstall: () => {
@@ -109,6 +116,7 @@ const PLATFORMS = [
109
116
  id: 'windsurf',
110
117
  label: 'Windsurf (per-repo rule)',
111
118
  scope: 'project',
119
+ rulePath: () => path.join(process.cwd(), '.windsurf', 'rules', 'lakonai.md'),
112
120
  detect: () => fs.existsSync(path.join(process.cwd(), '.windsurf')),
113
121
  install: ({ rule, id }) => upsertBlock(id, path.join(process.cwd(), '.windsurf', 'rules', 'lakonai.md'), rule),
114
122
  uninstall: () => {
@@ -120,6 +128,7 @@ const PLATFORMS = [
120
128
  id: 'cline',
121
129
  label: 'Cline (per-repo rule)',
122
130
  scope: 'project',
131
+ rulePath: () => path.join(process.cwd(), '.clinerules', 'lakonai.md'),
123
132
  detect: () => fs.existsSync(path.join(process.cwd(), '.clinerules')),
124
133
  install: ({ rule, id }) => upsertBlock(id, path.join(process.cwd(), '.clinerules', 'lakonai.md'), rule),
125
134
  uninstall: () => {
@@ -131,10 +140,11 @@ const PLATFORMS = [
131
140
  id: 'gemini',
132
141
  label: 'Gemini CLI',
133
142
  scope: 'global',
143
+ rulePath: (home) => path.join(home, '.gemini', 'GEMINI.md'),
134
144
  detect: (home) => dirExists(path.join(home, '.gemini')),
135
145
  install: ({ home, rule, id }) => upsertBlock(id, path.join(home, '.gemini', 'GEMINI.md'), rule),
136
146
  uninstall: ({ home }) => stripBlock(path.join(home, '.gemini', 'GEMINI.md')),
137
147
  },
138
148
  ];
139
149
 
140
- module.exports = { list: () => PLATFORMS, revertPlatform };
150
+ module.exports = { list: () => PLATFORMS, revertPlatform, hasBlock };
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 };
@@ -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 instructions where ambiguity could cause harm
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
- Resume terse mode after.
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
 
package/src/shell.js ADDED
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ // Optional shell wrapper — the only way to get AUTOMATIC filtering on platforms
4
+ // without a hook API (Cursor/Windsurf/Cline/Gemini/Copilot). It defines shell
5
+ // functions that route a conservative, read-only, output-only set of commands
6
+ // through `lakonai`. Gated behind $LAKON_SHELL so it NEVER affects an interactive
7
+ // terminal unless the user opts in (e.g. exports LAKON_SHELL=1 in the env their
8
+ // agent runs commands in). Experimental: wrapping changes piped output, so the
9
+ // set is deliberately limited to safe commands.
10
+
11
+ const MARK_BEGIN = '# lakonai:shell:begin';
12
+ const MARK_END = '# lakonai:shell:end';
13
+
14
+ // Read-only, output-only commands where filtering is safe. Deliberately excludes
15
+ // git (commit opens an editor), tail (-f streams), and anything interactive.
16
+ const WRAPPED = ['ls', 'grep', 'rg', 'ag', 'find'];
17
+
18
+ function snippet() {
19
+ const body = WRAPPED.map(
20
+ (c) => ` ${c}() { command lakonai ${c} "$@"; }`
21
+ ).join('\n');
22
+ return [
23
+ MARK_BEGIN,
24
+ '# Auto-filter read-only commands through lakonai when LAKON_SHELL is set.',
25
+ '# Remove this block (or unset LAKON_SHELL) to disable.',
26
+ 'if [ -n "$LAKON_SHELL" ]; then',
27
+ body,
28
+ 'fi',
29
+ MARK_END,
30
+ '',
31
+ ].join('\n');
32
+ }
33
+
34
+ module.exports = { snippet, WRAPPED, MARK_BEGIN, MARK_END };