mirror-mind 0.0.1 → 0.33.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/.claude/hooks/log-assistant-reply.sh +85 -0
- package/.claude/hooks/log-session-end.sh +85 -0
- package/.claude/hooks/log-user-prompt.sh +85 -0
- package/.claude/hooks/mirror-inject.sh +85 -0
- package/.claude/hooks/session-start.sh +85 -0
- package/.gemini/hooks/log-assistant.sh +85 -0
- package/.gemini/hooks/log-user.sh +85 -0
- package/.gemini/hooks/session-end.sh +85 -0
- package/.gemini/hooks/session-start.sh +85 -0
- package/.pi/extensions/mirror-logger.ts +646 -0
- package/.pi/skills/mm-backup/SKILL.md +21 -0
- package/.pi/skills/mm-build/SKILL.md +1206 -0
- package/.pi/skills/mm-consolidate/SKILL.md +112 -0
- package/.pi/skills/mm-consult/SKILL.md +70 -0
- package/.pi/skills/mm-conversations/SKILL.md +16 -0
- package/.pi/skills/mm-discard/SKILL.md +39 -0
- package/.pi/skills/mm-explore/SKILL.md +255 -0
- package/.pi/skills/mm-help/SKILL.md +74 -0
- package/.pi/skills/mm-identity/SKILL.md +96 -0
- package/.pi/skills/mm-journal/SKILL.md +16 -0
- package/.pi/skills/mm-journey/SKILL.md +23 -0
- package/.pi/skills/mm-journeys/SKILL.md +15 -0
- package/.pi/skills/mm-memories/SKILL.md +17 -0
- package/.pi/skills/mm-mirror/SKILL.md +98 -0
- package/.pi/skills/mm-mute/SKILL.md +18 -0
- package/.pi/skills/mm-new/SKILL.md +18 -0
- package/.pi/skills/mm-recall/SKILL.md +17 -0
- package/.pi/skills/mm-release-notes/SKILL.md +52 -0
- package/.pi/skills/mm-seed/SKILL.md +19 -0
- package/.pi/skills/mm-shadow/SKILL.md +117 -0
- package/.pi/skills/mm-soul/SKILL.md +502 -0
- package/.pi/skills/mm-tasks/SKILL.md +24 -0
- package/.pi/skills/mm-update/SKILL.md +32 -0
- package/.pi/skills/mm-week/SKILL.md +28 -0
- package/.pi/skills/mm-welcome/SKILL.md +24 -0
- package/AGENTS.md +188 -0
- package/README.md +126 -9
- package/bin/loader.js +67 -0
- package/bin/mirror-hook.js +7 -0
- package/bin/mirror.js +7 -0
- package/docs/releases/index.md +100 -0
- package/docs/releases/pending-cutoffs.md +510 -0
- package/docs/releases/v0.10.0.md +123 -0
- package/docs/releases/v0.10.1.md +66 -0
- package/docs/releases/v0.10.10.md +51 -0
- package/docs/releases/v0.10.11.md +39 -0
- package/docs/releases/v0.10.12.md +57 -0
- package/docs/releases/v0.10.13.md +35 -0
- package/docs/releases/v0.10.14.md +42 -0
- package/docs/releases/v0.10.15.md +53 -0
- package/docs/releases/v0.10.16.md +35 -0
- package/docs/releases/v0.10.17.md +43 -0
- package/docs/releases/v0.10.2.md +64 -0
- package/docs/releases/v0.10.3.md +78 -0
- package/docs/releases/v0.10.4.md +42 -0
- package/docs/releases/v0.10.5.md +57 -0
- package/docs/releases/v0.10.6.md +47 -0
- package/docs/releases/v0.10.7.md +53 -0
- package/docs/releases/v0.10.8.md +49 -0
- package/docs/releases/v0.10.9.md +37 -0
- package/docs/releases/v0.11.0.md +86 -0
- package/docs/releases/v0.12.0.md +67 -0
- package/docs/releases/v0.13.0.md +64 -0
- package/docs/releases/v0.14.0.md +68 -0
- package/docs/releases/v0.15.0.md +48 -0
- package/docs/releases/v0.16.0.md +50 -0
- package/docs/releases/v0.16.1.md +55 -0
- package/docs/releases/v0.16.2.md +36 -0
- package/docs/releases/v0.17.0.md +50 -0
- package/docs/releases/v0.17.1.md +58 -0
- package/docs/releases/v0.17.2.md +42 -0
- package/docs/releases/v0.17.3.md +58 -0
- package/docs/releases/v0.18.0.md +84 -0
- package/docs/releases/v0.18.1.md +51 -0
- package/docs/releases/v0.18.2.md +69 -0
- package/docs/releases/v0.19.0.md +85 -0
- package/docs/releases/v0.19.1.md +46 -0
- package/docs/releases/v0.20.0.md +85 -0
- package/docs/releases/v0.21.0.md +61 -0
- package/docs/releases/v0.21.1.md +47 -0
- package/docs/releases/v0.22.0.md +77 -0
- package/docs/releases/v0.22.1.md +42 -0
- package/docs/releases/v0.23.0.md +105 -0
- package/docs/releases/v0.24.0.md +125 -0
- package/docs/releases/v0.25.0.md +107 -0
- package/docs/releases/v0.26.0.md +139 -0
- package/docs/releases/v0.26.1.md +65 -0
- package/docs/releases/v0.26.2.md +43 -0
- package/docs/releases/v0.27.0.md +63 -0
- package/docs/releases/v0.28.0.md +59 -0
- package/docs/releases/v0.29.0.md +61 -0
- package/docs/releases/v0.29.1.md +59 -0
- package/docs/releases/v0.29.2.md +59 -0
- package/docs/releases/v0.29.3.md +93 -0
- package/docs/releases/v0.30.0.md +75 -0
- package/docs/releases/v0.30.1.md +93 -0
- package/docs/releases/v0.30.2.md +66 -0
- package/docs/releases/v0.31.0.md +122 -0
- package/docs/releases/v0.31.1.md +142 -0
- package/docs/releases/v0.31.10.md +118 -0
- package/docs/releases/v0.31.11.md +88 -0
- package/docs/releases/v0.31.12.md +105 -0
- package/docs/releases/v0.31.13.md +99 -0
- package/docs/releases/v0.31.14.md +97 -0
- package/docs/releases/v0.31.2.md +115 -0
- package/docs/releases/v0.31.3.md +142 -0
- package/docs/releases/v0.31.4.md +117 -0
- package/docs/releases/v0.31.5.md +155 -0
- package/docs/releases/v0.31.6.md +132 -0
- package/docs/releases/v0.31.7.md +132 -0
- package/docs/releases/v0.31.8.md +120 -0
- package/docs/releases/v0.31.9.md +120 -0
- package/docs/releases/v0.32.0.md +261 -0
- package/docs/releases/v0.32.1.md +59 -0
- package/docs/releases/v0.33.0.md +164 -0
- package/docs/releases/v0.8.0.md +118 -0
- package/docs/releases/v0.9.0.md +98 -0
- package/docs/releases/v0.9.1.md +83 -0
- package/package.json +102 -6
- package/plugins/mirror-mind/.claude-plugin/plugin.json +17 -0
- package/plugins/mirror-mind/hooks/hooks.json +62 -0
- package/plugins/mirror-mind/hooks/log-assistant-reply.sh +98 -0
- package/plugins/mirror-mind/hooks/log-session-end.sh +98 -0
- package/plugins/mirror-mind/hooks/log-user-prompt.sh +98 -0
- package/plugins/mirror-mind/hooks/mirror-inject.sh +98 -0
- package/plugins/mirror-mind/hooks/session-start.sh +98 -0
- package/plugins/mirror-mind/skills/mm-backup/SKILL.md +27 -0
- package/plugins/mirror-mind/skills/mm-build/SKILL.md +1206 -0
- package/plugins/mirror-mind/skills/mm-consolidate/SKILL.md +112 -0
- package/plugins/mirror-mind/skills/mm-consult/SKILL.md +83 -0
- package/plugins/mirror-mind/skills/mm-conversations/SKILL.md +17 -0
- package/plugins/mirror-mind/skills/mm-discard/SKILL.md +40 -0
- package/plugins/mirror-mind/skills/mm-explore/SKILL.md +241 -0
- package/plugins/mirror-mind/skills/mm-help/SKILL.md +104 -0
- package/plugins/mirror-mind/skills/mm-identity/SKILL.md +96 -0
- package/plugins/mirror-mind/skills/mm-journal/SKILL.md +21 -0
- package/plugins/mirror-mind/skills/mm-journey/SKILL.md +37 -0
- package/plugins/mirror-mind/skills/mm-journeys/SKILL.md +15 -0
- package/plugins/mirror-mind/skills/mm-memories/SKILL.md +20 -0
- package/plugins/mirror-mind/skills/mm-mirror/SKILL.md +67 -0
- package/plugins/mirror-mind/skills/mm-mute/SKILL.md +18 -0
- package/plugins/mirror-mind/skills/mm-new/SKILL.md +18 -0
- package/plugins/mirror-mind/skills/mm-recall/SKILL.md +17 -0
- package/plugins/mirror-mind/skills/mm-release-notes/SKILL.md +31 -0
- package/plugins/mirror-mind/skills/mm-seed/SKILL.md +15 -0
- package/plugins/mirror-mind/skills/mm-shadow/SKILL.md +117 -0
- package/plugins/mirror-mind/skills/mm-soul/SKILL.md +488 -0
- package/plugins/mirror-mind/skills/mm-tasks/SKILL.md +36 -0
- package/plugins/mirror-mind/skills/mm-update/SKILL.md +30 -0
- package/plugins/mirror-mind/skills/mm-week/SKILL.md +46 -0
- package/plugins/mirror-mind/skills/mm-welcome/SKILL.md +22 -0
- package/scripts/codex-hooks/session-end.sh +85 -0
- package/scripts/codex-hooks/session-start.sh +85 -0
- package/scripts/codex-mirror.sh +48 -0
- package/templates/identity/README.md +119 -0
- package/templates/identity/ego/behavior.yaml +52 -0
- package/templates/identity/ego/constraints.yaml +15 -0
- package/templates/identity/ego/identity.yaml +43 -0
- package/templates/identity/journeys/personal-growth.yaml +39 -0
- package/templates/identity/organization/identity.yaml +24 -0
- package/templates/identity/organization/principles.yaml +17 -0
- package/templates/identity/personas/coach.yaml +94 -0
- package/templates/identity/personas/designer.yaml +93 -0
- package/templates/identity/personas/doctor.yaml +96 -0
- package/templates/identity/personas/engineer.yaml +77 -0
- package/templates/identity/personas/financial.yaml +97 -0
- package/templates/identity/personas/prompt-engineer.yaml +122 -0
- package/templates/identity/personas/researcher.yaml +88 -0
- package/templates/identity/personas/strategist.yaml +91 -0
- package/templates/identity/personas/teacher.yaml +95 -0
- package/templates/identity/personas/therapist.yaml +91 -0
- package/templates/identity/personas/thinker.yaml +74 -0
- package/templates/identity/personas/writer.yaml +76 -0
- package/templates/identity/self/config.yaml +16 -0
- package/templates/identity/self/soul.yaml +105 -0
- package/templates/identity/user/identity.yaml +30 -0
- package/ts/src/backup/staging.ts +62 -0
- package/ts/src/backup/zipBackup.ts +267 -0
- package/ts/src/backup/zipReader.ts +109 -0
- package/ts/src/backup/zipWriter.ts +148 -0
- package/ts/src/builder/activeCheckpoint.ts +134 -0
- package/ts/src/builder/aggregateStatus.ts +34 -0
- package/ts/src/builder/approve.ts +149 -0
- package/ts/src/builder/argv.ts +292 -0
- package/ts/src/builder/ariadMethod.ts +536 -0
- package/ts/src/builder/artifacts/artifactSurfaces.ts +106 -0
- package/ts/src/builder/artifacts/artifactWriter.ts +113 -0
- package/ts/src/builder/artifacts/closureArtifacts.ts +199 -0
- package/ts/src/builder/artifacts/deliveryStoryArtifacts.ts +316 -0
- package/ts/src/builder/artifacts/planArtifacts.ts +242 -0
- package/ts/src/builder/artifacts/scaffoldSections.ts +273 -0
- package/ts/src/builder/artifacts/scaffoldState.ts +227 -0
- package/ts/src/builder/artifacts/storyFiles.ts +61 -0
- package/ts/src/builder/artifacts/storyIndex.ts +166 -0
- package/ts/src/builder/cadence.ts +59 -0
- package/ts/src/builder/card.ts +192 -0
- package/ts/src/builder/checkpointRefused.ts +66 -0
- package/ts/src/builder/closure.ts +964 -0
- package/ts/src/builder/commands.ts +2053 -0
- package/ts/src/builder/cursorPosition.ts +176 -0
- package/ts/src/builder/cursorTransitions.ts +77 -0
- package/ts/src/builder/deliveryCursor.ts +577 -0
- package/ts/src/builder/deliveryStoryClosure.ts +521 -0
- package/ts/src/builder/deliveryStoryPlan.ts +536 -0
- package/ts/src/builder/deliveryStoryReady.ts +160 -0
- package/ts/src/builder/deliveryStoryRoadmapClosure.ts +151 -0
- package/ts/src/builder/expand.ts +336 -0
- package/ts/src/builder/flowUnit.ts +339 -0
- package/ts/src/builder/homeSurface.ts +122 -0
- package/ts/src/builder/implementationGuard.ts +125 -0
- package/ts/src/builder/index.ts +11 -0
- package/ts/src/builder/lifecycleRefusal.ts +92 -0
- package/ts/src/builder/lifecycleRibbon.ts +159 -0
- package/ts/src/builder/load.ts +313 -0
- package/ts/src/builder/methodAdoption.ts +113 -0
- package/ts/src/builder/methodDefinition.ts +429 -0
- package/ts/src/builder/methodInspection.ts +371 -0
- package/ts/src/builder/plan.ts +408 -0
- package/ts/src/builder/planPreauthorization.ts +265 -0
- package/ts/src/builder/prepare.ts +225 -0
- package/ts/src/builder/projectPaths.ts +64 -0
- package/ts/src/builder/pull.ts +356 -0
- package/ts/src/builder/pullCandidates.ts +463 -0
- package/ts/src/builder/pullCandidatesRender.ts +238 -0
- package/ts/src/builder/refinementField.ts +93 -0
- package/ts/src/builder/releaseIntent.ts +173 -0
- package/ts/src/builder/resumeState.ts +84 -0
- package/ts/src/builder/resumeSurface.ts +149 -0
- package/ts/src/builder/roadmapGrammar.ts +300 -0
- package/ts/src/builder/roadmapScan.ts +97 -0
- package/ts/src/builder/roadmapScope.ts +210 -0
- package/ts/src/builder/scopePhrases.ts +146 -0
- package/ts/src/builder/storyPaths.ts +196 -0
- package/ts/src/builder/storyPlanPreauthorization.ts +287 -0
- package/ts/src/builder/surfaceProtocol.ts +42 -0
- package/ts/src/builder/templateGeneration.ts +148 -0
- package/ts/src/builder/transition.ts +178 -0
- package/ts/src/consult/args.ts +99 -0
- package/ts/src/consult/core.ts +122 -0
- package/ts/src/consult/modelCatalog.ts +55 -0
- package/ts/src/consult/render.ts +47 -0
- package/ts/src/conversation/append.ts +414 -0
- package/ts/src/conversation/backfill.ts +387 -0
- package/ts/src/conversation/closeTail.ts +467 -0
- package/ts/src/conversation/extraction.ts +333 -0
- package/ts/src/conversation/extractionDriver.ts +130 -0
- package/ts/src/conversation/extractionRun.ts +70 -0
- package/ts/src/conversation/hookPayload.ts +51 -0
- package/ts/src/conversation/journeyInference.ts +165 -0
- package/ts/src/conversation/journeyRepair.ts +114 -0
- package/ts/src/conversation/lifecycleFaces.ts +197 -0
- package/ts/src/conversation/lifecycleWrites.ts +313 -0
- package/ts/src/conversation/listing.ts +77 -0
- package/ts/src/conversation/logger.ts +851 -0
- package/ts/src/conversation/loggerCli.ts +321 -0
- package/ts/src/conversation/loggerRuntime.ts +259 -0
- package/ts/src/conversation/metadataLifecycle.ts +443 -0
- package/ts/src/conversation/recall.ts +66 -0
- package/ts/src/conversation/sessionComposites.ts +258 -0
- package/ts/src/conversation/sessionImport.ts +90 -0
- package/ts/src/conversation/transcriptBackfill.ts +141 -0
- package/ts/src/cultivation/applyActions.ts +241 -0
- package/ts/src/cultivation/cluster.ts +86 -0
- package/ts/src/cultivation/consolidationStore.ts +281 -0
- package/ts/src/cultivation/promptContext.ts +62 -0
- package/ts/src/cultivation/propose.ts +305 -0
- package/ts/src/cultivation/scan.ts +155 -0
- package/ts/src/db/backupGate.ts +47 -0
- package/ts/src/db/bootstrap.ts +108 -0
- package/ts/src/db/bootstrapLock.ts +223 -0
- package/ts/src/db/copyGuard.ts +60 -0
- package/ts/src/db/database.ts +397 -0
- package/ts/src/db/decode.ts +66 -0
- package/ts/src/db/ftsIntegrity.ts +41 -0
- package/ts/src/db/migrateOnOpen.ts +214 -0
- package/ts/src/db/migrations.ts +576 -0
- package/ts/src/db/readyOnOpen.ts +35 -0
- package/ts/src/db/rowDecode.ts +42 -0
- package/ts/src/db/schema.ts +432 -0
- package/ts/src/db/schemaInventory.ts +225 -0
- package/ts/src/db/schemaInventorySnapshot.ts +2107 -0
- package/ts/src/db/schemaState.ts +91 -0
- package/ts/src/db/schemaTsDivergence.ts +114 -0
- package/ts/src/descriptor/descriptorRead.ts +49 -0
- package/ts/src/docs/docsLint.ts +265 -0
- package/ts/src/explorer/handoff.ts +522 -0
- package/ts/src/explorer/render.ts +335 -0
- package/ts/src/explorer/story.ts +769 -0
- package/ts/src/explorer/transition.ts +72 -0
- package/ts/src/extensions/bindings.ts +170 -0
- package/ts/src/extensions/catalog.ts +249 -0
- package/ts/src/extensions/catalogCommands.ts +513 -0
- package/ts/src/extensions/catalogWrites.ts +652 -0
- package/ts/src/extensions/contextRuntime.ts +325 -0
- package/ts/src/extensions/dispatch.ts +374 -0
- package/ts/src/extensions/errors.ts +24 -0
- package/ts/src/extensions/manifest.ts +356 -0
- package/ts/src/extensions/migrations.ts +350 -0
- package/ts/src/extraction/conversation.ts +304 -0
- package/ts/src/extraction/conversationMetadata.ts +206 -0
- package/ts/src/extraction/fencing.ts +106 -0
- package/ts/src/extraction/json.ts +17 -0
- package/ts/src/extraction/prompts.ts +470 -0
- package/ts/src/frontDoor/args.ts +30 -0
- package/ts/src/frontDoor/argvShape.ts +106 -0
- package/ts/src/frontDoor/buildLoadRuntime.ts +139 -0
- package/ts/src/frontDoor/buildRoute.ts +398 -0
- package/ts/src/frontDoor/cli.ts +1872 -0
- package/ts/src/frontDoor/cloneRoleGuard.ts +98 -0
- package/ts/src/frontDoor/consultRoute.ts +50 -0
- package/ts/src/frontDoor/contentTailRoute.ts +239 -0
- package/ts/src/frontDoor/conversationLoggerRoute.ts +83 -0
- package/ts/src/frontDoor/cultivationRoute.ts +210 -0
- package/ts/src/frontDoor/dbPath.ts +131 -0
- package/ts/src/frontDoor/dbSafetyToolsRoute.ts +240 -0
- package/ts/src/frontDoor/exploreRoute.ts +572 -0
- package/ts/src/frontDoor/extensionCatalogRoute.ts +252 -0
- package/ts/src/frontDoor/frontDoorLog.ts +57 -0
- package/ts/src/frontDoor/identityWrite.ts +36 -0
- package/ts/src/frontDoor/journeyWriteRoute.ts +26 -0
- package/ts/src/frontDoor/lifecycleWriteRoute.ts +110 -0
- package/ts/src/frontDoor/liveBackup.ts +100 -0
- package/ts/src/frontDoor/mirrorModeRoute.ts +163 -0
- package/ts/src/frontDoor/namedRefusal.ts +35 -0
- package/ts/src/frontDoor/nodeSupport.ts +24 -0
- package/ts/src/frontDoor/render/consolidate.ts +199 -0
- package/ts/src/frontDoor/render/conversations.ts +33 -0
- package/ts/src/frontDoor/render/cultivationShared.ts +21 -0
- package/ts/src/frontDoor/render/descriptor.ts +20 -0
- package/ts/src/frontDoor/render/detectPersona.ts +50 -0
- package/ts/src/frontDoor/render/icons.ts +13 -0
- package/ts/src/frontDoor/render/identity.ts +59 -0
- package/ts/src/frontDoor/render/identityRows.ts +17 -0
- package/ts/src/frontDoor/render/inspectPersona.ts +53 -0
- package/ts/src/frontDoor/render/journeyStatus.ts +78 -0
- package/ts/src/frontDoor/render/journeys.ts +79 -0
- package/ts/src/frontDoor/render/list.ts +41 -0
- package/ts/src/frontDoor/render/memories.ts +67 -0
- package/ts/src/frontDoor/render/recall.ts +49 -0
- package/ts/src/frontDoor/render/shadow.ts +155 -0
- package/ts/src/frontDoor/render/tasks.ts +99 -0
- package/ts/src/frontDoor/render/tasksImportSync.ts +63 -0
- package/ts/src/frontDoor/render/week.ts +113 -0
- package/ts/src/frontDoor/routing.ts +1001 -0
- package/ts/src/frontDoor/runtimeRoute.ts +623 -0
- package/ts/src/frontDoor/searchRoute.ts +166 -0
- package/ts/src/frontDoor/seedPaths.ts +98 -0
- package/ts/src/frontDoor/sessionStartWelcomeRoute.ts +166 -0
- package/ts/src/frontDoor/soulRoute.ts +433 -0
- package/ts/src/frontDoor/stdinSource.ts +37 -0
- package/ts/src/frontDoor/tasksImportSyncRoute.ts +110 -0
- package/ts/src/frontDoor/tasksWriteRoute.ts +101 -0
- package/ts/src/frontDoor/usage.ts +176 -0
- package/ts/src/guards/claudePlugin.ts +298 -0
- package/ts/src/guards/packContents.ts +306 -0
- package/ts/src/guards/piSourcedSkills.ts +70 -0
- package/ts/src/guards/retiredRouteShadows.ts +57 -0
- package/ts/src/guards/retiredSurfaces.ts +564 -0
- package/ts/src/hooks/claude.ts +214 -0
- package/ts/src/hooks/codex.ts +45 -0
- package/ts/src/hooks/gemini.ts +126 -0
- package/ts/src/hooks/main.ts +109 -0
- package/ts/src/hooks/mirrorState.ts +71 -0
- package/ts/src/hooks/payload.ts +73 -0
- package/ts/src/hooks/runtime.ts +179 -0
- package/ts/src/hooks/runtimeDetection.ts +34 -0
- package/ts/src/identity/applyConsolidationIdentityUpdate.ts +67 -0
- package/ts/src/identity/descriptorGenerate.ts +162 -0
- package/ts/src/identity/identityEdit.ts +143 -0
- package/ts/src/identity/identityKey.ts +77 -0
- package/ts/src/identity/identityRead.ts +69 -0
- package/ts/src/identity/identityStore.ts +80 -0
- package/ts/src/identity/journeyListing.ts +53 -0
- package/ts/src/identity/personaInspect.ts +44 -0
- package/ts/src/identity/personaListing.ts +37 -0
- package/ts/src/identity/setIdentity.ts +64 -0
- package/ts/src/index.ts +231 -0
- package/ts/src/init/init.ts +111 -0
- package/ts/src/journey/journeyOptions.ts +131 -0
- package/ts/src/journey/journeyRemoval.ts +158 -0
- package/ts/src/journey/journeyStatus.ts +149 -0
- package/ts/src/journey/journeySyncFile.ts +87 -0
- package/ts/src/journey/journeyWrite.ts +203 -0
- package/ts/src/journey/parentJourney.ts +41 -0
- package/ts/src/journey/validateParentJourney.ts +55 -0
- package/ts/src/mcp/boundary.ts +151 -0
- package/ts/src/mcp/guards.ts +244 -0
- package/ts/src/mcp/main.ts +121 -0
- package/ts/src/mcp/payload.ts +141 -0
- package/ts/src/mcp/protocol.ts +141 -0
- package/ts/src/mcp/readModels.ts +241 -0
- package/ts/src/mcp/registry.ts +201 -0
- package/ts/src/mcp/serve.ts +120 -0
- package/ts/src/mcp/tools/deterministic.ts +137 -0
- package/ts/src/mcp/tools/providerCrossing.ts +187 -0
- package/ts/src/mcp/wire.ts +8 -0
- package/ts/src/memory/journal.ts +180 -0
- package/ts/src/memory/listing.ts +107 -0
- package/ts/src/memory/memoryWrite.ts +88 -0
- package/ts/src/memory/reinforcement.ts +35 -0
- package/ts/src/mirror/context.ts +161 -0
- package/ts/src/mirror/defaultResolution.ts +199 -0
- package/ts/src/mirror/mirrorForm.ts +43 -0
- package/ts/src/mirror/orchestration.ts +364 -0
- package/ts/src/mirror/reception.ts +194 -0
- package/ts/src/mirror/render.ts +75 -0
- package/ts/src/mirror/runtimeSession.ts +205 -0
- package/ts/src/mode/operatingMode.ts +148 -0
- package/ts/src/observability/callOutcome.ts +115 -0
- package/ts/src/observability/inspectLedger.ts +329 -0
- package/ts/src/observability/ledgerHooks.ts +126 -0
- package/ts/src/observability/llmCalls.ts +154 -0
- package/ts/src/persona/detectPersona.ts +81 -0
- package/ts/src/planning/promptAssembly.ts +111 -0
- package/ts/src/planning/weekPending.ts +81 -0
- package/ts/src/planning/weekPlan.ts +183 -0
- package/ts/src/planning/weekSave.ts +117 -0
- package/ts/src/providers/config.ts +189 -0
- package/ts/src/providers/cost.ts +64 -0
- package/ts/src/providers/credits.ts +204 -0
- package/ts/src/providers/embedding.ts +321 -0
- package/ts/src/providers/familyProviders.ts +147 -0
- package/ts/src/providers/llm.ts +334 -0
- package/ts/src/providers/openrouter.ts +244 -0
- package/ts/src/providers/redaction.ts +110 -0
- package/ts/src/providers/replay.ts +15 -0
- package/ts/src/providers/transport.ts +410 -0
- package/ts/src/repair/encodingRepair.ts +253 -0
- package/ts/src/runtime/backup.ts +151 -0
- package/ts/src/runtime/channel.ts +146 -0
- package/ts/src/runtime/config.ts +168 -0
- package/ts/src/runtime/diagnose.ts +686 -0
- package/ts/src/runtime/git.ts +510 -0
- package/ts/src/runtime/installKind.ts +220 -0
- package/ts/src/runtime/migrate.ts +154 -0
- package/ts/src/runtime/packageIdentity.ts +102 -0
- package/ts/src/runtime/releaseNotes.ts +244 -0
- package/ts/src/runtime/status.ts +557 -0
- package/ts/src/runtime/strategies/clone.ts +200 -0
- package/ts/src/runtime/strategies/package.ts +328 -0
- package/ts/src/runtime/treeRoot.ts +30 -0
- package/ts/src/runtime/update.ts +445 -0
- package/ts/src/runtime/updateGate.ts +40 -0
- package/ts/src/runtime/updatePipeline.ts +159 -0
- package/ts/src/runtime/version.ts +36 -0
- package/ts/src/runtime/wiring.ts +130 -0
- package/ts/src/search/memorySearch.ts +338 -0
- package/ts/src/search/ranker.ts +154 -0
- package/ts/src/seed/seed.ts +256 -0
- package/ts/src/seed/seedYaml.ts +133 -0
- package/ts/src/soul/apply.ts +218 -0
- package/ts/src/soul/harvest.ts +267 -0
- package/ts/src/soul/prompts/soul_beauty_voice.md +103 -0
- package/ts/src/soul/prompts/soul_self_voice.md +219 -0
- package/ts/src/soul/prompts/soul_wisdom_voice.md +121 -0
- package/ts/src/soul/prompts.ts +85 -0
- package/ts/src/soul/render.ts +358 -0
- package/ts/src/soul/state.ts +212 -0
- package/ts/src/soul/transition.ts +37 -0
- package/ts/src/tasks/journeyPathParse.ts +113 -0
- package/ts/src/tasks/taskImportSync.ts +142 -0
- package/ts/src/tasks/taskStore.ts +312 -0
- package/ts/src/tasks/weekView.ts +120 -0
- package/ts/src/util/clipCodePoints.ts +26 -0
- package/ts/src/util/paths.ts +63 -0
- package/ts/src/util/program.ts +9 -0
- package/ts/src/util/pyGenerators.ts +144 -0
- package/ts/src/util/pythonText.ts +317 -0
- package/ts/src/util/semver.ts +45 -0
- package/ts/src/util/shellWord.ts +25 -0
- package/ts/src/util/slug.ts +64 -0
- package/ts/src/welcome/card.ts +339 -0
- package/ts/src/welcome/statusLine.ts +101 -0
- package/ts/src/welcome/updateCache.ts +129 -0
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
// Fresh-database schema DDL — the TS core's first slice of schema custody
|
|
2
|
+
// (CV22.DS6.TS1).
|
|
3
|
+
//
|
|
4
|
+
// This is a structural port of Python's `SCHEMA`
|
|
5
|
+
// (`src/memory/db/schema.py`), comments rewritten to English per CV0. Every
|
|
6
|
+
// `CREATE TABLE`/`CREATE INDEX`/`CREATE VIRTUAL TABLE`/`CREATE TRIGGER`
|
|
7
|
+
// statement here must stay a faithful structural match of the Python source:
|
|
8
|
+
// same tables, columns, types, defaults, primary keys, foreign keys, indexes
|
|
9
|
+
// (including partial predicates), CHECK constraints, and the `memories_fts`
|
|
10
|
+
// FTS5 external-content configuration and its shadow triggers.
|
|
11
|
+
// `ts/src/db/schema.test.ts` proves this structurally (not textually — see
|
|
12
|
+
// `schemaInventory.ts`) against a snapshot committed from the Python side.
|
|
13
|
+
//
|
|
14
|
+
// Scope boundary: this module owns DDL only. It does NOT run migrations or
|
|
15
|
+
// seed `_migrations` bookkeeping (CV22.DS6.TS2). Its two callers compose it
|
|
16
|
+
// AFTER `runMigrations`, the order Python's `get_connection` used on every
|
|
17
|
+
// open: `bootstrapDatabase` for a new file, and migrate-on-open's slow path
|
|
18
|
+
// for an existing one (CV22.DS10.TS5 handoff review, B1). That is how a
|
|
19
|
+
// database older than an object only this DDL creates, such as
|
|
20
|
+
// `_ext_bindings`, still gets it. `createSchema` is safe to call against an
|
|
21
|
+
// already-populated database (every statement is `IF NOT EXISTS`) and safe to
|
|
22
|
+
// call twice.
|
|
23
|
+
//
|
|
24
|
+
// The `identity` table's `layer`/`key` enumeration comments are preserved
|
|
25
|
+
// verbatim from the Python source (translated word-for-word, not paraphrased)
|
|
26
|
+
// — they are the de facto documentation of the identity taxonomy that prompt
|
|
27
|
+
// composition depends on.
|
|
28
|
+
|
|
29
|
+
import type { WritableDatabase } from "./database.ts";
|
|
30
|
+
|
|
31
|
+
export const SCHEMA = `
|
|
32
|
+
CREATE TABLE IF NOT EXISTS conversations (
|
|
33
|
+
id TEXT PRIMARY KEY,
|
|
34
|
+
title TEXT,
|
|
35
|
+
started_at TEXT NOT NULL,
|
|
36
|
+
ended_at TEXT,
|
|
37
|
+
interface TEXT NOT NULL,
|
|
38
|
+
persona TEXT,
|
|
39
|
+
journey TEXT,
|
|
40
|
+
summary TEXT,
|
|
41
|
+
tags TEXT,
|
|
42
|
+
metadata TEXT
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
CREATE TABLE IF NOT EXISTS messages (
|
|
46
|
+
id TEXT PRIMARY KEY,
|
|
47
|
+
conversation_id TEXT NOT NULL REFERENCES conversations(id),
|
|
48
|
+
role TEXT NOT NULL,
|
|
49
|
+
content TEXT NOT NULL,
|
|
50
|
+
created_at TEXT NOT NULL,
|
|
51
|
+
token_count INTEGER,
|
|
52
|
+
metadata TEXT
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
CREATE TABLE IF NOT EXISTS memories (
|
|
56
|
+
id TEXT PRIMARY KEY,
|
|
57
|
+
conversation_id TEXT REFERENCES conversations(id),
|
|
58
|
+
memory_type TEXT NOT NULL,
|
|
59
|
+
layer TEXT NOT NULL DEFAULT 'ego',
|
|
60
|
+
title TEXT NOT NULL,
|
|
61
|
+
content TEXT NOT NULL,
|
|
62
|
+
context TEXT,
|
|
63
|
+
journey TEXT,
|
|
64
|
+
persona TEXT,
|
|
65
|
+
tags TEXT,
|
|
66
|
+
created_at TEXT NOT NULL,
|
|
67
|
+
relevance_score REAL DEFAULT 1.0,
|
|
68
|
+
embedding BLOB,
|
|
69
|
+
metadata TEXT,
|
|
70
|
+
last_accessed_at TEXT,
|
|
71
|
+
use_count INTEGER NOT NULL DEFAULT 0,
|
|
72
|
+
readiness_state TEXT NOT NULL DEFAULT 'observed'
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
CREATE TABLE IF NOT EXISTS conversation_embeddings (
|
|
76
|
+
conversation_id TEXT PRIMARY KEY REFERENCES conversations(id),
|
|
77
|
+
summary_embedding BLOB
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
CREATE TABLE IF NOT EXISTS runtime_sessions (
|
|
81
|
+
session_id TEXT PRIMARY KEY,
|
|
82
|
+
conversation_id TEXT REFERENCES conversations(id),
|
|
83
|
+
interface TEXT,
|
|
84
|
+
mirror_active INTEGER NOT NULL DEFAULT 0,
|
|
85
|
+
persona TEXT,
|
|
86
|
+
journey TEXT,
|
|
87
|
+
hook_injected INTEGER NOT NULL DEFAULT 0,
|
|
88
|
+
active INTEGER NOT NULL DEFAULT 1,
|
|
89
|
+
started_at TEXT NOT NULL,
|
|
90
|
+
updated_at TEXT NOT NULL,
|
|
91
|
+
closed_at TEXT,
|
|
92
|
+
metadata TEXT
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
CREATE INDEX IF NOT EXISTS idx_runtime_sessions_conversation ON runtime_sessions(conversation_id);
|
|
96
|
+
CREATE INDEX IF NOT EXISTS idx_runtime_sessions_active ON runtime_sessions(active);
|
|
97
|
+
|
|
98
|
+
CREATE TABLE IF NOT EXISTS builder_refinement_stories (
|
|
99
|
+
id TEXT PRIMARY KEY,
|
|
100
|
+
journey TEXT NOT NULL,
|
|
101
|
+
display_code TEXT NOT NULL,
|
|
102
|
+
title TEXT NOT NULL,
|
|
103
|
+
description TEXT,
|
|
104
|
+
status TEXT NOT NULL DEFAULT 'draft',
|
|
105
|
+
position INTEGER NOT NULL DEFAULT 0,
|
|
106
|
+
source TEXT NOT NULL DEFAULT 'manual',
|
|
107
|
+
provenance TEXT,
|
|
108
|
+
created_at TEXT NOT NULL,
|
|
109
|
+
updated_at TEXT NOT NULL,
|
|
110
|
+
pulled_at TEXT,
|
|
111
|
+
closed_at TEXT,
|
|
112
|
+
CHECK(status IN ('draft', 'open', 'active', 'closed', 'parked'))
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
CREATE INDEX IF NOT EXISTS idx_builder_refinement_stories_journey_status
|
|
116
|
+
ON builder_refinement_stories(journey, status, position, updated_at);
|
|
117
|
+
CREATE UNIQUE INDEX IF NOT EXISTS ux_builder_refinement_stories_journey_display_code
|
|
118
|
+
ON builder_refinement_stories(journey, display_code);
|
|
119
|
+
|
|
120
|
+
CREATE TABLE IF NOT EXISTS builder_change_requests (
|
|
121
|
+
id TEXT PRIMARY KEY,
|
|
122
|
+
journey TEXT NOT NULL,
|
|
123
|
+
display_code TEXT NOT NULL,
|
|
124
|
+
refinement_story_id TEXT REFERENCES builder_refinement_stories(id),
|
|
125
|
+
title TEXT NOT NULL,
|
|
126
|
+
body TEXT NOT NULL,
|
|
127
|
+
status TEXT NOT NULL DEFAULT 'captured',
|
|
128
|
+
position INTEGER NOT NULL DEFAULT 0,
|
|
129
|
+
source TEXT NOT NULL DEFAULT 'manual',
|
|
130
|
+
provenance TEXT,
|
|
131
|
+
outcome_notes TEXT,
|
|
132
|
+
created_at TEXT NOT NULL,
|
|
133
|
+
updated_at TEXT NOT NULL,
|
|
134
|
+
completed_at TEXT,
|
|
135
|
+
CHECK(status IN (
|
|
136
|
+
'captured', 'planned', 'active', 'implemented', 'validated',
|
|
137
|
+
'done', 'parked', 'rejected', 'promoted'
|
|
138
|
+
))
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
CREATE INDEX IF NOT EXISTS idx_builder_change_requests_story_status
|
|
142
|
+
ON builder_change_requests(journey, refinement_story_id, status, position, updated_at);
|
|
143
|
+
CREATE INDEX IF NOT EXISTS idx_builder_change_requests_journey_status
|
|
144
|
+
ON builder_change_requests(journey, status, updated_at);
|
|
145
|
+
CREATE UNIQUE INDEX IF NOT EXISTS ux_builder_change_requests_journey_display_code
|
|
146
|
+
ON builder_change_requests(journey, display_code);
|
|
147
|
+
|
|
148
|
+
CREATE TABLE IF NOT EXISTS builder_refinement_cursors (
|
|
149
|
+
journey TEXT PRIMARY KEY,
|
|
150
|
+
active_refinement_story_id TEXT REFERENCES builder_refinement_stories(id),
|
|
151
|
+
active_change_request_id TEXT REFERENCES builder_change_requests(id),
|
|
152
|
+
last_refinement_event TEXT,
|
|
153
|
+
updated_at TEXT NOT NULL
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
CREATE TABLE IF NOT EXISTS memory_access_log (
|
|
157
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
158
|
+
memory_id TEXT NOT NULL REFERENCES memories(id),
|
|
159
|
+
accessed_at TEXT NOT NULL,
|
|
160
|
+
access_context TEXT
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
CREATE INDEX IF NOT EXISTS idx_messages_conversation ON messages(conversation_id);
|
|
164
|
+
CREATE INDEX IF NOT EXISTS idx_memories_type ON memories(memory_type);
|
|
165
|
+
CREATE INDEX IF NOT EXISTS idx_memories_layer ON memories(layer);
|
|
166
|
+
CREATE INDEX IF NOT EXISTS idx_memories_journey ON memories(journey);
|
|
167
|
+
CREATE INDEX IF NOT EXISTS idx_memories_created ON memories(created_at);
|
|
168
|
+
CREATE INDEX IF NOT EXISTS idx_access_log_memory ON memory_access_log(memory_id);
|
|
169
|
+
|
|
170
|
+
-- Column order intentionally does NOT match src/memory/db/schema.py's literal
|
|
171
|
+
-- text. On a real fresh Python database, migrations run before SCHEMA:
|
|
172
|
+
-- migration 003_create_tasks creates this table without scheduled_at/time_hint,
|
|
173
|
+
-- then 004_tasks_temporal_fields ALTER TABLE ADD COLUMNs them afterward, which
|
|
174
|
+
-- always appends at the end regardless of where they appear in schema.py's
|
|
175
|
+
-- aspirational inline text (SCHEMA's own CREATE TABLE IF NOT EXISTS never
|
|
176
|
+
-- fires for tasks in practice, since migrations already created it). This
|
|
177
|
+
-- order matches the true output of Python's actual bootstrap path, proven by
|
|
178
|
+
-- CV22.DS6.TS1's structural-parity test against a real fresh Python database.
|
|
179
|
+
CREATE TABLE IF NOT EXISTS tasks (
|
|
180
|
+
id TEXT PRIMARY KEY,
|
|
181
|
+
journey TEXT,
|
|
182
|
+
title TEXT NOT NULL,
|
|
183
|
+
status TEXT NOT NULL DEFAULT 'todo',
|
|
184
|
+
due_date TEXT,
|
|
185
|
+
stage TEXT,
|
|
186
|
+
context TEXT,
|
|
187
|
+
source TEXT NOT NULL DEFAULT 'manual',
|
|
188
|
+
created_at TEXT NOT NULL,
|
|
189
|
+
updated_at TEXT NOT NULL,
|
|
190
|
+
completed_at TEXT,
|
|
191
|
+
metadata TEXT,
|
|
192
|
+
scheduled_at TEXT,
|
|
193
|
+
time_hint TEXT
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
CREATE INDEX IF NOT EXISTS idx_tasks_journey ON tasks(journey);
|
|
197
|
+
CREATE INDEX IF NOT EXISTS idx_tasks_status ON tasks(status);
|
|
198
|
+
CREATE INDEX IF NOT EXISTS idx_tasks_due_date ON tasks(due_date);
|
|
199
|
+
|
|
200
|
+
CREATE TABLE IF NOT EXISTS identity (
|
|
201
|
+
id TEXT PRIMARY KEY,
|
|
202
|
+
layer TEXT NOT NULL, -- 'self', 'ego', 'user', 'organization', 'persona', 'journey', 'journey_path'
|
|
203
|
+
key TEXT NOT NULL, -- 'soul', 'behavior', 'identity', 'principles', or persona_id
|
|
204
|
+
content TEXT NOT NULL, -- prompt content (markdown/text)
|
|
205
|
+
version TEXT DEFAULT '1.0.0',
|
|
206
|
+
created_at TEXT NOT NULL,
|
|
207
|
+
updated_at TEXT NOT NULL,
|
|
208
|
+
metadata TEXT,
|
|
209
|
+
parent_journey TEXT, -- journey hierarchy, first-class (CV22.DS6.US2); mirrored in metadata JSON during the transition
|
|
210
|
+
UNIQUE(layer, key)
|
|
211
|
+
);
|
|
212
|
+
CREATE INDEX IF NOT EXISTS idx_identity_parent_journey ON identity(parent_journey) WHERE parent_journey IS NOT NULL;
|
|
213
|
+
|
|
214
|
+
CREATE TABLE IF NOT EXISTS journey_mutation_receipts (
|
|
215
|
+
request_id TEXT PRIMARY KEY,
|
|
216
|
+
request_digest TEXT NOT NULL,
|
|
217
|
+
source_version TEXT NOT NULL,
|
|
218
|
+
result_version TEXT NOT NULL,
|
|
219
|
+
operation TEXT NOT NULL,
|
|
220
|
+
journey_id TEXT NOT NULL,
|
|
221
|
+
created_at TEXT NOT NULL
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
CREATE TABLE IF NOT EXISTS identity_integrations (
|
|
225
|
+
id TEXT PRIMARY KEY,
|
|
226
|
+
layer TEXT NOT NULL,
|
|
227
|
+
key TEXT NOT NULL,
|
|
228
|
+
content TEXT NOT NULL,
|
|
229
|
+
source TEXT NOT NULL DEFAULT 'soul_mode',
|
|
230
|
+
origin TEXT,
|
|
231
|
+
conversation_id TEXT REFERENCES conversations(id),
|
|
232
|
+
journal_id TEXT REFERENCES memories(id),
|
|
233
|
+
created_at TEXT NOT NULL,
|
|
234
|
+
status TEXT NOT NULL DEFAULT 'active',
|
|
235
|
+
metadata TEXT NOT NULL DEFAULT '{}'
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
CREATE INDEX IF NOT EXISTS idx_identity_integrations_target
|
|
239
|
+
ON identity_integrations(layer, key, created_at);
|
|
240
|
+
CREATE INDEX IF NOT EXISTS idx_identity_integrations_status
|
|
241
|
+
ON identity_integrations(status);
|
|
242
|
+
|
|
243
|
+
CREATE TABLE IF NOT EXISTS attachments (
|
|
244
|
+
id TEXT PRIMARY KEY,
|
|
245
|
+
journey_id TEXT NOT NULL,
|
|
246
|
+
name TEXT NOT NULL,
|
|
247
|
+
description TEXT,
|
|
248
|
+
content TEXT NOT NULL,
|
|
249
|
+
content_type TEXT NOT NULL DEFAULT 'markdown',
|
|
250
|
+
tags TEXT,
|
|
251
|
+
embedding BLOB,
|
|
252
|
+
created_at TEXT NOT NULL,
|
|
253
|
+
updated_at TEXT NOT NULL,
|
|
254
|
+
metadata TEXT
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
CREATE INDEX IF NOT EXISTS idx_attachments_journey ON attachments(journey_id);
|
|
258
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_attachments_journey_name ON attachments(journey_id, name);
|
|
259
|
+
|
|
260
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS memories_fts USING fts5(
|
|
261
|
+
title,
|
|
262
|
+
content,
|
|
263
|
+
context,
|
|
264
|
+
content=memories,
|
|
265
|
+
content_rowid=rowid
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
CREATE TRIGGER IF NOT EXISTS memories_fts_ai AFTER INSERT ON memories BEGIN
|
|
269
|
+
INSERT INTO memories_fts(rowid, title, content, context)
|
|
270
|
+
VALUES (NEW.rowid, NEW.title, NEW.content, COALESCE(NEW.context, ''));
|
|
271
|
+
END;
|
|
272
|
+
|
|
273
|
+
CREATE TRIGGER IF NOT EXISTS memories_fts_ad AFTER DELETE ON memories BEGIN
|
|
274
|
+
INSERT INTO memories_fts(memories_fts, rowid, title, content, context)
|
|
275
|
+
VALUES ('delete', OLD.rowid, OLD.title, OLD.content, COALESCE(OLD.context, ''));
|
|
276
|
+
END;
|
|
277
|
+
|
|
278
|
+
CREATE TRIGGER IF NOT EXISTS memories_fts_au AFTER UPDATE ON memories BEGIN
|
|
279
|
+
INSERT INTO memories_fts(memories_fts, rowid, title, content, context)
|
|
280
|
+
VALUES ('delete', OLD.rowid, OLD.title, OLD.content, COALESCE(OLD.context, ''));
|
|
281
|
+
INSERT INTO memories_fts(rowid, title, content, context)
|
|
282
|
+
VALUES (NEW.rowid, NEW.title, NEW.content, COALESCE(NEW.context, ''));
|
|
283
|
+
END;
|
|
284
|
+
|
|
285
|
+
CREATE TABLE IF NOT EXISTS identity_descriptors (
|
|
286
|
+
layer TEXT NOT NULL,
|
|
287
|
+
key TEXT NOT NULL,
|
|
288
|
+
descriptor TEXT NOT NULL,
|
|
289
|
+
generated_at TEXT NOT NULL,
|
|
290
|
+
PRIMARY KEY (layer, key)
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
CREATE TABLE IF NOT EXISTS consolidations (
|
|
294
|
+
id TEXT PRIMARY KEY,
|
|
295
|
+
action TEXT NOT NULL, -- 'merge' | 'identity_update' | 'shadow_candidate'
|
|
296
|
+
proposal TEXT NOT NULL, -- LLM-generated proposal (full markdown text)
|
|
297
|
+
result TEXT, -- content actually written (accepted as-is or user-edited)
|
|
298
|
+
source_memory_ids TEXT NOT NULL, -- JSON array of Memory.id values
|
|
299
|
+
target_layer TEXT, -- 'ego', 'self', 'shadow' (for identity_update)
|
|
300
|
+
target_key TEXT, -- 'behavior', 'soul', etc. (for identity_update)
|
|
301
|
+
rationale TEXT, -- one-sentence LLM rationale for the chosen action
|
|
302
|
+
status TEXT NOT NULL DEFAULT 'pending', -- 'pending' | 'accepted' | 'rejected'
|
|
303
|
+
created_at TEXT NOT NULL,
|
|
304
|
+
reviewed_at TEXT
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
CREATE INDEX IF NOT EXISTS idx_consolidations_status ON consolidations(status);
|
|
308
|
+
CREATE INDEX IF NOT EXISTS idx_consolidations_created ON consolidations(created_at);
|
|
309
|
+
|
|
310
|
+
CREATE TABLE IF NOT EXISTS llm_calls (
|
|
311
|
+
id TEXT PRIMARY KEY,
|
|
312
|
+
role TEXT NOT NULL,
|
|
313
|
+
model TEXT NOT NULL,
|
|
314
|
+
prompt TEXT NOT NULL,
|
|
315
|
+
response TEXT NOT NULL,
|
|
316
|
+
prompt_tokens INTEGER,
|
|
317
|
+
completion_tokens INTEGER,
|
|
318
|
+
latency_ms INTEGER,
|
|
319
|
+
cost_usd REAL,
|
|
320
|
+
conversation_id TEXT REFERENCES conversations(id),
|
|
321
|
+
session_id TEXT,
|
|
322
|
+
called_at TEXT NOT NULL
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
CREATE INDEX IF NOT EXISTS idx_llm_calls_conversation ON llm_calls(conversation_id);
|
|
326
|
+
CREATE INDEX IF NOT EXISTS idx_llm_calls_role ON llm_calls(role);
|
|
327
|
+
CREATE INDEX IF NOT EXISTS idx_llm_calls_called_at ON llm_calls(called_at);
|
|
328
|
+
|
|
329
|
+
CREATE TABLE IF NOT EXISTS operation_runs (
|
|
330
|
+
id TEXT PRIMARY KEY,
|
|
331
|
+
operation_id TEXT NOT NULL,
|
|
332
|
+
status TEXT NOT NULL,
|
|
333
|
+
outcome TEXT,
|
|
334
|
+
parameters_json TEXT NOT NULL,
|
|
335
|
+
summary_json TEXT,
|
|
336
|
+
result_json TEXT,
|
|
337
|
+
error TEXT,
|
|
338
|
+
started_at TEXT NOT NULL,
|
|
339
|
+
completed_at TEXT,
|
|
340
|
+
created_at TEXT NOT NULL
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
CREATE INDEX IF NOT EXISTS idx_operation_runs_operation ON operation_runs(operation_id);
|
|
344
|
+
CREATE INDEX IF NOT EXISTS idx_operation_runs_started ON operation_runs(started_at);
|
|
345
|
+
CREATE INDEX IF NOT EXISTS idx_operation_runs_status ON operation_runs(status);
|
|
346
|
+
|
|
347
|
+
CREATE TABLE IF NOT EXISTS operation_run_events (
|
|
348
|
+
id TEXT PRIMARY KEY,
|
|
349
|
+
run_id TEXT NOT NULL REFERENCES operation_runs(id) ON DELETE CASCADE,
|
|
350
|
+
sequence INTEGER NOT NULL,
|
|
351
|
+
kind TEXT NOT NULL,
|
|
352
|
+
message TEXT NOT NULL,
|
|
353
|
+
details_json TEXT,
|
|
354
|
+
created_at TEXT NOT NULL
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
CREATE INDEX IF NOT EXISTS idx_operation_run_events_run
|
|
358
|
+
ON operation_run_events(run_id, sequence);
|
|
359
|
+
|
|
360
|
+
CREATE TABLE IF NOT EXISTS exploratory_stories (
|
|
361
|
+
id TEXT PRIMARY KEY,
|
|
362
|
+
journey TEXT NOT NULL,
|
|
363
|
+
title TEXT,
|
|
364
|
+
status TEXT NOT NULL DEFAULT 'active',
|
|
365
|
+
current_story TEXT,
|
|
366
|
+
narrative_summary TEXT,
|
|
367
|
+
last_story_card TEXT,
|
|
368
|
+
attractors_json TEXT,
|
|
369
|
+
experiment_proposal_json TEXT,
|
|
370
|
+
builder_handoff_json TEXT,
|
|
371
|
+
source_conversations_json TEXT,
|
|
372
|
+
artifact_dir TEXT,
|
|
373
|
+
created_at TEXT NOT NULL,
|
|
374
|
+
updated_at TEXT NOT NULL,
|
|
375
|
+
promoted_at TEXT,
|
|
376
|
+
archived_at TEXT,
|
|
377
|
+
CHECK(status IN ('active', 'archived', 'promoted'))
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
CREATE INDEX IF NOT EXISTS idx_exploratory_stories_journey
|
|
381
|
+
ON exploratory_stories(journey, updated_at);
|
|
382
|
+
CREATE INDEX IF NOT EXISTS idx_exploratory_stories_status
|
|
383
|
+
ON exploratory_stories(status);
|
|
384
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_exploratory_stories_one_active_per_journey
|
|
385
|
+
ON exploratory_stories(journey)
|
|
386
|
+
WHERE status = 'active';
|
|
387
|
+
|
|
388
|
+
-- Extension subsystem bookkeeping.
|
|
389
|
+
--
|
|
390
|
+
-- _ext_migrations tracks which SQL migration files have been applied per
|
|
391
|
+
-- extension. The checksum guards against in-place edits to an applied
|
|
392
|
+
-- migration: the runner refuses to skip or replay a file whose contents
|
|
393
|
+
-- changed since it was first applied.
|
|
394
|
+
--
|
|
395
|
+
-- _ext_bindings maps an extension's capabilities to integration targets
|
|
396
|
+
-- (typically a persona). The Mirror Mode context dispatcher reads this
|
|
397
|
+
-- table after persona resolution to decide which extension providers to
|
|
398
|
+
-- invoke. See docs/product/extensions/binding-model.md.
|
|
399
|
+
CREATE TABLE IF NOT EXISTS _ext_migrations (
|
|
400
|
+
extension_id TEXT NOT NULL,
|
|
401
|
+
filename TEXT NOT NULL,
|
|
402
|
+
checksum TEXT NOT NULL,
|
|
403
|
+
applied_at TEXT NOT NULL,
|
|
404
|
+
PRIMARY KEY (extension_id, filename)
|
|
405
|
+
);
|
|
406
|
+
|
|
407
|
+
CREATE TABLE IF NOT EXISTS _ext_bindings (
|
|
408
|
+
extension_id TEXT NOT NULL,
|
|
409
|
+
capability_id TEXT NOT NULL,
|
|
410
|
+
target_kind TEXT NOT NULL, -- 'persona' | 'journey' | 'global'
|
|
411
|
+
target_id TEXT, -- NULL only when target_kind = 'global'
|
|
412
|
+
created_at TEXT NOT NULL,
|
|
413
|
+
PRIMARY KEY (extension_id, capability_id, target_kind, target_id)
|
|
414
|
+
);
|
|
415
|
+
|
|
416
|
+
CREATE INDEX IF NOT EXISTS idx_ext_bindings_target
|
|
417
|
+
ON _ext_bindings(target_kind, target_id);
|
|
418
|
+
`;
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Create the fresh-database schema on `db`. Idempotent — every statement is
|
|
422
|
+
* `IF NOT EXISTS` — so calling this against an already-populated database is
|
|
423
|
+
* a safe no-op that leaves existing data untouched, and calling it twice in a
|
|
424
|
+
* row is not an error.
|
|
425
|
+
*
|
|
426
|
+
* Scope: DDL only. Does not run migrations, does not seed `_migrations`
|
|
427
|
+
* bookkeeping (CV22.DS6.TS2), does not apply locking or connection pragmas
|
|
428
|
+
* (CV22.DS6.TS3) — see the module comment.
|
|
429
|
+
*/
|
|
430
|
+
export function createSchema(db: WritableDatabase): void {
|
|
431
|
+
db.exec(SCHEMA);
|
|
432
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
// Canonical, cross-language schema inventory for the TS custody-transfer
|
|
2
|
+
// contract (CV22.DS6.TS1).
|
|
3
|
+
//
|
|
4
|
+
// Independent TypeScript implementation of `src/memory/db/schema_inventory.py`
|
|
5
|
+
// — see that module's docstring for the full contract: why parity is proven
|
|
6
|
+
// structurally (not by comparing raw `sqlite_master.sql` text, since CV0
|
|
7
|
+
// rewrites DDL comments to English while the frozen Python DDL keeps its
|
|
8
|
+
// historical mixed-language comments), and why FTS5-internal shadow tables
|
|
9
|
+
// (`<virtual-table>_data`/`_idx`/`_docsize`/`_config`/`_content`) are excluded
|
|
10
|
+
// (their internal shape is a SQLite-library-version implementation detail,
|
|
11
|
+
// not part of our DDL contract).
|
|
12
|
+
//
|
|
13
|
+
// The two implementations must produce byte-identical canonical output for
|
|
14
|
+
// equivalent schemas: `schemaInventorySnapshot.ts` is a snapshot committed
|
|
15
|
+
// from the Python side, and `schema.test.ts` asserts a TS-created database's
|
|
16
|
+
// inventory (via this module) equals it.
|
|
17
|
+
|
|
18
|
+
import type { Database } from "./database.ts";
|
|
19
|
+
|
|
20
|
+
export interface ColumnInventory {
|
|
21
|
+
name: string;
|
|
22
|
+
type: string;
|
|
23
|
+
notnull: number;
|
|
24
|
+
dflt_value: string | null;
|
|
25
|
+
pk: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ForeignKeyInventory {
|
|
29
|
+
table: string;
|
|
30
|
+
from: string;
|
|
31
|
+
to: string;
|
|
32
|
+
on_update: string;
|
|
33
|
+
on_delete: string;
|
|
34
|
+
match: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface TableInventory {
|
|
38
|
+
columns: ColumnInventory[];
|
|
39
|
+
foreign_keys: ForeignKeyInventory[];
|
|
40
|
+
sql: string | null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface IndexInventory {
|
|
44
|
+
table: string;
|
|
45
|
+
unique: number;
|
|
46
|
+
columns: string[];
|
|
47
|
+
sql: string | null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface TriggerInventory {
|
|
51
|
+
table: string;
|
|
52
|
+
sql: string | null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface SchemaInventory {
|
|
56
|
+
tables: Record<string, TableInventory>;
|
|
57
|
+
indexes: Record<string, IndexInventory>;
|
|
58
|
+
triggers: Record<string, TriggerInventory>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Tables that are custody-transfer scope boundaries, not part of the TS1 DDL
|
|
62
|
+
// contract:
|
|
63
|
+
// - `_migrations`: bookkeeping for the migration engine (CV22.DS6.TS2). A
|
|
64
|
+
// fresh Python database has it (via `run_migrations`); a TS1
|
|
65
|
+
// `createSchema()` fresh database intentionally does not yet.
|
|
66
|
+
// - `sqlite_sequence`: SQLite's own AUTOINCREMENT bookkeeping table.
|
|
67
|
+
const EXCLUDED_TABLES = new Set(["_migrations", "sqlite_sequence"]);
|
|
68
|
+
|
|
69
|
+
const FTS_SHADOW_SUFFIXES = ["_data", "_idx", "_docsize", "_config", "_content"];
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Strip SQL comments and collapse whitespace, preserving string literals.
|
|
73
|
+
* Also strips whitespace immediately before `,`/`)` — the shape SQLite's own
|
|
74
|
+
* `ALTER TABLE ADD COLUMN` produces when it textually splices a new column
|
|
75
|
+
* definition into a table's stored `CREATE TABLE` text. Must stay
|
|
76
|
+
* behaviorally identical to `memory.db.schema_inventory.normalize_sql`
|
|
77
|
+
* (Python) — keep the two in lockstep.
|
|
78
|
+
*/
|
|
79
|
+
export function normalizeSql(sql: string | null): string | null {
|
|
80
|
+
if (sql === null) return null;
|
|
81
|
+
const out: string[] = [];
|
|
82
|
+
let inString = false;
|
|
83
|
+
let i = 0;
|
|
84
|
+
const n = sql.length;
|
|
85
|
+
while (i < n) {
|
|
86
|
+
const ch = sql[i];
|
|
87
|
+
if (inString) {
|
|
88
|
+
out.push(ch);
|
|
89
|
+
if (ch === "'") {
|
|
90
|
+
if (i + 1 < n && sql[i + 1] === "'") {
|
|
91
|
+
out.push(sql[i + 1] as string);
|
|
92
|
+
i += 2;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
inString = false;
|
|
96
|
+
}
|
|
97
|
+
i += 1;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (ch === "'") {
|
|
101
|
+
inString = true;
|
|
102
|
+
out.push(ch);
|
|
103
|
+
i += 1;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (ch === "-" && i + 1 < n && sql[i + 1] === "-") {
|
|
107
|
+
const newline = sql.indexOf("\n", i);
|
|
108
|
+
i = newline === -1 ? n : newline;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (ch === "/" && i + 1 < n && sql[i + 1] === "*") {
|
|
112
|
+
const end = sql.indexOf("*/", i + 2);
|
|
113
|
+
i = end === -1 ? n : end + 2;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
out.push(ch as string);
|
|
117
|
+
i += 1;
|
|
118
|
+
}
|
|
119
|
+
const collapsed = out.join("").replace(/\s+/g, " ").trim();
|
|
120
|
+
return collapsed.replace(/\s+([,)])/g, "$1");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
interface SqliteMasterRow {
|
|
124
|
+
type: string;
|
|
125
|
+
name: string;
|
|
126
|
+
tbl_name: string;
|
|
127
|
+
sql: string | null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function virtualTableNames(objects: readonly SqliteMasterRow[]): Set<string> {
|
|
131
|
+
return new Set(
|
|
132
|
+
objects
|
|
133
|
+
.filter((row) => row.type === "table" && (row.sql ?? "").startsWith("CREATE VIRTUAL TABLE"))
|
|
134
|
+
.map((row) => row.name),
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function isFtsShadowTable(name: string, virtualTables: ReadonlySet<string>): boolean {
|
|
139
|
+
for (const vt of virtualTables) {
|
|
140
|
+
for (const suffix of FTS_SHADOW_SUFFIXES) {
|
|
141
|
+
if (name === `${vt}${suffix}`) return true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function tableInventory(db: Database, name: string, sql: string | null): TableInventory {
|
|
148
|
+
const columns = (
|
|
149
|
+
db.prepare(`PRAGMA table_info("${name}")`).all() as Record<string, unknown>[]
|
|
150
|
+
).map((row) => ({
|
|
151
|
+
name: row.name as string,
|
|
152
|
+
type: row.type as string,
|
|
153
|
+
notnull: row.notnull as number,
|
|
154
|
+
dflt_value: (row.dflt_value as string | null) ?? null,
|
|
155
|
+
pk: row.pk as number,
|
|
156
|
+
}));
|
|
157
|
+
const foreignKeys = (
|
|
158
|
+
db.prepare(`PRAGMA foreign_key_list("${name}")`).all() as Record<string, unknown>[]
|
|
159
|
+
)
|
|
160
|
+
.map(
|
|
161
|
+
(row): ForeignKeyInventory => ({
|
|
162
|
+
table: row.table as string,
|
|
163
|
+
from: row.from as string,
|
|
164
|
+
to: row.to as string,
|
|
165
|
+
on_update: row.on_update as string,
|
|
166
|
+
on_delete: row.on_delete as string,
|
|
167
|
+
match: row.match as string,
|
|
168
|
+
}),
|
|
169
|
+
)
|
|
170
|
+
.sort((a, b) =>
|
|
171
|
+
a.table === b.table ? a.from.localeCompare(b.from) : a.table.localeCompare(b.table),
|
|
172
|
+
);
|
|
173
|
+
return { columns, foreign_keys: foreignKeys, sql: normalizeSql(sql) };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function indexInventory(
|
|
177
|
+
db: Database,
|
|
178
|
+
name: string,
|
|
179
|
+
table: string,
|
|
180
|
+
sql: string | null,
|
|
181
|
+
): IndexInventory {
|
|
182
|
+
const columns = (
|
|
183
|
+
db.prepare(`PRAGMA index_info("${name}")`).all() as Record<string, unknown>[]
|
|
184
|
+
).map((row) => row.name as string);
|
|
185
|
+
const listRows = db.prepare(`PRAGMA index_list("${table}")`).all() as Record<string, unknown>[];
|
|
186
|
+
const listRow = listRows.find((row) => row.name === name);
|
|
187
|
+
const unique = listRow ? Number(listRow.unique) : 0;
|
|
188
|
+
return { table, unique, columns, sql: normalizeSql(sql) };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Build the canonical, cross-language schema inventory for `db`. See the
|
|
193
|
+
* module comment (and the Python counterpart) for what is included/excluded
|
|
194
|
+
* and why.
|
|
195
|
+
*/
|
|
196
|
+
export function buildSchemaInventory(db: Database): SchemaInventory {
|
|
197
|
+
const objects = db
|
|
198
|
+
.prepare(
|
|
199
|
+
"SELECT type, name, tbl_name, sql FROM sqlite_master WHERE type IN ('table', 'index', 'trigger')",
|
|
200
|
+
)
|
|
201
|
+
.all() as unknown as SqliteMasterRow[];
|
|
202
|
+
const virtualTables = virtualTableNames(objects);
|
|
203
|
+
|
|
204
|
+
const tables: Record<string, TableInventory> = {};
|
|
205
|
+
const indexes: Record<string, IndexInventory> = {};
|
|
206
|
+
const triggers: Record<string, TriggerInventory> = {};
|
|
207
|
+
|
|
208
|
+
for (const row of objects) {
|
|
209
|
+
// An index or trigger belonging to an excluded table (e.g. the autoindex
|
|
210
|
+
// SQLite creates for `_migrations`' non-INTEGER PRIMARY KEY) must not
|
|
211
|
+
// dangle in the inventory once its owning table is excluded.
|
|
212
|
+
if (EXCLUDED_TABLES.has(row.tbl_name)) continue;
|
|
213
|
+
if (row.type === "table") {
|
|
214
|
+
if (EXCLUDED_TABLES.has(row.name) || row.name.startsWith("sqlite_")) continue;
|
|
215
|
+
if (isFtsShadowTable(row.name, virtualTables)) continue;
|
|
216
|
+
tables[row.name] = tableInventory(db, row.name, row.sql);
|
|
217
|
+
} else if (row.type === "index") {
|
|
218
|
+
indexes[row.name] = indexInventory(db, row.name, row.tbl_name, row.sql);
|
|
219
|
+
} else if (row.type === "trigger") {
|
|
220
|
+
triggers[row.name] = { table: row.tbl_name, sql: normalizeSql(row.sql) };
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return { tables, indexes, triggers };
|
|
225
|
+
}
|