@north-light/crouter 0.3.227 → 0.3.229
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/dist/api/client.d.ts +5 -5
- package/dist/api/client.js +3 -3
- package/dist/api/dto/broker-ops.d.ts +8 -0
- package/dist/api/dto/memory.d.ts +8 -7
- package/dist/api/dto/memory.js +2 -2
- package/dist/builtin-memory/04-base-worker.md +1 -1
- package/dist/builtin-memory/insights/init.md +5 -5
- package/dist/builtin-memory/internal/INDEX.md +1 -1
- package/dist/builtin-memory/internal/agent-shaping.md +11 -11
- package/dist/builtin-memory/internal/examples/INDEX.md +1 -1
- package/dist/builtin-memory/internal/memory-loading.md +6 -6
- package/dist/builtin-memory/internal/plugins.md +1 -1
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/memory-slash-commands.ts +50 -37
- package/dist/clients/attach/__tests__/pane-tag-successor.test.js +56 -0
- package/dist/clients/attach/__tests__/profile-files.test.js +21 -0
- package/dist/clients/attach/chrome/inbox-strip.js +11 -7
- package/dist/clients/attach/session/pane-tag.d.ts +28 -2
- package/dist/clients/attach/session/pane-tag.js +48 -22
- package/dist/clients/attach/session/profile-files.d.ts +6 -0
- package/dist/clients/attach/session/profile-files.js +44 -11
- package/dist/clients/attach/slash/dispatch.js +4 -7
- package/dist/clients/attach/viewer.js +588 -596
- package/dist/commands/__tests__/surface-reload-target.test.js +21 -0
- package/dist/commands/api-client.d.ts +3 -7
- package/dist/commands/api-client.js +7 -12
- package/dist/commands/memory/__tests__/command-selector-and-mutation-guards.test.js +292 -0
- package/dist/commands/memory/__tests__/repository-root-lint.test.js +146 -0
- package/dist/commands/memory/delete.js +51 -24
- package/dist/commands/memory/edit.js +50 -10
- package/dist/commands/memory/find.js +105 -56
- package/dist/commands/memory/history.js +51 -31
- package/dist/commands/memory/lint.d.ts +0 -9
- package/dist/commands/memory/lint.js +78 -322
- package/dist/commands/memory/list.d.ts +12 -4
- package/dist/commands/memory/list.js +64 -25
- package/dist/commands/memory/move.js +103 -73
- package/dist/commands/memory/origin.js +35 -5
- package/dist/commands/memory/read.d.ts +4 -0
- package/dist/commands/memory/read.js +132 -80
- package/dist/commands/memory/shared.d.ts +115 -25
- package/dist/commands/memory/shared.js +331 -74
- package/dist/commands/memory/write.js +72 -21
- package/dist/commands/memory.js +2 -2
- package/dist/commands/node/create.d.ts +1 -1
- package/dist/commands/node/create.js +1 -1
- package/dist/commands/node/inspect.js +1 -1
- package/dist/commands/node/lifecycle.js +5 -5
- package/dist/commands/pkg/market-manage.js +25 -24
- package/dist/commands/pkg/plugin-manage.d.ts +22 -6
- package/dist/commands/pkg/plugin-manage.js +118 -25
- package/dist/commands/pkg/shared.d.ts +8 -0
- package/dist/commands/pkg/shared.js +23 -20
- package/dist/commands/surface-reload.d.ts +5 -0
- package/dist/commands/surface-reload.js +9 -1
- package/dist/commands/sys/__tests__/migrate.test.js +1140 -22
- package/dist/commands/sys/__tests__/sync-project-guidance.test.js +218 -0
- package/dist/commands/sys/migrate.js +126 -140
- package/dist/commands/sys/panels/profiles-panel.d.ts +66 -0
- package/dist/commands/sys/panels/profiles-panel.js +599 -0
- package/dist/commands/sys/settings-shell.d.ts +4 -2
- package/dist/commands/sys/settings-shell.js +35 -4
- package/dist/commands/sys/settings.js +21 -5
- package/dist/commands/sys/sync-deps.d.ts +2 -0
- package/dist/commands/sys/sync-deps.js +26 -15
- package/dist/commands/sys/sync-project-guidance.js +228 -145
- package/dist/commands/sys/sync-skills.js +28 -17
- package/dist/commands/sys/update.js +11 -3
- package/dist/core/__tests__/canvas-inbox-watcher-hold.test.js +15 -2
- package/dist/core/__tests__/config-change-delta.test.js +106 -0
- package/dist/core/__tests__/context-intro.test.js +13 -9
- package/dist/core/__tests__/daemon-boot.test.js +22 -16
- package/dist/core/__tests__/fixtures/memory-slash-live-probe.js +5 -1
- package/dist/core/__tests__/human-deliver.test.js +19 -0
- package/dist/core/__tests__/inline-memory-refs.test.js +50 -46
- package/dist/core/__tests__/{serial → integration}/broker-fork-seam.test.js +1 -1
- package/dist/core/__tests__/{serial → integration}/broker-sdk-wiring.test.js +1 -1
- package/dist/core/__tests__/{serial → integration}/broker-snapshot-history.test.js +1 -1
- package/dist/core/__tests__/{serial → integration}/command-plugins.test.js +94 -3
- package/dist/core/__tests__/{serial → integration}/deferred-no-wake.test.js +1 -1
- package/dist/core/__tests__/{serial → integration}/flagship-lifecycle.test.js +13 -27
- package/dist/core/__tests__/{serial → integration}/host-teardown-process-group.test.js +1 -1
- package/dist/core/__tests__/{serial → integration}/human-deliver-e2e.test.js +1 -1
- package/dist/core/__tests__/{live-mutation-verbs.test.js → integration/live-mutation-verbs.test.js} +22 -33
- package/dist/core/__tests__/{serial → integration}/live-mutation.test.js +21 -41
- package/dist/core/__tests__/integration/refresh-stall-recycle.test.d.ts +1 -0
- package/dist/core/__tests__/{serial → integration}/refresh-stall-recycle.test.js +1 -1
- package/dist/core/__tests__/integration/revive.test.d.ts +1 -0
- package/dist/core/__tests__/{serial → integration}/revive.test.js +38 -19
- package/dist/core/__tests__/integration/spawn-root.test.d.ts +1 -0
- package/dist/core/__tests__/{serial → integration}/spawn-root.test.js +104 -1
- package/dist/core/__tests__/integration/subscription-delivery.test.d.ts +1 -0
- package/dist/core/__tests__/{serial → integration}/subscription-delivery.test.js +1 -1
- package/dist/core/__tests__/integration/tmux-surface.test.d.ts +1 -0
- package/dist/core/__tests__/{serial → integration}/tmux-surface.test.js +1 -1
- package/dist/core/__tests__/integration/worktree-land.test.d.ts +1 -0
- package/dist/core/__tests__/integration/worktree-land.test.js +400 -0
- package/dist/core/__tests__/integration/worktree-reap.test.d.ts +1 -0
- package/dist/core/__tests__/{serial/worktree.test.js → integration/worktree-reap.test.js} +6 -338
- package/dist/core/__tests__/kickoff.test.js +16 -5
- package/dist/core/__tests__/memory-resolver-precedence.test.js +122 -91
- package/dist/core/__tests__/nested-store-discovery.test.js +5 -3
- package/dist/core/__tests__/on-read-crouter-home-fence.test.js +2 -1
- package/dist/core/__tests__/on-read-dedup-resume.test.js +39 -27
- package/dist/core/__tests__/on-read-nested-store.test.js +19 -13
- package/dist/core/__tests__/profile-project-memory-delivery.test.js +138 -44
- package/dist/core/__tests__/repository-association.test.d.ts +1 -0
- package/dist/core/__tests__/repository-association.test.js +153 -0
- package/dist/core/__tests__/repository-root-identity.test.d.ts +1 -0
- package/dist/core/__tests__/repository-root-identity.test.js +219 -0
- package/dist/core/__tests__/review-model-floor.test.js +12 -4
- package/dist/core/__tests__/seam/memory-slash-node-relative-inventory.test.js +27 -11
- package/dist/core/__tests__/warm-claim-preference-snapshot.test.d.ts +1 -0
- package/dist/core/__tests__/warm-claim-preference-snapshot.test.js +40 -0
- package/dist/core/canvas/canvas.d.ts +3 -0
- package/dist/core/canvas/canvas.js +30 -10
- package/dist/core/canvas/db.js +28 -1
- package/dist/core/canvas/paths.d.ts +4 -6
- package/dist/core/canvas/paths.js +8 -6
- package/dist/core/canvas/render-source.js +2 -2
- package/dist/core/canvas/types.d.ts +9 -13
- package/dist/core/config.d.ts +3 -3
- package/dist/core/config.js +3 -3
- package/dist/core/exclusive-lock.d.ts +2 -0
- package/dist/core/exclusive-lock.js +21 -0
- package/dist/core/git.d.ts +0 -1
- package/dist/core/git.js +0 -3
- package/dist/core/human/__tests__/integration/inbox-core.test.d.ts +1 -0
- package/dist/core/human/feedback-companion.js +3 -0
- package/dist/core/human/scan.js +8 -1
- package/dist/core/keybindings/catalog.d.ts +2 -2
- package/dist/core/keybindings/catalog.js +2 -1
- package/dist/core/memory/doc-link-grammar.js +2 -2
- package/dist/core/memory/history.d.ts +24 -0
- package/dist/core/memory/history.js +66 -1
- package/dist/core/memory/identity.d.ts +65 -0
- package/dist/core/memory/identity.js +185 -0
- package/dist/core/memory/inline-ref-guidance.d.ts +1 -1
- package/dist/core/memory/inline-ref-guidance.js +1 -1
- package/dist/core/memory/inline-ref-inventory.d.ts +3 -10
- package/dist/core/memory/inline-ref-inventory.js +30 -62
- package/dist/core/memory/lint.d.ts +129 -0
- package/dist/core/memory/lint.js +517 -0
- package/dist/core/memory/project-namespace.d.ts +31 -0
- package/dist/core/memory/project-namespace.js +85 -0
- package/dist/core/memory/repository-association.d.ts +31 -0
- package/dist/core/memory/repository-association.js +129 -0
- package/dist/core/memory/tree.d.ts +39 -0
- package/dist/core/memory/tree.js +93 -0
- package/dist/core/memory-resolver.d.ts +193 -90
- package/dist/core/memory-resolver.js +461 -375
- package/dist/core/nested-stores.js +6 -13
- package/dist/core/profiles/select.d.ts +4 -1
- package/dist/core/profiles/select.js +108 -48
- package/dist/core/review/__tests__/capture-origin.test.js +2 -2
- package/dist/core/review/__tests__/stage-identity.test.js +2 -2
- package/dist/core/review/companion.js +11 -2
- package/dist/core/runtime/bearings.d.ts +2 -2
- package/dist/core/runtime/bearings.js +3 -3
- package/dist/core/runtime/broker/daemon-ops.d.ts +2 -2
- package/dist/core/runtime/broker/rebind.js +5 -0
- package/dist/core/runtime/broker-extension-render.d.ts +7 -3
- package/dist/core/runtime/broker-extension-render.js +10 -5
- package/dist/core/runtime/broker-persona-guidance.d.ts +19 -5
- package/dist/core/runtime/broker-persona-guidance.js +122 -27
- package/dist/core/runtime/deliver-live.d.ts +16 -4
- package/dist/core/runtime/deliver-live.js +29 -15
- package/dist/core/runtime/kickoff.d.ts +3 -3
- package/dist/core/runtime/kickoff.js +8 -16
- package/dist/core/runtime/launch.js +1 -1
- package/dist/core/runtime/lifecycle.js +2 -3
- package/dist/core/runtime/nodes.d.ts +3 -4
- package/dist/core/runtime/nodes.js +3 -4
- package/dist/core/runtime/persona.d.ts +8 -12
- package/dist/core/runtime/persona.js +24 -96
- package/dist/core/runtime/promote.d.ts +2 -2
- package/dist/core/runtime/promote.js +8 -21
- package/dist/core/runtime/revive.js +20 -17
- package/dist/core/runtime/spawn.js +18 -7
- package/dist/core/runtime/tmux-bindings.js +2 -3
- package/dist/core/runtime/warm-pool.js +3 -4
- package/dist/core/scope.js +2 -0
- package/dist/core/self-update.d.ts +0 -2
- package/dist/core/self-update.js +2 -35
- package/dist/core/substrate/__tests__/surface-match-memory-read.test.d.ts +1 -0
- package/dist/core/substrate/__tests__/surface-match-memory-read.test.js +28 -0
- package/dist/core/substrate/index.d.ts +2 -2
- package/dist/core/substrate/index.js +1 -1
- package/dist/core/substrate/injected-store.d.ts +43 -27
- package/dist/core/substrate/injected-store.js +208 -104
- package/dist/core/substrate/listings.d.ts +19 -12
- package/dist/core/substrate/listings.js +75 -52
- package/dist/core/substrate/on-read-node.d.ts +4 -7
- package/dist/core/substrate/on-read-node.js +6 -8
- package/dist/core/substrate/on-read.d.ts +22 -25
- package/dist/core/substrate/on-read.js +103 -147
- package/dist/core/substrate/render-node.d.ts +4 -7
- package/dist/core/substrate/render-node.js +5 -7
- package/dist/core/substrate/render.d.ts +21 -3
- package/dist/core/substrate/render.js +291 -223
- package/dist/core/substrate/schema.d.ts +1 -13
- package/dist/core/substrate/schema.js +5 -40
- package/dist/core/substrate/session-cache.d.ts +14 -4
- package/dist/core/substrate/session-cache.js +40 -22
- package/dist/core/substrate/surface-match.d.ts +9 -7
- package/dist/core/substrate/surface-match.js +26 -25
- package/dist/daemon/__tests__/helpers/source-daemon.d.ts +30 -0
- package/dist/daemon/__tests__/helpers/source-daemon.js +174 -0
- package/dist/daemon/__tests__/integration/migration-startup.test.d.ts +1 -0
- package/dist/daemon/__tests__/integration/migration-startup.test.js +97 -0
- package/dist/daemon/api/__tests__/bridge-heartbeat.test.js +21 -5
- package/dist/daemon/api/handlers/broker-ops.js +21 -16
- package/dist/daemon/api/handlers/memory.js +2 -0
- package/dist/daemon/crtrd.js +2 -0
- package/dist/daemon/human/finish.js +8 -1
- package/dist/daemon/manage.d.ts +0 -1
- package/dist/daemon/manage.js +7 -16
- package/dist/daemon/startup-policy.d.ts +1 -0
- package/dist/daemon/startup-policy.js +1 -0
- package/dist/migrations/001-surfaces-frontmatter.js +21 -109
- package/dist/migrations/002-profile-project-memory.js +1 -0
- package/dist/migrations/003-repository-root-memory-identity/front-door.d.ts +26 -0
- package/dist/migrations/003-repository-root-memory-identity/front-door.js +231 -0
- package/dist/migrations/003-repository-root-memory-identity/index.d.ts +2 -0
- package/dist/migrations/003-repository-root-memory-identity/index.js +513 -0
- package/dist/migrations/003-repository-root-memory-identity/references.d.ts +95 -0
- package/dist/migrations/003-repository-root-memory-identity/references.js +469 -0
- package/dist/migrations/003-repository-root-memory-identity/repository-facts.d.ts +39 -0
- package/dist/migrations/003-repository-root-memory-identity/repository-facts.js +349 -0
- package/dist/migrations/__tests__/activation-concurrency.test.d.ts +1 -0
- package/dist/migrations/__tests__/activation-concurrency.test.js +145 -0
- package/dist/migrations/__tests__/activation.test.d.ts +1 -0
- package/dist/migrations/__tests__/activation.test.js +149 -0
- package/dist/migrations/__tests__/deletion-and-root-declaration.test.d.ts +1 -0
- package/dist/migrations/__tests__/deletion-and-root-declaration.test.js +149 -0
- package/dist/migrations/activation.d.ts +16 -0
- package/dist/migrations/activation.js +78 -0
- package/dist/migrations/convergent.d.ts +14 -3
- package/dist/migrations/convergent.js +21 -10
- package/dist/migrations/corpus.d.ts +78 -0
- package/dist/migrations/corpus.js +497 -0
- package/dist/migrations/frontmatter-splice.d.ts +15 -0
- package/dist/migrations/frontmatter-splice.js +176 -0
- package/dist/migrations/registry.d.ts +6 -1
- package/dist/migrations/registry.js +7 -2
- package/dist/migrations/runner.d.ts +41 -0
- package/dist/migrations/runner.js +81 -0
- package/dist/migrations/types.d.ts +148 -9
- package/dist/migrations/types.js +9 -2
- package/dist/pi-extensions/__tests__/canvas-context-intro.test.js +225 -17
- package/dist/pi-extensions/__tests__/canvas-goal-capture-envelope.test.js +11 -3
- package/dist/pi-extensions/canvas-context-intro.d.ts +3 -5
- package/dist/pi-extensions/canvas-context-intro.js +50 -46
- package/dist/pi-extensions/canvas-doc-substrate.d.ts +1 -8
- package/dist/pi-extensions/canvas-doc-substrate.js +55 -122
- package/dist/pi-extensions/canvas-stophook.js +6 -13
- package/dist/shared/generated-context.d.ts +0 -3
- package/dist/shared/generated-context.js +0 -57
- package/dist/shared/tool-groups.js +2 -3
- package/dist/types.d.ts +8 -11
- package/dist/types.js +4 -31
- package/package.json +5 -4
- package/runtime.lock.json +2 -2
- package/dist/builtin-memory/05-kinds/design/00-base.md +0 -17
- package/dist/builtin-memory/05-kinds/design/01-orchestrator.md +0 -15
- package/dist/builtin-memory/05-kinds/design/design-contract.md +0 -19
- package/dist/builtin-memory/05-kinds/developer/00-base.md +0 -17
- package/dist/builtin-memory/05-kinds/developer/01-orchestrator.md +0 -15
- package/dist/builtin-memory/05-kinds/plan/00-base.md +0 -17
- package/dist/builtin-memory/05-kinds/plan/01-orchestrator.md +0 -17
- package/dist/builtin-memory/05-kinds/plan/plan-contract.md +0 -28
- package/dist/builtin-memory/05-kinds/plan/reviewers/architecture-fit.md +0 -15
- package/dist/builtin-memory/05-kinds/plan/reviewers/code-smells.md +0 -15
- package/dist/builtin-memory/05-kinds/plan/reviewers/lens-contract.md +0 -13
- package/dist/builtin-memory/05-kinds/plan/reviewers/pattern-consistency.md +0 -17
- package/dist/builtin-memory/05-kinds/plan/reviewers/requirements-coverage.md +0 -17
- package/dist/builtin-memory/05-kinds/plan/reviewers/security.md +0 -17
- package/dist/builtin-memory/05-kinds/spec/00-base.md +0 -17
- package/dist/builtin-memory/05-kinds/spec/01-orchestrator.md +0 -15
- package/dist/builtin-memory/05-kinds/spec/requirements.md +0 -15
- package/dist/builtin-memory/design/guide.md +0 -35
- package/dist/builtin-memory/design/roadmap.md +0 -21
- package/dist/builtin-memory/development.md +0 -113
- package/dist/builtin-memory/plan/roadmap.md +0 -25
- package/dist/builtin-memory/spec/guide.md +0 -53
- package/dist/builtin-memory/spec/requirements.md +0 -29
- package/dist/builtin-memory/spec/roadmap.md +0 -36
- package/dist/builtin-memory/testing.md +0 -39
- /package/dist/api/__tests__/{serial → integration}/client.test.d.ts +0 -0
- /package/dist/api/__tests__/{serial → integration}/client.test.js +0 -0
- /package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/__tests__/{serial → integration}/provider-rotation.test.ts +0 -0
- /package/dist/clients/{inbox/__tests__/serial/inbox-controller.test.d.ts → attach/__tests__/pane-tag-successor.test.d.ts} +0 -0
- /package/dist/clients/{inbox/__tests__/serial/mount-panel.test.d.ts → attach/__tests__/profile-files.test.d.ts} +0 -0
- /package/dist/{core/__tests__/live-mutation-verbs.test.d.ts → clients/inbox/__tests__/integration/inbox-controller.test.d.ts} +0 -0
- /package/dist/clients/inbox/__tests__/{serial → integration}/inbox-controller.test.js +0 -0
- /package/dist/{core/__tests__/serial/broker-fork-seam.test.d.ts → clients/inbox/__tests__/integration/mount-panel.test.d.ts} +0 -0
- /package/dist/clients/inbox/__tests__/{serial → integration}/mount-panel.test.js +0 -0
- /package/dist/{core/__tests__/serial/broker-sdk-wiring.test.d.ts → commands/__tests__/surface-reload-target.test.d.ts} +0 -0
- /package/dist/{core/__tests__/serial/broker-snapshot-history.test.d.ts → commands/memory/__tests__/command-selector-and-mutation-guards.test.d.ts} +0 -0
- /package/dist/{core/__tests__/serial/command-plugins.test.d.ts → commands/memory/__tests__/repository-root-lint.test.d.ts} +0 -0
- /package/dist/{core/__tests__/serial/deferred-no-wake.test.d.ts → commands/sys/__tests__/sync-project-guidance.test.d.ts} +0 -0
- /package/dist/core/__tests__/{serial/flagship-lifecycle.test.d.ts → config-change-delta.test.d.ts} +0 -0
- /package/dist/core/__tests__/{serial/host-teardown-process-group.test.d.ts → integration/broker-fork-seam.test.d.ts} +0 -0
- /package/dist/core/__tests__/{serial/human-deliver-e2e.test.d.ts → integration/broker-sdk-wiring.test.d.ts} +0 -0
- /package/dist/core/__tests__/{serial/live-mutation.test.d.ts → integration/broker-snapshot-history.test.d.ts} +0 -0
- /package/dist/core/__tests__/{serial/refresh-stall-recycle.test.d.ts → integration/command-plugins.test.d.ts} +0 -0
- /package/dist/core/__tests__/{serial/revive.test.d.ts → integration/deferred-no-wake.test.d.ts} +0 -0
- /package/dist/core/__tests__/{serial/spawn-root.test.d.ts → integration/flagship-lifecycle.test.d.ts} +0 -0
- /package/dist/core/__tests__/{serial/subscription-delivery.test.d.ts → integration/host-teardown-process-group.test.d.ts} +0 -0
- /package/dist/core/__tests__/{serial/tmux-surface.test.d.ts → integration/human-deliver-e2e.test.d.ts} +0 -0
- /package/dist/core/__tests__/{serial/worktree.test.d.ts → integration/live-mutation-verbs.test.d.ts} +0 -0
- /package/dist/core/{human/__tests__/serial/inbox-core.test.d.ts → __tests__/integration/live-mutation.test.d.ts} +0 -0
- /package/dist/core/human/__tests__/{serial → integration}/inbox-core.test.js +0 -0
|
@@ -1,37 +1,53 @@
|
|
|
1
1
|
import { defineLeaf } from '../../core/command.js';
|
|
2
|
-
import { listAllMemoryDocs } from '../../core/memory-resolver.js';
|
|
2
|
+
import { listAllMemoryDocs, loadMemoryStoreView } from '../../core/memory-resolver.js';
|
|
3
3
|
import { memoryExtensionEffectiveCatalog, projectEffectiveMemoryExtensions } from '../../core/memory/extensions.js';
|
|
4
4
|
import { renderResult } from '../../core/render.js';
|
|
5
5
|
import { parseSubstrateDoc } from '../../core/substrate/schema.js';
|
|
6
6
|
import { paginate } from '../../core/pagination.js';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import { candidateRow } from './read.js';
|
|
8
|
+
import { MEMORY_KINDS, registerMemoryListingExposure, requireMountedStore, resolveReadSelector, scopeRank, selectorParam, } from './shared.js';
|
|
9
|
+
/** The inventory over one corpus. A target view is winner-only: one row per
|
|
10
|
+
* canonical identity, first in source order, because that is the document a
|
|
11
|
+
* read of the name returns. An exact store (`--dir`) is not deduped — the
|
|
12
|
+
* point of naming a store is to see what it physically holds, including a pair
|
|
13
|
+
* that shares one identity. */
|
|
14
|
+
export function listMemoryDocs(kindFilter, docs, dedup) {
|
|
15
|
+
const byName = new Map();
|
|
16
|
+
for (const doc of docs) {
|
|
17
|
+
const bucket = byName.get(doc.name);
|
|
18
|
+
if (bucket !== undefined)
|
|
19
|
+
bucket.push(doc);
|
|
20
|
+
else
|
|
21
|
+
byName.set(doc.name, [doc]);
|
|
22
|
+
}
|
|
23
|
+
const seen = new Set();
|
|
10
24
|
const items = [];
|
|
11
|
-
const addItem = (item) => {
|
|
12
|
-
const id = `${item.scope}/${item.name}`;
|
|
13
|
-
if (seen.has(id))
|
|
14
|
-
return;
|
|
15
|
-
seen.add(id);
|
|
16
|
-
items.push(item);
|
|
17
|
-
};
|
|
18
|
-
// Substrate memory docs (project > user > builtin precedence).
|
|
19
25
|
for (const doc of docs) {
|
|
20
26
|
const sub = parseSubstrateDoc(doc);
|
|
21
27
|
if (sub === null)
|
|
22
28
|
continue;
|
|
23
29
|
if (kindFilter !== undefined && sub.kind !== kindFilter)
|
|
24
30
|
continue;
|
|
25
|
-
|
|
31
|
+
if (dedup) {
|
|
32
|
+
if (seen.has(sub.name))
|
|
33
|
+
continue;
|
|
34
|
+
seen.add(sub.name);
|
|
35
|
+
}
|
|
36
|
+
items.push({
|
|
26
37
|
name: sub.name,
|
|
27
38
|
kind: sub.kind,
|
|
28
39
|
scope: sub.scope,
|
|
29
40
|
path: sub.path,
|
|
41
|
+
storeRoot: doc.root,
|
|
42
|
+
physicalRelativePath: doc.physicalRelativePath,
|
|
30
43
|
shortForm: sub.shortForm,
|
|
31
44
|
slash: sub.slash,
|
|
32
45
|
extensions: projectEffectiveMemoryExtensions(doc.frontmatter?.['extensions'], memoryExtensionEffectiveCatalog(doc)),
|
|
46
|
+
candidates: byName.get(doc.name) ?? [doc],
|
|
33
47
|
});
|
|
34
48
|
}
|
|
49
|
+
// Physical path is the final tiebreaker so two rows of one identity keep a
|
|
50
|
+
// stable order — the cursor key ends on the same component.
|
|
35
51
|
items.sort((a, b) => {
|
|
36
52
|
const sr = scopeRank(a.scope) - scopeRank(b.scope);
|
|
37
53
|
if (sr !== 0)
|
|
@@ -39,56 +55,79 @@ export function listMemoryDocs(kindFilter, scopeFilter, quiet = false, docs = li
|
|
|
39
55
|
const kc = a.kind.localeCompare(b.kind);
|
|
40
56
|
if (kc !== 0)
|
|
41
57
|
return kc;
|
|
42
|
-
|
|
58
|
+
const nc = a.name.localeCompare(b.name);
|
|
59
|
+
return nc !== 0 ? nc : a.physicalRelativePath.localeCompare(b.physicalRelativePath);
|
|
43
60
|
});
|
|
44
61
|
return items;
|
|
45
62
|
}
|
|
46
63
|
export const listLeaf = defineLeaf({
|
|
47
64
|
name: 'list',
|
|
48
65
|
description: 'inventory of stored memory documents',
|
|
49
|
-
whenToUse: 'browse everything stored — one
|
|
66
|
+
whenToUse: 'browse everything stored — one row per canonical name with its short-form hook, kind, and scope. Every name is readable as-is with `crtr memory read`. This is the one surface that shows short-form. Reach for `crtr memory find` instead when you already have a topic or keyword in mind rather than wanting the whole inventory.',
|
|
50
67
|
help: {
|
|
51
68
|
name: 'memory list',
|
|
52
|
-
summary: 'inventory every memory document across the resolved scopes, one
|
|
69
|
+
summary: 'inventory every memory document across the resolved scopes, one row per canonical name',
|
|
53
70
|
params: [
|
|
54
71
|
{ kind: 'flag', name: 'kind', type: 'enum', choices: [...MEMORY_KINDS], required: false, constraint: 'Filter to a single kind. Default: all kinds.' },
|
|
55
|
-
|
|
56
|
-
|
|
72
|
+
selectorParam('scope-read', {}, 'Default: every resolved scope.'),
|
|
73
|
+
selectorParam('dir', {}, 'Lists that store alone, and lists it physically: two documents sharing one canonical name both appear, where the default view shows only the winner.'),
|
|
74
|
+
{ kind: 'flag', name: 'paths', type: 'bool', required: false, default: false, constraint: 'Include each row\'s physical location — absolute path, store root, store-relative path, and every other physical document sharing its canonical name. Off by default.' },
|
|
57
75
|
{ kind: 'flag', name: 'limit', type: 'int', required: false, default: 50, constraint: 'Default 50, max 200.' },
|
|
58
76
|
{ kind: 'flag', name: 'cursor', type: 'string', required: false, constraint: 'Opaque token from next_cursor. Omit on first call.' },
|
|
59
77
|
],
|
|
60
78
|
output: [
|
|
61
|
-
{ name: 'items', type: 'object[]', required: true, constraint: 'One row per
|
|
79
|
+
{ name: 'items', type: 'object[]', required: true, constraint: 'One row per canonical name: {name, short_form, kind, scope, extensions}. extensions carries effective valid plugin-owned metadata; enabled defaults appear here without becoming frontmatter, while disabled and unresolved namespaces are omitted. With --paths each row also carries path, store_root, physical_relative_path, and — only when several physical documents share the name — candidates, one {winner, scope, store_root, physical_relative_path, path} row each in source order. Every name is readable as-is with `crtr memory read` (a name that carries members answers with its own document plus that directory listing). short_form is the abbreviated hook — shown here and nowhere else. Sorted by scope then kind then name ascending.' },
|
|
62
80
|
{ name: 'next_cursor', type: 'string | null', required: true, constraint: 'Opaque token for the next page; null means no more items.' },
|
|
63
81
|
{ name: 'total', type: 'integer | null', required: true, constraint: 'Exact total across all pages when cheap to compute (always cheap here); never null in practice for this leaf.' },
|
|
64
82
|
{ name: 'follow_up', type: 'string', required: true, constraint: 'Concrete next commands — read a document in full or narrow the inventory.' },
|
|
65
83
|
],
|
|
66
84
|
outputKind: 'object',
|
|
67
|
-
effects: ['
|
|
85
|
+
effects: ['Records this inventory page as listing context for the current node without marking any listed document as loaded.'],
|
|
68
86
|
},
|
|
69
87
|
run: async (input) => {
|
|
70
88
|
const kindFilter = input['kind'];
|
|
71
|
-
const
|
|
89
|
+
const dirArg = input['dir'];
|
|
72
90
|
const includePaths = input['paths'] ?? false;
|
|
73
91
|
const limitRaw = input['limit'];
|
|
74
92
|
const limit = limitRaw !== undefined ? Math.min(Math.max(1, limitRaw), 200) : 50;
|
|
75
93
|
const cursor = input['cursor'];
|
|
76
|
-
const
|
|
77
|
-
const
|
|
94
|
+
const selector = resolveReadSelector({ scope: input['scope'], dir: dirArg });
|
|
95
|
+
const items = selector.store !== null
|
|
96
|
+
? listMemoryDocs(kindFilter, loadMemoryStoreView(requireMountedStore(selector.store), false).docs, false)
|
|
97
|
+
: listMemoryDocs(kindFilter, listAllMemoryDocs(selector.scope, false, true), true);
|
|
98
|
+
const keyOf = (d) => `${String(scopeRank(d.scope) + 10).padStart(2, '0')}:${d.kind}:${d.name}:${d.physicalRelativePath}`;
|
|
78
99
|
const result = paginate(items, { limit, cursor }, { defaultLimit: 50, maxLimit: 200, keyOf, total: 'count' });
|
|
79
|
-
|
|
100
|
+
const output = {
|
|
80
101
|
items: result.items.map((d) => ({
|
|
81
102
|
name: d.name,
|
|
82
103
|
short_form: d.shortForm,
|
|
83
104
|
kind: d.kind,
|
|
84
105
|
scope: d.scope,
|
|
85
106
|
extensions: d.extensions,
|
|
86
|
-
...(includePaths
|
|
107
|
+
...(includePaths
|
|
108
|
+
? {
|
|
109
|
+
path: d.path,
|
|
110
|
+
store_root: d.storeRoot,
|
|
111
|
+
physical_relative_path: d.physicalRelativePath,
|
|
112
|
+
...(d.candidates.length > 1
|
|
113
|
+
? { candidates: d.candidates.map((c) => candidateRow(c, d.candidates[0])) }
|
|
114
|
+
: {}),
|
|
115
|
+
}
|
|
116
|
+
: {}),
|
|
87
117
|
})),
|
|
88
118
|
next_cursor: result.next_cursor,
|
|
89
119
|
total: result.total,
|
|
90
120
|
follow_up: 'Read one in full with `crtr memory read <name>`, or revise one with `crtr memory edit <name> --rationale "<why>"` (body, routing, frontmatter, and visibility all go through that one verb, and it records the change). Narrow with --kind / --scope, page with --cursor, or search a topic with `crtr memory find <query>`.',
|
|
91
121
|
};
|
|
122
|
+
registerMemoryListingExposure(`listing:memory-list:${JSON.stringify({
|
|
123
|
+
kind: kindFilter ?? null,
|
|
124
|
+
scope: selector.scope ?? null,
|
|
125
|
+
dir: dirArg ?? null,
|
|
126
|
+
paths: includePaths,
|
|
127
|
+
limit,
|
|
128
|
+
cursor: cursor ?? null,
|
|
129
|
+
})}`);
|
|
130
|
+
return output;
|
|
92
131
|
},
|
|
93
132
|
render: (result) => {
|
|
94
133
|
const items = result['items'].map(({ extensions: _extensions, ...item }) => item);
|
|
@@ -3,12 +3,12 @@ import { dirname, resolve as resolvePath } from 'node:path';
|
|
|
3
3
|
import { defineLeaf } from '../../core/command.js';
|
|
4
4
|
import { CrtrError, notFound, usage } from '../../core/errors.js';
|
|
5
5
|
import { ensureDir, pathExists, readText, realpathOrSelf, writeText } from '../../core/fs-utils.js';
|
|
6
|
-
import { listAllMemoryDocs,
|
|
7
|
-
import { findDocLinks
|
|
6
|
+
import { listAllMemoryDocs, loadMemoryStoreView, resolveMemoryCandidates } from '../../core/memory-resolver.js';
|
|
7
|
+
import { findDocLinks } from '../../core/memory/doc-link-grammar.js';
|
|
8
8
|
import { appendHistoryRecord, buildHistoryRecord, historyLogPathFor } from '../../core/memory/history.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
9
|
+
import { explicitLocalName } from '../../core/memory/identity.js';
|
|
10
|
+
import { buildMemoryTree } from '../../core/memory/tree.js';
|
|
11
|
+
import { MEMORY_WRITE_SCOPES, literalBodySegment, planNewDocumentPlacement, pruneEmptyParents, requireCanonicalName, requireLocalNameInStore, requireMountedStore, selectMutationDoc, resolveReadSelector, selectorParam, serializeMemoryDocLiteral, } from './shared.js';
|
|
12
12
|
/** Replace every `[[oldName]]` doc link in a full document source with
|
|
13
13
|
* `[[newName]]`, splicing only within the literal body segment so the
|
|
14
14
|
* frontmatter block is never touched. Link spans come from the shared
|
|
@@ -25,97 +25,113 @@ function rewriteRefs(source, oldName, newName) {
|
|
|
25
25
|
}
|
|
26
26
|
return { text, count: links.length };
|
|
27
27
|
}
|
|
28
|
+
/** Every physical document owning the source's exact canonical identity — in
|
|
29
|
+
* the target view, or inside the one store `--dir` selected — or null when
|
|
30
|
+
* nothing answers to that name. */
|
|
31
|
+
function sourceCandidates(rawName, scope, storeView) {
|
|
32
|
+
if (storeView !== null)
|
|
33
|
+
return storeView.candidates(rawName);
|
|
34
|
+
try {
|
|
35
|
+
return resolveMemoryCandidates(rawName, {
|
|
36
|
+
includeDescendants: true,
|
|
37
|
+
...(scope !== undefined ? { scope } : {}),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
if (e instanceof CrtrError && e.code === 'not_found')
|
|
42
|
+
return null;
|
|
43
|
+
throw e; // usage propagates with its own recovery guidance
|
|
44
|
+
}
|
|
45
|
+
}
|
|
28
46
|
export const moveLeaf = defineLeaf({
|
|
29
47
|
name: 'move',
|
|
30
48
|
description: 'rename or relocate a memory document, rewriting inbound links',
|
|
31
|
-
whenToUse: 'a stored document should answer to a different name — renamed in place or relocated under another directory. The sanctioned way to move one, so you never mv the markdown off disk: this verb carries the document’s revision history along and rewrites every inbound `[[ref]]` across writable stores, so authored links break loudly or not at all.
|
|
49
|
+
whenToUse: 'a stored document should answer to a different canonical name — renamed in place or relocated under another directory. The sanctioned way to move one, so you never mv the markdown off disk: this verb carries the document’s revision history along and rewrites every inbound `[[ref]]` across writable stores, so authored links break loudly or not at all. Source and destination are both full canonical names in the SAME store, so a move never changes which repository-relative prefix the document composes under. The repository-root document is immutable, but a nested store’s optional root guide is an ordinary document that may move. One document per move: moving a directory’s own document leaves its members where they are, so relocate a whole directory member by member. If two physical files in that store share the source identity, this verb selects the first physical path in stable lexical order and recovers the collision.',
|
|
32
50
|
help: {
|
|
33
51
|
name: 'memory move',
|
|
34
|
-
summary: 'move
|
|
52
|
+
summary: 'move one document to a new canonical name inside its own store, rewriting inbound [[refs]]',
|
|
35
53
|
params: [
|
|
36
|
-
{ kind: 'positional', name: 'name', required: true, constraint: '
|
|
37
|
-
{ kind: 'flag', name: 'to', type: 'string', required: true, constraint: 'The new canonical name, in the
|
|
38
|
-
|
|
54
|
+
{ kind: 'positional', name: 'name', required: true, constraint: 'Full canonical name of the document to move — a project document is `<namespace>/<local name>`. Resolution is exact, as `read` resolves it: a file path, a bare leaf, a `<scope>/<name>` spelling, and a trailing `/INDEX` all fail. If two physical files in the selected store own the name, move selects the first path in stable lexical order and recovers the collision. Builtin and installed-plugin documents are read-only and refuse to move, as does the repository-root document, which declares the immutable namespace for every document in the repository; a nested store’s root guide is ordinary and may move.' },
|
|
55
|
+
{ kind: 'flag', name: 'to', type: 'string', required: true, constraint: 'The new full canonical name, in the SAME store — the repository namespace and store path included, since a move never crosses stores. `/`-joined segments of [A-Za-z0-9_-], no trailing `INDEX` (a directory’s document answers at the directory name). A nested store’s effective prefix is a legal destination for its optional root guide. Rejected when a document in that store already answers to it, or when either `<local name>.md` or `<local name>/INDEX.md` already exists there.' },
|
|
56
|
+
selectorParam('scope-read', { choices: [...MEMORY_WRITE_SCOPES] }, 'builtin is not a choice — builtin documents ship with the package and cannot move.'),
|
|
57
|
+
selectorParam('dir', {}, 'Source, destination, and inbound-link rewriting all stay inside that one store, so moving a non-winning duplicate leaves every other store untouched — and rewrites no link at all, because the name still resolves to the candidate that outranks it here.'),
|
|
39
58
|
],
|
|
40
59
|
output: [
|
|
41
60
|
{ name: 'name', type: 'string', required: true, constraint: 'The document’s new canonical name.' },
|
|
42
|
-
{ name: 'previous_name', type: 'string', required: true, constraint: 'The name it answered to before the move.' },
|
|
61
|
+
{ name: 'previous_name', type: 'string', required: true, constraint: 'The canonical name it answered to before the move.' },
|
|
43
62
|
{ name: 'scope', type: 'string', required: true, constraint: 'Scope of the store the document moved within: node, user, project, or profile.' },
|
|
44
|
-
{ name: 'path', type: 'string', required: true, constraint: 'Absolute path of the document at its new location.' },
|
|
63
|
+
{ name: 'path', type: 'string', required: true, constraint: 'Absolute path of the document at its new location — `<local name>/INDEX.md` when that canonical directory already has members in the store, else `<local name>.md`.' },
|
|
45
64
|
{ name: 'moved', type: 'boolean', required: true, constraint: 'Always true on success — the file and its revision log now live at the new name.' },
|
|
46
65
|
{ name: 'log_path', type: 'string', required: true, constraint: 'Absolute path to the revision log at its new location, ending in a `move` record that names the previous canonical name.' },
|
|
47
|
-
{ name: 'refs_rewritten', type: 'object[]', required: true, constraint: 'Documents whose bodies were rewritten from `[[<previous_name>]]` to `[[<name>]]`. Each: {name, scope, path, refs}. Empty when nothing linked to the document — or when the moved
|
|
66
|
+
{ name: 'refs_rewritten', type: 'object[]', required: true, constraint: 'Documents whose bodies were rewritten from `[[<previous_name>]]` to `[[<name>]]`. Each: {name, scope, path, refs}. Empty when nothing linked to the document — or when the moved file is not what that name resolves to here (another store’s candidate wins the address), in which case inbound refs keep resolving to that winner and are left alone.' },
|
|
48
67
|
{ name: 'follow_up', type: 'string', required: true, constraint: 'Concrete next commands — read it back at the new name, verify the corpus with lint.' },
|
|
49
68
|
],
|
|
50
69
|
outputKind: 'object',
|
|
51
70
|
effects: [
|
|
52
|
-
'Moves
|
|
53
|
-
'
|
|
71
|
+
'Moves the document to the physical form its new local name takes in that store (creating parent directories, pruning any it leaves empty) and moves its `.history/<physical path>.jsonl` log with it, appending a `move` record naming the previous canonical name.',
|
|
72
|
+
'Drops an explicit `name:` frontmatter pin, so the moved document answers to its path-derived identity — the name you asked for.',
|
|
73
|
+
'Rewrites every inbound `[[<name>]]` doc link to `[[<new-name>]]` — across the target view’s writable stores, or inside the one store `--dir` selected — appending an `edit` record to each rewritten document’s revision log. Aborts before any write when a read-only (builtin or installed-plugin) document carries such a link.',
|
|
54
74
|
],
|
|
55
75
|
},
|
|
56
76
|
run: async (input) => {
|
|
57
77
|
const nameRaw = input['name'];
|
|
58
|
-
const
|
|
78
|
+
const newNameRaw = (input['to'] ?? '').trim();
|
|
59
79
|
const scopeArg = input['scope'];
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
throw usage(`${dirName} is a directory, and a directory never moves as a unit — move its member docs individually.`, {
|
|
69
|
-
memory: dirName,
|
|
70
|
-
next: `Run \`crtr memory read ${dirName}\` to list the members, then \`crtr memory move <member> --to <new-name>\` per doc.`,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
throw notFound(`memory document not found: ${nameRaw}`, {
|
|
80
|
+
const dirArg = input['dir'];
|
|
81
|
+
const selector = resolveReadSelector({ scope: scopeArg, dir: dirArg });
|
|
82
|
+
const storeView = selector.store === null ? null : loadMemoryStoreView(requireMountedStore(selector.store), true);
|
|
83
|
+
const set = sourceCandidates(nameRaw, selector.scope, storeView);
|
|
84
|
+
if (set === null) {
|
|
85
|
+
const tree = buildMemoryTree(storeView?.docs ?? listAllMemoryDocs(undefined, true, true));
|
|
86
|
+
if (tree.isDirectory(nameRaw)) {
|
|
87
|
+
throw usage(`${nameRaw} is a canonical directory with no document of its own, and a directory never moves as a unit — move its members individually.`, {
|
|
74
88
|
memory: nameRaw,
|
|
75
|
-
next:
|
|
89
|
+
next: `Run \`crtr memory read ${nameRaw}\` to list the members, then \`crtr memory move <member> --to <new-name>\` per document.`,
|
|
76
90
|
});
|
|
77
91
|
}
|
|
78
|
-
throw
|
|
92
|
+
throw notFound(`memory document not found: ${nameRaw}`, {
|
|
93
|
+
memory: nameRaw,
|
|
94
|
+
next: 'A move takes the full canonical name (a project document is <namespace>/<local name>), and a directory’s own document answers at the directory name. Run `crtr memory find <leaf>` to look it up, or pass --dir to reach one exact project store.',
|
|
95
|
+
});
|
|
79
96
|
}
|
|
97
|
+
const selected = selectMutationDoc(set);
|
|
98
|
+
const doc = selected.doc;
|
|
80
99
|
if (doc.plugin !== undefined) {
|
|
81
100
|
throw usage(`${doc.name} belongs to the installed plugin "${doc.plugin}" — it is not a scope doc and cannot be moved here. Manage plugin docs with \`crtr pkg\`.`, { memory: doc.name, plugin: doc.plugin });
|
|
82
101
|
}
|
|
83
102
|
if (doc.scope === 'builtin') {
|
|
84
103
|
throw usage(`${doc.name} is a builtin document shipped with the package (read-only) — it cannot be moved. Override it with a same-named doc at a writable scope instead (\`crtr memory write ${doc.name} ...\`).`, { memory: doc.name, scope: 'builtin' });
|
|
85
104
|
}
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
throw usage(`${doc.name} pins its identity with an explicit \`name\` frontmatter field, so its name is not path-derived and a file move would not rename it. Edit the field with \`crtr memory edit ${doc.name}\` instead.`, { memory: doc.name, path: doc.path });
|
|
105
|
+
// Only the repository-root document declares the namespace and is
|
|
106
|
+
// immutable through the memory commands.
|
|
107
|
+
if (doc.localName === '' && doc.store.ownerRelativePath === '') {
|
|
108
|
+
throw usage(`${doc.name} is the repository-root document at ${doc.path}, which declares the namespace every document in this repository composes under — it answers at the namespace itself and cannot be moved.`, { memory: doc.name, path: doc.path });
|
|
91
109
|
}
|
|
92
|
-
if (
|
|
110
|
+
if (newNameRaw === '')
|
|
93
111
|
throw usage('--to requires the new canonical name');
|
|
94
|
-
|
|
95
|
-
throw usage(`invalid new name: ${newName} — a canonical name is one or more [A-Za-z0-9_-] segments joined by \`/\``);
|
|
96
|
-
}
|
|
97
|
-
// Identity is derived from the path with `NN-` ordering prefixes stripped,
|
|
98
|
-
// so a prefixed target name would derive a different identity than asked.
|
|
99
|
-
if (normalizeDocName(newName) !== newName) {
|
|
100
|
-
throw usage(`invalid new name: ${newName} — a \`NN-\` ordering prefix is stripped from derived identity, so this doc would answer to ${normalizeDocName(newName)} instead. Name it that directly.`);
|
|
101
|
-
}
|
|
112
|
+
const newName = requireCanonicalName(newNameRaw);
|
|
102
113
|
if (newName === doc.name)
|
|
103
114
|
throw usage(`${doc.name} already answers to that name — nothing to move`);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
throw usage(`the target is occupied: ${newPath} already exists — pick a free name or delete the occupant first`, { memory: newName, path: newPath });
|
|
107
|
-
}
|
|
108
|
-
const corpus = listAllMemoryDocs(undefined, true, true);
|
|
109
|
-
const byName = docsByName(corpus);
|
|
110
|
-
const taken = byName.get(newName);
|
|
111
|
-
if (taken !== undefined) {
|
|
112
|
-
throw usage(`${newName} already answers to a document (${taken.scope} scope, ${taken.path}) — moving onto it would make every rewritten ref ambiguous. Pick a free name.`, { memory: newName, path: taken.path });
|
|
115
|
+
if (doc.store.ownerRelativePath === '' && requireLocalNameInStore(doc.store, newName) === '') {
|
|
116
|
+
throw usage(`${newName} is the repository namespace of the store at ${doc.root} — its repository-root document declares that namespace and is not a destination a move can create.`, { memory: newName });
|
|
113
117
|
}
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
//
|
|
118
|
+
// Occupancy (the identity AND both physical forms of it) is checked in the
|
|
119
|
+
// one store the document lives in; another store legitimately carries the
|
|
120
|
+
// same canonical name. The source itself is excluded, so retiring an
|
|
121
|
+
// explicit `name:` pin back to the file's own path-derived identity is a
|
|
122
|
+
// legal destination.
|
|
117
123
|
const movedReal = realpathOrSelf(doc.path);
|
|
118
|
-
const
|
|
124
|
+
const placement = planNewDocumentPlacement(doc.store, newName, storeView?.docs, doc);
|
|
125
|
+
const inPlace = realpathOrSelf(placement.path) === movedReal;
|
|
126
|
+
// Two corpora, one rule each. Winner facts always come from the live target
|
|
127
|
+
// view: `--dir` picks which store may be WRITTEN, never who owns the
|
|
128
|
+
// address, so a selected non-winning duplicate keeps every inbound ref
|
|
129
|
+
// pointing at the document that still answers here. The rewrite corpus is
|
|
130
|
+
// what this move may change — that one store under `--dir`, the same target
|
|
131
|
+
// view otherwise.
|
|
132
|
+
const targetDocs = listAllMemoryDocs(undefined, true, true);
|
|
133
|
+
const corpus = storeView?.docs ?? targetDocs;
|
|
134
|
+
const winner = targetDocs.find((d) => d.name === doc.name);
|
|
119
135
|
const isWinner = winner !== undefined && realpathOrSelf(winner.path) === movedReal;
|
|
120
136
|
const referencing = [];
|
|
121
137
|
const blocked = [];
|
|
@@ -153,18 +169,30 @@ export const moveLeaf = defineLeaf({
|
|
|
153
169
|
appendHistoryRecord(historyLogPathFor(d.root, d.path), buildHistoryRecord({ op: 'edit', rationale: `\`crtr memory move\`: [[${doc.name}]] → [[${newName}]]`, before, after }));
|
|
154
170
|
refsRewritten.push({ name: d.name, scope: d.scope, path: d.path, refs: count });
|
|
155
171
|
}
|
|
156
|
-
// The doc itself: self-refs rewrite in the same motion as the move.
|
|
172
|
+
// The doc itself: self-refs rewrite in the same motion as the move. An
|
|
173
|
+
// explicit `name` pinned identity to that string rather than the path, so
|
|
174
|
+
// the move drops it — the destination name IS the path-derived identity.
|
|
157
175
|
const before = readText(doc.path);
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
176
|
+
const rewritten = isWinner ? rewriteRefs(before, doc.name, newName).text : before;
|
|
177
|
+
let after = rewritten;
|
|
178
|
+
if (explicitLocalName(doc.frontmatter) !== null) {
|
|
179
|
+
const frontmatter = { ...(doc.frontmatter ?? {}) };
|
|
180
|
+
delete frontmatter['name'];
|
|
181
|
+
after = serializeMemoryDocLiteral(frontmatter, literalBodySegment(rewritten));
|
|
182
|
+
}
|
|
183
|
+
writeText(placement.path, after);
|
|
184
|
+
const physicalSegments = doc.physicalRelativePath.split('/').length;
|
|
185
|
+
if (!inPlace) {
|
|
186
|
+
rmSync(doc.path);
|
|
187
|
+
pruneEmptyParents(resolvePath(doc.path), physicalSegments);
|
|
188
|
+
}
|
|
189
|
+
// The revision log travels with the doc — history follows the file, so it
|
|
190
|
+
// moves to the sidecar mirroring the destination's physical path. A log
|
|
191
|
+
// already there (a prior, deleted life of that path) keeps its records;
|
|
192
|
+
// this doc's records append after them.
|
|
165
193
|
const oldLog = historyLogPathFor(doc.root, doc.path);
|
|
166
|
-
const newLog = historyLogPathFor(
|
|
167
|
-
if (pathExists(oldLog)) {
|
|
194
|
+
const newLog = historyLogPathFor(placement.store.storeRoot, placement.path);
|
|
195
|
+
if (!inPlace && pathExists(oldLog)) {
|
|
168
196
|
ensureDir(dirname(newLog));
|
|
169
197
|
if (pathExists(newLog)) {
|
|
170
198
|
appendFileSync(newLog, readText(oldLog), 'utf8');
|
|
@@ -173,23 +201,25 @@ export const moveLeaf = defineLeaf({
|
|
|
173
201
|
else {
|
|
174
202
|
renameSync(oldLog, newLog);
|
|
175
203
|
}
|
|
176
|
-
pruneEmptyParents(resolvePath(oldLog),
|
|
204
|
+
pruneEmptyParents(resolvePath(oldLog), physicalSegments);
|
|
177
205
|
}
|
|
178
206
|
appendHistoryRecord(newLog, buildHistoryRecord({ op: 'move', from: doc.name, before, after }));
|
|
179
207
|
const refsNote = isWinner
|
|
180
208
|
? refsRewritten.length > 0
|
|
181
209
|
? ` Rewrote [[${doc.name}]] in ${refsRewritten.length} doc${refsRewritten.length === 1 ? '' : 's'}.`
|
|
182
210
|
: ' No inbound refs needed rewriting.'
|
|
183
|
-
:
|
|
211
|
+
: winner === undefined
|
|
212
|
+
? ` Inbound [[${doc.name}]] refs were left alone: no document answers to that name in this target view, so no link here pointed at the moved file.`
|
|
213
|
+
: ` Inbound [[${doc.name}]] refs were left alone: ${winner.path} answers to that name in this target view, so they still resolve to it.`;
|
|
184
214
|
return {
|
|
185
215
|
name: newName,
|
|
186
216
|
previous_name: doc.name,
|
|
187
217
|
scope: doc.scope,
|
|
188
|
-
path:
|
|
218
|
+
path: placement.path,
|
|
189
219
|
moved: true,
|
|
190
220
|
log_path: newLog,
|
|
191
221
|
refs_rewritten: refsRewritten,
|
|
192
|
-
follow_up: `Moved
|
|
222
|
+
follow_up: `Moved${selected.collisionPaths.length > 0 ? ` the first physical path in stable lexical order (${doc.path}) to recover a same-store collision.` : '.'}${refsNote} Read it back with \`crtr memory read ${newName}\`, and run \`crtr memory lint\` to verify no link dangles.`,
|
|
193
223
|
};
|
|
194
224
|
},
|
|
195
225
|
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { defineLeaf } from '../../core/command.js';
|
|
2
2
|
import { CrtrError, notFound } from '../../core/errors.js';
|
|
3
|
-
import {
|
|
3
|
+
import { loadMemoryStoreView, resolveMemoryCandidates } from '../../core/memory-resolver.js';
|
|
4
4
|
import { ApiError } from '../../api/index.js';
|
|
5
5
|
import { cliClient } from '../api-client.js';
|
|
6
6
|
import { contextDir } from '../../core/canvas/paths.js';
|
|
7
|
+
import { requireMountedStore, requireUnambiguousDoc, resolveReadSelector, selectorParam } from './shared.js';
|
|
7
8
|
export const originLeaf = defineLeaf({
|
|
8
9
|
name: 'origin',
|
|
9
10
|
description: 'deref a memory document back to the node + conversation that created it',
|
|
@@ -12,11 +13,19 @@ export const originLeaf = defineLeaf({
|
|
|
12
13
|
name: 'memory origin',
|
|
13
14
|
summary: 'resolve a doc name to its creation provenance and deref the originating node',
|
|
14
15
|
params: [
|
|
15
|
-
{ kind: 'positional', name: 'name', required: true, constraint: '
|
|
16
|
+
{ kind: 'positional', name: 'name', required: true, constraint: 'Full canonical memory name (a project document includes its namespace). Resolved exactly across the selected target view; a same-store physical collision is refused.' },
|
|
17
|
+
selectorParam('scope-read'),
|
|
18
|
+
selectorParam('dir'),
|
|
19
|
+
selectorParam('profile'),
|
|
16
20
|
],
|
|
17
21
|
output: [
|
|
18
22
|
{ name: 'name', type: 'string', required: true, constraint: 'Resolved document name.' },
|
|
19
23
|
{ name: 'path', type: 'string', required: true, constraint: 'Absolute path to the document on disk.' },
|
|
24
|
+
{ name: 'scope', type: 'string', required: true, constraint: 'Scope whose ordered store view supplied the document.' },
|
|
25
|
+
{ name: 'local_name', type: 'string', required: true, constraint: 'Store-local identity, before project namespace composition.' },
|
|
26
|
+
{ name: 'store_root', type: 'string', required: true, constraint: 'Absolute memory store root containing the document.' },
|
|
27
|
+
{ name: 'physical_relative_path', type: 'string', required: true, constraint: 'Store-relative physical markdown path; sidecars preserve this shape.' },
|
|
28
|
+
{ name: 'representation', type: 'string', required: true, constraint: 'Physical representation: leaf-file or directory-index.' },
|
|
20
29
|
{ name: 'origin_recorded', type: 'boolean', required: true, constraint: 'true when the doc carries an `origin` provenance block; false for hand-authored or pre-provenance docs.' },
|
|
21
30
|
{ name: 'created', type: 'string', required: false, constraint: 'ISO timestamp the doc was created. Absent when origin_recorded is false.' },
|
|
22
31
|
{ name: 'cwd', type: 'string', required: false, constraint: 'Working directory the authoring conversation ran in.' },
|
|
@@ -35,25 +44,41 @@ export const originLeaf = defineLeaf({
|
|
|
35
44
|
},
|
|
36
45
|
run: async (input) => {
|
|
37
46
|
const nameRaw = input['name'];
|
|
38
|
-
|
|
47
|
+
const selector = resolveReadSelector({
|
|
48
|
+
scope: input['scope'],
|
|
49
|
+
dir: input['dir'],
|
|
50
|
+
profile: input['profile'],
|
|
51
|
+
});
|
|
52
|
+
if (selector.store !== null)
|
|
53
|
+
requireMountedStore(selector.store);
|
|
54
|
+
let set;
|
|
39
55
|
try {
|
|
40
|
-
|
|
56
|
+
set = selector.store !== null
|
|
57
|
+
? loadMemoryStoreView(selector.store, true).candidates(nameRaw)
|
|
58
|
+
: resolveMemoryCandidates(nameRaw, { includeDescendants: true, ...(selector.scope ? { scope: selector.scope } : {}) });
|
|
41
59
|
}
|
|
42
60
|
catch (e) {
|
|
43
61
|
if (!(e instanceof CrtrError && e.code === 'not_found'))
|
|
44
62
|
throw e;
|
|
63
|
+
set = null;
|
|
45
64
|
}
|
|
46
|
-
if (
|
|
65
|
+
if (set === null) {
|
|
47
66
|
throw notFound(`memory document not found: ${nameRaw}`, {
|
|
48
67
|
memory: nameRaw,
|
|
49
68
|
next: 'Run `crtr memory find <query>` to discover documents, or `crtr memory list` to browse the inventory.',
|
|
50
69
|
});
|
|
51
70
|
}
|
|
71
|
+
const doc = requireUnambiguousDoc(set);
|
|
52
72
|
const origin = doc.frontmatter?.['origin'];
|
|
53
73
|
if (origin === undefined || typeof origin !== 'object') {
|
|
54
74
|
return {
|
|
55
75
|
name: doc.name,
|
|
56
76
|
path: doc.path,
|
|
77
|
+
scope: doc.scope,
|
|
78
|
+
local_name: doc.localName,
|
|
79
|
+
store_root: doc.root,
|
|
80
|
+
physical_relative_path: doc.physicalRelativePath,
|
|
81
|
+
representation: doc.representation,
|
|
57
82
|
origin_recorded: false,
|
|
58
83
|
follow_up: 'No provenance recorded \u2014 this doc was hand-authored or created before provenance capture. Read its body with `crtr memory read ' +
|
|
59
84
|
doc.name +
|
|
@@ -83,6 +108,11 @@ export const originLeaf = defineLeaf({
|
|
|
83
108
|
return {
|
|
84
109
|
name: doc.name,
|
|
85
110
|
path: doc.path,
|
|
111
|
+
scope: doc.scope,
|
|
112
|
+
local_name: doc.localName,
|
|
113
|
+
store_root: doc.root,
|
|
114
|
+
physical_relative_path: doc.physicalRelativePath,
|
|
115
|
+
representation: doc.representation,
|
|
86
116
|
origin_recorded: true,
|
|
87
117
|
created: str(origin['created']) ?? undefined,
|
|
88
118
|
cwd: str(origin['cwd']) ?? undefined,
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { createMemoryDocSnapshot, resolveMemoryDocs } from '../../core/memory-resolver.js';
|
|
2
|
+
import type { MemoryDoc } from '../../core/memory-resolver.js';
|
|
2
3
|
export { createMemoryDocSnapshot, resolveMemoryDocs };
|
|
3
4
|
/** Load the body at an already-resolved memory path with the same frontmatter
|
|
4
5
|
* stripping and in-node path interpolation as `memory read`. Callers that
|
|
5
6
|
* already have the resolved path (such as slash-command discovery) avoid
|
|
6
7
|
* re-walking every memory store for each document. */
|
|
7
8
|
export declare function readMemoryDocContent(path: string, includeFrontmatter?: boolean): string;
|
|
9
|
+
/** One physical document sharing a canonical identity, as the path-aware
|
|
10
|
+
* surfaces report it. `--dir <its project>` is how a non-winner is reached. */
|
|
11
|
+
export declare function candidateRow(doc: MemoryDoc, winner: MemoryDoc): Record<string, unknown>;
|
|
8
12
|
export declare const readLeaf: import("../../core/command.js").LeafDef;
|