total-recall-brain 3.40.7 → 3.41.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.
Files changed (172) hide show
  1. package/bin/total-recall-memory.mjs +0 -0
  2. package/bin/total-recall.mjs +9 -40
  3. package/docs/reference/cli-reference.md +65 -1
  4. package/frontend/dist/assets/{index-AGUes-VG.css → index-BG9NkVUy.css} +1 -1
  5. package/frontend/dist/assets/{index-Bt5iVPZj.js → index-BtuiZqwP.js} +20 -7
  6. package/frontend/dist/index.html +2 -2
  7. package/frontend/src/components/plugins/PluginPanel.tsx +31 -5
  8. package/frontend/src/components/plugins/card/CardEngine.tsx +15 -23
  9. package/frontend/src/components/plugins/card/CardScenes.tsx +52 -23
  10. package/frontend/src/components/plugins/card/card.css +2 -5
  11. package/frontend/src/components/plugins/card/contract.ts +13 -19
  12. package/frontend/src/components/plugins/card/format.ts +8 -1
  13. package/frontend/src/components/plugins/card/widgets.tsx +4 -35
  14. package/frontend/src/components/plugins/plugin-frame.ts +30 -3
  15. package/frontend/src/pages/PluginsPage.tsx +3 -2
  16. package/package.json +1 -1
  17. package/scaffold/.agent/skills/meta-harness/references/optimized/original.md +1 -1
  18. package/scaffold/.agent/skills/plugin/SKILL.md +110 -0
  19. package/scaffold/.agent/skills/plugin/evals/README.md +53 -0
  20. package/scaffold/.agent/skills/plugin/evals/cases/01-fabricated-seed.mjs +42 -0
  21. package/scaffold/.agent/skills/plugin/evals/cases/02-reassuring-default.mjs +39 -0
  22. package/scaffold/.agent/skills/plugin/evals/cases/03-declared-template.mjs +32 -0
  23. package/scaffold/.agent/skills/plugin/evals/cases/04-card-collects-credential.mjs +46 -0
  24. package/scaffold/.agent/skills/plugin/evals/cases/05-host-leak-in-scaffold.mjs +55 -0
  25. package/scaffold/.agent/skills/plugin/evals/cases/06-correct-plugin.mjs +92 -0
  26. package/scaffold/.agent/skills/plugin/evals/run.mjs +118 -0
  27. package/scaffold/.agent/skills/plugin/prompts/01-function.md +29 -0
  28. package/scaffold/.agent/skills/plugin/prompts/02-surfaces.md +43 -0
  29. package/scaffold/.agent/skills/plugin/prompts/03-scaffold.md +31 -0
  30. package/scaffold/.agent/skills/plugin/prompts/04-cli.md +49 -0
  31. package/scaffold/.agent/skills/plugin/prompts/05-credentials.md +41 -0
  32. package/scaffold/.agent/skills/plugin/prompts/06-card.md +46 -0
  33. package/scaffold/.agent/skills/plugin/prompts/07-scaffold.md +52 -0
  34. package/scaffold/.agent/skills/plugin/prompts/08-verify.md +43 -0
  35. package/scaffold/.agent/skills/plugin/references/anti-patterns.md +123 -0
  36. package/scaffold/.agent/skills/plugin/references/card.md +90 -0
  37. package/scaffold/.agent/skills/plugin/references/scaffold.md +120 -0
  38. package/scaffold/.agent/skills/plugin/references/surfaces.md +206 -0
  39. package/scaffold/.agent/skills/plugin/scripts/record.mjs +360 -0
  40. package/scaffold/.agent/skills/plugin/subagents/card-designer.md +60 -0
  41. package/scaffold/.agent/skills/plugin/subagents/plugin-reviewer.md +55 -0
  42. package/scaffold/.agent/skills/plugin/subagents/scaffold-extractor.md +71 -0
  43. package/scaffold/.agent/skills/total-recall/plugins/auth/package-lock.json +71 -1441
  44. package/scaffold/.agent/skills/total-recall/plugins/auth/package.json +7 -5
  45. package/scaffold/.agent/skills/total-recall/plugins/auth/plugin.json +3 -44
  46. package/scaffold/.agent/skills/total-recall/plugins/auth/scripts/agent-login-pty.py +185 -0
  47. package/scaffold/.agent/skills/total-recall/plugins/auth/src/cli-secret.mjs +20 -1
  48. package/scaffold/.agent/skills/total-recall/plugins/auth/src/host-secrets-store.mjs +15 -0
  49. package/scaffold/.agent/skills/total-recall/plugins/auth/src/secrets-env-export.mjs +6 -4
  50. package/scaffold/.agent/skills/total-recall/plugins/auth/src/secrets-remote-deploy.mjs +1 -0
  51. package/scaffold/.agent/skills/total-recall/plugins/cli-agents/plugin.json +0 -24
  52. package/scaffold/.agent/skills/total-recall/plugins/code-quality/package-lock.json +4 -4
  53. package/scaffold/.agent/skills/total-recall/plugins/code-quality/plugin.json +0 -21
  54. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/package-lock.json +4 -4
  55. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/plugin.json +0 -32
  56. package/scaffold/.agent/skills/total-recall/plugins/embeddings/package-lock.json +4 -4
  57. package/scaffold/.agent/skills/total-recall/plugins/embeddings/plugin.json +11 -0
  58. package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/README.md +5 -2
  59. package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/package-lock.json +4 -4
  60. package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/plugin.json +1 -28
  61. package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/ui/DESIGN.md +95 -13
  62. package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/ui/card.js +553 -340
  63. package/scaffold/.agent/skills/total-recall/plugins/mesh/plugin.json +0 -36
  64. package/scaffold/.agent/skills/total-recall/plugins/mesh/ui/card.js +383 -400
  65. package/scaffold/.agent/skills/total-recall/plugins/openwiki/package-lock.json +4 -4
  66. package/scaffold/.agent/skills/total-recall/plugins/openwiki/package.json +0 -1
  67. package/scaffold/.agent/skills/total-recall/plugins/openwiki/plugin.json +0 -28
  68. package/scaffold/.agent/skills/total-recall/plugins/security/package-lock.json +4 -4
  69. package/scaffold/.agent/skills/total-recall/plugins/security/plugin.json +0 -32
  70. package/scaffold/.agent/skills/total-recall/references/auth.md +3 -1
  71. package/scaffold/.agent/skills/total-recall/references/memory.md +4 -0
  72. package/scaffold/.agent/skills/total-recall/references/openwiki.md +2 -0
  73. package/scaffold/.agent/skills/total-recall/references/operations.md +12 -0
  74. package/src/cli/brain.mjs +72 -2
  75. package/src/cli/connect.mjs +10 -39
  76. package/src/cli/context-stats.mjs +104 -0
  77. package/src/cli/context.mjs +8 -0
  78. package/src/cli/daemon.mjs +10 -1
  79. package/src/cli/export.mjs +3 -2
  80. package/src/cli/ingest-okf.mjs +12 -15
  81. package/src/cli/init.mjs +0 -85
  82. package/src/cli/lint.mjs +3 -2
  83. package/src/cli/plugin/copies.mjs +68 -0
  84. package/src/cli/plugin/create.mjs +22 -24
  85. package/src/cli/plugin/index.mjs +49 -3
  86. package/src/cli/plugin/search.mjs +19 -2
  87. package/src/cli/rebuild.mjs +2 -0
  88. package/src/cli/remember.mjs +23 -0
  89. package/src/cli/status.mjs +10 -3
  90. package/src/cli/update.mjs +3 -2
  91. package/src/core/action-predictor.mjs +161 -0
  92. package/src/core/app-deploy/runtime-cli/node.mjs.tmpl +20 -3
  93. package/src/core/app-deploy/source.mjs +16 -9
  94. package/src/core/automatic-brain-updates.mjs +6 -3
  95. package/src/core/brain-registry.mjs +19 -2
  96. package/src/core/brain-state.mjs +23 -0
  97. package/src/core/cli-commands.mjs +1 -0
  98. package/src/core/cli-maintenance.mjs +1 -1
  99. package/src/core/cli-semantic-index.mjs +1 -1
  100. package/src/core/command-surface.mjs +3 -3
  101. package/src/core/composed-command-resolution.mjs +21 -0
  102. package/src/core/config.mjs +84 -0
  103. package/src/core/confined-memory.mjs +93 -0
  104. package/src/core/context-telemetry.mjs +214 -0
  105. package/src/core/daemon-control.mjs +14 -43
  106. package/src/core/fast-recall.mjs +1 -1
  107. package/src/core/memory-brain.mjs +2 -0
  108. package/src/core/plugin-activation.mjs +38 -6
  109. package/src/core/plugin-bundle.mjs +54 -0
  110. package/src/core/plugin-catalog.mjs +1 -1
  111. package/src/core/plugin-context.mjs +1 -1
  112. package/src/core/plugin-contracts/card.mjs +69 -37
  113. package/src/core/plugin-loader.mjs +5 -6
  114. package/src/core/plugin-runner.mjs +13 -6
  115. package/src/core/plugin-runtime.mjs +5 -4
  116. package/src/core/plugin-setup.mjs +5 -3
  117. package/src/core/plugin-state-store.mjs +12 -1
  118. package/src/core/plugin-state.mjs +46 -5
  119. package/src/core/plugin-store.mjs +78 -3
  120. package/src/core/plugin-tasks.mjs +3 -1
  121. package/src/core/plugin-updates.mjs +117 -0
  122. package/src/core/plugin-vendor.mjs +10 -4
  123. package/src/core/project-brain.mjs +14 -41
  124. package/src/core/project-id.mjs +4 -1
  125. package/src/core/required-plugins.mjs +151 -13
  126. package/src/core/skills-registry.mjs +27 -3
  127. package/src/core/ssss-kernel-bridge.mjs +3 -1
  128. package/src/core/startup-health.mjs +66 -16
  129. package/src/core/surface.mjs +53 -46
  130. package/src/core/testing/plugin-fixture.mjs +69 -0
  131. package/src/core/vault-files.mjs +13 -0
  132. package/src/core/vault.mjs +4 -30
  133. package/src/server/index.mjs +13 -1
  134. package/src/server/invoke-decision-child.mjs +49 -0
  135. package/src/server/invoke-execution.mjs +87 -0
  136. package/src/server/invoke-policy.mjs +64 -0
  137. package/src/server/invoke-read-child.mjs +26 -0
  138. package/src/server/invoke-targets.mjs +49 -0
  139. package/src/server/invoke-write-child.mjs +19 -0
  140. package/src/server/routes/invoke.mjs +314 -0
  141. package/src/server/routes/plugins.mjs +1 -1
  142. package/scaffold/.agent/skills/plugins/SKILL.md +0 -57
  143. package/scaffold/.agent/skills/plugins/references/card-design.md +0 -55
  144. package/scaffold/.agent/skills/plugins/references/distribution.md +0 -23
  145. package/scaffold/.agent/skills/plugins/references/manifest-contract.md +0 -90
  146. package/scaffold/.agent/skills/plugins/references/optimized/index.md +0 -9
  147. package/scaffold/.agent/skills/plugins/references/optimized/manifest.json +0 -35
  148. package/scaffold/.agent/skills/plugins/references/optimized/original.md +0 -58
  149. package/scaffold/.agent/skills/plugins/references/optimized/section-01.md +0 -5
  150. package/scaffold/.agent/skills/plugins/references/optimized/section-02.md +0 -25
  151. package/scaffold/.agent/skills/plugins/references/optimized/section-03.md +0 -12
  152. package/scaffold/.agent/skills/plugins/references/optimized/section-04.md +0 -7
  153. package/scaffold/.agent/skills/plugins/references/optimized/section-05.md +0 -5
  154. package/scaffold/.agent/skills/total-recall/openwiki/README.md +0 -10
  155. package/scaffold/.agent/skills/total-recall/openwiki/architecture.md +0 -5
  156. package/scaffold/.agent/skills/total-recall/openwiki/ide.md +0 -10
  157. package/scaffold/.agent/skills/total-recall/openwiki/memory.md +0 -11
  158. package/scaffold/.agent/skills/total-recall/openwiki/secrets.md +0 -7
  159. package/scaffold/.agent/skills/total-recall/openwiki/skills.md +0 -7
  160. package/scaffold/openwiki/README.md +0 -10
  161. package/scaffold/openwiki/architecture.md +0 -5
  162. package/scaffold/openwiki/ide.md +0 -10
  163. package/scaffold/openwiki/memory.md +0 -11
  164. package/scaffold/openwiki/secrets.md +0 -7
  165. package/scaffold/openwiki/skills.md +0 -7
  166. package/src/core/okf-adapter.mjs +0 -559
  167. package/templates/openwiki/README.md +0 -10
  168. package/templates/openwiki/architecture.md +0 -5
  169. package/templates/openwiki/ide.md +0 -10
  170. package/templates/openwiki/memory.md +0 -11
  171. package/templates/openwiki/secrets.md +0 -7
  172. package/templates/openwiki/skills.md +0 -7
