gdp-wired 0.50.2 → 0.50.4
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.
- package/README.md +8 -2
- package/dist/core/agent-consult/cli.d.ts +2 -0
- package/dist/core/agent-consult/cli.js +19 -0
- package/dist/core/agent-consult/protocol.d.ts +93 -0
- package/dist/core/agent-consult/protocol.js +154 -0
- package/dist/core/agent-consult/service.d.ts +435 -0
- package/dist/core/agent-consult/service.js +84 -0
- package/dist/core/agent-consult/session.d.ts +13 -0
- package/dist/core/agent-consult/session.js +163 -0
- package/dist/core/agent-consult/source-service.d.ts +83 -0
- package/dist/core/agent-consult/source-service.js +51 -0
- package/dist/core/agent-consult/tsconfig.json +5 -0
- package/dist/core/agent-consult/worker.d.ts +1 -0
- package/dist/core/agent-consult/worker.js +17 -0
- package/dist/core/agent-consult/workspace.d.ts +27 -0
- package/dist/core/agent-consult/workspace.js +66 -0
- package/dist/core/agent-consult.d.ts +8 -0
- package/dist/core/agent-consult.js +6 -0
- package/dist/core/cli.d.ts +17 -1
- package/dist/core/cli.js +174 -68
- package/dist/core/discover.d.ts +6 -1
- package/dist/core/discover.js +54 -7
- package/dist/core/dsl-deadline.d.ts +3 -0
- package/dist/core/dsl-deadline.js +26 -2
- package/dist/core/dsl.d.ts +3 -1
- package/dist/core/dsl.js +93 -30
- package/dist/core/effect.d.ts +12 -0
- package/dist/core/effect.js +26 -9
- package/dist/core/ex/harness.exs +171 -5
- package/dist/core/extract-c.js +63 -6
- package/dist/core/extract-check.d.ts +5 -1
- package/dist/core/extract-check.js +28 -10
- package/dist/core/extract-go-check.js +127 -1
- package/dist/core/extract-go.js +8 -2
- package/dist/core/extract-jvm.js +2 -2
- package/dist/core/extract-rs.js +51 -5
- package/dist/core/extract-step.js +40 -6
- package/dist/core/extract-swift.js +47 -3
- package/dist/core/extract.d.ts +8 -0
- package/dist/core/infer.d.ts +8 -0
- package/dist/core/infer.js +133 -16
- package/dist/core/jvm/Harness.java +135 -3
- package/dist/core/jvm/Rt.java +66 -4
- package/dist/core/laws.js +51 -10
- package/dist/core/native-law.d.ts +3 -1
- package/dist/core/native-law.js +126 -14
- package/dist/core/native-observations.d.ts +20 -0
- package/dist/core/native-observations.js +41 -0
- package/dist/core/native-wire.d.ts +1 -0
- package/dist/core/native-wire.js +16 -2
- package/dist/core/py/harness.py +21 -4
- package/dist/core/rb/harness.rb +178 -9
- package/dist/core/search-termination.d.ts +35 -0
- package/dist/core/search-termination.js +13 -0
- package/dist/core/search-watchdog.d.ts +8 -0
- package/dist/core/search-watchdog.js +34 -0
- package/dist/core/source-check.d.ts +3 -0
- package/dist/core/swift/Harness.swift +65 -4
- package/dist/core/swift/Main.swift +27 -4
- package/dist/core/wall.d.ts +3 -1
- package/dist/core/wall.js +7 -4
- package/dist/core/work-refusal.d.ts +3 -0
- package/dist/core/work-refusal.js +8 -0
- package/dist/kernel/prove.d.ts +2 -0
- package/dist/kernel/prove.js +13 -5
- package/docs/agent-consult-workspace-check.md +118 -0
- package/docs/agent-consult.md +151 -0
- package/examples/agent-consult.json +22 -0
- package/package.json +11 -3
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import { type Law } from '../../core/machine.js';
|
|
2
|
+
type Proof = {
|
|
3
|
+
proven: boolean;
|
|
4
|
+
checked: boolean;
|
|
5
|
+
status: string;
|
|
6
|
+
goal?: string;
|
|
7
|
+
why?: string;
|
|
8
|
+
witness?: unknown;
|
|
9
|
+
};
|
|
10
|
+
type RawProof = {
|
|
11
|
+
proven: boolean;
|
|
12
|
+
checked: boolean;
|
|
13
|
+
failed?: {
|
|
14
|
+
goal?: string;
|
|
15
|
+
stuck?: string;
|
|
16
|
+
witness?: unknown;
|
|
17
|
+
why?: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export declare function proofSummary(v: RawProof): Proof;
|
|
21
|
+
export declare function failure(tool: string, e: unknown): {
|
|
22
|
+
schema: string;
|
|
23
|
+
tool: string;
|
|
24
|
+
ok: boolean;
|
|
25
|
+
refusal: {
|
|
26
|
+
code: string;
|
|
27
|
+
message: string;
|
|
28
|
+
fix: string;
|
|
29
|
+
};
|
|
30
|
+
explanation: string;
|
|
31
|
+
};
|
|
32
|
+
export declare function execute(tool: unknown, args: unknown): {
|
|
33
|
+
assumptions: {
|
|
34
|
+
domain: string;
|
|
35
|
+
scope: string;
|
|
36
|
+
subjects: {
|
|
37
|
+
initial: Record<string, import("../../core/machine.ts").E>;
|
|
38
|
+
pre: import("../../core/machine.ts").C | null;
|
|
39
|
+
requestAssumption: import("../../core/machine.ts").C | null;
|
|
40
|
+
unit: string;
|
|
41
|
+
revision: string;
|
|
42
|
+
}[];
|
|
43
|
+
laws: Law[];
|
|
44
|
+
};
|
|
45
|
+
budget: {
|
|
46
|
+
limits: import("./protocol.ts").Budget;
|
|
47
|
+
apiCalls: number;
|
|
48
|
+
work: Readonly<{
|
|
49
|
+
numerator: string;
|
|
50
|
+
denominator: string;
|
|
51
|
+
}>;
|
|
52
|
+
counters: {
|
|
53
|
+
[k: string]: string;
|
|
54
|
+
};
|
|
55
|
+
profile: "raw-work-v1";
|
|
56
|
+
provisional: boolean;
|
|
57
|
+
};
|
|
58
|
+
subject: {
|
|
59
|
+
unit: string;
|
|
60
|
+
revision: string;
|
|
61
|
+
};
|
|
62
|
+
label: string;
|
|
63
|
+
result: {
|
|
64
|
+
verdicts: {
|
|
65
|
+
proven: boolean;
|
|
66
|
+
checked: boolean;
|
|
67
|
+
status: string;
|
|
68
|
+
goal?: string;
|
|
69
|
+
why?: string;
|
|
70
|
+
witness?: unknown;
|
|
71
|
+
law: string;
|
|
72
|
+
}[];
|
|
73
|
+
cases?: undefined;
|
|
74
|
+
satisfied?: undefined;
|
|
75
|
+
discovered?: undefined;
|
|
76
|
+
nearMisses?: undefined;
|
|
77
|
+
unresolvedNearMisses?: undefined;
|
|
78
|
+
inference?: undefined;
|
|
79
|
+
nearMissSource?: undefined;
|
|
80
|
+
stillHold?: undefined;
|
|
81
|
+
newlyBroken?: undefined;
|
|
82
|
+
lostProof?: undefined;
|
|
83
|
+
behaviour?: undefined;
|
|
84
|
+
};
|
|
85
|
+
statusEvidence: {
|
|
86
|
+
proven: boolean;
|
|
87
|
+
checked: boolean;
|
|
88
|
+
laws: string[];
|
|
89
|
+
unit: string;
|
|
90
|
+
revision: string;
|
|
91
|
+
}[];
|
|
92
|
+
explanation: string;
|
|
93
|
+
before?: undefined;
|
|
94
|
+
schema: string;
|
|
95
|
+
tool: import("./protocol.ts").Tool;
|
|
96
|
+
ok: boolean;
|
|
97
|
+
} | {
|
|
98
|
+
assumptions: {
|
|
99
|
+
domain: string;
|
|
100
|
+
scope: string;
|
|
101
|
+
subjects: {
|
|
102
|
+
initial: Record<string, import("../../core/machine.ts").E>;
|
|
103
|
+
pre: import("../../core/machine.ts").C | null;
|
|
104
|
+
requestAssumption: import("../../core/machine.ts").C | null;
|
|
105
|
+
unit: string;
|
|
106
|
+
revision: string;
|
|
107
|
+
}[];
|
|
108
|
+
laws: Law[];
|
|
109
|
+
};
|
|
110
|
+
budget: {
|
|
111
|
+
limits: import("./protocol.ts").Budget;
|
|
112
|
+
apiCalls: number;
|
|
113
|
+
work: Readonly<{
|
|
114
|
+
numerator: string;
|
|
115
|
+
denominator: string;
|
|
116
|
+
}>;
|
|
117
|
+
counters: {
|
|
118
|
+
[k: string]: string;
|
|
119
|
+
};
|
|
120
|
+
profile: "raw-work-v1";
|
|
121
|
+
provisional: boolean;
|
|
122
|
+
};
|
|
123
|
+
subject: {
|
|
124
|
+
unit: string;
|
|
125
|
+
revision: string;
|
|
126
|
+
};
|
|
127
|
+
result: {
|
|
128
|
+
cases: {
|
|
129
|
+
law: string;
|
|
130
|
+
counterexample: {
|
|
131
|
+
params: {
|
|
132
|
+
[x: string]: number;
|
|
133
|
+
};
|
|
134
|
+
initial: {
|
|
135
|
+
[x: string]: number;
|
|
136
|
+
};
|
|
137
|
+
steps: {
|
|
138
|
+
input: {
|
|
139
|
+
[x: string]: number;
|
|
140
|
+
};
|
|
141
|
+
after: {
|
|
142
|
+
[x: string]: number;
|
|
143
|
+
};
|
|
144
|
+
}[];
|
|
145
|
+
explanation: string;
|
|
146
|
+
minimality: {
|
|
147
|
+
kind: string;
|
|
148
|
+
maxDepth: number;
|
|
149
|
+
defaultValueBound: number;
|
|
150
|
+
note: string;
|
|
151
|
+
};
|
|
152
|
+
} | null;
|
|
153
|
+
}[];
|
|
154
|
+
verdicts?: undefined;
|
|
155
|
+
satisfied?: undefined;
|
|
156
|
+
discovered?: undefined;
|
|
157
|
+
nearMisses?: undefined;
|
|
158
|
+
unresolvedNearMisses?: undefined;
|
|
159
|
+
inference?: undefined;
|
|
160
|
+
nearMissSource?: undefined;
|
|
161
|
+
stillHold?: undefined;
|
|
162
|
+
newlyBroken?: undefined;
|
|
163
|
+
lostProof?: undefined;
|
|
164
|
+
behaviour?: undefined;
|
|
165
|
+
};
|
|
166
|
+
explanation: string;
|
|
167
|
+
label?: undefined;
|
|
168
|
+
statusEvidence?: undefined;
|
|
169
|
+
before?: undefined;
|
|
170
|
+
schema: string;
|
|
171
|
+
tool: import("./protocol.ts").Tool;
|
|
172
|
+
ok: boolean;
|
|
173
|
+
} | {
|
|
174
|
+
assumptions: {
|
|
175
|
+
domain: string;
|
|
176
|
+
scope: string;
|
|
177
|
+
subjects: {
|
|
178
|
+
initial: Record<string, import("../../core/machine.ts").E>;
|
|
179
|
+
pre: import("../../core/machine.ts").C | null;
|
|
180
|
+
requestAssumption: import("../../core/machine.ts").C | null;
|
|
181
|
+
unit: string;
|
|
182
|
+
revision: string;
|
|
183
|
+
}[];
|
|
184
|
+
laws: Law[];
|
|
185
|
+
};
|
|
186
|
+
budget: {
|
|
187
|
+
limits: import("./protocol.ts").Budget;
|
|
188
|
+
apiCalls: number;
|
|
189
|
+
work: Readonly<{
|
|
190
|
+
numerator: string;
|
|
191
|
+
denominator: string;
|
|
192
|
+
}>;
|
|
193
|
+
counters: {
|
|
194
|
+
[k: string]: string;
|
|
195
|
+
};
|
|
196
|
+
profile: "raw-work-v1";
|
|
197
|
+
provisional: boolean;
|
|
198
|
+
};
|
|
199
|
+
subject: {
|
|
200
|
+
unit: string;
|
|
201
|
+
revision: string;
|
|
202
|
+
};
|
|
203
|
+
result: {
|
|
204
|
+
satisfied: {
|
|
205
|
+
source: string;
|
|
206
|
+
proven: boolean;
|
|
207
|
+
checked: boolean;
|
|
208
|
+
status: string;
|
|
209
|
+
goal?: string;
|
|
210
|
+
why?: string;
|
|
211
|
+
witness?: unknown;
|
|
212
|
+
law: string;
|
|
213
|
+
}[];
|
|
214
|
+
discovered: {
|
|
215
|
+
source: string;
|
|
216
|
+
builderSource: string | null;
|
|
217
|
+
support: string[];
|
|
218
|
+
supportSource: string;
|
|
219
|
+
proven?: boolean | undefined;
|
|
220
|
+
checked?: boolean | undefined;
|
|
221
|
+
status?: string | undefined;
|
|
222
|
+
goal?: string;
|
|
223
|
+
why?: string;
|
|
224
|
+
witness?: unknown;
|
|
225
|
+
law: string;
|
|
226
|
+
}[];
|
|
227
|
+
nearMisses: {
|
|
228
|
+
law: string;
|
|
229
|
+
source: string;
|
|
230
|
+
counterexample: {
|
|
231
|
+
params: {
|
|
232
|
+
[x: string]: number;
|
|
233
|
+
};
|
|
234
|
+
initial: {
|
|
235
|
+
[x: string]: number;
|
|
236
|
+
};
|
|
237
|
+
steps: {
|
|
238
|
+
input: {
|
|
239
|
+
[x: string]: number;
|
|
240
|
+
};
|
|
241
|
+
after: {
|
|
242
|
+
[x: string]: number;
|
|
243
|
+
};
|
|
244
|
+
}[];
|
|
245
|
+
explanation: string;
|
|
246
|
+
minimality: {
|
|
247
|
+
kind: string;
|
|
248
|
+
maxDepth: number;
|
|
249
|
+
defaultValueBound: number;
|
|
250
|
+
note: string;
|
|
251
|
+
};
|
|
252
|
+
} | null;
|
|
253
|
+
}[];
|
|
254
|
+
unresolvedNearMisses: string[];
|
|
255
|
+
inference: {
|
|
256
|
+
proven: boolean;
|
|
257
|
+
checked: boolean;
|
|
258
|
+
samples: number;
|
|
259
|
+
candidates: number;
|
|
260
|
+
stopped: boolean;
|
|
261
|
+
};
|
|
262
|
+
nearMissSource: string;
|
|
263
|
+
verdicts?: undefined;
|
|
264
|
+
cases?: undefined;
|
|
265
|
+
stillHold?: undefined;
|
|
266
|
+
newlyBroken?: undefined;
|
|
267
|
+
lostProof?: undefined;
|
|
268
|
+
behaviour?: undefined;
|
|
269
|
+
};
|
|
270
|
+
explanation: string;
|
|
271
|
+
label?: undefined;
|
|
272
|
+
statusEvidence?: undefined;
|
|
273
|
+
before?: undefined;
|
|
274
|
+
schema: string;
|
|
275
|
+
tool: import("./protocol.ts").Tool;
|
|
276
|
+
ok: boolean;
|
|
277
|
+
} | {
|
|
278
|
+
assumptions: {
|
|
279
|
+
domain: string;
|
|
280
|
+
scope: string;
|
|
281
|
+
subjects: {
|
|
282
|
+
initial: Record<string, import("../../core/machine.ts").E>;
|
|
283
|
+
pre: import("../../core/machine.ts").C | null;
|
|
284
|
+
requestAssumption: import("../../core/machine.ts").C | null;
|
|
285
|
+
unit: string;
|
|
286
|
+
revision: string;
|
|
287
|
+
}[];
|
|
288
|
+
laws: Law[];
|
|
289
|
+
};
|
|
290
|
+
budget: {
|
|
291
|
+
limits: import("./protocol.ts").Budget;
|
|
292
|
+
apiCalls: number;
|
|
293
|
+
work: Readonly<{
|
|
294
|
+
numerator: string;
|
|
295
|
+
denominator: string;
|
|
296
|
+
}>;
|
|
297
|
+
counters: {
|
|
298
|
+
[k: string]: string;
|
|
299
|
+
};
|
|
300
|
+
profile: "raw-work-v1";
|
|
301
|
+
provisional: boolean;
|
|
302
|
+
};
|
|
303
|
+
subject: {
|
|
304
|
+
unit: string;
|
|
305
|
+
revision: string;
|
|
306
|
+
};
|
|
307
|
+
before: {
|
|
308
|
+
unit: string;
|
|
309
|
+
revision: string;
|
|
310
|
+
};
|
|
311
|
+
result: {
|
|
312
|
+
stillHold: string[];
|
|
313
|
+
newlyBroken: {
|
|
314
|
+
law: string;
|
|
315
|
+
trace: {
|
|
316
|
+
params: {
|
|
317
|
+
[x: string]: number;
|
|
318
|
+
};
|
|
319
|
+
initial: {
|
|
320
|
+
[x: string]: number;
|
|
321
|
+
};
|
|
322
|
+
steps: {
|
|
323
|
+
input: {
|
|
324
|
+
[x: string]: number;
|
|
325
|
+
};
|
|
326
|
+
after: {
|
|
327
|
+
[x: string]: number;
|
|
328
|
+
};
|
|
329
|
+
}[];
|
|
330
|
+
explanation: string;
|
|
331
|
+
minimality: {
|
|
332
|
+
kind: string;
|
|
333
|
+
maxDepth: number;
|
|
334
|
+
defaultValueBound: number;
|
|
335
|
+
note: string;
|
|
336
|
+
};
|
|
337
|
+
} | null;
|
|
338
|
+
}[];
|
|
339
|
+
lostProof: string[];
|
|
340
|
+
verdicts: {
|
|
341
|
+
law: string;
|
|
342
|
+
before: Proof;
|
|
343
|
+
after: Proof;
|
|
344
|
+
counterexample: {
|
|
345
|
+
params: {
|
|
346
|
+
[x: string]: number;
|
|
347
|
+
};
|
|
348
|
+
initial: {
|
|
349
|
+
[x: string]: number;
|
|
350
|
+
};
|
|
351
|
+
steps: {
|
|
352
|
+
input: {
|
|
353
|
+
[x: string]: number;
|
|
354
|
+
};
|
|
355
|
+
after: {
|
|
356
|
+
[x: string]: number;
|
|
357
|
+
};
|
|
358
|
+
}[];
|
|
359
|
+
explanation: string;
|
|
360
|
+
minimality: {
|
|
361
|
+
kind: string;
|
|
362
|
+
maxDepth: number;
|
|
363
|
+
defaultValueBound: number;
|
|
364
|
+
note: string;
|
|
365
|
+
};
|
|
366
|
+
} | null;
|
|
367
|
+
}[];
|
|
368
|
+
behaviour: {
|
|
369
|
+
scope: string;
|
|
370
|
+
status: string;
|
|
371
|
+
relation: Proof;
|
|
372
|
+
allowed: Proof;
|
|
373
|
+
trace: unknown;
|
|
374
|
+
stateNames: {
|
|
375
|
+
a: string;
|
|
376
|
+
b: string;
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
cases?: undefined;
|
|
380
|
+
satisfied?: undefined;
|
|
381
|
+
discovered?: undefined;
|
|
382
|
+
nearMisses?: undefined;
|
|
383
|
+
unresolvedNearMisses?: undefined;
|
|
384
|
+
inference?: undefined;
|
|
385
|
+
nearMissSource?: undefined;
|
|
386
|
+
};
|
|
387
|
+
statusEvidence: {
|
|
388
|
+
proven: boolean;
|
|
389
|
+
checked: boolean;
|
|
390
|
+
laws: string[];
|
|
391
|
+
unit: string;
|
|
392
|
+
revision: string;
|
|
393
|
+
}[];
|
|
394
|
+
explanation: string;
|
|
395
|
+
label?: undefined;
|
|
396
|
+
schema: string;
|
|
397
|
+
tool: import("./protocol.ts").Tool;
|
|
398
|
+
ok: boolean;
|
|
399
|
+
} | {
|
|
400
|
+
assumptions: {
|
|
401
|
+
domain: string;
|
|
402
|
+
scope: string;
|
|
403
|
+
subjects: {
|
|
404
|
+
initial: Record<string, import("../../core/machine.ts").E>;
|
|
405
|
+
pre: import("../../core/machine.ts").C | null;
|
|
406
|
+
requestAssumption: import("../../core/machine.ts").C | null;
|
|
407
|
+
unit: string;
|
|
408
|
+
revision: string;
|
|
409
|
+
}[];
|
|
410
|
+
laws: Law[];
|
|
411
|
+
} | null;
|
|
412
|
+
budget: {
|
|
413
|
+
limits: import("./protocol.ts").Budget | null;
|
|
414
|
+
apiCalls: number;
|
|
415
|
+
work: Readonly<{
|
|
416
|
+
numerator: string;
|
|
417
|
+
denominator: string;
|
|
418
|
+
}>;
|
|
419
|
+
counters: {
|
|
420
|
+
[k: string]: string;
|
|
421
|
+
};
|
|
422
|
+
profile: "raw-work-v1";
|
|
423
|
+
provisional: boolean;
|
|
424
|
+
};
|
|
425
|
+
schema: string;
|
|
426
|
+
tool: string;
|
|
427
|
+
ok: boolean;
|
|
428
|
+
refusal: {
|
|
429
|
+
code: string;
|
|
430
|
+
message: string;
|
|
431
|
+
fix: string;
|
|
432
|
+
};
|
|
433
|
+
explanation: string;
|
|
434
|
+
};
|
|
435
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { proveLaws, proveStepLaws, withBudget } from "../../kernel/prove.js";
|
|
2
|
+
import { search, interpret } from "../../core/machine.js";
|
|
3
|
+
import { inferLaws } from "../../core/infer.js";
|
|
4
|
+
import { refinement, agree } from "../../core/compose.js";
|
|
5
|
+
import { completeWorkProfile } from "../../core/work-profile.js";
|
|
6
|
+
import { workLedger, BudgetExpired } from "../../core/work-admission.js";
|
|
7
|
+
import { exactRaw, workFromExact, workSub } from "../../core/work-amount.js";
|
|
8
|
+
import { Refusal, refuse, parseRequest, revision } from "./protocol.js";
|
|
9
|
+
export function proofSummary(v) { return { proven: v.proven === true, checked: v.checked === true, status: v.proven === true && v.checked === true ? 'proven' : v.proven ? 'unchecked' : 'not-proven', ...(v.failed ? { goal: v.failed.goal, why: v.failed.why ?? v.failed.stuck, ...(v.failed.witness ? { witness: v.failed.witness } : {}) } : {}) }; }
|
|
10
|
+
const counterDelta = (before, after) => Object.fromEntries(Object.entries(after.counters).map(([k, v]) => [k, String(BigInt(v) - BigInt(before.counters[k]))]));
|
|
11
|
+
const source = (l) => `import type {Law} from 'gdp-wired/machine'\nconst law: Law = ${JSON.stringify(l)}\n`;
|
|
12
|
+
const binding = (u, laws) => ({ unit: u.unit, revision: revision(u, laws) });
|
|
13
|
+
export function failure(tool, e) { const r = e instanceof Refusal ? e : e instanceof BudgetExpired ? new Refusal('work-budget-exceeded', 'Increase budget.work within the published cap, or check fewer laws.', 'The counted work allowance was exhausted.') : e instanceof RangeError ? new Refusal('numeric-range-refused', 'Keep runtime arithmetic within nonnegative safe integers; use a separately validated bigint surface for larger values.', e.message) : new Refusal('engine-refused', 'Use the supported scalar AST; inspect the exact engine message and reduce/split the request.', e instanceof Error ? e.message : String(e)); return { schema: 'gdp-wired/agent-tool/v1', tool, ok: false, refusal: { code: r.code, message: r.message, fix: r.fix }, explanation: `${tool} refused: ${r.message} Fix: ${r.fix}` }; }
|
|
14
|
+
const context = (q) => ({ domain: 'scalar naturals; sub is truncated subtraction', scope: 'model laws from the declared initial state under pre and request assumptions; not native conformance', subjects: [q.subject, q.before, q.after].filter((u) => u !== undefined).map(u => ({ ...binding(u, q.laws ?? []), initial: u.rule.state, pre: u.rule.pre ?? null, requestAssumption: u.rule.assume ?? null })), laws: q.laws ?? [] });
|
|
15
|
+
export function execute(tool, args) {
|
|
16
|
+
const before = workLedger.snapshot();
|
|
17
|
+
let calls = 0, request;
|
|
18
|
+
const invoke = (f) => { if (!request || calls >= request.budget.apiCalls)
|
|
19
|
+
refuse('api-budget-exceeded', 'Increase budget.apiCalls or request fewer laws/candidates.', 'No further engine calls are admitted.'); calls++; return f(); };
|
|
20
|
+
try {
|
|
21
|
+
request = parseRequest(tool, args);
|
|
22
|
+
if (request.tool === 'status')
|
|
23
|
+
refuse('status-registry-required', 'Call status through the stdio server that observed the proof.', 'A fresh worker has no trusted status registry.');
|
|
24
|
+
if (!completeWorkProfile.enabled)
|
|
25
|
+
refuse('counted-profile-required', 'Start the worker with GDP_WORK_FULL=1 before importing the engine.', 'The complete counted-work profile is not enabled.');
|
|
26
|
+
const q = request, ls = q.laws;
|
|
27
|
+
const proof = (u, l) => proofSummary(invoke(() => proveLaws(u.rule, [l])));
|
|
28
|
+
const witness = (m, l) => {
|
|
29
|
+
const found = invoke(() => search(m, l, q.budget.depth, q.budget.bound));
|
|
30
|
+
if (!found)
|
|
31
|
+
return null;
|
|
32
|
+
const run = interpret(m);
|
|
33
|
+
let state = run.init(found.params);
|
|
34
|
+
const initial = { ...state.scalars }, steps = found.trace.map(input => { state = run.step(found.params, state, input); return { input, after: { ...state.scalars } }; });
|
|
35
|
+
return { params: found.params, initial, steps, explanation: `${l.name} fails from ${JSON.stringify(initial)} under parameters ${JSON.stringify(found.params)}${steps.length ? ': ' + steps.map((s, i) => `step ${i + 1}, input ${JSON.stringify(s.input)} -> ${JSON.stringify(s.after)}`).join('; ') : ' in the initial state'}. Shortest within the reported finite domain, not globally minimal.`, minimality: { kind: 'shortest-in-existing-finite-search', maxDepth: q.budget.depth, defaultValueBound: q.budget.bound, note: 'Existing search also honors explicit scalar upper bounds up to15; this is not a global unbounded minimality claim.' } };
|
|
36
|
+
};
|
|
37
|
+
const output = withBudget(q.budget.work, () => workLedger.withCapacityRefusalBoundary(() => {
|
|
38
|
+
if (q.tool === 'prove') {
|
|
39
|
+
const u = q.subject, verdicts = ls.map(l => ({ law: l.name, ...proof(u, l) })), proven = verdicts.every(v => v.proven && v.checked);
|
|
40
|
+
return { subject: binding(u, ls), label: proven ? 'proven' : 'not adequate', result: { verdicts }, statusEvidence: [{ ...binding(u, ls), proven, checked: proven, laws: ls.map(l => l.name) }], explanation: `${u.unit}: ${proven ? 'every requested law has a checked inductive proof' : 'not every requested law has a checked proof'}. Checked state names: ${Object.keys(u.rule.state).join(', ')}; parameters: ${u.rule.params.join(', ') || 'none'}. This is a rule proof, not native conformance.` };
|
|
41
|
+
}
|
|
42
|
+
if (q.tool === 'why_not') {
|
|
43
|
+
const u = q.subject, cases = ls.map(l => ({ law: l.name, counterexample: witness(u.rule, l) }));
|
|
44
|
+
return { subject: binding(u, ls), result: { cases }, explanation: `${u.unit}: ${cases.filter(c => c.counterexample).length} requested law(s) have a reachable interpreter counterexample in the stated finite domain. Traces use the original parameter, input and state names; absence of a trace does not prove a law.` };
|
|
45
|
+
}
|
|
46
|
+
if (q.tool === 'suggest') {
|
|
47
|
+
const u = q.subject, known = ls.map(l => ({ law: l.name, ...proof(u, l), source: source(l) }));
|
|
48
|
+
const inferred = invoke(() => inferLaws(u.rule, ls, [], { runs: 128, maxCandidates: q.budget.candidates, timed: false, minimize: false, ms: q.budget.work / 250, wall: Infinity }));
|
|
49
|
+
const found = inferred.found.slice(0, 8), support = [...ls, ...found.map(f => f.law)];
|
|
50
|
+
const closure = found.length ? proofSummary(invoke(() => proveLaws(u.rule, support))) : null;
|
|
51
|
+
const discovered = found.map(f => ({ law: f.law.name, ...closure, source: source(f.law), builderSource: f.source ?? null, support: support.map(l => l.name), supportSource: `import type {Law} from 'gdp-wired/machine'\nconst support: Law[] = ${JSON.stringify(support)}\n` }));
|
|
52
|
+
const nearMisses = (q.nearMisses ?? []).map(l => ({ law: l.name, source: source(l), counterexample: witness(u.rule, l) }));
|
|
53
|
+
return { subject: binding(u, ls), result: { satisfied: known.filter(p => p.proven && p.checked), discovered: discovered.filter(p => p.proven && p.checked), nearMisses: nearMisses.filter(n => n.counterexample), unresolvedNearMisses: nearMisses.filter(n => !n.counterexample).map(n => n.law), inference: { proven: inferred.proven === true, checked: inferred.checked === true, samples: inferred.stats.samples, candidates: inferred.stats.candidates, stopped: inferred.stats.stopped }, nearMissSource: 'caller-supplied candidate laws; no new candidate synthesis engine' }, explanation: `${u.unit}: existing inferLaws generated candidate laws; only checked laws or jointly checked support sets are returned as satisfied/discovered. Supplied near misses are returned only with a real bounded counterexample. Each item includes pasteable source; no statistical sample is promoted to a proof.` };
|
|
54
|
+
}
|
|
55
|
+
if (q.tool === 'check_change') {
|
|
56
|
+
const a = q.before, b = q.after;
|
|
57
|
+
const rows = ls.map(l => { const before = proof(a, l), after = proof(b, l); return { law: l.name, before, after, counterexample: before.proven && before.checked && !(after.proven && after.checked) ? witness(b.rule, l) : null }; });
|
|
58
|
+
const composed = refinement(b.rule, a.rule, { relation: agree(a.rule), witness: Object.fromEntries(a.rule.inputs.map(n => [n, { op: 'var', name: n }])) });
|
|
59
|
+
const relation = proofSummary(invoke(() => proveLaws(composed.machine, composed.laws)));
|
|
60
|
+
const allowed = proofSummary(invoke(() => proveStepLaws(composed.machine, composed.laws, composed.stepLaws)));
|
|
61
|
+
let difference = null;
|
|
62
|
+
if (!(relation.proven && relation.checked && allowed.proven && allowed.checked))
|
|
63
|
+
for (const l of composed.laws) {
|
|
64
|
+
difference = witness(composed.machine, l);
|
|
65
|
+
if (difference)
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
const refines = relation.proven && relation.checked && allowed.proven && allowed.checked;
|
|
69
|
+
return { subject: binding(b, ls), before: binding(a, ls), result: { stillHold: rows.filter(r => r.after.proven && r.after.checked).map(r => r.law), newlyBroken: rows.filter(r => r.counterexample).map(r => ({ law: r.law, trace: r.counterexample })), lostProof: rows.filter(r => r.before.proven && r.before.checked && !(r.after.proven && r.after.checked) && !r.counterexample).map(r => r.law), verdicts: rows, behaviour: { scope: 'after refines before under the implementation precondition; identity input witness, equality state relation; not bidirectional equivalence', status: refines ? 'checked-refinement' : difference ? 'bounded-difference' : 'unresolved', relation, allowed, trace: difference, stateNames: { a: 'after', b: 'before' } } }, statusEvidence: [{ ...binding(a, ls), proven: rows.every(r => r.before.proven && r.before.checked), checked: rows.every(r => r.before.proven && r.before.checked), laws: ls.map(l => l.name) }, { ...binding(b, ls), proven: rows.every(r => r.after.proven && r.after.checked), checked: rows.every(r => r.after.proven && r.after.checked), laws: ls.map(l => l.name) }], explanation: `${b.unit}: ${rows.filter(r => r.counterexample).length} previously checked law(s) now have a real counterexample; ${rows.filter(r => r.after.proven && r.after.checked).length} remain checked. Behaviour uses the existing compose.refinement machine and both invariant and request-admissibility checks; an unknown proof is not itself a behaviour difference.` };
|
|
70
|
+
}
|
|
71
|
+
return refuse('unknown-tool', 'Use a documented tool.', 'No implementation for this tool');
|
|
72
|
+
}));
|
|
73
|
+
const assumptions = context(q);
|
|
74
|
+
if ('statusEvidence' in output)
|
|
75
|
+
for (const record of output.statusEvidence ?? [])
|
|
76
|
+
Object.assign(record, { assumptions });
|
|
77
|
+
const after = workLedger.snapshot();
|
|
78
|
+
return { schema: 'gdp-wired/agent-tool/v1', tool: q.tool, ok: true, ...output, assumptions, budget: { limits: q.budget, apiCalls: calls, work: exactRaw(workSub(workFromExact(after.actual), workFromExact(before.actual))), counters: counterDelta(before, after), profile: completeWorkProfile.id, provisional: true } };
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
const after = workLedger.snapshot();
|
|
82
|
+
return { ...failure(String(tool), e), assumptions: request ? context(request) : null, budget: { limits: request?.budget ?? null, apiCalls: calls, work: exactRaw(workSub(workFromExact(after.actual), workFromExact(before.actual))), counters: counterDelta(before, after), profile: completeWorkProfile.id, provisional: true } };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ConsultationOptions } from './workspace.js';
|
|
2
|
+
type RecordValue = Record<string, unknown>;
|
|
3
|
+
export declare function createConsultation(options?: ConsultationOptions): {
|
|
4
|
+
handle: (request: unknown, options?: {
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
}) => Promise<RecordValue | null>;
|
|
7
|
+
call: (tool: unknown, args: unknown, options?: {
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
}) => Promise<RecordValue>;
|
|
10
|
+
close: () => Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export declare function serveStdio(options?: ConsultationOptions): Promise<void>;
|
|
13
|
+
export {};
|