@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,294 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
|
|
3
|
-
interface UnknownRecord {
|
|
4
|
-
[key: string]: unknown;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface ActiveBranchTurn {
|
|
8
|
-
role: string;
|
|
9
|
-
content: string;
|
|
10
|
-
turnIndex: number;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface ParsedSession {
|
|
14
|
-
id: string;
|
|
15
|
-
title: string;
|
|
16
|
-
createdAt: string;
|
|
17
|
-
turns: ActiveBranchTurn[];
|
|
18
|
-
parentSessionId?: string;
|
|
19
|
-
parentSessionFile?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface JsonlNodeInfo {
|
|
23
|
-
parentId?: string;
|
|
24
|
-
parentSessionId?: string;
|
|
25
|
-
parentSessionFile?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface ParsedJsonlLine {
|
|
29
|
-
id?: string;
|
|
30
|
-
parentId?: string;
|
|
31
|
-
parentSessionId?: string;
|
|
32
|
-
parentSessionFile?: string;
|
|
33
|
-
message?: {
|
|
34
|
-
role?: string;
|
|
35
|
-
content?: unknown;
|
|
36
|
-
};
|
|
37
|
-
role?: string;
|
|
38
|
-
content?: unknown;
|
|
39
|
-
timestamp?: string;
|
|
40
|
-
createdAt?: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function asString(value: unknown): string | undefined {
|
|
44
|
-
if (typeof value === "string") {
|
|
45
|
-
const text = value.trim();
|
|
46
|
-
return text.length > 0 ? text : undefined;
|
|
47
|
-
}
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function getStringField(obj: UnknownRecord, names: string[]): string | undefined {
|
|
52
|
-
for (const name of names) {
|
|
53
|
-
const found = asString(obj[name]);
|
|
54
|
-
if (found) return found;
|
|
55
|
-
}
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function getBooleanField(obj: UnknownRecord, names: string[]): boolean | undefined {
|
|
60
|
-
for (const name of names) {
|
|
61
|
-
if (typeof obj[name] === "boolean") return obj[name];
|
|
62
|
-
}
|
|
63
|
-
return undefined;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function messageText(content: unknown): string {
|
|
67
|
-
if (typeof content === "string") return content;
|
|
68
|
-
if (!Array.isArray(content)) return "";
|
|
69
|
-
|
|
70
|
-
const parts: string[] = [];
|
|
71
|
-
for (const block of content) {
|
|
72
|
-
if (typeof block === "string") {
|
|
73
|
-
parts.push(block);
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
if (block && typeof block === "object") {
|
|
77
|
-
const b = block as UnknownRecord;
|
|
78
|
-
if (typeof b.text === "string") parts.push(b.text);
|
|
79
|
-
else if (typeof b.content === "string") parts.push(b.content);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return parts.join("\n");
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function extractMessage(line: ParsedJsonlLine): { role: string; content: unknown } | null {
|
|
86
|
-
if (line.message?.role && line.message.content !== undefined) {
|
|
87
|
-
return { role: line.message.role, content: line.message.content };
|
|
88
|
-
}
|
|
89
|
-
if (line.role && line.content !== undefined) {
|
|
90
|
-
return { role: line.role, content: line.content };
|
|
91
|
-
}
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function pickActiveLeafHint(obj: UnknownRecord): string | undefined {
|
|
96
|
-
const explicitByName = getStringField(obj, [
|
|
97
|
-
"activeSessionId",
|
|
98
|
-
"active_session_id",
|
|
99
|
-
"activeSession",
|
|
100
|
-
"active_session",
|
|
101
|
-
"activeLeafId",
|
|
102
|
-
"active_leaf_id",
|
|
103
|
-
"activeLeafSessionId",
|
|
104
|
-
"active_leaf_session_id",
|
|
105
|
-
"currentSessionId",
|
|
106
|
-
"current_session_id",
|
|
107
|
-
"leafSessionId",
|
|
108
|
-
"leaf_session_id",
|
|
109
|
-
]);
|
|
110
|
-
if (explicitByName) return explicitByName;
|
|
111
|
-
|
|
112
|
-
if (getBooleanField(obj, ["active", "is_active", "isActive", "activeLeaf"])
|
|
113
|
-
&& typeof obj.id === "string") {
|
|
114
|
-
return obj.id;
|
|
115
|
-
}
|
|
116
|
-
return undefined;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function parseSessionIdFromPath(filePath: string | undefined): string | undefined {
|
|
120
|
-
const normalized = asString(filePath);
|
|
121
|
-
if (!normalized) return undefined;
|
|
122
|
-
const base = path.basename(normalized, path.extname(normalized));
|
|
123
|
-
const underscore = base.lastIndexOf("_");
|
|
124
|
-
if (underscore >= 0 && underscore < base.length - 1) {
|
|
125
|
-
return base.slice(underscore + 1);
|
|
126
|
-
}
|
|
127
|
-
return base || undefined;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function parseJsonlSession(raw: string, filePath: string): ParsedSession | null {
|
|
131
|
-
const lines = raw.split("\n").filter((line) => line.trim());
|
|
132
|
-
if (lines.length === 0) return null;
|
|
133
|
-
|
|
134
|
-
const parsedLines: ParsedJsonlLine[] = [];
|
|
135
|
-
const nodes = new Map<string, JsonlNodeInfo>();
|
|
136
|
-
|
|
137
|
-
let headerSessionId: string | undefined;
|
|
138
|
-
let headerTitle = "";
|
|
139
|
-
let headerCreatedAt = "";
|
|
140
|
-
let lastNodeId: string | undefined;
|
|
141
|
-
let explicitLeafHint: string | undefined;
|
|
142
|
-
let fallbackParentSessionId: string | undefined;
|
|
143
|
-
let fallbackParentSessionFile: string | undefined;
|
|
144
|
-
|
|
145
|
-
for (const rawLine of lines) {
|
|
146
|
-
let obj: UnknownRecord;
|
|
147
|
-
try {
|
|
148
|
-
obj = JSON.parse(rawLine) as UnknownRecord;
|
|
149
|
-
} catch {
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const id = getStringField(obj, ["id", "entryId", "entry_id"]);
|
|
154
|
-
const parentId = getStringField(obj, ["parentId", "parent_id"]);
|
|
155
|
-
const parentSessionId = getStringField(obj, [
|
|
156
|
-
"parentSessionId",
|
|
157
|
-
"parent_session_id",
|
|
158
|
-
]);
|
|
159
|
-
const parentSessionFile = getStringField(obj, [
|
|
160
|
-
"parentSessionFile",
|
|
161
|
-
"parent_session_file",
|
|
162
|
-
"parentSessionPath",
|
|
163
|
-
"parent_session_path",
|
|
164
|
-
"parentSession",
|
|
165
|
-
"parent_session",
|
|
166
|
-
]);
|
|
167
|
-
const type = asString(obj.type);
|
|
168
|
-
const message: ParsedJsonlLine["message"] = obj.message as ParsedJsonlLine["message"] | undefined;
|
|
169
|
-
|
|
170
|
-
const line: ParsedJsonlLine = {
|
|
171
|
-
id,
|
|
172
|
-
parentId,
|
|
173
|
-
parentSessionId,
|
|
174
|
-
parentSessionFile,
|
|
175
|
-
message,
|
|
176
|
-
role: asString(obj.role),
|
|
177
|
-
content: obj.content,
|
|
178
|
-
timestamp: asString(obj.timestamp),
|
|
179
|
-
createdAt: asString(obj.createdAt),
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
const explicitLeafId = pickActiveLeafHint(obj);
|
|
183
|
-
if (explicitLeafId) explicitLeafHint = explicitLeafId;
|
|
184
|
-
|
|
185
|
-
if (type === "session") {
|
|
186
|
-
headerSessionId = asString(obj.id) ?? headerSessionId;
|
|
187
|
-
headerTitle = asString(obj.title) ?? headerTitle;
|
|
188
|
-
headerCreatedAt = asString(obj.timestamp) ?? asString(obj.created_at) ?? asString(obj.createdAt) ?? headerCreatedAt;
|
|
189
|
-
if (!fallbackParentSessionId) {
|
|
190
|
-
fallbackParentSessionId = getStringField(obj, ["parentSessionId", "parent_session_id"]);
|
|
191
|
-
}
|
|
192
|
-
if (!fallbackParentSessionFile) {
|
|
193
|
-
fallbackParentSessionFile = getStringField(obj, [
|
|
194
|
-
"parentSessionFile",
|
|
195
|
-
"parent_session_file",
|
|
196
|
-
"parentSessionPath",
|
|
197
|
-
"parent_session_path",
|
|
198
|
-
"parentSession",
|
|
199
|
-
"parent_session",
|
|
200
|
-
]);
|
|
201
|
-
}
|
|
202
|
-
if (!fallbackParentSessionId && fallbackParentSessionFile) {
|
|
203
|
-
fallbackParentSessionId = parseSessionIdFromPath(fallbackParentSessionFile);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (id && type !== "session") {
|
|
208
|
-
nodes.set(id, {
|
|
209
|
-
parentId,
|
|
210
|
-
parentSessionId,
|
|
211
|
-
parentSessionFile,
|
|
212
|
-
});
|
|
213
|
-
lastNodeId = id;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
parsedLines.push(line);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (parsedLines.length === 0) return null;
|
|
220
|
-
|
|
221
|
-
const hasBranchNodes = nodes.size > 0;
|
|
222
|
-
let activeLeafId = explicitLeafHint ?? lastNodeId;
|
|
223
|
-
if (activeLeafId && explicitLeafHint && explicitLeafHint !== lastNodeId && !nodes.has(activeLeafId)) {
|
|
224
|
-
activeLeafId = lastNodeId;
|
|
225
|
-
}
|
|
226
|
-
const activeSessionId = activeLeafId ?? headerSessionId ?? path.basename(filePath, path.extname(filePath));
|
|
227
|
-
let parentSessionId: string | undefined = fallbackParentSessionId;
|
|
228
|
-
let parentSessionFile: string | undefined = fallbackParentSessionFile;
|
|
229
|
-
|
|
230
|
-
const activeNodeIds = new Set<string>();
|
|
231
|
-
if (hasBranchNodes && activeLeafId) {
|
|
232
|
-
let cursor: string | undefined = activeLeafId;
|
|
233
|
-
const leafNode = nodes.get(activeLeafId);
|
|
234
|
-
if (leafNode) {
|
|
235
|
-
if (leafNode.parentSessionId) {
|
|
236
|
-
parentSessionId = leafNode.parentSessionId;
|
|
237
|
-
}
|
|
238
|
-
if (leafNode.parentSessionFile) {
|
|
239
|
-
parentSessionFile = leafNode.parentSessionFile;
|
|
240
|
-
}
|
|
241
|
-
if (!parentSessionId && parentSessionFile) {
|
|
242
|
-
parentSessionId = parseSessionIdFromPath(parentSessionFile);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
for (let i = 0; i < nodes.size + 5; i++) {
|
|
246
|
-
if (!cursor || activeNodeIds.has(cursor)) break;
|
|
247
|
-
activeNodeIds.add(cursor);
|
|
248
|
-
const node = nodes.get(cursor);
|
|
249
|
-
if (!node) break;
|
|
250
|
-
if (!node.parentId) break;
|
|
251
|
-
cursor = node.parentId;
|
|
252
|
-
if (!nodes.has(cursor)) break;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const includeLine = (line: ParsedJsonlLine): boolean => {
|
|
257
|
-
if (!hasBranchNodes || !activeLeafId) return true;
|
|
258
|
-
if (!line.id && !line.parentId) return false;
|
|
259
|
-
if (line.id) return activeNodeIds.has(line.id);
|
|
260
|
-
if (line.parentId) return activeNodeIds.has(line.parentId);
|
|
261
|
-
return false;
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
const turns: ActiveBranchTurn[] = [];
|
|
265
|
-
let turnIndex = 0;
|
|
266
|
-
for (const line of parsedLines) {
|
|
267
|
-
if (!includeLine(line)) continue;
|
|
268
|
-
|
|
269
|
-
const messageObj = extractMessage(line);
|
|
270
|
-
if (!messageObj?.role || !messageObj.content) continue;
|
|
271
|
-
if (messageObj.role !== "user" && messageObj.role !== "assistant") continue;
|
|
272
|
-
const text = messageText(messageObj.content);
|
|
273
|
-
if (!text.trim()) continue;
|
|
274
|
-
|
|
275
|
-
turns.push({
|
|
276
|
-
role: messageObj.role,
|
|
277
|
-
content: text,
|
|
278
|
-
turnIndex: turnIndex++,
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if (turns.length === 0) return null;
|
|
283
|
-
|
|
284
|
-
return {
|
|
285
|
-
id: activeSessionId,
|
|
286
|
-
title: headerTitle,
|
|
287
|
-
createdAt: headerCreatedAt,
|
|
288
|
-
turns,
|
|
289
|
-
parentSessionId,
|
|
290
|
-
parentSessionFile,
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
export { messageText };
|
package/src/settings.ts
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
|
|
4
|
-
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
defaultMemoryConfig,
|
|
8
|
-
normalizeMemoryConfig,
|
|
9
|
-
type ExtractorType,
|
|
10
|
-
type ConsolidationConfig,
|
|
11
|
-
type MemoryConfig,
|
|
12
|
-
type MemoryProvider,
|
|
13
|
-
type TrainerConfig,
|
|
14
|
-
} from "./config.js";
|
|
15
|
-
import type { OllamaConfig } from "./adapters/ollamaClient.js";
|
|
16
|
-
import type { OpenAICompatConfig } from "./adapters/openaiCompatClient.js";
|
|
17
|
-
|
|
18
|
-
export interface MemorySettingsFile {
|
|
19
|
-
provider?: MemoryProvider;
|
|
20
|
-
tlmPath?: string;
|
|
21
|
-
socketPath?: string;
|
|
22
|
-
bundleRoot?: string;
|
|
23
|
-
sidecarReadyTimeoutMs?: number;
|
|
24
|
-
queryTimeoutMs?: number;
|
|
25
|
-
clientRequestTimeoutMs?: number;
|
|
26
|
-
sessionsDir?: string;
|
|
27
|
-
memoryMdPaths?: string[];
|
|
28
|
-
/** LLM for intent detection, rerank, and LLM extraction. Overrides default helper model. */
|
|
29
|
-
helperModel?: string;
|
|
30
|
-
/** Ollama local API config for helper / trainer / rerank. */
|
|
31
|
-
ollama?: Partial<OllamaConfig>;
|
|
32
|
-
/** OpenAI-compatible endpoint config (vLLM, SGLang, LM Studio, etc.) */
|
|
33
|
-
vllm?: Partial<OpenAICompatConfig>;
|
|
34
|
-
trainer?: Partial<TrainerConfig>;
|
|
35
|
-
consolidation?: Partial<ConsolidationConfig>;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface LoadedMemorySettings {
|
|
39
|
-
config: MemoryConfig;
|
|
40
|
-
helperModel: string | undefined;
|
|
41
|
-
ollama: OllamaConfig | null;
|
|
42
|
-
vllm: OpenAICompatConfig | null;
|
|
43
|
-
configPath: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Default path: ~/.pi/agent/memory.json */
|
|
47
|
-
export function defaultMemoryConfigPath(): string {
|
|
48
|
-
return path.join(getAgentDir(), "memory.json");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function readMemorySettingsFile(configPath = defaultMemoryConfigPath()): MemorySettingsFile {
|
|
52
|
-
try {
|
|
53
|
-
const raw = fs.readFileSync(configPath, "utf8");
|
|
54
|
-
const parsed = JSON.parse(raw) as unknown;
|
|
55
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
56
|
-
return {};
|
|
57
|
-
}
|
|
58
|
-
return parsed as MemorySettingsFile;
|
|
59
|
-
} catch (err) {
|
|
60
|
-
if ((err as NodeJS.ErrnoException).code === "ENOENT") {
|
|
61
|
-
return {};
|
|
62
|
-
}
|
|
63
|
-
throw new Error(
|
|
64
|
-
`Failed to load pi-memory config from ${configPath}: ${err instanceof Error ? err.message : String(err)}`,
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** Load pi-memory config from ~/.pi/agent/memory.json. */
|
|
70
|
-
export function loadMemorySettings(
|
|
71
|
-
overrides: Partial<MemoryConfig> = {},
|
|
72
|
-
configPath = defaultMemoryConfigPath(),
|
|
73
|
-
): LoadedMemorySettings {
|
|
74
|
-
const fileSettings = readMemorySettingsFile(configPath);
|
|
75
|
-
const {
|
|
76
|
-
helperModel,
|
|
77
|
-
ollama,
|
|
78
|
-
vllm,
|
|
79
|
-
trainer,
|
|
80
|
-
consolidation,
|
|
81
|
-
...configFields
|
|
82
|
-
} = fileSettings;
|
|
83
|
-
|
|
84
|
-
const config = normalizeMemoryConfig({
|
|
85
|
-
...configFields,
|
|
86
|
-
...(trainer ? { trainer } : {}),
|
|
87
|
-
...(consolidation ? { consolidation } : {}),
|
|
88
|
-
...overrides,
|
|
89
|
-
} as Partial<MemoryConfig> & Record<string, unknown>);
|
|
90
|
-
|
|
91
|
-
let resolvedOllama: OllamaConfig | null = null;
|
|
92
|
-
if (ollama && ollama.model) {
|
|
93
|
-
resolvedOllama = {
|
|
94
|
-
baseUrl: ollama.baseUrl?.trim() || "http://localhost:11434",
|
|
95
|
-
model: ollama.model.trim(),
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
let resolvedVllm: OpenAICompatConfig | null = null;
|
|
100
|
-
if (vllm && vllm.model) {
|
|
101
|
-
resolvedVllm = {
|
|
102
|
-
baseUrl: vllm.baseUrl?.trim() || "http://localhost:8000",
|
|
103
|
-
model: vllm.model.trim(),
|
|
104
|
-
apiKey: vllm.apiKey?.trim() || undefined,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return {
|
|
109
|
-
config,
|
|
110
|
-
helperModel: helperModel?.trim() || undefined,
|
|
111
|
-
ollama: resolvedOllama,
|
|
112
|
-
vllm: resolvedVllm,
|
|
113
|
-
configPath,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** Convenience alias when only MemoryConfig is needed. */
|
|
118
|
-
export function loadMemoryConfig(
|
|
119
|
-
overrides: Partial<MemoryConfig> = {},
|
|
120
|
-
configPath = defaultMemoryConfigPath(),
|
|
121
|
-
): MemoryConfig {
|
|
122
|
-
return loadMemorySettings(overrides, configPath).config;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export function resolveHelperModelSpec(
|
|
126
|
-
flagValue: string | boolean | undefined,
|
|
127
|
-
settingsHelperModel: string | undefined,
|
|
128
|
-
): string | undefined {
|
|
129
|
-
if (typeof flagValue === "string" && flagValue.trim()) {
|
|
130
|
-
return flagValue.trim();
|
|
131
|
-
}
|
|
132
|
-
return settingsHelperModel;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** Write memory settings back to disk (preserves unknown fields). */
|
|
136
|
-
export function saveMemorySettings(
|
|
137
|
-
updates: Partial<MemorySettingsFile>,
|
|
138
|
-
configPath = defaultMemoryConfigPath(),
|
|
139
|
-
): void {
|
|
140
|
-
let existing: Record<string, unknown> = {};
|
|
141
|
-
try {
|
|
142
|
-
const raw = fs.readFileSync(configPath, "utf8");
|
|
143
|
-
const parsed = JSON.parse(raw);
|
|
144
|
-
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
145
|
-
existing = parsed as Record<string, unknown>;
|
|
146
|
-
}
|
|
147
|
-
} catch { /* start fresh */ }
|
|
148
|
-
|
|
149
|
-
const merged = { ...existing, ...updates };
|
|
150
|
-
const dir = path.dirname(configPath);
|
|
151
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
152
|
-
fs.writeFileSync(configPath, JSON.stringify(merged, null, 2) + "\n", "utf8");
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export { defaultMemoryConfig };
|
|
156
|
-
export type {
|
|
157
|
-
ConsolidationConfig,
|
|
158
|
-
ExtractorType,
|
|
159
|
-
MemoryProvider,
|
|
160
|
-
TrainerConfig,
|
|
161
|
-
};
|
package/src/sidecar/bundle.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* True when `<bundleRoot>/current` resolves to a directory containing
|
|
6
|
-
* JSON-parseable manifest.json (Kocoro memory/service.go currentBundleReadable).
|
|
7
|
-
*/
|
|
8
|
-
export function currentBundleReadable(bundleRoot: string): boolean {
|
|
9
|
-
const currentPath = path.join(bundleRoot, "current");
|
|
10
|
-
let st: fs.Stats;
|
|
11
|
-
try {
|
|
12
|
-
st = fs.statSync(currentPath);
|
|
13
|
-
} catch {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
if (!st.isDirectory()) return false;
|
|
17
|
-
try {
|
|
18
|
-
const data = fs.readFileSync(path.join(currentPath, "manifest.json"), "utf8");
|
|
19
|
-
JSON.parse(data);
|
|
20
|
-
return true;
|
|
21
|
-
} catch {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface BundleManifestFile {
|
|
27
|
-
path: string;
|
|
28
|
-
size: number;
|
|
29
|
-
sha256: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface BundleManifest {
|
|
33
|
-
bundle_ts: string;
|
|
34
|
-
bundle_version: string;
|
|
35
|
-
size_bytes: number;
|
|
36
|
-
integrity_sha256: string;
|
|
37
|
-
files: BundleManifestFile[];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function readCurrentManifest(bundleRoot: string): BundleManifest | null {
|
|
41
|
-
if (!currentBundleReadable(bundleRoot)) return null;
|
|
42
|
-
const currentPath = path.join(bundleRoot, "current");
|
|
43
|
-
try {
|
|
44
|
-
const raw = fs.readFileSync(
|
|
45
|
-
path.join(currentPath, "manifest.json"),
|
|
46
|
-
"utf8",
|
|
47
|
-
);
|
|
48
|
-
return JSON.parse(raw) as BundleManifest;
|
|
49
|
-
} catch {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
}
|
package/src/sidecar/process.ts
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { access, constants } from "node:fs/promises";
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { spawn, type ChildProcess } from "node:child_process";
|
|
5
|
-
|
|
6
|
-
import type { MemoryConfig } from "../config.js";
|
|
7
|
-
import { SidecarClient } from "./client.js";
|
|
8
|
-
|
|
9
|
-
export class SidecarProcess {
|
|
10
|
-
private child: ChildProcess | null = null;
|
|
11
|
-
private readonly client: SidecarClient;
|
|
12
|
-
|
|
13
|
-
constructor(private readonly cfg: MemoryConfig) {
|
|
14
|
-
this.client = new SidecarClient(
|
|
15
|
-
cfg.socketPath,
|
|
16
|
-
Math.min(cfg.clientRequestTimeoutMs, 5_000),
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
getClient(): SidecarClient {
|
|
21
|
-
return this.client;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async resolveBinary(): Promise<string> {
|
|
25
|
-
const bin = this.cfg.tlmPath;
|
|
26
|
-
if (path.isAbsolute(bin)) {
|
|
27
|
-
await access(bin, constants.X_OK);
|
|
28
|
-
return bin;
|
|
29
|
-
}
|
|
30
|
-
const resolved = await which(bin);
|
|
31
|
-
if (!resolved) throw new Error(`${bin} not found in PATH`);
|
|
32
|
-
return resolved;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async spawn(): Promise<void> {
|
|
36
|
-
const bin = await this.resolveBinary().catch(() => {
|
|
37
|
-
throw new Error("memory: tlm binary not found");
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
if (this.cfg.socketPath) {
|
|
41
|
-
try {
|
|
42
|
-
fs.unlinkSync(this.cfg.socketPath);
|
|
43
|
-
} catch {
|
|
44
|
-
/* absent */
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const args = [
|
|
49
|
-
"serve",
|
|
50
|
-
"--socket",
|
|
51
|
-
this.cfg.socketPath,
|
|
52
|
-
"--bundle-root",
|
|
53
|
-
this.cfg.bundleRoot,
|
|
54
|
-
];
|
|
55
|
-
|
|
56
|
-
this.child = spawn(bin, args, {
|
|
57
|
-
stdio: "ignore",
|
|
58
|
-
detached: process.platform !== "win32",
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
this.child.on("error", () => {
|
|
62
|
-
/* handled by waitReady timeout */
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
this.child.unref?.();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async waitReady(signal?: AbortSignal): Promise<void> {
|
|
69
|
-
const deadline = Date.now() + this.cfg.sidecarReadyTimeoutMs;
|
|
70
|
-
let lastCompat = "";
|
|
71
|
-
let lastSub = "";
|
|
72
|
-
|
|
73
|
-
while (Date.now() < deadline) {
|
|
74
|
-
if (signal?.aborted) throw signal.reason ?? new Error("aborted");
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
const h = await this.client.health(signal);
|
|
78
|
-
lastCompat = h.compatibility ?? "";
|
|
79
|
-
lastSub = h.error ? String(h.error.details?.sub_code ?? "") : "";
|
|
80
|
-
|
|
81
|
-
if (h.ready === true) return;
|
|
82
|
-
if (h.compatibility === "unknown") return;
|
|
83
|
-
if (h.compatibility === "incompatible") {
|
|
84
|
-
// keep polling until ceiling — supervisor classifies schema mismatch
|
|
85
|
-
}
|
|
86
|
-
} catch {
|
|
87
|
-
/* sidecar still starting */
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
await sleep(500, signal);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
throw new Error(
|
|
94
|
-
`memory: sidecar ready ceiling exceeded` +
|
|
95
|
-
(lastCompat === "incompatible" && lastSub
|
|
96
|
-
? ` (incompatible: ${lastSub})`
|
|
97
|
-
: ""),
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async stop(): Promise<void> {
|
|
102
|
-
const child = this.child;
|
|
103
|
-
this.child = null;
|
|
104
|
-
if (!child?.pid) return;
|
|
105
|
-
|
|
106
|
-
if (process.platform === "win32") {
|
|
107
|
-
spawn("taskkill", ["/pid", String(child.pid), "/t", "/f"]);
|
|
108
|
-
} else {
|
|
109
|
-
try {
|
|
110
|
-
process.kill(-child.pid, "SIGTERM");
|
|
111
|
-
} catch {
|
|
112
|
-
try {
|
|
113
|
-
child.kill("SIGTERM");
|
|
114
|
-
} catch {
|
|
115
|
-
/* already dead */
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
await new Promise<void>((resolve) => {
|
|
121
|
-
const t = setTimeout(resolve, 2_000);
|
|
122
|
-
child.on("exit", () => {
|
|
123
|
-
clearTimeout(t);
|
|
124
|
-
resolve();
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
async function which(cmd: string): Promise<string | null> {
|
|
131
|
-
const { execFileSync } = await import("node:child_process");
|
|
132
|
-
try {
|
|
133
|
-
const result = execFileSync(
|
|
134
|
-
process.platform === "win32" ? "where" : "which",
|
|
135
|
-
[cmd],
|
|
136
|
-
{ encoding: "utf8", timeout: 3_000 },
|
|
137
|
-
).trim();
|
|
138
|
-
return result.split("\n")[0]?.trim() || null;
|
|
139
|
-
} catch {
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function sleep(ms: number, signal?: AbortSignal): Promise<void> {
|
|
145
|
-
return new Promise((resolve, reject) => {
|
|
146
|
-
if (signal?.aborted) {
|
|
147
|
-
reject(signal.reason ?? new Error("aborted"));
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
const t = setTimeout(resolve, ms);
|
|
151
|
-
signal?.addEventListener(
|
|
152
|
-
"abort",
|
|
153
|
-
() => {
|
|
154
|
-
clearTimeout(t);
|
|
155
|
-
reject(signal.reason ?? new Error("aborted"));
|
|
156
|
-
},
|
|
157
|
-
{ once: true },
|
|
158
|
-
);
|
|
159
|
-
});
|
|
160
|
-
}
|