@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,35 +0,0 @@
1
- import { type By, type Case, type ChangeRow, type JournalRow, type Manifest, type NoteRow, type RevisionRow } from './types.ts';
2
- export declare function whoIsThis(): By;
3
- export interface Commit {
4
- rev: number;
5
- rows: ChangeRow[];
6
- revision: RevisionRow;
7
- manifest: Manifest;
8
- /** cases whose stored source hash moved with no change worth a revision */
9
- refreshed: Case[];
10
- }
11
- export declare class DatasetStore {
12
- #private;
13
- readonly root: string;
14
- readonly dir: string;
15
- manifest: Manifest;
16
- private constructor();
17
- /** `write` claims the directory, creating it if it does not exist yet. */
18
- static open(root: string, options?: {
19
- write?: boolean;
20
- }): DatasetStore;
21
- exists(): boolean;
22
- ids(): string[];
23
- get(id: string): Case | undefined;
24
- all(): Case[];
25
- journal(id: string): JournalRow[];
26
- /** The case as it stood at a revision, read back from its journal. */
27
- at(id: string, rev: number): Case | undefined;
28
- revisions(): RevisionRow[];
29
- /** Cases written by an apply that never reached its manifest. */
30
- unfinished(): string[];
31
- note(id: string, row: NoteRow): void;
32
- commit(commit: Commit): void;
33
- release(): void;
34
- }
35
- //# sourceMappingURL=store.d.ts.map
@@ -1,177 +0,0 @@
1
- import { claimLock, ownLock } from '@zenera/neo';
2
- import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from 'node:fs';
3
- import { hostname } from 'node:os';
4
- import { join } from 'node:path';
5
- import { CliError, EXIT, META_PROMPT_ENV, META_SESSION_ENV } from "../../host.js";
6
- import { DATASET_DIR, DATASET_VERSION, } from "./types.js";
7
- // ---------------------------------------------------------------------------
8
- // The store
9
- //
10
- // Plain files, so git can diff them and a person can read them: a case per
11
- // file, a journal per case, a line per revision, and a manifest written last —
12
- // the manifest's revision is the commit marker, so an apply killed half-way
13
- // shows up as cases newer than it.
14
- //
15
- // Writes take the directory lock; reads never do. A note is one appended line
16
- // and takes no lock either, so an `analyze` running beside an apply can still
17
- // say what it found.
18
- // ---------------------------------------------------------------------------
19
- const MANIFEST = 'manifest.json';
20
- const REVISIONS = 'revisions.jsonl';
21
- const CASES = 'cases';
22
- const LOG = 'log';
23
- const LOCK = '.lock';
24
- export function whoIsThis() {
25
- const session = process.env[META_SESSION_ENV]?.trim();
26
- const prompt = process.env[META_PROMPT_ENV]?.trim();
27
- return {
28
- ...(session ? { session } : {}),
29
- ...(prompt ? { prompt } : {}),
30
- host: hostname(),
31
- };
32
- }
33
- function atomic(path, text) {
34
- const tmp = `${path}.tmp`;
35
- writeFileSync(tmp, text);
36
- renameSync(tmp, path);
37
- }
38
- function lines(path) {
39
- let text;
40
- try {
41
- text = readFileSync(path, 'utf8');
42
- }
43
- catch {
44
- return [];
45
- }
46
- return text
47
- .split('\n')
48
- .filter((line) => line.trim())
49
- .flatMap((line) => {
50
- try {
51
- return [JSON.parse(line)];
52
- }
53
- catch {
54
- return [];
55
- }
56
- });
57
- }
58
- const empty = () => ({ version: DATASET_VERSION, revision: 0, sources: {}, ignored: [] });
59
- export class DatasetStore {
60
- root;
61
- dir;
62
- manifest;
63
- #locked = false;
64
- constructor(root) {
65
- this.root = root;
66
- this.dir = join(root, DATASET_DIR);
67
- this.manifest = empty();
68
- try {
69
- const read = JSON.parse(readFileSync(join(this.dir, MANIFEST), 'utf8'));
70
- if (read.version !== DATASET_VERSION) {
71
- throw new CliError(`${this.dir} is dataset version ${read.version}; this zen reads ${DATASET_VERSION}`, EXIT.invalid, 'upgrade zen');
72
- }
73
- this.manifest = { ...empty(), ...read };
74
- }
75
- catch (err) {
76
- if (err instanceof CliError) {
77
- throw err;
78
- }
79
- }
80
- }
81
- /** `write` claims the directory, creating it if it does not exist yet. */
82
- static open(root, options = {}) {
83
- const store = new DatasetStore(root);
84
- if (options.write) {
85
- mkdirSync(join(store.dir, CASES), { recursive: true });
86
- mkdirSync(join(store.dir, LOG), { recursive: true });
87
- claimLock(join(store.dir, LOCK), ownLock(), (held) => new CliError(`the dataset is being written (pid ${held.pid}, since ${held.startedAt})`, EXIT.failed, `wait for it, or remove ${join(store.dir, LOCK)} if that process crashed`));
88
- store.#locked = true;
89
- }
90
- return store;
91
- }
92
- exists() {
93
- return existsSync(join(this.dir, MANIFEST));
94
- }
95
- ids() {
96
- try {
97
- return readdirSync(join(this.dir, CASES))
98
- .filter((f) => f.endsWith('.json'))
99
- .map((f) => f.slice(0, -'.json'.length))
100
- .sort();
101
- }
102
- catch {
103
- return [];
104
- }
105
- }
106
- get(id) {
107
- try {
108
- return JSON.parse(readFileSync(join(this.dir, CASES, `${id}.json`), 'utf8'));
109
- }
110
- catch {
111
- return undefined;
112
- }
113
- }
114
- all() {
115
- return this.ids().flatMap((id) => this.get(id) ?? []);
116
- }
117
- journal(id) {
118
- return lines(join(this.dir, LOG, `${id}.jsonl`));
119
- }
120
- /** The case as it stood at a revision, read back from its journal. */
121
- at(id, rev) {
122
- let found;
123
- for (const row of this.journal(id)) {
124
- if (row.type === 'change' && row.rev <= rev) {
125
- found = row.case;
126
- }
127
- }
128
- return found;
129
- }
130
- revisions() {
131
- return lines(join(this.dir, REVISIONS));
132
- }
133
- /** Cases written by an apply that never reached its manifest. */
134
- unfinished() {
135
- return this.all()
136
- .filter((c) => c.rev > this.manifest.revision)
137
- .map((c) => c.id);
138
- }
139
- note(id, row) {
140
- mkdirSync(join(this.dir, LOG), { recursive: true });
141
- appendFileSync(join(this.dir, LOG, `${id}.jsonl`), `${JSON.stringify(row)}\n`);
142
- }
143
- commit(commit) {
144
- if (!this.#locked) {
145
- throw new Error('commit without the dataset lock');
146
- }
147
- for (const row of commit.rows) {
148
- atomic(join(this.dir, CASES, `${row.case.id}.json`), `${JSON.stringify(row.case, null, 4)}\n`);
149
- appendFileSync(join(this.dir, LOG, `${row.case.id}.jsonl`), `${JSON.stringify(row)}\n`);
150
- }
151
- for (const c of commit.refreshed) {
152
- atomic(join(this.dir, CASES, `${c.id}.json`), `${JSON.stringify(c, null, 4)}\n`);
153
- }
154
- if (commit.rows.length > 0) {
155
- appendFileSync(join(this.dir, REVISIONS), `${JSON.stringify(commit.revision)}\n`);
156
- }
157
- this.manifest = {
158
- ...commit.manifest,
159
- revision: commit.rows.length > 0 ? commit.rev : commit.manifest.revision,
160
- updatedAt: new Date().toISOString(),
161
- };
162
- atomic(join(this.dir, MANIFEST), `${JSON.stringify(this.manifest, null, 4)}\n`);
163
- }
164
- release() {
165
- if (!this.#locked) {
166
- return;
167
- }
168
- this.#locked = false;
169
- try {
170
- unlinkSync(join(this.dir, LOCK));
171
- }
172
- catch {
173
- // Already gone, or taken over as stale.
174
- }
175
- }
176
- }
177
- //# sourceMappingURL=store.js.map
@@ -1,127 +0,0 @@
1
- export declare const DATASET_DIR = "dataset";
2
- export declare const DATASET_VERSION = 1;
3
- export declare const COMPLEXITIES: readonly ["simple", "medium", "complex"];
4
- export type Complexity = (typeof COMPLEXITIES)[number];
5
- export declare const STATUSES: readonly ["active", "retired"];
6
- export type Status = (typeof STATUSES)[number];
7
- export declare const NOTE_KINDS: readonly ["graded", "analyze", "difficult", "rubric-suspect", "observation"];
8
- export type NoteKind = (typeof NOTE_KINDS)[number];
9
- export declare const VERDICTS: readonly ["right", "wrong", "void"];
10
- export type Verdict = (typeof VERDICTS)[number];
11
- /** A case id names a directory under a batch dir, so it is one path segment. */
12
- export declare const CASE_ID: RegExp;
13
- export declare const MEDIA_KINDS: readonly ["image", "audio", "video", "file"];
14
- export type MediaKind = (typeof MEDIA_KINDS)[number];
15
- export type Part = string | {
16
- text: string;
17
- } | ({
18
- [K in MediaKind]?: string;
19
- } & {
20
- mimeType?: string;
21
- });
22
- export type Input = string | Part[];
23
- export interface RubricItem {
24
- id: string;
25
- text: string;
26
- }
27
- /** Where in a source file a case came from. Neither key means the whole file. */
28
- export interface Anchor {
29
- heading?: string[];
30
- pointer?: string;
31
- }
32
- export interface Source {
33
- /** project-relative */
34
- file: string;
35
- anchor?: Anchor;
36
- /** of the section the anchor names, when the case was last applied */
37
- sha256?: string;
38
- }
39
- export interface Case {
40
- id: string;
41
- rev: number;
42
- status: Status;
43
- class?: string;
44
- complexity?: Complexity;
45
- tags?: string[];
46
- input: Input;
47
- rubric: RubricItem[];
48
- expected?: string;
49
- notes?: string;
50
- source?: Source;
51
- /** fields a re-extraction must not overwrite */
52
- overrides?: string[];
53
- }
54
- /** A change to these is a different question: earlier results no longer count. */
55
- export declare const RESTART_FIELDS: readonly ["input", "rubric", "expected"];
56
- /** Fields a proposal or `update --set` may write. */
57
- export declare const CONTENT_FIELDS: readonly ["class", "complexity", "tags", "input", "rubric", "expected", "notes", "source"];
58
- export type ContentField = (typeof CONTENT_FIELDS)[number];
59
- /** Who did it: read from the environment `zen meta` gives its agent. */
60
- export interface By {
61
- session?: string;
62
- prompt?: string;
63
- host: string;
64
- }
65
- export interface FieldChange {
66
- path: string;
67
- from?: unknown;
68
- to?: unknown;
69
- }
70
- export type ChangeOp = 'add' | 'update' | 'retire' | 'restore';
71
- export interface ChangeRow {
72
- type: 'change';
73
- rev: number;
74
- at: string;
75
- op: ChangeOp;
76
- changes: FieldChange[];
77
- why: string;
78
- by: By;
79
- /** the case as it stood after this change, so any revision can be read back */
80
- case: Case;
81
- }
82
- export interface NoteRow {
83
- type: 'note';
84
- at: string;
85
- kind: NoteKind;
86
- /** the case revision the note is about */
87
- caseRev: number;
88
- run?: string;
89
- verdict?: Verdict;
90
- rubric?: Record<string, Grade>;
91
- text: string;
92
- by: By;
93
- }
94
- /** `invalid`: the rubric line itself is broken - it says how one implementation did it, not what is right. */
95
- export type Grade = 'pass' | 'fail' | 'invalid';
96
- export type JournalRow = ChangeRow | NoteRow;
97
- export interface Ignored {
98
- file: string;
99
- anchor: Anchor;
100
- why: string;
101
- rev: number;
102
- }
103
- export interface Manifest {
104
- version: number;
105
- revision: number;
106
- updatedAt?: string;
107
- /** whole-file hash of every source a case or an ignore names */
108
- sources: Record<string, {
109
- sha256: string;
110
- }>;
111
- ignored: Ignored[];
112
- }
113
- export interface RevisionRow {
114
- rev: number;
115
- at: string;
116
- why: string;
117
- by: By;
118
- added: string[];
119
- updated: string[];
120
- retired: string[];
121
- restored: string[];
122
- /** cases whose input, rubric or expected changed */
123
- restarted: string[];
124
- }
125
- export declare const anchorText: (anchor: Anchor | undefined) => string;
126
- export declare const sameAnchor: (a: Anchor | undefined, b: Anchor | undefined) => boolean;
127
- //# sourceMappingURL=types.d.ts.map
@@ -1,39 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- // A dataset, as stored
3
- //
4
- // One file per case holds what the case is now; one append-only journal per
5
- // case holds how it got there and what was learned about it. Nothing is ever
6
- // deleted: a removed case is `retired`, so an id is never reused and an old run
7
- // that names it still resolves.
8
- // ---------------------------------------------------------------------------
9
- export const DATASET_DIR = 'dataset';
10
- export const DATASET_VERSION = 1;
11
- export const COMPLEXITIES = ['simple', 'medium', 'complex'];
12
- export const STATUSES = ['active', 'retired'];
13
- export const NOTE_KINDS = [
14
- 'graded',
15
- 'analyze',
16
- 'difficult',
17
- 'rubric-suspect',
18
- 'observation',
19
- ];
20
- export const VERDICTS = ['right', 'wrong', 'void'];
21
- /** A case id names a directory under a batch dir, so it is one path segment. */
22
- export const CASE_ID = /^[A-Za-z0-9_.-]+$/;
23
- export const MEDIA_KINDS = ['image', 'audio', 'video', 'file'];
24
- /** A change to these is a different question: earlier results no longer count. */
25
- export const RESTART_FIELDS = ['input', 'rubric', 'expected'];
26
- /** Fields a proposal or `update --set` may write. */
27
- export const CONTENT_FIELDS = [
28
- 'class',
29
- 'complexity',
30
- 'tags',
31
- 'input',
32
- 'rubric',
33
- 'expected',
34
- 'notes',
35
- 'source',
36
- ];
37
- export const anchorText = (anchor) => anchor?.heading ? anchor.heading.join(' > ') : (anchor?.pointer ?? '(whole file)');
38
- export const sameAnchor = (a, b) => anchorText(a) === anchorText(b);
39
- //# sourceMappingURL=types.js.map
@@ -1,15 +0,0 @@
1
- /** A step that failed, with the log that says why. */
2
- export declare class StepError extends Error {
3
- readonly log?: string | undefined;
4
- constructor(message: string, log?: string | undefined);
5
- }
6
- export declare const sizeOf: (file: string) => number;
7
- /**
8
- * What broke, from what a step appended to its log since `from`: the provider's own line before
9
- * zen's generic `error ...`, and the meta agent's fuller log when the step names one.
10
- */
11
- export declare function errorIn(log: string, from?: number): {
12
- message?: string;
13
- log: string;
14
- };
15
- //# sourceMappingURL=failure.d.ts.map
@@ -1,26 +0,0 @@
1
- import { existsSync, readFileSync, statSync } from 'node:fs';
2
- /** A step that failed, with the log that says why. */
3
- export class StepError extends Error {
4
- log;
5
- constructor(message, log) {
6
- super(message);
7
- this.log = log;
8
- }
9
- }
10
- export const sizeOf = (file) => (existsSync(file) ? statSync(file).size : 0);
11
- /**
12
- * What broke, from what a step appended to its log since `from`: the provider's own line before
13
- * zen's generic `error ...`, and the meta agent's fuller log when the step names one.
14
- */
15
- export function errorIn(log, from = 0) {
16
- const text = existsSync(log) ? readFileSync(log).subarray(from).toString('utf8') : '';
17
- const lines = text
18
- .split('\n')
19
- .map((l) => l.trim())
20
- .filter(Boolean);
21
- const provider = lines.findLast((l) => /\bHTTP \d{3}\b|^"\d{3} [^"]+" \(\d{3}\)|not found|quota|rate limit|unavailable|timed out/i.test(l));
22
- const exited = lines.findLast((l) => /^error\s/.test(l))?.replace(/^error\s+/, '');
23
- const meta = lines.findLast((l) => /^log\s+\//.test(l))?.replace(/^log\s+/, '');
24
- return { message: provider ?? exited, log: meta ?? log };
25
- }
26
- //# sourceMappingURL=failure.js.map
@@ -1,57 +0,0 @@
1
- import { type Grade, type Verdict } from './dataset/types.ts';
2
- export type Phase = 'nomem' | 'mem';
3
- export interface Improvement {
4
- id: string;
5
- kind?: string;
6
- file?: string;
7
- change: string;
8
- why?: string;
9
- expect?: string;
10
- }
11
- export interface Feedback {
12
- /** `<case>@<phase>-<attempt>`, `<case>#<round>@...` after a retry; unique across the tuning */
13
- id: string;
14
- case: string;
15
- caseRev: number;
16
- /** absent in the first round */
17
- round?: number;
18
- phase: Phase;
19
- attempt: number;
20
- verdict: Verdict;
21
- rubric: Record<string, Grade>;
22
- /** right, and nothing left worth changing */
23
- done: boolean;
24
- summary: string;
25
- improvements: Improvement[];
26
- /** what outside the project made the run void: the sandbox, the network, a provider */
27
- infra?: string;
28
- /** a recheck's: the apply whose version the case failed on, after passing before it */
29
- recheck?: string;
30
- /** the try's folder, when it is not the case's own attempt folder */
31
- dir?: string;
32
- }
33
- /** A summary's first paragraph - the verdict, for a table cell or a one-line note. */
34
- export declare const lead: (summary: string) => string;
35
- /** A `specification` improvement is for the dataset, never for an apply: prose cannot fix a rubric. */
36
- export declare const forDataset: (i: Improvement) => boolean;
37
- /** The improvements an apply can act on. */
38
- export declare const forProse: (f: {
39
- improvements: Improvement[];
40
- }) => Improvement[];
41
- export declare const feedbackId: (caseId: string, phase: Phase, attempt: number, round?: number) => string;
42
- /**
43
- * The feedback, or what is wrong with the file - said so a model can fix it.
44
- * `rubric` is the case's rubric ids: given, every one must be graded.
45
- */
46
- export declare function readFeedback(file: string, known: {
47
- case: string;
48
- caseRev: number;
49
- round?: number;
50
- phase: Phase;
51
- attempt: number;
52
- }, rubricIds?: readonly string[]): {
53
- feedback: Feedback;
54
- } | {
55
- problem: string;
56
- };
57
- //# sourceMappingURL=feedback.d.ts.map
@@ -1,104 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import { VERDICTS } from "./dataset/types.js";
3
- /** A summary's first paragraph - the verdict, for a table cell or a one-line note. */
4
- export const lead = (summary) => summary.trim().split(/\n\s*\n/)[0] ?? '';
5
- /** A `specification` improvement is for the dataset, never for an apply: prose cannot fix a rubric. */
6
- export const forDataset = (i) => i.kind === 'specification';
7
- /** The improvements an apply can act on. */
8
- export const forProse = (f) => f.improvements.filter((i) => !forDataset(i));
9
- // Round 1 keeps the bare form, so the ids applies already took still match.
10
- export const feedbackId = (caseId, phase, attempt, round = 1) => `${caseId}${round > 1 ? `#${round}` : ''}@${phase}-${attempt}`;
11
- const isObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
12
- /**
13
- * The feedback, or what is wrong with the file - said so a model can fix it.
14
- * `rubric` is the case's rubric ids: given, every one must be graded.
15
- */
16
- export function readFeedback(file, known, rubricIds = []) {
17
- let raw;
18
- try {
19
- raw = JSON.parse(readFileSync(file, 'utf8'));
20
- }
21
- catch (err) {
22
- return {
23
- problem: err.code === 'ENOENT' ? 'missing' : 'not JSON',
24
- };
25
- }
26
- if (!isObject(raw)) {
27
- return { problem: 'not a JSON object' };
28
- }
29
- if (!VERDICTS.includes(raw.verdict)) {
30
- return { problem: `"verdict" must be one of ${VERDICTS.join(', ')}` };
31
- }
32
- if (typeof raw.done !== 'boolean') {
33
- return { problem: '"done" must be true or false' };
34
- }
35
- if (!Array.isArray(raw.improvements)) {
36
- return { problem: '"improvements" must be a list (empty when there is nothing to change)' };
37
- }
38
- const improvements = [];
39
- for (const [i, item] of raw.improvements.entries()) {
40
- if (!isObject(item) || typeof item.change !== 'string' || !item.change.trim()) {
41
- return { problem: `improvements[${i}] needs a "change"` };
42
- }
43
- const text = (key) => typeof item[key] === 'string' ? item[key] : undefined;
44
- improvements.push({
45
- id: text('id') ?? `i${i + 1}`,
46
- change: item.change,
47
- ...(text('kind') ? { kind: text('kind') } : {}),
48
- ...(text('file') ? { file: text('file') } : {}),
49
- ...(text('why') ? { why: text('why') } : {}),
50
- ...(text('expect') ? { expect: text('expect') } : {}),
51
- });
52
- }
53
- const rubric = {};
54
- if (isObject(raw.rubric)) {
55
- for (const [id, result] of Object.entries(raw.rubric)) {
56
- if (result === 'pass' || result === 'fail' || result === 'invalid') {
57
- rubric[id] = result;
58
- }
59
- }
60
- }
61
- const verdict = raw.verdict;
62
- const infra = typeof raw.infra === 'string' ? raw.infra.trim() : '';
63
- if (verdict === 'void' && !infra) {
64
- return {
65
- problem: 'void without "infra" - say what outside the project failed (the sandbox, the ' +
66
- 'network, a provider, a service the case needs), with node ids',
67
- };
68
- }
69
- const ungraded = rubricIds.filter((id) => !(id in rubric));
70
- if (verdict !== 'void' && ungraded.length > 0) {
71
- return {
72
- problem: `missing grades for rubric lines ${ungraded.join(', ')} - grade every line of ` +
73
- `\`zen meta dataset show ${known.case}@${known.caseRev}\` "pass", "fail" or "invalid" under "rubric"`,
74
- };
75
- }
76
- const unexplained = Object.entries(rubric)
77
- .filter(([, g]) => g === 'invalid')
78
- .map(([id]) => id)
79
- .filter((id) => !improvements.some((i) => forDataset(i) && `${i.change} ${i.why ?? ''}`.split(/[^\w-]+/).includes(id)));
80
- if (unexplained.length > 0) {
81
- return {
82
- problem: `rubric lines ${unexplained.join(', ')} are graded "invalid" with no ` +
83
- '"specification" improvement naming them - add one per line saying what is wrong ' +
84
- 'with it and how it should read',
85
- };
86
- }
87
- const failed = Object.values(rubric).includes('fail');
88
- // A right run whose only findings are about the dataset has nothing left for the prose.
89
- const onlyDataset = improvements.length > 0 && forProse({ improvements }).length === 0;
90
- return {
91
- feedback: {
92
- id: feedbackId(known.case, known.phase, known.attempt, known.round),
93
- ...known,
94
- verdict,
95
- rubric,
96
- // `done` on a wrong answer or a failed rubric line is a contradiction; those win.
97
- done: (raw.done || onlyDataset) && verdict === 'right' && !failed,
98
- summary: typeof raw.summary === 'string' ? raw.summary : '',
99
- improvements,
100
- ...(verdict === 'void' ? { infra } : {}),
101
- },
102
- };
103
- }
104
- //# sourceMappingURL=feedback.js.map
@@ -1,98 +0,0 @@
1
- import { type Cost } from './cost.ts';
2
- import { type Feedback, type Improvement } from './feedback.ts';
3
- import { type Seat, type Tuning } from './tuning.ts';
4
- export interface AppliedFile {
5
- ids: string[];
6
- from: number;
7
- to: number;
8
- at: string;
9
- startedAt?: string;
10
- skipped?: boolean;
11
- /** why the edit was undone: it failed `zen check`, or went over a limit */
12
- discarded?: string;
13
- /** a consolidation, from before an apply tidied up after itself */
14
- kind?: 'consolidate';
15
- /** what the agents always read, before and after */
16
- bytes?: {
17
- before: number;
18
- after: number;
19
- };
20
- }
21
- export interface Decision {
22
- decision?: string;
23
- note?: string;
24
- disposition?: string;
25
- /** the skill the improvement created or changed */
26
- skill?: string;
27
- }
28
- export type Decisions = Record<string, Record<string, Decision>>;
29
- export interface Deferred {
30
- request: string;
31
- case: string;
32
- apply: string;
33
- improvement: Improvement;
34
- note?: string;
35
- }
36
- /** `<request> <improvement>` for each improvement of inputs.json that decisions.json gives no valid decision. */
37
- export declare function undecided(dir: string): string[];
38
- export declare class Improvements {
39
- #private;
40
- readonly pending: Feedback[];
41
- /** the batch an apply is working on */
42
- inApply: Feedback[];
43
- /** cases parked right now */
44
- parked: number;
45
- /** `zen run`s in flight */
46
- runs: number;
47
- applying: boolean;
48
- /** the apply under way; `name` once it has a folder, before that it waits for runs */
49
- current: {
50
- since: number;
51
- name?: string;
52
- dir?: string;
53
- requests?: number;
54
- /** which gate the edit is at; absent while it waits for runs */
55
- step?: 'edit' | 'check';
56
- } | undefined;
57
- /** applies started in this process */
58
- started: number;
59
- /** applies finished in this process - an analysis spanning one may see edits */
60
- count: number;
61
- constructor(t: Tuning);
62
- /** Re-reads which requests the applies took - a recovery may have removed one. */
63
- reload(): void;
64
- get dir(): string;
65
- isApplied(id: string): boolean;
66
- /**
67
- * Every apply's decisions, later ones over earlier, per improvement. An edit
68
- * that was undone kept nothing, so what it applied or merged reads `discarded`.
69
- */
70
- decisions(): Decisions;
71
- /** Improvements held back for want of a second case, and not taken up since. */
72
- deferred(): Deferred[];
73
- /** The skills an apply made or changed for this request: the case's next run should load them. */
74
- skillsFor(id: string): string[];
75
- /**
76
- * Parks until an apply has taken this feedback, the worker free meanwhile. Taken already - after a restart - returns at once.
77
- * `structural` when the apply found nothing prose can fix.
78
- */
79
- apply(feedback: Feedback, s: Seat): Promise<{
80
- structural?: string;
81
- }>;
82
- /** A recheck's request: queued like a parked case's, with no case waiting on it. */
83
- regressed(feedback: Feedback): void;
84
- /** Before a run starts: wait out an apply, or stop. */
85
- notApplying(): Promise<void>;
86
- /** The applier: runs until the tuning is finished. */
87
- loop(): Promise<void>;
88
- /** What the agents read when the tuning began - its first version, even for a tuning begun before this was kept. */
89
- baseline(): Promise<Cost>;
90
- /** Requests every apply so far took, for the report. */
91
- applies(): {
92
- name: string;
93
- dir: string;
94
- applied?: AppliedFile;
95
- inputs?: Feedback[];
96
- }[];
97
- }
98
- //# sourceMappingURL=improvements.d.ts.map