lakonai 1.2.8 → 1.4.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 +33 -8
- package/bin/lakonai.js +41 -1
- package/package.json +3 -2
- package/src/depth.js +212 -0
- package/src/doctor.js +2 -2
- package/src/filters/defs.js +1 -0
- package/src/filters/engine.js +10 -0
- package/src/filters/git.js +21 -1
- package/src/filters/index.js +5 -1
- package/src/hooks/bash-rewrite.js +58 -15
- package/src/hooks/prompt-depth.js +66 -0
- package/src/hooks/stop-hook.js +55 -1
- package/src/install/claude-commands.js +23 -0
- package/src/install/claude-hook.js +9 -0
- package/src/install/codex-hook.js +128 -0
- package/src/install/platforms.js +16 -2
- package/src/learn-report.js +2 -1
- package/src/learn.js +46 -6
- package/src/proxy/brevity.js +61 -0
- package/src/proxy/server.js +4 -1
- package/src/rules/lakonai.md +35 -0
- package/src/shell.js +141 -0
- package/src/tracking.js +67 -1
package/src/tracking.js
CHANGED
|
@@ -17,6 +17,18 @@ function logPath() {
|
|
|
17
17
|
return path.join(dataDir(), 'log.jsonl');
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
// Which agent ran the command. Every agent spawns its shell with its own
|
|
21
|
+
// marker: Claude Code sets CLAUDECODE=1; Codex CLI sets CODEX_THREAD_ID /
|
|
22
|
+
// CODEX_TOOL_CALL_ID (CODEX_SANDBOX* under its sandbox); Gemini CLI sets
|
|
23
|
+
// GEMINI_CLI=1. LAKON_AGENT overrides, for agents with no marker.
|
|
24
|
+
function detectAgent(env = process.env) {
|
|
25
|
+
if (env.LAKON_AGENT) return String(env.LAKON_AGENT);
|
|
26
|
+
if (env.CLAUDECODE === '1') return 'claude';
|
|
27
|
+
if (env.CODEX_THREAD_ID || env.CODEX_TOOL_CALL_ID || env.CODEX_SANDBOX || env.CODEX_SANDBOX_NETWORK_DISABLED) return 'codex';
|
|
28
|
+
if (env.GEMINI_CLI === '1') return 'gemini';
|
|
29
|
+
return 'other';
|
|
30
|
+
}
|
|
31
|
+
|
|
20
32
|
function record({ cmd, args, rawTokens, filteredTokens }) {
|
|
21
33
|
if (process.env.LAKON_NO_TRACK === '1') return;
|
|
22
34
|
try {
|
|
@@ -28,6 +40,7 @@ function record({ cmd, args, rawTokens, filteredTokens }) {
|
|
|
28
40
|
raw: rawTokens,
|
|
29
41
|
out: filteredTokens,
|
|
30
42
|
saved: Math.max(0, rawTokens - filteredTokens),
|
|
43
|
+
agent: detectAgent(),
|
|
31
44
|
};
|
|
32
45
|
fs.appendFileSync(logPath(), JSON.stringify(entry) + '\n');
|
|
33
46
|
/* istanbul ignore next */
|
|
@@ -91,6 +104,43 @@ function byCommand(entries) {
|
|
|
91
104
|
return [...map.values()].sort((a, b) => b.saved - a.saved);
|
|
92
105
|
}
|
|
93
106
|
|
|
107
|
+
// Output side: how long the model's own answers are. Session entries are
|
|
108
|
+
// written by the Stop hook; `out_lines` only exists on entries recorded since
|
|
109
|
+
// the answer budget shipped, so older sessions are simply skipped.
|
|
110
|
+
function responseStats(entries) {
|
|
111
|
+
const turns = entries.filter((e) => isSessionEntry(e) && typeof e.out_lines === 'number');
|
|
112
|
+
if (!turns.length) return null;
|
|
113
|
+
const sum = (k) => turns.reduce((a, e) => a + (e[k] || 0), 0);
|
|
114
|
+
const lines = sum('out_lines');
|
|
115
|
+
const { BUDGETS } = require('./depth');
|
|
116
|
+
// The loosest budget (plan/review) is the conservative bar — a turn over it
|
|
117
|
+
// is long by any reading.
|
|
118
|
+
const overBudget = turns.filter((e) => e.out_lines > BUDGETS.plan).length;
|
|
119
|
+
return {
|
|
120
|
+
turns: turns.length,
|
|
121
|
+
lines,
|
|
122
|
+
tokens: sum('out_tokens'),
|
|
123
|
+
avgLines: Math.round((lines / turns.length) * 10) / 10,
|
|
124
|
+
overBudget,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Savings per agent. Entries written before the agent field existed are
|
|
129
|
+
// grouped as 'unknown' rather than guessed.
|
|
130
|
+
function byAgent(entries) {
|
|
131
|
+
const map = new Map();
|
|
132
|
+
for (const e of entries) {
|
|
133
|
+
if (isSessionEntry(e)) continue;
|
|
134
|
+
const k = e.agent || 'unknown';
|
|
135
|
+
if (!map.has(k)) map.set(k, { agent: k, calls: 0, raw: 0, saved: 0 });
|
|
136
|
+
const acc = map.get(k);
|
|
137
|
+
acc.calls += 1;
|
|
138
|
+
acc.raw += e.raw || 0;
|
|
139
|
+
acc.saved += e.saved || 0;
|
|
140
|
+
}
|
|
141
|
+
return [...map.values()].sort((a, b) => b.saved - a.saved);
|
|
142
|
+
}
|
|
143
|
+
|
|
94
144
|
function pct(saved, raw) {
|
|
95
145
|
if (!raw) return 0;
|
|
96
146
|
return Math.round((saved / raw) * 100);
|
|
@@ -146,6 +196,22 @@ function report() {
|
|
|
146
196
|
lines.push(` ${pad(label, 11)}${green(tok(a.saved))} saved ${dim(`(${pct(a.saved, a.raw)}%)`)}`);
|
|
147
197
|
}
|
|
148
198
|
|
|
199
|
+
const resp = responseStats(entries);
|
|
200
|
+
if (resp) {
|
|
201
|
+
const share = Math.round((resp.overBudget / resp.turns) * 100);
|
|
202
|
+
lines.push('');
|
|
203
|
+
lines.push(
|
|
204
|
+
` ${pad('answers', 11)}${green(`${resp.avgLines} lines`)} avg across ${resp.turns} turns ` +
|
|
205
|
+
dim(`(${resp.overBudget} over budget, ${share}%)`)
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const agents = byAgent(entries).filter((a) => a.agent !== 'unknown');
|
|
210
|
+
if (agents.length) {
|
|
211
|
+
lines.push('');
|
|
212
|
+
lines.push(' ' + dim('by agent: ') + agents.map((a) => `${a.agent} ${green(tok(a.saved))} ${dim(`(${pct(a.saved, a.raw)}%)`)}`).join(dim(' · ')));
|
|
213
|
+
}
|
|
214
|
+
|
|
149
215
|
const top = byCommand(entries).slice(0, 5);
|
|
150
216
|
if (top.length) {
|
|
151
217
|
lines.push('');
|
|
@@ -160,4 +226,4 @@ function reset() {
|
|
|
160
226
|
catch { return false; }
|
|
161
227
|
}
|
|
162
228
|
|
|
163
|
-
module.exports = { record, report, reset, readEntries, logPath };
|
|
229
|
+
module.exports = { record, report, reset, readEntries, logPath, responseStats, detectAgent, byAgent };
|