@method-ai-hq/sdk 0.19.0 → 0.20.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 (31) hide show
  1. package/README.md +1 -1
  2. package/dist/packages/sdk/package.json +2 -2
  3. package/dist/packages/sdk/src/authoring-instructions.d.ts +1 -1
  4. package/dist/packages/sdk/src/authoring-instructions.js +1 -1
  5. package/dist/packages/sdk/src/current-inspection.js +3 -0
  6. package/dist/packages/sdk/src/fix-lines.d.ts +82 -0
  7. package/dist/packages/sdk/src/fix-lines.js +63 -0
  8. package/dist/packages/sdk/src/fix-outcomes.d.ts +72 -0
  9. package/dist/packages/sdk/src/fix-outcomes.js +201 -0
  10. package/dist/packages/sdk/src/improve.d.ts +132 -34
  11. package/dist/packages/sdk/src/improve.js +523 -176
  12. package/dist/packages/sdk/src/judge.d.ts +12 -11
  13. package/dist/packages/sdk/src/judge.js +63 -39
  14. package/dist/packages/sdk/src/learned.d.ts +43 -0
  15. package/dist/packages/sdk/src/learned.js +97 -0
  16. package/dist/packages/sdk/src/local-cli.js +8 -1
  17. package/dist/packages/sdk/src/local-judgments.d.ts +2 -0
  18. package/dist/packages/sdk/src/method-files.d.ts +3 -2
  19. package/dist/packages/sdk/src/method-files.js +7 -3
  20. package/dist/packages/sdk/src/method-help.d.ts +1 -1
  21. package/dist/packages/sdk/src/method-help.js +16 -12
  22. package/dist/packages/sdk/src/method.js +51 -9
  23. package/dist/packages/sdk/src/quality.d.ts +62 -11
  24. package/dist/packages/sdk/src/quality.js +56 -21
  25. package/dist/packages/sdk/src/undo.d.ts +50 -0
  26. package/dist/packages/sdk/src/undo.js +108 -0
  27. package/dist/packages/sdk/src/watch.d.ts +20 -0
  28. package/dist/packages/sdk/src/watch.js +86 -0
  29. package/dist/packages/workflow-language/src/inspection.d.ts +30 -0
  30. package/dist/packages/workflow-language/src/inspection.js +3 -1
  31. package/package.json +2 -2
@@ -1,4 +1,5 @@
1
1
  import type { MethodClient } from './method-client.js';
2
+ import type { CorrectionOutcome } from './fix-lines.js';
2
3
  /** A judgment as improve.method reads it. new marks the corrections to fix now; run is the account record of a run with no folder here. */
