gestalt-mobile 0.67.2 → 0.68.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.
Files changed (35) hide show
  1. package/dist/client/assets/index-BZ3ivopC.js +183 -0
  2. package/dist/client/assets/index-DRbCnCbk.css +1 -0
  3. package/dist/client/index.html +2 -2
  4. package/dist/server/server/composition.contracts.js +976 -0
  5. package/dist/server/server/composition.js +330 -57
  6. package/dist/server/server/features/autopilot/application/service.js +18 -1
  7. package/dist/server/server/features/plans/application/org-plan-launch-store.js +6 -0
  8. package/dist/server/server/features/plans/application/prepare-org-plan-settings.js +66 -0
  9. package/dist/server/server/features/plans/application/prepare-org-plan-supervision.js +86 -0
  10. package/dist/server/server/features/plans/application/start-org-plan-supervision.js +323 -0
  11. package/dist/server/server/features/plans/execute-plan/endpoint.js +27 -0
  12. package/dist/server/server/features/plans/get-workspace-plan/endpoint.js +2 -1
  13. package/dist/server/server/features/plans/open-plan/endpoint.js +2 -1
  14. package/dist/server/server/features/plans/prepare-supervision/endpoint.js +52 -0
  15. package/dist/server/server/features/plans/register-routes.js +6 -0
  16. package/dist/server/server/features/sessions/application/resolve-session-skills.js +35 -0
  17. package/dist/server/server/features/sessions/application/start-settings.js +2 -1
  18. package/dist/server/server/features/sessions/register-routes.js +1 -0
  19. package/dist/server/server/features/sessions/start-session/endpoint.js +5 -0
  20. package/dist/server/server/features/sessions/start-session/use-case.js +7 -32
  21. package/dist/server/server/features/sessions/start-turn/endpoint.js +9 -167
  22. package/dist/server/server/features/sessions/start-turn/use-case.js +243 -0
  23. package/dist/server/server/features/skills/application/read-global-profiles.js +34 -0
  24. package/dist/server/server/features/skills/list-profiles/endpoint.js +9 -33
  25. package/dist/server/server/platform/catalog/filesystem-workspace-catalog.js +11 -0
  26. package/dist/server/server/platform/codex/session-runtime.js +20 -6
  27. package/dist/server/server/platform/persistence/migrate.js +12 -0
  28. package/dist/server/server/platform/persistence/sqlite-org-plan-launch-store.js +215 -0
  29. package/dist/server/server/platform/plans/filesystem-org-plan-context.js +99 -0
  30. package/dist/server/server/platform/plans/filesystem-workspace-plan-catalog.js +36 -3
  31. package/dist/server/shared/contracts/org-plan-execution.js +46 -0
  32. package/dist/server/shared/contracts/session-defaults.js +33 -3
  33. package/package.json +1 -1
  34. package/dist/client/assets/index-DcXYn8rY.js +0 -128
  35. package/dist/client/assets/index-DxsD-jG4.css +0 -1
