@opencorelabs/lucidity 0.8.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 +2 -2
- package/dist/assets/speech/lucidity-speech +0 -0
- 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/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 +3 -14
- package/dist/coding/runCodeTurn.d.ts.map +1 -1
- package/dist/coding/runCodeTurn.js +21 -86
- 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 +49 -1
- package/dist/coding/workspaceRegistry.d.ts.map +1 -1
- package/dist/coding/workspaceRegistry.js +208 -17
- package/dist/coding/worktree.d.ts +61 -18
- package/dist/coding/worktree.d.ts.map +1 -1
- package/dist/coding/worktree.js +149 -17
- 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/index.js +21 -28
- 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/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/room/client.d.ts +2 -20
- package/dist/room/client.d.ts.map +1 -1
- package/dist/room/client.js +18 -29
- package/dist/room/computer.d.ts.map +1 -1
- package/dist/room/computer.js +1 -2
- package/dist/room/incidents.d.ts +3 -0
- package/dist/room/incidents.d.ts.map +1 -1
- package/dist/room/incidents.js +1 -0
- package/dist/room/turnQueue.d.ts.map +1 -1
- package/dist/room/turnQueue.js +28 -22
- package/dist/runtimeStore.d.ts +2 -0
- package/dist/runtimeStore.d.ts.map +1 -1
- package/dist/runtimeStore.js +17 -0
- package/dist/vault.d.ts +6 -3
- package/dist/vault.d.ts.map +1 -1
- package/dist/vault.js +18 -4
- package/package.json +1 -1
- package/src/automations/service.ts +47 -21
- package/src/automations/store.ts +41 -50
- package/src/automations/workflow.ts +49 -0
- package/src/coding/listPrs.ts +14 -0
- package/src/coding/runCodeTurn.ts +26 -95
- package/src/coding/runReview.ts +83 -0
- package/src/coding/workspaceRegistry.ts +186 -16
- package/src/coding/worktree.ts +161 -20
- package/src/coding/worktreeSetup.ts +50 -0
- package/src/index.ts +22 -31
- package/src/jobs/briefing.ts +62 -109
- package/src/logTimestamps.ts +14 -0
- package/src/providerRecovery.ts +99 -0
- package/src/room/client.ts +19 -54
- package/src/room/computer.ts +1 -2
- package/src/room/incidents.ts +4 -0
- package/src/room/turnQueue.ts +27 -29
- package/src/runtimeStore.ts +18 -1
- package/src/vault.ts +16 -7
- package/vendor/mcp-server/package.json +1 -1
- package/vendor/runtime/README.md +34 -0
- package/vendor/runtime/dist/executor/claudeAgent.d.ts +4 -0
- package/vendor/runtime/dist/executor/claudeAgent.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/claudeAgent.js +57 -4
- package/vendor/runtime/dist/executor/codex.d.ts +7 -2
- package/vendor/runtime/dist/executor/codex.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codex.js +47 -4
- 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/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/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/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/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/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/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/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/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/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/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 +3 -1
- package/vendor/runtime/dist/executor/codexRpc.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexRpc.js +3 -2
- package/vendor/runtime/dist/executor/health.d.ts +6 -1
- package/vendor/runtime/dist/executor/health.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/health.js +4 -0
- package/vendor/runtime/dist/executor/ownership.d.ts +6 -1
- package/vendor/runtime/dist/executor/ownership.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/ownership.js +7 -0
- package/vendor/runtime/dist/executor/types.d.ts +25 -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 +1 -1
- package/vendor/runtime/dist/index.d.ts.map +1 -1
- package/vendor/runtime/src/executor/claudeAgent.ts +50 -4
- package/vendor/runtime/src/executor/codex.ts +51 -5
- package/vendor/runtime/src/executor/codexProtocol/AgentPath.ts +5 -0
- 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/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/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/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/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/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/ThreadSection.ts +21 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/ThreadSectionAppearance.ts +8 -0
- 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/TurnStatus.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/WebSearchAction.ts +5 -0
- package/vendor/runtime/src/executor/codexRpc.ts +4 -2
- package/vendor/runtime/src/executor/health.ts +5 -1
- package/vendor/runtime/src/executor/ownership.ts +8 -1
- package/vendor/runtime/src/executor/types.ts +18 -1
- package/vendor/runtime/src/harness/index.ts +1 -0
- package/vendor/runtime/src/index.ts +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/computer.d.ts +1 -1
- package/vendor/shared/dist/computer.d.ts.map +1 -1
- package/vendor/shared/dist/computer.js +1 -2
- package/vendor/shared/dist/constants.d.ts +1 -1
- package/vendor/shared/dist/constants.d.ts.map +1 -1
- package/vendor/shared/dist/constants.js +3 -10
- package/vendor/shared/dist/index.d.ts +4 -2
- package/vendor/shared/dist/index.d.ts.map +1 -1
- package/vendor/shared/dist/index.js +3 -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 +98 -169
- package/vendor/shared/dist/schemas/harness.d.ts.map +1 -1
- package/vendor/shared/dist/schemas/harness.js +19 -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 +117 -0
- package/vendor/shared/dist/workspaces.d.ts.map +1 -1
- package/vendor/shared/dist/workspaces.js +50 -1
- package/vendor/shared/src/automations.ts +12 -0
- package/vendor/shared/src/computer.ts +3 -3
- package/vendor/shared/src/constants.ts +3 -10
- package/vendor/shared/src/index.ts +3 -6
- package/vendor/shared/src/messagingSafety.ts +11 -0
- package/vendor/shared/src/schemas/harness.ts +18 -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 +56 -1
- package/dist/coding/conduct.d.ts +0 -48
- package/dist/coding/conduct.d.ts.map +0 -1
- package/dist/coding/conduct.js +0 -263
- 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/src/coding/conduct.ts +0 -325
- package/src/coding/fleetPlan.ts +0 -135
- package/src/coding/fleetTasks.ts +0 -109
|
@@ -1,18 +1,39 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
1
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
2
3
|
import { realpath } from 'node:fs/promises';
|
|
3
4
|
import { createHash } from 'node:crypto';
|
|
4
|
-
import { sessionProvider } from '@lucidity/shared';
|
|
5
|
+
import { RepoSettingsSchema, sessionProvider } from '@lucidity/shared';
|
|
5
6
|
import { conversationKey } from '../runtimeStore.js';
|
|
6
7
|
import { LaneQueue } from '../queue.js';
|
|
7
8
|
import { resolveRepo } from './repos.js';
|
|
8
|
-
import { ensureWorkspace, sessionWorktreePath, workspaceBase, workspaceBranchExists } from './worktree.js';
|
|
9
|
-
|
|
9
|
+
import { archiveWorktree, archivedHead, deleteArchivedWorktree, ensureWorkspace, headSha, restoreArchivedFiles, sessionBranch, sessionWorktreePath, unmergedArchivedWork, workspaceBase, workspaceBranchExists } from './worktree.js';
|
|
10
|
+
import { copyIncludedFiles, matchedFiles, runSetupScript } from './worktreeSetup.js';
|
|
11
|
+
import { inspectRun, continuationRequest } from './runReview.js';
|
|
12
|
+
/** "Worktree 3": the next number this repository has not used. */
|
|
13
|
+
export function nextWorkerTitle(titles) {
|
|
14
|
+
const used = titles.map((title) => (title.startsWith('Worktree ') ? Number(title.slice(9)) : 0));
|
|
15
|
+
return `Worktree ${Math.max(0, ...used.filter(Number.isInteger)) + 1}`;
|
|
16
|
+
}
|
|
17
|
+
// Two checkouts fighting over :3001 and :8081 is half of CLAUDE.md's gotchas. Every worktree
|
|
18
|
+
// gets ten ports of its own, kept for its lifetime, well away from those defaults and from the
|
|
19
|
+
// owner's phone Metro on 8090.
|
|
20
|
+
const PORT_BASE = 4100;
|
|
21
|
+
const PORT_BLOCK = 10;
|
|
22
|
+
/** The lowest block of ports no other worktree on this computer holds. */
|
|
23
|
+
export function nextPortBlock(taken) {
|
|
24
|
+
const used = new Set(taken);
|
|
25
|
+
let port = PORT_BASE;
|
|
26
|
+
while (used.has(port))
|
|
27
|
+
port += PORT_BLOCK;
|
|
28
|
+
return port;
|
|
29
|
+
}
|
|
10
30
|
/** Workspace lifetime is independent of runs, provider sessions, PRs, and phone storage. */
|
|
11
31
|
export class WorkspaceRegistry {
|
|
12
32
|
store;
|
|
13
33
|
repos;
|
|
14
34
|
baseDir;
|
|
15
35
|
lanes = new LaneQueue();
|
|
36
|
+
setups = new Map();
|
|
16
37
|
constructor(store, repos, baseDir) {
|
|
17
38
|
this.store = store;
|
|
18
39
|
this.repos = repos;
|
|
@@ -26,13 +47,99 @@ export class WorkspaceRegistry {
|
|
|
26
47
|
}
|
|
27
48
|
public(worker) {
|
|
28
49
|
const { path: _, legacyMessages: __, sessionCheckout: ___, legacy: ____, ...row } = worker;
|
|
29
|
-
return { ...row, resume: this.store.latestSession(worker.conversationId) ?? row.resume
|
|
50
|
+
return { ...row, resume: this.store.latestSession(worker.conversationId) ?? row.resume,
|
|
51
|
+
...(this.setups.has(worker.workerId) ? { setup: 'running' } : {}) };
|
|
30
52
|
}
|
|
31
53
|
list(repoId) {
|
|
32
54
|
return this.store.list('workers')
|
|
33
55
|
.filter((w) => (!repoId || w.repoId === repoId) && this.repos().some((r) => r.id === w.repoId))
|
|
34
56
|
.map((w) => this.public(w));
|
|
35
57
|
}
|
|
58
|
+
/** How this repository's worktrees are prepared. Nothing is copied or run until the owner sets it. */
|
|
59
|
+
settings(repoId) {
|
|
60
|
+
return RepoSettingsSchema.parse(this.store.get('repo-settings', repoId) ?? {});
|
|
61
|
+
}
|
|
62
|
+
places(repoId) {
|
|
63
|
+
const root = this.repo(repoId).root;
|
|
64
|
+
return { root, worktrees: dirname(sessionWorktreePath(repoId, this.baseDir, 'x')),
|
|
65
|
+
copyMatches: matchedFiles(root, this.settings(repoId).copy) };
|
|
66
|
+
}
|
|
67
|
+
/** Run the archive command, then free the folder. Shared by the phone's Archive and archive-on-merge. */
|
|
68
|
+
async archive(worker) {
|
|
69
|
+
const { repoId, workerId } = worker;
|
|
70
|
+
if (worker.state === 'creating' || this.setups.has(workerId))
|
|
71
|
+
throw new Error('Wait for workspace setup to finish before archiving.');
|
|
72
|
+
if (this.store.unfinished(worker.conversationId))
|
|
73
|
+
throw new Error('Stop this worker and its queued messages before archiving it.');
|
|
74
|
+
// The session checkout is shared with the classic single session, so its folder stays.
|
|
75
|
+
if (!worker.sessionCheckout) {
|
|
76
|
+
const root = this.repo(repoId).root;
|
|
77
|
+
const settings = this.settings(repoId);
|
|
78
|
+
const path = sessionWorktreePath(repoId, this.baseDir, workerId);
|
|
79
|
+
if (settings.archiveScript && existsSync(path))
|
|
80
|
+
await runSetupScript(root, path, worker.title, settings.archiveScript, worker.port).catch((error) => {
|
|
81
|
+
const detail = String(error.stderr || error.message).trim().slice(-600);
|
|
82
|
+
throw new Error(`The archive command failed, so this worktree was kept. ${detail}`);
|
|
83
|
+
});
|
|
84
|
+
await archiveWorktree(root, { path, branch: worker.branch ?? sessionBranch(repoId, workerId), mode: 'worktree' }, workerId, { deleteBranch: settings.deleteBranchOnArchive });
|
|
85
|
+
}
|
|
86
|
+
this.save({ ...worker, state: 'archived' });
|
|
87
|
+
}
|
|
88
|
+
/** Remove an archived worktree for good: its local branch, its snapshot and its record. Answers
|
|
89
|
+
* with the work that would be lost, deleting nothing, unless there is none or `force` is set. */
|
|
90
|
+
delete(repoId, workerId, force) {
|
|
91
|
+
const root = this.repo(repoId).root;
|
|
92
|
+
// Queued behind create, so a restore that is already under way finishes first and is seen here.
|
|
93
|
+
return this.lanes.run(root, async () => {
|
|
94
|
+
const worker = this.store.get('workers', workerId);
|
|
95
|
+
// Already gone: another device may still list a worktree that was deleted from this one.
|
|
96
|
+
if (!worker)
|
|
97
|
+
return undefined;
|
|
98
|
+
if (worker.repoId !== repoId)
|
|
99
|
+
throw new Error('This worker is not registered in this repository.');
|
|
100
|
+
if (worker.state !== 'archived')
|
|
101
|
+
throw new Error('Archive this worktree before deleting it.');
|
|
102
|
+
// The session checkout's branch and folder belong to the classic single session, so they stay.
|
|
103
|
+
if (!worker.sessionCheckout) {
|
|
104
|
+
const branch = worker.branch ?? sessionBranch(repoId, workerId);
|
|
105
|
+
if (!force) {
|
|
106
|
+
const unmerged = await unmergedArchivedWork(root, workerId, branch, [worker.baseRef, this.settings(repoId).baseRef, this.repos().find((r) => r.id === repoId)?.baseRef]);
|
|
107
|
+
if (unmerged.commits || unmerged.uncommitted)
|
|
108
|
+
return unmerged;
|
|
109
|
+
}
|
|
110
|
+
await deleteArchivedWorktree(root, workerId, branch).catch((error) => {
|
|
111
|
+
const detail = String(error.stderr || error.message).trim().slice(-600);
|
|
112
|
+
throw new Error(`This worktree's branch could not be deleted, so it was kept. ${detail}`);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
// The conversation's runs stay: they are the receipts that stop a replayed request running twice.
|
|
116
|
+
this.store.transaction(() => {
|
|
117
|
+
this.store.delete('workers', workerId);
|
|
118
|
+
this.store.delete('workspaces', worker.conversationId);
|
|
119
|
+
});
|
|
120
|
+
return undefined;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/** Archive ready worktrees whose pull request has merged, in repositories that asked for it.
|
|
124
|
+
* A worktree with commits past the merged head, or a turn in flight, is left alone. */
|
|
125
|
+
async archiveMerged(mergedHead) {
|
|
126
|
+
const archived = [];
|
|
127
|
+
for (const worker of this.store.list('workers')) {
|
|
128
|
+
if (worker.state !== 'ready' || worker.sessionCheckout || !worker.path || !worker.branch)
|
|
129
|
+
continue;
|
|
130
|
+
try {
|
|
131
|
+
if (!this.settings(worker.repoId).archiveOnMerge || !existsSync(worker.path))
|
|
132
|
+
continue;
|
|
133
|
+
const merged = await mergedHead(this.repo(worker.repoId).root, worker.branch);
|
|
134
|
+
if (!merged || merged !== await headSha(worker.path))
|
|
135
|
+
continue;
|
|
136
|
+
await this.archive(worker);
|
|
137
|
+
archived.push(worker.workerId);
|
|
138
|
+
}
|
|
139
|
+
catch { /* busy, or the repository is gone: try again on the next sweep */ }
|
|
140
|
+
}
|
|
141
|
+
return archived;
|
|
142
|
+
}
|
|
36
143
|
save(worker) {
|
|
37
144
|
this.store.set('workers', worker.workerId, { ...worker, updatedAt: new Date().toISOString() });
|
|
38
145
|
}
|
|
@@ -64,7 +171,7 @@ export class WorkspaceRegistry {
|
|
|
64
171
|
return this.public(previous);
|
|
65
172
|
const now = new Date().toISOString();
|
|
66
173
|
const worker = previous ?? {
|
|
67
|
-
workerId, repoId, title: title ||
|
|
174
|
+
workerId, repoId, title: title || nextWorkerTitle(this.store.list('workers').filter((w) => w.repoId === repoId).map((w) => w.title)), brief,
|
|
68
175
|
workspaceId: workerId, conversationId: conversationKey({ kind: 'code', repoId, workerId }),
|
|
69
176
|
state: 'creating', createdAt: now, updatedAt: now,
|
|
70
177
|
};
|
|
@@ -73,18 +180,25 @@ export class WorkspaceRegistry {
|
|
|
73
180
|
const gitWorkerId = worker.sessionCheckout ? undefined : workerId;
|
|
74
181
|
const path = sessionWorktreePath(repoId, this.baseDir, gitWorkerId);
|
|
75
182
|
const branchExists = await workspaceBranchExists(repo.root, repoId, gitWorkerId);
|
|
76
|
-
|
|
183
|
+
// A branch deleted on archive is re-created from the commit its snapshot was taken on.
|
|
184
|
+
const archivedTip = gitWorkerId && !branchExists && !existsSync(path) ? await archivedHead(repo.root, workerId) : undefined;
|
|
185
|
+
if (worker.legacy && !existsSync(path) && !branchExists && !archivedTip)
|
|
77
186
|
throw new Error('The original worker branch and files are missing. Its conversation is preserved; create a new worker for new work.');
|
|
78
187
|
// A known legacy directory is adopted without fetching or resetting it.
|
|
79
|
-
const base = existsSync(path) || branchExists || previous?.baseSha
|
|
188
|
+
const base = existsSync(path) || branchExists || archivedTip || previous?.baseSha
|
|
80
189
|
? previous?.baseSha ? { ref: previous.baseRef, sha: previous.baseSha } : undefined
|
|
81
|
-
: await workspaceBase(repo.root, this.repos().find((r) => r.id === repoId)?.baseRef);
|
|
190
|
+
: await workspaceBase(repo.root, this.settings(repoId).baseRef || this.repos().find((r) => r.id === repoId)?.baseRef);
|
|
82
191
|
if (base)
|
|
83
192
|
this.save({ ...worker, state: 'creating', baseRef: base.ref, baseSha: base.sha });
|
|
84
|
-
const
|
|
193
|
+
const fresh = !existsSync(path);
|
|
194
|
+
const workspace = await ensureWorkspace(repo.root, repoId, { workerId: gitWorkerId, baseDir: this.baseDir, startPoint: archivedTip ?? base?.sha });
|
|
195
|
+
if (gitWorkerId)
|
|
196
|
+
await restoreArchivedFiles(repo.root, workspace, workerId);
|
|
85
197
|
const ready = { ...worker, state: 'ready', error: undefined, path: await realpath(workspace.path),
|
|
86
|
-
branch: workspace.branch, ...(base ? { baseRef: base.ref, baseSha: base.sha } : {}) };
|
|
198
|
+
port: this.portOf(worker), branch: workspace.branch, ...(base ? { baseRef: base.ref, baseSha: base.sha } : {}) };
|
|
87
199
|
this.save(ready);
|
|
200
|
+
if (fresh && gitWorkerId)
|
|
201
|
+
this.setUp(repo.root, ready);
|
|
88
202
|
return this.public(ready);
|
|
89
203
|
}
|
|
90
204
|
catch (error) {
|
|
@@ -94,11 +208,38 @@ export class WorkspaceRegistry {
|
|
|
94
208
|
}
|
|
95
209
|
});
|
|
96
210
|
}
|
|
211
|
+
/** A worktree's port block. Archived worktrees keep theirs so a restore comes back on the same ports. */
|
|
212
|
+
portOf(worker) {
|
|
213
|
+
return worker.port ?? nextPortBlock(this.store.list('workers').map((w) => w.port));
|
|
214
|
+
}
|
|
215
|
+
/** Fill in a worktree: the repository's listed files, then its setup command. This runs after the
|
|
216
|
+
* worktree is reported ready so the phone is not kept waiting; a turn waits for it in prepare().
|
|
217
|
+
* A failure is noted on the worker and never fails the worktree. */
|
|
218
|
+
setUp(repoRoot, worker) {
|
|
219
|
+
const settings = this.settings(worker.repoId);
|
|
220
|
+
if (!settings.copy.length && !settings.setup)
|
|
221
|
+
return;
|
|
222
|
+
this.save({ ...worker, setup: undefined, error: undefined });
|
|
223
|
+
const run = (async () => {
|
|
224
|
+
copyIncludedFiles(repoRoot, worker.path, settings.copy);
|
|
225
|
+
if (settings.setup)
|
|
226
|
+
await runSetupScript(repoRoot, worker.path, worker.title, settings.setup, worker.port);
|
|
227
|
+
})().catch((error) => {
|
|
228
|
+
const detail = String(error.stderr || error.message).trim().slice(-600);
|
|
229
|
+
console.error(`[workspaces] setup failed for ${worker.workerId}: ${detail}`);
|
|
230
|
+
const current = this.store.get('workers', worker.workerId);
|
|
231
|
+
if (current?.state === 'ready')
|
|
232
|
+
this.save({ ...current, setup: 'failed', error: detail });
|
|
233
|
+
}).finally(() => this.setups.delete(worker.workerId));
|
|
234
|
+
this.setups.set(worker.workerId, run);
|
|
235
|
+
}
|
|
97
236
|
async prepare(request) {
|
|
237
|
+
this.checkRecoveryWorkspace(request);
|
|
98
238
|
const repo = this.repo(request.repoId);
|
|
99
239
|
let gitWorkerId = request.workerId;
|
|
100
240
|
if (request.workerId) {
|
|
101
241
|
await this.create(request.repoId, request.workerId, undefined, request.prompt);
|
|
242
|
+
await this.setups.get(request.workerId);
|
|
102
243
|
const worker = this.store.get('workers', request.workerId);
|
|
103
244
|
if (worker.sessionCheckout)
|
|
104
245
|
gitWorkerId = undefined;
|
|
@@ -111,7 +252,14 @@ export class WorkspaceRegistry {
|
|
|
111
252
|
mode: request.workerId ? 'worktree' : request.mode, workerId: gitWorkerId, baseDir: this.baseDir,
|
|
112
253
|
});
|
|
113
254
|
this.store.set('workspaces', conversationKey({ ...request, kind: 'code' }), { ...workspace, repoId: request.repoId });
|
|
114
|
-
|
|
255
|
+
const worker = request.workerId ? this.store.get('workers', request.workerId) : undefined;
|
|
256
|
+
if (!worker || worker.sessionCheckout)
|
|
257
|
+
return workspace;
|
|
258
|
+
// Worktrees made before ports existed get their block on their next turn.
|
|
259
|
+
const port = this.portOf(worker);
|
|
260
|
+
if (worker.port !== port)
|
|
261
|
+
this.save({ ...worker, port });
|
|
262
|
+
return { ...workspace, env: { LUCIDITY_PORT: String(port), LUCIDITY_WORKTREE_NAME: worker.title } };
|
|
115
263
|
}
|
|
116
264
|
checkout(command, commandId) {
|
|
117
265
|
if (!command.repoId || command.workerId)
|
|
@@ -169,6 +317,15 @@ export class WorkspaceRegistry {
|
|
|
169
317
|
frames: state.frames, terminated: state.terminated }));
|
|
170
318
|
}
|
|
171
319
|
async command(command, commandId) {
|
|
320
|
+
if (command.action === 'inspect-run' || command.action === 'continue-run') {
|
|
321
|
+
if (!command.repoId)
|
|
322
|
+
throw new Error('Select a repository.');
|
|
323
|
+
const repo = this.repo(command.repoId);
|
|
324
|
+
const path = command.checkout ? repo.root : command.workerId ? this.store.get('workers', command.workerId)?.path : undefined;
|
|
325
|
+
if (command.action === 'continue-run')
|
|
326
|
+
return { workers: this.list(command.repoId), review: this.store.get('run-reviews', command.requestId) };
|
|
327
|
+
return { workers: this.list(command.repoId), review: await inspectRun(this.store, command, path) };
|
|
328
|
+
}
|
|
172
329
|
if (command.checkout)
|
|
173
330
|
return this.checkout(command, commandId);
|
|
174
331
|
if (command.action === 'clear-history')
|
|
@@ -177,6 +334,14 @@ export class WorkspaceRegistry {
|
|
|
177
334
|
let workerId = command.workerId;
|
|
178
335
|
if (action === 'list')
|
|
179
336
|
return { workers: this.list(repoId) };
|
|
337
|
+
if (action === 'settings' || action === 'save-settings') {
|
|
338
|
+
if (!repoId)
|
|
339
|
+
throw new Error('Select a repository.');
|
|
340
|
+
this.repo(repoId);
|
|
341
|
+
if (action === 'save-settings')
|
|
342
|
+
this.store.set('repo-settings', repoId, RepoSettingsSchema.parse(command.settings ?? {}));
|
|
343
|
+
return { workers: this.list(repoId), settings: this.settings(repoId), places: this.places(repoId) };
|
|
344
|
+
}
|
|
180
345
|
if (action === 'import' && repoId && command.legacy?.sessionCheckout) {
|
|
181
346
|
const key = createHash('sha256').update(this.repo(repoId).root).digest('hex');
|
|
182
347
|
workerId = `${key.slice(0, 8)}-${key.slice(8, 12)}-7${key.slice(13, 16)}-8${key.slice(17, 20)}-${key.slice(20, 32)}`;
|
|
@@ -200,6 +365,10 @@ export class WorkspaceRegistry {
|
|
|
200
365
|
await this.create(repoId, workerId).catch(() => { });
|
|
201
366
|
}
|
|
202
367
|
}
|
|
368
|
+
else if (action === 'delete') {
|
|
369
|
+
const unmerged = await this.delete(repoId, workerId, command.force);
|
|
370
|
+
return { workers: this.list(repoId), ...(unmerged ? { unmerged } : {}) };
|
|
371
|
+
}
|
|
203
372
|
else {
|
|
204
373
|
const worker = this.store.get('workers', workerId);
|
|
205
374
|
if (!worker || worker.repoId !== repoId)
|
|
@@ -214,11 +383,13 @@ export class WorkspaceRegistry {
|
|
|
214
383
|
...(page.length === 10 ? { nextBefore: page[0].request.id } : {}) };
|
|
215
384
|
}
|
|
216
385
|
if (action === 'archive') {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
386
|
+
await this.archive(worker);
|
|
387
|
+
}
|
|
388
|
+
else if (action === 'setup') {
|
|
389
|
+
if (worker.state !== 'ready' || worker.sessionCheckout || !worker.path)
|
|
390
|
+
throw new Error('This worktree is not ready for setup.');
|
|
391
|
+
if (!this.setups.has(workerId))
|
|
392
|
+
this.setUp(this.repo(repoId).root, worker);
|
|
222
393
|
}
|
|
223
394
|
else if (action === 'restore') {
|
|
224
395
|
this.save({ ...worker, state: 'creating' });
|
|
@@ -227,4 +398,24 @@ export class WorkspaceRegistry {
|
|
|
227
398
|
}
|
|
228
399
|
return { workers: this.list(repoId) };
|
|
229
400
|
}
|
|
401
|
+
continuation(command) {
|
|
402
|
+
if (!command.repoId)
|
|
403
|
+
throw new Error('Select a repository.');
|
|
404
|
+
this.repo(command.repoId);
|
|
405
|
+
if (command.workerId && this.store.get('workers', command.workerId)?.state !== 'ready')
|
|
406
|
+
throw new Error('Restore this worker before continuing.');
|
|
407
|
+
const request = continuationRequest(this.store, command);
|
|
408
|
+
this.checkRecoveryWorkspace(request);
|
|
409
|
+
return request;
|
|
410
|
+
}
|
|
411
|
+
checkRecoveryWorkspace(request) {
|
|
412
|
+
if (!request.recoveryOf)
|
|
413
|
+
return;
|
|
414
|
+
const review = this.store.get('run-reviews', request.recoveryOf);
|
|
415
|
+
const worker = request.workerId ? this.store.get('workers', request.workerId) : undefined;
|
|
416
|
+
const path = !request.workerId && request.mode === 'in-place' ? this.repo(request.repoId).root :
|
|
417
|
+
sessionWorktreePath(request.repoId, this.baseDir, worker?.sessionCheckout ? undefined : request.workerId);
|
|
418
|
+
if (!review?.workspace || !existsSync(review.workspace) || !existsSync(path) || realpathSync(path) !== realpathSync(review.workspace))
|
|
419
|
+
throw new Error('The configured workspace changed since this turn. Restore the reviewed workspace before continuing.');
|
|
420
|
+
}
|
|
230
421
|
}
|
|
@@ -8,24 +8,20 @@ export interface Workspace {
|
|
|
8
8
|
/** The branch commits land on. `HEAD` when the in-place checkout is detached. */
|
|
9
9
|
branch: string;
|
|
10
10
|
mode: WorkspaceMode;
|
|
11
|
+
/** Variables the turn's agent runs with, such as the worktree's port block. */
|
|
12
|
+
env?: Record<string, string>;
|
|
11
13
|
}
|
|
12
|
-
/** The stable branch name for a coding session.
|
|
13
|
-
* a
|
|
14
|
-
* subtask's id), so N workers on one repo hold N isolated branches.
|
|
14
|
+
/** The stable branch name for a coding session. The repository's main session is
|
|
15
|
+
* `lucid/<repo>`; a worktree gets `wt/<repo>/<workerId>`.
|
|
15
16
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* exclusive (the D/F conflict). Keeping workers under `fleet/` leaves the bare
|
|
20
|
-
* `lucid/<repo>` — the classic single session AND the fleet's integration target,
|
|
21
|
-
* the one branch a fleet PR opens from — untouched. `workerId` absent → the classic
|
|
22
|
-
* branch, byte-for-byte as before. */
|
|
17
|
+
* Worktrees live under their own `wt/` namespace instead of `lucid/<repo>/…` because a git
|
|
18
|
+
* ref can't be both a leaf and a directory, so `lucid/<repo>` and `lucid/<repo>/<workerId>`
|
|
19
|
+
* cannot both exist. */
|
|
23
20
|
export declare function sessionBranch(repoId: string, workerId?: string): string;
|
|
24
|
-
/** The stable
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* default root (tests point it at a temp dir); `workerId` absent → the classic path. */
|
|
21
|
+
/** The stable folder for a coding session (constant across turns, so `--resume` resolves).
|
|
22
|
+
* The main session lives at `<base>/<repo>`; a worktree at `<base>/wt/<repo>/<workerId>`, a
|
|
23
|
+
* sibling of it and never nested inside it (which would put a checkout within a checkout).
|
|
24
|
+
* `baseDir` overrides the default root (tests point it at a temp dir). */
|
|
29
25
|
export declare function sessionWorktreePath(repoId: string, baseDir?: string, workerId?: string): string;
|
|
30
26
|
/** The branch checked out in `repoRoot`, or `HEAD` when detached. */
|
|
31
27
|
export declare function currentBranch(repoRoot: string): Promise<string>;
|
|
@@ -75,9 +71,7 @@ export declare function ensureWorkspace(repoRoot: string, repoId: string, opts?:
|
|
|
75
71
|
fresh?: boolean;
|
|
76
72
|
startPoint?: string;
|
|
77
73
|
baseDir?: string;
|
|
78
|
-
/**
|
|
79
|
-
* worktree/branch so N workers run in parallel on one repo. Absent → the classic
|
|
80
|
-
* single session, unchanged. */
|
|
74
|
+
/** Present → that worktree's own folder and branch. Absent → the main session. */
|
|
81
75
|
workerId?: string;
|
|
82
76
|
}): Promise<Workspace>;
|
|
83
77
|
/**
|
|
@@ -141,6 +135,55 @@ export declare function commitWorkspace(ws: Workspace, message: string, paths: s
|
|
|
141
135
|
export declare function removeWorktree(repoRoot: string, ws: Workspace, opts?: {
|
|
142
136
|
keepBranch?: boolean;
|
|
143
137
|
}): Promise<void>;
|
|
138
|
+
/** Where an archived worker's files are parked. Under `refs/lucid/`, so no branch or push sees it. */
|
|
139
|
+
export declare function archivedWorktreeRef(workerId: string): string;
|
|
140
|
+
/**
|
|
141
|
+
* Free an archived worker's folder. Its full working state (tracked, staged and untracked,
|
|
142
|
+
* gitignored files excluded) is parked first as a commit on top of the worktree's HEAD, so
|
|
143
|
+
* uncommitted work survives. The branch stays. Throws before removing anything if the
|
|
144
|
+
* snapshot cannot be written.
|
|
145
|
+
*/
|
|
146
|
+
export declare function archiveWorktree(repoRoot: string, ws: Workspace, workerId: string, opts?: {
|
|
147
|
+
deleteBranch?: boolean;
|
|
148
|
+
}): Promise<void>;
|
|
149
|
+
/** The commit an archived worker's branch pointed at, for re-creating a branch deleted on archive. */
|
|
150
|
+
export declare function archivedHead(repoRoot: string, workerId: string): Promise<string | undefined>;
|
|
151
|
+
/**
|
|
152
|
+
* What deleting an archived worker would lose: commits on its branch (or, when the branch was
|
|
153
|
+
* deleted on archive, on the commit its snapshot was taken from) that are in none of `baseRefs`,
|
|
154
|
+
* the remote default branch or the branch's own remote copy, plus whether the snapshot holds
|
|
155
|
+
* files that were never committed.
|
|
156
|
+
*
|
|
157
|
+
* A commit whose change is already in the base under another sha does not count, so a branch
|
|
158
|
+
* that was rebase-merged reads as merged. A squash merge cannot be recognised this way and
|
|
159
|
+
* still counts. Remote refs are refreshed first when anything looks unmerged, since a pull
|
|
160
|
+
* request merged on GitHub is only visible after a fetch; offline, the last fetched state is used.
|
|
161
|
+
*/
|
|
162
|
+
export declare function unmergedArchivedWork(repoRoot: string, workerId: string, branch: string, baseRefs?: (string | undefined)[]): Promise<{
|
|
163
|
+
commits: number;
|
|
164
|
+
uncommitted: boolean;
|
|
165
|
+
}>;
|
|
166
|
+
/** Remove what an archived worker left in the repository: its local branch, if it still has one,
|
|
167
|
+
* and its snapshot. The remote branch is not touched. */
|
|
168
|
+
export declare function deleteArchivedWorktree(repoRoot: string, workerId: string, branch: string): Promise<void>;
|
|
169
|
+
/** Per-file added and removed line counts for everything in a folder that differs from `base`,
|
|
170
|
+
* committed or not. Tracked files only; a binary file counts as zero lines. */
|
|
171
|
+
export declare function numstatSince(path: string, base: string): Promise<Map<string, [added: number, removed: number]>>;
|
|
172
|
+
/** What changed between two readings of {@link numstatSince} taken against the same base: the
|
|
173
|
+
* turn's own work, with whatever was already uncommitted when it started taken out. */
|
|
174
|
+
export declare function turnChangeCounts(before: Map<string, [number, number]>, after: Map<string, [number, number]>): {
|
|
175
|
+
added: number;
|
|
176
|
+
removed: number;
|
|
177
|
+
files: string[];
|
|
178
|
+
} | undefined;
|
|
179
|
+
/** The commit checked out in a folder. */
|
|
180
|
+
export declare function headSha(path: string): Promise<string>;
|
|
181
|
+
/**
|
|
182
|
+
* Put an archived worker's uncommitted files back into its re-created worktree. They return
|
|
183
|
+
* unstaged. If the branch moved while the worker was archived the snapshot no longer fits, so
|
|
184
|
+
* it is left under its ref for a manual `git restore --source` and nothing is overwritten.
|
|
185
|
+
*/
|
|
186
|
+
export declare function restoreArchivedFiles(repoRoot: string, ws: Workspace, workerId: string): Promise<void>;
|
|
144
187
|
/** A review can inspect tracked changes without staging or reading unrelated untracked files. */
|
|
145
188
|
export declare function reviewDiff(ws: Workspace): Promise<string>;
|
|
146
189
|
//# sourceMappingURL=worktree.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worktree.d.ts","sourceRoot":"","sources":["../../src/coding/worktree.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAStD;;kEAEkE;AAClE,MAAM,WAAW,SAAS;IACxB,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,iFAAiF;IACjF,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"worktree.d.ts","sourceRoot":"","sources":["../../src/coding/worktree.ts"],"names":[],"mappings":"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"}
|
package/dist/coding/worktree.js
CHANGED
|
@@ -16,30 +16,24 @@ async function git(cwd, args, env) {
|
|
|
16
16
|
function slug(repoId) {
|
|
17
17
|
return repoId.replace(/[^A-Za-z0-9._-]/g, '-');
|
|
18
18
|
}
|
|
19
|
-
/** The stable branch name for a coding session.
|
|
20
|
-
* a
|
|
21
|
-
* subtask's id), so N workers on one repo hold N isolated branches.
|
|
19
|
+
/** The stable branch name for a coding session. The repository's main session is
|
|
20
|
+
* `lucid/<repo>`; a worktree gets `wt/<repo>/<workerId>`.
|
|
22
21
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* exclusive (the D/F conflict). Keeping workers under `fleet/` leaves the bare
|
|
27
|
-
* `lucid/<repo>` — the classic single session AND the fleet's integration target,
|
|
28
|
-
* the one branch a fleet PR opens from — untouched. `workerId` absent → the classic
|
|
29
|
-
* branch, byte-for-byte as before. */
|
|
22
|
+
* Worktrees live under their own `wt/` namespace instead of `lucid/<repo>/…` because a git
|
|
23
|
+
* ref can't be both a leaf and a directory, so `lucid/<repo>` and `lucid/<repo>/<workerId>`
|
|
24
|
+
* cannot both exist. */
|
|
30
25
|
export function sessionBranch(repoId, workerId) {
|
|
31
26
|
return workerId
|
|
32
|
-
? `
|
|
27
|
+
? `wt/${slug(repoId)}/${slug(workerId)}`
|
|
33
28
|
: `lucid/${slug(repoId)}`;
|
|
34
29
|
}
|
|
35
|
-
/** The stable
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* default root (tests point it at a temp dir); `workerId` absent → the classic path. */
|
|
30
|
+
/** The stable folder for a coding session (constant across turns, so `--resume` resolves).
|
|
31
|
+
* The main session lives at `<base>/<repo>`; a worktree at `<base>/wt/<repo>/<workerId>`, a
|
|
32
|
+
* sibling of it and never nested inside it (which would put a checkout within a checkout).
|
|
33
|
+
* `baseDir` overrides the default root (tests point it at a temp dir). */
|
|
40
34
|
export function sessionWorktreePath(repoId, baseDir = WORKTREE_BASE, workerId) {
|
|
41
35
|
return workerId
|
|
42
|
-
? join(baseDir, '
|
|
36
|
+
? join(baseDir, 'wt', slug(repoId), slug(workerId))
|
|
43
37
|
: join(baseDir, slug(repoId));
|
|
44
38
|
}
|
|
45
39
|
/** The branch checked out in `repoRoot`, or `HEAD` when detached. */
|
|
@@ -276,6 +270,144 @@ export async function removeWorktree(repoRoot, ws, opts = {}) {
|
|
|
276
270
|
}
|
|
277
271
|
}
|
|
278
272
|
}
|
|
273
|
+
/** Where an archived worker's files are parked. Under `refs/lucid/`, so no branch or push sees it. */
|
|
274
|
+
export function archivedWorktreeRef(workerId) {
|
|
275
|
+
return `refs/lucid/archived/${slug(workerId)}`;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Free an archived worker's folder. Its full working state (tracked, staged and untracked,
|
|
279
|
+
* gitignored files excluded) is parked first as a commit on top of the worktree's HEAD, so
|
|
280
|
+
* uncommitted work survives. The branch stays. Throws before removing anything if the
|
|
281
|
+
* snapshot cannot be written.
|
|
282
|
+
*/
|
|
283
|
+
export async function archiveWorktree(repoRoot, ws, workerId, opts = {}) {
|
|
284
|
+
if (ws.mode === 'in-place' || resolve(ws.path) === resolve(repoRoot)) {
|
|
285
|
+
throw new Error(`refusing to remove the repo checkout itself: ${ws.path}`);
|
|
286
|
+
}
|
|
287
|
+
if (!existsSync(ws.path))
|
|
288
|
+
return;
|
|
289
|
+
const tree = await snapshotTree(ws);
|
|
290
|
+
const head = (await git(ws.path, ['rev-parse', 'HEAD'])).trim();
|
|
291
|
+
const sha = (await git(ws.path, ['commit-tree', tree, '-p', head, '-m', 'Archived worktree'])).trim();
|
|
292
|
+
await git(repoRoot, ['update-ref', archivedWorktreeRef(workerId), sha]);
|
|
293
|
+
await git(repoRoot, ['worktree', 'remove', '--force', ws.path]);
|
|
294
|
+
// The snapshot's parent is the branch tip, so the branch can be re-created from it on restore.
|
|
295
|
+
if (opts.deleteBranch)
|
|
296
|
+
await git(repoRoot, ['branch', '-D', ws.branch]).catch(() => { });
|
|
297
|
+
}
|
|
298
|
+
/** The commit an archived worker's branch pointed at, for re-creating a branch deleted on archive. */
|
|
299
|
+
export async function archivedHead(repoRoot, workerId) {
|
|
300
|
+
return git(repoRoot, ['rev-parse', '--verify', '--quiet', `${archivedWorktreeRef(workerId)}^`]).then((s) => s.trim() || undefined, () => undefined);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* What deleting an archived worker would lose: commits on its branch (or, when the branch was
|
|
304
|
+
* deleted on archive, on the commit its snapshot was taken from) that are in none of `baseRefs`,
|
|
305
|
+
* the remote default branch or the branch's own remote copy, plus whether the snapshot holds
|
|
306
|
+
* files that were never committed.
|
|
307
|
+
*
|
|
308
|
+
* A commit whose change is already in the base under another sha does not count, so a branch
|
|
309
|
+
* that was rebase-merged reads as merged. A squash merge cannot be recognised this way and
|
|
310
|
+
* still counts. Remote refs are refreshed first when anything looks unmerged, since a pull
|
|
311
|
+
* request merged on GitHub is only visible after a fetch; offline, the last fetched state is used.
|
|
312
|
+
*/
|
|
313
|
+
export async function unmergedArchivedWork(repoRoot, workerId, branch, baseRefs = []) {
|
|
314
|
+
const sha = (ref) => git(repoRoot, ['rev-parse', '--verify', '--quiet', '--end-of-options', `${ref}^{commit}`]).then((s) => s.trim() || undefined, () => undefined);
|
|
315
|
+
const present = async (refs) => [...new Set((await Promise.all(refs.map((ref) => (ref ? sha(ref) : undefined)))).filter((s) => !!s))];
|
|
316
|
+
const snapshot = archivedWorktreeRef(workerId);
|
|
317
|
+
const trees = await git(repoRoot, ['rev-parse', '--verify', '--quiet', `${snapshot}^{tree}`])
|
|
318
|
+
.then(async (tree) => [tree.trim(), (await git(repoRoot, ['rev-parse', '--verify', '--quiet', `${snapshot}^^{tree}`])).trim()], () => []);
|
|
319
|
+
const uncommitted = trees.length === 2 && trees[0] !== trees[1];
|
|
320
|
+
const tips = await present([`refs/heads/${branch}`, `${snapshot}^`]);
|
|
321
|
+
if (!tips.length)
|
|
322
|
+
return { commits: 0, uncommitted };
|
|
323
|
+
const kept = async () => {
|
|
324
|
+
const remoteDefault = await git(repoRoot, ['symbolic-ref', '--quiet', '--short', 'refs/remotes/origin/HEAD']).then((s) => s.trim(), () => '');
|
|
325
|
+
const refs = await present([
|
|
326
|
+
...baseRefs.flatMap((ref) => (!ref || ref === 'HEAD' || ref.startsWith('origin/') ? [ref] : [`origin/${ref}`, ref])),
|
|
327
|
+
remoteDefault, remoteDefault && `refs/heads/${remoteDefault.replace(/^origin\//, '')}`,
|
|
328
|
+
`refs/remotes/origin/${branch}`, `${branch}@{upstream}`,
|
|
329
|
+
]);
|
|
330
|
+
// A repository with no remote and no configured base has only its own checkout to compare against.
|
|
331
|
+
return refs.length ? refs : present(['HEAD']);
|
|
332
|
+
};
|
|
333
|
+
const ahead = async (bases) => (await git(repoRoot, ['rev-list', '--no-merges', ...tips, '--not', ...bases])).split('\n').filter(Boolean);
|
|
334
|
+
let bases = await kept();
|
|
335
|
+
let commits = await ahead(bases);
|
|
336
|
+
if (commits.length) {
|
|
337
|
+
await exec('git', ['fetch', 'origin'], { cwd: repoRoot, timeout: 20_000 }).catch(() => { });
|
|
338
|
+
bases = await kept();
|
|
339
|
+
commits = await ahead(bases);
|
|
340
|
+
}
|
|
341
|
+
if (commits.length && bases[0]) {
|
|
342
|
+
const applied = new Set(commits);
|
|
343
|
+
for (const tip of tips) {
|
|
344
|
+
const fresh = await git(repoRoot, ['rev-list', '--no-merges', '--cherry-pick', '--right-only', `${bases[0]}...${tip}`]);
|
|
345
|
+
for (const commit of fresh.split('\n'))
|
|
346
|
+
applied.delete(commit);
|
|
347
|
+
}
|
|
348
|
+
commits = commits.filter((commit) => !applied.has(commit));
|
|
349
|
+
}
|
|
350
|
+
return { commits: commits.length, uncommitted };
|
|
351
|
+
}
|
|
352
|
+
/** Remove what an archived worker left in the repository: its local branch, if it still has one,
|
|
353
|
+
* and its snapshot. The remote branch is not touched. */
|
|
354
|
+
export async function deleteArchivedWorktree(repoRoot, workerId, branch) {
|
|
355
|
+
// A folder removed by hand still holds its branch until its worktree entry is pruned.
|
|
356
|
+
await git(repoRoot, ['worktree', 'prune']).catch(() => { });
|
|
357
|
+
const exists = await git(repoRoot, ['show-ref', '--verify', `refs/heads/${branch}`]).then(() => true, () => false);
|
|
358
|
+
if (exists)
|
|
359
|
+
await git(repoRoot, ['branch', '-D', '--end-of-options', branch]);
|
|
360
|
+
await git(repoRoot, ['update-ref', '-d', archivedWorktreeRef(workerId)]);
|
|
361
|
+
}
|
|
362
|
+
/** Per-file added and removed line counts for everything in a folder that differs from `base`,
|
|
363
|
+
* committed or not. Tracked files only; a binary file counts as zero lines. */
|
|
364
|
+
export async function numstatSince(path, base) {
|
|
365
|
+
const out = await git(path, ['diff', '--numstat', '-z', base]);
|
|
366
|
+
const stats = new Map();
|
|
367
|
+
for (const row of out.split('\0')) {
|
|
368
|
+
const [added, removed, file] = row.split('\t');
|
|
369
|
+
if (file)
|
|
370
|
+
stats.set(file, [Number(added) || 0, Number(removed) || 0]);
|
|
371
|
+
}
|
|
372
|
+
return stats;
|
|
373
|
+
}
|
|
374
|
+
/** What changed between two readings of {@link numstatSince} taken against the same base: the
|
|
375
|
+
* turn's own work, with whatever was already uncommitted when it started taken out. */
|
|
376
|
+
export function turnChangeCounts(before, after) {
|
|
377
|
+
let added = 0;
|
|
378
|
+
let removed = 0;
|
|
379
|
+
const files = [];
|
|
380
|
+
for (const file of new Set([...before.keys(), ...after.keys()])) {
|
|
381
|
+
const [a0, r0] = before.get(file) ?? [0, 0];
|
|
382
|
+
const [a1, r1] = after.get(file) ?? [0, 0];
|
|
383
|
+
if (a0 === a1 && r0 === r1)
|
|
384
|
+
continue;
|
|
385
|
+
added += Math.max(0, a1 - a0);
|
|
386
|
+
removed += Math.max(0, r1 - r0);
|
|
387
|
+
if (files.length < 40)
|
|
388
|
+
files.push(file);
|
|
389
|
+
}
|
|
390
|
+
return files.length ? { added, removed, files } : undefined;
|
|
391
|
+
}
|
|
392
|
+
/** The commit checked out in a folder. */
|
|
393
|
+
export async function headSha(path) {
|
|
394
|
+
return (await git(path, ['rev-parse', 'HEAD'])).trim();
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Put an archived worker's uncommitted files back into its re-created worktree. They return
|
|
398
|
+
* unstaged. If the branch moved while the worker was archived the snapshot no longer fits, so
|
|
399
|
+
* it is left under its ref for a manual `git restore --source` and nothing is overwritten.
|
|
400
|
+
*/
|
|
401
|
+
export async function restoreArchivedFiles(repoRoot, ws, workerId) {
|
|
402
|
+
const ref = archivedWorktreeRef(workerId);
|
|
403
|
+
const parent = await git(repoRoot, ['rev-parse', '--verify', '--quiet', `${ref}^`]).then((s) => s.trim(), () => '');
|
|
404
|
+
if (!parent)
|
|
405
|
+
return;
|
|
406
|
+
if (parent !== (await git(ws.path, ['rev-parse', 'HEAD'])).trim())
|
|
407
|
+
return;
|
|
408
|
+
await git(ws.path, ['restore', `--source=${ref}`, '--worktree', '--', '.']);
|
|
409
|
+
await git(repoRoot, ['update-ref', '-d', ref]);
|
|
410
|
+
}
|
|
279
411
|
/** A review can inspect tracked changes without staging or reading unrelated untracked files. */
|
|
280
412
|
export async function reviewDiff(ws) {
|
|
281
413
|
const diff = await git(ws.path, ['diff', '--no-ext-diff', '--no-textconv', 'HEAD', '--']);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The files the copy list matches in the repository right now. */
|
|
2
|
+
export declare function matchedFiles(repoRoot: string, include: string[]): string[];
|
|
3
|
+
/** Copy the repository's listed files into the worktree. A file already there is never overwritten. */
|
|
4
|
+
export declare function copyIncludedFiles(repoRoot: string, worktree: string, include: string[]): string[];
|
|
5
|
+
/** Run one of the repository's commands (setup or archive) in the worktree. */
|
|
6
|
+
export declare function runSetupScript(repoRoot: string, worktree: string, name: string, setup: string, port?: number): Promise<void>;
|
|
7
|
+
//# sourceMappingURL=worktreeSetup.d.ts.map
|