3
4
  export type ImproveJudgment = {
4
5
  id: string;
@@ -13,13 +14,12 @@ export type ImproveJudgment = {
13
14
  created_at: string;
14
15
  new?: boolean;
15
16
  run?: unknown;
17
+ noted_by?: string | null;
18
+ /** The question that an earlier fix asked about this correction, and the person's answer. */
19
+ question?: string;
20
+ answer?: string;
16
21
  };
17
- /** What the loop did with one correction, as the account records it. */
18
- export type CorrectionOutcome = {
19
- id: string;
20
- outcome: 'fixed' | 'no_change' | 'already_changed' | 'held';
21
- detail?: string;
22
- };
22
+ export type { CorrectionOutcome };
23
23
  /** Runs a local Method file; the default is the runtime that `method run FILE` uses. */
24
24
  export type RunFile = (file: string, flags: Record<string, unknown>, syncFactory: undefined, onEvent: undefined, client: MethodClient, baseConfig: undefined, secrets: Record<string, string>) => Promise<{
25
25
  status: string;
@@ -41,13 +41,17 @@ export type ImproveProposal = {
41
41
  [key: string]: unknown;
42
42
  };
43
43
  };
44
+ export type ImproveResult = ImproveProposal & {
45
+ capped: string;
46
+ outcomes: CorrectionOutcome[];
47
+ background_cases: string[];
48
+ summary: string;
49
+ };
44
50
  export type FixOutcome = {
45
51
  file: string;
46
52
  judgments: string[];
47
- corrections: number;
48
- from_dashboard: number;
49
53
  kind: 'change' | 'none';
50
- line: string;
54
+ applied: boolean;
51
55
  cause: string;
52
56
  steps: string[];
53
57
  cases: {
@@ -57,11 +61,9 @@ export type FixOutcome = {
57
61
  reason: string;
58
62
  }[];
59
63
  };
60
- earlier_passed: number;
61
64
  version?: {
62
65
  version_id: string;
63
66
  url: string;
64
- undo: string;
65
67
  } | undefined;
66
68
  usage: {
67
69
  model_calls: number;
@@ -70,16 +72,31 @@ export type FixOutcome = {
70
72
  } | null;
71
73
  capped: string;
72
74
  log: string;
73
- changed?: string;
74
- outcomes?: CorrectionOutcome[];
75
+ outcomes: CorrectionOutcome[];
76
+ /** The cases that run after an applied change, and the undo record of that change. */
77
+ background_cases: string[];
78
+ undo_id?: string | undefined;
79
+ /** The corrections that the applied change answered, with their notes. */
80
+ fixed: {
81
+ id: string;
82
+ note: string | null;
83
+ }[];
75
84
  };
76
85
  /**
77
- * Read the result of improve.method: {proposal: <SubmitProposal as JSON text>, kind, proposal_id, capped}. A change has
78
- * the tested workflow (and a changed package file for a script change); none has no workflow.
86
+ * One outcome of improve.method in the form the lines read: {id, outcome, detail, reason?, question?, held_with?,
87
+ * learned_rule?, again?, tests?: {case, base, candidate: {passes, runs}, guards: []}, tried?}. A fixed outcome's detail
88
+ * says what is different now; a held outcome's detail is about the loop, so the line names only the other person.
79
89
  */
80
- export declare function readImproveResult(result: unknown): ImproveProposal & {
81
- capped: string;
82
- };
90
+ export declare function loopOutcome(o: any): CorrectionOutcome;
91
+ /**
92
+ * Read the result of improve.method: {proposal: <SubmitProposal as JSON text>, kind, proposal_id, outcomes: <JSON text,
93
+ * one outcome per new correction>, background_cases: [case ids], summary: one plain line}. A change has the tested
94
+ * workflow and the changed package files (a script, learned.json). A pruning sweep (mode prune) has no outcomes; its
95
+ * summary says what it removed, and what it left because nothing checks it.
96
+ */
97
+ export declare function readImproveResult(result: unknown, options?: {
98
+ prune?: boolean;
99
+ }): ImproveResult;
83
100
  /**
84
101
  * Download the published improve.method and its files into the Method cache, once per version. For developers of
85
102
  * improve.method: METHOD_IMPROVE_METHOD=PATH runs that local improve.method file instead, from its own folder.
@@ -90,13 +107,12 @@ export declare function cachedImproveMethod(client: MethodClient): Promise<{
90
107
  version_id: string;
91
108
  }>;
92
109
  /**
93
- * Run improve.method on this computer. Its model steps and its scripts' model requests follow the rule of every run:
110
+ * Run improve.method on this computer (mode prune: the pruning pass). Its model steps and its scripts' model requests follow the rule of every run:
94
111
  * the user's own Claude Code or Codex first, hosted models only without one. The run gets the signed-in key and server
95
112
  * as its IMPROVE_API_KEY and IMPROVE_SERVER secrets, for this run only. Its output goes to a log file.
96
113
  */
97
- export declare function runImprovement(client: MethodClient, file: string, judgments: ImproveJudgment[], runFolders: string[], run?: RunFile): Promise<{
114
+ export declare function runImprovement(client: MethodClient, file: string, judgments: ImproveJudgment[], runFolders: string[], run?: RunFile, mode?: 'prune'): Promise<{
98
115
  log: string;
99
- summary: any;
100
116
  cause: string;
101
117
  workflow: unknown | null;
102
118
  files: {
@@ -110,48 +126,130 @@ export declare function runImprovement(client: MethodClient, file: string, judgm
110
126
  [key: string]: unknown;
111
127
  };
112
128
  capped: string;
129
+ outcomes: CorrectionOutcome[];
130
+ background_cases: string[];
131
+ summary: string;
113
132
  }>;
114
133
  /** The ID of the regression case that a correction makes: one per judgment, so a later loop finds it. */
115
134
  export declare const correctionCaseId: (judgmentId: string) => string;
135
+ /** One thing that the person saw: the result, a step output, a file the run wrote, or a call or effect it made. */
136
+ type Seen = {
137
+ ref: string;
138
+ label: string;
139
+ value: unknown;
140
+ };
141
+ /** What the person saw of a run, with the ref that a case uses for each thing (runtime 0.16.0 refs). */
142
+ export declare function seenOfRun(outcome: any): Seen[];
116
143
  /**
117
- * Make the regression case of a correction, even from vague words such as "it's not even redlined": a model writes 1 to
118
- * 3 plain sentences from the note and the run's result, and method case new keeps them only when they fail on the run.
119
- * A rule that fails nothing gets one more try with the reason. The person's words decide a conflict with an instruction.
144
+ * Make the regression case of a correction, even from vague words such as "it's not even redlined". A model reads what
145
+ * the person saw (the result, the files the run wrote, and the calls and effects it made) and writes 1 to 3 plain
146
+ * sentences, each about one of those things; for a note about form or a missing action, also a small check script. A
147
+ * sentence is kept only when it fails on the corrected run and passes on every approved run of the same part, with two
148
+ * judges when both Claude Code and Codex are signed in. Sentences that do not fail get one more try with the reason.
120
149
  */
121
150
  export declare function caseFromCorrection(file: string, judgment: {
122
151
  id: string;
123
152
  note: string | null;
124
153
  corrected?: unknown;
125
154
  noted_by?: string | null;
126
- }, runDir: string): Promise<{
155
+ answer?: string | null;
156
+ }, runDir: string, options?: {
157
+ approvedRuns?: string[];
158
+ }): Promise<{
127
159
  id: string;
128
160
  made: boolean;
129
161
  }>;
162
+ /** The corrections of a Method that wait for a fix. */
163
+ export declare function waitingCorrections(client: MethodClient, file: string, methodId: string, waitMs?: number): Promise<{
164
+ note: string | null;
165
+ corrected: {} | null;
166
+ answer: string | null;
167
+ run_dir: string | undefined;
168
+ id: string;
169
+ run_id: string;
170
+ step_id: string | null;
171
+ verdict: "right" | "wrong";
172
+ source: string;
173
+ created_at: string;
174
+ pending: boolean;
175
+ noted_by?: string | null;
176
+ outcome?: string | null;
177
+ handled_by?: string | null;
178
+ held_with?: string | null;
179
+ question?: string | null;
180
+ }[]>;
130
181
  /**
131
- * Fix the pending corrections of a Method file on this computer: the loop. Returns undefined when nothing waits. It
132
- * takes the pending corrections in the account first, so two computers never fix one correction twice, and gives them
133
- * back when the loop stops before it decides. A subscription limit or another failure of the model service is a plain
134
- * error.
182
+ * Fix the pending corrections of a Method file on this computer: one pass of the loop. Returns undefined when nothing
183
+ * waits. It takes the pending corrections in the account first, so two computers never fix one correction twice, and
184
+ * gives them back when the loop stops before it decides. Each correction gets its own outcome. A subscription limit or
185
+ * another failure of the model service is a plain error.
135
186
  */
136
187
  export declare function fixCorrections(client: MethodClient, file: string, options?: {
137
188
  run?: RunFile;
138
189
  waitMs?: number;
190
+ skip?: Set<string>;
139
191
  }): Promise<FixOutcome | undefined>;
192
+ /** Whether a fix of the Method runs on this computer now. */
193
+ export declare function fixRunning(methodId: string): boolean;
140
194
  /**
141
195
  * Fix the waiting corrections of a Method file while holding its lock, pass after pass until none waits, so the
142
- * corrections that arrive during a pass join the next. Returns undefined when another fix of the Method holds the lock.
196
+ * corrections that arrive during a pass join the next. Each correction's outcome is saved for method wait. After a pass
197
+ * that changed the file, the other cases run (improve.method's background_cases): a failure undoes that change. Then a
198
+ * pruning pass runs when it is due. Returns undefined when another fix of the Method holds the lock.
143
199
  */
144
200
  export declare function fixWaiting(client: MethodClient, file: string, options?: {
145
201
  run?: RunFile;
146
202
  waitMs?: number;
203
+ runCases?: RunCases;
147
204
  }): Promise<FixOutcome[] | undefined>;
205
+ /** Runs cases of a Method file (quality.ts runCases); tests replace it. */
206
+ export type RunCases = (file: string, flags: Record<string, never>, options: {
207
+ ids: string[];
208
+ casesDir?: string;
209
+ }) => Promise<{
210
+ cases: {
211
+ id: string;
212
+ verdict: string;
213
+ }[];
214
+ }>;
215
+ /**
216
+ * The later check of an applied change: the Method's other cases (improve.method's background_cases) run on the changed
217
+ * file. A failing case that belongs to a retired learned rule (its from.case) brings that rule back. Any other case that
218
+ * fails now and passed before the change (a correction that no fix answered yet fails on both) undoes the change, saves the restored file as a new version, and opens the corrections it answered again, so the next
219
+ * method run fixes them anew. Each of these says one line on the next method run or method wait.
220
+ */
221
+ export declare function checkBackground(client: MethodClient, file: string, fix: Pick<FixOutcome, 'background_cases' | 'undo_id' | 'fixed' | 'cause'>, options?: {
222
+ runCases?: RunCases;
223
+ }): Promise<{
224
+ failed: string[];
225
+ restored: string[];
226
+ undone: boolean;
227
+ reopened: string[];
228
+ }>;
229
+ /**
230
+ * The pruning pass (improve.method with mode prune): it retires learned rules and deletes prompt text that tests show
231
+ * no longer change any result, and reports text that no test covers without deleting it. The change applies at once,
232
+ * with undo; the next method run or method wait shows the sweep's summary line.
233
+ */
234
+ export declare function pruneMethod(client: MethodClient, file: string, options?: {
235
+ run?: RunFile;
236
+ }): Promise<{
237
+ changed: boolean;
238
+ } | undefined>;
148
239
  /**
149
240
  * Fix the Method for one correction: run the fix, or, when a fix of the Method already runs on this computer, wait for
150
- * the fix that takes this correction. Returns the outcome of the fix that took it, or undefined when no fix here took it.
241
+ * the fix that takes this correction. Returns the stored outcome, or undefined when no fix here took it.
151
242
  */
152
243
  export declare function fixCorrection(client: MethodClient, file: string, judgmentId: string, options?: {
153
244
  run?: RunFile;
154
245
  pollMs?: number;
155
- }): Promise<FixOutcome | undefined>;
156
- /** The one line for corrections that waited, printed before method run or method judge goes on. */
157
- export declare function waitingLine(outcome: FixOutcome): string;
246
+ }): Promise<import("./fix-outcomes.js").StoredOutcome | undefined>;
247
+ /**
248
+ * `method __fix FILE --judgment ID... [--prune]`: the fix of method judge, method answer and method run, in its own
249
+ * process. Every correction it was started for ends with a stored outcome or error.
250
+ */
251
+ export declare function backgroundFix(client: MethodClient, file: string, ids: string[], options?: {
252
+ run?: RunFile;
253
+ prune?: boolean;
254
+ pollMs?: number;
255
+ }): Promise<void>;