@opencorelabs/lucidity 0.3.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -3
- package/dist/assets/speech/licenses/FluidAudio/LICENSE +201 -0
- package/dist/assets/speech/licenses/FluidAudio/ThirdPartyLicenses/fastcluster-LICENSE.md +11 -0
- package/dist/assets/speech/licenses/FluidAudio/ThirdPartyLicenses/vbx-LICENSE.md +201 -0
- package/dist/assets/speech/lucidity-speech +0 -0
- package/dist/automations/agent.d.ts +16 -0
- package/dist/automations/agent.d.ts.map +1 -0
- package/dist/automations/agent.js +196 -0
- package/dist/automations/cli.d.ts +4 -0
- package/dist/automations/cli.d.ts.map +1 -0
- package/dist/automations/cli.js +44 -0
- package/dist/automations/connections.d.ts +11 -0
- package/dist/automations/connections.d.ts.map +1 -0
- package/dist/automations/connections.js +74 -0
- package/dist/automations/designer.d.ts +39 -0
- package/dist/automations/designer.d.ts.map +1 -0
- package/dist/automations/designer.js +450 -0
- package/dist/automations/history.d.ts +4 -0
- package/dist/automations/history.d.ts.map +1 -0
- package/dist/automations/history.js +57 -0
- package/dist/automations/learning.d.ts +19 -0
- package/dist/automations/learning.d.ts.map +1 -0
- package/dist/automations/learning.js +121 -0
- package/dist/automations/pinterest.d.ts +21 -0
- package/dist/automations/pinterest.d.ts.map +1 -0
- package/dist/automations/pinterest.js +113 -0
- package/dist/automations/service.d.ts +42 -0
- package/dist/automations/service.d.ts.map +1 -0
- package/dist/automations/service.js +406 -0
- package/dist/automations/setup.d.ts +3 -0
- package/dist/automations/setup.d.ts.map +1 -0
- package/dist/automations/setup.js +48 -0
- package/dist/automations/skill.d.ts +3 -0
- package/dist/automations/skill.d.ts.map +1 -0
- package/dist/automations/skill.js +29 -0
- package/dist/automations/store.d.ts +13 -0
- package/dist/automations/store.d.ts.map +1 -0
- package/dist/automations/store.js +46 -0
- package/dist/chat/server.d.ts +2 -0
- package/dist/chat/server.d.ts.map +1 -1
- package/dist/chat/server.js +46 -2
- package/dist/coding/commandContext.d.ts +6 -0
- package/dist/coding/commandContext.d.ts.map +1 -0
- package/dist/coding/commandContext.js +20 -0
- package/dist/coding/runCodeTurn.d.ts +12 -2
- package/dist/coding/runCodeTurn.d.ts.map +1 -1
- package/dist/coding/runCodeTurn.js +49 -19
- package/dist/coding/worktree.d.ts +3 -4
- package/dist/coding/worktree.d.ts.map +1 -1
- package/dist/coding/worktree.js +3 -4
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +20 -3
- package/dist/decisions/cli.d.ts +2 -0
- package/dist/decisions/cli.d.ts.map +1 -0
- package/dist/decisions/cli.js +106 -0
- package/dist/decisions/client.d.ts +20 -0
- package/dist/decisions/client.d.ts.map +1 -0
- package/dist/decisions/client.js +41 -0
- package/dist/handoff.d.ts +11 -0
- package/dist/handoff.d.ts.map +1 -0
- package/dist/handoff.js +21 -0
- package/dist/index.js +185 -40
- package/dist/jobs/briefing.js +1 -1
- package/dist/jobs/extraction.d.ts.map +1 -1
- package/dist/jobs/extraction.js +112 -22
- package/dist/jobs/fastModeReview.d.ts +39 -0
- package/dist/jobs/fastModeReview.d.ts.map +1 -0
- package/dist/jobs/fastModeReview.js +192 -0
- package/dist/jobs/voiceReview.d.ts +24 -0
- package/dist/jobs/voiceReview.d.ts.map +1 -0
- package/dist/jobs/voiceReview.js +128 -0
- package/dist/mcp/clients.d.ts +5 -0
- package/dist/mcp/clients.d.ts.map +1 -1
- package/dist/mcp/clients.js +1 -1
- package/dist/mcp/config.d.ts +3 -1
- package/dist/mcp/config.d.ts.map +1 -1
- package/dist/mcp/config.js +48 -6
- package/dist/mcp/paired.js +1 -0
- package/dist/notesContext.d.ts.map +1 -1
- package/dist/notesContext.js +3 -2
- package/dist/room/client.d.ts +20 -7
- package/dist/room/client.d.ts.map +1 -1
- package/dist/room/client.js +266 -47
- package/dist/room/computer.d.ts.map +1 -1
- package/dist/room/computer.js +9 -0
- package/dist/room/context.d.ts +3 -2
- package/dist/room/context.d.ts.map +1 -1
- package/dist/room/context.js +10 -3
- package/dist/room/turnQueue.d.ts +40 -0
- package/dist/room/turnQueue.d.ts.map +1 -0
- package/dist/room/turnQueue.js +301 -0
- package/dist/skills/lucidity-automations/SKILL.md +54 -0
- package/dist/speech/captures.d.ts +30 -0
- package/dist/speech/captures.d.ts.map +1 -0
- package/dist/speech/captures.js +209 -0
- package/dist/speech/fluidAudio.d.ts +28 -0
- package/dist/speech/fluidAudio.d.ts.map +1 -0
- package/dist/speech/fluidAudio.js +182 -0
- package/dist/speech/service.d.ts +14 -0
- package/dist/speech/service.d.ts.map +1 -0
- package/dist/speech/service.js +88 -0
- package/dist/speech/types.d.ts +19 -0
- package/dist/speech/types.d.ts.map +1 -0
- package/dist/speech/types.js +1 -0
- package/dist/turnLog.d.ts +1 -0
- package/dist/turnLog.d.ts.map +1 -1
- package/dist/turnLog.js +3 -0
- package/native/speech/Package.resolved +15 -0
- package/native/speech/Package.swift +16 -0
- package/native/speech/Sources/lucidity-speech/Speech.swift +81 -0
- package/package.json +6 -2
- package/src/automations/agent.ts +239 -0
- package/src/automations/cli.ts +52 -0
- package/src/automations/connections.ts +83 -0
- package/src/automations/designer.ts +594 -0
- package/src/automations/history.ts +59 -0
- package/src/automations/learning.ts +180 -0
- package/src/automations/pinterest.ts +146 -0
- package/src/automations/service.ts +505 -0
- package/src/automations/setup.ts +71 -0
- package/src/automations/skill.ts +40 -0
- package/src/automations/store.ts +63 -0
- package/src/chat/server.ts +62 -3
- package/src/coding/commandContext.ts +29 -0
- package/src/coding/runCodeTurn.ts +65 -21
- package/src/coding/worktree.ts +3 -4
- package/src/config.ts +29 -2
- package/src/decisions/cli.ts +136 -0
- package/src/decisions/client.ts +62 -0
- package/src/handoff.ts +28 -0
- package/src/index.ts +202 -67
- package/src/jobs/briefing.ts +1 -1
- package/src/jobs/extraction.ts +157 -32
- package/src/jobs/fastModeReview.ts +221 -0
- package/src/jobs/voiceReview.ts +156 -0
- package/src/mcp/clients.ts +1 -1
- package/src/mcp/config.ts +56 -6
- package/src/mcp/paired.ts +1 -0
- package/src/notesContext.ts +3 -2
- package/src/room/client.ts +320 -54
- package/src/room/computer.ts +9 -0
- package/src/room/context.ts +12 -3
- package/src/room/turnQueue.ts +358 -0
- package/src/speech/captures.ts +265 -0
- package/src/speech/fluidAudio.ts +242 -0
- package/src/speech/service.ts +108 -0
- package/src/speech/types.ts +13 -0
- package/src/turnLog.ts +4 -0
- package/vendor/decisions/LICENSE +662 -0
- package/vendor/decisions/dist/capture.d.ts +79 -0
- package/vendor/decisions/dist/capture.js +183 -0
- package/vendor/decisions/dist/command.d.ts +202 -0
- package/vendor/decisions/dist/command.js +750 -0
- package/vendor/decisions/dist/dayPlan.d.ts +9 -0
- package/vendor/decisions/dist/dayPlan.js +82 -0
- package/vendor/decisions/dist/gate.d.ts +12 -0
- package/vendor/decisions/dist/gate.js +18 -0
- package/vendor/decisions/dist/index.d.ts +6 -0
- package/vendor/decisions/dist/index.js +6 -0
- package/vendor/decisions/dist/jev.d.ts +15 -0
- package/vendor/decisions/dist/jev.js +244 -0
- package/vendor/decisions/dist/types.d.ts +67 -0
- package/vendor/decisions/dist/types.js +1 -0
- package/vendor/decisions/package.json +22 -0
- package/vendor/decisions/src/capture.ts +199 -0
- package/vendor/decisions/src/command.ts +836 -0
- package/vendor/decisions/src/dayPlan.ts +80 -0
- package/vendor/decisions/src/gate.ts +32 -0
- package/vendor/decisions/src/index.ts +6 -0
- package/vendor/decisions/src/jev.ts +295 -0
- package/vendor/decisions/src/types.ts +79 -0
- package/vendor/mcp-server/README.md +6 -1
- package/vendor/mcp-server/dist/client.d.ts +1 -0
- package/vendor/mcp-server/dist/client.d.ts.map +1 -1
- package/vendor/mcp-server/dist/client.js +8 -0
- package/vendor/mcp-server/dist/commentProvider.d.ts +3 -0
- package/vendor/mcp-server/dist/commentProvider.d.ts.map +1 -0
- package/vendor/mcp-server/dist/commentProvider.js +10 -0
- package/vendor/mcp-server/dist/index.js +21 -6
- package/vendor/mcp-server/dist/tools/automations.d.ts +6 -0
- package/vendor/mcp-server/dist/tools/automations.d.ts.map +1 -0
- package/vendor/mcp-server/dist/tools/automations.js +163 -0
- package/vendor/mcp-server/dist/tools/commandEventFormat.d.ts +52 -0
- package/vendor/mcp-server/dist/tools/commandEventFormat.d.ts.map +1 -0
- package/vendor/mcp-server/dist/tools/commandEventFormat.js +83 -0
- package/vendor/mcp-server/dist/tools/commandEvents.d.ts +3 -0
- package/vendor/mcp-server/dist/tools/commandEvents.d.ts.map +1 -0
- package/vendor/mcp-server/dist/tools/commandEvents.js +21 -0
- package/vendor/mcp-server/dist/tools/comments.d.ts.map +1 -1
- package/vendor/mcp-server/dist/tools/comments.js +25 -4
- package/vendor/mcp-server/dist/tools/index.d.ts +2 -0
- package/vendor/mcp-server/dist/tools/index.d.ts.map +1 -1
- package/vendor/mcp-server/dist/tools/index.js +2 -0
- package/vendor/mcp-server/dist/tools/journal.d.ts +3 -0
- package/vendor/mcp-server/dist/tools/journal.d.ts.map +1 -0
- package/vendor/mcp-server/dist/tools/journal.js +131 -0
- package/vendor/mcp-server/dist/tools/taskActivity.d.ts +3 -0
- package/vendor/mcp-server/dist/tools/taskActivity.d.ts.map +1 -0
- package/vendor/mcp-server/dist/tools/taskActivity.js +32 -0
- package/vendor/mcp-server/dist/tools/taskOccurrences.d.ts +3 -0
- package/vendor/mcp-server/dist/tools/taskOccurrences.d.ts.map +1 -0
- package/vendor/mcp-server/dist/tools/taskOccurrences.js +12 -0
- package/vendor/mcp-server/dist/tools/taskTrash.d.ts +3 -0
- package/vendor/mcp-server/dist/tools/taskTrash.d.ts.map +1 -0
- package/vendor/mcp-server/dist/tools/taskTrash.js +21 -0
- package/vendor/mcp-server/dist/tools/tasks.d.ts.map +1 -1
- package/vendor/mcp-server/dist/tools/tasks.js +67 -27
- package/vendor/mcp-server/package.json +5 -1
- package/vendor/mcp-server/src/client.ts +10 -0
- package/vendor/mcp-server/src/commentProvider.ts +9 -0
- package/vendor/mcp-server/src/index.ts +20 -6
- package/vendor/mcp-server/src/tools/automations.ts +199 -0
- package/vendor/mcp-server/src/tools/commandEventFormat.ts +108 -0
- package/vendor/mcp-server/src/tools/commandEvents.ts +27 -0
- package/vendor/mcp-server/src/tools/comments.ts +24 -3
- package/vendor/mcp-server/src/tools/index.ts +2 -0
- package/vendor/mcp-server/src/tools/journal.ts +168 -0
- package/vendor/mcp-server/src/tools/taskActivity.ts +55 -0
- package/vendor/mcp-server/src/tools/taskOccurrences.ts +26 -0
- package/vendor/mcp-server/src/tools/taskTrash.ts +23 -0
- package/vendor/mcp-server/src/tools/tasks.ts +66 -30
- package/vendor/notes/dist/index.d.ts +2 -0
- package/vendor/notes/dist/index.d.ts.map +1 -1
- package/vendor/notes/dist/index.js +2 -0
- package/vendor/notes/dist/journal-backend.d.ts +4 -0
- package/vendor/notes/dist/journal-backend.d.ts.map +1 -0
- package/vendor/notes/dist/journal-backend.js +33 -0
- package/vendor/notes/dist/journal.d.ts +7 -0
- package/vendor/notes/dist/journal.d.ts.map +1 -0
- package/vendor/notes/dist/journal.js +173 -0
- package/vendor/notes/dist/vault.d.ts.map +1 -1
- package/vendor/notes/dist/vault.js +6 -1
- package/vendor/notes/src/index.ts +2 -0
- package/vendor/notes/src/journal-backend.ts +53 -0
- package/vendor/notes/src/journal.ts +194 -0
- package/vendor/notes/src/vault.ts +9 -1
- package/vendor/runtime/README.md +4 -0
- package/vendor/runtime/dist/executor/claudeAgent.d.ts +2 -0
- package/vendor/runtime/dist/executor/claudeAgent.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/claudeAgent.js +117 -8
- package/vendor/runtime/dist/executor/claudeCode.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/claudeCode.js +8 -4
- package/vendor/runtime/dist/executor/codex.d.ts +2 -0
- package/vendor/runtime/dist/executor/codex.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codex.js +214 -11
- package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/PlanType.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CreditsSnapshot.d.ts +6 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CreditsSnapshot.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CreditsSnapshot.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts +26 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitReachedType.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitReachedType.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitReachedType.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetCredit.d.ts +27 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetCredit.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetCredit.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetCreditStatus.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetCreditStatus.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetCreditStatus.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetCreditsSummary.d.ts +13 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetCreditsSummary.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetCreditsSummary.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetType.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetType.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitResetType.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts +20 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitWindow.d.ts +6 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitWindow.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitWindow.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewDelivery.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewDelivery.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewDelivery.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts +12 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewTarget.d.ts +17 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewTarget.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewTarget.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillDependencies.d.ts +5 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillDependencies.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillDependencies.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillErrorInfo.d.ts +5 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillErrorInfo.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillErrorInfo.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillInterface.d.ts +18 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillInterface.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillInterface.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillMetadata.d.ts +22 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillMetadata.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillMetadata.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillScope.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillScope.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillScope.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillToolDependency.d.ts +9 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillToolDependency.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillToolDependency.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillsListEntry.d.ts +8 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillsListEntry.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillsListEntry.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillsListResponse.d.ts +5 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillsListResponse.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SkillsListResponse.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SpendControlLimitSnapshot.d.ts +7 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SpendControlLimitSnapshot.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/SpendControlLimitSnapshot.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSetNameParams.d.ts +5 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSetNameParams.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSetNameParams.js +2 -0
- package/vendor/runtime/dist/executor/health.d.ts +1 -0
- package/vendor/runtime/dist/executor/health.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/health.js +3 -0
- package/vendor/runtime/dist/executor/liveTurns.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/liveTurns.js +3 -0
- package/vendor/runtime/dist/executor/providerRouter.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/providerRouter.js +2 -1
- package/vendor/runtime/dist/executor/types.d.ts +10 -0
- package/vendor/runtime/dist/executor/types.d.ts.map +1 -1
- package/vendor/runtime/dist/harness/index.d.ts +2 -0
- package/vendor/runtime/dist/harness/index.d.ts.map +1 -1
- package/vendor/runtime/dist/harness/index.js +46 -1
- package/vendor/runtime/dist/harness/types.d.ts +5 -1
- package/vendor/runtime/dist/harness/types.d.ts.map +1 -1
- 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 +2 -0
- package/vendor/runtime/dist/journal/context.d.ts +18 -0
- package/vendor/runtime/dist/journal/context.d.ts.map +1 -1
- package/vendor/runtime/dist/journal/context.js +19 -5
- package/vendor/runtime/dist/prompts/briefing.d.ts +4 -7
- package/vendor/runtime/dist/prompts/briefing.d.ts.map +1 -1
- package/vendor/runtime/dist/prompts/briefing.js +61 -12
- package/vendor/runtime/dist/prompts/cardStatement.d.ts +7 -0
- package/vendor/runtime/dist/prompts/cardStatement.d.ts.map +1 -0
- package/vendor/runtime/dist/prompts/cardStatement.js +52 -0
- package/vendor/runtime/dist/prompts/chat.d.ts +1 -0
- package/vendor/runtime/dist/prompts/chat.d.ts.map +1 -1
- package/vendor/runtime/dist/prompts/chat.js +15 -1
- package/vendor/runtime/dist/prompts/dayPlanning.d.ts +44 -0
- package/vendor/runtime/dist/prompts/dayPlanning.d.ts.map +1 -0
- package/vendor/runtime/dist/prompts/dayPlanning.js +42 -0
- package/vendor/runtime/dist/prompts/projectCapture.d.ts +7 -0
- package/vendor/runtime/dist/prompts/projectCapture.d.ts.map +1 -0
- package/vendor/runtime/dist/prompts/projectCapture.js +31 -0
- package/vendor/runtime/src/executor/claudeAgent.ts +137 -7
- package/vendor/runtime/src/executor/claudeCode.ts +6 -4
- package/vendor/runtime/src/executor/codex.ts +281 -20
- package/vendor/runtime/src/executor/codexProtocol/PlanType.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/CreditsSnapshot.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/GetAccountRateLimitsResponse.ts +25 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitReachedType.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitResetCredit.ts +27 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitResetCreditStatus.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitResetCreditsSummary.ts +14 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitResetType.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitSnapshot.ts +14 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitWindow.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/ReviewDelivery.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/ReviewStartParams.ts +12 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/ReviewTarget.ts +9 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/SkillDependencies.ts +6 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/SkillErrorInfo.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/SkillInterface.ts +14 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/SkillMetadata.ts +17 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/SkillScope.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/SkillToolDependency.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/SkillsListEntry.ts +7 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/SkillsListResponse.ts +6 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/SpendControlLimitSnapshot.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/ThreadSetNameParams.ts +5 -0
- package/vendor/runtime/src/executor/health.ts +3 -0
- package/vendor/runtime/src/executor/liveTurns.ts +3 -0
- package/vendor/runtime/src/executor/providerRouter.ts +2 -1
- package/vendor/runtime/src/executor/types.ts +10 -0
- package/vendor/runtime/src/harness/index.ts +51 -6
- package/vendor/runtime/src/harness/types.ts +5 -1
- package/vendor/runtime/src/index.ts +4 -1
- package/vendor/runtime/src/journal/context.ts +40 -7
- package/vendor/runtime/src/prompts/briefing.ts +62 -17
- package/vendor/runtime/src/prompts/cardStatement.ts +64 -0
- package/vendor/runtime/src/prompts/chat.ts +25 -3
- package/vendor/runtime/src/prompts/dayPlanning.ts +46 -0
- package/vendor/runtime/src/prompts/projectCapture.ts +51 -0
- package/vendor/shared/dist/agentCommands.d.ts +22 -0
- package/vendor/shared/dist/agentCommands.d.ts.map +1 -0
- package/vendor/shared/dist/agentCommands.js +11 -0
- package/vendor/shared/dist/automationTemplates.d.ts +37 -0
- package/vendor/shared/dist/automationTemplates.d.ts.map +1 -0
- package/vendor/shared/dist/automationTemplates.js +48 -0
- package/vendor/shared/dist/automations.d.ts +1052 -0
- package/vendor/shared/dist/automations.d.ts.map +1 -0
- package/vendor/shared/dist/automations.js +300 -0
- package/vendor/shared/dist/cardStatement.d.ts +28 -0
- package/vendor/shared/dist/cardStatement.d.ts.map +1 -0
- package/vendor/shared/dist/cardStatement.js +37 -0
- package/vendor/shared/dist/cardStudio.d.ts +756 -0
- package/vendor/shared/dist/cardStudio.d.ts.map +1 -0
- package/vendor/shared/dist/cardStudio.js +297 -0
- package/vendor/shared/dist/commandLocal.d.ts +218 -0
- package/vendor/shared/dist/commandLocal.d.ts.map +1 -0
- package/vendor/shared/dist/commandLocal.js +664 -0
- package/vendor/shared/dist/commandText.d.ts +12 -0
- package/vendor/shared/dist/commandText.d.ts.map +1 -0
- package/vendor/shared/dist/commandText.js +21 -0
- package/vendor/shared/dist/commands.d.ts +1534 -0
- package/vendor/shared/dist/commands.d.ts.map +1 -0
- package/vendor/shared/dist/commands.js +233 -0
- package/vendor/shared/dist/computer.d.ts +9 -9
- package/vendor/shared/dist/computer.d.ts.map +1 -1
- package/vendor/shared/dist/computer.js +12 -2
- 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 +9 -2
- package/vendor/shared/dist/dayPlan.d.ts +86 -0
- package/vendor/shared/dist/dayPlan.d.ts.map +1 -0
- package/vendor/shared/dist/dayPlan.js +46 -0
- package/vendor/shared/dist/dayPlanning.d.ts +139 -0
- package/vendor/shared/dist/dayPlanning.d.ts.map +1 -0
- package/vendor/shared/dist/dayPlanning.js +67 -0
- package/vendor/shared/dist/githubContributions.d.ts +93 -0
- package/vendor/shared/dist/githubContributions.d.ts.map +1 -0
- package/vendor/shared/dist/githubContributions.js +54 -0
- package/vendor/shared/dist/habitContributions.d.ts +26 -0
- package/vendor/shared/dist/habitContributions.d.ts.map +1 -0
- package/vendor/shared/dist/habitContributions.js +119 -0
- package/vendor/shared/dist/index.d.ts +28 -2
- package/vendor/shared/dist/index.d.ts.map +1 -1
- package/vendor/shared/dist/index.js +25 -2
- package/vendor/shared/dist/journal-migration.d.ts +29 -0
- package/vendor/shared/dist/journal-migration.d.ts.map +1 -0
- package/vendor/shared/dist/journal-migration.js +73 -0
- package/vendor/shared/dist/journal-vault.d.ts +414 -0
- package/vendor/shared/dist/journal-vault.d.ts.map +1 -0
- package/vendor/shared/dist/journal-vault.js +972 -0
- package/vendor/shared/dist/projectCapture.d.ts +73 -0
- package/vendor/shared/dist/projectCapture.d.ts.map +1 -0
- package/vendor/shared/dist/projectCapture.js +66 -0
- package/vendor/shared/dist/quickAdd.d.ts +90 -0
- package/vendor/shared/dist/quickAdd.d.ts.map +1 -0
- package/vendor/shared/dist/quickAdd.js +260 -0
- package/vendor/shared/dist/recurrence.d.ts +44 -0
- package/vendor/shared/dist/recurrence.d.ts.map +1 -0
- package/vendor/shared/dist/recurrence.js +37 -0
- package/vendor/shared/dist/reminderWords.d.ts +11 -0
- package/vendor/shared/dist/reminderWords.d.ts.map +1 -0
- package/vendor/shared/dist/reminderWords.js +63 -0
- package/vendor/shared/dist/schemas/comment.d.ts +13 -1
- package/vendor/shared/dist/schemas/comment.d.ts.map +1 -1
- package/vendor/shared/dist/schemas/comment.js +5 -0
- package/vendor/shared/dist/schemas/conversation.d.ts +3 -3
- package/vendor/shared/dist/schemas/harness.d.ts +976 -59
- package/vendor/shared/dist/schemas/harness.d.ts.map +1 -1
- package/vendor/shared/dist/schemas/harness.js +124 -3
- package/vendor/shared/dist/schemas/journal.d.ts +10 -0
- package/vendor/shared/dist/schemas/journal.d.ts.map +1 -1
- package/vendor/shared/dist/schemas/journal.js +10 -2
- package/vendor/shared/dist/schemas/notification.d.ts +1 -1
- package/vendor/shared/dist/schemas/organization.d.ts +3 -2
- package/vendor/shared/dist/schemas/organization.d.ts.map +1 -1
- package/vendor/shared/dist/schemas/organization.js +3 -2
- package/vendor/shared/dist/schemas/proposal.d.ts +7 -3
- package/vendor/shared/dist/schemas/proposal.d.ts.map +1 -1
- package/vendor/shared/dist/schemas/proposal.js +2 -1
- package/vendor/shared/dist/schemas/request.d.ts +44 -4
- package/vendor/shared/dist/schemas/request.d.ts.map +1 -1
- package/vendor/shared/dist/schemas/task.d.ts +83 -8
- package/vendor/shared/dist/schemas/task.d.ts.map +1 -1
- package/vendor/shared/dist/schemas/task.js +20 -2
- package/vendor/shared/dist/schemas/timeSession.d.ts +2 -2
- package/vendor/shared/dist/smartCapture.d.ts +60 -0
- package/vendor/shared/dist/smartCapture.d.ts.map +1 -0
- package/vendor/shared/dist/smartCapture.js +56 -0
- package/vendor/shared/dist/speech.d.ts +39 -0
- package/vendor/shared/dist/speech.d.ts.map +1 -0
- package/vendor/shared/dist/speech.js +36 -0
- package/vendor/shared/dist/spokenNames.d.ts +25 -0
- package/vendor/shared/dist/spokenNames.d.ts.map +1 -0
- package/vendor/shared/dist/spokenNames.js +120 -0
- package/vendor/shared/dist/taskActivity.d.ts +76 -0
- package/vendor/shared/dist/taskActivity.d.ts.map +1 -0
- package/vendor/shared/dist/taskActivity.js +27 -0
- package/vendor/shared/dist/vault-search.d.ts +50 -0
- package/vendor/shared/dist/vault-search.d.ts.map +1 -0
- package/vendor/shared/dist/vault-search.js +177 -0
- package/vendor/shared/dist/voiceCapture.d.ts +32 -0
- package/vendor/shared/dist/voiceCapture.d.ts.map +1 -0
- package/vendor/shared/dist/voiceCapture.js +29 -0
- package/vendor/shared/package.json +4 -0
- package/vendor/shared/src/agentCommands.ts +35 -0
- package/vendor/shared/src/automationTemplates.ts +54 -0
- package/vendor/shared/src/automations.ts +329 -0
- package/vendor/shared/src/cardStatement.ts +49 -0
- package/vendor/shared/src/cardStudio.ts +340 -0
- package/vendor/shared/src/commandLocal.ts +740 -0
- package/vendor/shared/src/commandText.ts +25 -0
- package/vendor/shared/src/commands.ts +255 -0
- package/vendor/shared/src/computer.ts +25 -6
- package/vendor/shared/src/constants.ts +9 -2
- package/vendor/shared/src/dayPlan.ts +81 -0
- package/vendor/shared/src/dayPlanning.ts +77 -0
- package/vendor/shared/src/githubContributions.ts +70 -0
- package/vendor/shared/src/habitContributions.ts +144 -0
- package/vendor/shared/src/index.ts +44 -1
- package/vendor/shared/src/journal-migration.ts +130 -0
- package/vendor/shared/src/journal-vault.ts +1240 -0
- package/vendor/shared/src/projectCapture.ts +86 -0
- package/vendor/shared/src/quickAdd.ts +310 -0
- package/vendor/shared/src/recurrence.ts +37 -0
- package/vendor/shared/src/reminderWords.ts +54 -0
- package/vendor/shared/src/schemas/comment.ts +5 -0
- package/vendor/shared/src/schemas/harness.ts +146 -7
- package/vendor/shared/src/schemas/journal.ts +15 -6
- package/vendor/shared/src/schemas/organization.ts +3 -2
- package/vendor/shared/src/schemas/proposal.ts +6 -1
- package/vendor/shared/src/schemas/task.ts +20 -2
- package/vendor/shared/src/smartCapture.ts +67 -0
- package/vendor/shared/src/speech.ts +44 -0
- package/vendor/shared/src/spokenNames.ts +128 -0
- package/vendor/shared/src/taskActivity.ts +34 -0
- package/vendor/shared/src/vault-search.ts +243 -0
- package/vendor/shared/src/voiceCapture.ts +34 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mkdirSync,
|
|
3
|
+
readFileSync,
|
|
4
|
+
readdirSync,
|
|
5
|
+
renameSync,
|
|
6
|
+
writeFileSync,
|
|
7
|
+
statSync,
|
|
8
|
+
unlinkSync,
|
|
9
|
+
} from 'node:fs';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { HarnessRequestSchema, type HarnessRequest } from '@lucidity/shared';
|
|
12
|
+
import type { TurnLogStore } from '../turnLog.js';
|
|
13
|
+
import { LaneQueue } from '../queue.js';
|
|
14
|
+
|
|
15
|
+
type Request = Extract<HarnessRequest, { kind: 'ask' | 'code' }>;
|
|
16
|
+
type Entry = {
|
|
17
|
+
request: Request;
|
|
18
|
+
state: 'queued' | 'running' | 'steering' | 'done' | 'failed' | 'skipped';
|
|
19
|
+
action?: 'cancel' | 'steer';
|
|
20
|
+
resume?: string;
|
|
21
|
+
};
|
|
22
|
+
export function turnLane(req: Request): string {
|
|
23
|
+
return req.kind === 'ask'
|
|
24
|
+
? 'room:ask'
|
|
25
|
+
: `room:code:${req.repoId}${req.workerId ? `:${req.workerId}` : ''}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Persist before acknowledgement, resolve continuity on the computer, and never replay
|
|
29
|
+
* an execution whose outcome became uncertain. The socket only observes this queue. */
|
|
30
|
+
export class DurableTurnQueue {
|
|
31
|
+
private entries = new Map<string, Entry>();
|
|
32
|
+
private scheduled = new Set<string>();
|
|
33
|
+
private stopped = false;
|
|
34
|
+
private pumping = false;
|
|
35
|
+
constructor(
|
|
36
|
+
private readonly deps: {
|
|
37
|
+
dir: string;
|
|
38
|
+
logs: TurnLogStore;
|
|
39
|
+
lanes: LaneQueue;
|
|
40
|
+
sendRaw: (frame: unknown) => void;
|
|
41
|
+
execute: (request: Request) => Promise<void>;
|
|
42
|
+
steer?: (targetId: string, prompt: string) => Promise<void>;
|
|
43
|
+
},
|
|
44
|
+
) {
|
|
45
|
+
mkdirSync(deps.dir, { recursive: true, mode: 0o700 });
|
|
46
|
+
for (const name of readdirSync(deps.dir)
|
|
47
|
+
.filter((name) => name.endsWith('.json'))
|
|
48
|
+
.sort()) {
|
|
49
|
+
const entry = JSON.parse(
|
|
50
|
+
readFileSync(join(deps.dir, name), 'utf8'),
|
|
51
|
+
) as Entry;
|
|
52
|
+
if (
|
|
53
|
+
['done', 'failed', 'skipped'].includes(entry.state) &&
|
|
54
|
+
Date.now() - statSync(join(deps.dir, name)).mtimeMs > 24 * 60 * 60_000
|
|
55
|
+
) {
|
|
56
|
+
unlinkSync(join(deps.dir, name));
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const parsed = HarnessRequestSchema.parse(entry.request);
|
|
60
|
+
if (parsed.kind !== 'ask' && parsed.kind !== 'code')
|
|
61
|
+
throw new Error('Invalid queued turn');
|
|
62
|
+
entry.request = parsed;
|
|
63
|
+
this.entries.set(parsed.id, entry);
|
|
64
|
+
const terminal = this.terminal(parsed.id);
|
|
65
|
+
if (entry.state === 'running' || entry.state === 'steering') {
|
|
66
|
+
if (terminal?.type === 'done') {
|
|
67
|
+
this.save({
|
|
68
|
+
...entry,
|
|
69
|
+
state: 'done',
|
|
70
|
+
resume: this.session(parsed.id),
|
|
71
|
+
});
|
|
72
|
+
} else {
|
|
73
|
+
this.fail(
|
|
74
|
+
entry,
|
|
75
|
+
'Lucid restarted during this turn. It was not run again. Review the result before resending.',
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
} else if (entry.state === 'skipped' && !terminal) {
|
|
79
|
+
this.publish(parsed.id, {
|
|
80
|
+
type: 'cancelled',
|
|
81
|
+
queueAction: entry.action,
|
|
82
|
+
});
|
|
83
|
+
} else if (entry.state === 'failed' && !terminal) {
|
|
84
|
+
this.publish(parsed.id, {
|
|
85
|
+
type: 'error',
|
|
86
|
+
message:
|
|
87
|
+
'This queued turn could not finish. Review it before resending.',
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
for (const entry of this.entries.values()) {
|
|
92
|
+
const previous = entry.request.afterRequestId;
|
|
93
|
+
if (
|
|
94
|
+
entry.state === 'queued' &&
|
|
95
|
+
previous &&
|
|
96
|
+
!this.entries.has(previous) &&
|
|
97
|
+
!this.terminal(previous)
|
|
98
|
+
)
|
|
99
|
+
this.fail(
|
|
100
|
+
entry,
|
|
101
|
+
'Lucid restarted before the preceding turn finished. Review it before resending this message.',
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private save(entry: Entry): void {
|
|
107
|
+
const path = join(this.deps.dir, `${entry.request.id}.json`);
|
|
108
|
+
writeFileSync(`${path}.tmp`, JSON.stringify(entry), {
|
|
109
|
+
mode: 0o600,
|
|
110
|
+
flush: true,
|
|
111
|
+
});
|
|
112
|
+
renameSync(`${path}.tmp`, path);
|
|
113
|
+
this.entries.set(entry.request.id, entry);
|
|
114
|
+
}
|
|
115
|
+
private publish(id: string, event: Record<string, unknown>): void {
|
|
116
|
+
const frame = this.deps.logs.append(id, { ...event, requestId: id });
|
|
117
|
+
if (
|
|
118
|
+
!this.deps.logs.read(id).frames.some((saved) => saved.seq === frame.seq)
|
|
119
|
+
)
|
|
120
|
+
throw new Error('Could not save the queue receipt on this computer.');
|
|
121
|
+
this.deps.sendRaw(frame);
|
|
122
|
+
}
|
|
123
|
+
private terminal(id: string) {
|
|
124
|
+
return this.deps.logs
|
|
125
|
+
.read(id)
|
|
126
|
+
.frames.slice()
|
|
127
|
+
.reverse()
|
|
128
|
+
.find((frame) =>
|
|
129
|
+
['done', 'error', 'cancelled'].includes(String(frame.type)),
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
private session(id: string): string | undefined {
|
|
133
|
+
const frames = this.deps.logs.read(id).frames;
|
|
134
|
+
const value = frames
|
|
135
|
+
.slice()
|
|
136
|
+
.reverse()
|
|
137
|
+
.find((frame) => typeof frame.sessionId === 'string')?.sessionId;
|
|
138
|
+
return typeof value === 'string' ? value : undefined;
|
|
139
|
+
}
|
|
140
|
+
private fail(entry: Entry, message: string): void {
|
|
141
|
+
this.save({ ...entry, state: 'failed' });
|
|
142
|
+
if (!this.deps.logs.read(entry.request.id).terminated)
|
|
143
|
+
this.publish(entry.request.id, { type: 'error', message });
|
|
144
|
+
this.wake();
|
|
145
|
+
}
|
|
146
|
+
owns(id: string): boolean {
|
|
147
|
+
const state = this.entries.get(id)?.state;
|
|
148
|
+
return state === 'queued' || state === 'running' || state === 'steering';
|
|
149
|
+
}
|
|
150
|
+
confirm(id: string): void {
|
|
151
|
+
const entry = this.entries.get(id);
|
|
152
|
+
if (entry && this.owns(id))
|
|
153
|
+
this.publish(id, {
|
|
154
|
+
type: 'queue_state',
|
|
155
|
+
state: entry.state === 'running' ? 'running' : 'queued',
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
enqueue(request: Request): void {
|
|
159
|
+
if (!request.stream)
|
|
160
|
+
throw new Error('Queued turns require streaming replies.');
|
|
161
|
+
const existing = this.entries.get(request.id);
|
|
162
|
+
if (existing) {
|
|
163
|
+
if (JSON.stringify(existing.request) !== JSON.stringify(request))
|
|
164
|
+
throw new Error('Request ID already belongs to another message.');
|
|
165
|
+
for (const frame of this.deps.logs.read(request.id).frames)
|
|
166
|
+
this.deps.sendRaw(frame);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (this.deps.logs.read(request.id).exists)
|
|
170
|
+
throw new Error('This request was already submitted.');
|
|
171
|
+
if (
|
|
172
|
+
[...this.entries.values()].filter((e) => this.owns(e.request.id))
|
|
173
|
+
.length >= 100
|
|
174
|
+
)
|
|
175
|
+
throw new Error(
|
|
176
|
+
'The computer queue is full. Wait for some messages to finish.',
|
|
177
|
+
);
|
|
178
|
+
if (request.afterRequestId) {
|
|
179
|
+
const previous = this.entries.get(request.afterRequestId)?.request;
|
|
180
|
+
const receipt = this.deps.logs
|
|
181
|
+
.read(request.afterRequestId)
|
|
182
|
+
.frames.find((frame) => frame.type === 'accepted');
|
|
183
|
+
const scope =
|
|
184
|
+
previous ?? (receipt?.scope as Record<string, unknown> | undefined);
|
|
185
|
+
const same =
|
|
186
|
+
scope &&
|
|
187
|
+
(request.kind === 'ask'
|
|
188
|
+
? scope.kind === 'ask'
|
|
189
|
+
: (scope.kind === 'code' &&
|
|
190
|
+
scope.repoId === request.repoId &&
|
|
191
|
+
scope.workerId === request.workerId &&
|
|
192
|
+
(scope.mode ?? 'worktree') === (request.mode ?? 'worktree')) ||
|
|
193
|
+
(scope.kind === 'conduct' &&
|
|
194
|
+
scope.repoId === request.repoId &&
|
|
195
|
+
!!request.workerId));
|
|
196
|
+
if (!same)
|
|
197
|
+
throw new Error(
|
|
198
|
+
'The preceding turn does not belong to this conversation. Refresh it before sending again.',
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
const entry: Entry = { request, state: 'queued' };
|
|
202
|
+
this.save(entry);
|
|
203
|
+
try {
|
|
204
|
+
this.publish(request.id, { type: 'queue_state', state: 'queued' });
|
|
205
|
+
} catch (error) {
|
|
206
|
+
this.save({ ...entry, state: 'failed' });
|
|
207
|
+
throw error;
|
|
208
|
+
}
|
|
209
|
+
this.wake();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Skipped queue entries inherit their predecessor, so removing B from A→B→C
|
|
213
|
+
* never starts a new conversation or strands C. Failed executions stop dependants. */
|
|
214
|
+
private predecessor(entry: Entry): { ready: boolean; resume?: string } {
|
|
215
|
+
const id = entry.request.afterRequestId;
|
|
216
|
+
if (!id) return { ready: true, resume: entry.request.resume };
|
|
217
|
+
const previous = this.entries.get(id);
|
|
218
|
+
if (previous) {
|
|
219
|
+
if (previous.state === 'skipped') return this.predecessor(previous);
|
|
220
|
+
if (previous.state === 'failed')
|
|
221
|
+
throw new Error(
|
|
222
|
+
'The previous turn did not finish. Review it before resending this message.',
|
|
223
|
+
);
|
|
224
|
+
if (previous.state !== 'done') return { ready: false };
|
|
225
|
+
if (!previous.resume)
|
|
226
|
+
throw new Error(
|
|
227
|
+
'The previous turn has no session to continue. Start a new conversation.',
|
|
228
|
+
);
|
|
229
|
+
return { ready: true, resume: previous.resume };
|
|
230
|
+
}
|
|
231
|
+
const terminal = this.terminal(id);
|
|
232
|
+
if (!terminal) return { ready: false };
|
|
233
|
+
if (terminal.type !== 'done')
|
|
234
|
+
throw new Error(
|
|
235
|
+
'The previous turn did not finish. Review it before resending this message.',
|
|
236
|
+
);
|
|
237
|
+
const receipt = this.deps.logs
|
|
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);
|
|
250
|
+
if (!resume)
|
|
251
|
+
throw new Error(
|
|
252
|
+
'The previous turn has no session to continue. Start a new conversation.',
|
|
253
|
+
);
|
|
254
|
+
return { ready: true, resume };
|
|
255
|
+
}
|
|
256
|
+
wake(): void {
|
|
257
|
+
if (this.stopped || this.pumping) return;
|
|
258
|
+
this.pumping = true;
|
|
259
|
+
queueMicrotask(() => {
|
|
260
|
+
this.pumping = false;
|
|
261
|
+
if (this.stopped) return;
|
|
262
|
+
const occupied = new Set<string>();
|
|
263
|
+
for (const [id, entry] of this.entries) {
|
|
264
|
+
const lane = turnLane(entry.request);
|
|
265
|
+
if (!this.owns(id)) continue;
|
|
266
|
+
if (occupied.has(lane)) continue;
|
|
267
|
+
occupied.add(lane);
|
|
268
|
+
if (entry.state !== 'queued' || this.scheduled.has(id)) continue;
|
|
269
|
+
try {
|
|
270
|
+
if (!this.predecessor(entry).ready) continue;
|
|
271
|
+
} catch (error) {
|
|
272
|
+
this.fail(entry, String((error as Error).message));
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
this.scheduled.add(id);
|
|
276
|
+
void this.deps.lanes
|
|
277
|
+
.run(turnLane(entry.request), async () => {
|
|
278
|
+
const current = this.entries.get(id)!;
|
|
279
|
+
if (this.stopped || current.state !== 'queued') return;
|
|
280
|
+
const previous = this.predecessor(current);
|
|
281
|
+
if (!previous.ready) return;
|
|
282
|
+
this.save({ ...current, state: 'running' });
|
|
283
|
+
this.publish(id, { type: 'queue_state', state: 'running' });
|
|
284
|
+
await this.deps.execute({
|
|
285
|
+
...current.request,
|
|
286
|
+
resume: previous.resume,
|
|
287
|
+
queue: false,
|
|
288
|
+
afterRequestId: undefined,
|
|
289
|
+
});
|
|
290
|
+
if (this.terminal(id)?.type === 'done')
|
|
291
|
+
this.save({
|
|
292
|
+
...current,
|
|
293
|
+
state: 'done',
|
|
294
|
+
resume: this.session(id),
|
|
295
|
+
});
|
|
296
|
+
else
|
|
297
|
+
this.fail(
|
|
298
|
+
current,
|
|
299
|
+
'The turn ended before completion. Review it before resending.',
|
|
300
|
+
);
|
|
301
|
+
})
|
|
302
|
+
.catch((error) =>
|
|
303
|
+
this.fail(this.entries.get(id)!, String(error.message)),
|
|
304
|
+
)
|
|
305
|
+
.finally(() => {
|
|
306
|
+
this.scheduled.delete(id);
|
|
307
|
+
this.wake();
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
async control(
|
|
313
|
+
id: string,
|
|
314
|
+
action: 'cancel' | 'steer',
|
|
315
|
+
activeId?: string,
|
|
316
|
+
): Promise<void> {
|
|
317
|
+
const entry = this.entries.get(id);
|
|
318
|
+
if (!entry) throw new Error('This message is not in the computer queue.');
|
|
319
|
+
if (entry.state === 'skipped' && entry.action === action) {
|
|
320
|
+
const frame = this.terminal(id);
|
|
321
|
+
if (frame) this.deps.sendRaw(frame);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (entry.state !== 'queued')
|
|
325
|
+
throw new Error('This message has already started or left the queue.');
|
|
326
|
+
if (action === 'steer') {
|
|
327
|
+
if (entry.request.images?.length)
|
|
328
|
+
throw new Error('Attachments must run as a separate turn.');
|
|
329
|
+
if (!activeId || !this.deps.steer)
|
|
330
|
+
throw new Error('There is no active turn to influence.');
|
|
331
|
+
const active = this.entries.get(activeId);
|
|
332
|
+
// For a spawned fleet worker, the active request uses the worker's own ID.
|
|
333
|
+
if (
|
|
334
|
+
active
|
|
335
|
+
? turnLane(active.request) !== turnLane(entry.request) ||
|
|
336
|
+
active.state !== 'running'
|
|
337
|
+
: entry.request.kind !== 'code' || entry.request.workerId !== activeId
|
|
338
|
+
)
|
|
339
|
+
throw new Error(
|
|
340
|
+
'The active turn does not belong to this conversation.',
|
|
341
|
+
);
|
|
342
|
+
this.save({ ...entry, state: 'steering' });
|
|
343
|
+
try {
|
|
344
|
+
await this.deps.steer(activeId, entry.request.prompt);
|
|
345
|
+
} catch (error) {
|
|
346
|
+
this.save(entry);
|
|
347
|
+
this.wake();
|
|
348
|
+
throw error;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
this.save({ ...entry, state: 'skipped', action });
|
|
352
|
+
this.publish(id, { type: 'cancelled', queueAction: action });
|
|
353
|
+
this.wake();
|
|
354
|
+
}
|
|
355
|
+
stop(): void {
|
|
356
|
+
this.stopped = true;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import {
|
|
3
|
+
mkdirSync,
|
|
4
|
+
readFileSync,
|
|
5
|
+
writeFileSync,
|
|
6
|
+
renameSync,
|
|
7
|
+
readdirSync,
|
|
8
|
+
unlinkSync,
|
|
9
|
+
existsSync,
|
|
10
|
+
openSync,
|
|
11
|
+
fsyncSync,
|
|
12
|
+
closeSync,
|
|
13
|
+
} from 'node:fs';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { z } from 'zod';
|
|
16
|
+
import {
|
|
17
|
+
MAX_CAPTURE_BYTES,
|
|
18
|
+
MAX_CAPTURE_SECONDS,
|
|
19
|
+
VoiceCaptureInputSchema,
|
|
20
|
+
VoiceCaptureReceiptSchema,
|
|
21
|
+
type VoiceCaptureInput,
|
|
22
|
+
type VoiceCaptureReceipt,
|
|
23
|
+
type SpeechAudio,
|
|
24
|
+
type SpeechTranscript,
|
|
25
|
+
} from '@lucidity/shared';
|
|
26
|
+
|
|
27
|
+
const StoredSchema = z.object({
|
|
28
|
+
credentialId: z.uuid(),
|
|
29
|
+
digest: z.string().regex(/^[a-f0-9]{64}$/),
|
|
30
|
+
receipt: VoiceCaptureReceiptSchema,
|
|
31
|
+
});
|
|
32
|
+
type Stored = z.infer<typeof StoredSchema>;
|
|
33
|
+
type Options = {
|
|
34
|
+
directory: string;
|
|
35
|
+
transcribe: (
|
|
36
|
+
audio: SpeechAudio,
|
|
37
|
+
signal: AbortSignal,
|
|
38
|
+
) => Promise<SpeechTranscript>;
|
|
39
|
+
act: (transcript: string, signal: AbortSignal) => Promise<string>;
|
|
40
|
+
logger?: (message: string) => void;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** Durable acceptance precedes the HTTP acknowledgement. Never repeat an action
|
|
44
|
+
* whose outcome may have been committed before a crash or lost provider reply. */
|
|
45
|
+
export class VoiceCaptureService {
|
|
46
|
+
private readonly records = new Map<string, Stored>();
|
|
47
|
+
private readonly controller = new AbortController();
|
|
48
|
+
private running = false;
|
|
49
|
+
private faulted = false;
|
|
50
|
+
constructor(private readonly opts: Options) {
|
|
51
|
+
mkdirSync(opts.directory, { recursive: true, mode: 0o700 });
|
|
52
|
+
for (const name of readdirSync(opts.directory)) {
|
|
53
|
+
if (!name.endsWith('.json')) continue;
|
|
54
|
+
// Fail closed on a corrupt receipt. Ignoring it could replay an action.
|
|
55
|
+
const record = StoredSchema.parse(
|
|
56
|
+
JSON.parse(readFileSync(join(opts.directory, name), 'utf8')),
|
|
57
|
+
);
|
|
58
|
+
const key = this.key(record.credentialId, record.receipt.captureId);
|
|
59
|
+
if (name !== `${key}.json`)
|
|
60
|
+
throw new Error('Invalid voice capture receipt filename.');
|
|
61
|
+
if (record.receipt.state === 'acting') {
|
|
62
|
+
record.receipt = {
|
|
63
|
+
...record.receipt,
|
|
64
|
+
state: 'uncertain',
|
|
65
|
+
message:
|
|
66
|
+
'The computer restarted during this action. Check Lucidity before recording it again.',
|
|
67
|
+
updatedAt: new Date().toISOString(),
|
|
68
|
+
};
|
|
69
|
+
this.save(key, record);
|
|
70
|
+
} else if (record.receipt.state === 'transcribing') {
|
|
71
|
+
record.receipt.state = 'queued';
|
|
72
|
+
this.save(key, record);
|
|
73
|
+
}
|
|
74
|
+
this.records.set(key, record);
|
|
75
|
+
if (this.terminal(record.receipt)) this.removeAudio(key);
|
|
76
|
+
}
|
|
77
|
+
// Remove incomplete writes left before acceptance, never accepted recordings.
|
|
78
|
+
for (const name of readdirSync(opts.directory)) {
|
|
79
|
+
if (
|
|
80
|
+
name.endsWith('.tmp') ||
|
|
81
|
+
(name.endsWith('.m4a') && !this.records.has(name.slice(0, -4)))
|
|
82
|
+
)
|
|
83
|
+
unlinkSync(join(opts.directory, name));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
private key(credentialId: string, captureId: string) {
|
|
87
|
+
return `${z.uuid().parse(credentialId)}_${z.uuid().parse(captureId)}`;
|
|
88
|
+
}
|
|
89
|
+
private terminal(receipt: VoiceCaptureReceipt) {
|
|
90
|
+
return ['done', 'failed', 'uncertain'].includes(receipt.state);
|
|
91
|
+
}
|
|
92
|
+
private atomic(path: string, bytes: string | Buffer) {
|
|
93
|
+
const temporary = `${path}.tmp`;
|
|
94
|
+
writeFileSync(temporary, bytes, { mode: 0o600 });
|
|
95
|
+
const fd = openSync(temporary, 'r');
|
|
96
|
+
try {
|
|
97
|
+
fsyncSync(fd);
|
|
98
|
+
} finally {
|
|
99
|
+
closeSync(fd);
|
|
100
|
+
}
|
|
101
|
+
renameSync(temporary, path);
|
|
102
|
+
const directory = openSync(this.opts.directory, 'r');
|
|
103
|
+
try {
|
|
104
|
+
fsyncSync(directory);
|
|
105
|
+
} finally {
|
|
106
|
+
closeSync(directory);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
private save(key: string, record: Stored) {
|
|
110
|
+
this.atomic(
|
|
111
|
+
join(this.opts.directory, `${key}.json`),
|
|
112
|
+
JSON.stringify(record),
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
private removeAudio(key: string) {
|
|
116
|
+
const path = join(this.opts.directory, `${key}.m4a`);
|
|
117
|
+
if (existsSync(path)) unlinkSync(path);
|
|
118
|
+
}
|
|
119
|
+
status(credentialId: string, captureId: string): VoiceCaptureReceipt | null {
|
|
120
|
+
const receipt = this.records.get(
|
|
121
|
+
this.key(credentialId, captureId),
|
|
122
|
+
)?.receipt;
|
|
123
|
+
return receipt ? { ...receipt } : null;
|
|
124
|
+
}
|
|
125
|
+
submit(credentialId: string, input: VoiceCaptureInput): VoiceCaptureReceipt {
|
|
126
|
+
const parsed = VoiceCaptureInputSchema.parse(input);
|
|
127
|
+
const key = this.key(credentialId, parsed.captureId);
|
|
128
|
+
const bytes = Buffer.from(parsed.audio.base64, 'base64');
|
|
129
|
+
if (
|
|
130
|
+
!bytes.length ||
|
|
131
|
+
bytes.length > MAX_CAPTURE_BYTES ||
|
|
132
|
+
bytes.toString('base64') !== parsed.audio.base64
|
|
133
|
+
)
|
|
134
|
+
throw new Error('The recording is incomplete or larger than 2 MB.');
|
|
135
|
+
const digest = createHash('sha256').update(bytes).digest('hex');
|
|
136
|
+
const previous = this.records.get(key);
|
|
137
|
+
if (previous) {
|
|
138
|
+
if (previous.digest !== digest)
|
|
139
|
+
throw new Error(
|
|
140
|
+
'This capture ID already belongs to another recording.',
|
|
141
|
+
);
|
|
142
|
+
return { ...previous.receipt };
|
|
143
|
+
}
|
|
144
|
+
if (this.faulted)
|
|
145
|
+
throw new Error(
|
|
146
|
+
'Voice capture storage needs attention on your computer.',
|
|
147
|
+
);
|
|
148
|
+
if (this.controller.signal.aborted)
|
|
149
|
+
throw new Error(
|
|
150
|
+
'The computer is shutting down. Keep the recording and retry.',
|
|
151
|
+
);
|
|
152
|
+
if (
|
|
153
|
+
[...this.records.values()].filter((r) => !this.terminal(r.receipt))
|
|
154
|
+
.length >= 20
|
|
155
|
+
)
|
|
156
|
+
throw new Error(
|
|
157
|
+
'The computer capture queue is full. Keep the recording and retry later.',
|
|
158
|
+
);
|
|
159
|
+
const record: Stored = {
|
|
160
|
+
credentialId,
|
|
161
|
+
digest,
|
|
162
|
+
receipt: {
|
|
163
|
+
captureId: parsed.captureId,
|
|
164
|
+
state: 'queued',
|
|
165
|
+
updatedAt: new Date().toISOString(),
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
this.atomic(join(this.opts.directory, `${key}.m4a`), bytes);
|
|
169
|
+
this.save(key, record);
|
|
170
|
+
this.records.set(key, record);
|
|
171
|
+
this.wake();
|
|
172
|
+
return { ...record.receipt };
|
|
173
|
+
}
|
|
174
|
+
wake() {
|
|
175
|
+
if (this.running || this.faulted || this.controller.signal.aborted) return;
|
|
176
|
+
this.running = true;
|
|
177
|
+
// Defer so acceptance can reach the client before model loading starts.
|
|
178
|
+
void Promise.resolve()
|
|
179
|
+
.then(() => this.drain())
|
|
180
|
+
.catch(() => {
|
|
181
|
+
this.faulted = true;
|
|
182
|
+
this.opts.logger?.(
|
|
183
|
+
'Voice capture processing stopped because a receipt could not be saved.',
|
|
184
|
+
);
|
|
185
|
+
})
|
|
186
|
+
.finally(() => {
|
|
187
|
+
this.running = false;
|
|
188
|
+
if (
|
|
189
|
+
[...this.records.values()].some(
|
|
190
|
+
(record) => record.receipt.state === 'queued',
|
|
191
|
+
)
|
|
192
|
+
)
|
|
193
|
+
this.wake();
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
private update(
|
|
197
|
+
key: string,
|
|
198
|
+
record: Stored,
|
|
199
|
+
patch: Partial<VoiceCaptureReceipt>,
|
|
200
|
+
) {
|
|
201
|
+
const next = {
|
|
202
|
+
...record,
|
|
203
|
+
receipt: {
|
|
204
|
+
...record.receipt,
|
|
205
|
+
...patch,
|
|
206
|
+
updatedAt: new Date().toISOString(),
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
this.save(key, next);
|
|
210
|
+
this.records.set(key, next);
|
|
211
|
+
return next;
|
|
212
|
+
}
|
|
213
|
+
private async drain() {
|
|
214
|
+
for (const [key, original] of this.records) {
|
|
215
|
+
if (this.controller.signal.aborted) return;
|
|
216
|
+
if (original.receipt.state !== 'queued') continue;
|
|
217
|
+
let record = original;
|
|
218
|
+
let actionStarted = false;
|
|
219
|
+
try {
|
|
220
|
+
const signal = this.controller.signal;
|
|
221
|
+
record = this.update(key, record, { state: 'transcribing' });
|
|
222
|
+
const audio = readFileSync(join(this.opts.directory, `${key}.m4a`));
|
|
223
|
+
const transcript = await this.opts.transcribe(
|
|
224
|
+
{ format: 'm4a', base64: audio.toString('base64') },
|
|
225
|
+
signal,
|
|
226
|
+
);
|
|
227
|
+
signal.throwIfAborted();
|
|
228
|
+
if (
|
|
229
|
+
transcript.durationSeconds > MAX_CAPTURE_SECONDS ||
|
|
230
|
+
!transcript.text.trim() ||
|
|
231
|
+
transcript.text.length > 8000
|
|
232
|
+
)
|
|
233
|
+
throw new Error('Record a shorter instruction, up to two minutes.');
|
|
234
|
+
record = this.update(key, record, {
|
|
235
|
+
state: 'acting',
|
|
236
|
+
transcript: transcript.text,
|
|
237
|
+
});
|
|
238
|
+
actionStarted = true;
|
|
239
|
+
this.removeAudio(key);
|
|
240
|
+
const result = await this.opts.act(transcript.text, signal);
|
|
241
|
+
signal.throwIfAborted();
|
|
242
|
+
record = this.update(key, record, {
|
|
243
|
+
state: 'done',
|
|
244
|
+
result: result.slice(0, 4000),
|
|
245
|
+
});
|
|
246
|
+
} catch {
|
|
247
|
+
if (this.controller.signal.aborted && !actionStarted) {
|
|
248
|
+
this.update(key, record, { state: 'queued' });
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
// An action may already have caused effects. Do not offer automatic retry.
|
|
252
|
+
record = this.update(key, record, {
|
|
253
|
+
state: actionStarted ? 'uncertain' : 'failed',
|
|
254
|
+
message: actionStarted
|
|
255
|
+
? 'The action could not be confirmed. Check Lucidity before recording it again.'
|
|
256
|
+
: 'The recording could not be processed. Check speech recognition on your computer.',
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
if (this.terminal(record.receipt)) this.removeAudio(key);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
stop() {
|
|
263
|
+
this.controller.abort();
|
|
264
|
+
}
|
|
265
|
+
}
|