@zenera/cli 1.1.23 → 1.1.25

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 (184) hide show
  1. package/README.md +88 -2
  2. package/dist/ask.d.ts +51 -0
  3. package/dist/ask.js +166 -0
  4. package/dist/banner.js +2 -2
  5. package/dist/batch.d.ts +83 -0
  6. package/dist/batch.js +413 -0
  7. package/dist/catalog.d.ts +11 -1
  8. package/dist/catalog.js +80 -7
  9. package/dist/command.d.ts +6 -0
  10. package/dist/commands/inspect.d.ts +57 -0
  11. package/dist/commands/inspect.js +539 -91
  12. package/dist/commands/list.js +128 -19
  13. package/dist/commands/memory.js +461 -32
  14. package/dist/commands/meta.js +311 -21
  15. package/dist/commands/models.js +110 -14
  16. package/dist/commands/open.js +4 -4
  17. package/dist/commands/run.js +175 -36
  18. package/dist/commands/sandbox.js +148 -15
  19. package/dist/engine.d.ts +24 -0
  20. package/dist/engine.js +61 -8
  21. package/dist/eventlog.d.ts +59 -0
  22. package/dist/eventlog.js +146 -0
  23. package/dist/liveness.d.ts +7 -0
  24. package/dist/liveness.js +20 -3
  25. package/dist/main.js +5 -2
  26. package/dist/meta/editor.d.ts +9 -0
  27. package/dist/meta/editor.js +60 -0
  28. package/dist/meta/finetune/children.d.ts +8 -0
  29. package/dist/meta/finetune/children.js +76 -0
  30. package/dist/meta/finetune/command.d.ts +30 -0
  31. package/dist/meta/finetune/command.js +338 -0
  32. package/dist/meta/finetune/dataset/anchors.d.ts +41 -0
  33. package/dist/meta/finetune/dataset/anchors.js +239 -0
  34. package/dist/meta/finetune/dataset/changes.d.ts +36 -0
  35. package/dist/meta/finetune/dataset/changes.js +319 -0
  36. package/dist/meta/finetune/dataset/command.d.ts +17 -0
  37. package/dist/meta/finetune/dataset/command.js +1011 -0
  38. package/dist/meta/finetune/dataset/drift.d.ts +33 -0
  39. package/dist/meta/finetune/dataset/drift.js +71 -0
  40. package/dist/meta/finetune/dataset/export.d.ts +26 -0
  41. package/dist/meta/finetune/dataset/export.js +51 -0
  42. package/dist/meta/finetune/dataset/index.d.ts +2 -0
  43. package/dist/meta/finetune/dataset/index.js +2 -0
  44. package/dist/meta/finetune/dataset/sample.d.ts +50 -0
  45. package/dist/meta/finetune/dataset/sample.js +197 -0
  46. package/dist/meta/finetune/dataset/schema.d.ts +33 -0
  47. package/dist/meta/finetune/dataset/schema.js +216 -0
  48. package/dist/meta/finetune/dataset/store.d.ts +35 -0
  49. package/dist/meta/finetune/dataset/store.js +177 -0
  50. package/dist/meta/finetune/dataset/types.d.ts +125 -0
  51. package/dist/meta/finetune/dataset/types.js +39 -0
  52. package/dist/meta/finetune/failure.d.ts +15 -0
  53. package/dist/meta/finetune/failure.js +26 -0
  54. package/dist/meta/finetune/feedback.d.ts +45 -0
  55. package/dist/meta/finetune/feedback.js +85 -0
  56. package/dist/meta/finetune/improvements.d.ts +51 -0
  57. package/dist/meta/finetune/improvements.js +244 -0
  58. package/dist/meta/finetune/index.d.ts +2 -0
  59. package/dist/meta/finetune/index.js +2 -0
  60. package/dist/meta/finetune/journal.d.ts +35 -0
  61. package/dist/meta/finetune/journal.js +135 -0
  62. package/dist/meta/finetune/live.d.ts +74 -0
  63. package/dist/meta/finetune/live.js +226 -0
  64. package/dist/meta/finetune/loop.d.ts +3 -0
  65. package/dist/meta/finetune/loop.js +114 -0
  66. package/dist/meta/finetune/memories.d.ts +47 -0
  67. package/dist/meta/finetune/memories.js +154 -0
  68. package/dist/meta/finetune/report.d.ts +33 -0
  69. package/dist/meta/finetune/report.js +1284 -0
  70. package/dist/meta/finetune/retry.d.ts +24 -0
  71. package/dist/meta/finetune/retry.js +96 -0
  72. package/dist/meta/finetune/sampler.d.ts +18 -0
  73. package/dist/meta/finetune/sampler.js +41 -0
  74. package/dist/meta/finetune/system.d.ts +27 -0
  75. package/dist/meta/finetune/system.js +132 -0
  76. package/dist/meta/finetune/train.d.ts +39 -0
  77. package/dist/meta/finetune/train.js +391 -0
  78. package/dist/meta/finetune/tui.d.ts +16 -0
  79. package/dist/meta/finetune/tui.js +291 -0
  80. package/dist/meta/finetune/tuning.d.ts +167 -0
  81. package/dist/meta/finetune/tuning.js +289 -0
  82. package/dist/meta/finetune/usage.d.ts +62 -0
  83. package/dist/meta/finetune/usage.js +225 -0
  84. package/dist/meta/host.d.ts +14 -0
  85. package/dist/meta/host.js +20 -0
  86. package/dist/meta/index.d.ts +11 -0
  87. package/dist/meta/index.js +11 -0
  88. package/dist/meta/launch.d.ts +81 -0
  89. package/dist/meta/launch.js +286 -0
  90. package/dist/meta/model.d.ts +44 -0
  91. package/dist/meta/model.js +119 -0
  92. package/dist/meta/prompts.d.ts +18 -0
  93. package/dist/meta/prompts.js +61 -0
  94. package/dist/meta/relay.d.ts +20 -0
  95. package/dist/meta/relay.js +123 -0
  96. package/dist/meta/tokens.d.ts +52 -0
  97. package/dist/meta/tokens.js +226 -0
  98. package/dist/meta/window.d.ts +61 -0
  99. package/dist/meta/window.js +198 -0
  100. package/dist/meta/wire.d.ts +42 -0
  101. package/dist/meta/wire.js +129 -0
  102. package/dist/modelref.d.ts +16 -0
  103. package/dist/modelref.js +41 -0
  104. package/dist/narrate.js +5 -2
  105. package/dist/podman.d.ts +42 -0
  106. package/dist/podman.js +198 -5
  107. package/dist/progress.d.ts +33 -0
  108. package/dist/progress.js +402 -0
  109. package/dist/projects.d.ts +0 -5
  110. package/dist/projects.js +2 -15
  111. package/dist/request.d.ts +45 -0
  112. package/dist/request.js +300 -0
  113. package/dist/sandbox.d.ts +2 -0
  114. package/dist/sandbox.js +20 -3
  115. package/dist/scaffold.d.ts +15 -6
  116. package/dist/scaffold.js +5 -60
  117. package/dist/session.d.ts +26 -1
  118. package/dist/session.js +46 -32
  119. package/dist/term.d.ts +5 -0
  120. package/dist/term.js +28 -3
  121. package/dist/trace.d.ts +84 -0
  122. package/dist/trace.js +737 -0
  123. package/dist/tui/models.d.ts +33 -0
  124. package/dist/tui/models.js +389 -0
  125. package/dist/tui/wrap.d.ts +5 -0
  126. package/dist/tui/wrap.js +12 -0
  127. package/dist/usage.d.ts +78 -0
  128. package/dist/usage.js +51 -0
  129. package/dist/validate.js +25 -3
  130. package/package.json +3 -2
  131. package/templates/editor/.github/copilot-instructions.md +41 -107
  132. package/templates/editor/.github/prompts/analyze.prompt.md +31 -0
  133. package/templates/editor/.github/prompts/dataset.prompt.md +108 -0
  134. package/templates/editor/.github/prompts/finetune-apply.prompt.md +91 -0
  135. package/templates/editor/.github/prompts/finetune.prompt.md +744 -0
  136. package/templates/editor/.github/prompts/new-agent.prompt.md +3 -1
  137. package/templates/editor/.github/prompts/new-skill.prompt.md +2 -0
  138. package/templates/editor/.github/prompts/project-review.prompt.md +4 -3
  139. package/templates/editor/.github/skills/zen-analyze-run/SKILL.md +483 -0
  140. package/templates/editor/.github/skills/zen-cli/SKILL.md +18 -4
  141. package/templates/editor/.github/skills/zen-cli/references/check.md +7 -5
  142. package/templates/editor/.github/skills/zen-cli/references/dataset.md +34 -0
  143. package/templates/editor/.github/skills/zen-cli/references/finetune.md +77 -0
  144. package/templates/editor/.github/skills/zen-cli/references/inspect.md +300 -21
  145. package/templates/editor/.github/skills/zen-cli/references/memory.md +121 -28
  146. package/templates/editor/.github/skills/zen-cli/references/meta.md +61 -0
  147. package/templates/editor/.github/skills/zen-cli/references/models.md +6 -2
  148. package/templates/editor/.github/skills/zen-cli/references/projects.md +12 -5
  149. package/templates/editor/.github/skills/zen-cli/references/rag.md +24 -6
  150. package/templates/editor/.github/skills/zen-cli/references/run.md +201 -4
  151. package/templates/editor/.github/skills/zen-cli/references/sandbox.md +10 -1
  152. package/templates/editor/.github/skills/zen-code-python/SKILL.md +123 -0
  153. package/templates/editor/.github/skills/zen-code-python/references/code_python.md +48 -0
  154. package/templates/editor/.github/skills/zen-dataset/SKILL.md +253 -0
  155. package/templates/editor/.github/skills/zen-finetune/SKILL.md +1791 -0
  156. package/templates/editor/.github/skills/zen-finetune/references/readme-template.md +268 -0
  157. package/templates/editor/.github/skills/zen-finetune/scripts/batch.mjs +390 -0
  158. package/templates/editor/.github/skills/zen-finetune/scripts/difficult.mjs +243 -0
  159. package/templates/editor/.github/skills/zen-finetune/scripts/memory.mjs +280 -0
  160. package/templates/editor/.github/skills/zen-finetune/scripts/next.mjs +398 -0
  161. package/templates/editor/.github/skills/zen-finetune/scripts/report.mjs +797 -0
  162. package/templates/editor/.github/skills/zen-finetune/scripts/select.mjs +354 -0
  163. package/templates/editor/.github/skills/zen-finetune/scripts/usage.mjs +722 -0
  164. package/templates/editor/.github/skills/zen-inspect/SKILL.md +431 -0
  165. package/templates/editor/.github/skills/zen-inspect-ask/SKILL.md +270 -0
  166. package/templates/editor/.github/skills/zen-memory/SKILL.md +78 -29
  167. package/templates/editor/.github/skills/zen-memory-warmup/SKILL.md +363 -531
  168. package/templates/editor/.github/skills/zen-rag-docs/SKILL.md +20 -8
  169. package/templates/editor/.github/skills/zen-review/SKILL.md +5 -3
  170. package/templates/editor/.github/skills/zen-review/scripts/check-paths.sh +5 -4
  171. package/templates/editor/.github/skills/zen-sandbox/SKILL.md +25 -2
  172. package/templates/editor/.github/skills/zen-sandbox-capacity/SKILL.md +334 -0
  173. package/templates/editor/.github/skills/zen-sandbox-capacity/references/loadtest.md +181 -0
  174. package/templates/editor/.github/skills/zen-sandbox-capacity/scripts/preflight_sandbox.sh +457 -0
  175. package/templates/editor/.github/skills/zen-topology/SKILL.md +283 -0
  176. package/templates/editor/.vscode/agents.schema.json +1 -1
  177. package/templates/editor/.vscode/settings.json +2 -0
  178. package/templates/project/agents/files-instructions.md +35 -13
  179. package/templates/project/agents/fork-instructions.md +27 -0
  180. package/templates/project/agents/memory-instructions.md +106 -34
  181. package/templates/project/agents/tools-instructions.md +7 -4
  182. package/templates/project/gitignore +5 -0
  183. package/dist/meta.d.ts +0 -221
  184. package/dist/meta.js +0 -684