@@ -0,0 +1,86 @@
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 { assessModelPolicyAdmission } from '../domain/model-policy-admission.js';
7
+ /** Read-only admission: no session creation, turn submission or activating attachment ports. */
8
+ export async function prepareOrgPlanSupervision(reference, deps, expectedRevision, skillProfile) {
9
+ const blocked = (code, reason) => ({ kind: 'blocked', code, reason });
10
+ const changed = () => blocked('CONTEXT_CHANGED', 'The plan file or project context changed. Refresh the plan and confirm again.');
11
+ let resolved;
12
+ try {
13
+ resolved = await deps.resolveReference(reference);
14
+ }
15
+ catch {
16
+ resolved = null;
17
+ }
18
+ if (!resolved && expectedRevision)
19
+ return changed();
20
+ if (!resolved)
21
+ return blocked('REFERENCE_UNAVAILABLE', 'The plan workspace or session is no longer available.');
22
+ let file;
23
+ try {
24
+ file = await deps.read(resolved.workspacePath, resolved.planName);
25
+ }
26
+ catch {
27
+ if (expectedRevision)
28
+ return changed();
29
+ return blocked('PLAN_UNREADABLE', 'The plan cannot be read safely.');
30
+ }
31
+ if (file.kind !== 'available' && expectedRevision)
32
+ return changed();
33
+ if (file.kind === 'missing')
34
+ return blocked('PLAN_NOT_FOUND', 'The plan file no longer exists.');
35
+ if (file.kind === 'unavailable')
36
+ return blocked('PLAN_UNREADABLE', 'The plan cannot be read safely.');
37
+ if (file.kind === 'invalid')
38
+ return blocked('INVALID_PLAN', `This Org document is not a valid Gestalt plan (${file.reason}).`);
39
+ let context;
40
+ try {
41
+ context = await deps.workspace(file.canonicalPath, file.revision);
42
+ }
43
+ catch {
44
+ context = null;
45
+ }
46
+ if (!context)
47
+ return expectedRevision
48
+ ? changed()
49
+ : blocked('WORKSPACE_UNAVAILABLE', 'The plan has no permitted project workspace.');
50
+ if (expectedRevision && context.revision !== expectedRevision)
51
+ return changed();
52
+ if (file.plan.executionComplete)
53
+ return blocked('NO_REMAINING_WORK', 'Every plan step is complete and reviewed.');
54
+ const policy = deps.policy(file.plan);
55
+ if (!policy.allowed)
56
+ return blocked('MODEL_POLICY_UNAVAILABLE', policy.action);
57
+ try {
58
+ const owner = await deps.owner(file.canonicalPath);
59
+ if (owner)
60
+ return {
61
+ kind: 'blocked',
62
+ code: 'ACTIVE_SUPERVISION',
63
+ reason: 'This plan already has a supervisor. Open its session to continue or recover it.',
64
+ ...(owner.sessionId ? { existingSessionId: owner.sessionId } : {}),
65
+ };
66
+ if (!(await deps.runtimeAvailable()))
67
+ return blocked('CODEX_UNAVAILABLE', 'Codex supervision is currently unavailable.');
68
+ }
69
+ catch {
70
+ return blocked('CODEX_UNAVAILABLE', 'Supervision availability could not be verified. Retry after refreshing.');
71
+ }
72
+ const settings = await deps.settings(context.workspace.path, skillProfile);
73
+ if (settings.kind !== 'available')
74
+ return blocked(settings.code, settings.reason);
75
+ return {
76
+ kind: 'eligible',
77
+ reference,
78
+ title: file.plan.title,
79
+ sourcePath: file.canonicalPath,
80
+ workspace: context.workspace,
81
+ revision: context.revision,
82
+ settings: settings.settings,
83
+ skillProfiles: settings.skillProfiles,
84
+ warnings: settings.warnings,
85
+ };
86
+ }
@@ -0,0 +1,323 @@
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 { orgPlanLaunchRequestSchema, } from '../../../../shared/contracts/org-plan-execution.js';
8
+ import { fingerprintTurnInput, } from '../../sessions/start-turn/use-case.js';
9
+ /** One public application boundary, including durable ownership and retry rules. */
10
+ export async function startOrgPlanSupervision(request, deps) {
11
+ const parsed = orgPlanLaunchRequestSchema.safeParse(request);
12
+ if (!parsed.success)
13
+ return {
14
+ kind: 'rejected',
15
+ code: 'INVALID_LAUNCH_REQUEST',
16
+ reason: 'Confirm a valid plan and launch identity.',
17
+ };
18
+ const input = parsed.data;
19
+ const reference = input.reference;
20
+ const fingerprint = createHash('sha256')
21
+ .update(JSON.stringify([
22
+ reference.kind,
23
+ reference.kind === 'workspace' ? reference.workspaceId : reference.sessionId,
24
+ reference.kind === 'retained-session' ? null : reference.planName,
25
+ input.expectedRevision,
26
+ input.skillProfile ?? null,
27
+ ]))
28
+ .digest('hex');
29
+ let record = deps.launches.find(input.launchId);
30
+ let preparedHere = false;
31
+ if (record) {
32
+ if (!(await deps.authorizeReplay(record)))
33
+ return unavailable();
34
+ if (record.requestFingerprint !== fingerprint)
35
+ return conflict();
36
+ }
37
+ else {
38
+ const context = await deps.prepare(reference, input.expectedRevision, input.skillProfile);
39
+ if (context.kind === 'blocked') {
40
+ // Another delivery can reserve/attach while this delivery is preparing.
41
+ // Records are retained, so one bounded re-entry takes the replay path.
42
+ return deps.launches.find(input.launchId) ? startOrgPlanSupervision(input, deps) : context;
43
+ }
44
+ let skillSelection;
45
+ try {
46
+ skillSelection = await deps.captureSkills(context);
47
+ }
48
+ catch {
49
+ return {
50
+ kind: 'blocked',
51
+ code: 'SKILL_PROFILE_UNAVAILABLE',
52
+ reason: 'Supervisor skills changed or could not be read. Refresh and confirm again.',
53
+ };
54
+ }
55
+ if (!skillSelection.skills.some((skill) => skill.name === 'gestalt:org-plan' && skill.enabled))
56
+ return {
57
+ kind: 'blocked',
58
+ code: 'GESTALT_CAPABILITIES_UNAVAILABLE',
59
+ reason: 'The Org-plan skill changed before launch. Refresh and confirm again.',
60
+ };
61
+ deps.reclaimForgottenOwner?.(context.sourcePath);
62
+ const reservation = deps.launches.reserve({
63
+ launchId: input.launchId,
64
+ requestFingerprint: fingerprint,
65
+ sessionId: deps.createId(),
66
+ canonicalPath: context.sourcePath,
67
+ context,
68
+ skillSelection,
69
+ phase: 'reserved',
70
+ bootstrapFingerprint: fingerprintTurnInput(supervisionRequest(context.sourcePath)),
71
+ });
72
+ record = reservation.record;
73
+ preparedHere = reservation.kind === 'reserved';
74
+ if (reservation.kind === 'owned')
75
+ return {
76
+ kind: 'blocked',
77
+ code: 'ACTIVE_SUPERVISION',
78
+ reason: 'This plan already has a supervisor launch. Open its session to continue or recover it.',
79
+ ...(deps.sessions.find(record.sessionId) ? { existingSessionId: record.sessionId } : {}),
80
+ };
81
+ if (record.requestFingerprint !== fingerprint)
82
+ return conflict();
83
+ }
84
+ return deps.launches.run(input.launchId, async () => {
85
+ const current = deps.launches.find(input.launchId);
86
+ if (!(await deps.authorizeReplay(current)))
87
+ return unavailable();
88
+ if (current.requestFingerprint !== fingerprint)
89
+ return conflict();
90
+ if (!preparedHere &&
91
+ !deps.sessions.find(current.sessionId) &&
92
+ ['reserved', 'creating'].includes(current.phase)) {
93
+ const validation = await revalidateUnpublished(input, current, deps);
94
+ if (validation)
95
+ return validation;
96
+ }
97
+ return continueLaunch(deps.launches.find(current.launchId) ?? current, deps);
98
+ });
99
+ }
100
+ async function continueLaunch(record, deps) {
101
+ if (deps.sessions.unavailable?.(record.sessionId))
102
+ return unavailable();
103
+ let session = deps.sessions.find(record.sessionId);
104
+ if (record.bootstrap) {
105
+ return session
106
+ ? { kind: 'started', launchId: record.launchId, session, bootstrap: record.bootstrap }
107
+ : unavailable();
108
+ }
109
+ if (record.phase === 'submitting') {
110
+ const receipt = deps.acceptedTurn?.(record);
111
+ if (receipt?.activeTurnId && session) {
112
+ const bootstrap = {
113
+ kind: 'accepted',
114
+ requestId: `org-plan-bootstrap:${record.launchId}`,
115
+ turnId: receipt.activeTurnId,
116
+ };
117
+ deps.launches.save({ ...record, phase: 'accepted', bootstrap }, 'submitting');
118
+ deps.onSettled?.(session.id);
119
+ return { kind: 'started', launchId: record.launchId, session, bootstrap };
120
+ }
121
+ return session
122
+ ? partial(record, session, 'bootstrap', record.manualRecoveryTurnId
123
+ ? 'Bootstrap acceptance remains unconfirmed. You continued through ordinary Chat; Execute will not repeat the bootstrap.'
124
+ : 'Bootstrap acceptance is uncertain. Inspect history and send explicit recovery guidance in ordinary Chat; Execute will not repeat the bootstrap.')
125
+ : pending(record, deps, 'bootstrap');
126
+ }
127
+ if (record.phase === 'reserved' && session) {
128
+ deps.launches.save({ ...record, phase: 'session' }, 'reserved');
129
+ record = deps.launches.find(record.launchId);
130
+ }
131
+ if ((record.phase === 'reserved' || record.phase === 'creating') && !session) {
132
+ if (record.notPersisted && !deps.launches.acquireOwner(record)) {
133
+ const owner = deps.launches.owner(record.canonicalPath);
134
+ return {
135
+ kind: 'blocked',
136
+ code: 'ACTIVE_SUPERVISION',
137
+ reason: 'Another launch now owns this plan.',
138
+ ...(owner && deps.sessions.find(owner.sessionId)
139
+ ? { existingSessionId: owner.sessionId }
140
+ : {}),
141
+ };
142
+ }
143
+ if (record.phase === 'reserved' &&
144
+ !deps.launches.save({ ...record, phase: 'creating' }, 'reserved'))
145
+ return pending(record, deps, 'activation');
146
+ record = { ...record, phase: 'creating' };
147
+ try {
148
+ session = await deps.sessions.create(record.sessionId, record.context, record.skillSelection, record);
149
+ }
150
+ catch (error) {
151
+ session = deps.sessions.find(record.sessionId);
152
+ if (session)
153
+ deps.launches.save({ ...record, phase: 'session' }, 'creating');
154
+ else if (error instanceof OrgPlanSessionNotPublished) {
155
+ deps.launches.revokePublication(record, deps.sessions);
156
+ }
157
+ return session
158
+ ? partial(record, session, 'activation', 'The session was saved but could not start. Open it to recover.')
159
+ : {
160
+ kind: 'blocked',
161
+ code: 'CODEX_UNAVAILABLE',
162
+ reason: 'The supervisor session could not be saved. Retry after refreshing.',
163
+ };
164
+ }
165
+ deps.launches.save({ ...record, phase: 'session' }, 'creating');
166
+ record = deps.launches.find(record.launchId) ?? { ...record, phase: 'session' };
167
+ }
168
+ if (record.bootstrap && session)
169
+ return {
170
+ kind: 'started',
171
+ launchId: record.launchId,
172
+ session: deps.sessions.find(session.id) ?? session,
173
+ bootstrap: record.bootstrap,
174
+ };
175
+ if (!session)
176
+ return pending(record, deps, 'activation');
177
+ if (session.desiredState === 'active' &&
178
+ ['starting', 'recovering', 'ready'].includes(session.state) &&
179
+ deps.sessions.recover &&
180
+ (record.phase === 'creating' || session.state !== 'ready')) {
181
+ try {
182
+ const recovered = await deps.sessions.recover(session);
183
+ if (recovered) {
184
+ session = recovered;
185
+ deps.launches.save({ ...record, phase: 'session' }, record.phase);
186
+ record = { ...record, phase: 'session' };
187
+ }
188
+ }
189
+ catch {
190
+ return partial(record, deps.sessions.find(session.id) ?? session, 'activation', 'This session could not acquire its ordinary writer. Open it to recover without starting another session.');
191
+ }
192
+ }
193
+ if (deps.sessions.unavailable?.(record.sessionId))
194
+ return unavailable();
195
+ session = deps.sessions.find(record.sessionId);
196
+ if (!session)
197
+ return pending(record, deps, 'activation');
198
+ if (record.phase === 'creating' || session.state !== 'ready' || session.desiredState !== 'active')
199
+ return partial(record, session, 'activation', 'This existing session is not ready. Use its ordinary session controls to recover.');
200
+ if (!deps.launches.save({ ...record, phase: 'submitting' }, 'session'))
201
+ return pending(record, deps, 'bootstrap');
202
+ const requestId = `org-plan-bootstrap:${record.launchId}`;
203
+ try {
204
+ const turn = await deps.submitTurn({
205
+ sessionId: session.id,
206
+ text: supervisionRequest(record.canonicalPath),
207
+ key: requestId,
208
+ });
209
+ if (turn.kind === 'accepted' && turn.session.activeTurnId) {
210
+ const bootstrap = { kind: 'accepted', requestId, turnId: turn.session.activeTurnId };
211
+ deps.launches.save({ ...record, phase: 'accepted', bootstrap }, 'submitting');
212
+ deps.onSettled?.(session.id);
213
+ const currentSession = deps.sessions.find(session.id);
214
+ if (!currentSession || deps.sessions.unavailable?.(session.id))
215
+ return unavailable();
216
+ return {
217
+ kind: 'started',
218
+ launchId: record.launchId,
219
+ session: currentSession,
220
+ bootstrap,
221
+ };
222
+ }
223
+ // A definitive ordinary rejection has not accepted a turn and can be retried safely.
224
+ deps.launches.save({ ...record, phase: 'session' }, 'submitting');
225
+ }
226
+ catch {
227
+ // Retain the durable submitting fence: transport failure may hide accepted work.
228
+ }
229
+ return partial(record, deps.sessions.find(session.id) ?? session, 'bootstrap', 'The session is available, but its supervision request was not confirmed. Open it to recover.');
230
+ }
231
+ /** Only a completed ordinary create call with proof it never entered publication may use this. */
232
+ export class OrgPlanSessionNotPublished extends Error {
233
+ constructor() {
234
+ super('ORG_PLAN_SESSION_NOT_PUBLISHED');
235
+ }
236
+ }
237
+ async function revalidateUnpublished(input, record, deps) {
238
+ const fresh = await deps.prepare(input.reference, input.expectedRevision, input.skillProfile, record.launchId);
239
+ let blocked = fresh.kind === 'blocked' ? fresh : null;
240
+ if (fresh.kind === 'eligible') {
241
+ try {
242
+ const skills = await deps.captureSkills(fresh);
243
+ if (fresh.sourcePath !== record.canonicalPath ||
244
+ fresh.revision !== record.context.revision ||
245
+ fresh.workspace.id !== record.context.workspace.id ||
246
+ fresh.workspace.path !== record.context.workspace.path ||
247
+ stableJSON(fresh.settings) !== stableJSON(record.context.settings) ||
248
+ stableJSON(skills) !== stableJSON(record.skillSelection))
249
+ blocked = {
250
+ kind: 'blocked',
251
+ code: 'CONTEXT_CHANGED',
252
+ reason: 'The never-published launch context or defaults changed. Refresh and confirm a new launch intent.',
253
+ };
254
+ }
255
+ catch {
256
+ blocked = {
257
+ kind: 'blocked',
258
+ code: 'SKILL_PROFILE_UNAVAILABLE',
259
+ reason: 'Supervisor skills changed. Refresh and confirm again.',
260
+ };
261
+ }
262
+ }
263
+ if (blocked) {
264
+ // Revocation fences any delayed publisher; absence alone is never death proof.
265
+ if (!deps.launches.revokePublication(record, deps.sessions) &&
266
+ deps.sessions.find(record.sessionId))
267
+ return null;
268
+ return blocked;
269
+ }
270
+ return null;
271
+ }
272
+ function stableJSON(value) {
273
+ const sorted = (item) => Array.isArray(item)
274
+ ? item.map(sorted)
275
+ : item && typeof item === 'object'
276
+ ? Object.fromEntries(Object.entries(item)
277
+ .sort(([a], [b]) => a.localeCompare(b))
278
+ .map(([key, entry]) => [key, sorted(entry)]))
279
+ : item;
280
+ return JSON.stringify(sorted(value));
281
+ }
282
+ function partial(record, session, stage, reason) {
283
+ return {
284
+ kind: 'partial',
285
+ launchId: record.launchId,
286
+ session,
287
+ bootstrap: { kind: 'pending' },
288
+ stage,
289
+ reason,
290
+ };
291
+ }
292
+ function pending(record, deps, stage) {
293
+ const session = deps.sessions.find(record.sessionId);
294
+ return session
295
+ ? partial(record, session, stage, 'The existing launch is still being resolved. Open its session to recover.')
296
+ : {
297
+ kind: 'blocked',
298
+ code: 'CODEX_UNAVAILABLE',
299
+ reason: 'The launch is reserved but session publication is not confirmed. Retry the same launch identity.',
300
+ };
301
+ }
302
+ function unavailable() {
303
+ return {
304
+ kind: 'blocked',
305
+ code: 'REFERENCE_UNAVAILABLE',
306
+ reason: 'The original session or permitted workspace is no longer available. Refresh before starting another launch.',
307
+ };
308
+ }
309
+ function conflict() {
310
+ return {
311
+ kind: 'rejected',
312
+ code: 'LAUNCH_CONFLICT',
313
+ reason: 'This launch identity was already used with different confirmed inputs.',
314
+ };
315
+ }
316
+ function supervisionRequest(canonicalPath) {
317
+ return [
318
+ 'Use $gestalt:org-plan to load and supervise this exact Org plan:',
319
+ JSON.stringify(canonicalPath),
320
+ 'Follow the complete supervised execution workflow: single writer per milestone, required skill loading, focused tests, independent review and acceptance, one conventional commit per accepted milestone, checkpoints, and terminal whole-branch review.',
321
+ 'Preserve the plan progress and model policy, Manual Off, attention, permissions, sandbox and approval gates. The normal supervisor plan-loading and real helper supervision-start publication establish attachment and continuation.',
322
+ ].join('\n');
323
+ }
@@ -0,0 +1,27 @@
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 { orgPlanLaunchRequestSchema, } from '../../../../shared/contracts/org-plan-execution.js';
7
+ export function registerExecuteOrgPlan(app, deps) {
8
+ app.post('/api/plans/execute', async (request, reply) => {
9
+ const parsed = orgPlanLaunchRequestSchema.safeParse(request.body);
10
+ if (!parsed.success)
11
+ return reply.code(400).send({
12
+ kind: 'rejected',
13
+ code: 'INVALID_LAUNCH_REQUEST',
14
+ reason: 'Confirm a valid plan and launch identity.',
15
+ });
16
+ const result = await deps.startOrgPlanSupervision(parsed.data);
17
+ const status = result.kind === 'rejected'
18
+ ? result.code === 'LAUNCH_CONFLICT'
19
+ ? 409
20
+ : 400
21
+ : result.kind === 'blocked' &&
22
+ ['CONTEXT_CHANGED', 'ACTIVE_SUPERVISION'].includes(result.code)
23
+ ? 409
24
+ : 200;
25
+ return reply.code(status).send(result);
26
+ });
27
+ }
@@ -9,13 +9,14 @@ export function registerGetWorkspacePlan(app, deps) {
9
9
  const workspace = await deps.workspaces.resolve(request.params.workspaceId);
10
10
  const result = await deps.plans.read(workspace.realPath, request.params.planName);
11
11
  if (result.kind === 'available')
12
- return reply.send(result.plan);
12
+ return reply.send({ ...result.plan, sourcePath: result.sourcePath });
13
13
  if (result.kind === 'source')
14
14
  return reply.send({
15
15
  kind: 'org-source',
16
16
  planName: request.params.planName,
17
17
  title: result.title,
18
18
  source: result.source,
19
+ sourcePath: result.sourcePath,
19
20
  });
20
21
  if (result.kind === 'missing')
21
22
  return reply.code(404).send({ code: 'PLAN_NOT_FOUND' });
@@ -14,13 +14,14 @@ export function registerOpenPlan(app, deps) {
14
14
  try {
15
15
  const result = await deps.open(sessionId, planName);
16
16
  if (result.kind === 'available')
17
- return reply.send(result.plan);
17
+ return reply.send({ ...result.plan, sourcePath: result.sourcePath });
18
18
  if (result.kind === 'source')
19
19
  return reply.send({
20
20
  kind: 'org-source',
21
21
  planName,
22
22
  title: result.title,
23
23
  source: result.source,
24
+ sourcePath: result.sourcePath,
24
25
  });
25
26
  if (result.kind === 'missing')
26
27
  return reply.code(404).send({ code: 'PLAN_NOT_FOUND' });
@@ -0,0 +1,52 @@
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
+ export function registerPrepareOrgPlanSupervision(app, deps) {
7
+ app.post('/api/plans/prepare', async (request, reply) => {
8
+ const reference = parseReference(request.body);
9
+ if (!reference)
10
+ return reply.code(400).send({ code: 'PLAN_REFERENCE_REQUIRED' });
11
+ const expectedRevision = request.body.expectedRevision;
12
+ const skillProfile = request.body.skillProfile;
13
+ const result = skillProfile !== undefined
14
+ ? await deps.prepare(reference, expectedRevision, skillProfile)
15
+ : expectedRevision
16
+ ? await deps.prepare(reference, expectedRevision)
17
+ : await deps.prepare(reference);
18
+ return reply
19
+ .code(result.kind === 'blocked' && result.code === 'CONTEXT_CHANGED' ? 409 : 200)
20
+ .send(result);
21
+ });
22
+ }
23
+ function parseReference(value) {
24
+ if (!value || typeof value !== 'object')
25
+ return null;
26
+ const input = value;
27
+ if (input.skillProfile !== undefined &&
28
+ (typeof input.skillProfile !== 'string' || input.skillProfile.length > 256))
29
+ return null;
30
+ if (input.expectedRevision !== undefined &&
31
+ (typeof input.expectedRevision !== 'string' || !input.expectedRevision))
32
+ return null;
33
+ if (input.kind === 'retained-session') {
34
+ if (Object.keys(input).some((key) => !['kind', 'sessionId', 'expectedRevision', 'skillProfile'].includes(key)) ||
35
+ typeof input.sessionId !== 'string' ||
36
+ !input.sessionId)
37
+ return null;
38
+ return { kind: 'retained-session', sessionId: input.sessionId };
39
+ }
40
+ const idKey = input.kind === 'workspace' ? 'workspaceId' : input.kind === 'session' ? 'sessionId' : null;
41
+ if (!idKey ||
42
+ Object.keys(input).some((key) => !['kind', idKey, 'planName', 'expectedRevision', 'skillProfile'].includes(key)))
43
+ return null;
44
+ if (typeof input[idKey] !== 'string' ||
45
+ !input[idKey] ||
46
+ typeof input.planName !== 'string' ||
47
+ !input.planName)
48
+ return null;
49
+ return input.kind === 'workspace'
50
+ ? { kind: 'workspace', workspaceId: input[idKey], planName: input.planName }
51
+ : { kind: 'session', sessionId: input[idKey], planName: input.planName };
52
+ }
@@ -10,7 +10,13 @@ import { registerGetWorkspacePlan } from './get-workspace-plan/endpoint.js';
10
10
  import { registerListWorkspacePlans } from './list-workspace-plans/endpoint.js';
11
11
  import { registerOpenPlan } from './open-plan/endpoint.js';
12
12
  import { registerArchiveWorkspacePlan } from './archive-workspace-plan/endpoint.js';
13
+ import { registerPrepareOrgPlanSupervision } from './prepare-supervision/endpoint.js';
14
+ import { registerExecuteOrgPlan } from './execute-plan/endpoint.js';
13
15
  export function registerPlanRoutes(app, deps) {
16
+ if (deps.prepareOrgPlanRoutes)
17
+ registerPrepareOrgPlanSupervision(app, deps.prepareOrgPlanRoutes);
18
+ if (deps.executeOrgPlanRoutes)
19
+ registerExecuteOrgPlan(app, deps.executeOrgPlanRoutes);
14
20
  if (deps.planRoutes) {
15
21
  registerGetPlan(app, deps.planRoutes);
16
22
  registerClosePlan(app, deps.planRoutes);
@@ -0,0 +1,35 @@
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 { createEffectiveSkillSelection, } from '../model/relay-session.js';
7
+ import { reconcileSkillSelectionSnapshot, } from '../../skills/model/skill-profile.js';
8
+ import { SkillProfileError } from '../../skills/model/errors.js';
9
+ /** Same immutable profile/capability snapshot for ordinary starts and read-only preparation. */
10
+ export async function resolveSessionSkillSelection(input, deps) {
11
+ const selectedProfile = input.skillProfile
12
+ ? await deps.skillProfiles.readGlobalProfile(input.skillProfile)
13
+ : deps.defaultSkillProfile;
14
+ if (input.skillProfile && !selectedProfile)
15
+ throw new SkillProfileError('UNKNOWN_SKILL_PROFILE', 'The selected skill profile does not exist.');
16
+ const [projectProfile, catalog] = await Promise.all([
17
+ deps.skillProfiles.readWorkspaceDefault(input.workspacePath),
18
+ deps.skillCatalog(input.provider, input.profile).list(input.workspacePath),
19
+ ]);
20
+ const sourceProfile = selectedProfile ?? projectProfile;
21
+ const reconciled = reconcileSkillSelectionSnapshot(catalog.skills, sourceProfile?.skills);
22
+ return createEffectiveSkillSelection({
23
+ ...(sourceProfile?.capabilities ? { capabilities: sourceProfile.capabilities } : {}),
24
+ ...(selectedProfile ? { selectedProfileName: selectedProfile.name } : {}),
25
+ skills: [
26
+ ...reconciled.skills.map((skill) => ({
27
+ name: skill.name,
28
+ path: skill.path,
29
+ enabled: skill.enabled,
30
+ })),
31
+ ...reconciled.missing,
32
+ ],
33
+ ...(reconciled.warnings.length ? { warnings: reconciled.warnings } : {}),
34
+ });
35
+ }
@@ -3,5 +3,6 @@
3
3
  * Designed by Denis Roio <jaromil@dyne.org>
4
4
  * SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  */
6
+ import { newSessionFallback } from '../../../../shared/contracts/session-defaults.js';
6
7
  /** The relay's configured default, kept explicit so deployments can change it centrally later. */
7
- export const DEFAULT_SESSION_MODEL = 'gpt-5.6-terra';
8
+ export const DEFAULT_SESSION_MODEL = newSessionFallback.model;
@@ -117,6 +117,7 @@ export function registerSessionRoutes(app, deps) {
117
117
  save: sessions.save,
118
118
  onStarted: sessions.onTurnStarted,
119
119
  idempotency: sessions.idempotency,
120
+ submit: sessions.submitTurn,
120
121
  });
121
122
  if (sessions.models)
122
123
  registerSelectModel(app, {
@@ -30,6 +30,11 @@ export function registerStartSession(app, deps) {
30
30
  }
31
31
  catch (error) {
32
32
  deps.reportFailure?.('start-session', error);
33
+ if (error instanceof Error && error.message === 'CODEX_EXECUTOR_MODEL_UNAVAILABLE')
34
+ return reply
35
+ .code(400)
36
+ .type('application/problem+json')
37
+ .send(problem(error.message, 400, 'The executor model is unavailable in Codex. Choose an available model in New session settings and retry.', true));
33
38
  if (error instanceof Error &&
34
39
  (error.message.startsWith('SESSION_SCRATCH_') ||
35
40
  error.message.startsWith('SCRATCH_CLEANUP_')))
@@ -5,8 +5,8 @@
5
5
  */
6
6
  import { RelaySession, } from '../model/relay-session.js';
7
7
  import { DEFAULT_SESSION_MODEL } from '../application/start-settings.js';
8
- import { reconcileSkillSelectionSnapshot, } from '../../skills/model/skill-profile.js';
9
- import { SkillProfileError } from '../../skills/model/errors.js';
8
+ import { defaultProviderModel } from '../../../../shared/contracts/session-defaults.js';
9
+ import { resolveSessionSkillSelection } from '../application/resolve-session-skills.js';
10
10
  export async function startSession(input, deps) {
11
11
  // Codex launcher profiles select the app-server skill directory. Kimi owns
12
12
  // its isolated profile lifecycle, so it must not require a Codex launcher
@@ -22,42 +22,17 @@ export async function startSession(input, deps) {
22
22
  // An omitted model resolves to the provider's own default: the relay-wide
23
23
  // default when that provider serves it, otherwise the provider's first
24
24
  // available model, so a kimi request never inherits the codex default.
25
- model ??= models.includes(DEFAULT_SESSION_MODEL)
26
- ? DEFAULT_SESSION_MODEL
27
- : (models[0] ?? DEFAULT_SESSION_MODEL);
25
+ model ??= defaultProviderModel(input.provider, models);
28
26
  if (!models.includes(model))
29
27
  throw new Error(input.provider === 'codex' ? 'CODEX_MODEL_UNAVAILABLE' : 'KIMI_MODEL_UNAVAILABLE');
28
+ if (input.provider === 'codex' && input.executorModel && !models.includes(input.executorModel))
29
+ throw new Error('CODEX_EXECUTOR_MODEL_UNAVAILABLE');
30
30
  }
31
31
  else {
32
32
  model ??= DEFAULT_SESSION_MODEL;
33
33
  }
34
- let effectiveSkillSelection = deps.inheritedSkillSelection;
35
- if (!effectiveSkillSelection) {
36
- const selectedProfile = input.skillProfile
37
- ? await deps.skillProfiles.readGlobalProfile(input.skillProfile)
38
- : deps.defaultSkillProfile;
39
- if (input.skillProfile && !selectedProfile)
40
- throw new SkillProfileError('UNKNOWN_SKILL_PROFILE', 'The selected skill profile does not exist.');
41
- const [projectProfile, catalog] = await Promise.all([
42
- deps.skillProfiles.readWorkspaceDefault(workspace.realPath),
43
- deps.skillCatalog(input.provider, input.profile).list(workspace.realPath),
44
- ]);
45
- const sourceProfile = selectedProfile ?? projectProfile;
46
- const reconciledSkills = reconcileSkillSelectionSnapshot(catalog.skills, sourceProfile?.skills);
47
- effectiveSkillSelection = {
48
- ...(sourceProfile?.capabilities ? { capabilities: sourceProfile.capabilities } : {}),
49
- ...(selectedProfile ? { selectedProfileName: selectedProfile.name } : {}),
50
- skills: [
51
- ...reconciledSkills.skills.map((skill) => ({
52
- name: skill.name,
53
- path: skill.path,
54
- enabled: skill.enabled,
55
- })),
56
- ...reconciledSkills.missing,
57
- ],
58
- ...(reconciledSkills.warnings.length > 0 ? { warnings: reconciledSkills.warnings } : {}),
59
- };
60
- }
34
+ const effectiveSkillSelection = deps.inheritedSkillSelection ??
35
+ (await resolveSessionSkillSelection({ ...input, workspacePath: workspace.realPath }, deps));
61
36
  const branch = await deps.gitBranch?.(workspace.realPath);
62
37
  const session = RelaySession.create({
63
38
  id: deps.createId(),