@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
package/src/room/turnQueue.ts
CHANGED
|
@@ -2,8 +2,6 @@ import {
|
|
|
2
2
|
mkdirSync,
|
|
3
3
|
readFileSync,
|
|
4
4
|
readdirSync,
|
|
5
|
-
renameSync,
|
|
6
|
-
writeFileSync,
|
|
7
5
|
statSync,
|
|
8
6
|
unlinkSync,
|
|
9
7
|
} from 'node:fs';
|
|
@@ -15,9 +13,11 @@ import { LaneQueue } from '../queue.js';
|
|
|
15
13
|
type Request = Extract<HarnessRequest, { kind: 'ask' | 'code' }>;
|
|
16
14
|
type Entry = {
|
|
17
15
|
request: Request;
|
|
18
|
-
state: 'queued' | 'running' | 'steering' | 'done' | 'failed' | 'skipped';
|
|
16
|
+
state: 'queued' | 'held' | 'running' | 'steering' | 'done' | 'failed' | 'skipped';
|
|
17
|
+
blockedBy?: string;
|
|
19
18
|
action?: 'cancel' | 'steer';
|
|
20
19
|
resume?: string;
|
|
20
|
+
failure?: { message: string; code?: string };
|
|
21
21
|
};
|
|
22
22
|
export function turnLane(req: Request): string {
|
|
23
23
|
return req.kind === 'ask'
|
|
@@ -43,6 +43,8 @@ export class DurableTurnQueue {
|
|
|
43
43
|
},
|
|
44
44
|
) {
|
|
45
45
|
mkdirSync(deps.dir, { recursive: true, mode: 0o700 });
|
|
46
|
+
for (const entry of deps.logs.runtime.list<Entry>('queue'))
|
|
47
|
+
this.entries.set(entry.request.id, entry);
|
|
46
48
|
for (const name of readdirSync(deps.dir)
|
|
47
49
|
.filter((name) => name.endsWith('.json'))
|
|
48
50
|
.sort()) {
|
|
@@ -56,6 +58,11 @@ export class DurableTurnQueue {
|
|
|
56
58
|
unlinkSync(join(deps.dir, name));
|
|
57
59
|
continue;
|
|
58
60
|
}
|
|
61
|
+
if (this.entries.has(entry.request.id)) continue;
|
|
62
|
+
this.deps.logs.runtime.set('queue', entry.request.id, entry);
|
|
63
|
+
this.entries.set(entry.request.id, entry);
|
|
64
|
+
}
|
|
65
|
+
for (const entry of this.entries.values()) {
|
|
59
66
|
const parsed = HarnessRequestSchema.parse(entry.request);
|
|
60
67
|
if (parsed.kind !== 'ask' && parsed.kind !== 'code')
|
|
61
68
|
throw new Error('Invalid queued turn');
|
|
@@ -72,7 +79,8 @@ export class DurableTurnQueue {
|
|
|
72
79
|
} else {
|
|
73
80
|
this.fail(
|
|
74
81
|
entry,
|
|
75
|
-
'Lucid restarted during this turn. It was not run again. Review
|
|
82
|
+
'Lucid restarted during this turn. It was not run again. Review its work before continuing.',
|
|
83
|
+
'interrupted_unknown',
|
|
76
84
|
);
|
|
77
85
|
}
|
|
78
86
|
} else if (entry.state === 'skipped' && !terminal) {
|
|
@@ -83,8 +91,8 @@ export class DurableTurnQueue {
|
|
|
83
91
|
} else if (entry.state === 'failed' && !terminal) {
|
|
84
92
|
this.publish(parsed.id, {
|
|
85
93
|
type: 'error',
|
|
86
|
-
message:
|
|
87
|
-
'This queued turn could not finish. Review it before resending.',
|
|
94
|
+
...(entry.failure ?? { message:
|
|
95
|
+
'This queued turn could not finish. Review it before resending.' }),
|
|
88
96
|
});
|
|
89
97
|
}
|
|
90
98
|
}
|
|
@@ -104,12 +112,7 @@ export class DurableTurnQueue {
|
|
|
104
112
|
}
|
|
105
113
|
|
|
106
114
|
private save(entry: Entry): void {
|
|
107
|
-
|
|
108
|
-
writeFileSync(`${path}.tmp`, JSON.stringify(entry), {
|
|
109
|
-
mode: 0o600,
|
|
110
|
-
flush: true,
|
|
111
|
-
});
|
|
112
|
-
renameSync(`${path}.tmp`, path);
|
|
115
|
+
this.deps.logs.runtime.set('queue', entry.request.id, entry);
|
|
113
116
|
this.entries.set(entry.request.id, entry);
|
|
114
117
|
}
|
|
115
118
|
private publish(id: string, event: Record<string, unknown>): void {
|
|
@@ -137,15 +140,16 @@ export class DurableTurnQueue {
|
|
|
137
140
|
.find((frame) => typeof frame.sessionId === 'string')?.sessionId;
|
|
138
141
|
return typeof value === 'string' ? value : undefined;
|
|
139
142
|
}
|
|
140
|
-
private fail(entry: Entry, message: string): void {
|
|
141
|
-
|
|
143
|
+
private fail(entry: Entry, message: string, code?: string): void {
|
|
144
|
+
const failure = { message, ...(code ? { code } : {}) };
|
|
145
|
+
this.save({ ...entry, state: 'failed', failure });
|
|
142
146
|
if (!this.deps.logs.read(entry.request.id).terminated)
|
|
143
|
-
this.publish(entry.request.id, { type: 'error',
|
|
147
|
+
this.publish(entry.request.id, { type: 'error', ...failure });
|
|
144
148
|
this.wake();
|
|
145
149
|
}
|
|
146
150
|
owns(id: string): boolean {
|
|
147
151
|
const state = this.entries.get(id)?.state;
|
|
148
|
-
return state === 'queued' || state === 'running' || state === 'steering';
|
|
152
|
+
return state === 'queued' || state === 'held' || state === 'running' || state === 'steering';
|
|
149
153
|
}
|
|
150
154
|
confirm(id: string): void {
|
|
151
155
|
const entry = this.entries.get(id);
|
|
@@ -153,6 +157,7 @@ export class DurableTurnQueue {
|
|
|
153
157
|
this.publish(id, {
|
|
154
158
|
type: 'queue_state',
|
|
155
159
|
state: entry.state === 'running' ? 'running' : 'queued',
|
|
160
|
+
...(entry.blockedBy ? { blockedBy: entry.blockedBy, message: 'Held for review of the interrupted turn.' } : {}),
|
|
156
161
|
});
|
|
157
162
|
}
|
|
158
163
|
enqueue(request: Request): void {
|
|
@@ -160,7 +165,7 @@ export class DurableTurnQueue {
|
|
|
160
165
|
throw new Error('Queued turns require streaming replies.');
|
|
161
166
|
const existing = this.entries.get(request.id);
|
|
162
167
|
if (existing) {
|
|
163
|
-
if (JSON.stringify(existing.request) !== JSON.stringify(request))
|
|
168
|
+
if (JSON.stringify(HarnessRequestSchema.parse(existing.request)) !== JSON.stringify(HarnessRequestSchema.parse(request)))
|
|
164
169
|
throw new Error('Request ID already belongs to another message.');
|
|
165
170
|
for (const frame of this.deps.logs.read(request.id).frames)
|
|
166
171
|
this.deps.sendRaw(frame);
|
|
@@ -186,37 +191,32 @@ export class DurableTurnQueue {
|
|
|
186
191
|
scope &&
|
|
187
192
|
(request.kind === 'ask'
|
|
188
193
|
? scope.kind === 'ask'
|
|
189
|
-
:
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
(scope.kind === 'conduct' &&
|
|
194
|
-
scope.repoId === request.repoId &&
|
|
195
|
-
!!request.workerId));
|
|
194
|
+
: scope.kind === 'code' &&
|
|
195
|
+
scope.repoId === request.repoId &&
|
|
196
|
+
scope.workerId === request.workerId &&
|
|
197
|
+
(scope.mode ?? 'worktree') === (request.mode ?? 'worktree'));
|
|
196
198
|
if (!same)
|
|
197
199
|
throw new Error(
|
|
198
200
|
'The preceding turn does not belong to this conversation. Refresh it before sending again.',
|
|
199
201
|
);
|
|
200
202
|
}
|
|
201
203
|
const entry: Entry = { request, state: 'queued' };
|
|
202
|
-
this.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
} catch (error) {
|
|
206
|
-
this.save({ ...entry, state: 'failed' });
|
|
207
|
-
throw error;
|
|
208
|
-
}
|
|
204
|
+
const accepted = this.deps.logs.runtime.accept(request, entry);
|
|
205
|
+
this.entries.set(request.id, entry);
|
|
206
|
+
for (const frame of accepted.frames) this.deps.sendRaw(frame);
|
|
209
207
|
this.wake();
|
|
210
208
|
}
|
|
211
209
|
|
|
212
210
|
/** Skipped queue entries inherit their predecessor, so removing B from A→B→C
|
|
213
211
|
* never starts a new conversation or strands C. Failed executions stop dependants. */
|
|
214
|
-
private predecessor(entry: Entry): { ready: boolean; resume?: string } {
|
|
212
|
+
private predecessor(entry: Entry): { ready: boolean; resume?: string; blockedBy?: string } {
|
|
215
213
|
const id = entry.request.afterRequestId;
|
|
216
214
|
if (!id) return { ready: true, resume: entry.request.resume };
|
|
217
215
|
const previous = this.entries.get(id);
|
|
218
216
|
if (previous) {
|
|
219
217
|
if (previous.state === 'skipped') return this.predecessor(previous);
|
|
218
|
+
if (previous.state === 'held') return { ready: false, blockedBy: previous.blockedBy ?? id };
|
|
219
|
+
if (previous.state === 'failed' && this.terminal(id)?.code === 'interrupted_unknown') return { ready: false, blockedBy: id };
|
|
220
220
|
if (previous.state === 'failed')
|
|
221
221
|
throw new Error(
|
|
222
222
|
'The previous turn did not finish. Review it before resending this message.',
|
|
@@ -230,23 +230,12 @@ export class DurableTurnQueue {
|
|
|
230
230
|
}
|
|
231
231
|
const terminal = this.terminal(id);
|
|
232
232
|
if (!terminal) return { ready: false };
|
|
233
|
+
if (terminal.code === 'interrupted_unknown') return { ready: false, blockedBy: id };
|
|
233
234
|
if (terminal.type !== 'done')
|
|
234
235
|
throw new Error(
|
|
235
236
|
'The previous turn did not finish. Review it before resending this message.',
|
|
236
237
|
);
|
|
237
|
-
const
|
|
238
|
-
.read(id)
|
|
239
|
-
.frames.find((frame) => frame.type === 'accepted');
|
|
240
|
-
const scope = receipt?.scope as Record<string, unknown> | undefined;
|
|
241
|
-
const source =
|
|
242
|
-
scope?.kind === 'conduct' && entry.request.kind === 'code'
|
|
243
|
-
? entry.request.workerId!
|
|
244
|
-
: id;
|
|
245
|
-
if (source !== id && this.terminal(source)?.type !== 'done')
|
|
246
|
-
throw new Error(
|
|
247
|
-
'The worker did not finish. Review it before resending this message.',
|
|
248
|
-
);
|
|
249
|
-
const resume = this.session(source);
|
|
238
|
+
const resume = this.session(id);
|
|
250
239
|
if (!resume)
|
|
251
240
|
throw new Error(
|
|
252
241
|
'The previous turn has no session to continue. Start a new conversation.',
|
|
@@ -254,29 +243,37 @@ export class DurableTurnQueue {
|
|
|
254
243
|
return { ready: true, resume };
|
|
255
244
|
}
|
|
256
245
|
wake(): void {
|
|
257
|
-
if (this.stopped || this.pumping) return;
|
|
246
|
+
if (this.stopped || this.pumping || !this.deps.logs.runtime.writable) return;
|
|
258
247
|
this.pumping = true;
|
|
259
248
|
queueMicrotask(() => {
|
|
260
249
|
this.pumping = false;
|
|
261
|
-
if (this.stopped) return;
|
|
250
|
+
if (this.stopped || !this.deps.logs.runtime.writable) return;
|
|
262
251
|
const occupied = new Set<string>();
|
|
263
252
|
for (const [id, entry] of this.entries) {
|
|
264
253
|
const lane = turnLane(entry.request);
|
|
265
254
|
if (!this.owns(id)) continue;
|
|
255
|
+
if (entry.state === 'held') continue;
|
|
266
256
|
if (occupied.has(lane)) continue;
|
|
267
|
-
occupied.add(lane);
|
|
268
|
-
if (entry.state !== 'queued' || this.scheduled.has(id)) continue;
|
|
257
|
+
if (entry.state !== 'queued' || this.scheduled.has(id)) { occupied.add(lane); continue; }
|
|
269
258
|
try {
|
|
270
|
-
|
|
259
|
+
const previous = this.predecessor(entry);
|
|
260
|
+
if (!previous.ready) {
|
|
261
|
+
if (previous.blockedBy) {
|
|
262
|
+
this.save({ ...entry, state: 'held', blockedBy: previous.blockedBy });
|
|
263
|
+
this.confirm(id);
|
|
264
|
+
}
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
271
267
|
} catch (error) {
|
|
272
268
|
this.fail(entry, String((error as Error).message));
|
|
273
269
|
continue;
|
|
274
270
|
}
|
|
271
|
+
occupied.add(lane);
|
|
275
272
|
this.scheduled.add(id);
|
|
276
273
|
void this.deps.lanes
|
|
277
274
|
.run(turnLane(entry.request), async () => {
|
|
278
275
|
const current = this.entries.get(id)!;
|
|
279
|
-
if (this.stopped || current.state !== 'queued') return;
|
|
276
|
+
if (this.stopped || !this.deps.logs.runtime.writable || current.state !== 'queued') return;
|
|
280
277
|
const previous = this.predecessor(current);
|
|
281
278
|
if (!previous.ready) return;
|
|
282
279
|
this.save({ ...current, state: 'running' });
|
|
@@ -299,9 +296,9 @@ export class DurableTurnQueue {
|
|
|
299
296
|
'The turn ended before completion. Review it before resending.',
|
|
300
297
|
);
|
|
301
298
|
})
|
|
302
|
-
.catch((error) =>
|
|
303
|
-
this.fail(this.entries.get(id)!, String(error.message))
|
|
304
|
-
)
|
|
299
|
+
.catch((error) => {
|
|
300
|
+
if (this.deps.logs.runtime.writable) this.fail(this.entries.get(id)!, String(error.message));
|
|
301
|
+
})
|
|
305
302
|
.finally(() => {
|
|
306
303
|
this.scheduled.delete(id);
|
|
307
304
|
this.wake();
|
|
@@ -321,15 +318,15 @@ export class DurableTurnQueue {
|
|
|
321
318
|
if (frame) this.deps.sendRaw(frame);
|
|
322
319
|
return;
|
|
323
320
|
}
|
|
324
|
-
if (entry.state !== 'queued')
|
|
321
|
+
if (entry.state !== 'queued' && entry.state !== 'held')
|
|
325
322
|
throw new Error('This message has already started or left the queue.');
|
|
326
323
|
if (action === 'steer') {
|
|
324
|
+
if (entry.state === 'held') throw new Error('Review the interrupted turn before using this follow-up.');
|
|
327
325
|
if (entry.request.images?.length)
|
|
328
326
|
throw new Error('Attachments must run as a separate turn.');
|
|
329
327
|
if (!activeId || !this.deps.steer)
|
|
330
328
|
throw new Error('There is no active turn to influence.');
|
|
331
329
|
const active = this.entries.get(activeId);
|
|
332
|
-
// For a spawned fleet worker, the active request uses the worker's own ID.
|
|
333
330
|
if (
|
|
334
331
|
active
|
|
335
332
|
? turnLane(active.request) !== turnLane(entry.request) ||
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// @ts-expect-error Node 22 runtime API; the repository's Node type baseline is 20.
|
|
2
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
3
|
+
import { chmodSync, mkdirSync } from 'node:fs';
|
|
4
|
+
import { dirname } from 'node:path';
|
|
5
|
+
import type { HarnessRequest, RunReview } from '@lucidity/shared';
|
|
6
|
+
import type { TurnFrame, TurnState } from './turnLog.js';
|
|
7
|
+
|
|
8
|
+
const terminalTypes = new Set(['done', 'error', 'cancelled']);
|
|
9
|
+
|
|
10
|
+
function canonical(value: unknown): string {
|
|
11
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`;
|
|
12
|
+
if (value && typeof value === 'object')
|
|
13
|
+
return `{${Object.entries(value).filter(([, v]) => v !== undefined).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(',')}}`;
|
|
14
|
+
return JSON.stringify(value);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function conversationKey(request: { kind: string; repoId?: string; workerId?: string; mode?: string }): string {
|
|
18
|
+
return request.kind === 'code'
|
|
19
|
+
? JSON.stringify(['code', request.repoId, request.workerId ?? request.mode ?? 'worktree'])
|
|
20
|
+
: request.kind;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Local execution authority. Transactions commit before their receipts reach the transport. */
|
|
24
|
+
export class RuntimeStore {
|
|
25
|
+
private db: any;
|
|
26
|
+
private storageError?: Error;
|
|
27
|
+
get writable(): boolean { return !this.storageError; }
|
|
28
|
+
private write<T>(action: () => T): T {
|
|
29
|
+
if (this.storageError) throw new Error(`Runtime storage is unavailable until restart: ${this.storageError.message}`);
|
|
30
|
+
try { return action(); }
|
|
31
|
+
catch (error) {
|
|
32
|
+
const code = (error as { code?: string })?.code ?? '';
|
|
33
|
+
if (code.includes('SQLITE') || code === 'ERR_INVALID_STATE')
|
|
34
|
+
this.storageError = error instanceof Error ? error : new Error(String(error));
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
constructor(path: string) {
|
|
39
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
40
|
+
this.db = new DatabaseSync(path);
|
|
41
|
+
chmodSync(path, 0o600);
|
|
42
|
+
this.db.exec(`
|
|
43
|
+
PRAGMA journal_mode=WAL;
|
|
44
|
+
PRAGMA synchronous=FULL;
|
|
45
|
+
PRAGMA busy_timeout=5000;
|
|
46
|
+
CREATE TABLE IF NOT EXISTS runs (
|
|
47
|
+
id TEXT PRIMARY KEY, command TEXT, conversation TEXT,
|
|
48
|
+
state TEXT NOT NULL DEFAULT 'accepted', cursor INTEGER NOT NULL DEFAULT 0,
|
|
49
|
+
terminal TEXT, updated INTEGER NOT NULL
|
|
50
|
+
);
|
|
51
|
+
CREATE INDEX IF NOT EXISTS runs_conversation ON runs(conversation, updated);
|
|
52
|
+
CREATE TABLE IF NOT EXISTS events (
|
|
53
|
+
run_id TEXT NOT NULL, seq INTEGER NOT NULL, frame TEXT NOT NULL,
|
|
54
|
+
PRIMARY KEY(run_id, seq)
|
|
55
|
+
);
|
|
56
|
+
CREATE TABLE IF NOT EXISTS records (
|
|
57
|
+
bucket TEXT NOT NULL, id TEXT NOT NULL, value TEXT NOT NULL,
|
|
58
|
+
PRIMARY KEY(bucket, id)
|
|
59
|
+
);
|
|
60
|
+
`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
transaction<T>(action: () => T): T {
|
|
64
|
+
return this.write(() => {
|
|
65
|
+
this.db.exec('BEGIN IMMEDIATE');
|
|
66
|
+
try {
|
|
67
|
+
const result = action();
|
|
68
|
+
this.db.exec('COMMIT');
|
|
69
|
+
return result;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
try { this.db.exec('ROLLBACK'); } catch { /* preserve the original storage failure */ }
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get<T>(bucket: string, id: string): T | undefined {
|
|
78
|
+
const row = this.db.prepare('SELECT value FROM records WHERE bucket=? AND id=?').get(bucket, id);
|
|
79
|
+
return row ? JSON.parse(row.value) as T : undefined;
|
|
80
|
+
}
|
|
81
|
+
set(bucket: string, id: string, value: unknown): void {
|
|
82
|
+
this.write(() => this.db.prepare('INSERT INTO records VALUES (?, ?, ?) ON CONFLICT(bucket,id) DO UPDATE SET value=excluded.value')
|
|
83
|
+
.run(bucket, id, JSON.stringify(value)));
|
|
84
|
+
}
|
|
85
|
+
delete(bucket: string, id: string): void {
|
|
86
|
+
this.write(() => this.db.prepare('DELETE FROM records WHERE bucket=? AND id=?').run(bucket, id));
|
|
87
|
+
}
|
|
88
|
+
list<T>(bucket: string): T[] {
|
|
89
|
+
return this.db.prepare('SELECT value FROM records WHERE bucket=? ORDER BY rowid').all(bucket)
|
|
90
|
+
.map((row: { value: string }) => JSON.parse(row.value) as T);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The command and its first replayable receipt are one durable operation. */
|
|
94
|
+
accept(request: HarnessRequest, queuedEntry?: unknown): { duplicate: boolean; frames: TurnFrame[] } {
|
|
95
|
+
return this.transaction(() => {
|
|
96
|
+
const payload = canonical(request);
|
|
97
|
+
const old = this.db.prepare('SELECT command, cursor FROM runs WHERE id=?').get(request.id);
|
|
98
|
+
if (old?.command && old.command !== payload)
|
|
99
|
+
throw new Error('This request ID already belongs to different input.');
|
|
100
|
+
if (old) return { duplicate: true, frames: this.read(request.id).frames };
|
|
101
|
+
if (request.kind === 'code' && request.recoveryOf) {
|
|
102
|
+
const review = this.get<RunReview>('run-reviews', request.recoveryOf);
|
|
103
|
+
const source = this.command(request.recoveryOf);
|
|
104
|
+
if (!review || review.reviewId !== request.recoveryReviewId || review.continuationId !== request.id ||
|
|
105
|
+
source?.kind !== 'code' || conversationKey(source) !== conversationKey(request) ||
|
|
106
|
+
this.read(source.id).frames.at(-1)?.code !== 'interrupted_unknown' ||
|
|
107
|
+
review.continuedAt || !request.prompt.trim() || request.prompt.trim().startsWith('/') || request.prompt.trim() === source.prompt.trim())
|
|
108
|
+
throw new Error('A current review is required before continuing this interrupted turn.');
|
|
109
|
+
this.set('run-reviews', source.id, { ...review, continuedAt: new Date().toISOString(), instruction: request.prompt });
|
|
110
|
+
}
|
|
111
|
+
this.db.prepare('INSERT INTO runs (id,command,conversation,updated) VALUES (?,?,?,?)')
|
|
112
|
+
.run(request.id, payload, conversationKey(request), Date.now());
|
|
113
|
+
const scope = {
|
|
114
|
+
kind: request.kind,
|
|
115
|
+
...('repoId' in request ? { repoId: request.repoId } : {}),
|
|
116
|
+
...('workerId' in request ? { workerId: request.workerId } : {}),
|
|
117
|
+
...('mode' in request ? { mode: request.mode } : {}),
|
|
118
|
+
};
|
|
119
|
+
const frames = [this.appendInside(request.id, { type: 'accepted', requestId: request.id, scope })];
|
|
120
|
+
if (queuedEntry) {
|
|
121
|
+
this.set('queue', request.id, queuedEntry);
|
|
122
|
+
frames.push(this.appendInside(request.id, { type: 'queue_state', requestId: request.id, state: 'queued' }));
|
|
123
|
+
}
|
|
124
|
+
return { duplicate: false, frames };
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private appendInside(id: string, event: Record<string, unknown>): TurnFrame {
|
|
129
|
+
this.db.prepare('INSERT OR IGNORE INTO runs (id,updated) VALUES (?,?)').run(id, Date.now());
|
|
130
|
+
const run = this.db.prepare('SELECT cursor, terminal FROM runs WHERE id=?').get(id);
|
|
131
|
+
if (run.terminal) {
|
|
132
|
+
// Reconfirm the committed outcome, never continue a completed attempt.
|
|
133
|
+
this.set('protocol-fault', id, { type: event.type, at: new Date().toISOString() });
|
|
134
|
+
return JSON.parse(run.terminal);
|
|
135
|
+
}
|
|
136
|
+
const frame = { ...event, seq: run.cursor + 1 };
|
|
137
|
+
const serialized = JSON.stringify(frame);
|
|
138
|
+
const terminal = terminalTypes.has(String(event.type));
|
|
139
|
+
const state = terminal ? String(event.type) : event.type === 'accepted' ? 'accepted' : event.type === 'queue_state' ? String(event.state) : 'running';
|
|
140
|
+
this.db.prepare('INSERT INTO events VALUES (?,?,?)').run(id, frame.seq, serialized);
|
|
141
|
+
this.db.prepare('UPDATE runs SET cursor=?, terminal=?, state=?, updated=? WHERE id=?')
|
|
142
|
+
.run(frame.seq, terminal ? serialized : null, state, Date.now(), id);
|
|
143
|
+
return frame;
|
|
144
|
+
}
|
|
145
|
+
append(id: string, event: Record<string, unknown>): TurnFrame {
|
|
146
|
+
return this.transaction(() => this.appendInside(id, event));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
status(id: string): Omit<TurnState, 'frames'> {
|
|
150
|
+
const run = this.db.prepare('SELECT cursor, terminal FROM runs WHERE id=?').get(id);
|
|
151
|
+
return { exists: !!run, maxSeq: run?.cursor ?? 0, terminated: !!run?.terminal };
|
|
152
|
+
}
|
|
153
|
+
read(id: string): TurnState {
|
|
154
|
+
const status = this.status(id);
|
|
155
|
+
if (!status.exists) return { ...status, frames: [] };
|
|
156
|
+
const frames = this.db.prepare('SELECT frame FROM events WHERE run_id=? ORDER BY seq').all(id)
|
|
157
|
+
.map((row: { frame: string }) => JSON.parse(row.frame) as TurnFrame);
|
|
158
|
+
return { ...status, frames };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
importLog(id: string, state: TurnState): void {
|
|
162
|
+
if (!state.exists || this.read(id).exists) return;
|
|
163
|
+
this.transaction(() => {
|
|
164
|
+
const last = [...state.frames].reverse().find((f) => terminalTypes.has(String(f.type)));
|
|
165
|
+
this.db.prepare('INSERT OR IGNORE INTO runs (id,cursor,terminal,state,updated) VALUES (?,?,?,?,?)')
|
|
166
|
+
.run(id, state.maxSeq, last ? JSON.stringify(last) : null, last ? String(last.type) : 'interrupted_unknown', Date.now());
|
|
167
|
+
for (const frame of state.frames)
|
|
168
|
+
this.db.prepare('INSERT OR IGNORE INTO events VALUES (?,?,?)').run(id, frame.seq, JSON.stringify(frame));
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
commands(conversation: string, page?: { before?: string; after?: string; limit: number }): { request: HarnessRequest; state: TurnState }[] {
|
|
173
|
+
const rows: { id: string; command: string }[] = page
|
|
174
|
+
? this.db.prepare(`SELECT id,command FROM runs WHERE conversation=? AND command IS NOT NULL
|
|
175
|
+
AND rowid < COALESCE((SELECT rowid FROM runs WHERE id=?), 9223372036854775807)
|
|
176
|
+
AND rowid > COALESCE((SELECT rowid FROM runs WHERE id=?), 0)
|
|
177
|
+
ORDER BY rowid DESC LIMIT ?`).all(conversation, page.before ?? '', page.after ?? '', page.limit).reverse()
|
|
178
|
+
: this.db.prepare('SELECT id,command FROM runs WHERE conversation=? AND command IS NOT NULL ORDER BY rowid').all(conversation);
|
|
179
|
+
return rows.map((row) => ({ request: JSON.parse(row.command), state: this.read(row.id) }));
|
|
180
|
+
}
|
|
181
|
+
latestSession(conversation: string, after?: string): string | undefined {
|
|
182
|
+
return this.db.prepare(`SELECT json_extract(events.frame, '$.sessionId') AS session
|
|
183
|
+
FROM runs JOIN events ON events.run_id=runs.id WHERE runs.conversation=?
|
|
184
|
+
AND json_type(events.frame, '$.sessionId')='text'
|
|
185
|
+
AND runs.rowid > COALESCE((SELECT rowid FROM runs WHERE id=?), 0)
|
|
186
|
+
ORDER BY runs.rowid DESC, events.seq DESC LIMIT 1`).get(conversation, after ?? '')?.session;
|
|
187
|
+
}
|
|
188
|
+
lastCommand(conversation: string): string | undefined {
|
|
189
|
+
return this.db.prepare('SELECT id FROM runs WHERE conversation=? AND command IS NOT NULL ORDER BY rowid DESC LIMIT 1').get(conversation)?.id;
|
|
190
|
+
}
|
|
191
|
+
command(id: string): HarnessRequest | undefined {
|
|
192
|
+
const row = this.db.prepare('SELECT command FROM runs WHERE id=?').get(id);
|
|
193
|
+
return row?.command ? JSON.parse(row.command) : undefined;
|
|
194
|
+
}
|
|
195
|
+
unfinished(conversation: string): boolean {
|
|
196
|
+
return !!this.db.prepare('SELECT id FROM runs WHERE conversation=? AND terminal IS NULL LIMIT 1').get(conversation);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
reconcile(owns: (id: string) => boolean): void {
|
|
200
|
+
for (const row of this.db.prepare('SELECT id FROM runs WHERE terminal IS NULL').all() as { id: string }[]) {
|
|
201
|
+
if (owns(row.id)) continue;
|
|
202
|
+
this.append(row.id, { type: 'error', requestId: row.id, code: 'interrupted_unknown',
|
|
203
|
+
message: 'Lucid restarted before this turn settled. It was not run again. Review its work before continuing.' });
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
close(): void { this.db.close(); }
|
|
207
|
+
}
|
package/src/setup/server.ts
CHANGED
|
@@ -122,7 +122,7 @@ export async function checkSetupProviders() {
|
|
|
122
122
|
message: '',
|
|
123
123
|
};
|
|
124
124
|
} catch (e) {
|
|
125
|
-
const health = providerFailure(e);
|
|
125
|
+
const health = providerFailure(e) ?? { auth: 'unknown', problem: 'unavailable' };
|
|
126
126
|
return {
|
|
127
127
|
id,
|
|
128
128
|
label: id === 'claude' ? 'Claude' : 'Codex',
|
package/src/turnLog.ts
CHANGED
|
@@ -9,23 +9,12 @@ import {
|
|
|
9
9
|
} from 'node:fs';
|
|
10
10
|
import { join } from 'node:path';
|
|
11
11
|
import { TURNS_DIR } from './config.js';
|
|
12
|
+
import { RuntimeStore } from './runtimeStore.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* appended (with a monotonic `seq`) BEFORE it goes on the socket, so a frame produced
|
|
18
|
-
* while the socket is down — or while the phone is away — survives on disk. The phone
|
|
19
|
-
* recovers by sending a `pull` request; the daemon replays `readState().frames` after
|
|
20
|
-
* the phone's `sinceSeq`.
|
|
21
|
-
*
|
|
22
|
-
* The daemon OWNS `seq` here (starting at 1, per requestId). This is the linchpin of the
|
|
23
|
-
* whole recovery scheme: the same `seq` must appear on the live-forwarded frame, the
|
|
24
|
-
* server's replay-on-rejoin, and a daemon pull, so the phone can de-dup across all three.
|
|
25
|
-
* The relay forwards frames verbatim (it no longer stamps `seq`).
|
|
26
|
-
*
|
|
27
|
-
* Never throws — a logging or disk error must not take a turn down; it just makes that
|
|
28
|
-
* turn unrecoverable (the live frame still goes out). Mirrors `runlog.ts`.
|
|
15
|
+
* SQLite owns command receipts and ordered run events. JSONL files remain bounded
|
|
16
|
+
* diagnostic exports and are imported once when opening an older installation.
|
|
17
|
+
* A storage failure rejects admission or propagates to the execution owner.
|
|
29
18
|
*/
|
|
30
19
|
|
|
31
20
|
/** A logged frame: the exact wire frame plus its daemon-authored `seq`. */
|
|
@@ -114,59 +103,13 @@ function appendLine(path: string, line: string): boolean {
|
|
|
114
103
|
}
|
|
115
104
|
}
|
|
116
105
|
|
|
117
|
-
/**
|
|
118
|
-
* One turn's log. Owns the per-requestId `seq` counter (a shared handle, NOT a closure
|
|
119
|
-
* local, so a concurrent `cancel`'s terminal frame gets the next `seq` on the same
|
|
120
|
-
* counter). Seeds itself from any existing file so seq keeps climbing across a daemon
|
|
121
|
-
* restart (a re-created handle resumes from the file's `maxSeq`).
|
|
122
|
-
*/
|
|
123
|
-
export class TurnLog {
|
|
124
|
-
private readonly path: string;
|
|
125
|
-
private readonly maxBytes: number;
|
|
126
|
-
private nextSeq: number;
|
|
127
|
-
private bytes: number;
|
|
128
|
-
private terminatedFlag: boolean;
|
|
129
|
-
|
|
130
|
-
constructor(requestId: string, dir: string, maxBytes = MAX_TURN_LOG_BYTES) {
|
|
131
|
-
this.path = join(dir, `${requestId}.jsonl`);
|
|
132
|
-
this.maxBytes = maxBytes;
|
|
133
|
-
const st = scanTurnFile(this.path);
|
|
134
|
-
this.nextSeq = st.maxSeq + 1;
|
|
135
|
-
this.bytes = st.bytes;
|
|
136
|
-
this.terminatedFlag = st.terminated;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
get terminated(): boolean {
|
|
140
|
-
return this.terminatedFlag;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/** Stamp the next `seq`, append the frame (unless a droppable delta past the byte cap),
|
|
144
|
-
* and return the stamped frame to put on the wire. */
|
|
145
|
-
write(event: Record<string, unknown>): TurnFrame {
|
|
146
|
-
const seq = this.nextSeq++;
|
|
147
|
-
const frame: TurnFrame = { ...event, seq };
|
|
148
|
-
const type = typeof event.type === 'string' ? event.type : '';
|
|
149
|
-
const droppable = type === 'delta' && this.bytes >= this.maxBytes;
|
|
150
|
-
if (!droppable) {
|
|
151
|
-
const line = JSON.stringify(frame) + '\n';
|
|
152
|
-
if (appendLine(this.path, line))
|
|
153
|
-
this.bytes += Buffer.byteLength(line, 'utf8');
|
|
154
|
-
}
|
|
155
|
-
if (isTerminalType(type)) this.terminatedFlag = true;
|
|
156
|
-
return frame;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* All turn logs for this daemon. Keeps an in-memory {@link TurnLog} per in-flight turn
|
|
162
|
-
* (the live seq counter), dropped once the turn terminates — the file lives on for 24h.
|
|
163
|
-
* The file is the source of truth for replay ({@link read}).
|
|
164
|
-
*/
|
|
106
|
+
/** Compatibility reader/exporter around the transactional local runtime ledger. */
|
|
165
107
|
export class TurnLogStore {
|
|
166
108
|
private readonly dir: string;
|
|
167
109
|
private readonly clock: () => number;
|
|
168
110
|
private readonly maxBytes: number;
|
|
169
|
-
private readonly
|
|
111
|
+
private readonly exportBytes = new Map<string, number>();
|
|
112
|
+
readonly runtime: RuntimeStore;
|
|
170
113
|
|
|
171
114
|
queueDirectory(): string {
|
|
172
115
|
return join(this.dir, 'queue');
|
|
@@ -178,6 +121,7 @@ export class TurnLogStore {
|
|
|
178
121
|
this.dir = opts.dir ?? TURNS_DIR;
|
|
179
122
|
this.clock = opts.now ?? Date.now;
|
|
180
123
|
this.maxBytes = opts.maxBytes ?? MAX_TURN_LOG_BYTES;
|
|
124
|
+
this.runtime = new RuntimeStore(join(this.dir, 'runtime.sqlite'));
|
|
181
125
|
try {
|
|
182
126
|
mkdirSync(this.dir, { recursive: true });
|
|
183
127
|
} catch {
|
|
@@ -187,24 +131,37 @@ export class TurnLogStore {
|
|
|
187
131
|
|
|
188
132
|
/** Log + stamp one outgoing stream frame; returns the stamped frame to send. */
|
|
189
133
|
append(requestId: string, event: Record<string, unknown>): TurnFrame {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
134
|
+
if (!this.runtime.status(requestId).exists) this.read(requestId);
|
|
135
|
+
const before = this.runtime.status(requestId);
|
|
136
|
+
const frame = this.runtime.append(requestId, event);
|
|
137
|
+
if (before.terminated) return frame;
|
|
138
|
+
// Bounded diagnostic exports are optional; a failed export never loses the SQLite event.
|
|
139
|
+
const path = join(this.dir, `${requestId}.jsonl`);
|
|
140
|
+
const bytes = this.exportBytes.get(requestId) ?? (existsSync(path) ? statSync(path).size : 0);
|
|
141
|
+
if (event.type !== 'delta' || bytes < this.maxBytes) {
|
|
142
|
+
const line = JSON.stringify(frame) + '\n';
|
|
143
|
+
if (appendLine(path, line)) this.exportBytes.set(requestId, bytes + Buffer.byteLength(line));
|
|
194
144
|
}
|
|
195
|
-
|
|
196
|
-
if (log.terminated) this.logs.delete(requestId); // free memory; file persists
|
|
145
|
+
if (TERMINAL_TYPES.has(String(event.type))) this.exportBytes.delete(requestId);
|
|
197
146
|
return frame;
|
|
198
147
|
}
|
|
199
148
|
|
|
200
|
-
/** The durable state of a turn, read from disk — for serving a `pull`. */
|
|
201
149
|
read(requestId: string): TurnState {
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
);
|
|
205
|
-
return
|
|
150
|
+
const state = this.runtime.read(requestId);
|
|
151
|
+
if (state.exists) return state;
|
|
152
|
+
this.runtime.importLog(requestId, scanTurnFile(join(this.dir, `${requestId}.jsonl`)));
|
|
153
|
+
return this.runtime.read(requestId);
|
|
206
154
|
}
|
|
207
155
|
|
|
156
|
+
/** Startup recovery is independent of whether a phone asks to replay a turn. */
|
|
157
|
+
reconcile(owns: (id: string) => boolean): void {
|
|
158
|
+
for (const name of readdirSync(this.dir))
|
|
159
|
+
if (name.endsWith('.jsonl')) this.read(name.slice(0, -6));
|
|
160
|
+
this.runtime.reconcile(owns);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
close(): void { this.runtime.close(); }
|
|
164
|
+
|
|
208
165
|
/** Delete turn logs whose file hasn't been touched in `maxAgeMs`. Never throws. */
|
|
209
166
|
prune(maxAgeMs: number = TURN_LOG_MAX_AGE_MS): void {
|
|
210
167
|
const now = this.clock();
|