lakonai 0.16.0 → 0.16.2

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
@@ -77,43 +77,47 @@ Two extras worth knowing:
77
77
 
78
78
  ---
79
79
 
80
- ## Output savings: improvements on top of improvements
80
+ ## Output savings: the rule trims the model's prose too
81
81
 
82
- How much does the rule cut the model's output? We measured the **same rule, same
83
- prompt** against two baselines:
82
+ The input side (filtered shell output, blocked reads, compressed catalogs) is
83
+ deterministic. But the terse rule also makes the **model itself** write less.
84
+ `lakonai gain` measures it by running the same prompts through your local AI CLI
85
+ twice - once rule-free, once with the terse rule as a system prompt - and
86
+ comparing output tokens.
84
87
 
85
- | The model lakonai is layered on… | …and the rule cuts | |
86
- | ------------------------------------------- | :----------------: | ---------------------------------------------- |
87
- | a **raw, verbose** model (Gemini default) | **~70%** | as strong as any terse-prompt tool |
88
- | **Claude Code** - already concise by design | **~10% more** | the hard case: trimming what's already trimmed |
88
+ On a rule-free Claude baseline, explain / how-do-I / write-a-function prompts run
89
+ **~52% leaner** with the rule (1332 → 634 tokens across 4 prompts).
89
90
 
90
- _361 → 107 tokens on the verbose baseline; 240 → 216 on Claude Code. Same rule -
91
- the only variable is how much fat the model started with._
91
+ Read that as a **best case on prose turns**, not your day-to-day average:
92
92
 
93
- Anyone can cut the obvious fat (~70% off a rambling API). lakonai's edge is the
94
- **hard** case: point it at an agent that's _already_ optimized for brevity and it
95
- **still finds another ~10%** - stacked on top of filtered shell output, blocked
96
- reads, and compressed catalogs. **Improvements on top of improvements.**
93
+ - it's a small, fixed corpus of chatty prompts - exactly where preamble balloons;
94
+ - model output varies run to run (the figure is a single weekly sample, not an average);
95
+ - agentic turns (code edits, tool calls, diffs) are mostly code, not prose, so the
96
+ rule trims far less there.
97
97
 
98
- > `lakonai gain` shows the honest **~10% marginal** number - what you actually save
99
- > on _your_ already-concise agent, not an inflated raw-baseline headline.
98
+ Your real workload lands somewhere between the deterministic **input** savings
99
+ (~46%) and this prose ceiling, pulled down by however much of your work is
100
+ code and tooling rather than explanation.
101
+
102
+ > `lakonai gain` shows both: the measured, deterministic input number and the
103
+ > estimated output number - labelled as an estimate, never inflated into a headline.
100
104
 
101
105
  ---
102
106
 
103
107
  ## See your savings
104
108
 
105
109
  ```
106
- lakonai - saved 161.8k tok (67% smaller) across 2104 commands
110
+ lakonai - saved 196.8k tok (46% smaller) across 1910 commands
107
111
 
108
- today 6.7k tok saved (68%)
109
- this week 36.4k tok saved (67%)
112
+ today 984 tok saved (17%)
113
+ this week 124.5k tok saved (57%)
110
114
 
111
- top: git 124.3k · ls 18.2k · grep 12.0k
115
+ top: grep 55.3k · tail 55.1k · Read 34.3k · git 23.4k · cat 15.2k
112
116
 
113
- output (terse rule): ~10% fewer tokens vs your agent's baseline
117
+ output (terse rule): ~52% fewer tokens (1332 → 634, 4 prompts) [claude]
114
118
  ```
115
119
 
