lakonai 0.9.0 → 0.11.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 +43 -1
- package/bin/lakonai.js +24 -0
- package/package.json +5 -2
- package/src/doctor.js +60 -0
- package/src/install/claude-agents.js +100 -0
- package/src/install/platforms.js +11 -1
- package/src/shell.js +34 -0
- package/src/shrink.js +0 -0
package/README.md
CHANGED
|
@@ -198,6 +198,9 @@ saved: 85%
|
|
|
198
198
|
| `lakonai reset` | Wipe the savings log |
|
|
199
199
|
| `lakonai mode [lite\|full\|ultra]` | Show or set terse intensity (default `full`) |
|
|
200
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`) |
|
|
203
|
+
| `lakonai shrink <mcp-server-cmd>` | MCP proxy: compress tool/prompt/resource descriptions before they hit context |
|
|
201
204
|
| `lakonai version` / `--version` / `-v` | Print the installed lakonai version |
|
|
202
205
|
|
|
203
206
|
---
|
|
@@ -249,6 +252,24 @@ prose tersely using **your existing `claude` CLI** (`claude --print` — no sepa
|
|
|
249
252
|
API key, no new dependency); `--dry-run` previews the savings. The original is
|
|
250
253
|
backed up to `<file>.bak`.
|
|
251
254
|
|
|
255
|
+
### Shrink MCP tool descriptions
|
|
256
|
+
|
|
257
|
+
If you use MCP servers, their tool/prompt/resource **descriptions** load into
|
|
258
|
+
context every session. Wrap a server with `lakonai shrink` to compress those
|
|
259
|
+
descriptions (offline, regex) while leaving requests and tool-call results
|
|
260
|
+
untouched:
|
|
261
|
+
|
|
262
|
+
```jsonc
|
|
263
|
+
{
|
|
264
|
+
"mcpServers": {
|
|
265
|
+
"fs": {
|
|
266
|
+
"command": "lakonai",
|
|
267
|
+
"args": ["shrink", "npx", "@modelcontextprotocol/server-filesystem", "/path"]
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
252
273
|
### Read tool guard (Claude Code)
|
|
253
274
|
|
|
254
275
|
The `Read` hook automatically:
|
|
@@ -307,6 +328,27 @@ Each profile gets its own independent install. `lakonai uninstall` / `lakonai re
|
|
|
307
328
|
| Windsurf | project² | `.windsurf/rules/lakonai.md` in the current dir |
|
|
308
329
|
| Cline | project² | `.clinerules/lakonai.md` in the current dir |
|
|
309
330
|
|
|
331
|
+
### What each agent actually gets (honest capability matrix)
|
|
332
|
+
|
|
333
|
+
The powerful input-side features (shell-output filtering, Read/Grep guards,
|
|
334
|
+
auto-learning, per-turn reinforcement) are **hooks — they run on Claude Code
|
|
335
|
+
only**. Everywhere else, lakonai delivers the terse rule, and shell filtering
|
|
336
|
+
happens by **the model prefixing `lakonai`** (the rule tells it to) or via the
|
|
337
|
+
opt-in `lakonai shell-init` wrapper. Honest matrix:
|
|
338
|
+
|
|
339
|
+
| Agent | Terse rule | Shell filter | Read/Grep guard | Auto-learning | Reinforcement | `/lakonai:*` + subagents |
|
|
340
|
+
|-------------|:---------:|-------------------------|:---------------:|:-------------:|:-------------:|:-------------:|
|
|
341
|
+
| Claude Code | ✅ | ✅ automatic (hook) | ✅ | ✅ | ✅ | ✅ |
|
|
342
|
+
| Codex CLI | ✅ | ⚠️ via rule / shell-init | ❌ | ❌ | ❌ | ❌ |
|
|
343
|
+
| Cursor | ✅ | ⚠️ via rule / shell-init | ❌ (rule) | ❌ | ❌ | ❌ |
|
|
344
|
+
| Windsurf | ✅ | ⚠️ via rule / shell-init | ❌ (rule) | ❌ | ❌ | ❌ |
|
|
345
|
+
| Cline | ✅ | ⚠️ via rule / shell-init | ❌ (rule) | ❌ | ❌ | ❌ |
|
|
346
|
+
| Gemini CLI | ✅ | ⚠️ via rule / shell-init | ❌ (rule) | ❌ | ❌ | ❌ |
|
|
347
|
+
|
|
348
|
+
⚠️ = the model has to cooperate (prefix `lakonai`) or you opt into the shell
|
|
349
|
+
wrapper. Run `lakonai doctor` to see, per platform, what's actually active on your
|
|
350
|
+
machine.
|
|
351
|
+
|
|
310
352
|
¹ "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.
|
|
311
353
|
|
|
312
354
|
² 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.
|
|
@@ -377,7 +419,7 @@ npm run test:coverage:check # enforce the coverage threshold
|
|
|
377
419
|
node bin/lakonai.js --help
|
|
378
420
|
```
|
|
379
421
|
|
|
380
|
-
Suite: **
|
|
422
|
+
Suite: **301 tests**. Coverage gate: **100% lines / 100% branches / 100% functions / 100% statements**. Zero runtime dependencies. Node ≥ 18.
|
|
381
423
|
|
|
382
424
|
---
|
|
383
425
|
|
package/bin/lakonai.js
CHANGED
|
@@ -198,6 +198,30 @@ async function main() {
|
|
|
198
198
|
process.stdout.write(`${r.file}: ${r.before} → ${r.after} tokens (-${r.saved}%, ${r.mode})${tail}\n`);
|
|
199
199
|
return;
|
|
200
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
|
+
}
|
|
220
|
+
/* istanbul ignore next -- long-running stdio MCP proxy; logic tested via src/shrink */
|
|
221
|
+
if (first === 'shrink') {
|
|
222
|
+
require('../src/shrink').runProxy(rest);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
201
225
|
|
|
202
226
|
runAndFilter(first, rest);
|
|
203
227
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lakonai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.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"
|
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,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 };
|
package/src/install/platforms.js
CHANGED
|
@@ -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/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 };
|
package/src/shrink.js
ADDED
|
Binary file
|