pi-obsidian-memory 0.0.1 → 0.1.1
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 +237 -7
- package/package.json +41 -11
- package/skills/obsidian-memory/SKILL.md +101 -0
- package/src/domain/capture/constants.ts +5 -0
- package/src/domain/capture/index.ts +6 -0
- package/src/domain/capture/input-problems.ts +9 -0
- package/src/domain/capture/schemas.ts +92 -0
- package/src/domain/capture/tally.ts +26 -0
- package/src/domain/capture/types.ts +49 -0
- package/src/domain/capture/validate.ts +75 -0
- package/src/domain/command-flags/constants.ts +141 -0
- package/src/domain/command-flags/index.ts +1 -0
- package/src/domain/config/change.ts +105 -0
- package/src/domain/config/constants.ts +25 -0
- package/src/domain/config/diagnostics.ts +35 -0
- package/src/domain/config/disclosures.ts +8 -0
- package/src/domain/config/fields.ts +7 -0
- package/src/domain/config/index.ts +11 -0
- package/src/domain/config/inspection.ts +43 -0
- package/src/domain/config/invariants.ts +68 -0
- package/src/domain/config/legacy-capture.ts +17 -0
- package/src/domain/config/observations.ts +109 -0
- package/src/domain/config/parse.ts +25 -0
- package/src/domain/config/paths.ts +61 -0
- package/src/domain/config/registration.ts +34 -0
- package/src/domain/config/repair.ts +36 -0
- package/src/domain/config/resources.ts +65 -0
- package/src/domain/config/rules.ts +49 -0
- package/src/domain/config/schemas.ts +155 -0
- package/src/domain/config/settings.ts +23 -0
- package/src/domain/config/types.ts +239 -0
- package/src/domain/decision-model/constants.ts +7 -0
- package/src/domain/decision-model/cutoffs.ts +8 -0
- package/src/domain/decision-model/endpoint.ts +11 -0
- package/src/domain/decision-model/failure-detail.ts +8 -0
- package/src/domain/decision-model/index.ts +6 -0
- package/src/domain/decision-model/rank.ts +36 -0
- package/src/domain/decision-model/types.ts +77 -0
- package/src/domain/embeddings/constants.ts +55 -0
- package/src/domain/embeddings/identity.ts +30 -0
- package/src/domain/embeddings/index.ts +5 -0
- package/src/domain/embeddings/schemas.ts +25 -0
- package/src/domain/embeddings/types.ts +52 -0
- package/src/domain/embeddings/vectors.ts +53 -0
- package/src/domain/folder-index/constants.ts +9 -0
- package/src/domain/folder-index/display.ts +22 -0
- package/src/domain/folder-index/index.ts +5 -0
- package/src/domain/folder-index/listing.ts +58 -0
- package/src/domain/folder-index/render.ts +114 -0
- package/src/domain/folder-index/types.ts +41 -0
- package/src/domain/index.ts +22 -0
- package/src/domain/lifecycle/index.ts +2 -0
- package/src/domain/lifecycle/lifecycle.ts +39 -0
- package/src/domain/lifecycle/types.ts +17 -0
- package/src/domain/loaded-memory/budget.ts +14 -0
- package/src/domain/loaded-memory/constants.ts +9 -0
- package/src/domain/loaded-memory/index.ts +4 -0
- package/src/domain/loaded-memory/render.ts +30 -0
- package/src/domain/loaded-memory/types.ts +19 -0
- package/src/domain/memory/draft.ts +12 -0
- package/src/domain/memory/index.ts +4 -0
- package/src/domain/memory/schemas.ts +15 -0
- package/src/domain/memory/target.ts +27 -0
- package/src/domain/memory/types.ts +20 -0
- package/src/domain/memory-agent/index.ts +5 -0
- package/src/domain/memory-agent/input-problems.ts +9 -0
- package/src/domain/memory-agent/refusal.ts +6 -0
- package/src/domain/memory-agent/schemas.ts +112 -0
- package/src/domain/memory-agent/types.ts +25 -0
- package/src/domain/memory-agent/validate.ts +67 -0
- package/src/domain/names/constants.ts +32 -0
- package/src/domain/names/index.ts +2 -0
- package/src/domain/names/names.ts +83 -0
- package/src/domain/note/check.ts +68 -0
- package/src/domain/note/constants.ts +15 -0
- package/src/domain/note/frontmatter-fields.ts +175 -0
- package/src/domain/note/frontmatter.ts +138 -0
- package/src/domain/note/index.ts +9 -0
- package/src/domain/note/parse.ts +41 -0
- package/src/domain/note/render.ts +27 -0
- package/src/domain/note/schema-errors.ts +41 -0
- package/src/domain/note/schemas.ts +38 -0
- package/src/domain/note/types.ts +53 -0
- package/src/domain/note/validate.ts +19 -0
- package/src/domain/path-platform/index.ts +2 -0
- package/src/domain/path-platform/path-module.ts +11 -0
- package/src/domain/path-platform/types.ts +1 -0
- package/src/domain/search-catalog/constants.ts +1 -0
- package/src/domain/search-catalog/coverage.ts +35 -0
- package/src/domain/search-catalog/dont-forget.ts +10 -0
- package/src/domain/search-catalog/fingerprint.ts +9 -0
- package/src/domain/search-catalog/index.ts +10 -0
- package/src/domain/search-catalog/inspection.ts +47 -0
- package/src/domain/search-catalog/plan.ts +68 -0
- package/src/domain/search-catalog/ranking.ts +27 -0
- package/src/domain/search-catalog/schemas.ts +49 -0
- package/src/domain/search-catalog/types.ts +103 -0
- package/src/domain/search-catalog/vector-refresh.ts +22 -0
- package/src/domain/shell-edit/command-segments.ts +28 -0
- package/src/domain/shell-edit/command-words.ts +22 -0
- package/src/domain/shell-edit/constants.ts +125 -0
- package/src/domain/shell-edit/executed-files.ts +154 -0
- package/src/domain/shell-edit/index.ts +6 -0
- package/src/domain/shell-edit/powershell-files.ts +38 -0
- package/src/domain/shell-edit/rules.ts +19 -0
- package/src/domain/shell-edit/types.ts +75 -0
- package/src/domain/tool-flags/constants.ts +178 -0
- package/src/domain/tool-flags/index.ts +2 -0
- package/src/domain/tool-flags/types.ts +7 -0
- package/src/domain/validation/constants.ts +1 -0
- package/src/domain/validation/describe.ts +137 -0
- package/src/domain/validation/index.ts +3 -0
- package/src/domain/validation/types.ts +3 -0
- package/src/domain/vault-access/absolute-candidate.ts +81 -0
- package/src/domain/vault-access/argument-tokens.ts +22 -0
- package/src/domain/vault-access/command-mentions-vault.ts +115 -0
- package/src/domain/vault-access/constants.ts +54 -0
- package/src/domain/vault-access/index.ts +7 -0
- package/src/domain/vault-access/types.ts +18 -0
- package/src/domain/vault-access/vault-access-refusal.ts +36 -0
- package/src/domain/vault-access/vault-location.ts +22 -0
- package/src/domain/vault-assets/index.ts +2 -0
- package/src/domain/vault-assets/render.ts +51 -0
- package/src/domain/vault-assets/types.ts +36 -0
- package/src/domain/vault-catalog/analyze.ts +37 -0
- package/src/domain/vault-catalog/classify.ts +37 -0
- package/src/domain/vault-catalog/dont-forget.ts +6 -0
- package/src/domain/vault-catalog/export-entries.ts +10 -0
- package/src/domain/vault-catalog/index.ts +5 -0
- package/src/domain/vault-catalog/types.ts +114 -0
- package/src/domain/vault-diagnosis/diagnose.ts +79 -0
- package/src/domain/vault-diagnosis/index.ts +2 -0
- package/src/domain/vault-diagnosis/types.ts +31 -0
- package/src/domain/vault-path/constants.ts +13 -0
- package/src/domain/vault-path/index.ts +2 -0
- package/src/domain/vault-path/vault-path.ts +65 -0
- package/src/pi/capture/cadence.ts +49 -0
- package/src/pi/capture/completion.ts +26 -0
- package/src/pi/capture/constants.ts +5 -0
- package/src/pi/capture/handlers.ts +30 -0
- package/src/pi/capture/index.ts +8 -0
- package/src/pi/capture/runtime.ts +83 -0
- package/src/pi/capture/schemas.ts +8 -0
- package/src/pi/capture/tool-calls.ts +6 -0
- package/src/pi/capture/transcript.ts +55 -0
- package/src/pi/capture/types.ts +46 -0
- package/src/pi/change-report/constants.ts +15 -0
- package/src/pi/change-report/index.ts +3 -0
- package/src/pi/change-report/report.ts +54 -0
- package/src/pi/change-report/types.ts +8 -0
- package/src/pi/context/constants.ts +5 -0
- package/src/pi/context/index.ts +3 -0
- package/src/pi/context/status.ts +15 -0
- package/src/pi/context/types.ts +98 -0
- package/src/pi/extension.ts +100 -0
- package/src/pi/index.ts +26 -0
- package/src/pi/memory-add/constants.ts +13 -0
- package/src/pi/memory-add/index.ts +5 -0
- package/src/pi/memory-add/memory-add.ts +31 -0
- package/src/pi/memory-add/respond.ts +55 -0
- package/src/pi/memory-add/schemas.ts +29 -0
- package/src/pi/memory-add/types.ts +15 -0
- package/src/pi/memory-archive/constants.ts +8 -0
- package/src/pi/memory-archive/index.ts +4 -0
- package/src/pi/memory-archive/memory-archive.ts +29 -0
- package/src/pi/memory-archive/schemas.ts +15 -0
- package/src/pi/memory-archive/types.ts +8 -0
- package/src/pi/memory-block/block.ts +75 -0
- package/src/pi/memory-block/constants.ts +24 -0
- package/src/pi/memory-block/index.ts +4 -0
- package/src/pi/memory-block/render.ts +54 -0
- package/src/pi/memory-block/types.ts +24 -0
- package/src/pi/memory-doctor/constants.ts +43 -0
- package/src/pi/memory-doctor/index.ts +4 -0
- package/src/pi/memory-doctor/memory-doctor.ts +135 -0
- package/src/pi/memory-doctor/report.ts +101 -0
- package/src/pi/memory-doctor/types.ts +13 -0
- package/src/pi/memory-export/constants.ts +15 -0
- package/src/pi/memory-export/index.ts +4 -0
- package/src/pi/memory-export/memory-export.ts +57 -0
- package/src/pi/memory-export/name.ts +9 -0
- package/src/pi/memory-export/types.ts +4 -0
- package/src/pi/memory-get/constants.ts +12 -0
- package/src/pi/memory-get/index.ts +5 -0
- package/src/pi/memory-get/memory-get.ts +23 -0
- package/src/pi/memory-get/respond.ts +38 -0
- package/src/pi/memory-get/schemas.ts +13 -0
- package/src/pi/memory-get/types.ts +10 -0
- package/src/pi/memory-init/constants.ts +17 -0
- package/src/pi/memory-init/index.ts +2 -0
- package/src/pi/memory-init/memory-init.ts +63 -0
- package/src/pi/memory-search/constants.ts +16 -0
- package/src/pi/memory-search/index.ts +5 -0
- package/src/pi/memory-search/memory-search.ts +22 -0
- package/src/pi/memory-search/respond.ts +62 -0
- package/src/pi/memory-search/schemas.ts +11 -0
- package/src/pi/memory-search/types.ts +10 -0
- package/src/pi/memory-session/constants.ts +7 -0
- package/src/pi/memory-session/index.ts +4 -0
- package/src/pi/memory-session/keeper.ts +101 -0
- package/src/pi/memory-session/respond.ts +6 -0
- package/src/pi/memory-session/types.ts +23 -0
- package/src/pi/memory-settings/constants.ts +69 -0
- package/src/pi/memory-settings/edits.ts +46 -0
- package/src/pi/memory-settings/index.ts +9 -0
- package/src/pi/memory-settings/lines.ts +119 -0
- package/src/pi/memory-settings/models.ts +81 -0
- package/src/pi/memory-settings/projects.ts +46 -0
- package/src/pi/memory-settings/providers.ts +77 -0
- package/src/pi/memory-settings/save.ts +16 -0
- package/src/pi/memory-settings/screen.ts +27 -0
- package/src/pi/memory-settings/types.ts +87 -0
- package/src/pi/memory-setup/constants.ts +33 -0
- package/src/pi/memory-setup/disclosure.ts +22 -0
- package/src/pi/memory-setup/index.ts +4 -0
- package/src/pi/memory-setup/memory-setup.ts +153 -0
- package/src/pi/memory-setup/types.ts +6 -0
- package/src/pi/memory-succeed/constants.ts +10 -0
- package/src/pi/memory-succeed/index.ts +4 -0
- package/src/pi/memory-succeed/memory-succeed.ts +34 -0
- package/src/pi/memory-succeed/schemas.ts +30 -0
- package/src/pi/memory-succeed/types.ts +8 -0
- package/src/pi/memory-update/constants.ts +8 -0
- package/src/pi/memory-update/index.ts +4 -0
- package/src/pi/memory-update/memory-update.ts +29 -0
- package/src/pi/memory-update/schemas.ts +24 -0
- package/src/pi/memory-update/types.ts +8 -0
- package/src/pi/paths/constants.ts +7 -0
- package/src/pi/paths/index.ts +2 -0
- package/src/pi/paths/paths.ts +15 -0
- package/src/pi/paths/platform.ts +7 -0
- package/src/pi/registrar.ts +25 -0
- package/src/pi/registration-report/constants.ts +13 -0
- package/src/pi/registration-report/index.ts +2 -0
- package/src/pi/registration-report/report.ts +26 -0
- package/src/pi/relevant-memory/constants.ts +3 -0
- package/src/pi/relevant-memory/index.ts +4 -0
- package/src/pi/relevant-memory/prompt.ts +23 -0
- package/src/pi/relevant-memory/runtime.ts +88 -0
- package/src/pi/relevant-memory/types.ts +14 -0
- package/src/pi/semantic/constants.ts +3 -0
- package/src/pi/semantic/index.ts +2 -0
- package/src/pi/semantic/runtime.ts +59 -0
- package/src/pi/session-start/constants.ts +7 -0
- package/src/pi/session-start/index.ts +3 -0
- package/src/pi/session-start/session-start.ts +48 -0
- package/src/pi/session-start/types.ts +5 -0
- package/src/pi/shell-edit-guard/guard.ts +41 -0
- package/src/pi/shell-edit-guard/index.ts +3 -0
- package/src/pi/shell-edit-guard/prompt.ts +30 -0
- package/src/pi/shell-edit-guard/types.ts +13 -0
- package/src/pi/types.ts +44 -0
- package/src/pi/vault-guard/constants.ts +1 -0
- package/src/pi/vault-guard/index.ts +4 -0
- package/src/pi/vault-guard/request.ts +39 -0
- package/src/pi/vault-guard/types.ts +5 -0
- package/src/pi/vault-guard/vault-guard.ts +21 -0
- package/src/services/capture-cadence/domain-rules.ts +8 -0
- package/src/services/capture-cadence/index.ts +1 -0
- package/src/services/clock/clock.ts +7 -0
- package/src/services/clock/index.ts +1 -0
- package/src/services/config/canonicalize.ts +163 -0
- package/src/services/config/constants.ts +1 -0
- package/src/services/config/fully-qualified-path.ts +14 -0
- package/src/services/config/index.ts +12 -0
- package/src/services/config/path-identity.ts +65 -0
- package/src/services/config/publication.ts +75 -0
- package/src/services/config/read.ts +47 -0
- package/src/services/config/registration.ts +26 -0
- package/src/services/config/resolve-input.ts +27 -0
- package/src/services/config/snapshot.ts +26 -0
- package/src/services/config/target.ts +2 -0
- package/src/services/config/types.ts +97 -0
- package/src/services/config/vault-access.ts +2 -0
- package/src/services/config/volume-namespace.ts +5 -0
- package/src/services/config/write.ts +63 -0
- package/src/services/decision-model/constants.ts +16 -0
- package/src/services/decision-model/decide.ts +42 -0
- package/src/services/decision-model/diagnostics.ts +6 -0
- package/src/services/decision-model/endpoint.ts +1 -0
- package/src/services/decision-model/failure-detail.ts +1 -0
- package/src/services/decision-model/index.ts +7 -0
- package/src/services/decision-model/interruption.ts +29 -0
- package/src/services/decision-model/jev.ts +61 -0
- package/src/services/decision-model/laya-batch.ts +64 -0
- package/src/services/decision-model/laya-http-failure.ts +41 -0
- package/src/services/decision-model/laya-response.ts +95 -0
- package/src/services/decision-model/laya.ts +35 -0
- package/src/services/decision-model/preflight.ts +24 -0
- package/src/services/decision-model/prompts.ts +36 -0
- package/src/services/decision-model/schemas.ts +43 -0
- package/src/services/decision-model/score-candidates.ts +41 -0
- package/src/services/decision-model/types.ts +182 -0
- package/src/services/embeddings/asset-download.ts +45 -0
- package/src/services/embeddings/asset-fetch.ts +39 -0
- package/src/services/embeddings/asset-inspection.ts +36 -0
- package/src/services/embeddings/batch.ts +32 -0
- package/src/services/embeddings/chunks.ts +80 -0
- package/src/services/embeddings/configuration.ts +8 -0
- package/src/services/embeddings/constants.ts +24 -0
- package/src/services/embeddings/errors.ts +11 -0
- package/src/services/embeddings/google.ts +90 -0
- package/src/services/embeddings/http.ts +64 -0
- package/src/services/embeddings/index.ts +17 -0
- package/src/services/embeddings/inference.ts +35 -0
- package/src/services/embeddings/local.ts +138 -0
- package/src/services/embeddings/model-asset.ts +68 -0
- package/src/services/embeddings/model-cache.ts +30 -0
- package/src/services/embeddings/openai.ts +64 -0
- package/src/services/embeddings/operation.ts +31 -0
- package/src/services/embeddings/responses.ts +41 -0
- package/src/services/embeddings/runtime.ts +13 -0
- package/src/services/embeddings/schemas.ts +53 -0
- package/src/services/embeddings/types.ts +116 -0
- package/src/services/id/id.ts +5 -0
- package/src/services/id/index.ts +1 -0
- package/src/services/index.ts +11 -0
- package/src/services/llm/capture.ts +19 -0
- package/src/services/llm/check-chat-models.ts +38 -0
- package/src/services/llm/complete.ts +57 -0
- package/src/services/llm/constants.ts +32 -0
- package/src/services/llm/domain-rules.ts +2 -0
- package/src/services/llm/index.ts +6 -0
- package/src/services/llm/lifetime.ts +16 -0
- package/src/services/llm/retrieve.ts +19 -0
- package/src/services/llm/schemas.ts +9 -0
- package/src/services/llm/types.ts +94 -0
- package/src/services/search-index/catalog-query.ts +34 -0
- package/src/services/search-index/catalog-statements.ts +33 -0
- package/src/services/search-index/catalog.ts +19 -0
- package/src/services/search-index/cleanup.ts +13 -0
- package/src/services/search-index/close.ts +5 -0
- package/src/services/search-index/constants.ts +102 -0
- package/src/services/search-index/dont-forget.ts +1 -0
- package/src/services/search-index/fingerprint.ts +17 -0
- package/src/services/search-index/folder-index-statements.ts +17 -0
- package/src/services/search-index/folder-index-storage.ts +54 -0
- package/src/services/search-index/folder-indexes.ts +13 -0
- package/src/services/search-index/index.ts +14 -0
- package/src/services/search-index/inspection.ts +1 -0
- package/src/services/search-index/inventory.ts +67 -0
- package/src/services/search-index/legacy.ts +64 -0
- package/src/services/search-index/location.ts +12 -0
- package/src/services/search-index/open.ts +46 -0
- package/src/services/search-index/query.ts +39 -0
- package/src/services/search-index/ranking.ts +12 -0
- package/src/services/search-index/reconcile.ts +93 -0
- package/src/services/search-index/recovery.ts +56 -0
- package/src/services/search-index/refusals.ts +21 -0
- package/src/services/search-index/schema.ts +42 -0
- package/src/services/search-index/schemas.ts +181 -0
- package/src/services/search-index/search.ts +5 -0
- package/src/services/search-index/statements.ts +18 -0
- package/src/services/search-index/storage.ts +207 -0
- package/src/services/search-index/types.ts +113 -0
- package/src/services/search-index/vector-statements.ts +18 -0
- package/src/services/search-index/vector-storage.ts +169 -0
- package/src/services/search-index/vectors.ts +18 -0
- package/src/services/search-index/write.ts +9 -0
- package/src/services/shell-edit/ask.ts +53 -0
- package/src/services/shell-edit/domain-rules.ts +2 -0
- package/src/services/shell-edit/index.ts +4 -0
- package/src/services/shell-edit/schemas.ts +23 -0
- package/src/services/shell-edit/types.ts +61 -0
- package/src/services/shell-scripts/constants.ts +1 -0
- package/src/services/shell-scripts/files.ts +16 -0
- package/src/services/shell-scripts/index.ts +5 -0
- package/src/services/shell-scripts/package-scripts.ts +74 -0
- package/src/services/shell-scripts/schemas.ts +3 -0
- package/src/services/shell-scripts/scripts.ts +27 -0
- package/src/services/shell-scripts/types.ts +11 -0
- package/src/services/vault/archive.ts +31 -0
- package/src/services/vault/bootstrap/ensure.ts +50 -0
- package/src/services/vault/bootstrap/index.ts +2 -0
- package/src/services/vault/bootstrap/paths.ts +57 -0
- package/src/services/vault/bootstrap/types.ts +17 -0
- package/src/services/vault/bootstrap/write.ts +47 -0
- package/src/services/vault/catalog/bytes.ts +51 -0
- package/src/services/vault/catalog/dont-forget.ts +1 -0
- package/src/services/vault/catalog/enumerate.ts +69 -0
- package/src/services/vault/catalog/export.ts +21 -0
- package/src/services/vault/catalog/failures.ts +16 -0
- package/src/services/vault/catalog/index.ts +10 -0
- package/src/services/vault/catalog/inspect.ts +41 -0
- package/src/services/vault/catalog/observe.ts +35 -0
- package/src/services/vault/catalog/resolve.ts +94 -0
- package/src/services/vault/catalog/stat.ts +23 -0
- package/src/services/vault/catalog/types.ts +69 -0
- package/src/services/vault/catalog/visit.ts +58 -0
- package/src/services/vault/complete-blank.ts +66 -0
- package/src/services/vault/constants.ts +3 -0
- package/src/services/vault/context/index.ts +1 -0
- package/src/services/vault/context/types.ts +10 -0
- package/src/services/vault/create.ts +19 -0
- package/src/services/vault/display.ts +6 -0
- package/src/services/vault/domain-rules.ts +10 -0
- package/src/services/vault/draft.ts +2 -0
- package/src/services/vault/filesystem/failures.ts +53 -0
- package/src/services/vault/filesystem/hash.ts +5 -0
- package/src/services/vault/filesystem/index.ts +5 -0
- package/src/services/vault/filesystem/read.ts +61 -0
- package/src/services/vault/filesystem/types.ts +36 -0
- package/src/services/vault/filesystem/write.ts +80 -0
- package/src/services/vault/find.ts +27 -0
- package/src/services/vault/folder-contents.ts +31 -0
- package/src/services/vault/folder-index/index.ts +2 -0
- package/src/services/vault/folder-index/read.ts +87 -0
- package/src/services/vault/folder-index/types.ts +19 -0
- package/src/services/vault/folder-listing.ts +1 -0
- package/src/services/vault/index.ts +21 -0
- package/src/services/vault/inspect-folder.ts +13 -0
- package/src/services/vault/list.ts +121 -0
- package/src/services/vault/memory-folder.ts +24 -0
- package/src/services/vault/paths.ts +11 -0
- package/src/services/vault/publish.ts +52 -0
- package/src/services/vault/read.ts +46 -0
- package/src/services/vault/refresh-folders.ts +197 -0
- package/src/services/vault/refresh-plan.ts +79 -0
- package/src/services/vault/refresh.ts +8 -0
- package/src/services/vault/refusals.ts +23 -0
- package/src/services/vault/relocate.ts +131 -0
- package/src/services/vault/relocation-checks.ts +89 -0
- package/src/services/vault/resolve-stored-file.ts +43 -0
- package/src/services/vault/resolve.ts +109 -0
- package/src/services/vault/succeed.ts +45 -0
- package/src/services/vault/types.ts +199 -0
- package/src/services/vault/update-file.ts +58 -0
- package/src/services/vault/update.ts +22 -0
- package/src/services/vault/write-new-file.ts +37 -0
- package/src/shared/index.ts +1 -0
- package/src/shared/result/index.ts +1 -0
- package/src/shared/result/types.ts +17 -0
- package/src/usecases/add-memory/add-memory.ts +83 -0
- package/src/usecases/add-memory/index.ts +4 -0
- package/src/usecases/add-memory/maintenance.ts +23 -0
- package/src/usecases/add-memory/schemas.ts +12 -0
- package/src/usecases/add-memory/types.ts +47 -0
- package/src/usecases/archive-memory/archive-memory.ts +27 -0
- package/src/usecases/archive-memory/index.ts +3 -0
- package/src/usecases/archive-memory/schemas.ts +11 -0
- package/src/usecases/archive-memory/types.ts +17 -0
- package/src/usecases/capture-memory/apply.ts +73 -0
- package/src/usecases/capture-memory/capture-memory.ts +117 -0
- package/src/usecases/capture-memory/constants.ts +15 -0
- package/src/usecases/capture-memory/index.ts +5 -0
- package/src/usecases/capture-memory/observe.ts +122 -0
- package/src/usecases/capture-memory/settings.ts +20 -0
- package/src/usecases/capture-memory/types.ts +103 -0
- package/src/usecases/check-shell-edit/check-shell-edit.ts +28 -0
- package/src/usecases/check-shell-edit/index.ts +2 -0
- package/src/usecases/check-shell-edit/types.ts +30 -0
- package/src/usecases/check-vault-access/check-vault-access.ts +23 -0
- package/src/usecases/check-vault-access/constants.ts +7 -0
- package/src/usecases/check-vault-access/index.ts +4 -0
- package/src/usecases/check-vault-access/raw-device.ts +10 -0
- package/src/usecases/check-vault-access/targets.ts +49 -0
- package/src/usecases/check-vault-access/types.ts +33 -0
- package/src/usecases/complete-blank-memory/complete-blank-memory.ts +48 -0
- package/src/usecases/complete-blank-memory/constants.ts +3 -0
- package/src/usecases/complete-blank-memory/index.ts +4 -0
- package/src/usecases/complete-blank-memory/schemas.ts +14 -0
- package/src/usecases/complete-blank-memory/types.ts +28 -0
- package/src/usecases/diagnose-memory/constants.ts +3 -0
- package/src/usecases/diagnose-memory/decision.ts +36 -0
- package/src/usecases/diagnose-memory/diagnose-memory.ts +52 -0
- package/src/usecases/diagnose-memory/embeddings.ts +39 -0
- package/src/usecases/diagnose-memory/index.ts +5 -0
- package/src/usecases/diagnose-memory/types.ts +86 -0
- package/src/usecases/diagnose-memory/vault.ts +33 -0
- package/src/usecases/export-memory/collect.ts +20 -0
- package/src/usecases/export-memory/constants.ts +3 -0
- package/src/usecases/export-memory/export-memory.ts +84 -0
- package/src/usecases/export-memory/index.ts +3 -0
- package/src/usecases/export-memory/types.ts +28 -0
- package/src/usecases/get-memory/get-memory.ts +97 -0
- package/src/usecases/get-memory/index.ts +2 -0
- package/src/usecases/get-memory/types.ts +25 -0
- package/src/usecases/index.ts +25 -0
- package/src/usecases/list-memory/index.ts +2 -0
- package/src/usecases/list-memory/leased/index.ts +2 -0
- package/src/usecases/list-memory/leased/read.ts +16 -0
- package/src/usecases/list-memory/leased/types.ts +21 -0
- package/src/usecases/list-memory/list-memory.ts +33 -0
- package/src/usecases/list-memory/types.ts +8 -0
- package/src/usecases/load-dont-forget/index.ts +2 -0
- package/src/usecases/load-dont-forget/load-dont-forget.ts +111 -0
- package/src/usecases/load-dont-forget/types.ts +26 -0
- package/src/usecases/memory-change/change.ts +42 -0
- package/src/usecases/memory-change/index.ts +5 -0
- package/src/usecases/memory-change/maintenance.ts +11 -0
- package/src/usecases/memory-change/partial.ts +18 -0
- package/src/usecases/memory-change/receipt.ts +40 -0
- package/src/usecases/memory-change/types.ts +44 -0
- package/src/usecases/operation-context/context.ts +37 -0
- package/src/usecases/operation-context/index.ts +2 -0
- package/src/usecases/operation-context/types.ts +19 -0
- package/src/usecases/registration/check.ts +6 -0
- package/src/usecases/registration/entry.ts +33 -0
- package/src/usecases/registration/index.ts +8 -0
- package/src/usecases/registration/init.ts +94 -0
- package/src/usecases/registration/prepare-init.ts +43 -0
- package/src/usecases/registration/prepare.ts +35 -0
- package/src/usecases/registration/propose.ts +34 -0
- package/src/usecases/registration/publication.ts +90 -0
- package/src/usecases/registration/setup.ts +41 -0
- package/src/usecases/registration/types.ts +107 -0
- package/src/usecases/relevant-memory/agent.ts +55 -0
- package/src/usecases/relevant-memory/constants.ts +28 -0
- package/src/usecases/relevant-memory/cutoffs.ts +29 -0
- package/src/usecases/relevant-memory/decision.ts +102 -0
- package/src/usecases/relevant-memory/index.ts +11 -0
- package/src/usecases/relevant-memory/loaded.ts +31 -0
- package/src/usecases/relevant-memory/refresh.ts +30 -0
- package/src/usecases/relevant-memory/retrieve-memory.ts +62 -0
- package/src/usecases/relevant-memory/schemas.ts +20 -0
- package/src/usecases/relevant-memory/session-memory.ts +53 -0
- package/src/usecases/relevant-memory/track-dont-forget.ts +13 -0
- package/src/usecases/relevant-memory/types.ts +106 -0
- package/src/usecases/resolve-memory/index.ts +2 -0
- package/src/usecases/resolve-memory/leased/index.ts +2 -0
- package/src/usecases/resolve-memory/leased/resolve.ts +109 -0
- package/src/usecases/resolve-memory/leased/types.ts +35 -0
- package/src/usecases/resolve-memory/resolve-memory.ts +23 -0
- package/src/usecases/resolve-memory/types.ts +7 -0
- package/src/usecases/search-memory/constants.ts +1 -0
- package/src/usecases/search-memory/index.ts +3 -0
- package/src/usecases/search-memory/search-memory.ts +132 -0
- package/src/usecases/search-memory/types.ts +39 -0
- package/src/usecases/semantic/constants.ts +7 -0
- package/src/usecases/semantic/index.ts +5 -0
- package/src/usecases/semantic/prepare.ts +30 -0
- package/src/usecases/semantic/rank.ts +83 -0
- package/src/usecases/semantic/refresh-vectors.ts +95 -0
- package/src/usecases/semantic/types.ts +17 -0
- package/src/usecases/semantic-port/index.ts +1 -0
- package/src/usecases/semantic-port/types.ts +20 -0
- package/src/usecases/semantic-provider/constants.ts +6 -0
- package/src/usecases/semantic-provider/index.ts +5 -0
- package/src/usecases/semantic-provider/local.ts +33 -0
- package/src/usecases/semantic-provider/remote.ts +10 -0
- package/src/usecases/semantic-provider/size.ts +10 -0
- package/src/usecases/semantic-provider/types.ts +19 -0
- package/src/usecases/session/index.ts +2 -0
- package/src/usecases/session/lease.ts +70 -0
- package/src/usecases/session/receipts.ts +46 -0
- package/src/usecases/session/state.ts +106 -0
- package/src/usecases/session/types.ts +45 -0
- package/src/usecases/settings/change.ts +142 -0
- package/src/usecases/settings/index.ts +3 -0
- package/src/usecases/settings/prepare.ts +24 -0
- package/src/usecases/settings/types.ts +32 -0
- package/src/usecases/succeed-memory/index.ts +3 -0
- package/src/usecases/succeed-memory/schemas.ts +13 -0
- package/src/usecases/succeed-memory/succeed-memory.ts +34 -0
- package/src/usecases/succeed-memory/types.ts +18 -0
- package/src/usecases/synchronize-memory/index.ts +2 -0
- package/src/usecases/synchronize-memory/leased/aliases.ts +55 -0
- package/src/usecases/synchronize-memory/leased/folder-states.ts +58 -0
- package/src/usecases/synchronize-memory/leased/index.ts +2 -0
- package/src/usecases/synchronize-memory/leased/inspection.ts +32 -0
- package/src/usecases/synchronize-memory/leased/maintenance.ts +41 -0
- package/src/usecases/synchronize-memory/leased/publication.ts +55 -0
- package/src/usecases/synchronize-memory/leased/scan.ts +37 -0
- package/src/usecases/synchronize-memory/leased/synchronize.ts +102 -0
- package/src/usecases/synchronize-memory/leased/types.ts +60 -0
- package/src/usecases/synchronize-memory/synchronize-memory.ts +26 -0
- package/src/usecases/synchronize-memory/types.ts +5 -0
- package/src/usecases/update-memory/index.ts +3 -0
- package/src/usecases/update-memory/schemas.ts +14 -0
- package/src/usecases/update-memory/types.ts +16 -0
- package/src/usecases/update-memory/update-memory.ts +31 -0
- package/CHANGELOG.md +0 -21
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
canonicalizeRegistration,
|
|
3
|
+
checkConfigSnapshot,
|
|
4
|
+
ensureVaultAssets,
|
|
5
|
+
targetVault,
|
|
6
|
+
type VaultBootstrapProgress,
|
|
7
|
+
writeConfig,
|
|
8
|
+
} from "#src/services"
|
|
9
|
+
import type { Failed } from "#src/shared"
|
|
10
|
+
import type {
|
|
11
|
+
RegistrationCause,
|
|
12
|
+
RegistrationContext,
|
|
13
|
+
RegistrationFailure,
|
|
14
|
+
RegistrationPublication,
|
|
15
|
+
RegistrationResult,
|
|
16
|
+
RegistrationStage,
|
|
17
|
+
} from "./types.ts"
|
|
18
|
+
|
|
19
|
+
export function registrationInterruption(context: RegistrationContext): Failed | null {
|
|
20
|
+
if (context.signal.aborted || !context.session.isCurrent(context.stamp)) {
|
|
21
|
+
return { succeeded: false, problems: ["registration cancelled or session authority changed"] }
|
|
22
|
+
}
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function registrationFailure(
|
|
27
|
+
stage: RegistrationStage,
|
|
28
|
+
cause: RegistrationCause,
|
|
29
|
+
assets: VaultBootstrapProgress,
|
|
30
|
+
): RegistrationFailure {
|
|
31
|
+
return { succeeded: false, stage, cause, assets, problems: cause.problems }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function registrationValidationFailure(cause: RegistrationCause): RegistrationFailure {
|
|
35
|
+
return registrationFailure("validation", cause, {
|
|
36
|
+
createdRoot: false,
|
|
37
|
+
created: [],
|
|
38
|
+
preserved: [],
|
|
39
|
+
maintenanceProblems: [],
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function publishRegistration(
|
|
44
|
+
publication: RegistrationPublication,
|
|
45
|
+
context: RegistrationContext,
|
|
46
|
+
): Promise<RegistrationResult> {
|
|
47
|
+
const { write, scope } = publication
|
|
48
|
+
const canonical = await canonicalizeRegistration({
|
|
49
|
+
config: write.config,
|
|
50
|
+
configPath: write.path,
|
|
51
|
+
indexPath: write.indexPath,
|
|
52
|
+
platform: context.platform,
|
|
53
|
+
})
|
|
54
|
+
const interrupted = registrationInterruption(context)
|
|
55
|
+
if (interrupted) return registrationValidationFailure(interrupted)
|
|
56
|
+
if (!canonical.succeeded) return registrationValidationFailure(canonical)
|
|
57
|
+
const snapshot = await checkConfigSnapshot(write)
|
|
58
|
+
const stale = registrationInterruption(context)
|
|
59
|
+
if (stale) return registrationValidationFailure(stale)
|
|
60
|
+
if (!snapshot.succeeded) return registrationValidationFailure(snapshot)
|
|
61
|
+
const target = targetVault(write.config, scope, context.workingFolder, context.platform)
|
|
62
|
+
if (!target.succeeded) return registrationValidationFailure(target)
|
|
63
|
+
const assets = await ensureVaultAssets({ ...target.output, limits: write.config.limits })
|
|
64
|
+
if (!assets.succeeded) return registrationFailure("bootstrap", assets, assets)
|
|
65
|
+
return commitRegistration(publication, context, assets.output)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function commitRegistration(
|
|
69
|
+
publication: RegistrationPublication,
|
|
70
|
+
context: RegistrationContext,
|
|
71
|
+
assets: VaultBootstrapProgress,
|
|
72
|
+
): Promise<RegistrationResult> {
|
|
73
|
+
const interrupted = registrationInterruption(context)
|
|
74
|
+
if (interrupted) return registrationFailure("config", interrupted, assets)
|
|
75
|
+
const snapshot = await checkConfigSnapshot(publication.write)
|
|
76
|
+
const stale = registrationInterruption(context)
|
|
77
|
+
if (stale) return registrationFailure("config", stale, assets)
|
|
78
|
+
if (!snapshot.succeeded) return registrationFailure("config", snapshot, assets)
|
|
79
|
+
const written = await writeConfig(publication.write)
|
|
80
|
+
if (!written.succeeded) return registrationFailure("config", written, assets)
|
|
81
|
+
if (context.session.isCurrent(context.stamp)) context.session.invalidate(context.stamp)
|
|
82
|
+
return {
|
|
83
|
+
succeeded: true,
|
|
84
|
+
output: {
|
|
85
|
+
configHash: written.output.hash,
|
|
86
|
+
assets,
|
|
87
|
+
warnings: [...assets.maintenanceProblems, ...written.warnings],
|
|
88
|
+
},
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { resolveRegistrationVault, type WriteConfigRequest } from "#src/services"
|
|
2
|
+
import { captureRegistrationContext, captureSetupCommit } from "./entry.ts"
|
|
3
|
+
import { publishRegistration, registrationInterruption, registrationValidationFailure } from "./publication.ts"
|
|
4
|
+
import type { RegistrationContext, RegistrationResult, SetupCommitRequest } from "./types.ts"
|
|
5
|
+
|
|
6
|
+
export async function setupMemory(
|
|
7
|
+
input: SetupCommitRequest,
|
|
8
|
+
callerContext: RegistrationContext,
|
|
9
|
+
): Promise<RegistrationResult> {
|
|
10
|
+
const context = captureRegistrationContext(callerContext)
|
|
11
|
+
const captured = captureSetupCommit(input)
|
|
12
|
+
if (!captured.succeeded) return registrationValidationFailure(captured)
|
|
13
|
+
const lease = await context.session.acquire(context.stamp, context.signal)
|
|
14
|
+
if (!lease) {
|
|
15
|
+
return registrationValidationFailure({ succeeded: false, problems: ["registration session admission refused"] })
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const interrupted = registrationInterruption(context)
|
|
19
|
+
if (interrupted) return registrationValidationFailure(interrupted)
|
|
20
|
+
return await prepareGlobalRegistration(captured.output, context)
|
|
21
|
+
} finally {
|
|
22
|
+
lease.release()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function prepareGlobalRegistration(
|
|
27
|
+
request: SetupCommitRequest,
|
|
28
|
+
context: RegistrationContext,
|
|
29
|
+
): Promise<RegistrationResult> {
|
|
30
|
+
const vault = resolveRegistrationVault({ vault: request.config.global.vault, workingFolder: context.workingFolder })
|
|
31
|
+
if (!vault.succeeded) return registrationValidationFailure(vault)
|
|
32
|
+
const write: WriteConfigRequest = {
|
|
33
|
+
path: context.configPath,
|
|
34
|
+
platform: context.platform,
|
|
35
|
+
indexPath: context.indexPath,
|
|
36
|
+
config: { ...request.config, global: { ...request.config.global, vault: vault.output } },
|
|
37
|
+
expectedHash: request.expectedHash,
|
|
38
|
+
}
|
|
39
|
+
if (request.replacementConfirmed) write.replacementConfirmed = true
|
|
40
|
+
return publishRegistration({ write, scope: "global" }, context)
|
|
41
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ChatModelReference,
|
|
3
|
+
ConfigRefusal,
|
|
4
|
+
ConfigRepairDraft,
|
|
5
|
+
ConfigSnapshot,
|
|
6
|
+
ConfigWriteRefusal,
|
|
7
|
+
MemoryConfig,
|
|
8
|
+
MemoryScope,
|
|
9
|
+
ProjectEntry,
|
|
10
|
+
SetupDisclosure,
|
|
11
|
+
VaultBootstrapFailure,
|
|
12
|
+
VaultBootstrapProgress,
|
|
13
|
+
WriteConfigRequest,
|
|
14
|
+
} from "#src/services"
|
|
15
|
+
import type { Failed, Succeeded } from "#src/shared"
|
|
16
|
+
import type { MemoryContext } from "#src/usecases/add-memory"
|
|
17
|
+
import type { MemorySession, OperationStamp } from "#src/usecases/session"
|
|
18
|
+
|
|
19
|
+
export type {
|
|
20
|
+
ChatModelReference,
|
|
21
|
+
ConfigRepairDraft,
|
|
22
|
+
ConfigSnapshot,
|
|
23
|
+
MemoryConfig,
|
|
24
|
+
SetupDisclosure,
|
|
25
|
+
VaultBootstrapProgress,
|
|
26
|
+
} from "#src/services"
|
|
27
|
+
|
|
28
|
+
export interface RegistrationContext extends MemoryContext {
|
|
29
|
+
indexPath: string
|
|
30
|
+
session: MemorySession
|
|
31
|
+
stamp: OperationStamp
|
|
32
|
+
signal: AbortSignal
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SetupPreparationRequest {
|
|
36
|
+
selectedModel: ChatModelReference | null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface SetupPreparation {
|
|
40
|
+
snapshot: ConfigSnapshot
|
|
41
|
+
draft: ConfigRepairDraft
|
|
42
|
+
selectedModel: ChatModelReference | null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type SetupPreparationResult = Succeeded<SetupPreparation> | Failed
|
|
46
|
+
|
|
47
|
+
export interface SetupCommitRequest {
|
|
48
|
+
config: MemoryConfig
|
|
49
|
+
expectedHash: string | null
|
|
50
|
+
replacementConfirmed: boolean
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type SetupCommitCaptureResult = Succeeded<SetupCommitRequest> | Failed
|
|
54
|
+
|
|
55
|
+
export interface InitCommitRequest {
|
|
56
|
+
name: string
|
|
57
|
+
vault: string
|
|
58
|
+
expectedHash: string
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface RegistrationOutcome {
|
|
62
|
+
configHash: string
|
|
63
|
+
assets: VaultBootstrapProgress
|
|
64
|
+
warnings: string[]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type RegistrationStage = "validation" | "bootstrap" | "config"
|
|
68
|
+
export type RegistrationCause = ConfigRefusal | ConfigWriteRefusal | VaultBootstrapFailure | Failed
|
|
69
|
+
|
|
70
|
+
export interface RegistrationFailure extends Failed {
|
|
71
|
+
stage: RegistrationStage
|
|
72
|
+
assets: VaultBootstrapProgress
|
|
73
|
+
cause: RegistrationCause
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type RegistrationResult = Succeeded<RegistrationOutcome> | RegistrationFailure
|
|
77
|
+
|
|
78
|
+
export interface RegistrationPublication {
|
|
79
|
+
write: WriteConfigRequest
|
|
80
|
+
scope: MemoryScope
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type SetupVaultMode = "create" | "attach"
|
|
84
|
+
|
|
85
|
+
export interface SetupProposalRequest {
|
|
86
|
+
draft: ConfigRepairDraft
|
|
87
|
+
vault: string
|
|
88
|
+
mode: SetupVaultMode
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface ProposedSetup {
|
|
92
|
+
config: MemoryConfig
|
|
93
|
+
disclosures: SetupDisclosure[]
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export type SetupProposalResult = Succeeded<ProposedSetup> | Failed
|
|
97
|
+
|
|
98
|
+
export interface InitPreparation {
|
|
99
|
+
expectedHash: string
|
|
100
|
+
existing: ProjectEntry | null
|
|
101
|
+
defaultName: string
|
|
102
|
+
takenNames: string[]
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export type InitPreparationResult = Succeeded<InitPreparation> | ConfigRefusal
|
|
106
|
+
|
|
107
|
+
export type ProjectNameResult = Succeeded<string> | Failed
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CompletionPort,
|
|
3
|
+
type MemoryIdentity,
|
|
4
|
+
type MemoryObservation,
|
|
5
|
+
type ReadObservation,
|
|
6
|
+
type RetrievalObservation,
|
|
7
|
+
refusalObservation,
|
|
8
|
+
retrieveStep,
|
|
9
|
+
} from "#src/services"
|
|
10
|
+
import { detailOf, observeGet, observeList, observeSearch } from "#src/usecases/capture-memory"
|
|
11
|
+
import { type MemoryOperationContext, memoryOperationInterruption } from "#src/usecases/operation-context"
|
|
12
|
+
import { AGENT_FAILED } from "./constants.ts"
|
|
13
|
+
import type { AgentOutcome, AgentRequest, ReadStep } from "./types.ts"
|
|
14
|
+
|
|
15
|
+
export async function findNotes(
|
|
16
|
+
request: AgentRequest,
|
|
17
|
+
context: MemoryOperationContext,
|
|
18
|
+
complete: CompletionPort,
|
|
19
|
+
): Promise<AgentOutcome> {
|
|
20
|
+
const observations: RetrievalObservation[] = []
|
|
21
|
+
for (;;) {
|
|
22
|
+
if (memoryOperationInterruption(context)) return { succeeded: false, notice: null }
|
|
23
|
+
const { agent, query, model } = request
|
|
24
|
+
const step = await retrieveStep({ context: agent, query, observations, model, signal: context.signal }, complete)
|
|
25
|
+
if (!step.succeeded && "modelCall" in step) {
|
|
26
|
+
if (memoryOperationInterruption(context)) return { succeeded: false, notice: null }
|
|
27
|
+
return { succeeded: false, notice: `${AGENT_FAILED} ${detailOf(step.problems)}` }
|
|
28
|
+
}
|
|
29
|
+
if (!step.succeeded) {
|
|
30
|
+
observations.push(refusalObservation(step.problems))
|
|
31
|
+
continue
|
|
32
|
+
}
|
|
33
|
+
if (step.output.action === "finish") return { succeeded: true, output: chosen(step.output.notes, observations) }
|
|
34
|
+
observations.push(await observe(step.output, context))
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function observe(action: ReadStep, context: MemoryOperationContext): Promise<MemoryObservation> {
|
|
39
|
+
if (action.action === "search") return observeSearch(action.vault, action.query, context)
|
|
40
|
+
if (action.action === "get") return observeGet({ vault: action.vault, path: action.path }, context)
|
|
41
|
+
return observeList(action.vault, action.folder, context)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function chosen(identities: MemoryIdentity[], observations: RetrievalObservation[]): ReadObservation[] {
|
|
45
|
+
const reads = observations.filter((observation) => observation.kind === "read")
|
|
46
|
+
return identities.flatMap((identity) =>
|
|
47
|
+
reads.filter(
|
|
48
|
+
(read) =>
|
|
49
|
+
read.vault === identity.vault &&
|
|
50
|
+
read.path === identity.path &&
|
|
51
|
+
read.id === identity.id &&
|
|
52
|
+
read.hash === identity.hash,
|
|
53
|
+
),
|
|
54
|
+
)
|
|
55
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const RELEVANT_INTRO =
|
|
2
|
+
"Relevant long-term memory for this message. This is only part of your memory; use memory_search to find more, and memory_get to read a note in full."
|
|
3
|
+
|
|
4
|
+
export const SESSION_INTRO =
|
|
5
|
+
"Relevant long-term memory for this work. This is only part of your memory; use memory_search to find more, and memory_get to read a note in full."
|
|
6
|
+
|
|
7
|
+
export const NO_CHANGES = { loaded: [], forgotten: [] }
|
|
8
|
+
|
|
9
|
+
export const BLOCK_SEPARATOR = "\n\n"
|
|
10
|
+
|
|
11
|
+
export const SESSION_QUERY_PREFIX = "Memory relevant to starting work on"
|
|
12
|
+
|
|
13
|
+
export const NO_PROJECT = "no registered project"
|
|
14
|
+
|
|
15
|
+
export const ROUTING_MISSING_HELP =
|
|
16
|
+
"the Laya server did not say which model answered (it runs with LAYA_JEV_STRICT); run laya-serve without LAYA_JEV_STRICT and bound to 127.0.0.1 with LAYA_HOST"
|
|
17
|
+
|
|
18
|
+
export const CUTOFFS_MISSING = "Per-message memory is off: the decision model has no cutoff for"
|
|
19
|
+
|
|
20
|
+
export const CUTOFFS_HELP = "set it with /memory-setup; nothing was added"
|
|
21
|
+
|
|
22
|
+
export const COULD_NOT_SCORE = "The decision model could not score"
|
|
23
|
+
|
|
24
|
+
export const AGENT_FAILED = "The memory agent could not find memory:"
|
|
25
|
+
|
|
26
|
+
export const DECISION_UNAVAILABLE = "The decision model is unavailable, so no memory was added:"
|
|
27
|
+
|
|
28
|
+
export const SESSION_LOAD_FAILED = "Relevant notes could not be loaded:"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type DecisionCutoffs, defaultCutoffs, type MemoryConfig } from "#src/services"
|
|
2
|
+
import { CUTOFFS_HELP, CUTOFFS_MISSING } from "./constants.ts"
|
|
3
|
+
import type { CutoffReport, CutoffValue } from "./types.ts"
|
|
4
|
+
|
|
5
|
+
function cutoffOf(configured: number | undefined, fallback: number | undefined): CutoffValue {
|
|
6
|
+
if (typeof configured === "number") return { value: configured, source: "config" }
|
|
7
|
+
if (typeof fallback === "number") return { value: fallback, source: "typesafe" }
|
|
8
|
+
return { value: null, source: "missing" }
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function resolveCutoffs(config: MemoryConfig["decisionModel"]): CutoffReport {
|
|
12
|
+
const defaults = defaultCutoffs(config.provider)
|
|
13
|
+
return {
|
|
14
|
+
gate: cutoffOf(config.gateThreshold, defaults.gate),
|
|
15
|
+
relevance: cutoffOf(config.relevanceThreshold, defaults.relevance),
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function decidingCutoffs(report: CutoffReport): DecisionCutoffs | null {
|
|
20
|
+
if (typeof report.gate.value !== "number" || typeof report.relevance.value !== "number") return null
|
|
21
|
+
return { gate: report.gate.value, relevance: report.relevance.value }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function cutoffsMissingNotice(report: CutoffReport): string {
|
|
25
|
+
const names: string[] = []
|
|
26
|
+
if (report.gate.source === "missing") names.push("gateThreshold")
|
|
27
|
+
if (report.relevance.source === "missing") names.push("relevanceThreshold")
|
|
28
|
+
return `${CUTOFFS_MISSING} ${names.join(" and ")}; ${CUTOFFS_HELP}`
|
|
29
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CandidateScore,
|
|
3
|
+
type DecisionContext,
|
|
4
|
+
type DecisionFailure,
|
|
5
|
+
type DecisionLimits,
|
|
6
|
+
type DecisionResult,
|
|
7
|
+
decideMemory,
|
|
8
|
+
type MemoryConfig,
|
|
9
|
+
type ReadObservation,
|
|
10
|
+
rankCandidates,
|
|
11
|
+
scoreCandidates,
|
|
12
|
+
} from "#src/services"
|
|
13
|
+
import { COULD_NOT_SCORE, DECISION_UNAVAILABLE, ROUTING_MISSING_HELP } from "./constants.ts"
|
|
14
|
+
import type { JevSource, RankedNotes } from "./types.ts"
|
|
15
|
+
|
|
16
|
+
export async function decisionContextOf(
|
|
17
|
+
config: MemoryConfig["decisionModel"],
|
|
18
|
+
limits: DecisionLimits,
|
|
19
|
+
jev: JevSource,
|
|
20
|
+
): Promise<DecisionContext | string> {
|
|
21
|
+
if (config.provider === "laya") {
|
|
22
|
+
return {
|
|
23
|
+
provider: "laya",
|
|
24
|
+
endpoint: config.endpoint,
|
|
25
|
+
model: config.model,
|
|
26
|
+
maxTokens: config.maxTokens,
|
|
27
|
+
headMaxTokens: config.headMaxTokens,
|
|
28
|
+
...limits,
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const access = await jev(config.model)
|
|
32
|
+
if (!access.available) return `${DECISION_UNAVAILABLE} ${access.reason}`
|
|
33
|
+
return {
|
|
34
|
+
provider: "typesafe",
|
|
35
|
+
model: config.model,
|
|
36
|
+
classifier: access.classifier,
|
|
37
|
+
...limits,
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function decisionNotice(result: DecisionResult): string | null {
|
|
42
|
+
if (result.succeeded) return null
|
|
43
|
+
return `${DECISION_UNAVAILABLE} ${describeDecisionFailure(result)}`
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function describeDecisionFailure(failure: DecisionFailure): string {
|
|
47
|
+
if (failure.code === "routing-missing") return ROUTING_MISSING_HELP
|
|
48
|
+
if (failure.code !== "http-error" || typeof failure.httpStatus !== "number") return failure.code
|
|
49
|
+
let text = `${failure.code} (HTTP ${failure.httpStatus})`
|
|
50
|
+
if (typeof failure.detail === "string") text = `${text}: ${failure.detail}`
|
|
51
|
+
return text
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function needsMemory(
|
|
55
|
+
context: DecisionContext,
|
|
56
|
+
message: string,
|
|
57
|
+
project: string | null,
|
|
58
|
+
folder: string,
|
|
59
|
+
): Promise<DecisionResult> {
|
|
60
|
+
return decideMemory({ context, request: { message, project, folder } })
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function rankNotes(
|
|
64
|
+
context: DecisionContext,
|
|
65
|
+
message: string,
|
|
66
|
+
notes: ReadObservation[],
|
|
67
|
+
cutoff: number,
|
|
68
|
+
): Promise<RankedNotes> {
|
|
69
|
+
const results = await scoreCandidates(
|
|
70
|
+
context,
|
|
71
|
+
notes.map((note) => ({
|
|
72
|
+
message,
|
|
73
|
+
identity: identityOf(note),
|
|
74
|
+
candidate: { statement: note.statement, body: note.body },
|
|
75
|
+
})),
|
|
76
|
+
)
|
|
77
|
+
const scores: CandidateScore[] = []
|
|
78
|
+
let failure: DecisionFailure | null = null
|
|
79
|
+
let failed = 0
|
|
80
|
+
results.forEach((result, index) => {
|
|
81
|
+
const note = notes[index]
|
|
82
|
+
if (result.succeeded && note) scores.push({ identity: identityOf(note), probability: result.output.probability })
|
|
83
|
+
else if (!result.succeeded) {
|
|
84
|
+
failed += 1
|
|
85
|
+
failure = result
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
if (failure && failed === notes.length) return { notes: [], notice: decisionNotice(failure) }
|
|
89
|
+
const ranked = rankCandidates(scores, cutoff)
|
|
90
|
+
let notice: string | null = null
|
|
91
|
+
if (failed > 0) notice = `${COULD_NOT_SCORE} ${failed} of ${notes.length} notes`
|
|
92
|
+
return { notes: ranked.flatMap((score) => notes.filter((note) => matches(note, score))), notice }
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function identityOf(note: ReadObservation): CandidateScore["identity"] {
|
|
96
|
+
return { vault: note.vault, id: note.id, revision: note.hash }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function matches(note: ReadObservation, score: CandidateScore): boolean {
|
|
100
|
+
const { identity } = score
|
|
101
|
+
return note.vault === identity.vault && note.id === identity.id && note.hash === identity.revision
|
|
102
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./agent.ts"
|
|
2
|
+
export * from "./constants.ts"
|
|
3
|
+
export * from "./cutoffs.ts"
|
|
4
|
+
export * from "./decision.ts"
|
|
5
|
+
export * from "./loaded.ts"
|
|
6
|
+
export * from "./refresh.ts"
|
|
7
|
+
export * from "./retrieve-memory.ts"
|
|
8
|
+
export * from "./schemas.ts"
|
|
9
|
+
export * from "./session-memory.ts"
|
|
10
|
+
export * from "./track-dont-forget.ts"
|
|
11
|
+
export * from "./types.ts"
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ReadObservation } from "#src/services"
|
|
2
|
+
import type { LoadedChanges } from "./types.ts"
|
|
3
|
+
|
|
4
|
+
export class LoadedMemory {
|
|
5
|
+
#notes = new Map<string, ReadObservation>()
|
|
6
|
+
|
|
7
|
+
all(): ReadObservation[] {
|
|
8
|
+
return [...this.#notes.values()]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
apply(changes: LoadedChanges): void {
|
|
12
|
+
for (const note of changes.forgotten) this.forget(note)
|
|
13
|
+
for (const note of changes.loaded) this.remember(note)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
has(note: ReadObservation): boolean {
|
|
17
|
+
return this.#notes.get(keyOf(note))?.hash === note.hash
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
remember(note: ReadObservation): void {
|
|
21
|
+
this.#notes.set(keyOf(note), note)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
forget(note: ReadObservation): void {
|
|
25
|
+
this.#notes.delete(keyOf(note))
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function keyOf(note: ReadObservation): string {
|
|
30
|
+
return `${note.vault}:${note.path}`
|
|
31
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type InvalidReason, invalidatedBlock, type ReadObservation, replacementBlock } from "#src/services"
|
|
2
|
+
import { observeLoadedNote, type UnreadableNote } from "#src/usecases/capture-memory"
|
|
3
|
+
import { type MemoryOperationContext, memoryOperationInterruption } from "#src/usecases/operation-context"
|
|
4
|
+
import type { LoadedStore, Refreshed } from "./types.ts"
|
|
5
|
+
|
|
6
|
+
export async function refreshLoaded(loaded: LoadedStore, context: MemoryOperationContext): Promise<Refreshed> {
|
|
7
|
+
const blocks: string[] = []
|
|
8
|
+
const replaced: ReadObservation[] = []
|
|
9
|
+
const forgotten: ReadObservation[] = []
|
|
10
|
+
for (const previous of loaded.all()) {
|
|
11
|
+
const current = await observeLoadedNote(previous, context)
|
|
12
|
+
if (memoryOperationInterruption(context)) break
|
|
13
|
+
if (current.kind === "unreadable") {
|
|
14
|
+
loaded.forget(previous)
|
|
15
|
+
forgotten.push(previous)
|
|
16
|
+
blocks.push(invalidatedBlock(previous, invalidReason(current)))
|
|
17
|
+
} else if (current.hash !== previous.hash) {
|
|
18
|
+
loaded.remember(current)
|
|
19
|
+
replaced.push(current)
|
|
20
|
+
blocks.push(replacementBlock(previous, current))
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return { blocks, changes: { loaded: replaced, forgotten } }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function invalidReason(unreadable: UnreadableNote): InvalidReason {
|
|
27
|
+
if (unreadable.existence === "gone") return { kind: "gone" }
|
|
28
|
+
if (unreadable.existence === "present") return { kind: "unusable", problem: unreadable.detail }
|
|
29
|
+
return { kind: "unreadable", problem: unreadable.detail }
|
|
30
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { fitBudget, loadedNoteBlock, shouldRetrieveMemory } from "#src/services"
|
|
2
|
+
import type { MemoryOperationContext } from "#src/usecases/operation-context"
|
|
3
|
+
import { type ResolvedMemory, resolveMemory } from "#src/usecases/resolve-memory"
|
|
4
|
+
import { findNotes } from "./agent.ts"
|
|
5
|
+
import { BLOCK_SEPARATOR, RELEVANT_INTRO } from "./constants.ts"
|
|
6
|
+
import { cutoffsMissingNotice, decidingCutoffs, resolveCutoffs } from "./cutoffs.ts"
|
|
7
|
+
import { decisionContextOf, decisionNotice, needsMemory, rankNotes } from "./decision.ts"
|
|
8
|
+
import { refreshLoaded } from "./refresh.ts"
|
|
9
|
+
import type { RankedNotes, RetrieveDeps, RetrieveMemoryResult, RetrieveRequest } from "./types.ts"
|
|
10
|
+
|
|
11
|
+
export async function retrieveMemory(
|
|
12
|
+
request: RetrieveRequest,
|
|
13
|
+
context: MemoryOperationContext,
|
|
14
|
+
deps: RetrieveDeps,
|
|
15
|
+
): Promise<RetrieveMemoryResult> {
|
|
16
|
+
const resolved = await resolveMemory(context)
|
|
17
|
+
if (!resolved.succeeded) return resolved
|
|
18
|
+
const refreshed = await refreshLoaded(deps.loaded, context)
|
|
19
|
+
const blocks = refreshed.blocks
|
|
20
|
+
let found: RankedNotes = { notes: [], notice: null }
|
|
21
|
+
if (request.message.trim() !== "") found = await relevantNotes(request.message, resolved.output, context, deps)
|
|
22
|
+
const fitted = fitBudget(found.notes, resolved.output.config.context.budgetChars)
|
|
23
|
+
for (const note of fitted) deps.loaded.remember(note)
|
|
24
|
+
blocks.push(...fitted.map(loadedNoteBlock))
|
|
25
|
+
let text: string | null = null
|
|
26
|
+
if (blocks.length > 0) text = [RELEVANT_INTRO, ...blocks].join(BLOCK_SEPARATOR)
|
|
27
|
+
const notices: string[] = []
|
|
28
|
+
if (found.notice) notices.push(found.notice)
|
|
29
|
+
const changes = { loaded: [...refreshed.changes.loaded, ...fitted], forgotten: refreshed.changes.forgotten }
|
|
30
|
+
return { succeeded: true, output: { text, notices, changes } }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function relevantNotes(
|
|
34
|
+
message: string,
|
|
35
|
+
memory: ResolvedMemory,
|
|
36
|
+
context: MemoryOperationContext,
|
|
37
|
+
deps: RetrieveDeps,
|
|
38
|
+
): Promise<RankedNotes> {
|
|
39
|
+
const report = resolveCutoffs(memory.config.decisionModel)
|
|
40
|
+
const cutoffs = decidingCutoffs(report)
|
|
41
|
+
if (!cutoffs) return { notes: [], notice: cutoffsMissingNotice(report) }
|
|
42
|
+
const decision = await decisionContextOf(memory.config.decisionModel, { signal: context.signal }, deps.jev)
|
|
43
|
+
if (typeof decision === "string") return { notes: [], notice: decision }
|
|
44
|
+
let project: string | null = null
|
|
45
|
+
if (memory.project) project = memory.project.vault.name
|
|
46
|
+
const folder = context.workingFolder
|
|
47
|
+
const needed = await needsMemory(decision, message, project, folder)
|
|
48
|
+
if (!needed.succeeded) return { notes: [], notice: decisionNotice(needed) }
|
|
49
|
+
if (!shouldRetrieveMemory(needed.output.probability, cutoffs.gate)) return { notes: [], notice: null }
|
|
50
|
+
const agent = await findNotes(
|
|
51
|
+
{
|
|
52
|
+
agent: { project, folder },
|
|
53
|
+
query: message,
|
|
54
|
+
model: memory.config.memoryAgent.model,
|
|
55
|
+
},
|
|
56
|
+
context,
|
|
57
|
+
deps.complete,
|
|
58
|
+
)
|
|
59
|
+
if (!agent.succeeded) return { notes: [], notice: agent.notice }
|
|
60
|
+
const fresh = agent.output.filter((note) => !note.dontForget && !deps.loaded.has(note))
|
|
61
|
+
return rankNotes(decision, message, fresh, cutoffs.relevance)
|
|
62
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Type from "typebox"
|
|
2
|
+
|
|
3
|
+
import { BLANK_NOTE_TYPES } from "#src/usecases/complete-blank-memory"
|
|
4
|
+
|
|
5
|
+
export const StoredNoteSchema = Type.Object({
|
|
6
|
+
kind: Type.Literal("read"),
|
|
7
|
+
vault: Type.Enum(["global", "project"]),
|
|
8
|
+
path: Type.String(),
|
|
9
|
+
id: Type.String(),
|
|
10
|
+
hash: Type.String(),
|
|
11
|
+
statement: Type.String(),
|
|
12
|
+
body: Type.String(),
|
|
13
|
+
type: Type.Enum(BLANK_NOTE_TYPES),
|
|
14
|
+
dontForget: Type.Boolean(),
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export const LoadedChangesSchema = Type.Object({
|
|
18
|
+
loaded: Type.Array(StoredNoteSchema),
|
|
19
|
+
forgotten: Type.Array(StoredNoteSchema),
|
|
20
|
+
})
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { fitBudget, loadedNoteBlock } from "#src/services"
|
|
2
|
+
import type { MemoryOperationContext } from "#src/usecases/operation-context"
|
|
3
|
+
import { resolveMemory } from "#src/usecases/resolve-memory"
|
|
4
|
+
import { findNotes } from "./agent.ts"
|
|
5
|
+
import {
|
|
6
|
+
BLOCK_SEPARATOR,
|
|
7
|
+
NO_CHANGES,
|
|
8
|
+
NO_PROJECT,
|
|
9
|
+
SESSION_INTRO,
|
|
10
|
+
SESSION_LOAD_FAILED,
|
|
11
|
+
SESSION_QUERY_PREFIX,
|
|
12
|
+
} from "./constants.ts"
|
|
13
|
+
import type { RetrievedMemory, RetrieveMemoryResult, SessionMemoryDeps } from "./types.ts"
|
|
14
|
+
|
|
15
|
+
export async function loadSessionMemory(
|
|
16
|
+
context: MemoryOperationContext,
|
|
17
|
+
deps: SessionMemoryDeps,
|
|
18
|
+
): Promise<RetrieveMemoryResult> {
|
|
19
|
+
const resolved = await resolveMemory(context)
|
|
20
|
+
if (!resolved.succeeded) return resolved
|
|
21
|
+
const { config, project } = resolved.output
|
|
22
|
+
const { workingFolder } = context
|
|
23
|
+
let name: string | null = null
|
|
24
|
+
let label = NO_PROJECT
|
|
25
|
+
if (project) {
|
|
26
|
+
name = project.vault.name
|
|
27
|
+
label = name
|
|
28
|
+
}
|
|
29
|
+
const found = await findNotes(
|
|
30
|
+
{
|
|
31
|
+
agent: { project: name, folder: workingFolder },
|
|
32
|
+
query: `${SESSION_QUERY_PREFIX} ${label} in ${workingFolder}`,
|
|
33
|
+
model: config.memoryAgent.model,
|
|
34
|
+
},
|
|
35
|
+
context,
|
|
36
|
+
deps.complete,
|
|
37
|
+
)
|
|
38
|
+
if (!found.succeeded) return { succeeded: true, output: failedLoad(found.notice) }
|
|
39
|
+
const fitted = fitBudget(
|
|
40
|
+
found.output.filter((note) => !note.dontForget),
|
|
41
|
+
config.context.budgetChars,
|
|
42
|
+
)
|
|
43
|
+
for (const note of fitted) deps.loaded.remember(note)
|
|
44
|
+
if (fitted.length === 0) return { succeeded: true, output: { text: null, notices: [], changes: NO_CHANGES } }
|
|
45
|
+
const text = [SESSION_INTRO, ...fitted.map(loadedNoteBlock)].join(BLOCK_SEPARATOR)
|
|
46
|
+
return { succeeded: true, output: { text, notices: [], changes: NO_CHANGES } }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function failedLoad(notice: string | null): RetrievedMemory {
|
|
50
|
+
if (typeof notice !== "string") return { text: null, notices: [], changes: NO_CHANGES }
|
|
51
|
+
const text = `${SESSION_LOAD_FAILED} ${notice}`
|
|
52
|
+
return { text, notices: [text], changes: NO_CHANGES }
|
|
53
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LoadDontForgetResult } from "#src/usecases/load-dont-forget"
|
|
2
|
+
import type { LoadedMemory } from "./loaded.ts"
|
|
3
|
+
|
|
4
|
+
export function trackDontForget(loaded: LoadedMemory, result: LoadDontForgetResult): void {
|
|
5
|
+
if (!result.succeeded) return
|
|
6
|
+
for (const vault of result.output.vaults) {
|
|
7
|
+
for (const note of vault.notes) {
|
|
8
|
+
if (note.body.length === 0) continue
|
|
9
|
+
const { vault: scope, path, id, hash, statement, body, type } = note
|
|
10
|
+
loaded.remember({ kind: "read", vault: scope, path, id, hash, statement, body, type, dontForget: true })
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|