@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,15 @@
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
@@ -0,0 +1,26 @@
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
@@ -0,0 +1,57 @@
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
@@ -0,0 +1,104 @@
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
@@ -0,0 +1,98 @@
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