@opencorelabs/lucidity 0.7.0 → 0.9.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/README.md +9 -2
- package/dist/assets/speech/lucidity-speech +0 -0
- package/dist/automations/agent.d.ts.map +1 -1
- package/dist/automations/agent.js +2 -0
- package/dist/automations/designer.d.ts +1 -1
- package/dist/automations/service.d.ts +4 -0
- package/dist/automations/service.d.ts.map +1 -1
- package/dist/automations/service.js +60 -22
- package/dist/automations/store.d.ts +9 -3
- package/dist/automations/store.d.ts.map +1 -1
- package/dist/automations/store.js +45 -32
- package/dist/automations/workflow.d.ts +14 -0
- package/dist/automations/workflow.d.ts.map +1 -0
- package/dist/automations/workflow.js +57 -0
- package/dist/chat/server.d.ts +1 -0
- package/dist/chat/server.d.ts.map +1 -1
- package/dist/chat/server.js +6 -1
- package/dist/coding/listPrs.d.ts +2 -0
- package/dist/coding/listPrs.d.ts.map +1 -1
- package/dist/coding/listPrs.js +10 -0
- package/dist/coding/runCodeTurn.d.ts +6 -30
- package/dist/coding/runCodeTurn.d.ts.map +1 -1
- package/dist/coding/runCodeTurn.js +145 -218
- package/dist/coding/runReview.d.ts +10 -0
- package/dist/coding/runReview.d.ts.map +1 -0
- package/dist/coding/runReview.js +87 -0
- package/dist/coding/workspaceRegistry.d.ts +72 -0
- package/dist/coding/workspaceRegistry.d.ts.map +1 -0
- package/dist/coding/workspaceRegistry.js +421 -0
- package/dist/coding/worktree.d.ts +72 -32
- package/dist/coding/worktree.d.ts.map +1 -1
- package/dist/coding/worktree.js +190 -38
- package/dist/coding/worktreeSetup.d.ts +7 -0
- package/dist/coding/worktreeSetup.d.ts.map +1 -0
- package/dist/coding/worktreeSetup.js +49 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/daemonLease.d.ts +12 -0
- package/dist/daemonLease.d.ts.map +1 -0
- package/dist/daemonLease.js +32 -0
- package/dist/goals/assessment.d.ts +115 -0
- package/dist/goals/assessment.d.ts.map +1 -0
- package/dist/goals/assessment.js +67 -0
- package/dist/goals/notes.d.ts +18 -0
- package/dist/goals/notes.d.ts.map +1 -0
- package/dist/goals/notes.js +72 -0
- package/dist/index.js +75 -40
- package/dist/jobs/briefing.d.ts +2 -16
- package/dist/jobs/briefing.d.ts.map +1 -1
- package/dist/jobs/briefing.js +65 -93
- package/dist/jobs/goals.d.ts +15 -0
- package/dist/jobs/goals.d.ts.map +1 -0
- package/dist/jobs/goals.js +286 -0
- package/dist/jobs/weeklyReview.d.ts.map +1 -1
- package/dist/jobs/weeklyReview.js +3 -2
- package/dist/logTimestamps.d.ts +10 -0
- package/dist/logTimestamps.d.ts.map +1 -0
- package/dist/logTimestamps.js +12 -0
- package/dist/providerRecovery.d.ts +48 -0
- package/dist/providerRecovery.d.ts.map +1 -0
- package/dist/providerRecovery.js +100 -0
- package/dist/queue.d.ts +1 -0
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +4 -0
- package/dist/room/client.d.ts +6 -19
- package/dist/room/client.d.ts.map +1 -1
- package/dist/room/client.js +127 -123
- package/dist/room/computer.js +1 -1
- package/dist/room/durablePublish.d.ts +6 -0
- package/dist/room/durablePublish.d.ts.map +1 -0
- package/dist/room/durablePublish.js +19 -0
- package/dist/room/incidents.d.ts +4 -1
- package/dist/room/incidents.d.ts.map +1 -1
- package/dist/room/incidents.js +15 -7
- package/dist/room/turnQueue.d.ts.map +1 -1
- package/dist/room/turnQueue.js +55 -46
- package/dist/runtimeStore.d.ts +46 -0
- package/dist/runtimeStore.d.ts.map +1 -0
- package/dist/runtimeStore.js +205 -0
- package/dist/setup/server.js +1 -1
- package/dist/turnLog.d.ts +10 -40
- package/dist/turnLog.d.ts.map +1 -1
- package/dist/turnLog.js +33 -56
- package/dist/vault.d.ts +6 -3
- package/dist/vault.d.ts.map +1 -1
- package/dist/vault.js +18 -4
- package/package.json +4 -4
- package/src/automations/agent.ts +2 -0
- package/src/automations/service.ts +47 -21
- package/src/automations/store.ts +41 -50
- package/src/automations/workflow.ts +49 -0
- package/src/chat/server.ts +7 -1
- package/src/coding/listPrs.ts +14 -0
- package/src/coding/runCodeTurn.ts +51 -139
- package/src/coding/runReview.ts +83 -0
- package/src/coding/workspaceRegistry.ts +380 -0
- package/src/coding/worktree.ts +205 -40
- package/src/coding/worktreeSetup.ts +50 -0
- package/src/config.ts +2 -0
- package/src/daemonLease.ts +33 -0
- package/src/goals/assessment.ts +106 -0
- package/src/goals/notes.ts +88 -0
- package/src/index.ts +76 -46
- package/src/jobs/briefing.ts +62 -109
- package/src/jobs/goals.ts +384 -0
- package/src/jobs/weeklyReview.ts +4 -3
- package/src/logTimestamps.ts +14 -0
- package/src/providerRecovery.ts +99 -0
- package/src/queue.ts +4 -0
- package/src/room/client.ts +84 -116
- package/src/room/computer.ts +1 -1
- package/src/room/durablePublish.ts +25 -0
- package/src/room/incidents.ts +20 -8
- package/src/room/turnQueue.ts +53 -56
- package/src/runtimeStore.ts +207 -0
- package/src/setup/server.ts +1 -1
- package/src/turnLog.ts +32 -75
- package/src/vault.ts +16 -7
- package/vendor/mcp-server/dist/index.js +2 -0
- package/vendor/mcp-server/dist/tools/goals.d.ts +4 -0
- package/vendor/mcp-server/dist/tools/goals.d.ts.map +1 -0
- package/vendor/mcp-server/dist/tools/goals.js +38 -0
- package/vendor/mcp-server/package.json +1 -1
- package/vendor/mcp-server/src/index.ts +2 -0
- package/vendor/mcp-server/src/tools/goals.ts +62 -0
- package/vendor/runtime/README.md +36 -2
- package/vendor/runtime/dist/executor/asyncQueue.d.ts +1 -0
- package/vendor/runtime/dist/executor/asyncQueue.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/asyncQueue.js +3 -0
- package/vendor/runtime/dist/executor/claudeAgent.d.ts +5 -1
- package/vendor/runtime/dist/executor/claudeAgent.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/claudeAgent.js +77 -13
- package/vendor/runtime/dist/executor/codex.d.ts +8 -2
- package/vendor/runtime/dist/executor/codex.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codex.js +113 -38
- package/vendor/runtime/dist/executor/codexProtocol/AgentPath.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/AgentPath.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/AgentPath.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/FunctionCallOutputContentItem.d.ts +4 -1
- package/vendor/runtime/dist/executor/codexProtocol/FunctionCallOutputContentItem.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationFailure.d.ts +6 -0
- package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationFailure.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationFailure.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationItem.d.ts +12 -0
- package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationItem.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationItem.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/LegacyAppPathString.d.ts +24 -0
- package/vendor/runtime/dist/executor/codexProtocol/LegacyAppPathString.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/LegacyAppPathString.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/MessagePhase.d.ts +8 -0
- package/vendor/runtime/dist/executor/codexProtocol/MessagePhase.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/MessagePhase.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/Personality.d.ts +3 -0
- package/vendor/runtime/dist/executor/codexProtocol/Personality.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/SleepItem.d.ts +8 -0
- package/vendor/runtime/dist/executor/codexProtocol/SleepItem.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/SleepItem.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/SubAgentSource.d.ts +14 -0
- package/vendor/runtime/dist/executor/codexProtocol/SubAgentSource.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/SubAgentSource.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/ThreadId.d.ts +7 -0
- package/vendor/runtime/dist/executor/codexProtocol/ThreadId.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/ThreadId.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/WebSearchItem.d.ts +15 -0
- package/vendor/runtime/dist/executor/codexProtocol/WebSearchItem.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/WebSearchItem.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/AgentMessageDelivery.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/AgentMessageDelivery.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/AgentMessageDelivery.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/AsyncUserInputQuestion.d.ts +5 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/AsyncUserInputQuestion.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/AsyncUserInputQuestion.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CodexErrorInfo.d.ts +29 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CodexErrorInfo.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CodexErrorInfo.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentState.d.ts +6 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentState.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentState.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentStatus.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentStatus.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentStatus.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentTool.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentTool.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentTool.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentToolCallStatus.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentToolCallStatus.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentToolCallStatus.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CommandAction.d.ts +20 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CommandAction.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CommandAction.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionSource.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionSource.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionSource.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionStatus.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionStatus.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionStatus.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.d.ts +6 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallOutputContentItem.d.ts +11 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallOutputContentItem.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallOutputContentItem.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallStatus.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallStatus.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallStatus.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/FileUpdateChange.d.ts +7 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/FileUpdateChange.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/FileUpdateChange.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts +5 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/GitInfo.d.ts +6 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/GitInfo.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/GitInfo.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/HookPromptFragment.d.ts +5 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/HookPromptFragment.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/HookPromptFragment.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppDisplayMode.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppDisplayMode.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppDisplayMode.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppUi.d.ts +9 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppUi.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppUi.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallAppContext.d.ts +8 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallAppContext.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallAppContext.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallError.d.ts +4 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallError.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallError.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallResult.d.ts +7 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallResult.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallResult.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallStatus.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallStatus.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallStatus.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitation.d.ts +6 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitation.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitation.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitationEntry.d.ts +7 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitationEntry.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitationEntry.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentErrorDetails.d.ts +16 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentErrorDetails.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentErrorDetails.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentSteer.d.ts +4 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentSteer.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentSteer.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/Model.d.ts +8 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/Model.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.d.ts +11 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/NonSteerableTurnKind.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/NonSteerableTurnKind.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/NonSteerableTurnKind.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/PatchApplyStatus.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/PatchApplyStatus.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/PatchApplyStatus.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/PatchChangeKind.d.ts +9 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/PatchChangeKind.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/PatchChangeKind.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts +4 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/SessionSource.d.ts +7 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SessionSource.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SessionSource.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SubAgentActivityKind.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SubAgentActivityKind.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SubAgentActivityKind.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/Thread.d.ts +100 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/Thread.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/Thread.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadActiveFlag.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadActiveFlag.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadActiveFlag.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadHistoryMode.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadHistoryMode.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadHistoryMode.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadItem.d.ts +216 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadItem.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadItem.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadParams.d.ts +11 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadParams.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadParams.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadResponse.d.ts +5 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadResponse.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadResponse.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadResumeParams.d.ts +4 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadResumeParams.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSection.d.ts +19 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSection.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSection.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSectionAppearance.d.ts +8 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSectionAppearance.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSectionAppearance.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStartParams.d.ts +3 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStartParams.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStatus.d.ts +12 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStatus.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStatus.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/Turn.d.ts +36 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/Turn.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/Turn.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/TurnError.d.ts +12 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/TurnError.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/TurnError.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/TurnItemsView.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/TurnItemsView.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/TurnItemsView.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStartParams.d.ts +7 -2
- package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStartParams.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStatus.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStatus.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStatus.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/UserInput.d.ts +3 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/UserInput.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/WebSearchAction.d.ts +15 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/WebSearchAction.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/WebSearchAction.js +2 -0
- package/vendor/runtime/dist/executor/codexRpc.d.ts +13 -4
- package/vendor/runtime/dist/executor/codexRpc.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexRpc.js +21 -5
- package/vendor/runtime/dist/executor/codexSessions.d.ts +30 -0
- package/vendor/runtime/dist/executor/codexSessions.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexSessions.js +88 -0
- package/vendor/runtime/dist/executor/health.d.ts +8 -2
- package/vendor/runtime/dist/executor/health.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/health.js +21 -5
- package/vendor/runtime/dist/executor/liveTurns.d.ts +2 -1
- package/vendor/runtime/dist/executor/liveTurns.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/liveTurns.js +12 -5
- package/vendor/runtime/dist/executor/ownership.d.ts +40 -0
- package/vendor/runtime/dist/executor/ownership.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/ownership.js +106 -0
- package/vendor/runtime/dist/executor/providerRouter.d.ts +1 -0
- package/vendor/runtime/dist/executor/providerRouter.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/providerRouter.js +5 -0
- package/vendor/runtime/dist/executor/types.d.ts +27 -0
- package/vendor/runtime/dist/executor/types.d.ts.map +1 -1
- package/vendor/runtime/dist/harness/index.d.ts.map +1 -1
- package/vendor/runtime/dist/harness/index.js +1 -0
- package/vendor/runtime/dist/index.d.ts +2 -1
- package/vendor/runtime/dist/index.d.ts.map +1 -1
- package/vendor/runtime/dist/index.js +1 -0
- package/vendor/runtime/src/executor/asyncQueue.ts +3 -0
- package/vendor/runtime/src/executor/claudeAgent.ts +66 -13
- package/vendor/runtime/src/executor/codex.ts +124 -47
- package/vendor/runtime/src/executor/codexProtocol/AgentPath.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/FunctionCallOutputContentItem.ts +1 -1
- package/vendor/runtime/src/executor/codexProtocol/ImageGenerationFailure.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/ImageGenerationItem.ts +7 -0
- package/vendor/runtime/src/executor/codexProtocol/LegacyAppPathString.ts +27 -0
- package/vendor/runtime/src/executor/codexProtocol/MessagePhase.ts +11 -0
- package/vendor/runtime/src/executor/codexProtocol/Personality.ts +3 -0
- package/vendor/runtime/src/executor/codexProtocol/PlanType.ts +1 -1
- package/vendor/runtime/src/executor/codexProtocol/README.md +2 -2
- package/vendor/runtime/src/executor/codexProtocol/SleepItem.ts +8 -0
- package/vendor/runtime/src/executor/codexProtocol/SubAgentSource.ts +7 -0
- package/vendor/runtime/src/executor/codexProtocol/ThreadId.ts +10 -0
- package/vendor/runtime/src/executor/codexProtocol/WebSearchItem.ts +14 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/AgentMessageDelivery.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/AsyncUserInputQuestion.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/CodexErrorInfo.ts +12 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/CollabAgentState.ts +6 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/CollabAgentStatus.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/CollabAgentTool.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/CollabAgentToolCallStatus.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/CommandAction.ts +6 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/CommandExecutionSource.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/CommandExecutionStatus.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/CyberAccessProgram.ts +9 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/DynamicToolCallOutputContentItem.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/DynamicToolCallStatus.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/FileUpdateChange.ts +6 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/GetAccountRateLimitsResponse.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/GitInfo.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/HookPromptFragment.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/McpAppDisplayMode.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/McpAppUi.ts +9 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/McpToolCallAppContext.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/McpToolCallError.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/McpToolCallResult.ts +6 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/McpToolCallStatus.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/MemoryCitation.ts +6 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/MemoryCitationEntry.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/MisalignmentErrorDetails.ts +18 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/MisalignmentSteer.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/Model.ts +11 -2
- package/vendor/runtime/src/executor/codexProtocol/v2/ModelAccessPrograms.ts +13 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/NonSteerableTurnKind.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/PatchApplyStatus.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/PatchChangeKind.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitSnapshot.ts +5 -1
- package/vendor/runtime/src/executor/codexProtocol/v2/ReviewStartParams.ts +2 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/SessionSource.ts +6 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/SubAgentActivityKind.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/Thread.ts +104 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/ThreadActiveFlag.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/ThreadHistoryMode.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/ThreadItem.ts +125 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/ThreadReadParams.ts +12 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/ThreadReadResponse.ts +6 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/ThreadResumeParams.ts +5 -1
- package/vendor/runtime/src/executor/codexProtocol/v2/ThreadSection.ts +21 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/ThreadSectionAppearance.ts +8 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/ThreadStartParams.ts +4 -1
- package/vendor/runtime/src/executor/codexProtocol/v2/ThreadStatus.ts +6 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/Turn.ts +37 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/TurnError.ts +11 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/TurnItemsView.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/TurnStartParams.ts +7 -2
- package/vendor/runtime/src/executor/codexProtocol/v2/TurnStatus.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/UserInput.ts +1 -1
- package/vendor/runtime/src/executor/codexProtocol/v2/WebSearchAction.ts +5 -0
- package/vendor/runtime/src/executor/codexRpc.ts +26 -6
- package/vendor/runtime/src/executor/codexSessions.ts +108 -0
- package/vendor/runtime/src/executor/health.ts +21 -7
- package/vendor/runtime/src/executor/liveTurns.ts +12 -5
- package/vendor/runtime/src/executor/ownership.ts +83 -0
- package/vendor/runtime/src/executor/providerRouter.ts +6 -0
- package/vendor/runtime/src/executor/types.ts +20 -1
- package/vendor/runtime/src/harness/index.ts +1 -0
- package/vendor/runtime/src/index.ts +2 -1
- package/vendor/shared/dist/agentCommands.d.ts +1 -0
- package/vendor/shared/dist/agentCommands.d.ts.map +1 -1
- package/vendor/shared/dist/automations.d.ts +34 -0
- package/vendor/shared/dist/automations.d.ts.map +1 -1
- package/vendor/shared/dist/automations.js +12 -0
- package/vendor/shared/dist/cardStudio.d.ts +41 -0
- package/vendor/shared/dist/cardStudio.d.ts.map +1 -1
- package/vendor/shared/dist/cardStudio.js +13 -3
- package/vendor/shared/dist/computer.d.ts +7 -1
- package/vendor/shared/dist/computer.d.ts.map +1 -1
- package/vendor/shared/dist/computer.js +13 -4
- package/vendor/shared/dist/constants.d.ts +3 -3
- package/vendor/shared/dist/constants.d.ts.map +1 -1
- package/vendor/shared/dist/constants.js +8 -14
- package/vendor/shared/dist/goalNotes.d.ts +4 -0
- package/vendor/shared/dist/goalNotes.d.ts.map +1 -0
- package/vendor/shared/dist/goalNotes.js +23 -0
- package/vendor/shared/dist/goals.d.ts +835 -0
- package/vendor/shared/dist/goals.d.ts.map +1 -0
- package/vendor/shared/dist/goals.js +198 -0
- package/vendor/shared/dist/index.d.ts +7 -2
- package/vendor/shared/dist/index.d.ts.map +1 -1
- package/vendor/shared/dist/index.js +6 -1
- package/vendor/shared/dist/journal-vault.d.ts +1 -1
- package/vendor/shared/dist/messagingSafety.d.ts +21 -0
- package/vendor/shared/dist/messagingSafety.d.ts.map +1 -0
- package/vendor/shared/dist/messagingSafety.js +8 -0
- package/vendor/shared/dist/schemas/harness.d.ts +199 -169
- package/vendor/shared/dist/schemas/harness.d.ts.map +1 -1
- package/vendor/shared/dist/schemas/harness.js +25 -124
- package/vendor/shared/dist/smartCapture.d.ts +24 -0
- package/vendor/shared/dist/smartCapture.d.ts.map +1 -1
- package/vendor/shared/dist/smartCapture.js +15 -0
- package/vendor/shared/dist/taskSync.d.ts +342 -0
- package/vendor/shared/dist/taskSync.d.ts.map +1 -0
- package/vendor/shared/dist/taskSync.js +111 -0
- package/vendor/shared/dist/types.d.ts +1 -4
- package/vendor/shared/dist/types.d.ts.map +1 -1
- package/vendor/shared/dist/voiceCapture.d.ts +1 -1
- package/vendor/shared/dist/workspaces.d.ts +255 -0
- package/vendor/shared/dist/workspaces.d.ts.map +1 -0
- package/vendor/shared/dist/workspaces.js +89 -0
- package/vendor/shared/src/agentCommands.ts +1 -0
- package/vendor/shared/src/automations.ts +12 -0
- package/vendor/shared/src/cardStudio.ts +13 -3
- package/vendor/shared/src/computer.ts +19 -5
- package/vendor/shared/src/constants.ts +8 -14
- package/vendor/shared/src/goalNotes.ts +23 -0
- package/vendor/shared/src/goals.ts +237 -0
- package/vendor/shared/src/index.ts +7 -6
- package/vendor/shared/src/messagingSafety.ts +11 -0
- package/vendor/shared/src/schemas/harness.ts +24 -130
- package/vendor/shared/src/smartCapture.ts +27 -0
- package/vendor/shared/src/taskSync.ts +81 -0
- package/vendor/shared/src/types.ts +0 -6
- package/vendor/shared/src/workspaces.ts +103 -0
- package/dist/coding/conduct.d.ts +0 -69
- package/dist/coding/conduct.d.ts.map +0 -1
- package/dist/coding/conduct.js +0 -348
- package/dist/coding/fleetIntegrate.d.ts +0 -37
- package/dist/coding/fleetIntegrate.d.ts.map +0 -1
- package/dist/coding/fleetIntegrate.js +0 -64
- package/dist/coding/fleetPlan.d.ts +0 -20
- package/dist/coding/fleetPlan.d.ts.map +0 -1
- package/dist/coding/fleetPlan.js +0 -125
- package/dist/coding/fleetTasks.d.ts +0 -33
- package/dist/coding/fleetTasks.d.ts.map +0 -1
- package/dist/coding/fleetTasks.js +0 -75
- package/dist/coding/openFleetPr.d.ts +0 -41
- package/dist/coding/openFleetPr.d.ts.map +0 -1
- package/dist/coding/openFleetPr.js +0 -121
- package/src/coding/conduct.ts +0 -462
- package/src/coding/fleetIntegrate.ts +0 -95
- package/src/coding/fleetPlan.ts +0 -135
- package/src/coding/fleetTasks.ts +0 -109
- package/src/coding/openFleetPr.ts +0 -148
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { realpath } from 'node:fs/promises';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { RepoSettingsSchema, sessionProvider, type RepoSettings, type RunReview, type UnmergedWork, type WorkspaceCommand, type WorkspaceSnapshot, type WorkerWorkspace } from '@lucidity/shared';
|
|
6
|
+
import { RuntimeStore, conversationKey } from '../runtimeStore.js';
|
|
7
|
+
import type { RepoEntry } from '../config.js';
|
|
8
|
+
import { LaneQueue } from '../queue.js';
|
|
9
|
+
import { resolveRepo } from './repos.js';
|
|
10
|
+
import { archiveWorktree, archivedHead, deleteArchivedWorktree, ensureWorkspace, headSha, restoreArchivedFiles, sessionBranch, sessionWorktreePath, unmergedArchivedWork, workspaceBase, workspaceBranchExists, type Workspace } from './worktree.js';
|
|
11
|
+
import type { CodeTurnRequest } from './runCodeTurn.js';
|
|
12
|
+
import { copyIncludedFiles, matchedFiles, runSetupScript } from './worktreeSetup.js';
|
|
13
|
+
import { inspectRun, continuationRequest } from './runReview.js';
|
|
14
|
+
|
|
15
|
+
/** "Worktree 3": the next number this repository has not used. */
|
|
16
|
+
export function nextWorkerTitle(titles: string[]): string {
|
|
17
|
+
const used = titles.map((title) => (title.startsWith('Worktree ') ? Number(title.slice(9)) : 0));
|
|
18
|
+
return `Worktree ${Math.max(0, ...used.filter(Number.isInteger)) + 1}`;
|
|
19
|
+
}
|
|
20
|
+
// Two checkouts fighting over :3001 and :8081 is half of CLAUDE.md's gotchas. Every worktree
|
|
21
|
+
// gets ten ports of its own, kept for its lifetime, well away from those defaults and from the
|
|
22
|
+
// owner's phone Metro on 8090.
|
|
23
|
+
const PORT_BASE = 4100;
|
|
24
|
+
const PORT_BLOCK = 10;
|
|
25
|
+
|
|
26
|
+
/** The lowest block of ports no other worktree on this computer holds. */
|
|
27
|
+
export function nextPortBlock(taken: Array<number | undefined>): number {
|
|
28
|
+
const used = new Set(taken);
|
|
29
|
+
let port = PORT_BASE;
|
|
30
|
+
while (used.has(port)) port += PORT_BLOCK;
|
|
31
|
+
return port;
|
|
32
|
+
}
|
|
33
|
+
type SavedWorker = WorkerWorkspace & { path?: string; sessionCheckout?: boolean; legacy?: boolean; legacyMessages?: NonNullable<WorkspaceSnapshot['legacyMessages']> };
|
|
34
|
+
type SavedCheckout = { revision: string; clearedThrough?: string; legacyMessages?: WorkspaceSnapshot['legacyMessages']; resume?: string };
|
|
35
|
+
|
|
36
|
+
/** Workspace lifetime is independent of runs, provider sessions, PRs, and phone storage. */
|
|
37
|
+
export class WorkspaceRegistry {
|
|
38
|
+
private lanes = new LaneQueue();
|
|
39
|
+
private setups = new Map<string, Promise<void>>();
|
|
40
|
+
constructor(private readonly store: RuntimeStore, private readonly repos: () => RepoEntry[], private readonly baseDir?: string) {}
|
|
41
|
+
|
|
42
|
+
private repo(id: string) {
|
|
43
|
+
const repo = resolveRepo(id, this.repos());
|
|
44
|
+
if (!repo) throw new Error('This repository is not available on the paired computer.');
|
|
45
|
+
return repo;
|
|
46
|
+
}
|
|
47
|
+
private public(worker: SavedWorker): WorkerWorkspace {
|
|
48
|
+
const { path: _, legacyMessages: __, sessionCheckout: ___, legacy: ____, ...row } = worker;
|
|
49
|
+
return { ...row, resume: this.store.latestSession(worker.conversationId) ?? row.resume,
|
|
50
|
+
...(this.setups.has(worker.workerId) ? { setup: 'running' as const } : {}) };
|
|
51
|
+
}
|
|
52
|
+
list(repoId?: string): WorkerWorkspace[] {
|
|
53
|
+
return this.store.list<SavedWorker>('workers')
|
|
54
|
+
.filter((w) => (!repoId || w.repoId === repoId) && this.repos().some((r) => r.id === w.repoId))
|
|
55
|
+
.map((w) => this.public(w));
|
|
56
|
+
}
|
|
57
|
+
/** How this repository's worktrees are prepared. Nothing is copied or run until the owner sets it. */
|
|
58
|
+
settings(repoId: string): RepoSettings {
|
|
59
|
+
return RepoSettingsSchema.parse(this.store.get<RepoSettings>('repo-settings', repoId) ?? {});
|
|
60
|
+
}
|
|
61
|
+
private places(repoId: string) {
|
|
62
|
+
const root = this.repo(repoId).root;
|
|
63
|
+
return { root, worktrees: dirname(sessionWorktreePath(repoId, this.baseDir, 'x')),
|
|
64
|
+
copyMatches: matchedFiles(root, this.settings(repoId).copy) };
|
|
65
|
+
}
|
|
66
|
+
/** Run the archive command, then free the folder. Shared by the phone's Archive and archive-on-merge. */
|
|
67
|
+
private async archive(worker: SavedWorker): Promise<void> {
|
|
68
|
+
const { repoId, workerId } = worker;
|
|
69
|
+
if (worker.state === 'creating' || this.setups.has(workerId)) throw new Error('Wait for workspace setup to finish before archiving.');
|
|
70
|
+
if (this.store.unfinished(worker.conversationId))
|
|
71
|
+
throw new Error('Stop this worker and its queued messages before archiving it.');
|
|
72
|
+
// The session checkout is shared with the classic single session, so its folder stays.
|
|
73
|
+
if (!worker.sessionCheckout) {
|
|
74
|
+
const root = this.repo(repoId).root;
|
|
75
|
+
const settings = this.settings(repoId);
|
|
76
|
+
const path = sessionWorktreePath(repoId, this.baseDir, workerId);
|
|
77
|
+
if (settings.archiveScript && existsSync(path))
|
|
78
|
+
await runSetupScript(root, path, worker.title, settings.archiveScript, worker.port).catch((error) => {
|
|
79
|
+
const detail = String((error as { stderr?: string }).stderr || (error as Error).message).trim().slice(-600);
|
|
80
|
+
throw new Error(`The archive command failed, so this worktree was kept. ${detail}`);
|
|
81
|
+
});
|
|
82
|
+
await archiveWorktree(root, { path, branch: worker.branch ?? sessionBranch(repoId, workerId), mode: 'worktree' },
|
|
83
|
+
workerId, { deleteBranch: settings.deleteBranchOnArchive });
|
|
84
|
+
}
|
|
85
|
+
this.save({ ...worker, state: 'archived' });
|
|
86
|
+
}
|
|
87
|
+
/** Remove an archived worktree for good: its local branch, its snapshot and its record. Answers
|
|
88
|
+
* with the work that would be lost, deleting nothing, unless there is none or `force` is set. */
|
|
89
|
+
private delete(repoId: string, workerId: string, force?: boolean): Promise<UnmergedWork | undefined> {
|
|
90
|
+
const root = this.repo(repoId).root;
|
|
91
|
+
// Queued behind create, so a restore that is already under way finishes first and is seen here.
|
|
92
|
+
return this.lanes.run(root, async () => {
|
|
93
|
+
const worker = this.store.get<SavedWorker>('workers', workerId);
|
|
94
|
+
// Already gone: another device may still list a worktree that was deleted from this one.
|
|
95
|
+
if (!worker) return undefined;
|
|
96
|
+
if (worker.repoId !== repoId) throw new Error('This worker is not registered in this repository.');
|
|
97
|
+
if (worker.state !== 'archived') throw new Error('Archive this worktree before deleting it.');
|
|
98
|
+
// The session checkout's branch and folder belong to the classic single session, so they stay.
|
|
99
|
+
if (!worker.sessionCheckout) {
|
|
100
|
+
const branch = worker.branch ?? sessionBranch(repoId, workerId);
|
|
101
|
+
if (!force) {
|
|
102
|
+
const unmerged = await unmergedArchivedWork(root, workerId, branch,
|
|
103
|
+
[worker.baseRef, this.settings(repoId).baseRef, this.repos().find((r) => r.id === repoId)?.baseRef]);
|
|
104
|
+
if (unmerged.commits || unmerged.uncommitted) return unmerged;
|
|
105
|
+
}
|
|
106
|
+
await deleteArchivedWorktree(root, workerId, branch).catch((error) => {
|
|
107
|
+
const detail = String((error as { stderr?: string }).stderr || (error as Error).message).trim().slice(-600);
|
|
108
|
+
throw new Error(`This worktree's branch could not be deleted, so it was kept. ${detail}`);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
// The conversation's runs stay: they are the receipts that stop a replayed request running twice.
|
|
112
|
+
this.store.transaction(() => {
|
|
113
|
+
this.store.delete('workers', workerId);
|
|
114
|
+
this.store.delete('workspaces', worker.conversationId);
|
|
115
|
+
});
|
|
116
|
+
return undefined;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/** Archive ready worktrees whose pull request has merged, in repositories that asked for it.
|
|
120
|
+
* A worktree with commits past the merged head, or a turn in flight, is left alone. */
|
|
121
|
+
async archiveMerged(mergedHead: (repoRoot: string, branch: string) => Promise<string | undefined>): Promise<string[]> {
|
|
122
|
+
const archived: string[] = [];
|
|
123
|
+
for (const worker of this.store.list<SavedWorker>('workers')) {
|
|
124
|
+
if (worker.state !== 'ready' || worker.sessionCheckout || !worker.path || !worker.branch) continue;
|
|
125
|
+
try {
|
|
126
|
+
if (!this.settings(worker.repoId).archiveOnMerge || !existsSync(worker.path)) continue;
|
|
127
|
+
const merged = await mergedHead(this.repo(worker.repoId).root, worker.branch);
|
|
128
|
+
if (!merged || merged !== await headSha(worker.path)) continue;
|
|
129
|
+
await this.archive(worker);
|
|
130
|
+
archived.push(worker.workerId);
|
|
131
|
+
} catch { /* busy, or the repository is gone: try again on the next sweep */ }
|
|
132
|
+
}
|
|
133
|
+
return archived;
|
|
134
|
+
}
|
|
135
|
+
private save(worker: SavedWorker): void {
|
|
136
|
+
this.store.set('workers', worker.workerId, { ...worker, updatedAt: new Date().toISOString() });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
resume(request: CodeTurnRequest): string | undefined {
|
|
140
|
+
if (!request.workerId && request.mode === 'in-place' && !request.handoff) {
|
|
141
|
+
const conversation = conversationKey({ ...request, kind: 'code' });
|
|
142
|
+
const checkout = this.store.get<SavedCheckout>('checkout-conversations', conversation);
|
|
143
|
+
const resume = this.store.latestSession(conversation, checkout?.clearedThrough) ?? checkout?.resume ??
|
|
144
|
+
(checkout && checkout.revision !== '0' ? undefined : request.resume);
|
|
145
|
+
return request.provider && sessionProvider(resume) !== request.provider ? undefined : resume;
|
|
146
|
+
}
|
|
147
|
+
if (!request.workerId || request.handoff) return request.resume;
|
|
148
|
+
const worker = this.store.get<SavedWorker>('workers', request.workerId);
|
|
149
|
+
if (!worker || worker.repoId !== request.repoId) return request.resume;
|
|
150
|
+
const resume = this.store.latestSession(worker.conversationId) ?? worker.resume ?? request.resume;
|
|
151
|
+
return request.provider && sessionProvider(resume) !== request.provider ? undefined : resume;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async create(repoId: string, workerId: string, title?: string, brief = ''): Promise<WorkerWorkspace> {
|
|
155
|
+
const repo = this.repo(repoId);
|
|
156
|
+
return this.lanes.run(repo.root, async () => {
|
|
157
|
+
const previous = this.store.get<SavedWorker>('workers', workerId);
|
|
158
|
+
if (previous && previous.repoId !== repoId) throw new Error('This worker belongs to another repository.');
|
|
159
|
+
if (previous?.state === 'archived') throw new Error('Restore this worker before continuing.');
|
|
160
|
+
if (previous?.state === 'ready') return this.public(previous);
|
|
161
|
+
const now = new Date().toISOString();
|
|
162
|
+
const worker: SavedWorker = previous ?? {
|
|
163
|
+
workerId, repoId, title: title || nextWorkerTitle(this.store.list<SavedWorker>('workers').filter((w) => w.repoId === repoId).map((w) => w.title)), brief,
|
|
164
|
+
workspaceId: workerId, conversationId: conversationKey({ kind: 'code', repoId, workerId }),
|
|
165
|
+
state: 'creating', createdAt: now, updatedAt: now,
|
|
166
|
+
};
|
|
167
|
+
this.save({ ...worker, state: 'creating', error: undefined });
|
|
168
|
+
try {
|
|
169
|
+
const gitWorkerId = worker.sessionCheckout ? undefined : workerId;
|
|
170
|
+
const path = sessionWorktreePath(repoId, this.baseDir, gitWorkerId);
|
|
171
|
+
const branchExists = await workspaceBranchExists(repo.root, repoId, gitWorkerId);
|
|
172
|
+
// A branch deleted on archive is re-created from the commit its snapshot was taken on.
|
|
173
|
+
const archivedTip = gitWorkerId && !branchExists && !existsSync(path) ? await archivedHead(repo.root, workerId) : undefined;
|
|
174
|
+
if (worker.legacy && !existsSync(path) && !branchExists && !archivedTip)
|
|
175
|
+
throw new Error('The original worker branch and files are missing. Its conversation is preserved; create a new worker for new work.');
|
|
176
|
+
// A known legacy directory is adopted without fetching or resetting it.
|
|
177
|
+
const base = existsSync(path) || branchExists || archivedTip || previous?.baseSha
|
|
178
|
+
? previous?.baseSha ? { ref: previous.baseRef!, sha: previous.baseSha } : undefined
|
|
179
|
+
: await workspaceBase(repo.root, this.settings(repoId).baseRef || this.repos().find((r) => r.id === repoId)?.baseRef);
|
|
180
|
+
if (base) this.save({ ...worker, state: 'creating', baseRef: base.ref, baseSha: base.sha });
|
|
181
|
+
const fresh = !existsSync(path);
|
|
182
|
+
const workspace = await ensureWorkspace(repo.root, repoId, { workerId: gitWorkerId, baseDir: this.baseDir, startPoint: archivedTip ?? base?.sha });
|
|
183
|
+
if (gitWorkerId) await restoreArchivedFiles(repo.root, workspace, workerId);
|
|
184
|
+
const ready: SavedWorker = { ...worker, state: 'ready', error: undefined, path: await realpath(workspace.path),
|
|
185
|
+
port: this.portOf(worker), branch: workspace.branch, ...(base ? { baseRef: base.ref, baseSha: base.sha } : {}) };
|
|
186
|
+
this.save(ready);
|
|
187
|
+
if (fresh && gitWorkerId) this.setUp(repo.root, ready);
|
|
188
|
+
return this.public(ready);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
const reserved = this.store.get<SavedWorker>('workers', workerId) ?? worker;
|
|
191
|
+
this.save({ ...reserved, state: 'setup_failed', error: error instanceof Error ? error.message : String(error) });
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** A worktree's port block. Archived worktrees keep theirs so a restore comes back on the same ports. */
|
|
198
|
+
private portOf(worker: SavedWorker): number {
|
|
199
|
+
return worker.port ?? nextPortBlock(this.store.list<SavedWorker>('workers').map((w) => w.port));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Fill in a worktree: the repository's listed files, then its setup command. This runs after the
|
|
203
|
+
* worktree is reported ready so the phone is not kept waiting; a turn waits for it in prepare().
|
|
204
|
+
* A failure is noted on the worker and never fails the worktree. */
|
|
205
|
+
private setUp(repoRoot: string, worker: SavedWorker): void {
|
|
206
|
+
const settings = this.settings(worker.repoId);
|
|
207
|
+
if (!settings.copy.length && !settings.setup) return;
|
|
208
|
+
this.save({ ...worker, setup: undefined, error: undefined });
|
|
209
|
+
const run = (async () => {
|
|
210
|
+
copyIncludedFiles(repoRoot, worker.path!, settings.copy);
|
|
211
|
+
if (settings.setup) await runSetupScript(repoRoot, worker.path!, worker.title, settings.setup, worker.port);
|
|
212
|
+
})().catch((error) => {
|
|
213
|
+
const detail = String((error as { stderr?: string }).stderr || (error as Error).message).trim().slice(-600);
|
|
214
|
+
console.error(`[workspaces] setup failed for ${worker.workerId}: ${detail}`);
|
|
215
|
+
const current = this.store.get<SavedWorker>('workers', worker.workerId);
|
|
216
|
+
if (current?.state === 'ready') this.save({ ...current, setup: 'failed', error: detail });
|
|
217
|
+
}).finally(() => this.setups.delete(worker.workerId));
|
|
218
|
+
this.setups.set(worker.workerId, run);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async prepare(request: CodeTurnRequest): Promise<Workspace> {
|
|
222
|
+
this.checkRecoveryWorkspace(request);
|
|
223
|
+
const repo = this.repo(request.repoId);
|
|
224
|
+
let gitWorkerId = request.workerId;
|
|
225
|
+
if (request.workerId) {
|
|
226
|
+
await this.create(request.repoId, request.workerId, undefined, request.prompt);
|
|
227
|
+
await this.setups.get(request.workerId);
|
|
228
|
+
const worker = this.store.get<SavedWorker>('workers', request.workerId)!;
|
|
229
|
+
if (worker.sessionCheckout) gitWorkerId = undefined;
|
|
230
|
+
if (!worker.path || !existsSync(worker.path)) {
|
|
231
|
+
this.save({ ...worker, state: 'setup_failed', error: 'Workspace files are missing. Restore or retry setup to recover the branch.' });
|
|
232
|
+
throw new Error('Workspace files are missing. Retry setup to recover the branch.');
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const workspace = await ensureWorkspace(repo.root, request.repoId, {
|
|
236
|
+
mode: request.workerId ? 'worktree' : request.mode, workerId: gitWorkerId, baseDir: this.baseDir,
|
|
237
|
+
});
|
|
238
|
+
this.store.set('workspaces', conversationKey({ ...request, kind: 'code' }), { ...workspace, repoId: request.repoId });
|
|
239
|
+
const worker = request.workerId ? this.store.get<SavedWorker>('workers', request.workerId) : undefined;
|
|
240
|
+
if (!worker || worker.sessionCheckout) return workspace;
|
|
241
|
+
// Worktrees made before ports existed get their block on their next turn.
|
|
242
|
+
const port = this.portOf(worker);
|
|
243
|
+
if (worker.port !== port) this.save({ ...worker, port });
|
|
244
|
+
return { ...workspace, env: { LUCIDITY_PORT: String(port), LUCIDITY_WORKTREE_NAME: worker.title } };
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
private checkout(command: WorkspaceCommand, commandId?: string): WorkspaceSnapshot {
|
|
248
|
+
if (!command.repoId || command.workerId) throw new Error('Select a repository main checkout.');
|
|
249
|
+
this.repo(command.repoId);
|
|
250
|
+
const conversationId = conversationKey({ kind: 'code', repoId: command.repoId, mode: 'in-place' });
|
|
251
|
+
if (!['history', 'import', 'clear-history'].includes(command.action))
|
|
252
|
+
throw new Error('Main checkout supports history, import and clear.');
|
|
253
|
+
const saved = () => this.store.get<SavedCheckout>('checkout-conversations', conversationId) ?? { revision: '0' };
|
|
254
|
+
if (command.action !== 'history') {
|
|
255
|
+
this.store.transaction(() => {
|
|
256
|
+
const receipt = commandId && this.store.get<{ input: string }>('workspace-commands', commandId);
|
|
257
|
+
if (receipt) {
|
|
258
|
+
if (receipt.input !== JSON.stringify(command)) throw new Error('This command ID already belongs to different input.');
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const checkout = saved();
|
|
262
|
+
if ((command.revision ?? '0') !== checkout.revision)
|
|
263
|
+
throw new Error('This conversation changed on the computer. Refresh before changing its history.');
|
|
264
|
+
if (command.action === 'clear-history') {
|
|
265
|
+
if (this.store.unfinished(conversationId)) throw new Error('Finish or stop active and queued messages before clearing this conversation.');
|
|
266
|
+
this.store.set('checkout-conversations', conversationId, {
|
|
267
|
+
revision: commandId ?? `${Date.now()}:${checkout.revision}`,
|
|
268
|
+
clearedThrough: this.store.lastCommand(conversationId),
|
|
269
|
+
} satisfies SavedCheckout);
|
|
270
|
+
} else {
|
|
271
|
+
const messages = new Map((checkout.legacyMessages ?? []).map((message) => [message.id, message]));
|
|
272
|
+
for (const message of command.legacy?.messages ?? []) if (!messages.has(message.id)) messages.set(message.id, message);
|
|
273
|
+
this.store.set('checkout-conversations', conversationId, { ...checkout,
|
|
274
|
+
legacyMessages: [...messages.values()], resume: checkout.resume ?? command.legacy?.resume,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
if (commandId) this.store.set('workspace-commands', commandId, { input: JSON.stringify(command) });
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
const checkout = saved();
|
|
281
|
+
const page = this.store.commands(conversationId, { before: command.before, after: checkout.clearedThrough, limit: 10 });
|
|
282
|
+
return {
|
|
283
|
+
workers: [], checkout: { repoId: command.repoId, conversationId, revision: checkout.revision,
|
|
284
|
+
resume: this.store.latestSession(conversationId, checkout.clearedThrough) ?? checkout.resume },
|
|
285
|
+
legacyMessages: command.before ? [] : checkout.legacyMessages,
|
|
286
|
+
runs: this.historyRuns(page),
|
|
287
|
+
...(page.length === 10 ? { nextBefore: page[0]!.request.id } : {}),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private historyRuns(page: ReturnType<RuntimeStore['commands']>): WorkspaceSnapshot['runs'] {
|
|
292
|
+
return page.map(({ request, state }) => ({ requestId: request.id, prompt: 'prompt' in request ? request.prompt : '',
|
|
293
|
+
...('handoff' in request && request.handoff && request.provider ? { handoff: { from: request.handoff.from, to: request.provider } } : {}),
|
|
294
|
+
frames: state.frames, terminated: state.terminated }));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
async command(command: WorkspaceCommand, commandId?: string): Promise<WorkspaceSnapshot> {
|
|
298
|
+
if (command.action === 'inspect-run' || command.action === 'continue-run') {
|
|
299
|
+
if (!command.repoId) throw new Error('Select a repository.');
|
|
300
|
+
const repo = this.repo(command.repoId);
|
|
301
|
+
const path = command.checkout ? repo.root : command.workerId ? this.store.get<SavedWorker>('workers', command.workerId)?.path : undefined;
|
|
302
|
+
if (command.action === 'continue-run') return { workers: this.list(command.repoId), review: this.store.get('run-reviews', command.requestId!) };
|
|
303
|
+
return { workers: this.list(command.repoId), review: await inspectRun(this.store, command, path) };
|
|
304
|
+
}
|
|
305
|
+
if (command.checkout) return this.checkout(command, commandId);
|
|
306
|
+
if (command.action === 'clear-history') throw new Error('Select Main checkout to clear its history.');
|
|
307
|
+
const { action, repoId } = command;
|
|
308
|
+
let workerId = command.workerId;
|
|
309
|
+
if (action === 'list') return { workers: this.list(repoId) };
|
|
310
|
+
if (action === 'settings' || action === 'save-settings') {
|
|
311
|
+
if (!repoId) throw new Error('Select a repository.');
|
|
312
|
+
this.repo(repoId);
|
|
313
|
+
if (action === 'save-settings') this.store.set('repo-settings', repoId, RepoSettingsSchema.parse(command.settings ?? {}));
|
|
314
|
+
return { workers: this.list(repoId), settings: this.settings(repoId), places: this.places(repoId) };
|
|
315
|
+
}
|
|
316
|
+
if (action === 'import' && repoId && command.legacy?.sessionCheckout) {
|
|
317
|
+
const key = createHash('sha256').update(this.repo(repoId).root).digest('hex');
|
|
318
|
+
workerId = `${key.slice(0, 8)}-${key.slice(8, 12)}-7${key.slice(13, 16)}-8${key.slice(17, 20)}-${key.slice(20, 32)}`;
|
|
319
|
+
}
|
|
320
|
+
if (!repoId || !workerId) throw new Error('Select a repository and worker.');
|
|
321
|
+
this.repo(repoId);
|
|
322
|
+
if (action === 'create') await this.create(repoId, workerId, command.title, command.brief);
|
|
323
|
+
else if (action === 'import') {
|
|
324
|
+
const previous = this.store.get<SavedWorker>('workers', workerId);
|
|
325
|
+
if (previous && previous.repoId !== repoId) throw new Error('This worker belongs to another repository.');
|
|
326
|
+
if (!previous) {
|
|
327
|
+
const now = new Date().toISOString();
|
|
328
|
+
this.save({ workerId, repoId, title: command.title ?? 'Worker', brief: command.brief ?? '',
|
|
329
|
+
workspaceId: workerId, conversationId: conversationKey({ kind: 'code', repoId, workerId }),
|
|
330
|
+
state: 'setup_failed', createdAt: now, updatedAt: now,
|
|
331
|
+
legacyMessages: command.legacy?.messages ?? [], resume: command.legacy?.resume,
|
|
332
|
+
sessionCheckout: command.legacy?.sessionCheckout, legacy: true });
|
|
333
|
+
await this.create(repoId, workerId).catch(() => {});
|
|
334
|
+
}
|
|
335
|
+
} else if (action === 'delete') {
|
|
336
|
+
const unmerged = await this.delete(repoId, workerId, command.force);
|
|
337
|
+
return { workers: this.list(repoId), ...(unmerged ? { unmerged } : {}) };
|
|
338
|
+
} else {
|
|
339
|
+
const worker = this.store.get<SavedWorker>('workers', workerId);
|
|
340
|
+
if (!worker || worker.repoId !== repoId) throw new Error('This worker is not registered in this repository.');
|
|
341
|
+
if (action === 'history') {
|
|
342
|
+
const page = this.store.commands(worker.conversationId, { before: command.before, limit: 10 });
|
|
343
|
+
const frames = page.flatMap((r) => r.state.frames);
|
|
344
|
+
const resume = [...frames].reverse().find((f) => typeof f.sessionId === 'string')?.sessionId;
|
|
345
|
+
return { workers: [{ ...this.public(worker), ...(typeof resume === 'string' ? { resume } : {}) }],
|
|
346
|
+
legacyMessages: command.before ? [] : worker.legacyMessages,
|
|
347
|
+
runs: this.historyRuns(page),
|
|
348
|
+
...(page.length === 10 ? { nextBefore: page[0]!.request.id } : {}) };
|
|
349
|
+
}
|
|
350
|
+
if (action === 'archive') {
|
|
351
|
+
await this.archive(worker);
|
|
352
|
+
} else if (action === 'setup') {
|
|
353
|
+
if (worker.state !== 'ready' || worker.sessionCheckout || !worker.path) throw new Error('This worktree is not ready for setup.');
|
|
354
|
+
if (!this.setups.has(workerId)) this.setUp(this.repo(repoId).root, worker);
|
|
355
|
+
} else if (action === 'restore') {
|
|
356
|
+
this.save({ ...worker, state: 'creating' });
|
|
357
|
+
await this.create(repoId, workerId);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return { workers: this.list(repoId) };
|
|
361
|
+
}
|
|
362
|
+
continuation(command: WorkspaceCommand) {
|
|
363
|
+
if (!command.repoId) throw new Error('Select a repository.');
|
|
364
|
+
this.repo(command.repoId);
|
|
365
|
+
if (command.workerId && this.store.get<SavedWorker>('workers', command.workerId)?.state !== 'ready')
|
|
366
|
+
throw new Error('Restore this worker before continuing.');
|
|
367
|
+
const request = continuationRequest(this.store, command);
|
|
368
|
+
this.checkRecoveryWorkspace(request);
|
|
369
|
+
return request;
|
|
370
|
+
}
|
|
371
|
+
private checkRecoveryWorkspace(request: CodeTurnRequest) {
|
|
372
|
+
if (!request.recoveryOf) return;
|
|
373
|
+
const review = this.store.get<RunReview>('run-reviews', request.recoveryOf);
|
|
374
|
+
const worker = request.workerId ? this.store.get<SavedWorker>('workers', request.workerId) : undefined;
|
|
375
|
+
const path = !request.workerId && request.mode === 'in-place' ? this.repo(request.repoId).root :
|
|
376
|
+
sessionWorktreePath(request.repoId, this.baseDir, worker?.sessionCheckout ? undefined : request.workerId);
|
|
377
|
+
if (!review?.workspace || !existsSync(review.workspace) || !existsSync(path) || realpathSync(path) !== realpathSync(review.workspace))
|
|
378
|
+
throw new Error('The configured workspace changed since this turn. Restore the reviewed workspace before continuing.');
|
|
379
|
+
}
|
|
380
|
+
}
|