arco-workbench 0.2.2 → 0.2.5
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/CONTRIBUTING.md +1 -1
- package/THIRD_PARTY_NOTICES +2 -2
- package/client/dist/assets/{PhosphorBackdrop-BbR3xmfD.js → PhosphorBackdrop-CLILIwOQ.js} +1 -1
- package/client/dist/assets/{ThemedBackgroundShaderImpl-UMjbs9ZN.js → ThemedBackgroundShaderImpl-B87chcb5.js} +1 -1
- package/client/dist/assets/{XtermView-n135qz-f.js → XtermView-BP_j7WSN.js} +1 -1
- package/client/dist/assets/{galleryEditor-CFSke4by.js → galleryEditor-B90phoBI.js} +1 -1
- package/client/dist/assets/{index-DeoJbjI3.js → index-BfPp1Oup.js} +270 -270
- package/client/dist/index.html +1 -1
- package/client/dist/manifest-mobile.webmanifest +1 -0
- package/client/src/App.tsx +2 -2
- package/client/src/components/AuthReloginNotice.tsx +7 -6
- package/client/src/components/ChatMessage.tsx +41 -29
- package/client/src/components/ChatPanel.tsx +17 -4
- package/client/src/components/ClaudeNativeAccountPicker.tsx +32 -0
- package/client/src/components/ClaudeNativeAuthRow.tsx +71 -19
- package/client/src/components/ClusterRightPanel/AddWorkerSection.tsx +11 -281
- package/client/src/components/ClusterRightPanel/AutoPickupControl.tsx +1 -1
- package/client/src/components/ClusterRightPanel/FreshMemberForm.tsx +315 -0
- package/client/src/components/ClusterRightPanel/ReplaceMemberDialog.tsx +17 -7
- package/client/src/components/ClusterRightPanel/index.tsx +1 -1
- package/client/src/components/ClusterRightPanel/useFreshMemberPicker.ts +6 -4
- package/client/src/components/ClusterTab.tsx +2 -2
- package/client/src/components/Connections/Connections.tsx +7 -11
- package/client/src/components/Connections/model.ts +3 -1
- package/client/src/components/FileViewerModal.tsx +54 -17
- package/client/src/components/GitHubPanel/index.tsx +9 -5
- package/client/src/components/HandoffDialog.tsx +5 -3
- package/client/src/components/MobileShell.tsx +1 -33
- package/client/src/components/OperatorQuestionNotice.tsx +5 -4
- package/client/src/components/ProvidersPopover.tsx +6 -2
- package/client/src/components/RightPanel/ActivityTab.tsx +2 -1
- package/client/src/components/RightPanel/ConfigTab.tsx +23 -5
- package/client/src/components/RightPanel/OutputsPanel.tsx +21 -9
- package/client/src/components/RightPanel/outputsReconcile.ts +31 -0
- package/client/src/components/SettingsPanel.tsx +7 -10
- package/client/src/components/SpawnDialog.tsx +14 -3
- package/client/src/components/TabBar.tsx +2 -2
- package/client/src/components/TabContextMenu.tsx +73 -133
- package/client/src/components/TerminalInput.tsx +4 -3
- package/client/src/components/TranscriptWorkerDialog.tsx +14 -4
- package/client/src/components/UsageBar.tsx +37 -18
- package/client/src/components/WorkflowCreator/ClusterMembersSection.tsx +29 -3
- package/client/src/components/WorkflowCreator/index.tsx +29 -15
- package/client/src/components/WorkflowView.tsx +1 -1
- package/client/src/components/providerIndicator.ts +7 -3
- package/client/src/components/research/QuickResearchOverview.tsx +7 -3
- package/client/src/components/research/SavedQuickKeep.tsx +7 -3
- package/client/src/components/settings/GitHubAuthRow.tsx +34 -0
- package/client/src/explorer/ArtifactsLens.tsx +17 -8
- package/client/src/explorer/ExplorerApp.tsx +3 -3
- package/client/src/explorer/types.ts +3 -1
- package/client/src/help/content/cluster.tsx +10 -4
- package/client/src/help/content/composer.tsx +3 -2
- package/client/src/help/content/header.tsx +6 -3
- package/client/src/help/content/misc.tsx +9 -7
- package/client/src/help/content/rightPanel.tsx +11 -6
- package/client/src/help/content/settings.tsx +14 -3
- package/client/src/help/content/tabbar.tsx +1 -1
- package/client/src/help/manualSections/actions.tsx +5 -1
- package/client/src/help/manualSections/clusters.tsx +21 -15
- package/client/src/help/manualSections/configuration.tsx +6 -4
- package/client/src/help/manualSections/gettingStarted.tsx +4 -2
- package/client/src/help/manualSections/maintenance.tsx +24 -0
- package/client/src/help/manualSections/powerFeatures.tsx +4 -2
- package/client/src/help/manualSections/providers.tsx +11 -4
- package/client/src/help/manualSections/workspace.tsx +3 -3
- package/client/src/hooks/useClaudeNativeCatalog.ts +26 -0
- package/client/src/hooks/useClaudeNativeLogin.ts +16 -11
- package/client/src/hooks/useWebSocket.ts +4 -2
- package/client/src/layout/layoutRange.ts +14 -5
- package/client/src/main.tsx +2 -0
- package/client/src/questions/waitingQuestion.ts +2 -0
- package/client/src/stores/appStore.ts +5 -1
- package/client/src/stores/appStore.types.ts +2 -0
- package/client/src/stores/replayContext.ts +20 -0
- package/client/src/utils/chatFileLinks.ts +34 -3
- package/client/src/utils/claudeAuth.ts +9 -1
- package/client/src/ws/handleServerMessage.ts +11 -3
- package/docs/ARCHITECTURE.md +3 -3
- package/docs/BACKUP.md +1 -1
- package/docs/CHECKPOINTS.md +67 -3
- package/docs/CLIENT.md +11 -6
- package/docs/EXTENDING.md +1 -1
- package/docs/FEATURES.md +3 -3
- package/docs/GETTING_STARTED.md +5 -4
- package/docs/GIT_WORKBENCH.md +8 -0
- package/docs/GLOSSARY.md +2 -2
- package/docs/GOTCHAS.md +4 -4
- package/docs/HTTP_API.md +63 -30
- package/docs/OPERATIONS.md +11 -0
- package/docs/OPERATOR_ACTIONS.md +2 -2
- package/docs/OUTPUTS.md +48 -6
- package/docs/PERSISTENCE.md +1 -1
- package/docs/PRIMITIVES.md +4 -2
- package/docs/PROTOCOL_CLUSTER.md +12 -6
- package/docs/PROTOCOL_PRIMITIVES.md +1 -1
- package/docs/PROVIDERS.md +47 -10
- package/docs/RESEARCH.md +3 -3
- package/docs/SETTINGS.md +9 -4
- package/node_modules/@arco/shared/dist/protocol/clusters.d.ts +15 -3
- package/node_modules/@arco/shared/dist/protocol/clusters.js +1 -1
- package/node_modules/@arco/shared/dist/protocol/models.d.ts +6 -1
- package/node_modules/@arco/shared/dist/protocol/operatorQuestions.d.ts +2 -1
- package/node_modules/@arco/shared/dist/protocol/settings.d.ts +3 -0
- package/node_modules/@arco/shared/dist/protocol/settings.js +5 -0
- package/node_modules/@arco/shared/dist/protocol/workflows.d.ts +1 -0
- package/node_modules/@arco/shared/dist/protocol/workflows.js +0 -2
- package/node_modules/@arco/shared/package.json +1 -1
- package/package.json +2 -2
- package/scripts/packaging/services.mjs +20 -1
- package/scripts/packaging/update.mjs +37 -2
- package/server/dist/attention.d.ts +6 -0
- package/server/dist/attention.js +6 -0
- package/server/dist/auth.d.ts +5 -0
- package/server/dist/auth.js +31 -20
- package/server/dist/clusterAutoTurn.d.ts +5 -1
- package/server/dist/clusterAutoTurn.js +31 -9
- package/server/dist/clusterPresets.js +3 -3
- package/server/dist/effortValidation.d.ts +2 -2
- package/server/dist/effortValidation.js +4 -4
- package/server/dist/explorerArtifacts.d.ts +1 -0
- package/server/dist/explorerArtifacts.js +12 -1
- package/server/dist/explorerDocs.d.ts +1 -0
- package/server/dist/explorerDocs.js +4 -4
- package/server/dist/geminiMembers.d.ts +7 -1
- package/server/dist/geminiMembers.js +28 -14
- package/server/dist/gitSnapshots.d.ts +1 -0
- package/server/dist/gitSnapshots.js +547 -83
- package/server/dist/http/clusterRoutes.js +9 -3
- package/server/dist/http/conversationFiles.d.ts +36 -0
- package/server/dist/http/conversationFiles.js +222 -0
- package/server/dist/http/fileBytes.d.ts +3 -0
- package/server/dist/http/fileBytes.js +33 -0
- package/server/dist/http/fileContentRoute.d.ts +2 -0
- package/server/dist/http/fileContentRoute.js +139 -0
- package/server/dist/http/fileRead.d.ts +54 -2
- package/server/dist/http/fileRead.js +31 -24
- package/server/dist/http/outputRoutes.js +14 -21
- package/server/dist/http/readConfinement.d.ts +0 -11
- package/server/dist/http/readConfinement.js +4 -30
- package/server/dist/http/router.js +41 -66
- package/server/dist/index.js +26 -12
- package/server/dist/management/initHubLink.js +1 -1
- package/server/dist/outputs.js +8 -0
- package/server/dist/primitives/exportContext.d.ts +2 -0
- package/server/dist/primitives/exportContext.js +13 -2
- package/server/dist/primitives/runCompare.d.ts +7 -1
- package/server/dist/primitives/runCompare.js +44 -20
- package/server/dist/project/taskLedger.js +46 -34
- package/server/dist/providerAccounts.d.ts +4 -0
- package/server/dist/providerAccounts.js +20 -1
- package/server/dist/providers/antigravity/artifacts.d.ts +23 -0
- package/server/dist/providers/antigravity/artifacts.js +140 -0
- package/server/dist/providers/antigravity/index.js +85 -7
- package/server/dist/providers/antigravity/questions.d.ts +2 -0
- package/server/dist/providers/antigravity/questions.js +58 -0
- package/server/dist/providers/claude-native/auth.d.ts +9 -8
- package/server/dist/providers/claude-native/auth.js +50 -58
- package/server/dist/providers/claude-native/authStatus.d.ts +2 -2
- package/server/dist/providers/claude-native/authStatus.js +9 -7
- package/server/dist/providers/claude-native/catalog.d.ts +6 -5
- package/server/dist/providers/claude-native/catalog.js +50 -39
- package/server/dist/providers/claude-native/oauth.d.ts +10 -9
- package/server/dist/providers/claude-native/oauth.js +120 -96
- package/server/dist/providers/claude-native/worker.d.ts +1 -0
- package/server/dist/providers/claude-native/worker.js +38 -23
- package/server/dist/providers/codex-appserver/operatorQuestions.d.ts +5 -3
- package/server/dist/providers/codex-appserver/operatorQuestions.js +27 -13
- package/server/dist/providers/codexChatBoundary.js +6 -1
- package/server/dist/research/quickPromotion.d.ts +3 -0
- package/server/dist/research/quickPromotion.js +26 -9
- package/server/dist/research/savedQuickPromotion.js +2 -11
- package/server/dist/server/broadcast.js +6 -0
- package/server/dist/settings.d.ts +1 -0
- package/server/dist/settings.js +39 -7
- package/server/dist/skills.js +1 -1
- package/server/dist/smartPickupAdapters.d.ts +1 -0
- package/server/dist/smartPickupAdapters.js +2 -2
- package/server/dist/smartPickupObserver.js +8 -5
- package/server/dist/thirdPartySkills.js +11 -5
- package/server/dist/turnChanges.d.ts +1 -1
- package/server/dist/turnChanges.js +5 -4
- package/server/dist/usage.d.ts +1 -1
- package/server/dist/usage.js +39 -27
- package/server/dist/workers/WorkerManager.d.ts +1 -0
- package/server/dist/workers/WorkerManager.js +1 -0
- package/server/dist/workers/processKill.js +37 -24
- package/server/dist/workflowMeta.js +2 -2
- package/server/dist/ws/clusterHandlers.d.ts +2 -2
- package/server/dist/ws/clusterHandlers.js +127 -113
- package/server/dist/ws/clusterMembers.d.ts +1 -1
- package/server/dist/ws/clusterMembers.js +34 -4
- package/server/dist/ws/compactHandlers.js +30 -14
- package/server/dist/ws/compareHandlers.js +53 -21
- package/server/dist/ws/gateHandlers.js +2 -0
- package/server/dist/ws/genesisHandlers.js +5 -3
- package/server/dist/ws/handoffHandlers.d.ts +1 -1
- package/server/dist/ws/handoffHandlers.js +115 -39
- package/server/dist/ws/transcriptWorkerHandlers.js +7 -2
- package/server/dist/ws/turnEngine.js +37 -19
- package/server/dist/ws/updatePrimaryConfig.d.ts +3 -2
- package/server/dist/ws/updatePrimaryConfig.js +236 -133
- package/server/dist/ws/workflowHandlers.js +21 -4
- package/server/package.json +1 -1
- package/server/src/attention.ts +7 -0
- package/server/src/auth.ts +33 -20
- package/server/src/clusterAutoTurn.ts +31 -11
- package/server/src/clusterPresets.ts +2 -2
- package/server/src/effortValidation.ts +4 -4
- package/server/src/explorerArtifacts.ts +12 -1
- package/server/src/explorerDocs.ts +5 -5
- package/server/src/geminiMembers.ts +26 -15
- package/server/src/gitSnapshots.ts +538 -82
- package/server/src/http/clusterRoutes.ts +10 -3
- package/server/src/http/conversationFiles.ts +231 -0
- package/server/src/http/fileBytes.ts +34 -0
- package/server/src/http/fileContentRoute.ts +123 -0
- package/server/src/http/fileRead.ts +30 -25
- package/server/src/http/outputRoutes.ts +13 -13
- package/server/src/http/readConfinement.ts +3 -30
- package/server/src/http/router.ts +39 -62
- package/server/src/index.ts +27 -18
- package/server/src/management/initHubLink.ts +1 -1
- package/server/src/outputs.ts +8 -0
- package/server/src/primitives/exportContext.ts +14 -2
- package/server/src/primitives/runCompare.ts +73 -46
- package/server/src/project/taskLedger.ts +47 -30
- package/server/src/providerAccounts.ts +20 -1
- package/server/src/providers/antigravity/artifacts.ts +121 -0
- package/server/src/providers/antigravity/index.ts +64 -6
- package/server/src/providers/antigravity/questions.ts +52 -0
- package/server/src/providers/claude-native/auth.ts +45 -60
- package/server/src/providers/claude-native/authStatus.ts +9 -8
- package/server/src/providers/claude-native/catalog.ts +52 -35
- package/server/src/providers/claude-native/oauth.ts +101 -77
- package/server/src/providers/claude-native/worker.ts +38 -22
- package/server/src/providers/codex-appserver/operatorQuestions.ts +26 -12
- package/server/src/providers/codexChatBoundary.ts +6 -1
- package/server/src/research/quickPromotion.ts +24 -6
- package/server/src/research/savedQuickPromotion.ts +2 -8
- package/server/src/server/broadcast.ts +4 -0
- package/server/src/settings.ts +36 -8
- package/server/src/skills.ts +1 -1
- package/server/src/smartPickupAdapters.ts +3 -2
- package/server/src/smartPickupObserver.ts +8 -5
- package/server/src/thirdPartySkills.ts +11 -5
- package/server/src/turnChanges.ts +5 -4
- package/server/src/usage.ts +30 -22
- package/server/src/workers/WorkerManager.ts +2 -0
- package/server/src/workers/processKill.ts +37 -23
- package/server/src/workflowMeta.ts +2 -2
- package/server/src/ws/clusterHandlers.ts +107 -104
- package/server/src/ws/clusterMembers.ts +25 -6
- package/server/src/ws/compactHandlers.ts +29 -15
- package/server/src/ws/compareHandlers.ts +59 -25
- package/server/src/ws/gateHandlers.ts +2 -0
- package/server/src/ws/genesisHandlers.ts +5 -4
- package/server/src/ws/handoffHandlers.ts +105 -37
- package/server/src/ws/transcriptWorkerHandlers.ts +6 -2
- package/server/src/ws/turnEngine.ts +36 -18
- package/server/src/ws/updatePrimaryConfig.ts +230 -132
- package/server/src/ws/workflowHandlers.ts +20 -4
- package/shared/dist/protocol/clusters.d.ts +15 -3
- package/shared/dist/protocol/clusters.js +1 -1
- package/shared/dist/protocol/models.d.ts +6 -1
- package/shared/dist/protocol/operatorQuestions.d.ts +2 -1
- package/shared/dist/protocol/settings.d.ts +3 -0
- package/shared/dist/protocol/settings.js +5 -0
- package/shared/dist/protocol/workflows.d.ts +1 -0
- package/shared/dist/protocol/workflows.js +0 -2
- package/shared/src/protocol/clusters.ts +23 -5
- package/shared/src/protocol/compare.ts +2 -2
- package/shared/src/protocol/models.ts +8 -4
- package/shared/src/protocol/operatorQuestions.ts +2 -1
- package/shared/src/protocol/settings.ts +8 -1
- package/shared/src/protocol/workflows.ts +1 -1
|
@@ -369,16 +369,35 @@ export async function loadKernel(cwd: string, boardKey?: TaskBoardKey): Promise<
|
|
|
369
369
|
if (!cwd) return { tasks: [], comments: [], runs: [] };
|
|
370
370
|
const snapshot = await readKernelSnapshot(cwd, boardKey);
|
|
371
371
|
if (snapshot !== null) return snapshot;
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
372
|
+
return rebuildKernelOnce(cwd, boardKey);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Without a snapshot the board is folded from every conversation's log in the
|
|
376
|
+
// project. Reconnecting tabs of one project each ask for the board at once, so
|
|
377
|
+
// concurrent requests share one rebuild: N tabs used to start N rebuilds, each
|
|
378
|
+
// reading all N logs again, and the server answered none of them for many
|
|
379
|
+
// seconds on a project with long histories.
|
|
380
|
+
const kernelRebuilds = new Map<string, Promise<TaskKernelState>>();
|
|
381
|
+
function rebuildKernelOnce(cwd: string, boardKey?: TaskBoardKey): Promise<TaskKernelState> {
|
|
382
|
+
const key = `${cwd}\0${sanitizeBoardKey(boardKey) ?? ''}`;
|
|
383
|
+
const running = kernelRebuilds.get(key);
|
|
384
|
+
if (running) return running;
|
|
385
|
+
const started = (async () => {
|
|
386
|
+
// One pass over the logs gives the tasks, comments, runs and receipts.
|
|
387
|
+
const events = await taskLedgerEvents(cwd, boardKey);
|
|
388
|
+
const tasks = foldTasks(events);
|
|
389
|
+
const comments = foldComments(events);
|
|
390
|
+
const runs = foldRuns(events);
|
|
391
|
+
const proposalReceipts: Record<string, string> = {};
|
|
392
|
+
for (const event of events) {
|
|
393
|
+
const receipt = event.payload?.proposalReceipt as { key?: unknown; taskId?: unknown } | undefined;
|
|
394
|
+
if (typeof receipt?.key === 'string' && typeof receipt.taskId === 'string') proposalReceipts[receipt.key] = receipt.taskId;
|
|
395
|
+
}
|
|
396
|
+
await saveKernel(cwd, { tasks, comments, runs, proposalReceipts }, boardKey).catch(() => { /* best-effort cache write */ });
|
|
397
|
+
return { tasks, comments, runs, proposalReceipts };
|
|
398
|
+
})().finally(() => { kernelRebuilds.delete(key); });
|
|
399
|
+
kernelRebuilds.set(key, started);
|
|
400
|
+
return started;
|
|
382
401
|
}
|
|
383
402
|
|
|
384
403
|
export async function saveKernel(cwd: string, state: TaskKernelState, boardKey?: TaskBoardKey): Promise<void> {
|
|
@@ -506,22 +525,7 @@ function eventBelongsToBoard(ev: TaskLedgerEventMessage, boardKey?: TaskBoardKey
|
|
|
506
525
|
return sanitizeBoardKey(ev.boardKey) === sanitizeBoardKey(boardKey);
|
|
507
526
|
}
|
|
508
527
|
|
|
509
|
-
|
|
510
|
-
if (!cwd) return [];
|
|
511
|
-
const metas = await listWorkflowMetas(cwd).catch(() => []);
|
|
512
|
-
const events: Array<TaskLedgerEventMessage & { seq: number }> = [];
|
|
513
|
-
for (const meta of metas) {
|
|
514
|
-
const msgs = await replayEvents(cwd, meta.workflowId, 0).catch(() => []);
|
|
515
|
-
for (const m of msgs) {
|
|
516
|
-
if (m.type !== 'task_ledger_event') continue;
|
|
517
|
-
const ev = m as unknown as TaskLedgerEventMessage & { seq?: number };
|
|
518
|
-
// Only fold events for THIS cwd (a workflow's log is cwd-local, but the
|
|
519
|
-
// event carries cwd explicitly — guard against a moved log).
|
|
520
|
-
if (ev.cwd !== cwd || !eventBelongsToBoard(ev, boardKey)) continue;
|
|
521
|
-
events.push({ ...ev, seq: ev.seq ?? 0 });
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
events.sort((a, b) => (a.at - b.at) || (a.seq - b.seq));
|
|
528
|
+
function foldTasks(events: Array<TaskLedgerEventMessage & { seq: number }>): LedgerTask[] {
|
|
525
529
|
const byId = new Map<string, LedgerTask>();
|
|
526
530
|
for (const ev of events) {
|
|
527
531
|
if (ev.op === 'delete') {
|
|
@@ -534,6 +538,11 @@ export async function rebuildFromEvents(cwd: string, boardKey?: TaskBoardKey): P
|
|
|
534
538
|
return [...byId.values()].sort((a, b) => a.createdAt - b.createdAt);
|
|
535
539
|
}
|
|
536
540
|
|
|
541
|
+
export async function rebuildFromEvents(cwd: string, boardKey?: TaskBoardKey): Promise<LedgerTask[]> {
|
|
542
|
+
if (!cwd) return [];
|
|
543
|
+
return foldTasks(await taskLedgerEvents(cwd, boardKey));
|
|
544
|
+
}
|
|
545
|
+
|
|
537
546
|
async function taskLedgerEvents(cwd: string, boardKey?: TaskBoardKey): Promise<Array<TaskLedgerEventMessage & { seq: number }>> {
|
|
538
547
|
if (!cwd) return [];
|
|
539
548
|
const metas = await listWorkflowMetas(cwd).catch(() => []);
|
|
@@ -551,9 +560,9 @@ async function taskLedgerEvents(cwd: string, boardKey?: TaskBoardKey): Promise<A
|
|
|
551
560
|
return events;
|
|
552
561
|
}
|
|
553
562
|
|
|
554
|
-
|
|
563
|
+
function foldComments(events: Array<TaskLedgerEventMessage & { seq: number }>): TaskComment[] {
|
|
555
564
|
const comments: TaskComment[] = [];
|
|
556
|
-
for (const ev of
|
|
565
|
+
for (const ev of events) {
|
|
557
566
|
const comment = ev.payload?.comment;
|
|
558
567
|
if (isTaskComment(comment)) {
|
|
559
568
|
comments.push(normalizeComment(comment));
|
|
@@ -563,9 +572,13 @@ export async function rebuildCommentsFromEvents(cwd: string, boardKey?: TaskBoar
|
|
|
563
572
|
return comments;
|
|
564
573
|
}
|
|
565
574
|
|
|
566
|
-
export async function
|
|
575
|
+
export async function rebuildCommentsFromEvents(cwd: string, boardKey?: TaskBoardKey): Promise<TaskComment[]> {
|
|
576
|
+
return foldComments(await taskLedgerEvents(cwd, boardKey));
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
function foldRuns(events: Array<TaskLedgerEventMessage & { seq: number }>): TaskRun[] {
|
|
567
580
|
const byId = new Map<string, TaskRun>();
|
|
568
|
-
for (const ev of
|
|
581
|
+
for (const ev of events) {
|
|
569
582
|
const run = ev.payload?.run;
|
|
570
583
|
if (
|
|
571
584
|
(ev.op === 'run_started'
|
|
@@ -583,6 +596,10 @@ export async function rebuildRunsFromEvents(cwd: string, boardKey?: TaskBoardKey
|
|
|
583
596
|
return [...byId.values()].sort((a, b) => a.startedAt - b.startedAt);
|
|
584
597
|
}
|
|
585
598
|
|
|
599
|
+
export async function rebuildRunsFromEvents(cwd: string, boardKey?: TaskBoardKey): Promise<TaskRun[]> {
|
|
600
|
+
return foldRuns(await taskLedgerEvents(cwd, boardKey));
|
|
601
|
+
}
|
|
602
|
+
|
|
586
603
|
// ── mutation helpers (pure — caller persists + emits the event) ──────────────
|
|
587
604
|
|
|
588
605
|
export function newTask(input: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mkdir, readFile, writeFile } from 'fs/promises';
|
|
2
2
|
import { dirname, join, resolve } from 'path';
|
|
3
3
|
import { homedir } from 'os';
|
|
4
|
-
import { TERMINAL_CODEX_ACCOUNT, type ProviderName, type ProviderAccountProfile } from '@arco/shared';
|
|
4
|
+
import { DEFAULT_CLAUDE_NATIVE_ACCOUNT, isClaudeNativeProfileId, TERMINAL_CODEX_ACCOUNT, type ProviderName, type ProviderAccountProfile } from '@arco/shared';
|
|
5
5
|
import { readSettings } from './settings.js';
|
|
6
6
|
import { arcoHome } from './arcoHome.js';
|
|
7
7
|
|
|
@@ -31,6 +31,25 @@ export async function configuredAccounts(provider: 'codex' | 'claude', cwd?: str
|
|
|
31
31
|
return settings?.providerAccounts?.[provider] ?? [];
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
export class ClaudeNativeAccountUnavailableError extends Error {
|
|
35
|
+
constructor() {
|
|
36
|
+
super('The saved Claude Native account is unavailable. Choose an account in CONFIG before sending again.');
|
|
37
|
+
this.name = 'ClaudeNativeAccountUnavailableError';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Native keeps the original store for unbound workflows. Legacy Claude labels
|
|
42
|
+
// were never credential bindings and cannot opt an old tab into a new sign-in.
|
|
43
|
+
export async function requireClaudeNativeAccount(accountRef?: string): Promise<string> {
|
|
44
|
+
if (accountRef === undefined || accountRef === DEFAULT_CLAUDE_NATIVE_ACCOUNT) return DEFAULT_CLAUDE_NATIVE_ACCOUNT;
|
|
45
|
+
if (isClaudeNativeProfileId(accountRef)) {
|
|
46
|
+
const settings = await readSettings();
|
|
47
|
+
if (settings.providerAccounts?.claudeNative?.some(profile => profile.id === accountRef)
|
|
48
|
+
&& !settings.providerAccounts.claude?.some(profile => profile.id === accountRef)) return accountRef;
|
|
49
|
+
}
|
|
50
|
+
throw new ClaudeNativeAccountUnavailableError();
|
|
51
|
+
}
|
|
52
|
+
|
|
34
53
|
export async function resolveProviderAccount(
|
|
35
54
|
provider: ProviderName,
|
|
36
55
|
accountRef: string | undefined,
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// The CLI owns its session files. Only names observed at turn completion are
|
|
2
|
+
// recorded, independently of writable project metadata. No Gemini directory
|
|
3
|
+
// becomes a general file, media, editor or download root.
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { homedir } from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { readdir, realpath } from 'node:fs/promises';
|
|
8
|
+
import { arcoHome } from '../../arcoHome.js';
|
|
9
|
+
import { atomicWriteFile, withFileLock } from '../../atomicFile.js';
|
|
10
|
+
import { openCheckedFile } from '../../checkedFile.js';
|
|
11
|
+
import { assertSpellingSafe, FileAccessError } from '../../fileAccessPolicy.js';
|
|
12
|
+
|
|
13
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
14
|
+
const MAX_BYTES = 25 * 1024 * 1024;
|
|
15
|
+
const skipped = new Set(['scratch', 'logs', 'worktrees', 'raw-tools']);
|
|
16
|
+
const digest = (value: string) => createHash('sha256').update(value).digest('hex');
|
|
17
|
+
|
|
18
|
+
function validName(key: string): boolean {
|
|
19
|
+
const [session, ...parts] = key.split('/');
|
|
20
|
+
// Apply ordinary browser filename rules below the one authorized provider
|
|
21
|
+
// directory. Its parent is deliberately outside the general browser roots.
|
|
22
|
+
try { assertSpellingSafe('/' + key, path.posix); } catch { return false; }
|
|
23
|
+
return UUID.test(session) && parts.length >= 1 && parts.length <= 4 && parts.every(part =>
|
|
24
|
+
part.length > 0 && !part.startsWith('.') && !/[\\:\x00-\x1f]/.test(part)
|
|
25
|
+
&& !/[. ]$/.test(part) && !/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(part)
|
|
26
|
+
&& !/\.metadata\.json$|\.resolved(?:\.\d+)?$/i.test(part))
|
|
27
|
+
&& parts.slice(0, -1).every(part => !skipped.has(part.toLowerCase()));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function geminiSessionKey(file: string): string | null | undefined {
|
|
31
|
+
const match = /[\\/]\.gemini[\\/]antigravity-cli[\\/]brain[\\/](.*)$/i.exec(file);
|
|
32
|
+
if (!match) return undefined;
|
|
33
|
+
const [session, ...parts] = match[1].split(/[\\/]/);
|
|
34
|
+
const key = [session.toLowerCase(), ...parts].join('/');
|
|
35
|
+
return validName(key) ? key : null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function manifest(cwd: string, workflowId: string) {
|
|
39
|
+
return path.join(arcoHome(), 'gemini-artifacts-' + digest(JSON.stringify([await realpath(cwd), workflowId])) + '.json');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function names(file: string): Promise<string[]> {
|
|
43
|
+
const handle = await openCheckedFile(file).catch(error => {
|
|
44
|
+
if (error.code !== 'ENOENT') throw error;
|
|
45
|
+
return null;
|
|
46
|
+
});
|
|
47
|
+
if (!handle) return [];
|
|
48
|
+
try {
|
|
49
|
+
if ((await handle.stat()).size > 8 * 1024 * 1024) throw new FileAccessError();
|
|
50
|
+
const rows: unknown = JSON.parse(await handle.readFile('utf8'));
|
|
51
|
+
if (!Array.isArray(rows) || rows.length > 2000 || !rows.every(row => typeof row === 'string' && validName(row))) throw new FileAccessError();
|
|
52
|
+
return rows;
|
|
53
|
+
} finally { await handle.close(); }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function brainRoot() {
|
|
57
|
+
return path.join(await realpath(homedir()), '.gemini', 'antigravity-cli', 'brain');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Recheck the spelling, link count and size for each listing and each read.
|
|
61
|
+
// Callers serve bytes from this same handle, up to the checked size.
|
|
62
|
+
async function openArtifact(root: string, key: string) {
|
|
63
|
+
const file = path.join(root, ...key.split('/'));
|
|
64
|
+
const handle = await openCheckedFile(file);
|
|
65
|
+
try {
|
|
66
|
+
const info = await handle.stat();
|
|
67
|
+
if (info.nlink !== 1 || info.size > MAX_BYTES) throw new FileAccessError();
|
|
68
|
+
return { handle, info, file };
|
|
69
|
+
} catch (error) { await handle.close(); throw error; }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function collectGeminiArtifacts(opts: { sessionId: string; storeCwd: string; workflowId: string }) {
|
|
73
|
+
const session = opts.sessionId.toLowerCase();
|
|
74
|
+
if (!UUID.test(session)) return;
|
|
75
|
+
const root = await brainRoot();
|
|
76
|
+
const found: string[] = [];
|
|
77
|
+
async function walk(prefix: string, depth: number) {
|
|
78
|
+
const dir = path.join(root, ...prefix.split('/'));
|
|
79
|
+
if (await realpath(dir).catch(() => '') !== dir) return;
|
|
80
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
81
|
+
if (found.length >= 200) break;
|
|
82
|
+
const key = prefix + '/' + entry.name;
|
|
83
|
+
if (!validName(key)) continue;
|
|
84
|
+
if (entry.isDirectory() && depth < 3 && !skipped.has(entry.name.toLowerCase())) await walk(key, depth + 1);
|
|
85
|
+
else if (entry.isFile()) {
|
|
86
|
+
const opened = await openArtifact(root, key).catch(() => null);
|
|
87
|
+
if (opened) { await opened.handle.close(); found.push(key); }
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
await walk(session, 0);
|
|
92
|
+
const file = await manifest(opts.storeCwd, opts.workflowId);
|
|
93
|
+
await withFileLock(file, async () => {
|
|
94
|
+
const previous = await names(file);
|
|
95
|
+
const next = previous.filter(key => !key.startsWith(session + '/')).concat(found).slice(-2000);
|
|
96
|
+
if (JSON.stringify(next) !== JSON.stringify(previous)) await atomicWriteFile(file, JSON.stringify(next), { mode: 0o600, skipMkdir: true });
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const idFor = (key: string) => 'gemini-' + digest(key);
|
|
101
|
+
export async function listGeminiArtifacts(cwd: string, workflowId: string) {
|
|
102
|
+
const keys = await names(await manifest(cwd, workflowId));
|
|
103
|
+
const rows = [];
|
|
104
|
+
if (keys.length) {
|
|
105
|
+
const root = await brainRoot();
|
|
106
|
+
for (const key of keys) {
|
|
107
|
+
const opened = await openArtifact(root, key).catch(() => null);
|
|
108
|
+
if (!opened) continue;
|
|
109
|
+
await opened.handle.close();
|
|
110
|
+
rows.push({ id: idFor(key), path: opened.file, name: path.basename(opened.file), size: opened.info.size, mtime: opened.info.mtimeMs });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return rows;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export async function openGeminiArtifact(cwd: string, workflowId: string, selector: { key: string } | { id: string }) {
|
|
117
|
+
const keys = await names(await manifest(cwd, workflowId));
|
|
118
|
+
const key = keys.find(item => 'key' in selector ? item === selector.key : idFor(item) === selector.id);
|
|
119
|
+
if (!key) throw new FileAccessError();
|
|
120
|
+
return { ...await openArtifact(await brainRoot(), key), id: idFor(key) };
|
|
121
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
1
4
|
import { resolve as resolvePath } from 'node:path';
|
|
2
5
|
import { findDiagnosticExecutable } from '../../diagnostics/executableLookup.js';
|
|
3
6
|
import { loadResearch, researcherFor } from '../../research/researchState.js';
|
|
@@ -9,8 +12,9 @@ import { GEMINI_RESEARCH_SIGN_IN_NEEDED, noteGeminiResearchSignInExpired, readGe
|
|
|
9
12
|
import { historyBinding } from '../handoffHistoryBinding.js';
|
|
10
13
|
import { ensureClusterLoopbackMcp, closeClusterLoopbackMcp } from '../../mcp/clusterMcpLoopback.js';
|
|
11
14
|
import { prepareProviderAttachments } from '../providerFileContent.js';
|
|
15
|
+
import { collectGeminiArtifacts } from './artifacts.js';
|
|
12
16
|
import { noteAntigravityTurnSuccess, noteAntigravitySignInRequired } from './status.js';
|
|
13
|
-
import { lstat, realpath } from 'node:fs/promises';
|
|
17
|
+
import { mkdir, mkdtemp, rm, writeFile, lstat, realpath } from 'node:fs/promises';
|
|
14
18
|
import { dirname, isAbsolute, relative, sep } from 'node:path';
|
|
15
19
|
import { arcoHome } from '../../arcoHome.js';
|
|
16
20
|
import { isIncognitoChatCwd, antigravityChatWorkspace } from '../../chatMode.js';
|
|
@@ -24,6 +28,7 @@ import { resolveCommand } from '../../windowsCommand.js';
|
|
|
24
28
|
import { killProcessTree } from '../../workers/processKill.js';
|
|
25
29
|
import { probeVersion } from '../../capabilities.js';
|
|
26
30
|
import { compareVersions } from '../../updateCheck.js';
|
|
31
|
+
import { askGeminiQuestion } from './questions.js';
|
|
27
32
|
|
|
28
33
|
export class AntigravitySubagentNotice {
|
|
29
34
|
private shown = false;
|
|
@@ -39,6 +44,25 @@ export class AntigravitySubagentNotice {
|
|
|
39
44
|
|
|
40
45
|
export function permittedAgyModel(id: string): boolean { return /^gemini-[a-z0-9.-]+$/.test(id); }
|
|
41
46
|
|
|
47
|
+
// ACP applies a selected custom agent to session/new. Loading an old session
|
|
48
|
+
// restores its original tools. Summaries therefore use a fresh private
|
|
49
|
+
// workspace, a unique reply-only agent, and the bounded transcript as input.
|
|
50
|
+
async function createHandoffWriter() {
|
|
51
|
+
const cwd = await mkdtemp(join(tmpdir(), 'arco-handoff-'));
|
|
52
|
+
const name = 'handoff-' + randomUUID();
|
|
53
|
+
const dir = join(cwd, '.agents', 'agents');
|
|
54
|
+
try {
|
|
55
|
+
await mkdir(dir, { recursive: true });
|
|
56
|
+
await writeFile(join(dir, name + '.md'), [
|
|
57
|
+
'---', 'name: ' + name, 'description: Write a handoff document.',
|
|
58
|
+
'mainAgent: true', 'subagent: false', 'tools: [send_message]',
|
|
59
|
+
'inheritMcp: false', 'inheritCustomizations: false', 'commandExecutionPolicy: "off"',
|
|
60
|
+
'---', 'Write the document from the supplied conversation and return it as text.',
|
|
61
|
+
].join('\n'), { mode: 0o600 });
|
|
62
|
+
return { cwd, name };
|
|
63
|
+
} catch (error) { await rm(cwd, { recursive: true, force: true }); throw error; }
|
|
64
|
+
}
|
|
65
|
+
|
|
42
66
|
class AntigravityTurn extends EventEmitter implements ProviderProcess {
|
|
43
67
|
private proc: ChildProcess | null = null;
|
|
44
68
|
private rpc: AcpJsonRpcClient | null = null;
|
|
@@ -48,6 +72,8 @@ class AntigravityTurn extends EventEmitter implements ProviderProcess {
|
|
|
48
72
|
private startedAt = 0;
|
|
49
73
|
private contextSize: number | undefined;
|
|
50
74
|
private contextUsed: number | undefined;
|
|
75
|
+
private sessionId: string | undefined;
|
|
76
|
+
private artifactsCollected = false;
|
|
51
77
|
constructor(readonly id: string, private config: WorkerConfig) { super(); }
|
|
52
78
|
get status(): WorkerStatus { return this._status; }
|
|
53
79
|
get output(): string { return this._output; }
|
|
@@ -62,12 +88,23 @@ class AntigravityTurn extends EventEmitter implements ProviderProcess {
|
|
|
62
88
|
else noteAntigravitySignInRequired();
|
|
63
89
|
}
|
|
64
90
|
cancelAcpPermissions(this.config.workflowId ?? '');
|
|
91
|
+
void this.collectArtifacts();
|
|
65
92
|
if (this.config.workflowId) closeClusterLoopbackMcp(this.config.workflowId);
|
|
66
93
|
this.rpc?.close('turn finished');
|
|
67
94
|
if (this.proc?.pid) killProcessTree(this.proc.pid, { graceMs: 1000, label: 'Antigravity turn' });
|
|
68
95
|
this.emit('error', message);
|
|
69
96
|
}
|
|
70
97
|
kill(): void { this.fail(new Error('Turn cancelled.')); }
|
|
98
|
+
// Finished filenames of this session are registered for this workflow once
|
|
99
|
+
// per turn. A researcher's session lives in its fenced home and is skipped.
|
|
100
|
+
private async collectArtifacts(): Promise<void> {
|
|
101
|
+
const workflowId = this.config.workflowId, storeCwd = this.config.persistenceCwd ?? this.config.cwd;
|
|
102
|
+
if (this.config.antigravityHandoffWriter || this.artifactsCollected || !this.sessionId || !workflowId || !storeCwd || this.config.clusterAccessMode === 'researcher') return;
|
|
103
|
+
this.artifactsCollected = true;
|
|
104
|
+
try {
|
|
105
|
+
await collectGeminiArtifacts({ sessionId: this.sessionId, storeCwd, workflowId });
|
|
106
|
+
} catch { this.emit('system_notice', 'Gemini artifacts from this turn could not be listed in Outputs.'); }
|
|
107
|
+
}
|
|
71
108
|
// docs/RESEARCH.md "Gemini researchers": a researcher runs only inside the
|
|
72
109
|
// worker fence, with its own copy of the separate research sign-in.
|
|
73
110
|
private async prepareFence(workflowId: string): Promise<Awaited<ReturnType<typeof prepareAntigravityIsolatedLaunch>>> {
|
|
@@ -88,11 +125,16 @@ class AntigravityTurn extends EventEmitter implements ProviderProcess {
|
|
|
88
125
|
}
|
|
89
126
|
private async run(prompt: string): Promise<void> {
|
|
90
127
|
const workflowId = this.config.workflowId;
|
|
91
|
-
|
|
128
|
+
const writer = this.config.antigravityHandoffWriter === true;
|
|
129
|
+
const authorized = writer
|
|
130
|
+
? this.config.sandbox === 'read-only' && !this.config.resumeSessionId && !this.config.clusterId && !this.config.clusterAccessMode
|
|
131
|
+
: this.config.antigravityInteractive === true && this.config.interactionMode === 'agent' && !this.config.sandbox;
|
|
132
|
+
if (!workflowId || !authorized || this.config.voiceOperator || this.config.incognito) throw new Error('Antigravity runs only on an interactive message the operator sent or a requested handoff.');
|
|
92
133
|
if (!permittedAgyModel(this.config.model)) throw new Error('Antigravity requires a Gemini model.');
|
|
93
134
|
const subagentNotice = new AntigravitySubagentNotice(await probeVersion('agy'));
|
|
94
135
|
if (this.finished) return;
|
|
95
136
|
const researcher = this.config.clusterAccessMode === 'researcher';
|
|
137
|
+
const supportsQuestions = !writer && !researcher && !this.config.clusterResearchDirector && prompt.trim() !== '/compact';
|
|
96
138
|
let fenced: Awaited<ReturnType<typeof prepareAntigravityIsolatedLaunch>> | undefined;
|
|
97
139
|
let cwd: string;
|
|
98
140
|
if (researcher) {
|
|
@@ -116,9 +158,14 @@ class AntigravityTurn extends EventEmitter implements ProviderProcess {
|
|
|
116
158
|
if (this.config.antigravityChatWorkspace && !managedChat) throw new Error('The Antigravity Chat working folder does not match this Chat.');
|
|
117
159
|
this.startedAt = Date.now();
|
|
118
160
|
}
|
|
161
|
+
const writerWorkspace = writer ? await createHandoffWriter() : undefined;
|
|
162
|
+
if (writerWorkspace) cwd = writerWorkspace.cwd;
|
|
163
|
+
const removeWriter = () => writerWorkspace && rm(writerWorkspace.cwd, { recursive: true, force: true }).catch(() => {});
|
|
164
|
+
if (this.finished) { await removeWriter(); await fenced?.close(); return; }
|
|
119
165
|
const proc = fenced
|
|
120
166
|
? spawn(fenced.command.file, fenced.command.args, { cwd: '/', env: { PATH: '/usr/bin:/bin' }, stdio: ['pipe', 'pipe', 'pipe'], detached: true })
|
|
121
|
-
: (() => { const agy = resolveCommand('agy', ['acp'], { fresh: true }); return spawn(agy.command, agy.args, { cwd, ...(agy.env ? { env: agy.env } : {}), stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true, detached: process.platform !== 'win32' }); })();
|
|
167
|
+
: (() => { const agy = resolveCommand('agy', writerWorkspace ? ['acp', '--agent', writerWorkspace.name] : ['acp'], { fresh: true }); return spawn(agy.command, agy.args, { cwd, ...(agy.env ? { env: agy.env } : {}), stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true, detached: process.platform !== 'win32' }); })();
|
|
168
|
+
if (writerWorkspace) proc.once('close', () => { void removeWriter(); });
|
|
122
169
|
if (fenced) { const launch = fenced; proc.once('close', () => { void launch.close().catch(() => this.emit('system_notice', 'Worker isolation cleanup failed.')); }); }
|
|
123
170
|
this.proc = proc;
|
|
124
171
|
proc.once('error', error => this.fail(error));
|
|
@@ -126,8 +173,16 @@ class AntigravityTurn extends EventEmitter implements ProviderProcess {
|
|
|
126
173
|
proc.stderr?.resume();
|
|
127
174
|
if (!proc.stdin || !proc.stdout) throw new Error('Antigravity ACP streams unavailable.');
|
|
128
175
|
const rpc = this.rpc = new AcpJsonRpcClient(proc.stdin, proc.stdout);
|
|
176
|
+
let questionPending = false;
|
|
129
177
|
rpc.onRequest = async (request: IncomingRequest) => {
|
|
178
|
+
if (writer && request.method === 'session/request_permission') return { outcome: { outcome: 'cancelled' } };
|
|
130
179
|
if (request.method === 'session/request_permission') return requestAcpPermission(workflowId, request.params as Record<string, unknown>, this.config.skipPermissions === true);
|
|
180
|
+
if (request.method === 'elicitation/create' && supportsQuestions && this.sessionId && this._status === 'running') {
|
|
181
|
+
if (questionPending) return { action: 'decline' };
|
|
182
|
+
questionPending = true;
|
|
183
|
+
try { return await askGeminiQuestion(rpc, workflowId, this.sessionId, request.params); }
|
|
184
|
+
finally { questionPending = false; }
|
|
185
|
+
}
|
|
131
186
|
throw new AcpReplyError(-32601, `Method not supported: ${request.method}`);
|
|
132
187
|
};
|
|
133
188
|
rpc.on('notification', (notification: JsonRpcNotification) => {
|
|
@@ -143,8 +198,8 @@ class AntigravityTurn extends EventEmitter implements ProviderProcess {
|
|
|
143
198
|
this.emit('tool_use', { id: update.toolCallId, name: update.name === 'invoke_subagent' ? 'invoke_subagent' : update.title ?? 'Antigravity tool', input: JSON.stringify(update.rawInput ?? {}), status: update.status === 'completed' ? 'completed' : update.status === 'failed' ? 'failed' : 'in_progress', ...(update.rawOutput !== undefined ? { output: JSON.stringify(update.rawOutput) } : {}) });
|
|
144
199
|
}
|
|
145
200
|
});
|
|
146
|
-
await rpc.request('initialize', { protocolVersion: 1, clientCapabilities: {}, clientInfo: { name: 'Arco', version: '1' } });
|
|
147
|
-
const bridge = fenced ? { name: 'arco-cluster', url: fenced.mailUrl } : await ensureClusterLoopbackMcp({
|
|
201
|
+
await rpc.request('initialize', { protocolVersion: 1, clientCapabilities: supportsQuestions ? { elicitation: { form: {} } } : {}, clientInfo: { name: 'Arco', version: '1' } });
|
|
202
|
+
const bridge = writer ? undefined : fenced ? { name: 'arco-cluster', url: fenced.mailUrl } : await ensureClusterLoopbackMcp({
|
|
148
203
|
workflowId, clusterId: this.config.clusterId ?? '', cwd,
|
|
149
204
|
arcoPort: parseInt(process.env.ARCO_PORT || '3001', 10),
|
|
150
205
|
taskBoardAttached: this.config.clusterTaskBoardAttached === true,
|
|
@@ -155,7 +210,7 @@ class AntigravityTurn extends EventEmitter implements ProviderProcess {
|
|
|
155
210
|
readOnly: this.config.sandbox === 'read-only',
|
|
156
211
|
});
|
|
157
212
|
if (this.finished) { closeClusterLoopbackMcp(workflowId); return; }
|
|
158
|
-
const args = { cwd, mcpServers: [{ type: 'http', name: bridge.name, url: bridge.url, headers: [] }] };
|
|
213
|
+
const args = { cwd, mcpServers: bridge ? [{ type: 'http', name: bridge.name, url: bridge.url, headers: [] }] : [] };
|
|
159
214
|
const result = await rpc.request<{ sessionId: string; configOptions?: Array<{ id: string; options?: Array<{ value: string }> }> }>(this.config.resumeSessionId ? 'session/load' : 'session/new', this.config.resumeSessionId ? { ...args, sessionId: this.config.resumeSessionId } : args);
|
|
160
215
|
const mode = result.configOptions?.find(x => x.id === 'mode');
|
|
161
216
|
if (mode?.options?.some(x => x.value === 'default')) await rpc.request('session/set_config_option', { sessionId: result.sessionId, configId: 'mode', value: 'default' });
|
|
@@ -166,6 +221,7 @@ class AntigravityTurn extends EventEmitter implements ProviderProcess {
|
|
|
166
221
|
const effort = (configured.configOptions ?? result.configOptions)?.find(x => x.id === 'thought_level');
|
|
167
222
|
if (effort && !effort.options?.some(x => x.value === this.config.effort)) throw new Error('This thinking level is not offered for the selected Antigravity model.');
|
|
168
223
|
if (effort) await rpc.request('session/set_config_option', { sessionId: result.sessionId, configId: 'thought_level', value: this.config.effort });
|
|
224
|
+
this.sessionId = result.sessionId;
|
|
169
225
|
this._status = 'running'; this.emit('init', { model: this.config.model, sessionId: result.sessionId });
|
|
170
226
|
if (fenced && this.config.clusterId) void setResearcherIsolation(this.config.clusterId, workflowId, 'sandboxed').catch(() => undefined);
|
|
171
227
|
const prepared = await prepareProviderAttachments(this.config.attachments, true, undefined, false, true);
|
|
@@ -173,6 +229,8 @@ class AntigravityTurn extends EventEmitter implements ProviderProcess {
|
|
|
173
229
|
const answer = await rpc.request<{ usage?: Record<string, number>; stopReason?: string }>('session/prompt', { sessionId: result.sessionId, prompt: content });
|
|
174
230
|
if (answer.stopReason === 'cancelled') throw new Error('Turn cancelled.');
|
|
175
231
|
if (this.finished) return;
|
|
232
|
+
await this.collectArtifacts();
|
|
233
|
+
if (this.finished) return;
|
|
176
234
|
this.finished = true; this._status = 'completed'; if (this.config.clusterAccessMode === 'researcher') noteGeminiResearchSignInExpired(false); else noteAntigravityTurnSuccess();
|
|
177
235
|
this.emit('result', { text: this._output, costUsd: 0, durationMs: Date.now() - this.startedAt, usage: answer.usage ? { input_tokens: answer.usage.inputTokens ?? 0, output_tokens: answer.usage.outputTokens ?? 0, cache_read_input_tokens: answer.usage.cachedReadTokens ?? 0, cache_creation_input_tokens: answer.usage.cachedWriteTokens ?? 0, reasoning_output_tokens: answer.usage.thoughtTokens ?? 0, total_tokens: answer.usage.totalTokens ?? 0 } : undefined, modelContextWindow: this.contextSize, lastPromptTokens: this.contextUsed });
|
|
178
236
|
closeClusterLoopbackMcp(workflowId);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { OperatorQuestion } from '@arco/shared';
|
|
2
|
+
import { AcpJsonRpcClient, AcpReplyError } from '../acp/acpJsonRpc.js';
|
|
3
|
+
import { openGeminiOperatorQuestion } from '../codex-appserver/operatorQuestions.js';
|
|
4
|
+
|
|
5
|
+
const record = (value: unknown): value is Record<string, unknown> => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
6
|
+
|
|
7
|
+
export async function askGeminiQuestion(rpc: AcpJsonRpcClient, workflowId: string, sessionId: string, params: unknown): Promise<unknown> {
|
|
8
|
+
if (!record(params) || params.mode !== 'form' || params.sessionId !== sessionId || typeof params.message !== 'string' || !params.message.trim() || params.message.length > 32768) {
|
|
9
|
+
throw new AcpReplyError(-32602, 'Invalid Gemini question request.');
|
|
10
|
+
}
|
|
11
|
+
const schema = params.requestedSchema;
|
|
12
|
+
if (!record(schema) || schema.type !== 'object' || !record(schema.properties)) return { action: 'decline' };
|
|
13
|
+
const fields = Object.entries(schema.properties);
|
|
14
|
+
if (!fields.length || fields.length > 6) return { action: 'decline' };
|
|
15
|
+
const required = schema.required ?? [];
|
|
16
|
+
if (!Array.isArray(required) || required.some(id => typeof id !== 'string' || !Object.hasOwn(schema.properties as object, id))) return { action: 'decline' };
|
|
17
|
+
const questions: OperatorQuestion[] = [];
|
|
18
|
+
const values = new Map<string, Map<string, string>>();
|
|
19
|
+
for (const [id, field] of fields) {
|
|
20
|
+
if (!id || id.length > 256 || Object.hasOwn(Object.prototype, id) || !record(field) || field.type !== 'string' || field.pattern !== undefined || field.format !== undefined || field.minLength !== undefined || field.maxLength !== undefined) return { action: 'decline' };
|
|
21
|
+
const title = typeof field.title === 'string' ? field.title : '';
|
|
22
|
+
const description = typeof field.description === 'string' ? field.description : '';
|
|
23
|
+
const prompt = fields.length === 1 ? params.message : [title || id, description].filter(Boolean).join('\n');
|
|
24
|
+
if (title.length > 1024 || prompt.length > 32768) return { action: 'decline' };
|
|
25
|
+
const choices = field.oneOf ?? (Array.isArray(field.enum) ? field.enum.map(value => ({ const: value })) : field.enum);
|
|
26
|
+
const labels = new Map<string, string>();
|
|
27
|
+
if (choices !== undefined) {
|
|
28
|
+
if (!Array.isArray(choices) || !choices.length || choices.length > 20) return { action: 'decline' };
|
|
29
|
+
for (const choice of choices) {
|
|
30
|
+
if (!record(choice) || typeof choice.const !== 'string' || !choice.const.trim() || choice.const.length > 4096) return { action: 'decline' };
|
|
31
|
+
const label = typeof choice.title === 'string' ? choice.title : choice.const;
|
|
32
|
+
if (!label.trim() || label.length > 4096 || labels.has(label)) return { action: 'decline' };
|
|
33
|
+
labels.set(label, choice.const);
|
|
34
|
+
}
|
|
35
|
+
values.set(id, labels);
|
|
36
|
+
}
|
|
37
|
+
questions.push({ id, header: fields.length === 1 ? title : questions.length === 0 ? params.message.slice(0, 1024) : '', question: prompt,
|
|
38
|
+
options: labels.size ? [...labels.keys()].map(label => ({ label, description: '' })) : undefined, allowOther: false, secret: false, optional: !required.includes(id) });
|
|
39
|
+
}
|
|
40
|
+
return new Promise(resolve => {
|
|
41
|
+
const cancel = openGeminiOperatorQuestion(workflowId, sessionId, questions, answers => {
|
|
42
|
+
rpc.off('close', onClose);
|
|
43
|
+
const content = answers && Object.fromEntries(Object.entries(answers).map(([id, [answer]]) => [id, values.get(id)?.get(answer) ?? answer]));
|
|
44
|
+
resolve(content ? { action: 'accept', content } : { action: 'decline' });
|
|
45
|
+
});
|
|
46
|
+
function onClose() {
|
|
47
|
+
cancel();
|
|
48
|
+
resolve({ action: 'cancel' });
|
|
49
|
+
}
|
|
50
|
+
rpc.once('close', onClose);
|
|
51
|
+
});
|
|
52
|
+
}
|