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
package/dist/core/discover.js
CHANGED
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
// out.verdict // the laws, proven of out.rule: r with its functions and lists made again with the lemmas
|
|
12
12
|
// out.found // per function or list, the lemmas found, as source to paste into recur(...) or carriesList(...)
|
|
13
13
|
import { quietly } from "./cyclic.js";
|
|
14
|
+
import { BudgetExpired, checkBudget, checkWorkEndpoint, withBudget } from "./wall.js";
|
|
15
|
+
import { workContext, workRefusalWhy } from "./work-refusal.js";
|
|
16
|
+
import { WatchdogExpired, checkWatchdog, withSearchWatchdog } from "./search-watchdog.js";
|
|
17
|
+
import { searchContext, stoppedSearch } from "./search-termination.js";
|
|
14
18
|
import { any, atMost, compileFunction, evalC, evalE, n, plus, prod, same, seeded, times, x } from "./machine.js";
|
|
15
19
|
import { Unproven, lit, proveFold, proveSteps, recur, recurOf } from "./dsl.js";
|
|
16
20
|
import { gcd, plus as addLin } from "./solver.js";
|
|
@@ -310,13 +314,56 @@ function houdiniList(r, part, cands, params) {
|
|
|
310
314
|
}
|
|
311
315
|
return undefined;
|
|
312
316
|
}
|
|
313
|
-
//
|
|
314
|
-
//
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
317
|
+
// The optional fifth argument bounds the entire discovery, including sampling,
|
|
318
|
+
// candidate proofs and minimization. Nested calls keep the enclosing authority.
|
|
319
|
+
export function discover(r, laws, stepLaws = [], first, opts = {}) {
|
|
320
|
+
let completed, initial = first;
|
|
321
|
+
const run = () => {
|
|
322
|
+
checkWorkEndpoint('discovery entry');
|
|
323
|
+
const normalized = r.withSumsOf(laws, stepLaws);
|
|
324
|
+
const result = quietly(() => {
|
|
325
|
+
initial ??= proveSteps(normalized, laws, stepLaws, { search: false });
|
|
326
|
+
return discoverSearch(normalized, laws, stepLaws, initial);
|
|
327
|
+
});
|
|
328
|
+
// Record completion only after counted authority has accepted its cost.
|
|
329
|
+
// A later own safety-clock observation must not overwrite that evidence.
|
|
330
|
+
checkBudget('discovery result');
|
|
331
|
+
completed = result;
|
|
332
|
+
checkWatchdog('discovery result');
|
|
333
|
+
return result;
|
|
334
|
+
};
|
|
335
|
+
const work = () => {
|
|
336
|
+
if (opts.work === undefined)
|
|
337
|
+
return run();
|
|
338
|
+
try {
|
|
339
|
+
return withBudget(opts.work, run);
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
if (!(error instanceof BudgetExpired))
|
|
343
|
+
throw error;
|
|
344
|
+
// Only work authority is checked here: an OWN watchdog may have
|
|
345
|
+
// expired after the actual BudgetExpired. Record its work cause before
|
|
346
|
+
// the outer safety scope unwinds/rechecks any ancestor watchdog.
|
|
347
|
+
checkBudget(error.phase);
|
|
348
|
+
const context = workContext(error) ?? (initial ? searchContext(initial) : undefined);
|
|
349
|
+
return { rule: r, found: {}, verdict: { proven: false, checked: false, stuck: 'unknown', why: workRefusalWhy(error), stopped: true,
|
|
350
|
+
termination: { kind: 'work-exhausted', phase: error.phase, scope: 'search' }, ...(context ? { context } : {}) } };
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
try {
|
|
354
|
+
return withSearchWatchdog(opts.watchdogMs, () => completed = work());
|
|
355
|
+
}
|
|
356
|
+
catch (error) {
|
|
357
|
+
if (!(error instanceof WatchdogExpired))
|
|
358
|
+
throw error;
|
|
359
|
+
checkWatchdog(error.termination.phase); // an expired ancestor must not return through this helper
|
|
360
|
+
checkBudget(error.termination.phase); // neither may a work owner hidden by the child's own watchdog
|
|
361
|
+
// The final scope guard may observe expiry after the synchronous request
|
|
362
|
+
// already finished. No search was interrupted then; retain its real result.
|
|
363
|
+
if (completed)
|
|
364
|
+
return completed;
|
|
365
|
+
return { rule: r, found: {}, verdict: stoppedSearch({ proven: false, checked: false, stuck: 'unknown', ...(initial ? { context: searchContext(initial) } : {}) }, error.termination) };
|
|
366
|
+
}
|
|
320
367
|
}
|
|
321
368
|
function discoverSearch(r, laws, stepLaws, first) {
|
|
322
369
|
if (first.proven && first.checked)
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { type WorkAmount } from './work-amount.js';
|
|
2
|
+
export declare function remainingStageWork(requested: number | WorkAmount, parts: number): number | WorkAmount;
|
|
3
|
+
export declare function withStageWork<T, F>(units: number | WorkAmount, run: () => T, refused: () => F): T | F;
|
|
1
4
|
export declare function withStageDeadline<T, F>(until: number, run: () => T, refused: () => F): T | F;
|
|
2
5
|
export declare function withStageAllowance<T, F>(ms: number, run: () => T, refused: () => F): T | F;
|
|
3
6
|
export declare function withStageWall<T, F>(until: number, run: () => T, refused: () => F): T | F;
|
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
// Soft search limits are not replacements for the caller's work budget.
|
|
2
2
|
// Legacy mode executes the identical polling path. Full accounting consumes
|
|
3
3
|
// only authenticated refusals belonging to this stage's own endpoint.
|
|
4
|
-
import { budgetEnd, clock, fullRate, inWorkScope, withDeadline, withWall, wallDeadline } from "../kernel/prove.js";
|
|
4
|
+
import { budgetEnd, clock, fullRate, inWorkScope, withDeadline, withWall, wallDeadline, remainingWork } from "../kernel/prove.js";
|
|
5
5
|
import { workLedger } from "./work-admission.js";
|
|
6
|
-
import { workFromNumber, workMultiply } from "./work-amount.js";
|
|
6
|
+
import { minWork, workDivide, workFromNumber, workMultiply } from "./work-amount.js";
|
|
7
7
|
import { completeWorkProfile } from "./work-profile.js";
|
|
8
8
|
import { inProxySearch } from "./search-policy.js";
|
|
9
|
+
import { BudgetExpired, checkWorkEndpoint, withBudget } from "./wall.js";
|
|
10
|
+
// Divide what the enclosing owner can still grant, not the original request.
|
|
11
|
+
// An earlier phase may already have used almost all of that original allowance.
|
|
12
|
+
export function remainingStageWork(requested, parts) {
|
|
13
|
+
if (!Number.isFinite(parts) || parts <= 0)
|
|
14
|
+
throw new RangeError('stage divisor must be positive and finite');
|
|
15
|
+
if (typeof requested === 'number')
|
|
16
|
+
return Math.min(requested, remainingWork()) / parts;
|
|
17
|
+
const available = workLedger.available();
|
|
18
|
+
return workDivide(available === null ? requested : minWork(requested, available), workFromNumber(parts));
|
|
19
|
+
}
|
|
20
|
+
// A bounded deterministic attempt may decline without consuming the parent's
|
|
21
|
+
// remaining search. A root/ancestor refusal must still reach its own owner.
|
|
22
|
+
export function withStageWork(units, run, refused) {
|
|
23
|
+
try {
|
|
24
|
+
return withBudget(units, run);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (!(error instanceof BudgetExpired))
|
|
28
|
+
throw error;
|
|
29
|
+
checkWorkEndpoint(error.phase);
|
|
30
|
+
return refused();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
9
33
|
export function withStageDeadline(until, run, refused) {
|
|
10
34
|
if (!completeWorkProfile.enabled || inProxySearch())
|
|
11
35
|
return withDeadline(until, run);
|
package/dist/core/dsl.d.ts
CHANGED
|
@@ -922,7 +922,8 @@ export declare class LoopRule<P extends Obj = {}, I extends Obj = {}, S extends
|
|
|
922
922
|
randomInput(rand: Rand, bound: number): Record<string, number>;
|
|
923
923
|
}
|
|
924
924
|
export declare const loop: (name: string) => LoopRule;
|
|
925
|
-
export type
|
|
925
|
+
export type { SearchTermination, SearchContext, SearchTerminationFields } from './search-termination.js';
|
|
926
|
+
export type Verdict = TranslationFields & import('./search-termination.ts').SearchTerminationFields & {
|
|
926
927
|
proven: boolean;
|
|
927
928
|
checked: boolean;
|
|
928
929
|
stuck?: string;
|
|
@@ -970,6 +971,7 @@ export type CandidateSeedAudit = {
|
|
|
970
971
|
reason?: string;
|
|
971
972
|
};
|
|
972
973
|
export type ProveOptions = {
|
|
974
|
+
watchdogMs?: number;
|
|
973
975
|
search?: boolean | {
|
|
974
976
|
ms?: number;
|
|
975
977
|
work?: number | WorkAmount;
|
package/dist/core/dsl.js
CHANGED
|
@@ -28,12 +28,14 @@ import { allowed, keysOf, requestEnv, watch, watchWork } from "./watch.js";
|
|
|
28
28
|
import { ghostOf, proveSome, skolemOf, someHolds, substVars, substVarsE, witnessSupport } from "./exists.js";
|
|
29
29
|
import { check, mapArities, checkRecur, foldObligations, ghostedMachine, loopObligations, someOfGhostsOk, substC, sumMachine } from "../kernel/kernel.js";
|
|
30
30
|
import { certLoop, clock, counted, factsFor, fullRate, grow, pastWall, proveLaw, proveLaws, proveLiveness, proveSetFast, proveStepLaws, usualProof, withModelRounds, withWall } from "../kernel/prove.js";
|
|
31
|
-
import { WallExpired, checkWall, checkWorkEndpoint, searchWall, withBudget, BudgetExpired } from "./wall.js";
|
|
31
|
+
import { WallExpired, checkWall, checkBudget, checkWorkEndpoint, searchWall, withBudget, BudgetExpired } from "./wall.js";
|
|
32
32
|
import { completeWorkProfile } from "./work-profile.js";
|
|
33
33
|
import { workLedger } from "./work-admission.js";
|
|
34
|
-
import { withStageAllowance, withStageDeadline, withStageWall } from "./dsl-deadline.js";
|
|
34
|
+
import { withStageAllowance, withStageDeadline, withStageWall, withStageWork, remainingStageWork } from "./dsl-deadline.js";
|
|
35
|
+
import { completedSearch, searchContext, stoppedSearch } from "./search-termination.js";
|
|
36
|
+
import { WatchdogExpired, checkWatchdog, withSearchWatchdog } from "./search-watchdog.js";
|
|
35
37
|
import { withPublicSearchPolicy } from "./search-policy.js";
|
|
36
|
-
import { workRefusalWhy } from "./work-refusal.js";
|
|
38
|
+
import { captureWorkContext, workContext, workRefusalWhy } from "./work-refusal.js";
|
|
37
39
|
import { workDivide, workFromNumber, workToNumber } from "./work-amount.js";
|
|
38
40
|
import { certCyclic, certOn, crossCyclic, cyclicOn, foldNodes, proveCyclic, quietly, recurNodes, translatedProof, uncovered } from "./cyclic.js";
|
|
39
41
|
import { discover } from "./discover.js";
|
|
@@ -3246,7 +3248,7 @@ function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
|
|
|
3246
3248
|
return at(params, 0);
|
|
3247
3249
|
}
|
|
3248
3250
|
catch (e) {
|
|
3249
|
-
if (e instanceof WallExpired)
|
|
3251
|
+
if (e instanceof WallExpired || e instanceof WatchdogExpired)
|
|
3250
3252
|
throw e;
|
|
3251
3253
|
if (e instanceof BudgetExpired)
|
|
3252
3254
|
checkWorkEndpoint(e.phase);
|
|
@@ -3335,7 +3337,7 @@ function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
|
|
|
3335
3337
|
}
|
|
3336
3338
|
}
|
|
3337
3339
|
catch (e) {
|
|
3338
|
-
if (e instanceof WallExpired)
|
|
3340
|
+
if (e instanceof WallExpired || e instanceof WatchdogExpired)
|
|
3339
3341
|
throw e;
|
|
3340
3342
|
if (e instanceof BudgetExpired)
|
|
3341
3343
|
checkWorkEndpoint(e.phase);
|
|
@@ -3359,13 +3361,19 @@ function workPlan(opts) {
|
|
|
3359
3361
|
if (work === undefined || opts.search === false)
|
|
3360
3362
|
return { work, opts };
|
|
3361
3363
|
const search = typeof opts.search === 'object' ? { ...opts.search } : {};
|
|
3364
|
+
// An explicit public work grant remains a work grant through every plain
|
|
3365
|
+
// search phase. It must not be re-expressed as a counted-millisecond
|
|
3366
|
+
// deadline: the enclosing ledger endpoint is its sole semantic authority.
|
|
3367
|
+
if (explicit !== undefined) {
|
|
3368
|
+
delete search.ms;
|
|
3369
|
+
return { work, opts: { ...opts, search } };
|
|
3370
|
+
}
|
|
3362
3371
|
delete search.work;
|
|
3363
|
-
//
|
|
3364
|
-
// original amount. This display must never become the root's authority.
|
|
3372
|
+
// Legacy ms compatibility keeps its historical counted-clock scheduling.
|
|
3365
3373
|
search.ms = typeof work === 'number' ? work / fullRate : workToNumber(workDivide(work, workFromNumber(fullRate)));
|
|
3366
3374
|
return { work, opts: { ...opts, search } };
|
|
3367
3375
|
}
|
|
3368
|
-
function workVerdict(opts,
|
|
3376
|
+
function workVerdict(opts, run) {
|
|
3369
3377
|
const plan = workPlan(opts);
|
|
3370
3378
|
// An implicit child inherits the owner's hard allowance, not a fresh default.
|
|
3371
3379
|
// Keep workPlan's validation and scheduling hint; let the owner's refusal
|
|
@@ -3375,37 +3383,56 @@ function workVerdict(opts, supported, run) {
|
|
|
3375
3383
|
return run(plan.opts);
|
|
3376
3384
|
if (plan.work === undefined)
|
|
3377
3385
|
return run(plan.opts);
|
|
3378
|
-
if (!completeWorkProfile.enabled && !supported)
|
|
3379
|
-
return { proven: false, checked: false, stuck: 'unknown', why: 'work mode: plain-path migration pending' };
|
|
3380
3386
|
try {
|
|
3381
3387
|
return withBudget(plan.work, () => run(plan.opts));
|
|
3382
3388
|
}
|
|
3383
3389
|
catch (error) {
|
|
3384
3390
|
if (!(error instanceof BudgetExpired))
|
|
3385
3391
|
throw error;
|
|
3386
|
-
|
|
3392
|
+
// Once this child's scope has unwound, an exhausted ancestor still owns
|
|
3393
|
+
// its refusal. Do not turn the parent's cancellation into a child result.
|
|
3394
|
+
checkBudget(error.phase); // work-only: this call's own watchdog is still installed
|
|
3395
|
+
return { proven: false, checked: false, stuck: 'unknown', why: workRefusalWhy(error), stopped: true, termination: { kind: 'work-exhausted', phase: error.phase, scope: 'search' }, ...(workContext(error) ? { context: workContext(error) } : {}) };
|
|
3396
|
+
}
|
|
3397
|
+
}
|
|
3398
|
+
function watchdogVerdict(ms, run) {
|
|
3399
|
+
let result;
|
|
3400
|
+
try {
|
|
3401
|
+
return withSearchWatchdog(ms, () => result = run());
|
|
3402
|
+
}
|
|
3403
|
+
catch (e) {
|
|
3404
|
+
if (!(e instanceof WatchdogExpired))
|
|
3405
|
+
throw e;
|
|
3406
|
+
checkWatchdog(e.termination.phase); // an expired ancestor still owns cancellation
|
|
3407
|
+
checkBudget(e.termination.phase); // an owned clock must not hide exhausted ancestor work
|
|
3408
|
+
if (completedSearch(result) || result?.stopped && result.termination)
|
|
3409
|
+
return result;
|
|
3410
|
+
return stoppedSearch({ ...result, proven: false, checked: false, stuck: 'unknown' }, e.termination);
|
|
3387
3411
|
}
|
|
3388
3412
|
}
|
|
3389
3413
|
export function proveRule(r, laws, opts = {}) {
|
|
3390
|
-
return withModelRounds(opts.modelRounds, () => withPublicRule(outermost => {
|
|
3414
|
+
return watchdogVerdict(opts.watchdogMs, () => withModelRounds(opts.modelRounds, () => withPublicRule(outermost => {
|
|
3391
3415
|
const captureMachine = r.machine, hasCounts = !!Object.keys(captureMachine.counts ?? {}).length;
|
|
3392
|
-
const result = workVerdict(opts,
|
|
3416
|
+
const result = workVerdict(opts, plan => withPublicSearchPolicy(hasCounts, () => proveRuleWall(r, laws, plan)));
|
|
3393
3417
|
return outermost ? publishProof(result, captureMachine, laws) : result;
|
|
3394
|
-
}));
|
|
3418
|
+
})));
|
|
3395
3419
|
}
|
|
3396
3420
|
function proveRuleWall(r, laws, opts) {
|
|
3397
3421
|
const ms = typeof opts.search === 'object' ? opts.search.ms : undefined;
|
|
3398
3422
|
const run = () => {
|
|
3423
|
+
let result;
|
|
3399
3424
|
try {
|
|
3400
3425
|
checkWall('rule preflight');
|
|
3401
|
-
const out = proveRuleIn(r, laws, opts);
|
|
3402
|
-
|
|
3426
|
+
const out = result = proveRuleIn(r, laws, opts);
|
|
3427
|
+
if (!completedSearch(out) && !(out.stopped && out.termination))
|
|
3428
|
+
checkWall('rule result');
|
|
3403
3429
|
return out;
|
|
3404
3430
|
}
|
|
3405
3431
|
catch (e) {
|
|
3406
|
-
if (!(e instanceof WallExpired))
|
|
3432
|
+
if (!(e instanceof WallExpired) && !(e instanceof WatchdogExpired))
|
|
3407
3433
|
throw e;
|
|
3408
|
-
|
|
3434
|
+
const out = { ...result, proven: false, checked: false, stuck: 'unknown', why: result?.why ?? e.message };
|
|
3435
|
+
return e.termination ? stoppedSearch(out, e.termination) : out;
|
|
3409
3436
|
}
|
|
3410
3437
|
};
|
|
3411
3438
|
// One absolute wall for setup, sampling, generation and proof, not a fresh
|
|
@@ -3462,7 +3489,11 @@ function proveRuleIn(r, laws, opts) {
|
|
|
3462
3489
|
// Quantified witness preflight needs a counted allocation: a slow attempt must
|
|
3463
3490
|
// not seed different memoized decisions. Other laws keep their existing budget;
|
|
3464
3491
|
// inference's query rate is not calibrated for their whole-set preflight.
|
|
3465
|
-
const
|
|
3492
|
+
const explicitWork = typeof opts.search === 'object' ? opts.search.work : undefined;
|
|
3493
|
+
// Whole-set preflight is only one search strategy. In work mode reserve a
|
|
3494
|
+
// deterministic eighth for it, rather than starving inference at the root.
|
|
3495
|
+
const preflight = explicitWork === undefined ? undefined : remainingStageWork(explicitWork, 8);
|
|
3496
|
+
const out = preflight !== undefined ? withStageWork(preflight, given, () => undefined) : ms === undefined ? given() : withStageWall(countedSearchNow() + ms / share, () => share === 1 ? given() : counted(inferRates.work, () => withStageDeadline(clock() + ms / share, given, () => undefined)), () => undefined);
|
|
3466
3497
|
const v = out ? { ...verdictOf(out), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) }
|
|
3467
3498
|
: { proven: false, checked: false, stuck: 'unknown' };
|
|
3468
3499
|
if (out)
|
|
@@ -3470,7 +3501,7 @@ function proveRuleIn(r, laws, opts) {
|
|
|
3470
3501
|
return searched(r, laws, [], v, opts);
|
|
3471
3502
|
}
|
|
3472
3503
|
export function proveSteps(r, laws, stepLaws, opts = {}) {
|
|
3473
|
-
return
|
|
3504
|
+
return watchdogVerdict(opts.watchdogMs, () => workVerdict(opts, plan => proveStepsWall(r, laws, stepLaws, plan)));
|
|
3474
3505
|
}
|
|
3475
3506
|
function proveStepsWall(r, laws, stepLaws, opts) {
|
|
3476
3507
|
const ms = typeof opts.search === 'object' ? opts.search.ms : undefined;
|
|
@@ -3481,9 +3512,10 @@ function proveStepsWall(r, laws, stepLaws, opts) {
|
|
|
3481
3512
|
return proveStepsIn(r, laws, stepLaws, opts);
|
|
3482
3513
|
}
|
|
3483
3514
|
catch (e) {
|
|
3484
|
-
if (!(e instanceof WallExpired))
|
|
3515
|
+
if (!(e instanceof WallExpired) && !(e instanceof WatchdogExpired))
|
|
3485
3516
|
throw e;
|
|
3486
|
-
|
|
3517
|
+
const out = { proven: false, checked: false, stuck: 'unknown', why: e.message };
|
|
3518
|
+
return e.termination ? stoppedSearch(out, e.termination) : out;
|
|
3487
3519
|
}
|
|
3488
3520
|
};
|
|
3489
3521
|
const verdict = opts.from !== 'any' || ms === undefined ? run()
|
|
@@ -3532,13 +3564,30 @@ function stepGhosts(m, stepLaws) {
|
|
|
3532
3564
|
// recurrences or carried lists (the rule made again with them), then invariants over what it then is. The verdict is the
|
|
3533
3565
|
// prover's on the laws with what was found; when nothing is found, the prover's own (with why).
|
|
3534
3566
|
function searched(r, laws, stepLaws, v, opts) {
|
|
3567
|
+
try {
|
|
3568
|
+
return searchedIn(r, laws, stepLaws, v, opts);
|
|
3569
|
+
}
|
|
3570
|
+
catch (e) {
|
|
3571
|
+
// Keep the initial SAT/goal/model before the outer catch can replace it.
|
|
3572
|
+
// The exception carries provenance stamped before the clock scope unwinds.
|
|
3573
|
+
if (e instanceof BudgetExpired) {
|
|
3574
|
+
captureWorkContext(e, searchContext(v));
|
|
3575
|
+
throw e;
|
|
3576
|
+
}
|
|
3577
|
+
if ((!(e instanceof WallExpired) && !(e instanceof WatchdogExpired)) || !e.termination)
|
|
3578
|
+
throw e;
|
|
3579
|
+
return stoppedSearch(v, e.termination);
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
function searchedIn(r, laws, stepLaws, v, opts) {
|
|
3535
3583
|
const any = opts.from === 'any';
|
|
3536
3584
|
if ((v.proven && v.checked) || opts.search === false || v.run || v.stuck === 'sat' && (any || !/@step|@\d+ steps/.test(v.goal ?? '')))
|
|
3537
3585
|
return v;
|
|
3538
3586
|
// The deeper runs; then runs over small values (keys that meet, small params), whose requests meet their
|
|
3539
3587
|
// assumption's equalities and clocks, or near the counterexample the verdict ends at.
|
|
3540
3588
|
// (the three within the search's budget again, on the wall: past it they stop, and the search starts as it would)
|
|
3541
|
-
const
|
|
3589
|
+
const explicitWork = typeof opts.search === 'object' ? opts.search.work : undefined;
|
|
3590
|
+
const ms = explicitWork === undefined ? (typeof opts.search === 'object' && opts.search.ms !== undefined ? opts.search.ms : 10_000) : Infinity, runsUntil = explicitWork === undefined ? countedSearchNow() + ms : Infinity;
|
|
3542
3591
|
for (const b of [deeperBudget, { ...deeperBudget, bound: 1, seed: 31, states: false }, { ...deeperBudget, trials: 1200, seed: 41, states: false, mixed: true, ...(v.witness ? { near: v.witness } : {}) }]) {
|
|
3543
3592
|
const deeper = refuteByRuns(r, laws, stepLaws, { ...b, until: runsUntil });
|
|
3544
3593
|
if (deeper?.run)
|
|
@@ -3553,9 +3602,16 @@ function searched(r, laws, stepLaws, v, opts) {
|
|
|
3553
3602
|
if (deeper?.run)
|
|
3554
3603
|
return refutedVerdict(deeper);
|
|
3555
3604
|
}
|
|
3556
|
-
const until = clock() + (typeof opts.search === 'object' && opts.search.ms !== undefined ? opts.search.ms : 10_000);
|
|
3557
|
-
//
|
|
3558
|
-
|
|
3605
|
+
const until = explicitWork === undefined ? clock() + (typeof opts.search === 'object' && opts.search.ms !== undefined ? opts.search.ms : 10_000) : Infinity;
|
|
3606
|
+
// Work uses only its ledger; legacy stages retain their captured real/count endpoint.
|
|
3607
|
+
if (explicitWork !== undefined)
|
|
3608
|
+
return searchedUntil(r, laws, stepLaws, v, opts, until);
|
|
3609
|
+
return withStageWall(countedSearchNow() + Math.max(0, until - clock()), () => {
|
|
3610
|
+
const out = searchedUntil(r, laws, stepLaws, v, opts, until);
|
|
3611
|
+
if (!(out.proven && out.checked) && !out.run)
|
|
3612
|
+
checkWall('search result');
|
|
3613
|
+
return out;
|
|
3614
|
+
}, () => stoppedSearch(v, { kind: 'work-exhausted', phase: 'search stage', scope: 'stage' }));
|
|
3559
3615
|
}
|
|
3560
3616
|
// Two machines alike up to the names of the keys their quantified flags and writes at every key bind (the rule builds
|
|
3561
3617
|
// fresh ones each time it is read): each bound name by its place of first binding.
|
|
@@ -3568,7 +3624,7 @@ const sameMachine = (a, b) => {
|
|
|
3568
3624
|
return canon(a) === canon(b);
|
|
3569
3625
|
};
|
|
3570
3626
|
function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
3571
|
-
const any = opts.from === 'any';
|
|
3627
|
+
const any = opts.from === 'any', explicitWork = typeof opts.search === 'object' ? opts.search.work : undefined;
|
|
3572
3628
|
// Bounded runs (core/bmc.ts): a law broken k steps from the start, a model of the kernel's k-step goal, the run taken
|
|
3573
3629
|
// by the interpreter. The shallow depths first, within a fortieth of the search's budget (at most 250 ms, counted in
|
|
3574
3630
|
// the cost model's work: kernel/prove.ts's `counted` with `full`); the deeper ones only where the invariant search
|
|
@@ -3727,13 +3783,19 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3727
3783
|
keep = keep.filter(c => !drop.includes(c));
|
|
3728
3784
|
}
|
|
3729
3785
|
}
|
|
3730
|
-
|
|
3786
|
+
let searchStop;
|
|
3787
|
+
const stageStopped = () => { searchStop = { kind: 'work-exhausted', phase: 'invariant search', scope: 'stage' }; return undefined; };
|
|
3788
|
+
const inferenceBudget = explicitWork === undefined ? { ms } : { work: explicitWork };
|
|
3789
|
+
const infer = () => inferLaws(target, [...fresh.map(f => f.law), ...sought], stepLaws, { ...inferenceBudget, ...((rule === r && !fresh.length) || sk ? { first: v } : {}), ...(sk ? { join: 0 } : {}) });
|
|
3790
|
+
const inf = explicitWork === undefined ? withStageWall(tailAt(), infer, stageStopped) : infer();
|
|
3731
3791
|
if (!(inf?.proven && inf.checked)) {
|
|
3732
3792
|
// The sum of each map the step writes (withMapSums): the search again over the rule with them, within half of what
|
|
3733
3793
|
// is left (at most 20 s), where a law of cells against a total needs one (no ERC20 balance past the supply).
|
|
3734
3794
|
const summed = target.withMapSums();
|
|
3735
3795
|
if (summed && until - clock() - tail > 1000) {
|
|
3736
|
-
const
|
|
3796
|
+
const infer2 = () => inferLaws(summed, [...fresh.map(f => f.law), ...sought], stepLaws, explicitWork === undefined ? { ms: Math.min(20_000, (until - clock() - tail) / 2) } : { work: explicitWork });
|
|
3797
|
+
const inf2 = explicitWork === undefined ? withStageWall(tailAt(), infer2, stageStopped) : infer2();
|
|
3798
|
+
searchStop = inf2?.termination ?? searchStop;
|
|
3737
3799
|
if (inf2?.proven && inf2.checked) {
|
|
3738
3800
|
const { found, stats: _s2, ...verdict } = inf2;
|
|
3739
3801
|
void _s2;
|
|
@@ -3746,7 +3808,8 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3746
3808
|
const deep = bounded(Math.max(0, Math.min(until - clock(), ghosted && !laws.length ? 10_000 : Infinity)), Math.max(1, reached), true);
|
|
3747
3809
|
if (deep)
|
|
3748
3810
|
return refutedBy(deep);
|
|
3749
|
-
|
|
3811
|
+
const termination = inf?.termination ?? searchStop;
|
|
3812
|
+
return termination ? stoppedSearch(v, termination) : { ...v, why: [v.why, inf ? `the search found nothing that proves it in ${Math.round(inf.stats.ms)} ms` : 'the search reached its stage deadline'].filter(Boolean).join('; ') };
|
|
3750
3813
|
}
|
|
3751
3814
|
const { found, stats: _stats, ...verdict } = inf;
|
|
3752
3815
|
void _stats;
|
package/dist/core/effect.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as dsl from './dsl.js';
|
|
1
2
|
import type { Rule } from './dsl.js';
|
|
2
3
|
import { type Law, type Rand } from './machine.js';
|
|
3
4
|
import { type Source } from './extract-read.js';
|
|
@@ -41,12 +42,23 @@ export type Primitive = Prim & {
|
|
|
41
42
|
laws: Law[];
|
|
42
43
|
lemmas?: Law[];
|
|
43
44
|
};
|
|
45
|
+
export type LemmaAttempt = {
|
|
46
|
+
name: string;
|
|
47
|
+
verdict?: dsl.Verdict;
|
|
48
|
+
failure?: {
|
|
49
|
+
name: string;
|
|
50
|
+
message: string;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
44
53
|
export declare function withLemmas(x: Extraction, opts?: {
|
|
45
54
|
ms?: number;
|
|
55
|
+
work?: number;
|
|
56
|
+
watchdogMs?: number;
|
|
46
57
|
}): {
|
|
47
58
|
x: Extraction;
|
|
48
59
|
proven: string[];
|
|
49
60
|
unproven: string[];
|
|
61
|
+
attempts: LemmaAttempt[];
|
|
50
62
|
};
|
|
51
63
|
export { fiberRun } from './fiber-run.js';
|
|
52
64
|
export declare function fromSchedule(source: string, opts: {
|
package/dist/core/effect.js
CHANGED
|
@@ -18,6 +18,8 @@ import ts from 'typescript';
|
|
|
18
18
|
import * as dsl from "./dsl.js";
|
|
19
19
|
import { interpret, lcg, seeded } from "./machine.js";
|
|
20
20
|
import { allowed } from "./watch.js";
|
|
21
|
+
import { BudgetExpired, checkWorkEndpoint } from "./wall.js";
|
|
22
|
+
import { WatchdogExpired } from "./search-watchdog.js";
|
|
21
23
|
import * as I from "./extract-ir.js";
|
|
22
24
|
import { Refusal, bare as strip, beside, impure, memberName, normalize, placed, refuse, shapeOf, sourceOf, text, where } from "./extract-read.js";
|
|
23
25
|
import { readFactory, setupOf } from "./extract-shapes.js";
|
|
@@ -671,22 +673,37 @@ function modelled(code, file, entry, E, opts) {
|
|
|
671
673
|
const lemmas = prims.flatMap(p => p.lemmas ?? []);
|
|
672
674
|
return { ...x, invariants: [...x.invariants ?? [], ...prims.flatMap(p => p.invariants)], notes: [...w.notes, ...x.notes], primitives: prims, ...(lemmas.length ? { lemmas } : {}) };
|
|
673
675
|
}
|
|
674
|
-
//
|
|
675
|
-
//
|
|
676
|
-
//
|
|
677
|
-
// are left out (a lemma is no claim: the laws stated are).
|
|
676
|
+
// work and watchdogMs are PER LEMMA, like the legacy ms option, not a
|
|
677
|
+
// whole-call grant. Every child is clamped to any enclosing work/watchdog
|
|
678
|
+
// scope; callers needing a shared total can wrap this synchronous helper.
|
|
678
679
|
export function withLemmas(x, opts = {}) {
|
|
680
|
+
if (opts.work !== undefined && opts.ms !== undefined)
|
|
681
|
+
throw new RangeError('choose a work budget or a legacy ms budget, not both');
|
|
679
682
|
const lemmas = x.lemmas ?? [], inv = [...x.invariants ?? []], proven = [], unproven = [];
|
|
683
|
+
const attempts = [];
|
|
680
684
|
if (!x.rule)
|
|
681
|
-
return { x, proven, unproven };
|
|
685
|
+
return { x, proven, unproven, attempts };
|
|
682
686
|
for (const l of lemmas) {
|
|
683
|
-
let v;
|
|
687
|
+
let v, failure;
|
|
688
|
+
const proofOptions = { search: opts.work === undefined ? { ms: opts.ms ?? 30_000 } : { work: opts.work }, ...(opts.watchdogMs === undefined ? {} : { watchdogMs: opts.watchdogMs }) };
|
|
684
689
|
try {
|
|
685
|
-
v = dsl.proveRule(x.rule, [...inv, l],
|
|
690
|
+
v = dsl.proveRule(x.rule, [...inv, l], proofOptions);
|
|
686
691
|
}
|
|
687
|
-
catch {
|
|
692
|
+
catch (error) {
|
|
693
|
+
// An enclosing work owner must observe its own cancellation. A helper
|
|
694
|
+
// cannot renew that authority by treating the error as a dropped lemma.
|
|
695
|
+
if (error instanceof BudgetExpired) {
|
|
696
|
+
checkWorkEndpoint(error.phase);
|
|
697
|
+
throw error;
|
|
698
|
+
}
|
|
699
|
+
if (error instanceof WatchdogExpired)
|
|
700
|
+
throw error;
|
|
701
|
+
failure = { name: error instanceof Error ? error.name : typeof error, message: error instanceof Error ? error.message : String(error) };
|
|
688
702
|
v = undefined;
|
|
689
703
|
}
|
|
704
|
+
// Keep local optional-lemma stops separate from the eventual source-law
|
|
705
|
+
// verdict. An owned refusal is data, never an invented ancestor expiry.
|
|
706
|
+
attempts.push({ name: l.name, ...(v ? { verdict: v } : { failure }) });
|
|
690
707
|
// These are mathematical supports, not source claims. The caller's marked
|
|
691
708
|
// rule still requires native finalization; a native translation error is not admitted.
|
|
692
709
|
if (v && ((v.proven && v.checked) || (v.kernelProven === true && v.translation === 'unchecked'))) {
|
|
@@ -696,7 +713,7 @@ export function withLemmas(x, opts = {}) {
|
|
|
696
713
|
else
|
|
697
714
|
unproven.push(l.name);
|
|
698
715
|
}
|
|
699
|
-
return { x: { ...x, invariants: inv }, proven, unproven };
|
|
716
|
+
return { x: { ...x, invariants: inv }, proven, unproven, attempts };
|
|
700
717
|
}
|
|
701
718
|
// --- many fibers: a method that is several steps ---------------------------------------------------------------------
|
|
702
719
|
// A method's atomic units: the statements of its body that run an effect on the service's state (a transaction, a Ref
|