gestalt-mobile 0.44.4 → 0.45.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 +6 -0
- package/dist/client/assets/index-Copi3ec4.css +1 -0
- package/dist/client/assets/index-UqpTKH1P.js +109 -0
- package/dist/client/index.html +2 -2
- package/dist/server/server/app.js +3 -0
- package/dist/server/server/composition.contracts.js +79 -0
- package/dist/server/server/composition.js +110 -0
- package/dist/server/server/features/control-plane-trace/export-trace.js +63 -2
- package/dist/server/server/features/self-debug/create-session.js +34 -0
- package/dist/server/server/features/self-debug/endpoint.js +81 -0
- package/dist/server/server/features/sessions/model/relay-session.js +1 -0
- package/dist/server/server/platform/persistence/migrate.js +2 -0
- package/dist/server/server/platform/persistence/sqlite-session-repository.js +5 -2
- package/dist/server/server/platform/self-debug/workspace.js +166 -0
- package/dist/server/shared/contracts/self-debug.js +33 -0
- package/package.json +1 -1
- package/dist/client/assets/index-DEVCzFB9.css +0 -1
- package/dist/client/assets/index-DYZT_mLU.js +0 -108
package/dist/client/index.html
CHANGED
|
@@ -16,8 +16,8 @@ SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
16
16
|
<link rel="icon" href="/icons/gestalt-mobile-192.png" />
|
|
17
17
|
<link rel="apple-touch-icon" href="/icons/gestalt-mobile-180.png" />
|
|
18
18
|
<title>Gestalt Mobile</title>
|
|
19
|
-
<script type="module" crossorigin src="/assets/index-
|
|
20
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
19
|
+
<script type="module" crossorigin src="/assets/index-UqpTKH1P.js"></script>
|
|
20
|
+
<link rel="stylesheet" crossorigin href="/assets/index-Copi3ec4.css">
|
|
21
21
|
</head>
|
|
22
22
|
<body>
|
|
23
23
|
<div id="app"></div>
|
|
@@ -20,6 +20,7 @@ import { registerAutopilotRoutes } from './features/autopilot/register-routes.js
|
|
|
20
20
|
import { registerFileRoutes } from './features/files/register-routes.js';
|
|
21
21
|
import { registerMaintenanceRoutes } from './features/maintenance/register-routes.js';
|
|
22
22
|
import { registerPwaRoutes } from './features/pwa/register-routes.js';
|
|
23
|
+
import { registerSelfDebug } from './features/self-debug/endpoint.js';
|
|
23
24
|
export async function buildApp(deps) {
|
|
24
25
|
// Keep the default boundary finite even when an endpoint forgot a narrower schema.
|
|
25
26
|
const app = fastify({ logger: false, bodyLimit: 1024 * 1024 });
|
|
@@ -47,6 +48,8 @@ export async function buildApp(deps) {
|
|
|
47
48
|
registerAuthRoutes(app, deps);
|
|
48
49
|
registerCatalogRoutes(app, { bootstrap: deps.bootstrap, sessionDefaults: deps.sessionDefaults });
|
|
49
50
|
registerSessionRoutes(app, deps);
|
|
51
|
+
if (deps.selfDebug)
|
|
52
|
+
registerSelfDebug(app, deps.selfDebug);
|
|
50
53
|
if (deps.autopilot)
|
|
51
54
|
registerAutopilotRoutes(app, deps.autopilot, deps.sessionRoutes?.idempotency, deps.sessionRoutes ? (id) => deps.sessionRoutes?.find(id)?.provider : undefined);
|
|
52
55
|
if (deps.orgPlanAttention)
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
6
|
import { once } from 'node:events';
|
|
7
|
+
import { execFile } from 'node:child_process';
|
|
8
|
+
import { promisify } from 'node:util';
|
|
7
9
|
import { createHash } from 'node:crypto';
|
|
8
10
|
import { mkdtemp, mkdir, rm, symlink, writeFile } from 'node:fs/promises';
|
|
9
11
|
import { DatabaseSync } from 'node:sqlite';
|
|
@@ -3506,6 +3508,83 @@ describe('production composition', () => {
|
|
|
3506
3508
|
});
|
|
3507
3509
|
});
|
|
3508
3510
|
describeCompositionConcern('sessions', () => {
|
|
3511
|
+
it('starts Self DEBUG as an independent root with the installed executor settings and persists its incident packet', async () => {
|
|
3512
|
+
const root = await mkdtemp(join(tmpdir(), 'gestalt-debug-root-'));
|
|
3513
|
+
const dataDir = await mkdtemp(join(tmpdir(), 'gestalt-debug-state-'));
|
|
3514
|
+
const homeDirectory = await mkdtemp(join(tmpdir(), 'gestalt-debug-home-'));
|
|
3515
|
+
ownTemporaryPaths(root, dataDir, homeDirectory);
|
|
3516
|
+
await mkdir(join(root, 'workspace'));
|
|
3517
|
+
const debugRoot = join(homeDirectory, '.gestalt', 'self-debug');
|
|
3518
|
+
await mkdir(debugRoot, { recursive: true });
|
|
3519
|
+
const exec = promisify(execFile);
|
|
3520
|
+
for (const name of ['gestalt', 'gestalt-mobile', 'gestalt-agents']) {
|
|
3521
|
+
await exec('git', ['init', join(debugRoot, name)]);
|
|
3522
|
+
await exec('git', [
|
|
3523
|
+
'-C',
|
|
3524
|
+
join(debugRoot, name),
|
|
3525
|
+
'remote',
|
|
3526
|
+
'add',
|
|
3527
|
+
'origin',
|
|
3528
|
+
`https://github.com/dyne/${name}.git`,
|
|
3529
|
+
]);
|
|
3530
|
+
}
|
|
3531
|
+
// Isolate the same profile path production resolves, including an explicit CODEX_HOME.
|
|
3532
|
+
const codexHome = join(homeDirectory, '.codex');
|
|
3533
|
+
vi.stubEnv('CODEX_HOME', codexHome);
|
|
3534
|
+
onTestFinished(() => {
|
|
3535
|
+
vi.unstubAllEnvs();
|
|
3536
|
+
});
|
|
3537
|
+
await mkdir(join(codexHome, 'agents'), { recursive: true });
|
|
3538
|
+
await writeFile(join(codexHome, 'agents', 'org-plan-executor.toml'), 'model = "configured-debug-model"\nmodel_reasoning_effort = "high"\n');
|
|
3539
|
+
const handles = [];
|
|
3540
|
+
const app = await composeAuthorizedApp({
|
|
3541
|
+
root,
|
|
3542
|
+
dataDir,
|
|
3543
|
+
homeDirectory,
|
|
3544
|
+
relyingParty,
|
|
3545
|
+
installedCodexVersion: 'codex-cli 0.144.3',
|
|
3546
|
+
startAppServers: true,
|
|
3547
|
+
launchAppServer: liveAppServer(handles),
|
|
3548
|
+
componentVersions: [{ id: 'codex', label: 'Codex', version: '0.144.3' }],
|
|
3549
|
+
sessionModelCatalog: { list: async () => ['gpt-5.6-terra', 'configured-debug-model'] },
|
|
3550
|
+
profiles: {
|
|
3551
|
+
list: async () => [],
|
|
3552
|
+
require: async () => ({ name: 'default', state: 'ok', status: 'ready' }),
|
|
3553
|
+
},
|
|
3554
|
+
});
|
|
3555
|
+
onTestFinished(() => app.close());
|
|
3556
|
+
const sourceId = await createComposedSession(app);
|
|
3557
|
+
await app.inject({ method: 'POST', url: `/api/sessions/${sourceId}/stop`, payload: {} });
|
|
3558
|
+
const confirmation = (await app.inject(`/api/sessions/${sourceId}/debug`)).json();
|
|
3559
|
+
expect(confirmation.context.mobileSession).toBe(sourceId);
|
|
3560
|
+
const response = await app.inject({
|
|
3561
|
+
method: 'POST',
|
|
3562
|
+
url: `/api/sessions/${sourceId}/debug`,
|
|
3563
|
+
payload: { confirmationId: confirmation.confirmationId },
|
|
3564
|
+
});
|
|
3565
|
+
expect(response.statusCode).toBe(202);
|
|
3566
|
+
const debug = response.json();
|
|
3567
|
+
expect(debug.id).not.toBe(sourceId);
|
|
3568
|
+
expect(debug.workspacePath).toBe(debugRoot);
|
|
3569
|
+
expect(debug.model).toBe('configured-debug-model');
|
|
3570
|
+
expect(debug.threadId).not.toBe(confirmation.context.codexThread);
|
|
3571
|
+
const request = handles
|
|
3572
|
+
.flatMap((handle) => handle.requests)
|
|
3573
|
+
.find((request) => request.method === 'turn/start' &&
|
|
3574
|
+
request.params.threadId === debug.threadId);
|
|
3575
|
+
expect(request?.params).toMatchObject({
|
|
3576
|
+
model: 'configured-debug-model',
|
|
3577
|
+
effort: 'high',
|
|
3578
|
+
input: [{ type: 'text', text: expect.stringContaining('User detected an error') }],
|
|
3579
|
+
});
|
|
3580
|
+
expect((await app.inject('/api/sessions'))
|
|
3581
|
+
.json()
|
|
3582
|
+
.find((session) => session.id === debug.id).selfDebug).toEqual(debug.selfDebug);
|
|
3583
|
+
expect((await app.inject(`/api/sessions/${debug.id}/debug/trace`)).json()).toMatchObject({
|
|
3584
|
+
context: confirmation.context,
|
|
3585
|
+
sourceAgent: { status: 'unavailable' },
|
|
3586
|
+
});
|
|
3587
|
+
});
|
|
3509
3588
|
it('does not resolve a Git operation target outside the configured root', async () => {
|
|
3510
3589
|
const root = await mkdtemp(join(tmpdir(), 'gestalt-mobile-root-'));
|
|
3511
3590
|
const outside = await mkdtemp(join(tmpdir(), 'gestalt-mobile-outside-'));
|
|
@@ -11,6 +11,9 @@ import { SessionModelConfig } from './platform/codex/session-model-config.js';
|
|
|
11
11
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
12
12
|
import { debuglog } from 'node:util';
|
|
13
13
|
import { buildApp } from './app.js';
|
|
14
|
+
import { SelfDebugWorkspace } from './platform/self-debug/workspace.js';
|
|
15
|
+
import { createSelfDebugSession } from './features/self-debug/create-session.js';
|
|
16
|
+
import { startSession } from './features/sessions/start-session/use-case.js';
|
|
14
17
|
import { FilesystemWorkspaceCatalog } from './platform/catalog/filesystem-workspace-catalog.js';
|
|
15
18
|
import { FilesystemWorkspaceFiles } from './platform/filesystem/filesystem-workspace-files.js';
|
|
16
19
|
import { protocolCompatibility } from './platform/codex/protocol-compatibility.js';
|
|
@@ -381,6 +384,8 @@ export async function composeRelayApp(options) {
|
|
|
381
384
|
options.onAutopilotCoordinator?.(autopilot);
|
|
382
385
|
const workspaces = new FilesystemWorkspaceCatalog(root);
|
|
383
386
|
const workspaceFiles = new FilesystemWorkspaceFiles();
|
|
387
|
+
const debugHome = options.homeDirectory ?? homedir();
|
|
388
|
+
const debugWorkspace = new SelfDebugWorkspace(join(debugHome, '.gestalt', 'self-debug'), join(process.env.CODEX_HOME ?? join(debugHome, '.codex'), 'agents', 'org-plan-executor.toml'), databasePath);
|
|
384
389
|
const homeDirectory = options.homeDirectory ?? homedir();
|
|
385
390
|
// Constructing the manager is cheap (no spawn until `ensure`); building it
|
|
386
391
|
// before the model catalog lets the catalog reuse the gestalt-owned servers.
|
|
@@ -1226,6 +1231,111 @@ export async function composeRelayApp(options) {
|
|
|
1226
1231
|
protocolCompatible: protocol.compatible,
|
|
1227
1232
|
providers: providerAvailability,
|
|
1228
1233
|
},
|
|
1234
|
+
selfDebug: runtime
|
|
1235
|
+
? {
|
|
1236
|
+
find: (id) => sessions.find(id),
|
|
1237
|
+
createId: randomUUID,
|
|
1238
|
+
now: () => new Date().toISOString(),
|
|
1239
|
+
context: (source) => {
|
|
1240
|
+
const control = autopilotStore.find(source.id);
|
|
1241
|
+
return {
|
|
1242
|
+
handoffTrace: control?.checkpoints?.activeHandoffId ?? null,
|
|
1243
|
+
control: control?.lastControlId ?? null,
|
|
1244
|
+
mobileSession: source.id,
|
|
1245
|
+
codexThread: source.provider === 'codex' ? source.threadId : null,
|
|
1246
|
+
sourceThread: source.threadId,
|
|
1247
|
+
provider: source.provider,
|
|
1248
|
+
capturedAt: new Date().toISOString(),
|
|
1249
|
+
versions: options.componentVersions ?? [],
|
|
1250
|
+
};
|
|
1251
|
+
},
|
|
1252
|
+
readTrace: (debug) => debugWorkspace.readTrace(debug),
|
|
1253
|
+
create: (context) => createSelfDebugSession(context, {
|
|
1254
|
+
createId: randomUUID,
|
|
1255
|
+
now: () => new Date().toISOString(),
|
|
1256
|
+
settings: async () => {
|
|
1257
|
+
const installed = await debugWorkspace.settings();
|
|
1258
|
+
const source = sessions.find(context.mobileSession);
|
|
1259
|
+
const defaults = await sessionDefaults.read();
|
|
1260
|
+
return {
|
|
1261
|
+
...installed,
|
|
1262
|
+
model: source?.modelSettings?.executorModel ??
|
|
1263
|
+
defaults?.executorModel ??
|
|
1264
|
+
installed.model,
|
|
1265
|
+
reasoningEffort: source?.modelSettings?.executorReasoningEffort ??
|
|
1266
|
+
defaults?.executorReasoningEffort ??
|
|
1267
|
+
installed.reasoningEffort,
|
|
1268
|
+
};
|
|
1269
|
+
},
|
|
1270
|
+
capture: async (id, capturedContext, agent) => {
|
|
1271
|
+
const captured = await debugWorkspace.capture(id, capturedContext, agent);
|
|
1272
|
+
return {
|
|
1273
|
+
...captured,
|
|
1274
|
+
absoluteTracePath: join(captured.root, captured.debug.tracePath),
|
|
1275
|
+
};
|
|
1276
|
+
},
|
|
1277
|
+
askSource: async (id, context, debug) => {
|
|
1278
|
+
const source = sessions.find(context.mobileSession);
|
|
1279
|
+
if (source && source.threadId === (context.sourceThread ?? context.codexThread))
|
|
1280
|
+
await debugWorkspace.askSource(id, source, debug, async (prompt) => {
|
|
1281
|
+
const sourceRuntime = ownerRuntime(source);
|
|
1282
|
+
// Never resume or replace the source writer merely to ask for diagnostics.
|
|
1283
|
+
if (!sourceRuntime?.ownsWriter(source.id))
|
|
1284
|
+
throw new Error('DEBUG_SOURCE_UNAVAILABLE');
|
|
1285
|
+
if (source.state === 'turnActive' && source.activeTurnId)
|
|
1286
|
+
await sourceRuntime.queueTurnInput(source, source.activeTurnId, prompt, `self-debug-${id}`);
|
|
1287
|
+
else if (source.state === 'ready') {
|
|
1288
|
+
const started = await sourceRuntime.startTurn(source, prompt, `self-debug-${id}`, new Date().toISOString());
|
|
1289
|
+
saveSession(started);
|
|
1290
|
+
activity.observe({
|
|
1291
|
+
sessionId: source.id,
|
|
1292
|
+
occurredAt: started.updatedAt,
|
|
1293
|
+
kind: 'turnStarted',
|
|
1294
|
+
threadId: started.threadId,
|
|
1295
|
+
turnId: started.activeTurnId,
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
else
|
|
1299
|
+
throw new Error('DEBUG_SOURCE_UNAVAILABLE');
|
|
1300
|
+
});
|
|
1301
|
+
},
|
|
1302
|
+
createSession: async (id, root, agent) => {
|
|
1303
|
+
await debugWorkspace.prepare();
|
|
1304
|
+
const debugCatalog = new FilesystemWorkspaceCatalog(root);
|
|
1305
|
+
const [workspace] = await debugCatalog.list();
|
|
1306
|
+
return startSession({
|
|
1307
|
+
workspaceId: workspace.id,
|
|
1308
|
+
profile: 'default',
|
|
1309
|
+
provider: 'codex',
|
|
1310
|
+
model: agent.model,
|
|
1311
|
+
reasoningEffort: agent.reasoningEffort,
|
|
1312
|
+
sandbox: 'workspace-git',
|
|
1313
|
+
approvalPolicy: 'never',
|
|
1314
|
+
}, {
|
|
1315
|
+
createId: () => id,
|
|
1316
|
+
now: () => new Date().toISOString(),
|
|
1317
|
+
save: saveSession,
|
|
1318
|
+
workspaces: debugCatalog,
|
|
1319
|
+
profiles: options.profiles,
|
|
1320
|
+
skillProfiles,
|
|
1321
|
+
skillCatalog,
|
|
1322
|
+
sessionModels,
|
|
1323
|
+
});
|
|
1324
|
+
},
|
|
1325
|
+
start: (session) => runtime.start(session, new Date().toISOString()),
|
|
1326
|
+
startTurn: (session, prompt, messageId) => runtime.startTurn(session, prompt, messageId, new Date().toISOString()),
|
|
1327
|
+
find: (id) => sessions.find(id),
|
|
1328
|
+
save: saveSession,
|
|
1329
|
+
onStarted: (session) => activity.observe({
|
|
1330
|
+
sessionId: session.id,
|
|
1331
|
+
occurredAt: session.updatedAt,
|
|
1332
|
+
kind: 'turnStarted',
|
|
1333
|
+
threadId: session.threadId,
|
|
1334
|
+
turnId: session.activeTurnId,
|
|
1335
|
+
}),
|
|
1336
|
+
}),
|
|
1337
|
+
}
|
|
1338
|
+
: undefined,
|
|
1229
1339
|
sessionRoutes: {
|
|
1230
1340
|
createId: randomUUID,
|
|
1231
1341
|
now: () => new Date().toISOString(),
|
|
@@ -5,6 +5,66 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { DatabaseSync } from 'node:sqlite';
|
|
7
7
|
const relevant = /^(?:org-plan\.|autopilot\.|agent\.activity\.|session\.status\.)/;
|
|
8
|
+
// Export structural telemetry only. Event types alone do not imply payload safety.
|
|
9
|
+
const diagnosticFields = new Set([
|
|
10
|
+
'traceId',
|
|
11
|
+
'handoffId',
|
|
12
|
+
'controlId',
|
|
13
|
+
'turnId',
|
|
14
|
+
'requestId',
|
|
15
|
+
'threadId',
|
|
16
|
+
'sessionId',
|
|
17
|
+
'generation',
|
|
18
|
+
'sequence',
|
|
19
|
+
'state',
|
|
20
|
+
'status',
|
|
21
|
+
'reason',
|
|
22
|
+
'code',
|
|
23
|
+
'enabled',
|
|
24
|
+
'requestedEnabled',
|
|
25
|
+
'desiredState',
|
|
26
|
+
'stopReason',
|
|
27
|
+
'failureCount',
|
|
28
|
+
'noProgressCount',
|
|
29
|
+
'canonicalPosition',
|
|
30
|
+
'taskPath',
|
|
31
|
+
'taskName',
|
|
32
|
+
'continuationGeneration',
|
|
33
|
+
'activeHandoffId',
|
|
34
|
+
'lastControlId',
|
|
35
|
+
'lastTurnId',
|
|
36
|
+
'confidence',
|
|
37
|
+
'observedAt',
|
|
38
|
+
'root',
|
|
39
|
+
'subagents',
|
|
40
|
+
'processes',
|
|
41
|
+
'aggregateSubagents',
|
|
42
|
+
'aggregateProcesses',
|
|
43
|
+
'kind',
|
|
44
|
+
'id',
|
|
45
|
+
'parentThreadId',
|
|
46
|
+
'running',
|
|
47
|
+
'completed',
|
|
48
|
+
'pending',
|
|
49
|
+
'count',
|
|
50
|
+
]);
|
|
51
|
+
export function redactDiagnosticPayload(value, depth = 0) {
|
|
52
|
+
if (depth > 8)
|
|
53
|
+
return null;
|
|
54
|
+
if (typeof value === 'string')
|
|
55
|
+
return value.length <= 200 && /^[a-zA-Z0-9_./:@+-]*$/.test(value) ? value : '[redacted]';
|
|
56
|
+
if (typeof value === 'number')
|
|
57
|
+
return Number.isFinite(value) ? value : null;
|
|
58
|
+
if (typeof value === 'boolean' || value === null)
|
|
59
|
+
return value;
|
|
60
|
+
if (Array.isArray(value))
|
|
61
|
+
return value.slice(0, 100).map((item) => redactDiagnosticPayload(item, depth + 1));
|
|
62
|
+
if (!value || typeof value !== 'object')
|
|
63
|
+
return null;
|
|
64
|
+
return Object.fromEntries(Object.entries(value)
|
|
65
|
+
.filter(([key]) => diagnosticFields.has(key))
|
|
66
|
+
.map(([key, item]) => [key, redactDiagnosticPayload(item, depth + 1)]));
|
|
67
|
+
}
|
|
8
68
|
function objectPayload(value) {
|
|
9
69
|
try {
|
|
10
70
|
const parsed = JSON.parse(value);
|
|
@@ -50,12 +110,13 @@ export function exportControlPlaneTrace(databasePath, sessionId, generatedAt = n
|
|
|
50
110
|
const database = new DatabaseSync(databasePath, { readOnly: true });
|
|
51
111
|
try {
|
|
52
112
|
const rows = database
|
|
53
|
-
.prepare(
|
|
113
|
+
.prepare("SELECT sequence,occurred_at,type,payload_json FROM session_events WHERE session_id = ? AND (type LIKE 'org-plan.%' OR type LIKE 'autopilot.%' OR type LIKE 'agent.activity.%' OR type LIKE 'session.status.%') ORDER BY sequence DESC LIMIT 5000")
|
|
54
114
|
.all(sessionId);
|
|
55
115
|
const events = rows
|
|
116
|
+
.reverse()
|
|
56
117
|
.filter((row) => relevant.test(row.type))
|
|
57
118
|
.map((row) => {
|
|
58
|
-
const payload = objectPayload(row.payload_json);
|
|
119
|
+
const payload = redactDiagnosticPayload(objectPayload(row.payload_json));
|
|
59
120
|
return {
|
|
60
121
|
sequence: row.sequence,
|
|
61
122
|
occurredAt: row.occurred_at,
|
|
@@ -0,0 +1,34 @@
|
|
|
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 { selfDebugPrompt, } from '../../../shared/contracts/self-debug.js';
|
|
7
|
+
import { RelaySession } from '../sessions/model/relay-session.js';
|
|
8
|
+
export async function createSelfDebugSession(context, deps) {
|
|
9
|
+
const id = deps.createId();
|
|
10
|
+
const agent = await deps.settings();
|
|
11
|
+
const captured = await deps.capture(id, context, agent);
|
|
12
|
+
// Diagnostic collection is best effort; source-agent failure never blocks the new root.
|
|
13
|
+
try {
|
|
14
|
+
await deps.askSource(id, context, captured.debug);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
/* Captured evidence remains sufficient to begin. */
|
|
18
|
+
}
|
|
19
|
+
let session = await deps.createSession(id, captured.root, agent);
|
|
20
|
+
session = { ...session, selfDebug: captured.debug };
|
|
21
|
+
deps.save(session);
|
|
22
|
+
try {
|
|
23
|
+
session = await deps.start(session);
|
|
24
|
+
deps.save(session);
|
|
25
|
+
session = await deps.startTurn(session, selfDebugPrompt(captured.debug, captured.absoluteTracePath), `self-debug-root-${id}`);
|
|
26
|
+
deps.save(session);
|
|
27
|
+
deps.onStarted(session);
|
|
28
|
+
return session;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
deps.save(RelaySession.rehydrate(deps.find(id) ?? session).requireAttention(deps.now()).snapshot);
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
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 { z } from 'zod';
|
|
7
|
+
import { problem } from '../../platform/http/problem.js';
|
|
8
|
+
const paramsSchema = z.object({ sessionId: z.string().min(1).max(200) });
|
|
9
|
+
const bodySchema = z.object({ confirmationId: z.string().min(1).max(200) }).strict();
|
|
10
|
+
/** A confirmation is bound to one existing thread; repeat submits share the same operation. */
|
|
11
|
+
export function registerSelfDebug(app, deps) {
|
|
12
|
+
const confirmations = new Map();
|
|
13
|
+
app.get('/api/sessions/:sessionId/debug', async (request, reply) => {
|
|
14
|
+
const parsed = paramsSchema.safeParse(request.params);
|
|
15
|
+
const source = parsed.success ? deps.find(parsed.data.sessionId) : null;
|
|
16
|
+
if (!source?.threadId)
|
|
17
|
+
return reply
|
|
18
|
+
.code(404)
|
|
19
|
+
.send(problem('DEBUG_SESSION_NOT_FOUND', 404, 'Select an existing Chat session.'));
|
|
20
|
+
const now = Date.parse(deps.now());
|
|
21
|
+
for (const [key, value] of confirmations)
|
|
22
|
+
if (value.expiresAt <= now)
|
|
23
|
+
confirmations.delete(key);
|
|
24
|
+
if (confirmations.size >= 100)
|
|
25
|
+
return reply
|
|
26
|
+
.code(429)
|
|
27
|
+
.send(problem('DEBUG_CONFIRMATION_LIMIT', 429, 'Too many pending debug requests. Try again shortly.'));
|
|
28
|
+
const confirmationId = deps.createId();
|
|
29
|
+
const context = deps.context(source);
|
|
30
|
+
confirmations.set(confirmationId, { context, expiresAt: now + 30 * 60 * 1000 });
|
|
31
|
+
return { confirmationId, context };
|
|
32
|
+
});
|
|
33
|
+
app.post('/api/sessions/:sessionId/debug', { bodyLimit: 1024 }, async (request, reply) => {
|
|
34
|
+
const params = paramsSchema.safeParse(request.params);
|
|
35
|
+
const body = bodySchema.safeParse(request.body);
|
|
36
|
+
const confirmation = body.success ? confirmations.get(body.data.confirmationId) : null;
|
|
37
|
+
if (!params.success ||
|
|
38
|
+
!confirmation ||
|
|
39
|
+
confirmation.context.mobileSession !== params.data.sessionId ||
|
|
40
|
+
confirmation.expiresAt <= Date.parse(deps.now()))
|
|
41
|
+
return reply
|
|
42
|
+
.code(409)
|
|
43
|
+
.send(problem('DEBUG_CONFIRMATION_EXPIRED', 409, 'Reopen DEBUG to confirm the current session details.'));
|
|
44
|
+
if (!confirmation.operation) {
|
|
45
|
+
const source = deps.find(params.data.sessionId);
|
|
46
|
+
if (!source ||
|
|
47
|
+
source.threadId !== (confirmation.context.sourceThread ?? confirmation.context.codexThread))
|
|
48
|
+
return reply
|
|
49
|
+
.code(409)
|
|
50
|
+
.send(problem('DEBUG_SOURCE_CHANGED', 409, 'The source session changed. Reopen DEBUG.'));
|
|
51
|
+
confirmation.operation = deps.create(confirmation.context);
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
return reply.code(202).send(await confirmation.operation);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Keep the rejected operation: a transport retry must never duplicate a partial session.
|
|
58
|
+
return reply
|
|
59
|
+
.code(503)
|
|
60
|
+
.send(problem('DEBUG_START_FAILED', 503, 'Self DEBUG could not start. Check Sessions for a saved debug session before trying again.'));
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
app.get('/api/sessions/:sessionId/debug/trace', async (request, reply) => {
|
|
64
|
+
const params = paramsSchema.safeParse(request.params);
|
|
65
|
+
const session = params.success ? deps.find(params.data.sessionId) : null;
|
|
66
|
+
if (!session?.selfDebug)
|
|
67
|
+
return reply
|
|
68
|
+
.code(404)
|
|
69
|
+
.send(problem('DEBUG_TRACE_NOT_FOUND', 404, 'This session has no diagnostic trace.'));
|
|
70
|
+
try {
|
|
71
|
+
return reply
|
|
72
|
+
.type('application/json; charset=utf-8')
|
|
73
|
+
.send(await deps.readTrace(session.selfDebug));
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return reply
|
|
77
|
+
.code(404)
|
|
78
|
+
.send(problem('DEBUG_TRACE_NOT_FOUND', 404, 'The diagnostic trace is no longer available.'));
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
@@ -175,6 +175,7 @@ function copy(snapshot) {
|
|
|
175
175
|
return {
|
|
176
176
|
...snapshot,
|
|
177
177
|
...(snapshot.modelSettings ? { modelSettings: { ...snapshot.modelSettings } } : {}),
|
|
178
|
+
...(snapshot.selfDebug ? { selfDebug: structuredClone(snapshot.selfDebug) } : {}),
|
|
178
179
|
...(snapshot.effectiveSkillSelection === undefined
|
|
179
180
|
? {}
|
|
180
181
|
: {
|
|
@@ -37,6 +37,8 @@ export function migrate(database) {
|
|
|
37
37
|
database.exec('ALTER TABLE relay_sessions ADD COLUMN last_org_plan_json TEXT');
|
|
38
38
|
if (!columns.some((column) => column.name === 'model_settings_json'))
|
|
39
39
|
database.exec('ALTER TABLE relay_sessions ADD COLUMN model_settings_json TEXT');
|
|
40
|
+
if (!columns.some((column) => column.name === 'self_debug_json'))
|
|
41
|
+
database.exec('ALTER TABLE relay_sessions ADD COLUMN self_debug_json TEXT');
|
|
40
42
|
if (!columns.some((column) => column.name === 'model'))
|
|
41
43
|
database.exec('ALTER TABLE relay_sessions ADD COLUMN model TEXT');
|
|
42
44
|
if (!columns.some((column) => column.name === 'branch'))
|
|
@@ -11,10 +11,10 @@ export class SqliteSessionRepository {
|
|
|
11
11
|
}
|
|
12
12
|
save(session) {
|
|
13
13
|
this.db
|
|
14
|
-
.prepare('INSERT INTO relay_sessions (id,workspace_id,workspace_path,provider,profile,model,branch,sandbox,approval_policy,thread_id,state,desired_state,active_turn_id,protocol_version,attention_tool_capability,failure_count,effective_skill_selection_json,last_org_plan_json,model_settings_json,created_at,updated_at) VALUES (
|
|
14
|
+
.prepare('INSERT INTO relay_sessions (id,workspace_id,workspace_path,provider,profile,model,branch,sandbox,approval_policy,thread_id,state,desired_state,active_turn_id,protocol_version,attention_tool_capability,failure_count,effective_skill_selection_json,last_org_plan_json,model_settings_json,self_debug_json,created_at,updated_at) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ON CONFLICT(id) DO UPDATE SET workspace_id=excluded.workspace_id,workspace_path=excluded.workspace_path,provider=excluded.provider,profile=excluded.profile,model=excluded.model,branch=excluded.branch,sandbox=excluded.sandbox,approval_policy=excluded.approval_policy,thread_id=excluded.thread_id,state=excluded.state,desired_state=excluded.desired_state,active_turn_id=excluded.active_turn_id,protocol_version=excluded.protocol_version,attention_tool_capability=excluded.attention_tool_capability,failure_count=excluded.failure_count,effective_skill_selection_json=excluded.effective_skill_selection_json,last_org_plan_json=excluded.last_org_plan_json,model_settings_json=excluded.model_settings_json,self_debug_json=excluded.self_debug_json,updated_at=excluded.updated_at')
|
|
15
15
|
.run(session.id, session.workspaceId, session.workspacePath, session.provider, session.profile, session.model ?? null, session.branch ?? null, session.executionPolicy?.sandbox ?? null, session.executionPolicy?.approvalPolicy ?? null, session.threadId, session.state, session.desiredState, session.activeTurnId, session.protocolVersion, session.attentionToolCapability ?? null, session.failureCount, session.effectiveSkillSelection === undefined
|
|
16
16
|
? null
|
|
17
|
-
: JSON.stringify(session.effectiveSkillSelection), session.lastOrgPlan === undefined ? null : JSON.stringify(session.lastOrgPlan), session.modelSettings === undefined ? null : JSON.stringify(session.modelSettings), session.createdAt, session.updatedAt);
|
|
17
|
+
: JSON.stringify(session.effectiveSkillSelection), session.lastOrgPlan === undefined ? null : JSON.stringify(session.lastOrgPlan), session.modelSettings === undefined ? null : JSON.stringify(session.modelSettings), session.selfDebug ? JSON.stringify(session.selfDebug) : null, session.createdAt, session.updatedAt);
|
|
18
18
|
}
|
|
19
19
|
find(id) {
|
|
20
20
|
const row = this.db.prepare('SELECT * FROM relay_sessions WHERE id = ?').get(id);
|
|
@@ -66,6 +66,9 @@ function map(row) {
|
|
|
66
66
|
failureCount: row.failure_count,
|
|
67
67
|
...(effectiveSkillSelection === undefined ? {} : { effectiveSkillSelection }),
|
|
68
68
|
...(lastOrgPlan === undefined ? {} : { lastOrgPlan }),
|
|
69
|
+
...(row.self_debug_json
|
|
70
|
+
? { selfDebug: JSON.parse(row.self_debug_json) }
|
|
71
|
+
: {}),
|
|
69
72
|
pendingInteractions: [],
|
|
70
73
|
createdAt: row.created_at,
|
|
71
74
|
updatedAt: row.updated_at,
|