@opencorelabs/lucidity 0.3.0 → 0.6.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 +9 -2
- 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 +179 -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 +262 -45
- package/dist/room/computer.d.ts.map +1 -1
- package/dist/room/computer.js +8 -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 +196 -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 +316 -52
- package/src/room/computer.ts +8 -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/gate.d.ts +12 -0
- package/vendor/decisions/dist/gate.js +18 -0
- package/vendor/decisions/dist/index.d.ts +5 -0
- package/vendor/decisions/dist/index.js +5 -0
- package/vendor/decisions/dist/jev.d.ts +15 -0
- package/vendor/decisions/dist/jev.js +242 -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/gate.ts +32 -0
- package/vendor/decisions/src/index.ts +5 -0
- package/vendor/decisions/src/jev.ts +293 -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 +113 -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 +213 -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 +8 -0
- package/vendor/runtime/dist/executor/types.d.ts.map +1 -1
- package/vendor/runtime/dist/harness/index.d.ts +1 -0
- package/vendor/runtime/dist/harness/index.d.ts.map +1 -1
- package/vendor/runtime/dist/harness/index.js +35 -1
- package/vendor/runtime/dist/harness/types.d.ts +4 -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/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 +133 -7
- package/vendor/runtime/src/executor/claudeCode.ts +6 -4
- package/vendor/runtime/src/executor/codex.ts +280 -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 +8 -0
- package/vendor/runtime/src/harness/index.ts +40 -6
- package/vendor/runtime/src/harness/types.ts +4 -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/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 +662 -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 +1516 -0
- package/vendor/shared/dist/commands.d.ts.map +1 -0
- package/vendor/shared/dist/commands.js +231 -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 +11 -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/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 +26 -2
- package/vendor/shared/dist/index.d.ts.map +1 -1
- package/vendor/shared/dist/index.js +23 -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 +922 -59
- package/vendor/shared/dist/schemas/harness.d.ts.map +1 -1
- package/vendor/shared/dist/schemas/harness.js +122 -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 +738 -0
- package/vendor/shared/src/commandText.ts +25 -0
- package/vendor/shared/src/commands.ts +253 -0
- package/vendor/shared/src/computer.ts +23 -6
- package/vendor/shared/src/constants.ts +9 -2
- package/vendor/shared/src/githubContributions.ts +70 -0
- package/vendor/shared/src/habitContributions.ts +144 -0
- package/vendor/shared/src/index.ts +42 -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 +144 -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,972 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { CreateJournalSegmentSchema, JournalDaySchema, JournalSegmentSchema, JournalObservationSchema, CorrectJournalSegmentSchema, } from './schemas/journal.js';
|
|
3
|
+
import { ProposalWithEvidenceSchema, ProposalSchema, TaskProposalPayloadSchema, LinkProposalPayloadSchema, } from './schemas/proposal.js';
|
|
4
|
+
/** Reserved application records. Portable exports belong outside this directory. */
|
|
5
|
+
export const JOURNAL_RECORDS = 'Journal/Records/';
|
|
6
|
+
export function isJournalRecordPath(path) {
|
|
7
|
+
const parts = [];
|
|
8
|
+
for (const part of path.replaceAll('\\', '/').split('/')) {
|
|
9
|
+
if (!part || part === '.')
|
|
10
|
+
continue;
|
|
11
|
+
if (part === '..')
|
|
12
|
+
parts.pop();
|
|
13
|
+
else
|
|
14
|
+
parts.push(part);
|
|
15
|
+
}
|
|
16
|
+
const normalized = parts.join('/').toLowerCase();
|
|
17
|
+
return (normalized === 'journal/records' ||
|
|
18
|
+
normalized.startsWith('journal/records/'));
|
|
19
|
+
}
|
|
20
|
+
const sha = z.string().regex(/^[a-f0-9]{64}$/);
|
|
21
|
+
const common = { version: z.literal(1), owner: z.uuidv7(), id: z.uuidv7() };
|
|
22
|
+
const recordSchema = z.discriminatedUnion('kind', [
|
|
23
|
+
z.object({
|
|
24
|
+
...common,
|
|
25
|
+
kind: z.literal('capture'),
|
|
26
|
+
segment: JournalSegmentSchema.omit({
|
|
27
|
+
transcript: true,
|
|
28
|
+
correctedTranscript: true,
|
|
29
|
+
}),
|
|
30
|
+
day: JournalDaySchema,
|
|
31
|
+
bodyHash: sha,
|
|
32
|
+
}),
|
|
33
|
+
z.object({
|
|
34
|
+
...common,
|
|
35
|
+
kind: z.literal('correction'),
|
|
36
|
+
segmentId: z.uuidv7(),
|
|
37
|
+
parents: z.array(sha).min(1),
|
|
38
|
+
at: z.coerce.date(),
|
|
39
|
+
revert: z.boolean(),
|
|
40
|
+
bodyHash: sha,
|
|
41
|
+
}),
|
|
42
|
+
z.object({
|
|
43
|
+
...common,
|
|
44
|
+
kind: z.literal('deletion'),
|
|
45
|
+
segmentId: z.uuidv7(),
|
|
46
|
+
at: z.coerce.date(),
|
|
47
|
+
}),
|
|
48
|
+
z.object({
|
|
49
|
+
...common,
|
|
50
|
+
kind: z.literal('extraction'),
|
|
51
|
+
segmentId: z.uuidv7(),
|
|
52
|
+
revision: sha,
|
|
53
|
+
extractorVersion: z.string(),
|
|
54
|
+
at: z.coerce.date(),
|
|
55
|
+
model: z.string().optional(),
|
|
56
|
+
error: z.string().optional(),
|
|
57
|
+
observations: z.array(JournalObservationSchema),
|
|
58
|
+
proposals: z.array(ProposalWithEvidenceSchema),
|
|
59
|
+
legacyStamp: z.unknown().optional(),
|
|
60
|
+
}),
|
|
61
|
+
z.object({
|
|
62
|
+
...common,
|
|
63
|
+
kind: z.literal('decision'),
|
|
64
|
+
proposalId: z.uuidv7(),
|
|
65
|
+
segmentId: z.uuidv7().nullable(),
|
|
66
|
+
status: z.enum(['accepting', 'accepted', 'rejected']),
|
|
67
|
+
at: z.coerce.date(),
|
|
68
|
+
payload: z.unknown(),
|
|
69
|
+
resultId: z.uuidv7().nullable(),
|
|
70
|
+
reason: z.string().nullable(),
|
|
71
|
+
}),
|
|
72
|
+
z.object({
|
|
73
|
+
...common,
|
|
74
|
+
kind: z.literal('legacy-proposal'),
|
|
75
|
+
proposal: ProposalWithEvidenceSchema,
|
|
76
|
+
segmentId: z.uuidv7().nullable(),
|
|
77
|
+
}),
|
|
78
|
+
z.object({ ...common, kind: z.literal('legacy-day'), day: JournalDaySchema }),
|
|
79
|
+
z.object({
|
|
80
|
+
...common,
|
|
81
|
+
kind: z.literal('activation'),
|
|
82
|
+
sourceDigest: sha,
|
|
83
|
+
vaultDigest: sha,
|
|
84
|
+
files: z
|
|
85
|
+
.array(z.object({
|
|
86
|
+
path: z.string(),
|
|
87
|
+
hash: sha,
|
|
88
|
+
segmentId: z.uuidv7().optional(),
|
|
89
|
+
}))
|
|
90
|
+
.default([]),
|
|
91
|
+
}),
|
|
92
|
+
]);
|
|
93
|
+
export class JournalVaultError extends Error {
|
|
94
|
+
code;
|
|
95
|
+
constructor(code, message) {
|
|
96
|
+
super(message);
|
|
97
|
+
this.code = code;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const invalid = () => new JournalVaultError('invalid', 'A Journal record needs attention. Its original file has been preserved.');
|
|
101
|
+
const prefix = '<!-- lucidity-journal-v1 ';
|
|
102
|
+
/** Immutable files plus a disposable index; no HTTP client or hosted fallback. */
|
|
103
|
+
export class JournalVault {
|
|
104
|
+
owner;
|
|
105
|
+
files;
|
|
106
|
+
index;
|
|
107
|
+
records = new Map();
|
|
108
|
+
scope = '';
|
|
109
|
+
revoked = false;
|
|
110
|
+
unresolved = 0;
|
|
111
|
+
serial = Promise.resolve();
|
|
112
|
+
listeners = new Set();
|
|
113
|
+
state = { version: 0, pending: 0, ready: false, error: '' };
|
|
114
|
+
constructor(owner, files, index) {
|
|
115
|
+
this.owner = owner;
|
|
116
|
+
this.files = files;
|
|
117
|
+
this.index = index;
|
|
118
|
+
z.uuidv7().parse(owner);
|
|
119
|
+
}
|
|
120
|
+
get root() {
|
|
121
|
+
return `${JOURNAL_RECORDS}${this.owner}/`;
|
|
122
|
+
}
|
|
123
|
+
get storageScope() {
|
|
124
|
+
return this.scope;
|
|
125
|
+
}
|
|
126
|
+
getSnapshot = () => this.state;
|
|
127
|
+
subscribe = (fn) => {
|
|
128
|
+
this.listeners.add(fn);
|
|
129
|
+
return () => {
|
|
130
|
+
this.listeners.delete(fn);
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
publish(next) {
|
|
134
|
+
this.state = { ...this.state, ...next, version: this.state.version + 1 };
|
|
135
|
+
this.listeners.forEach((fn) => fn());
|
|
136
|
+
}
|
|
137
|
+
run(fn) {
|
|
138
|
+
const work = this.serial.then(fn, fn);
|
|
139
|
+
this.serial = work.catch(() => { });
|
|
140
|
+
return work;
|
|
141
|
+
}
|
|
142
|
+
async session() {
|
|
143
|
+
if (this.revoked)
|
|
144
|
+
throw new JournalVaultError('changed', 'Reopen Journal to connect the current vault account.');
|
|
145
|
+
let scope;
|
|
146
|
+
try {
|
|
147
|
+
scope = await this.files.scope();
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
this.records.clear();
|
|
151
|
+
if (error instanceof JournalVaultError && error.code === 'changed')
|
|
152
|
+
this.revoked = true;
|
|
153
|
+
if (this.scope)
|
|
154
|
+
await (await this.index?.())?.clear(`${this.scope}:journal:${this.owner}`);
|
|
155
|
+
this.publish({
|
|
156
|
+
ready: false,
|
|
157
|
+
error: 'Your Journal vault is unavailable. Reconnect the original account.',
|
|
158
|
+
});
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
if (!scope)
|
|
162
|
+
throw new JournalVaultError('unavailable', 'Connect your personal vault to use Journal.');
|
|
163
|
+
if (this.scope && this.scope !== scope) {
|
|
164
|
+
const previous = this.scope;
|
|
165
|
+
this.records.clear();
|
|
166
|
+
this.revoked = true;
|
|
167
|
+
await (await this.index?.())?.clear(`${previous}:journal:${this.owner}`);
|
|
168
|
+
this.publish({
|
|
169
|
+
ready: false,
|
|
170
|
+
error: 'The vault account changed. Reopen Journal to connect this account.',
|
|
171
|
+
});
|
|
172
|
+
throw new JournalVaultError('changed', this.state.error);
|
|
173
|
+
}
|
|
174
|
+
this.scope = scope;
|
|
175
|
+
return scope;
|
|
176
|
+
}
|
|
177
|
+
async check(scope) {
|
|
178
|
+
if (scope !== (await this.session())) {
|
|
179
|
+
this.records.clear();
|
|
180
|
+
this.revoked = true;
|
|
181
|
+
this.publish({ ready: false });
|
|
182
|
+
throw new JournalVaultError('changed', 'The vault account changed. Your capture has not been saved to the new account.');
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async encode(record, body = '') {
|
|
186
|
+
const metadata = JSON.stringify(recordSchema.parse(record))
|
|
187
|
+
.replaceAll('<', '\\u003c')
|
|
188
|
+
.replaceAll('>', '\\u003e');
|
|
189
|
+
return `${prefix}${metadata} -->\n\n${body}`;
|
|
190
|
+
}
|
|
191
|
+
async decode(path, content) {
|
|
192
|
+
const end = content.indexOf(' -->\n\n');
|
|
193
|
+
if (!content.startsWith(prefix) || end < 0)
|
|
194
|
+
throw invalid();
|
|
195
|
+
let record;
|
|
196
|
+
try {
|
|
197
|
+
record = recordSchema.parse(JSON.parse(content.slice(prefix.length, end)));
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
throw invalid();
|
|
201
|
+
}
|
|
202
|
+
const body = content.slice(end + ' -->\n\n'.length);
|
|
203
|
+
if (record.owner !== this.owner)
|
|
204
|
+
throw invalid();
|
|
205
|
+
if ('bodyHash' in record &&
|
|
206
|
+
(await this.files.hash(body)) !== record.bodyHash)
|
|
207
|
+
throw invalid();
|
|
208
|
+
if (record.kind === 'capture' &&
|
|
209
|
+
(record.segment.userId !== this.owner ||
|
|
210
|
+
record.day.userId !== this.owner ||
|
|
211
|
+
record.segment.dayId !== record.day.id ||
|
|
212
|
+
record.segment.id !== record.id))
|
|
213
|
+
throw invalid();
|
|
214
|
+
if (path !== this.path(record))
|
|
215
|
+
throw invalid();
|
|
216
|
+
return { path, record, body, revision: await this.files.hash(content) };
|
|
217
|
+
}
|
|
218
|
+
path(record) {
|
|
219
|
+
switch (record.kind) {
|
|
220
|
+
case 'capture':
|
|
221
|
+
return `${this.root}captures/${record.day.localDate.replaceAll('-', '/')}/${record.id}.md`;
|
|
222
|
+
case 'correction':
|
|
223
|
+
return `${this.root}corrections/${record.segmentId}/${record.id}.md`;
|
|
224
|
+
case 'deletion':
|
|
225
|
+
return `${this.root}deletions/${record.segmentId}.md`;
|
|
226
|
+
case 'extraction':
|
|
227
|
+
return `${this.root}extractions/${record.segmentId}/${record.id}.md`;
|
|
228
|
+
case 'decision':
|
|
229
|
+
return `${this.root}decisions/${record.proposalId}/${record.id}.md`;
|
|
230
|
+
case 'legacy-proposal':
|
|
231
|
+
return `${this.root}imports/proposals/${record.id}.md`;
|
|
232
|
+
case 'legacy-day':
|
|
233
|
+
return `${this.root}imports/days/${record.id}.md`;
|
|
234
|
+
case 'activation':
|
|
235
|
+
return `${this.root}activation/${record.id}.md`;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async commit(record, body = '') {
|
|
239
|
+
const scope = await this.session();
|
|
240
|
+
const path = this.path(record), content = await this.encode(record, body);
|
|
241
|
+
await this.check(scope);
|
|
242
|
+
try {
|
|
243
|
+
await this.files.create(path, content);
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
// A response may be lost after a successful create. Only identical bytes are a retry.
|
|
247
|
+
let existing;
|
|
248
|
+
try {
|
|
249
|
+
existing = await this.files.read(path);
|
|
250
|
+
}
|
|
251
|
+
catch {
|
|
252
|
+
throw error;
|
|
253
|
+
}
|
|
254
|
+
if (existing !== content)
|
|
255
|
+
throw new JournalVaultError('conflict', 'A different Journal record already exists. Both copies have been preserved.');
|
|
256
|
+
}
|
|
257
|
+
await this.check(scope);
|
|
258
|
+
if ((await this.files.read(path)) !== content)
|
|
259
|
+
throw invalid();
|
|
260
|
+
this.records.set(path, {
|
|
261
|
+
...(await this.decode(path, content)),
|
|
262
|
+
content,
|
|
263
|
+
fingerprint: '',
|
|
264
|
+
});
|
|
265
|
+
return path;
|
|
266
|
+
}
|
|
267
|
+
refresh = () => this.run(() => this.reconcile());
|
|
268
|
+
async reconcile() {
|
|
269
|
+
const scope = await this.session();
|
|
270
|
+
try {
|
|
271
|
+
const files = (await this.files.list()).filter((file) => file.path.startsWith(this.root));
|
|
272
|
+
await this.check(scope);
|
|
273
|
+
const paths = new Set(files.map((file) => file.path));
|
|
274
|
+
for (const path of this.records.keys())
|
|
275
|
+
if (!paths.has(path))
|
|
276
|
+
this.records.delete(path);
|
|
277
|
+
let pending = 0;
|
|
278
|
+
for (const file of files) {
|
|
279
|
+
if (file.conflicted) {
|
|
280
|
+
this.records.delete(file.path);
|
|
281
|
+
throw new JournalVaultError('conflict', 'iCloud has conflicting Journal files. Both copies are preserved; resolve them before continuing.');
|
|
282
|
+
}
|
|
283
|
+
if (file.downloaded === false) {
|
|
284
|
+
this.records.delete(file.path);
|
|
285
|
+
pending++;
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (this.records.get(file.path)?.fingerprint === file.fingerprint)
|
|
289
|
+
continue;
|
|
290
|
+
this.records.delete(file.path);
|
|
291
|
+
let content;
|
|
292
|
+
try {
|
|
293
|
+
content = await this.files.read(file.path);
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
if (error instanceof JournalVaultError &&
|
|
297
|
+
error.code === 'unavailable') {
|
|
298
|
+
pending++;
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
const decoded = await this.decode(file.path, content);
|
|
304
|
+
await this.check(scope);
|
|
305
|
+
this.records.set(file.path, {
|
|
306
|
+
...decoded,
|
|
307
|
+
content,
|
|
308
|
+
fingerprint: file.fingerprint,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
if (pending)
|
|
312
|
+
await this.files.requestDownloads?.(files
|
|
313
|
+
.filter((f) => f.downloaded === false)
|
|
314
|
+
.slice(0, 8)
|
|
315
|
+
.map((f) => f.path));
|
|
316
|
+
await this.cleanup();
|
|
317
|
+
await this.reindex();
|
|
318
|
+
await this.check(scope);
|
|
319
|
+
this.publish({
|
|
320
|
+
pending: pending + this.unresolved,
|
|
321
|
+
ready: true,
|
|
322
|
+
error: '',
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
catch (error) {
|
|
326
|
+
// Never let an invalid/deleted record leave searchable stale words behind.
|
|
327
|
+
await (await this.index?.())?.clear(`${scope}:journal:${this.owner}`);
|
|
328
|
+
this.publish({
|
|
329
|
+
ready: false,
|
|
330
|
+
error: error instanceof JournalVaultError
|
|
331
|
+
? error.message
|
|
332
|
+
: 'Journal could not read your vault. Your files are unchanged.',
|
|
333
|
+
});
|
|
334
|
+
throw error;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
tombstones() {
|
|
338
|
+
return new Set([...this.records.values()].flatMap(({ record }) => record.kind === 'deletion' ? [record.segmentId] : []));
|
|
339
|
+
}
|
|
340
|
+
async cleanup() {
|
|
341
|
+
const deleted = this.tombstones();
|
|
342
|
+
for (const [path, stored] of this.records) {
|
|
343
|
+
const r = stored.record;
|
|
344
|
+
const id = r.kind === 'capture' ? r.id : 'segmentId' in r ? r.segmentId : null;
|
|
345
|
+
if (id && deleted.has(id) && r.kind !== 'deletion') {
|
|
346
|
+
await this.check(this.scope);
|
|
347
|
+
await this.files.remove(path, stored.content);
|
|
348
|
+
this.records.delete(path);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
segments() {
|
|
353
|
+
const deleted = this.tombstones();
|
|
354
|
+
const all = [...this.records.values()];
|
|
355
|
+
const correctionsBySegment = new Map();
|
|
356
|
+
const extractionsByRevision = new Map();
|
|
357
|
+
const proposals = new Map();
|
|
358
|
+
for (const stored of all) {
|
|
359
|
+
const r = stored.record;
|
|
360
|
+
if (r.kind === 'correction') {
|
|
361
|
+
const list = correctionsBySegment.get(r.segmentId) ?? [];
|
|
362
|
+
list.push(stored);
|
|
363
|
+
correctionsBySegment.set(r.segmentId, list);
|
|
364
|
+
}
|
|
365
|
+
else if (r.kind === 'extraction') {
|
|
366
|
+
const key = r.segmentId + r.revision;
|
|
367
|
+
const list = extractionsByRevision.get(key) ?? [];
|
|
368
|
+
list.push(stored);
|
|
369
|
+
extractionsByRevision.set(key, list);
|
|
370
|
+
r.proposals.forEach((p) => proposals.set(p.id, p));
|
|
371
|
+
}
|
|
372
|
+
else if (r.kind === 'legacy-proposal')
|
|
373
|
+
proposals.set(r.proposal.id, r.proposal);
|
|
374
|
+
}
|
|
375
|
+
const links = new Map();
|
|
376
|
+
for (const { record: r } of all)
|
|
377
|
+
if (r.kind === 'decision' && r.status === 'accepted') {
|
|
378
|
+
const proposal = proposals.get(r.proposalId);
|
|
379
|
+
if (proposal?.kind === 'link' &&
|
|
380
|
+
proposal.observationId &&
|
|
381
|
+
(!links.has(proposal.observationId) ||
|
|
382
|
+
links.get(proposal.observationId).id < r.id))
|
|
383
|
+
links.set(proposal.observationId, r);
|
|
384
|
+
}
|
|
385
|
+
const captureIds = new Set(all.flatMap((r) => (r.record.kind === 'capture' ? [r.record.id] : [])));
|
|
386
|
+
this.unresolved = new Set(all.flatMap(({ record: r }) => 'segmentId' in r &&
|
|
387
|
+
r.segmentId &&
|
|
388
|
+
r.kind !== 'deletion' &&
|
|
389
|
+
!deleted.has(r.segmentId) &&
|
|
390
|
+
!captureIds.has(r.segmentId)
|
|
391
|
+
? [r.segmentId]
|
|
392
|
+
: [])).size;
|
|
393
|
+
return all
|
|
394
|
+
.flatMap((capture) => {
|
|
395
|
+
const c = capture.record;
|
|
396
|
+
if (c.kind !== 'capture' || deleted.has(c.id))
|
|
397
|
+
return [];
|
|
398
|
+
const candidates = correctionsBySegment.get(c.id) ?? [];
|
|
399
|
+
// Parents must exist. Missing parents are an incomplete download, not a new winner.
|
|
400
|
+
const connected = new Set([capture.revision]);
|
|
401
|
+
for (let pass = 0; pass < candidates.length; pass++)
|
|
402
|
+
for (const candidate of candidates) {
|
|
403
|
+
if (candidate.record.kind === 'correction' &&
|
|
404
|
+
candidate.record.parents.every((p) => connected.has(p)))
|
|
405
|
+
connected.add(candidate.revision);
|
|
406
|
+
}
|
|
407
|
+
if (candidates.some((r) => !connected.has(r.revision))) {
|
|
408
|
+
this.unresolved++;
|
|
409
|
+
return [];
|
|
410
|
+
}
|
|
411
|
+
const superseded = new Set(candidates.flatMap((r) => r.record.kind === 'correction' ? r.record.parents : []));
|
|
412
|
+
const leaves = [capture, ...candidates]
|
|
413
|
+
.filter((r) => !superseded.has(r.revision))
|
|
414
|
+
.sort((a, b) => a.revision.localeCompare(b.revision));
|
|
415
|
+
const text = (r) => r.record.kind === 'correction' && !r.record.revert
|
|
416
|
+
? r.body
|
|
417
|
+
: capture.body;
|
|
418
|
+
const current = leaves.length === 1 ? leaves[0] : capture;
|
|
419
|
+
const corrections = leaves.filter((r) => r.record.kind === 'correction');
|
|
420
|
+
const extraction = (extractionsByRevision.get(c.id + current.revision) ?? []).sort((a, b) => b.record.id.localeCompare(a.record.id))[0];
|
|
421
|
+
const observations = (leaves.length === 1 && extraction?.record.kind === 'extraction'
|
|
422
|
+
? extraction.record.observations
|
|
423
|
+
: []).map((observation) => {
|
|
424
|
+
const decision = links.get(observation.id);
|
|
425
|
+
if (!decision)
|
|
426
|
+
return observation;
|
|
427
|
+
const link = LinkProposalPayloadSchema.safeParse(decision.payload);
|
|
428
|
+
return link.success
|
|
429
|
+
? {
|
|
430
|
+
...observation,
|
|
431
|
+
[link.data.target === 'project' ? 'projectId' : 'taskId']: link.data.targetId,
|
|
432
|
+
updatedAt: decision.at,
|
|
433
|
+
}
|
|
434
|
+
: observation;
|
|
435
|
+
});
|
|
436
|
+
return [
|
|
437
|
+
{
|
|
438
|
+
...c.segment,
|
|
439
|
+
transcript: capture.body,
|
|
440
|
+
correctedTranscript: current.record.kind === 'correction' && !current.record.revert
|
|
441
|
+
? current.body
|
|
442
|
+
: null,
|
|
443
|
+
localDate: c.day.localDate,
|
|
444
|
+
timeZone: c.day.timeZone,
|
|
445
|
+
updatedAt: corrections.reduce((at, r) => r.record.kind === 'correction' && r.record.at > at
|
|
446
|
+
? r.record.at
|
|
447
|
+
: at, c.segment.updatedAt),
|
|
448
|
+
revisions: leaves.map((r) => r.revision),
|
|
449
|
+
conflicts: leaves.length > 1
|
|
450
|
+
? leaves.map((r) => ({ revision: r.revision, text: text(r) }))
|
|
451
|
+
: [],
|
|
452
|
+
observations,
|
|
453
|
+
},
|
|
454
|
+
];
|
|
455
|
+
})
|
|
456
|
+
.sort((a, b) => a.capturedAt.getTime() - b.capturedAt.getTime() ||
|
|
457
|
+
a.id.localeCompare(b.id));
|
|
458
|
+
}
|
|
459
|
+
async days(opts = {}) {
|
|
460
|
+
await this.refresh();
|
|
461
|
+
const groups = new Map();
|
|
462
|
+
for (const segment of this.segments()) {
|
|
463
|
+
const list = groups.get(segment.localDate) ?? [];
|
|
464
|
+
list.push(segment);
|
|
465
|
+
groups.set(segment.localDate, list);
|
|
466
|
+
}
|
|
467
|
+
return [...groups]
|
|
468
|
+
.filter(([date]) => !opts.before || date < opts.before)
|
|
469
|
+
.sort(([a], [b]) => b.localeCompare(a))
|
|
470
|
+
.slice(0, opts.limit ?? 30)
|
|
471
|
+
.map(([localDate, segments]) => {
|
|
472
|
+
const first = segments[0];
|
|
473
|
+
return {
|
|
474
|
+
id: first.dayId,
|
|
475
|
+
userId: this.owner,
|
|
476
|
+
localDate,
|
|
477
|
+
timeZone: first.timeZone,
|
|
478
|
+
createdAt: first.createdAt,
|
|
479
|
+
updatedAt: new Date(Math.max(...segments.map((s) => s.updatedAt.getTime()))),
|
|
480
|
+
segmentCount: segments.length,
|
|
481
|
+
totalDurationMs: segments.reduce((n, s) => n + (s.durationMs ?? 0), 0),
|
|
482
|
+
firstCapturedAt: first.capturedAt,
|
|
483
|
+
lastCapturedAt: segments.at(-1).capturedAt,
|
|
484
|
+
preview: (first.correctedTranscript ?? first.transcript)
|
|
485
|
+
.replace(/\s+/g, ' ')
|
|
486
|
+
.slice(0, 180),
|
|
487
|
+
};
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
async day(localDate) {
|
|
491
|
+
const days = await this.days({ limit: Number.MAX_SAFE_INTEGER });
|
|
492
|
+
const day = days.find((d) => d.localDate === localDate);
|
|
493
|
+
return day
|
|
494
|
+
? {
|
|
495
|
+
...day,
|
|
496
|
+
segments: this.segments().filter((s) => s.localDate === localDate),
|
|
497
|
+
}
|
|
498
|
+
: null;
|
|
499
|
+
}
|
|
500
|
+
capture(input) {
|
|
501
|
+
return this.run(async () => {
|
|
502
|
+
await this.reconcile();
|
|
503
|
+
const parsed = CreateJournalSegmentSchema.parse(input);
|
|
504
|
+
if (this.tombstones().has(parsed.id))
|
|
505
|
+
throw new JournalVaultError('deleted', 'This capture was deleted on another device.');
|
|
506
|
+
const existing = this.segments().find((s) => s.id === parsed.id);
|
|
507
|
+
if (existing) {
|
|
508
|
+
if (existing.transcript !== parsed.transcript ||
|
|
509
|
+
existing.localDate !== parsed.localDate)
|
|
510
|
+
throw invalid();
|
|
511
|
+
return existing;
|
|
512
|
+
}
|
|
513
|
+
const at = parsed.capturedAt;
|
|
514
|
+
const dayId = this.segments().find((s) => s.localDate === parsed.localDate)?.dayId ??
|
|
515
|
+
parsed.id;
|
|
516
|
+
await this.commit({
|
|
517
|
+
version: 1,
|
|
518
|
+
owner: this.owner,
|
|
519
|
+
id: parsed.id,
|
|
520
|
+
kind: 'capture',
|
|
521
|
+
bodyHash: await this.files.hash(parsed.transcript),
|
|
522
|
+
day: {
|
|
523
|
+
id: dayId,
|
|
524
|
+
userId: this.owner,
|
|
525
|
+
localDate: parsed.localDate,
|
|
526
|
+
timeZone: parsed.timeZone ?? null,
|
|
527
|
+
createdAt: at,
|
|
528
|
+
updatedAt: at,
|
|
529
|
+
},
|
|
530
|
+
segment: {
|
|
531
|
+
id: parsed.id,
|
|
532
|
+
dayId,
|
|
533
|
+
userId: this.owner,
|
|
534
|
+
capturedAt: at,
|
|
535
|
+
durationMs: parsed.durationMs ?? null,
|
|
536
|
+
source: parsed.source,
|
|
537
|
+
engine: parsed.engine ?? null,
|
|
538
|
+
createdAt: at,
|
|
539
|
+
updatedAt: at,
|
|
540
|
+
},
|
|
541
|
+
}, parsed.transcript);
|
|
542
|
+
await this.reindex();
|
|
543
|
+
this.publish({});
|
|
544
|
+
return this.segments().find((s) => s.id === parsed.id);
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
correct(segmentId, text, expectedRevisions) {
|
|
548
|
+
return this.run(async () => {
|
|
549
|
+
await this.reconcile();
|
|
550
|
+
const segment = this.segments().find((s) => s.id === segmentId);
|
|
551
|
+
if (!segment)
|
|
552
|
+
throw new JournalVaultError('deleted', 'The capture is unavailable or has been deleted.');
|
|
553
|
+
if ([...expectedRevisions].sort().join() !==
|
|
554
|
+
[...segment.revisions].sort().join())
|
|
555
|
+
throw new JournalVaultError('changed', 'This capture changed on another device. Reload it before saving your correction.');
|
|
556
|
+
const { correctedTranscript } = CorrectJournalSegmentSchema.parse({
|
|
557
|
+
correctedTranscript: text,
|
|
558
|
+
});
|
|
559
|
+
await this.commit({
|
|
560
|
+
version: 1,
|
|
561
|
+
owner: this.owner,
|
|
562
|
+
id: this.files.uuid(),
|
|
563
|
+
kind: 'correction',
|
|
564
|
+
segmentId,
|
|
565
|
+
parents: expectedRevisions,
|
|
566
|
+
at: new Date(),
|
|
567
|
+
revert: correctedTranscript === null,
|
|
568
|
+
bodyHash: await this.files.hash(correctedTranscript ?? ''),
|
|
569
|
+
}, correctedTranscript ?? '');
|
|
570
|
+
await this.reindex();
|
|
571
|
+
this.publish({});
|
|
572
|
+
return this.segments().find((s) => s.id === segmentId);
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
delete(segmentId) {
|
|
576
|
+
return this.run(async () => {
|
|
577
|
+
await this.reconcile();
|
|
578
|
+
if (!this.tombstones().has(segmentId))
|
|
579
|
+
await this.commit({
|
|
580
|
+
version: 1,
|
|
581
|
+
owner: this.owner,
|
|
582
|
+
id: segmentId,
|
|
583
|
+
kind: 'deletion',
|
|
584
|
+
segmentId,
|
|
585
|
+
at: new Date(),
|
|
586
|
+
});
|
|
587
|
+
await this.cleanup();
|
|
588
|
+
await this.reindex();
|
|
589
|
+
this.publish({});
|
|
590
|
+
return { ok: true };
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
async reindex() {
|
|
594
|
+
const index = await this.index?.();
|
|
595
|
+
if (!index)
|
|
596
|
+
return;
|
|
597
|
+
const scope = `${this.scope}:journal:${this.owner}`;
|
|
598
|
+
const segments = this.segments().filter((s) => !s.conflicts.length);
|
|
599
|
+
const ids = new Set(segments.map((s) => s.id));
|
|
600
|
+
const inventory = new Map((await index.inventory(scope, 'journal')).map((row) => [
|
|
601
|
+
row.id,
|
|
602
|
+
row.fingerprint,
|
|
603
|
+
]));
|
|
604
|
+
for (const id of inventory.keys())
|
|
605
|
+
if (!ids.has(id))
|
|
606
|
+
await index.remove(scope, 'journal', id);
|
|
607
|
+
for (const segment of segments) {
|
|
608
|
+
const revision = segment.revisions[0];
|
|
609
|
+
if (inventory.get(segment.id) === revision)
|
|
610
|
+
continue;
|
|
611
|
+
const document = {
|
|
612
|
+
id: segment.id,
|
|
613
|
+
kind: 'journal',
|
|
614
|
+
path: segment.localDate,
|
|
615
|
+
title: segment.localDate,
|
|
616
|
+
body: segment.correctedTranscript ?? segment.transcript,
|
|
617
|
+
revision,
|
|
618
|
+
fingerprint: revision,
|
|
619
|
+
modifiedAt: segment.capturedAt.getTime(),
|
|
620
|
+
};
|
|
621
|
+
await this.check(this.scope);
|
|
622
|
+
await index.put(scope, document);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
/** Imports are replayable, preserve server timestamps/IDs, and verify each written file. */
|
|
626
|
+
importLegacy(snapshot) {
|
|
627
|
+
return this.run(async () => {
|
|
628
|
+
await this.reconcile();
|
|
629
|
+
const paths = new Set();
|
|
630
|
+
const commit = async (record, body = '') => {
|
|
631
|
+
paths.add(await this.commit(record, body));
|
|
632
|
+
};
|
|
633
|
+
const days = snapshot.days.map((row) => JournalDaySchema.parse(row));
|
|
634
|
+
const segments = snapshot.segments.map((row) => JournalSegmentSchema.parse(row));
|
|
635
|
+
const observations = snapshot.observations.map((row) => JournalObservationSchema.parse(row));
|
|
636
|
+
for (const day of days) {
|
|
637
|
+
if (day.userId !== this.owner)
|
|
638
|
+
throw invalid();
|
|
639
|
+
await commit({
|
|
640
|
+
version: 1,
|
|
641
|
+
owner: this.owner,
|
|
642
|
+
id: day.id,
|
|
643
|
+
kind: 'legacy-day',
|
|
644
|
+
day,
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
for (const source of segments) {
|
|
648
|
+
const day = days.find((d) => d.id === source.dayId);
|
|
649
|
+
if (!day || source.userId !== this.owner)
|
|
650
|
+
throw invalid();
|
|
651
|
+
if (this.tombstones().has(source.id))
|
|
652
|
+
throw new JournalVaultError('deleted', 'A migrated capture has since been deleted. Resume from the completed migration receipt.');
|
|
653
|
+
const { transcript, correctedTranscript, ...segment } = source;
|
|
654
|
+
const base = {
|
|
655
|
+
version: 1,
|
|
656
|
+
owner: this.owner,
|
|
657
|
+
id: source.id,
|
|
658
|
+
kind: 'capture',
|
|
659
|
+
day,
|
|
660
|
+
segment,
|
|
661
|
+
bodyHash: await this.files.hash(transcript),
|
|
662
|
+
};
|
|
663
|
+
await commit(base, transcript);
|
|
664
|
+
let revision = await this.files.hash(await this.encode(base, transcript));
|
|
665
|
+
if (correctedTranscript !== null) {
|
|
666
|
+
const correction = {
|
|
667
|
+
version: 1,
|
|
668
|
+
owner: this.owner,
|
|
669
|
+
id: source.id,
|
|
670
|
+
kind: 'correction',
|
|
671
|
+
segmentId: source.id,
|
|
672
|
+
parents: [revision],
|
|
673
|
+
at: source.updatedAt,
|
|
674
|
+
revert: false,
|
|
675
|
+
bodyHash: await this.files.hash(correctedTranscript),
|
|
676
|
+
};
|
|
677
|
+
await commit(correction, correctedTranscript);
|
|
678
|
+
revision = await this.files.hash(await this.encode(correction, correctedTranscript));
|
|
679
|
+
}
|
|
680
|
+
const stamp = snapshot.extractions.find((row) => row.segmentId === source.id);
|
|
681
|
+
const derived = observations.filter((o) => o.segmentId === source.id);
|
|
682
|
+
if (derived.some((o) => o.userId !== this.owner))
|
|
683
|
+
throw invalid();
|
|
684
|
+
if (stamp || derived.length) {
|
|
685
|
+
const at = new Date(String(stamp?.extractedAt ?? source.updatedAt.toISOString()));
|
|
686
|
+
// Preserve stale evidence for the migration audit, but never quote it as current.
|
|
687
|
+
await commit({
|
|
688
|
+
version: 1,
|
|
689
|
+
owner: this.owner,
|
|
690
|
+
id: source.id,
|
|
691
|
+
kind: 'extraction',
|
|
692
|
+
segmentId: source.id,
|
|
693
|
+
revision: at < source.updatedAt ? '0'.repeat(64) : revision,
|
|
694
|
+
extractorVersion: String(stamp?.extractorVersion ?? 'legacy'),
|
|
695
|
+
at,
|
|
696
|
+
...(stamp?.model ? { model: String(stamp.model) } : {}),
|
|
697
|
+
...(stamp?.error ? { error: String(stamp.error) } : {}),
|
|
698
|
+
observations: derived,
|
|
699
|
+
proposals: [],
|
|
700
|
+
...(stamp ? { legacyStamp: stamp } : {}),
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
for (const row of snapshot.proposals) {
|
|
705
|
+
const proposal = ProposalSchema.parse(row);
|
|
706
|
+
if (proposal.userId !== this.owner)
|
|
707
|
+
throw invalid();
|
|
708
|
+
const observation = observations.find((o) => o.id === proposal.observationId);
|
|
709
|
+
const segment = segments.find((s) => s.id === observation?.segmentId);
|
|
710
|
+
const day = days.find((d) => d.id === segment?.dayId);
|
|
711
|
+
const evidence = observation && segment && day
|
|
712
|
+
? {
|
|
713
|
+
segmentId: segment.id,
|
|
714
|
+
localDate: day.localDate,
|
|
715
|
+
capturedAt: segment.capturedAt,
|
|
716
|
+
quote: (segment.correctedTranscript ?? segment.transcript).slice(observation.startOffset, observation.endOffset),
|
|
717
|
+
}
|
|
718
|
+
: null;
|
|
719
|
+
await commit({
|
|
720
|
+
version: 1,
|
|
721
|
+
owner: this.owner,
|
|
722
|
+
id: proposal.id,
|
|
723
|
+
kind: 'legacy-proposal',
|
|
724
|
+
segmentId: segment?.id ?? null,
|
|
725
|
+
proposal: { ...proposal, evidence },
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
const receipts = [];
|
|
729
|
+
for (const path of [...paths].sort()) {
|
|
730
|
+
const record = this.records.get(path).record;
|
|
731
|
+
const segmentId = record.kind === 'capture'
|
|
732
|
+
? record.id
|
|
733
|
+
: 'segmentId' in record
|
|
734
|
+
? record.segmentId
|
|
735
|
+
: null;
|
|
736
|
+
receipts.push({
|
|
737
|
+
path,
|
|
738
|
+
hash: await this.files.hash(await this.files.read(path)),
|
|
739
|
+
...(segmentId ? { segmentId } : {}),
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
await this.reindex();
|
|
743
|
+
this.publish({});
|
|
744
|
+
return {
|
|
745
|
+
files: receipts,
|
|
746
|
+
vaultDigest: await this.files.hash(JSON.stringify(receipts)),
|
|
747
|
+
};
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
activate(migrationId, sourceDigest, vaultDigest, files = []) {
|
|
751
|
+
return this.run(async () => {
|
|
752
|
+
await this.commit({
|
|
753
|
+
version: 1,
|
|
754
|
+
owner: this.owner,
|
|
755
|
+
id: migrationId,
|
|
756
|
+
kind: 'activation',
|
|
757
|
+
sourceDigest,
|
|
758
|
+
vaultDigest,
|
|
759
|
+
files,
|
|
760
|
+
});
|
|
761
|
+
this.publish({});
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
activation() {
|
|
765
|
+
return [...this.records.values()]
|
|
766
|
+
.map((r) => r.record)
|
|
767
|
+
.find((r) => r.kind === 'activation');
|
|
768
|
+
}
|
|
769
|
+
async verifyMigration(requireUploaded = false) {
|
|
770
|
+
await this.refresh();
|
|
771
|
+
const activation = this.activation();
|
|
772
|
+
if (activation?.kind !== 'activation' ||
|
|
773
|
+
(await this.files.hash(JSON.stringify(activation.files))) !==
|
|
774
|
+
activation.vaultDigest)
|
|
775
|
+
throw new JournalVaultError('invalid', 'The migration receipt could not be verified. Server originals have been preserved.');
|
|
776
|
+
const inventory = new Map((await this.files.list()).map((file) => [file.path, file]));
|
|
777
|
+
const deleted = this.tombstones();
|
|
778
|
+
const requireUpload = (path) => {
|
|
779
|
+
if (requireUploaded && inventory.get(path)?.uploaded !== true)
|
|
780
|
+
throw new JournalVaultError('unavailable', 'Wait until iCloud has uploaded all migrated Journal files before removing the server copy.');
|
|
781
|
+
};
|
|
782
|
+
for (const file of activation.files) {
|
|
783
|
+
if (!file.path.startsWith(this.root))
|
|
784
|
+
throw invalid();
|
|
785
|
+
if (file.segmentId && deleted.has(file.segmentId)) {
|
|
786
|
+
requireUpload(`${this.root}deletions/${file.segmentId}.md`);
|
|
787
|
+
continue;
|
|
788
|
+
}
|
|
789
|
+
if ((await this.files.hash(await this.files.read(file.path))) !== file.hash)
|
|
790
|
+
throw new JournalVaultError('changed', 'A migrated file changed outside Journal. Server originals have been preserved.');
|
|
791
|
+
requireUpload(file.path);
|
|
792
|
+
}
|
|
793
|
+
requireUpload(this.path(activation));
|
|
794
|
+
return {
|
|
795
|
+
migrationId: activation.id,
|
|
796
|
+
vaultDigest: activation.vaultDigest,
|
|
797
|
+
files: activation.files.length,
|
|
798
|
+
};
|
|
799
|
+
}
|
|
800
|
+
async unextracted(version, limit = 25) {
|
|
801
|
+
await this.refresh();
|
|
802
|
+
const extracted = new Set([...this.records.values()].flatMap(({ record: r }) => r.kind === 'extraction' && r.extractorVersion === version
|
|
803
|
+
? [r.segmentId + r.revision]
|
|
804
|
+
: []));
|
|
805
|
+
return this.segments()
|
|
806
|
+
.filter((s) => !s.conflicts.length && !extracted.has(s.id + s.revisions[0]))
|
|
807
|
+
.slice(0, limit);
|
|
808
|
+
}
|
|
809
|
+
writeExtraction(input) {
|
|
810
|
+
return this.run(async () => {
|
|
811
|
+
await this.reconcile();
|
|
812
|
+
const segment = this.segments().find((s) => s.id === input.segmentId);
|
|
813
|
+
if (!segment ||
|
|
814
|
+
segment.conflicts.length ||
|
|
815
|
+
segment.revisions[0] !== input.revision)
|
|
816
|
+
throw new JournalVaultError('changed', 'The capture changed during extraction. Results were not applied.');
|
|
817
|
+
const words = segment.correctedTranscript ?? segment.transcript;
|
|
818
|
+
if (input.observations.some((o) => o.userId !== this.owner ||
|
|
819
|
+
o.segmentId !== segment.id ||
|
|
820
|
+
o.startOffset < 0 ||
|
|
821
|
+
o.endOffset > words.length ||
|
|
822
|
+
o.endOffset <= o.startOffset))
|
|
823
|
+
throw invalid();
|
|
824
|
+
if (input.proposals.some((p) => p.userId !== this.owner ||
|
|
825
|
+
p.evidence?.segmentId !== segment.id ||
|
|
826
|
+
!input.observations.some((o) => o.id === p.observationId)))
|
|
827
|
+
throw invalid();
|
|
828
|
+
// One completed result per revision/version, including empty/error results.
|
|
829
|
+
if ([...this.records.values()].some(({ record: r }) => r.kind === 'extraction' &&
|
|
830
|
+
r.segmentId === segment.id &&
|
|
831
|
+
r.revision === input.revision &&
|
|
832
|
+
r.extractorVersion === input.extractorVersion))
|
|
833
|
+
return;
|
|
834
|
+
await this.commit({
|
|
835
|
+
...input,
|
|
836
|
+
version: 1,
|
|
837
|
+
owner: this.owner,
|
|
838
|
+
id: this.files.uuid(),
|
|
839
|
+
kind: 'extraction',
|
|
840
|
+
at: new Date(),
|
|
841
|
+
});
|
|
842
|
+
this.publish({});
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
proposalSnapshot() {
|
|
846
|
+
const all = [...this.records.values()].map((r) => r.record);
|
|
847
|
+
const segments = this.segments();
|
|
848
|
+
const candidates = all.flatMap((r) => r.kind === 'legacy-proposal'
|
|
849
|
+
? [r.proposal]
|
|
850
|
+
: r.kind === 'extraction' &&
|
|
851
|
+
segments.some((s) => s.id === r.segmentId &&
|
|
852
|
+
s.revisions.length === 1 &&
|
|
853
|
+
s.revisions[0] === r.revision)
|
|
854
|
+
? r.proposals
|
|
855
|
+
: []);
|
|
856
|
+
return candidates
|
|
857
|
+
.filter((p) => !p.evidence ||
|
|
858
|
+
(!this.tombstones().has(p.evidence.segmentId) &&
|
|
859
|
+
(p.status !== 'pending' ||
|
|
860
|
+
segments.some((s) => s.id === p.evidence.segmentId &&
|
|
861
|
+
s.observations.some((o) => o.id === p.observationId)))))
|
|
862
|
+
.map((p) => {
|
|
863
|
+
const decisions = all
|
|
864
|
+
.filter((r) => r.kind === 'decision' && r.proposalId === p.id)
|
|
865
|
+
.sort((a, b) => b.id.localeCompare(a.id));
|
|
866
|
+
const decision = decisions.find((r) => r.kind === 'decision' && r.status === 'accepted') ?? decisions[0];
|
|
867
|
+
if (decision?.kind !== 'decision')
|
|
868
|
+
return p;
|
|
869
|
+
return {
|
|
870
|
+
...p,
|
|
871
|
+
status: decision.status === 'accepting'
|
|
872
|
+
? 'pending'
|
|
873
|
+
: decision.status,
|
|
874
|
+
payload: decision.payload,
|
|
875
|
+
resultId: decision.resultId,
|
|
876
|
+
rejectionReason: decision.reason,
|
|
877
|
+
decidedAt: decision.at,
|
|
878
|
+
};
|
|
879
|
+
})
|
|
880
|
+
.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
881
|
+
}
|
|
882
|
+
async proposals(status = 'pending') {
|
|
883
|
+
await this.refresh();
|
|
884
|
+
return this.proposalSnapshot().filter((p) => status === 'all' || p.status === 'pending');
|
|
885
|
+
}
|
|
886
|
+
decide(input, publish, validateLink) {
|
|
887
|
+
return this.run(async () => {
|
|
888
|
+
await this.reconcile();
|
|
889
|
+
const proposal = this.proposalSnapshot().find((p) => p.id === input.id);
|
|
890
|
+
if (!proposal)
|
|
891
|
+
throw new JournalVaultError('unavailable', 'The suggestion is no longer available.');
|
|
892
|
+
if (proposal.status !== 'pending')
|
|
893
|
+
return proposal;
|
|
894
|
+
if (proposal.evidence) {
|
|
895
|
+
const segment = this.segments().find((s) => s.id === proposal.evidence.segmentId);
|
|
896
|
+
if (!segment ||
|
|
897
|
+
segment.conflicts.length ||
|
|
898
|
+
!segment.observations.some((o) => o.id === proposal.observationId))
|
|
899
|
+
throw new JournalVaultError('changed', 'The source words changed. Wait for the refreshed suggestion.');
|
|
900
|
+
}
|
|
901
|
+
const payload = input.payload ?? proposal.payload;
|
|
902
|
+
const accepting = [...this.records.values()]
|
|
903
|
+
.map((r) => r.record)
|
|
904
|
+
.find((r) => r.kind === 'decision' &&
|
|
905
|
+
r.proposalId === proposal.id &&
|
|
906
|
+
r.status === 'accepting');
|
|
907
|
+
if (accepting?.kind === 'decision') {
|
|
908
|
+
if (input.decision === 'reject')
|
|
909
|
+
throw new JournalVaultError('changed', 'This task may already have been added. Finish the pending Add to Tasks action before deciding again.');
|
|
910
|
+
if (JSON.stringify(accepting.payload) !== JSON.stringify(payload))
|
|
911
|
+
throw new JournalVaultError('changed', 'Finish publishing the original task fields first. You can edit the resulting task afterward.');
|
|
912
|
+
}
|
|
913
|
+
const base = {
|
|
914
|
+
version: 1,
|
|
915
|
+
owner: this.owner,
|
|
916
|
+
kind: 'decision',
|
|
917
|
+
proposalId: proposal.id,
|
|
918
|
+
segmentId: proposal.evidence?.segmentId ?? null,
|
|
919
|
+
at: new Date(),
|
|
920
|
+
payload,
|
|
921
|
+
reason: input.reason ?? null,
|
|
922
|
+
};
|
|
923
|
+
if (input.decision === 'reject') {
|
|
924
|
+
await this.commit({
|
|
925
|
+
...base,
|
|
926
|
+
id: this.files.uuid(),
|
|
927
|
+
status: 'rejected',
|
|
928
|
+
resultId: null,
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
else {
|
|
932
|
+
let resultId;
|
|
933
|
+
if (proposal.kind === 'task') {
|
|
934
|
+
const task = TaskProposalPayloadSchema.parse(payload);
|
|
935
|
+
// Durable intent before the only content publication: selected task fields.
|
|
936
|
+
await this.commit({
|
|
937
|
+
...base,
|
|
938
|
+
id: this.files.uuid(),
|
|
939
|
+
status: 'accepting',
|
|
940
|
+
resultId: proposal.id,
|
|
941
|
+
});
|
|
942
|
+
resultId = (await publish(proposal.id, task)).id;
|
|
943
|
+
}
|
|
944
|
+
else if (proposal.kind === 'link') {
|
|
945
|
+
const link = LinkProposalPayloadSchema.parse(payload);
|
|
946
|
+
await validateLink(link.target, link.targetId);
|
|
947
|
+
resultId = link.targetId;
|
|
948
|
+
}
|
|
949
|
+
else
|
|
950
|
+
throw invalid();
|
|
951
|
+
await this.commit({
|
|
952
|
+
...base,
|
|
953
|
+
id: this.files.uuid(),
|
|
954
|
+
status: 'accepted',
|
|
955
|
+
resultId,
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
this.publish({});
|
|
959
|
+
return this.proposalSnapshot().find((p) => p.id === input.id);
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
async search(query, limit = 30, offset = 0) {
|
|
963
|
+
await this.refresh();
|
|
964
|
+
const index = await this.index?.();
|
|
965
|
+
if (!index)
|
|
966
|
+
throw new JournalVaultError('unavailable', 'This device has no Journal search index.');
|
|
967
|
+
const scope = this.scope;
|
|
968
|
+
const hits = await index.search(`${scope}:journal:${this.owner}`, 'journal', query, limit, offset);
|
|
969
|
+
await this.check(scope);
|
|
970
|
+
return hits;
|
|
971
|
+
}
|
|
972
|
+
}
|