@@ -9,7 +9,7 @@
9
9
  "version": "0.1.1",
10
10
  "license": "MIT",
11
11
  "devDependencies": {
12
- "total-recall-brain": "3.40.4"
12
+ "total-recall-brain": "^3.40.7"
13
13
  }
14
14
  },
15
15
  "node_modules/@hexagon/base64": {
@@ -2556,9 +2556,9 @@
2556
2556
  }
2557
2557
  },
2558
2558
  "node_modules/total-recall-brain": {
2559
- "version": "3.40.4",
2560
- "resolved": "https://registry.npmjs.org/total-recall-brain/-/total-recall-brain-3.40.4.tgz",
2561
- "integrity": "sha512-/9JfUWyzXcgHu3kV/rqsOvclMY25PpfW4jSrunsCrkt2MPDUDfGD+z22AoA/OG/jSHE4ZvD/A9QV4IYE2+O99w==",
2559
+ "version": "3.40.7",
2560
+ "resolved": "https://registry.npmjs.org/total-recall-brain/-/total-recall-brain-3.40.7.tgz",
2561
+ "integrity": "sha512-G+sEWXVucI5Zs8uV1ie8P+mV/6cncWX76ES72T5dnPB3sFAwlcG9ous2SYTUaYUOETGB2vHTSo3cV4XWkHQ0Ww==",
2562
2562
  "dev": true,
2563
2563
  "license": "MIT",
2564
2564
  "workspaces": [
@@ -6,7 +6,6 @@
6
6
  "scripts": {
7
7
  "test": "node --test test/*.test.mjs"
8
8
  },
9
- "dependencies": {},
10
9
  "license": "MIT",
11
10
  "files": [
12
11
  "cli.mjs",
@@ -131,33 +131,5 @@
131
131
  "status": {
132
132
  "command": "status",
133
133
  "refresh_seconds": 300
134
- },
135
- "card_layout": {
136
- "template": "dashboard",
137
- "regions": [
138
- {
139
- "widget": "status",
140
- "title": "Status"
141
- },
142
- {
143
- "widget": "live",
144
- "title": "Live view"
145
- },
146
- {
147
- "widget": "list",
148
- "title": "Details",
149
- "source": {
150
- "command": "hubs"
151
- }
152
- },
153
- {
154
- "widget": "actions",
155
- "title": "Commands"
156
- },
157
- {
158
- "widget": "activity",
159
- "title": "Recent activity"
160
- }
161
- ]
162
134
  }
163
135
  }
@@ -10,7 +10,7 @@
10
10
  "license": "MIT",
11
11
  "devDependencies": {
12
12
  "jsdom": "^26.1.0",
13
- "total-recall-brain": "3.40.4"
13
+ "total-recall-brain": "^3.40.7"
14
14
  }
15
15
  },
16
16
  "node_modules/@asamuzakjp/css-color": {
@@ -2916,9 +2916,9 @@
2916
2916
  }
2917
2917
  },
