skill-autoroute 0.1.0 → 0.2.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 +4 -29
- package/bin/cli.js +16 -1
- package/package.json +1 -1
- package/src/flow.js +44 -15
- package/src/triggers.js +4 -1
- package/src/usage.js +21 -16
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
For Claude Code and Codex · No API key · Zero tokens when nothing matches
|
|
8
8
|
|
|
9
|
-

|
|
9
|
+
[](https://www.npmjs.com/package/skill-autoroute)
|
|
10
10
|

|
|
11
11
|

|
|
12
12
|

|
|
@@ -39,25 +39,11 @@ No match means no output and **0 extra tokens**. No AI runs at prompt time. The
|
|
|
39
39
|
|
|
40
40
|
### 1 · Setup (once)
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
flowchart LR
|
|
44
|
-
A["🔍 Find skills<br/><sub>Claude Code + Codex</sub>"] --> B["🛡️ Security scan<br/><sub>fixed rules + optional AI</sub>"]
|
|
45
|
-
B --> C["👯 Find duplicates<br/><sub>AI picks the better one</sub>"]
|
|
46
|
-
C --> D["☑️ You choose<br/><sub>check / uncheck</sub>"]
|
|
47
|
-
D --> E["⚡ Make triggers<br/><sub>with your own CLI login</sub>"]
|
|
48
|
-
E --> F["🪝 Install hook<br/><sub>+ trigger table</sub>"]
|
|
49
|
-
```
|
|
42
|
+

|
|
50
43
|
|
|
51
44
|
### 2 · Every prompt (automatic)
|
|
52
45
|
|
|
53
|
-
|
|
54
|
-
flowchart LR
|
|
55
|
-
P["You type a prompt"] --> H{"Hook checks<br/>trigger table"}
|
|
56
|
-
H -- "match" --> Y["Adds one hint line<br/><sub>≤ 3 skills, ~60 tokens each</sub>"]
|
|
57
|
-
H -- "no match" --> N["Adds nothing<br/><sub>0 tokens</sub>"]
|
|
58
|
-
Y --> AG["Agent reads the skill<br/>and does the work"]
|
|
59
|
-
N --> AG
|
|
60
|
-
```
|
|
46
|
+

|
|
61
47
|
|
|
62
48
|
---
|
|
63
49
|
|
|
@@ -236,18 +222,7 @@ When your skills change, the hint line tells you so. Run `regenerate`.
|
|
|
236
222
|
|
|
237
223
|
## User or project install
|
|
238
224
|
|
|
239
|
-
|
|
240
|
-
flowchart TB
|
|
241
|
-
subgraph U["👤 User level (default)"]
|
|
242
|
-
U1["~/.config/skill-autoroute/<br/>route.mjs + routes.json"]
|
|
243
|
-
end
|
|
244
|
-
subgraph P["📁 Project level (--project)"]
|
|
245
|
-
P1[".skill-autoroute/<br/>route.mjs + routes.json<br/><sub>commit it for your team</sub>"]
|
|
246
|
-
end
|
|
247
|
-
U1 --> M{"Hook merges both<br/><sub>project wins on same name</sub>"}
|
|
248
|
-
P1 --> M
|
|
249
|
-
M --> R["Hints"]
|
|
250
|
-
```
|
|
225
|
+

|
|
251
226
|
|
|
252
227
|
- **User level** works in every folder.
|
|
253
228
|
- **Project level** goes into the repository, so teammates get it on clone. It adds a hook to `.claude/settings.json`.
|
package/bin/cli.js
CHANGED
|
@@ -40,7 +40,22 @@ const clackUi = {
|
|
|
40
40
|
log: (m) => p.log.message(m),
|
|
41
41
|
confirm: async (message, initialValue = true) => unwrap(await p.confirm({ message, initialValue })),
|
|
42
42
|
select: async (message, options, initialValue) => unwrap(await p.select({ message, options, initialValue })),
|
|
43
|
-
multiselect: async (message, options, initialValues) =>
|
|
43
|
+
multiselect: async (message, options, initialValues) => {
|
|
44
|
+
if (!options.some((o) => o.group)) return unwrap(await p.multiselect({ message, options, initialValues, required: false }));
|
|
45
|
+
const groups = {};
|
|
46
|
+
for (const { group, ...o } of options) (groups[group] ??= []).push(o);
|
|
47
|
+
return unwrap(await p.groupMultiselect({ message, options: groups, initialValues, required: false }));
|
|
48
|
+
},
|
|
49
|
+
progress: (max) => {
|
|
50
|
+
const bar = p.progress({ max, indicator: 'timer' });
|
|
51
|
+
// A label wider than the terminal wraps, and the bar then cannot redraw its own line.
|
|
52
|
+
const fit = (m = '') => { const w = Math.max(20, (process.stdout.columns || 80) - 60); return m.length > w ? `${m.slice(0, w - 1)}…` : m; };
|
|
53
|
+
let started = false;
|
|
54
|
+
return {
|
|
55
|
+
next: (msg) => { if (started) bar.advance(1, fit(msg)); else { bar.start(fit(msg)); started = true; } },
|
|
56
|
+
done: (msg) => { if (!started) bar.start(); bar.advance(1); bar.stop(fit(msg)); },
|
|
57
|
+
};
|
|
58
|
+
},
|
|
44
59
|
text: async (message) => unwrap(await p.text({ message })) ?? '',
|
|
45
60
|
};
|
|
46
61
|
|
package/package.json
CHANGED
package/src/flow.js
CHANGED
|
@@ -9,7 +9,7 @@ import { scanStatic, label } from './scan/static.js';
|
|
|
9
9
|
import { aiScan, mergeScan } from './scan/ai.js';
|
|
10
10
|
import { candidateGroups, aiDedupe, MAX_GROUP } from './dedupe.js';
|
|
11
11
|
import { aiTriggers, keywordRules, TRIGGER_PROMPT } from './triggers.js';
|
|
12
|
-
import { estimate, Recorder, formatReport, writeReport, hookReport } from './usage.js';
|
|
12
|
+
import { estimate, Recorder, formatReport, writeReport, hookReport, num } from './usage.js';
|
|
13
13
|
import { readTable, writeTable, mergeTables } from './table.js';
|
|
14
14
|
import { pickModel } from './models.js';
|
|
15
15
|
import { routesPath, reportPath, hookCopyPath, logPath } from './paths.js';
|
|
@@ -32,11 +32,14 @@ const size = (f) => { try { return statSync(f).size; } catch { return 0; } };
|
|
|
32
32
|
// Project tables store paths relative to the project root so the folder can move or be cloned (the hook resolves them).
|
|
33
33
|
const keyOf = (scope) => (p) => (scope === 'project' ? relative(process.cwd(), p).split(sep).join('/') : p);
|
|
34
34
|
const forHook = (scope, t) => (scope === 'project' ? resolveProject(t, process.cwd()) : t);
|
|
35
|
+
const NO_HINT = '(no hints for this prompt: no checked skill has a rule whose words all appear in it. Rules match whole words, so a typo or a word the rules do not list gives no hint.)';
|
|
35
36
|
const AI_NOTE = 'AI flagged this (details in the install output)';
|
|
36
37
|
|
|
37
38
|
// Non-interactive ui: every prompt takes its default; AI steps run (spec: --yes never prompts).
|
|
39
|
+
// progress(max) returns {next(label), done(message)}: next() marks the previous item finished and names the current one.
|
|
40
|
+
const quietProgress = () => ({ next() {}, done() {} });
|
|
38
41
|
export const plainUi = (log = console.log) => ({
|
|
39
|
-
yes: true, log, confirm: async () => true, select: async (_m, _o, d) => d, multiselect: async (_m, _o, d) => d, text: async () => '',
|
|
42
|
+
yes: true, log, confirm: async () => true, select: async (_m, _o, d) => d, multiselect: async (_m, _o, d) => d, text: async () => '', progress: quietProgress,
|
|
40
43
|
});
|
|
41
44
|
|
|
42
45
|
export function findTools() {
|
|
@@ -81,11 +84,18 @@ export async function probe(ctx) {
|
|
|
81
84
|
ctx.est.probe = { input: ctx.overhead, cacheRead: ctx.cacheOverhead, output: usage.output ?? 0 };
|
|
82
85
|
}
|
|
83
86
|
|
|
87
|
+
const WHY = {
|
|
88
|
+
scan: 'an AI reads every file of each skill and looks for risky instructions (secrets sent out, remote code, hidden prompts)',
|
|
89
|
+
dedupe: 'an AI compares skills with the same name and picks the one to keep',
|
|
90
|
+
triggers: 'an AI writes the word patterns that decide which prompts get a hint for each skill',
|
|
91
|
+
};
|
|
92
|
+
const calls = (step, n) => (step === 'triggers' ? Math.ceil(n / BATCH) : n);
|
|
93
|
+
|
|
84
94
|
async function aiStep(ctx, ui, step, items, what) {
|
|
85
95
|
if (!ctx.ai || !items.length) return false;
|
|
86
96
|
const e = (ctx.est[step] = estimates(step, items, ctx.overhead, ctx.cacheOverhead));
|
|
87
97
|
const m = pickModel(ctx.aiName, step, ctx.overrides);
|
|
88
|
-
ui.log(`${what}: ${step
|
|
98
|
+
ui.log(`${what}: ${WHY[step]}.\n${num(calls(step, items.length))} calls with ${m.model ?? 'codex default'}/${m.effort}, est input ${num(e.input)}, est cache-read ${num(e.cacheRead)}, est output ${num(e.output)} tokens (estimate)`);
|
|
89
99
|
return ui.confirm(`Run ${what}?`, true);
|
|
90
100
|
}
|
|
91
101
|
|
|
@@ -93,13 +103,18 @@ export async function runScans(skills, ctx, ui) {
|
|
|
93
103
|
const scans = new Map(skills.map((s) => [s.skillPath, scanStatic(s)]));
|
|
94
104
|
if (await aiStep(ctx, ui, 'scan', skills, 'AI deep scan')) {
|
|
95
105
|
const m = model(ctx, 'scan');
|
|
96
|
-
|
|
97
|
-
|
|
106
|
+
const bar = ui.progress(skills.length);
|
|
107
|
+
const failed = [];
|
|
108
|
+
for (const [i, s] of skills.entries()) {
|
|
109
|
+
bar.next(`AI deep scan ${i + 1}/${skills.length}: ${show(s.name)}`);
|
|
110
|
+
const before = ctx.rec.rows().length;
|
|
98
111
|
const r = await aiScan(ctx.ai, s, m, ctx.rec);
|
|
99
112
|
// aiScan swallows errors; no recorded call means the call failed
|
|
100
|
-
if (ctx.rec.rows().length ===
|
|
113
|
+
if (ctx.rec.rows().length === before) failed.push(show(s.name));
|
|
101
114
|
else scans.set(s.skillPath, mergeScan(scans.get(s.skillPath), r));
|
|
102
115
|
}
|
|
116
|
+
bar.done(`AI deep scan done: ${skills.length - failed.length} of ${skills.length} skills scanned`);
|
|
117
|
+
if (failed.length) ui.log(`AI scan failed for ${failed.join(', ')}; static result kept`);
|
|
103
118
|
}
|
|
104
119
|
return scans;
|
|
105
120
|
}
|
|
@@ -110,17 +125,22 @@ export async function runDedupe(skills, ctx, ui) {
|
|
|
110
125
|
const groups = candidateGroups(skills);
|
|
111
126
|
if (!(await aiStep(ctx, ui, 'dedupe', groups, 'duplicate comparison'))) return out;
|
|
112
127
|
const m = model(ctx, 'dedupe');
|
|
113
|
-
|
|
128
|
+
const bar = ui.progress(groups.length);
|
|
129
|
+
const failed = [];
|
|
130
|
+
for (const [i, all] of groups.entries()) {
|
|
114
131
|
const g = all.slice(0, MAX_GROUP);
|
|
132
|
+
bar.next(`duplicate comparison ${i + 1}/${groups.length}: ${show(all[0].name)} (${all.length} copies)`);
|
|
115
133
|
for (const s of all.slice(MAX_GROUP)) out.set(s.skillPath, { tooLarge: true });
|
|
116
134
|
const v = await aiDedupe(ctx.ai, g, m, ctx.rec);
|
|
117
|
-
if (!v.keep) {
|
|
135
|
+
if (!v.keep) { failed.push(g.map((s) => show(s.name)).join(', ')); continue; }
|
|
118
136
|
const keep = g.find((s) => s.skillPath === v.keep);
|
|
119
137
|
for (const s of g) {
|
|
120
138
|
const reason = v.reasons[s.skillPath] ?? '';
|
|
121
139
|
out.set(s.skillPath, s === keep ? { preferred: true, reason } : { of: keep.name, from: `${keep.tool}, ${keep.source}`, reason });
|
|
122
140
|
}
|
|
123
141
|
}
|
|
142
|
+
bar.done(`duplicate comparison done: ${groups.length} group${groups.length === 1 ? '' : 's'}`);
|
|
143
|
+
for (const f of failed) ui.log(`duplicate comparison failed for ${f}; all kept as found`);
|
|
124
144
|
return out;
|
|
125
145
|
}
|
|
126
146
|
|
|
@@ -134,20 +154,27 @@ export function buildRows(skills, scans, dupes = new Map()) {
|
|
|
134
154
|
return { skill, scan, dup, enabled: scan.verdict !== 'block' && !dup?.of, text: parts.join(' · ') };
|
|
135
155
|
});
|
|
136
156
|
}
|
|
157
|
+
// Picker group: the plugin a skill ships in, or the tool's own skills folder.
|
|
158
|
+
export const groupOf = (s) => (String(s.source).startsWith('plugin:') ? `plugin ${show(String(s.source).slice(7))}` : `${s.tool} ${show(s.source)} skills`);
|
|
137
159
|
const rowText = (r, on) => (on ? r.text : `${r.text} · still loaded by ${r.skill.tool}`);
|
|
138
160
|
const printRows = (rows, ui) => { for (const r of rows) ui.log(`[${r.enabled ? 'x' : ' '}] ${rowText(r, r.enabled)}`); };
|
|
139
161
|
|
|
140
162
|
async function pickRows(rows, ui) {
|
|
141
163
|
if (ui.yes) { printRows(rows, ui); return rows; }
|
|
142
164
|
const idx = await ui.multiselect('Skills to route (unchecked skills stay installed, they only get no hints)',
|
|
143
|
-
rows.map((r, i) => ({ value: i, label: rowText(r, r.enabled) })), rows.flatMap((r, i) => (r.enabled ? [i] : [])));
|
|
165
|
+
rows.map((r, i) => ({ value: i, label: rowText(r, r.enabled), group: groupOf(r.skill) })), rows.flatMap((r, i) => (r.enabled ? [i] : [])));
|
|
144
166
|
return rows.map((r, i) => ({ ...r, enabled: idx.includes(i) }));
|
|
145
167
|
}
|
|
146
168
|
|
|
147
169
|
// Returns {bySkill: Map name -> {priority, rules}, rejected, fellBack, mode}.
|
|
148
170
|
export async function generate(skills, ctx, ui) {
|
|
149
171
|
if (await aiStep(ctx, ui, 'triggers', skills, 'trigger generation')) {
|
|
150
|
-
|
|
172
|
+
const n = calls('triggers', skills.length);
|
|
173
|
+
const bar = ui.progress(n);
|
|
174
|
+
const r = await aiTriggers(ctx.ai, skills, model(ctx, 'triggers'), ctx.rec,
|
|
175
|
+
(i, batch) => bar.next(`trigger generation ${i + 1}/${n}: ${show(batch[0].name)} to ${show(batch[batch.length - 1].name)} (${batch.length} skills)`));
|
|
176
|
+
bar.done(`trigger generation done: ${num(skills.length)} skills in ${n} call${n === 1 ? '' : 's'}`);
|
|
177
|
+
return { mode: 'ai', ...r };
|
|
151
178
|
}
|
|
152
179
|
const bySkill = new Map();
|
|
153
180
|
for (const s of skills) { const k = keywordRules(s); if (k.rules.length) bySkill.set(s.name, k); }
|
|
@@ -218,8 +245,10 @@ async function prelude(o, ui) {
|
|
|
218
245
|
const ctx = context(aiName, o);
|
|
219
246
|
if (ctx.ai) {
|
|
220
247
|
try {
|
|
221
|
-
|
|
222
|
-
|
|
248
|
+
const bar = ui.progress(1);
|
|
249
|
+
bar.next(`checking the ${aiName} login (1 small call)`);
|
|
250
|
+
try { await probe(ctx); } finally { bar.done('login check finished'); }
|
|
251
|
+
ui.log(`probe: ${aiName} login works; fixed overhead ${num(ctx.overhead)} input tokens per call (1 call)`);
|
|
223
252
|
} catch (e) {
|
|
224
253
|
ui.log(`probe failed: ${show(e.message)}`);
|
|
225
254
|
if (!(await ui.confirm('Continue with keywords only (no AI)?', true))) throw new Cancel();
|
|
@@ -241,7 +270,7 @@ function dryRun(ctx, skills, ui) {
|
|
|
241
270
|
for (const [step, items] of [['scan', skills], ['dedupe', candidateGroups(skills)], ['triggers', statics]]) {
|
|
242
271
|
const e = estimates(step, items, ctx.overhead, ctx.cacheOverhead);
|
|
243
272
|
const m = pickModel(ctx.aiName, step, ctx.overrides);
|
|
244
|
-
ui.log(`${step}: ${step
|
|
273
|
+
ui.log(`${step}: ${num(calls(step, items.length))} calls, ${m.model ?? 'codex default'}/${m.effort}, est input ${num(e.input)}, est cache-read ${num(e.cacheRead)}, est output ${num(e.output)} tokens`);
|
|
245
274
|
}
|
|
246
275
|
ui.log('est = estimate (characters / 4 plus the measured input and cache-read per call); the probe above was 1 real call.');
|
|
247
276
|
}
|
|
@@ -267,7 +296,7 @@ export async function install(o, ui) {
|
|
|
267
296
|
while (!ui.yes) {
|
|
268
297
|
const p = await ui.text('Preview: type a prompt to see its hints (empty to finish)');
|
|
269
298
|
if (!p) break;
|
|
270
|
-
ui.log(show(route(p, forHook(scope, table)) ??
|
|
299
|
+
ui.log(show(route(p, forHook(scope, table)) ?? NO_HINT));
|
|
271
300
|
}
|
|
272
301
|
const notes = write(scope, table, tools, ctx);
|
|
273
302
|
if (tools.filter((t) => ADAPTERS[t].hookConfig(scope)).every((t) => selfTest(scope, t))) ui.log('self-test: hook ran and its output has the right shape');
|
|
@@ -376,7 +405,7 @@ export async function bench(o, ui) {
|
|
|
376
405
|
try {
|
|
377
406
|
const off = await call(p, true);
|
|
378
407
|
const on = await call(p, false);
|
|
379
|
-
ui.log(`${i + 1}. ${p.slice(0, 40)} ${off} ${on} ${on - off >= 0 ? '+' : ''}${on - off}`);
|
|
408
|
+
ui.log(`${i + 1}. ${p.slice(0, 40)} ${num(off)} ${num(on)} ${on - off >= 0 ? '+' : ''}${num(on - off)}`);
|
|
380
409
|
} catch (e) { ui.log(`${i + 1}. failed: ${show(e.message)}`); }
|
|
381
410
|
}
|
|
382
411
|
ui.log('Numbers include your normal context (settings, hooks, MCP, instructions); only the difference comes from the hook. Small differences can be cache noise.');
|
package/src/triggers.js
CHANGED
|
@@ -75,6 +75,7 @@ Lessons from rules that went wrong:
|
|
|
75
75
|
- Never use .* or .+ between words. For "A then later B" write two patterns in one rule, such as ["\\\\bA\\\\b", "\\\\bB\\\\b"], so both must match.
|
|
76
76
|
- No nested quantifiers like (a+)+. Keep each pattern under 200 characters. JavaScript syntax, no lookbehind.
|
|
77
77
|
- Do not write a pattern that matches almost every prompt. A skill with no clear trigger gets a narrow rule or priority 90 to 100.
|
|
78
|
+
- Rules that only match the skill's own name or jargon never fire: users describe the task, not the skill. Give each skill at least one rule built from the everyday words a user types for that task, with common synonyms and word forms in one group. A planning skill: "\\\\b(plan|planning|blueprint|roadmap|spec)\\\\b". An API skill: "\\\\b(endpoint|api|route|webhook)s?\\\\b". A brainstorming skill: "\\\\b(brainstorm\\\\w*|ideas?|ideate)\\\\b". Pair a common word with a task word in one rule when the word alone is too broad.
|
|
78
79
|
|
|
79
80
|
<${tag}>
|
|
80
81
|
${lines.join('\n')}
|
|
@@ -85,7 +86,8 @@ const clampPriority = (p) =>
|
|
|
85
86
|
typeof p === 'number' && Number.isFinite(p) ? Math.min(100, Math.max(1, Math.round(p))) : FALLBACK_PRIORITY;
|
|
86
87
|
|
|
87
88
|
/** bySkill holds only skills that ended with at least one rule; skills with none are listed in fellBack only. */
|
|
88
|
-
|
|
89
|
+
// onBatch(index, batch) runs before each call, for a progress bar.
|
|
90
|
+
export async function aiTriggers(adapter, skills, { model, effort } = {}, recorder, onBatch = () => {}) {
|
|
89
91
|
const bySkill = new Map();
|
|
90
92
|
const rejected = [];
|
|
91
93
|
const fellBack = [];
|
|
@@ -96,6 +98,7 @@ export async function aiTriggers(adapter, skills, { model, effort } = {}, record
|
|
|
96
98
|
};
|
|
97
99
|
for (let i = 0; i < skills.length; i += BATCH) {
|
|
98
100
|
const batch = skills.slice(i, i + BATCH);
|
|
101
|
+
onBatch(i / BATCH, batch);
|
|
99
102
|
let entries = null;
|
|
100
103
|
try {
|
|
101
104
|
const { json, usage } = await adapter.headless({ prompt: TRIGGER_PROMPT(batch), schema: TRIGGER_SCHEMA, model, effort });
|
package/src/usage.js
CHANGED
|
@@ -27,22 +27,27 @@ export class Recorder {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
const pad = (v, n) => String(v).padEnd(n);
|
|
30
|
+
// 515450 -> "515,450": long token counts are read at a glance.
|
|
31
|
+
export const num = (n) => (typeof n === 'number' ? n.toLocaleString('en-US') : String(n));
|
|
30
32
|
|
|
31
33
|
// Input and cache-read are separate columns on purpose: Codex may or may not count cached tokens inside input.
|
|
34
|
+
// Each real number has its estimate in the column beside it; numbers are right-aligned so digits line up.
|
|
32
35
|
export function formatReport(totals = {}, estimates = {}) {
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const
|
|
36
|
+
const steps = Object.keys(totals);
|
|
37
|
+
const est = (s, k) => (estimates[s]?.[k] == null ? 'n/a' : num(estimates[s][k]));
|
|
38
|
+
const sum = (f) => num(steps.reduce((a, s) => a + f(totals[s]), 0));
|
|
39
|
+
const estSum = (k) => (steps.every((s) => estimates[s]?.[k] != null) ? num(steps.reduce((a, s) => a + estimates[s][k], 0)) : 'n/a');
|
|
40
|
+
const rows = steps.map((s) => {
|
|
41
|
+
const t = totals[s];
|
|
42
|
+
return [s, t.model ?? '-', num(t.calls), num(t.input), est(s, 'input'), num(t.cacheRead), est(s, 'cacheRead'), num(t.output), est(s, 'output')];
|
|
43
|
+
});
|
|
44
|
+
const total = ['total', '', sum((t) => t.calls), sum((t) => t.input), estSum('input'), sum((t) => t.cacheRead), estSum('cacheRead'), sum((t) => t.output), estSum('output')];
|
|
45
|
+
const head = ['step', 'model', 'calls', 'input', 'est input', 'cache-read', 'est cache-read', 'output', 'est output'];
|
|
46
|
+
const w = head.map((h, i) => Math.max(...[head, ...rows, total].map((r) => String(r[i]).length)));
|
|
47
|
+
const line = (r) => r.map((c, i) => (i < 2 ? pad(c, w[i]) : String(c).padStart(w[i]))).join(' ').trimEnd();
|
|
48
|
+
const rule = w.map((n) => '─'.repeat(n)).join(' ');
|
|
44
49
|
return [
|
|
45
|
-
line(head), ...rows.map(line),
|
|
50
|
+
line(head), rule, ...rows.map(line), rule, line(total), '',
|
|
46
51
|
'est = estimate (characters / 4 plus overhead per call). Real numbers come from the CLI usage output.',
|
|
47
52
|
'Input and cache-read are separate columns and are not summed. The router adds tokens; it does not reduce them.',
|
|
48
53
|
].join('\n');
|
|
@@ -71,7 +76,7 @@ export function hookReport(table, logLines) {
|
|
|
71
76
|
const w = Math.max(0, ...skills.map((s) => s.name.length));
|
|
72
77
|
for (const s of skills) {
|
|
73
78
|
const c = size(s).length;
|
|
74
|
-
out.push(` ${pad(s.name, w)} ${c} chars ~${tokens(c)} tokens (estimate)`);
|
|
79
|
+
out.push(` ${pad(s.name, w)} ${num(c)} chars ~${num(tokens(c))} tokens (estimate)`);
|
|
75
80
|
}
|
|
76
81
|
if (!skills.length) out.push(' no enabled skills in the table');
|
|
77
82
|
const fires = parseLog(logLines);
|
|
@@ -83,9 +88,9 @@ export function hookReport(table, logLines) {
|
|
|
83
88
|
const total = fires.reduce((a, f) => a + f.chars, 0);
|
|
84
89
|
const round1 = (n) => Math.round(n * 10) / 10;
|
|
85
90
|
out.push(
|
|
86
|
-
`Usage log: ${fires.length} fires over ${days} active days, ${round1(fires.length / days)} fires per active day`,
|
|
87
|
-
` average added: ${Math.round(total / fires.length)} chars per fire (~${tokens(total / fires.length)} tokens, estimate)`,
|
|
88
|
-
` average added: ${Math.round(total / days)} chars per active day (~${tokens(total / days)} tokens, estimate)`,
|
|
91
|
+
`Usage log: ${num(fires.length)} fires over ${num(days)} active days, ${round1(fires.length / days)} fires per active day`,
|
|
92
|
+
` average added: ${num(Math.round(total / fires.length))} chars per fire (~${num(tokens(total / fires.length))} tokens, estimate)`,
|
|
93
|
+
` average added: ${num(Math.round(total / days))} chars per active day (~${num(tokens(total / days))} tokens, estimate)`,
|
|
89
94
|
);
|
|
90
95
|
return out.join('\n');
|
|
91
96
|
}
|