@zenera/meta 0.0.0-stage → 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 (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +156 -2
  3. package/dist/command.d.ts +5 -0
  4. package/dist/command.js +1086 -0
  5. package/dist/dataset/anchors.d.ts +41 -0
  6. package/dist/dataset/anchors.js +239 -0
  7. package/dist/dataset/changes.d.ts +36 -0
  8. package/dist/dataset/changes.js +319 -0
  9. package/dist/dataset/command.d.ts +17 -0
  10. package/dist/dataset/command.js +1011 -0
  11. package/dist/dataset/drift.d.ts +33 -0
  12. package/dist/dataset/drift.js +71 -0
  13. package/dist/dataset/export.d.ts +26 -0
  14. package/dist/dataset/export.js +51 -0
  15. package/dist/dataset/index.d.ts +2 -0
  16. package/dist/dataset/index.js +2 -0
  17. package/dist/dataset/sample.d.ts +50 -0
  18. package/dist/dataset/sample.js +197 -0
  19. package/dist/dataset/schema.d.ts +33 -0
  20. package/dist/dataset/schema.js +216 -0
  21. package/dist/dataset/store.d.ts +35 -0
  22. package/dist/dataset/store.js +177 -0
  23. package/dist/dataset/types.d.ts +127 -0
  24. package/dist/dataset/types.js +39 -0
  25. package/dist/finetune/analyze-brief.d.ts +26 -0
  26. package/dist/finetune/analyze-brief.js +131 -0
  27. package/dist/finetune/apply-brief.d.ts +23 -0
  28. package/dist/finetune/apply-brief.js +247 -0
  29. package/dist/finetune/brief.d.ts +45 -0
  30. package/dist/finetune/brief.js +158 -0
  31. package/dist/finetune/children.d.ts +8 -0
  32. package/dist/finetune/children.js +76 -0
  33. package/dist/finetune/command.d.ts +30 -0
  34. package/dist/finetune/command.js +520 -0
  35. package/dist/finetune/cost.d.ts +46 -0
  36. package/dist/finetune/cost.js +105 -0
  37. package/dist/finetune/failure.d.ts +15 -0
  38. package/dist/finetune/failure.js +26 -0
  39. package/dist/finetune/feedback.d.ts +57 -0
  40. package/dist/finetune/feedback.js +104 -0
  41. package/dist/finetune/improvements.d.ts +98 -0
  42. package/dist/finetune/improvements.js +501 -0
  43. package/dist/finetune/index.d.ts +2 -0
  44. package/dist/finetune/index.js +2 -0
  45. package/dist/finetune/journal.d.ts +35 -0
  46. package/dist/finetune/journal.js +135 -0
  47. package/dist/finetune/live.d.ts +84 -0
  48. package/dist/finetune/live.js +272 -0
  49. package/dist/finetune/loop.d.ts +3 -0
  50. package/dist/finetune/loop.js +163 -0
  51. package/dist/finetune/memories.d.ts +47 -0
  52. package/dist/finetune/memories.js +171 -0
  53. package/dist/finetune/next-case.d.ts +18 -0
  54. package/dist/finetune/next-case.js +47 -0
  55. package/dist/finetune/recheck.d.ts +58 -0
  56. package/dist/finetune/recheck.js +311 -0
  57. package/dist/finetune/report.d.ts +40 -0
  58. package/dist/finetune/report.js +1397 -0
  59. package/dist/finetune/retry.d.ts +24 -0
  60. package/dist/finetune/retry.js +96 -0
  61. package/dist/finetune/system.d.ts +27 -0
  62. package/dist/finetune/system.js +132 -0
  63. package/dist/finetune/train.d.ts +43 -0
  64. package/dist/finetune/train.js +425 -0
  65. package/dist/finetune/tui.d.ts +16 -0
  66. package/dist/finetune/tui.js +316 -0
  67. package/dist/finetune/tuning.d.ts +193 -0
  68. package/dist/finetune/tuning.js +308 -0
  69. package/dist/finetune/usage.d.ts +66 -0
  70. package/dist/finetune/usage.js +260 -0
  71. package/dist/finetune/view.d.ts +9 -0
  72. package/dist/finetune/view.js +27 -0
  73. package/dist/host.d.ts +2 -0
  74. package/dist/host.js +14 -0
  75. package/dist/index.d.ts +10 -0
  76. package/dist/index.js +15 -0
  77. package/dist/launch.d.ts +90 -0
  78. package/dist/launch.js +310 -0
  79. package/dist/model.d.ts +61 -0
  80. package/dist/model.js +146 -0
  81. package/dist/prompts.d.ts +23 -0
  82. package/dist/prompts.js +84 -0
  83. package/dist/relay.d.ts +20 -0
  84. package/dist/relay.js +123 -0
  85. package/dist/sink.d.ts +61 -0
  86. package/dist/sink.js +198 -0
  87. package/dist/tokens.d.ts +52 -0
  88. package/dist/tokens.js +226 -0
  89. package/dist/wire.d.ts +51 -0
  90. package/dist/wire.js +159 -0
  91. package/package.json +54 -5
@@ -0,0 +1,35 @@
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
@@ -0,0 +1,177 @@
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
@@ -0,0 +1,127 @@
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
@@ -0,0 +1,39 @@
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
@@ -0,0 +1,26 @@
1
+ import { type Brief, type Step } from './brief.ts';
2
+ import type { Case } from '../dataset/types.ts';
3
+ import { type Phase } from './feedback.ts';
4
+ import { type Attempt } from './report.ts';
5
+ import type { Run } from './train.ts';
6
+ import type { Tuning } from './tuning.ts';
7
+ export interface AnalyzeBrief extends Brief {
8
+ run: Run;
9
+ case: Case;
10
+ phase: Phase;
11
+ attempt: number;
12
+ /** earlier tries of this case revision, oldest first */
13
+ earlier: Attempt[];
14
+ /** the patch a recheck checks */
15
+ recheck?: string;
16
+ /** skills an apply made for this case that the run never loaded */
17
+ missed?: string[];
18
+ /** the try's folder: brief.md, feedback.json and ask/ live here */
19
+ dir: string;
20
+ }
21
+ export declare const ANALYZE_BRIEF: Step<AnalyzeBrief>[];
22
+ /** The analysis brief as markdown. */
23
+ export declare function renderAnalyzeBrief(b: AnalyzeBrief, log: string, steps?: Step<AnalyzeBrief>[]): Promise<string>;
24
+ /** Writes `brief.md` into the try's folder; the path is what `--prompt-file` takes. */
25
+ export declare function writeAnalyzeBrief(t: Tuning, dir: string, at: Omit<AnalyzeBrief, 't' | 'systemDir' | 'project' | 'dir'>): Promise<string>;
26
+ //# sourceMappingURL=analyze-brief.d.ts.map
@@ -0,0 +1,131 @@
1
+ import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { SHARED_RULES, validateProject } from "../host.js";
4
+ import { cut, files, oneLine, PHASE_WORD, renderBrief, skillIndex, STEP_MAX, word, } from "./brief.js";
5
+ import { feedbackId } from "./feedback.js";
6
+ import { fence, rubricScore, since } from "./report.js";
7
+ export const ANALYZE_BRIEF = [
8
+ { zen: (b) => ['meta', 'dataset', 'show', `${b.case.id}@${b.case.rev}`, '--json'] },
9
+ { sh: () => "grep -nE 'memory:|handoffs:|fork:' agents.yaml" },
10
+ { zen: (b) => ['inspect', 'graph', '--dir', b.run.dir, '--no-style'] },
11
+ { cat: (b) => [join(b.run.dir, 'meta.json'), join(b.run.dir, 'input.md')] },
12
+ { cat: (b) => [join(b.run.dir, 'output.md')], max: 8000 },
13
+ { title: 'Earlier tries of this case', fn: earlierTries },
14
+ // It cuts the diff itself, inside its fence.
15
+ {
16
+ title: 'What changed in agents.yaml and agents/ since the last try',
17
+ fn: systemDiff,
18
+ max: Infinity,
19
+ },
20
+ { cat: (b) => (b.recheck ? [b.recheck] : undefined) },
21
+ { title: 'Skills an apply made for this case, never loaded by this run', fn: missedSkills },
22
+ { cat: () => ['agents.yaml'] },
23
+ {
24
+ cat: (b) => files(b, 'agents/*instructions.md').filter((f) => !SHARED_RULES.includes(f)),
25
+ },
26
+ { title: 'Skills: which agent can load which, and the index', fn: skillIndex },
27
+ // Last: the largest, and the agent can read a left-out prompt itself.
28
+ { cat: (b) => files(b, 'agents/prompts/*.md'), max: 40_000 },
29
+ ];
30
+ /** The analysis brief as markdown. */
31
+ export async function renderAnalyzeBrief(b, log, steps = ANALYZE_BRIEF) {
32
+ return renderBrief(b, log, steps, [
33
+ `The run is \`${b.run.dir}\`, on system v${b.run.system}: the project files below are as that version had them.\n`,
34
+ [
35
+ 'Where to write - both folders exist, so no `mkdir` and no `test -f`:',
36
+ '',
37
+ `- each question for \`zen inspect ask\`: \`${join(b.dir, 'ask')}/<node>-<topic>.md\``,
38
+ `- the feedback file: \`${join(b.dir, 'feedback.json')}\`, not written yet - write it in one call`,
39
+ '',
40
+ ].join('\n'),
41
+ ]);
42
+ }
43
+ /** Writes `brief.md` into the try's folder; the path is what `--prompt-file` takes. */
44
+ export async function writeAnalyzeBrief(t, dir, at) {
45
+ mkdirSync(join(dir, 'ask'), { recursive: true });
46
+ const snapshot = t.system.snapshotDir(at.run.system);
47
+ const systemDir = existsSync(snapshot) ? snapshot : t.root;
48
+ let report;
49
+ const b = {
50
+ ...at,
51
+ t,
52
+ dir,
53
+ systemDir,
54
+ project: () => (report ??= validateProject({ dir: systemDir })
55
+ .catch(() => validateProject({ dir: t.root }))
56
+ .catch(() => undefined)),
57
+ };
58
+ const file = join(dir, 'brief.md');
59
+ writeFileSync(file, await renderAnalyzeBrief(b, join(dir, 'brief.log')));
60
+ return file;
61
+ }
62
+ // ---------------------------------------------------------------------------
63
+ // The computed sections
64
+ // ---------------------------------------------------------------------------
65
+ function earlierTries(b) {
66
+ const decided = b.t.improvements.decisions();
67
+ const round = b.t.round(b.case);
68
+ return b.earlier
69
+ .filter((a) => a.feedback)
70
+ .map((a) => {
71
+ const f = a.feedback;
72
+ const id = feedbackId(b.case.id, a.phase, a.attempt, round);
73
+ const cost = a.run
74
+ ? `, v${a.run.system}, ${a.run.turns ?? '?'} LLM calls, ${since(a.run.durationMs ?? 0)}`
75
+ : '';
76
+ const rows = f.improvements.map((i) => {
77
+ const d = decided[id]?.[i.id];
78
+ const decision = d?.decision
79
+ ? `${d.decision}${d.note ? `: ${d.note}` : ''}`
80
+ : 'not applied yet';
81
+ return `| ${i.id} | ${oneLine(i.change)} | ${oneLine(i.file ?? '-')} | ${oneLine(decision)} |`;
82
+ });
83
+ return [
84
+ `#### ${PHASE_WORD[a.phase]}, try ${a.attempt} - ${f.verdict}, rubric ${rubricScore(f)}${f.done ? ', done' : ''}${cost}`,
85
+ '',
86
+ ...f.summary
87
+ .trim()
88
+ .split('\n')
89
+ .map((l) => (l.trim() ? `> ${l}` : '>')),
90
+ '',
91
+ ...(rows.length > 0
92
+ ? ['| # | Change | File | Decision |', '| --- | --- | --- | --- |', ...rows, '']
93
+ : []),
94
+ ].join('\n');
95
+ })
96
+ .join('\n');
97
+ }
98
+ function systemDiff(b) {
99
+ const last = [...b.earlier].reverse().find((a) => a.run);
100
+ if (!last?.run || last.run.system === b.run.system) {
101
+ return undefined;
102
+ }
103
+ const diff = b.t.system.diff(last.run.system, b.run.system).trim();
104
+ if (!diff) {
105
+ return undefined;
106
+ }
107
+ const pad = (v) => `v${String(v).padStart(2, '0')}`;
108
+ const { body, note } = cut(diff, STEP_MAX, `the whole diff: git -C ${word(b.t.system.dir)} diff --no-index ${pad(last.run.system)} ${pad(b.run.system)}`);
109
+ const tick = fence(body);
110
+ return [
111
+ `From v${last.run.system} (${PHASE_WORD[last.phase]}, try ${last.attempt}) to v${b.run.system} (this run):`,
112
+ '',
113
+ `${tick}diff`,
114
+ body,
115
+ tick,
116
+ ...(note ? [note] : []),
117
+ ].join('\n');
118
+ }
119
+ async function missedSkills(b) {
120
+ if (!b.missed?.length) {
121
+ return undefined;
122
+ }
123
+ const entries = (await b.project())?.skills.entries ?? [];
124
+ return b.missed
125
+ .map((name) => {
126
+ const s = entries.find((e) => e.name === name);
127
+ return `- \`${name}\`: ${s ? s.description : '(no such skill in this version)'}`;
128
+ })
129
+ .join('\n');
130
+ }
131
+ //# sourceMappingURL=analyze-brief.js.map
@@ -0,0 +1,23 @@
1
+ import { type Brief, type Step } from './brief.ts';
2
+ import { type Feedback } from './feedback.ts';
3
+ import type { Deferred } from './improvements.ts';
4
+ import { type Tuning } from './tuning.ts';
5
+ /** One entry of inputs.json. */
6
+ export type Request = Feedback & {
7
+ file: string;
8
+ missedSkills?: string[];
9
+ };
10
+ export interface ApplyBrief extends Brief {
11
+ dir: string;
12
+ attempt: number;
13
+ inputs: Request[];
14
+ deferred: Deferred[];
15
+ }
16
+ /** The editor skills this project's capabilities call for, each with why. */
17
+ export declare function editorSkills(root: string, inputs: {
18
+ phase: string;
19
+ }[]): [string, string][];
20
+ export declare const APPLY_BRIEF: Step<ApplyBrief>[];
21
+ /** Writes `brief.md` into the apply's folder, for this attempt; returns its path. */
22
+ export declare function writeApplyBrief(t: Tuning, dir: string, attempt: number): Promise<string>;
23
+ //# sourceMappingURL=apply-brief.d.ts.map