@chendpoc/pi-memory 0.1.13 → 0.2.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 +66 -258
- package/UBIQUITOUS_LANGUAGE.md +81 -0
- package/dist/adapters/embed/factory.d.ts +7 -0
- package/dist/adapters/embed/factory.d.ts.map +1 -0
- package/dist/adapters/embed/factory.js +44 -0
- package/dist/adapters/embed/factory.js.map +1 -0
- package/dist/adapters/embed/hash.d.ts +3 -0
- package/dist/adapters/embed/hash.d.ts.map +1 -0
- package/dist/adapters/embed/hash.js +26 -0
- package/dist/adapters/embed/hash.js.map +1 -0
- package/dist/adapters/embed/normalize.d.ts +3 -0
- package/dist/adapters/embed/normalize.d.ts.map +1 -0
- package/dist/adapters/embed/normalize.js +15 -0
- package/dist/adapters/embed/normalize.js.map +1 -0
- package/dist/adapters/embed/ollama.d.ts +8 -0
- package/dist/adapters/embed/ollama.d.ts.map +1 -0
- package/dist/adapters/embed/ollama.js +31 -0
- package/dist/adapters/embed/ollama.js.map +1 -0
- package/dist/adapters/embed/openai.d.ts +8 -0
- package/dist/adapters/embed/openai.d.ts.map +1 -0
- package/dist/adapters/embed/openai.js +30 -0
- package/dist/adapters/embed/openai.js.map +1 -0
- package/dist/adapters/embed/types.d.ts +9 -0
- package/dist/adapters/embed/types.d.ts.map +1 -0
- package/dist/adapters/embed/types.js.map +1 -0
- package/dist/adapters/http.d.ts +13 -0
- package/dist/adapters/http.d.ts.map +1 -0
- package/dist/adapters/http.js +31 -0
- package/dist/adapters/http.js.map +1 -0
- package/dist/adapters/index.d.ts +4 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +4 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/llm/extractText.d.ts +5 -0
- package/dist/adapters/llm/extractText.d.ts.map +1 -0
- package/dist/adapters/llm/extractText.js +7 -0
- package/dist/adapters/llm/extractText.js.map +1 -0
- package/dist/adapters/llm/factory.d.ts +11 -0
- package/dist/adapters/llm/factory.d.ts.map +1 -0
- package/dist/adapters/llm/factory.js +48 -0
- package/dist/adapters/llm/factory.js.map +1 -0
- package/dist/adapters/llm/index.d.ts +8 -0
- package/dist/adapters/llm/index.d.ts.map +1 -0
- package/dist/adapters/llm/index.js +7 -0
- package/dist/adapters/llm/index.js.map +1 -0
- package/dist/adapters/llm/modelSpec.d.ts +10 -0
- package/dist/adapters/llm/modelSpec.d.ts.map +1 -0
- package/dist/adapters/llm/modelSpec.js +21 -0
- package/dist/adapters/llm/modelSpec.js.map +1 -0
- package/dist/adapters/llm/ollama.d.ts +4 -0
- package/dist/adapters/llm/ollama.d.ts.map +1 -0
- package/dist/adapters/llm/ollama.js +32 -0
- package/dist/adapters/llm/ollama.js.map +1 -0
- package/dist/adapters/llm/openai-compat.d.ts +4 -0
- package/dist/adapters/llm/openai-compat.d.ts.map +1 -0
- package/dist/adapters/llm/openai-compat.js +36 -0
- package/dist/adapters/llm/openai-compat.js.map +1 -0
- package/dist/adapters/llm/pi-ai.d.ts +5 -0
- package/dist/adapters/llm/pi-ai.d.ts.map +1 -0
- package/dist/adapters/llm/pi-ai.js +60 -0
- package/dist/adapters/llm/pi-ai.js.map +1 -0
- package/dist/adapters/llm/standalone.d.ts +6 -0
- package/dist/adapters/llm/standalone.d.ts.map +1 -0
- package/dist/adapters/llm/standalone.js +44 -0
- package/dist/adapters/llm/standalone.js.map +1 -0
- package/dist/adapters/llm/types.d.ts +15 -0
- package/dist/adapters/llm/types.d.ts.map +1 -0
- package/dist/adapters/llm/types.js.map +1 -0
- package/dist/cli/init.d.ts +3 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +13 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/jobs.d.ts +32 -0
- package/dist/cli/jobs.d.ts.map +1 -0
- package/dist/cli/jobs.js +100 -0
- package/dist/cli/jobs.js.map +1 -0
- package/dist/cli/log.d.ts +14 -0
- package/dist/cli/log.d.ts.map +1 -0
- package/dist/cli/log.js +32 -0
- package/dist/cli/log.js.map +1 -0
- package/dist/cli/parseArgs.d.ts +35 -0
- package/dist/cli/parseArgs.d.ts.map +1 -0
- package/dist/cli/parseArgs.js +127 -0
- package/dist/cli/parseArgs.js.map +1 -0
- package/dist/cli/status.d.ts +44 -0
- package/dist/cli/status.d.ts.map +1 -0
- package/dist/cli/status.js +238 -0
- package/dist/cli/status.js.map +1 -0
- package/dist/cli/theme.d.ts +14 -0
- package/dist/cli/theme.d.ts.map +1 -0
- package/dist/cli/theme.js +20 -0
- package/dist/cli/theme.js.map +1 -0
- package/dist/cli.js +70 -356
- package/dist/cli.js.map +1 -1
- package/dist/commands/index.d.ts +6 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +14 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/parseMemoryStatusArgs.d.ts +3 -0
- package/dist/commands/parseMemoryStatusArgs.d.ts.map +1 -0
- package/dist/commands/parseMemoryStatusArgs.js +15 -0
- package/dist/commands/parseMemoryStatusArgs.js.map +1 -0
- package/dist/commands/parseRememberArgs.d.ts +10 -0
- package/dist/commands/parseRememberArgs.d.ts.map +1 -0
- package/dist/commands/parseRememberArgs.js +46 -0
- package/dist/commands/parseRememberArgs.js.map +1 -0
- package/dist/commands/remember.d.ts +8 -0
- package/dist/commands/remember.d.ts.map +1 -0
- package/dist/commands/remember.js +30 -0
- package/dist/commands/remember.js.map +1 -0
- package/dist/commands/status.d.ts +10 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +81 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/types.d.ts +10 -0
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/types.js +2 -0
- package/dist/{consolidation → commands}/types.js.map +1 -1
- package/dist/compact/index.d.ts +5 -0
- package/dist/compact/index.d.ts.map +1 -0
- package/dist/compact/index.js +5 -0
- package/dist/compact/index.js.map +1 -0
- package/dist/compact/parseMemoryExport.d.ts +6 -0
- package/dist/compact/parseMemoryExport.d.ts.map +1 -0
- package/dist/compact/parseMemoryExport.js +62 -0
- package/dist/compact/parseMemoryExport.js.map +1 -0
- package/dist/compact/register.d.ts +10 -0
- package/dist/compact/register.d.ts.map +1 -0
- package/dist/compact/register.js +47 -0
- package/dist/compact/register.js.map +1 -0
- package/dist/compact/runSummary.d.ts +6 -0
- package/dist/compact/runSummary.d.ts.map +1 -0
- package/dist/compact/runSummary.js +29 -0
- package/dist/compact/runSummary.js.map +1 -0
- package/dist/compact/subagentDelta.d.ts +6 -0
- package/dist/compact/subagentDelta.d.ts.map +1 -0
- package/dist/compact/subagentDelta.js +13 -0
- package/dist/compact/subagentDelta.js.map +1 -0
- package/dist/compact/summaryPrompt.d.ts +3 -0
- package/dist/compact/summaryPrompt.d.ts.map +1 -0
- package/dist/compact/summaryPrompt.js +41 -0
- package/dist/compact/summaryPrompt.js.map +1 -0
- package/dist/config/agentDir.d.ts +11 -0
- package/dist/config/agentDir.d.ts.map +1 -0
- package/dist/config/agentDir.js +21 -0
- package/dist/config/agentDir.js.map +1 -0
- package/dist/config/chunking.d.ts +7 -0
- package/dist/config/chunking.d.ts.map +1 -0
- package/dist/config/chunking.js +20 -0
- package/dist/config/chunking.js.map +1 -0
- package/dist/config/env.d.ts +28 -0
- package/dist/config/env.d.ts.map +1 -0
- package/dist/config/env.js +43 -0
- package/dist/config/env.js.map +1 -0
- package/dist/config/index.d.ts +7 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +7 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loadEnv.d.ts +10 -0
- package/dist/config/loadEnv.d.ts.map +1 -0
- package/dist/config/loadEnv.js +25 -0
- package/dist/config/loadEnv.js.map +1 -0
- package/dist/config/preflightBudget.d.ts +9 -0
- package/dist/config/preflightBudget.d.ts.map +1 -0
- package/dist/config/preflightBudget.js +16 -0
- package/dist/config/preflightBudget.js.map +1 -0
- package/dist/config/retrieval.d.ts +10 -0
- package/dist/config/retrieval.d.ts.map +1 -0
- package/dist/config/retrieval.js +31 -0
- package/dist/config/retrieval.js.map +1 -0
- package/dist/consolidate/entryKey.d.ts +6 -0
- package/dist/consolidate/entryKey.d.ts.map +1 -0
- package/dist/consolidate/entryKey.js +5 -0
- package/dist/consolidate/entryKey.js.map +1 -0
- package/dist/consolidate/index.d.ts +5 -0
- package/dist/consolidate/index.d.ts.map +1 -0
- package/dist/consolidate/index.js +5 -0
- package/dist/consolidate/index.js.map +1 -0
- package/dist/consolidate/mergeEntries.d.ts +4 -0
- package/dist/consolidate/mergeEntries.d.ts.map +1 -0
- package/dist/consolidate/mergeEntries.js +17 -0
- package/dist/consolidate/mergeEntries.js.map +1 -0
- package/dist/consolidate/mergePrompt.d.ts +4 -0
- package/dist/consolidate/mergePrompt.d.ts.map +1 -0
- package/dist/consolidate/mergePrompt.js +40 -0
- package/dist/consolidate/mergePrompt.js.map +1 -0
- package/dist/consolidate/mergeWithLlm.d.ts +4 -0
- package/dist/consolidate/mergeWithLlm.d.ts.map +1 -0
- package/dist/consolidate/mergeWithLlm.js +27 -0
- package/dist/consolidate/mergeWithLlm.js.map +1 -0
- package/dist/consolidate/runJob.d.ts +29 -0
- package/dist/consolidate/runJob.d.ts.map +1 -0
- package/dist/consolidate/runJob.js +48 -0
- package/dist/consolidate/runJob.js.map +1 -0
- package/dist/consolidate/scheduler.d.ts +18 -0
- package/dist/consolidate/scheduler.d.ts.map +1 -0
- package/dist/consolidate/scheduler.js +32 -0
- package/dist/consolidate/scheduler.js.map +1 -0
- package/dist/constants/chunking.d.ts +7 -0
- package/dist/constants/chunking.d.ts.map +1 -0
- package/dist/constants/chunking.js +7 -0
- package/dist/constants/chunking.js.map +1 -0
- package/dist/constants/env.d.ts +44 -0
- package/dist/constants/env.d.ts.map +1 -0
- package/dist/constants/env.js +49 -0
- package/dist/constants/env.js.map +1 -0
- package/dist/constants/index.d.ts +8 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +8 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/memory.d.ts +17 -0
- package/dist/constants/memory.d.ts.map +1 -0
- package/dist/constants/memory.js +16 -0
- package/dist/constants/memory.js.map +1 -0
- package/dist/constants/paths.d.ts +23 -0
- package/dist/constants/paths.d.ts.map +1 -0
- package/dist/constants/paths.js +23 -0
- package/dist/constants/paths.js.map +1 -0
- package/dist/constants/preflight.d.ts +10 -0
- package/dist/constants/preflight.d.ts.map +1 -0
- package/dist/constants/preflight.js +10 -0
- package/dist/constants/preflight.js.map +1 -0
- package/dist/constants/retrieval.d.ts +10 -0
- package/dist/constants/retrieval.d.ts.map +1 -0
- package/dist/constants/retrieval.js +10 -0
- package/dist/constants/retrieval.js.map +1 -0
- package/dist/constants/security.d.ts +5 -0
- package/dist/constants/security.d.ts.map +1 -0
- package/dist/constants/security.js +5 -0
- package/dist/constants/security.js.map +1 -0
- package/dist/constants/timing.d.ts +36 -0
- package/dist/constants/timing.d.ts.map +1 -0
- package/dist/constants/timing.js +36 -0
- package/dist/constants/timing.js.map +1 -0
- package/dist/index.d.ts +11 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -28
- package/dist/index.js.map +1 -1
- package/dist/init/workspace.d.ts +15 -0
- package/dist/init/workspace.d.ts.map +1 -0
- package/dist/init/workspace.js +32 -0
- package/dist/init/workspace.js.map +1 -0
- package/dist/ipc/jsonlFramer.d.ts +9 -0
- package/dist/ipc/jsonlFramer.d.ts.map +1 -0
- package/dist/ipc/jsonlFramer.js +26 -0
- package/dist/ipc/jsonlFramer.js.map +1 -0
- package/dist/pi-extension.d.ts +0 -2
- package/dist/pi-extension.d.ts.map +1 -1
- package/dist/pi-extension.js +161 -520
- package/dist/pi-extension.js.map +1 -1
- package/dist/preflight/episodic.d.ts +20 -0
- package/dist/preflight/episodic.d.ts.map +1 -0
- package/dist/preflight/episodic.js +109 -0
- package/dist/preflight/episodic.js.map +1 -0
- package/dist/preflight/queryCache.d.ts +15 -0
- package/dist/preflight/queryCache.d.ts.map +1 -0
- package/dist/preflight/queryCache.js +46 -0
- package/dist/preflight/queryCache.js.map +1 -0
- package/dist/preflight/queryIntent.d.ts +20 -0
- package/dist/preflight/queryIntent.d.ts.map +1 -0
- package/dist/preflight/queryIntent.js +75 -0
- package/dist/preflight/queryIntent.js.map +1 -0
- package/dist/preflight/render.d.ts +8 -33
- package/dist/preflight/render.d.ts.map +1 -1
- package/dist/preflight/render.js +29 -126
- package/dist/preflight/render.js.map +1 -1
- package/dist/preflight/session.d.ts +3 -0
- package/dist/preflight/session.d.ts.map +1 -0
- package/dist/preflight/session.js +6 -0
- package/dist/preflight/session.js.map +1 -0
- package/dist/preflight/strip.d.ts +0 -8
- package/dist/preflight/strip.d.ts.map +1 -1
- package/dist/preflight/strip.js +2 -11
- package/dist/preflight/strip.js.map +1 -1
- package/dist/shutdown/enqueue.d.ts +12 -0
- package/dist/shutdown/enqueue.d.ts.map +1 -0
- package/dist/shutdown/enqueue.js +14 -0
- package/dist/shutdown/enqueue.js.map +1 -0
- package/dist/shutdown/extractPrompt.d.ts +4 -0
- package/dist/shutdown/extractPrompt.d.ts.map +1 -0
- package/dist/shutdown/extractPrompt.js +29 -0
- package/dist/shutdown/extractPrompt.js.map +1 -0
- package/dist/shutdown/processed.d.ts +9 -0
- package/dist/shutdown/processed.d.ts.map +1 -0
- package/dist/shutdown/processed.js +28 -0
- package/dist/shutdown/processed.js.map +1 -0
- package/dist/shutdown/readQueue.d.ts +4 -0
- package/dist/shutdown/readQueue.d.ts.map +1 -0
- package/dist/shutdown/readQueue.js +26 -0
- package/dist/shutdown/readQueue.js.map +1 -0
- package/dist/shutdown/runDrainJob.d.ts +26 -0
- package/dist/shutdown/runDrainJob.d.ts.map +1 -0
- package/dist/shutdown/runDrainJob.js +143 -0
- package/dist/shutdown/runDrainJob.js.map +1 -0
- package/dist/shutdown/sessionReader.d.ts +6 -0
- package/dist/shutdown/sessionReader.d.ts.map +1 -0
- package/dist/shutdown/sessionReader.js +44 -0
- package/dist/shutdown/sessionReader.js.map +1 -0
- package/dist/sidecar/client.d.ts +17 -16
- package/dist/sidecar/client.d.ts.map +1 -1
- package/dist/sidecar/client.js +64 -100
- package/dist/sidecar/client.js.map +1 -1
- package/dist/sidecar/paths.d.ts +8 -0
- package/dist/sidecar/paths.d.ts.map +1 -0
- package/dist/sidecar/paths.js +23 -0
- package/dist/sidecar/paths.js.map +1 -0
- package/dist/sidecar/protocol.d.ts +54 -0
- package/dist/sidecar/protocol.d.ts.map +1 -0
- package/dist/sidecar/protocol.js +4 -0
- package/dist/sidecar/protocol.js.map +1 -0
- package/dist/sidecar/reindexBridge.d.ts +13 -0
- package/dist/sidecar/reindexBridge.d.ts.map +1 -0
- package/dist/sidecar/reindexBridge.js +37 -0
- package/dist/sidecar/reindexBridge.js.map +1 -0
- package/dist/sidecar/server/process.d.ts +2 -0
- package/dist/sidecar/server/process.d.ts.map +1 -0
- package/dist/sidecar/server/process.js +22 -0
- package/dist/sidecar/server/process.js.map +1 -0
- package/dist/sidecar/server/query.d.ts +8 -0
- package/dist/sidecar/server/query.d.ts.map +1 -0
- package/dist/sidecar/server/query.js +7 -0
- package/dist/sidecar/server/query.js.map +1 -0
- package/dist/sidecar/server/reindex.d.ts +8 -0
- package/dist/sidecar/server/reindex.d.ts.map +1 -0
- package/dist/sidecar/server/reindex.js +12 -0
- package/dist/sidecar/server/reindex.js.map +1 -0
- package/dist/sidecar/server/server.d.ts +11 -0
- package/dist/sidecar/server/server.d.ts.map +1 -0
- package/dist/sidecar/server/server.js +76 -0
- package/dist/sidecar/server/server.js.map +1 -0
- package/dist/sidecar/server/stats.d.ts +8 -0
- package/dist/sidecar/server/stats.d.ts.map +1 -0
- package/dist/sidecar/server/stats.js +18 -0
- package/dist/sidecar/server/stats.js.map +1 -0
- package/dist/sidecar/server/vec/embedder.d.ts +2 -0
- package/dist/sidecar/server/vec/embedder.d.ts.map +1 -0
- package/dist/sidecar/server/vec/embedder.js +2 -0
- package/dist/sidecar/server/vec/embedder.js.map +1 -0
- package/dist/sidecar/server/vec/mmr.d.ts +13 -0
- package/dist/sidecar/server/vec/mmr.d.ts.map +1 -0
- package/dist/sidecar/server/vec/mmr.js +36 -0
- package/dist/sidecar/server/vec/mmr.js.map +1 -0
- package/dist/sidecar/server/vec/store.d.ts +30 -0
- package/dist/sidecar/server/vec/store.d.ts.map +1 -0
- package/dist/sidecar/server/vec/store.js +179 -0
- package/dist/sidecar/server/vec/store.js.map +1 -0
- package/dist/sidecar/sidecarManager.d.ts +10 -0
- package/dist/sidecar/sidecarManager.d.ts.map +1 -0
- package/dist/sidecar/sidecarManager.js +111 -0
- package/dist/sidecar/sidecarManager.js.map +1 -0
- package/dist/sidecar/utils.d.ts +3 -0
- package/dist/sidecar/utils.d.ts.map +1 -0
- package/dist/sidecar/utils.js +27 -0
- package/dist/sidecar/utils.js.map +1 -0
- package/dist/store/backend.d.ts +12 -0
- package/dist/store/backend.d.ts.map +1 -0
- package/dist/store/backend.js +47 -0
- package/dist/store/backend.js.map +1 -0
- package/dist/store/index.d.ts +6 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +6 -0
- package/dist/store/index.js.map +1 -0
- package/dist/store/indexChunks.d.ts +9 -0
- package/dist/store/indexChunks.d.ts.map +1 -0
- package/dist/store/indexChunks.js +78 -0
- package/dist/store/indexChunks.js.map +1 -0
- package/dist/store/markdown/format.d.ts +5 -0
- package/dist/store/markdown/format.d.ts.map +1 -0
- package/dist/store/markdown/format.js +14 -0
- package/dist/store/markdown/format.js.map +1 -0
- package/dist/store/markdown/parse.d.ts +5 -0
- package/dist/store/markdown/parse.d.ts.map +1 -0
- package/dist/store/markdown/parse.js +57 -0
- package/dist/store/markdown/parse.js.map +1 -0
- package/dist/store/markdown/template.d.ts +3 -0
- package/dist/store/markdown/template.d.ts.map +1 -0
- package/dist/store/markdown/template.js +22 -0
- package/dist/store/markdown/template.js.map +1 -0
- package/dist/store/memoryStore.d.ts +69 -0
- package/dist/store/memoryStore.d.ts.map +1 -0
- package/dist/store/memoryStore.js +421 -0
- package/dist/store/memoryStore.js.map +1 -0
- package/dist/store/paths.d.ts +10 -0
- package/dist/store/paths.d.ts.map +1 -0
- package/dist/store/paths.js +19 -0
- package/dist/store/paths.js.map +1 -0
- package/dist/store/types.d.ts +38 -0
- package/dist/store/types.d.ts.map +1 -0
- package/dist/store/types.js +3 -0
- package/dist/store/types.js.map +1 -0
- package/dist/ui/memoryStatusWidget.d.ts +20 -0
- package/dist/ui/memoryStatusWidget.d.ts.map +1 -0
- package/dist/ui/memoryStatusWidget.js +51 -0
- package/dist/ui/memoryStatusWidget.js.map +1 -0
- package/dist/utils/debugLog.d.ts +4 -0
- package/dist/utils/debugLog.d.ts.map +1 -0
- package/dist/utils/debugLog.js +14 -0
- package/dist/utils/debugLog.js.map +1 -0
- package/dist/utils/fs.d.ts +26 -0
- package/dist/utils/fs.d.ts.map +1 -0
- package/dist/utils/fs.js +101 -0
- package/dist/utils/fs.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/paths.d.ts +22 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +51 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/platform.d.ts +7 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +18 -0
- package/dist/utils/platform.js.map +1 -0
- package/dist/utils/scheduler.d.ts +33 -0
- package/dist/utils/scheduler.d.ts.map +1 -0
- package/dist/utils/scheduler.js +63 -0
- package/dist/utils/scheduler.js.map +1 -0
- package/dist/utils/socket.d.ts +7 -0
- package/dist/utils/socket.d.ts.map +1 -0
- package/dist/utils/socket.js +35 -0
- package/dist/utils/socket.js.map +1 -0
- package/dist/utils/time.d.ts +22 -0
- package/dist/utils/time.d.ts.map +1 -0
- package/dist/utils/time.js +42 -0
- package/dist/utils/time.js.map +1 -0
- package/package.json +28 -10
- package/scripts/init-memory-workspace.mjs +62 -0
- package/scripts/path-utils.mjs +12 -0
- package/scripts/platform-fs.mjs +65 -0
- package/scripts/postinstall.mjs +17 -0
- package/src/adapters/embed/factory.ts +50 -0
- package/src/adapters/embed/hash.ts +29 -0
- package/src/adapters/embed/normalize.ts +13 -0
- package/src/adapters/embed/ollama.ts +49 -0
- package/src/adapters/embed/openai.ts +46 -0
- package/src/adapters/embed/types.ts +9 -0
- package/src/adapters/http.ts +42 -0
- package/src/adapters/index.ts +16 -0
- package/src/adapters/llm/extractText.ts +6 -0
- package/src/adapters/llm/factory.ts +60 -0
- package/src/adapters/llm/index.ts +7 -0
- package/src/adapters/llm/modelSpec.ts +39 -0
- package/src/adapters/llm/ollama.ts +42 -0
- package/src/adapters/llm/openai-compat.ts +46 -0
- package/src/adapters/llm/pi-ai.ts +75 -0
- package/src/adapters/llm/standalone.ts +60 -0
- package/src/adapters/llm/types.ts +16 -0
- package/src/cli/init.ts +18 -0
- package/src/cli/jobs.ts +144 -0
- package/src/cli/log.ts +46 -0
- package/src/cli/parseArgs.ts +175 -0
- package/src/cli/status.ts +323 -0
- package/src/cli/theme.ts +26 -0
- package/src/cli.ts +80 -374
- package/src/commands/index.ts +20 -0
- package/src/commands/parseMemoryStatusArgs.ts +11 -0
- package/src/commands/parseRememberArgs.ts +55 -0
- package/src/commands/remember.ts +43 -0
- package/src/commands/status.ts +112 -0
- package/src/commands/types.ts +12 -0
- package/src/compact/index.ts +4 -0
- package/src/compact/parseMemoryExport.ts +71 -0
- package/src/compact/register.ts +57 -0
- package/src/compact/runSummary.ts +42 -0
- package/src/compact/subagentDelta.ts +22 -0
- package/src/compact/summaryPrompt.ts +45 -0
- package/src/config/agentDir.ts +24 -0
- package/src/config/chunking.ts +36 -0
- package/src/config/env.ts +97 -0
- package/src/config/index.ts +6 -0
- package/src/config/loadEnv.ts +26 -0
- package/src/config/preflightBudget.ts +33 -0
- package/src/config/retrieval.ts +50 -0
- package/src/consolidate/entryKey.ts +4 -0
- package/src/consolidate/index.ts +4 -0
- package/src/consolidate/mergeEntries.ts +22 -0
- package/src/consolidate/mergePrompt.ts +46 -0
- package/src/consolidate/mergeWithLlm.ts +39 -0
- package/src/consolidate/runJob.ts +81 -0
- package/src/consolidate/scheduler.ts +54 -0
- package/src/constants/chunking.ts +8 -0
- package/src/constants/env.ts +56 -0
- package/src/constants/index.ts +7 -0
- package/src/constants/memory.ts +22 -0
- package/src/constants/paths.ts +26 -0
- package/src/constants/preflight.ts +13 -0
- package/src/constants/retrieval.ts +10 -0
- package/src/constants/security.ts +5 -0
- package/src/constants/timing.ts +46 -0
- package/src/index.ts +11 -247
- package/src/init/workspace.ts +44 -0
- package/src/ipc/jsonlFramer.ts +29 -0
- package/src/pi-extension.ts +177 -606
- package/src/preflight/episodic.ts +159 -0
- package/src/preflight/queryCache.ts +59 -0
- package/src/preflight/queryIntent.ts +92 -0
- package/src/preflight/render.ts +34 -180
- package/src/preflight/session.ts +7 -0
- package/src/preflight/strip.ts +4 -11
- package/src/shutdown/enqueue.ts +29 -0
- package/src/shutdown/extractPrompt.ts +27 -0
- package/src/shutdown/processed.ts +45 -0
- package/src/shutdown/readQueue.ts +26 -0
- package/src/shutdown/runDrainJob.ts +202 -0
- package/src/shutdown/sessionReader.ts +61 -0
- package/src/sidecar/client.ts +98 -150
- package/src/sidecar/paths.ts +31 -0
- package/src/sidecar/protocol.ts +38 -0
- package/src/sidecar/reindexBridge.ts +52 -0
- package/src/sidecar/server/process.ts +27 -0
- package/src/sidecar/server/query.ts +16 -0
- package/src/sidecar/server/reindex.ts +21 -0
- package/src/sidecar/server/server.ts +105 -0
- package/src/sidecar/server/stats.ts +23 -0
- package/src/sidecar/server/vec/embedder.ts +1 -0
- package/src/sidecar/server/vec/mmr.ts +55 -0
- package/src/sidecar/server/vec/store.ts +232 -0
- package/src/sidecar/sidecarManager.ts +134 -0
- package/src/sidecar/utils.ts +28 -0
- package/src/store/backend.ts +66 -0
- package/src/store/index.ts +5 -0
- package/src/store/indexChunks.ts +89 -0
- package/src/store/markdown/format.ts +16 -0
- package/src/store/markdown/parse.ts +63 -0
- package/src/store/markdown/template.ts +24 -0
- package/src/store/memoryStore.ts +518 -0
- package/src/store/paths.ts +33 -0
- package/src/store/proper-lockfile.d.ts +3 -0
- package/src/store/types.ts +46 -0
- package/src/ui/memoryStatusWidget.ts +80 -0
- package/src/utils/debugLog.ts +22 -0
- package/src/utils/fs.ts +115 -0
- package/src/utils/index.ts +68 -0
- package/src/utils/paths.ts +67 -0
- package/src/utils/platform.ts +20 -0
- package/src/utils/scheduler.ts +98 -0
- package/src/utils/socket.ts +33 -0
- package/src/utils/time.ts +51 -0
- package/templates/MEMORY.md.example +22 -0
- package/dist/adapters/ollamaClient.d.ts +0 -11
- package/dist/adapters/ollamaClient.d.ts.map +0 -1
- package/dist/adapters/ollamaClient.js +0 -122
- package/dist/adapters/ollamaClient.js.map +0 -1
- package/dist/adapters/openaiCompatClient.d.ts +0 -11
- package/dist/adapters/openaiCompatClient.d.ts.map +0 -1
- package/dist/adapters/openaiCompatClient.js +0 -118
- package/dist/adapters/openaiCompatClient.js.map +0 -1
- package/dist/adapters/piComplete.d.ts +0 -17
- package/dist/adapters/piComplete.d.ts.map +0 -1
- package/dist/adapters/piComplete.js +0 -169
- package/dist/adapters/piComplete.js.map +0 -1
- package/dist/bundle/install.d.ts +0 -34
- package/dist/bundle/install.d.ts.map +0 -1
- package/dist/bundle/install.js +0 -183
- package/dist/bundle/install.js.map +0 -1
- package/dist/cache/memoryCaches.d.ts +0 -32
- package/dist/cache/memoryCaches.d.ts.map +0 -1
- package/dist/cache/memoryCaches.js +0 -59
- package/dist/cache/memoryCaches.js.map +0 -1
- package/dist/config.d.ts +0 -55
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -85
- package/dist/config.js.map +0 -1
- package/dist/consolidation/enqueue.d.ts +0 -33
- package/dist/consolidation/enqueue.d.ts.map +0 -1
- package/dist/consolidation/enqueue.js +0 -145
- package/dist/consolidation/enqueue.js.map +0 -1
- package/dist/consolidation/index.d.ts +0 -19
- package/dist/consolidation/index.d.ts.map +0 -1
- package/dist/consolidation/index.js +0 -15
- package/dist/consolidation/index.js.map +0 -1
- package/dist/consolidation/lock.d.ts +0 -5
- package/dist/consolidation/lock.d.ts.map +0 -1
- package/dist/consolidation/lock.js +0 -33
- package/dist/consolidation/lock.js.map +0 -1
- package/dist/consolidation/log.d.ts +0 -8
- package/dist/consolidation/log.d.ts.map +0 -1
- package/dist/consolidation/log.js +0 -32
- package/dist/consolidation/log.js.map +0 -1
- package/dist/consolidation/memoryIndex.d.ts +0 -18
- package/dist/consolidation/memoryIndex.d.ts.map +0 -1
- package/dist/consolidation/memoryIndex.js +0 -100
- package/dist/consolidation/memoryIndex.js.map +0 -1
- package/dist/consolidation/phase2/runPhase2.d.ts +0 -23
- package/dist/consolidation/phase2/runPhase2.d.ts.map +0 -1
- package/dist/consolidation/phase2/runPhase2.js +0 -196
- package/dist/consolidation/phase2/runPhase2.js.map +0 -1
- package/dist/consolidation/scheduler/launchd.d.ts +0 -5
- package/dist/consolidation/scheduler/launchd.d.ts.map +0 -1
- package/dist/consolidation/scheduler/launchd.js +0 -54
- package/dist/consolidation/scheduler/launchd.js.map +0 -1
- package/dist/consolidation/scheduler/runConsolidate.d.ts +0 -26
- package/dist/consolidation/scheduler/runConsolidate.d.ts.map +0 -1
- package/dist/consolidation/scheduler/runConsolidate.js +0 -83
- package/dist/consolidation/scheduler/runConsolidate.js.map +0 -1
- package/dist/consolidation/scheduler/setupSchedule.d.ts +0 -3
- package/dist/consolidation/scheduler/setupSchedule.d.ts.map +0 -1
- package/dist/consolidation/scheduler/setupSchedule.js +0 -79
- package/dist/consolidation/scheduler/setupSchedule.js.map +0 -1
- package/dist/consolidation/scheduler/systemd.d.ts +0 -9
- package/dist/consolidation/scheduler/systemd.d.ts.map +0 -1
- package/dist/consolidation/scheduler/systemd.js +0 -57
- package/dist/consolidation/scheduler/systemd.js.map +0 -1
- package/dist/consolidation/scheduler/types.d.ts +0 -24
- package/dist/consolidation/scheduler/types.d.ts.map +0 -1
- package/dist/consolidation/scheduler/types.js.map +0 -1
- package/dist/consolidation/scope.d.ts +0 -12
- package/dist/consolidation/scope.d.ts.map +0 -1
- package/dist/consolidation/scope.js +0 -51
- package/dist/consolidation/scope.js.map +0 -1
- package/dist/consolidation/stage1/deltaExtract.d.ts +0 -3
- package/dist/consolidation/stage1/deltaExtract.d.ts.map +0 -1
- package/dist/consolidation/stage1/deltaExtract.js +0 -19
- package/dist/consolidation/stage1/deltaExtract.js.map +0 -1
- package/dist/consolidation/stage1/drainQueue.d.ts +0 -21
- package/dist/consolidation/stage1/drainQueue.d.ts.map +0 -1
- package/dist/consolidation/stage1/drainQueue.js +0 -113
- package/dist/consolidation/stage1/drainQueue.js.map +0 -1
- package/dist/consolidation/stage1/extractSession.d.ts +0 -6
- package/dist/consolidation/stage1/extractSession.d.ts.map +0 -1
- package/dist/consolidation/stage1/extractSession.js +0 -47
- package/dist/consolidation/stage1/extractSession.js.map +0 -1
- package/dist/consolidation/stage1/store.d.ts +0 -45
- package/dist/consolidation/stage1/store.d.ts.map +0 -1
- package/dist/consolidation/stage1/store.js +0 -297
- package/dist/consolidation/stage1/store.js.map +0 -1
- package/dist/consolidation/types.d.ts +0 -49
- package/dist/consolidation/types.d.ts.map +0 -1
- package/dist/errclass.d.ts +0 -7
- package/dist/errclass.d.ts.map +0 -1
- package/dist/errclass.js +0 -32
- package/dist/errclass.js.map +0 -1
- package/dist/extension.d.ts +0 -24
- package/dist/extension.d.ts.map +0 -1
- package/dist/extension.js +0 -7
- package/dist/extension.js.map +0 -1
- package/dist/fallback/index.d.ts +0 -11
- package/dist/fallback/index.d.ts.map +0 -1
- package/dist/fallback/index.js +0 -16
- package/dist/fallback/index.js.map +0 -1
- package/dist/fallback/llmRerank.d.ts +0 -19
- package/dist/fallback/llmRerank.d.ts.map +0 -1
- package/dist/fallback/llmRerank.js +0 -68
- package/dist/fallback/llmRerank.js.map +0 -1
- package/dist/fallback/memoryMd.d.ts +0 -6
- package/dist/fallback/memoryMd.d.ts.map +0 -1
- package/dist/fallback/memoryMd.js +0 -35
- package/dist/fallback/memoryMd.js.map +0 -1
- package/dist/fallback/sessionIndex.d.ts +0 -35
- package/dist/fallback/sessionIndex.d.ts.map +0 -1
- package/dist/fallback/sessionIndex.js +0 -239
- package/dist/fallback/sessionIndex.js.map +0 -1
- package/dist/fallback/sessionSearch.d.ts +0 -18
- package/dist/fallback/sessionSearch.d.ts.map +0 -1
- package/dist/fallback/sessionSearch.js +0 -234
- package/dist/fallback/sessionSearch.js.map +0 -1
- package/dist/local/graphQuery.d.ts +0 -31
- package/dist/local/graphQuery.d.ts.map +0 -1
- package/dist/local/graphQuery.js +0 -195
- package/dist/local/graphQuery.js.map +0 -1
- package/dist/paths.d.ts +0 -7
- package/dist/paths.d.ts.map +0 -1
- package/dist/paths.js +0 -26
- package/dist/paths.js.map +0 -1
- package/dist/preflight/detectIntents.d.ts +0 -102
- package/dist/preflight/detectIntents.d.ts.map +0 -1
- package/dist/preflight/detectIntents.js +0 -631
- package/dist/preflight/detectIntents.js.map +0 -1
- package/dist/preflight/hook.d.ts +0 -76
- package/dist/preflight/hook.d.ts.map +0 -1
- package/dist/preflight/hook.js +0 -122
- package/dist/preflight/hook.js.map +0 -1
- package/dist/service.d.ts +0 -72
- package/dist/service.d.ts.map +0 -1
- package/dist/service.js +0 -257
- package/dist/service.js.map +0 -1
- package/dist/session/activeBranch.d.ts +0 -17
- package/dist/session/activeBranch.d.ts.map +0 -1
- package/dist/session/activeBranch.js +0 -251
- package/dist/session/activeBranch.js.map +0 -1
- package/dist/settings.d.ts +0 -41
- package/dist/settings.d.ts.map +0 -1
- package/dist/settings.js +0 -85
- package/dist/settings.js.map +0 -1
- package/dist/sidecar/bundle.d.ts +0 -19
- package/dist/sidecar/bundle.d.ts.map +0 -1
- package/dist/sidecar/bundle.js +0 -39
- package/dist/sidecar/bundle.js.map +0 -1
- package/dist/sidecar/process.d.ts +0 -14
- package/dist/sidecar/process.d.ts.map +0 -1
- package/dist/sidecar/process.js +0 -138
- package/dist/sidecar/process.js.map +0 -1
- package/dist/tools/memoryAppend.d.ts +0 -47
- package/dist/tools/memoryAppend.d.ts.map +0 -1
- package/dist/tools/memoryAppend.js +0 -138
- package/dist/tools/memoryAppend.js.map +0 -1
- package/dist/tools/memoryRecall.d.ts +0 -113
- package/dist/tools/memoryRecall.d.ts.map +0 -1
- package/dist/tools/memoryRecall.js +0 -351
- package/dist/tools/memoryRecall.js.map +0 -1
- package/dist/trainer/bundleBuilder.d.ts +0 -30
- package/dist/trainer/bundleBuilder.d.ts.map +0 -1
- package/dist/trainer/bundleBuilder.js +0 -106
- package/dist/trainer/bundleBuilder.js.map +0 -1
- package/dist/trainer/bundleLoader.d.ts +0 -12
- package/dist/trainer/bundleLoader.d.ts.map +0 -1
- package/dist/trainer/bundleLoader.js +0 -59
- package/dist/trainer/bundleLoader.js.map +0 -1
- package/dist/trainer/deltaMerge.d.ts +0 -38
- package/dist/trainer/deltaMerge.d.ts.map +0 -1
- package/dist/trainer/deltaMerge.js +0 -183
- package/dist/trainer/deltaMerge.js.map +0 -1
- package/dist/trainer/entityResolver.d.ts +0 -27
- package/dist/trainer/entityResolver.d.ts.map +0 -1
- package/dist/trainer/entityResolver.js +0 -92
- package/dist/trainer/entityResolver.js.map +0 -1
- package/dist/trainer/extractFacts.d.ts +0 -67
- package/dist/trainer/extractFacts.d.ts.map +0 -1
- package/dist/trainer/extractFacts.js +0 -213
- package/dist/trainer/extractFacts.js.map +0 -1
- package/dist/trainer/index.d.ts +0 -54
- package/dist/trainer/index.d.ts.map +0 -1
- package/dist/trainer/index.js +0 -82
- package/dist/trainer/index.js.map +0 -1
- package/dist/trainer/llmExtractor.d.ts +0 -16
- package/dist/trainer/llmExtractor.d.ts.map +0 -1
- package/dist/trainer/llmExtractor.js +0 -146
- package/dist/trainer/llmExtractor.js.map +0 -1
- package/dist/trainer/marker.d.ts +0 -10
- package/dist/trainer/marker.d.ts.map +0 -1
- package/dist/trainer/marker.js +0 -28
- package/dist/trainer/marker.js.map +0 -1
- package/dist/trainer/scheduler.d.ts +0 -33
- package/dist/trainer/scheduler.d.ts.map +0 -1
- package/dist/trainer/scheduler.js +0 -73
- package/dist/trainer/scheduler.js.map +0 -1
- package/dist/trainer/sessionLoader.d.ts +0 -26
- package/dist/trainer/sessionLoader.d.ts.map +0 -1
- package/dist/trainer/sessionLoader.js +0 -145
- package/dist/trainer/sessionLoader.js.map +0 -1
- package/dist/types.d.ts +0 -135
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -8
- package/dist/types.js.map +0 -1
- package/src/adapters/ollamaClient.ts +0 -179
- package/src/adapters/openaiCompatClient.ts +0 -155
- package/src/adapters/piComplete.ts +0 -233
- package/src/bundle/install.ts +0 -206
- package/src/cache/memoryCaches.ts +0 -72
- package/src/config.ts +0 -180
- package/src/consolidation/enqueue.ts +0 -205
- package/src/consolidation/index.ts +0 -90
- package/src/consolidation/lock.ts +0 -41
- package/src/consolidation/log.ts +0 -43
- package/src/consolidation/memoryIndex.ts +0 -127
- package/src/consolidation/phase2/runPhase2.ts +0 -255
- package/src/consolidation/scheduler/launchd.ts +0 -62
- package/src/consolidation/scheduler/runConsolidate.ts +0 -115
- package/src/consolidation/scheduler/setupSchedule.ts +0 -106
- package/src/consolidation/scheduler/systemd.ts +0 -78
- package/src/consolidation/scheduler/types.ts +0 -27
- package/src/consolidation/scope.ts +0 -58
- package/src/consolidation/stage1/deltaExtract.ts +0 -29
- package/src/consolidation/stage1/drainQueue.ts +0 -143
- package/src/consolidation/stage1/extractSession.ts +0 -58
- package/src/consolidation/stage1/store.ts +0 -411
- package/src/consolidation/types.ts +0 -52
- package/src/errclass.ts +0 -37
- package/src/extension.ts +0 -23
- package/src/fallback/index.ts +0 -24
- package/src/fallback/llmRerank.ts +0 -97
- package/src/fallback/memoryMd.ts +0 -36
- package/src/fallback/sessionIndex.ts +0 -290
- package/src/fallback/sessionSearch.ts +0 -261
- package/src/local/graphQuery.ts +0 -252
- package/src/paths.ts +0 -28
- package/src/preflight/detectIntents.ts +0 -660
- package/src/preflight/hook.ts +0 -213
- package/src/service.ts +0 -306
- package/src/session/activeBranch.ts +0 -294
- package/src/settings.ts +0 -161
- package/src/sidecar/bundle.ts +0 -52
- package/src/sidecar/process.ts +0 -160
- package/src/tools/memoryAppend.ts +0 -166
- package/src/tools/memoryRecall.ts +0 -388
- package/src/trainer/bundleBuilder.ts +0 -192
- package/src/trainer/bundleLoader.ts +0 -105
- package/src/trainer/deltaMerge.ts +0 -221
- package/src/trainer/entityResolver.ts +0 -140
- package/src/trainer/extractFacts.ts +0 -312
- package/src/trainer/index.ts +0 -147
- package/src/trainer/llmExtractor.ts +0 -206
- package/src/trainer/marker.ts +0 -30
- package/src/trainer/scheduler.ts +0 -107
- package/src/trainer/sessionLoader.ts +0 -176
- package/src/types.ts +0 -168
- /package/dist/{consolidation/scheduler → adapters/embed}/types.js +0 -0
- /package/dist/{consolidation → adapters/llm}/types.js +0 -0
|
@@ -1,411 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
PendingSession,
|
|
5
|
-
Stage1Output,
|
|
6
|
-
ConsolidationStatus,
|
|
7
|
-
} from "../types.js";
|
|
8
|
-
|
|
9
|
-
export interface SqliteDatabase {
|
|
10
|
-
pragma(sql: string): unknown;
|
|
11
|
-
exec(sql: string): void;
|
|
12
|
-
prepare(sql: string): {
|
|
13
|
-
run(...args: unknown[]): unknown;
|
|
14
|
-
get(...args: unknown[]): unknown;
|
|
15
|
-
all(...args: unknown[]): unknown[];
|
|
16
|
-
};
|
|
17
|
-
transaction<T>(fn: () => T): () => T;
|
|
18
|
-
close(): void;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type SqliteConstructor = new (path: string) => SqliteDatabase;
|
|
22
|
-
|
|
23
|
-
function loadSqlite(): SqliteConstructor | null {
|
|
24
|
-
try {
|
|
25
|
-
const require = createRequire(import.meta.url);
|
|
26
|
-
const mod = require("better-sqlite3") as SqliteConstructor;
|
|
27
|
-
return mod;
|
|
28
|
-
} catch {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const SCHEMA_VERSION = 1;
|
|
34
|
-
|
|
35
|
-
const SCHEMA_SQL = `
|
|
36
|
-
CREATE TABLE IF NOT EXISTS pending_sessions (
|
|
37
|
-
session_id TEXT PRIMARY KEY,
|
|
38
|
-
session_file TEXT NOT NULL,
|
|
39
|
-
cwd TEXT NOT NULL,
|
|
40
|
-
git_root TEXT,
|
|
41
|
-
project_hash TEXT,
|
|
42
|
-
parent_session_id TEXT,
|
|
43
|
-
parent_session_file TEXT,
|
|
44
|
-
user_turn_count INTEGER NOT NULL,
|
|
45
|
-
ended_at TEXT NOT NULL,
|
|
46
|
-
status TEXT NOT NULL CHECK (status IN ('pending', 'processing', 'done', 'skipped', 'failed')),
|
|
47
|
-
error_message TEXT,
|
|
48
|
-
created_at TEXT NOT NULL,
|
|
49
|
-
updated_at TEXT NOT NULL
|
|
50
|
-
);
|
|
51
|
-
CREATE INDEX IF NOT EXISTS idx_pending_sessions_status ON pending_sessions(status);
|
|
52
|
-
CREATE TABLE IF NOT EXISTS stage1_outputs (
|
|
53
|
-
session_id TEXT PRIMARY KEY,
|
|
54
|
-
session_file TEXT NOT NULL,
|
|
55
|
-
source_mtime_ms INTEGER NOT NULL,
|
|
56
|
-
generated_at TEXT NOT NULL,
|
|
57
|
-
raw_memory TEXT NOT NULL,
|
|
58
|
-
rollout_summary TEXT NOT NULL,
|
|
59
|
-
scope TEXT NOT NULL,
|
|
60
|
-
status TEXT NOT NULL CHECK (status IN ('pending', 'processing', 'done', 'skipped', 'failed')),
|
|
61
|
-
selected_for_phase2 INTEGER NOT NULL DEFAULT 0,
|
|
62
|
-
usage_count INTEGER NOT NULL DEFAULT 0,
|
|
63
|
-
last_usage TEXT,
|
|
64
|
-
error_message TEXT
|
|
65
|
-
);
|
|
66
|
-
CREATE INDEX IF NOT EXISTS idx_stage1_outputs_status ON stage1_outputs(status);
|
|
67
|
-
`;
|
|
68
|
-
|
|
69
|
-
const UPSERT_PENDING_SQL = `
|
|
70
|
-
INSERT INTO pending_sessions (
|
|
71
|
-
session_id,
|
|
72
|
-
session_file,
|
|
73
|
-
cwd,
|
|
74
|
-
git_root,
|
|
75
|
-
project_hash,
|
|
76
|
-
parent_session_id,
|
|
77
|
-
parent_session_file,
|
|
78
|
-
user_turn_count,
|
|
79
|
-
ended_at,
|
|
80
|
-
status,
|
|
81
|
-
error_message,
|
|
82
|
-
created_at,
|
|
83
|
-
updated_at
|
|
84
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
85
|
-
ON CONFLICT(session_id) DO UPDATE SET
|
|
86
|
-
session_file = excluded.session_file,
|
|
87
|
-
cwd = excluded.cwd,
|
|
88
|
-
git_root = excluded.git_root,
|
|
89
|
-
project_hash = excluded.project_hash,
|
|
90
|
-
parent_session_id = excluded.parent_session_id,
|
|
91
|
-
parent_session_file = excluded.parent_session_file,
|
|
92
|
-
user_turn_count = excluded.user_turn_count,
|
|
93
|
-
ended_at = excluded.ended_at,
|
|
94
|
-
status = excluded.status,
|
|
95
|
-
error_message = excluded.error_message,
|
|
96
|
-
updated_at = excluded.updated_at;
|
|
97
|
-
`;
|
|
98
|
-
|
|
99
|
-
const UPSERT_STAGE1_SQL = `
|
|
100
|
-
INSERT INTO stage1_outputs (
|
|
101
|
-
session_id,
|
|
102
|
-
session_file,
|
|
103
|
-
source_mtime_ms,
|
|
104
|
-
generated_at,
|
|
105
|
-
raw_memory,
|
|
106
|
-
rollout_summary,
|
|
107
|
-
scope,
|
|
108
|
-
status,
|
|
109
|
-
selected_for_phase2,
|
|
110
|
-
usage_count,
|
|
111
|
-
last_usage,
|
|
112
|
-
error_message
|
|
113
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
114
|
-
ON CONFLICT(session_id) DO UPDATE SET
|
|
115
|
-
session_file = excluded.session_file,
|
|
116
|
-
source_mtime_ms = excluded.source_mtime_ms,
|
|
117
|
-
generated_at = excluded.generated_at,
|
|
118
|
-
raw_memory = excluded.raw_memory,
|
|
119
|
-
rollout_summary = excluded.rollout_summary,
|
|
120
|
-
scope = excluded.scope,
|
|
121
|
-
status = excluded.status,
|
|
122
|
-
selected_for_phase2 = excluded.selected_for_phase2,
|
|
123
|
-
usage_count = excluded.usage_count,
|
|
124
|
-
last_usage = excluded.last_usage,
|
|
125
|
-
error_message = excluded.error_message;
|
|
126
|
-
`;
|
|
127
|
-
|
|
128
|
-
export interface ConsolidationStore {
|
|
129
|
-
upsertPendingSession(session: Omit<PendingSession, "created_at" | "updated_at"> & {
|
|
130
|
-
created_at: string;
|
|
131
|
-
updated_at: string;
|
|
132
|
-
}): PendingSession;
|
|
133
|
-
upsertStage1Output(output: Stage1Output): void;
|
|
134
|
-
getPendingSession(sessionId: string): PendingSession | null;
|
|
135
|
-
listPendingSessions(limit?: number): PendingSession[];
|
|
136
|
-
setPendingSessionStatus(
|
|
137
|
-
sessionId: string,
|
|
138
|
-
status: ConsolidationStatus,
|
|
139
|
-
errorMessage?: string | null,
|
|
140
|
-
updatedAt?: string,
|
|
141
|
-
): void;
|
|
142
|
-
getStage1Output(sessionId: string): Stage1Output | null;
|
|
143
|
-
listUnselectedStage1(limit: number): Stage1Output[];
|
|
144
|
-
listStage1OlderThan(cutoffIso: string, limit?: number): Stage1Output[];
|
|
145
|
-
markStage1Selected(sessionIds: string[]): void;
|
|
146
|
-
incrementStage1Usage(sessionId: string, usedAt?: string): void;
|
|
147
|
-
countPendingSessions(): number;
|
|
148
|
-
getConsolidationStatusCounts(): {
|
|
149
|
-
pending: number;
|
|
150
|
-
processing: number;
|
|
151
|
-
done: number;
|
|
152
|
-
skipped: number;
|
|
153
|
-
failed: number;
|
|
154
|
-
};
|
|
155
|
-
getStage1Count(): number;
|
|
156
|
-
getLastGeneratedAt(): string | null;
|
|
157
|
-
getLastUpdatedAt(): string | null;
|
|
158
|
-
close(): void;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function toIsoTimestamp(value: Date | string | undefined = new Date()): string {
|
|
162
|
-
const dt = typeof value === "string" ? new Date(value) : value;
|
|
163
|
-
return dt.toISOString();
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function getUserVersion(db: SqliteDatabase): number {
|
|
167
|
-
const raw = db.pragma("user_version");
|
|
168
|
-
if (Array.isArray(raw) && raw[0] && typeof raw[0] === "object" && "user_version" in raw[0]) {
|
|
169
|
-
return Number((raw[0] as { user_version: number }).user_version);
|
|
170
|
-
}
|
|
171
|
-
if (typeof raw === "number") return raw;
|
|
172
|
-
return 0;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function setUserVersion(db: SqliteDatabase, version: number): void {
|
|
176
|
-
db.pragma(`user_version = ${version}`);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function normalizeSessionRow(row: Record<string, unknown> | undefined | null): PendingSession | null {
|
|
180
|
-
if (!row) return null;
|
|
181
|
-
return {
|
|
182
|
-
session_id: String(row.session_id ?? ""),
|
|
183
|
-
session_file: String(row.session_file ?? ""),
|
|
184
|
-
cwd: String(row.cwd ?? ""),
|
|
185
|
-
git_root: row.git_root == null ? null : String(row.git_root),
|
|
186
|
-
project_hash: row.project_hash == null ? null : String(row.project_hash),
|
|
187
|
-
parent_session_id: row.parent_session_id == null ? null : String(row.parent_session_id),
|
|
188
|
-
parent_session_file: row.parent_session_file == null ? null : String(row.parent_session_file),
|
|
189
|
-
user_turn_count: Number(row.user_turn_count ?? 0),
|
|
190
|
-
ended_at: String(row.ended_at ?? ""),
|
|
191
|
-
status: String(row.status ?? "pending") as ConsolidationStatus,
|
|
192
|
-
error_message: row.error_message == null ? null : String(row.error_message),
|
|
193
|
-
created_at: String(row.created_at ?? ""),
|
|
194
|
-
updated_at: String(row.updated_at ?? ""),
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function normalizeStage1Row(row: Record<string, unknown> | undefined | null): Stage1Output | null {
|
|
199
|
-
if (!row) return null;
|
|
200
|
-
return {
|
|
201
|
-
session_id: String(row.session_id ?? ""),
|
|
202
|
-
session_file: String(row.session_file ?? ""),
|
|
203
|
-
source_mtime_ms: toNumber(row.source_mtime_ms, 0),
|
|
204
|
-
generated_at: String(row.generated_at ?? ""),
|
|
205
|
-
raw_memory: String(row.raw_memory ?? ""),
|
|
206
|
-
rollout_summary: String(row.rollout_summary ?? ""),
|
|
207
|
-
scope: String(row.scope ?? "global"),
|
|
208
|
-
status: String(row.status ?? "pending") as ConsolidationStatus,
|
|
209
|
-
selected_for_phase2: Number(row.selected_for_phase2 ?? 0) === 1,
|
|
210
|
-
usage_count: toNumber(row.usage_count, 0),
|
|
211
|
-
last_usage: row.last_usage == null ? null : String(row.last_usage),
|
|
212
|
-
error_message: row.error_message == null ? null : String(row.error_message),
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function toBoolInt(value: boolean): number {
|
|
217
|
-
return value ? 1 : 0;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function toNumber(value: unknown, fallback = 0): number {
|
|
221
|
-
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
222
|
-
if (typeof value === "string") {
|
|
223
|
-
const parsed = Number(value);
|
|
224
|
-
return Number.isFinite(parsed) ? parsed : fallback;
|
|
225
|
-
}
|
|
226
|
-
return fallback;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Lazy-open a sqlite database and ensure the consolidation schema exists.
|
|
231
|
-
* Returns null when better-sqlite3 is unavailable and no injected DB is provided.
|
|
232
|
-
*/
|
|
233
|
-
export function openConsolidationStore(
|
|
234
|
-
dbPath: string,
|
|
235
|
-
injectedDb?: SqliteDatabase,
|
|
236
|
-
): ConsolidationStore | null {
|
|
237
|
-
let db: SqliteDatabase;
|
|
238
|
-
if (injectedDb) {
|
|
239
|
-
db = injectedDb;
|
|
240
|
-
} else {
|
|
241
|
-
const Sqlite = loadSqlite();
|
|
242
|
-
if (!Sqlite) return null;
|
|
243
|
-
db = new Sqlite(dbPath);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
db.pragma("journal_mode = WAL");
|
|
247
|
-
const current = getUserVersion(db);
|
|
248
|
-
if (current !== SCHEMA_VERSION) {
|
|
249
|
-
db.exec(SCHEMA_SQL);
|
|
250
|
-
setUserVersion(db, SCHEMA_VERSION);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const upsertPendingStmt = db.prepare(UPSERT_PENDING_SQL);
|
|
254
|
-
const upsertStage1Stmt = db.prepare(UPSERT_STAGE1_SQL);
|
|
255
|
-
const selectPendingByIdStmt = db.prepare("SELECT * FROM pending_sessions WHERE session_id = ?");
|
|
256
|
-
const listPendingStmt = db.prepare(
|
|
257
|
-
"SELECT * FROM pending_sessions WHERE status IN ('pending', 'failed') ORDER BY ended_at ASC LIMIT ?",
|
|
258
|
-
);
|
|
259
|
-
const updatePendingStatusStmt = db.prepare(
|
|
260
|
-
"UPDATE pending_sessions SET status = ?, error_message = ?, updated_at = ? WHERE session_id = ?",
|
|
261
|
-
);
|
|
262
|
-
const selectStage1ByIdStmt = db.prepare("SELECT * FROM stage1_outputs WHERE session_id = ?");
|
|
263
|
-
const listUnselectedStage1Stmt = db.prepare(
|
|
264
|
-
"SELECT * FROM stage1_outputs WHERE selected_for_phase2 = 0 AND status = 'done' ORDER BY generated_at DESC LIMIT ?",
|
|
265
|
-
);
|
|
266
|
-
const listStage1OlderThanStmt = db.prepare(
|
|
267
|
-
"SELECT * FROM stage1_outputs WHERE last_usage IS NOT NULL AND last_usage < ? ORDER BY last_usage ASC LIMIT ?",
|
|
268
|
-
);
|
|
269
|
-
const markStage1SelectedStmt = db.prepare(
|
|
270
|
-
"UPDATE stage1_outputs SET selected_for_phase2 = 1 WHERE session_id = ?",
|
|
271
|
-
);
|
|
272
|
-
const incrementStage1UsageStmt = db.prepare(
|
|
273
|
-
"UPDATE stage1_outputs SET usage_count = usage_count + 1, last_usage = ? WHERE session_id = ?",
|
|
274
|
-
);
|
|
275
|
-
const countPendingAllStmt = db.prepare("SELECT COUNT(*) AS count FROM pending_sessions");
|
|
276
|
-
const countPendingByStatusStmt = db.prepare(
|
|
277
|
-
"SELECT status, COUNT(*) AS count FROM pending_sessions GROUP BY status",
|
|
278
|
-
);
|
|
279
|
-
const countStage1Stmt = db.prepare("SELECT COUNT(*) AS count FROM stage1_outputs");
|
|
280
|
-
const lastGeneratedStmt = db.prepare("SELECT MAX(generated_at) AS generated_at FROM stage1_outputs");
|
|
281
|
-
const lastUpdatedStmt = db.prepare("SELECT MAX(updated_at) AS updated_at FROM pending_sessions");
|
|
282
|
-
|
|
283
|
-
return {
|
|
284
|
-
upsertPendingSession(session): PendingSession {
|
|
285
|
-
const now = toIsoTimestamp(session.updated_at);
|
|
286
|
-
const payload = {
|
|
287
|
-
...session,
|
|
288
|
-
created_at: session.created_at ?? now,
|
|
289
|
-
updated_at: now,
|
|
290
|
-
};
|
|
291
|
-
upsertPendingStmt.run(
|
|
292
|
-
payload.session_id,
|
|
293
|
-
payload.session_file,
|
|
294
|
-
payload.cwd,
|
|
295
|
-
payload.git_root,
|
|
296
|
-
payload.project_hash,
|
|
297
|
-
payload.parent_session_id,
|
|
298
|
-
payload.parent_session_file,
|
|
299
|
-
payload.user_turn_count,
|
|
300
|
-
payload.ended_at,
|
|
301
|
-
payload.status,
|
|
302
|
-
payload.error_message,
|
|
303
|
-
payload.created_at,
|
|
304
|
-
payload.updated_at,
|
|
305
|
-
);
|
|
306
|
-
return payload;
|
|
307
|
-
},
|
|
308
|
-
upsertStage1Output(output): void {
|
|
309
|
-
upsertStage1Stmt.run(
|
|
310
|
-
output.session_id,
|
|
311
|
-
output.session_file,
|
|
312
|
-
output.source_mtime_ms,
|
|
313
|
-
output.generated_at,
|
|
314
|
-
output.raw_memory,
|
|
315
|
-
output.rollout_summary,
|
|
316
|
-
output.scope,
|
|
317
|
-
output.status,
|
|
318
|
-
toBoolInt(output.selected_for_phase2),
|
|
319
|
-
output.usage_count,
|
|
320
|
-
output.last_usage,
|
|
321
|
-
output.error_message,
|
|
322
|
-
);
|
|
323
|
-
},
|
|
324
|
-
getPendingSession(sessionId: string): PendingSession | null {
|
|
325
|
-
return normalizeSessionRow(
|
|
326
|
-
selectPendingByIdStmt.get(sessionId) as Record<string, unknown> | undefined,
|
|
327
|
-
);
|
|
328
|
-
},
|
|
329
|
-
listPendingSessions(limit = 100): PendingSession[] {
|
|
330
|
-
const rows = listPendingStmt.all(limit) as Array<Record<string, unknown>>;
|
|
331
|
-
return rows
|
|
332
|
-
.map((row) => normalizeSessionRow(row))
|
|
333
|
-
.filter((row): row is PendingSession => row != null);
|
|
334
|
-
},
|
|
335
|
-
setPendingSessionStatus(
|
|
336
|
-
sessionId: string,
|
|
337
|
-
status: ConsolidationStatus,
|
|
338
|
-
errorMessage: string | null = null,
|
|
339
|
-
updatedAt = new Date().toISOString(),
|
|
340
|
-
): void {
|
|
341
|
-
updatePendingStatusStmt.run(status, errorMessage, updatedAt, sessionId);
|
|
342
|
-
},
|
|
343
|
-
getStage1Output(sessionId: string): Stage1Output | null {
|
|
344
|
-
return normalizeStage1Row(
|
|
345
|
-
selectStage1ByIdStmt.get(sessionId) as Record<string, unknown> | undefined,
|
|
346
|
-
);
|
|
347
|
-
},
|
|
348
|
-
listUnselectedStage1(limit: number): Stage1Output[] {
|
|
349
|
-
const rows = listUnselectedStage1Stmt.all(limit) as Array<Record<string, unknown>>;
|
|
350
|
-
return rows
|
|
351
|
-
.map((row) => normalizeStage1Row(row))
|
|
352
|
-
.filter((row): row is Stage1Output => row != null);
|
|
353
|
-
},
|
|
354
|
-
listStage1OlderThan(cutoffIso: string, limit = 100): Stage1Output[] {
|
|
355
|
-
const rows = listStage1OlderThanStmt.all(cutoffIso, limit) as Array<Record<string, unknown>>;
|
|
356
|
-
return rows
|
|
357
|
-
.map((row) => normalizeStage1Row(row))
|
|
358
|
-
.filter((row): row is Stage1Output => row != null);
|
|
359
|
-
},
|
|
360
|
-
markStage1Selected(sessionIds: string[]): void {
|
|
361
|
-
const tx = db.transaction(() => {
|
|
362
|
-
for (const sessionId of sessionIds) markStage1SelectedStmt.run(sessionId);
|
|
363
|
-
});
|
|
364
|
-
tx();
|
|
365
|
-
},
|
|
366
|
-
incrementStage1Usage(sessionId: string, usedAt = new Date().toISOString()): void {
|
|
367
|
-
incrementStage1UsageStmt.run(usedAt, sessionId);
|
|
368
|
-
},
|
|
369
|
-
countPendingSessions(): number {
|
|
370
|
-
const row = countPendingAllStmt.get() as { count?: number | string } | undefined;
|
|
371
|
-
return toNumber(row?.count, 0);
|
|
372
|
-
},
|
|
373
|
-
getConsolidationStatusCounts() {
|
|
374
|
-
const rows = countPendingByStatusStmt.all() as Array<{
|
|
375
|
-
status: ConsolidationStatus;
|
|
376
|
-
count: number | string;
|
|
377
|
-
}>;
|
|
378
|
-
const counts = {
|
|
379
|
-
pending: 0,
|
|
380
|
-
processing: 0,
|
|
381
|
-
done: 0,
|
|
382
|
-
skipped: 0,
|
|
383
|
-
failed: 0,
|
|
384
|
-
};
|
|
385
|
-
for (const row of rows) {
|
|
386
|
-
const status = row.status;
|
|
387
|
-
if (status in counts) {
|
|
388
|
-
counts[status] = toNumber(row.count, 0);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
return counts;
|
|
392
|
-
},
|
|
393
|
-
getStage1Count(): number {
|
|
394
|
-
const row = countStage1Stmt.get() as { count?: number | string } | undefined;
|
|
395
|
-
return toNumber(row?.count, 0);
|
|
396
|
-
},
|
|
397
|
-
getLastGeneratedAt(): string | null {
|
|
398
|
-
const row = lastGeneratedStmt.get() as { generated_at?: string } | undefined;
|
|
399
|
-
if (!row?.generated_at) return null;
|
|
400
|
-
return String(row.generated_at);
|
|
401
|
-
},
|
|
402
|
-
getLastUpdatedAt(): string | null {
|
|
403
|
-
const row = lastUpdatedStmt.get() as { updated_at?: string } | undefined;
|
|
404
|
-
if (!row?.updated_at) return null;
|
|
405
|
-
return String(row.updated_at);
|
|
406
|
-
},
|
|
407
|
-
close(): void {
|
|
408
|
-
db.close();
|
|
409
|
-
},
|
|
410
|
-
};
|
|
411
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export type ConsolidationStatus = "pending" | "processing" | "done" | "skipped" | "failed";
|
|
2
|
-
|
|
3
|
-
export interface PendingSession {
|
|
4
|
-
session_id: string;
|
|
5
|
-
session_file: string;
|
|
6
|
-
cwd: string;
|
|
7
|
-
git_root: string | null;
|
|
8
|
-
project_hash: string | null;
|
|
9
|
-
parent_session_id: string | null;
|
|
10
|
-
parent_session_file: string | null;
|
|
11
|
-
user_turn_count: number;
|
|
12
|
-
ended_at: string;
|
|
13
|
-
status: ConsolidationStatus;
|
|
14
|
-
error_message: string | null;
|
|
15
|
-
created_at: string;
|
|
16
|
-
updated_at: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface Stage1Output {
|
|
20
|
-
session_id: string;
|
|
21
|
-
session_file: string;
|
|
22
|
-
source_mtime_ms: number;
|
|
23
|
-
generated_at: string;
|
|
24
|
-
raw_memory: string;
|
|
25
|
-
rollout_summary: string;
|
|
26
|
-
scope: string;
|
|
27
|
-
status: ConsolidationStatus;
|
|
28
|
-
selected_for_phase2: boolean;
|
|
29
|
-
usage_count: number;
|
|
30
|
-
last_usage: string | null;
|
|
31
|
-
error_message: string | null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface JobReport {
|
|
35
|
-
session_id: string;
|
|
36
|
-
enqueued: boolean;
|
|
37
|
-
action: "created" | "updated" | "skipped";
|
|
38
|
-
status: ConsolidationStatus;
|
|
39
|
-
reason?: string;
|
|
40
|
-
now: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface ConsolidationStatusReport {
|
|
44
|
-
pending: number;
|
|
45
|
-
processing: number;
|
|
46
|
-
done: number;
|
|
47
|
-
skipped: number;
|
|
48
|
-
failed: number;
|
|
49
|
-
stage1Count: number;
|
|
50
|
-
lastGeneratedAt: string | null;
|
|
51
|
-
lastUpdatedAt: string | null;
|
|
52
|
-
}
|
package/src/errclass.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { errorSubCode, type ResponseEnvelope } from "./types.js";
|
|
2
|
-
|
|
3
|
-
export type ErrorClass = "ok" | "retryable" | "permanent" | "unavailable";
|
|
4
|
-
|
|
5
|
-
export const ErrTransport = new Error("memory: transport failure");
|
|
6
|
-
|
|
7
|
-
export function classifyTransportError(err: unknown): ErrorClass {
|
|
8
|
-
return err == null ? "ok" : "unavailable";
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/** Maps HTTP status + envelope → error class (Kocoro memory/errclass.go). */
|
|
12
|
-
export function classifyHTTP(
|
|
13
|
-
status: number,
|
|
14
|
-
env: ResponseEnvelope | null,
|
|
15
|
-
): ErrorClass {
|
|
16
|
-
if (status >= 200 && status < 300) return "ok";
|
|
17
|
-
const sub = env?.error ? errorSubCode(env.error) : "";
|
|
18
|
-
const code = env?.error?.code ?? "";
|
|
19
|
-
switch (status) {
|
|
20
|
-
case 400:
|
|
21
|
-
return "permanent";
|
|
22
|
-
case 401:
|
|
23
|
-
case 403:
|
|
24
|
-
return "permanent";
|
|
25
|
-
case 409:
|
|
26
|
-
return "retryable";
|
|
27
|
-
case 422:
|
|
28
|
-
return "permanent";
|
|
29
|
-
case 503:
|
|
30
|
-
if (code === "not_ready" || sub === "not_ready") return "unavailable";
|
|
31
|
-
return "permanent";
|
|
32
|
-
case 500:
|
|
33
|
-
return "retryable";
|
|
34
|
-
default:
|
|
35
|
-
return "retryable";
|
|
36
|
-
}
|
|
37
|
-
}
|
package/src/extension.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated Use `@chendpoc/pi-memory/extension` (pi-extension.ts) with real ExtensionAPI.
|
|
3
|
-
* Re-exports the Pi extension entry for backward compatibility.
|
|
4
|
-
*/
|
|
5
|
-
export { default, default as piMemoryExtension, getSharedMemoryService } from "./pi-extension.js";
|
|
6
|
-
export type { BeforeTurnHook, MemoryHelperLLM } from "./preflight/hook.js";
|
|
7
|
-
export { createBeforeTurnHook } from "./preflight/hook.js";
|
|
8
|
-
|
|
9
|
-
/** @deprecated Stub types kept for programmatic callers migrating off the old API. */
|
|
10
|
-
export interface PiExtensionAPI {
|
|
11
|
-
config?: Record<string, unknown>;
|
|
12
|
-
registerTool(tool: PiAgentTool): void;
|
|
13
|
-
onBeforeTurn?(hook: import("./preflight/hook.js").BeforeTurnHook): void;
|
|
14
|
-
onUnload?(fn: () => void | Promise<void>): void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** @deprecated */
|
|
18
|
-
export interface PiAgentTool {
|
|
19
|
-
name: string;
|
|
20
|
-
description: string;
|
|
21
|
-
parameters: Record<string, unknown>;
|
|
22
|
-
execute(args: Record<string, unknown>, ctx?: { signal?: AbortSignal }): Promise<string>;
|
|
23
|
-
}
|
package/src/fallback/index.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { FallbackQuery } from "../types.js";
|
|
2
|
-
import { memoryMdSnippet } from "./memoryMd.js";
|
|
3
|
-
import { sessionKeywordSearch } from "./sessionSearch.js";
|
|
4
|
-
|
|
5
|
-
export type { SessionSearchHit } from "./sessionSearch.js";
|
|
6
|
-
export { sessionKeywordSearch } from "./sessionSearch.js";
|
|
7
|
-
export { memoryMdSnippet } from "./memoryMd.js";
|
|
8
|
-
|
|
9
|
-
export interface FallbackOptions {
|
|
10
|
-
sessionsDir: string;
|
|
11
|
-
memoryMdPaths: string[];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** Real fallback: session JSON keyword search + MEMORY.md grep. */
|
|
15
|
-
export function createFallbackQuery(opts: FallbackOptions): FallbackQuery {
|
|
16
|
-
return {
|
|
17
|
-
async sessionKeyword(query: string, limit: number) {
|
|
18
|
-
return sessionKeywordSearch(opts.sessionsDir, query, limit);
|
|
19
|
-
},
|
|
20
|
-
async memoryFileSnippet(query: string) {
|
|
21
|
-
return memoryMdSnippet(opts.memoryMdPaths, query);
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import type { LLMClient } from "../trainer/llmExtractor.js";
|
|
2
|
-
import type { SessionSearchHit } from "./sessionSearch.js";
|
|
3
|
-
import { cacheKeyForRerank, rerankCache } from "../cache/memoryCaches.js";
|
|
4
|
-
|
|
5
|
-
export interface RerankOptions {
|
|
6
|
-
client: LLMClient;
|
|
7
|
-
maxCandidates?: number;
|
|
8
|
-
maxTokens?: number;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface RankedResult {
|
|
12
|
-
index: number;
|
|
13
|
-
score: number;
|
|
14
|
-
summary: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const DEFAULT_MAX_CANDIDATES = 10;
|
|
18
|
-
|
|
19
|
-
function buildRerankPrompt(query: string, hits: SessionSearchHit[]): string {
|
|
20
|
-
const numbered = hits
|
|
21
|
-
.map((h, i) => `#${i}: [${h.session_title || "untitled"}] ${h.snippet}`)
|
|
22
|
-
.join("\n");
|
|
23
|
-
|
|
24
|
-
return `You are a relevance judge. Given a user query and numbered search results from past sessions, rate each result 0-10 for relevance to the query and write a one-sentence summary of the relevant content.
|
|
25
|
-
|
|
26
|
-
Query: ${query}
|
|
27
|
-
|
|
28
|
-
Results:
|
|
29
|
-
${numbered}
|
|
30
|
-
|
|
31
|
-
Respond with ONLY a JSON array (no markdown fences, no explanation):
|
|
32
|
-
[{ "index": 0, "score": 8, "summary": "..." }, ...]`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
interface RawRankedItem {
|
|
36
|
-
index?: unknown;
|
|
37
|
-
score?: unknown;
|
|
38
|
-
summary?: unknown;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function parseRerankResponse(raw: string, hitCount: number): RankedResult[] | null {
|
|
42
|
-
const cleaned = raw.replace(/^```(?:json)?\s*/m, "").replace(/\s*```\s*$/m, "").trim();
|
|
43
|
-
|
|
44
|
-
let parsed: unknown;
|
|
45
|
-
try {
|
|
46
|
-
parsed = JSON.parse(cleaned);
|
|
47
|
-
} catch {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (!Array.isArray(parsed)) return null;
|
|
52
|
-
|
|
53
|
-
const results: RankedResult[] = [];
|
|
54
|
-
for (const item of parsed as RawRankedItem[]) {
|
|
55
|
-
const index = typeof item.index === "number" ? item.index : -1;
|
|
56
|
-
const score = typeof item.score === "number" ? item.score : 0;
|
|
57
|
-
const summary = typeof item.summary === "string" ? item.summary.trim() : "";
|
|
58
|
-
if (index < 0 || index >= hitCount || !summary) continue;
|
|
59
|
-
results.push({ index, score: Math.max(0, Math.min(10, score)), summary });
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (results.length === 0) return null;
|
|
63
|
-
|
|
64
|
-
results.sort((a, b) => b.score - a.score);
|
|
65
|
-
return results;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Rerank FTS5 search hits using an LLM. Returns scored + summarized results
|
|
70
|
-
* sorted by relevance. On any LLM failure, returns null (caller should use
|
|
71
|
-
* original hits as fallback).
|
|
72
|
-
*/
|
|
73
|
-
export async function rerankWithLLM(
|
|
74
|
-
query: string,
|
|
75
|
-
hits: SessionSearchHit[],
|
|
76
|
-
opts: RerankOptions,
|
|
77
|
-
): Promise<RankedResult[] | null> {
|
|
78
|
-
if (hits.length === 0) return null;
|
|
79
|
-
|
|
80
|
-
const maxCandidates = opts.maxCandidates ?? DEFAULT_MAX_CANDIDATES;
|
|
81
|
-
const truncated = hits.slice(0, maxCandidates);
|
|
82
|
-
|
|
83
|
-
const cacheKey = cacheKeyForRerank(query, truncated);
|
|
84
|
-
const cached = rerankCache.get(cacheKey);
|
|
85
|
-
if (cached) return cached;
|
|
86
|
-
|
|
87
|
-
const prompt = buildRerankPrompt(query, truncated);
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
const response = await opts.client.complete(prompt);
|
|
91
|
-
const results = parseRerankResponse(response, truncated.length);
|
|
92
|
-
if (results) rerankCache.set(cacheKey, results);
|
|
93
|
-
return results;
|
|
94
|
-
} catch {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
}
|
package/src/fallback/memoryMd.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
|
|
3
|
-
const SNIPPET_CAP = 4096;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Best-effort grep of MEMORY.md for query terms (Kocoro memory_fallback.go).
|
|
7
|
-
* Returns joined matching lines capped at 4KB. Empty string if absent/no match.
|
|
8
|
-
*/
|
|
9
|
-
export async function memoryMdSnippet(
|
|
10
|
-
paths: string[],
|
|
11
|
-
query: string,
|
|
12
|
-
): Promise<string> {
|
|
13
|
-
const q = query.trim().toLowerCase();
|
|
14
|
-
if (!q) return "";
|
|
15
|
-
|
|
16
|
-
for (const p of paths) {
|
|
17
|
-
let text: string;
|
|
18
|
-
try {
|
|
19
|
-
text = await fs.readFile(p, "utf8");
|
|
20
|
-
} catch {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
const matches: string[] = [];
|
|
24
|
-
let total = 0;
|
|
25
|
-
for (const line of text.split("\n")) {
|
|
26
|
-
if (!line.toLowerCase().includes(q)) continue;
|
|
27
|
-
matches.push(line);
|
|
28
|
-
total += line.length + 1;
|
|
29
|
-
if (total > SNIPPET_CAP) break;
|
|
30
|
-
}
|
|
31
|
-
if (matches.length > 0) {
|
|
32
|
-
return matches.join("\n");
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return "";
|
|
36
|
-
}
|