@zenera/cli 1.2.8 → 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
@@ -1,24 +0,0 @@
1
- import type { Case } from './dataset/types.ts';
2
- import type { Tuning } from './tuning.ts';
3
- export interface RetryPick {
4
- /** every difficult case */
5
- difficult?: boolean;
6
- classes?: string[];
7
- /** ids or globs */
8
- ids: string[];
9
- yes?: boolean;
10
- }
11
- export interface RetryPlan {
12
- take: Case[];
13
- /** matched, but not difficult: why each is left as it is */
14
- skip: {
15
- id: string;
16
- why: string;
17
- }[];
18
- /** what the cases taken spent last round, as a guide to what another will */
19
- tokens: number;
20
- }
21
- export declare function planRetry(t: Tuning, pick: RetryPick): RetryPlan;
22
- /** Moves each case's round aside, under the loop's lock so no tuning is writing into it. */
23
- export declare function retry(t: Tuning, pick: RetryPick): Promise<RetryPlan>;
24
- //# sourceMappingURL=retry.d.ts.map
@@ -1,96 +0,0 @@
1
- import { anyOf, claimLock, ownLock, wildcard } from '@zenera/neo';
2
- import { mkdirSync, renameSync, unlinkSync } from 'node:fs';
3
- import { hostname } from 'node:os';
4
- import { join } from 'node:path';
5
- import { CliError, confirm, EXIT, note, usageError } from "../host.js";
6
- import { DatasetStore } from "./dataset/store.js";
7
- import { recover } from "./journal.js";
8
- import { resultOf, selection } from "./sampler.js";
9
- import { short, STAGES, total } from "./usage.js";
10
- export function planRetry(t, pick) {
11
- if (!pick.difficult && !pick.classes?.length && pick.ids.length === 0) {
12
- throw usageError('retry which cases?', 'name them (ids or globs), or --difficult for all of them, or --class <c>');
13
- }
14
- const ids = anyOf(pick.ids.map((p) => wildcard(p)));
15
- const plan = { take: [], skip: [], tokens: 0 };
16
- for (const c of selection(t)) {
17
- // Names add to --difficult; a class narrows both.
18
- const named = ids?.(c.id) ?? false;
19
- if (ids && !named && !pick.difficult) {
20
- continue;
21
- }
22
- if (pick.classes?.length && !pick.classes.includes(c.class ?? '')) {
23
- continue;
24
- }
25
- const r = resultOf(t, c);
26
- if (r?.state === 'difficult') {
27
- plan.take.push(c);
28
- for (const stage of STAGES) {
29
- const s = total(r.tokens?.[stage]);
30
- plan.tokens += s.input + s.output;
31
- }
32
- continue;
33
- }
34
- // Only named cases are worth a word; a class or --difficult says nothing of the rest.
35
- if (named) {
36
- plan.skip.push({
37
- id: c.id,
38
- why: !r
39
- ? 'not finished yet - start carries on with it'
40
- : r.state === 'failed'
41
- ? 'failed, not difficult - start resumes it'
42
- : 'completed - change the case to run it again',
43
- });
44
- }
45
- }
46
- return plan;
47
- }
48
- /** Moves each case's round aside, under the loop's lock so no tuning is writing into it. */
49
- export async function retry(t, pick) {
50
- const plan = planRetry(t, pick);
51
- for (const s of plan.skip) {
52
- note(`${s.id}: ${s.why}`);
53
- }
54
- if (plan.take.length === 0) {
55
- note('nothing to retry');
56
- return plan;
57
- }
58
- const said = `${plan.take.length} case(s) for another round - about ${short(plan.tokens)} tokens, going by their last round`;
59
- if (!pick.yes && !(await confirm(`${said}. Go ahead?`))) {
60
- note('left as they were');
61
- return { ...plan, take: [] };
62
- }
63
- mkdirSync(t.dir, { recursive: true });
64
- const lock = join(t.dir, 'loop.lock');
65
- claimLock(lock, ownLock(), (held) => new CliError(`a tuning is running here (pid ${held.pid})`, EXIT.failed, 'stop it first: zen meta finetune stop'));
66
- try {
67
- // A step a kill cut off points into the very folders about to move.
68
- await recover(t);
69
- const store = DatasetStore.open(t.root);
70
- for (const c of plan.take) {
71
- const round = t.round(c);
72
- mkdirSync(t.roundsDir(c), { recursive: true });
73
- renameSync(t.caseDir(c), join(t.roundsDir(c), `r${c.rev}.${round}`));
74
- t.event({ what: 'retry', case: c.id, rev: c.rev, detail: `round ${round + 1}` });
75
- store.note(c.id, {
76
- type: 'note',
77
- at: new Date().toISOString(),
78
- kind: 'observation',
79
- caseRev: c.rev,
80
- text: `retried: round ${round} was difficult, round ${round + 1} starts on system v${t.system.version()}`,
81
- by: { prompt: 'finetune', host: hostname() },
82
- });
83
- }
84
- }
85
- finally {
86
- try {
87
- unlinkSync(lock);
88
- }
89
- catch {
90
- // Taken over as stale; nothing to give back.
91
- }
92
- }
93
- note(`${said}. Run them: zen meta finetune start`);
94
- return plan;
95
- }
96
- //# sourceMappingURL=retry.js.map
@@ -1,18 +0,0 @@
1
- import type { Case } from './dataset/types.ts';
2
- import { type Tuning } from './tuning.ts';
3
- import type { ByStage } from './usage.ts';
4
- export interface Result {
5
- /** `failed`: something outside the prose broke, so nothing was learned and it runs again */
6
- state: 'completed' | 'difficult' | 'failed';
7
- phase: 'nomem' | 'mem';
8
- reason?: string;
9
- caseRev: number;
10
- at: string;
11
- /** per stage and model, over every try of the case */
12
- tokens?: ByStage;
13
- }
14
- /** The cases this tuning covers, in the order they are taken. */
15
- export declare function selection(t: Tuning): Case[];
16
- export declare function resultOf(t: Tuning, c: Case): Result | undefined;
17
- export declare function nextCase(t: Tuning): Case | undefined;
18
- //# sourceMappingURL=sampler.d.ts.map
@@ -1,47 +0,0 @@
1
- import { anyOf, wildcard } from '@zenera/neo';
2
- import { existsSync } from 'node:fs';
3
- import { join } from 'node:path';
4
- import { sample } from "./dataset/sample.js";
5
- import { DatasetStore } from "./dataset/store.js";
6
- import { readJson } from "./tuning.js";
7
- /** The cases this tuning covers, in the order they are taken. */
8
- export function selection(t) {
9
- const store = DatasetStore.open(t.root);
10
- const cases = store.all();
11
- const ids = anyOf((t.config.ids ?? []).map((p) => wildcard(p)));
12
- const drawn = sample(cases, {
13
- status: 'active',
14
- ...(t.config.classes?.length ? { classes: t.config.classes } : {}),
15
- ...(t.config.rubric !== undefined ? { rubric: t.config.rubric } : {}),
16
- ...(ids ? { ids } : {}),
17
- }, { by: ['class'], weights: new Map(), order: ['rubric'], seed: t.config.seed }, () => []);
18
- const byId = new Map(cases.map((c) => [c.id, c]));
19
- const ordered = drawn.ids.map((id) => byId.get(id));
20
- return t.config.limit ? ordered.slice(0, t.config.limit) : ordered;
21
- }
22
- export function resultOf(t, c) {
23
- const file = join(t.caseDir(c), 'result.json');
24
- const r = existsSync(file) ? readJson(file) : undefined;
25
- // Written before `failed` existed: a void run or an error was filed as difficult.
26
- if (r?.state === 'difficult' && /^(void|error):/.test(r.reason ?? '')) {
27
- return { ...r, state: 'failed' };
28
- }
29
- return r;
30
- }
31
- export function nextCase(t) {
32
- if (t.more !== undefined && t.tried.size >= t.more) {
33
- return undefined;
34
- }
35
- return selection(t).find((c) => {
36
- if (t.claimed.has(c.id)) {
37
- return false;
38
- }
39
- const r = resultOf(t, c);
40
- if (r) {
41
- // Once per start: a sandbox that is down would only fail it again at once.
42
- return r.state === 'failed' && !t.tried.has(c.id);
43
- }
44
- return true;
45
- });
46
- }
47
- //# sourceMappingURL=sampler.js.map
@@ -1,27 +0,0 @@
1
- export interface VersionRow {
2
- v: number;
3
- hash: string;
4
- at: string;
5
- from: 'start' | 'external' | 'apply';
6
- apply?: string;
7
- }
8
- export declare class SystemVersions {
9
- #private;
10
- readonly root: string;
11
- readonly dir: string;
12
- constructor(root: string, dir: string);
13
- hash(): string;
14
- rows(): VersionRow[];
15
- current(): VersionRow | undefined;
16
- version(): number;
17
- snapshotDir(v: number): string;
18
- /** A new version when the system moved since the last one; the last one otherwise. */
19
- record(from: VersionRow['from'], apply?: string): VersionRow;
20
- /** Puts version `v` back, exactly: files added since are removed. */
21
- restore(v: number): void;
22
- /** Forgets the versions an apply recorded, as if it never ran. */
23
- drop(apply: string): void;
24
- /** `git diff` between two versions' copies; a file list where git is missing. */
25
- diff(a: number, b: number): string;
26
- }
27
- //# sourceMappingURL=system.d.ts.map
@@ -1,132 +0,0 @@
1
- import { spawnSync } from 'node:child_process';
2
- import { createHash } from 'node:crypto';
3
- import { appendFileSync, copyFileSync, cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync, } from 'node:fs';
4
- import { join } from 'node:path';
5
- // ---------------------------------------------------------------------------
6
- // The system under tuning, as numbered versions
7
- //
8
- // What tuning changes is `agents.yaml` and everything under `agents/`, so that
9
- // is the system: hashed as a whole, copied whole at every version, so any
10
- // version can be diffed against another or put back. A version is recorded
11
- // when the hash moves - by an apply, or by someone's hand between sessions.
12
- // ---------------------------------------------------------------------------
13
- const CONFIG_FILES = ['agents.yaml', 'agents.yml'];
14
- const AGENTS = 'agents';
15
- const pad = (n) => String(n).padStart(2, '0');
16
- export class SystemVersions {
17
- root;
18
- dir;
19
- constructor(root, dir) {
20
- this.root = root;
21
- this.dir = dir;
22
- }
23
- #files() {
24
- const found = CONFIG_FILES.filter((f) => existsSync(join(this.root, f)));
25
- const agents = join(this.root, AGENTS);
26
- if (existsSync(agents)) {
27
- for (const entry of readdirSync(agents, { recursive: true, withFileTypes: true })) {
28
- if (entry.isFile() && entry.name !== '.DS_Store') {
29
- const rel = join(entry.parentPath, entry.name).slice(this.root.length + 1);
30
- found.push(rel.split('\\').join('/'));
31
- }
32
- }
33
- }
34
- return found.sort();
35
- }
36
- hash() {
37
- const h = createHash('sha256');
38
- for (const rel of this.#files()) {
39
- h.update(rel)
40
- .update('\0')
41
- .update(readFileSync(join(this.root, rel)))
42
- .update('\0');
43
- }
44
- return h.digest('hex').slice(0, 16);
45
- }
46
- rows() {
47
- try {
48
- return readFileSync(join(this.dir, 'systems.jsonl'), 'utf8')
49
- .split('\n')
50
- .filter(Boolean)
51
- .map((line) => JSON.parse(line));
52
- }
53
- catch {
54
- return [];
55
- }
56
- }
57
- current() {
58
- return this.rows().at(-1);
59
- }
60
- version() {
61
- return this.current()?.v ?? 0;
62
- }
63
- snapshotDir(v) {
64
- return join(this.dir, `v${pad(v)}`);
65
- }
66
- /** A new version when the system moved since the last one; the last one otherwise. */
67
- record(from, apply) {
68
- const hash = this.hash();
69
- const last = this.current();
70
- if (last?.hash === hash) {
71
- return last;
72
- }
73
- const row = {
74
- v: (last?.v ?? 0) + 1,
75
- hash,
76
- at: new Date().toISOString(),
77
- from: from === 'start' && last ? 'external' : from,
78
- ...(apply ? { apply } : {}),
79
- };
80
- const to = this.snapshotDir(row.v);
81
- rmSync(to, { recursive: true, force: true });
82
- mkdirSync(to, { recursive: true });
83
- for (const f of CONFIG_FILES) {
84
- if (existsSync(join(this.root, f))) {
85
- copyFileSync(join(this.root, f), join(to, f));
86
- }
87
- }
88
- if (existsSync(join(this.root, AGENTS))) {
89
- cpSync(join(this.root, AGENTS), join(to, AGENTS), { recursive: true });
90
- }
91
- mkdirSync(this.dir, { recursive: true });
92
- appendFileSync(join(this.dir, 'systems.jsonl'), `${JSON.stringify(row)}\n`);
93
- return row;
94
- }
95
- /** Puts version `v` back, exactly: files added since are removed. */
96
- restore(v) {
97
- const from = this.snapshotDir(v);
98
- for (const f of CONFIG_FILES) {
99
- rmSync(join(this.root, f), { force: true });
100
- if (existsSync(join(from, f))) {
101
- copyFileSync(join(from, f), join(this.root, f));
102
- }
103
- }
104
- rmSync(join(this.root, AGENTS), { recursive: true, force: true });
105
- if (existsSync(join(from, AGENTS))) {
106
- cpSync(join(from, AGENTS), join(this.root, AGENTS), { recursive: true });
107
- }
108
- }
109
- /** Forgets the versions an apply recorded, as if it never ran. */
110
- drop(apply) {
111
- const rows = this.rows();
112
- const keep = rows.filter((r) => r.apply !== apply);
113
- if (keep.length === rows.length) {
114
- return;
115
- }
116
- for (const r of rows) {
117
- if (r.apply === apply) {
118
- rmSync(this.snapshotDir(r.v), { recursive: true, force: true });
119
- }
120
- }
121
- writeFileSync(join(this.dir, 'systems.jsonl'), keep.map((r) => `${JSON.stringify(r)}\n`).join(''));
122
- }
123
- /** `git diff` between two versions' copies; a file list where git is missing. */
124
- diff(a, b) {
125
- const res = spawnSync('git', ['diff', '--no-index', '--no-color', '--', `v${pad(a)}`, `v${pad(b)}`], { cwd: this.dir, encoding: 'utf8' });
126
- if (res.error || (res.status !== 0 && res.status !== 1)) {
127
- return `(git diff unavailable) v${pad(a)} -> v${pad(b)}\n`;
128
- }
129
- return res.stdout;
130
- }
131
- }
132
- //# sourceMappingURL=system.js.map
@@ -1,43 +0,0 @@
1
- import type { TokenUsage } from '@zenera/neo';
2
- import type { Case } from './dataset/types.ts';
3
- import { StepError } from './failure.ts';
4
- import { type Phase } from './feedback.ts';
5
- import { type Seat, type Tuning } from './tuning.ts';
6
- import { type ByModel, type RunMetrics } from './usage.ts';
7
- export declare function train(t: Tuning, s: Seat, c: Case): Promise<void>;
8
- export interface Run {
9
- /** the run directory under sessions/ */
10
- dir: string;
11
- /** the memory it ran with and committed into */
12
- memory: string;
13
- /** its own empty directory, the root of the agent's file tools */
14
- workspace?: string;
15
- /** the system version it ran on */
16
- system: number;
17
- report?: string;
18
- graph?: string;
19
- /** the run's own error, when it failed - still worth analyzing */
20
- failed?: string;
21
- turns?: number;
22
- usage?: TokenUsage;
23
- /** per model, from the run's trajectory */
24
- tokens?: ByModel;
25
- metrics?: RunMetrics;
26
- durationMs?: number;
27
- /** skills an apply made for this case that the run never loaded */
28
- missedSkills?: string[];
29
- }
30
- export declare class VoidRun extends StepError {
31
- }
32
- /** The container engine failed: every run after this one would fail the same way. */
33
- export declare class SandboxDown extends StepError {
34
- }
35
- /** One `zen run`. Writes run.json, or says why the run was void. */
36
- export declare function runOnce(t: Tuning, c: Case, dir: string, memory?: string, expect?: string[]): Promise<string | undefined>;
37
- /** The meta agent's answer is the human report: kept as analysis.md beside the feedback. A retry keeps its own envelope, so its tokens are counted too. */
38
- export declare function keepAnalysis(dir: string, stdout: string, replace?: boolean): void;
39
- export declare function markCompleted(t: Tuning, c: Case): void;
40
- export declare function markDifficult(t: Tuning, c: Case, phase: Phase, reason: string): void;
41
- /** Something outside the prose broke. The case keeps its tries and runs again at the next start. */
42
- export declare function markFailed(t: Tuning, c: Case, phase: Phase, reason: string): void;
43
- //# sourceMappingURL=train.d.ts.map