@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
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { SHUTDOWN_PROCESSED_FILE } from "../constants/memory.js";
|
|
2
|
+
import { joinPath, readText, writeText } from "../utils/fs.js";
|
|
3
|
+
|
|
4
|
+
export type ShutdownProcessedState = {
|
|
5
|
+
processed: string[];
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type ShutdownSkipReason =
|
|
9
|
+
| "missing_session"
|
|
10
|
+
| "compaction_already_ingested"
|
|
11
|
+
| "subagent_no_delta"
|
|
12
|
+
| "no_export"
|
|
13
|
+
| "no_llm"
|
|
14
|
+
| "ingested_compaction"
|
|
15
|
+
| "ingested_llm";
|
|
16
|
+
|
|
17
|
+
export function shutdownProcessedPath(agentDir: string): string {
|
|
18
|
+
return joinPath(agentDir, SHUTDOWN_PROCESSED_FILE);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function readShutdownProcessedState(agentDir: string): Promise<ShutdownProcessedState> {
|
|
22
|
+
const raw = await readText(shutdownProcessedPath(agentDir));
|
|
23
|
+
if (!raw.trim()) return { processed: [] };
|
|
24
|
+
try {
|
|
25
|
+
const parsed = JSON.parse(raw) as ShutdownProcessedState;
|
|
26
|
+
return { processed: Array.isArray(parsed.processed) ? parsed.processed : [] };
|
|
27
|
+
} catch {
|
|
28
|
+
return { processed: [] };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function markShutdownProcessed(
|
|
33
|
+
agentDir: string,
|
|
34
|
+
sessionFile: string,
|
|
35
|
+
): Promise<void> {
|
|
36
|
+
const state = await readShutdownProcessedState(agentDir);
|
|
37
|
+
if (!state.processed.includes(sessionFile)) {
|
|
38
|
+
state.processed.push(sessionFile);
|
|
39
|
+
}
|
|
40
|
+
await writeText(shutdownProcessedPath(agentDir), JSON.stringify(state, null, 2));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function isShutdownProcessed(state: ShutdownProcessedState, sessionFile: string): boolean {
|
|
44
|
+
return state.processed.includes(sessionFile);
|
|
45
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { parseJsonlLine } from "../ipc/jsonlFramer.js";
|
|
2
|
+
import { readText } from "../utils/fs.js";
|
|
3
|
+
|
|
4
|
+
import { shutdownQueuePath, type ShutdownQueueEntry } from "./enqueue.js";
|
|
5
|
+
|
|
6
|
+
/** Latest queue row per session file (deduped). */
|
|
7
|
+
export async function readShutdownQueueEntries(agentDir: string): Promise<ShutdownQueueEntry[]> {
|
|
8
|
+
const raw = await readText(shutdownQueuePath(agentDir));
|
|
9
|
+
if (!raw.trim()) return [];
|
|
10
|
+
|
|
11
|
+
const bySession = new Map<string, ShutdownQueueEntry>();
|
|
12
|
+
|
|
13
|
+
for (const line of raw.split("\n")) {
|
|
14
|
+
const trimmed = line.trim();
|
|
15
|
+
if (!trimmed) continue;
|
|
16
|
+
try {
|
|
17
|
+
const entry = parseJsonlLine<ShutdownQueueEntry>(trimmed);
|
|
18
|
+
if (!entry.sessionFile?.trim()) continue;
|
|
19
|
+
bySession.set(entry.sessionFile, entry);
|
|
20
|
+
} catch {
|
|
21
|
+
// skip malformed lines
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return [...bySession.values()];
|
|
26
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import type { LlmClient } from "../adapters/llm/types.js";
|
|
2
|
+
import {
|
|
3
|
+
filterCompactionDelta,
|
|
4
|
+
shouldSkipSubagentCompactionIngest,
|
|
5
|
+
} from "../compact/subagentDelta.js";
|
|
6
|
+
import { parseMemoryExport } from "../compact/parseMemoryExport.js";
|
|
7
|
+
import { reindex } from "../sidecar/client.js";
|
|
8
|
+
import { ensureSidecarRunning } from "../sidecar/sidecarManager.js";
|
|
9
|
+
import { resolveSidecarPaths } from "../sidecar/paths.js";
|
|
10
|
+
import { sidecarQueryCache } from "../preflight/queryCache.js";
|
|
11
|
+
import type { MemoryStore } from "../store/memoryStore.js";
|
|
12
|
+
import { canRead, pathExists } from "../utils/fs.js";
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
buildShutdownMemoryExportPrompt,
|
|
16
|
+
wrapShutdownExportMarkdown,
|
|
17
|
+
} from "./extractPrompt.js";
|
|
18
|
+
import { markShutdownProcessed, readShutdownProcessedState, isShutdownProcessed } from "./processed.js";
|
|
19
|
+
import { readShutdownQueueEntries } from "./readQueue.js";
|
|
20
|
+
import type { ShutdownQueueEntry } from "./enqueue.js";
|
|
21
|
+
import { readLatestCompactionSummary, readSessionConversationText } from "./sessionReader.js";
|
|
22
|
+
|
|
23
|
+
export type DrainShutdownQueueStats = {
|
|
24
|
+
queued: number;
|
|
25
|
+
skipped: number;
|
|
26
|
+
ingested: number;
|
|
27
|
+
appended: number;
|
|
28
|
+
indexGeneration?: number;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type RunDrainShutdownQueueOptions = {
|
|
32
|
+
store: MemoryStore;
|
|
33
|
+
agentDir: string;
|
|
34
|
+
llm?: LlmClient | null;
|
|
35
|
+
reindex?: boolean;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type RunDrainShutdownQueueResult =
|
|
39
|
+
| { status: "empty" }
|
|
40
|
+
| { status: "drained"; stats: DrainShutdownQueueStats }
|
|
41
|
+
| { status: "failed"; error: Error };
|
|
42
|
+
|
|
43
|
+
export async function runDrainShutdownQueueJob(
|
|
44
|
+
opts: RunDrainShutdownQueueOptions,
|
|
45
|
+
): Promise<RunDrainShutdownQueueResult> {
|
|
46
|
+
const queue = await readShutdownQueueEntries(opts.agentDir);
|
|
47
|
+
if (queue.length === 0) return { status: "empty" };
|
|
48
|
+
|
|
49
|
+
const processedState = await readShutdownProcessedState(opts.agentDir);
|
|
50
|
+
const stats: DrainShutdownQueueStats = {
|
|
51
|
+
queued: queue.length,
|
|
52
|
+
skipped: 0,
|
|
53
|
+
ingested: 0,
|
|
54
|
+
appended: 0,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
for (const entry of queue) {
|
|
59
|
+
const sessionFile = entry.sessionFile.trim();
|
|
60
|
+
if (isShutdownProcessed(processedState, sessionFile)) {
|
|
61
|
+
stats.skipped += 1;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const result = await drainQueueEntry({
|
|
66
|
+
entry,
|
|
67
|
+
store: opts.store,
|
|
68
|
+
agentDir: opts.agentDir,
|
|
69
|
+
llm: opts.llm ?? null,
|
|
70
|
+
});
|
|
71
|
+
stats.appended += result.appended;
|
|
72
|
+
if (result.appended > 0) {
|
|
73
|
+
stats.ingested += 1;
|
|
74
|
+
} else {
|
|
75
|
+
stats.skipped += 1;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (stats.appended > 0 && opts.reindex !== false) {
|
|
80
|
+
stats.indexGeneration = await syncSidecarIndex(opts.agentDir, opts.store);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return { status: "drained", stats };
|
|
84
|
+
} catch (error) {
|
|
85
|
+
return {
|
|
86
|
+
status: "failed",
|
|
87
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function drainQueueEntry(opts: {
|
|
93
|
+
entry: ShutdownQueueEntry;
|
|
94
|
+
store: MemoryStore;
|
|
95
|
+
agentDir: string;
|
|
96
|
+
llm: LlmClient | null;
|
|
97
|
+
}): Promise<{ appended: number }> {
|
|
98
|
+
const sessionFile = opts.entry.sessionFile.trim();
|
|
99
|
+
if (!sessionFile) {
|
|
100
|
+
return { appended: 0 };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!pathExists(sessionFile) || !canRead(sessionFile)) {
|
|
104
|
+
await markShutdownProcessed(opts.agentDir, sessionFile);
|
|
105
|
+
return { appended: 0 };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const compaction = await readLatestCompactionSummary(sessionFile);
|
|
109
|
+
if (compaction && (await opts.store.hasProcessedCompaction(compaction.compactionId))) {
|
|
110
|
+
await markShutdownProcessed(opts.agentDir, sessionFile);
|
|
111
|
+
return { appended: 0 };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (compaction) {
|
|
115
|
+
const appended = await ingestFromSummary({
|
|
116
|
+
store: opts.store,
|
|
117
|
+
agentDir: opts.agentDir,
|
|
118
|
+
sessionFile,
|
|
119
|
+
summary: compaction.summary,
|
|
120
|
+
compactionId: compaction.compactionId,
|
|
121
|
+
subagent: opts.entry.isSubagent,
|
|
122
|
+
});
|
|
123
|
+
return { appended };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (!opts.llm) {
|
|
127
|
+
await markShutdownProcessed(opts.agentDir, sessionFile);
|
|
128
|
+
return { appended: 0 };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const conversationText = await readSessionConversationText(sessionFile);
|
|
132
|
+
if (!conversationText?.trim()) {
|
|
133
|
+
await markShutdownProcessed(opts.agentDir, sessionFile);
|
|
134
|
+
return { appended: 0 };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const prompt = buildShutdownMemoryExportPrompt(conversationText);
|
|
138
|
+
const raw = await opts.llm.complete(prompt);
|
|
139
|
+
const summary = wrapShutdownExportMarkdown(raw);
|
|
140
|
+
if (!summary.trim()) {
|
|
141
|
+
await markShutdownProcessed(opts.agentDir, sessionFile);
|
|
142
|
+
return { appended: 0 };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const appended = await ingestFromSummary({
|
|
146
|
+
store: opts.store,
|
|
147
|
+
agentDir: opts.agentDir,
|
|
148
|
+
sessionFile,
|
|
149
|
+
summary,
|
|
150
|
+
subagent: opts.entry.isSubagent,
|
|
151
|
+
});
|
|
152
|
+
return { appended };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function ingestFromSummary(opts: {
|
|
156
|
+
store: MemoryStore;
|
|
157
|
+
agentDir: string;
|
|
158
|
+
sessionFile: string;
|
|
159
|
+
summary: string;
|
|
160
|
+
compactionId?: string;
|
|
161
|
+
subagent?: boolean;
|
|
162
|
+
}): Promise<number> {
|
|
163
|
+
const parsed = parseMemoryExport(opts.summary);
|
|
164
|
+
if (parsed.length === 0) {
|
|
165
|
+
if (opts.compactionId) {
|
|
166
|
+
await opts.store.markCompactionProcessed(opts.compactionId);
|
|
167
|
+
}
|
|
168
|
+
await markShutdownProcessed(opts.agentDir, opts.sessionFile);
|
|
169
|
+
return 0;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
let entries = parsed;
|
|
173
|
+
if (opts.subagent) {
|
|
174
|
+
const existing = await opts.store.listEntries();
|
|
175
|
+
entries = filterCompactionDelta(parsed, existing);
|
|
176
|
+
if (shouldSkipSubagentCompactionIngest(parsed, entries)) {
|
|
177
|
+
if (opts.compactionId) {
|
|
178
|
+
await opts.store.markCompactionProcessed(opts.compactionId);
|
|
179
|
+
}
|
|
180
|
+
await markShutdownProcessed(opts.agentDir, opts.sessionFile);
|
|
181
|
+
return 0;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (entries.length > 0) {
|
|
186
|
+
await opts.store.appendMany(entries, { mode: "ifAbsent" });
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (opts.compactionId) {
|
|
190
|
+
await opts.store.markCompactionProcessed(opts.compactionId);
|
|
191
|
+
}
|
|
192
|
+
await markShutdownProcessed(opts.agentDir, opts.sessionFile);
|
|
193
|
+
return entries.length;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function syncSidecarIndex(agentDir: string, store: MemoryStore): Promise<number> {
|
|
197
|
+
const sidecar = resolveSidecarPaths(agentDir);
|
|
198
|
+
await ensureSidecarRunning(sidecar);
|
|
199
|
+
const result = await reindex(sidecar.socketPath, await store.exportForIndex());
|
|
200
|
+
sidecarQueryCache.onReindexComplete(agentDir, result.index_generation);
|
|
201
|
+
return result.index_generation;
|
|
202
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import {
|
|
3
|
+
buildSessionContext,
|
|
4
|
+
convertToLlm,
|
|
5
|
+
getLatestCompactionEntry,
|
|
6
|
+
parseSessionEntries,
|
|
7
|
+
serializeConversation,
|
|
8
|
+
type FileEntry,
|
|
9
|
+
type SessionEntry,
|
|
10
|
+
} from "@earendil-works/pi-coding-agent";
|
|
11
|
+
|
|
12
|
+
import { stripPrivateMemory } from "../preflight/strip.js";
|
|
13
|
+
import { readTextRequired } from "../utils/fs.js";
|
|
14
|
+
|
|
15
|
+
function stripPrivateMemoryFromMessages(messages: AgentMessage[]): AgentMessage[] {
|
|
16
|
+
return messages.map((message) => {
|
|
17
|
+
if (message.role !== "user") return message;
|
|
18
|
+
if (typeof message.content === "string") {
|
|
19
|
+
return { ...message, content: stripPrivateMemory(message.content) };
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
...message,
|
|
23
|
+
content: message.content.map((block) =>
|
|
24
|
+
block.type === "text" ? { ...block, text: stripPrivateMemory(block.text) } : block,
|
|
25
|
+
),
|
|
26
|
+
} as AgentMessage;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function toSessionEntries(fileEntries: FileEntry[]): SessionEntry[] {
|
|
31
|
+
return fileEntries.filter((entry): entry is SessionEntry => entry.type !== "session");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function resolveLeafId(entries: SessionEntry[]): string | null {
|
|
35
|
+
return entries.at(-1)?.id ?? null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function readSessionConversationText(sessionFile: string): Promise<string | null> {
|
|
39
|
+
const content = await readTextRequired(sessionFile);
|
|
40
|
+
const fileEntries = parseSessionEntries(content);
|
|
41
|
+
const entries = toSessionEntries(fileEntries);
|
|
42
|
+
if (entries.length === 0) return null;
|
|
43
|
+
|
|
44
|
+
const context = buildSessionContext(entries, resolveLeafId(entries));
|
|
45
|
+
const messages = stripPrivateMemoryFromMessages(context.messages);
|
|
46
|
+
if (messages.length === 0) return null;
|
|
47
|
+
|
|
48
|
+
return serializeConversation(convertToLlm(messages));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function readLatestCompactionSummary(sessionFile: string): Promise<{
|
|
52
|
+
compactionId: string;
|
|
53
|
+
summary: string;
|
|
54
|
+
} | null> {
|
|
55
|
+
const content = await readTextRequired(sessionFile);
|
|
56
|
+
const fileEntries = parseSessionEntries(content);
|
|
57
|
+
const entries = toSessionEntries(fileEntries);
|
|
58
|
+
const compaction = getLatestCompactionEntry(entries);
|
|
59
|
+
if (!compaction?.summary?.trim()) return null;
|
|
60
|
+
return { compactionId: compaction.id, summary: compaction.summary };
|
|
61
|
+
}
|
package/src/sidecar/client.ts
CHANGED
|
@@ -1,166 +1,114 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
// Agent 侧:发送请求到 sidecar
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import net from "node:net";
|
|
3
4
|
|
|
4
5
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "../
|
|
10
|
-
import type
|
|
11
|
-
HealthPayload,
|
|
12
|
-
QueryIntent,
|
|
13
|
-
QueryRequest,
|
|
14
|
-
ReloadResponse,
|
|
15
|
-
ResponseEnvelope,
|
|
16
|
-
} from "../types.js";
|
|
6
|
+
SIDECAR_PING_TIMEOUT_MS,
|
|
7
|
+
SIDECAR_QUERY_TIMEOUT_MS,
|
|
8
|
+
SIDECAR_REINDEX_TIMEOUT_MS,
|
|
9
|
+
} from "../constants/timing.js";
|
|
10
|
+
import { JsonlFramer, parseJsonlLine, serializeJsonlFrame } from "../ipc/jsonlFramer.js";
|
|
11
|
+
import { isErrorResponse, type IndexDocument, type IndexStats, type SidecarResponse } from "./protocol.js";
|
|
17
12
|
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
export function sidecarRequest<T extends SidecarResponse>(
|
|
14
|
+
socketPath: string,
|
|
15
|
+
frame: Record<string, unknown>,
|
|
16
|
+
timeoutMs = SIDECAR_QUERY_TIMEOUT_MS,
|
|
17
|
+
): Promise<T> {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
const socket = net.connect(socketPath);
|
|
20
|
+
const framer = new JsonlFramer();
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
) {}
|
|
22
|
+
const timer = setTimeout(() => {
|
|
23
|
+
socket.destroy();
|
|
24
|
+
reject(new Error("Sidecar request timed out"));
|
|
25
|
+
}, timeoutMs);
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
socket.on("connect", () => {
|
|
28
|
+
socket.write(serializeJsonlFrame(frame));
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
socket.on("data", (chunk) => {
|
|
32
|
+
for (const line of framer.push(chunk.toString())) {
|
|
33
|
+
clearTimeout(timer);
|
|
34
|
+
socket.end();
|
|
35
|
+
|
|
36
|
+
let response: SidecarResponse;
|
|
37
|
+
try {
|
|
38
|
+
response = parseJsonlLine<SidecarResponse>(line);
|
|
39
|
+
} catch {
|
|
40
|
+
reject(new Error("Invalid JSON response from sidecar"));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (isErrorResponse(response)) {
|
|
45
|
+
reject(new Error(response.error));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
31
48
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
signal?: AbortSignal,
|
|
35
|
-
): Promise<{
|
|
36
|
-
env: ResponseEnvelope | null;
|
|
37
|
-
errorClass: ErrorClass;
|
|
38
|
-
transportError?: Error;
|
|
39
|
-
}> {
|
|
40
|
-
const rid = requestId();
|
|
41
|
-
const body: QueryRequest = { intent, request_id: rid };
|
|
42
|
-
try {
|
|
43
|
-
const { status, data } = await this.doRaw<ResponseEnvelope>(
|
|
44
|
-
"POST",
|
|
45
|
-
"/query",
|
|
46
|
-
body,
|
|
47
|
-
signal,
|
|
48
|
-
rid,
|
|
49
|
-
);
|
|
50
|
-
return {
|
|
51
|
-
env: data,
|
|
52
|
-
errorClass: classifyHTTP(status, data),
|
|
53
|
-
};
|
|
54
|
-
} catch (err) {
|
|
55
|
-
if (err instanceof Error && err.message.includes("transport")) {
|
|
56
|
-
return {
|
|
57
|
-
env: null,
|
|
58
|
-
errorClass: classifyTransportError(err),
|
|
59
|
-
transportError: err,
|
|
60
|
-
};
|
|
49
|
+
resolve(response as T);
|
|
50
|
+
return;
|
|
61
51
|
}
|
|
62
|
-
|
|
63
|
-
env: null,
|
|
64
|
-
errorClass: "unavailable",
|
|
65
|
-
transportError: err instanceof Error ? err : new Error(String(err)),
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
52
|
+
});
|
|
69
53
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
54
|
+
socket.on("error", reject);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
73
57
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
): Promise<T> {
|
|
81
|
-
const { data } = await this.doRaw<T>(
|
|
82
|
-
method,
|
|
83
|
-
path,
|
|
84
|
-
body,
|
|
85
|
-
signal,
|
|
86
|
-
requestIdHeader,
|
|
58
|
+
export async function ping(socketPath: string): Promise<boolean> {
|
|
59
|
+
try {
|
|
60
|
+
const res = await sidecarRequest<Extract<SidecarResponse, { type: "pong" }>>(
|
|
61
|
+
socketPath,
|
|
62
|
+
{ type: "ping" },
|
|
63
|
+
SIDECAR_PING_TIMEOUT_MS,
|
|
87
64
|
);
|
|
88
|
-
return
|
|
65
|
+
return res.type === "pong";
|
|
66
|
+
} catch {
|
|
67
|
+
return false;
|
|
89
68
|
}
|
|
69
|
+
}
|
|
90
70
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
? {
|
|
109
|
-
"Content-Type": "application/json",
|
|
110
|
-
"Content-Length": Buffer.byteLength(payload),
|
|
111
|
-
}
|
|
112
|
-
: {}),
|
|
113
|
-
},
|
|
114
|
-
timeout: this.timeoutMs,
|
|
115
|
-
},
|
|
116
|
-
(res) => {
|
|
117
|
-
const chunks: Buffer[] = [];
|
|
118
|
-
res.on("data", (c) => chunks.push(c));
|
|
119
|
-
res.on("end", () => {
|
|
120
|
-
const text = Buffer.concat(chunks).toString("utf8");
|
|
121
|
-
if (!text) {
|
|
122
|
-
reject(new Error(`${ErrTransport.message}: empty body`));
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
try {
|
|
126
|
-
resolve({
|
|
127
|
-
status: res.statusCode ?? 0,
|
|
128
|
-
data: JSON.parse(text) as T,
|
|
129
|
-
});
|
|
130
|
-
} catch (e) {
|
|
131
|
-
reject(
|
|
132
|
-
new Error(
|
|
133
|
-
`${ErrTransport.message}: decode: ${e instanceof Error ? e.message : e}`,
|
|
134
|
-
),
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
},
|
|
139
|
-
);
|
|
71
|
+
export async function fetchIndexStats(
|
|
72
|
+
socketPath: string,
|
|
73
|
+
): Promise<{ stats: IndexStats } | { error: string }> {
|
|
74
|
+
try {
|
|
75
|
+
const res = await sidecarRequest<Extract<SidecarResponse, { type: "stats_ok" }>>(
|
|
76
|
+
socketPath,
|
|
77
|
+
{ type: "stats" },
|
|
78
|
+
SIDECAR_PING_TIMEOUT_MS,
|
|
79
|
+
);
|
|
80
|
+
if (res.type !== "stats_ok") return { error: "unexpected sidecar response" };
|
|
81
|
+
const { type: _type, ...stats } = res;
|
|
82
|
+
return { stats };
|
|
83
|
+
} catch (error) {
|
|
84
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
85
|
+
return { error: message };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
140
88
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
89
|
+
export async function query(
|
|
90
|
+
socketPath: string,
|
|
91
|
+
queryText: string,
|
|
92
|
+
timeoutMs = SIDECAR_QUERY_TIMEOUT_MS,
|
|
93
|
+
) {
|
|
94
|
+
const request_id = randomUUID();
|
|
95
|
+
return sidecarRequest<Extract<SidecarResponse, { type: "result" }>>(
|
|
96
|
+
socketPath,
|
|
97
|
+
{ type: "query", request_id, query: queryText },
|
|
98
|
+
timeoutMs,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
147
101
|
|
|
148
|
-
|
|
149
|
-
if (signal.aborted) {
|
|
150
|
-
req.destroy(new Error(`${ErrTransport.message}: aborted`));
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
signal.addEventListener(
|
|
154
|
-
"abort",
|
|
155
|
-
() => {
|
|
156
|
-
req.destroy(new Error(`${ErrTransport.message}: aborted`));
|
|
157
|
-
},
|
|
158
|
-
{ once: true },
|
|
159
|
-
);
|
|
160
|
-
}
|
|
102
|
+
export type ReindexResult = Extract<SidecarResponse, { type: "reindex_ok" }>;
|
|
161
103
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
104
|
+
export async function reindex(
|
|
105
|
+
socketPath: string,
|
|
106
|
+
documents: IndexDocument[] = [],
|
|
107
|
+
): Promise<ReindexResult> {
|
|
108
|
+
const request_id = randomUUID();
|
|
109
|
+
return sidecarRequest<ReindexResult>(
|
|
110
|
+
socketPath,
|
|
111
|
+
{ type: "reindex", request_id, documents },
|
|
112
|
+
SIDECAR_REINDEX_TIMEOUT_MS,
|
|
113
|
+
);
|
|
166
114
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
|
|
3
|
+
import { SIDECAR_DB_FILE, SIDECAR_SOCKET_FILE } from "../constants/paths.js";
|
|
4
|
+
import { canRead, joinPath, pathDirname } from "../utils/fs.js";
|
|
5
|
+
|
|
6
|
+
export type SidecarPaths = {
|
|
7
|
+
socketPath: string;
|
|
8
|
+
dbPath: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function resolveSidecarPaths(agentDir: string): SidecarPaths {
|
|
12
|
+
return {
|
|
13
|
+
socketPath: joinPath(agentDir, SIDECAR_SOCKET_FILE),
|
|
14
|
+
dbPath: joinPath(agentDir, SIDECAR_DB_FILE),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Resolve compiled sidecar entry (dist/sidecar/server/process.js). */
|
|
19
|
+
export function resolveSidecarEntry(): string {
|
|
20
|
+
const here = pathDirname(fileURLToPath(import.meta.url));
|
|
21
|
+
const candidates = [
|
|
22
|
+
joinPath(here, "server/process.js"),
|
|
23
|
+
joinPath(here, "../../dist/sidecar/server/process.js"),
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
for (const entry of candidates) {
|
|
27
|
+
if (canRead(entry)) return entry;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
throw new Error("Sidecar entry not found; run `pnpm build` first");
|
|
31
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type MemoryEntry = {
|
|
2
|
+
content: string;
|
|
3
|
+
relevance: number;
|
|
4
|
+
timestamp: string;
|
|
5
|
+
source: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type IndexDocument = {
|
|
9
|
+
id: string;
|
|
10
|
+
content: string;
|
|
11
|
+
source: string;
|
|
12
|
+
timestamp: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type SidecarRequest =
|
|
16
|
+
| { type: "ping" }
|
|
17
|
+
| { type: "stats" }
|
|
18
|
+
| { type: "query"; request_id: string; query: string }
|
|
19
|
+
| { type: "reindex"; request_id: string; documents?: IndexDocument[] };
|
|
20
|
+
|
|
21
|
+
export type IndexStats = {
|
|
22
|
+
index_generation: number;
|
|
23
|
+
chunk_count: number;
|
|
24
|
+
embedding_provider?: string;
|
|
25
|
+
embedding_model?: string;
|
|
26
|
+
embedding_dim?: number;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type SidecarResponse =
|
|
30
|
+
| { type: "pong" }
|
|
31
|
+
| { type: "stats_ok" } & IndexStats
|
|
32
|
+
| { type: "result"; request_id: string; results: MemoryEntry[] }
|
|
33
|
+
| { type: "reindex_ok"; request_id: string; indexed: number; index_generation: number }
|
|
34
|
+
| { type: "error"; request_id?: string; error: string };
|
|
35
|
+
|
|
36
|
+
export function isErrorResponse(res: SidecarResponse): res is Extract<SidecarResponse, { type: "error" }> {
|
|
37
|
+
return res.type === "error";
|
|
38
|
+
}
|