gestalt-mobile 0.54.1 → 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-BoOCaxSo.js → index-DdEHicWt.js} +3 -3
- package/dist/client/index.html +1 -1
- package/dist/server/server/composition.contracts.js +490 -4
- 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/org-plan-checkpoint/application/validate.js +8 -2
- 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/dist/server/shared/contracts/plan-signal.js +1 -0
- package/gestalt-supervision-capabilities.json +8 -2
- package/package.json +1 -1
- package/scripts/watch-github-run.mjs +283 -51
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
const models = ['gpt-6-luna', 'gpt-6-sol', 'gpt-6.1-sol'];
|
|
7
|
+
const required = [
|
|
8
|
+
'MODEL',
|
|
9
|
+
'REASONING_EFFORT',
|
|
10
|
+
'MODEL_RATIONALE',
|
|
11
|
+
'MODEL_FALLBACKS',
|
|
12
|
+
'MODEL_ESCALATION_TRIGGER',
|
|
13
|
+
];
|
|
14
|
+
const exception = [
|
|
15
|
+
'EFFORT_NECESSITY_KIND',
|
|
16
|
+
'EFFORT_NECESSITY',
|
|
17
|
+
'EFFORT_EVIDENCE',
|
|
18
|
+
'EFFORT_SCOPE',
|
|
19
|
+
'RETURN_TO_MEDIUM',
|
|
20
|
+
'SCOPE_REASSESSMENT',
|
|
21
|
+
];
|
|
22
|
+
/** Same schema as Agents model-policy-v1; no catalog or effective-setting inference. */
|
|
23
|
+
export function parseModelPolicy(properties, level, version) {
|
|
24
|
+
const declared = [...required, ...exception].filter((key) => properties.has(key));
|
|
25
|
+
const invalid = () => {
|
|
26
|
+
throw new Error('INVALID_MODEL_POLICY');
|
|
27
|
+
};
|
|
28
|
+
if (properties.has('MODEL_POLICY_VERSION'))
|
|
29
|
+
invalid();
|
|
30
|
+
if (declared.length && (level === 2 || version === undefined))
|
|
31
|
+
invalid();
|
|
32
|
+
if (version === undefined || level === 2)
|
|
33
|
+
return undefined;
|
|
34
|
+
if (required.some((key) => !properties.get(key)?.trim()))
|
|
35
|
+
invalid();
|
|
36
|
+
if (declared.some((key) => !properties.get(key).trim() || Buffer.byteLength(properties.get(key), 'utf8') > 1024))
|
|
37
|
+
invalid();
|
|
38
|
+
const model = properties.get('MODEL');
|
|
39
|
+
const reasoningEffort = properties.get('REASONING_EFFORT');
|
|
40
|
+
if (!models.includes(model) || !['medium', 'high', 'xhigh'].includes(reasoningEffort))
|
|
41
|
+
invalid();
|
|
42
|
+
const rawFallbacks = properties.get('MODEL_FALLBACKS');
|
|
43
|
+
const allowedFallbacks = rawFallbacks === 'none' ? [] : rawFallbacks.split(' ');
|
|
44
|
+
if (allowedFallbacks.some((id) => !models.includes(id) || id === model) ||
|
|
45
|
+
new Set(allowedFallbacks).size !== allowedFallbacks.length)
|
|
46
|
+
invalid();
|
|
47
|
+
let necessity = null;
|
|
48
|
+
if (reasoningEffort === 'medium') {
|
|
49
|
+
if (exception.some((key) => properties.has(key)))
|
|
50
|
+
invalid();
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
if (exception.slice(0, 5).some((key) => !properties.get(key)?.trim()) ||
|
|
54
|
+
!['unresolved-correctness', 'specific-reasoning'].includes(properties.get('EFFORT_NECESSITY_KIND')) ||
|
|
55
|
+
(reasoningEffort === 'xhigh' && !properties.get('SCOPE_REASSESSMENT')?.trim()))
|
|
56
|
+
invalid();
|
|
57
|
+
necessity = Object.freeze({
|
|
58
|
+
kind: properties.get('EFFORT_NECESSITY_KIND'),
|
|
59
|
+
whyMediumInadequate: properties.get('EFFORT_NECESSITY'),
|
|
60
|
+
evidence: properties.get('EFFORT_EVIDENCE'),
|
|
61
|
+
affectedScope: properties.get('EFFORT_SCOPE'),
|
|
62
|
+
returnToMedium: properties.get('RETURN_TO_MEDIUM'),
|
|
63
|
+
...(properties.has('SCOPE_REASSESSMENT')
|
|
64
|
+
? { scopeReassessment: properties.get('SCOPE_REASSESSMENT') }
|
|
65
|
+
: {}),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return Object.freeze({
|
|
69
|
+
version: 1,
|
|
70
|
+
model: model,
|
|
71
|
+
reasoningEffort: reasoningEffort,
|
|
72
|
+
rationale: properties.get('MODEL_RATIONALE'),
|
|
73
|
+
allowedFallbacks: Object.freeze(allowedFallbacks),
|
|
74
|
+
escalationTrigger: properties.get('MODEL_ESCALATION_TRIGGER'),
|
|
75
|
+
necessity,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
@@ -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' &&
|