2918
2918
  "node_modules/total-recall-brain": {
2919
- "version": "3.40.4",
2920
- "resolved": "https://registry.npmjs.org/total-recall-brain/-/total-recall-brain-3.40.4.tgz",
2921
- "integrity": "sha512-/9JfUWyzXcgHu3kV/rqsOvclMY25PpfW4jSrunsCrkt2MPDUDfGD+z22AoA/OG/jSHE4ZvD/A9QV4IYE2+O99w==",
2919
+ "version": "3.40.7",
2920
+ "resolved": "https://registry.npmjs.org/total-recall-brain/-/total-recall-brain-3.40.7.tgz",
2921
+ "integrity": "sha512-G+sEWXVucI5Zs8uV1ie8P+mV/6cncWX76ES72T5dnPB3sFAwlcG9ous2SYTUaYUOETGB2vHTSo3cV4XWkHQ0Ww==",
2922
2922
  "dev": true,
2923
2923
  "license": "MIT",
2924
2924
  "workspaces": [
@@ -259,37 +259,5 @@
259
259
  "distribution": {
260
260
  "tier": "official",
261
261
  "license": "open"
262
- },
263
- "card_layout": {
264
- "template": "vault",
265
- "regions": [
266
- {
267
- "widget": "status",
268
- "title": "Status"
269
- },
270
- {
271
- "widget": "live",
272
- "title": "Live view"
273
- },
274
- {
275
- "widget": "list",
276
- "title": "Details",
277
- "source": {
278
- "command": "platforms"
279
- }
280
- },
281
- {
282
- "widget": "actions",
283
- "title": "Commands"
284
- },
285
- {
286
- "widget": "credentials",
287
- "title": "Credentials"
288
- },
289
- {
290
- "widget": "activity",
291
- "title": "Recent activity"
292
- }
293
- ]
294
262
  }
295
263
  }
@@ -4,7 +4,7 @@ Auth is the credential owner and is shipped in Total Recall scaffold. Its source
4
4
 
5
5
  Discover `total-recall auth --help` and `total-recall auth secret --help`. The auth namespace is the only credential command path. Use `auth secret set KEY --stdin` for values, never argv, chat, logs or vault content. `auth secret list` and `catalog` expose metadata. Avoid `get` in a tool transcript; consumers resolve through the auth runtime in-process. Auth API lives under `/api/plugins/auth/secrets`; any retained legacy HTTP route is implemented by auth, never core.
6
6
 
7
- Select the store explicitly with the supported brain/store configuration. Existing carrier paths and encrypted data are preserved; no migration may overwrite credentials. No implicit merging of project/global stores or environment credential fallback. Auth alone manages its unlock carriers. Failed unlock/decryption must propagate; never report the store empty after failure. Rekey changes the master carrier, not provider keys: read the current rekey CLI and runbook, update every selected carrier, verify fresh-shell reads and retired-password rejection without exposing either password.
7
+ There is one secrets store per host: the global auth store. The CLI never selects a store from the cwd (`--project` and `--layer` are refused); `TR_SECRETS_BRAIN` is the only override, for deploy, ops and tests. A per-repo `secrets.enc` is breakage: fold it in with `auth secret merge-store <dir>` (a dry run unless `--apply`; conflicts are settled only with `--take` or `--rename`) and archive it encrypted. Existing carrier paths and encrypted data are preserved; no migration may overwrite credentials. No environment credential fallback. Auth alone manages its unlock carriers. Failed unlock/decryption must propagate; never report the store empty after failure. Rekey changes the master carrier, not provider keys: read the current rekey CLI and runbook, update every selected carrier, verify fresh-shell reads and retired-password rejection without exposing either password.
8
8
 
9
9
  For provider key setup, verify against an authenticated provider operation before saving; format-only checks and timeouts are not verification. Require HTTPS except explicit loopback development, reject redirects containing credentials, and return safe errors. Rotation follows verify → store/project → deploy/verify → revoke, respecting the provider's supported recipe and user authorization. Manual provider steps remain manual. Exported environment files are deployment projections, not an alternate credential authority.
10
10
 
@@ -22,6 +22,8 @@ Before uninstall, auth decrypts/verifies the source and retains byte-identical e
22
22
 
23
23
  Auth card/panel results represent completed operations only. Passkey registration requires browser credential creation and successful server verification. HTTP reachability is not provider authentication or a security audit. Configuration is not an active rotation schedule. The scaffold installs auth and resolves declared dependencies to compatible installed host packages; missing/incompatible dependencies fail initialization.
24
24
 
25
+ Production services own distinct, app-named keys bound to their repo with `provides` naming the app-facing variable; `auth secret get KEY` or `set KEY` run inside that repo resolves to the app's key, and elsewhere to the plain (developer) key. Read bindings, tags and provides with `auth secret list --json` (metadata only). Metadata writes never move a value's `updated_at`.
26
+
25
27
  Internal CLI consumers may use `auth secret get KEY --json`: a missing key returns `{found:false}`; found values remain private to the consuming process. Unlock, parsing and decryption failures are errors. `TR_SECRETS_BRAIN` selects one store for the complete operation; no project-to-global retry is permitted. Consumer transports must parse structured results, propagate failures, use stdin for writes and verify readback. Never run a value-returning command into an agent transcript.
26
28
 
27
29
  ## Mesh-identity secret sync
@@ -5,3 +5,7 @@
5
5
  Context returns the complete required rule set, not just a relevance-ranked search result. Treat unknown applicability conservatively. Explicit budgets govern readiness. `context:universal` is a curated permanent bootstrap, not an automatic property of every global rule. Do not infer local applicability from global descriptive facts.
6
6
 
7
7
  Use `compile` to rebuild instruction surfaces and indexes after externally maintained skill/rule sources change. Do not delete embeddings databases to force work. Inspect proposals through proposal operations; memory node enumeration excludes proposal documents. Embedding coverage counts eligible memory documents. SSSS registry/envelope validation and event receipts define persistence; projections are derived.
8
+
9
+ Compilation verifies instruction output bytes and canonical file bindings before recording disposable `surface-artifacts.json`; incremental skips require intact outputs as well as unchanged inputs. Missing or edited managed instruction outputs trigger repair. Actual client consumption remains a separate verification step.
10
+
11
+ OKF conversion, import/export, metadata checks and explicit `okf project` index/log generation belong to the OKF plugin. Core `export --okf`, `ingest okf` and `lint --okf` delegate to its declared active adapter and fail if the owner is unavailable. Core compilation never generates OKF index.md or log.md.
@@ -2,6 +2,8 @@
2
2
 
3
3
  OpenWiki is a plugin-owned documentation hub and ingestion capability. Discover `total-recall openwiki --help`, then `openwiki hubs --json`. Current hubs discovery reads Markdown files directly under the current project's `openwiki/` directory; ingestion recursively reads a supplied directory. The hub count is a filesystem inventory, not proof of prior graph indexing.
4
4
 
5
+ Core initialization does not create wiki pages. Use `total-recall openwiki bootstrap --brain <absolute-brain-dir> [--project-root <absolute-repo-dir>] --json` explicitly when seed documentation is wanted. `--dry-run` previews missing pages; existing authored pages and page symlinks are preserved. The OpenWiki plugin owns these templates and their bootstrap implementation.
6
+
5
7
  Read existing relevant hubs before changing architecture or capability boundaries. Maintain source-linked hubs for core architecture, plugin ownership, auth/secrets, CRM and current implementation/verification state. Use normal source edits for documentation Markdown; never edit canonical memory files directly. Keep secrets, personal vault contents and generated state out of hubs.
6
8
 
7
9
  Review `openwiki ingest <absolute-directory> --dry-run --project`, then ingest through the plugin without `--dry-run`. `--global` explicitly selects the global brain. The plugin routes each document through validated `remember`; read import/error totals and actual exit status. Verify resulting `openwiki-<path-slug>` documents with local recall. A dry run does not index anything. A backend health probe does not prove graph coverage. Partial imports must be reported and repaired.
@@ -12,6 +12,18 @@ For research queues, discover `research --help`, select project/global scope exp
12
12
 
13
13
  Publication/deployment use the owning push/deploy procedures when authorized. Shared production services require staged health-checked zero-downtime switching and rollback. Do not use a generated restart command as permission to interrupt a serving process.
14
14
 
15
+ ## Optional developer API
16
+
17
+ The full server's `/v1/invoke` requires a named auth-owned PAT with a literal `invoke:full` or `invoke:restricted` mode; legacy wildcards and dashboard sessions do not opt in. Full mode requires full grants throughout the issuer chain and intentionally grants trusted host administration, including auth-owned credentials and nested owner execution. Do not describe it as a sandbox or give it to a restricted consumer to bypass a denial.
18
+
19
+ Restricted `ssss.read` additionally requires `ssss:read` and `brain:server`, uses local server-brain retrieval and spends no provider credits. Restricted `ssss.write` requires `ssss:write` and `brain:server` and creates descriptive facts only through the shared memory owner with generated create-only paths, exact schemas and generator-free local indexing. The same owner supports local `remember fact "content" --confined-fact`. Arbitrary mutation metadata, rule categories, CLI/plugin/composed execution and paid decisions remain unavailable. Capabilities omit denied operations. Fresh role/issuer/expiry/revocation checks, controlled child environment, filesystem permissions, concurrency/time/output bounds and validated SSSS execution audit apply. Mutation errors preserve known commit/index state or report unknown commit state after interruption; effects already committed cannot be rolled back. Provider quotas, broader owner adapters and the complete API/launch journey remain separate acceptance work. Read the shipped `docs/reference/cli-reference.md` developer API contract before migration or execution.
20
+
15
21
  ## Uniform dependency updates
16
22
 
23
+ Project registration automatically creates and records its stable UUID through the existing identity owner. Malformed/non-object identities are preserved and fail explicitly; provisioning failure must not register an incomplete fallback. `project-id --all` is for legacy reconciliation, not a required step after ordinary registration.
24
+
25
+ Restricted memory also accepts `project:<uuid>` with the effective auth scope `brain:project-<uuid>` plus its read/write scope. Use existing brain registration/on/off, project-id and auth-key commands. Only registered, enabled, canonical identity-matched brains execute; discovery lists granted usable IDs, never paths. Running work pins and revalidates that binding; removal, disablement or identity/path changes stop continuation. Project-only keys have no implicit server access. Writes retain the closed descriptive fact schema and validated SSSS owner.
26
+
27
+ Full-mode `decision.run` and `decision.predict` execute the installed owner in bounded children, with auth-owner credential resolution inside the child. Timeout, output overflow, client disconnect and revoked authority terminate local continuation. Decision failure envelopes suppress child diagnostics; credential/provider failures are explicit. Cancellation cannot reverse accepted remote billing. Spending quotas and broader restricted adapters remain separate acceptance work.
28
+
17
29
  Use `total-recall update --all-brains` to plan both SSSS and Total Recall updates across registered brains, installed plugin owners and nested consumers. Add `--apply` to pin the resolved published releases, refresh npm/pnpm locks and verify actual package resolution; `--json` returns per-consumer results and failures. Extra roots use repeatable `--repo` or `TR_SYNC_REPOS`. Every consumer owns a local installation: a shared node_modules link is detached without mutating its former target and restored on failure. Missing versions, unsupported managers, newer previews and verification mismatches fail explicitly. This updates local dependencies; it does not deploy services or merge brains.
package/src/cli/brain.mjs CHANGED
@@ -16,6 +16,10 @@ function printHelp() { console.log(`
16
16
  register <project-path> Track any project path (full brain + registry)
17
17
  unregister <project-path> Remove a project directory path from the registry
18
18
  ensure <project-path> Ensure a full project brain layout + register
19
+ import <vault-dir> --to <project-path> [--dry-run]
20
+ Import every memory node from another vault directory
21
+ (an archive or a retired brain) into that project's
22
+ brain through validated writes; existing slugs are kept
19
23
 
20
24
  Any repo works — pass absolute or relative paths you choose. No product defaults.
21
25
 
@@ -27,6 +31,7 @@ function printHelp() { console.log(`
27
31
  npx total-recall brain off hermes-agent
28
32
  npx total-recall brain on global
29
33
  npx total-recall brain unregister /path/to/project
34
+ npx total-recall brain import ~/Archive/old-brain/memory-vault --to ~/code/my-lib
30
35
 
31
36
  Skill multi-repo sync: registered projects + TR_SYNC_REPOS + skill track/--repo
32
37
  `);
@@ -58,6 +63,9 @@ export default async function brain(args) {
58
63
  case 'ensure':
59
64
  await handleEnsure(args.slice(1), globalBrainDir);
60
65
  break;
66
+ case 'import':
67
+ await handleImport(args.slice(1));
68
+ break;
61
69
  case 'on':
62
70
  case 'off':
63
71
  await handleToggle(subcommand.toLowerCase() === 'on', args.slice(1), globalBrainDir);
@@ -104,11 +112,14 @@ async function handleEnsure(targetArgs, globalBrainDir) {
104
112
  tags: ['project-brain', 'full-brain'],
105
113
  });
106
114
  const health = inspectProjectBrain(abs);
115
+ const { ensureProjectGitignore } = await import('./init.mjs');
116
+ const ignored = ensureProjectGitignore(abs);
107
117
  console.log(`\n ✅ Full project brain ready`);
108
118
  console.log(` Repo: ${result.repoRoot}`);
109
119
  console.log(` Brain: ${result.brainDir}`);
110
120
  console.log(` complete=${health.complete} full_brain=${health.full_brain}`);
111
- console.log(` openwiki files +${result.openwiki?.files_added || 0}, dirs +${result.dirs_created}`);
121
+ console.log(` directories created +${result.dirs_created}`);
122
+ if (ignored.length) console.log(` .gitignore +${ignored.length} brain-state exclusions`);
112
123
  console.log('');
113
124
  }
114
125
 
@@ -213,7 +224,7 @@ async function handleRegister(registryPath, targetArgs) {
213
224
  process.exit(1);
214
225
  }
215
226
 
216
- // Full project brain for any user repo (vault, openwiki, sessions, …)
227
+ // Full project brain for any user repo (vault, sessions, registry, …)
217
228
  try {
218
229
  const { ensureFullProjectBrain } = await import('../core/project-brain.mjs');
219
230
  const globalBrainDir = path.join(getGlobalAgentDir(), 'skills', 'total-recall');
@@ -224,8 +235,15 @@ async function handleRegister(registryPath, targetArgs) {
224
235
  register: true,
225
236
  });
226
237
  console.log(` ✅ Full project brain ready at ${path.join(absoluteRoot, '.agent', 'skills', 'total-recall')}`);
238
+ // A registered repo carries a brain whose config holds a live PAT; keep it
239
+ // out of git the same way `init --project` does.
240
+ const { ensureProjectGitignore } = await import('./init.mjs');
241
+ const ignored = ensureProjectGitignore(absoluteRoot);
242
+ if (ignored.length) console.log(` ✅ .gitignore +${ignored.length} brain-state exclusions`);
227
243
  } catch (err) {
228
244
  console.error(` ⚠️ Could not fully provision brain layout: ${err.message}`);
245
+ process.exitCode = 1;
246
+ return;
229
247
  }
230
248
 
231
249
  const brainDir = path.join(absoluteRoot, '.agent', 'skills', 'total-recall');
@@ -298,6 +316,58 @@ async function handleUnregister(registryPath, targetArgs) {
298
316
  console.log(` ✅ Successfully unregistered project: "${absoluteRoot}"`);
299
317
  }
300
318
 
319
+ /**
320
+ * Import memory nodes from a vault directory into a project's brain.
321
+ *
322
+ * The source is read, never written: an archived brain, or the vault of a brain
323
+ * being retired. Every node goes through the validated SSSS write path at the
324
+ * same vault-relative path, so the target's event log records each one. A slug
325
+ * the target already holds is left alone, which makes a rerun safe.
326
+ */
327
+ async function handleImport(targetArgs) {
328
+ const toIdx = targetArgs.indexOf('--to');
329
+ const source = targetArgs.find((a, i) => !a.startsWith('-') && i !== toIdx + 1);
330
+ const target = toIdx !== -1 ? targetArgs[toIdx + 1] : null;
331
+ const dryRun = targetArgs.includes('--dry-run');
332
+ if (!source || !target) {
333
+ console.error(' ⚠️ Usage: npx total-recall brain import <vault-dir> --to <project-path> [--dry-run]');
334
+ process.exit(1);
335
+ }
336
+ const sourceDir = path.resolve(source);
337
+ const projectRoot = path.resolve(target);
338
+ if (!fs.existsSync(sourceDir) || !fs.statSync(sourceDir).isDirectory()) {
339
+ console.error(` ⚠️ Source vault not found: ${sourceDir}`);
340
+ process.exit(1);
341
+ }
342
+ const vaultDir = path.join(projectRoot, '.agent', 'skills', 'total-recall', 'memory-vault');
343
+ if (!fs.existsSync(vaultDir)) {
344
+ console.error(` ⚠️ No project brain at ${projectRoot}. Run: npx total-recall brain register ${projectRoot}`);
345
+ process.exit(1);
346
+ }
347
+ if (path.resolve(sourceDir) === path.resolve(vaultDir)) {
348
+ console.error(' ⚠️ Source and target are the same vault.');
349
+ process.exit(1);
350
+ }
351
+ const { loadNodes } = await import('../core/vault.mjs');
352
+ const { writeNodeValidatedAsync } = await import('../core/validated-write.mjs');
353
+ const existing = new Set(loadNodes(vaultDir).map(n => n.slug));
354
+ let imported = 0, skipped = 0;
355
+ const failed = [];
356
+ for (const node of loadNodes(sourceDir)) {
357
+ if (existing.has(node.slug)) { skipped++; continue; }
358
+ const rel = path.relative(sourceDir, node._filePath).split(path.sep).join('/');
359
+ if (dryRun) { imported++; continue; }
360
+ const { _filePath, _filepath, ...clean } = node;
361
+ const result = await writeNodeValidatedAsync(clean, vaultDir, { path: rel });
362
+ if (result.success) { imported++; existing.add(node.slug); }
363
+ else failed.push(`${rel}: ${result.validation?.errors?.join('; ') || result.error}`);
364
+ }
365
+ const verb = dryRun ? 'Would import' : 'Imported';
366
+ console.log(` ${failed.length ? '⚠️ ' : '✅'} ${verb} ${imported} node(s) into ${vaultDir}; ${skipped} already present`);
367
+ for (const line of failed) console.error(` ✗ ${line}`);
368
+ if (failed.length) process.exitCode = 1;
369
+ }
370
+
301
371
  function countMdFiles(dir) {
302
372
  if (!fs.existsSync(dir)) return 0;
303
373
  let count = 0;
@@ -25,16 +25,20 @@ export const CLIENTS = {
25
25
  },
26
26
  hermes: {
27
27
  label: 'Hermes Agent',
28
- mode: 'hermes',
29
- memoryPath: path.join(os.homedir(), '.hermes', 'memories', 'MEMORY.md'),
30
- userPath: path.join(os.homedir(), '.hermes', 'memories', 'USER.md'),
28
+ mode: 'symlink',
29
+ // Hermes loads the AGENTS.md chain (git root to cwd) as context files.
30
+ // ~/.hermes/memories/MEMORY.md is the agent's own notes store, read only
31
+ // from HERMES_HOME; Total Recall never writes it.
32
+ target: 'AGENTS.md',
31
33
  skillsProjection: { scope: 'project', dir: path.join('.hermes', 'skills') }
32
34
  },
33
35
  'hermes-agent': {
34
36
  label: 'Hermes Agent',
35
- mode: 'hermes',
36
- memoryPath: path.join(os.homedir(), '.hermes', 'memories', 'MEMORY.md'),
37
- userPath: path.join(os.homedir(), '.hermes', 'memories', 'USER.md'),
37
+ mode: 'symlink',
38
+ // Hermes loads the AGENTS.md chain (git root to cwd) as context files.
39
+ // ~/.hermes/memories/MEMORY.md is the agent's own notes store, read only
40
+ // from HERMES_HOME; Total Recall never writes it.
41
+ target: 'AGENTS.md',
38
42
  skillsProjection: { scope: 'project', dir: path.join('.hermes', 'skills') }
39
43
  },
40
44
  dsh: {
@@ -884,39 +888,6 @@ export default async function connect(args) {
884
888
  result.projection = { targetPath, action: 'symlinked' };
885
889
  }
886
890
  result.notes.push(` ~/.pi/agent/AGENTS.md → ${instructionsPath}`);
887
- } else if (preset.mode === 'hermes') {
888
- // Hermes: write compiled MEMORY.md to ~/.hermes/memories/MEMORY.md (max 2200 chars)
889
- // and project-local .hermes/memories/MEMORY.md if inside a project workspace
890
- const instructions = readInstructions(cwd, agentDir);
891
- if (!instructions) throw new Error('No INSTRUCTIONS.md found. Run npx total-recall init or compile first.');
892
- const homeDir = process.env.HOME || os.homedir();
893
- const globalMemPath = path.join(homeDir, '.hermes', 'memories', 'MEMORY.md');
894
- const capped = instructions.slice(0, 2200);
895
-
896
- let wroteGlobal = false;
897
- try {
898
- fs.mkdirSync(path.dirname(globalMemPath), { recursive: true });
899
- fs.writeFileSync(globalMemPath, capped, 'utf8');
900
- wroteGlobal = true;
901
- } catch {
902
- // Gracefully continue if global directory is unwritable in sandbox
903
- }
904
-
905
- let localMemPath = null;
906
- if (!isHome) {
907
- localMemPath = path.join(cwd, '.hermes', 'memories', 'MEMORY.md');
908
- fs.mkdirSync(path.dirname(localMemPath), { recursive: true });
909
- fs.writeFileSync(localMemPath, capped, 'utf8');
910
- }
911
-
912
- result.projection = { targetPath: localMemPath || globalMemPath, action: 'written' };
913
- if (wroteGlobal) {
914
- result.notes.push(` Hermes MEMORY.md (${capped.length} chars) → ${globalMemPath}`);
915
- }
916
- if (localMemPath) {
917
- result.notes.push(` Hermes local MEMORY.md → ${localMemPath}`);
918
- }
919
- result.notes.push(' Note: Hermes has a 2,200-char limit on MEMORY.md. Total Recall auto-caps this.');
920
891
  } else if (preset.mode === 'dsh') {
921
892
  // DeepSeek Harness: write global ~/.dsh/memory/MEMORY.md and symlink project AGENTS.md
922
893
  const instructions = readInstructions(cwd, agentDir);
@@ -0,0 +1,104 @@
1
+ /**
2
+ * total-recall context-stats — read the capsule measurement ledger.
3
+ *
4
+ * Answers the questions a context-policy decision actually needs:
5
+ * - Which actions overflow, and how often (a rate, not an anecdote)?
6
+ * - How close is the required set to the budget, per action?
7
+ * - Which rules are force-included on every call?
8
+ *
9
+ * Read-only. Measurement is recorded by `total-recall context`.
10
+ */
11
+ import path from 'node:path';
12
+ import { getBothBrains, parseLayerFlag } from './agent-dir.mjs';
13
+ import { readLedger, summariseLedger, ledgerPath, telemetryEnabled } from '../core/context-telemetry.mjs';
14
+ import { readConfigValue } from './config.mjs';
15
+
16
+ const pct = (n) => `${Math.round(n * 100)}%`;
17
+
18
+ function renderSummary(summary, { budget, ledger }) {
19
+ const lines = [];
20
+ if (summary.samples === 0) {
21
+ lines.push('No capsule measurements recorded yet.');
22
+ lines.push('');
23
+ lines.push('Every `total-recall context` call records one line. Run a few, then re-check.');
24
+ return lines.join('\n');
25
+ }
26
+ lines.push(`Capsule measurements: ${summary.samples} sample(s)`);
27
+ lines.push(`Range: ${summary.first_at} → ${summary.last_at}`);
28
+ if (budget) lines.push(`Configured budget: ${budget}`);
29
+ lines.push('');
30
+ lines.push('By action:');
31
+ lines.push(' action samples overflow required(avg/max) excluded');
32
+ for (const a of summary.actions) {
33
+ lines.push(` ${String(a.action).padEnd(12)} ${String(a.samples).padStart(7)} ${pct(a.overflow_rate).padStart(8)} ${String(a.required_avg).padStart(8)}/${String(a.required_max).padEnd(8)} ${a.excluded_total}`);
34
+ }
35
+ if (budget) {
36
+ const worst = summary.actions[0];
37
+ if (worst) {
38
+ lines.push('');
39
+ const head = worst.required_max - budget;
40
+ lines.push(head > 0
41
+ ? `Headroom: NEGATIVE on '${worst.action}' by ${head} tokens at its largest sample.`
42
+ : `Headroom: ${budget - worst.required_max} tokens at the largest required set ('${worst.action}').`);
43
+ }
44
+ }
45
+ if (summary.most_required.length) {
46
+ lines.push('');
47
+ lines.push('Rules included most often (candidates for action-scoping):');
48
+ for (const r of summary.most_required.slice(0, 15)) {
49
+ lines.push(` ${String(r.appearances).padStart(6)}x ${r.id}`);
50
+ }
51
+ }
52
+ lines.push('');
53
+ lines.push(`Ledger: ${ledger}`);
54
+ lines.push('Identifiers and counts only; never rule text or capsule content.');
55
+ return lines.join('\n');
56
+ }
57
+
58
+ export default async function contextStats(args = []) {
59
+ if (args.includes('--help') || args.includes('-h')) {
60
+ console.log('Usage: total-recall context-stats [--json] [--limit N] [--project|--global]\n\nRead-only summary of capsule measurements recorded by `total-recall context`.\nReports overflow rate per action, required-token headroom, and which rules are\nincluded most often (the input to action-scoping a rule).\n\nEnvironment: TR_CONTEXT_TELEMETRY=off stops recording (this command then reports\nno samples). TR_CONTEXT_LEDGER_MAX_BYTES caps the ledger (default 8 MiB).');
61
+ return;
62
+ }
63
+ // parseLayerFlag consumes --global/--project and returns what is left, so the
64
+ // loop must read `remainingArgs`; reading `args` re-rejected the layer flag.
65
+ const { layer, remainingArgs } = parseLayerFlag(args);
66
+ let isJson = false, limit = 0;
67
+ for (let i = 0; i < remainingArgs.length; i++) {
68
+ if (remainingArgs[i] === '--json') { isJson = true; continue; }
69
+ if (remainingArgs[i] === '--limit') { limit = Number(remainingArgs[++i]) || 0; continue; }
70
+ // Reject an unknown flag rather than ignoring it: a silently dropped
71
+ // --globel would report project scope while the operator believed
72
+ // otherwise, and this command exists to be trusted about scope.
73
+ throw new Error(`Unknown context-stats option: ${remainingArgs[i]}`);
74
+ }
75
+
76
+ const brains = getBothBrains();
77
+ const own = layer !== 'global' && brains.project ? brains.project.brainDir : null;
78
+ const global = layer !== 'project' && brains.global ? brains.global.brainDir : null;
79
+ const brainDir = own || global;
80
+ if (!brainDir) throw new Error('No enabled brain in selected scope');
81
+ const derivedDir = path.join(brainDir, 'memory-derived');
82
+
83
+ const records = readLedger(derivedDir, { limit });
84
+ const summary = summariseLedger(records);
85
+ const budget = (() => {
86
+ for (const candidate of [layer === 'global' ? 'global' : 'project', 'global']) {
87
+ try { const v = readConfigValue('context_budget', candidate); if (Number.isFinite(v) && v > 0) return v; } catch { /* next layer */ }
88
+ }
89
+ return null;
90
+ })();
91
+
92
+ if (isJson) {
93
+ console.log(JSON.stringify({
94
+ enabled: telemetryEnabled(), budget, ledger: ledgerPath(derivedDir),
95
+ ...summary,
96
+ }, null, 2));
97
+ return;
98
+ }
99
+ if (!telemetryEnabled()) {
100
+ console.log('Capsule telemetry is off (TR_CONTEXT_TELEMETRY=off). No measurements are recorded.');
101
+ return;
102
+ }
103
+ console.log(renderSummary(summary, { budget, ledger: ledgerPath(derivedDir) }));
104
+ }
@@ -6,6 +6,7 @@ import { compileContext, capsuleResponse, renderCapsule } from '../core/context-
6
6
  import { isBrainEnabled } from '../core/brain-registry.mjs';
7
7
  import { surfaceInputsHash } from '../core/command-surface.mjs';
8
8
  import { readConfigValue } from './config.mjs';
9
+ import { recordCapsule } from '../core/context-telemetry.mjs';
9
10
 
10
11
  export default async function context(args = []) {
11
12
  if (!args.length || args.includes('--help')) {
@@ -46,6 +47,13 @@ export default async function context(args = []) {
46
47
  derivedDir, contributions: legacyRuleContributions(skillsDir), versionInputs: surfaceInputsHash({ skillsDir }) });
47
48
  if (debug && format === 'text') throw new Error('--debug requires --format json');
48
49
  const response = capsuleResponse(result, { total: budget, debug, format });
50
+ // Measured before the admission branch, so a capsule that failed to fit is
51
+ // recorded too. Those refusals are the samples the budget decision needs, and
52
+ // a measurement that only counts successes would hide the exact case it
53
+ // exists to explain.
54
+ recordCapsule({ ...result.stats, total_tokens: result.stats.total_tokens }, {
55
+ derivedDir, action: actions, query, consumer: 'cli',
56
+ });
49
57
  if (!response.ready && !debug) {
50
58
  // Admission failed: emitting bodies here makes each budget retry load the
51
59
  // same rules again. Keep the full set in the compiler/API, and admit it only
@@ -18,7 +18,7 @@ import os from 'node:os';
18
18
  import path from 'node:path';
19
19
  import { fileURLToPath } from 'node:url';
20
20
  import { resolveBrainDir } from './agent-dir.mjs';
21
- import { startDaemon, stopDaemon, readPid } from '../core/daemon-control.mjs';
21
+ import { startDaemon, stopDaemon, readPid, getDaemonObservation } from '../core/daemon-control.mjs';
22
22
 
23
23
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
24
24
  const ROOT = path.join(__dirname, '..', '..');
@@ -208,6 +208,14 @@ export default async function daemon(args) {
208
208
  const useSystemd = hasSystemd();
209
209
  const useLaunchd = !useSystemd && hasLaunchd();
210
210
 
211
+ // Managers must honor the same brain lock as direct lifecycle operations.
212
+ if (['start', 'ensure', 'stop'].includes(subcommand)) {
213
+ const observation = getDaemonObservation();
214
+ if (['conflict', 'unknown'].includes(observation.status)) {
215
+ throw new Error(`Daemon ${subcommand} refused: ${observation.reason || observation.status}; expected ${observation.expected_entry}${observation.entry ? `, observed ${observation.entry}` : ''}`);
216
+ }
217
+ }
218
+
211
219
  switch (subcommand) {
212
220
  case 'ensure': {
213
221
  if(!useSystemd)throw new Error('Managed daemon ensure currently requires systemd on the daemon host');
@@ -253,6 +261,7 @@ export default async function daemon(args) {
253
261
  else await directStop();
254
262
  break;
255
263
  case 'status':
264
+ console.log(JSON.stringify({ daemon: getDaemonObservation() }));
256
265
  if (useSystemd) systemdStatus();
257
266
  else if (useLaunchd) launchctlStatus();
258
267
  else directStatus();
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { parseLayerFlag, resolveBrainDir } from './agent-dir.mjs';
4
- import { exportBundle } from '../core/okf-adapter.mjs';
4
+ import { loadPluginModule } from '../core/plugin-runtime.mjs';
5
5
 
6
6
  export default async function exportCommand(args) {
7
7
  const { layer, remainingArgs } = parseLayerFlag(args);
@@ -51,6 +51,7 @@ export default async function exportCommand(args) {
51
51
  console.log(` 📂 Destination: ${opts.outputPath} (Format: ${opts.format})`);
52
52
 
53
53
  try {
54
+ const { exportBundle } = await loadPluginModule('okf', 'adapter', { activeRequired: true });
54
55
  const report = await exportBundle(vaultDir, opts.outputPath, {
55
56
  format: opts.format,
56
57
  stripSsss: opts.stripSsss
@@ -63,7 +64,7 @@ export default async function exportCommand(args) {
63
64
  console.log(` ✅ Export completed successfully.\n`);
64
65
  } catch (err) {
65
66
  console.error(`\n ❌ Export failed: ${err.message}\n`);
66
- process.exit(1);
67
+ process.exitCode = 1;
67
68
  }
68
69
  }
69
70
 
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { parseLayerFlag, resolveBrainDir } from './agent-dir.mjs';
4
- import { importBundle } from '../core/okf-adapter.mjs';
4
+ import { loadPluginModule } from '../core/plugin-runtime.mjs';
5
5
 
6
6
  export async function runOkfIngest(args) {
7
7
  const { layer, remainingArgs } = parseLayerFlag(args);
@@ -69,6 +69,7 @@ export async function runOkfIngest(args) {
69
69
  console.log(` 🧠 Target Brain: ${layer} (${vaultDir})`);
70
70
  if (opts.dryRun) console.log(' ⚠️ DRY RUN: No actual writes will be committed.');
71
71
 
72
+ const { importBundle } = await loadPluginModule('okf', 'adapter', { activeRequired: true });
72
73
  const report = await importBundle(opts.bundlePath, vaultDir, {
73
74
  dryRun: opts.dryRun,
74
75
  category: opts.category,
@@ -94,23 +95,19 @@ export async function runOkfIngest(args) {
94
95
  for (const item of report.errors) {
95
96
  console.log(` • ${item.file}: ${item.error}`);
96
97
  }
97
- process.exit(1);
98
+ process.exitCode = 1;
99
+ return;
98
100
  }
99
101
 
100
102
  if (report.imported.length > 0 && !opts.dryRun) {
101
- // Recompile active memory surfaces and indexes in the background to avoid blocking the CLI call.
102
- console.log('\n ⏳ Recompiling active memory surfaces and indexes in the background...');
103
- try {
104
- const { spawn } = await import('node:child_process');
105
- const child = spawn(process.argv[0], [process.argv[1], 'compile'], {
106
- detached: true,
107
- stdio: 'ignore'
108
- });
109
- child.unref();
110
- console.log(' ✅ Background compilation started.');
111
- } catch (err) {
112
- console.warn(` ⚠️ Background recompilation spawn failed: ${err.message}`);
113
- }
103
+ console.log('\n ⏳ Recompiling memory surfaces and indexes...');
104
+ const { spawn } = await import('node:child_process');
105
+ await new Promise((resolve, reject) => {
106
+ const child = spawn(process.argv[0], [process.argv[1], 'compile', ...(layer === 'project' ? ['--project'] : layer === 'global' ? ['--global'] : [])], { stdio: 'inherit' });
107
+ child.once('error', reject);
108
+ child.once('exit', (code, signal) => code === 0 ? resolve() : reject(new Error(`Compilation failed (${signal || code})`)));
109
+ });
110
+ console.log(' ✅ Compilation completed.');
114
111
  }
115
112
  }
116
113