gdp-wired 0.50.3 → 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 +4 -0
- 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 +5 -0
- package/dist/core/cli.js +118 -49
- 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/cli.js
CHANGED
|
@@ -9,12 +9,20 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
9
9
|
};
|
|
10
10
|
import { fiberRun } from "./fiber-run.js";
|
|
11
11
|
import { securityTemplates } from "./security.js";
|
|
12
|
-
import { proveLeadsTo, proveRule, proveSteps } from "./dsl.js";
|
|
12
|
+
import { proveLeadsTo as rawLeadsTo, proveRule as rawRule, proveSteps as rawSteps } from "./dsl.js";
|
|
13
|
+
import { traceNow, withTraceWorkScope } from "./trace-clock.js";
|
|
13
14
|
import { terminationWhy } from "./search-termination.js";
|
|
14
15
|
import { validateWatchdog } from "./search-watchdog.js";
|
|
15
16
|
import { sourceDiagnostic } from "./source-diagnostic.js";
|
|
16
17
|
import { LawError, buildLaw, buildLeadsTo, buildTwoRuns, citesIn, isLeadsTo, isTwoRuns, lawsIn, namesWithClock } from "./laws.js";
|
|
17
|
-
import { certify, proveTwoRuns } from "./relational.js";
|
|
18
|
+
import { certify, proveTwoRuns as rawTwoRuns } from "./relational.js";
|
|
19
|
+
let syncControl;
|
|
20
|
+
const admitted = (f) => syncControl ? syncControl.invoke(f) : f();
|
|
21
|
+
const proveRule = (...a) => admitted(() => rawRule(...a));
|
|
22
|
+
const proveSteps = (...a) => admitted(() => rawSteps(...a));
|
|
23
|
+
const proveLeadsTo = (...a) => admitted(() => rawLeadsTo(...a));
|
|
24
|
+
const proveTwoRuns = (...a) => admitted(() => rawTwoRuns(...a));
|
|
25
|
+
const cliNow = () => syncControl ? traceNow() : Date.now();
|
|
18
26
|
import { contend, envOf, inEnv, shrinkRun } from "./system.js";
|
|
19
27
|
const proc = globalThis.process;
|
|
20
28
|
const fs = proc.getBuiltinModule('node:fs'), path = proc.getBuiltinModule('node:path');
|
|
@@ -105,7 +113,8 @@ async function extractOne(t, o) {
|
|
|
105
113
|
}
|
|
106
114
|
// A TypeScript file's relative imports, read beside it as TypeScript resolves them (two deep, at most 12 files), by their
|
|
107
115
|
// path from the file's directory: their classes and functions are the code's own, read and inlined, not another module's.
|
|
108
|
-
function relativeImports(entry) {
|
|
116
|
+
function relativeImports(entry, guard) {
|
|
117
|
+
guard?.(entry);
|
|
109
118
|
const out = {}, seen = new Set([entry]), queue = [[entry, 1]], dir = path.dirname(entry);
|
|
110
119
|
while (queue.length && Object.keys(out).length < 12) {
|
|
111
120
|
const [from, depth] = queue.shift();
|
|
@@ -114,6 +123,7 @@ function relativeImports(entry) {
|
|
|
114
123
|
const hit = [base, ...['.ts', '.tsx', '.js', '.jsx', '.mjs'].map(x => `${bare}${x}`), ...['/index.ts', '/index.tsx', '/index.js'].map(x => `${base}${x}`)].find(c => fs.existsSync(c) && !fs.statSync(c).isDirectory());
|
|
115
124
|
if (!hit || seen.has(hit) || Object.keys(out).length >= 12)
|
|
116
125
|
continue;
|
|
126
|
+
guard?.(hit);
|
|
117
127
|
seen.add(hit);
|
|
118
128
|
out[path.relative(dir, hit)] = fs.readFileSync(hit, 'utf8');
|
|
119
129
|
if (depth < 2)
|
|
@@ -193,6 +203,10 @@ async function extractWith(t, o) {
|
|
|
193
203
|
}
|
|
194
204
|
}
|
|
195
205
|
export function configFor(from) {
|
|
206
|
+
// Workspace initial profile deliberately has no project-config overrides/interpreters.
|
|
207
|
+
// Do not even search ancestors outside the server-authorized workspace.
|
|
208
|
+
if (syncControl)
|
|
209
|
+
return { all: {}, rules: {} };
|
|
196
210
|
// (the first of the three in a directory that holds gdp's options)
|
|
197
211
|
const holder = (d) => ['gdp.toml', 'pyproject.toml', 'package.json'].find(f => fs.existsSync(path.join(d, f)) && (f === 'gdp.toml' || (f === 'pyproject.toml' ? /^\[tool\.gdp\b/m : /"gdp"\s*:/).test(fs.readFileSync(path.join(d, f), 'utf8'))));
|
|
198
212
|
const dir = up(from, d => !!holder(d));
|
|
@@ -293,9 +307,7 @@ const searchOf = (v) => v.stopped && v.termination && !(v.proven && v.checked) &
|
|
|
293
307
|
? { stopped: true, termination: v.termination, ...(v.context ? { context: v.context } : {}) } : {};
|
|
294
308
|
const whyOf = (v, semantic) => searchOf(v).termination && v.translation !== 'unchecked' && v.translation !== 'error'
|
|
295
309
|
? terminationWhy(v.termination) : semantic;
|
|
296
|
-
|
|
297
|
-
// overload on the caller's behalf or let a successful variant hide another variant's refusal.
|
|
298
|
-
async function expandInitializers(t, o, laws, rows) {
|
|
310
|
+
function* expandInitializers(t, o, laws, rows) {
|
|
299
311
|
if (!rows.some(r => r.x.initializers))
|
|
300
312
|
return rows;
|
|
301
313
|
const { json: _j, ms: _m, propose: _p, clock: _c, cert: _t, from: _fr, env: _e, ...flags } = o;
|
|
@@ -324,27 +336,27 @@ async function expandInitializers(t, o, laws, rows) {
|
|
|
324
336
|
const opts = merge(merge({ ...shared, keep }, cfg.rules[entry] || {}), flags);
|
|
325
337
|
// A rule-specific constructor choice discovered after entry inference still takes precedence.
|
|
326
338
|
if (opts.ctor !== undefined) {
|
|
327
|
-
out.push({ entry, x:
|
|
339
|
+
out.push({ entry, x: yield { target: t, options: { ...opts, entry: variants.entry } } });
|
|
328
340
|
continue;
|
|
329
341
|
}
|
|
330
342
|
for (const ctor of [...new Set(variants.selectors)]) {
|
|
331
|
-
const x =
|
|
343
|
+
const x = yield { target: t, options: { ...opts, entry: variants.entry, ctor } };
|
|
332
344
|
x.notes.push(`initializer ${ctor}: separate scope; every initializer is required for coverage of the class`);
|
|
333
345
|
out.push({ entry, ctor, x });
|
|
334
346
|
}
|
|
335
347
|
}
|
|
336
348
|
return out;
|
|
337
349
|
}
|
|
338
|
-
|
|
339
|
-
const got =
|
|
350
|
+
function* rulesOf(t, o, laws) {
|
|
351
|
+
const got = yield* rulesOf0(t, o, laws);
|
|
340
352
|
if (o.entry)
|
|
341
|
-
return expandInitializers(t, o, laws, got);
|
|
353
|
+
return yield* expandInitializers(t, o, laws, got);
|
|
342
354
|
// (a function that is a request of a rule read, a C file's globals', is read with it)
|
|
343
355
|
const evs = (x) => { const s = x.model?.inputs?.find(v => v.name === (x.names ?? []).find(n => n.role === 'method')?.rule)?.sort; return s?.k === 'choice' ? s.values ?? [] : []; };
|
|
344
356
|
const have = new Set(got.flatMap(r => [r.entry, r.x.model?.name, r.x.initializers?.name, ...(r.x.ok ? [...(r.x.names ?? []).map(n => n.method), ...evs(r.x)] : [])].filter((n) => !!n)));
|
|
345
357
|
const more = [...new Set(laws.map(l => l.cls ?? l.fn).filter((n) => !!n && !have.has(n)))];
|
|
346
358
|
if (!more.length)
|
|
347
|
-
return expandInitializers(t, o, laws, got);
|
|
359
|
+
return yield* expandInitializers(t, o, laws, got);
|
|
348
360
|
const { json: _j, ms: _m, propose: _p, clock: _c, cert: _t, from: _fr, env: _e, ...flags } = o;
|
|
349
361
|
void _j;
|
|
350
362
|
void _m;
|
|
@@ -357,11 +369,13 @@ async function rulesOf(t, o, laws) {
|
|
|
357
369
|
void _k;
|
|
358
370
|
void _f;
|
|
359
371
|
const keep = [...new Set(laws.flatMap(l => l.expr.match(/[A-Za-z_]\w*(?:::[A-Za-z_]\w*)*/g) ?? []).flatMap(k => (k.includes('::') ? [k, ...k.split('::')] : [k])))];
|
|
360
|
-
const extra =
|
|
372
|
+
const extra = [];
|
|
373
|
+
for (const entry of more)
|
|
374
|
+
extra.push({ entry, x: yield { target: t, options: { ...merge(merge({ ...shared, keep }, cfg.rules[entry] || {}), flags), entry } } });
|
|
361
375
|
// (the first rule, read with no entry named, kept only where it read something or nothing else was)
|
|
362
|
-
return expandInitializers(t, o, laws, [...got.filter(r => r.x.ok || r.entry || !extra.length), ...extra]);
|
|
376
|
+
return yield* expandInitializers(t, o, laws, [...got.filter(r => r.x.ok || r.entry || !extra.length), ...extra]);
|
|
363
377
|
}
|
|
364
|
-
|
|
378
|
+
function* rulesOf0(t, o, laws) {
|
|
365
379
|
const { json: _j, ms: _m, propose: _p, clock: _c, cert: _t, from: _fr, env: _e, ...flags } = o;
|
|
366
380
|
void _j;
|
|
367
381
|
void _m;
|
|
@@ -378,24 +392,27 @@ async function rulesOf0(t, o, laws) {
|
|
|
378
392
|
// (the names the laws read, so an argument a law reads stays in the rule though the code ignores it)
|
|
379
393
|
const keep = [...new Set(laws.flatMap(l => l.expr.match(/[A-Za-z_]\w*(?:::[A-Za-z_]\w*)*/g) ?? []).flatMap(k => (k.includes('::') ? [k, ...k.split('::')] : [k])))];
|
|
380
394
|
const optsFor = (entry) => merge(merge({ ...shared, keep }, (entry && cfg.rules[entry]) || {}), flags);
|
|
381
|
-
const one =
|
|
382
|
-
const x =
|
|
383
|
-
|
|
395
|
+
const one = function* (entry) {
|
|
396
|
+
const x = yield { target: t, options: { ...optsFor(entry), ...(entry ? { entry } : {}) } };
|
|
397
|
+
const found = x.model?.name;
|
|
398
|
+
return !entry && found && cfg.rules[found] ? { entry: found, x: yield { target: t, options: { ...optsFor(found), entry: found } } } : { entry, x };
|
|
384
399
|
};
|
|
400
|
+
const manyOf = function* (entries) { const rows = []; for (const entry of entries)
|
|
401
|
+
rows.push(yield* one(entry)); return rows; };
|
|
385
402
|
const given = o.entry ?? cfg.all.entry;
|
|
386
403
|
if (given)
|
|
387
|
-
return [
|
|
404
|
+
return [yield* one(given)];
|
|
388
405
|
if (t.lang === 'ts' || t.lang === 'cpp') {
|
|
389
406
|
const code = t.files.map(f => fs.readFileSync(f, 'utf8')).join('\n');
|
|
390
407
|
const re = t.lang === 'cpp' ? /^\s*(?:class|struct)\s+(\w+)\s*(?::[^{]*)?\{/gm : /export\s+(?:default\s+)?(?:abstract\s+)?class\s+(\w+)|export\s+(?:const|function)\s+(\w+)/g;
|
|
391
408
|
// (C++: a class its source file defines methods of, `Alarm::detected(...) {`, declared in its header)
|
|
392
409
|
const defs = t.lang === 'cpp' ? [...code.matchAll(/^[\w:<>*&\s]*?\b(\w+)::~?\w+\s*\([^;]*?\)\s*(?:const\s*)?(?::[^{;]*)?\{/gm)].map(m => m[1]) : [];
|
|
393
410
|
const cands = [...new Set([...[...code.matchAll(re)].map(m => m[1] ?? m[2]), ...defs])];
|
|
394
|
-
const all =
|
|
411
|
+
const all = yield* manyOf(cands);
|
|
395
412
|
const good = all.filter(r => r.x.ok);
|
|
396
413
|
return good.length ? good : all.length ? all : [{ x: { ok: false, refusals: [{ where: t.at, what: 'no class or exported function to read: name the entry (--entry)' }], notes: [] } }];
|
|
397
414
|
}
|
|
398
|
-
const first =
|
|
415
|
+
const first = yield* one();
|
|
399
416
|
if (first.x.ok)
|
|
400
417
|
return [first];
|
|
401
418
|
// (refused with no entry named: the rules gdp.toml names that the code has, each with its options)
|
|
@@ -405,7 +422,7 @@ async function rulesOf0(t, o, laws) {
|
|
|
405
422
|
const many = /several (?:classes|structs) (?:write their state|written by the file's functions) \(([^)]*)\)/.exec(first.x.refusals[0]?.what ?? '')?.[1].split(', ') ?? [];
|
|
406
423
|
const fns0 = [...new Set(laws.filter(l => !l.cls && l.fn).map(l => l.fn))];
|
|
407
424
|
if (named.length)
|
|
408
|
-
return
|
|
425
|
+
return yield* manyOf([...new Set([...many, ...named, ...fns0])]);
|
|
409
426
|
// (a contract's file names its contracts: refused with none named, the refusal is the rule's)
|
|
410
427
|
if (t.lang === 'solidity')
|
|
411
428
|
return [first];
|
|
@@ -413,7 +430,7 @@ async function rulesOf0(t, o, laws) {
|
|
|
413
430
|
const what = first.x.refusals[0]?.what ?? '';
|
|
414
431
|
const several = /several (?:classes|structs) (?:write their state|written by the file's functions) \(([^)]*)\)/.exec(what)?.[1].split(', ') ?? [];
|
|
415
432
|
const fns = [...new Set(laws.filter(l => !l.cls && l.fn).map(l => l.fn))];
|
|
416
|
-
return several.length || fns.length ?
|
|
433
|
+
return several.length || fns.length ? yield* manyOf([...several, ...fns]) : [first];
|
|
417
434
|
}
|
|
418
435
|
// (a class statement's name: its keyword at the start of a line, after modifiers; never a word in a comment)
|
|
419
436
|
const classAt = (line) => {
|
|
@@ -512,9 +529,65 @@ export function scoped(file) {
|
|
|
512
529
|
return { ...l, ...(cls ? { cls } : {}), ...(fn ? { fn } : {}) };
|
|
513
530
|
});
|
|
514
531
|
}
|
|
532
|
+
// Both drivers consume the same enumeration, configuration and proof/proposal algorithm.
|
|
515
533
|
export async function checkTarget(t, o) {
|
|
534
|
+
return drivePipeline(checkPipeline(t, o));
|
|
535
|
+
}
|
|
536
|
+
async function drivePipeline(pipeline) {
|
|
537
|
+
let next = pipeline.next();
|
|
538
|
+
while (!next.done) {
|
|
539
|
+
const job = next.value;
|
|
540
|
+
if ('target' in job)
|
|
541
|
+
next = pipeline.next(await extractOne(job.target, job.options));
|
|
542
|
+
else {
|
|
543
|
+
const { withLemmas } = await import("./effect.js"), w = withLemmas(job.lemmas, { ...(job.work === undefined ? { ms: job.ms } : { work: job.work }), watchdogMs: job.watchdogMs });
|
|
544
|
+
job.output.supportAttempts = w.attempts.map(a => ({ name: a.name, ...(a.verdict ? { proven: a.verdict.proven, checked: a.verdict.checked, ...searchOf(a.verdict), ...(a.verdict.why ? { why: a.verdict.why } : {}), ...(a.verdict.translation ? { translation: a.verdict.translation } : {}), ...(a.verdict.kernelProven === undefined ? {} : { kernelProven: a.verdict.kernelProven }) } : {}), ...(a.failure ? { failure: a.failure } : {}) }));
|
|
545
|
+
job.output.notes = [...job.output.notes, ...w.proven.map(n => `lemma proven, beside every law: ${n}`), ...w.unproven.map(n => `lemma not proven (left out): ${n}`)];
|
|
546
|
+
next = pipeline.next(w.x);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return next.value;
|
|
550
|
+
}
|
|
551
|
+
// Initialization only: no source reads/extraction/proof before the caller's counted scope.
|
|
552
|
+
// Async-only Effect/XState and package-oriented front ends intentionally remain unsupported.
|
|
553
|
+
export async function prepareFileCheck() {
|
|
554
|
+
const [{ extractPython }, { extract }] = await Promise.all([import("./extract-py.js"), import("./extract.js")]);
|
|
555
|
+
return (file, root, control, guard) => {
|
|
556
|
+
if (syncControl)
|
|
557
|
+
throw new Error('nested synchronous source checks are unsupported');
|
|
558
|
+
const lang = EXT[path.extname(file)];
|
|
559
|
+
if (lang !== 'python' && lang !== 'ts')
|
|
560
|
+
throw new Error('workspace check supports Python and plain TypeScript/JavaScript files only');
|
|
561
|
+
syncControl = control;
|
|
562
|
+
try {
|
|
563
|
+
return withTraceWorkScope(() => {
|
|
564
|
+
guard(file);
|
|
565
|
+
const pipeline = checkPipeline({ lang, at: file, files: [file] }, { ms: 2000, propose: true });
|
|
566
|
+
let next = pipeline.next();
|
|
567
|
+
while (!next.done) {
|
|
568
|
+
const job = next.value;
|
|
569
|
+
if (!('target' in job))
|
|
570
|
+
throw new Error('Effect lemmas require an async-only source engine');
|
|
571
|
+
guard(job.target.at);
|
|
572
|
+
const code = fs.readFileSync(job.target.at, 'utf8');
|
|
573
|
+
if (lang === 'ts' && /(?:from\s+|import\s*\(\s*|require\s*\(\s*|import\s*)['"](?:effect|xstate)(?:[/'"])/.test(code))
|
|
574
|
+
throw new Error('Effect/XState workspace checks require an async-only source engine');
|
|
575
|
+
const options = { ...job.options, root };
|
|
576
|
+
const x = control.invoke(() => lang === 'python' ? extractPython(job.target.at, options) : extract({ code, file: job.target.at }, { ...options, files: relativeImports(job.target.at, guard) }));
|
|
577
|
+
next = pipeline.next(x);
|
|
578
|
+
}
|
|
579
|
+
guard(file);
|
|
580
|
+
return next.value;
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
finally {
|
|
584
|
+
syncControl = undefined;
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
function* checkPipeline(t, o) {
|
|
516
589
|
const laws = t.files.flatMap(scoped), cites = t.files.flatMap(f => citesIn(fs.readFileSync(f, 'utf8'), path.basename(f)));
|
|
517
|
-
const rules =
|
|
590
|
+
const rules = yield* rulesOf(t, o, laws);
|
|
518
591
|
const outs = [];
|
|
519
592
|
// (the clock's unit, for durations in a law: the language's clock, or clock = "s" | "ms" in gdp.toml or --clock)
|
|
520
593
|
const unit = o.clock ?? configFor(t.lang === 'go' || t.lang === 'rust' || fs.statSync(t.at).isDirectory() ? t.at : path.dirname(t.at)).all.clock ?? CLOCK[t.lang];
|
|
@@ -544,12 +617,8 @@ export async function checkTarget(t, o) {
|
|
|
544
617
|
continue;
|
|
545
618
|
}
|
|
546
619
|
// (an Effect service's primitives: the lemmas of their use proven first, each proven one beside every law)
|
|
547
|
-
if (x.lemmas?.length)
|
|
548
|
-
|
|
549
|
-
x = w.x;
|
|
550
|
-
r.supportAttempts = w.attempts.map(a => ({ name: a.name, ...(a.verdict ? { proven: a.verdict.proven, checked: a.verdict.checked, ...searchOf(a.verdict), ...(a.verdict.why ? { why: a.verdict.why } : {}), ...(a.verdict.translation ? { translation: a.verdict.translation } : {}), ...(a.verdict.kernelProven === undefined ? {} : { kernelProven: a.verdict.kernelProven }) } : {}), ...(a.failure ? { failure: a.failure } : {}) }));
|
|
551
|
-
r.notes = [...r.notes, ...w.proven.map(n => `lemma proven, beside every law: ${n}`), ...w.unproven.map(n => `lemma not proven (left out): ${n}`)];
|
|
552
|
-
}
|
|
620
|
+
if (x.lemmas?.length)
|
|
621
|
+
x = yield { lemmas: x, ms: Math.max(o.ms, 30_000), work: o.work, watchdogMs: o.watchdogMs, output: r };
|
|
553
622
|
const ev = x.evidence;
|
|
554
623
|
if (ev)
|
|
555
624
|
r.checked = `checked against ${'probes' in ev ? `the code: ${ev.requests} requests from the start, ${ev.fromStates} from drawn states, ${ev.probes.steps} from the prover's witnesses` : `XState's own actor: ${ev.events} events`}${ev.coverage.arms ? `, ${ev.coverage.hit} of ${ev.coverage.arms} branch arms` : ''}${'startsOutside' in ev && ev.startsOutside ? `; ${ev.startsOutside} starts whose constructor passes 2^53 - 1 left out (outside the rule's numbers: the claim is for starts within them)` : ''}`;
|
|
@@ -621,11 +690,11 @@ export async function checkTarget(t, o) {
|
|
|
621
690
|
if (o.security) {
|
|
622
691
|
// Deliberately separate from accepted policy and from heuristic proposals that hide broken guesses.
|
|
623
692
|
// Do not pass previously proven candidates as hypotheses; use the same environment/replay as stated laws.
|
|
624
|
-
const candidates = securityTemplates(x), until =
|
|
625
|
-
r.security = candidates.map(l => ({ ...(
|
|
693
|
+
const candidates = securityTemplates(x), until = cliNow() + o.ms;
|
|
694
|
+
r.security = candidates.map(l => ({ ...(cliNow() >= until
|
|
626
695
|
? { name: l.name, expr: l.expr, verdict: 'unknown', why: 'security proposal budget exhausted', ms: 0 }
|
|
627
|
-
: sys ? proveInEnv(x, l, Math.max(1, Math.min(2000, until -
|
|
628
|
-
: prove(x, l, Math.max(1, Math.min(2000, until -
|
|
696
|
+
: sys ? proveInEnv(x, l, Math.max(1, Math.min(2000, until - cliNow())), [], { ...ctx, sys, entry: name, cert: undefined })
|
|
697
|
+
: prove(x, l, Math.max(1, Math.min(2000, until - cliNow())), [], { ...ctx, entry: name, cert: undefined })),
|
|
629
698
|
securityKind: l.securityKind, review: l.review,
|
|
630
699
|
where: `${l.method ? `above ${l.method}: ` : ''}${COMMENT[t.lang]} gdp: law ${l.name}: ${l.expr}` }));
|
|
631
700
|
r.notes.push('security candidates require policy review; arbitrary requests in arbitrary order, values within the extracted types; bind identity/roles to authentication, not caller claims');
|
|
@@ -695,7 +764,7 @@ function ruleFor(x, expr) {
|
|
|
695
764
|
}
|
|
696
765
|
function prove(x0, l, ms, proven, ctx, work = ctx?.work) {
|
|
697
766
|
const x = ruleFor(x0, l.expr);
|
|
698
|
-
const t0 =
|
|
767
|
+
const t0 = cliNow(), cites = ctx?.cites.filter(c => c.law === l.name).map(c => c.text) ?? [];
|
|
699
768
|
const base = { name: l.name, expr: l.expr, ...(l.where ? { where: l.where } : {}), ...(cites.length ? { cites } : {}) };
|
|
700
769
|
const inv = x.invariants ?? [], search = { search: work === undefined ? { ms } : { work }, watchdogMs: ctx?.watchdogMs, ...(ctx?.from ? { from: ctx.from } : {}) };
|
|
701
770
|
// (whenever <from>, later <to>: proven with the rule's invariants and the laws proven so far, each helpful request fair)
|
|
@@ -716,9 +785,9 @@ function prove(x0, l, ms, proven, ctx, work = ctx?.work) {
|
|
|
716
785
|
v = proveLeadsTo(x.rule, [...inv, ...proven], lt, { ms });
|
|
717
786
|
}
|
|
718
787
|
catch (e) {
|
|
719
|
-
return { ...base, kind: 'leads to', verdict: 'unknown', why: e.message, ms:
|
|
788
|
+
return { ...base, kind: 'leads to', verdict: 'unknown', why: e.message, ms: cliNow() - t0 };
|
|
720
789
|
}
|
|
721
|
-
return { ...base, ...translationOf(v), ...searchOf(v), kind: 'leads to', verdict: v.proven && v.checked ? 'proven' : 'unknown', ...(v.proven && v.checked ? {} : { why: whyOf(v, [v.goal, v.stuck, v.why].filter(Boolean).join('; ') || 'not proven') }), ms:
|
|
790
|
+
return { ...base, ...translationOf(v), ...searchOf(v), kind: 'leads to', verdict: v.proven && v.checked ? 'proven' : 'unknown', ...(v.proven && v.checked ? {} : { why: whyOf(v, [v.goal, v.stuck, v.why].filter(Boolean).join('; ') || 'not proven') }), ms: cliNow() - t0 };
|
|
722
791
|
}
|
|
723
792
|
let b, two;
|
|
724
793
|
// (a law that can't be built is not read, with why: never the whole check aborted)
|
|
@@ -743,11 +812,11 @@ function prove(x0, l, ms, proven, ctx, work = ctx?.work) {
|
|
|
743
812
|
r = proveRule(x.rule, [...inv, b.law], { search: work === undefined ? { ms } : { work }, watchdogMs: ctx?.watchdogMs });
|
|
744
813
|
}
|
|
745
814
|
catch (e) {
|
|
746
|
-
return { ...base, kind: 'law', verdict: 'unknown', why: e.message, ms:
|
|
815
|
+
return { ...base, kind: 'law', verdict: 'unknown', why: e.message, ms: cliNow() - t0 };
|
|
747
816
|
}
|
|
748
817
|
if (r.run && r.translation !== 'unchecked' && r.translation !== 'error')
|
|
749
|
-
return { ...base, ...translationOf(r), ...searchOf(r), kind: 'law', verdict: 'broken', run: runOf(x, r.run), ms:
|
|
750
|
-
return { ...base, ...translationOf(r), ...searchOf(r), kind: 'law', verdict: r.translation === 'error' ? 'not read' : 'unknown', why: r.proven && r.checked ? `true in every state a run from the start reaches, not inductive from every state the laws allow (from = "any"): state the law it needs beside it${r.found?.laws?.length ? `: ${r.found.laws.map(f => f.text).join('; ')}` : ''}` : whyOf(r, r.why ?? r.stuck ?? 'not proven'), ...(r.found?.laws?.length ? { found: r.found.laws.map(f => f.text) } : {}), ms:
|
|
818
|
+
return { ...base, ...translationOf(r), ...searchOf(r), kind: 'law', verdict: 'broken', run: runOf(x, r.run), ms: cliNow() - t0 };
|
|
819
|
+
return { ...base, ...translationOf(r), ...searchOf(r), kind: 'law', verdict: r.translation === 'error' ? 'not read' : 'unknown', why: r.proven && r.checked ? `true in every state a run from the start reaches, not inductive from every state the laws allow (from = "any"): state the law it needs beside it${r.found?.laws?.length ? `: ${r.found.laws.map(f => f.text).join('; ')}` : ''}` : whyOf(r, r.why ?? r.stuck ?? 'not proven'), ...(r.found?.laws?.length ? { found: r.found.laws.map(f => f.text) } : {}), ms: cliNow() - t0 };
|
|
751
820
|
}
|
|
752
821
|
// (from any state: a law about states proven with the others stated beside it, as one inductive set)
|
|
753
822
|
const beside = () => (ctx?.together ?? []).filter(m => m.name !== l.name).flatMap(m => { try {
|
|
@@ -761,7 +830,7 @@ function prove(x0, l, ms, proven, ctx, work = ctx?.work) {
|
|
|
761
830
|
v = two ? proveTwoRuns(two, { ...search, invariants: [two.sides[0] === x.rule ? inv : (ctx?.others && Object.values(ctx.others).find(o => o.rule === two.sides[0])?.invariants) ?? [], inv] }) : b.kind === 'law' ? proveRule(x.rule, [...inv, ...(ctx?.from ? beside() : []), b.law], search) : proveSteps(x.rule, [...inv, ...proven], [b.law], search);
|
|
762
831
|
}
|
|
763
832
|
catch (e) {
|
|
764
|
-
return { ...base, kind, verdict: 'unknown', why: e.message, ms:
|
|
833
|
+
return { ...base, kind, verdict: 'unknown', why: e.message, ms: cliNow() - t0 };
|
|
765
834
|
}
|
|
766
835
|
// (from any state: a step that breaks the law from a state the laws allow refutes it, reachable or not; the run that
|
|
767
836
|
// reaches one from the start, where the search from the start finds it, is shown with it)
|
|
@@ -811,13 +880,13 @@ function prove(x0, l, ms, proven, ctx, work = ctx?.work) {
|
|
|
811
880
|
}
|
|
812
881
|
}
|
|
813
882
|
return { ...base, ...translationOf(v), ...searchOf(v), kind, verdict, ...(ctx?.from && verdict === 'proven' ? { from: 'any' } : {}), ...(replayed ? { replayed } : {}), ...(v.run && verdict === 'broken' ? { run: two ? pairRunOf(x, v.run, two) : runOf(x, v.run) } : {}), ...(verdict === 'unknown' || verdict === 'not read' || (verdict === 'broken' && !v.run) ? { why: whyOf(v, [v.why ?? v.stuck ?? 'not proven', ...(at.length ? [`a state the laws allow where a step breaks it, no run from the start found reaching it: ${at.join(', ')}`] : [])].join('; ')) } : {}),
|
|
814
|
-
...(v.run && !two ? { assumes: assumedOf(x, v.run) } : {}), ...(found?.length ? { found } : {}), ...(cert ? { cert } : {}), ms:
|
|
883
|
+
...(v.run && !two ? { assumes: assumedOf(x, v.run) } : {}), ...(found?.length ? { found } : {}), ...(cert ? { cert } : {}), ms: cliNow() - t0 };
|
|
815
884
|
}
|
|
816
885
|
// A law of a rule in its environment (core/system.ts's inEnv): built on the rule as the code's names read it, then
|
|
817
886
|
// lifted to every call at once; proven of the system, a run shown as the calls' steps.
|
|
818
887
|
function proveInEnv(x, l, ms, proven, ctx) {
|
|
819
888
|
const work = ctx.work;
|
|
820
|
-
const t0 =
|
|
889
|
+
const t0 = cliNow(), sys = ctx.sys, base = { name: l.name, expr: l.expr, ...(l.where ? { where: l.where } : {}) };
|
|
821
890
|
if (isLeadsTo(l.expr) || isTwoRuns(l.expr))
|
|
822
891
|
return { ...base, verdict: 'not read', why: `a ${isLeadsTo(l.expr) ? 'leads-to' : 'two-run'} law is not lifted to the environment (state it of the rule with no env)`, ms: 0 };
|
|
823
892
|
// (at most one call between a and b: a flow's mutual exclusion, its leases running out where their keys expire)
|
|
@@ -842,7 +911,7 @@ function proveInEnv(x, l, ms, proven, ctx) {
|
|
|
842
911
|
}
|
|
843
912
|
}
|
|
844
913
|
catch (e) {
|
|
845
|
-
return { ...base, kind: b.kind, verdict: 'unknown', why: e.message, ms:
|
|
914
|
+
return { ...base, kind: b.kind, verdict: 'unknown', why: e.message, ms: cliNow() - t0 };
|
|
846
915
|
}
|
|
847
916
|
// (not proven and no run: calls contending with one request, a run the search's own draws seldom make)
|
|
848
917
|
if (work === undefined && !v.stopped && !(v.proven && v.checked) && !v.run) {
|
|
@@ -854,7 +923,7 @@ function proveInEnv(x, l, ms, proven, ctx) {
|
|
|
854
923
|
if (verdict === 'proven' && b.kind === 'law')
|
|
855
924
|
proven.push(law);
|
|
856
925
|
const found = v.found?.laws?.map(f => f.text);
|
|
857
|
-
return { ...base, ...translationOf(v), ...searchOf(v), kind: b.kind, verdict, ...(v.run && verdict === 'broken' ? { run: sysRunOf(x, sys, shrinkRun(sys.rule, law, v.run)) } : {}), ...(verdict === 'unknown' || verdict === 'not read' ? { why: whyOf(v, v.why ?? v.stuck ?? 'not proven') } : {}), ...(found?.length ? { found } : {}), ms:
|
|
926
|
+
return { ...base, ...translationOf(v), ...searchOf(v), kind: b.kind, verdict, ...(v.run && verdict === 'broken' ? { run: sysRunOf(x, sys, shrinkRun(sys.rule, law, v.run)) } : {}), ...(verdict === 'unknown' || verdict === 'not read' ? { why: whyOf(v, v.why ?? v.stuck ?? 'not proven') } : {}), ...(found?.length ? { found } : {}), ms: cliNow() - t0 };
|
|
858
927
|
}
|
|
859
928
|
// A run of the system as each call's steps: a call begins with its request, reads, commits; a store's key expires.
|
|
860
929
|
function sysRunOf(x, sys, run) {
|
|
@@ -1022,11 +1091,11 @@ function propose(x, lang, o, proven, stated) {
|
|
|
1022
1091
|
add(`${codeOf(v)} never goes down`, `${codeOf(v)} >= old(${codeOf(v)})`);
|
|
1023
1092
|
add(`${codeOf(v)} never goes up`, `${codeOf(v)} <= old(${codeOf(v)})`);
|
|
1024
1093
|
}
|
|
1025
|
-
const shown = [], until =
|
|
1094
|
+
const shown = [], until = cliNow() + Math.max(5000, o.ms * 2);
|
|
1026
1095
|
let broken = 0;
|
|
1027
1096
|
const fixed = new Set();
|
|
1028
|
-
for (const c of cands.slice(0, 40)) {
|
|
1029
|
-
if (
|
|
1097
|
+
for (const c of cands.slice(0, syncControl ? Math.min(40, syncControl.candidates) : 40)) {
|
|
1098
|
+
if (cliNow() > until)
|
|
1030
1099
|
break;
|
|
1031
1100
|
const v = /^(.+) never (?:changes|goes (?:down|up))$/.exec(c.name)?.[1];
|
|
1032
1101
|
if (v && fixed.has(v))
|
|
@@ -1178,7 +1247,7 @@ async function draft(target, o) {
|
|
|
1178
1247
|
out('gdp-wired draft: --clause <text> or --clause-file <file>');
|
|
1179
1248
|
return 2;
|
|
1180
1249
|
}
|
|
1181
|
-
const t = targetsOf(target)[0], rules = await rulesOf(t, { ...o, propose: false }, []), x = rules.find(r => r.x.ok)?.x;
|
|
1250
|
+
const t = targetsOf(target)[0], rules = await drivePipeline(rulesOf(t, { ...o, propose: false }, [])), x = rules.find(r => r.x.ok)?.x;
|
|
1182
1251
|
if (!x) {
|
|
1183
1252
|
out(`gdp-wired draft: no rule read from ${target}: ${rules[0]?.x.refusals[0]?.what ?? ''}`);
|
|
1184
1253
|
return 2;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Workspace `check`
|
|
2
|
+
|
|
3
|
+
Use `check` to read laws from a trusted Python or plain TypeScript/JavaScript
|
|
4
|
+
workspace through the same engine as the CLI. The default remains data-only;
|
|
5
|
+
filesystem access requires explicit server configuration.
|
|
6
|
+
|
|
7
|
+
The native edit/check fixture exercises both Python and TypeScript through the
|
|
8
|
+
built Node MCP server: a bounded implementation is proven, a conservative edit
|
|
9
|
+
remains proven, and a bad edit is broken with a real run. These results retain
|
|
10
|
+
`translation: sampled`; they are not exhaustive native equivalence certificates.
|
|
11
|
+
|
|
12
|
+
## Server-owned authority; data-only default
|
|
13
|
+
|
|
14
|
+
`createConsultation()` and the stdio executable with no root configuration keep
|
|
15
|
+
the old data-only default. All six tools are listed; `check` returns the typed
|
|
16
|
+
`workspace-unconfigured` refusal until the server explicitly opts in:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import {createConsultation} from 'gdp-wired/agent-consult'
|
|
20
|
+
|
|
21
|
+
const session = createConsultation({workspaceRoots: ['/absolute/trusted/project']})
|
|
22
|
+
const receipt = await session.call('check', {
|
|
23
|
+
file: '/absolute/trusted/project/counter.py',
|
|
24
|
+
budget: {work: 5000000, apiCalls: 64, candidates: 2}
|
|
25
|
+
})
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
For the stdio server, the operator sets `GDP_AGENT_CONSULT_ROOTS` to a JSON array
|
|
29
|
+
of absolute directories in its startup environment. CLI arguments still cannot
|
|
30
|
+
choose roots, source modules, flags or interpreters. Root configuration is never
|
|
31
|
+
accepted in tool arguments, including nested `options`, `root`, `roots`, `python`
|
|
32
|
+
or `workspaceRoots`. The existing five tools remain data-only.
|
|
33
|
+
|
|
34
|
+
The server canonicalizes/freezes at most16 roots once. Requests must name absolute
|
|
35
|
+
local regular files (no URLs, directories, devices, relative paths or `..`).
|
|
36
|
+
Containment uses `path.relative`, not a string prefix. Both root and file symlinks
|
|
37
|
+
are realpathed; out-of-root results and sibling-prefix paths are refused. Source
|
|
38
|
+
reads used by the guard use a no-follow/nonblocking read-only FD and fstat; each
|
|
39
|
+
file is capped at128KiB. Root dev/inode and file identity/content are rechecked
|
|
40
|
+
before/after the pipeline; source and relative TS dependency hashes bind the
|
|
41
|
+
returned revision. Replacements or edits observed during a check refuse rather
|
|
42
|
+
than silently bind another revision.
|
|
43
|
+
|
|
44
|
+
**Not an OS sandbox:** the configured root is a trust grant to execute the existing
|
|
45
|
+
extractor/runtime/project code. Python may import dependencies; TypeScript native
|
|
46
|
+
replay may execute code. Those runtimes can read dependencies and access resources
|
|
47
|
+
outside the root with the worker's OS permissions. No claim of transitive import
|
|
48
|
+
confinement, hostile-code containment, or atomic filesystem snapshots is made.
|
|
49
|
+
An adversarial process can race mutable files between rechecks. Use a stable,
|
|
50
|
+
trusted checkout and externally enforced OS isolation for untrusted code. Cancellation
|
|
51
|
+
joins the direct worker; this is not a descendant-process sandbox/reaper guarantee.
|
|
52
|
+
No arbitrary shell launcher is added; only the installed fixed-path worker runs.
|
|
53
|
+
|
|
54
|
+
## Shared engine, explicit initial scope
|
|
55
|
+
|
|
56
|
+
`packages/cli/bin.js` delegates to `core/cli.ts`. The latter now has one generator
|
|
57
|
+
pipeline for entry enumeration, initializer expansion, laws, proof/replay and
|
|
58
|
+
proposals. Ordinary CLI calls drive it asynchronously; workspace check preloads
|
|
59
|
+
Python/plainTS extractor modules as initialization and then drives that **same**
|
|
60
|
+
pipeline synchronously inside the counted root. No copied extraction/proof engine
|
|
61
|
+
and no `withBudget(Promise)`.
|
|
62
|
+
|
|
63
|
+
Supported initially: Python and plain TypeScript/JavaScript (`.py`, `.ts`, `.mts`,
|
|
64
|
+
`.tsx`, `.js`, `.mjs`). Effect/XState, async lemma expansion and other CLI language
|
|
65
|
+
frontends are explicitly refused. The initial workspace profile does **not** read
|
|
66
|
+
project GDP configuration: no ancestor search, no config-specified interpreters,
|
|
67
|
+
root overrides, certificate writes or CLI switches. Ordinary CLI defaults/config
|
|
68
|
+
behavior remain unchanged. Rules needing config receive the extractor's refusal
|
|
69
|
+
or unknown rather than substituted modeling choices.
|
|
70
|
+
|
|
71
|
+
The returned `result.rules` is the existing structured CLI `RuleOut[]`: stated
|
|
72
|
+
laws, refusal reasons, replayed runs where available, and proposals with paste-ready
|
|
73
|
+
language comments in `where`. `proven` requires a nonempty stated law set all
|
|
74
|
+
reported proven by that engine; `broken` requires a stated broken law with a real
|
|
75
|
+
run; otherwise the aggregate is `unknown` with a reason. Each rule/law retains its
|
|
76
|
+
own detailed verdict. `check` does not populate the scalar-model `status` registry.
|
|
77
|
+
|
|
78
|
+
**Evidence boundary:** a model-only result with `translation: unchecked` remains
|
|
79
|
+
unknown even when `kernelProven: true`. When the existing engine supplies a native
|
|
80
|
+
law journal, its `sampled` or `exhaustive` profile and observation count are retained.
|
|
81
|
+
The current Python/TypeScript demo uses sampled journals. A checked symbolic proof
|
|
82
|
+
plus sampled native observations does not establish universal source equivalence.
|
|
83
|
+
This adapter neither upgrades unchecked results nor invents counterexample runs.
|
|
84
|
+
|
|
85
|
+
## Budget coverage
|
|
86
|
+
|
|
87
|
+
One `withBudget` root and sticky capacity-refusal boundary surround synchronous
|
|
88
|
+
extraction, law parsing, proofs, replay, proposals, source receipt construction and
|
|
89
|
+
serialization validation. Each extraction and top-level proof/step/liveness/two-run
|
|
90
|
+
API call is admitted against `apiCalls`. API exhaustion is also sticky, so existing
|
|
91
|
+
CLI catch-and-return-unknown handlers cannot turn exhaustion into a successful
|
|
92
|
+
partial proof receipt. Proposal candidates are finite and capped by the request
|
|
93
|
+
hint (at most40); CLI wall-clock stops/telemetry are disabled only for this counted
|
|
94
|
+
synchronous path. Ordinary CLI wall behavior is unchanged.
|
|
95
|
+
|
|
96
|
+
Exact work/counter deltas and profile identity are retained. Counted work means
|
|
97
|
+
**existing engine sinks**, not CPU instructions: module initialization, filesystem
|
|
98
|
+
bytes/identity/hash operations, unmetered frontend parsing, external interpreter
|
|
99
|
+
runtime and project execution are not charged to the work vector. Source-byte and
|
|
100
|
+
API caps are separate controls. These exclusions are explicit in every source
|
|
101
|
+
budget receipt; external runtime is not misrepresented as counted work.
|
|
102
|
+
|
|
103
|
+
## Development checks
|
|
104
|
+
|
|
105
|
+
After normal dependency preparation, run these checks in the project's test environment:
|
|
106
|
+
|
|
107
|
+
1. `bunx tsc -p core/agent-consult/tsconfig.json --noEmit`
|
|
108
|
+
2. `GDP_WORK_FULL=1 bun test core/agent-consult/workspace.test.ts core/agent-consult.test.ts research/agent-tools/protocol.test.ts research/agent-tools/service.test.ts`
|
|
109
|
+
3. The existing CLI, budget ownership, watchdog and package regression suites.
|
|
110
|
+
4. `bun scripts/build.ts`
|
|
111
|
+
5. `node scripts/agent-consult-workspace-demo.mjs > "$SUPERCOMPUTER_OUTPUT_DIR/workspace-check-transcript.jsonl"`
|
|
112
|
+
|
|
113
|
+
The last command creates temporary Python and TS files, initializes/lists the
|
|
114
|
+
built Node MCP server, edits each through good/good-edit/bad versions, and logs
|
|
115
|
+
actual edit/request/response/observation JSONL. It requires successful extraction,
|
|
116
|
+
changing source revisions, sampled native-law observations for the good edits,
|
|
117
|
+
and real runs for the bad edits. The server must close cleanly after stdin EOF.
|
|
118
|
+
The workspace suite is also registered in the default CI test roster.
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# Agent consultation: MCP and library
|
|
2
|
+
|
|
3
|
+
The supported adapter asks the **existing** gdp-wired engines whether a scalar-natural
|
|
4
|
+
model law has a checked proof, a reachable counterexample, or a missing inductive
|
|
5
|
+
invariant. It adds no inference/proof algorithm. This is a package integration, not
|
|
6
|
+
a new proof capability or a native/source-conformance certification. The counted
|
|
7
|
+
work profile is still provisional research machinery. Do not use `ok: true` alone
|
|
8
|
+
as a proof: require each relevant `proven === true && checked === true`.
|
|
9
|
+
|
|
10
|
+
## Start and configure
|
|
11
|
+
|
|
12
|
+
After installing a version of `gdp-wired` containing this surface (this change does
|
|
13
|
+
not publish one), run `gdp-wired-agent-consult`. Node >=20 is sufficient; no Bun,
|
|
14
|
+
MCP SDK, credentials, network service or model provider is needed for the data-only tools.
|
|
15
|
+
Opt-in workspace extraction additionally needs TypeScript beside the package and the
|
|
16
|
+
source language runtime (Python for `.py`), exactly as the CLI does. In a source checkout the equivalent is
|
|
17
|
+
`bun core/agent-consult/cli.ts`; build with the repository's normal build before
|
|
18
|
+
running `node dist/core/agent-consult/cli.js`.
|
|
19
|
+
|
|
20
|
+
Generic MCP client configuration (configure your client explicitly; nothing is
|
|
21
|
+
registered automatically):
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"mcpServers": {
|
|
26
|
+
"gdp-wired": {
|
|
27
|
+
"command": "/absolute/path/to/node",
|
|
28
|
+
"args": ["/absolute/path/to/node_modules/gdp-wired/dist/core/agent-consult/cli.js"]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Use an explicitly installed/pinned package; avoid an unpinned runtime download.
|
|
35
|
+
The CLI accepts **no arguments**, roots, modules, file paths or source code. It
|
|
36
|
+
reads newline-delimited JSON-RPC 2.0 MCP (protocol `2024-11-05`) on stdin; stdout is
|
|
37
|
+
protocol JSON only. `initialize`, `ping`, `tools/list`, `tools/call` are supported.
|
|
38
|
+
Results include both `structuredContent` and equivalent JSON text for older clients.
|
|
39
|
+
No HTTP transport, resources, prompts, dynamic roots or persistent database is provided.
|
|
40
|
+
The server name is now `gdp-wired-agent-consult` (formerly the research prototype's
|
|
41
|
+
`gdp-wired-agent-tools-prototype`). The original five tools and their v1 schemas
|
|
42
|
+
are preserved; the additional `check` tool has an explicit workspace trust boundary.
|
|
43
|
+
|
|
44
|
+
Workspace checking is a separate server-authorized opt-in: see
|
|
45
|
+
[workspace check trust/budget contract and native demo](agent-consult-workspace-check.md).
|
|
46
|
+
With no configured roots, `check` refuses and the original data-only default remains.
|
|
47
|
+
|
|
48
|
+
## Agent reasoning loop
|
|
49
|
+
|
|
50
|
+
1. Translate the rule and law faithfully to **data**, never a module to execute.
|
|
51
|
+
[examples/agent-consult.json](../examples/agent-consult.json) is a complete
|
|
52
|
+
`tools/call` request for a capped budget. Read `tools/list` for recursive schemas.
|
|
53
|
+
2. `prove {subject,laws,budget?}` returns per-law checked inductive verdicts.
|
|
54
|
+
A failed induction step can be an unreachable state: it is not a real bug yet.
|
|
55
|
+
3. `why_not {subject,laws,budget?}` asks existing finite search for a reachable,
|
|
56
|
+
interpreter-checked trace. Original parameter/input/state names are preserved.
|
|
57
|
+
No trace **does not** establish a law. Trace minimality is length-first only
|
|
58
|
+
inside the reported finite domain, not global minimality.
|
|
59
|
+
4. If no real trace explains the failed proof, use
|
|
60
|
+
`suggest {subject,laws,nearMisses?,budget?}`. Existing `inferLaws` proposes helper
|
|
61
|
+
invariants; only jointly checked support sets are returned as `discovered`.
|
|
62
|
+
Keep `supportSource` with the goal; do not paste a helper while dropping the
|
|
63
|
+
laws that support it. A missing invariant is not inferred from silence alone.
|
|
64
|
+
`nearMisses` are caller-supplied candidates, not generated language-model laws;
|
|
65
|
+
a returned near miss includes a real trace. `unresolvedNearMisses` are unknown.
|
|
66
|
+
5. `check_change {before,after,laws,budget?}` rechecks the same laws on revisions
|
|
67
|
+
with identical unit, parameter, input and state names. `newlyBroken` requires
|
|
68
|
+
an old checked proof plus a new reachable trace. `lostProof` is separate.
|
|
69
|
+
Behaviour comparison is **directional refinement under the after rule's
|
|
70
|
+
precondition**, using existing compose and both invariant/admissibility checks;
|
|
71
|
+
it is not bidirectional/source equivalence.
|
|
72
|
+
6. `status {unit,revision}` uses the digest returned by a computational request.
|
|
73
|
+
It never accepts labels supplied by a caller, substitutes another revision,
|
|
74
|
+
or invents native evidence. Only `prove`/`check_change` populate its registry.
|
|
75
|
+
`nativeLabel` is null. Unknown/evicted revisions return `missing-evidence`.
|
|
76
|
+
|
|
77
|
+
A `subject` is `{unit,rule}`. Rule data includes `name`, `params`, `inputs`,
|
|
78
|
+
initial `state`, `step.state`, optional `pre` and `assume`; laws are `{name,holds}`.
|
|
79
|
+
Terms: `var`, `const`, `add`, **truncated natural `sub`**, `min`, `max`, constant
|
|
80
|
+
`mul`, `if`. Conditions: `<`, `<=`, `=`, `and`, `or`, `not`. Signed values, maps,
|
|
81
|
+
functions, quantification, callbacks, source, modules, paths and URLs are refused by
|
|
82
|
+
the five data-only tools, not approximated. `check` alone accepts a local file path. Outputs include `assumptions`: exact initial/pre/request data
|
|
83
|
+
and laws bound into the revision. Retain those alongside proofs and suggestions.
|
|
84
|
+
A model proof does not assert the shipping program matches that model.
|
|
85
|
+
|
|
86
|
+
## Library
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import {createConsultation} from 'gdp-wired/agent-consult'
|
|
90
|
+
const session = createConsultation()
|
|
91
|
+
try {
|
|
92
|
+
const receipt = await session.call('prove', {subject, laws, budget: {work: 500000}})
|
|
93
|
+
// Inspect receipt; only checked proof pairs establish model laws.
|
|
94
|
+
const explained = await session.call('why_not', {subject, laws})
|
|
95
|
+
} finally {
|
|
96
|
+
await session.close()
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`call(tool,args,{signal?})` returns the structured data envelope.
|
|
101
|
+
`handle(jsonRpcRequest,{signal?})` returns a JSON-RPC response (or null for a
|
|
102
|
+
notification). Both serialize work per session. No engine is imported into the
|
|
103
|
+
host: each computational request uses a fresh installed worker with a fixed path
|
|
104
|
+
and sanitized environment. Status is session-local, bounded to256 revisions
|
|
105
|
+
(oldest entries evicted); a new session has no evidence. Importing the subpath
|
|
106
|
+
starts no server, worker, signal handler or stdin listener.
|
|
107
|
+
|
|
108
|
+
`AbortSignal` cancels library requests; `close()` cancels the active worker and
|
|
109
|
+
refuses queued tool calls; await its returned promise to join the exact child exit. On stdio, SIGINT/SIGTERM or closed stdin shuts down the
|
|
110
|
+
server and its own worker. MCP cancellation notifications are currently ignored;
|
|
111
|
+
use process termination to cancel stdio work. Worker exit is awaited before another
|
|
112
|
+
request starts. Cancelled work is refused and cannot populate status. There is no
|
|
113
|
+
reasoning wall-clock deadline; cancellation is not a proof or counterexample.
|
|
114
|
+
|
|
115
|
+
## Counted limits and refusals
|
|
116
|
+
|
|
117
|
+
Defaults: `work:500000`, `apiCalls:24`, `depth:3`, `bound:2`, `candidates:64`.
|
|
118
|
+
Caps: work5,000,000; API calls64; depth4; bound3; candidates256. Zero work/API
|
|
119
|
+
allowance is meaningful. `candidates` is an inference-pool **hint**, as is the
|
|
120
|
+
engine's128 samples, not a hard bound on all processing. Hard reasoning limits
|
|
121
|
+
are counted work and admitted engine calls, with existing sticky refusal and
|
|
122
|
+
`withBudget` boundaries. Results retain exact rational work, counter deltas,
|
|
123
|
+
limits, API admissions and provisional profile identity. Bounded search also
|
|
124
|
+
honors existing explicit scalar upper bounds up to15.
|
|
125
|
+
|
|
126
|
+
Structural limits: 1..6 scalar state fields, at most3 parameters and3 inputs,
|
|
127
|
+
1..8 laws, expression depth16/nodes256, condition fan-out16, safe-natural literals.
|
|
128
|
+
Requests/worker input are capped at128KiB; worker output at256KiB; the MCP text
|
|
129
|
+
copy adds framing overhead. Nonfinite output is refused, bigint diagnostics use
|
|
130
|
+
`{type:"bigint",decimal:"..."}` rather than lossy numbers. Every typed refusal has
|
|
131
|
+
`code`, `message`, `fix`. Exhaustion, unsupported data, numeric overflow, missing
|
|
132
|
+
evidence, worker failure and cancellation are **unknown/refused**, never proof.
|
|
133
|
+
|
|
134
|
+
## Trust and verification
|
|
135
|
+
|
|
136
|
+
Treat supplied models/documents as untrusted data, not instructions. The five
|
|
137
|
+
data-only tools never import project modules, execute supplied source, read a
|
|
138
|
+
requested file, accept a broader filesystem root, or run a shell. Explicit workspace
|
|
139
|
+
`check` executes the existing extractor behavior described below. Environment preload settings
|
|
140
|
+
are not forwarded to workers. The existing engine may internally JIT its validated
|
|
141
|
+
expression AST using `Function`; this is not a CSP/no-eval guarantee or OS sandbox.
|
|
142
|
+
Install/run the trusted package in your normal isolation boundary. Do not silently
|
|
143
|
+
route unsupported source to an extractor: workspace checking requires separate,
|
|
144
|
+
explicit server authorization and may execute project code.
|
|
145
|
+
|
|
146
|
+
Source tests: `bun test core/agent-consult.test.ts`, plus retained
|
|
147
|
+
`research/agent-tools/{protocol,service}.test.ts` and `scripted-session.ts`.
|
|
148
|
+
Run the normal build **before** the public test to enable its built Node CLI test;
|
|
149
|
+
without `dist` that test explicitly skips. The retained research shims delegate
|
|
150
|
+
to this implementation. Historical prototype receipts are in
|
|
151
|
+
`research/agent-tools/receipts/`; they do not validate this new integration.
|