dsh-mnemon 0.1.1 → 0.1.2

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 (102) hide show
  1. package/README.en.md +4 -3
  2. package/README.md +4 -3
  3. package/cordis.patch.yml +1 -0
  4. package/docs/en/configuration.md +11 -6
  5. package/docs/en/getting-started.md +6 -4
  6. package/docs/en/interfaces.md +5 -3
  7. package/docs/en/operations.md +3 -2
  8. package/docs/en/project-overview.md +3 -1
  9. package/docs/en/roadmap.md +1 -1
  10. package/docs/en/storage-model.md +1 -1
  11. package/docs/zh-CN/configuration.md +11 -6
  12. package/docs/zh-CN/getting-started.md +6 -4
  13. package/docs/zh-CN/interfaces.md +5 -3
  14. package/docs/zh-CN/operations.md +3 -2
  15. package/docs/zh-CN/project-overview.md +3 -1
  16. package/docs/zh-CN/roadmap.md +1 -1
  17. package/docs/zh-CN/storage-model.md +1 -1
  18. package/lib/client.js +806 -421
  19. package/lib/client.js.map +1 -1
  20. package/lib/index.js +276 -92
  21. package/lib/types/client/MnemonSettingsCard.d.ts +1 -3
  22. package/lib/types/client/MnemonSettingsCard.d.ts.map +1 -1
  23. package/lib/types/client/MnemonSettingsCard.js +10 -27
  24. package/lib/types/client/MnemonSettingsCard.js.map +1 -1
  25. package/lib/types/client/MnemonView.d.ts +13 -0
  26. package/lib/types/client/MnemonView.d.ts.map +1 -1
  27. package/lib/types/client/MnemonView.js +14 -6
  28. package/lib/types/client/MnemonView.js.map +1 -1
  29. package/lib/types/client/api.d.ts +3 -1
  30. package/lib/types/client/api.d.ts.map +1 -1
  31. package/lib/types/client/api.js +31 -23
  32. package/lib/types/client/api.js.map +1 -1
  33. package/lib/types/client/index.d.ts +1 -1
  34. package/lib/types/client/index.d.ts.map +1 -1
  35. package/lib/types/client/index.js +42 -29
  36. package/lib/types/client/index.js.map +1 -1
  37. package/lib/types/client/locales.d.ts +32 -12
  38. package/lib/types/client/locales.d.ts.map +1 -1
  39. package/lib/types/client/locales.js +42 -22
  40. package/lib/types/client/locales.js.map +1 -1
  41. package/lib/types/client/sidebar-entry.d.ts +6 -0
  42. package/lib/types/client/sidebar-entry.d.ts.map +1 -0
  43. package/lib/types/client/sidebar-entry.js +132 -0
  44. package/lib/types/client/sidebar-entry.js.map +1 -0
  45. package/lib/types/client/workspace-controller.d.ts +15 -0
  46. package/lib/types/client/workspace-controller.d.ts.map +1 -0
  47. package/lib/types/client/workspace-controller.js +21 -0
  48. package/lib/types/client/workspace-controller.js.map +1 -0
  49. package/lib/types/client/workspace-mount.d.ts +8 -0
  50. package/lib/types/client/workspace-mount.d.ts.map +1 -0
  51. package/lib/types/client/workspace-mount.js +135 -0
  52. package/lib/types/client/workspace-mount.js.map +1 -0
  53. package/lib/types/commands.d.ts +10 -2
  54. package/lib/types/commands.d.ts.map +1 -1
  55. package/lib/types/commands.js +5 -1
  56. package/lib/types/commands.js.map +1 -1
  57. package/lib/types/config.d.ts +5 -2
  58. package/lib/types/config.d.ts.map +1 -1
  59. package/lib/types/config.js +2 -0
  60. package/lib/types/config.js.map +1 -1
  61. package/lib/types/contracts.d.ts +11 -0
  62. package/lib/types/contracts.d.ts.map +1 -1
  63. package/lib/types/documents.d.ts.map +1 -1
  64. package/lib/types/documents.js +6 -14
  65. package/lib/types/documents.js.map +1 -1
  66. package/lib/types/guidance.d.ts +3 -1
  67. package/lib/types/guidance.d.ts.map +1 -1
  68. package/lib/types/guidance.js +12 -0
  69. package/lib/types/guidance.js.map +1 -1
  70. package/lib/types/index.d.ts.map +1 -1
  71. package/lib/types/index.js +7 -7
  72. package/lib/types/index.js.map +1 -1
  73. package/lib/types/lifecycle.d.ts +9 -2
  74. package/lib/types/lifecycle.d.ts.map +1 -1
  75. package/lib/types/lifecycle.js +8 -1
  76. package/lib/types/lifecycle.js.map +1 -1
  77. package/lib/types/live-runtime.d.ts +26 -2
  78. package/lib/types/live-runtime.d.ts.map +1 -1
  79. package/lib/types/live-runtime.js +73 -3
  80. package/lib/types/live-runtime.js.map +1 -1
  81. package/lib/types/rpc.d.ts +6 -3
  82. package/lib/types/rpc.d.ts.map +1 -1
  83. package/lib/types/rpc.js +116 -19
  84. package/lib/types/rpc.js.map +1 -1
  85. package/lib/types/runner.d.ts +1 -1
  86. package/lib/types/runner.d.ts.map +1 -1
  87. package/lib/types/runner.js +2 -2
  88. package/lib/types/runner.js.map +1 -1
  89. package/lib/types/service.d.ts +16 -0
  90. package/lib/types/service.d.ts.map +1 -1
  91. package/lib/types/service.js.map +1 -1
  92. package/lib/types/settings.js +1 -1
  93. package/lib/types/settings.js.map +1 -1
  94. package/lib/types/subagent.d.ts +11 -2
  95. package/lib/types/subagent.d.ts.map +1 -1
  96. package/lib/types/subagent.js +34 -29
  97. package/lib/types/subagent.js.map +1 -1
  98. package/lib/types/tools.d.ts +11 -1
  99. package/lib/types/tools.d.ts.map +1 -1
  100. package/lib/types/tools.js +27 -16
  101. package/lib/types/tools.js.map +1 -1
  102. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -33,6 +33,7 @@ const Config = z.object({
33
33
  timeoutMs: z.number().step(1).min(100).max(12e4).default(DEFAULT_TIMEOUT_MS),
34
34
  defaultRecallLimit: z.number().step(1).min(1).max(50).default(10),
35
35
  routingGuidance: z.boolean().default(true),
36
+ displayMode: z.union(["sidebar", "buildin"]).default("sidebar"),
36
37
  tabEnabled: z.boolean().default(true),
37
38
  writeEnabled: z.boolean().default(true),
38
39
  lifecycleEnabled: z.boolean().default(true),
@@ -117,6 +118,7 @@ function resolveConfig(config = {}) {
117
118
  timeoutMs: config.timeoutMs ?? 1e4,
118
119
  defaultRecallLimit: config.defaultRecallLimit ?? 10,
119
120
  routingGuidance: config.routingGuidance ?? true,
121
+ displayMode: config.displayMode ?? "sidebar",
120
122
  tabEnabled: config.tabEnabled ?? true,
121
123
  writeEnabled: config.writeEnabled ?? true,
122
124
  lifecycleEnabled: config.lifecycleEnabled ?? true,
@@ -132,6 +134,9 @@ function resolveConfig(config = {}) {
132
134
  }
133
135
  //#endregion
134
136
  //#region lib/types/commands.js
137
+ function isAgentServiceSource(value) {
138
+ return "forAgent" in value && typeof value.forAgent === "function";
139
+ }
135
140
  const USAGE = "用法:/mnemon [status|recall <查询>|related <ID>|remember <内容>|forget <ID>]";
136
141
  function error(text) {
137
142
  return {
@@ -166,7 +171,8 @@ function splitInput(rawInput) {
166
171
  argument: input.slice(separator).trim()
167
172
  };
168
173
  }
169
- async function execute(service, coordinator, invocation) {
174
+ async function execute(serviceOrSource, coordinator, invocation) {
175
+ const service = isAgentServiceSource(serviceOrSource) ? serviceOrSource.forAgent(invocation.agent).service : serviceOrSource;
170
176
  const { verb, argument } = splitInput(invocation.rawInput);
171
177
  switch (verb) {
172
178
  case "status": {
@@ -762,26 +768,19 @@ var DocumentManager = class {
762
768
  }
763
769
  forWorkspace(workspaceRoot) {
764
770
  const root = resolve(workspaceRoot);
765
- let controller = this.controllers.get(root);
771
+ const storageRoot = this.storageRoot?.();
772
+ const key = storageRoot === void 0 ? root : `${resolve(storageRoot)}\0${root}`;
773
+ let controller = this.controllers.get(key);
766
774
  if (controller === void 0) {
767
- controller = new DocumentController(root, this.limitBytes, this.now);
768
- this.controllers.set(root, controller);
775
+ controller = new DocumentController(root, this.limitBytes, this.now, storageRoot);
776
+ this.controllers.set(key, controller);
769
777
  }
770
778
  return controller;
771
779
  }
772
780
  forAgent(agent) {
773
781
  const cwd = agent.session.header?.cwd;
774
782
  if (cwd === void 0 || cwd.trim() === "") throw new Error("the current DSH session has no workspace for Mnemon Documents");
775
- if (this.storageRoot === void 0) return this.forWorkspace(cwd);
776
- const storageRoot = resolve(this.storageRoot());
777
- const root = resolve(cwd);
778
- const key = `${storageRoot}\0${root}`;
779
- let controller = this.controllers.get(key);
780
- if (controller === void 0) {
781
- controller = new DocumentController(root, this.limitBytes, this.now, storageRoot);
782
- this.controllers.set(key, controller);
783
- }
784
- return controller;
783
+ return this.forWorkspace(cwd);
785
784
  }
786
785
  };
787
786
  //#endregion
@@ -792,6 +791,9 @@ const ROUTING_GUIDANCE = "Use memory only by need. For substantial project recor
792
791
  function systemPrompt(ctx) {
793
792
  return ctx.get("systemPrompt");
794
793
  }
794
+ function scopedSystemPrompt(agent) {
795
+ return agent.ctx.get?.("systemPrompt");
796
+ }
795
797
  function registerGuidance(ctx, config) {
796
798
  systemPrompt(ctx)?.section?.({
797
799
  name: GUIDANCE_SECTION_NAME,
@@ -807,6 +809,15 @@ function registerRuntimeMemoryContext(ctx, runtimeMemory) {
807
809
  text: () => runtimeMemory.contextText()
808
810
  });
809
811
  }
812
+ /** Shadow the global fallback with the current Agent workspace's hot memory. */
813
+ function registerAgentRuntimeMemoryContext(agent, runtimeMemory) {
814
+ const dispose = scopedSystemPrompt(agent)?.section?.({
815
+ name: RUNTIME_MEMORY_SECTION_NAME,
816
+ order: 145,
817
+ text: () => runtimeMemory().contextText()
818
+ });
819
+ return typeof dispose === "function" ? dispose : () => {};
820
+ }
810
821
  const RUNTIME_ENTRY_DELIMITER = "\n§\n";
811
822
  const RUNTIME_MEMORY_LIMITS = {
812
823
  memory: 10240,
@@ -2120,7 +2131,7 @@ var MnemonCliError = class extends Error {
2120
2131
  this.stderr = stderr;
2121
2132
  }
2122
2133
  };
2123
- function createRunner(config, processRunner = runProcess) {
2134
+ function createRunner(config, processRunner = runProcess, workspaceRoot) {
2124
2135
  const found = findMnemonCommand(config);
2125
2136
  const command = found ?? config.cliPath ?? "mnemon";
2126
2137
  let processQueue = Promise.resolve();
@@ -2132,7 +2143,7 @@ function createRunner(config, processRunner = runProcess) {
2132
2143
  return args;
2133
2144
  };
2134
2145
  const effectiveDataDir = () => {
2135
- if (config.storageScope === "workspace") return resolve(process.cwd(), ".mnemon");
2146
+ if (config.storageScope === "workspace") return resolve(workspaceRoot ?? process.cwd(), ".mnemon");
2136
2147
  if (config.storageScope === "custom") return expandHome$1(config.dataDir);
2137
2148
  return expandHome$1(process.env.MNEMON_DATA_DIR?.trim() || "~/.mnemon");
2138
2149
  };
@@ -3223,8 +3234,8 @@ var StorageScopeInspector = class {
3223
3234
  * validate and initialize the selected storage root, so a failed candidate is
3224
3235
  * rejected by DSH settings validation without disturbing the active graph.
3225
3236
  */
3226
- function createRuntimeGraph(config) {
3227
- const runner = createRunner(config);
3237
+ function createRuntimeGraph(config, workspaceRoot) {
3238
+ const runner = createRunner(config, void 0, workspaceRoot);
3228
3239
  const service = new MnemonService(runner, config);
3229
3240
  return {
3230
3241
  config,
@@ -3268,7 +3279,10 @@ function liveProxy(resolve) {
3268
3279
  * generation until that invocation settles.
3269
3280
  */
3270
3281
  var LiveMnemonRuntime = class {
3282
+ workspaceRegistry;
3283
+ agents;
3271
3284
  current;
3285
+ workspaceGraphs = /* @__PURE__ */ new Map();
3272
3286
  config;
3273
3287
  runner;
3274
3288
  service;
@@ -3276,7 +3290,9 @@ var LiveMnemonRuntime = class {
3276
3290
  documents;
3277
3291
  storage;
3278
3292
  packs;
3279
- constructor(initial) {
3293
+ constructor(initial, workspaceRegistry, agents) {
3294
+ this.workspaceRegistry = workspaceRegistry;
3295
+ this.agents = agents;
3280
3296
  this.current = initial;
3281
3297
  this.config = liveProxy(() => this.current.config);
3282
3298
  this.runner = liveProxy(() => this.current.runner);
@@ -3288,13 +3304,72 @@ var LiveMnemonRuntime = class {
3288
3304
  }
3289
3305
  swap(next) {
3290
3306
  this.current = next;
3307
+ this.workspaceGraphs.clear();
3291
3308
  }
3292
3309
  snapshot() {
3293
3310
  return this.current;
3294
3311
  }
3312
+ /** Resolve the runtime that must serve one Agent execution. */
3313
+ forAgent(agent) {
3314
+ if (this.current.config.storageScope !== "workspace") return this.current;
3315
+ const cwd = agent.session.header?.cwd?.trim();
3316
+ if (cwd === void 0 || cwd === "") throw new Error("the current DSH session has no workspace for Mnemon");
3317
+ return this.forWorkspacePath(cwd);
3318
+ }
3319
+ /** Resolve an authorized DSH workspace selected by the Web workbench. */
3320
+ forWorkspaceId(workspaceId) {
3321
+ const workspace = this.requireWorkspace(workspaceId);
3322
+ return this.current.config.storageScope === "workspace" ? this.forWorkspacePath(workspace.path) : this.current;
3323
+ }
3324
+ /** Resolve a Web request, preferring its explicit inspection workspace. */
3325
+ route(request) {
3326
+ const effectiveAgent = this.agent(request.sessionId);
3327
+ const effectiveWorkspace = effectiveAgent === void 0 ? void 0 : this.workspaceForPath(effectiveAgent.session.header?.cwd);
3328
+ const selectedWorkspace = request.workspaceId === void 0 || request.workspaceId.trim() === "" ? effectiveWorkspace : this.requireWorkspace(request.workspaceId);
3329
+ const graph = selectedWorkspace === void 0 ? effectiveAgent === void 0 ? this.current : this.forAgent(effectiveAgent) : this.current.config.storageScope === "workspace" ? this.forWorkspacePath(selectedWorkspace.path) : this.current;
3330
+ const effectiveGraph = effectiveAgent === void 0 ? this.current : this.forAgent(effectiveAgent);
3331
+ const selectedRoot = resolve(graph.runner.effectiveDataDir());
3332
+ const effectiveRoot = resolve(effectiveGraph.runner.effectiveDataDir());
3333
+ return {
3334
+ graph,
3335
+ ...selectedWorkspace === void 0 ? {} : { selectedWorkspace },
3336
+ ...effectiveWorkspace === void 0 ? {} : { effectiveWorkspace },
3337
+ selectedRoot,
3338
+ effectiveRoot,
3339
+ aligned: selectedRoot === effectiveRoot
3340
+ };
3341
+ }
3342
+ forWorkspacePath(workspaceRoot) {
3343
+ const key = resolve(workspaceRoot);
3344
+ let graph = this.workspaceGraphs.get(key);
3345
+ if (graph === void 0) {
3346
+ graph = createRuntimeGraph(this.current.config, key);
3347
+ this.workspaceGraphs.set(key, graph);
3348
+ }
3349
+ return graph;
3350
+ }
3351
+ agent(sessionId) {
3352
+ const normalized = sessionId?.trim();
3353
+ return normalized === void 0 || normalized === "" ? void 0 : this.agents?.get(normalized);
3354
+ }
3355
+ requireWorkspace(workspaceId) {
3356
+ const normalized = workspaceId.trim();
3357
+ const workspace = normalized === "" ? void 0 : this.workspaceRegistry?.get(normalized);
3358
+ if (workspace === void 0) throw new Error("selected DSH workspace is unavailable");
3359
+ return workspace;
3360
+ }
3361
+ workspaceForPath(path) {
3362
+ const normalized = path?.trim();
3363
+ if (normalized === void 0 || normalized === "") return void 0;
3364
+ const canonical = resolve(normalized);
3365
+ return this.workspaceRegistry?.list().find((workspace) => resolve(workspace.path) === canonical);
3366
+ }
3295
3367
  };
3296
3368
  //#endregion
3297
3369
  //#region lib/types/subagent.js
3370
+ function isAgentRuntimeSource$1(value) {
3371
+ return typeof value === "object" && value !== null && "forAgent" in value && typeof value.forAgent === "function";
3372
+ }
3298
3373
  const READ_TOOLS = [
3299
3374
  "mnemon_memory_bodies",
3300
3375
  "mnemon_recall",
@@ -3679,7 +3754,7 @@ function isSubagent(agent) {
3679
3754
  /** Delegates memory judgment and execution to a fresh, tool-scoped DSH child. */
3680
3755
  var MnemonSubagentCoordinator = class {
3681
3756
  subagents;
3682
- runtimeMemory;
3757
+ runtimeMemoryOrSource;
3683
3758
  documents;
3684
3759
  counters = {
3685
3760
  recalls: 0,
@@ -3693,25 +3768,22 @@ var MnemonSubagentCoordinator = class {
3693
3768
  };
3694
3769
  runtimeQueue = Promise.resolve();
3695
3770
  documentQueue = Promise.resolve();
3696
- constructor(subagents, runtimeMemory, documents) {
3771
+ constructor(subagents, runtimeMemoryOrSource, documents) {
3697
3772
  this.subagents = subagents;
3698
- this.runtimeMemory = runtimeMemory;
3773
+ this.runtimeMemoryOrSource = runtimeMemoryOrSource;
3699
3774
  this.documents = documents;
3700
3775
  }
3701
3776
  snapshot() {
3702
3777
  return { ...this.counters };
3703
3778
  }
3704
3779
  documentsSnapshot(parent) {
3705
- if (this.documents === void 0) throw new Error("Mnemon Documents control plane is unavailable");
3706
- return this.documents.forAgent(parent).snapshot();
3780
+ return this.documentsFor(parent).forAgent(parent).snapshot();
3707
3781
  }
3708
3782
  documentGet(parent, id) {
3709
- if (this.documents === void 0) throw new Error("Mnemon Documents control plane is unavailable");
3710
- return this.documents.forAgent(parent).get(id);
3783
+ return this.documentsFor(parent).forAgent(parent).get(id);
3711
3784
  }
3712
3785
  documentSearch(parent, query, includeArchived = false, limit) {
3713
- if (this.documents === void 0) throw new Error("Mnemon Documents control plane is unavailable");
3714
- return this.documents.forAgent(parent).search(query, {
3786
+ return this.documentsFor(parent).forAgent(parent).search(query, {
3715
3787
  includeArchived,
3716
3788
  ...limit === void 0 ? {} : { limit }
3717
3789
  });
@@ -3811,8 +3883,7 @@ ${naturalRequest(request)}`;
3811
3883
  };
3812
3884
  }
3813
3885
  async documentLocked(parent, request, signal) {
3814
- if (this.documents === void 0) throw new Error("Mnemon Documents control plane is unavailable");
3815
- const controller = this.documents.forAgent(parent);
3886
+ const controller = this.documentsFor(parent).forAgent(parent);
3816
3887
  const archivedDocumentIds = [];
3817
3888
  const memoryBodyIds = /* @__PURE__ */ new Set();
3818
3889
  let lastArchive;
@@ -3848,8 +3919,7 @@ ${naturalRequest(request)}`;
3848
3919
  };
3849
3920
  }
3850
3921
  async archiveDocumentLocked(parent, id, signal) {
3851
- if (this.documents === void 0) throw new Error("Mnemon Documents control plane is unavailable");
3852
- const controller = this.documents.forAgent(parent);
3922
+ const controller = this.documentsFor(parent).forAgent(parent);
3853
3923
  const document = controller.get(id);
3854
3924
  if (document.status !== "active") throw new Error("only active documents can be archived");
3855
3925
  const { provider, runId, result } = await this.delegate(parent, "document-archive", "Archive managed document", "Archive this managed document now.", DOCUMENT_ARCHIVE_TOOLS, DOCUMENT_ARCHIVE_SCHEMA, signal, "spawn", documentArchivePersona(document));
@@ -3872,14 +3942,14 @@ ${naturalRequest(request)}`;
3872
3942
  };
3873
3943
  }
3874
3944
  async runtimeLocked(parent, request, signal) {
3875
- if (this.runtimeMemory === void 0) throw new Error("runtime memory control plane is unavailable");
3945
+ const runtimeMemory = this.runtimeMemoryFor(parent);
3876
3946
  try {
3877
- return await this.runtimeMemory.mutate(request);
3947
+ return await runtimeMemory.mutate(request);
3878
3948
  } catch (error) {
3879
3949
  if (!(error instanceof RuntimeMemoryCapacityError) || request.action !== "add") throw error;
3880
3950
  }
3881
3951
  if (request.target === "user") return this.compactUserAndRetry(parent, request, signal);
3882
- const snapshot = this.runtimeMemory.snapshot();
3952
+ const snapshot = runtimeMemory.snapshot();
3883
3953
  const targetView = snapshot.targets[request.target];
3884
3954
  const targetEntries = snapshot.entries.filter((entry) => entry.target === request.target);
3885
3955
  if (targetEntries.length === 0) throw new Error("runtime memory capacity was exceeded without entries available for archival");
@@ -3906,9 +3976,9 @@ ${indentedText(request.content ?? "")}`;
3906
3976
  importance: item.importance
3907
3977
  };
3908
3978
  }) : [];
3909
- await this.runtimeMemory.compactTarget(snapshot.revision, request.target, compactedEntries, compactedBudget);
3979
+ await runtimeMemory.compactTarget(snapshot.revision, request.target, compactedEntries, compactedBudget);
3910
3980
  return {
3911
- ...await this.runtimeMemory.mutate(request),
3981
+ ...await runtimeMemory.mutate(request),
3912
3982
  maintenance: {
3913
3983
  kind: "mnemon-archive",
3914
3984
  runId,
@@ -3919,8 +3989,8 @@ ${indentedText(request.content ?? "")}`;
3919
3989
  };
3920
3990
  }
3921
3991
  async compactUserAndRetry(parent, request, signal) {
3922
- if (this.runtimeMemory === void 0) throw new Error("runtime memory control plane is unavailable");
3923
- const snapshot = this.runtimeMemory.snapshot();
3992
+ const runtimeMemory = this.runtimeMemoryFor(parent);
3993
+ const snapshot = runtimeMemory.snapshot();
3924
3994
  const targetEntries = snapshot.entries.filter((entry) => entry.target === "user");
3925
3995
  if (targetEntries.length === 0) throw new Error("USER.md capacity was exceeded without entries available for compaction");
3926
3996
  const targetView = snapshot.targets.user;
@@ -3973,9 +4043,9 @@ ${indentedText(request.content ?? "")}`;
3973
4043
  }));
3974
4044
  const candidateBytes = Buffer.byteLength(candidates.map((entry) => entry.content.trim().replace(/\s+/gu, " ")).join(RUNTIME_ENTRY_DELIMITER), "utf8");
3975
4045
  if (candidateBytes > compactedBudget) throw new Error(`USER.md compaction did not fit the host budget (${candidateBytes} > ${compactedBudget} bytes)`);
3976
- await this.runtimeMemory.compactTarget(snapshot.revision, "user", candidates, compactedBudget);
4046
+ await runtimeMemory.compactTarget(snapshot.revision, "user", candidates, compactedBudget);
3977
4047
  return {
3978
- ...await this.runtimeMemory.mutate(request),
4048
+ ...await runtimeMemory.mutate(request),
3979
4049
  maintenance: {
3980
4050
  kind: "local-compaction",
3981
4051
  runId,
@@ -4043,6 +4113,16 @@ ${indentedText(request.content ?? "")}`;
4043
4113
  if (selected === void 0) throw new Error("dsh-mnemon requires a DSH subagent provider with structured output, tool filtering, persona, and depth limiting");
4044
4114
  return selected;
4045
4115
  }
4116
+ runtimeMemoryFor(parent) {
4117
+ if (isAgentRuntimeSource$1(this.runtimeMemoryOrSource)) return this.runtimeMemoryOrSource.forAgent(parent).runtimeMemory;
4118
+ if (this.runtimeMemoryOrSource === void 0) throw new Error("runtime memory control plane is unavailable");
4119
+ return this.runtimeMemoryOrSource;
4120
+ }
4121
+ documentsFor(parent) {
4122
+ if (isAgentRuntimeSource$1(this.runtimeMemoryOrSource)) return this.runtimeMemoryOrSource.forAgent(parent).documents;
4123
+ if (this.documents === void 0) throw new Error("Mnemon Documents control plane is unavailable");
4124
+ return this.documents;
4125
+ }
4046
4126
  };
4047
4127
  //#endregion
4048
4128
  //#region lib/types/review-activity.js
@@ -4436,6 +4516,7 @@ var MnemonLifecycle = class {
4436
4516
  ctx;
4437
4517
  coordinator;
4438
4518
  config;
4519
+ runtimeSource;
4439
4520
  owners = /* @__PURE__ */ new Map();
4440
4521
  counters = {
4441
4522
  primes: 0,
@@ -4446,10 +4527,11 @@ var MnemonLifecycle = class {
4446
4527
  };
4447
4528
  /** Bounded process-local replay fence for finalized-message write actions. */
4448
4529
  supervisedWritebacks = /* @__PURE__ */ new Map();
4449
- constructor(ctx, coordinator, config) {
4530
+ constructor(ctx, coordinator, config, runtimeSource) {
4450
4531
  this.ctx = ctx;
4451
4532
  this.coordinator = coordinator;
4452
4533
  this.config = config;
4534
+ this.runtimeSource = runtimeSource;
4453
4535
  }
4454
4536
  start() {
4455
4537
  const stopCreated = this.ctx.on("agent/created", (({ agent }) => {
@@ -4585,7 +4667,9 @@ var MnemonLifecycle = class {
4585
4667
  let dispose;
4586
4668
  dispose = agent.ctx.effect(() => {
4587
4669
  const stop = lifecycle.start();
4670
+ const stopRuntimeContext = this.runtimeSource === void 0 ? () => {} : registerAgentRuntimeMemoryContext(agent, () => this.runtimeSource.forAgent(agent).runtimeMemory);
4588
4671
  return () => {
4672
+ stopRuntimeContext();
4589
4673
  stop();
4590
4674
  if (this.owners.get(agent)?.dispose === dispose) this.owners.delete(agent);
4591
4675
  };
@@ -4598,6 +4682,41 @@ var MnemonLifecycle = class {
4598
4682
  };
4599
4683
  //#endregion
4600
4684
  //#region lib/types/rpc.js
4685
+ function isRoutedRuntime(value) {
4686
+ return "route" in value && typeof value.route === "function";
4687
+ }
4688
+ function requestedScope(payload) {
4689
+ const workspaceId = payload.workspaceId === void 0 ? void 0 : String(payload.workspaceId).trim();
4690
+ const sessionId = payload.sessionId === void 0 ? void 0 : String(payload.sessionId).trim();
4691
+ return {
4692
+ ...workspaceId === void 0 || workspaceId === "" ? {} : { workspaceId },
4693
+ ...sessionId === void 0 || sessionId === "" ? {} : { sessionId }
4694
+ };
4695
+ }
4696
+ function runtimeFor(input, payload, runtimeMemory, storage) {
4697
+ if (isRoutedRuntime(input)) {
4698
+ const scope = requestedScope(payload);
4699
+ const route = input.route(scope);
4700
+ return {
4701
+ graph: route.graph,
4702
+ route,
4703
+ explicitWorkspace: scope.workspaceId !== void 0 && route.graph.config.storageScope === "workspace"
4704
+ };
4705
+ }
4706
+ return {
4707
+ graph: {
4708
+ service: input,
4709
+ runtimeMemory,
4710
+ documents: void 0,
4711
+ storage,
4712
+ packs: void 0
4713
+ },
4714
+ explicitWorkspace: false
4715
+ };
4716
+ }
4717
+ function requireAligned(route) {
4718
+ if (route?.aligned === false) throw new Error("the selected memory workspace differs from the current session; align the workbench before running an Agent-backed operation");
4719
+ }
4601
4720
  const MNEMON_READ_CHANNEL = "/dsh-mnemon-read";
4602
4721
  const MNEMON_WRITE_CHANNEL = "/dsh-mnemon-write";
4603
4722
  const MNEMON_PACK_CHANNEL = "/dsh-mnemon-pack";
@@ -4631,34 +4750,55 @@ function badRequest$1(message) {
4631
4750
  }
4632
4751
  };
4633
4752
  }
4634
- function createReadHandler(service, lifecycle, runtimeMemory, storage) {
4753
+ function createReadHandler(input, lifecycle, runtimeMemory, storage) {
4635
4754
  return async (endpoint, rawPayload) => {
4636
4755
  try {
4637
4756
  const payload = object$1(rawPayload);
4757
+ const resolved = runtimeFor(input, payload, runtimeMemory, storage);
4758
+ const { service } = resolved.graph;
4759
+ const selectedWorkspace = resolved.route?.selectedWorkspace;
4760
+ const documentController = resolved.explicitWorkspace && selectedWorkspace !== void 0 ? resolved.graph.documents.forWorkspace(selectedWorkspace.path) : void 0;
4638
4761
  switch (endpoint) {
4639
4762
  case "runtime-memory":
4640
- if (runtimeMemory === void 0) throw new Error("runtime memory is unavailable");
4641
- return success$1(runtimeMemory.snapshot());
4763
+ if (resolved.graph.runtimeMemory === void 0) throw new Error("runtime memory is unavailable");
4764
+ return success$1(resolved.graph.runtimeMemory.snapshot());
4642
4765
  case "status": {
4643
4766
  const sessionId = payload.sessionId === void 0 ? "" : String(payload.sessionId).trim();
4644
4767
  let documents;
4645
- if (lifecycle !== void 0 && sessionId !== "") try {
4768
+ if (documentController !== void 0) try {
4769
+ documents = documentController.snapshot();
4770
+ } catch {}
4771
+ else if (lifecycle !== void 0 && sessionId !== "") try {
4646
4772
  documents = lifecycle.documents(sessionId);
4647
4773
  } catch {}
4648
4774
  return success$1({
4649
4775
  ...await service.status(),
4650
4776
  ...lifecycle === void 0 ? {} : { lifecycle: lifecycle.snapshot(payload.sessionId === void 0 ? void 0 : String(payload.sessionId)) },
4651
4777
  ...documents === void 0 ? {} : { documents },
4652
- ...storage === void 0 ? {} : { storage: storage.catalog(lifecycle?.workspaceRoot(sessionId)) }
4778
+ ...resolved.graph.storage === void 0 ? {} : { storage: resolved.graph.storage.catalog(selectedWorkspace?.path ?? lifecycle?.workspaceRoot(sessionId)) },
4779
+ ...resolved.route === void 0 ? {} : { workspaceContext: {
4780
+ mode: service.config.storageScope,
4781
+ selectedRoot: resolved.route.selectedRoot,
4782
+ effectiveRoot: resolved.route.effectiveRoot,
4783
+ aligned: resolved.route.aligned,
4784
+ ...resolved.route.selectedWorkspace === void 0 ? {} : { selectedWorkspace: resolved.route.selectedWorkspace },
4785
+ ...resolved.route.effectiveWorkspace === void 0 ? {} : { effectiveWorkspace: resolved.route.effectiveWorkspace }
4786
+ } }
4653
4787
  });
4654
4788
  }
4655
4789
  case "documents":
4790
+ if (documentController !== void 0) return success$1(documentController.snapshot());
4656
4791
  if (lifecycle === void 0) throw new Error("Mnemon Documents require lifecycle integration");
4657
4792
  return success$1(lifecycle.documents(String(payload.sessionId ?? "")));
4658
4793
  case "document":
4794
+ if (documentController !== void 0) return success$1(documentController.get(String(payload.id ?? "")));
4659
4795
  if (lifecycle === void 0) throw new Error("Mnemon Documents require lifecycle integration");
4660
4796
  return success$1(lifecycle.document(String(payload.sessionId ?? ""), String(payload.id ?? "")));
4661
4797
  case "document-search":
4798
+ if (documentController !== void 0) return success$1(await documentController.search(String(payload.query ?? ""), {
4799
+ includeArchived: payload.includeArchived === true,
4800
+ ...payload.limit === void 0 ? {} : { limit: Number(payload.limit) }
4801
+ }));
4662
4802
  if (lifecycle === void 0) throw new Error("Mnemon Documents require lifecycle integration");
4663
4803
  return success$1(await lifecycle.searchDocuments(String(payload.sessionId ?? ""), String(payload.query ?? ""), payload.includeArchived === true, payload.limit === void 0 ? void 0 : Number(payload.limit)));
4664
4804
  case "graph": return success$1(await service.graph(void 0, Array.isArray(payload.memoryBodyIds) ? payload.memoryBodyIds.map(String) : void 0));
@@ -4721,14 +4861,20 @@ function createReadHandler(service, lifecycle, runtimeMemory, storage) {
4721
4861
  }
4722
4862
  };
4723
4863
  }
4724
- function createWriteHandler(service, lifecycle, runtimeMemory) {
4864
+ function createWriteHandler(input, lifecycle, runtimeMemory) {
4725
4865
  return async (endpoint, rawPayload) => {
4726
4866
  try {
4727
- if (!service.config.writeEnabled) throw new Error("dsh-mnemon is configured read-only (writeEnabled: false)");
4728
4867
  const payload = object$1(rawPayload);
4868
+ const resolved = runtimeFor(input, payload, runtimeMemory);
4869
+ const { service } = resolved.graph;
4870
+ if (!service.config.writeEnabled) throw new Error("dsh-mnemon is configured read-only (writeEnabled: false)");
4871
+ const selectedWorkspace = resolved.route?.selectedWorkspace;
4872
+ const documentController = resolved.explicitWorkspace && selectedWorkspace !== void 0 ? resolved.graph.documents.forWorkspace(selectedWorkspace.path) : void 0;
4873
+ const inspectionDiverged = resolved.explicitWorkspace && resolved.route?.aligned === false;
4874
+ const alignedSession = resolved.explicitWorkspace && resolved.route?.aligned === true && resolved.route.effectiveWorkspace !== void 0;
4729
4875
  switch (endpoint) {
4730
4876
  case "runtime-memory":
4731
- if (runtimeMemory === void 0) throw new Error("runtime memory is unavailable");
4877
+ if (resolved.graph.runtimeMemory === void 0) throw new Error("runtime memory is unavailable");
4732
4878
  {
4733
4879
  const request = {
4734
4880
  action: String(payload.action ?? ""),
@@ -4738,36 +4884,57 @@ function createWriteHandler(service, lifecycle, runtimeMemory) {
4738
4884
  ...payload.importance === void 0 ? {} : { importance: String(payload.importance) }
4739
4885
  };
4740
4886
  const sessionId = String(payload.sessionId ?? "").trim();
4741
- return success$1(lifecycle === void 0 || sessionId === "" ? await runtimeMemory.mutate(request) : await lifecycle.runtime(sessionId, request));
4887
+ return success$1(inspectionDiverged || lifecycle === void 0 || sessionId === "" || resolved.explicitWorkspace && !alignedSession ? await resolved.graph.runtimeMemory.mutate(request) : await lifecycle.runtime(sessionId, request));
4742
4888
  }
4743
4889
  case "supervise":
4744
4890
  if (lifecycle === void 0) throw new Error("Mnemon lifecycle integration is unavailable");
4891
+ requireAligned(resolved.route);
4745
4892
  return success$1(await lifecycle.supervise(String(payload.sessionId ?? ""), String(payload.content ?? ""), payload.idempotencyKey === void 0 ? void 0 : String(payload.idempotencyKey)));
4746
- case "document":
4747
- if (lifecycle === void 0) throw new Error("Mnemon Documents require lifecycle integration");
4748
- {
4749
- const action = String(payload.action ?? "");
4750
- const sessionId = String(payload.sessionId ?? "");
4751
- if (action === "archive") return success$1(await lifecycle.archiveDocument(sessionId, String(payload.id ?? "")));
4752
- if (action === "create") return success$1(await lifecycle.mutateDocument(sessionId, {
4893
+ case "document": {
4894
+ const action = String(payload.action ?? "");
4895
+ const sessionId = String(payload.sessionId ?? "");
4896
+ if (documentController !== void 0 && action !== "archive" && (!alignedSession || lifecycle === void 0)) {
4897
+ const sessionIds = resolved.route?.aligned === true && sessionId.trim() !== "" ? [sessionId] : [];
4898
+ if (action === "create") return success$1(await documentController.mutate({
4753
4899
  action: "create",
4754
4900
  title: String(payload.title ?? ""),
4755
4901
  content: String(payload.content ?? ""),
4756
4902
  ...payload.description === void 0 ? {} : { description: String(payload.description) },
4757
4903
  ...Array.isArray(payload.sourcePaths) ? { sourcePaths: payload.sourcePaths.map(String) } : {},
4758
- sessionIds: [sessionId]
4904
+ sessionIds
4759
4905
  }));
4760
- if (action === "update") return success$1(await lifecycle.mutateDocument(sessionId, {
4906
+ if (action === "update") return success$1(await documentController.mutate({
4761
4907
  action: "update",
4762
4908
  id: String(payload.id ?? ""),
4763
4909
  ...payload.title === void 0 ? {} : { title: String(payload.title) },
4764
4910
  ...payload.description === void 0 ? {} : { description: String(payload.description) },
4765
4911
  ...payload.content === void 0 ? {} : { content: String(payload.content) },
4766
4912
  ...Array.isArray(payload.sourcePaths) ? { sourcePaths: payload.sourcePaths.map(String) } : {},
4767
- sessionIds: [sessionId]
4913
+ sessionIds
4768
4914
  }));
4769
- return badRequest$1(`unknown document action: ${action}`);
4770
4915
  }
4916
+ if (lifecycle === void 0) throw new Error("Mnemon Documents require lifecycle integration");
4917
+ if (resolved.explicitWorkspace) requireAligned(resolved.route);
4918
+ if (action === "archive") return success$1(await lifecycle.archiveDocument(sessionId, String(payload.id ?? "")));
4919
+ if (action === "create") return success$1(await lifecycle.mutateDocument(sessionId, {
4920
+ action: "create",
4921
+ title: String(payload.title ?? ""),
4922
+ content: String(payload.content ?? ""),
4923
+ ...payload.description === void 0 ? {} : { description: String(payload.description) },
4924
+ ...Array.isArray(payload.sourcePaths) ? { sourcePaths: payload.sourcePaths.map(String) } : {},
4925
+ sessionIds: [sessionId]
4926
+ }));
4927
+ if (action === "update") return success$1(await lifecycle.mutateDocument(sessionId, {
4928
+ action: "update",
4929
+ id: String(payload.id ?? ""),
4930
+ ...payload.title === void 0 ? {} : { title: String(payload.title) },
4931
+ ...payload.description === void 0 ? {} : { description: String(payload.description) },
4932
+ ...payload.content === void 0 ? {} : { content: String(payload.content) },
4933
+ ...Array.isArray(payload.sourcePaths) ? { sourcePaths: payload.sourcePaths.map(String) } : {},
4934
+ sessionIds: [sessionId]
4935
+ }));
4936
+ return badRequest$1(`unknown document action: ${action}`);
4937
+ }
4771
4938
  case "remember": {
4772
4939
  const request = {
4773
4940
  content: String(payload.content ?? ""),
@@ -4778,10 +4945,10 @@ function createWriteHandler(service, lifecycle, runtimeMemory) {
4778
4945
  ...payload.memoryBodyId === void 0 ? {} : { memoryBodyId: String(payload.memoryBodyId) },
4779
4946
  source: "user"
4780
4947
  };
4781
- return success$1(lifecycle === void 0 ? await service.remember(request) : await lifecycle.remember(String(payload.sessionId ?? ""), request));
4948
+ return success$1(inspectionDiverged || lifecycle === void 0 || resolved.explicitWorkspace && !alignedSession ? await service.remember(request) : await lifecycle.remember(String(payload.sessionId ?? ""), request));
4782
4949
  }
4783
- case "link": return success$1(lifecycle === void 0 ? await service.link(String(payload.sourceId ?? ""), String(payload.targetId ?? ""), payload.type, payload.weight === void 0 ? .5 : Number(payload.weight), payload.reason === void 0 ? void 0 : String(payload.reason), void 0, payload.memoryBodyId === void 0 ? void 0 : String(payload.memoryBodyId)) : await lifecycle.mutate(String(payload.sessionId ?? ""), "link", payload));
4784
- case "forget": return success$1(lifecycle === void 0 ? await service.forget(String(payload.id ?? ""), void 0, payload.memoryBodyId === void 0 ? void 0 : String(payload.memoryBodyId)) : await lifecycle.mutate(String(payload.sessionId ?? ""), "forget", {
4950
+ case "link": return success$1(inspectionDiverged || lifecycle === void 0 || resolved.explicitWorkspace && !alignedSession ? await service.link(String(payload.sourceId ?? ""), String(payload.targetId ?? ""), payload.type, payload.weight === void 0 ? .5 : Number(payload.weight), payload.reason === void 0 ? void 0 : String(payload.reason), void 0, payload.memoryBodyId === void 0 ? void 0 : String(payload.memoryBodyId)) : await lifecycle.mutate(String(payload.sessionId ?? ""), "link", payload));
4951
+ case "forget": return success$1(inspectionDiverged || lifecycle === void 0 || resolved.explicitWorkspace && !alignedSession ? await service.forget(String(payload.id ?? ""), void 0, payload.memoryBodyId === void 0 ? void 0 : String(payload.memoryBodyId)) : await lifecycle.mutate(String(payload.sessionId ?? ""), "forget", {
4785
4952
  id: String(payload.id ?? ""),
4786
4953
  ...payload.memoryBodyId === void 0 ? {} : { memoryBodyId: String(payload.memoryBodyId) }
4787
4954
  }));
@@ -4821,10 +4988,12 @@ function createPackHandler(manager, writeEnabled = true) {
4821
4988
  };
4822
4989
  }
4823
4990
  /** Read operations are available to trusted Web hosts; local mutations stay loopback-only. */
4824
- function registerRpc(connection, service, lifecycle, runtimeMemory, storage, packs) {
4825
- connection.rpc.handle(MNEMON_READ_CHANNEL, createReadHandler(service, lifecycle, runtimeMemory, storage), { authority: "trusted-host" });
4826
- connection.rpc.handle(MNEMON_WRITE_CHANNEL, createWriteHandler(service, lifecycle, runtimeMemory), { authority: "loopback" });
4827
- if (packs !== void 0) connection.rpc.handle(MNEMON_PACK_CHANNEL, createPackHandler(packs, () => service.config.writeEnabled), { authority: "loopback" });
4991
+ function registerRpc(connection, input, lifecycle, runtimeMemory, storage, packs) {
4992
+ connection.rpc.handle(MNEMON_READ_CHANNEL, createReadHandler(input, lifecycle, runtimeMemory, storage), { authority: "trusted-host" });
4993
+ connection.rpc.handle(MNEMON_WRITE_CHANNEL, createWriteHandler(input, lifecycle, runtimeMemory), { authority: "loopback" });
4994
+ const packManager = isRoutedRuntime(input) ? input.packs : packs;
4995
+ const config = input.config;
4996
+ if (packManager !== void 0) connection.rpc.handle(MNEMON_PACK_CHANNEL, createPackHandler(packManager, () => config.writeEnabled), { authority: "loopback" });
4828
4997
  }
4829
4998
  //#endregion
4830
4999
  //#region lib/types/settings.js
@@ -4888,6 +5057,7 @@ const MUTABLE_FIELDS = [
4888
5057
  "recallMode",
4889
5058
  "writebackMode",
4890
5059
  "idleReviewMs",
5060
+ "displayMode",
4891
5061
  "tabEnabled",
4892
5062
  "writeEnabled"
4893
5063
  ];
@@ -4967,8 +5137,21 @@ function requireAgent(exec) {
4967
5137
  if (exec.agent === void 0) throw new Error("Mnemon semantic operations require a live DSH agent");
4968
5138
  return exec.agent;
4969
5139
  }
5140
+ function isAgentRuntimeSource(value) {
5141
+ return "forAgent" in value && typeof value.forAgent === "function";
5142
+ }
4970
5143
  /** Root calls delegate to a bounded child; memory-worker calls reach the deterministic service. */
4971
- function registerTools(ctx, service, coordinator, runtimeMemory, documents) {
5144
+ function registerTools(ctx, serviceOrSource, coordinator, runtimeMemory, documents) {
5145
+ const runtimeFor = (exec) => {
5146
+ if (isAgentRuntimeSource(serviceOrSource)) return serviceOrSource.forAgent(requireAgent(exec));
5147
+ if (runtimeMemory === void 0 || documents === void 0) throw new Error("Mnemon runtime control plane is unavailable");
5148
+ return {
5149
+ service: serviceOrSource,
5150
+ runtimeMemory,
5151
+ documents
5152
+ };
5153
+ };
5154
+ const config = serviceOrSource.config;
4972
5155
  ctx.tools.register(definition({
4973
5156
  name: "mnemon_memory_bodies",
4974
5157
  description: "List the global Mnemon Memory Space catalog, including each space id, name, description, activation state, database path, and statistics. Read only. Use this before choosing a write target, or when the Prime summary is insufficient. Recall may only read active spaces; writes may target any space.",
@@ -4980,7 +5163,7 @@ function registerTools(ctx, service, coordinator, runtimeMemory, documents) {
4980
5163
  schema: JSON_OBJECT_OUTPUT,
4981
5164
  render: (_args, value) => text(value)
4982
5165
  },
4983
- execute: (_args, exec) => service.bodies(exec.signal),
5166
+ execute: (_args, exec) => runtimeFor(exec).service.bodies(exec.signal),
4984
5167
  presentCall: () => ({
4985
5168
  card: "generic",
4986
5169
  title: "Inspect Mnemon Memory Spaces",
@@ -5039,7 +5222,7 @@ function registerTools(ctx, service, coordinator, runtimeMemory, documents) {
5039
5222
  render: (_args, value) => text(value)
5040
5223
  },
5041
5224
  async execute(args, exec) {
5042
- return isSubagent(exec.agent) ? service.search(args, exec.signal) : coordinator.recall(requireAgent(exec), args, exec.signal);
5225
+ return isSubagent(exec.agent) ? runtimeFor(exec).service.search(args, exec.signal) : coordinator.recall(requireAgent(exec), args, exec.signal);
5043
5226
  },
5044
5227
  presentCall: (args) => ({
5045
5228
  card: "generic",
@@ -5083,7 +5266,7 @@ function registerTools(ctx, service, coordinator, runtimeMemory, documents) {
5083
5266
  },
5084
5267
  async execute(args, exec) {
5085
5268
  if (!isSubagent(exec.agent)) return coordinator.related(requireAgent(exec), args.id, args.memoryBodyId, exec.signal);
5086
- const results = await service.related(args.id, args.depth, args.edge, exec.signal, args.memoryBodyId);
5269
+ const results = await runtimeFor(exec).service.related(args.id, args.depth, args.edge, exec.signal, args.memoryBodyId);
5087
5270
  return {
5088
5271
  id: args.id,
5089
5272
  depth: args.depth ?? 2,
@@ -5114,7 +5297,7 @@ function registerTools(ctx, service, coordinator, runtimeMemory, documents) {
5114
5297
  schema: JSON_OBJECT_OUTPUT,
5115
5298
  render: (_args, value) => text(value)
5116
5299
  },
5117
- execute: (_args, exec) => service.status(exec.signal),
5300
+ execute: (_args, exec) => runtimeFor(exec).service.status(exec.signal),
5118
5301
  presentCall: () => ({
5119
5302
  card: "generic",
5120
5303
  title: "Check Mnemon status",
@@ -5151,7 +5334,7 @@ function registerTools(ctx, service, coordinator, runtimeMemory, documents) {
5151
5334
  render: (_args, value) => text(value)
5152
5335
  },
5153
5336
  async execute(args, exec) {
5154
- const controller = documents.forAgent(requireAgent(exec));
5337
+ const controller = runtimeFor(exec).documents.forAgent(requireAgent(exec));
5155
5338
  const result = await controller.search(args.query, {
5156
5339
  ...args.includeArchived === void 0 ? {} : { includeArchived: args.includeArchived },
5157
5340
  limit: Math.min(8, args.limit ?? 8)
@@ -5229,7 +5412,7 @@ function registerTools(ctx, service, coordinator, runtimeMemory, documents) {
5229
5412
  render: (_args, value) => text(value)
5230
5413
  },
5231
5414
  execute: (args, exec) => {
5232
- if (!service.config.writeEnabled) throw new Error("dsh-mnemon is configured read-only (writeEnabled: false)");
5415
+ if (!config.writeEnabled) throw new Error("dsh-mnemon is configured read-only (writeEnabled: false)");
5233
5416
  const agent = requireAgent(exec);
5234
5417
  if (args.action === "archive") {
5235
5418
  if (isSubagent(agent)) throw new Error("idle document workers cannot cold-archive directly");
@@ -5252,7 +5435,7 @@ function registerTools(ctx, service, coordinator, runtimeMemory, documents) {
5252
5435
  ...args.sourcePaths === void 0 ? {} : { sourcePaths: args.sourcePaths },
5253
5436
  sessionIds: [agent.id]
5254
5437
  };
5255
- return isSubagent(agent) ? documents.forAgent(agent).mutate(request) : coordinator.document(agent, request, exec.signal);
5438
+ return isSubagent(agent) ? runtimeFor(exec).documents.forAgent(agent).mutate(request) : coordinator.document(agent, request, exec.signal);
5256
5439
  },
5257
5440
  presentCall: (args) => ({
5258
5441
  card: "generic",
@@ -5310,7 +5493,7 @@ function registerTools(ctx, service, coordinator, runtimeMemory, documents) {
5310
5493
  render: (_args, value) => text(value)
5311
5494
  },
5312
5495
  execute: (args, exec) => {
5313
- if (!service.config.writeEnabled) throw new Error("dsh-mnemon is configured read-only (writeEnabled: false)");
5496
+ if (!config.writeEnabled) throw new Error("dsh-mnemon is configured read-only (writeEnabled: false)");
5314
5497
  const request = {
5315
5498
  action: args.action,
5316
5499
  target: args.target,
@@ -5318,7 +5501,7 @@ function registerTools(ctx, service, coordinator, runtimeMemory, documents) {
5318
5501
  ...args.old_text === void 0 ? {} : { oldText: args.old_text },
5319
5502
  ...args.importance === void 0 ? {} : { importance: args.importance }
5320
5503
  };
5321
- return isSubagent(exec.agent) ? runtimeMemory.mutate(request) : coordinator.runtime(requireAgent(exec), request, exec.signal);
5504
+ return isSubagent(exec.agent) ? runtimeFor(exec).runtimeMemory.mutate(request) : coordinator.runtime(requireAgent(exec), request, exec.signal);
5322
5505
  },
5323
5506
  presentCall: (args) => ({
5324
5507
  card: "generic",
@@ -5379,7 +5562,7 @@ function registerTools(ctx, service, coordinator, runtimeMemory, documents) {
5379
5562
  ...args,
5380
5563
  source: args.source ?? "agent"
5381
5564
  };
5382
- return isSubagent(exec.agent) ? service.remember(request, exec.signal) : coordinator.remember(requireAgent(exec), request, exec.signal);
5565
+ return isSubagent(exec.agent) ? runtimeFor(exec).service.remember(request, exec.signal) : coordinator.remember(requireAgent(exec), request, exec.signal);
5383
5566
  },
5384
5567
  presentCall: () => ({
5385
5568
  card: "generic",
@@ -5420,7 +5603,7 @@ function registerTools(ctx, service, coordinator, runtimeMemory, documents) {
5420
5603
  render: (_args, value) => text(value)
5421
5604
  },
5422
5605
  async execute(args, exec) {
5423
- return isSubagent(exec.agent) ? service.link(args.sourceId, args.targetId, args.type, args.weight, args.reason, exec.signal, args.memoryBodyId) : coordinator.write(requireAgent(exec), "link", args, exec.signal);
5606
+ return isSubagent(exec.agent) ? runtimeFor(exec).service.link(args.sourceId, args.targetId, args.type, args.weight, args.reason, exec.signal, args.memoryBodyId) : coordinator.write(requireAgent(exec), "link", args, exec.signal);
5424
5607
  },
5425
5608
  presentCall: () => ({
5426
5609
  card: "generic",
@@ -5450,7 +5633,7 @@ function registerTools(ctx, service, coordinator, runtimeMemory, documents) {
5450
5633
  schema: JSON_OBJECT_OUTPUT,
5451
5634
  render: (_args, value) => text(value)
5452
5635
  },
5453
- execute: (args, exec) => isSubagent(exec.agent) ? service.forget(args.id, exec.signal, args.memoryBodyId) : coordinator.write(requireAgent(exec), "forget", args, exec.signal),
5636
+ execute: (args, exec) => isSubagent(exec.agent) ? runtimeFor(exec).service.forget(args.id, exec.signal, args.memoryBodyId) : coordinator.write(requireAgent(exec), "forget", args, exec.signal),
5454
5637
  presentCall: (args) => ({
5455
5638
  card: "generic",
5456
5639
  title: "Forget Mnemon insight",
@@ -5483,7 +5666,7 @@ function registerTools(ctx, service, coordinator, runtimeMemory, documents) {
5483
5666
  schema: JSON_OBJECT_OUTPUT,
5484
5667
  render: (_args, value) => text(value)
5485
5668
  },
5486
- execute: (args, exec) => isSubagent(exec.agent) ? service.createBody(args, exec.signal) : coordinator.write(requireAgent(exec), "create-memory-body", args, exec.signal),
5669
+ execute: (args, exec) => isSubagent(exec.agent) ? runtimeFor(exec).service.createBody(args, exec.signal) : coordinator.write(requireAgent(exec), "create-memory-body", args, exec.signal),
5487
5670
  presentCall: () => ({
5488
5671
  card: "generic",
5489
5672
  title: "Create Mnemon Memory Space",
@@ -5511,7 +5694,7 @@ function registerTools(ctx, service, coordinator, runtimeMemory, documents) {
5511
5694
  schema: JSON_OBJECT_OUTPUT,
5512
5695
  render: (_args, value) => text(value)
5513
5696
  },
5514
- execute: (args, exec) => isSubagent(exec.agent) ? service.updateBody(args.memoryBodyId, args) : coordinator.write(requireAgent(exec), "update-memory-body", args, exec.signal),
5697
+ execute: (args, exec) => isSubagent(exec.agent) ? runtimeFor(exec).service.updateBody(args.memoryBodyId, args) : coordinator.write(requireAgent(exec), "update-memory-body", args, exec.signal),
5515
5698
  presentCall: () => ({
5516
5699
  card: "generic",
5517
5700
  title: "Update Mnemon Memory Space",
@@ -5545,7 +5728,7 @@ function registerTools(ctx, service, coordinator, runtimeMemory, documents) {
5545
5728
  schema: JSON_OBJECT_OUTPUT,
5546
5729
  render: (_args, value) => text(value)
5547
5730
  },
5548
- execute: (args, exec) => isSubagent(exec.agent) ? service.mergeBodies(args.targetMemoryBodyId, args.sourceMemoryBodyIds, args.deactivateSources ?? true, exec.signal) : coordinator.write(requireAgent(exec), "merge-memory-bodies", args, exec.signal),
5731
+ execute: (args, exec) => isSubagent(exec.agent) ? runtimeFor(exec).service.mergeBodies(args.targetMemoryBodyId, args.sourceMemoryBodyIds, args.deactivateSources ?? true, exec.signal) : coordinator.write(requireAgent(exec), "merge-memory-bodies", args, exec.signal),
5549
5732
  presentCall: () => ({
5550
5733
  card: "generic",
5551
5734
  title: "Merge Mnemon Memory Spaces",
@@ -5565,7 +5748,8 @@ const inject = [
5565
5748
  "settings",
5566
5749
  "commands",
5567
5750
  "agents",
5568
- "subagents"
5751
+ "subagents",
5752
+ "workspaceRegistry"
5569
5753
  ];
5570
5754
  /** Mount native model tools on every DSH surface and UI RPC only when Web connection exists. */
5571
5755
  function apply(rawContext, config = {}) {
@@ -5578,7 +5762,7 @@ function apply(rawContext, config = {}) {
5578
5762
  prepared.set(value, createRuntimeGraph(resolveConfig(value)));
5579
5763
  }
5580
5764
  }).get();
5581
- const runtime = new LiveMnemonRuntime(prepared.get(initialSettings) ?? createRuntimeGraph(resolveConfig(initialSettings)));
5765
+ const runtime = new LiveMnemonRuntime(prepared.get(initialSettings) ?? createRuntimeGraph(resolveConfig(initialSettings)), ctx.workspaceRegistry, ctx.agents);
5582
5766
  const resolved = runtime.config;
5583
5767
  ctx.on("settings/updated", ((namespace, next) => {
5584
5768
  if (namespace !== "mnemon") return;
@@ -5588,15 +5772,15 @@ function apply(rawContext, config = {}) {
5588
5772
  base: resolveInteractionConfig(resolved.conversationInteraction),
5589
5773
  applies: "live"
5590
5774
  });
5591
- const coordinator = new MnemonSubagentCoordinator(ctx.subagents, runtime.runtimeMemory, runtime.documents);
5592
- const lifecycle = new MnemonLifecycle(ctx, coordinator, resolved);
5775
+ const coordinator = new MnemonSubagentCoordinator(ctx.subagents, runtime);
5776
+ const lifecycle = new MnemonLifecycle(ctx, coordinator, runtime.config, runtime);
5593
5777
  ctx.effect(() => lifecycle.start(), "dsh-mnemon.lifecycle-root()");
5594
- registerTools(ctx, runtime.service, coordinator, runtime.runtimeMemory, runtime.documents);
5595
- registerCommands(ctx.commands, runtime.service, coordinator);
5778
+ registerTools(ctx, runtime, coordinator);
5779
+ registerCommands(ctx.commands, runtime, coordinator);
5596
5780
  registerGuidance(ctx, resolved);
5597
5781
  registerRuntimeMemoryContext(ctx, runtime.runtimeMemory);
5598
5782
  ctx.inject(["connection"], (webContext) => {
5599
- registerRpc(webContext.connection, runtime.service, lifecycle, runtime.runtimeMemory, runtime.storage, runtime.packs);
5783
+ registerRpc(webContext.connection, runtime, lifecycle);
5600
5784
  registerSettingsRpc(webContext.connection, ctx.settings);
5601
5785
  });
5602
5786
  }