gestalt-mobile 0.54.2 → 0.55.0
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 +19 -0
- package/dist/client/assets/{index-CRxjJEwq.js → index-DdEHicWt.js} +3 -3
- package/dist/client/index.html +1 -1
- package/dist/server/server/composition.contracts.js +379 -2
- package/dist/server/server/composition.js +38 -1
- package/dist/server/server/features/autopilot/application/service.js +174 -17
- package/dist/server/server/features/autopilot/domain/supervision-protocol.js +34 -0
- package/dist/server/server/features/plans/application/executor-model-evidence.js +192 -0
- package/dist/server/server/features/plans/application/parse-model-policy.js +77 -0
- package/dist/server/server/features/plans/application/parse-supervised-plan.js +23 -4
- package/dist/server/server/features/plans/application/supervised-plan-registry.js +16 -1
- package/dist/server/server/features/plans/domain/model-policy-admission.js +43 -0
- package/dist/server/server/platform/codex/codex-model-catalog.js +38 -0
- package/dist/server/server/platform/codex/executor-configuration.js +90 -0
- package/dist/server/server/platform/codex/session-runtime.js +33 -1
- package/dist/server/server/platform/plans/filesystem-plan-status-source.js +118 -13
- package/dist/server/server/platform/plans/org-plan-capabilities.js +2 -2
- package/gestalt-supervision-capabilities.json +8 -2
- package/package.json +1 -1
- package/scripts/watch-github-run.mjs +283 -51
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
6
|
import { isAbsolute, relative, resolve } from 'node:path';
|
|
7
|
+
import { parseModelPolicy } from './parse-model-policy.js';
|
|
7
8
|
const headingPattern = /^(\*{1,2}) (TODO|WIP|DONE|SUSPENDED) \[#([ABC])\] (.+)$/;
|
|
8
9
|
const propertyPattern = /^:([A-Z_]+):(?:[ \t](.*))?$/;
|
|
9
10
|
const descriptionPattern = /^- ([A-Za-z][A-Za-z ]*?) ::(?:[ \t](.*))?$/;
|
|
@@ -17,9 +18,17 @@ export function parseSupervisedPlan(input) {
|
|
|
17
18
|
const lines = input.source.replace(/\r\n?/g, '\n').split('\n');
|
|
18
19
|
const metadata = new Map();
|
|
19
20
|
const headings = [];
|
|
21
|
+
const declarations = lines
|
|
22
|
+
.map((line, index) => ({ line, index }))
|
|
23
|
+
.filter(({ line }) => /^#\+MODEL_POLICY_VERSION:/i.test(line));
|
|
24
|
+
const firstHeading = lines.findIndex((line) => line.startsWith('*'));
|
|
25
|
+
if (declarations.length > 1 ||
|
|
26
|
+
declarations.some(({ line, index }) => line !== '#+MODEL_POLICY_VERSION: 1' || index >= firstHeading))
|
|
27
|
+
return unavailable('INVALID_MODEL_POLICY');
|
|
28
|
+
const modelPolicyVersion = declarations.length ? 1 : undefined;
|
|
20
29
|
for (let index = 0; index < lines.length;) {
|
|
21
30
|
const line = lines[index];
|
|
22
|
-
const metadataMatch = /^#\+([A-
|
|
31
|
+
const metadataMatch = /^#\+([A-Z_]+):(?:[ \t](.*))?$/.exec(line);
|
|
23
32
|
if (metadataMatch) {
|
|
24
33
|
metadata.set(metadataMatch[1], metadataMatch[2] ?? '');
|
|
25
34
|
index += 1;
|
|
@@ -98,11 +107,19 @@ export function parseSupervisedPlan(input) {
|
|
|
98
107
|
return unavailable('MALFORMED_ORG');
|
|
99
108
|
if (new Set(headings.map((heading) => heading.id)).size !== headings.length)
|
|
100
109
|
return unavailable('DUPLICATE_ID');
|
|
110
|
+
const modelPolicies = new Map();
|
|
111
|
+
try {
|
|
112
|
+
for (const heading of headings)
|
|
113
|
+
modelPolicies.set(heading.id, parseModelPolicy(heading.properties, heading.level, modelPolicyVersion));
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return unavailable('INVALID_MODEL_POLICY');
|
|
117
|
+
}
|
|
101
118
|
if (!hasValidSuspension(headings))
|
|
102
119
|
return unavailable('MALFORMED_ORG');
|
|
103
120
|
if (!hasValidWipPath(headings))
|
|
104
121
|
return unavailable('MULTIPLE_WIP');
|
|
105
|
-
const built = buildSteps(headings);
|
|
122
|
+
const built = buildSteps(headings, modelPolicies);
|
|
106
123
|
if (!built)
|
|
107
124
|
return unavailable('MISSING_REQUIRED_FIELD');
|
|
108
125
|
const allSteps = headings;
|
|
@@ -120,6 +137,7 @@ export function parseSupervisedPlan(input) {
|
|
|
120
137
|
...(metadata.has('SUBTITLE') ? { subtitle: metadata.get('SUBTITLE') } : {}),
|
|
121
138
|
...(metadata.has('DATE') ? { date: metadata.get('DATE') } : {}),
|
|
122
139
|
...(metadata.has('KEYWORDS') ? { keywords: metadata.get('KEYWORDS') } : {}),
|
|
140
|
+
...(modelPolicyVersion ? { modelPolicyVersion } : {}),
|
|
123
141
|
steps: built,
|
|
124
142
|
totalSteps: allSteps.length,
|
|
125
143
|
doneSteps: allSteps.filter((step) => step.state === 'DONE').length,
|
|
@@ -136,7 +154,7 @@ export function isPlanPathWithinWorkspace(planPath, workspacePath) {
|
|
|
136
154
|
return (pathWithinWorkspace === '' ||
|
|
137
155
|
(!pathWithinWorkspace.startsWith('..') && !isAbsolute(pathWithinWorkspace)));
|
|
138
156
|
}
|
|
139
|
-
function buildSteps(headings) {
|
|
157
|
+
function buildSteps(headings, modelPolicies) {
|
|
140
158
|
const parents = [];
|
|
141
159
|
for (let index = 0; index < headings.length; index += 1) {
|
|
142
160
|
const heading = headings[index];
|
|
@@ -144,7 +162,8 @@ function buildSteps(headings) {
|
|
|
144
162
|
const step = makeStep(heading);
|
|
145
163
|
if (!step)
|
|
146
164
|
return null;
|
|
147
|
-
|
|
165
|
+
const modelPolicy = modelPolicies.get(heading.id);
|
|
166
|
+
parents.push(modelPolicy ? { ...step, modelPolicy } : step);
|
|
148
167
|
continue;
|
|
149
168
|
}
|
|
150
169
|
const parent = parents.at(-1);
|
|
@@ -5,14 +5,28 @@
|
|
|
5
5
|
*/
|
|
6
6
|
/** Retains at most one validated plan projection for each relay session. */
|
|
7
7
|
export class SupervisedPlanRegistry {
|
|
8
|
+
policyUnavailable = new Set();
|
|
8
9
|
plans = new Map();
|
|
9
10
|
accept(sessionId, update) {
|
|
10
|
-
if (update.kind === 'updated')
|
|
11
|
+
if (update.kind === 'updated') {
|
|
11
12
|
this.plans.set(sessionId, {
|
|
12
13
|
plan: update.plan,
|
|
13
14
|
identity: update.identity,
|
|
14
15
|
publicationReason: update.reason,
|
|
15
16
|
});
|
|
17
|
+
this.policyUnavailable.delete(sessionId);
|
|
18
|
+
}
|
|
19
|
+
else if (update.modelPolicyRequired || this.find(sessionId)?.modelPolicyVersion === 1) {
|
|
20
|
+
this.policyUnavailable.add(sessionId);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** An invalid mandatory publication cannot silently reuse a legacy execution policy. */
|
|
24
|
+
modelPolicyStatus(sessionId) {
|
|
25
|
+
return this.policyUnavailable.has(sessionId)
|
|
26
|
+
? 'unavailable'
|
|
27
|
+
: this.find(sessionId)?.modelPolicyVersion === 1
|
|
28
|
+
? 'required'
|
|
29
|
+
: 'legacy';
|
|
16
30
|
}
|
|
17
31
|
find(sessionId) {
|
|
18
32
|
return this.plans.get(sessionId)?.plan ?? null;
|
|
@@ -25,5 +39,6 @@ export class SupervisedPlanRegistry {
|
|
|
25
39
|
}
|
|
26
40
|
clear(sessionId) {
|
|
27
41
|
this.plans.delete(sessionId);
|
|
42
|
+
this.policyUnavailable.delete(sessionId);
|
|
28
43
|
}
|
|
29
44
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
/** Scope is automatic Org execution, not the supervisor's manual model selection or repair input. */
|
|
7
|
+
export function assessModelPolicyAdmission(plan, status = 'legacy') {
|
|
8
|
+
const blocked = (reason) => ({
|
|
9
|
+
allowed: false,
|
|
10
|
+
code: 'AUTOPILOT_MODEL_POLICY_UNAVAILABLE',
|
|
11
|
+
reason,
|
|
12
|
+
action: 'Keep Org automation off until a compatible runtime can attest the canonical executor settings. Manual plan review and repair remain available.',
|
|
13
|
+
});
|
|
14
|
+
if (status === 'unavailable')
|
|
15
|
+
return blocked('POLICY_PROJECTION_UNAVAILABLE');
|
|
16
|
+
const version = plan?.modelPolicyVersion;
|
|
17
|
+
const hasPolicy = plan?.steps.some((step) => step.modelPolicy !== undefined);
|
|
18
|
+
if (version === undefined && !hasPolicy && status === 'legacy')
|
|
19
|
+
return { allowed: true, scope: 'legacy' };
|
|
20
|
+
if (version !== 1)
|
|
21
|
+
return blocked('POLICY_VERSION_UNSUPPORTED');
|
|
22
|
+
if (!plan?.steps.length || plan.steps.some((step) => step.modelPolicy?.version !== 1))
|
|
23
|
+
return blocked('POLICY_FIELDS_INVALID');
|
|
24
|
+
if (plan.steps.some((step) => !['gpt-6-luna', 'gpt-6-sol', 'gpt-6.1-sol'].includes(step.modelPolicy.model)))
|
|
25
|
+
return blocked('MODEL_PROHIBITED');
|
|
26
|
+
// Configured settings and locally derived digests from the current adapter do
|
|
27
|
+
// not satisfy the Agents runtime receipt/revision contract. No bypass flag or
|
|
28
|
+
// fixture can turn this prerequisite into live admission.
|
|
29
|
+
return blocked('RUNTIME_ATTESTATION_UNAVAILABLE');
|
|
30
|
+
}
|
|
31
|
+
export class ModelPolicyAdmissionError extends Error {
|
|
32
|
+
admission;
|
|
33
|
+
code = 'AUTOPILOT_MODEL_POLICY_UNAVAILABLE';
|
|
34
|
+
constructor(admission) {
|
|
35
|
+
super(admission.code);
|
|
36
|
+
this.admission = admission;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function requireModelPolicyAdmission(plan, status) {
|
|
40
|
+
const admission = assessModelPolicyAdmission(plan, status);
|
|
41
|
+
if (!admission.allowed)
|
|
42
|
+
throw new ModelPolicyAdmissionError(admission);
|
|
43
|
+
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
7
8
|
import { launchCodexAppServer } from './codex-process-launcher.js';
|
|
8
9
|
const modelSchema = z.object({ id: z.string().min(1) });
|
|
9
10
|
const resultSchema = z.union([
|
|
@@ -11,6 +12,43 @@ const resultSchema = z.union([
|
|
|
11
12
|
z.object({ models: z.array(modelSchema) }),
|
|
12
13
|
z.object({ data: z.object({ models: z.array(modelSchema) }) }),
|
|
13
14
|
]);
|
|
15
|
+
/** Bounded policy catalog from the same model/list source; missing effort support stays unknown. */
|
|
16
|
+
export function decodeCodexPolicyCatalog(value) {
|
|
17
|
+
const record = value && typeof value === 'object' ? value : null;
|
|
18
|
+
if (!record || (record.nextCursor !== undefined && record.nextCursor !== null))
|
|
19
|
+
return null;
|
|
20
|
+
const nested = record.data && typeof record.data === 'object'
|
|
21
|
+
? record.data
|
|
22
|
+
: null;
|
|
23
|
+
const rows = Array.isArray(record.data) ? record.data : (record.models ?? nested?.models);
|
|
24
|
+
if (!Array.isArray(rows) || rows.length === 0 || rows.length > 512)
|
|
25
|
+
return null;
|
|
26
|
+
const schema = z.object({
|
|
27
|
+
id: z.string().min(1).max(128),
|
|
28
|
+
supportedReasoningEfforts: z
|
|
29
|
+
.array(z.object({ reasoningEffort: z.string().min(1).max(24) }))
|
|
30
|
+
.min(1)
|
|
31
|
+
.max(16),
|
|
32
|
+
});
|
|
33
|
+
const models = [];
|
|
34
|
+
for (const row of rows) {
|
|
35
|
+
const parsed = schema.safeParse(row);
|
|
36
|
+
if (!parsed.success)
|
|
37
|
+
return null;
|
|
38
|
+
const efforts = parsed.data.supportedReasoningEfforts.map((entry) => entry.reasoningEffort);
|
|
39
|
+
if (new Set(efforts).size !== efforts.length)
|
|
40
|
+
return null;
|
|
41
|
+
models.push({ id: parsed.data.id, reasoningEfforts: efforts.sort() });
|
|
42
|
+
}
|
|
43
|
+
if (new Set(models.map((model) => model.id)).size !== models.length)
|
|
44
|
+
return null;
|
|
45
|
+
models.sort((a, b) => a.id.localeCompare(b.id));
|
|
46
|
+
return {
|
|
47
|
+
source: 'runtime',
|
|
48
|
+
revision: createHash('sha256').update(JSON.stringify(models)).digest('hex'),
|
|
49
|
+
models,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
14
52
|
/** Short-lived adapter for the Codex app-server model catalog. */
|
|
15
53
|
export class CodexModelCatalog {
|
|
16
54
|
cwd;
|
|
@@ -0,0 +1,90 @@
|
|
|
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, randomUUID } from 'node:crypto';
|
|
7
|
+
import { decodeCodexPolicyCatalog } from './codex-model-catalog.js';
|
|
8
|
+
const record = (value) => value && typeof value === 'object' && !Array.isArray(value)
|
|
9
|
+
? value
|
|
10
|
+
: null;
|
|
11
|
+
const small = (value, bytes) => typeof value === 'string' &&
|
|
12
|
+
value.trim() &&
|
|
13
|
+
Buffer.byteLength(JSON.stringify(value), 'utf8') <= bytes
|
|
14
|
+
? value
|
|
15
|
+
: null;
|
|
16
|
+
/** Metadata reads only. Never resume a child or recover settings from a request/profile/root. */
|
|
17
|
+
export async function readExecutorConfiguration(rpc, input, current, now = () => new Date().toISOString(), timeoutMs = 5_000) {
|
|
18
|
+
if (!current())
|
|
19
|
+
return { kind: 'unavailable', code: 'RUNTIME_UNAVAILABLE' };
|
|
20
|
+
const deadline = Date.now() + timeoutMs;
|
|
21
|
+
const request = async (method, params) => {
|
|
22
|
+
let timer;
|
|
23
|
+
try {
|
|
24
|
+
return await Promise.race([
|
|
25
|
+
rpc.request(method, params),
|
|
26
|
+
new Promise((_, reject) => {
|
|
27
|
+
timer = setTimeout(() => reject(new Error('EXECUTOR_CONFIGURATION_TIMEOUT')), Math.max(1, deadline - Date.now()));
|
|
28
|
+
}),
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
if (timer)
|
|
33
|
+
clearTimeout(timer);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
let threadResult;
|
|
37
|
+
try {
|
|
38
|
+
threadResult = await request('thread/read', { threadId: input.threadId, includeTurns: false });
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return { kind: 'unavailable', code: 'RUNTIME_UNAVAILABLE' };
|
|
42
|
+
}
|
|
43
|
+
const observedAt = now();
|
|
44
|
+
const thread = record(record(threadResult)?.thread);
|
|
45
|
+
const source = record(thread?.source);
|
|
46
|
+
const spawn = record(record(source?.subAgent ?? source?.subagent)?.thread_spawn);
|
|
47
|
+
if (!small(thread?.id, 256) ||
|
|
48
|
+
!small(thread?.parentThreadId, 256) ||
|
|
49
|
+
!small(spawn?.agent_path, 256))
|
|
50
|
+
return { kind: 'unavailable', code: 'CHILD_BINDING_UNKNOWN' };
|
|
51
|
+
if (!thread ||
|
|
52
|
+
thread.id !== input.threadId ||
|
|
53
|
+
thread.parentThreadId !== input.rootThreadId ||
|
|
54
|
+
spawn?.agent_path !== input.taskPath ||
|
|
55
|
+
input.threadId === input.rootThreadId)
|
|
56
|
+
return { kind: 'unavailable', code: 'CHILD_BINDING_MISMATCH' };
|
|
57
|
+
const status = record(thread.status)?.type;
|
|
58
|
+
if (status === 'notLoaded')
|
|
59
|
+
return { kind: 'unavailable', code: 'CHILD_NOT_LOADED' };
|
|
60
|
+
if (status !== 'idle' && status !== 'active')
|
|
61
|
+
return { kind: 'unavailable', code: 'RUNTIME_UNAVAILABLE' };
|
|
62
|
+
let catalog = null;
|
|
63
|
+
try {
|
|
64
|
+
catalog = decodeCodexPolicyCatalog(await request('model/list', {}));
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
/* Unknown support cannot become an empty successful catalog. */
|
|
68
|
+
}
|
|
69
|
+
if (!current())
|
|
70
|
+
return { kind: 'unavailable', code: 'OBSERVATION_CHANGED' };
|
|
71
|
+
const model = small(thread.model, 64);
|
|
72
|
+
const reasoningEffort = small(thread.reasoningEffort, 24);
|
|
73
|
+
return {
|
|
74
|
+
kind: 'observed',
|
|
75
|
+
configuration: {
|
|
76
|
+
source: 'runtime-thread-metadata',
|
|
77
|
+
observationId: randomUUID(),
|
|
78
|
+
observedAt,
|
|
79
|
+
model,
|
|
80
|
+
reasoningEffort,
|
|
81
|
+
role: small(thread.agentRole, 64),
|
|
82
|
+
// Thread.updatedAt is recency, not a settings revision. Do not promote it.
|
|
83
|
+
settingsRevision: null,
|
|
84
|
+
settingsFingerprint: createHash('sha256')
|
|
85
|
+
.update(JSON.stringify({ model, reasoningEffort }))
|
|
86
|
+
.digest('hex'),
|
|
87
|
+
catalog,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
6
|
import { ORG_PLAN_CAPABILITIES } from '../plans/org-plan-capabilities.js';
|
|
7
|
+
import { readExecutorConfiguration } from './executor-configuration.js';
|
|
7
8
|
import { RelaySession, } from '../../features/sessions/model/relay-session.js';
|
|
8
9
|
import { randomUUID } from 'node:crypto';
|
|
9
10
|
import { createPlanMeasurementSnapshot, } from '../../features/plans/application/measurement-snapshot.js';
|
|
@@ -52,6 +53,8 @@ class SessionResource {
|
|
|
52
53
|
capabilities = new Map();
|
|
53
54
|
spawnedAgentModels = new Map();
|
|
54
55
|
attemptedAgentModelRecovery = new Set();
|
|
56
|
+
/** Local race fence only; never presented as a runtime-issued settings revision. */
|
|
57
|
+
configurationChanges = new Map();
|
|
55
58
|
ownedChildProcesses = new Map();
|
|
56
59
|
/** Retries from a durable Autopilot issued command reuse this opaque action id. */
|
|
57
60
|
completedProcessActions = new Map();
|
|
@@ -112,13 +115,30 @@ export class CodexSessionRuntime {
|
|
|
112
115
|
readerCwd;
|
|
113
116
|
resolveModelConfig;
|
|
114
117
|
retrieval;
|
|
118
|
+
requireExecutorAdmission;
|
|
119
|
+
/** Trusted read-only port for the current controller-bound child on its owning process. */
|
|
120
|
+
async readExecutorConfiguration(input) {
|
|
121
|
+
const resource = this.sessions.get(input.sessionId);
|
|
122
|
+
if (!resource || !resource.active || resource.threadId !== input.rootThreadId)
|
|
123
|
+
return { kind: 'unavailable', code: 'RUNTIME_UNAVAILABLE' };
|
|
124
|
+
if (!resource.configurationChanges.has(input.threadId)) {
|
|
125
|
+
if (resource.configurationChanges.size >= 256)
|
|
126
|
+
return { kind: 'unavailable', code: 'RUNTIME_UNAVAILABLE' };
|
|
127
|
+
resource.configurationChanges.set(input.threadId, 0);
|
|
128
|
+
}
|
|
129
|
+
const changes = resource.configurationChanges.get(input.threadId);
|
|
130
|
+
return readExecutorConfiguration(resource.process.rpc, input, () => resource.active &&
|
|
131
|
+
this.sessions.get(input.sessionId) === resource &&
|
|
132
|
+
resource.threadId === input.rootThreadId &&
|
|
133
|
+
resource.configurationChanges.get(input.threadId) === changes);
|
|
134
|
+
}
|
|
115
135
|
serverResponseListeners = new Set();
|
|
116
136
|
constructor(launch,
|
|
117
137
|
// Kept as an ignored compatibility slot while callers migrate from the old
|
|
118
138
|
// correlated-map constructor shape. Live ownership is `sessions` only.
|
|
119
139
|
_legacyProcesses = undefined, onNotification, onServerRequest, onProcessExit, resolveSkills, planStatusSource, onPlanStatus, planMeasurementBaseUrl,
|
|
120
140
|
// Compatibility slot: blocking app-server requests wait for explicit input.
|
|
121
|
-
_legacyRequestTimeoutMs = undefined, maxPendingRequests = 64, readerCwd, resolveModelConfig, retrieval) {
|
|
141
|
+
_legacyRequestTimeoutMs = undefined, maxPendingRequests = 64, readerCwd, resolveModelConfig, retrieval, requireExecutorAdmission) {
|
|
122
142
|
this.launch = launch;
|
|
123
143
|
this.onNotification = onNotification;
|
|
124
144
|
this.onServerRequest = onServerRequest;
|
|
@@ -131,6 +151,7 @@ export class CodexSessionRuntime {
|
|
|
131
151
|
this.readerCwd = readerCwd;
|
|
132
152
|
this.resolveModelConfig = resolveModelConfig;
|
|
133
153
|
this.retrieval = retrieval;
|
|
154
|
+
this.requireExecutorAdmission = requireExecutorAdmission;
|
|
134
155
|
void _legacyProcesses;
|
|
135
156
|
void _legacyRequestTimeoutMs;
|
|
136
157
|
}
|
|
@@ -256,6 +277,7 @@ export class CodexSessionRuntime {
|
|
|
256
277
|
return RelaySession.rehydrate(session).startTurn(result, now).snapshot;
|
|
257
278
|
}
|
|
258
279
|
async startExecutorTurn(session, childThreadId, text, clientUserMessageId) {
|
|
280
|
+
this.requireExecutorAdmission?.(session.id);
|
|
259
281
|
const resource = this.sessions.get(session.id);
|
|
260
282
|
if (!resource)
|
|
261
283
|
throw new Error('CODEX_SESSION_NOT_RUNNING');
|
|
@@ -283,7 +305,9 @@ export class CodexSessionRuntime {
|
|
|
283
305
|
error.code !== -32600 ||
|
|
284
306
|
error.message !== `thread not found: ${childThreadId}`)
|
|
285
307
|
throw error;
|
|
308
|
+
this.requireExecutorAdmission?.(session.id);
|
|
286
309
|
await resource.process.rpc.request('thread/resume', { threadId: childThreadId });
|
|
310
|
+
this.requireExecutorAdmission?.(session.id);
|
|
287
311
|
response = await resource.process.rpc.request('turn/start', params);
|
|
288
312
|
}
|
|
289
313
|
const result = decodeTurnStart(response);
|
|
@@ -952,6 +976,14 @@ export class CodexSessionRuntime {
|
|
|
952
976
|
const notificationUnsubscribe = process.rpc.onNotification((notification) => {
|
|
953
977
|
if (!resource.active)
|
|
954
978
|
return;
|
|
979
|
+
if (notification.method === 'thread/settings/updated' ||
|
|
980
|
+
notification.method === 'turn/started') {
|
|
981
|
+
const threadId = boundedString(asRecord(notification.params)?.threadId, 256);
|
|
982
|
+
if (threadId &&
|
|
983
|
+
(resource.configurationChanges.has(threadId) ||
|
|
984
|
+
resource.configurationChanges.size < 256))
|
|
985
|
+
resource.configurationChanges.set(threadId, (resource.configurationChanges.get(threadId) ?? 0) + 1);
|
|
986
|
+
}
|
|
955
987
|
if (notification.method === 'mcpServer/statusUpdated') {
|
|
956
988
|
const status = notification.params;
|
|
957
989
|
if (status?.name === 'gestalt-serena' &&
|
|
@@ -9,6 +9,7 @@ import { isPlanSignalReason } from '../../../shared/contracts/plan-signal.js';
|
|
|
9
9
|
import { basename, dirname, join } from 'node:path';
|
|
10
10
|
import { parseSupervisedPlan } from '../../features/plans/application/parse-supervised-plan.js';
|
|
11
11
|
import { isPlanPathWithinWorkspace } from '../../features/plans/application/parse-supervised-plan.js';
|
|
12
|
+
import { ORG_PLAN_CAPABILITIES } from './org-plan-capabilities.js';
|
|
12
13
|
const statusFileSuffix = '.plan-status.json';
|
|
13
14
|
export class FilesystemPlanStatusSource {
|
|
14
15
|
dismissalDirectory;
|
|
@@ -61,21 +62,41 @@ export class FilesystemPlanStatusSource {
|
|
|
61
62
|
const statusPath = planStatusFilePath(directory, planPath);
|
|
62
63
|
const candidate = join(directory, `.${randomUUID()}.status.tmp`);
|
|
63
64
|
try {
|
|
64
|
-
await writeFile(candidate, JSON.stringify({
|
|
65
|
+
await writeFile(candidate, JSON.stringify({
|
|
66
|
+
schemaVersion: 1,
|
|
67
|
+
planPath,
|
|
68
|
+
reason,
|
|
69
|
+
updatedAt: new Date().toISOString(),
|
|
70
|
+
...(parsed.plan.modelPolicyVersion
|
|
71
|
+
? {
|
|
72
|
+
modelPolicyVersion: parsed.plan.modelPolicyVersion,
|
|
73
|
+
requiredCapabilities: ['l1-model-policy-v1'],
|
|
74
|
+
}
|
|
75
|
+
: {}),
|
|
76
|
+
}), { mode: 0o600 });
|
|
65
77
|
await rename(candidate, statusPath);
|
|
66
78
|
}
|
|
67
79
|
finally {
|
|
68
80
|
await rm(candidate, { force: true }).catch(() => { });
|
|
69
81
|
}
|
|
82
|
+
// Explicit validated attachment supersedes incompatible pointer hints in
|
|
83
|
+
// this session only. Plan files are never removed or rewritten here.
|
|
84
|
+
for (const filename of await readdir(directory)) {
|
|
85
|
+
const stalePath = join(directory, filename);
|
|
86
|
+
if (stalePath === statusPath || !filename.endsWith(statusFileSuffix))
|
|
87
|
+
continue;
|
|
88
|
+
const stale = await this.planReadFilesystem.readFile(stalePath, 'utf8').catch(() => '');
|
|
89
|
+
if (declaresModelPolicy(stale) && !parseSignal(stale))
|
|
90
|
+
await rm(stalePath, { force: true });
|
|
91
|
+
}
|
|
70
92
|
const identity = createHash('sha256').update(planPath).digest('hex');
|
|
71
93
|
const dismissed = new Set(await this.dismissed(session.id));
|
|
72
94
|
if (dismissed.delete(identity))
|
|
73
95
|
await this.saveDismissals(session.id, dismissed);
|
|
74
96
|
const lease = this.leases.get(session.id);
|
|
75
|
-
if (lease)
|
|
76
|
-
await lease.refreshLatest();
|
|
77
|
-
else
|
|
97
|
+
if (!lease)
|
|
78
98
|
await this.open(session, listener);
|
|
99
|
+
await this.leases.get(session.id)?.selectAttachment(statusPath);
|
|
79
100
|
}
|
|
80
101
|
closeAll() {
|
|
81
102
|
for (const lease of this.leases.values())
|
|
@@ -201,6 +222,9 @@ class ActiveLease {
|
|
|
201
222
|
activeStatusPath;
|
|
202
223
|
activePlanPath;
|
|
203
224
|
lastEmittedUpdate;
|
|
225
|
+
policyBlockedStatusPath;
|
|
226
|
+
/** Retire older reads when mandatory rejection or explicit recovery changes admission. */
|
|
227
|
+
policySelectionRevision = 0;
|
|
204
228
|
constructor(statusDirectory, sessionId, workspacePath, listener, planReadFilesystem, isDismissed, onActiveStatusPath, onClose) {
|
|
205
229
|
this.statusDirectory = statusDirectory;
|
|
206
230
|
this.sessionId = sessionId;
|
|
@@ -302,9 +326,21 @@ class ActiveLease {
|
|
|
302
326
|
}, 25);
|
|
303
327
|
}
|
|
304
328
|
async refreshCurrent() {
|
|
305
|
-
|
|
329
|
+
// Admission/checkpoint reads must see mandatory publications even while the
|
|
330
|
+
// directory watcher is debouncing an update to a different status path.
|
|
331
|
+
return this.refreshLatest();
|
|
332
|
+
}
|
|
333
|
+
async selectAttachment(statusPath) {
|
|
334
|
+
this.policySelectionRevision += 1;
|
|
335
|
+
const blocked = this.policyBlockedStatusPath;
|
|
336
|
+
const update = await this.refreshPath(statusPath, undefined, true);
|
|
337
|
+
if (update?.kind !== 'updated')
|
|
338
|
+
throw new Error('PLAN_UNAVAILABLE');
|
|
339
|
+
if (update?.kind === 'updated' && blocked && blocked !== statusPath)
|
|
340
|
+
await rm(blocked, { force: true });
|
|
306
341
|
}
|
|
307
342
|
async refreshLatest() {
|
|
343
|
+
const policyRevision = this.policySelectionRevision;
|
|
308
344
|
try {
|
|
309
345
|
const candidates = (await readdir(this.statusDirectory))
|
|
310
346
|
.filter((filename) => filename.endsWith(statusFileSuffix))
|
|
@@ -314,21 +350,49 @@ class ActiveLease {
|
|
|
314
350
|
this.planReadFilesystem.readFile(statusPath, 'utf8').catch(() => ''),
|
|
315
351
|
stat(statusPath).catch(() => undefined),
|
|
316
352
|
]);
|
|
317
|
-
return {
|
|
353
|
+
return {
|
|
354
|
+
statusPath,
|
|
355
|
+
signal: parseSignal(source),
|
|
356
|
+
modifiedAt: metadata?.mtimeMs ?? 0,
|
|
357
|
+
policyRequired: declaresModelPolicy(source),
|
|
358
|
+
};
|
|
318
359
|
}));
|
|
319
360
|
const latest = signals
|
|
320
361
|
.filter((candidate) => candidate.signal !== null)
|
|
321
362
|
.sort((left, right) => right.signal.updatedAt.localeCompare(left.signal.updatedAt) ||
|
|
322
363
|
right.modifiedAt - left.modifiedAt)[0];
|
|
323
|
-
|
|
364
|
+
if (policyRevision !== this.policySelectionRevision)
|
|
365
|
+
return null;
|
|
366
|
+
const invalidPolicy = signals
|
|
367
|
+
.filter((candidate) => !candidate.signal && candidate.policyRequired)
|
|
368
|
+
.sort((a, b) => b.modifiedAt - a.modifiedAt)[0];
|
|
369
|
+
if (invalidPolicy && (!latest || invalidPolicy.modifiedAt >= latest.modifiedAt)) {
|
|
370
|
+
this.policyBlockedStatusPath = invalidPolicy.statusPath;
|
|
371
|
+
return !this.closed ? this.emitUnavailable(true) : null;
|
|
372
|
+
}
|
|
373
|
+
return latest
|
|
374
|
+
? this.refreshPath(latest.statusPath, latest.signal, true)
|
|
375
|
+
: this.activeStatusPath
|
|
376
|
+
? this.refreshPath(this.activeStatusPath, undefined, true)
|
|
377
|
+
: null;
|
|
324
378
|
}
|
|
325
379
|
catch {
|
|
326
380
|
return !this.closed ? this.emitUnavailable() : null;
|
|
327
381
|
}
|
|
328
382
|
}
|
|
329
|
-
async refreshPath(statusPath, parsedSignal) {
|
|
383
|
+
async refreshPath(statusPath, parsedSignal, selectedLatest = false) {
|
|
384
|
+
if (this.policyBlockedStatusPath &&
|
|
385
|
+
!selectedLatest &&
|
|
386
|
+
statusPath !== this.policyBlockedStatusPath)
|
|
387
|
+
return this.refreshLatest();
|
|
388
|
+
let policyRequired = parsedSignal?.modelPolicyVersion === 1;
|
|
389
|
+
const policyRevision = this.policySelectionRevision;
|
|
330
390
|
try {
|
|
331
|
-
const
|
|
391
|
+
const source = parsedSignal
|
|
392
|
+
? null
|
|
393
|
+
: await this.planReadFilesystem.readFile(statusPath, 'utf8');
|
|
394
|
+
policyRequired ||= source !== null && declaresModelPolicy(source);
|
|
395
|
+
const signal = parsedSignal ?? parseSignal(source);
|
|
332
396
|
if (!signal)
|
|
333
397
|
throw new Error('INVALID_PLAN_STATUS');
|
|
334
398
|
const [planPath, workspacePath] = await Promise.all([
|
|
@@ -346,8 +410,14 @@ class ActiveLease {
|
|
|
346
410
|
workspacePath,
|
|
347
411
|
});
|
|
348
412
|
if (result.kind === 'available') {
|
|
413
|
+
policyRequired ||= result.plan.modelPolicyVersion === 1;
|
|
414
|
+
if (result.plan.modelPolicyVersion !== signal.modelPolicyVersion)
|
|
415
|
+
throw new Error('MODEL_POLICY_PUBLICATION_MISMATCH');
|
|
349
416
|
if (!this.closed && !(await this.isDismissed(identity)) && !this.closed) {
|
|
417
|
+
if (policyRevision !== this.policySelectionRevision)
|
|
418
|
+
return null;
|
|
350
419
|
const previousStatusPath = this.activeStatusPath;
|
|
420
|
+
this.policyBlockedStatusPath = undefined;
|
|
351
421
|
this.activeStatusPath = statusPath;
|
|
352
422
|
this.watchActivePlan(planPath);
|
|
353
423
|
this.onActiveStatusPath(statusPath);
|
|
@@ -369,25 +439,44 @@ class ActiveLease {
|
|
|
369
439
|
}
|
|
370
440
|
}
|
|
371
441
|
else if (!this.closed) {
|
|
372
|
-
|
|
442
|
+
if (policyRevision !== this.policySelectionRevision)
|
|
443
|
+
return null;
|
|
444
|
+
policyRequired ||= result.reason === 'INVALID_MODEL_POLICY';
|
|
445
|
+
if (policyRequired)
|
|
446
|
+
this.policyBlockedStatusPath = statusPath;
|
|
447
|
+
return this.emitUnavailable(policyRequired);
|
|
373
448
|
}
|
|
374
449
|
return null;
|
|
375
450
|
}
|
|
376
451
|
catch (error) {
|
|
452
|
+
if (policyRevision !== this.policySelectionRevision)
|
|
453
|
+
return null;
|
|
377
454
|
if (error.code === 'ENOENT' &&
|
|
378
455
|
this.activeStatusPath !== undefined &&
|
|
379
456
|
statusPath !== this.activeStatusPath)
|
|
380
457
|
return null;
|
|
381
|
-
|
|
458
|
+
if (policyRequired)
|
|
459
|
+
this.policyBlockedStatusPath = statusPath;
|
|
460
|
+
return !this.closed ? this.emitUnavailable(policyRequired) : null;
|
|
382
461
|
}
|
|
383
462
|
}
|
|
384
|
-
emitUnavailable() {
|
|
463
|
+
emitUnavailable(modelPolicyRequired = false) {
|
|
464
|
+
if (modelPolicyRequired)
|
|
465
|
+
this.policySelectionRevision += 1;
|
|
385
466
|
this.lastEmittedUpdate = undefined;
|
|
386
|
-
const update = {
|
|
467
|
+
const update = {
|
|
468
|
+
kind: 'unavailable',
|
|
469
|
+
code: 'PLAN_STATUS_UNAVAILABLE',
|
|
470
|
+
...(modelPolicyRequired ? { modelPolicyRequired: true } : {}),
|
|
471
|
+
};
|
|
387
472
|
this.listener(update);
|
|
388
473
|
return update;
|
|
389
474
|
}
|
|
390
475
|
}
|
|
476
|
+
/** Recognize mandatory policy even when its version/capability envelope cannot be parsed. */
|
|
477
|
+
function declaresModelPolicy(source) {
|
|
478
|
+
return /"modelPolicyVersion"\s*:|"l1-model-policy[^"\r\n]*"/.test(source);
|
|
479
|
+
}
|
|
391
480
|
function parseSignal(source) {
|
|
392
481
|
try {
|
|
393
482
|
const value = JSON.parse(source);
|
|
@@ -398,9 +487,25 @@ function parseSignal(source) {
|
|
|
398
487
|
return null;
|
|
399
488
|
if (typeof signal.reason !== 'string' || !isRfc3339Utc(signal.updatedAt))
|
|
400
489
|
return null;
|
|
490
|
+
const required = signal.requiredCapabilities;
|
|
491
|
+
if (required !== undefined &&
|
|
492
|
+
(!Array.isArray(required) ||
|
|
493
|
+
required.some((capability) => typeof capability !== 'string' ||
|
|
494
|
+
!ORG_PLAN_CAPABILITIES.split(',').includes(capability))))
|
|
495
|
+
return null;
|
|
496
|
+
if (signal.modelPolicyVersion !== undefined &&
|
|
497
|
+
(signal.modelPolicyVersion !== 1 ||
|
|
498
|
+
!Array.isArray(required) ||
|
|
499
|
+
!required.includes('l1-model-policy-v1')))
|
|
500
|
+
return null;
|
|
501
|
+
if (Array.isArray(required) &&
|
|
502
|
+
required.includes('l1-model-policy-v1') &&
|
|
503
|
+
signal.modelPolicyVersion !== 1)
|
|
504
|
+
return null;
|
|
401
505
|
return {
|
|
402
506
|
planPath: signal.planPath,
|
|
403
507
|
updatedAt: signal.updatedAt,
|
|
508
|
+
...(signal.modelPolicyVersion === 1 ? { modelPolicyVersion: 1 } : {}),
|
|
404
509
|
reason: isPlanSignalReason(signal.reason) ? signal.reason : null,
|
|
405
510
|
};
|
|
406
511
|
}
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
|
-
/**
|
|
7
|
-
export const ORG_PLAN_CAPABILITIES = 'suspension-v1,nested-suspension-v1';
|
|
6
|
+
/** Schema/retention support only; never asserts effective runtime enforcement. */
|
|
7
|
+
export const ORG_PLAN_CAPABILITIES = 'suspension-v1,nested-suspension-v1,l1-model-policy-v1';
|
|
@@ -13,6 +13,12 @@
|
|
|
13
13
|
"session-verdict",
|
|
14
14
|
"acknowledgement-safe-composer",
|
|
15
15
|
"org-plan-contract",
|
|
16
|
-
"suspension-v1"
|
|
17
|
-
|
|
16
|
+
"suspension-v1",
|
|
17
|
+
"l1-model-policy-v1"
|
|
18
|
+
],
|
|
19
|
+
"modelPolicyContract": {
|
|
20
|
+
"version": 1,
|
|
21
|
+
"scope": "schema-and-retention",
|
|
22
|
+
"runtimeEnforcement": false
|
|
23
|
+
}
|
|
18
24
|
}
|