116
- Input is measured & deterministic; output is measured by your local AI CLI (no key,
120
+ Input is measured & deterministic; output is estimated by your local AI CLI (no key,
117
121
  weekly, at a TTY only). Both sides, one number.
118
122
 
119
123
  ---
package/bin/lakonai.js CHANGED
@@ -156,20 +156,24 @@ async function maybeRefreshOutputBench() {
156
156
  process.stderr.write(
157
157
  `measuring output savings with ${provider.bin} (one-off, ~a minute, no API key)…\n`
158
158
  );
159
- // Isolate both arms from the installed rule so the baseline is truly rule-free
160
- // (otherwise the CLI auto-loads ~/.claude/CLAUDE.md and we'd compare rule vs rule).
159
+ // Both arms run rule-free (so the CLI's own config doesn't auto-load the
160
+ // installed terse rule and pollute the baseline) from an empty cwd (so no
161
+ // project CLAUDE.md leaks in). The terse arm differs ONLY by the rule appended
162
+ // as a system prompt. Auth stays on the real Keychain credential — see
163
+ // callAgent's ruleFree note for why we don't redirect the config dir.
161
164
  const fs = require('fs');
162
165
  const os = require('os');
163
166
  const path = require('path');
164
- const cleanDir = fs.mkdtempSync(path.join(os.tmpdir(), 'lakon-clean-'));
167
+ const emptyCwd = fs.mkdtempSync(path.join(os.tmpdir(), 'lakon-bench-'));
165
168
  let res;
166
169
  try {
167
170
  res = ob.measure({
168
- call: (p, system) => llm.callAgent(p, { provider, systemPrompt: system, cleanConfigDir: cleanDir }),
171
+ call: (p, system) =>
172
+ llm.callAgent(p, { provider, systemPrompt: system, ruleFree: true, cwd: emptyCwd }),
169
173
  });
170
174
  } finally {
171
175
  try {
172
- fs.rmSync(cleanDir, { recursive: true, force: true });
176
+ fs.rmSync(emptyCwd, { recursive: true, force: true });
173
177
  } catch {
174
178
  /* temp dir cleanup is best-effort */
175
179
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lakonai",
3
- "version": "0.16.0",
3
+ "version": "0.16.2",
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/mem-llm.js CHANGED
@@ -20,7 +20,7 @@ const { spawnSync } = require('child_process');
20
20
  // so they cannot drive compression directly — a user on those platforms relies on
21
21
  // whichever of the CLIs below they also have installed.
22
22
  const PROVIDERS = [
23
- { id: 'claude', platform: 'Claude Code', bin: 'claude', stdin: true, args: () => ['--print'], modelFlag: '--model', systemFlag: '--append-system-prompt', cleanEnvVar: 'CLAUDE_CONFIG_DIR' },
23
+ { id: 'claude', platform: 'Claude Code', bin: 'claude', stdin: true, args: () => ['--print'], modelFlag: '--model', systemFlag: '--append-system-prompt', ruleFreeArgs: ['--setting-sources', 'project'] },
24
24
  { id: 'gemini', platform: 'Gemini CLI', bin: 'gemini', stdin: false, args: (p) => ['-p', p], modelFlag: '-m' },
25
25
  { id: 'codex', platform: 'Codex', bin: 'codex', stdin: true, args: () => ['exec', '-'], modelFlag: '-m' },
26
26
  { id: 'cursor', platform: 'Cursor', bin: 'cursor-agent', stdin: false, args: (p) => ['-p', p], modelFlag: '--model' },
@@ -113,7 +113,7 @@ ${compressed}`;
113
113
  // Run the chosen agent CLI in non-interactive mode. `run` is injectable for tests
114
114
  // (production: spawnSync). Throws a clear error when the CLI is missing or returns
115
115
  // non-zero so the caller can surface it.
116
- function callAgent(prompt, { run = spawnSync, provider, model = process.env.LAKONAI_MEM_MODEL, systemPrompt, cleanConfigDir } = {}) {
116
+ function callAgent(prompt, { run = spawnSync, provider, model = process.env.LAKONAI_MEM_MODEL, systemPrompt, ruleFree, cwd } = {}) {
117
117
  const p = provider || pickProvider();
118
118
  // Prefer the CLI's real system-prompt flag (stronger behavioral effect); fall
119
119
  // back to prepending it to the prompt when the CLI has no such flag.
@@ -122,13 +122,16 @@ function callAgent(prompt, { run = spawnSync, provider, model = process.env.LAKO
122
122
  const args = p.args(effective);
123
123
  if (model && p.modelFlag) args.push(p.modelFlag, model);
124
124
  if (useFlag) args.push(p.systemFlag, systemPrompt);
125
- // For a clean benchmark baseline: point the CLI at an empty config dir so it
126
- // does NOT auto-load the installed rule (e.g. ~/.claude/CLAUDE.md). Otherwise
127
- // the "no rule" arm would still have the rule, making the delta meaningless.
125
+ // For a clean benchmark baseline: stop the CLI auto-loading the installed rule
126
+ // (e.g. ~/.claude/CLAUDE.md) so the "no rule" arm is truly rule-free. We do this
127
+ // via the CLI's own flag (claude: --setting-sources project, dropping the `user`
128
+ // source) — NOT by redirecting the config dir, which on macOS switches the CLI to
129
+ // file-based auth and leaves it "Not logged in" (the credential lives in the
130
+ // Keychain, keyed to the default config dir). Pair it with an empty `cwd` so no
131
+ // project CLAUDE.md leaks in either.
132
+ if (ruleFree && p.ruleFreeArgs) args.push(...p.ruleFreeArgs);
128
133
  const opts = { input: p.stdin ? effective : undefined, encoding: 'utf8', maxBuffer: 8 * 1024 * 1024 };
129
- if (cleanConfigDir && p.cleanEnvVar) {
130
- opts.env = { ...process.env, [p.cleanEnvVar]: cleanConfigDir };
131
- }
134
+ if (cwd) opts.cwd = cwd;
132
135
  const res = run(p.bin, args, opts);
133
136
  if (res.error) {
134
137
  if (res.error.code === 'ENOENT') {