gestalt-mobile 0.60.2 → 0.61.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -2
- package/dist/server/server/composition.contracts.js +155 -6
- package/dist/server/server/composition.js +69 -16
- package/dist/server/server/features/autopilot/application/policy.js +3 -3
- package/dist/server/server/features/autopilot/application/service.js +25 -2
- package/dist/server/server/features/autopilot/application/supervision-snapshot.js +165 -0
- package/dist/server/server/features/autopilot/domain/supervision-protocol.js +15 -0
- package/dist/server/server/features/control-plane-trace/export-trace.js +1 -0
- package/dist/server/server/features/host-tests/application/handle-tool.js +24 -0
- package/dist/server/server/features/plans/application/parse-model-policy.js +4 -4
- package/dist/server/server/features/plans/domain/model-policy-admission.js +14 -12
- package/dist/server/server/features/plans/domain/supervised-plan.js +4 -0
- package/dist/server/server/platform/codex/session-runtime.js +4 -6
- package/dist/server/server/platform/host-tests/runner.js +27 -0
- package/dist/server/shared/contracts/host-tests.js +20 -2
- package/dist/server/shared/contracts/org-plan-health.js +28 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -67,6 +67,10 @@ Expand **Advanced settings** to change model thinking, the Org-plan executor mod
|
|
|
67
67
|
and thinking, provider, sandbox, or approval policy, or to manage skill profiles.
|
|
68
68
|
The executor starts with `gpt-5.6-terra` and high thinking; the supervisor uses medium thinking.
|
|
69
69
|
Executor overrides preserve the installed role instructions and belong to each new session.
|
|
70
|
+
These settings are launch defaults, not a mandatory L1 model. The Org supervisor's
|
|
71
|
+
explicit runtime-supported model/effort choice wins; conflicting fixed roles use
|
|
72
|
+
the default-agent override route with executor duties. Follow-ups without an L1
|
|
73
|
+
policy preserve the existing child's settings instead of repinning defaults.
|
|
70
74
|
**Save as defaults** stores the
|
|
71
75
|
current session settings in `~/.gestalt/session-defaults.json` on the relay host.
|
|
72
76
|
New browser visits load those settings; Advanced settings starts collapsed.
|
|
@@ -106,17 +110,21 @@ Version-1 plans separate requested model choices from assurance. Existing plans
|
|
|
106
110
|
without `#+MODEL_POLICY_ASSURANCE` use disclosed **configured compatibility**;
|
|
107
111
|
their policy metadata and file bytes need no migration. An explicit
|
|
108
112
|
`#+MODEL_POLICY_ASSURANCE: configured` selects the same mode. Mobile validates
|
|
109
|
-
|
|
113
|
+
bounded model/effort identifiers and any optional detailed effort rationale, checks the active runtime
|
|
110
114
|
catalog before versioned root dispatch, and directs the root to launch the exact
|
|
111
115
|
L1 model/effort through supported overrides with inherited sandbox and approval
|
|
112
116
|
policy. Automatic executor resumes use that L1 policy rather than session defaults.
|
|
117
|
+
The supervisor may revise each L1 choice without a separate model/effort approval.
|
|
118
|
+
After pausing an active writer and recording/resyncing the revised policy,
|
|
119
|
+
Mobile validates support and applies it to the same child's next safe turn.
|
|
120
|
+
Unavailable model/effort pairs fail explicitly; defaults never replace them silently.
|
|
113
121
|
|
|
114
122
|
`#+MODEL_POLICY_ASSURANCE: runtime-attested` explicitly requires strict runtime
|
|
115
123
|
receipts. The current adapter cannot supply runtime-issued settings revisions;
|
|
116
124
|
strict plans fail with `RUNTIME_ATTESTATION_UNAVAILABLE` and remain strict until
|
|
117
125
|
the user authorizes a change. Repeated approvals or attention resolution cannot
|
|
118
126
|
provide that capability. Manual Off is independently respected. Legacy plans
|
|
119
|
-
without model policy
|
|
127
|
+
without model policy preserve their executor's existing settings on follow-up.
|
|
120
128
|
|
|
121
129
|
`gestalt_org_plan_health` reports `executionAdmission.allowed`, configured
|
|
122
130
|
assurance and `executorLaunch`, which checks the requested L1 model/effort using
|
|
@@ -388,6 +388,138 @@ async function createUnauthorizedProductionApp(root, dataDir) {
|
|
|
388
388
|
}
|
|
389
389
|
describe('production composition', () => {
|
|
390
390
|
describeCompositionConcern('autopilot', () => {
|
|
391
|
+
it('serves compact supervision deltas and wakes only for the selected host run', async () => {
|
|
392
|
+
let coordinator;
|
|
393
|
+
const f = await createProductionAutopilotFixture({
|
|
394
|
+
autopilotSchedule: () => () => { },
|
|
395
|
+
onAutopilotCoordinator: (value) => {
|
|
396
|
+
coordinator = value;
|
|
397
|
+
},
|
|
398
|
+
});
|
|
399
|
+
onTestFinished(() => f.app.close());
|
|
400
|
+
const exec = promisify(execFile);
|
|
401
|
+
await exec('git', ['init', '-q', f.workspacePath]);
|
|
402
|
+
await exec('git', [
|
|
403
|
+
'-c',
|
|
404
|
+
'user.name=Fixture',
|
|
405
|
+
'-c',
|
|
406
|
+
'user.email=fixture@example.invalid',
|
|
407
|
+
'commit',
|
|
408
|
+
'--allow-empty',
|
|
409
|
+
'-qm',
|
|
410
|
+
'fixture',
|
|
411
|
+
], { cwd: f.workspacePath });
|
|
412
|
+
const marker = join(f.dataDir, 'release-test');
|
|
413
|
+
await mkdir(join(f.workspacePath, '.gestalt'), { recursive: true });
|
|
414
|
+
await writeFile(join(f.workspacePath, '.gestalt/host-tests.json'), JSON.stringify({
|
|
415
|
+
version: 1,
|
|
416
|
+
suites: [
|
|
417
|
+
{
|
|
418
|
+
id: 'controlled',
|
|
419
|
+
repository: f.workspacePath,
|
|
420
|
+
command: process.execPath,
|
|
421
|
+
args: [
|
|
422
|
+
'-e',
|
|
423
|
+
"setInterval(()=>{if(require('node:fs').existsSync(process.argv[1]))process.exit(0)},20)",
|
|
424
|
+
marker,
|
|
425
|
+
],
|
|
426
|
+
timeoutMs: 10_000,
|
|
427
|
+
maxOutputBytes: 4096,
|
|
428
|
+
},
|
|
429
|
+
],
|
|
430
|
+
}));
|
|
431
|
+
expect((await f.app.inject({
|
|
432
|
+
method: 'POST',
|
|
433
|
+
url: `/api/sessions/${f.sessionId}/turns`,
|
|
434
|
+
payload: { text: 'Synthetic run wait fixture' },
|
|
435
|
+
})).statusCode).toBe(202);
|
|
436
|
+
const session = (await f.app.inject(`/api/sessions/${f.sessionId}`)).json();
|
|
437
|
+
const handle = f.handles.find((value) => value.calls.includes('turn/start'));
|
|
438
|
+
let requestId = 5000;
|
|
439
|
+
const call = async (tool, args) => {
|
|
440
|
+
const response = (await handle.request({
|
|
441
|
+
id: ++requestId,
|
|
442
|
+
method: 'item/tool/call',
|
|
443
|
+
params: {
|
|
444
|
+
threadId: session.threadId,
|
|
445
|
+
turnId: session.activeTurnId,
|
|
446
|
+
tool,
|
|
447
|
+
arguments: args,
|
|
448
|
+
},
|
|
449
|
+
}));
|
|
450
|
+
return JSON.parse(response.contentItems[0].text);
|
|
451
|
+
};
|
|
452
|
+
const initial = await call('gestalt_org_plan_health', { view: 'compact' });
|
|
453
|
+
expect(initial.snapshot).toMatchObject({
|
|
454
|
+
plan: { l1: { id: 'parent' } },
|
|
455
|
+
tests: { running: 0, unread: 0 },
|
|
456
|
+
control: { enabled: true },
|
|
457
|
+
});
|
|
458
|
+
expect(Buffer.byteLength(JSON.stringify(initial))).toBeLessThan(2500);
|
|
459
|
+
const unchanged = await call('gestalt_org_plan_health', {
|
|
460
|
+
view: 'compact',
|
|
461
|
+
sinceRevision: initial.revision,
|
|
462
|
+
});
|
|
463
|
+
expect(unchanged).toEqual({ revision: initial.revision, unchanged: true });
|
|
464
|
+
expect(Buffer.byteLength(JSON.stringify(unchanged))).toBeLessThan(120);
|
|
465
|
+
expect(await call('gestalt_org_plan_health', {})).toMatchObject({
|
|
466
|
+
enabled: true,
|
|
467
|
+
health: expect.any(Object),
|
|
468
|
+
});
|
|
469
|
+
const run = await call('gestalt_test_runner', {
|
|
470
|
+
operation: 'start',
|
|
471
|
+
suite: 'controlled',
|
|
472
|
+
requestId: '00000000-0000-4000-8000-000000000002',
|
|
473
|
+
});
|
|
474
|
+
expect(run.state).toBe('running');
|
|
475
|
+
const changed = await call('gestalt_org_plan_health', {
|
|
476
|
+
view: 'compact',
|
|
477
|
+
sinceRevision: initial.revision,
|
|
478
|
+
});
|
|
479
|
+
expect(changed.changes.tests).toMatchObject({
|
|
480
|
+
running: 1,
|
|
481
|
+
runs: [{ runId: run.runId, state: 'running' }],
|
|
482
|
+
});
|
|
483
|
+
expect(changed.snapshot).toBeUndefined();
|
|
484
|
+
expect(await call('gestalt_test_runner', {
|
|
485
|
+
operation: 'wait',
|
|
486
|
+
runId: run.runId,
|
|
487
|
+
maxWaitMs: 60_000,
|
|
488
|
+
})).toEqual({ accepted: true, runId: run.runId });
|
|
489
|
+
// A retried request must not register another lease or reset its deadline.
|
|
490
|
+
expect(await call('gestalt_test_runner', {
|
|
491
|
+
operation: 'wait',
|
|
492
|
+
runId: run.runId,
|
|
493
|
+
maxWaitMs: 60_000,
|
|
494
|
+
})).toEqual({ accepted: true, runId: run.runId });
|
|
495
|
+
expect(coordinator.rootProcessCompleted(f.sessionId, 'another-run')).toBe(false);
|
|
496
|
+
expect(coordinator.semanticEvent(f.sessionId, 'processResultAvailable')).toBe(false);
|
|
497
|
+
const parked = await call('gestalt_org_plan_health', {
|
|
498
|
+
view: 'compact',
|
|
499
|
+
sinceRevision: changed.revision,
|
|
500
|
+
});
|
|
501
|
+
expect(parked.changes.wait).toMatchObject({ runId: run.runId });
|
|
502
|
+
const database = new DatabaseSync(join(f.dataDir, 'relay.sqlite'));
|
|
503
|
+
onTestFinished(() => database.close());
|
|
504
|
+
const count = (type) => database
|
|
505
|
+
.prepare('SELECT COUNT(*) AS count FROM session_events WHERE session_id=? AND type=?')
|
|
506
|
+
.get(f.sessionId, type)?.count;
|
|
507
|
+
expect(count('autopilot.wait-registered')).toBe(1);
|
|
508
|
+
expect(count('autopilot.wait-woken')).toBe(0);
|
|
509
|
+
await writeFile(marker, 'done');
|
|
510
|
+
await vi.waitFor(() => expect(count('autopilot.wait-woken')).toBe(1), { timeout: 5000 });
|
|
511
|
+
expect(await call('gestalt_test_runner', { operation: 'wait', runId: run.runId })).toMatchObject({
|
|
512
|
+
accepted: false,
|
|
513
|
+
reason: 'runCompleted',
|
|
514
|
+
next: 'continueSameTurn',
|
|
515
|
+
result: { state: 'passed', exitCode: 0 },
|
|
516
|
+
});
|
|
517
|
+
expect(await call('gestalt_test_runner', {
|
|
518
|
+
operation: 'wait',
|
|
519
|
+
runId: '00000000-0000-4000-8000-000000000099',
|
|
520
|
+
})).toEqual({ error: 'runNotFound' });
|
|
521
|
+
expect(count('autopilot.wait-woken')).toBe(1);
|
|
522
|
+
});
|
|
391
523
|
it('does not park after a host test completes before process-wait registration', async () => {
|
|
392
524
|
let coordinator;
|
|
393
525
|
const f = await createProductionAutopilotFixture({
|
|
@@ -784,6 +916,8 @@ describe('production composition', () => {
|
|
|
784
916
|
it.each([
|
|
785
917
|
'match',
|
|
786
918
|
'mismatch',
|
|
919
|
+
'supervisor-terra',
|
|
920
|
+
'unsupported-terra-effort',
|
|
787
921
|
'off-during-read',
|
|
788
922
|
'policy-during-read',
|
|
789
923
|
'same-plan-during-read',
|
|
@@ -830,7 +964,11 @@ describe('production composition', () => {
|
|
|
830
964
|
timer.cancelled = true;
|
|
831
965
|
};
|
|
832
966
|
},
|
|
833
|
-
},
|
|
967
|
+
}, ['supervisor-terra', 'unsupported-terra-effort'].includes(scenario)
|
|
968
|
+
? versionedText()
|
|
969
|
+
.replace(':MODEL: gpt-6.1-sol', ':MODEL: gpt-6.1-terra')
|
|
970
|
+
.replace(':REASONING_EFFORT: medium', ':REASONING_EFFORT: high')
|
|
971
|
+
: versionedText());
|
|
834
972
|
onTestFinished(() => f.app.close());
|
|
835
973
|
const actualRootThreadId = (await f.app.inject(`/api/sessions/${f.sessionId}`)).json()
|
|
836
974
|
.threadId;
|
|
@@ -848,7 +986,18 @@ describe('production composition', () => {
|
|
|
848
986
|
for (const handle of f.handles)
|
|
849
987
|
handle.respond = async (method, params) => {
|
|
850
988
|
if (method === 'model/list')
|
|
851
|
-
return
|
|
989
|
+
return ['supervisor-terra', 'unsupported-terra-effort'].includes(scenario)
|
|
990
|
+
? {
|
|
991
|
+
data: [
|
|
992
|
+
{
|
|
993
|
+
id: 'gpt-6.1-terra',
|
|
994
|
+
supportedReasoningEfforts: [
|
|
995
|
+
{ reasoningEffort: scenario === 'supervisor-terra' ? 'high' : 'medium' },
|
|
996
|
+
],
|
|
997
|
+
},
|
|
998
|
+
],
|
|
999
|
+
}
|
|
1000
|
+
: policyCatalog;
|
|
852
1001
|
if (method === 'thread/read' && params.threadId === 'child-1') {
|
|
853
1002
|
sawRead = true;
|
|
854
1003
|
if (['off-during-read', 'policy-during-read', 'same-plan-during-read'].includes(scenario))
|
|
@@ -920,15 +1069,15 @@ describe('production composition', () => {
|
|
|
920
1069
|
}
|
|
921
1070
|
pendingRead.resolve({});
|
|
922
1071
|
pendingRecovery.resolve({});
|
|
923
|
-
if (
|
|
1072
|
+
if (['match', 'mismatch', 'supervisor-terra', 'same-plan-during-read'].includes(scenario)) {
|
|
924
1073
|
await vi.waitFor(() => expect(childStarts).toBe(1));
|
|
925
1074
|
const call = f.handles
|
|
926
1075
|
.flatMap((handle) => handle.requests)
|
|
927
1076
|
.find((call) => call.method === 'turn/start');
|
|
928
1077
|
expect(call?.params).toMatchObject({
|
|
929
1078
|
threadId: 'child-1',
|
|
930
|
-
model: 'gpt-6.1-sol',
|
|
931
|
-
effort: 'medium',
|
|
1079
|
+
model: scenario === 'supervisor-terra' ? 'gpt-6.1-terra' : 'gpt-6.1-sol',
|
|
1080
|
+
effort: scenario === 'supervisor-terra' ? 'high' : 'medium',
|
|
932
1081
|
});
|
|
933
1082
|
}
|
|
934
1083
|
else {
|
|
@@ -3581,7 +3730,7 @@ describe('production composition', () => {
|
|
|
3581
3730
|
// rejected child continuation; it must never target the dead child.
|
|
3582
3731
|
expect((starts[3]?.params).threadId).not.toBe('child-1');
|
|
3583
3732
|
expect((starts[3]?.params).input?.[0]?.text).toContain('Launch task_name l1_g2 for canonical L1');
|
|
3584
|
-
expect((starts[3]?.params).input?.[0]?.text).toContain('
|
|
3733
|
+
expect((starts[3]?.params).input?.[0]?.text).toContain('The supervisor chooses the exact runtime-supported model');
|
|
3585
3734
|
// Capacity recovery is allowed only for the active root control. It
|
|
3586
3735
|
// recycles that writer but must retain the one durable g2 handoff.
|
|
3587
3736
|
const rootHandle = fixture.handles.find((candidate) => candidate.requests.some((request) => request.method === 'turn/start' &&
|
|
@@ -93,7 +93,8 @@ import { createRelyingPartyConfig } from './config.js';
|
|
|
93
93
|
import { parseOrgPlanAttention, parseOrgPlanAttentionToolResponse, toOrgPlanAttentionAcknowledgement, } from '../shared/contracts/org-plan-attention.js';
|
|
94
94
|
import { autopilotWaitLeaseToolResponse, } from '../shared/contracts/autopilot-wait-lease.js';
|
|
95
95
|
import { agentCapacityRecoveryToolResponse } from '../shared/contracts/agent-capacity-recovery.js';
|
|
96
|
-
import { isOrgPlanHealthCall } from '../shared/contracts/org-plan-health.js';
|
|
96
|
+
import { isOrgPlanHealthCall, parseOrgPlanHealthArguments, } from '../shared/contracts/org-plan-health.js';
|
|
97
|
+
import { compactSupervisionSnapshot, SupervisionSnapshots, } from './features/autopilot/application/supervision-snapshot.js';
|
|
97
98
|
import { ExecutorModelEvidenceReader } from './features/plans/application/executor-model-evidence.js';
|
|
98
99
|
import { ExecutorLaunchValidationReader } from './features/plans/application/executor-launch-validation.js';
|
|
99
100
|
import { requireModelPolicyAdmission } from './features/plans/domain/model-policy-admission.js';
|
|
@@ -114,6 +115,7 @@ export async function composeRelayApp(options) {
|
|
|
114
115
|
throw new Error('Authorization randomness must return exactly 32 bytes');
|
|
115
116
|
const root = resolve(options.root);
|
|
116
117
|
let hostTests;
|
|
118
|
+
const supervisionSnapshots = new SupervisionSnapshots();
|
|
117
119
|
const databasePath = options.dataDir
|
|
118
120
|
? join(resolve(options.dataDir), 'relay.sqlite')
|
|
119
121
|
: resolveStateDatabasePath(root, process.env.XDG_STATE_HOME ?? join(homedir(), '.local', 'state'));
|
|
@@ -264,6 +266,7 @@ export async function composeRelayApp(options) {
|
|
|
264
266
|
});
|
|
265
267
|
const autopilot = new AutopilotCoordinator({
|
|
266
268
|
pendingProcessResult: (sessionId) => hostTests?.hasUnreadResult(sessionId) ?? false,
|
|
269
|
+
processResultState: (sessionId, runId) => hostTests?.resultState(sessionId, runId) ?? 'missing',
|
|
267
270
|
modelPolicyStatus: (sessionId) => supervisedPlans.modelPolicyStatus(sessionId),
|
|
268
271
|
store: autopilotStore,
|
|
269
272
|
now: () => new Date().toISOString(),
|
|
@@ -953,6 +956,26 @@ export async function composeRelayApp(options) {
|
|
|
953
956
|
workspace: session.workspacePath,
|
|
954
957
|
root: origin?.kind === 'root',
|
|
955
958
|
provider: session.provider,
|
|
959
|
+
waitForRun: (runId, maxWaitMs) => {
|
|
960
|
+
const current = sessions.find(sessionId);
|
|
961
|
+
if (origin?.kind !== 'root' ||
|
|
962
|
+
!current?.activeTurnId ||
|
|
963
|
+
origin.physicalTurnId !== current.activeTurnId)
|
|
964
|
+
return false;
|
|
965
|
+
const state = autopilotStore.find(sessionId);
|
|
966
|
+
if (!state?.requestedEnabled)
|
|
967
|
+
return false;
|
|
968
|
+
const leaseId = `host-test:${runId}:${current.activeTurnId}`;
|
|
969
|
+
if (state.supervision?.waitLease?.id === leaseId)
|
|
970
|
+
return true;
|
|
971
|
+
return autopilot.registerProactiveWait(sessionId, {
|
|
972
|
+
id: leaseId,
|
|
973
|
+
leaseId,
|
|
974
|
+
runId,
|
|
975
|
+
maxWaitMs,
|
|
976
|
+
wakeConditions: ['processResultAvailable'],
|
|
977
|
+
});
|
|
978
|
+
},
|
|
956
979
|
}, toolCall.arguments);
|
|
957
980
|
return (runtime?.resolveServerRequest(sessionId, String(request.id), {
|
|
958
981
|
success: true,
|
|
@@ -1004,26 +1027,51 @@ export async function composeRelayApp(options) {
|
|
|
1004
1027
|
};
|
|
1005
1028
|
}
|
|
1006
1029
|
}
|
|
1007
|
-
const modelPolicy = await
|
|
1008
|
-
|
|
1030
|
+
const [modelPolicy, executorLaunch] = await Promise.all([
|
|
1031
|
+
executorModelEvidence.read(sessionId),
|
|
1032
|
+
executorLaunchValidation.read(sessionId),
|
|
1033
|
+
]);
|
|
1009
1034
|
const snapshot = autopilot.snapshot(sessionId);
|
|
1035
|
+
const args = parseOrgPlanHealthArguments(toolCall?.arguments);
|
|
1036
|
+
const healthReport = args.view === 'compact'
|
|
1037
|
+
? supervisionSnapshots.read(sessionId, compactSupervisionSnapshot({
|
|
1038
|
+
autopilot: snapshot,
|
|
1039
|
+
plan: supervisedPlans.find(sessionId),
|
|
1040
|
+
planIdentity: supervisedPlans.identity(sessionId),
|
|
1041
|
+
activity: activity.snapshot(sessionId, new Date().toISOString()),
|
|
1042
|
+
pendingInteractions: blockingInteractions(sessionId).length,
|
|
1043
|
+
tests: hostTests?.supervisionSummary(sessionId) ?? {
|
|
1044
|
+
enabled: false,
|
|
1045
|
+
running: 0,
|
|
1046
|
+
unread: 0,
|
|
1047
|
+
omitted: 0,
|
|
1048
|
+
runs: [],
|
|
1049
|
+
},
|
|
1050
|
+
wait: autopilotStore.find(sessionId)?.supervision?.waitLease ?? null,
|
|
1051
|
+
binding: executorBinding
|
|
1052
|
+
? { status: executorBinding.status, code: executorBinding.code }
|
|
1053
|
+
: null,
|
|
1054
|
+
modelPolicy,
|
|
1055
|
+
launch: executorLaunch,
|
|
1056
|
+
}), args.sinceRevision)
|
|
1057
|
+
: {
|
|
1058
|
+
state: snapshot.state,
|
|
1059
|
+
enabled: snapshot.enabled,
|
|
1060
|
+
health: snapshot.health,
|
|
1061
|
+
reason: snapshot.reason,
|
|
1062
|
+
...(snapshot.executionAdmission
|
|
1063
|
+
? { executionAdmission: snapshot.executionAdmission }
|
|
1064
|
+
: {}),
|
|
1065
|
+
...(modelPolicy ? { modelPolicy } : {}),
|
|
1066
|
+
...(executorLaunch ? { executorLaunch } : {}),
|
|
1067
|
+
...(executorBinding ? { executorBinding } : {}),
|
|
1068
|
+
};
|
|
1010
1069
|
return (runtime?.resolveServerRequest(sessionId, String(request.id), {
|
|
1011
1070
|
success: true,
|
|
1012
1071
|
contentItems: [
|
|
1013
1072
|
{
|
|
1014
1073
|
type: 'inputText',
|
|
1015
|
-
text: JSON.stringify(
|
|
1016
|
-
state: snapshot.state,
|
|
1017
|
-
enabled: snapshot.enabled,
|
|
1018
|
-
health: snapshot.health,
|
|
1019
|
-
reason: snapshot.reason,
|
|
1020
|
-
...(snapshot.executionAdmission
|
|
1021
|
-
? { executionAdmission: snapshot.executionAdmission }
|
|
1022
|
-
: {}),
|
|
1023
|
-
...(modelPolicy ? { modelPolicy } : {}),
|
|
1024
|
-
...(executorLaunch ? { executorLaunch } : {}),
|
|
1025
|
-
...(executorBinding ? { executorBinding } : {}),
|
|
1026
|
-
}),
|
|
1074
|
+
text: JSON.stringify(healthReport),
|
|
1027
1075
|
},
|
|
1028
1076
|
],
|
|
1029
1077
|
}) === true);
|
|
@@ -1228,9 +1276,10 @@ export async function composeRelayApp(options) {
|
|
|
1228
1276
|
assertCurrent();
|
|
1229
1277
|
const report = await executorModelEvidence.read(sessionId);
|
|
1230
1278
|
assertCurrent();
|
|
1279
|
+
const settingsChange = report && ['MODEL_MISMATCH', 'EFFORT_MISMATCH'].includes(report.code);
|
|
1231
1280
|
if (!report ||
|
|
1232
1281
|
report.child.threadId !== threadId ||
|
|
1233
|
-
report.configuration === 'mismatch' ||
|
|
1282
|
+
(report.configuration === 'mismatch' && !settingsChange) ||
|
|
1234
1283
|
[
|
|
1235
1284
|
'CONTROLLER_BINDING_INVALID',
|
|
1236
1285
|
'CONTEXT_CHANGED',
|
|
@@ -1238,6 +1287,10 @@ export async function composeRelayApp(options) {
|
|
|
1238
1287
|
'OBSERVATION_CHANGED',
|
|
1239
1288
|
].includes(report.code))
|
|
1240
1289
|
throw new Error(`EXECUTOR_POLICY_BLOCKED:${report?.code ?? 'CHILD_BINDING_UNKNOWN'}`);
|
|
1290
|
+
// The supervisor's current L1 choice is applied at this safe turn
|
|
1291
|
+
// boundary, including a deliberate change from the child's old model.
|
|
1292
|
+
await runtime.validateExecutorPolicy(sessionId, report.requested);
|
|
1293
|
+
assertCurrent();
|
|
1241
1294
|
return { ...report.requested, assertCurrent };
|
|
1242
1295
|
})
|
|
1243
1296
|
: null;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { currentExecutableL1Index, } from '../../plans/domain/supervised-plan.js';
|
|
7
7
|
import { parseOrgPlanAgentIdentity } from '../../../../shared/org-plan-position.js';
|
|
8
|
-
export const AUTOPILOT_PROMPT_VERSION = '
|
|
8
|
+
export const AUTOPILOT_PROMPT_VERSION = 'v14';
|
|
9
9
|
export const AUTOPILOT_CONTINUATION_PROMPT = 'Inspect the active supervised Org Plan. Refer to every L1 as L<a> and each nested L2 as L<a>.<b>, using one-based positions. Spawn exactly one executor per L1 and pass the exact literal task_name l<a>: l1 for L1, l2 for L2, and so on. Never create an L2-specific task name or append a title, role, nickname, plan name, or generated label. A validated DONE L2 and an accepted L1 are mandatory answer boundaries. The corresponding gestalt_org_plan_checkpoint call must be the last tool call of that root turn: immediately emit exactly one boundary final and end the turn, without followup_task, review, executor launch, or later milestone work. An accepted L1 always ends the root turn with a chat answer: never continue into the next L1 or emit post-acceptance documentation as commentary. Roll up commentary, files, verification, and commands since the previous boundary into that one answer; all later milestone activity belongs to a new root turn. On this later Autopilot turn, resume the same executor after an L2 boundary or launch exactly one fresh canonical executor for the next L1 after an accepted-L1 boundary. Treat a status question as an interruption: answer briefly, then perform the applicable continuation in the same turn. Before sending any blocker response or yielding because progress cannot continue safely, call gestalt_org_plan_attention for the matching decision-table blocker; never rely on blocker prose as the signal. When explicit human permission is required for a physical executor replacement, include executorReplacement with the exact canonicalTaskName; Mobile alone computes and persists the physical generation. Do not call attention for routine progress or a recoverable failure. Before yielding for known long work, call gestalt_autopilot_wait_lease version 2 with relevant observable wake conditions and a bounded maxWaitMs; it is one episode, so reassess before registering another in a later turn. Yield only when its response contains accepted:true; accepted:false means no continuation was registered and requires same-turn supervision. For GitHub PR CI, start an owned gh pr checks --watch process and lease processExited plus processResultAvailable while it runs. Timestamp watcher state-change and terminal observations in UTC; distinguish observation time from upstream updated_at and process exit time. When the Autopilot probe is active, register the compatible wait lease, declare genuine attention, or immediately do actionable work; never acknowledge waiting in prose. Do not send a status-only response.';
|
|
10
10
|
export const AUTOPILOT_EXECUTOR_CONTINUATION_PROMPT = 'Continue the same assigned Org L1 from its durable state. A prior turn ending did not complete the objective. Consume any supplied process result and take the next legal L2 action. Whenever an L2 reaches DONE, return its concise structured evidence and end the executor turn so the root can publish that mandatory answer boundary. Also report at the L1 review boundary or through structured attention.';
|
|
11
11
|
/** Builds a physical launch instruction while keeping durable L1 identity canonical. */
|
|
@@ -13,10 +13,10 @@ export function autopilotExecutorLaunchPrompt(identity, plan) {
|
|
|
13
13
|
const policy = plan?.steps.find((_, index) => `L${index + 1}` === identity.canonicalPosition)?.modelPolicy;
|
|
14
14
|
const launch = policy
|
|
15
15
|
? `Launch task_name ${identity.taskName} for canonical ${identity.canonicalPosition}, preferring agent_type default, fork_turns none, explicit model ${policy.model} and reasoning_effort ${policy.reasoningEffort}. If explicit overrides are unavailable, use the verified fixed org-plan-executor role only when both pins exactly match ${policy.model}/${policy.reasoningEffort}, omitting ineffective overrides. Load the executor duties and full L1 assignment from the Org-plan launch contract. Validate actual host support and sandbox/approval inheritance before spawning; unsupported routes are capability blockers. Assurance is configured compatibility: unavailable runtime metadata remains unknown and does not require repeated human approval. Reject observed settings mismatches; never call requested settings observed or runtime-enforced. Preserve one writer, independent review, checkpoint and terminal review gates.`
|
|
16
|
-
: `Launch task_name ${identity.taskName} for canonical ${identity.canonicalPosition}
|
|
16
|
+
: `Launch task_name ${identity.taskName} for canonical ${identity.canonicalPosition}. The supervisor chooses the exact runtime-supported model and reasoning effort for this L1. For an explicit choice use agent_type default, fork_turns none, explicit model and reasoning_effort, and supply the executor duties and full assignment. The configured org-plan-executor role is a fallback only when no L1 choice is supplied; omit ineffective overrides on a fixed role. Retain canonical identity, permissions and review gates.`;
|
|
17
17
|
if (identity.generation === 1)
|
|
18
18
|
return `${AUTOPILOT_CONTINUATION_PROMPT} ${launch}`;
|
|
19
|
-
return `${AUTOPILOT_CONTINUATION_PROMPT} ${launch} This exact replacement generation ${identity.generation} is durably authorized by Mobile; do not infer another generation from this prompt or the roster; the durable ${identity.canonicalTaskName} slot may remain reserved. Do not reuse that task_name or
|
|
19
|
+
return `${AUTOPILOT_CONTINUATION_PROMPT} ${launch} This exact replacement generation ${identity.generation} is durably authorized by Mobile; do not infer another generation from this prompt or the roster; the durable ${identity.canonicalTaskName} slot may remain reserved. Do not reuse that task_name or treat a model change as replacement authorization. Apply updated model/effort only at a safe turn boundary. Interrupt the previous physical executor if it is still running, then spawn the authorized ${identity.taskName}. Transfer sole ${identity.canonicalPosition} ownership and continue from its durable Org Plan and worktree state.`;
|
|
20
20
|
}
|
|
21
21
|
export const defaultAutopilotPolicy = Object.freeze({
|
|
22
22
|
quiescenceMs: 1_000,
|
|
@@ -274,6 +274,11 @@ export class AutopilotCoordinator {
|
|
|
274
274
|
});
|
|
275
275
|
if (state.supervision.waitLease && validated.health.wait.wakeCategories.length > 0) {
|
|
276
276
|
this.parkedSubscriptions.set(sessionId, state.supervision.waitLease.id);
|
|
277
|
+
const runId = state.supervision.waitLease.runId;
|
|
278
|
+
if (runId && this.deps.processResultState?.(sessionId, runId) === 'completed') {
|
|
279
|
+
this.rootProcessCompleted(sessionId, runId);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
277
282
|
if (state.supervision.waitLease.resumeAt)
|
|
278
283
|
this.armWaitDeadline(sessionId, state.supervision.waitLease.id, state.supervision.waitLease.resumeAt);
|
|
279
284
|
return;
|
|
@@ -362,7 +367,15 @@ export class AutopilotCoordinator {
|
|
|
362
367
|
report.maxWaitMs > AUTOPILOT_WAIT_MAX_MS)
|
|
363
368
|
return false;
|
|
364
369
|
const now = this.deps.now();
|
|
365
|
-
const
|
|
370
|
+
const runState = report.runId
|
|
371
|
+
? this.deps.processResultState?.(sessionId, report.runId)
|
|
372
|
+
: undefined;
|
|
373
|
+
if (report.runId &&
|
|
374
|
+
(!runState ||
|
|
375
|
+
runState === 'missing' ||
|
|
376
|
+
!report.wakeConditions.some((condition) => ['processExited', 'processResultAvailable'].includes(condition))))
|
|
377
|
+
return false;
|
|
378
|
+
const processWakeSatisfied = report.wakeConditions.some((condition) => ['processExited', 'processResultAvailable'].includes(condition)) && (report.runId ? runState === 'completed' : this.deps.pendingProcessResult?.(sessionId));
|
|
366
379
|
if (processWakeSatisfied ||
|
|
367
380
|
this.executorWakeAlreadySatisfied(sessionId, state, report.wakeConditions)) {
|
|
368
381
|
// The requested edge is already visible. Fence every pending automatic
|
|
@@ -483,6 +496,9 @@ export class AutopilotCoordinator {
|
|
|
483
496
|
},
|
|
484
497
|
}),
|
|
485
498
|
leaseId: wake.leaseId,
|
|
499
|
+
...(state.supervision.waitLease?.runId
|
|
500
|
+
? { runId: state.supervision.waitLease.runId }
|
|
501
|
+
: {}),
|
|
486
502
|
reportId: state.supervision.lastReportId,
|
|
487
503
|
wakeCondition: wake.condition,
|
|
488
504
|
resumeAt: state.supervision.waitLease?.resumeAt ?? null,
|
|
@@ -543,7 +559,12 @@ export class AutopilotCoordinator {
|
|
|
543
559
|
const progressKey = createHash('sha256')
|
|
544
560
|
.update(`${this.progressKey(sessionId)}\0root-process\0${processId}`)
|
|
545
561
|
.digest('hex');
|
|
546
|
-
return this.observableWake(sessionId, {
|
|
562
|
+
return this.observableWake(sessionId, {
|
|
563
|
+
leaseId: lease.id,
|
|
564
|
+
condition,
|
|
565
|
+
progressKey,
|
|
566
|
+
runId: processId,
|
|
567
|
+
});
|
|
547
568
|
}
|
|
548
569
|
enable(sessionId) {
|
|
549
570
|
const session = this.deps.session(sessionId);
|
|
@@ -1620,6 +1641,7 @@ export class AutopilotCoordinator {
|
|
|
1620
1641
|
payload: {
|
|
1621
1642
|
...this.wakeAttribution(next),
|
|
1622
1643
|
leaseId: nextLease.id,
|
|
1644
|
+
...(nextLease.runId ? { runId: nextLease.runId } : {}),
|
|
1623
1645
|
reportId: next.supervision?.lastReportId,
|
|
1624
1646
|
resumeAt: nextLease.resumeAt ?? null,
|
|
1625
1647
|
wakeConditions: nextLease.wakeConditions,
|
|
@@ -1892,6 +1914,7 @@ export class AutopilotCoordinator {
|
|
|
1892
1914
|
...this.wakeAttribution(state),
|
|
1893
1915
|
wakeReason: 'deadline',
|
|
1894
1916
|
leaseId,
|
|
1917
|
+
...(lease.runId ? { runId: lease.runId } : {}),
|
|
1895
1918
|
reportId: state.supervision.lastReportId,
|
|
1896
1919
|
resumeAt,
|
|
1897
1920
|
observedAt,
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2026 Dyne.org foundation
|
|
3
|
+
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
|
+
*/
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { currentExecutableL1Index } from '../../plans/domain/supervised-plan.js';
|
|
8
|
+
import { executionComplete } from './policy.js';
|
|
9
|
+
const id = (value) => (value && value.length <= 128 ? value : null);
|
|
10
|
+
function planRevision(plan) {
|
|
11
|
+
const step = (value) => ({
|
|
12
|
+
id: value.id,
|
|
13
|
+
title: value.title,
|
|
14
|
+
state: value.state,
|
|
15
|
+
priority: value.priority,
|
|
16
|
+
reviewStatus: value.reviewStatus,
|
|
17
|
+
skills: value.skills,
|
|
18
|
+
description: value.description,
|
|
19
|
+
modelPolicy: value.modelPolicy,
|
|
20
|
+
children: value.children.map(step),
|
|
21
|
+
});
|
|
22
|
+
return createHash('sha256')
|
|
23
|
+
.update(JSON.stringify({
|
|
24
|
+
title: plan.title,
|
|
25
|
+
subtitle: plan.subtitle,
|
|
26
|
+
date: plan.date,
|
|
27
|
+
keywords: plan.keywords,
|
|
28
|
+
modelPolicyVersion: plan.modelPolicyVersion,
|
|
29
|
+
modelPolicyAssurance: plan.modelPolicyAssurance,
|
|
30
|
+
steps: plan.steps.map(step),
|
|
31
|
+
}))
|
|
32
|
+
.digest('hex');
|
|
33
|
+
}
|
|
34
|
+
/** No prose, command history, observation clocks or source paths enter the compact read model. */
|
|
35
|
+
export function compactSupervisionSnapshot(input) {
|
|
36
|
+
const { autopilot: a, activity, modelPolicy: m, launch: l } = input;
|
|
37
|
+
const parent = input.plan?.steps[currentExecutableL1Index(input.plan)];
|
|
38
|
+
const barrier = input.plan?.steps.find((step) => step.state === 'SUSPENDED');
|
|
39
|
+
const child = parent?.children.find((step) => step.id === input.plan?.currentStepId || step.state === 'WIP');
|
|
40
|
+
const priority = (agent) => (agent.threadId ?? agent.id) === a.executor?.threadId
|
|
41
|
+
? 0
|
|
42
|
+
: ['working', 'awaitingAgent', 'awaitingHuman', 'blocked'].includes(agent.state)
|
|
43
|
+
? 1
|
|
44
|
+
: 2;
|
|
45
|
+
const agents = [...activity.subagents].sort((left, right) => priority(left) - priority(right) || left.id.localeCompare(right.id));
|
|
46
|
+
const admission = a.executionAdmission;
|
|
47
|
+
return {
|
|
48
|
+
control: {
|
|
49
|
+
state: a.state,
|
|
50
|
+
enabled: a.enabled,
|
|
51
|
+
healthy: a.health.healthy,
|
|
52
|
+
phase: a.health.phase,
|
|
53
|
+
supervision: a.health.supervision,
|
|
54
|
+
reason: a.reason ?? null,
|
|
55
|
+
next: a.health.nextExpectedAction,
|
|
56
|
+
pendingInteractions: input.pendingInteractions,
|
|
57
|
+
},
|
|
58
|
+
plan: input.plan
|
|
59
|
+
? {
|
|
60
|
+
identity: id(input.planIdentity),
|
|
61
|
+
revision: planRevision(input.plan),
|
|
62
|
+
currentStepId: id(input.plan.currentStepId),
|
|
63
|
+
l1: parent
|
|
64
|
+
? { id: id(parent.id), state: parent.state, review: parent.reviewStatus ?? null }
|
|
65
|
+
: null,
|
|
66
|
+
l2: child ? { id: id(child.id), state: child.state } : null,
|
|
67
|
+
barrier: barrier ? { id: id(barrier.id), state: barrier.state } : null,
|
|
68
|
+
done: input.plan.doneSteps,
|
|
69
|
+
total: input.plan.totalSteps,
|
|
70
|
+
complete: executionComplete(input.plan),
|
|
71
|
+
}
|
|
72
|
+
: null,
|
|
73
|
+
executor: a.executor
|
|
74
|
+
? {
|
|
75
|
+
threadId: id(a.executor.threadId),
|
|
76
|
+
position: id(a.executor.canonicalPosition),
|
|
77
|
+
generation: a.executor.continuationGeneration,
|
|
78
|
+
outcome: a.executor.outcome,
|
|
79
|
+
}
|
|
80
|
+
: null,
|
|
81
|
+
activity: {
|
|
82
|
+
confidence: activity.confidence,
|
|
83
|
+
root: activity.root.state,
|
|
84
|
+
aggregate: activity.aggregateSubagents,
|
|
85
|
+
total: agents.length,
|
|
86
|
+
agents: agents.slice(0, 8).map((agent) => ({
|
|
87
|
+
id: id(agent.id),
|
|
88
|
+
threadId: id(agent.threadId),
|
|
89
|
+
position: id(agent.canonicalPosition),
|
|
90
|
+
state: agent.state,
|
|
91
|
+
reason: agent.reason,
|
|
92
|
+
})),
|
|
93
|
+
omitted: Math.max(0, agents.length - 8),
|
|
94
|
+
},
|
|
95
|
+
admission: admission
|
|
96
|
+
? admission.allowed
|
|
97
|
+
? {
|
|
98
|
+
allowed: true,
|
|
99
|
+
scope: admission.scope,
|
|
100
|
+
runtimeEnforcement: admission.scope === 'configured' ? false : null,
|
|
101
|
+
}
|
|
102
|
+
: { allowed: false, code: admission.code, reason: admission.reason }
|
|
103
|
+
: null,
|
|
104
|
+
binding: input.binding,
|
|
105
|
+
modelPolicy: m
|
|
106
|
+
? {
|
|
107
|
+
code: m.code,
|
|
108
|
+
configuration: m.configuration,
|
|
109
|
+
requested: m.requested,
|
|
110
|
+
effective: m.effective,
|
|
111
|
+
assurance: m.assurance,
|
|
112
|
+
attested: m.attested,
|
|
113
|
+
runtimeEnforcement: m.runtimeEnforcement,
|
|
114
|
+
}
|
|
115
|
+
: null,
|
|
116
|
+
launch: l
|
|
117
|
+
? {
|
|
118
|
+
code: l.code,
|
|
119
|
+
requested: l.requested,
|
|
120
|
+
validated: l.validated,
|
|
121
|
+
assurance: l.assurance,
|
|
122
|
+
runtimeEnforcement: l.runtimeEnforcement,
|
|
123
|
+
}
|
|
124
|
+
: null,
|
|
125
|
+
tests: input.tests,
|
|
126
|
+
wait: input.wait
|
|
127
|
+
? {
|
|
128
|
+
leaseId: id(input.wait.id),
|
|
129
|
+
runId: input.wait.runId ?? null,
|
|
130
|
+
resumeAt: input.wait.resumeAt ?? null,
|
|
131
|
+
conditions: input.wait.wakeConditions,
|
|
132
|
+
}
|
|
133
|
+
: null,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/** Bounded session-scoped history. A cache miss returns a full view, never a guessed delta. */
|
|
137
|
+
export class SupervisionSnapshots {
|
|
138
|
+
sessions = new Map();
|
|
139
|
+
read(sessionId, snapshot, sinceRevision) {
|
|
140
|
+
const stable = structuredClone(snapshot);
|
|
141
|
+
const revision = createHash('sha256')
|
|
142
|
+
.update(sessionId)
|
|
143
|
+
.update('\0')
|
|
144
|
+
.update(JSON.stringify(stable))
|
|
145
|
+
.digest('hex');
|
|
146
|
+
const history = this.sessions.get(sessionId) ?? new Map();
|
|
147
|
+
const previous = sinceRevision ? history.get(sinceRevision) : undefined;
|
|
148
|
+
history.set(revision, stable);
|
|
149
|
+
while (history.size > 8)
|
|
150
|
+
history.delete(history.keys().next().value);
|
|
151
|
+
this.sessions.set(sessionId, history);
|
|
152
|
+
while (this.sessions.size > 128)
|
|
153
|
+
this.sessions.delete(this.sessions.keys().next().value);
|
|
154
|
+
if (sinceRevision === revision)
|
|
155
|
+
return { revision, unchanged: true };
|
|
156
|
+
if (previous)
|
|
157
|
+
return {
|
|
158
|
+
revision,
|
|
159
|
+
unchanged: false,
|
|
160
|
+
changes: Object.fromEntries(Object.entries(stable).filter(([key, value]) => JSON.stringify(value) !==
|
|
161
|
+
JSON.stringify(previous[key]))),
|
|
162
|
+
};
|
|
163
|
+
return { revision, unchanged: false, reset: Boolean(sinceRevision), snapshot: stable };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -171,12 +171,15 @@ export function registerProactiveWait(state, report) {
|
|
|
171
171
|
const wakeConditions = uniqueSupportedWakeConditions(report.wakeConditions);
|
|
172
172
|
if (!report.leaseId || wakeConditions.length === 0)
|
|
173
173
|
return state;
|
|
174
|
+
if (report.runId !== undefined && !validRunWait(report.runId, wakeConditions))
|
|
175
|
+
return state;
|
|
174
176
|
return {
|
|
175
177
|
...state,
|
|
176
178
|
outcome: 'parked',
|
|
177
179
|
lastReportId: report.id,
|
|
178
180
|
waitLease: {
|
|
179
181
|
id: report.leaseId,
|
|
182
|
+
...(report.runId ? { runId: report.runId } : {}),
|
|
180
183
|
probeKey: state.progressKey,
|
|
181
184
|
wakeConditions,
|
|
182
185
|
resumeAt: report.resumeAt,
|
|
@@ -213,6 +216,9 @@ export function consumeObservableWake(state, wake) {
|
|
|
213
216
|
!lease ||
|
|
214
217
|
wake.leaseId !== lease.id ||
|
|
215
218
|
!lease.wakeConditions.includes(wake.condition) ||
|
|
219
|
+
(lease.runId &&
|
|
220
|
+
['processExited', 'processResultAvailable'].includes(wake.condition) &&
|
|
221
|
+
wake.runId !== lease.runId) ||
|
|
216
222
|
wake.progressKey === lease.probeKey)
|
|
217
223
|
return state;
|
|
218
224
|
if (lease.resumeAt)
|
|
@@ -374,6 +380,9 @@ function parseWaitLease(value) {
|
|
|
374
380
|
if (wakeConditions.length !== candidate.wakeConditions.length)
|
|
375
381
|
return undefined;
|
|
376
382
|
const resumeAt = candidate.resumeAt;
|
|
383
|
+
const runId = candidate.runId;
|
|
384
|
+
if (runId !== undefined && (!validRunWait(runId, wakeConditions) || resumeAt === undefined))
|
|
385
|
+
return undefined;
|
|
377
386
|
if (resumeAt !== undefined &&
|
|
378
387
|
(typeof resumeAt !== 'string' || !Number.isFinite(Date.parse(resumeAt))))
|
|
379
388
|
return undefined;
|
|
@@ -382,5 +391,11 @@ function parseWaitLease(value) {
|
|
|
382
391
|
probeKey: candidate.probeKey,
|
|
383
392
|
wakeConditions,
|
|
384
393
|
...(typeof resumeAt === 'string' ? { resumeAt } : {}),
|
|
394
|
+
...(typeof runId === 'string' ? { runId } : {}),
|
|
385
395
|
};
|
|
386
396
|
}
|
|
397
|
+
function validRunWait(runId, conditions) {
|
|
398
|
+
return (typeof runId === 'string' &&
|
|
399
|
+
/^[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i.test(runId) &&
|
|
400
|
+
conditions.some((condition) => ['processExited', 'processResultAvailable'].includes(condition)));
|
|
401
|
+
}
|
|
@@ -11,6 +11,7 @@ const statusTypes = ['autopilot.updated', 'agent.activity.updated', 'session.sta
|
|
|
11
11
|
// Export structural telemetry only. Event types alone do not imply payload safety.
|
|
12
12
|
const diagnosticFields = new Set([
|
|
13
13
|
'leaseId',
|
|
14
|
+
'runId',
|
|
14
15
|
'reportId',
|
|
15
16
|
'resumeAt',
|
|
16
17
|
'wakeCondition',
|
|
@@ -14,6 +14,30 @@ export async function handleHostTestTool(runner, context, args) {
|
|
|
14
14
|
if (!runner)
|
|
15
15
|
return { error: 'hostTestRunnerDisabled' };
|
|
16
16
|
try {
|
|
17
|
+
if (parsed.data.operation === 'wait') {
|
|
18
|
+
const { runId, maxWaitMs } = parsed.data;
|
|
19
|
+
const owner = { sessionId: context.sessionId, workspace: context.workspace };
|
|
20
|
+
const read = () => runner.request(owner, { operation: 'status', runId });
|
|
21
|
+
let result = await read();
|
|
22
|
+
if ('error' in result)
|
|
23
|
+
return result;
|
|
24
|
+
const registration = result.state === 'running'
|
|
25
|
+
? context.waitForRun?.(runId, maxWaitMs)
|
|
26
|
+
: 'wakeAlreadySatisfied';
|
|
27
|
+
if (registration === true)
|
|
28
|
+
return { accepted: true, runId };
|
|
29
|
+
if (registration === 'wakeAlreadySatisfied' && result.state === 'running')
|
|
30
|
+
result = await read();
|
|
31
|
+
return {
|
|
32
|
+
accepted: false,
|
|
33
|
+
runId,
|
|
34
|
+
next: 'continueSameTurn',
|
|
35
|
+
reason: registration === 'wakeAlreadySatisfied'
|
|
36
|
+
? 'runCompleted'
|
|
37
|
+
: 'automaticContinuationUnavailable',
|
|
38
|
+
result,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
17
41
|
return await runner.request({ sessionId: context.sessionId, workspace: context.workspace }, parsed.data);
|
|
18
42
|
}
|
|
19
43
|
catch {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
import { validPlanModel, validPlanEffort } from '../domain/supervised-plan.js';
|
|
7
7
|
const required = [
|
|
8
8
|
'MODEL',
|
|
9
9
|
'REASONING_EFFORT',
|
|
@@ -37,11 +37,11 @@ export function parseModelPolicy(properties, level, version) {
|
|
|
37
37
|
invalid();
|
|
38
38
|
const model = properties.get('MODEL');
|
|
39
39
|
const reasoningEffort = properties.get('REASONING_EFFORT');
|
|
40
|
-
if (!
|
|
40
|
+
if (!validPlanModel(model) || !validPlanEffort(reasoningEffort))
|
|
41
41
|
invalid();
|
|
42
42
|
const rawFallbacks = properties.get('MODEL_FALLBACKS');
|
|
43
43
|
const allowedFallbacks = rawFallbacks === 'none' ? [] : rawFallbacks.split(' ');
|
|
44
|
-
if (allowedFallbacks.some((id) => !
|
|
44
|
+
if (allowedFallbacks.some((id) => !validPlanModel(id) || id === model) ||
|
|
45
45
|
new Set(allowedFallbacks).size !== allowedFallbacks.length)
|
|
46
46
|
invalid();
|
|
47
47
|
let necessity = null;
|
|
@@ -49,7 +49,7 @@ export function parseModelPolicy(properties, level, version) {
|
|
|
49
49
|
if (exception.some((key) => properties.has(key)))
|
|
50
50
|
invalid();
|
|
51
51
|
}
|
|
52
|
-
else {
|
|
52
|
+
else if (exception.some((key) => properties.has(key))) {
|
|
53
53
|
if (exception.slice(0, 5).some((key) => !properties.get(key)?.trim()) ||
|
|
54
54
|
!['unresolved-correctness', 'specific-reasoning'].includes(properties.get('EFFORT_NECESSITY_KIND')) ||
|
|
55
55
|
(reasoningEffort === 'xhigh' && !properties.get('SCOPE_REASSESSMENT')?.trim()))
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
|
+
import { validPlanModel, validPlanEffort } from './supervised-plan.js';
|
|
6
7
|
/** Scope is automatic Org execution, not the supervisor's manual model selection or repair input. */
|
|
7
8
|
export function assessModelPolicyAdmission(plan, status = 'legacy') {
|
|
8
9
|
const blocked = (reason) => ({
|
|
@@ -23,23 +24,24 @@ export function assessModelPolicyAdmission(plan, status = 'legacy') {
|
|
|
23
24
|
return blocked('POLICY_VERSION_UNSUPPORTED');
|
|
24
25
|
if (!plan?.steps.length || plan.steps.some((step) => step.modelPolicy?.version !== 1))
|
|
25
26
|
return blocked('POLICY_FIELDS_INVALID');
|
|
26
|
-
if (plan.steps.some((step) => !
|
|
27
|
+
if (plan.steps.some((step) => !validPlanModel(step.modelPolicy.model)))
|
|
27
28
|
return blocked('MODEL_PROHIBITED');
|
|
28
29
|
if (plan.steps.some((step) => {
|
|
29
30
|
const policy = step.modelPolicy;
|
|
30
31
|
const necessity = policy.necessity;
|
|
31
|
-
return (!
|
|
32
|
+
return (!validPlanEffort(policy.reasoningEffort) ||
|
|
32
33
|
(policy.reasoningEffort === 'medium'
|
|
33
34
|
? necessity !== null
|
|
34
|
-
:
|
|
35
|
-
!
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
: necessity !== null &&
|
|
36
|
+
(!necessity ||
|
|
37
|
+
!['unresolved-correctness', 'specific-reasoning'].includes(necessity.kind) ||
|
|
38
|
+
![
|
|
39
|
+
necessity.whyMediumInadequate,
|
|
40
|
+
necessity.evidence,
|
|
41
|
+
necessity.affectedScope,
|
|
42
|
+
necessity.returnToMedium,
|
|
43
|
+
...(policy.reasoningEffort === 'xhigh' ? [necessity.scopeReassessment] : []),
|
|
44
|
+
].every((value) => typeof value === 'string' && value.trim()))));
|
|
43
45
|
}))
|
|
44
46
|
return blocked('EFFORT_UNSUPPORTED');
|
|
45
47
|
const assurance = plan.modelPolicyAssurance ?? 'configured';
|
|
@@ -52,7 +54,7 @@ export function assessModelPolicyAdmission(plan, status = 'legacy') {
|
|
|
52
54
|
scope: 'configured',
|
|
53
55
|
assurance: 'configured',
|
|
54
56
|
runtimeEnforcement: false,
|
|
55
|
-
action: 'Compatibility mode: validate
|
|
57
|
+
action: 'Compatibility mode: validate the supervisor-selected L1 settings against the runtime catalog and preserve controller-owned executor identity. Apply changed settings at the next safe turn, never repin them to session defaults. Missing observations remain unknown; no runtime attestation is claimed.',
|
|
56
58
|
};
|
|
57
59
|
}
|
|
58
60
|
export class ModelPolicyAdmissionError extends Error {
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
|
+
export const validPlanModel = (value) => typeof value === 'string' &&
|
|
7
|
+
value !== 'none' &&
|
|
8
|
+
/^[A-Za-z0-9][A-Za-z0-9._:/-]{0,63}$/.test(value);
|
|
9
|
+
export const validPlanEffort = (value) => typeof value === 'string' && /^[a-z][a-z0-9_-]{0,23}$/.test(value);
|
|
6
10
|
/** Suspended work is a barrier: no later implementation may be selected. */
|
|
7
11
|
export function currentExecutableL1Index(plan) {
|
|
8
12
|
const boundary = plan.steps.findIndex((step) => step.state === 'SUSPENDED');
|
|
@@ -309,12 +309,10 @@ export class CodexSessionRuntime {
|
|
|
309
309
|
threadId: childThreadId,
|
|
310
310
|
input: [{ type: 'text', text, text_elements: [] }],
|
|
311
311
|
clientUserMessageId,
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
...(
|
|
316
|
-
? { effort: policy?.reasoningEffort ?? session.modelSettings?.executorReasoningEffort }
|
|
317
|
-
: {}),
|
|
312
|
+
// Defaults apply at launch. Without an explicit L1 policy, preserve the
|
|
313
|
+
// existing child's choices rather than repinning it on every follow-up.
|
|
314
|
+
...(policy?.model ? { model: policy.model } : {}),
|
|
315
|
+
...(policy?.reasoningEffort ? { effort: policy.reasoningEffort } : {}),
|
|
318
316
|
};
|
|
319
317
|
let response;
|
|
320
318
|
try {
|
|
@@ -334,6 +334,33 @@ export class LocalHostTestRunner {
|
|
|
334
334
|
hasUnreadResult(sessionId) {
|
|
335
335
|
return [...this.results.values()].some((result) => result.sessionId === sessionId && result.state !== 'running' && !result.resultReadAt);
|
|
336
336
|
}
|
|
337
|
+
resultState(sessionId, runId) {
|
|
338
|
+
const result = this.results.get(runId);
|
|
339
|
+
return !result || result.sessionId !== sessionId
|
|
340
|
+
? 'missing'
|
|
341
|
+
: result.state === 'running'
|
|
342
|
+
? 'running'
|
|
343
|
+
: 'completed';
|
|
344
|
+
}
|
|
345
|
+
supervisionSummary(sessionId) {
|
|
346
|
+
const results = [...this.results.values()].filter((result) => result.sessionId === sessionId);
|
|
347
|
+
const pending = results
|
|
348
|
+
.filter((result) => result.state === 'running' || !result.resultReadAt)
|
|
349
|
+
.sort((a, b) => Number(b.state === 'running') - Number(a.state === 'running') ||
|
|
350
|
+
b.startedAt.localeCompare(a.startedAt) ||
|
|
351
|
+
a.runId.localeCompare(b.runId));
|
|
352
|
+
return {
|
|
353
|
+
enabled: true,
|
|
354
|
+
running: results.filter((result) => result.state === 'running').length,
|
|
355
|
+
unread: results.filter((result) => result.state !== 'running' && !result.resultReadAt).length,
|
|
356
|
+
runs: pending.slice(0, 8).map((result) => ({
|
|
357
|
+
runId: result.runId,
|
|
358
|
+
suite: result.suite,
|
|
359
|
+
state: result.state,
|
|
360
|
+
})),
|
|
361
|
+
omitted: Math.max(0, pending.length - 8),
|
|
362
|
+
};
|
|
363
|
+
}
|
|
337
364
|
async readResult(result) {
|
|
338
365
|
const pending = this.resultReads.get(result.runId);
|
|
339
366
|
if (pending)
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
+
import { AUTOPILOT_WAIT_MIN_MS, AUTOPILOT_WAIT_MAX_MS } from './autopilot-wait-lease.js';
|
|
7
8
|
const suite = z.string().regex(/^[a-z][a-z0-9-]{0,63}$/);
|
|
8
9
|
const runId = z.string().uuid();
|
|
9
10
|
export const hostTestRequest = z.discriminatedUnion('operation', [
|
|
@@ -18,19 +19,36 @@ export const hostTestRequest = z.discriminatedUnion('operation', [
|
|
|
18
19
|
.strict(),
|
|
19
20
|
z.object({ operation: z.literal('status'), runId }).strict(),
|
|
20
21
|
z.object({ operation: z.literal('cancel'), runId }).strict(),
|
|
22
|
+
z
|
|
23
|
+
.object({
|
|
24
|
+
operation: z.literal('wait'),
|
|
25
|
+
runId,
|
|
26
|
+
maxWaitMs: z
|
|
27
|
+
.number()
|
|
28
|
+
.int()
|
|
29
|
+
.min(AUTOPILOT_WAIT_MIN_MS)
|
|
30
|
+
.max(AUTOPILOT_WAIT_MAX_MS)
|
|
31
|
+
.default(600_000),
|
|
32
|
+
})
|
|
33
|
+
.strict(),
|
|
21
34
|
]);
|
|
22
35
|
export const gestaltTestRunnerDynamicTool = {
|
|
23
36
|
type: 'function',
|
|
24
37
|
name: 'gestalt_test_runner',
|
|
25
|
-
description: 'Run workspace test suites
|
|
38
|
+
description: 'Run workspace test suites as the host user; root supervisor only. Configure .gestalt/host-tests.json in the session workspace; suites reload without restart. list/inspect are read-only. start requires suite and UUID requestId; status/cancel/wait require runId. Prefer wait over polling: it returns a completed result or registers a run-specific Autopilot wait (maxWaitMs defaults to 600000). Yield only when accepted:true; otherwise continue in the same turn. No commands, environment or paths in arguments. Retains source fingerprints and private evidence; counts can be unknown. Keep the writer idle during tests. Never enables Autopilot or approves milestones.',
|
|
26
39
|
inputSchema: {
|
|
27
40
|
type: 'object',
|
|
28
41
|
additionalProperties: false,
|
|
29
42
|
properties: {
|
|
30
|
-
operation: { type: 'string', enum: ['list', 'inspect', 'start', 'status', 'cancel'] },
|
|
43
|
+
operation: { type: 'string', enum: ['list', 'inspect', 'start', 'status', 'cancel', 'wait'] },
|
|
31
44
|
suite: { type: 'string' },
|
|
32
45
|
requestId: { type: 'string' },
|
|
33
46
|
runId: { type: 'string' },
|
|
47
|
+
maxWaitMs: {
|
|
48
|
+
type: 'integer',
|
|
49
|
+
minimum: AUTOPILOT_WAIT_MIN_MS,
|
|
50
|
+
maximum: AUTOPILOT_WAIT_MAX_MS,
|
|
51
|
+
},
|
|
34
52
|
},
|
|
35
53
|
required: ['operation'],
|
|
36
54
|
},
|
|
@@ -6,16 +6,38 @@
|
|
|
6
6
|
export const gestaltOrgPlanHealthDynamicTool = {
|
|
7
7
|
type: 'function',
|
|
8
8
|
name: 'gestalt_org_plan_health',
|
|
9
|
-
description: 'Read Org health and reconcile observed
|
|
10
|
-
inputSchema: {
|
|
9
|
+
description: 'Read Org health and reconcile observed executor ownership without starting work or enabling Autopilot. Prefer view:compact for combined plan, activity, executor, test-run and wait state. Supply its revision as sinceRevision to receive only changed sections or unchanged:true. A missing/expired revision returns a full compact snapshot. Omit view for detailed launch/model-policy evidence. Never changes the Org Plan or clears attention.',
|
|
10
|
+
inputSchema: {
|
|
11
|
+
type: 'object',
|
|
12
|
+
additionalProperties: false,
|
|
13
|
+
properties: {
|
|
14
|
+
view: { type: 'string', enum: ['full', 'compact'] },
|
|
15
|
+
sinceRevision: { type: 'string', pattern: '^[a-f0-9]{64}$' },
|
|
16
|
+
},
|
|
17
|
+
},
|
|
11
18
|
};
|
|
19
|
+
export function parseOrgPlanHealthArguments(value) {
|
|
20
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
21
|
+
return null;
|
|
22
|
+
const args = value;
|
|
23
|
+
if (Object.keys(args).some((key) => !['view', 'sinceRevision'].includes(key)))
|
|
24
|
+
return null;
|
|
25
|
+
if (args.view !== undefined && args.view !== 'full' && args.view !== 'compact')
|
|
26
|
+
return null;
|
|
27
|
+
if (args.sinceRevision !== undefined &&
|
|
28
|
+
(args.view !== 'compact' ||
|
|
29
|
+
typeof args.sinceRevision !== 'string' ||
|
|
30
|
+
!/^[a-f0-9]{64}$/.test(args.sinceRevision)))
|
|
31
|
+
return null;
|
|
32
|
+
return {
|
|
33
|
+
view: args.view === 'compact' ? 'compact' : 'full',
|
|
34
|
+
...(typeof args.sinceRevision === 'string' ? { sinceRevision: args.sinceRevision } : {}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
12
37
|
export function isOrgPlanHealthCall(input) {
|
|
13
38
|
if (input.method !== 'item/tool/call' || !input.params || typeof input.params !== 'object')
|
|
14
39
|
return false;
|
|
15
40
|
const params = input.params;
|
|
16
41
|
return (params.tool === gestaltOrgPlanHealthDynamicTool.name &&
|
|
17
|
-
params.arguments !== null
|
|
18
|
-
typeof params.arguments === 'object' &&
|
|
19
|
-
!Array.isArray(params.arguments) &&
|
|
20
|
-
Object.keys(params.arguments).length === 0);
|
|
42
|
+
parseOrgPlanHealthArguments(params.arguments) !== null);
|
|
21
43
|
}
|