stratagate-dsh 0.3.20 → 0.3.22

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 (30) hide show
  1. package/CHANGELOG.md +719 -707
  2. package/LICENSE +21 -21
  3. package/dist/client.js +5 -4
  4. package/dist/index.js.map +1 -1
  5. package/dist/plugin.js +88 -37
  6. package/dist/plugin.js.map +1 -1
  7. package/docs/DSH.md +321 -290
  8. package/docs/DSH.zh-CN.md +282 -257
  9. package/docs/benchmarks/issue-128-windows-review.json +104 -104
  10. package/docs/benchmarks/issue-128-windows.json +103 -103
  11. package/docs/dreaming-agent.md +69 -69
  12. package/docs/feedback.md +50 -50
  13. package/docs/issue-128-lease-cache-review-followup.md +55 -55
  14. package/docs/issue-128-review-followup.md +58 -58
  15. package/docs/npm-release.md +52 -52
  16. package/docs/validation/frontend-feedback-20261021/background-refresh-failed.png +0 -0
  17. package/docs/validation/frontend-feedback-20261021/browser-results.json +334 -0
  18. package/docs/validation/frontend-feedback-20261021/first-read-graph.png +0 -0
  19. package/docs/validation/frontend-feedback-20261021/first-read-profile.png +0 -0
  20. package/docs/validation/frontend-feedback-20261021/first-read-short.png +0 -0
  21. package/docs/validation/frontend-feedback-20261021/profile-conflict.png +0 -0
  22. package/docs/validation/frontend-feedback-20261021/profile-save-regression.json +466 -0
  23. package/docs/validation/frontend-feedback-20261021/report.json +99 -0
  24. package/docs/validation/frontend-feedback-20261021/settings-saved-read-failed.png +0 -0
  25. package/docs/validation/frontend-feedback-20261021/settings-unknown.png +0 -0
  26. package/docs/validation/frontend-feedback-20261021/unit-results.json +1 -0
  27. package/docs/validation/issue119.md +41 -0
  28. package/docs/validation/workspace-cleanup-20261020.md +36 -0
  29. package/package.json +249 -249
  30. package/screenshots.json +8 -8
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/dsh-host-resolution.ts","../src/bootstrap.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\r\nimport { createRequire, registerHooks } from 'node:module'\r\nimport { dirname, isAbsolute, join, relative } from 'node:path'\r\nimport { fileURLToPath, pathToFileURL } from 'node:url'\r\n\r\nconst HOST_PACKAGES = [\r\n '@deepseek-ai/cordis',\r\n '@deepseek-ai/dsh-agent-default-model',\r\n '@deepseek-ai/dsh-client-ui-conversation',\r\n '@deepseek-ai/dsh-llm',\r\n '@deepseek-ai/dsh-native-command',\r\n '@deepseek-ai/dsh-session',\r\n '@deepseek-ai/dsh-session-format',\r\n '@deepseek-ai/dsh-session-format-catalog',\r\n '@deepseek-ai/dsh-session-format-v0-to-v1',\r\n '@deepseek-ai/dsh-settings',\r\n '@deepseek-ai/dsh-system-prompt',\r\n '@deepseek-ai/dsh-tools',\r\n '@deepseek-ai/schemastery',\r\n] as const\r\n\r\nconst installedHooks = Symbol.for('stratagate.dsh-host-resolution.v1')\r\n\r\nfunction isWithin(path: string, root: string): boolean {\r\n const child = relative(root, path)\r\n return child === '' || (!child.startsWith('..') && !isAbsolute(child))\r\n}\r\n\r\nfunction profileDirectory(start: string): string | undefined {\r\n let directory = start\r\n for (;;) {\r\n const manifestPath = join(directory, 'package.json')\r\n if (existsSync(manifestPath)) {\r\n try {\r\n const manifest = JSON.parse(readFileSync(manifestPath, 'utf8')) as { dsh?: { profile?: unknown } }\r\n if (manifest.dsh?.profile && typeof manifest.dsh.profile === 'object') return directory\r\n } catch {}\r\n }\r\n const parent = dirname(directory)\r\n if (parent === directory) return undefined\r\n directory = parent\r\n }\r\n}\r\n\r\nfunction hostPackage(specifier: string): boolean {\r\n return HOST_PACKAGES.some((name) => specifier === name || specifier.startsWith(`${name}/`))\r\n}\r\n\r\n/**\r\n * Force only StrataGate's DSH imports through the installation-owned fallback\r\n * created by DSH. The hook neither deletes nor rewrites the profile's package\r\n * tree, and imports belonging to the host or other plugins are untouched.\r\n */\r\nexport function installDshHostResolution(moduleUrl: string): boolean {\r\n const packageDirectory = dirname(dirname(fileURLToPath(moduleUrl)))\r\n const profile = profileDirectory(packageDirectory)\r\n if (!profile) return false\r\n\r\n const globalState = globalThis as typeof globalThis & { [installedHooks]?: Set<string> }\r\n const installed = globalState[installedHooks] ??= new Set<string>()\r\n const key = `${profile}\\u0000${packageDirectory}`\r\n if (installed.has(key)) return true\r\n\r\n const fallbackModules = join(dirname(profile), 'node_modules')\r\n const hostRequire = createRequire(join(fallbackModules, '.stratagate-host-resolution.cjs'))\r\n registerHooks({\r\n resolve(specifier, context, nextResolve) {\r\n const parent = context.parentURL?.startsWith('file:') ? fileURLToPath(context.parentURL) : undefined\r\n if (!hostPackage(specifier) || !parent || !isWithin(parent, packageDirectory)) {\r\n return nextResolve(specifier, context)\r\n }\r\n try {\r\n return { url: pathToFileURL(hostRequire.resolve(specifier)).href, shortCircuit: true }\r\n } catch (cause) {\r\n if (specifier === '@deepseek-ai/dsh-session-format-v0-to-v1'\r\n || specifier === '@deepseek-ai/dsh-session-format-catalog') {\r\n return nextResolve(specifier, context)\r\n }\r\n throw new Error(\r\n `StrataGate cannot resolve host-provided DSH package ${JSON.stringify(specifier)} from ${fallbackModules}. `\r\n + 'Start StrataGate through the DSH profile launcher so the host can prepare its module fallback.',\r\n { cause },\r\n )\r\n }\r\n },\r\n })\r\n installed.add(key)\r\n return true\r\n}\r\n","import { installDshHostResolution } from './dsh-host-resolution.js'\n\n// DSH prepares its installation-owned module fallback before it imports a\n// profile bundle. Install the narrowly-scoped resolver first, then load the\n// implementation so stale profile-local peers cannot win ESM resolution.\ninstallDshHostResolution(import.meta.url)\n\n// This file and src/index.ts are separate tsup entries. The runtime path is\n// intentionally external so the implementation is instantiated only after\n// the resolver above is active.\n// @ts-expect-error dist/plugin.js is emitted from src/index.ts during build.\nconst plugin = await import('./plugin.js') as typeof import('./index.js')\n\nexport const name = plugin.name\nexport const inject = plugin.inject\nexport const STRATAGATE_SETTINGS_NAMESPACE = plugin.STRATAGATE_SETTINGS_NAMESPACE\nexport const Config = plugin.Config\nexport const apply = plugin.apply\nexport type P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I,IAAY;AAClE,QAAM,MAAM,GAAG,OAAO,KAAS,gBAAgB;AAC/C,MAAI,UAAU,IAAI,GAAG,EAAG,QAAO;AAE/B,QAAM,kBAAkB,KAAK,QAAQ,OAAO,GAAG,cAAc;AAC7D,QAAM,cAAc,cAAc,KAAK,iBAAiB,iCAAiC,CAAC;AAC1F,gBAAc;AAAA,IACZ,QAAQ,WAAW,SAAS,aAAa;AACvC,YAAM,SAAS,QAAQ,WAAW,WAAW,OAAO,IAAI,cAAc,QAAQ,SAAS,IAAI;AAC3F,UAAI,CAAC,YAAY,SAAS,KAAK,CAAC,UAAU,CAAC,SAAS,QAAQ,gBAAgB,GAAG;AAC7E,eAAO,YAAY,WAAW,OAAO;AAAA,MACvC;AACA,UAAI;AACF,eAAO,EAAE,KAAK,cAAc,YAAY,QAAQ,SAAS,CAAC,EAAE,MAAM,cAAc,KAAK;AAAA,MACvF,SAAS,OAAO;AACd,YAAI,cAAc,8CACb,cAAc,2CAA2C;AAC5D,iBAAO,YAAY,WAAW,OAAO;AAAA,QACvC;AACA,cAAM,IAAI;AAAA,UACR,uDAAuD,KAAK,UAAU,SAAS,CAAC,SAAS,eAAe;AAAA,UAExG,EAAE,MAAM;AAAA,QACV;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACD,YAAU,IAAI,GAAG;AACjB,SAAO;AACT;;;ACnFA,yBAAyB,YAAY,GAAG;AAMxC,IAAM,SAAS,MAAM,OAAO,aAAa;AAElC,IAAM,OAAO,OAAO;AACpB,IAAM,SAAS,OAAO;AACtB,IAAM,gCAAgC,OAAO;AAC7C,IAAM,SAAS,OAAO;AACtB,IAAM,QAAQ,OAAO;","names":["name"]}
1
+ {"version":3,"sources":["../src/dsh-host-resolution.ts","../src/bootstrap.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\r\nimport { createRequire, registerHooks } from 'node:module'\r\nimport { dirname, isAbsolute, join, relative } from 'node:path'\r\nimport { fileURLToPath, pathToFileURL } from 'node:url'\r\n\r\nconst HOST_PACKAGES = [\r\n '@deepseek-ai/cordis',\r\n '@deepseek-ai/dsh-agent-default-model',\r\n '@deepseek-ai/dsh-client-ui-conversation',\r\n '@deepseek-ai/dsh-llm',\r\n '@deepseek-ai/dsh-native-command',\r\n '@deepseek-ai/dsh-session',\r\n '@deepseek-ai/dsh-session-format',\r\n '@deepseek-ai/dsh-session-format-catalog',\r\n '@deepseek-ai/dsh-session-format-v0-to-v1',\r\n '@deepseek-ai/dsh-settings',\r\n '@deepseek-ai/dsh-system-prompt',\r\n '@deepseek-ai/dsh-tools',\r\n '@deepseek-ai/schemastery',\r\n] as const\r\n\r\nconst installedHooks = Symbol.for('stratagate.dsh-host-resolution.v1')\r\n\r\nfunction isWithin(path: string, root: string): boolean {\r\n const child = relative(root, path)\r\n return child === '' || (!child.startsWith('..') && !isAbsolute(child))\r\n}\r\n\r\nfunction profileDirectory(start: string): string | undefined {\r\n let directory = start\r\n for (;;) {\r\n const manifestPath = join(directory, 'package.json')\r\n if (existsSync(manifestPath)) {\r\n try {\r\n const manifest = JSON.parse(readFileSync(manifestPath, 'utf8')) as { dsh?: { profile?: unknown } }\r\n if (manifest.dsh?.profile && typeof manifest.dsh.profile === 'object') return directory\r\n } catch {}\r\n }\r\n const parent = dirname(directory)\r\n if (parent === directory) return undefined\r\n directory = parent\r\n }\r\n}\r\n\r\nfunction hostPackage(specifier: string): boolean {\r\n return HOST_PACKAGES.some((name) => specifier === name || specifier.startsWith(`${name}/`))\r\n}\r\n\r\n/**\r\n * Force only StrataGate's DSH imports through the installation-owned fallback\r\n * created by DSH. The hook neither deletes nor rewrites the profile's package\r\n * tree, and imports belonging to the host or other plugins are untouched.\r\n */\r\nexport function installDshHostResolution(moduleUrl: string): boolean {\r\n const packageDirectory = dirname(dirname(fileURLToPath(moduleUrl)))\r\n const profile = profileDirectory(packageDirectory)\r\n if (!profile) return false\r\n\r\n const globalState = globalThis as typeof globalThis & { [installedHooks]?: Set<string> }\r\n const installed = globalState[installedHooks] ??= new Set<string>()\r\n const key = `${profile}\\u0000${packageDirectory}`\r\n if (installed.has(key)) return true\r\n\r\n const fallbackModules = join(dirname(profile), 'node_modules')\r\n const hostRequire = createRequire(join(fallbackModules, '.stratagate-host-resolution.cjs'))\r\n registerHooks({\r\n resolve(specifier, context, nextResolve) {\r\n const parent = context.parentURL?.startsWith('file:') ? fileURLToPath(context.parentURL) : undefined\r\n if (!hostPackage(specifier) || !parent || !isWithin(parent, packageDirectory)) {\r\n return nextResolve(specifier, context)\r\n }\r\n try {\r\n return { url: pathToFileURL(hostRequire.resolve(specifier)).href, shortCircuit: true }\r\n } catch (cause) {\r\n if (specifier === '@deepseek-ai/dsh-session-format-v0-to-v1'\r\n || specifier === '@deepseek-ai/dsh-session-format-catalog') {\r\n return nextResolve(specifier, context)\r\n }\r\n throw new Error(\r\n `StrataGate cannot resolve host-provided DSH package ${JSON.stringify(specifier)} from ${fallbackModules}. `\r\n + 'Start StrataGate through the DSH profile launcher so the host can prepare its module fallback.',\r\n { cause },\r\n )\r\n }\r\n },\r\n })\r\n installed.add(key)\r\n return true\r\n}\r\n","import { installDshHostResolution } from './dsh-host-resolution.js'\r\n\r\n// DSH prepares its installation-owned module fallback before it imports a\r\n// profile bundle. Install the narrowly-scoped resolver first, then load the\r\n// implementation so stale profile-local peers cannot win ESM resolution.\r\ninstallDshHostResolution(import.meta.url)\r\n\r\n// This file and src/index.ts are separate tsup entries. The runtime path is\r\n// intentionally external so the implementation is instantiated only after\r\n// the resolver above is active.\r\n// @ts-expect-error dist/plugin.js is emitted from src/index.ts during build.\r\nconst plugin = await import('./plugin.js') as typeof import('./index.js')\r\n\r\nexport const name = plugin.name\r\nexport const inject = plugin.inject\r\nexport const STRATAGATE_SETTINGS_NAMESPACE = plugin.STRATAGATE_SETTINGS_NAMESPACE\r\nexport const Config = plugin.Config\r\nexport const apply = plugin.apply\r\nexport type PluginConfig = import('./index.js').PluginConfig\r\n"],"mappings":";AAAA,SAAS,YAAY,oBAAoB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MAAI,UAAU,IAAI,GAAG,EAAG,QAAO;AAE/B,QAAM,kBAAkB,KAAK,QAAQ,OAAO,GAAG,cAAc;AAC7D,QAAM,cAAc,cAAc,KAAK,iBAAiB,iCAAiC,CAAC;AAC1F,gBAAc;AAAA,IACZ,QAAQ,WAAW,SAAS,aAAa;AACvC,YAAM,SAAS,QAAQ,WAAW,WAAW,OAAO,IAAI,cAAc,QAAQ,SAAS,IAAI;AAC3F,UAAI,CAAC,YAAY,SAAS,KAAK,CAAC,UAAU,CAAC,SAAS,QAAQ,gBAAgB,GAAG;AAC7E,eAAO,YAAY,WAAW,OAAO;AAAA,MACvC;AACA,UAAI;AACF,eAAO,EAAE,KAAK,cAAc,YAAY,QAAQ,SAAS,CAAC,EAAE,MAAM,cAAc,KAAK;AAAA,MACvF,SAAS,OAAO;AACd,YAAI,cAAc,8CACb,cAAc,2CAA2C;AAC5D,iBAAO,YAAY,WAAW,OAAO;AAAA,QACvC;AACA,cAAM,IAAI;AAAA,UACR,uDAAuD,KAAK,UAAU,SAAS,CAAC,SAAS,eAAe;AAAA,UAExG,EAAE,MAAM;AAAA,QACV;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACD,YAAU,IAAI,GAAG;AACjB,SAAO;AACT;;;ACnFA,yBAAyB,YAAY,GAAG;AAMxC,IAAM,SAAS,MAAM,OAAO,aAAa;AAElC,IAAM,OAAO,OAAO;AACpB,IAAM,SAAS,OAAO;AACtB,IAAM,gCAAgC,OAAO;AAC7C,IAAM,SAAS,OAAO;AACtB,IAAM,QAAQ,OAAO;","names":["name"]}
package/dist/plugin.js CHANGED
@@ -6770,6 +6770,11 @@ var StrataGate = class _StrataGate {
6770
6770
  };
