gestalt-mobile 0.70.1 → 0.71.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/dist/client/assets/index-BOJci8Jh.css +1 -0
- package/dist/client/assets/index-Cb4qCgbe.js +183 -0
- package/dist/client/index.html +2 -2
- package/dist/server/server/composition.contracts.js +260 -3
- package/dist/server/server/composition.js +21 -7
- package/dist/server/server/features/agent-activity/activity-dto.js +1 -0
- package/dist/server/server/features/agent-activity/model.js +22 -0
- package/dist/server/server/features/agent-activity/registry.js +8 -0
- package/dist/server/server/features/sessions/application/writer-acquisition.js +1 -1
- package/dist/server/server/features/sessions/register-routes.js +3 -0
- package/dist/server/server/platform/codex/activity-facts.js +18 -0
- package/dist/server/server/platform/persistence/sqlite-org-plan-launch-store.js +5 -0
- package/dist/server/server/platform/persistence/sqlite-supervision-takeover-store.js +11 -2
- package/package.json +1 -1
- package/dist/client/assets/index-BKHQ4DeL.js +0 -183
- package/dist/client/assets/index-Bzd358yL.css +0 -1
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-Cb4qCgbe.js"></script>
|
|
20
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BOJci8Jh.css">
|
|
21
21
|
</head>
|
|
22
22
|
<body>
|
|
23
23
|
<div id="app"></div>
|
|
@@ -23,10 +23,12 @@ import { SqliteAuthorizationStore } from './platform/auth/sqlite-authorization-s
|
|
|
23
23
|
import { SqliteEventJournal } from './platform/persistence/sqlite-event-journal.js';
|
|
24
24
|
import { SqliteIdempotencyStore } from './platform/persistence/sqlite-idempotency-store.js';
|
|
25
25
|
import { SqliteOrgPlanLaunchStore } from './platform/persistence/sqlite-org-plan-launch-store.js';
|
|
26
|
+
import { SqliteSupervisionTakeoverStore } from './platform/persistence/sqlite-supervision-takeover-store.js';
|
|
26
27
|
import { SqliteSessionRepository } from './platform/persistence/sqlite-session-repository.js';
|
|
27
28
|
import { RelaySession } from './features/sessions/model/relay-session.js';
|
|
28
29
|
import { SqliteAutopilotStore } from './platform/persistence/sqlite-autopilot-store.js';
|
|
29
30
|
import { startSupervisionProtocol } from './features/autopilot/domain/supervision-protocol.js';
|
|
31
|
+
import { disabledAutopilot } from './features/autopilot/domain/autopilot-session.js';
|
|
30
32
|
import { exportControlPlaneTrace } from './features/control-plane-trace/export-trace.js';
|
|
31
33
|
import { authorizationSessionId, authorizedDeviceId, localOwnerId, webAuthnCredentialId, } from './features/auth/domain/identifiers.js';
|
|
32
34
|
import { deviceNickname } from './features/auth/domain/device-nickname.js';
|
|
@@ -481,6 +483,7 @@ async function orgPlanActivationFixture(installedCodexVersion = 'codex-cli 0.144
|
|
|
481
483
|
failThread: false,
|
|
482
484
|
initializationGate: null,
|
|
483
485
|
threadGate: null,
|
|
486
|
+
catalogGate: null,
|
|
484
487
|
held: null,
|
|
485
488
|
};
|
|
486
489
|
const open = () => composeAuthorizedApp({
|
|
@@ -537,7 +540,18 @@ async function orgPlanActivationFixture(installedCodexVersion = 'codex-cli 0.144
|
|
|
537
540
|
throw new Error('INJECTED_THREAD_RECEIPT_LOSS');
|
|
538
541
|
}
|
|
539
542
|
}
|
|
540
|
-
if (method === 'skills/list')
|
|
543
|
+
if (method === 'skills/list') {
|
|
544
|
+
const gate = !runtime && controls.catalogGate;
|
|
545
|
+
if (gate) {
|
|
546
|
+
controls.catalogGate = null;
|
|
547
|
+
controls.held = 'catalog';
|
|
548
|
+
try {
|
|
549
|
+
await gate;
|
|
550
|
+
}
|
|
551
|
+
finally {
|
|
552
|
+
controls.held = null;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
541
555
|
return {
|
|
542
556
|
data: [
|
|
543
557
|
{
|
|
@@ -554,6 +568,7 @@ async function orgPlanActivationFixture(installedCodexVersion = 'codex-cli 0.144
|
|
|
554
568
|
},
|
|
555
569
|
],
|
|
556
570
|
};
|
|
571
|
+
}
|
|
557
572
|
return undefined;
|
|
558
573
|
};
|
|
559
574
|
return server;
|
|
@@ -570,7 +585,12 @@ async function orgPlanActivationFixture(installedCodexVersion = 'codex-cli 0.144
|
|
|
570
585
|
planName: '.gestalt/activation.org',
|
|
571
586
|
};
|
|
572
587
|
const prepared = (await app.inject({ method: 'POST', url: '/api/plans/prepare', payload: reference })).json();
|
|
573
|
-
expect(prepared
|
|
588
|
+
expect(prepared, JSON.stringify({
|
|
589
|
+
kind: prepared.kind,
|
|
590
|
+
code: prepared.code,
|
|
591
|
+
reason: prepared.reason,
|
|
592
|
+
existingSessionId: prepared.existingSessionId,
|
|
593
|
+
})).toMatchObject({ kind: 'eligible' });
|
|
574
594
|
return {
|
|
575
595
|
reference,
|
|
576
596
|
expectedRevision: prepared.revision,
|
|
@@ -591,6 +611,66 @@ async function orgPlanActivationFixture(installedCodexVersion = 'codex-cli 0.144
|
|
|
591
611
|
}
|
|
592
612
|
describe('production composition', () => {
|
|
593
613
|
describeCompositionConcern('autopilot', () => {
|
|
614
|
+
it('shows child progress without notifying Autopilot or starting a supervisor turn', async () => {
|
|
615
|
+
let coordinator;
|
|
616
|
+
const fixture = await createProductionAutopilotFixture({
|
|
617
|
+
autopilotSchedule: () => () => { },
|
|
618
|
+
onAutopilotCoordinator: (value) => {
|
|
619
|
+
coordinator = value;
|
|
620
|
+
},
|
|
621
|
+
});
|
|
622
|
+
onTestFinished(() => fixture.app.close());
|
|
623
|
+
const session = (await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json();
|
|
624
|
+
const handle = fixture.handles.find((candidate) => candidate.calls.includes('thread/start'));
|
|
625
|
+
const notify = vi.spyOn(coordinator, 'activityChanged');
|
|
626
|
+
handle.notify({
|
|
627
|
+
method: 'item/started',
|
|
628
|
+
params: {
|
|
629
|
+
threadId: session.threadId,
|
|
630
|
+
item: {
|
|
631
|
+
id: 'spawn',
|
|
632
|
+
type: 'collabAgentToolCall',
|
|
633
|
+
tool: 'spawnAgent',
|
|
634
|
+
senderThreadId: session.threadId,
|
|
635
|
+
receiverThreadIds: ['progress-child'],
|
|
636
|
+
agentsStates: { 'progress-child': { status: 'running' } },
|
|
637
|
+
},
|
|
638
|
+
},
|
|
639
|
+
});
|
|
640
|
+
expect(notify).toHaveBeenCalled();
|
|
641
|
+
notify.mockClear();
|
|
642
|
+
const before = fixture.handles.flatMap((candidate) => candidate.requests).length;
|
|
643
|
+
handle.notify({
|
|
644
|
+
method: 'item/completed',
|
|
645
|
+
params: {
|
|
646
|
+
threadId: 'progress-child',
|
|
647
|
+
item: {
|
|
648
|
+
id: 'progress',
|
|
649
|
+
type: 'agentMessage',
|
|
650
|
+
phase: 'commentary',
|
|
651
|
+
text: 'Checking focused tests.',
|
|
652
|
+
},
|
|
653
|
+
},
|
|
654
|
+
});
|
|
655
|
+
const updated = (await fixture.app.inject(`/api/sessions/${fixture.sessionId}`)).json();
|
|
656
|
+
expect(updated.agentActivity.subagents).toContainEqual(expect.objectContaining({
|
|
657
|
+
id: 'progress-child',
|
|
658
|
+
latestProgress: {
|
|
659
|
+
text: 'Checking focused tests.',
|
|
660
|
+
occurredAt: expect.any(String),
|
|
661
|
+
},
|
|
662
|
+
}));
|
|
663
|
+
expect(notify).not.toHaveBeenCalled();
|
|
664
|
+
expect(fixture.handles.flatMap((candidate) => candidate.requests)).toHaveLength(before);
|
|
665
|
+
const database = new DatabaseSync(join(fixture.dataDir, 'relay.sqlite'));
|
|
666
|
+
onTestFinished(() => database.close());
|
|
667
|
+
const rows = database
|
|
668
|
+
.prepare('SELECT type, payload_json FROM session_events WHERE session_id = ? ORDER BY sequence DESC LIMIT 5')
|
|
669
|
+
.all(fixture.sessionId);
|
|
670
|
+
expect(rows[0]?.type).toBe('agent.activity.updated');
|
|
671
|
+
expect(rows.some((row) => row.type === 'agentMessageCompleted')).toBe(false);
|
|
672
|
+
expect(JSON.stringify(exportControlPlaneTrace(join(fixture.dataDir, 'relay.sqlite'), fixture.sessionId))).not.toContain('Checking focused tests.');
|
|
673
|
+
});
|
|
594
674
|
it('starts one root recovery after an executor wake encounters a superseded issued command', async () => {
|
|
595
675
|
const timers = [];
|
|
596
676
|
let coordinator;
|
|
@@ -6005,6 +6085,155 @@ describe('production composition', () => {
|
|
|
6005
6085
|
});
|
|
6006
6086
|
});
|
|
6007
6087
|
describeCompositionConcern('lifecycle', () => {
|
|
6088
|
+
it.each(['stop', 'release'])('releases supervisor reservations after %s while retaining history and scratch across restart', async (operation) => {
|
|
6089
|
+
const f = await orgPlanActivationFixture('codex-cli 0.167.0');
|
|
6090
|
+
let app = await f.open();
|
|
6091
|
+
try {
|
|
6092
|
+
const payload = await f.prepare(app);
|
|
6093
|
+
const launched = (await app.inject({ method: 'POST', url: '/api/plans/execute', payload })).json();
|
|
6094
|
+
expect(launched).toMatchObject({ kind: 'started' });
|
|
6095
|
+
const id = launched.session.id;
|
|
6096
|
+
const identity = f.database((db) => {
|
|
6097
|
+
const record = new SqliteOrgPlanLaunchStore(db).forSession(id);
|
|
6098
|
+
const identity = createHash('sha256').update(record.canonicalPath).digest('hex');
|
|
6099
|
+
new SqliteSupervisionTakeoverStore(db, new SqliteAutopilotStore(db)).claim(identity, id);
|
|
6100
|
+
return identity;
|
|
6101
|
+
});
|
|
6102
|
+
const marker = join(f.workspacePath, 'tmp', 'retained-on-close.txt');
|
|
6103
|
+
await writeFile(marker, 'keep');
|
|
6104
|
+
expect(f.database((db) => new SqliteOrgPlanLaunchStore(db).workspaceOwner(f.workspacePath)?.sessionId)).toBe(id);
|
|
6105
|
+
expect((await app.inject({ method: 'POST', url: `/api/sessions/${id}/${operation}` }))
|
|
6106
|
+
.statusCode).toBe(202);
|
|
6107
|
+
expect(f.database((db) => new SqliteOrgPlanLaunchStore(db).workspaceOwner(f.workspacePath))).toBeNull();
|
|
6108
|
+
expect(f.database((db) => new SqliteSupervisionTakeoverStore(db, new SqliteAutopilotStore(db)).owner(identity))).toBeNull();
|
|
6109
|
+
expect((await app.inject(`/api/sessions/${id}`)).statusCode).toBe(200);
|
|
6110
|
+
expect(await readFile(marker, 'utf8')).toBe('keep');
|
|
6111
|
+
await app.close();
|
|
6112
|
+
app = await f.open();
|
|
6113
|
+
const next = await createComposedSession(app);
|
|
6114
|
+
expect(next).not.toBe(id);
|
|
6115
|
+
expect((await app.inject({ method: 'POST', url: `/api/sessions/${next}/stop` })).statusCode).toBe(202);
|
|
6116
|
+
const prepared = (await app.inject({
|
|
6117
|
+
method: 'POST',
|
|
6118
|
+
url: '/api/plans/prepare',
|
|
6119
|
+
payload: payload.reference,
|
|
6120
|
+
})).json();
|
|
6121
|
+
expect(prepared).toMatchObject({ kind: 'eligible' });
|
|
6122
|
+
const restarted = (await app.inject({
|
|
6123
|
+
method: 'POST',
|
|
6124
|
+
url: '/api/plans/execute',
|
|
6125
|
+
payload: {
|
|
6126
|
+
...payload,
|
|
6127
|
+
expectedRevision: prepared.revision,
|
|
6128
|
+
launchId: `next-${operation}`,
|
|
6129
|
+
},
|
|
6130
|
+
})).json();
|
|
6131
|
+
expect(restarted).toMatchObject({ kind: 'started' });
|
|
6132
|
+
expect(restarted.session.id).not.toBe(id);
|
|
6133
|
+
}
|
|
6134
|
+
finally {
|
|
6135
|
+
await app.close();
|
|
6136
|
+
}
|
|
6137
|
+
});
|
|
6138
|
+
it('keeps the reservation until Close has confirmed runtime shutdown', async () => {
|
|
6139
|
+
const f = await orgPlanActivationFixture('codex-cli 0.167.0');
|
|
6140
|
+
const app = await f.open();
|
|
6141
|
+
const gate = Promise.withResolvers();
|
|
6142
|
+
const original = CodexSessionRuntime.prototype.releaseForForget;
|
|
6143
|
+
let pending;
|
|
6144
|
+
let held = false;
|
|
6145
|
+
const spy = vi
|
|
6146
|
+
.spyOn(CodexSessionRuntime.prototype, 'releaseForForget')
|
|
6147
|
+
.mockImplementationOnce(async function (session) {
|
|
6148
|
+
held = true;
|
|
6149
|
+
await gate.promise;
|
|
6150
|
+
return original.call(this, session);
|
|
6151
|
+
});
|
|
6152
|
+
try {
|
|
6153
|
+
const payload = await f.prepare(app);
|
|
6154
|
+
const launched = (await app.inject({ method: 'POST', url: '/api/plans/execute', payload })).json();
|
|
6155
|
+
expect(launched).toMatchObject({ kind: 'started' });
|
|
6156
|
+
const id = launched.session.id;
|
|
6157
|
+
pending = Promise.resolve(app.inject({ method: 'POST', url: `/api/sessions/${id}/release` }));
|
|
6158
|
+
await expect.poll(() => held, { timeout: 2_000 }).toBe(true);
|
|
6159
|
+
expect(f.database((db) => new SqliteOrgPlanLaunchStore(db).workspaceOwner(f.workspacePath)?.sessionId)).toBe(id);
|
|
6160
|
+
const blocked = await app.inject({
|
|
6161
|
+
method: 'POST',
|
|
6162
|
+
url: '/api/sessions',
|
|
6163
|
+
payload: {
|
|
6164
|
+
workspaceId: payload.reference.workspaceId,
|
|
6165
|
+
profile: 'default',
|
|
6166
|
+
provider: 'codex',
|
|
6167
|
+
},
|
|
6168
|
+
});
|
|
6169
|
+
expect(blocked.statusCode).toBe(409);
|
|
6170
|
+
expect(blocked.json()).toMatchObject({ code: 'SESSION_WORKSPACE_LOCKED' });
|
|
6171
|
+
gate.resolve();
|
|
6172
|
+
expect((await pending).statusCode).toBe(202);
|
|
6173
|
+
expect(await createComposedSession(app)).not.toBe(id);
|
|
6174
|
+
}
|
|
6175
|
+
finally {
|
|
6176
|
+
gate.resolve();
|
|
6177
|
+
await pending?.catch(() => undefined);
|
|
6178
|
+
spy.mockRestore();
|
|
6179
|
+
await app.close();
|
|
6180
|
+
}
|
|
6181
|
+
});
|
|
6182
|
+
it('retains reservations when Close cannot confirm runtime shutdown and releases them on retry', async () => {
|
|
6183
|
+
const f = await orgPlanActivationFixture('codex-cli 0.167.0');
|
|
6184
|
+
const app = await f.open();
|
|
6185
|
+
const spy = vi.spyOn(CodexSessionRuntime.prototype, 'releaseForForget');
|
|
6186
|
+
try {
|
|
6187
|
+
const payload = await f.prepare(app);
|
|
6188
|
+
const launched = (await app.inject({ method: 'POST', url: '/api/plans/execute', payload })).json();
|
|
6189
|
+
expect(launched).toMatchObject({ kind: 'started' });
|
|
6190
|
+
const id = launched.session.id;
|
|
6191
|
+
spy.mockRejectedValueOnce(new Error('SESSION_RELEASE_UNCONFIRMED'));
|
|
6192
|
+
expect((await app.inject({ method: 'POST', url: `/api/sessions/${id}/release` })).statusCode).toBe(500);
|
|
6193
|
+
expect(f.database((db) => new SqliteOrgPlanLaunchStore(db).workspaceOwner(f.workspacePath)?.sessionId)).toBe(id);
|
|
6194
|
+
expect((await app.inject({ method: 'POST', url: `/api/sessions/${id}/release` })).statusCode).toBe(202);
|
|
6195
|
+
expect(f.database((db) => new SqliteOrgPlanLaunchStore(db).workspaceOwner(f.workspacePath))).toBeNull();
|
|
6196
|
+
expect(await createComposedSession(app)).not.toBe(id);
|
|
6197
|
+
}
|
|
6198
|
+
finally {
|
|
6199
|
+
spy.mockRestore();
|
|
6200
|
+
await app.close();
|
|
6201
|
+
}
|
|
6202
|
+
});
|
|
6203
|
+
it('keeps a retired supervisor fenced after its successor releases the reservation', async () => {
|
|
6204
|
+
const f = await orgPlanActivationFixture('codex-cli 0.167.0');
|
|
6205
|
+
const app = await f.open();
|
|
6206
|
+
try {
|
|
6207
|
+
const payload = await f.prepare(app);
|
|
6208
|
+
const launched = (await app.inject({ method: 'POST', url: '/api/plans/execute', payload })).json();
|
|
6209
|
+
expect(launched).toMatchObject({ kind: 'started' });
|
|
6210
|
+
const id = launched.session.id;
|
|
6211
|
+
expect((await app.inject({ method: 'POST', url: `/api/sessions/${id}/release` })).statusCode).toBe(202);
|
|
6212
|
+
f.database((db) => {
|
|
6213
|
+
const launch = new SqliteOrgPlanLaunchStore(db).forSession(id);
|
|
6214
|
+
const identity = createHash('sha256').update(launch.canonicalPath).digest('hex');
|
|
6215
|
+
const autopilot = new SqliteAutopilotStore(db);
|
|
6216
|
+
const state = autopilot.find(id) ?? disabledAutopilot(id, new Date().toISOString());
|
|
6217
|
+
autopilot.save({ ...state, planIdentity: identity });
|
|
6218
|
+
const takeover = new SqliteSupervisionTakeoverStore(db, autopilot);
|
|
6219
|
+
const successor = takeover.claim(identity, 'successor');
|
|
6220
|
+
expect(takeover.retire(successor, [id])).toBe(true);
|
|
6221
|
+
takeover.releaseSession('successor');
|
|
6222
|
+
});
|
|
6223
|
+
const turnsBefore = f.requests('turn/start').length;
|
|
6224
|
+
const resumed = await app.inject({
|
|
6225
|
+
method: 'POST',
|
|
6226
|
+
url: `/api/sessions/${id}/turns`,
|
|
6227
|
+
payload: { text: 'Continue work' },
|
|
6228
|
+
});
|
|
6229
|
+
expect(resumed.statusCode).toBe(409);
|
|
6230
|
+
expect(resumed.json()).toMatchObject({ code: 'SESSION_SUPERVISOR_REPLACED' });
|
|
6231
|
+
expect(f.requests('turn/start')).toHaveLength(turnsBefore);
|
|
6232
|
+
}
|
|
6233
|
+
finally {
|
|
6234
|
+
await app.close();
|
|
6235
|
+
}
|
|
6236
|
+
});
|
|
6008
6237
|
it('requires the prior session to stop, then fences it while a supervisor owns its workspace', async () => {
|
|
6009
6238
|
const f = await orgPlanActivationFixture('codex-cli 0.167.0');
|
|
6010
6239
|
const app = await f.open();
|
|
@@ -7042,6 +7271,7 @@ describe('production composition', () => {
|
|
|
7042
7271
|
});
|
|
7043
7272
|
it.each(['authoring-start', 'resync'])('executes a draft retained through %s in one new supervisor, including after restart', async (reason) => {
|
|
7044
7273
|
const f = await orgPlanActivationFixture();
|
|
7274
|
+
let settleWarmup;
|
|
7045
7275
|
let app = await f.open();
|
|
7046
7276
|
try {
|
|
7047
7277
|
const authorId = await createComposedSession(app);
|
|
@@ -7063,7 +7293,29 @@ describe('production composition', () => {
|
|
|
7063
7293
|
.run(authorId));
|
|
7064
7294
|
await app.close();
|
|
7065
7295
|
app = await f.open();
|
|
7296
|
+
const warmup = Promise.withResolvers();
|
|
7297
|
+
f.controls.catalogGate = warmup.promise;
|
|
7066
7298
|
await app.listen({ host: '127.0.0.1', port: 0 });
|
|
7299
|
+
settleWarmup = async () => {
|
|
7300
|
+
warmup.resolve();
|
|
7301
|
+
await expect
|
|
7302
|
+
.poll(async () => (await app.inject(`/api/sessions/${authorId}`)).json())
|
|
7303
|
+
.toMatchObject({ state: 'stopped', lastOrgPlan: { supervision: false } });
|
|
7304
|
+
};
|
|
7305
|
+
// Fastify listen() does not await async onListen hooks. Hold catalog
|
|
7306
|
+
// warmup so the retained legacy attachment is still unclassified.
|
|
7307
|
+
await vi.waitFor(() => expect(f.controls.held).toBe('catalog'));
|
|
7308
|
+
const early = await app.inject({
|
|
7309
|
+
method: 'POST',
|
|
7310
|
+
url: '/api/plans/prepare',
|
|
7311
|
+
payload: {
|
|
7312
|
+
kind: 'retained-session',
|
|
7313
|
+
sessionId: authorId,
|
|
7314
|
+
},
|
|
7315
|
+
});
|
|
7316
|
+
expect(early.json()).toMatchObject({ kind: 'blocked', code: 'ACTIVE_SUPERVISION' });
|
|
7317
|
+
await settleWarmup();
|
|
7318
|
+
settleWarmup = undefined;
|
|
7067
7319
|
const payload = await f.prepare(app);
|
|
7068
7320
|
expect((await app.inject(`/api/sessions/${authorId}`)).json()).toMatchObject({
|
|
7069
7321
|
lastOrgPlan: { attached: true, supervision: false },
|
|
@@ -7131,7 +7383,12 @@ describe('production composition', () => {
|
|
|
7131
7383
|
});
|
|
7132
7384
|
}
|
|
7133
7385
|
finally {
|
|
7134
|
-
|
|
7386
|
+
try {
|
|
7387
|
+
await settleWarmup?.();
|
|
7388
|
+
}
|
|
7389
|
+
finally {
|
|
7390
|
+
await app.close();
|
|
7391
|
+
}
|
|
7135
7392
|
}
|
|
7136
7393
|
});
|
|
7137
7394
|
it('retains an authored plan without starting supervision', async () => {
|
|
@@ -220,6 +220,8 @@ export async function composeRelayApp(options) {
|
|
|
220
220
|
const supervisorOwnership = (sessionId) => {
|
|
221
221
|
const identity = supervisedPlans.identity(sessionId) ?? autopilotStore.find(sessionId)?.planIdentity;
|
|
222
222
|
const owner = identity ? takeoverStore.owner(identity) : null;
|
|
223
|
+
if (identity && owner?.sessionId !== sessionId && takeoverStore.retired(identity, sessionId))
|
|
224
|
+
return 'replaced';
|
|
223
225
|
const path = sessions.find(sessionId)?.lastOrgPlan?.path;
|
|
224
226
|
const launchOwner = path ? orgPlanLaunches.owner(path) : null;
|
|
225
227
|
if (!owner && launchOwner && launchOwner.sessionId !== sessionId)
|
|
@@ -281,7 +283,7 @@ export async function composeRelayApp(options) {
|
|
|
281
283
|
}),
|
|
282
284
|
};
|
|
283
285
|
options.onAttentionTransitions?.(attentionTransitions);
|
|
284
|
-
const activity = new AgentActivityRegistry((snapshot, occurredAt) => {
|
|
286
|
+
const activity = new AgentActivityRegistry((snapshot, occurredAt, kind) => {
|
|
285
287
|
events.publish(journal.append(snapshot.sessionId, 'agent.activity.updated', {
|
|
286
288
|
...toAgentActivityDto(snapshot),
|
|
287
289
|
...(autopilotStore.find(snapshot.sessionId)?.checkpoints?.activeHandoffId
|
|
@@ -290,8 +292,10 @@ export async function composeRelayApp(options) {
|
|
|
290
292
|
}
|
|
291
293
|
: {}),
|
|
292
294
|
}, occurredAt));
|
|
293
|
-
|
|
294
|
-
|
|
295
|
+
if (kind !== 'progress') {
|
|
296
|
+
publishSessionStatus(snapshot.sessionId, occurredAt);
|
|
297
|
+
notifyAutopilotActivity(snapshot.sessionId);
|
|
298
|
+
}
|
|
295
299
|
}, {
|
|
296
300
|
rootThreadId: (sessionId) => sessions.find(sessionId)?.threadId ?? null,
|
|
297
301
|
// Evidence arms one bounded reconciliation; healthy sessions are never polled.
|
|
@@ -1001,9 +1005,10 @@ export async function composeRelayApp(options) {
|
|
|
1001
1005
|
title: update.plan.title,
|
|
1002
1006
|
path: update.planPath,
|
|
1003
1007
|
attached: true,
|
|
1004
|
-
supervision:
|
|
1005
|
-
|
|
1006
|
-
|
|
1008
|
+
supervision: session.desiredState !== 'stopped' &&
|
|
1009
|
+
(takeoverOwner
|
|
1010
|
+
? takeoverOwner.sessionId === sessionId
|
|
1011
|
+
: !launchOwner || launchOwner.sessionId === sessionId) &&
|
|
1007
1012
|
planAttachmentSupervision(session.lastOrgPlan, update, execution?.planIdentity === update.identity && !!execution.supervision),
|
|
1008
1013
|
},
|
|
1009
1014
|
updatedAt: occurredAt,
|
|
@@ -1940,13 +1945,16 @@ export async function composeRelayApp(options) {
|
|
|
1940
1945
|
if (pending && !reclaimableLaunchOwner(pending) && !ownUnpublished)
|
|
1941
1946
|
return {
|
|
1942
1947
|
...(sessions.find(pending.sessionId) ? { sessionId: pending.sessionId } : {}),
|
|
1943
|
-
reason: 'This plan or an overlapping workspace is reserved by another supervisor. Open its session to continue, or
|
|
1948
|
+
reason: 'This plan or an overlapping workspace is reserved by another supervisor. Open its session to continue, or close it to release the reservation.',
|
|
1944
1949
|
};
|
|
1945
1950
|
const busy = workspaceBusy(workspacePath);
|
|
1946
1951
|
if (busy && busy.sessionId !== pending?.sessionId)
|
|
1947
1952
|
return busy;
|
|
1948
1953
|
const identity = createHash('sha256').update(canonicalPath).digest('hex');
|
|
1949
1954
|
const owner = sessions.list().find((session) => {
|
|
1955
|
+
if (session.desiredState === 'stopped' &&
|
|
1956
|
+
['stopped', 'released'].includes(session.state))
|
|
1957
|
+
return false;
|
|
1950
1958
|
if (!session.lastOrgPlan?.attached || session.lastOrgPlan.path !== canonicalPath)
|
|
1951
1959
|
return false;
|
|
1952
1960
|
const execution = autopilotStore.find(session.id);
|
|
@@ -2376,6 +2384,12 @@ export async function composeRelayApp(options) {
|
|
|
2376
2384
|
if (session && owner)
|
|
2377
2385
|
await owner.releaseForForget(session);
|
|
2378
2386
|
await playwright.waitForRelease(id);
|
|
2387
|
+
const current = sessions.find(id);
|
|
2388
|
+
if (current?.desiredState === 'stopped' &&
|
|
2389
|
+
['stopped', 'released'].includes(current.state)) {
|
|
2390
|
+
orgPlanLaunches.releaseSession(id);
|
|
2391
|
+
takeoverStore.releaseSession(id);
|
|
2392
|
+
}
|
|
2379
2393
|
}
|
|
2380
2394
|
: undefined,
|
|
2381
2395
|
replyInteraction: runtime || kimiRuntime
|
|
@@ -22,6 +22,7 @@ export function toAgentActivityDto(snapshot) {
|
|
|
22
22
|
...(child.contextUsedPercent !== undefined
|
|
23
23
|
? { contextUsedPercent: child.contextUsedPercent }
|
|
24
24
|
: {}),
|
|
25
|
+
...(child.latestProgress ? { latestProgress: child.latestProgress } : {}),
|
|
25
26
|
ownedProcesses: (child.ownedProcesses ?? []).slice(0, 64).map((process) => ({
|
|
26
27
|
state: process.state,
|
|
27
28
|
ownership: process.ownership,
|
|
@@ -30,6 +30,27 @@ export function createAgentActivitySnapshot(sessionId, observedAt) {
|
|
|
30
30
|
export function projectAgentActivity(current, fact) {
|
|
31
31
|
if (fact.sessionId !== current.sessionId || !validTimestamp(fact.occurredAt))
|
|
32
32
|
return current;
|
|
33
|
+
if (fact.kind === 'progress') {
|
|
34
|
+
const child = current.subagents.find((candidate) => fact.threadId && candidate.threadId === fact.threadId);
|
|
35
|
+
const text = fact.progressText?.trim();
|
|
36
|
+
if (!child || !text || text.length > 512)
|
|
37
|
+
return current;
|
|
38
|
+
if (child.latestProgress &&
|
|
39
|
+
(Date.parse(fact.occurredAt) < Date.parse(child.latestProgress.occurredAt) ||
|
|
40
|
+
(fact.occurredAt === child.latestProgress.occurredAt && text === child.latestProgress.text)))
|
|
41
|
+
return current;
|
|
42
|
+
// Progress is display evidence, never a lifecycle or freshness signal.
|
|
43
|
+
return Object.freeze({
|
|
44
|
+
...current,
|
|
45
|
+
subagents: Object.freeze(current.subagents.map((candidate) => candidate === child
|
|
46
|
+
? Object.freeze({
|
|
47
|
+
...child,
|
|
48
|
+
latestProgress: Object.freeze({ text, occurredAt: fact.occurredAt }),
|
|
49
|
+
lastActivityAt: later(child.lastActivityAt, fact.occurredAt),
|
|
50
|
+
})
|
|
51
|
+
: candidate)),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
33
54
|
// Notifications can replay or arrive out of order. Never let an older fact
|
|
34
55
|
// regress an actor's authoritative state.
|
|
35
56
|
if (Date.parse(fact.occurredAt) < Date.parse(current.root.observedAt))
|
|
@@ -137,6 +158,7 @@ export function projectAgentActivity(current, fact) {
|
|
|
137
158
|
: before?.ownedProcesses
|
|
138
159
|
? { ownedProcesses: before.ownedProcesses }
|
|
139
160
|
: {}),
|
|
161
|
+
...(before?.latestProgress ? { latestProgress: before.latestProgress } : {}),
|
|
140
162
|
state: childState(fact.childStatus, fact.collaborationAction, before?.state),
|
|
141
163
|
reason: childReason(fact.childStatus, fact.collaborationAction),
|
|
142
164
|
observedAt: fact.occurredAt,
|
|
@@ -33,6 +33,14 @@ export class AgentActivityRegistry {
|
|
|
33
33
|
const current = rootThreadId && rootThreadId !== snapshot.rootThreadId
|
|
34
34
|
? Object.freeze({ ...snapshot, rootThreadId })
|
|
35
35
|
: snapshot;
|
|
36
|
+
if (fact.kind === 'progress') {
|
|
37
|
+
const next = projectAgentActivity(current, fact);
|
|
38
|
+
if (next !== current) {
|
|
39
|
+
this.#snapshots.set(fact.sessionId, next);
|
|
40
|
+
this.publish(next, fact.occurredAt, 'progress');
|
|
41
|
+
}
|
|
42
|
+
return next;
|
|
43
|
+
}
|
|
36
44
|
const next = withActivityConfidence(projectAgentActivity(current, fact), fact.kind === 'collaboration' && !fact.childId ? 'stale' : 'fresh');
|
|
37
45
|
if (next !== snapshot) {
|
|
38
46
|
this.#snapshots.set(fact.sessionId, next);
|
|
@@ -18,7 +18,7 @@ export function writerAcquisitionProblem(kind) {
|
|
|
18
18
|
status: 409,
|
|
19
19
|
code: 'SESSION_WORKSPACE_LOCKED',
|
|
20
20
|
retryable: false,
|
|
21
|
-
detail: 'An Org-plan supervisor owns this workspace. Continue in its session, or
|
|
21
|
+
detail: 'An Org-plan supervisor owns this workspace. Continue in its session, or close that session to release the reservation.',
|
|
22
22
|
};
|
|
23
23
|
case 'supervisorReplaced':
|
|
24
24
|
return {
|
|
@@ -25,6 +25,7 @@ import { registerStopSession } from './stop-session/endpoint.js';
|
|
|
25
25
|
import { registerRefreshActivity } from './refresh-activity/endpoint.js';
|
|
26
26
|
import { registerGetRetrievalReadiness } from './get-retrieval-readiness/endpoint.js';
|
|
27
27
|
import { registerCleanTmp } from './clean-tmp/endpoint.js';
|
|
28
|
+
import { WriterAcquisitionError, writerAcquisitionProblem, } from './application/writer-acquisition.js';
|
|
28
29
|
export function registerSessionRoutes(app, deps) {
|
|
29
30
|
const sessions = deps.sessionRoutes;
|
|
30
31
|
registerCleanTmp(app, deps.tmpCleanup);
|
|
@@ -191,6 +192,8 @@ export function registerSessionRoutes(app, deps) {
|
|
|
191
192
|
});
|
|
192
193
|
}
|
|
193
194
|
function safeErrorLabel(error) {
|
|
195
|
+
if (error instanceof WriterAcquisitionError)
|
|
196
|
+
return writerAcquisitionProblem(error.kind).code;
|
|
194
197
|
if (typeof error === 'object' && error !== null && 'code' in error) {
|
|
195
198
|
const code = error.code;
|
|
196
199
|
if (typeof code === 'string' && /^[A-Z0-9_]+$/.test(code))
|
|
@@ -95,6 +95,24 @@ export function decodeAgentActivityFacts(sessionId, occurredAt, input) {
|
|
|
95
95
|
}
|
|
96
96
|
if (input.method === 'item/started' || input.method === 'item/completed') {
|
|
97
97
|
const item = record(params.item);
|
|
98
|
+
if (input.method === 'item/completed' &&
|
|
99
|
+
item?.type === 'agentMessage' &&
|
|
100
|
+
item.phase === 'commentary' &&
|
|
101
|
+
typeof item.text === 'string' &&
|
|
102
|
+
id(params.threadId)) {
|
|
103
|
+
const text = item.text.replace(/\s+/g, ' ').trim();
|
|
104
|
+
return text
|
|
105
|
+
? [
|
|
106
|
+
{
|
|
107
|
+
sessionId,
|
|
108
|
+
occurredAt,
|
|
109
|
+
kind: 'progress',
|
|
110
|
+
threadId: id(params.threadId),
|
|
111
|
+
progressText: text.length > 512 ? `${text.slice(0, 511)}…` : text,
|
|
112
|
+
},
|
|
113
|
+
]
|
|
114
|
+
: [];
|
|
115
|
+
}
|
|
98
116
|
if (item?.type !== 'collabAgentToolCall' && item?.type !== 'collabToolCall')
|
|
99
117
|
return [];
|
|
100
118
|
const action = typeof item.tool === 'string' ? collaborationAction(item.tool) : undefined;
|
|
@@ -68,6 +68,11 @@ export class SqliteOrgPlanLaunchStore {
|
|
|
68
68
|
.prepare('UPDATE org_plan_launches SET canonical_path=NULL WHERE launch_id=? AND session_id=? AND canonical_path=?')
|
|
69
69
|
.run(record.launchId, record.sessionId, record.canonicalPath);
|
|
70
70
|
}
|
|
71
|
+
releaseSession(sessionId) {
|
|
72
|
+
this.db
|
|
73
|
+
.prepare('UPDATE org_plan_launches SET canonical_path=NULL WHERE session_id=?')
|
|
74
|
+
.run(sessionId);
|
|
75
|
+
}
|
|
71
76
|
acquireOwner(record) {
|
|
72
77
|
return this.activationTransaction(() => {
|
|
73
78
|
const owner = this.workspaceOwner(record.context.workspace.path);
|
|
@@ -13,12 +13,18 @@ export class SqliteSupervisionTakeoverStore {
|
|
|
13
13
|
}
|
|
14
14
|
owner(planIdentity) {
|
|
15
15
|
const row = this.db
|
|
16
|
-
.prepare(
|
|
16
|
+
.prepare("SELECT session_id,epoch,phase FROM org_plan_takeovers WHERE plan_identity=? AND phase!='released'")
|
|
17
17
|
.get(planIdentity);
|
|
18
18
|
return row
|
|
19
19
|
? { planIdentity, sessionId: row.session_id, epoch: row.epoch, phase: row.phase }
|
|
20
20
|
: null;
|
|
21
21
|
}
|
|
22
|
+
/** Keep the epoch tombstone and retired-writer fences after confirmed runtime release. */
|
|
23
|
+
releaseSession(sessionId) {
|
|
24
|
+
this.db
|
|
25
|
+
.prepare("UPDATE org_plan_takeovers SET phase='released',epoch=epoch+1 WHERE session_id=? AND phase!='released'")
|
|
26
|
+
.run(sessionId);
|
|
27
|
+
}
|
|
22
28
|
retired(planIdentity, sessionId) {
|
|
23
29
|
return Boolean(this.db
|
|
24
30
|
.prepare('SELECT 1 FROM org_plan_retired_supervisors WHERE plan_identity=? AND session_id=?')
|
|
@@ -71,7 +77,10 @@ export class SqliteSupervisionTakeoverStore {
|
|
|
71
77
|
return null;
|
|
72
78
|
}
|
|
73
79
|
}
|
|
74
|
-
const
|
|
80
|
+
const retained = this.db
|
|
81
|
+
.prepare('SELECT epoch FROM org_plan_takeovers WHERE plan_identity=?')
|
|
82
|
+
.get(planIdentity);
|
|
83
|
+
const epoch = previous?.sessionId === sessionId ? previous.epoch : (retained?.epoch ?? 0) + 1;
|
|
75
84
|
const phase = previous?.sessionId === sessionId ? previous.phase : 'stopping';
|
|
76
85
|
this.db
|
|
77
86
|
.prepare('INSERT INTO org_plan_takeovers (plan_identity,session_id,epoch,phase) VALUES (?,?,?,?) ON CONFLICT(plan_identity) DO UPDATE SET session_id=excluded.session_id,epoch=excluded.epoch,phase=excluded.phase')
|