@chendpoc/pi-memory 0.1.12 → 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 +67 -187
- 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 +2 -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 +2 -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 +68 -231
- 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/commands/types.js.map +1 -0
- 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 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -27
- 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 +194 -219
- 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 -19
- package/dist/preflight/render.d.ts.map +1 -1
- package/dist/preflight/render.js +29 -106
- 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 +40 -12
- 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 +82 -232
- 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 -241
- package/src/init/workspace.ts +44 -0
- package/src/ipc/jsonlFramer.ts +29 -0
- package/src/pi-extension.ts +186 -316
- 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 -173
- 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/config.d.ts +0 -27
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -49
- package/dist/config.js.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 -60
- 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 -287
- 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 -21
- package/dist/local/graphQuery.d.ts.map +0 -1
- package/dist/local/graphQuery.js +0 -170
- 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 -624
- package/dist/preflight/detectIntents.js.map +0 -1
- package/dist/preflight/hook.d.ts +0 -58
- package/dist/preflight/hook.d.ts.map +0 -1
- package/dist/preflight/hook.js +0 -77
- package/dist/preflight/hook.js.map +0 -1
- package/dist/service.d.ts +0 -56
- package/dist/service.d.ts.map +0 -1
- package/dist/service.js +0 -200
- package/dist/service.js.map +0 -1
- package/dist/settings.d.ts +0 -38
- package/dist/settings.d.ts.map +0 -1
- package/dist/settings.js +0 -68
- 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 -37
- package/dist/tools/memoryAppend.d.ts.map +0 -1
- package/dist/tools/memoryAppend.js +0 -99
- 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 -325
- 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 -31
- package/dist/trainer/scheduler.d.ts.map +0 -1
- package/dist/trainer/scheduler.js +0 -72
- package/dist/trainer/scheduler.js.map +0 -1
- package/dist/trainer/sessionLoader.d.ts +0 -23
- package/dist/trainer/sessionLoader.d.ts.map +0 -1
- package/dist/trainer/sessionLoader.js +0 -182
- 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 -92
- 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 -327
- 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 -199
- package/src/service.ts +0 -306
- package/src/settings.ts +0 -126
- package/src/sidecar/bundle.ts +0 -52
- package/src/sidecar/process.ts +0 -160
- package/src/tools/memoryAppend.ts +0 -113
- 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 -225
- package/src/types.ts +0 -168
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import fsSync from "node:fs";
|
|
2
|
-
import fs from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { openSessionIndex, type SessionIndex } from "./sessionIndex.js";
|
|
5
|
-
|
|
6
|
-
/** Mirrors Kocoro session.SearchResult for fallback hits. */
|
|
7
|
-
export interface SessionSearchHit {
|
|
8
|
-
session_id: string;
|
|
9
|
-
session_title: string;
|
|
10
|
-
role: string;
|
|
11
|
-
snippet: string;
|
|
12
|
-
msg_index: number;
|
|
13
|
-
created_at: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
let cachedIndex: SessionIndex | null = null;
|
|
17
|
-
let cachedDbPath: string | null = null;
|
|
18
|
-
|
|
19
|
-
function getSessionIndex(dbPath: string): SessionIndex | null {
|
|
20
|
-
if (cachedIndex && cachedDbPath === dbPath) return cachedIndex;
|
|
21
|
-
if (!fsSync.existsSync(dbPath)) return null;
|
|
22
|
-
cachedIndex = openSessionIndex(dbPath);
|
|
23
|
-
cachedDbPath = dbPath;
|
|
24
|
-
return cachedIndex;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Default session DB path. */
|
|
28
|
-
export function defaultSessionDbPath(sessionsDir: string): string {
|
|
29
|
-
return path.join(path.dirname(sessionsDir), "memory", "sessions.db");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface PiSessionMessage {
|
|
33
|
-
role?: string;
|
|
34
|
-
content?: unknown;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface PiSessionFile {
|
|
38
|
-
id?: string;
|
|
39
|
-
title?: string;
|
|
40
|
-
created_at?: string;
|
|
41
|
-
messages?: PiSessionMessage[];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const SNIPPET_MAX = 240;
|
|
45
|
-
|
|
46
|
-
async function collectFiles(dir: string): Promise<string[]> {
|
|
47
|
-
let names: string[];
|
|
48
|
-
try {
|
|
49
|
-
names = await fs.readdir(dir);
|
|
50
|
-
} catch {
|
|
51
|
-
return [];
|
|
52
|
-
}
|
|
53
|
-
const files: string[] = [];
|
|
54
|
-
for (const name of names) {
|
|
55
|
-
const full = path.join(dir, name);
|
|
56
|
-
let st;
|
|
57
|
-
try { st = await fs.stat(full); } catch { continue; }
|
|
58
|
-
if (st.isDirectory()) {
|
|
59
|
-
files.push(...await collectFiles(full));
|
|
60
|
-
} else if (st.isFile() && (name.endsWith(".json") || name.endsWith(".jsonl"))) {
|
|
61
|
-
files.push(full);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return files;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Keyword search over Pi-style session files (JSON + JSONL, recursive subdirectories).
|
|
69
|
-
* Uses FTS5 index when available, falls back to file scan.
|
|
70
|
-
* All whitespace-separated terms must match (case-insensitive AND).
|
|
71
|
-
*/
|
|
72
|
-
export async function sessionKeywordSearch(
|
|
73
|
-
sessionsDir: string,
|
|
74
|
-
query: string,
|
|
75
|
-
limit: number,
|
|
76
|
-
): Promise<SessionSearchHit[]> {
|
|
77
|
-
if (!sessionsDir.trim()) return [];
|
|
78
|
-
const q = query.trim();
|
|
79
|
-
if (!q) return [];
|
|
80
|
-
if (limit <= 0) limit = 20;
|
|
81
|
-
|
|
82
|
-
const dbPath = defaultSessionDbPath(sessionsDir);
|
|
83
|
-
const idx = getSessionIndex(dbPath);
|
|
84
|
-
if (idx) {
|
|
85
|
-
const results = idx.search(q, limit);
|
|
86
|
-
if (results.length > 0) return results;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const terms = splitTerms(q);
|
|
90
|
-
if (terms.length === 0) return [];
|
|
91
|
-
|
|
92
|
-
const filePaths = await collectFiles(sessionsDir);
|
|
93
|
-
const hits: SessionSearchHit[] = [];
|
|
94
|
-
|
|
95
|
-
for (const filePath of filePaths) {
|
|
96
|
-
let st;
|
|
97
|
-
try {
|
|
98
|
-
st = await fs.stat(filePath);
|
|
99
|
-
} catch {
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
if (!st.isFile()) continue;
|
|
103
|
-
|
|
104
|
-
let raw: string;
|
|
105
|
-
try {
|
|
106
|
-
raw = await fs.readFile(filePath, "utf8");
|
|
107
|
-
} catch {
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (filePath.endsWith(".jsonl")) {
|
|
112
|
-
scanJsonlFile(raw, filePath, terms, hits, limit);
|
|
113
|
-
} else {
|
|
114
|
-
scanJsonFile(raw, filePath, terms, hits, limit);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (hits.length >= limit) return hits;
|
|
118
|
-
}
|
|
119
|
-
return hits;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function scanJsonFile(
|
|
123
|
-
raw: string,
|
|
124
|
-
filePath: string,
|
|
125
|
-
terms: string[],
|
|
126
|
-
hits: SessionSearchHit[],
|
|
127
|
-
limit: number,
|
|
128
|
-
): void {
|
|
129
|
-
let session: PiSessionFile;
|
|
130
|
-
try {
|
|
131
|
-
session = JSON.parse(raw) as PiSessionFile;
|
|
132
|
-
} catch {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const sessionId = session.id ?? path.basename(filePath, ".json");
|
|
137
|
-
const title = session.title ?? "";
|
|
138
|
-
const createdAt = session.created_at ?? "";
|
|
139
|
-
|
|
140
|
-
for (let i = 0; i < (session.messages?.length ?? 0); i++) {
|
|
141
|
-
const msg = session.messages![i]!;
|
|
142
|
-
const text = messageText(msg.content);
|
|
143
|
-
if (!text || !allTermsMatch(text, terms)) continue;
|
|
144
|
-
hits.push({
|
|
145
|
-
session_id: sessionId,
|
|
146
|
-
session_title: title,
|
|
147
|
-
role: msg.role ?? "unknown",
|
|
148
|
-
snippet: makeSnippet(text, terms[0]!),
|
|
149
|
-
msg_index: i,
|
|
150
|
-
created_at: createdAt,
|
|
151
|
-
});
|
|
152
|
-
if (hits.length >= limit) return;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function scanJsonlFile(
|
|
157
|
-
raw: string,
|
|
158
|
-
filePath: string,
|
|
159
|
-
terms: string[],
|
|
160
|
-
hits: SessionSearchHit[],
|
|
161
|
-
limit: number,
|
|
162
|
-
): void {
|
|
163
|
-
const lines = raw.split("\n").filter((l) => l.trim());
|
|
164
|
-
let sessionId = path.basename(filePath, ".jsonl");
|
|
165
|
-
let title = "";
|
|
166
|
-
let createdAt = "";
|
|
167
|
-
let msgIndex = 0;
|
|
168
|
-
|
|
169
|
-
for (const line of lines) {
|
|
170
|
-
let obj: Record<string, unknown>;
|
|
171
|
-
try {
|
|
172
|
-
obj = JSON.parse(line) as Record<string, unknown>;
|
|
173
|
-
} catch {
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (obj.type === "session") {
|
|
178
|
-
sessionId = (obj.id as string) ?? sessionId;
|
|
179
|
-
title = (obj.title as string) ?? "";
|
|
180
|
-
createdAt = (obj.timestamp as string) ?? "";
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (obj.type === "message") {
|
|
185
|
-
const msg = (obj as { message?: PiSessionMessage }).message;
|
|
186
|
-
if (!msg?.role || !msg.content) continue;
|
|
187
|
-
if (msg.role !== "user" && msg.role !== "assistant") continue;
|
|
188
|
-
const text = messageText(msg.content);
|
|
189
|
-
if (!text || !allTermsMatch(text, terms)) continue;
|
|
190
|
-
hits.push({
|
|
191
|
-
session_id: sessionId,
|
|
192
|
-
session_title: title,
|
|
193
|
-
role: msg.role,
|
|
194
|
-
snippet: makeSnippet(text, terms[0]!),
|
|
195
|
-
msg_index: msgIndex,
|
|
196
|
-
created_at: createdAt,
|
|
197
|
-
});
|
|
198
|
-
msgIndex++;
|
|
199
|
-
if (hits.length >= limit) return;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function splitTerms(query: string): string[] {
|
|
205
|
-
const out: string[] = [];
|
|
206
|
-
let cur = "";
|
|
207
|
-
let inQuote = false;
|
|
208
|
-
for (const ch of query) {
|
|
209
|
-
if (ch === '"') {
|
|
210
|
-
inQuote = !inQuote;
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
if (!inQuote && /\s/.test(ch)) {
|
|
214
|
-
if (cur) {
|
|
215
|
-
out.push(cur.toLowerCase());
|
|
216
|
-
cur = "";
|
|
217
|
-
}
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
cur += ch;
|
|
221
|
-
}
|
|
222
|
-
if (cur) out.push(cur.toLowerCase());
|
|
223
|
-
return out;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function messageText(content: unknown): string {
|
|
227
|
-
if (typeof content === "string") return content;
|
|
228
|
-
if (!Array.isArray(content)) return "";
|
|
229
|
-
const parts: string[] = [];
|
|
230
|
-
for (const block of content) {
|
|
231
|
-
if (typeof block === "string") {
|
|
232
|
-
parts.push(block);
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
if (block && typeof block === "object") {
|
|
236
|
-
const b = block as Record<string, unknown>;
|
|
237
|
-
if (typeof b.text === "string") parts.push(b.text);
|
|
238
|
-
else if (typeof b.content === "string") parts.push(b.content);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
return parts.join("\n");
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function allTermsMatch(text: string, terms: string[]): boolean {
|
|
245
|
-
const lower = text.toLowerCase();
|
|
246
|
-
return terms.every((t) => lower.includes(t));
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
function makeSnippet(text: string, firstTerm: string): string {
|
|
250
|
-
const lower = text.toLowerCase();
|
|
251
|
-
const idx = lower.indexOf(firstTerm.toLowerCase());
|
|
252
|
-
if (idx < 0) {
|
|
253
|
-
return text.length <= SNIPPET_MAX ? text : text.slice(0, SNIPPET_MAX) + "...";
|
|
254
|
-
}
|
|
255
|
-
const start = Math.max(0, idx - 60);
|
|
256
|
-
const end = Math.min(text.length, idx + firstTerm.length + 120);
|
|
257
|
-
let snip = text.slice(start, end);
|
|
258
|
-
if (start > 0) snip = "..." + snip;
|
|
259
|
-
if (end < text.length) snip += "...";
|
|
260
|
-
return snip;
|
|
261
|
-
}
|
package/src/local/graphQuery.ts
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
ErrorClass,
|
|
6
|
-
MemoryBlock,
|
|
7
|
-
MemoryCandidateGroup,
|
|
8
|
-
QueryCandidate,
|
|
9
|
-
QueryIntent,
|
|
10
|
-
ResponseEnvelope,
|
|
11
|
-
} from "../types.js";
|
|
12
|
-
|
|
13
|
-
interface BundleEntity {
|
|
14
|
-
entity_id: string;
|
|
15
|
-
label: string;
|
|
16
|
-
type: string;
|
|
17
|
-
aliases: string[];
|
|
18
|
-
mention_count: number;
|
|
19
|
-
distinct_session_count: number;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface BundleEdge {
|
|
23
|
-
head_entity_id: string;
|
|
24
|
-
relation: string;
|
|
25
|
-
tail_entity_id: string;
|
|
26
|
-
supporting_event_ids: string[];
|
|
27
|
-
evidence: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface BundleEvent {
|
|
31
|
-
event_id: string;
|
|
32
|
-
description: string;
|
|
33
|
-
session_id: string;
|
|
34
|
-
timestamp: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface GraphData {
|
|
38
|
-
entities: BundleEntity[];
|
|
39
|
-
edges: BundleEdge[];
|
|
40
|
-
events: BundleEvent[];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export class LocalGraphQuerier {
|
|
44
|
-
private entities: BundleEntity[] = [];
|
|
45
|
-
private edges: BundleEdge[] = [];
|
|
46
|
-
private events: BundleEvent[] = [];
|
|
47
|
-
private entityById = new Map<string, BundleEntity>();
|
|
48
|
-
private entityByLabel = new Map<string, BundleEntity>();
|
|
49
|
-
private loaded = false;
|
|
50
|
-
private graphMtime = 0;
|
|
51
|
-
|
|
52
|
-
constructor(private readonly bundleRoot: string) {}
|
|
53
|
-
|
|
54
|
-
load(): boolean {
|
|
55
|
-
const graphPath = path.join(this.bundleRoot, "current", "graph.json");
|
|
56
|
-
try {
|
|
57
|
-
const raw = fs.readFileSync(graphPath, "utf8");
|
|
58
|
-
const data = JSON.parse(raw) as GraphData;
|
|
59
|
-
this.entities = data.entities ?? [];
|
|
60
|
-
this.edges = data.edges ?? [];
|
|
61
|
-
this.events = data.events ?? [];
|
|
62
|
-
|
|
63
|
-
this.entityById.clear();
|
|
64
|
-
this.entityByLabel.clear();
|
|
65
|
-
for (const e of this.entities) {
|
|
66
|
-
this.entityById.set(e.entity_id, e);
|
|
67
|
-
this.entityByLabel.set(e.label.toLowerCase(), e);
|
|
68
|
-
for (const alias of e.aliases) {
|
|
69
|
-
this.entityByLabel.set(alias.toLowerCase(), e);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
this.graphMtime = fs.statSync(graphPath).mtimeMs;
|
|
73
|
-
this.loaded = true;
|
|
74
|
-
return true;
|
|
75
|
-
} catch {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
isLoaded(): boolean {
|
|
81
|
-
return this.loaded;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Returns true when the on-disk graph.json has changed since the last load().
|
|
86
|
-
* Always returns false when not yet loaded.
|
|
87
|
-
*/
|
|
88
|
-
isStale(): boolean {
|
|
89
|
-
if (!this.loaded) return false;
|
|
90
|
-
const graphPath = path.join(this.bundleRoot, "current", "graph.json");
|
|
91
|
-
try {
|
|
92
|
-
return fs.statSync(graphPath).mtimeMs !== this.graphMtime;
|
|
93
|
-
} catch {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Re-loads from disk if isStale(). Returns true when a reload actually happened.
|
|
100
|
-
*/
|
|
101
|
-
reloadIfStale(): boolean {
|
|
102
|
-
if (!this.isStale()) return false;
|
|
103
|
-
return this.load();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
private findEntity(mention: string): BundleEntity | null {
|
|
107
|
-
const key = mention.toLowerCase().trim();
|
|
108
|
-
return this.entityByLabel.get(key) ?? null;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private findEntities(mentions: string[]): BundleEntity[] {
|
|
112
|
-
const found: BundleEntity[] = [];
|
|
113
|
-
for (const m of mentions) {
|
|
114
|
-
const e = this.findEntity(m);
|
|
115
|
-
if (e) found.push(e);
|
|
116
|
-
}
|
|
117
|
-
return found;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
query(intent: QueryIntent): {
|
|
121
|
-
env: ResponseEnvelope | null;
|
|
122
|
-
errorClass: ErrorClass;
|
|
123
|
-
} {
|
|
124
|
-
if (!this.loaded) {
|
|
125
|
-
return { env: null, errorClass: "unavailable" };
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const anchors = this.findEntities(intent.anchor_mentions);
|
|
129
|
-
if (anchors.length === 0) {
|
|
130
|
-
return {
|
|
131
|
-
env: this.makeEnvelope(intent, [], [], "no matching entities found"),
|
|
132
|
-
errorClass: "ok",
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const limit = intent.result_limit && intent.result_limit > 0 ? intent.result_limit : 10;
|
|
137
|
-
const candidates: QueryCandidate[] = [];
|
|
138
|
-
const groups: MemoryCandidateGroup[] = [];
|
|
139
|
-
|
|
140
|
-
for (const anchor of anchors) {
|
|
141
|
-
const relatedEdges = this.edges.filter((e) => {
|
|
142
|
-
const matchesHead = e.head_entity_id === anchor.entity_id;
|
|
143
|
-
const matchesTail = e.tail_entity_id === anchor.entity_id;
|
|
144
|
-
if (!matchesHead && !matchesTail) return false;
|
|
145
|
-
|
|
146
|
-
if (intent.relation_constraints?.length) {
|
|
147
|
-
return intent.relation_constraints.some((rc) => {
|
|
148
|
-
const clean = rc.replace(/\^-1$/, "").replace(/^\^/, "");
|
|
149
|
-
return e.relation === clean;
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
return true;
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
for (const edge of relatedEdges) {
|
|
156
|
-
if (candidates.length >= limit) break;
|
|
157
|
-
const isHead = edge.head_entity_id === anchor.entity_id;
|
|
158
|
-
const otherId = isHead ? edge.tail_entity_id : edge.head_entity_id;
|
|
159
|
-
const other = this.entityById.get(otherId);
|
|
160
|
-
if (!other) continue;
|
|
161
|
-
|
|
162
|
-
if (intent.candidate_type) {
|
|
163
|
-
if (other.type.toLowerCase() !== intent.candidate_type.toLowerCase()) continue;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const score = other.mention_count + (other.distinct_session_count * 2);
|
|
167
|
-
|
|
168
|
-
candidates.push({
|
|
169
|
-
value: other.label,
|
|
170
|
-
score,
|
|
171
|
-
evidence: edge.evidence.slice(0, 200),
|
|
172
|
-
supporting_event_ids: edge.supporting_event_ids,
|
|
173
|
-
entity_id: other.entity_id,
|
|
174
|
-
scope: `via_${anchor.label}`,
|
|
175
|
-
support_count: other.mention_count,
|
|
176
|
-
distinct_session_count: other.distinct_session_count,
|
|
177
|
-
observed_path: [{
|
|
178
|
-
from_entity_id: anchor.entity_id,
|
|
179
|
-
from_label: anchor.label,
|
|
180
|
-
relation: edge.relation,
|
|
181
|
-
direction: isHead ? "forward" : "inverse",
|
|
182
|
-
to_entity_id: other.entity_id,
|
|
183
|
-
to_label: other.label,
|
|
184
|
-
supporting_event_ids: edge.supporting_event_ids,
|
|
185
|
-
}],
|
|
186
|
-
path_collision_count: 0,
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
groups.push({
|
|
190
|
-
value: other.label,
|
|
191
|
-
score,
|
|
192
|
-
evidence: edge.evidence.slice(0, 200),
|
|
193
|
-
support_count: other.mention_count,
|
|
194
|
-
supporting_event_ids: edge.supporting_event_ids,
|
|
195
|
-
entity_ids: [other.entity_id],
|
|
196
|
-
scopes: [`via_${anchor.label}`],
|
|
197
|
-
via_relations: [edge.relation],
|
|
198
|
-
via_anchor_entity_ids: [anchor.entity_id],
|
|
199
|
-
observed_path: [{
|
|
200
|
-
from_entity_id: anchor.entity_id,
|
|
201
|
-
from_label: anchor.label,
|
|
202
|
-
relation: edge.relation,
|
|
203
|
-
direction: isHead ? "forward" : "inverse",
|
|
204
|
-
to_entity_id: other.entity_id,
|
|
205
|
-
to_label: other.label,
|
|
206
|
-
supporting_event_ids: edge.supporting_event_ids,
|
|
207
|
-
}],
|
|
208
|
-
path_collision_count: 0,
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
candidates.sort((a, b) => b.score - a.score);
|
|
214
|
-
groups.sort((a, b) => b.score - a.score);
|
|
215
|
-
|
|
216
|
-
return {
|
|
217
|
-
env: this.makeEnvelope(intent, candidates.slice(0, limit), groups.slice(0, limit)),
|
|
218
|
-
errorClass: "ok",
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
private makeEnvelope(
|
|
223
|
-
intent: QueryIntent,
|
|
224
|
-
candidates: QueryCandidate[],
|
|
225
|
-
groups: MemoryCandidateGroup[],
|
|
226
|
-
noDataReason?: string,
|
|
227
|
-
): ResponseEnvelope {
|
|
228
|
-
const manifestPath = path.join(this.bundleRoot, "current", "manifest.json");
|
|
229
|
-
let bundleVersion: string | undefined;
|
|
230
|
-
try {
|
|
231
|
-
const m = JSON.parse(fs.readFileSync(manifestPath, "utf8")) as { bundle_version?: string };
|
|
232
|
-
bundleVersion = m.bundle_version;
|
|
233
|
-
} catch { /* ok */ }
|
|
234
|
-
|
|
235
|
-
const memoryBlock: MemoryBlock = {
|
|
236
|
-
groups,
|
|
237
|
-
notes: [],
|
|
238
|
-
...(noDataReason ? { no_data_reason: noDataReason } : {}),
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
return {
|
|
242
|
-
protocol_version: 1,
|
|
243
|
-
bundle_version: bundleVersion,
|
|
244
|
-
request_id: `local-${Date.now()}`,
|
|
245
|
-
candidates,
|
|
246
|
-
memory_block: memoryBlock,
|
|
247
|
-
warnings: [],
|
|
248
|
-
reason: candidates.length > 0 ? "ok" : "no_data",
|
|
249
|
-
latency_ms: 0,
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
}
|
package/src/paths.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import os from "node:os";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
|
|
4
|
-
/** Expands a leading ~ to the user home directory. */
|
|
5
|
-
export function expandPath(p: string): string {
|
|
6
|
-
if (!p) return p;
|
|
7
|
-
if (p === "~") return os.homedir();
|
|
8
|
-
if (p.startsWith("~/") || p.startsWith("~\\")) {
|
|
9
|
-
return path.join(os.homedir(), p.slice(2));
|
|
10
|
-
}
|
|
11
|
-
return p;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function defaultPiHome(): string {
|
|
15
|
-
return path.join(os.homedir(), ".pi");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function defaultBundleRoot(): string {
|
|
19
|
-
return path.join(defaultPiHome(), "memory");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function defaultSocketPath(): string {
|
|
23
|
-
return path.join(defaultPiHome(), "memory.sock");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function defaultSessionsDir(): string {
|
|
27
|
-
return path.join(defaultPiHome(), "agent", "sessions");
|
|
28
|
-
}
|