gestalt-mobile 0.73.1 → 0.75.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-B7ZFxnEl.css +1 -0
- package/dist/client/assets/index-CpcdImYc.js +184 -0
- package/dist/client/index.html +2 -2
- package/dist/server/server/composition.contracts.js +61 -2
- package/dist/server/server/composition.js +137 -42
- package/dist/server/server/features/plans/application/prepare-org-plan-supervision.js +7 -1
- package/dist/server/server/features/plans/application/start-org-plan-supervision.js +28 -3
- package/dist/server/server/features/sessions/application/resolve-session-skills.js +9 -0
- package/dist/server/server/features/sessions/model/relay-session.js +9 -1
- package/dist/server/server/features/sessions/start-session/request.js +4 -1
- package/dist/server/server/features/skills/model/skill-profile.js +15 -2
- package/dist/server/server/platform/kimi/kimi-session-runtime.js +1 -1
- package/dist/server/shared/contracts/org-plan-execution.js +1 -0
- package/package.json +1 -1
- package/dist/client/assets/index-C5YNh-JV.js +0 -182
- package/dist/client/assets/index-EYPvWfrJ.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-CpcdImYc.js"></script>
|
|
20
|
+
<link rel="stylesheet" crossorigin href="/assets/index-B7ZFxnEl.css">
|
|
21
21
|
</head>
|
|
22
22
|
<body>
|
|
23
23
|
<div id="app"></div>
|
|
@@ -481,6 +481,7 @@ async function orgPlanActivationFixture(installedCodexVersion = 'codex-cli 0.144
|
|
|
481
481
|
const controls = {
|
|
482
482
|
failInitialize: false,
|
|
483
483
|
failThread: false,
|
|
484
|
+
threadBusy: false,
|
|
484
485
|
initializationGate: null,
|
|
485
486
|
threadGate: null,
|
|
486
487
|
catalogGate: null,
|
|
@@ -540,6 +541,14 @@ async function orgPlanActivationFixture(installedCodexVersion = 'codex-cli 0.144
|
|
|
540
541
|
throw new Error('INJECTED_THREAD_RECEIPT_LOSS');
|
|
541
542
|
}
|
|
542
543
|
}
|
|
544
|
+
if (method === 'thread/read' && controls.threadBusy) {
|
|
545
|
+
return {
|
|
546
|
+
thread: {
|
|
547
|
+
id: params.threadId,
|
|
548
|
+
status: { type: 'active' },
|
|
549
|
+
},
|
|
550
|
+
};
|
|
551
|
+
}
|
|
543
552
|
if (method === 'skills/list') {
|
|
544
553
|
const gate = !runtime && controls.catalogGate;
|
|
545
554
|
if (gate) {
|
|
@@ -6394,16 +6403,66 @@ describe('production composition', () => {
|
|
|
6394
6403
|
const launch = (await app.inject({ method: 'POST', url: '/api/plans/execute', payload })).json();
|
|
6395
6404
|
expect(launch).toMatchObject({
|
|
6396
6405
|
kind: 'blocked',
|
|
6397
|
-
code: '
|
|
6406
|
+
code: 'WORKSPACE_BUSY',
|
|
6398
6407
|
existingSessionId: id,
|
|
6399
6408
|
});
|
|
6400
|
-
expect(launch.reason).toContain('
|
|
6409
|
+
expect(launch.reason).toContain('idle');
|
|
6401
6410
|
expect((await app.inject('/api/sessions')).json()).toHaveLength(1);
|
|
6402
6411
|
}
|
|
6403
6412
|
finally {
|
|
6404
6413
|
await app.close();
|
|
6405
6414
|
}
|
|
6406
6415
|
});
|
|
6416
|
+
it('rechecks the confirmed session before replacement and keeps its saved thread', async () => {
|
|
6417
|
+
const f = await orgPlanActivationFixture('codex-cli 0.167.0');
|
|
6418
|
+
const app = await f.open();
|
|
6419
|
+
try {
|
|
6420
|
+
const id = await createComposedSession(app);
|
|
6421
|
+
const { threadId } = (await app.inject(`/api/sessions/${id}`)).json();
|
|
6422
|
+
const payload = await f.prepare(app);
|
|
6423
|
+
const reference = {
|
|
6424
|
+
kind: 'session',
|
|
6425
|
+
sessionId: id,
|
|
6426
|
+
planName: payload.reference.planName,
|
|
6427
|
+
};
|
|
6428
|
+
const prepare = async () => (await app.inject({
|
|
6429
|
+
method: 'POST',
|
|
6430
|
+
url: '/api/plans/prepare',
|
|
6431
|
+
payload: { ...reference, expectedRevision: payload.expectedRevision },
|
|
6432
|
+
})).json();
|
|
6433
|
+
await expect.poll(prepare).toMatchObject({
|
|
6434
|
+
kind: 'eligible',
|
|
6435
|
+
workspaceSession: { sessionId: id, replaceAllowed: true },
|
|
6436
|
+
});
|
|
6437
|
+
const execute = async () => (await app.inject({
|
|
6438
|
+
method: 'POST',
|
|
6439
|
+
url: '/api/plans/execute',
|
|
6440
|
+
payload: { ...payload, reference, replaceSessionId: id },
|
|
6441
|
+
})).json();
|
|
6442
|
+
// Simulate provider work beginning after the user saw the idle status.
|
|
6443
|
+
f.controls.threadBusy = true;
|
|
6444
|
+
expect(await execute()).toMatchObject({
|
|
6445
|
+
kind: 'blocked',
|
|
6446
|
+
code: 'WORKSPACE_BUSY',
|
|
6447
|
+
existingSessionId: id,
|
|
6448
|
+
});
|
|
6449
|
+
expect((await app.inject(`/api/sessions/${id}`)).json()).toMatchObject({
|
|
6450
|
+
state: 'ready',
|
|
6451
|
+
threadId,
|
|
6452
|
+
});
|
|
6453
|
+
expect(f.requests('thread/start')).toHaveLength(1);
|
|
6454
|
+
f.controls.threadBusy = false;
|
|
6455
|
+
expect(await execute()).toMatchObject({ kind: 'started', bootstrap: { kind: 'accepted' } });
|
|
6456
|
+
expect((await app.inject(`/api/sessions/${id}`)).json()).toMatchObject({
|
|
6457
|
+
state: 'released',
|
|
6458
|
+
threadId,
|
|
6459
|
+
});
|
|
6460
|
+
expect(f.requests('thread/start')).toHaveLength(2);
|
|
6461
|
+
}
|
|
6462
|
+
finally {
|
|
6463
|
+
await app.close();
|
|
6464
|
+
}
|
|
6465
|
+
});
|
|
6407
6466
|
it('executes a validated plan on Codex 0.167.0 with supervision instructions and exclusive workspace ownership', async () => {
|
|
6408
6467
|
const f = await orgPlanActivationFixture('codex-cli 0.167.0');
|
|
6409
6468
|
const app = await f.open();
|
|
@@ -57,7 +57,7 @@ import { SqliteAuthorizationStore } from './platform/auth/sqlite-authorization-s
|
|
|
57
57
|
import { SimpleWebAuthnAdapter } from './platform/auth/simple-webauthn-adapter.js';
|
|
58
58
|
import { authorizationSessionId, authorizedDeviceId } from './features/auth/domain/identifiers.js';
|
|
59
59
|
import { SqliteSessionRepository } from './platform/persistence/sqlite-session-repository.js';
|
|
60
|
-
import { SqliteWorkspaceLifecycle } from './platform/persistence/sqlite-workspace-lifecycle.js';
|
|
60
|
+
import { canonicalSessionWorkspace, SqliteWorkspaceLifecycle, } from './platform/persistence/sqlite-workspace-lifecycle.js';
|
|
61
61
|
import { FilesystemWorkspaceForget } from './platform/scratch/filesystem-workspace-forget.js';
|
|
62
62
|
import { SqliteEventJournal } from './platform/persistence/sqlite-event-journal.js';
|
|
63
63
|
import { SqlitePendingInteractionStore } from './platform/persistence/sqlite-pending-interaction-store.js';
|
|
@@ -98,7 +98,7 @@ import { CodexCapabilities } from './platform/codex/codex-capabilities.js';
|
|
|
98
98
|
import { CodexPlaywright } from './platform/codex/codex-playwright.js';
|
|
99
99
|
import { ManagedPlaywright } from './platform/codex/managed-playwright.js';
|
|
100
100
|
import { isManagedPlaywrightCall } from '../shared/contracts/managed-playwright.js';
|
|
101
|
-
import { compileSkillOverride } from './features/skills/model/skill-profile.js';
|
|
101
|
+
import { compileSkillOverride, isMandatoryGestaltSkill, } from './features/skills/model/skill-profile.js';
|
|
102
102
|
import { SupervisedPlanRegistry } from './features/plans/application/supervised-plan-registry.js';
|
|
103
103
|
import { planAttachmentSupervision } from './features/plans/application/plan-attachment-supervision.js';
|
|
104
104
|
import { prepareOrgPlanSupervision } from './features/plans/application/prepare-org-plan-supervision.js';
|
|
@@ -169,7 +169,11 @@ export async function composeRelayApp(options) {
|
|
|
169
169
|
const orgPlanLaunches = new SqliteOrgPlanLaunchStore(database);
|
|
170
170
|
// Admission spans asynchronous provider calls so Execute cannot reserve a workspace mid-start.
|
|
171
171
|
const workspaceAdmissions = new Map();
|
|
172
|
+
const replacingWorkspaceSessions = new Map();
|
|
172
173
|
const assertWorkspaceOwner = (session) => {
|
|
174
|
+
if (replacingWorkspaceSessions.size &&
|
|
175
|
+
replacingWorkspaceSessions.has(canonicalSessionWorkspace(session.workspacePath)))
|
|
176
|
+
throw new WriterAcquisitionError('workspaceLocked');
|
|
173
177
|
let owner = orgPlanLaunches.workspaceOwner(session.workspacePath);
|
|
174
178
|
while (owner &&
|
|
175
179
|
forgetOperations.find(owner.sessionId)?.phase === 'completed' &&
|
|
@@ -648,6 +652,7 @@ export async function composeRelayApp(options) {
|
|
|
648
652
|
return compileSkillOverride({
|
|
649
653
|
discovered: catalog.skills,
|
|
650
654
|
explicit: session.effectiveSkillSelection.skills,
|
|
655
|
+
mandatorySkillsOnly: session.effectiveSkillSelection.mandatorySkillsOnly,
|
|
651
656
|
}).skillsConfig;
|
|
652
657
|
const project = await skillProfiles.readWorkspaceDefault(session.workspacePath);
|
|
653
658
|
return compileSkillOverride({
|
|
@@ -1405,26 +1410,33 @@ export async function composeRelayApp(options) {
|
|
|
1405
1410
|
}, undefined, planStatusSource, acceptPlanUpdate, options.planMeasurementBaseUrl, 30_000, 64, root, (session) => sessionModelConfig.resolve(session), {
|
|
1406
1411
|
prepare: async (session, rpc, config, deadline) => {
|
|
1407
1412
|
const catalog = await new CodexSkillCatalog(session.profile, options.launchAppServer ?? launchCodexAppServer, Math.max(1, deadline - Date.now())).list(session.workspacePath);
|
|
1408
|
-
const
|
|
1413
|
+
const mandatorySkillsOnly = session.effectiveSkillSelection?.mandatorySkillsOnly;
|
|
1414
|
+
const project = mandatorySkillsOnly
|
|
1415
|
+
? undefined
|
|
1416
|
+
: await skillProfiles.readWorkspaceDefault(session.workspacePath);
|
|
1409
1417
|
const selected = compileSkillOverride({
|
|
1410
1418
|
discovered: catalog.skills,
|
|
1411
1419
|
explicit: session.effectiveSkillSelection?.skills ?? options.explicitSkillProfile?.skills,
|
|
1412
1420
|
project: project?.skills,
|
|
1421
|
+
mandatorySkillsOnly,
|
|
1413
1422
|
});
|
|
1423
|
+
const availableSkills = mandatorySkillsOnly
|
|
1424
|
+
? catalog.skills.filter(({ name }) => isMandatoryGestaltSkill(name))
|
|
1425
|
+
: catalog.skills;
|
|
1414
1426
|
const state = await capabilities.prepare({
|
|
1415
1427
|
cwd: session.workspacePath,
|
|
1416
1428
|
approvalPolicy: session.executionPolicy?.approvalPolicy ?? 'on-request',
|
|
1417
1429
|
rpc,
|
|
1418
1430
|
config,
|
|
1419
1431
|
deadline,
|
|
1420
|
-
skills:
|
|
1432
|
+
skills: availableSkills,
|
|
1421
1433
|
skillsConfig: selected.skillsConfig,
|
|
1422
1434
|
start: true,
|
|
1423
1435
|
startup: !session.threadId,
|
|
1424
1436
|
});
|
|
1425
1437
|
return playwright.prepare(state, playwrightAuthority(session), {
|
|
1426
1438
|
rpc,
|
|
1427
|
-
skills:
|
|
1439
|
+
skills: availableSkills,
|
|
1428
1440
|
deadline: Date.now() + 5_000,
|
|
1429
1441
|
current: () => playwrightAuthority(sessions.find(session.id) ?? session),
|
|
1430
1442
|
});
|
|
@@ -1915,18 +1927,19 @@ export async function composeRelayApp(options) {
|
|
|
1915
1927
|
const reclaimableLaunchOwner = (record) => forgetOperations.find(record.sessionId)?.phase === 'completed' &&
|
|
1916
1928
|
!sessions.find(record.sessionId) &&
|
|
1917
1929
|
!runtime?.ownsWriter(record.sessionId);
|
|
1918
|
-
const
|
|
1930
|
+
const sessionHasWorkspaceWork = (session, snapshot = activity.snapshot(session.id, new Date().toISOString())) => Boolean(session.activeTurnId ||
|
|
1931
|
+
pendingRootTurn(session.id) ||
|
|
1932
|
+
workspaceAdmissions.has(session.id) ||
|
|
1933
|
+
orgPlanStarting.has(session.id) ||
|
|
1934
|
+
snapshot.subagents.some((agent) => ['working', 'awaitingAgent'].includes(agent.state) ||
|
|
1935
|
+
agent.ownedProcesses?.some((process) => ['running', 'detached-active'].includes(process.state))));
|
|
1936
|
+
const workspaceBusy = (workspacePath, skipExact = false) => {
|
|
1919
1937
|
const session = sessions.list().find((session) => {
|
|
1920
1938
|
if (!within(workspacePath, session.workspacePath) &&
|
|
1921
1939
|
!within(session.workspacePath, workspacePath))
|
|
1922
1940
|
return false;
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
pendingRootTurn(session.id) ||
|
|
1926
|
-
workspaceAdmissions.has(session.id) ||
|
|
1927
|
-
orgPlanStarting.has(session.id) ||
|
|
1928
|
-
snapshot.subagents.some((agent) => ['working', 'awaitingAgent'].includes(agent.state) ||
|
|
1929
|
-
agent.ownedProcesses?.some((process) => ['running', 'detached-active'].includes(process.state))));
|
|
1941
|
+
return ((!skipExact || canonicalSessionWorkspace(session.workspacePath) !== workspacePath) &&
|
|
1942
|
+
sessionHasWorkspaceWork(session));
|
|
1930
1943
|
});
|
|
1931
1944
|
return session
|
|
1932
1945
|
? {
|
|
@@ -1935,8 +1948,110 @@ export async function composeRelayApp(options) {
|
|
|
1935
1948
|
}
|
|
1936
1949
|
: null;
|
|
1937
1950
|
};
|
|
1951
|
+
const workspaceSession = (workspacePath) => {
|
|
1952
|
+
const replacing = replacingWorkspaceSessions.get(workspacePath);
|
|
1953
|
+
if (replacing)
|
|
1954
|
+
return {
|
|
1955
|
+
sessionId: replacing.sessionId,
|
|
1956
|
+
replaceAllowed: !replacing.closing,
|
|
1957
|
+
retryClose: true,
|
|
1958
|
+
};
|
|
1959
|
+
const session = sessions
|
|
1960
|
+
.list()
|
|
1961
|
+
.find((candidate) => candidate.desiredState === 'active' &&
|
|
1962
|
+
!['stopped', 'released'].includes(candidate.state) &&
|
|
1963
|
+
canonicalSessionWorkspace(candidate.workspacePath) === workspacePath);
|
|
1964
|
+
if (!session)
|
|
1965
|
+
return null;
|
|
1966
|
+
const snapshot = activity.snapshot(session.id, new Date().toISOString());
|
|
1967
|
+
const automatic = autopilot.snapshot(session.id);
|
|
1968
|
+
return {
|
|
1969
|
+
sessionId: session.id,
|
|
1970
|
+
replaceAllowed: session.state === 'ready' &&
|
|
1971
|
+
snapshot.confidence === 'fresh' &&
|
|
1972
|
+
snapshot.root.state === 'idle' &&
|
|
1973
|
+
!sessionHasWorkspaceWork(session, snapshot) &&
|
|
1974
|
+
!session.pendingInteractions?.length &&
|
|
1975
|
+
!blockingInteractions(session.id).length &&
|
|
1976
|
+
automatic?.state !== 'attentionRequired' &&
|
|
1977
|
+
!automatic?.health?.healthy &&
|
|
1978
|
+
!forgetOperations.find(session.id) &&
|
|
1979
|
+
!hostTests?.supervisionSummary(session.id).running,
|
|
1980
|
+
};
|
|
1981
|
+
};
|
|
1982
|
+
const releaseSessionSnapshot = (session) => {
|
|
1983
|
+
providerRecovery.cancel(session.id);
|
|
1984
|
+
autopilot.cancel(session.id, 'sessionEnded');
|
|
1985
|
+
return RelaySession.rehydrate(session).release(new Date().toISOString()).snapshot;
|
|
1986
|
+
};
|
|
1987
|
+
const closeReleasedSession = async (id) => {
|
|
1988
|
+
providerRecovery.cancel(id);
|
|
1989
|
+
autopilot.cancel(id, 'sessionEnded');
|
|
1990
|
+
await hostTests?.cancelSession(id);
|
|
1991
|
+
planMeasurementRefresh?.stop(id);
|
|
1992
|
+
dismissPendingInteractions(id, new Date().toISOString());
|
|
1993
|
+
activity.dispose(id);
|
|
1994
|
+
const session = sessions.find(id);
|
|
1995
|
+
const owner = session ? ownerRuntime(session) : null;
|
|
1996
|
+
if (session && owner)
|
|
1997
|
+
await owner.releaseForForget(session);
|
|
1998
|
+
await playwright.waitForRelease(id);
|
|
1999
|
+
const current = sessions.find(id);
|
|
2000
|
+
if (current?.desiredState === 'stopped' && ['stopped', 'released'].includes(current.state)) {
|
|
2001
|
+
orgPlanLaunches.releaseSession(id);
|
|
2002
|
+
takeoverStore.releaseSession(id);
|
|
2003
|
+
if (replacingWorkspaceSessions.size) {
|
|
2004
|
+
const workspacePath = canonicalSessionWorkspace(current.workspacePath);
|
|
2005
|
+
if (replacingWorkspaceSessions.get(workspacePath)?.sessionId === id)
|
|
2006
|
+
replacingWorkspaceSessions.delete(workspacePath);
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
};
|
|
2010
|
+
const replaceIdleSession = async (workspacePath, id) => {
|
|
2011
|
+
const initial = workspaceSession(workspacePath);
|
|
2012
|
+
if (initial?.sessionId !== id || !initial.replaceAllowed)
|
|
2013
|
+
return false;
|
|
2014
|
+
if (!initial.retryClose)
|
|
2015
|
+
await activity.refresh(id);
|
|
2016
|
+
const occupant = workspaceSession(workspacePath);
|
|
2017
|
+
const session = sessions.find(id);
|
|
2018
|
+
if (!session ||
|
|
2019
|
+
forgetOperations.find(id) ||
|
|
2020
|
+
workspaceBusy(workspacePath, true) ||
|
|
2021
|
+
occupant?.sessionId !== id ||
|
|
2022
|
+
!occupant.replaceAllowed)
|
|
2023
|
+
return false;
|
|
2024
|
+
// Recheck and mark the saved session as released before yielding to provider teardown.
|
|
2025
|
+
const replacement = { sessionId: id, closing: true };
|
|
2026
|
+
replacingWorkspaceSessions.set(workspacePath, replacement);
|
|
2027
|
+
try {
|
|
2028
|
+
if (!occupant.retryClose)
|
|
2029
|
+
saveSession(releaseSessionSnapshot(session));
|
|
2030
|
+
await closeReleasedSession(id);
|
|
2031
|
+
return !replacingWorkspaceSessions.has(workspacePath);
|
|
2032
|
+
}
|
|
2033
|
+
catch {
|
|
2034
|
+
if (sessions.find(id)?.desiredState === 'active')
|
|
2035
|
+
replacingWorkspaceSessions.delete(workspacePath);
|
|
2036
|
+
return false;
|
|
2037
|
+
}
|
|
2038
|
+
finally {
|
|
2039
|
+
replacement.closing = false;
|
|
2040
|
+
}
|
|
2041
|
+
};
|
|
1938
2042
|
const prepareOrgPlan = (reference, expectedRevision, skillProfile, ownUnpublishedLaunchId) => prepareOrgPlanSupervision(reference, {
|
|
1939
2043
|
resolveReference: (ref) => orgPlanContext.resolveReference(ref),
|
|
2044
|
+
workspaceSession: async (workspacePath) => {
|
|
2045
|
+
const occupant = workspaceSession(workspacePath);
|
|
2046
|
+
if (expectedRevision &&
|
|
2047
|
+
occupant &&
|
|
2048
|
+
!occupant.replaceAllowed &&
|
|
2049
|
+
sessions.find(occupant.sessionId)?.state === 'ready') {
|
|
2050
|
+
await activity.refresh(occupant.sessionId);
|
|
2051
|
+
return workspaceSession(workspacePath);
|
|
2052
|
+
}
|
|
2053
|
+
return occupant;
|
|
2054
|
+
},
|
|
1940
2055
|
workspace: (path, revision) => orgPlanContext.workspace(path, revision),
|
|
1941
2056
|
read: (workspacePath, planName) => workspacePlanCatalog.readExecution(workspacePath, planName),
|
|
1942
2057
|
runtimeAvailable: async () => protocol.compatible
|
|
@@ -1963,14 +2078,17 @@ export async function composeRelayApp(options) {
|
|
|
1963
2078
|
!sessions.find(pending.sessionId) &&
|
|
1964
2079
|
!runtime?.ownsWriter(pending.sessionId) &&
|
|
1965
2080
|
['reserved', 'creating'].includes(pending.phase);
|
|
2081
|
+
const busy = workspaceBusy(workspacePath, true);
|
|
2082
|
+
if (busy && busy.sessionId !== pending?.sessionId)
|
|
2083
|
+
return busy;
|
|
1966
2084
|
if (pending && !reclaimableLaunchOwner(pending) && !ownUnpublished)
|
|
1967
2085
|
return {
|
|
1968
2086
|
...(sessions.find(pending.sessionId) ? { sessionId: pending.sessionId } : {}),
|
|
2087
|
+
...(pending.canonicalPath !== canonicalPath
|
|
2088
|
+
? { workspaceConflict: true }
|
|
2089
|
+
: {}),
|
|
1969
2090
|
reason: 'This plan or an overlapping workspace is reserved by another supervisor. Open its session to continue, or close it to release the reservation.',
|
|
1970
2091
|
};
|
|
1971
|
-
const busy = workspaceBusy(workspacePath);
|
|
1972
|
-
if (busy && busy.sessionId !== pending?.sessionId)
|
|
1973
|
-
return busy;
|
|
1974
2092
|
const identity = createHash('sha256').update(canonicalPath).digest('hex');
|
|
1975
2093
|
const owner = sessions.list().find((session) => {
|
|
1976
2094
|
if (session.desiredState === 'stopped' &&
|
|
@@ -1991,6 +2109,7 @@ export async function composeRelayApp(options) {
|
|
|
1991
2109
|
createId: randomUUID,
|
|
1992
2110
|
launches: orgPlanLaunches,
|
|
1993
2111
|
workspaceBusy,
|
|
2112
|
+
replaceIdleSession,
|
|
1994
2113
|
reclaimForgottenOwner: (path, workspacePath) => {
|
|
1995
2114
|
const record = orgPlanLaunches.owner(path);
|
|
1996
2115
|
if (record && reclaimableLaunchOwner(record))
|
|
@@ -2379,11 +2498,7 @@ export async function composeRelayApp(options) {
|
|
|
2379
2498
|
: recentThreads.executionPolicy(candidate.id),
|
|
2380
2499
|
})
|
|
2381
2500
|
: undefined,
|
|
2382
|
-
release:
|
|
2383
|
-
providerRecovery.cancel(session.id);
|
|
2384
|
-
autopilot.cancel(session.id, 'sessionEnded');
|
|
2385
|
-
return RelaySession.rehydrate(session).release(new Date().toISOString()).snapshot;
|
|
2386
|
-
},
|
|
2501
|
+
release: releaseSessionSnapshot,
|
|
2387
2502
|
remove: (id) => {
|
|
2388
2503
|
providerRecovery.cancel(id);
|
|
2389
2504
|
autopilot.cancel(id, 'sessionEnded');
|
|
@@ -2391,27 +2506,7 @@ export async function composeRelayApp(options) {
|
|
|
2391
2506
|
sessions.remove(id);
|
|
2392
2507
|
},
|
|
2393
2508
|
idempotency,
|
|
2394
|
-
close: runtime || kimiRuntime
|
|
2395
|
-
? async (id) => {
|
|
2396
|
-
providerRecovery.cancel(id);
|
|
2397
|
-
autopilot.cancel(id, 'sessionEnded');
|
|
2398
|
-
await hostTests?.cancelSession(id);
|
|
2399
|
-
planMeasurementRefresh?.stop(id);
|
|
2400
|
-
dismissPendingInteractions(id, new Date().toISOString());
|
|
2401
|
-
activity.dispose(id);
|
|
2402
|
-
const session = sessions.find(id);
|
|
2403
|
-
const owner = session ? ownerRuntime(session) : null;
|
|
2404
|
-
if (session && owner)
|
|
2405
|
-
await owner.releaseForForget(session);
|
|
2406
|
-
await playwright.waitForRelease(id);
|
|
2407
|
-
const current = sessions.find(id);
|
|
2408
|
-
if (current?.desiredState === 'stopped' &&
|
|
2409
|
-
['stopped', 'released'].includes(current.state)) {
|
|
2410
|
-
orgPlanLaunches.releaseSession(id);
|
|
2411
|
-
takeoverStore.releaseSession(id);
|
|
2412
|
-
}
|
|
2413
|
-
}
|
|
2414
|
-
: undefined,
|
|
2509
|
+
close: runtime || kimiRuntime ? closeReleasedSession : undefined,
|
|
2415
2510
|
replyInteraction: runtime || kimiRuntime
|
|
2416
2511
|
? async (sessionId, requestId, value) => {
|
|
2417
2512
|
providerRecovery.cancel(sessionId);
|
|
@@ -55,13 +55,18 @@ export async function prepareOrgPlanSupervision(reference, deps, expectedRevisio
|
|
|
55
55
|
if (!policy.allowed)
|
|
56
56
|
return blocked('MODEL_POLICY_UNAVAILABLE', policy.action);
|
|
57
57
|
let owner;
|
|
58
|
+
let workspaceSession;
|
|
58
59
|
try {
|
|
59
60
|
owner = await deps.owner(file.canonicalPath, context.workspace.path);
|
|
61
|
+
workspaceSession = await deps.workspaceSession?.(context.workspace.path);
|
|
60
62
|
}
|
|
61
63
|
catch {
|
|
62
64
|
return blocked('WORKSPACE_UNAVAILABLE', 'Plan and workspace ownership could not be verified. Refresh and retry.');
|
|
63
65
|
}
|
|
64
|
-
if (owner
|
|
66
|
+
if (owner &&
|
|
67
|
+
(!owner.workspaceConflict ||
|
|
68
|
+
!workspaceSession ||
|
|
69
|
+
owner.sessionId !== workspaceSession.sessionId))
|
|
65
70
|
return {
|
|
66
71
|
kind: 'blocked',
|
|
67
72
|
code: 'ACTIVE_SUPERVISION',
|
|
@@ -86,6 +91,7 @@ export async function prepareOrgPlanSupervision(reference, deps, expectedRevisio
|
|
|
86
91
|
title: file.plan.title,
|
|
87
92
|
sourcePath: file.canonicalPath,
|
|
88
93
|
workspace: context.workspace,
|
|
94
|
+
...(workspaceSession ? { workspaceSession } : {}),
|
|
89
95
|
revision: context.revision,
|
|
90
96
|
settings: settings.settings,
|
|
91
97
|
skillProfiles: settings.skillProfiles,
|
|
@@ -25,6 +25,7 @@ export async function startOrgPlanSupervision(request, deps) {
|
|
|
25
25
|
reference.kind === 'retained-session' ? null : reference.planName,
|
|
26
26
|
input.expectedRevision,
|
|
27
27
|
input.skillProfile ?? null,
|
|
28
|
+
...(input.replaceSessionId ? [input.replaceSessionId] : []),
|
|
28
29
|
]))
|
|
29
30
|
.digest('hex');
|
|
30
31
|
let record = deps.launches.find(input.launchId);
|
|
@@ -36,12 +37,15 @@ export async function startOrgPlanSupervision(request, deps) {
|
|
|
36
37
|
return conflict();
|
|
37
38
|
}
|
|
38
39
|
else {
|
|
39
|
-
|
|
40
|
+
let context = await deps.prepare(reference, input.expectedRevision, input.skillProfile);
|
|
40
41
|
if (context.kind === 'blocked') {
|
|
41
42
|
// Another delivery can reserve/attach while this delivery is preparing.
|
|
42
43
|
// Records are retained, so one bounded re-entry takes the replay path.
|
|
43
44
|
return deps.launches.find(input.launchId) ? startOrgPlanSupervision(input, deps) : context;
|
|
44
45
|
}
|
|
46
|
+
const occupant = context.workspaceSession;
|
|
47
|
+
if (occupant && (!occupant.replaceAllowed || occupant.sessionId !== input.replaceSessionId))
|
|
48
|
+
return replacementBlocked(occupant.sessionId);
|
|
45
49
|
let skillSelection;
|
|
46
50
|
try {
|
|
47
51
|
skillSelection = await deps.captureSkills(context);
|
|
@@ -59,6 +63,15 @@ export async function startOrgPlanSupervision(request, deps) {
|
|
|
59
63
|
code: 'GESTALT_CAPABILITIES_UNAVAILABLE',
|
|
60
64
|
reason: 'The Org-plan skill changed before launch. Refresh and confirm again.',
|
|
61
65
|
};
|
|
66
|
+
if (occupant) {
|
|
67
|
+
if (!(await deps.replaceIdleSession?.(context.workspace.path, occupant.sessionId)))
|
|
68
|
+
return replacementBlocked(occupant.sessionId);
|
|
69
|
+
context = await deps.prepare(reference, input.expectedRevision, input.skillProfile);
|
|
70
|
+
if (context.kind === 'blocked')
|
|
71
|
+
return context;
|
|
72
|
+
if (context.workspaceSession)
|
|
73
|
+
return replacementBlocked(context.workspaceSession.sessionId);
|
|
74
|
+
}
|
|
62
75
|
deps.reclaimForgottenOwner?.(context.sourcePath, context.workspace.path);
|
|
63
76
|
const busy = deps.workspaceBusy?.(context.workspace.path);
|
|
64
77
|
if (busy)
|
|
@@ -106,6 +119,14 @@ export async function startOrgPlanSupervision(request, deps) {
|
|
|
106
119
|
return continueLaunch(deps.launches.find(current.launchId) ?? current, deps);
|
|
107
120
|
});
|
|
108
121
|
}
|
|
122
|
+
function replacementBlocked(sessionId) {
|
|
123
|
+
return {
|
|
124
|
+
kind: 'blocked',
|
|
125
|
+
code: 'WORKSPACE_BUSY',
|
|
126
|
+
reason: 'Refresh the workspace session status and confirm replacement once it is idle.',
|
|
127
|
+
existingSessionId: sessionId,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
109
130
|
async function continueLaunch(record, deps) {
|
|
110
131
|
if (deps.sessions.unavailable?.(record.sessionId))
|
|
111
132
|
return unavailable();
|
|
@@ -255,8 +276,12 @@ export class OrgPlanSessionNotPublished extends Error {
|
|
|
255
276
|
}
|
|
256
277
|
async function revalidateUnpublished(input, record, deps) {
|
|
257
278
|
const fresh = await deps.prepare(input.reference, input.expectedRevision, input.skillProfile, record.launchId);
|
|
258
|
-
let blocked = fresh.kind === 'blocked'
|
|
259
|
-
|
|
279
|
+
let blocked = fresh.kind === 'blocked'
|
|
280
|
+
? fresh
|
|
281
|
+
: fresh.workspaceSession
|
|
282
|
+
? replacementBlocked(fresh.workspaceSession.sessionId)
|
|
283
|
+
: null;
|
|
284
|
+
if (fresh.kind === 'eligible' && !blocked) {
|
|
260
285
|
try {
|
|
261
286
|
const skills = await deps.captureSkills(fresh);
|
|
262
287
|
if (fresh.sourcePath !== record.canonicalPath ||
|
|
@@ -8,6 +8,15 @@ import { reconcileSkillSelectionSnapshot, } from '../../skills/model/skill-profi
|
|
|
8
8
|
import { SkillProfileError } from '../../skills/model/errors.js';
|
|
9
9
|
/** Same immutable profile/capability snapshot for ordinary starts and read-only preparation. */
|
|
10
10
|
export async function resolveSessionSkillSelection(input, deps) {
|
|
11
|
+
if (input.mandatorySkillsOnly) {
|
|
12
|
+
const catalog = await deps
|
|
13
|
+
.skillCatalog(input.provider, input.profile)
|
|
14
|
+
.list(input.workspacePath);
|
|
15
|
+
return createEffectiveSkillSelection({
|
|
16
|
+
mandatorySkillsOnly: true,
|
|
17
|
+
skills: catalog.skills.map(({ name, path, enabled }) => ({ name, path, enabled })),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
11
20
|
const selectedProfile = input.skillProfile
|
|
12
21
|
? await deps.skillProfiles.readGlobalProfile(input.skillProfile)
|
|
13
22
|
: deps.defaultSkillProfile;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { DomainError } from './errors.js';
|
|
7
7
|
import { profileCapabilitiesSchema, } from '../../../../shared/contracts/profile-capabilities.js';
|
|
8
|
-
import { createSkillSelection, normalizeSkillProfileName, } from '../../skills/model/skill-profile.js';
|
|
8
|
+
import { createSkillSelection, isMandatoryGestaltSkill, normalizeSkillProfileName, } from '../../skills/model/skill-profile.js';
|
|
9
9
|
import { interactionId, profileName, sessionId, threadId, turnId, workspaceId, workspacePath, } from './value-objects.js';
|
|
10
10
|
/** A durable thread can be read even when this relay has no live writer. */
|
|
11
11
|
export function isSessionReadable(session) {
|
|
@@ -36,6 +36,14 @@ export function createSessionExecutionPolicy(input) {
|
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
export function createEffectiveSkillSelection(input) {
|
|
39
|
+
if (input.mandatorySkillsOnly) {
|
|
40
|
+
return {
|
|
41
|
+
mandatorySkillsOnly: true,
|
|
42
|
+
skills: createSkillSelection(input.skills
|
|
43
|
+
.filter(({ name }) => isMandatoryGestaltSkill(name))
|
|
44
|
+
.map((skill) => ({ ...skill, enabled: true }))),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
39
47
|
const warnings = (input.warnings ?? []).filter((warning) => typeof warning === 'string' && warning.length > 0);
|
|
40
48
|
return {
|
|
41
49
|
...(input.capabilities === undefined
|
|
@@ -10,6 +10,7 @@ const schema = z.object({
|
|
|
10
10
|
provider: z.enum(['codex', 'kimi']),
|
|
11
11
|
profile: z.string().min(1),
|
|
12
12
|
skillProfile: z.string().trim().min(1).optional(),
|
|
13
|
+
mandatorySkillsOnly: z.literal(true).optional(),
|
|
13
14
|
model: z
|
|
14
15
|
.string()
|
|
15
16
|
.trim()
|
|
@@ -26,5 +27,7 @@ const schema = z.object({
|
|
|
26
27
|
/** Parses only settings that are safe to send directly to Codex thread/start. */
|
|
27
28
|
export function parseStartSessionRequest(input) {
|
|
28
29
|
const result = schema.safeParse(input);
|
|
29
|
-
|
|
30
|
+
if (!result.success || (result.data.mandatorySkillsOnly && result.data.skillProfile))
|
|
31
|
+
return null;
|
|
32
|
+
return result.data;
|
|
30
33
|
}
|
|
@@ -69,8 +69,11 @@ export const availableSkillSchema = z
|
|
|
69
69
|
* executors load declared and other relevant skills on demand.
|
|
70
70
|
*/
|
|
71
71
|
export function isAlwaysAdvertisedSkill(skill) {
|
|
72
|
-
return (isGestaltSkillName(skill.name) &&
|
|
73
|
-
|
|
72
|
+
return isMandatoryGestaltSkill(skill.name) || (isGestaltSkillName(skill.name) && skill.enabled);
|
|
73
|
+
}
|
|
74
|
+
/** Gestalt infrastructure remains available when all optional skills are off. */
|
|
75
|
+
export function isMandatoryGestaltSkill(name) {
|
|
76
|
+
return isGestaltSkillName(name) && !['gestalt:serena', 'gestalt:playwright'].includes(name);
|
|
74
77
|
}
|
|
75
78
|
export function isGestaltSkillName(name) {
|
|
76
79
|
return name.startsWith('gestalt:');
|
|
@@ -222,6 +225,16 @@ export function reconcileSkillSelectionSnapshot(discovered, selection) {
|
|
|
222
225
|
* It neither writes configuration nor mutates the user Codex installation.
|
|
223
226
|
*/
|
|
224
227
|
export function compileSkillOverride(input) {
|
|
228
|
+
if (input.mandatorySkillsOnly) {
|
|
229
|
+
return {
|
|
230
|
+
source: 'explicit',
|
|
231
|
+
skillsConfig: input.discovered.map(({ path, name }) => ({
|
|
232
|
+
path,
|
|
233
|
+
enabled: isMandatoryGestaltSkill(name),
|
|
234
|
+
})),
|
|
235
|
+
warnings: [],
|
|
236
|
+
};
|
|
237
|
+
}
|
|
225
238
|
const effective = selectEffectiveSkillSelection(input);
|
|
226
239
|
const reconciled = reconcileSkillSelectionSnapshot(input.discovered, effective.selection);
|
|
227
240
|
return {
|
|
@@ -278,7 +278,7 @@ export class KimiSessionRuntime {
|
|
|
278
278
|
const selection = effective?.skills ?? [];
|
|
279
279
|
if (effective?.selectedProfileName)
|
|
280
280
|
return normalizeSkillProfileName(effective.selectedProfileName);
|
|
281
|
-
if (!selection.length)
|
|
281
|
+
if (!selection.length && !effective?.mandatorySkillsOnly)
|
|
282
282
|
return 'default';
|
|
283
283
|
const canonical = JSON.stringify([...selection].sort((a, b) => a.path.localeCompare(b.path)));
|
|
284
284
|
return `sel-${createHash('sha256').update(canonical).digest('hex').slice(0, 12)}`;
|