6771
6771
  });
6772
6772
  }
6773
+ /** Query-independent availability in this namespace, before filters/pagination. */
6774
+ hasSearchableEvents(options = {}) {
6775
+ const visible2 = (event) => event.status === "active" || event.status === "superseded";
6776
+ return this.events.some(visible2) || Math.max(0, options.agentMemoryWeight ?? 1) > 0 && this.agentEvents.some(visible2);
6777
+ }
6773
6778
  async searchEvents(query, options = {}) {
6774
6779
  const limit = Math.max(1, Math.min(20, options.limit ?? 6));
6775
6780
  const offset = options.offset ?? 0;
@@ -7076,6 +7081,10 @@ var StrataGate = class _StrataGate {
7076
7081
  if (!element) throw new Error(`Unknown element: ${id}`);
7077
7082
  return elementViewAt(element, at);
7078
7083
  }
7084
+ /** Only sealed source messages are searched; open tails are native context. */
7085
+ hasSearchableRawMessages(options = {}) {
7086
+ return this.blocks.some((block) => block.l5Raw.some((message) => (options.threadId === void 0 || message.threadId === options.threadId || options.includeUnthreaded === true && message.threadId === void 0) && searchTokens(message.content).length > 0));
7087
+ }
7079
7088
  searchRawMemory(query, limit = 6, options = {}) {
7080
7089
  const tokens = searchTokens(query);
7081
7090
  if (tokens.length === 0) return [];
@@ -7820,6 +7829,11 @@ ${duplicate.summary}` : duplicate.summary;
7820
7829
  if (!job) throw new Error(`Unknown element projection: ${id}`);
7821
7830
  return job;
7822
7831
  }
7832
+ /** Use the same Event-authoritative visibility boundary as Graph search. */
7833
+ hasSearchableGraphNodes() {
7834
+ const events = this.listAllEvents();
7835
+ return this.graphNodes.some((node) => effectiveGraphNodeView(node, this.graphEdges, events) !== null);
7836
+ }
7823
7837
  async searchGraphNodes(query, limit = 8) {
7824
7838
  const queryTokens = [...new Set(searchTokens(query))];
7825
7839
  if (queryTokens.length === 0) return [];
@@ -12508,12 +12522,15 @@ var StrataGateRuntime = class {
12508
12522
  }
12509
12523
  })),
12510
12524
  results.map(({ event, score }) => compactEvent2(event, score)),
12511
- topicId !== void 0 ? {
12512
- topicId,
12513
- totalSourceEvents,
12514
- offset,
12515
- nextOffset: results.length === Math.max(1, Math.min(20, searchOptions.limit ?? 6)) && (totalSourceEvents === null || offset + results.length < totalSourceEvents) ? offset + results.length : null
12516
- } : {}
12525
+ {
12526
+ ...searchStatus(results, () => memory.hasSearchableEvents?.({ agentMemoryWeight: this.agentMemoryRetrievalWeight })),
12527
+ ...topicId !== void 0 ? {
12528
+ topicId,
12529
+ totalSourceEvents,
12530
+ offset,
12531
+ nextOffset: results.length === Math.max(1, Math.min(20, searchOptions.limit ?? 6)) && (totalSourceEvents === null || offset + results.length < totalSourceEvents) ? offset + results.length : null
12532
+ } : {}
12533
+ }
12517
12534
  );
12518
12535
  }
12519
12536
  /** A navigation read never creates a retrieval batch or reinforces sources. */
@@ -12611,7 +12628,12 @@ var StrataGateRuntime = class {
12611
12628
  elementIds: [],
12612
12629
  citation: citation("block", result.blockId, blockTitles.get(result.blockId) ?? "Block", `raw:${result.blockId}:${result.message.id}:${index}`, "blockId")
12613
12630
  }
12614
- })), results.map(compactRawHit), { scope, namespace: this.namespaceFor(session), threadId });
12631
+ })), results.map(compactRawHit), {
12632
+ scope,
12633
+ namespace: this.namespaceFor(session),
12634
+ threadId,
12635
+ ...searchStatus(results, () => memory.hasSearchableRawMessages?.(scope === "namespace" ? {} : { threadId }))
12636
+ });
12615
12637
  }
12616
12638
  async blocks(session, scope = "session", options = {}) {
12617
12639
  await this.flush();
@@ -13795,6 +13817,10 @@ var StrataGateRuntime = class {
13795
13817
  database.close();
13796
13818
  }
13797
13819
  }
13820
+ async adminSettings() {
13821
+ await this.settingsTail;
13822
+ return { blockTurnSize: this.blockTurnSize, blockDecayLambda: this.blockDecayLambda, agentMemoryRetrievalWeight: this.agentMemoryRetrievalWeight };
13823
+ }
13798
13824
  async adminSetBlockDecayLambda(value) {
13799
13825
  if (!Number.isFinite(value) || value < 0) {
13800
13826
  throw new TypeError("blockDecayLambda must be a non-negative finite number");
@@ -14082,7 +14108,8 @@ var StrataGateRuntime = class {
14082
14108
  }
14083
14109
  async searchGraph(session, query, limit = 8) {
14084
14110
  await this.flush();
14085
- const results = await (await this.space(session)).searchGraphNodes(query, limit);
14111
+ const memory = await this.space(session);
14112
+ const results = await memory.searchGraphNodes(query, limit);
14086
14113
  return this.batch(session, results.map(({ node, provenanceEventIds }) => ({
14087
14114
  ref: `graph-node:${node.id}`,
14088
14115
  target: {
@@ -14090,7 +14117,7 @@ var StrataGateRuntime = class {
14090
14117
  elementIds: [],
14091
14118
  citation: citation("graph", node.id, node.name, `graph-node:${node.id}`, "nodeId")
14092
14119
  }
14093
- })), results.map(compactGraphNode));
14120
+ })), results.map(compactGraphNode), searchStatus(results, () => memory.hasSearchableGraphNodes?.()));
14094
14121
  }
14095
14122
  async expandGraphNode(session, id) {
14096
14123
  await this.flush();
@@ -14673,6 +14700,18 @@ function activatedElements(memory, relevance) {
14673
14700
  weight
14674
14701
  ]).map(({ item }) => item);
14675
14702
  }
14703
+ function searchStatus(results, hasSearchableRecords) {
14704
+ if (results.length > 0) return { retrievalStatus: "matched" };
14705
+ const available = hasSearchableRecords();
14706
+ if (available === false) return {
14707
+ retrievalStatus: "scope_empty",
14708
+ retrievalHint: "\u5F53\u524D\u641C\u7D22\u8303\u56F4\u5185\u6CA1\u6709\u53EF\u641C\u7D22\u8BB0\u5F55\uFF1B\u4E0D\u80FD\u636E\u6B64\u65AD\u8A00\u5176\u4ED6\u8303\u56F4\u6216\u4ECE\u524D\u672A\u8BB0\u5F55\u8FC7\u3002"
14709
+ };
14710
+ return {
14711
+ retrievalStatus: available === true ? "no_match" : "unknown",
14712
+ retrievalHint: available === true ? "\u672C\u6B21\u68C0\u7D22\u672A\u627E\u5230\u5339\u914D\uFF0C\u4E0D\u80FD\u636E\u6B64\u65AD\u8A00\u76F8\u5173\u8BB0\u5FC6\u4E0D\u5B58\u5728\u3002" : "\u672C\u6B21\u672A\u8FD4\u56DE\u5339\u914D\uFF0C\u65E0\u6CD5\u53EF\u9760\u5224\u65AD\u5F53\u524D\u8303\u56F4\u662F\u5426\u6709\u53EF\u641C\u7D22\u8BB0\u5F55\uFF1B\u4E0D\u80FD\u636E\u6B64\u65AD\u8A00\u76F8\u5173\u8BB0\u5FC6\u4E0D\u5B58\u5728\u3002"
14713
+ };
14714
+ }
14676
14715
  function renderActivatedMemory(events, graphResults) {
14677
14716
  const heading = [
14678
14717
  "[Activated long-term memory]",
@@ -14729,7 +14768,7 @@ KnowledgeGraph:
14729
14768
  tokens += cost;
14730
14769
  nodeCount += 1;
14731
14770
  }
14732
- if (eventCount === 0 && nodeCount === 0) lines.push("(no activated memory)");
14771
+ if (eventCount === 0 && nodeCount === 0) lines.push("(no memory selected for automatic context)");
14733
14772
  return lines.join("\n");
14734
14773
  }
14735
14774
  function activeTurn(session) {
@@ -15111,6 +15150,7 @@ import { defineTool as defineTool2 } from "@deepseek-ai/dsh-tools";
15111
15150
  var AGENT_FEEDBACK_ENABLED = true;
15112
15151
 
15113
15152
  // src/tools.ts
15153
+ var SEARCH_RESULT_GUIDANCE = " Read retrievalStatus and retrievalHint: scope_empty applies only to this search scope; no_match means this query found no match; unknown means scope availability could not be determined. An empty result never proves a memory was never recorded. \u4E0D\u5F97\u628A\u7A7A\u7ED3\u679C\u8868\u8FF0\u6210\u201C\u6CA1\u6709\u8FD9\u6761\u8BB0\u5FC6\u201D\u6216\u201C\u4F60\u6CA1\u8BF4\u8FC7\u201D\u3002\u68C0\u7D22\u5F02\u5E38\u6309\u5DE5\u5177\u9519\u8BEF\u5904\u7406\uFF0C\u4E0D\u662F\u6B63\u5E38\u7A7A\u7ED3\u679C\u3002\u72B6\u6001\u63D0\u793A\u4E0D\u662F\u4E8B\u5B9E\u8BC1\u636E\uFF0C\u4E0D\u5F97\u91C7\u7528\u6216\u5F3A\u5316\u3002";
15114
15154
  var jsonOutput = {
15115
15155
  schema: { type: "json" },
15116
15156
  render: (_args, value) => [{
@@ -15206,7 +15246,7 @@ function registerMemoryTools(ctx, runtime) {
15206
15246
  }));
15207
15247
  ctx.tools.register(defineTool2({
15208
15248
  name: "memory_search_events",
15209
- description: "This tool is provided by the StrataGate plugin. Search durable Event memories for past facts, decisions, plans, changes, preferences, outcomes, and timing. Use a focused query with the most distinctive known names, entities, versions, tools, decisions, or outcomes. Results are compact candidates; rankScore reflects retrieval order only, not confidence or factual accuracy. Expand a relevant Event when its compact fields are not enough to verify the needed detail. Optionally pass topic_id to search within a navigated topic; query may be empty to browse its events, offset continues pagination, and temporalIntent first/latest controls chronology.",
15249
+ description: "This tool is provided by the StrataGate plugin. Search durable Event memories for past facts, decisions, plans, changes, preferences, outcomes, and timing. Use a focused query with the most distinctive known names, entities, versions, tools, decisions, or outcomes. Results are compact candidates; rankScore reflects retrieval order only, not confidence or factual accuracy. Expand a relevant Event when its compact fields are not enough to verify the needed detail. Optionally pass topic_id to search within a navigated topic; query may be empty to browse its events, offset continues pagination, and temporalIntent first/latest controls chronology." + SEARCH_RESULT_GUIDANCE,
15210
15250
  parameters: {
15211
15251
  query: { type: "string", required: true, description: "A focused query for the target historical memory. Prefer explicit names, entities, versions, tools, decisions, or outcomes over vague references. May be empty when browsing a supplied topic_id." },
15212
15252
  topic_id: { type: "string", description: "\u76EE\u5F55\u4E2D\u7684\u4E3B\u9898 ID\uFF1B\u9650\u5B9A\u771F\u5B9E\u6765\u6E90\u4E8B\u4EF6\uFF0C\u7A7A query \u53EF\u6D4F\u89C8\u3002" },
@@ -15228,7 +15268,7 @@ function registerMemoryTools(ctx, runtime) {
15228
15268
  }));
15229
15269
  ctx.tools.register(defineTool2({
15230
15270
  name: "memory_search_graph",
15231
- description: "This tool is provided by the StrataGate plugin. Search the Event-backed Knowledge Graph for current state and query-relevant history. Results explicitly label current, historical, or both; historical matches never imply current truth, disputed records remain marked, and Event evidence is bounded to the match. Endpoint names and aliases can match relations, while relation text alone is ranking context. rankScore is ranking-only, never confidence or factual accuracy.",
15271
+ description: "This tool is provided by the StrataGate plugin. Search the Event-backed Knowledge Graph for current state and query-relevant history. Results explicitly label current, historical, or both; historical matches never imply current truth, disputed records remain marked, and Event evidence is bounded to the match. Endpoint names and aliases can match relations, while relation text alone is ranking context. rankScore is ranking-only, never confidence or factual accuracy." + SEARCH_RESULT_GUIDANCE,
15232
15272
  parameters: {
15233
15273
  query: { type: "string", required: true },
15234
15274
  limit: { type: "integer", description: "Maximum results, 1-20." }
@@ -15245,7 +15285,7 @@ function registerMemoryTools(ctx, runtime) {
15245
15285
  }));
15246
15286
  ctx.tools.register(defineTool2({
15247
15287
  name: "memory_search_raw",
15248
- description: "This tool is provided by the StrataGate plugin. Search archived messages when summarized memories are insufficient. Returns compact raw hits (message id, blockId, excerpt, role, and time); use memory_expand_block with blockId for complete source details. By default searches the whole current namespace; use scope=session for the active thread. Returns evidence refs and batchId for assessment.",
15288
+ description: "This tool is provided by the StrataGate plugin. Search archived messages when summarized memories are insufficient. Returns compact raw hits (message id, blockId, excerpt, role, and time); use memory_expand_block with blockId for complete source details. By default searches the whole current namespace; use scope=session for the active thread. Returns evidence refs and batchId for assessment." + SEARCH_RESULT_GUIDANCE,
15249
15289
  parameters: {
15250
15290
  query: { type: "string", required: true },
15251
15291
  limit: { type: "integer" },
@@ -16808,11 +16848,12 @@ async function dashboard(runtime, url, ifNoneMatch) {
16808
16848
  const requestedNamespace = url.searchParams.get("namespace")?.trim() ?? "";
16809
16849
  const selected = entries.find(({ namespace }) => namespace === requestedNamespace) ?? entries[0];
16810
16850
  const threadId = url.searchParams.get("threadId")?.trim() ?? "";
16851
+ const region = url.searchParams.get("region") || "";
16811
16852
  const revisionKey = entries.map(({ namespace, revision }) => `${namespace}:${revision}`).join("|");
16812
16853
  const agentMemoryWeight = runtime.adminAgentMemoryRetrievalWeight?.() ?? 1;
16813
16854
  const duplicateKey = JSON.stringify(entries.map(({ namespace }) => runtime.adminDuplicateRepairStatus?.(namespace) ?? null));
16814
16855
  const etag = `"${createHash6("sha256").update(`${STRATAGATE_DSH_VERSION}\0${TOPIC_DIRECTORY_VIEW_VERSION}\0${revisionKey}\0${selected?.namespace ?? ""}\0${threadId}\0${agentMemoryWeight}\0${duplicateKey}`).digest("base64url").slice(0, 24)}"`;
16815
- if (ifNoneMatch.split(",").map((value) => value.trim()).includes(etag)) return { etag, notModified: true };
16856
+ if (!region && ifNoneMatch.split(",").map((value) => value.trim()).includes(etag)) return { etag, notModified: true };
16816
16857
  const overviewValue = await overview(runtime, entries);
16817
16858
  if (!selected) {
16818
16859
  return { etag, notModified: false, body: { namespace: null, overview: overviewValue, data: null, processing: false } };
@@ -16827,42 +16868,50 @@ async function dashboard(runtime, url, ifNoneMatch) {
16827
16868
  if (limit) target.searchParams.set("limit", limit);
16828
16869
  return target;
16829
16870
  };
16830
- const [eventResult, graphResult, blockResult, auditResult] = await Promise.all([
16831
- memories(snapshotRuntime, memoryUrl("events", "40")),
16832
- memories(snapshotRuntime, memoryUrl("graph")),
16833
- memories(snapshotRuntime, memoryUrl("blocks", "40")),
16834
- audit(snapshotRuntime, memoryUrl("audit", "100"))
16835
- ]);
16871
+ const readers = {
16872
+ events: () => memories(snapshotRuntime, memoryUrl("events", "40")),
16873
+ graph: () => memories(snapshotRuntime, memoryUrl("graph")),
16874
+ blocks: () => memories(snapshotRuntime, memoryUrl("blocks", "40")),
16875
+ audit: () => audit(snapshotRuntime, memoryUrl("audit", "100")),
16876
+ topics: () => topicDirectoryProjection(selected.snapshot, agentMemoryWeight).data
16877
+ };
16878
+ if (region && !Object.hasOwn(readers, region)) throw new AdminHttpError(400, "Unknown dashboard region");
16879
+ const keys = region ? [region] : Object.keys(readers);
16880
+ const results = await Promise.allSettled(keys.map((key) => Promise.resolve().then(readers[key])));
16881
+ const values = {}, readErrors = {};
16882
+ results.forEach((result, index) => {
16883
+ if (result.status === "fulfilled") values[keys[index]] = result.value;
16884
+ else readErrors[keys[index]] = "Content could not be read";
16885
+ });
16886
+ const { events: eventResult, graph: graphResult, blocks: blockResult, audit: auditResult, topics: topicDirectoryData } = values;
16836
16887
  const selectedOverview = overviewValue.namespaces?.find(({ namespace }) => namespace === selected.namespace);
16837
- const topicDirectoryData = topicDirectoryProjection(selected.snapshot, agentMemoryWeight).data;
16838
16888
  return {
16839
- etag,
16889
+ // Never cache a partial failure as a valid unchanged response.
16890
+ etag: region || Object.keys(readErrors).length ? "" : etag,
16840
16891
  notModified: false,
16841
16892
  body: {
16842
16893
  namespace: selected.namespace,
16843
16894
  revision: selected.revision,
16844
16895
  overview: overviewValue,
16845
- processing: Number(selectedOverview?.processingJobs ?? 0) > 0 || selectedOverview?.duplicateRepair?.status === "pending" || topicDirectoryData.bootstrap !== null && topicDirectoryData.bootstrap.total > 0 && (topicDirectoryData.bootstrap.status === "pending" || topicDirectoryData.bootstrap.status === "running"),
16896
+ readErrors,
16897
+ processing: Number(selectedOverview?.processingJobs ?? 0) > 0 || selectedOverview?.duplicateRepair?.status === "pending" || topicDirectoryData?.bootstrap != null && topicDirectoryData.bootstrap.total > 0 && (topicDirectoryData.bootstrap.status === "pending" || topicDirectoryData.bootstrap.status === "running"),
16846
16898
  data: {
16847
- events: eventResult.items ?? [],
16848
- graph: graphResult,
16849
- blocks: blockResult.items ?? [],
16850
- openBlock: blockResult.openBlock ?? null,
16851
- conversations: blockResult.conversations ?? [],
16852
- activeThreadId: blockResult.activeThreadId ?? null,
16853
- audit: auditResult.items ?? [],
16854
- topicDirectory: topicDirectoryData,
16899
+ ...eventResult ? { events: eventResult.items ?? [] } : {},
16900
+ ...graphResult ? { graph: graphResult } : {},
16901
+ ...blockResult ? { blocks: blockResult.items ?? [], openBlock: blockResult.openBlock ?? null, conversations: blockResult.conversations ?? [], activeThreadId: blockResult.activeThreadId ?? null } : {},
16902
+ ...auditResult ? { audit: auditResult.items ?? [] } : {},
16903
+ ...topicDirectoryData ? { topicDirectory: topicDirectoryData } : {},
16855
16904
  pagination: {
16856
- events: { total: eventResult.total ?? 0, offset: eventResult.offset ?? 0, limit: eventResult.limit ?? 40 },
16857
- blocks: { total: blockResult.total ?? 0, offset: blockResult.offset ?? 0, limit: blockResult.limit ?? 40 },
16858
- audit: { total: auditResult.total ?? 0, offset: auditResult.offset ?? 0, limit: auditResult.limit ?? 100 }
16905
+ ...eventResult ? { events: { total: eventResult.total ?? 0, offset: eventResult.offset ?? 0, limit: eventResult.limit ?? 40 } } : {},
16906
+ ...blockResult ? { blocks: { total: blockResult.total ?? 0, offset: blockResult.offset ?? 0, limit: blockResult.limit ?? 40 } } : {},
16907
+ ...auditResult ? { audit: { total: auditResult.total ?? 0, offset: auditResult.offset ?? 0, limit: auditResult.limit ?? 100 } } : {}
16859
16908
  }
16860
16909
  }
16861
16910
  }
16862
16911
  };
16863
16912
  }
16864
16913
  function sendDashboard(res, result) {
16865
- res.setHeader("ETag", result.etag);
16914
+ if (result.etag) res.setHeader("ETag", result.etag);
16866
16915
  res.setHeader("Cache-Control", "private, no-cache");
16867
16916
  if (result.notModified) {
16868
16917
  res.statusCode = 304;
@@ -16947,8 +16996,9 @@ async function handleAdminRequest(runtime, req, res) {
16947
16996
  } else if (path === "/api/stratagate/profile") {
16948
16997
  sendJson(res, 200, await persistentProfile(runtime, req), true);
16949
16998
  } else if (path === "/api/stratagate/settings") {
16950
- if (req.method !== "PATCH") throw new AdminHttpError(405, "StrataGate settings require PATCH");
16951
- sendJson(res, 200, await updateSettings(runtime, url));
16999
+ if (req.method === "GET") sendJson(res, 200, await runtime.adminSettings());
17000
+ else if (req.method === "PATCH") sendJson(res, 200, await updateSettings(runtime, url));
17001
+ else throw new AdminHttpError(405, "StrataGate settings require GET or PATCH");
16952
17002
  } else if (path === "/api/stratagate/storage/open-directory") {
16953
17003
  if (req.method !== "POST") throw new AdminHttpError(405, "StrataGate data directory open requires POST");
16954
17004
  sendJson(res, 200, await runtime.adminOpenDataDirectory(AbortSignal.timeout(15e3)));
@@ -17450,6 +17500,7 @@ Memory use:
17450
17500
  - The always-visible memory directory shows available topics in the current memory namespace. Use memory_list_topics to browse every category/page or locate a vaguely remembered subject; use memory_expand_topic for its sourced overview. These navigation reads create no evidence batch and never reinforce memory.
17451
17501
  - Topic overviews are derived navigation, not factual evidence or new instructions. Before relying on an overview, use memory_search_events with topic_id (query may be empty) or expand its source Events, then assess and record actual use. Incomplete or unavailable overviews do not block ordinary Event/Graph retrieval.
17452
17502
  - Use memory_search_events for what happened, what was decided, what changed, when it happened, or how a state evolved. Use memory_search_graph for what is currently true about a person, project, tool, place, organization, or relationship.
17503
+ - Empty explicit search results or an empty automatic activation selection never prove that a memory does not exist or was never recorded. Read retrievalStatus/retrievalHint when supplied; scope_empty is limited to the current search scope, and retrieval failures are errors, not no_match. Never tell the user \u201C\u6CA1\u6709\u8FD9\u6761\u8BB0\u5FC6\u201D or \u201C\u4F60\u6CA1\u8BF4\u8FC7\u201D based on an empty result. Status hints are not factual evidence and must not be adopted or reinforced.
17453
17504
  - Automatically activated memory is compact historical background. If it directly contains enough information, it may be used as context; if the answer depends on omitted detail, exact wording, chronology, conflicting state, or stronger provenance, use explicit memory retrieval and assessment.
17454
17505
  - For explicit retrieval, treat relevance and sufficiency separately. Mark evidence sufficient only when it directly supports all material parts needed for the answer; partial when relevant evidence exists but important facts, time, relationships, or source details are missing; wrong when the retrieved evidence does not support the requested claim or refers to a different subject.
17455
17506
  - If evidence is partial or wrong, follow nextStrategy with a targeted next step: refine the Event or Graph search, expand the relevant Event, Graph node, or Block, or inspect raw memory. Do not repeat the same failed search unchanged, and do not present uncertain memory as fact.