@@ -0,0 +1,24 @@
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
@@ -0,0 +1,96 @@
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
@@ -0,0 +1,18 @@
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
@@ -0,0 +1,41 @@
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
+ return selection(t).find((c) => {
33
+ if (t.claimed.has(c.id)) {
34
+ return false;
35
+ }
36
+ const r = resultOf(t, c);
37
+ // Once per start: a sandbox that is down would only fail it again at once.
38
+ return !r || (r.state === 'failed' && !t.tried.has(c.id));
39
+ });
40
+ }
41
+ //# sourceMappingURL=sampler.js.map
@@ -0,0 +1,27 @@
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
@@ -0,0 +1,132 @@
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
@@ -0,0 +1,39 @@
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
+ }
28
+ export declare class VoidRun extends StepError {
29
+ }
30
+ /** The container engine failed: every run after this one would fail the same way. */
31
+ export declare class SandboxDown extends StepError {
32
+ }
33
+ /** The case keeps one analyze session per revision, so each analysis remembers the last. */
34
+ export declare function sessionOf(t: Tuning, c: Case): string | undefined;
35
+ export declare function markCompleted(t: Tuning, c: Case): void;
36
+ export declare function markDifficult(t: Tuning, c: Case, phase: Phase, reason: string): void;
37
+ /** Something outside the prose broke. The case keeps its tries and runs again at the next start. */
38
+ export declare function markFailed(t: Tuning, c: Case, phase: Phase, reason: string): void;
39
+ //# sourceMappingURL=train.d.ts.map