@zenera/cli 1.2.9 → 1.3.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.
Files changed (107) hide show
  1. package/README.md +11 -3
  2. package/dist/command.d.ts +19 -0
  3. package/dist/command.js +5 -9
  4. package/dist/commands/index.d.ts +1 -1
  5. package/dist/commands/index.js +13 -3
  6. package/dist/commands/open.js +6 -1
  7. package/dist/commands/version.d.ts +11 -0
  8. package/dist/commands/version.js +129 -19
  9. package/dist/{completion.d.ts → complete.d.ts} +1 -1
  10. package/dist/{completion.js → complete.js} +14 -4
  11. package/dist/{meta/editor.js → editor.js} +7 -1
  12. package/dist/lib.d.ts +18 -1
  13. package/dist/lib.js +34 -0
  14. package/dist/main.js +1 -1
  15. package/dist/scaffold.js +7 -1
  16. package/package.json +6 -7
  17. package/templates/editor/.github/skills/zen-cli/references/meta.md +3 -0
  18. package/templates/editor/.github/skills/zen-cli/references/projects.md +7 -2
  19. package/dist/commands/meta.d.ts +0 -6
  20. package/dist/commands/meta.js +0 -1088
  21. package/dist/meta/finetune/analyze-brief.d.ts +0 -26
  22. package/dist/meta/finetune/analyze-brief.js +0 -131
  23. package/dist/meta/finetune/apply-brief.d.ts +0 -23
  24. package/dist/meta/finetune/apply-brief.js +0 -247
  25. package/dist/meta/finetune/brief.d.ts +0 -45
  26. package/dist/meta/finetune/brief.js +0 -158
  27. package/dist/meta/finetune/children.d.ts +0 -8
  28. package/dist/meta/finetune/children.js +0 -76
  29. package/dist/meta/finetune/command.d.ts +0 -30
  30. package/dist/meta/finetune/command.js +0 -516
  31. package/dist/meta/finetune/cost.d.ts +0 -46
  32. package/dist/meta/finetune/cost.js +0 -105
  33. package/dist/meta/finetune/dataset/anchors.d.ts +0 -41
  34. package/dist/meta/finetune/dataset/anchors.js +0 -239
  35. package/dist/meta/finetune/dataset/changes.d.ts +0 -36
  36. package/dist/meta/finetune/dataset/changes.js +0 -319
  37. package/dist/meta/finetune/dataset/command.d.ts +0 -17
  38. package/dist/meta/finetune/dataset/command.js +0 -1011
  39. package/dist/meta/finetune/dataset/drift.d.ts +0 -33
  40. package/dist/meta/finetune/dataset/drift.js +0 -71
  41. package/dist/meta/finetune/dataset/export.d.ts +0 -26
  42. package/dist/meta/finetune/dataset/export.js +0 -51
  43. package/dist/meta/finetune/dataset/index.d.ts +0 -2
  44. package/dist/meta/finetune/dataset/index.js +0 -2
  45. package/dist/meta/finetune/dataset/sample.d.ts +0 -50
  46. package/dist/meta/finetune/dataset/sample.js +0 -197
  47. package/dist/meta/finetune/dataset/schema.d.ts +0 -33
  48. package/dist/meta/finetune/dataset/schema.js +0 -216
  49. package/dist/meta/finetune/dataset/store.d.ts +0 -35
  50. package/dist/meta/finetune/dataset/store.js +0 -177
  51. package/dist/meta/finetune/dataset/types.d.ts +0 -127
  52. package/dist/meta/finetune/dataset/types.js +0 -39
  53. package/dist/meta/finetune/failure.d.ts +0 -15
  54. package/dist/meta/finetune/failure.js +0 -26
  55. package/dist/meta/finetune/feedback.d.ts +0 -57
  56. package/dist/meta/finetune/feedback.js +0 -104
  57. package/dist/meta/finetune/improvements.d.ts +0 -98
  58. package/dist/meta/finetune/improvements.js +0 -501
  59. package/dist/meta/finetune/index.d.ts +0 -2
  60. package/dist/meta/finetune/index.js +0 -2
  61. package/dist/meta/finetune/journal.d.ts +0 -35
  62. package/dist/meta/finetune/journal.js +0 -135
  63. package/dist/meta/finetune/live.d.ts +0 -84
  64. package/dist/meta/finetune/live.js +0 -272
  65. package/dist/meta/finetune/loop.d.ts +0 -3
  66. package/dist/meta/finetune/loop.js +0 -163
  67. package/dist/meta/finetune/memories.d.ts +0 -47
  68. package/dist/meta/finetune/memories.js +0 -171
  69. package/dist/meta/finetune/recheck.d.ts +0 -58
  70. package/dist/meta/finetune/recheck.js +0 -311
  71. package/dist/meta/finetune/report.d.ts +0 -40
  72. package/dist/meta/finetune/report.js +0 -1397
  73. package/dist/meta/finetune/retry.d.ts +0 -24
  74. package/dist/meta/finetune/retry.js +0 -96
  75. package/dist/meta/finetune/sampler.d.ts +0 -18
  76. package/dist/meta/finetune/sampler.js +0 -47
  77. package/dist/meta/finetune/system.d.ts +0 -27
  78. package/dist/meta/finetune/system.js +0 -132
  79. package/dist/meta/finetune/train.d.ts +0 -43
  80. package/dist/meta/finetune/train.js +0 -425
  81. package/dist/meta/finetune/tui.d.ts +0 -16
  82. package/dist/meta/finetune/tui.js +0 -316
  83. package/dist/meta/finetune/tuning.d.ts +0 -193
  84. package/dist/meta/finetune/tuning.js +0 -308
  85. package/dist/meta/finetune/usage.d.ts +0 -66
  86. package/dist/meta/finetune/usage.js +0 -260
  87. package/dist/meta/finetune/view.d.ts +0 -9
  88. package/dist/meta/finetune/view.js +0 -27
  89. package/dist/meta/host.d.ts +0 -16
  90. package/dist/meta/host.js +0 -22
  91. package/dist/meta/index.d.ts +0 -11
  92. package/dist/meta/index.js +0 -11
  93. package/dist/meta/launch.d.ts +0 -81
  94. package/dist/meta/launch.js +0 -288
  95. package/dist/meta/model.d.ts +0 -61
  96. package/dist/meta/model.js +0 -146
  97. package/dist/meta/prompts.d.ts +0 -23
  98. package/dist/meta/prompts.js +0 -84
  99. package/dist/meta/relay.d.ts +0 -20
  100. package/dist/meta/relay.js +0 -123
  101. package/dist/meta/tokens.d.ts +0 -52
  102. package/dist/meta/tokens.js +0 -226
  103. package/dist/meta/window.d.ts +0 -61
  104. package/dist/meta/window.js +0 -198
  105. package/dist/meta/wire.d.ts +0 -51
  106. package/dist/meta/wire.js +0 -159
  107. /package/dist/{meta/editor.d.ts → editor.d.ts} +0 -0
