@kabmo-labs/kabmo 0.25.0 → 0.26.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/index.html +1 -1
- package/dist/client/index.js +440 -436
- package/dist/client/static/js/{index-ga8cbpt4.js → index-95b3n20k.js} +945 -945
- package/dist/client/static/js/index-p2yw9ywf.css +1 -0
- package/package.json +1 -1
- package/src/client/components/common/session-actions-menu/index.tsx +38 -12
- package/src/client/components/common/session-branch/BranchGuides.tsx +93 -0
- package/src/client/components/common/session-branch/SubagentRow.tsx +77 -0
- package/src/client/components/common/session-branch/index.tsx +169 -0
- package/src/client/components/common/session-branch/session-branch.test.tsx +240 -0
- package/src/client/components/common/session-branch/style.ts +29 -0
- package/src/client/components/common/session-row/StatusSlot.tsx +15 -3
- package/src/client/components/common/session-row/index.tsx +24 -25
- package/src/client/components/common/session-row/session-row.test.tsx +11 -0
- package/src/client/components/common/session-state-provider/index.tsx +1 -1
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +64 -68
- package/src/client/components/layout/session-sidebar/SessionItem.batch.test.ts +3 -3
- package/src/client/components/layout/session-sidebar/SessionItem.test.ts +25 -2
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +33 -30
- package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +261 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +35 -225
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +36 -16
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +11 -3
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +13 -4
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +28 -13
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +59 -57
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +57 -61
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +5 -0
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +33 -30
- package/src/client/components/settings/Sidebar.tsx +1 -1
- package/src/client/components/settings/categories/NotificationSettings.test.tsx +92 -0
- package/src/client/components/settings/categories/NotificationSettings.tsx +112 -2
- package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +94 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +31 -5
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +28 -39
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +7 -5
- package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +10 -0
- package/src/client/components/workspace/chat-timeline/RunFooter.tsx +12 -3
- package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +15 -1
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +85 -0
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +84 -0
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +5 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +10 -21
- package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +115 -0
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +173 -0
- package/src/client/components/workspace/chat-timeline/target-picker/parent-session-options.test.ts +49 -0
- package/src/client/hooks/chat/composer/items.test.ts +19 -0
- package/src/client/hooks/chat/omp/folder-auto-expand.ts +1 -1
- package/src/client/hooks/chat/omp/pending-adoption.ts +51 -0
- package/src/client/hooks/chat/omp/pending-child.test.ts +73 -0
- package/src/client/hooks/chat/omp/pending-entry.ts +59 -0
- package/src/client/hooks/chat/omp/pending-rows.ts +6 -2
- package/src/client/hooks/chat/omp/pending-sessions.test.ts +1 -2
- package/src/client/hooks/chat/omp/pending-sessions.ts +45 -69
- package/src/client/hooks/chat/omp/pending-waiting.ts +1 -1
- package/src/client/hooks/chat/omp/run-switch.ts +1 -1
- package/src/client/hooks/chat/omp/session-list.tsx +4 -0
- package/src/client/hooks/chat/subagents/roster.ts +122 -0
- package/src/client/hooks/chat/timeline/child-spawn.test.ts +55 -0
- package/src/client/hooks/chat/timeline/child-spawn.ts +45 -0
- package/src/client/hooks/chat/timeline/fork-request.test.ts +54 -0
- package/src/client/hooks/chat/timeline/fork-request.ts +43 -0
- package/src/client/hooks/chat/timeline/mode-availability.test.ts +1 -1
- package/src/client/hooks/chat/timeline/mode-availability.ts +33 -0
- package/src/client/hooks/chat/timeline/mode-markers.ts +7 -1
- package/src/client/hooks/chat/timeline/mode-post.ts +15 -3
- package/src/client/hooks/chat/timeline/modes-contract.ts +9 -4
- package/src/client/hooks/chat/timeline/modes.test.ts +56 -18
- package/src/client/hooks/chat/timeline/modes.ts +42 -29
- package/src/client/hooks/chat/timeline/pending-branch.ts +205 -0
- package/src/client/hooks/chat/timeline/pending-dispatch.ts +253 -0
- package/src/client/hooks/chat/timeline/send.ts +17 -103
- package/src/client/hooks/chat/timeline/session-harness.ts +6 -0
- package/src/client/hooks/chat/timeline/stop-with-queue.ts +42 -0
- package/src/client/hooks/chat/timeline/use-fork-session.ts +40 -31
- package/src/client/hooks/models/use-harness-update.test.ts +137 -44
- package/src/client/hooks/models/use-harness-update.ts +133 -85
- package/src/client/hooks/ui/input-required-alert.ts +12 -5
- package/src/client/hooks/ui/notifications.ts +45 -0
- package/src/client/hooks/ui/run-outcome-alert.ts +48 -0
- package/src/client/hooks/workspace/expanded-sessions.ts +36 -7
- package/src/client/lib/native/open-session.ts +33 -0
- package/src/client/lib/notifications/os.test.ts +125 -0
- package/src/client/lib/notifications/os.ts +130 -0
- package/src/client/lib/plugins/sidebar-bridge.ts +2 -20
- package/src/client/lib/router/open-session.test.ts +75 -0
- package/src/client/lib/router/open-session.ts +34 -0
- package/src/client/lib/signals.ts +5 -1
- package/src/client/main.tsx +6 -0
- package/src/server/lib/db/schema.ts +1 -0
- package/src/server/lib/harness/acp/calls.ts +15 -1
- package/src/server/lib/harness/acp/client-capabilities.test.ts +55 -0
- package/src/server/lib/harness/acp/client-capabilities.ts +61 -0
- package/src/server/lib/harness/acp/client-fs.test.ts +135 -0
- package/src/server/lib/harness/acp/client-fs.ts +131 -0
- package/src/server/lib/harness/acp/client-initialize.test.ts +70 -0
- package/src/server/lib/harness/acp/client-initialize.ts +84 -0
- package/src/server/lib/harness/acp/client.ts +31 -21
- package/src/server/lib/harness/acp/commands.test.ts +5 -5
- package/src/server/lib/harness/acp/commands.ts +14 -2
- package/src/server/lib/harness/acp/frames-timing.test.ts +68 -0
- package/src/server/lib/harness/acp/frames-v2.test.ts +85 -0
- package/src/server/lib/harness/acp/frames.ts +71 -158
- package/src/server/lib/harness/acp/mapper.test.ts +40 -0
- package/src/server/lib/harness/acp/mapper.ts +12 -0
- package/src/server/lib/harness/acp/permissions.ts +6 -0
- package/src/server/lib/harness/acp/protocol.ts +41 -2
- package/src/server/lib/harness/acp/session-facts.ts +1 -1
- package/src/server/lib/harness/acp/session-handshake.test.ts +90 -1
- package/src/server/lib/harness/acp/session-handshake.ts +83 -6
- package/src/server/lib/harness/acp/session-idle.ts +7 -6
- package/src/server/lib/harness/acp/session-notifications.ts +41 -2
- package/src/server/lib/harness/acp/session-observers.test.ts +63 -0
- package/src/server/lib/harness/acp/session-permissions.test.ts +29 -0
- package/src/server/lib/harness/acp/session-permissions.ts +36 -0
- package/src/server/lib/harness/acp/session-requests.test.ts +92 -0
- package/src/server/lib/harness/acp/session-requests.ts +48 -6
- package/src/server/lib/harness/acp/session-turns.ts +8 -3
- package/src/server/lib/harness/acp/session-usage.ts +4 -0
- package/src/server/lib/harness/acp/session-web-state.ts +30 -2
- package/src/server/lib/harness/acp/session.test-util.ts +19 -1
- package/src/server/lib/harness/acp/session.ts +60 -60
- package/src/server/lib/harness/acp/tool-calls.ts +223 -0
- package/src/server/lib/harness/acp/turn.test.ts +102 -0
- package/src/server/lib/harness/acp/turn.ts +81 -6
- package/src/server/lib/harness/acp/v2.test.ts +144 -0
- package/src/server/lib/harness/acp/v2.ts +220 -0
- package/src/server/lib/harness/acp/verbs.ts +46 -6
- package/src/server/lib/harness/launch.test.ts +25 -0
- package/src/server/lib/harness/launch.ts +21 -9
- package/src/server/lib/harness/session.ts +3 -0
- package/src/server/lib/harness/update-job-store.test.ts +37 -12
- package/src/server/lib/harness/update-job-store.ts +22 -16
- package/src/server/lib/harness/update-job.server.ts +66 -175
- package/src/server/lib/harness/update-queue.server.ts +292 -0
- package/src/server/lib/harness/update-queue.test.ts +265 -0
- package/src/server/lib/harness/update-spawn.server.ts +96 -0
- package/src/server/lib/harness/update-worker.ts +8 -3
- package/src/server/lib/lifecycle/after-listen.ts +9 -0
- package/src/server/lib/lifecycle/paths.ts +14 -9
- package/src/server/lib/omp/rpc/run-settle.server.ts +10 -1
- package/src/server/lib/omp/rpc/subagent-liveness.ts +5 -5
- package/src/server/lib/omp/rpc/terminal-settle.ts +5 -1
- package/src/server/lib/omp/session/delete-flow.server.ts +1 -0
- package/src/server/lib/omp/session/sidebar-data.server.ts +10 -12
- package/src/server/lib/sessions/fork.server.test.ts +68 -0
- package/src/server/lib/sessions/fork.server.ts +31 -6
- package/src/server/lib/sessions/spawn.server.test.ts +41 -0
- package/src/server/lib/sessions/spawn.server.ts +27 -2
- package/src/server/routes/agent/harness-command.ts +6 -5
- package/src/server/routes/chat/stream.ts +7 -2
- package/src/server/routes/harness/update-status.ts +18 -12
- package/src/server/routes/harness/update.test.ts +53 -16
- package/src/server/routes/harness/update.ts +13 -8
- package/src/server/routes/sessions/body-readers.ts +43 -0
- package/src/server/routes/sessions/fork.ts +19 -4
- package/src/server/routes/sessions/routes.test.ts +1 -2
- package/src/server/routes/sessions/session.ts +19 -0
- package/src/server/routes/sessions/spawn.ts +16 -13
- package/src/shared/lib/chat/omp/agent-events.ts +11 -0
- package/src/shared/lib/chat/omp/session-modes-signal.test.ts +41 -0
- package/src/shared/lib/harness/mode-signal.ts +20 -0
- package/src/shared/lib/harness/session-modes.ts +24 -0
- package/src/shared/lib/harness/update-job.ts +53 -6
- package/src/shared/lib/icons/tint-hues.generated.ts +34 -34
- package/src/shared/lib/notifications/outcomes.test.ts +96 -0
- package/src/shared/lib/notifications/outcomes.ts +64 -0
- package/src/shared/lib/notifications/settings.test.ts +49 -0
- package/src/shared/lib/notifications/settings.ts +34 -0
- package/src/shared/lib/omp/session/default-title.ts +5 -4
- package/src/shared/lib/omp/session/prewarm-misc.test.ts +3 -2
- package/src/shared/lib/omp/session/schema-migrations.ts +4 -0
- package/src/shared/lib/omp/session/stream-state.server.test.ts +19 -0
- package/src/shared/lib/omp/session/stream-state.server.ts +24 -4
- package/src/shared/lib/settings/defaults.ts +3 -0
- package/src/shared/types/harness-update.ts +24 -0
- package/src/shared/types/realtime.ts +2 -0
- package/src/shared/types/settings/state.ts +10 -0
- package/src/shared/types/workspace.ts +4 -0
- package/src/test-support/harness-table.test-util.ts +25 -9
- package/dist/client/static/js/index-bc9aa4mx.css +0 -1
- package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +0 -113
- package/src/client/components/common/subagent-list/index.tsx +0 -165
- package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +0 -66
- package/src/client/hooks/workspace/child-expansion.ts +0 -33
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
} from '@/server/lib/omp/session/transcript-copy';
|
|
38
38
|
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
39
39
|
import type { SelectedModel } from '@/shared/types/models';
|
|
40
|
+
import type { AgentImage } from '@/shared/types/omp/agent';
|
|
40
41
|
import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
41
42
|
import {
|
|
42
43
|
createSessionRelation,
|
|
@@ -113,6 +114,13 @@ export interface ForkSessionInput {
|
|
|
113
114
|
/** A message/entry id; the fork cuts at the start of its turn. Omit for tip. */
|
|
114
115
|
anchorEntryId?: string | null;
|
|
115
116
|
prompt?: string | null;
|
|
117
|
+
/** Images the composer attached to the first prompt of the branch. */
|
|
118
|
+
images?: AgentImage[] | null;
|
|
119
|
+
/** The composer's model pick; applied before the branch's first prompt. */
|
|
120
|
+
model?: SelectedModel | null;
|
|
121
|
+
thinkingLevel?: string | null;
|
|
122
|
+
/** The composer's approval pick; omitted keeps the persisted setting. */
|
|
123
|
+
accessMode?: ApprovalMode | null;
|
|
116
124
|
title?: string | null;
|
|
117
125
|
cwd?: string | null;
|
|
118
126
|
visibility?: 'visible' | 'hidden';
|
|
@@ -200,9 +208,11 @@ export async function forkSession(
|
|
|
200
208
|
const cwd = input.cwd || source.cwd;
|
|
201
209
|
if (!cwd) throw new SessionForkError('cwd_required', 'The source has no working directory');
|
|
202
210
|
|
|
203
|
-
const accessMode = await loadPersistedAccessMode();
|
|
211
|
+
const accessMode = input.accessMode ?? await loadPersistedAccessMode();
|
|
204
212
|
const token = createAgentToken();
|
|
205
213
|
const env = agentEnvironment(token);
|
|
214
|
+
const model = input.model ?? null;
|
|
215
|
+
const thinkingLevel = input.thinkingLevel ?? null;
|
|
206
216
|
const forkCount = (await listForkRelations(input.sourceSessionId)).length + 1;
|
|
207
217
|
const sourceFile = await findSessionFileById(input.sourceSessionId);
|
|
208
218
|
let started: { session: ForkedSession; realSessionId: string };
|
|
@@ -232,7 +242,7 @@ export async function forkSession(
|
|
|
232
242
|
input.title?.trim() || newBranchTitle(transcriptTitle(lines), input.sourceSessionId, forkCount);
|
|
233
243
|
createdFile = await writeBranchFile({ sourceFile, lines: kept, newId, timestamp, title });
|
|
234
244
|
try {
|
|
235
|
-
started = await deps.startRpc(newId, createdFile, cwd, accessMode,
|
|
245
|
+
started = await deps.startRpc(newId, createdFile, cwd, accessMode, model, env);
|
|
236
246
|
} catch (error) {
|
|
237
247
|
await Bun.file(createdFile).delete().catch(() => {});
|
|
238
248
|
throw new SessionForkError(
|
|
@@ -255,8 +265,8 @@ export async function forkSession(
|
|
|
255
265
|
forkAgentSessionId: source.agentSessionId || input.sourceSessionId,
|
|
256
266
|
cwd,
|
|
257
267
|
accessMode,
|
|
258
|
-
model
|
|
259
|
-
thinkingLevel
|
|
268
|
+
model,
|
|
269
|
+
thinkingLevel,
|
|
260
270
|
env,
|
|
261
271
|
});
|
|
262
272
|
} catch (error) {
|
|
@@ -274,6 +284,16 @@ export async function forkSession(
|
|
|
274
284
|
}
|
|
275
285
|
}
|
|
276
286
|
|
|
287
|
+
// The RPC fork RESUMES the source transcript, which carries its own model
|
|
288
|
+
// and thinking level. A pick made in the fork composer is applied on top,
|
|
289
|
+
// before the branch's first prompt — ACP already received both at spawn.
|
|
290
|
+
if (sourceFile) {
|
|
291
|
+
if (model) await started.session.send({ type: 'set_model', ...model }).catch(() => {});
|
|
292
|
+
if (thinkingLevel) {
|
|
293
|
+
await started.session.send({ type: 'set_thinking_level', level: thinkingLevel }).catch(() => {});
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
277
297
|
try {
|
|
278
298
|
await rememberAgentToken(started.realSessionId, token);
|
|
279
299
|
await createSessionRelation({
|
|
@@ -283,8 +303,13 @@ export async function forkSession(
|
|
|
283
303
|
lifecycleOwnerSessionId: input.lifecycleOwnerSessionId ?? null,
|
|
284
304
|
visibility: input.visibility ?? 'visible',
|
|
285
305
|
});
|
|
286
|
-
|
|
287
|
-
|
|
306
|
+
const prompt = input.prompt?.trim() ?? '';
|
|
307
|
+
if (prompt || input.images?.length) {
|
|
308
|
+
await started.session.send({
|
|
309
|
+
type: 'prompt',
|
|
310
|
+
message: prompt,
|
|
311
|
+
...(input.images?.length ? { images: input.images } : {}),
|
|
312
|
+
});
|
|
288
313
|
}
|
|
289
314
|
} catch (error) {
|
|
290
315
|
await started.session.destroyAndWait().catch(() => {});
|
|
@@ -94,6 +94,7 @@ describe('spawnChildSession', () => {
|
|
|
94
94
|
harness: 'omp-rpc',
|
|
95
95
|
parentSessionId: 'parent',
|
|
96
96
|
depth: 1,
|
|
97
|
+
model: null,
|
|
97
98
|
});
|
|
98
99
|
expect(child.sent).toHaveLength(1);
|
|
99
100
|
expect(child.sent[0]).toMatchObject({ type: 'prompt' });
|
|
@@ -155,6 +156,46 @@ describe('spawnChildSession', () => {
|
|
|
155
156
|
).rejects.toMatchObject({ code: 'parent_folder_mismatch' });
|
|
156
157
|
});
|
|
157
158
|
|
|
159
|
+
test('applies the composer model, thinking level and access mode to an RPC child', async () => {
|
|
160
|
+
await saveHarnessSession({
|
|
161
|
+
sessionId: 'parent',
|
|
162
|
+
harness: 'omp-rpc',
|
|
163
|
+
agentSessionId: '',
|
|
164
|
+
cwd: root,
|
|
165
|
+
});
|
|
166
|
+
const child = fakeSession('child');
|
|
167
|
+
let mode: string | undefined;
|
|
168
|
+
const deps: SpawnSessionDeps = {
|
|
169
|
+
async startRpc(_cwd, accessMode) {
|
|
170
|
+
mode = accessMode;
|
|
171
|
+
return { session: child, realSessionId: child.sessionId };
|
|
172
|
+
},
|
|
173
|
+
async startAcp() {
|
|
174
|
+
throw new Error('not used');
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
await spawnChildSession(
|
|
179
|
+
{
|
|
180
|
+
parentSessionId: 'parent',
|
|
181
|
+
prompt: 'review this',
|
|
182
|
+
model: { provider: 'acme', modelId: 'big' },
|
|
183
|
+
thinkingLevel: 'high',
|
|
184
|
+
accessMode: 'yolo',
|
|
185
|
+
images: [{ type: 'image', data: 'aGk=', mimeType: 'image/png' }],
|
|
186
|
+
},
|
|
187
|
+
deps,
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
expect(mode).toBe('yolo');
|
|
191
|
+
expect(child.sent[0]).toEqual({ type: 'set_model', provider: 'acme', modelId: 'big' });
|
|
192
|
+
expect(child.sent[1]).toEqual({ type: 'set_thinking_level', level: 'high' });
|
|
193
|
+
expect(child.sent[2]).toMatchObject({
|
|
194
|
+
type: 'prompt',
|
|
195
|
+
images: [{ type: 'image', data: 'aGk=', mimeType: 'image/png' }],
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
158
199
|
test('an ACP worker with no explicit model leaves the harness default alone', async () => {
|
|
159
200
|
await saveHarnessSession({
|
|
160
201
|
sessionId: 'parent',
|
|
@@ -31,6 +31,7 @@ import { harnessProbeModels } from '@/server/lib/harness/probe-cache.server';
|
|
|
31
31
|
import { getDb } from '@/server/db.server';
|
|
32
32
|
import { HARNESS_IDS, harnessDescriptor, type HarnessId } from '@/shared/lib/harness/catalog';
|
|
33
33
|
import type { SelectedModel } from '@/shared/types/models';
|
|
34
|
+
import type { AgentImage } from '@/shared/types/omp/agent';
|
|
34
35
|
import { MAX_SESSION_DEPTH } from '@/server/lib/sessions/relation-types';
|
|
35
36
|
import {
|
|
36
37
|
createSessionRelation,
|
|
@@ -97,8 +98,13 @@ export interface SpawnChildSessionInput {
|
|
|
97
98
|
harness?: string | null;
|
|
98
99
|
cwd?: string | null;
|
|
99
100
|
prompt: string;
|
|
101
|
+
/** Images the composer attached to the first prompt. */
|
|
102
|
+
images?: AgentImage[] | null;
|
|
100
103
|
model?: SelectedModel | null;
|
|
101
104
|
thinkingLevel?: string | null;
|
|
105
|
+
/** The composer's approval pick. Omitted by the CLI, which keeps the
|
|
106
|
+
* persisted setting. */
|
|
107
|
+
accessMode?: ApprovalMode | null;
|
|
102
108
|
lifecycleOwnerSessionId?: string | null;
|
|
103
109
|
visibility?: 'visible' | 'hidden';
|
|
104
110
|
parentNotifications?: 'auto' | 'stuck' | 'off';
|
|
@@ -109,6 +115,9 @@ export interface SpawnChildSessionResult {
|
|
|
109
115
|
harness: HarnessId;
|
|
110
116
|
parentSessionId: string | null;
|
|
111
117
|
depth: number;
|
|
118
|
+
/** The model the child resolved to, so the client can seed its composer
|
|
119
|
+
* before the transcript carries a model_change entry. */
|
|
120
|
+
model: SelectedModel | null;
|
|
112
121
|
}
|
|
113
122
|
|
|
114
123
|
function harnessOf(value: string | null | undefined): HarnessId | null {
|
|
@@ -250,7 +259,7 @@ export async function spawnChildSession(
|
|
|
250
259
|
);
|
|
251
260
|
}
|
|
252
261
|
|
|
253
|
-
const accessMode = await loadPersistedAccessMode();
|
|
262
|
+
const accessMode = input.accessMode ?? await loadPersistedAccessMode();
|
|
254
263
|
const token = createAgentToken();
|
|
255
264
|
const env = agentEnvironment(token);
|
|
256
265
|
const model = await resolveSpawnModel(input.model ?? null, harness, parentSessionId, cwd);
|
|
@@ -267,6 +276,17 @@ export async function spawnChildSession(
|
|
|
267
276
|
env,
|
|
268
277
|
});
|
|
269
278
|
|
|
279
|
+
// `startRpc` takes a cwd only, so an RPC child would ignore the composer's
|
|
280
|
+
// model pick and run the project default. The pick is applied to the child
|
|
281
|
+
// BEFORE its first prompt, the same order `POST /api/agent/new` uses. ACP
|
|
282
|
+
// already received both at spawn time above.
|
|
283
|
+
if (harness === 'omp-rpc') {
|
|
284
|
+
if (model) await started.session.send({ type: 'set_model', ...model }).catch(() => {});
|
|
285
|
+
if (input.thinkingLevel) {
|
|
286
|
+
await started.session.send({ type: 'set_thinking_level', level: input.thinkingLevel }).catch(() => {});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
270
290
|
try {
|
|
271
291
|
await rememberAgentToken(started.realSessionId, token);
|
|
272
292
|
await createSessionRelation({
|
|
@@ -290,7 +310,11 @@ export async function spawnChildSession(
|
|
|
290
310
|
const message = parentSessionId
|
|
291
311
|
? dispatchedWorkerPrompt(parentSessionId, started.realSessionId, prompt)
|
|
292
312
|
: prompt;
|
|
293
|
-
await started.session.send({
|
|
313
|
+
await started.session.send({
|
|
314
|
+
type: 'prompt',
|
|
315
|
+
message,
|
|
316
|
+
...(input.images?.length ? { images: input.images } : {}),
|
|
317
|
+
});
|
|
294
318
|
} catch (error) {
|
|
295
319
|
await started.session.destroyAndWait().catch(() => {});
|
|
296
320
|
throw new SessionSpawnError(
|
|
@@ -306,5 +330,6 @@ export async function spawnChildSession(
|
|
|
306
330
|
harness,
|
|
307
331
|
parentSessionId,
|
|
308
332
|
depth,
|
|
333
|
+
model,
|
|
309
334
|
};
|
|
310
335
|
}
|
|
@@ -40,9 +40,10 @@ import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
|
40
40
|
*
|
|
41
41
|
* - an id this build's catalog no longer lists spawns NOTHING (a retired
|
|
42
42
|
* adapter must not be guessed at from a stale row);
|
|
43
|
-
* - a harness whose probe says it
|
|
44
|
-
* because the only alternative is
|
|
45
|
-
* chat's id — which would silently
|
|
43
|
+
* - a harness whose probe says it can neither `session/load` nor
|
|
44
|
+
* `session/resume` is refused in words, because the only alternative is
|
|
45
|
+
* starting a FRESH agent session under this chat's id — which would silently
|
|
46
|
+
* throw the conversation away.
|
|
46
47
|
*
|
|
47
48
|
* `omp-acp` is excluded even though ACP is what it speaks. It WRITES a session
|
|
48
49
|
* file, so the locator resumes it in place over RPC — the same chat, the same
|
|
@@ -63,8 +64,8 @@ export async function resumeRecordedHarnessSession(
|
|
|
63
64
|
|
|
64
65
|
const label = harnessDescriptor(harness)?.label ?? harness;
|
|
65
66
|
const probe = await freshProbe(harness);
|
|
66
|
-
if (probe
|
|
67
|
-
throw new Error(`${label} cannot restore this chat: it
|
|
67
|
+
if (probe && !probe.capabilities.loadSession && !probe.capabilities.resumeSession) {
|
|
68
|
+
throw new Error(`${label} cannot restore this chat: it supports neither session/load nor session/resume.`);
|
|
68
69
|
}
|
|
69
70
|
const { token, env } = mintAgentEnvironment();
|
|
70
71
|
const { session, realSessionId } = await startAcpSession({
|
|
@@ -46,6 +46,8 @@ async function handleStreamingRequest(request: Request) {
|
|
|
46
46
|
headers: { 'Cache-Control': 'no-cache, no-transform', 'X-Accel-Buffering': 'no' },
|
|
47
47
|
async onStart(handlers) {
|
|
48
48
|
let isAborted = false;
|
|
49
|
+
/** The reason the simulated stream threw, when it did. */
|
|
50
|
+
let failure: string | null = null;
|
|
49
51
|
const abortListener = () => {
|
|
50
52
|
isAborted = true;
|
|
51
53
|
};
|
|
@@ -94,13 +96,16 @@ async function handleStreamingRequest(request: Request) {
|
|
|
94
96
|
} catch (err: unknown) {
|
|
95
97
|
if (!isAborted) {
|
|
96
98
|
const message = err instanceof Error ? err.message : 'Streaming execution error';
|
|
99
|
+
failure = message;
|
|
97
100
|
sendEvent('error', { error: message });
|
|
98
101
|
}
|
|
99
102
|
} finally {
|
|
100
103
|
request.signal.removeEventListener('abort', abortListener);
|
|
101
104
|
// Terminal badge, not a deletion: opening the session acknowledges it,
|
|
102
|
-
// exactly as it does for a real run. An aborted stream is `abort
|
|
103
|
-
|
|
105
|
+
// exactly as it does for a real run. An aborted stream is `abort`, and a
|
|
106
|
+
// stream that threw carries its reason so the same failure notification
|
|
107
|
+
// fires here as on a real run.
|
|
108
|
+
void markStreamStatus(sessionId, isAborted ? 'abort' : 'finish', undefined, failure);
|
|
104
109
|
localRuns().delete(sessionId);
|
|
105
110
|
handlers.close();
|
|
106
111
|
}
|
|
@@ -4,23 +4,29 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* `GET /api/harness/update/status` —
|
|
7
|
+
* `GET /api/harness/update/status` — every harness's background update record.
|
|
8
8
|
*
|
|
9
|
-
* The POST answers
|
|
10
|
-
*
|
|
11
|
-
* finished.
|
|
12
|
-
*
|
|
13
|
-
* process, not in the worker.
|
|
9
|
+
* The POST answers in milliseconds and the install keeps running in a detached
|
|
10
|
+
* worker, so this is how the dialog learns where each run is and whether it
|
|
11
|
+
* finished. One record per harness, because two presses are a queue: a run
|
|
12
|
+
* installing and a run waiting its turn are two different rows.
|
|
14
13
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* A poll is also where the SERVER acts on the records: it applies the
|
|
15
|
+
* post-install side effects (`forgetProbe`, the launch-line repoint), settles a
|
|
16
|
+
* run that died without reporting, and starts the next waiting one. The ticker
|
|
17
|
+
* in `update-queue.server.ts` does the same without a browser, so this route is
|
|
18
|
+
* a read with the same pass in front of it — never the only thing keeping the
|
|
19
|
+
* queue moving.
|
|
20
|
+
*
|
|
21
|
+
* An empty array is a real answer — no update has ever run — and it must not be
|
|
22
|
+
* a 404: the About card asks this on every open, and a "not found" would read as
|
|
23
|
+
* a broken route rather than "nothing is running".
|
|
18
24
|
*/
|
|
19
25
|
|
|
20
26
|
import { json, NO_STORE_HEADERS } from '@/server/lib/remix-compat';
|
|
21
|
-
import {
|
|
27
|
+
import { pumpUpdateQueue } from '@/server/lib/harness/update-queue.server';
|
|
22
28
|
|
|
23
29
|
export async function loader() {
|
|
24
|
-
const
|
|
25
|
-
return json({
|
|
30
|
+
const jobs = await pumpUpdateQueue();
|
|
31
|
+
return json({ jobs }, { headers: NO_STORE_HEADERS });
|
|
26
32
|
}
|
|
@@ -6,11 +6,15 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* `POST /api/harness/update` and `GET /api/harness/update/status`.
|
|
8
8
|
*
|
|
9
|
-
* The route used to run the installs itself; it now
|
|
10
|
-
* and answers `202`. These cases pin the answers that do NOT
|
|
11
|
-
* the refusals and the progress read — because those are the
|
|
12
|
-
* branches on, and a wrong status there either starts a
|
|
13
|
-
* reports success it never observed.
|
|
9
|
+
* The route used to run the installs itself; it now accepts a run as a
|
|
10
|
+
* background job and answers `202`. These cases pin the answers that do NOT
|
|
11
|
+
* spawn anything — the refusals and the progress read — because those are the
|
|
12
|
+
* shapes the dialog branches on, and a wrong status there either starts a
|
|
13
|
+
* competing install or reports success it never observed.
|
|
14
|
+
*
|
|
15
|
+
* The queue's own decision (a second harness is accepted and waits) is pinned in
|
|
16
|
+
* `update-queue.test.ts`: reaching it through this route means planning an
|
|
17
|
+
* install, which reads the npm registry and probes the machine.
|
|
14
18
|
*/
|
|
15
19
|
|
|
16
20
|
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
@@ -20,6 +24,7 @@ import { join } from 'node:path';
|
|
|
20
24
|
import { action } from '@/server/routes/harness/update';
|
|
21
25
|
import { loader as statusLoader } from '@/server/routes/harness/update-status';
|
|
22
26
|
import { writeUpdateJob } from '@/server/lib/harness/update-job-store';
|
|
27
|
+
import { getHarnessUpdateStatusPath } from '@/server/lib/lifecycle/paths';
|
|
23
28
|
import type { HarnessUpdateJob } from '@/shared/types/harness-update';
|
|
24
29
|
|
|
25
30
|
let dir = '';
|
|
@@ -54,6 +59,7 @@ function job(overrides: Partial<HarnessUpdateJob> = {}): HarnessUpdateJob {
|
|
|
54
59
|
label: 'claude',
|
|
55
60
|
startedAt: Date.now(),
|
|
56
61
|
finishedAt: null,
|
|
62
|
+
queuedAt: null,
|
|
57
63
|
pid: process.pid,
|
|
58
64
|
steps: [{ part: 'adapter', command: 'npm install -g x', argv: ['npm', 'install', '-g', 'x'], state: 'running', code: null }],
|
|
59
65
|
output: '',
|
|
@@ -82,38 +88,69 @@ describe('POST /api/harness/update', () => {
|
|
|
82
88
|
expect(payload.error).toContain('installed by its vendor');
|
|
83
89
|
});
|
|
84
90
|
|
|
85
|
-
test('a second press
|
|
91
|
+
test('a second press for the SAME harness is a 409 that names the run', async () => {
|
|
86
92
|
// Measured corruption vector: a reload forgot the run and offered the button,
|
|
87
93
|
// so two `npm install -g` wrote the same prefix at once. The record on disk is
|
|
88
|
-
// what refuses it now.
|
|
89
|
-
|
|
94
|
+
// what refuses it now. A DIFFERENT harness is accepted and queued instead —
|
|
95
|
+
// see `update-queue.test.ts`.
|
|
96
|
+
await writeUpdateJob(job(), getHarnessUpdateStatusPath('claude'));
|
|
90
97
|
const response = (await action(post('claude'))) as Response;
|
|
91
98
|
expect(response.status).toBe(409);
|
|
92
99
|
const payload = (await response.json()) as { error: string; job: HarnessUpdateJob };
|
|
93
100
|
expect(payload.error).toContain('already running');
|
|
94
101
|
expect(payload.job.harness).toBe('claude');
|
|
95
102
|
});
|
|
103
|
+
|
|
104
|
+
test('a press for a harness that is already QUEUED says queued, not running', async () => {
|
|
105
|
+
await writeUpdateJob(
|
|
106
|
+
job({ harness: 'codex', label: 'codex', pid: null, queuedAt: Date.now() }),
|
|
107
|
+
getHarnessUpdateStatusPath('codex'),
|
|
108
|
+
);
|
|
109
|
+
const response = (await action(post('codex'))) as Response;
|
|
110
|
+
expect(response.status).toBe(409);
|
|
111
|
+
const payload = (await response.json()) as { error: string; job: HarnessUpdateJob };
|
|
112
|
+
expect(payload.error).toContain('already queued');
|
|
113
|
+
expect(payload.job.queuedAt).not.toBeNull();
|
|
114
|
+
});
|
|
96
115
|
});
|
|
97
116
|
|
|
98
117
|
describe('GET /api/harness/update/status', () => {
|
|
99
|
-
test('no run ever started is
|
|
118
|
+
test('no run ever started is an empty list, not a 404', async () => {
|
|
100
119
|
const response = (await statusLoader()) as Response;
|
|
101
120
|
expect(response.status).toBe(200);
|
|
102
|
-
expect(((await response.json()) as {
|
|
121
|
+
expect(((await response.json()) as { jobs: unknown[] }).jobs).toEqual([]);
|
|
103
122
|
});
|
|
104
123
|
|
|
105
124
|
test('a finished run is reported with its message', async () => {
|
|
106
|
-
|
|
125
|
+
await writeUpdateJob(job({
|
|
107
126
|
pid: null,
|
|
108
127
|
finishedAt: Date.now(),
|
|
109
128
|
ok: true,
|
|
110
129
|
applied: true,
|
|
111
130
|
message: 'claude updated (adapter) — check its status to read the new version',
|
|
112
|
-
});
|
|
113
|
-
await
|
|
131
|
+
}), getHarnessUpdateStatusPath('claude'));
|
|
132
|
+
const response = (await statusLoader()) as Response;
|
|
133
|
+
const { jobs } = (await response.json()) as { jobs: HarnessUpdateJob[] };
|
|
134
|
+
expect(jobs).toHaveLength(1);
|
|
135
|
+
expect(jobs[0].ok).toBe(true);
|
|
136
|
+
expect(jobs[0].message).toContain('claude updated');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('an installing run and a QUEUED one are two records, and the queue is not started', async () => {
|
|
140
|
+
// The press that would have been a 409 is now a waiting record. The poll must
|
|
141
|
+
// report both, and the waiting one must stay waiting while the first installs
|
|
142
|
+
// — the whole point of one install at a time.
|
|
143
|
+
await writeUpdateJob(job(), getHarnessUpdateStatusPath('claude'));
|
|
144
|
+
await writeUpdateJob(
|
|
145
|
+
job({ harness: 'codex', label: 'codex', pid: null, queuedAt: Date.now() }),
|
|
146
|
+
getHarnessUpdateStatusPath('codex'),
|
|
147
|
+
);
|
|
148
|
+
|
|
114
149
|
const response = (await statusLoader()) as Response;
|
|
115
|
-
const
|
|
116
|
-
expect(
|
|
117
|
-
|
|
150
|
+
const { jobs } = (await response.json()) as { jobs: HarnessUpdateJob[] };
|
|
151
|
+
expect(jobs.map((entry) => entry.harness).sort()).toEqual(['claude', 'codex']);
|
|
152
|
+
const codex = jobs.find((entry) => entry.harness === 'codex');
|
|
153
|
+
expect(codex?.queuedAt).not.toBeNull();
|
|
154
|
+
expect(codex?.pid).toBeNull();
|
|
118
155
|
});
|
|
119
156
|
});
|
|
@@ -45,9 +45,10 @@ import { harnessVersionState, type HarnessVersionState } from '@/server/lib/harn
|
|
|
45
45
|
import { planHarnessUpdate, type HarnessUpdateStep } from '@/shared/lib/harness/update-plan';
|
|
46
46
|
import { resolveOmpBin } from '@/server/lib/omp/core/cli';
|
|
47
47
|
import {
|
|
48
|
-
runningUpdateJob,
|
|
49
48
|
startHarnessUpdateJob,
|
|
49
|
+
unfinishedUpdateJob,
|
|
50
50
|
} from '@/server/lib/harness/update-job.server';
|
|
51
|
+
import { jobQueued } from '@/shared/lib/harness/update-job';
|
|
51
52
|
|
|
52
53
|
/** The answer to a press that has nothing to move, still plain JSON. */
|
|
53
54
|
interface HarnessUpdateOutcome {
|
|
@@ -111,13 +112,17 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
|
|
111
112
|
}, { status: 400 });
|
|
112
113
|
}
|
|
113
114
|
|
|
114
|
-
// Read BEFORE planning: the answer to a press
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
-
|
|
115
|
+
// Read BEFORE planning: the answer to a press must not depend on what this
|
|
116
|
+
// press would have planned, and planning reads the npm registry.
|
|
117
|
+
//
|
|
118
|
+
// Only THIS harness's own unfinished record refuses the press. A different
|
|
119
|
+
// harness is ACCEPTED and queued: one install runs at a time (they share the
|
|
120
|
+
// global npm prefix), but "update these two" is one decision the user gets to
|
|
121
|
+
// make, and the queue is what makes the second press work instead of 409.
|
|
122
|
+
const running = await unfinishedUpdateJob(harness);
|
|
118
123
|
if (running) {
|
|
119
124
|
return json({
|
|
120
|
-
error: `${running.label} update is already running — it continues in the background`,
|
|
125
|
+
error: `${running.label} update is already ${jobQueued(running) ? 'queued' : 'running'} — it continues in the background`,
|
|
121
126
|
job: running,
|
|
122
127
|
}, { status: 409, headers: NO_STORE_HEADERS });
|
|
123
128
|
}
|
|
@@ -127,7 +132,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
|
|
127
132
|
const { steps, error } = selfSteps(harness, label, facts.command);
|
|
128
133
|
if (error) return json({ error }, { status: 400 });
|
|
129
134
|
const job = await startHarnessUpdateJob(harness, label, steps);
|
|
130
|
-
return json({ started: true, job }, { status: 202, headers: NO_STORE_HEADERS });
|
|
135
|
+
return json({ started: true, queued: jobQueued(job), job }, { status: 202, headers: NO_STORE_HEADERS });
|
|
131
136
|
}
|
|
132
137
|
|
|
133
138
|
// `npm`: install the package at the version the registry reports NOW, so the
|
|
@@ -167,5 +172,5 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
|
|
167
172
|
}
|
|
168
173
|
|
|
169
174
|
const job = await startHarnessUpdateJob(harness, label, steps);
|
|
170
|
-
return json({ started: true, job }, { status: 202, headers: NO_STORE_HEADERS });
|
|
175
|
+
return json({ started: true, queued: jobQueued(job), job }, { status: 202, headers: NO_STORE_HEADERS });
|
|
171
176
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The JSON body readers shared by the session routes that accept a composer's
|
|
8
|
+
* picks: `/api/sessions/spawn` and `/api/sessions/:id/fork`.
|
|
9
|
+
*
|
|
10
|
+
* One copy, because the two endpoints promise the same shape (`harness`-style
|
|
11
|
+
* explicit picks, a model pair, images) and a second parser would drift into
|
|
12
|
+
* accepting something the other refuses.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { AgentImage } from '@/shared/types/omp/agent';
|
|
16
|
+
import type { SelectedModel } from '@/shared/types/models';
|
|
17
|
+
|
|
18
|
+
/** A trimmed non-empty string, or null — the routes' "absent" spelling. */
|
|
19
|
+
export function readString(value: unknown): string | null {
|
|
20
|
+
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A `{provider, modelId}` pair, or null when either half is missing. */
|
|
24
|
+
export function readModel(value: unknown): SelectedModel | null {
|
|
25
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
26
|
+
const record = value as Record<string, unknown>;
|
|
27
|
+
return typeof record.provider === 'string' && typeof record.modelId === 'string'
|
|
28
|
+
? { provider: record.provider, modelId: record.modelId }
|
|
29
|
+
: null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Image parts of a prompt, dropping entries without bytes or a MIME type. */
|
|
33
|
+
export function readImages(value: unknown): AgentImage[] | null {
|
|
34
|
+
if (!Array.isArray(value)) return null;
|
|
35
|
+
const images = value.flatMap((entry): AgentImage[] => {
|
|
36
|
+
if (!entry || typeof entry !== 'object') return [];
|
|
37
|
+
const record = entry as Record<string, unknown>;
|
|
38
|
+
return typeof record.data === 'string' && typeof record.mimeType === 'string'
|
|
39
|
+
? [{ type: 'image', data: record.data, mimeType: record.mimeType }]
|
|
40
|
+
: [];
|
|
41
|
+
});
|
|
42
|
+
return images.length ? images : null;
|
|
43
|
+
}
|
|
@@ -14,6 +14,9 @@ import { json } from '@/server/lib/remix-compat';
|
|
|
14
14
|
import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
|
|
15
15
|
import { methodNotAllowed, parseJsonBody } from '@/server/lib/route-adapter';
|
|
16
16
|
import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
|
|
17
|
+
import { readImages, readModel, readString } from '@/server/routes/sessions/body-readers';
|
|
18
|
+
import { isApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
19
|
+
import { isMockMode } from '@/server/mock.server';
|
|
17
20
|
import {
|
|
18
21
|
SessionForkError,
|
|
19
22
|
forkSession,
|
|
@@ -22,16 +25,16 @@ import {
|
|
|
22
25
|
interface ForkBody {
|
|
23
26
|
anchorEntryId?: unknown;
|
|
24
27
|
prompt?: unknown;
|
|
28
|
+
images?: unknown;
|
|
29
|
+
model?: unknown;
|
|
30
|
+
thinkingLevel?: unknown;
|
|
31
|
+
accessMode?: unknown;
|
|
25
32
|
title?: unknown;
|
|
26
33
|
cwd?: unknown;
|
|
27
34
|
visibility?: unknown;
|
|
28
35
|
lifecycleOwnerSessionId?: unknown;
|
|
29
36
|
}
|
|
30
37
|
|
|
31
|
-
function readString(value: unknown): string | null {
|
|
32
|
-
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
38
|
export async function forkSessionRoute({ request, params }: ActionFunctionArgs) {
|
|
36
39
|
if (request.method !== 'POST') return methodNotAllowed({ request, params });
|
|
37
40
|
const sourceSessionId = params.sessionId;
|
|
@@ -39,16 +42,28 @@ export async function forkSessionRoute({ request, params }: ActionFunctionArgs)
|
|
|
39
42
|
|
|
40
43
|
const parsed = await parseJsonBody<ForkBody>(request);
|
|
41
44
|
if (!parsed.ok) return json({ error: 'Invalid JSON body' }, { status: 400 });
|
|
45
|
+
// MOCK mode has no transcript to branch. The client answers with the
|
|
46
|
+
// simulated stream on this CODE, as it does for a new chat.
|
|
47
|
+
if (isMockMode()) {
|
|
48
|
+
return json({ error: 'Mock mode runs no agent process', code: 'mock_mode' }, { status: 400 });
|
|
49
|
+
}
|
|
42
50
|
const visibility = parsed.body.visibility;
|
|
43
51
|
if (visibility !== undefined && visibility !== 'visible' && visibility !== 'hidden') {
|
|
44
52
|
return json({ error: 'visibility must be "visible" or "hidden"' }, { status: 400 });
|
|
45
53
|
}
|
|
54
|
+
if (parsed.body.accessMode !== undefined && !isApprovalMode(parsed.body.accessMode)) {
|
|
55
|
+
return json({ error: 'accessMode is not a valid approval mode' }, { status: 400 });
|
|
56
|
+
}
|
|
46
57
|
|
|
47
58
|
try {
|
|
48
59
|
const result = await forkSession({
|
|
49
60
|
sourceSessionId,
|
|
50
61
|
anchorEntryId: readString(parsed.body.anchorEntryId),
|
|
51
62
|
prompt: readString(parsed.body.prompt),
|
|
63
|
+
images: readImages(parsed.body.images),
|
|
64
|
+
model: readModel(parsed.body.model),
|
|
65
|
+
thinkingLevel: readString(parsed.body.thinkingLevel),
|
|
66
|
+
accessMode: isApprovalMode(parsed.body.accessMode) ? parsed.body.accessMode : null,
|
|
52
67
|
title: readString(parsed.body.title),
|
|
53
68
|
cwd: readString(parsed.body.cwd),
|
|
54
69
|
...(visibility ? { visibility: visibility as 'visible' | 'hidden' } : {}),
|
|
@@ -206,8 +206,7 @@ describe('getSessionModes', () => {
|
|
|
206
206
|
claimHarness(wrapper as never, 'claude');
|
|
207
207
|
try {
|
|
208
208
|
const res = (await getSessionModes(loaderArgs(acpId)) as unknown as Response);
|
|
209
|
-
expect(res.
|
|
210
|
-
expect(await res.json()).toMatchObject({ sessionId: acpId, modes: { plan: true, goal: false } });
|
|
209
|
+
expect(await res.json()).toMatchObject({ sessionId: acpId, modes: { plan: true, goal: false, mode: { currentValue: 'plan' } } });
|
|
211
210
|
} finally {
|
|
212
211
|
globalThis.__ompSessions.delete(acpId);
|
|
213
212
|
}
|
|
@@ -16,6 +16,9 @@ import { getLiveSession, harnessOfSession } from '@/server/lib/omp/rpc/session-r
|
|
|
16
16
|
import { knownHarness, loadHarnessSession } from '@/server/lib/harness/session-store.server';
|
|
17
17
|
import { HARNESS_IDS } from '@/shared/lib/harness/catalog';
|
|
18
18
|
import { loadAcpGoalState } from '@/server/lib/harness/acp/acp-goal-state.server';
|
|
19
|
+
import { selectValues } from '@/server/lib/harness/launch';
|
|
20
|
+
import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
|
|
21
|
+
import type { SessionModeState } from '@/shared/lib/harness/session-modes';
|
|
19
22
|
import { asHarnessSession } from '@/server/lib/harness/registry';
|
|
20
23
|
import { applyHarnessMode } from '@/server/routes/agent/harness-command';
|
|
21
24
|
import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
|
|
@@ -77,12 +80,28 @@ export async function getSessionModes({ params }: LoaderFunctionArgs) {
|
|
|
77
80
|
if (applied.ok) plan = (applied.data as { enabled?: unknown } | null)?.enabled === true;
|
|
78
81
|
}
|
|
79
82
|
const active = state.record?.status === 'active';
|
|
83
|
+
// The agent's own mode ladder, so the composer can offer all of it. `omp-acp`
|
|
84
|
+
// is excluded: its selector is just default/plan, which the dedicated Plan
|
|
85
|
+
// toggle (with the goal exclusion) already expresses.
|
|
86
|
+
let mode: SessionModeState | null = null;
|
|
87
|
+
if (liveSession?.isAlive() && acpHarness !== 'omp-acp') {
|
|
88
|
+
const snapshot = await liveSession.send({ type: 'get_state' }).catch(() => null) as
|
|
89
|
+
| { configOptions?: AcpConfigOption[] }
|
|
90
|
+
| null;
|
|
91
|
+
const selector = Array.isArray(snapshot?.configOptions)
|
|
92
|
+
? snapshot.configOptions.find((option) => option.category === 'mode')
|
|
93
|
+
: undefined;
|
|
94
|
+
if (selector && typeof selector.currentValue === 'string') {
|
|
95
|
+
mode = { currentValue: selector.currentValue, values: selectValues(selector) };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
80
98
|
acpModes = {
|
|
81
99
|
plan,
|
|
82
100
|
goal: active,
|
|
83
101
|
goalLive: active,
|
|
84
102
|
goalRecord: state.record,
|
|
85
103
|
goalContinuation: state.continuation,
|
|
104
|
+
...(mode ? { mode } : {}),
|
|
86
105
|
};
|
|
87
106
|
}
|
|
88
107
|
|