package/dist/meta/host.js DELETED
@@ -1,22 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- // The meta layer's one door into the rest of the CLI
3
- //
4
- // Everything under `src/meta/` imports the runtime through this file and no
5
- // other, so the layer can leave for a package of its own by turning this into
6
- // a dependency. `test/meta-boundary.test.ts` holds the line.
7
- // ---------------------------------------------------------------------------
8
- export { envOf, paths, PROVIDERS, readJson, writeJson, } from '@zenera/engine';
9
- export { invokedAs, parse } from "../args.js";
10
- export { loadCatalogs } from "../catalog.js";
11
- export { PROVIDER_NAMES, splitRef } from "../modelref.js";
12
- export { duration } from "../narrate.js";
13
- export { rankModels } from "../rank.js";
14
- export { copyTree, SHARED_RULES, TEMPLATES } from "../scaffold.js";
15
- export { bold, CliError, confirm, credentialError, cut, cyan, dim, EXIT, green, invalidError, json, note, pad, plain, red, styled, table, usageError, write, writeAll, yellow, } from "../term.js";
16
- export { safe } from "../trace.js";
17
- export { formatInline, formatMarkdown } from "../tui/markdown.js";
18
- export { resolveTheme } from "../tui/theme.js";
19
- export { boxWidth } from "../tui/wrap.js";
20
- export { META_PROMPT_ENV, META_SESSION_ENV } from "../usage.js";
21
- export { validateProject } from "../validate.js";
22
- //# sourceMappingURL=host.js.map
@@ -1,11 +0,0 @@
1
- export * from './editor.ts';
2
- export * from './finetune/dataset/index.ts';
3
- export * from './finetune/index.ts';
4
- export * from './launch.ts';
5
- export * from './model.ts';
6
- export * from './prompts.ts';
7
- export * from './relay.ts';
8
- export * from './tokens.ts';
9
- export * from './window.ts';
10
- export * from './wire.ts';
11
- //# sourceMappingURL=index.d.ts.map
@@ -1,11 +0,0 @@
1
- export * from "./editor.js";
2
- export * from "./finetune/dataset/index.js";
3
- export * from "./finetune/index.js";
4
- export * from "./launch.js";
5
- export * from "./model.js";
6
- export * from "./prompts.js";
7
- export * from "./relay.js";
8
- export * from "./tokens.js";
9
- export * from "./window.js";
10
- export * from "./wire.js";
11
- //# sourceMappingURL=index.js.map
@@ -1,81 +0,0 @@
1
- import { spawn as nodeSpawn } from 'node:child_process';
2
- import { type Sink } from './window.ts';
3
- export interface Binary {
4
- command: string;
5
- args: string[];
6
- from: 'path' | 'npx';
7
- }
8
- /**
9
- * A `copilot` already installed is used as it is; otherwise `npx` fetches one.
10
- * Note that finding the name on `PATH` is not the same as finding the CLI —
11
- * an editor may have put a shim there that installs it on first run — so this
12
- * only decides how to launch, never whether it will work.
13
- */
14
- export declare function locate(has?: (cmd: string) => boolean): Binary;
15
- interface Event {
16
- type: string;
17
- data?: Record<string, unknown>;
18
- [key: string]: unknown;
19
- }
20
- export interface Outcome {
21
- /** the last thing the agent said that was not a preamble to a tool call */
22
- answer: string;
23
- exitCode: number;
24
- sessionId?: string;
25
- usage?: Record<string, unknown>;
26
- events: Event[];
27
- }
28
- export interface Log {
29
- readonly path: string;
30
- /** Where the answer alone goes, beside the log and openable on its own. */
31
- readonly answerPath: string;
32
- line(text: string): void;
33
- saveAnswer(text: string): void;
34
- close(): void;
35
- }
36
- /**
37
- * `<project>/.tmp/logs/meta.<when>[-<session>].log`, opened for append. The
38
- * session keeps runs started in the same second - a tuning loop's - apart.
39
- */
40
- export declare function openLog(dir: string, now?: Date, session?: string): Log;
41
- export declare function recordSession(dir: string, id: string): void;
42
- export declare function lastSession(dir: string): string | undefined;
43
- /**
44
- * Folds one event into the outcome and says what, if anything, to show for it.
45
- *
46
- * `assistant.message` carries both the running commentary and the final word;
47
- * what separates them is `toolRequests`, so the last message that asked for no
48
- * tool is the answer and the rest are narration.
49
- */
50
- export declare function absorb(event: Event, out: Outcome, sink: Sink, width: number): void;
51
- export interface Launch {
52
- binary: Binary;
53
- args: string[];
54
- env: Record<string, string>;
55
- cwd: string;
56
- sink?: Sink;
57
- log?: Log;
58
- width?: number;
59
- /** said after the elapsed time on the status row, e.g. the tokens so far */
60
- status?: () => string;
61
- /** every event copilot prints, before it is folded */
62
- onEvent?: (event: Event) => void;
63
- /** injected by the tests, which have no copilot and want none */
64
- spawn?: typeof nodeSpawn;
65
- }
66
- export declare function launch(opts: Launch): Promise<Outcome>;
67
- /** Resumes after copilot's own retries run out; `--retries` overrides. */
68
- export declare const DEFAULT_RESUMES = 5;
69
- /** What the resumed session is told, since `-p` has to say something. */
70
- export declare const RESUME_PROMPT = "The previous model call failed. Continue the task from where you stopped.";
71
- export declare function resumeDelayMs(attempt: number): number;
72
- /**
73
- * Why the run is worth resuming, or undefined when waiting cannot help.
74
- *
75
- * Only a refusal that time can cure counts: a rate limit, the provider's own
76
- * failure, a connection that timed out. A 400 or a bad key fails the same way
77
- * however often it is sent - except the one below.
78
- */
79
- export declare function transient(out: Outcome): string | undefined;
80
- export {};
81
- //# sourceMappingURL=launch.d.ts.map
@@ -1,288 +0,0 @@
1
- import { spawn as nodeSpawn } from 'node:child_process';
2
- import { createWriteStream, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
3
- import { createInterface } from 'node:readline';
4
- import { cut, dim, duration, formatInline, plain } from "./host.js";
5
- import { FRAME_MS, windowSink } from "./window.js";
6
- /**
7
- * A `copilot` already installed is used as it is; otherwise `npx` fetches one.
8
- * Note that finding the name on `PATH` is not the same as finding the CLI —
9
- * an editor may have put a shim there that installs it on first run — so this
10
- * only decides how to launch, never whether it will work.
11
- */
12
- export function locate(has = (cmd) => onPath(cmd)) {
13
- return has('copilot')
14
- ? { command: 'copilot', args: [], from: 'path' }
15
- : { command: 'npx', args: ['--yes', '@github/copilot'], from: 'npx' };
16
- }
17
- function onPath(cmd) {
18
- const dirs = (process.env.PATH ?? '').split(':').filter(Boolean);
19
- return dirs.some((d) => existsSync(`${d}/${cmd}`));
20
- }
21
- /**
22
- * `<project>/.tmp/logs/meta.<when>[-<session>].log`, opened for append. The
23
- * session keeps runs started in the same second - a tuning loop's - apart.
24
- */
25
- export function openLog(dir, now = new Date(), session) {
26
- const two = (n) => String(n).padStart(2, '0');
27
- const stamp = `${now.getFullYear()}${two(now.getMonth() + 1)}${two(now.getDate())}` +
28
- `${two(now.getHours())}${two(now.getMinutes())}${two(now.getSeconds())}` +
29
- (session ? `-${session.slice(0, 8)}` : '');
30
- const folder = `${dir}/.tmp/logs`;
31
- mkdirSync(folder, { recursive: true });
32
- const path = `${folder}/meta.${stamp}.log`;
33
- const answerPath = `${folder}/meta.${stamp}.md`;
34
- const file = createWriteStream(path, { flags: 'a' });
35
- return {
36
- path,
37
- answerPath,
38
- line: (text) => {
39
- file.write(`${plain(text)}\n`);
40
- },
41
- saveAnswer: (text) => {
42
- writeFileSync(answerPath, text.endsWith('\n') ? text : `${text}\n`);
43
- },
44
- close: () => {
45
- file.end();
46
- },
47
- };
48
- }
49
- /** The project's last meta session, so `zen meta resume` needs no id. */
50
- function sessionFile(dir) {
51
- return `${dir}/.tmp/logs/meta.session`;
52
- }
53
- export function recordSession(dir, id) {
54
- mkdirSync(`${dir}/.tmp/logs`, { recursive: true });
55
- writeFileSync(sessionFile(dir), `${id}\n`);
56
- }
57
- export function lastSession(dir) {
58
- try {
59
- return readFileSync(sessionFile(dir), 'utf8').trim() || undefined;
60
- }
61
- catch {
62
- return undefined;
63
- }
64
- }
65
- /** Everything the sink is told, kept by the log too — and the detail only there. */
66
- function tee(sink, log) {
67
- return {
68
- answer: (text) => sink.answer(text),
69
- narrate: (line) => {
70
- log.line(line);
71
- sink.narrate(line);
72
- },
73
- detail: (line) => log.line(line),
74
- warn: (line) => {
75
- log.line(line);
76
- sink.warn(line);
77
- },
78
- status: (line) => sink.status?.(line),
79
- close: () => sink.close?.(),
80
- };
81
- }
82
- /**
83
- * Folds one event into the outcome and says what, if anything, to show for it.
84
- *
85
- * `assistant.message` carries both the running commentary and the final word;
86
- * what separates them is `toolRequests`, so the last message that asked for no
87
- * tool is the answer and the rest are narration.
88
- */
89
- export function absorb(event, out, sink, width) {
90
- const data = (event.data ?? {});
91
- switch (event.type) {
92
- case 'assistant.message': {
93
- const content = String(data.content ?? '').trim();
94
- const requests = Array.isArray(data.toolRequests) ? data.toolRequests : [];
95
- if (requests.length === 0) {
96
- out.answer = content;
97
- }
98
- else if (content) {
99
- sink.narrate(cut(formatInline(content.replace(/\s+/g, ' ')), width));
100
- }
101
- break;
102
- }
103
- case 'tool.execution_start': {
104
- const args = (data.arguments ?? {});
105
- const what = String(args.command ?? args.description ?? data.toolName ?? '').trim();
106
- // Step-by-step belongs in the log: on screen it is a wall of `$`
107
- // saying less than the one line of commentary above it.
108
- sink.detail?.(`$ ${what.replace(/\s+/g, ' ')}`);
109
- break;
110
- }
111
- case 'tool.execution_complete': {
112
- if (data.success === false) {
113
- sink.detail?.(` ${String(data.toolName ?? 'the tool')} failed`);
114
- }
115
- break;
116
- }
117
- case 'session.tools_updated': {
118
- if (data.model) {
119
- sink.detail?.(`model ${String(data.model)}`);
120
- }
121
- break;
122
- }
123
- case 'session.error': {
124
- sink.warn(String(data.message ?? 'the session failed'));
125
- break;
126
- }
127
- case 'model.call_failure': {
128
- const status = data.statusCode ? ` (${String(data.statusCode)})` : '';
129
- sink.warn(`${cut(String(data.errorMessage ?? 'the model call failed'), width)}${status}`);
130
- break;
131
- }
132
- case 'result': {
133
- out.exitCode = Number(event.exitCode ?? 0);
134
- out.sessionId = event.sessionId;
135
- out.usage = event.usage;
136
- break;
137
- }
138
- default:
139
- break;
140
- }
141
- out.events.push(event);
142
- }
143
- export async function launch(opts) {
144
- const shown = opts.sink ?? windowSink();
145
- const sink = opts.log ? tee(shown, opts.log) : shown;
146
- // Without a terminal nothing wraps, and a cut line is lost from the log too.
147
- const width = opts.width ??
148
- (process.stderr.isTTY ? Math.max(40, (process.stderr.columns ?? 100) - 4) : Infinity);
149
- const start = opts.spawn ?? nodeSpawn;
150
- const out = { answer: '', exitCode: 0, events: [] };
151
- const child = start(opts.binary.command, [...opts.binary.args, ...opts.args], {
152
- cwd: opts.cwd,
153
- env: { ...process.env, ...opts.env },
154
- stdio: ['ignore', 'pipe', 'pipe'],
155
- shell: false,
156
- });
157
- const stop = (signal) => () => {
158
- child.kill(signal);
159
- };
160
- const onInt = stop('SIGINT');
161
- const onTerm = stop('SIGTERM');
162
- process.on('SIGINT', onInt);
163
- process.on('SIGTERM', onTerm);
164
- // The first model call says nothing for as long as it takes, and silence
165
- // after the model line is indistinguishable from a hang.
166
- const began = Date.now();
167
- const beat = setInterval(() => {
168
- const extra = opts.status?.();
169
- sink.status?.(`working: ${duration(Date.now() - began)}${extra ? ` · ${extra}` : ''}`);
170
- }, FRAME_MS);
171
- beat.unref();
172
- child.stderr?.on('data', (chunk) => {
173
- const text = chunk.toString().trimEnd();
174
- if (text) {
175
- sink.narrate(dim(text));
176
- }
177
- });
178
- try {
179
- const lines = createInterface({ input: child.stdout, crlfDelay: Infinity });
180
- for await (const line of lines) {
181
- if (!line.trim()) {
182
- continue;
183
- }
184
- let event;
185
- try {
186
- event = JSON.parse(line);
187
- }
188
- catch {
189
- // Not ours to interpret, but losing it is worse than showing it.
190
- sink.narrate(line);
191
- continue;
192
- }
193
- opts.onEvent?.(event);
194
- absorb(event, out, sink, width);
195
- }
196
- const code = await new Promise((resolve) => {
197
- child.on('close', (value, signal) => resolve(value ?? (signal ? 1 : 0)));
198
- });
199
- if (out.exitCode === 0 && code !== 0) {
200
- out.exitCode = code;
201
- }
202
- }
203
- finally {
204
- clearInterval(beat);
205
- process.off('SIGINT', onInt);
206
- process.off('SIGTERM', onTerm);
207
- // The answer is written by the caller, so the window has to be gone first.
208
- sink.close?.();
209
- }
210
- return out;
211
- }
212
- // ---------------------------------------------------------------------------
213
- // Resuming
214
- //
215
- // Copilot retries a failed model call itself, five times over about a minute,
216
- // and has no setting to change that. A run that outlasts it is still a session
217
- // on disk, so the retry happens one level up: wait, then resume that session.
218
- // ---------------------------------------------------------------------------
219
- /** Resumes after copilot's own retries run out; `--retries` overrides. */
220
- export const DEFAULT_RESUMES = 5;
221
- /** The first wait; it doubles per resume, up to `RESUME_MAX_MS`. */
222
- const RESUME_INITIAL_MS = 30_000;
223
- const RESUME_MAX_MS = 300_000;
224
- /** What the resumed session is told, since `-p` has to say something. */
225
- export const RESUME_PROMPT = 'The previous model call failed. Continue the task from where you stopped.';
226
- export function resumeDelayMs(attempt) {
227
- return Math.min(RESUME_INITIAL_MS * 2 ** attempt, RESUME_MAX_MS);
228
- }
229
- /**
230
- * Why the run is worth resuming, or undefined when waiting cannot help.
231
- *
232
- * Only a refusal that time can cure counts: a rate limit, the provider's own
233
- * failure, a connection that timed out. A 400 or a bad key fails the same way
234
- * however often it is sent - except the one below.
235
- */
236
- export function transient(out) {
237
- if (out.exitCode === 0 || !out.sessionId) {
238
- return undefined;
239
- }
240
- const at = out.events.findLastIndex((e) => e.type === 'session.error');
241
- const data = out.events[at]?.data;
242
- if (!data) {
243
- return undefined;
244
- }
245
- const status = Number(data.statusCode ?? 0);
246
- if (data.errorType === 'rate_limit' || status === 429) {
247
- return 'rate-limited (429)';
248
- }
249
- if (status === 408 || status >= 500) {
250
- return `the provider failed (${status})`;
251
- }
252
- if (/timed out|ECONNRESET|socket hang up/i.test(String(data.message ?? ''))) {
253
- return 'the connection failed';
254
- }
255
- if (status === 400 && injected(out.events.slice(0, at))) {
256
- return 'refused a tool call copilot made itself (400)';
257
- }
258
- return undefined;
259
- }
260
- /**
261
- * Whether the turn that failed began with a tool call copilot wrote, not the
262
- * model. When a background command finishes, copilot adds a `read_bash` of its
263
- * own; Gemini 3 rejects any tool call in the current turn that lacks its thought
264
- * signature, so that request is a 400 every time. A new user message - the
265
- * resume - starts a turn that no longer holds it.
266
- */
267
- function injected(before) {
268
- for (let i = before.length - 1; i >= 0; i--) {
269
- const event = before[i];
270
- if (event.type === 'system.notification') {
271
- return true;
272
- }
273
- if (event.type === 'user.message') {
274
- return false;
275
- }
276
- if (event.type === 'assistant.message') {
277
- if (event.data?.model) {
278
- return false;
279
- }
280
- const requests = event.data?.toolRequests;
281
- if (Array.isArray(requests) && requests.length > 0) {
282
- return true;
283
- }
284
- }
285
- }
286
- return false;
287
- }
288
- //# sourceMappingURL=launch.js.map
@@ -1,61 +0,0 @@
1
- import { type KeyStore, type Provider } from './host.ts';
2
- /** The variable a project's `.env` names it with — a zen ref, not a wire id. */
3
- export declare const MODEL_ENV = "ZENERA_META_MODEL";
4
- export type ModelSource = 'flag' | 'shell' | 'env' | 'store' | 'project' | 'default';
5
- export interface ModelChoice {
6
- /** a zen ref: `vertex/gemini-3.8-flash`, or a bare id for the default provider */
7
- ref: string;
8
- from: ModelSource;
9
- }
10
- export interface ModelSources {
11
- flag?: string;
12
- /** `ZENERA_META_MODEL` as it stood before the project's `.env` was folded in */
13
- shell?: string;
14
- /** the same variable after it was, which is the `.env` answer when they differ */
15
- env?: string;
16
- stored?: string;
17
- /** the project's `agents.yaml` `model:` */
18
- project?: string;
19
- /** what a held key recommends, when nothing above answered */
20
- fallback?: string;
21
- }
22
- /** Where the answer is looked for, best first. */
23
- export declare const ORDER: readonly ModelSource[];
24
- /**
25
- * Decides which model `zen meta` runs copilot on, when it can be named in six
26
- * places at once. The source comes back too, so a surprising pick can be traced
27
- * ("from agents.yaml model:") instead of guessed at.
28
- */
29
- export declare function chooseModel(sources: ModelSources): ModelChoice | undefined;
30
- export declare const SOURCE_LABELS: Record<ModelSource, string>;
31
- /** First of each row is the default; the rest are the next best. */
32
- export declare const RECOMMENDED: Partial<Record<Provider, readonly string[]>>;
33
- /**
34
- * The model `zen meta` falls back to when nothing names one, so a machine with
35
- * just a key (or just a gateway, which reaches every provider) still runs.
36
- * `only` is `--provider`: the recommendation for that provider, if it is held.
37
- */
38
- export declare function defaultRef(store: KeyStore, only?: Provider, gateway?: boolean): string | undefined;
39
- /**
40
- * The best chat model a gateway actually serves, by `rank.ts`: a vendor
41
- * recommendation it does not carry would fail on the first call. The store must
42
- * already be materialized, since that is what puts the gateway in the environment.
43
- */
44
- export declare function gatewayDefaultRef(only?: Provider): Promise<string | undefined>;
45
- /** The last resort: through a gateway, what it serves; otherwise what a held key recommends. */
46
- export declare function fallbackRef(store: KeyStore, only?: Provider, gateway?: boolean): Promise<string | undefined>;
47
- export interface MetaFile {
48
- version: 1;
49
- model?: string;
50
- }
51
- export declare const readMeta: () => Promise<MetaFile>;
52
- export declare function writeMeta(file: MetaFile): void;
53
- /**
54
- * The provider a misspelt prefix was reaching for, if that is what it is.
55
- *
56
- * `vertes/gemini-3.8-flash` is shaped exactly like the OpenRouter id
57
- * `meta-llama/llama-4`, so an unknown prefix cannot be an error on its own —
58
- * only one close enough to a real provider name to be a slip of the hand.
59
- */
60
- export declare function misspelledProvider(ref: string): Provider | undefined;
61
- //# sourceMappingURL=model.d.ts.map
@@ -1,146 +0,0 @@
1
- import { loadCatalogs, paths, PROVIDER_NAMES, PROVIDERS, rankModels, readJson, writeJson, } from "./host.js";
2
- import { metaCompatible } from "./wire.js";
3
- // ---------------------------------------------------------------------------
4
- // The model
5
- // ---------------------------------------------------------------------------
6
- /** The variable a project's `.env` names it with — a zen ref, not a wire id. */
7
- export const MODEL_ENV = 'ZENERA_META_MODEL';
8
- /** Where the answer is looked for, best first. */
9
- export const ORDER = [
10
- 'flag',
11
- 'shell',
12
- 'env',
13
- 'store',
14
- 'project',
15
- 'default',
16
- ];
17
- /**
18
- * Decides which model `zen meta` runs copilot on, when it can be named in six
19
- * places at once. The source comes back too, so a surprising pick can be traced
20
- * ("from agents.yaml model:") instead of guessed at.
21
- */
22
- export function chooseModel(sources) {
23
- const at = {
24
- flag: sources.flag,
25
- // `.env` only fills gaps, so an answer that survived it came from the shell
26
- shell: sources.shell,
27
- env: sources.shell ? undefined : sources.env,
28
- store: sources.stored,
29
- project: sources.project,
30
- default: sources.fallback,
31
- };
32
- for (const from of ORDER) {
33
- const ref = at[from]?.trim();
34
- if (ref) {
35
- return { ref, from };
36
- }
37
- }
38
- return undefined;
39
- }
40
- export const SOURCE_LABELS = {
41
- flag: '--model',
42
- shell: `${MODEL_ENV} (shell)`,
43
- env: `${MODEL_ENV} (.env)`,
44
- store: 'zen meta model',
45
- project: 'agents.yaml model:',
46
- default: 'recommended',
47
- };
48
- // ---------------------------------------------------------------------------
49
- // What to run when nobody said
50
- //
51
- // A first `zen meta` should work on a machine that has a key and nothing else,
52
- // so the last resort is the best model the keys on hand can buy rather than an
53
- // error. Deep tier deliberately: this agent is pointed at the project itself,
54
- // and a cheap model reading a specification is a false economy.
55
- // ---------------------------------------------------------------------------
56
- /** First of each row is the default; the rest are the next best. */
57
- export const RECOMMENDED = {
58
- openai: ['gpt-5.6-sol', 'gpt-5.6-terra'],
59
- anthropic: ['claude-opus-5', 'claude-sonnet-5'],
60
- vertex: ['gemini-3.8-flash', 'gemini-3.5-flash-lite'],
61
- google: ['gemini-3.8-flash', 'gemini-3.5-flash-lite'],
62
- openrouter: ['anthropic/claude-opus-5', 'openai/gpt-5.6-sol'],
63
- };
64
- /** Which provider is tried first when several are held. */
65
- const PREFERENCE = ['anthropic', 'openai', 'vertex', 'google', 'openrouter'];
66
- /**
67
- * The model `zen meta` falls back to when nothing names one, so a machine with
68
- * just a key (or just a gateway, which reaches every provider) still runs.
69
- * `only` is `--provider`: the recommendation for that provider, if it is held.
70
- */
71
- export function defaultRef(store, only, gateway = false) {
72
- for (const provider of only ? [only] : PREFERENCE) {
73
- const id = RECOMMENDED[provider]?.[0];
74
- if (id && (gateway || store.active(provider))) {
75
- return `${provider}/${id}`;
76
- }
77
- }
78
- return undefined;
79
- }
80
- /**
81
- * The best chat model a gateway actually serves, by `rank.ts`: a vendor
82
- * recommendation it does not carry would fail on the first call. The store must
83
- * already be materialized, since that is what puts the gateway in the environment.
84
- */
85
- export async function gatewayDefaultRef(only) {
86
- const cats = await loadCatalogs(only ? [only] : PROVIDERS);
87
- const usable = cats
88
- .flatMap((c) => c.entries)
89
- .filter((e) => e.roles.includes('chat') && metaCompatible(e.provider, e.id));
90
- const best = rankModels(usable)[0];
91
- return best ? `${best.provider}/${best.id}` : undefined;
92
- }
93
- /** The last resort: through a gateway, what it serves; otherwise what a held key recommends. */
94
- export async function fallbackRef(store, only, gateway = false) {
95
- return ((gateway ? await gatewayDefaultRef(only) : undefined) ?? defaultRef(store, only, gateway));
96
- }
97
- const EMPTY = { version: 1 };
98
- export const readMeta = () => readJson(paths.meta(), EMPTY);
99
- export function writeMeta(file) {
100
- writeJson(paths.meta(), file);
101
- }
102
- // ---------------------------------------------------------------------------
103
- // Refs
104
- // ---------------------------------------------------------------------------
105
- /**
106
- * The provider a misspelt prefix was reaching for, if that is what it is.
107
- *
108
- * `vertes/gemini-3.8-flash` is shaped exactly like the OpenRouter id
109
- * `meta-llama/llama-4`, so an unknown prefix cannot be an error on its own —
110
- * only one close enough to a real provider name to be a slip of the hand.
111
- */
112
- export function misspelledProvider(ref) {
113
- const slash = ref.indexOf('/');
114
- if (slash <= 0) {
115
- return undefined;
116
- }
117
- const head = ref.slice(0, slash).toLowerCase();
118
- if (PROVIDER_NAMES.has(head)) {
119
- return undefined;
120
- }
121
- for (const name of PROVIDER_NAMES) {
122
- // Two, so that a transposition — which Levenshtein counts twice — reads
123
- // as the typo it is. No provider name is short enough for that to be loose.
124
- if (distance(head, name) <= 2) {
125
- return name;
126
- }
127
- }
128
- return undefined;
129
- }
130
- /** Levenshtein, one row at a time. Both operands are a word long. */
131
- function distance(a, b) {
132
- if (Math.abs(a.length - b.length) > 2) {
133
- return 3;
134
- }
135
- let row = Array.from({ length: b.length + 1 }, (_, i) => i);
136
- for (let i = 1; i <= a.length; i++) {
137
- const next = [i];
138
- for (let j = 1; j <= b.length; j++) {
139
- const cost = a[i - 1] === b[j - 1] ? 0 : 1;
140
- next[j] = Math.min(next[j - 1] + 1, row[j] + 1, row[j - 1] + cost);
141
- }
142
- row = next;
143
- }
144
- return row[b.length];
145
- }
146
- //# sourceMappingURL=model.js.map
@@ -1,23 +0,0 @@
1
- export declare const SKILL_DIR = ".github/skills";
2
- export declare const PROMPT_DIR = ".github/prompts";
3
- /** `/project-review`, `project-review`, `project-review.prompt.md` or a path. */
4
- export declare function promptPath(dir: string, name: string): string;
5
- export interface StoredPrompt {
6
- name: string;
7
- path: string;
8
- description?: string;
9
- /** False for a skill marked `user-invocable: false` - the model's, not a command. */
10
- invocable: boolean;
11
- body: string;
12
- }
13
- /**
14
- * Frontmatter is the editor's business — `name`, `argument-hint`, the
15
- * invocation switches — and none of it means anything once the body is the
16
- * prompt, so only the body is sent. `description` is kept for the one line of
17
- * narration that says which command is running.
18
- */
19
- export declare function readPrompt(path: string, name: string, text: string): StoredPrompt;
20
- export declare function loadPrompt(dir: string, name: string): Promise<StoredPrompt>;
21
- /** The commands a person may type: every skill not marked for the model only, and any legacy prompt file. */
22
- export declare function listPrompts(dir: string): Promise<string[]>;
23
- //# sourceMappingURL=prompts.d.ts.map