stratagate-dsh 0.3.27 → 0.3.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/dist/client.d.ts +1 -1
- package/dist/client.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/plugin.js +147 -64
- package/dist/plugin.js.map +1 -1
- package/dist/repair-profile.js.map +1 -1
- package/docs/DSH.md +5 -0
- package/docs/DSH.zh-CN.md +5 -0
- package/docs/validation/frontend-feedback-20261021/background-refresh-failed.png +0 -0
- package/docs/validation/frontend-feedback-20261021/browser-results.json +334 -0
- package/docs/validation/frontend-feedback-20261021/first-read-graph.png +0 -0
- package/docs/validation/frontend-feedback-20261021/first-read-profile.png +0 -0
- package/docs/validation/frontend-feedback-20261021/first-read-short.png +0 -0
- package/docs/validation/frontend-feedback-20261021/profile-conflict.png +0 -0
- package/docs/validation/frontend-feedback-20261021/profile-save-regression.json +466 -0
- package/docs/validation/frontend-feedback-20261021/report.json +99 -0
- package/docs/validation/frontend-feedback-20261021/settings-saved-read-failed.png +0 -0
- package/docs/validation/frontend-feedback-20261021/settings-unknown.png +0 -0
- package/docs/validation/frontend-feedback-20261021/unit-results.json +1 -0
- package/docs/validation/issue119.md +41 -0
- package/docs/validation/workspace-cleanup-20261020.md +36 -0
- package/package.json +1 -1
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'\
|
|
1
|
+
{"version":3,"sources":["../src/dsh-host-resolution.ts","../src/bootstrap.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { createRequire, registerHooks } from 'node:module'\nimport { dirname, isAbsolute, join, relative } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\n\nconst HOST_PACKAGES = [\n '@deepseek-ai/cordis',\n '@deepseek-ai/dsh-agent-default-model',\n '@deepseek-ai/dsh-client-ui-conversation',\n '@deepseek-ai/dsh-llm',\n '@deepseek-ai/dsh-native-command',\n '@deepseek-ai/dsh-session',\n '@deepseek-ai/dsh-session-format',\n '@deepseek-ai/dsh-session-format-catalog',\n '@deepseek-ai/dsh-session-format-v0-to-v1',\n '@deepseek-ai/dsh-settings',\n '@deepseek-ai/dsh-system-prompt',\n '@deepseek-ai/dsh-tools',\n '@deepseek-ai/schemastery',\n] as const\n\nconst installedHooks = Symbol.for('stratagate.dsh-host-resolution.v1')\n\nfunction isWithin(path: string, root: string): boolean {\n const child = relative(root, path)\n return child === '' || (!child.startsWith('..') && !isAbsolute(child))\n}\n\nfunction profileDirectory(start: string): string | undefined {\n let directory = start\n for (;;) {\n const manifestPath = join(directory, 'package.json')\n if (existsSync(manifestPath)) {\n try {\n const manifest = JSON.parse(readFileSync(manifestPath, 'utf8')) as { dsh?: { profile?: unknown } }\n if (manifest.dsh?.profile && typeof manifest.dsh.profile === 'object') return directory\n } catch {}\n }\n const parent = dirname(directory)\n if (parent === directory) return undefined\n directory = parent\n }\n}\n\nfunction hostPackage(specifier: string): boolean {\n return HOST_PACKAGES.some((name) => specifier === name || specifier.startsWith(`${name}/`))\n}\n\n/**\n * Force only StrataGate's DSH imports through the installation-owned fallback\n * created by DSH. The hook neither deletes nor rewrites the profile's package\n * tree, and imports belonging to the host or other plugins are untouched.\n */\nexport function installDshHostResolution(moduleUrl: string): boolean {\n const packageDirectory = dirname(dirname(fileURLToPath(moduleUrl)))\n const profile = profileDirectory(packageDirectory)\n if (!profile) return false\n\n const globalState = globalThis as typeof globalThis & { [installedHooks]?: Set<string> }\n const installed = globalState[installedHooks] ??= new Set<string>()\n const key = `${profile}\\u0000${packageDirectory}`\n if (installed.has(key)) return true\n\n const fallbackModules = join(dirname(profile), 'node_modules')\n const hostRequire = createRequire(join(fallbackModules, '.stratagate-host-resolution.cjs'))\n registerHooks({\n resolve(specifier, context, nextResolve) {\n const parent = context.parentURL?.startsWith('file:') ? fileURLToPath(context.parentURL) : undefined\n if (!hostPackage(specifier) || !parent || !isWithin(parent, packageDirectory)) {\n return nextResolve(specifier, context)\n }\n try {\n return { url: pathToFileURL(hostRequire.resolve(specifier)).href, shortCircuit: true }\n } catch (cause) {\n if (specifier === '@deepseek-ai/dsh-session-format-v0-to-v1'\n || specifier === '@deepseek-ai/dsh-session-format-catalog') {\n return nextResolve(specifier, context)\n }\n throw new Error(\n `StrataGate cannot resolve host-provided DSH package ${JSON.stringify(specifier)} from ${fallbackModules}. `\n + 'Start StrataGate through the DSH profile launcher so the host can prepare its module fallback.',\n { cause },\n )\n }\n },\n })\n installed.add(key)\n return true\n}\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 PluginConfig = import('./index.js').PluginConfig\n"],"mappings":";AAAA,SAAS,YAAY,oBAAoB;AACzC,SAAS,eAAe,qBAAqB;AAC7C,SAAS,SAAS,YAAY,MAAM,gBAAgB;AACpD,SAAS,eAAe,qBAAqB;AAE7C,IAAM,gBAAgB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,iBAAiB,uBAAO,IAAI,mCAAmC;AAErE,SAAS,SAAS,MAAc,MAAuB;AACrD,QAAM,QAAQ,SAAS,MAAM,IAAI;AACjC,SAAO,UAAU,MAAO,CAAC,MAAM,WAAW,IAAI,KAAK,CAAC,WAAW,KAAK;AACtE;AAEA,SAAS,iBAAiB,OAAmC;AAC3D,MAAI,YAAY;AAChB,aAAS;AACP,UAAM,eAAe,KAAK,WAAW,cAAc;AACnD,QAAI,WAAW,YAAY,GAAG;AAC5B,UAAI;AACF,cAAM,WAAW,KAAK,MAAM,aAAa,cAAc,MAAM,CAAC;AAC9D,YAAI,SAAS,KAAK,WAAW,OAAO,SAAS,IAAI,YAAY,SAAU,QAAO;AAAA,MAChF,QAAQ;AAAA,MAAC;AAAA,IACX;AACA,UAAM,SAAS,QAAQ,SAAS;AAChC,QAAI,WAAW,UAAW,QAAO;AACjC,gBAAY;AAAA,EACd;AACF;AAEA,SAAS,YAAY,WAA4B;AAC/C,SAAO,cAAc,KAAK,CAACA,UAAS,cAAcA,SAAQ,UAAU,WAAW,GAAGA,KAAI,GAAG,CAAC;AAC5F;AAOO,SAAS,yBAAyB,WAA4B;AACnE,QAAM,mBAAmB,QAAQ,QAAQ,cAAc,SAAS,CAAC,CAAC;AAClE,QAAM,UAAU,iBAAiB,gBAAgB;AACjD,MAAI,CAAC,QAAS,QAAO;AAErB,QAAM,cAAc;AACpB,QAAM,YAAY,YAAY,cAAc,MAAM,oBAAI,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"]}
|
package/dist/plugin.js
CHANGED
|
@@ -2093,6 +2093,10 @@ function normalizeSnapshot(value) {
|
|
|
2093
2093
|
if (!Number.isSafeInteger(block.pointerAnchorBlockPosition) || block.pointerAnchorBlockPosition < 1) {
|
|
2094
2094
|
throw new TypeError("Invalid StrataGate snapshot: pointerAnchorBlockPosition must be a positive integer");
|
|
2095
2095
|
}
|
|
2096
|
+
if (block.surfaceCurrentLevel === void 0) block.surfaceCurrentLevel = null;
|
|
2097
|
+
if (block.surfaceCurrentLevel != null && (!Number.isSafeInteger(block.surfaceCurrentLevel) || block.surfaceCurrentLevel < 0 || block.surfaceCurrentLevel > 5)) {
|
|
2098
|
+
throw new TypeError("Invalid StrataGate snapshot: surfaceCurrentLevel must be a Block level");
|
|
2099
|
+
}
|
|
2096
2100
|
if (block.lastLiftedBy !== null && block.lastLiftedBy !== "user" && block.lastLiftedBy !== "agent") {
|
|
2097
2101
|
throw new TypeError("Invalid StrataGate snapshot: lastLiftedBy must be user, agent, or null");
|
|
2098
2102
|
}
|
|
@@ -3739,6 +3743,7 @@ CREATE TABLE IF NOT EXISTS blocks (
|
|
|
3739
3743
|
l3_condensed TEXT NOT NULL,
|
|
3740
3744
|
l4_readable TEXT NOT NULL,
|
|
3741
3745
|
pointer_current_level INTEGER NOT NULL,
|
|
3746
|
+
surface_current_level INTEGER CHECK (surface_current_level BETWEEN 0 AND 5),
|
|
3742
3747
|
pointer_anchor_level INTEGER NOT NULL,
|
|
3743
3748
|
pointer_anchor_block_position INTEGER NOT NULL,
|
|
3744
3749
|
last_lifted_at TEXT,
|
|
@@ -4188,6 +4193,7 @@ var SqliteStorage = class _SqliteStorage {
|
|
|
4188
4193
|
l4Readable: row.l4_readable,
|
|
4189
4194
|
l5Raw: messagesByBlock.get(row.id) ?? [],
|
|
4190
4195
|
pointerCurrentLevel: row.pointer_current_level,
|
|
4196
|
+
surfaceCurrentLevel: row.surface_current_level == null ? null : row.surface_current_level,
|
|
4191
4197
|
pointerAnchorLevel: row.pointer_anchor_level,
|
|
4192
4198
|
pointerAnchorBlockPosition: row.pointer_anchor_block_position,
|
|
4193
4199
|
lastLiftedAt: row.last_lifted_at,
|
|
@@ -4630,9 +4636,9 @@ var SqliteStorage = class _SqliteStorage {
|
|
|
4630
4636
|
INSERT INTO blocks (
|
|
4631
4637
|
namespace, id, thread_id, sequence, start_turn, end_turn, created_at, should_extract,
|
|
4632
4638
|
l0_title, l0_tags_json, l1_summary, l2_keypoints_json, l3_condensed, l4_readable,
|
|
4633
|
-
pointer_current_level, pointer_anchor_level, pointer_anchor_block_position, last_lifted_at, last_lifted_by,
|
|
4639
|
+
pointer_current_level, surface_current_level, pointer_anchor_level, pointer_anchor_block_position, last_lifted_at, last_lifted_by,
|
|
4634
4640
|
processing_status
|
|
4635
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
4641
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
4636
4642
|
ON CONFLICT (namespace, id) DO UPDATE SET
|
|
4637
4643
|
thread_id = excluded.thread_id,
|
|
4638
4644
|
sequence = excluded.sequence,
|
|
@@ -4647,6 +4653,7 @@ var SqliteStorage = class _SqliteStorage {
|
|
|
4647
4653
|
l3_condensed = excluded.l3_condensed,
|
|
4648
4654
|
l4_readable = excluded.l4_readable,
|
|
4649
4655
|
pointer_current_level = excluded.pointer_current_level,
|
|
4656
|
+
surface_current_level = excluded.surface_current_level,
|
|
4650
4657
|
pointer_anchor_level = excluded.pointer_anchor_level,
|
|
4651
4658
|
pointer_anchor_block_position = excluded.pointer_anchor_block_position,
|
|
4652
4659
|
last_lifted_at = excluded.last_lifted_at,
|
|
@@ -4670,6 +4677,7 @@ var SqliteStorage = class _SqliteStorage {
|
|
|
4670
4677
|
block.l3Condensed,
|
|
4671
4678
|
block.l4Readable,
|
|
4672
4679
|
block.pointerCurrentLevel,
|
|
4680
|
+
block.surfaceCurrentLevel ?? null,
|
|
4673
4681
|
block.pointerAnchorLevel,
|
|
4674
4682
|
block.pointerAnchorBlockPosition,
|
|
4675
4683
|
block.lastLiftedAt,
|
|
@@ -5466,6 +5474,9 @@ var SqliteStorage = class _SqliteStorage {
|
|
|
5466
5474
|
if (!blockColumns.some(({ name: name2 }) => name2 === "processing_status")) {
|
|
5467
5475
|
this.database.exec("ALTER TABLE blocks ADD COLUMN processing_status TEXT NOT NULL DEFAULT 'ready' CHECK (processing_status IN ('pending', 'ready'))");
|
|
5468
5476
|
}
|
|
5477
|
+
if (!blockColumns.some(({ name: name2 }) => name2 === "surface_current_level")) {
|
|
5478
|
+
this.database.exec("ALTER TABLE blocks ADD COLUMN surface_current_level INTEGER CHECK (surface_current_level BETWEEN 0 AND 5)");
|
|
5479
|
+
}
|
|
5469
5480
|
const eventColumns = this.database.prepare("PRAGMA table_info('events')").all();
|
|
5470
5481
|
if (!eventColumns.some(({ name: name2 }) => name2 === "formed_turn")) {
|
|
5471
5482
|
this.database.exec("ALTER TABLE events ADD COLUMN formed_turn INTEGER");
|
|
@@ -5509,6 +5520,9 @@ var SqliteStorage = class _SqliteStorage {
|
|
|
5509
5520
|
}
|
|
5510
5521
|
if (!this.hasColumn("memory_spaces", "graph_epoch")) this.database.exec("ALTER TABLE memory_spaces ADD COLUMN graph_epoch INTEGER NOT NULL DEFAULT 0");
|
|
5511
5522
|
if (!this.hasColumn("memory_spaces", "graph_approved_event_ids_json")) this.database.exec("ALTER TABLE memory_spaces ADD COLUMN graph_approved_event_ids_json TEXT NOT NULL DEFAULT '[]'");
|
|
5523
|
+
if (!this.hasColumn("blocks", "surface_current_level")) {
|
|
5524
|
+
this.database.exec("ALTER TABLE blocks ADD COLUMN surface_current_level INTEGER CHECK (surface_current_level BETWEEN 0 AND 5)");
|
|
5525
|
+
}
|
|
5512
5526
|
this.database.prepare("INSERT INTO stratagate_graph_policy_migrations (id, completed_at) VALUES (1, ?) ON CONFLICT (id) DO NOTHING").run(nowUtc8());
|
|
5513
5527
|
this.database.exec(THREAD_INDEXES);
|
|
5514
5528
|
this.rebuildLegacyElementSourceForeignKeys();
|
|
@@ -7333,11 +7347,22 @@ var StrataGate = class _StrataGate {
|
|
|
7333
7347
|
turnRange: [block.startTurn, block.endTurn],
|
|
7334
7348
|
age,
|
|
7335
7349
|
level,
|
|
7350
|
+
...block.surfaceCurrentLevel === void 0 ? {} : { surfaceLevel: block.surfaceCurrentLevel },
|
|
7336
7351
|
label: blockLevelLabel(level),
|
|
7337
7352
|
content: renderBlock(block, level)
|
|
7338
7353
|
};
|
|
7339
7354
|
});
|
|
7340
7355
|
}
|
|
7356
|
+
async setBlockSurfaceLevel(id, level) {
|
|
7357
|
+
if (level !== null && (!Number.isInteger(level) || level < 0 || level > 5)) throw new TypeError("Invalid surface level");
|
|
7358
|
+
if (this.blocks.find((block) => block.id === id)?.surfaceCurrentLevel === level) return;
|
|
7359
|
+
await this.commitMutation(() => {
|
|
7360
|
+
const block = this.blocks.find((candidate) => candidate.id === id);
|
|
7361
|
+
if (!block) throw new Error(`Unknown block: ${id}`);
|
|
7362
|
+
if (block.processingStatus !== "ready") throw new Error(`Block ${id} is not ready for surface tracking`);
|
|
7363
|
+
block.surfaceCurrentLevel = level;
|
|
7364
|
+
});
|
|
7365
|
+
}
|
|
7341
7366
|
async expandBlock(id, target = "next", source = "agent") {
|
|
7342
7367
|
return this.commitMutation(() => {
|
|
7343
7368
|
const block = this.blocks.find((candidate) => candidate.id === id);
|
|
@@ -7364,6 +7389,7 @@ var StrataGate = class _StrataGate {
|
|
|
7364
7389
|
turnRange: [block.startTurn, block.endTurn],
|
|
7365
7390
|
age: Math.max(0, latestBlockPosition - blockPosition),
|
|
7366
7391
|
level,
|
|
7392
|
+
...block.surfaceCurrentLevel === void 0 ? {} : { surfaceLevel: block.surfaceCurrentLevel },
|
|
7367
7393
|
label: blockLevelLabel(level),
|
|
7368
7394
|
content: renderBlock(block, level)
|
|
7369
7395
|
};
|
|
@@ -7658,6 +7684,7 @@ ${duplicate.summary}` : duplicate.summary;
|
|
|
7658
7684
|
processingStatus: "ready",
|
|
7659
7685
|
...deterministicBlockLayers([message]),
|
|
7660
7686
|
pointerCurrentLevel: 5,
|
|
7687
|
+
surfaceCurrentLevel: null,
|
|
7661
7688
|
pointerAnchorLevel: 5,
|
|
7662
7689
|
pointerAnchorBlockPosition: 1,
|
|
7663
7690
|
lastLiftedAt: null,
|
|
@@ -7695,6 +7722,7 @@ ${duplicate.summary}` : duplicate.summary;
|
|
|
7695
7722
|
processingStatus: "ready",
|
|
7696
7723
|
...deterministicBlockLayers([message]),
|
|
7697
7724
|
pointerCurrentLevel: 5,
|
|
7725
|
+
surfaceCurrentLevel: null,
|
|
7698
7726
|
pointerAnchorLevel: 5,
|
|
7699
7727
|
pointerAnchorBlockPosition: 1,
|
|
7700
7728
|
lastLiftedAt: null,
|
|
@@ -8411,6 +8439,7 @@ ${duplicate.summary}` : duplicate.summary;
|
|
|
8411
8439
|
processingStatus: "pending",
|
|
8412
8440
|
...deterministic,
|
|
8413
8441
|
pointerCurrentLevel: 5,
|
|
8442
|
+
surfaceCurrentLevel: null,
|
|
8414
8443
|
pointerAnchorLevel: 5,
|
|
8415
8444
|
pointerAnchorBlockPosition: blockPosition,
|
|
8416
8445
|
lastLiftedAt: null,
|
|
@@ -13054,7 +13083,8 @@ var StrataGateRuntime = class {
|
|
|
13054
13083
|
await this.flush();
|
|
13055
13084
|
const memory = await this.space(session);
|
|
13056
13085
|
const threadId = String(session.id);
|
|
13057
|
-
const snapshot = memory.exportSnapshot();
|
|
13086
|
+
const snapshot = this.observeBlockSurface(this.namespaceFor(session), memory.exportSnapshot());
|
|
13087
|
+
const actualLevels = new Map(snapshot.blocks.map((block) => [block.id, block.surfaceCurrentLevel ?? null]));
|
|
13058
13088
|
const namespaceBlockCount = snapshot.blocks.length;
|
|
13059
13089
|
const namespaceThreadIds = [...new Set(snapshot.blocks.map((block) => block.threadId).filter((value) => Boolean(value)))];
|
|
13060
13090
|
const openTailCount = snapshot.openTail.filter((message) => scope === "namespace" || message.threadId === threadId).length;
|
|
@@ -13066,7 +13096,8 @@ var StrataGateRuntime = class {
|
|
|
13066
13096
|
id,
|
|
13067
13097
|
title: compactText2(blockTitles.get(id) ?? "Block", 240),
|
|
13068
13098
|
turnRange,
|
|
13069
|
-
level
|
|
13099
|
+
level: actualLevels.get(id) ?? level,
|
|
13100
|
+
targetLevel: level
|
|
13070
13101
|
}));
|
|
13071
13102
|
const emptyReason = matches.length > 0 ? null : namespaceBlockCount === 0 ? openTailCount > 0 ? "open_tail_pending" : "no_blocks_in_namespace" : openTailCount > 0 ? "open_tail_pending" : "blocks_exist_in_other_threads";
|
|
13072
13103
|
const status = {
|
|
@@ -13088,7 +13119,7 @@ var StrataGateRuntime = class {
|
|
|
13088
13119
|
target: {
|
|
13089
13120
|
eventIds: [],
|
|
13090
13121
|
elementIds: [],
|
|
13091
|
-
citation: citation("block", result.id, blockTitles.get(result.id) ?? "Block", `block:${result.id}:level:${result.level}`, "blockId", { level: result.level })
|
|
13122
|
+
citation: citation("block", result.id, blockTitles.get(result.id) ?? "Block", `block:${result.id}:level:${result.level}`, "blockId", result.level === null ? {} : { level: result.level })
|
|
13092
13123
|
}
|
|
13093
13124
|
})), results, status);
|
|
13094
13125
|
}
|
|
@@ -13294,7 +13325,7 @@ var StrataGateRuntime = class {
|
|
|
13294
13325
|
await this.refreshExternalImportMemory(this.namespaceFor(session), memory);
|
|
13295
13326
|
const threadId = String(session.id);
|
|
13296
13327
|
const blockContexts = memory.getBlockContext(threadId);
|
|
13297
|
-
if (this.syncDecayedBlockSurface(session, memory, blockContexts)) {
|
|
13328
|
+
if (await this.syncDecayedBlockSurface(session, memory, blockContexts)) {
|
|
13298
13329
|
await this.flushNativeSession(session);
|
|
13299
13330
|
}
|
|
13300
13331
|
const openTail = memory.listOpenTail(threadId);
|
|
@@ -13339,7 +13370,22 @@ var StrataGateRuntime = class {
|
|
|
13339
13370
|
* events remain in the append-only log for transcript/evidence provenance,
|
|
13340
13371
|
* while deriveMessages() sees only this compressed checkpoint.
|
|
13341
13372
|
*/
|
|
13342
|
-
|
|
13373
|
+
surfaceSyncQueues = /* @__PURE__ */ new WeakMap();
|
|
13374
|
+
async withSurfaceSync(session, operation) {
|
|
13375
|
+
const previous = this.surfaceSyncQueues.get(session) ?? Promise.resolve();
|
|
13376
|
+
const pending = previous.catch(() => {
|
|
13377
|
+
}).then(operation);
|
|
13378
|
+
this.surfaceSyncQueues.set(session, pending);
|
|
13379
|
+
try {
|
|
13380
|
+
return await pending;
|
|
13381
|
+
} finally {
|
|
13382
|
+
if (this.surfaceSyncQueues.get(session) === pending) this.surfaceSyncQueues.delete(session);
|
|
13383
|
+
}
|
|
13384
|
+
}
|
|
13385
|
+
replaceSealedSurface(session, memory, block, context, endTurn) {
|
|
13386
|
+
return this.withSurfaceSync(session, () => this.replaceSealedSurfaceUnlocked(session, memory, block, context, endTurn));
|
|
13387
|
+
}
|
|
13388
|
+
async replaceSealedSurfaceUnlocked(session, memory, block, context, endTurn) {
|
|
13343
13389
|
if (endTurn === null || hostCompactionActive(session)) return false;
|
|
13344
13390
|
const sourceEventSeqs = sealedSurfaceSeqs(session, endTurn, block);
|
|
13345
13391
|
if (!sourceEventSeqs) return false;
|
|
@@ -13355,36 +13401,54 @@ var StrataGateRuntime = class {
|
|
|
13355
13401
|
surfaceOp: dshReplaceSurfaceOp(start, end),
|
|
13356
13402
|
sourceEventSeqs
|
|
13357
13403
|
});
|
|
13404
|
+
await this.flushNativeSession(session);
|
|
13405
|
+
const actual = currentBlockSurfaceMessages(session).get(block.id);
|
|
13406
|
+
await memory.setBlockSurfaceLevel(block.id, actual ? checkpointLevel(actual.text) : null);
|
|
13358
13407
|
return true;
|
|
13359
13408
|
}
|
|
13360
13409
|
/** Keep each native Block checkpoint synchronized with its current decay pointer. */
|
|
13361
13410
|
syncDecayedBlockSurface(session, memory, contexts) {
|
|
13362
|
-
|
|
13363
|
-
|
|
13411
|
+
return this.withSurfaceSync(session, () => this.syncDecayedBlockSurfaceUnlocked(session, memory, contexts));
|
|
13412
|
+
}
|
|
13413
|
+
async syncDecayedBlockSurfaceUnlocked(session, memory, contexts) {
|
|
13414
|
+
if (!session.surface || typeof session.deriveEventMessage !== "function" || hostCompactionActive(session)) return false;
|
|
13364
13415
|
const blocks = new Map(memory.listBlocks().map((block) => [block.id, block]));
|
|
13365
13416
|
const checkpointLimit = surfaceCheckpointLimit(session);
|
|
13366
13417
|
let changed = false;
|
|
13367
13418
|
for (const context of contexts) {
|
|
13368
|
-
|
|
13369
|
-
if (!node) continue;
|
|
13370
|
-
const currentLevel = Number(node.text.match(/^Level: L([0-5]) /mu)?.[1] ?? -1);
|
|
13371
|
-
const currentTokens = surfaceCheckpointTokens(node.text);
|
|
13372
|
-
const sourceTokens = originalCheckpointSourceTokens(session, node.seq);
|
|
13373
|
-
const violatesLimit = currentTokens > checkpointLimit || sourceTokens !== null && !worthwhileSurfaceReduction(sourceTokens, currentTokens);
|
|
13374
|
-
if (context.level >= currentLevel && currentLevel >= 0 && !violatesLimit) continue;
|
|
13419
|
+
if (hostCompactionActive(session)) break;
|
|
13375
13420
|
const block = blocks.get(context.id);
|
|
13376
13421
|
if (!block) continue;
|
|
13377
|
-
const
|
|
13422
|
+
const node = currentBlockSurfaceMessages(session).get(context.id);
|
|
13423
|
+
if (!node) {
|
|
13424
|
+
const endTurn = dshTurnAtBlockEnd(session, block);
|
|
13425
|
+
const native = endTurn === null ? null : sealedSurfaceSeqs(session, endTurn, block);
|
|
13426
|
+
if (native) {
|
|
13427
|
+
await memory.setBlockSurfaceLevel(context.id, 5);
|
|
13428
|
+
changed = await this.replaceSealedSurfaceUnlocked(session, memory, block, context, endTurn) || changed;
|
|
13429
|
+
} else {
|
|
13430
|
+
await memory.setBlockSurfaceLevel(context.id, null);
|
|
13431
|
+
}
|
|
13432
|
+
continue;
|
|
13433
|
+
}
|
|
13434
|
+
const currentLevel = checkpointLevel(node.text);
|
|
13435
|
+
if (block.surfaceCurrentLevel !== currentLevel) {
|
|
13436
|
+
await this.flushNativeSession(session);
|
|
13437
|
+
const observed = currentBlockSurfaceMessages(session).get(context.id);
|
|
13438
|
+
await memory.setBlockSurfaceLevel(context.id, observed ? checkpointLevel(observed.text) : null);
|
|
13439
|
+
if (observed?.seq !== node.seq) continue;
|
|
13440
|
+
}
|
|
13441
|
+
if (hostCompactionActive(session)) continue;
|
|
13442
|
+
if (currentLevel !== null && context.level >= currentLevel) continue;
|
|
13378
13443
|
const text3 = selectCompressedBlockSurfaceText(
|
|
13379
13444
|
node.text,
|
|
13380
13445
|
context,
|
|
13381
13446
|
block,
|
|
13382
|
-
|
|
13383
|
-
|
|
13447
|
+
context.level,
|
|
13448
|
+
originalCheckpointSourceTokens(session, node.seq),
|
|
13384
13449
|
checkpointLimit
|
|
13385
13450
|
);
|
|
13386
|
-
if (!text3) continue;
|
|
13387
|
-
if (node.text === text3) continue;
|
|
13451
|
+
if (!text3 || node.text === text3) continue;
|
|
13388
13452
|
session.append("user/message", createUserMessage2({
|
|
13389
13453
|
content: [{ type: "text", text: text3 }],
|
|
13390
13454
|
source: dshMessageSource()
|
|
@@ -13392,6 +13456,9 @@ var StrataGateRuntime = class {
|
|
|
13392
13456
|
surfaceOp: dshReplaceSurfaceOp(node.seq, node.seq),
|
|
13393
13457
|
sourceEventSeqs: [node.seq]
|
|
13394
13458
|
});
|
|
13459
|
+
await this.flushNativeSession(session);
|
|
13460
|
+
const actual = currentBlockSurfaceMessages(session).get(context.id);
|
|
13461
|
+
await memory.setBlockSurfaceLevel(context.id, actual ? checkpointLevel(actual.text) : null);
|
|
13395
13462
|
changed = true;
|
|
13396
13463
|
}
|
|
13397
13464
|
return changed;
|
|
@@ -13415,7 +13482,7 @@ var StrataGateRuntime = class {
|
|
|
13415
13482
|
const context = contexts.get(blockId);
|
|
13416
13483
|
if (!block || block.processingStatus !== "ready" || !context) continue;
|
|
13417
13484
|
try {
|
|
13418
|
-
changed = this.replaceSealedSurface(session, block, context, dshTurnAtBlockEnd(session, block)) || changed;
|
|
13485
|
+
changed = await this.replaceSealedSurface(session, memory, block, context, dshTurnAtBlockEnd(session, block)) || changed;
|
|
13419
13486
|
this.pendingSurfaceSync.delete(key);
|
|
13420
13487
|
} catch (error) {
|
|
13421
13488
|
this.onIngestError(error);
|
|
@@ -13708,6 +13775,24 @@ var StrataGateRuntime = class {
|
|
|
13708
13775
|
await storage.close();
|
|
13709
13776
|
}
|
|
13710
13777
|
}
|
|
13778
|
+
/** Read-only live-session overlay: a cached database pointer is never proof of an injected layer. */
|
|
13779
|
+
observeBlockSurface(namespace, snapshot) {
|
|
13780
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
13781
|
+
for (const [id, reference] of this.knownSessions) {
|
|
13782
|
+
const session = reference.deref();
|
|
13783
|
+
if (session?.surface && this.namespaceFor(session) === namespace) sessions.set(id, session);
|
|
13784
|
+
}
|
|
13785
|
+
if (sessions.size === 0) return snapshot;
|
|
13786
|
+
const checkpoints = new Map([...sessions].map(([id, session]) => [id, currentBlockSurfaceMessages(session)]));
|
|
13787
|
+
return { ...snapshot, blocks: snapshot.blocks.map((block) => {
|
|
13788
|
+
const session = block.threadId ? sessions.get(block.threadId) : void 0;
|
|
13789
|
+
if (!session || block.processingStatus !== "ready") return block;
|
|
13790
|
+
const checkpoint = checkpoints.get(block.threadId)?.get(block.id);
|
|
13791
|
+
const endTurn = checkpoint ? null : dshTurnAtBlockEnd(session, block);
|
|
13792
|
+
const surfaceCurrentLevel = checkpoint ? checkpointLevel(checkpoint.text) : endTurn !== null && sealedSurfaceSeqs(session, endTurn, block) ? 5 : null;
|
|
13793
|
+
return { ...block, surfaceCurrentLevel };
|
|
13794
|
+
}) };
|
|
13795
|
+
}
|
|
13711
13796
|
async adminSnapshotEntries() {
|
|
13712
13797
|
if (this.config.database === ":memory:" || !existsSync2(this.config.database)) return [];
|
|
13713
13798
|
const storage = new SqliteStorage({ filename: this.config.database, readonly: true });
|
|
@@ -13740,7 +13825,7 @@ var StrataGateRuntime = class {
|
|
|
13740
13825
|
for (const namespace of this.adminSnapshotCache.keys()) {
|
|
13741
13826
|
if (!activeNamespaces.has(namespace)) this.adminSnapshotCache.delete(namespace);
|
|
13742
13827
|
}
|
|
13743
|
-
return entries;
|
|
13828
|
+
return entries.map((entry) => ({ ...entry, snapshot: this.observeBlockSurface(entry.namespace, entry.snapshot) }));
|
|
13744
13829
|
} finally {
|
|
13745
13830
|
await storage.close();
|
|
13746
13831
|
}
|
|
@@ -13780,22 +13865,22 @@ var StrataGateRuntime = class {
|
|
|
13780
13865
|
await this.refreshExternalImportMemory(key, memory);
|
|
13781
13866
|
const revision = memory.storageRevision;
|
|
13782
13867
|
const cached = this.adminSnapshotCache.get(key);
|
|
13783
|
-
if (cached?.revision === revision) return cached.snapshot;
|
|
13868
|
+
if (cached?.revision === revision) return this.observeBlockSurface(key, cached.snapshot);
|
|
13784
13869
|
const entry = { namespace: key, revision, snapshot: memory.exportSnapshot() };
|
|
13785
13870
|
this.adminSnapshotCache.set(key, entry);
|
|
13786
|
-
return entry.snapshot;
|
|
13871
|
+
return this.observeBlockSurface(key, entry.snapshot);
|
|
13787
13872
|
}
|
|
13788
13873
|
const storage = new SqliteStorage({ filename: this.config.database, readonly: true });
|
|
13789
13874
|
try {
|
|
13790
13875
|
const head = storage.listNamespaceRevisions().find(({ namespace: namespace2 }) => namespace2 === key);
|
|
13791
13876
|
if (!head) return null;
|
|
13792
13877
|
const cached = this.adminSnapshotCache.get(key);
|
|
13793
|
-
if (cached?.revision === head.revision) return cached.snapshot;
|
|
13878
|
+
if (cached?.revision === head.revision) return this.observeBlockSurface(key, cached.snapshot);
|
|
13794
13879
|
const loaded = await storage.load(key);
|
|
13795
13880
|
if (!loaded) return null;
|
|
13796
13881
|
const entry = { namespace: key, revision: loaded.revision, snapshot: loaded.snapshot };
|
|
13797
13882
|
this.adminSnapshotCache.set(key, entry);
|
|
13798
|
-
return entry.snapshot;
|
|
13883
|
+
return this.observeBlockSurface(key, entry.snapshot);
|
|
13799
13884
|
} finally {
|
|
13800
13885
|
await storage.close();
|
|
13801
13886
|
}
|
|
@@ -14512,7 +14597,7 @@ var StrataGateRuntime = class {
|
|
|
14512
14597
|
try {
|
|
14513
14598
|
await memory2.resumePendingWork({ deferDerivation: true, threadId: String(session.id) });
|
|
14514
14599
|
const contexts = memory2.getBlockContext(String(session.id));
|
|
14515
|
-
if (this.syncDecayedBlockSurface(session, memory2, contexts)) {
|
|
14600
|
+
if (await this.syncDecayedBlockSurface(session, memory2, contexts)) {
|
|
14516
14601
|
await this.flushNativeSession(session);
|
|
14517
14602
|
}
|
|
14518
14603
|
} finally {
|
|
@@ -14628,9 +14713,9 @@ var StrataGateRuntime = class {
|
|
|
14628
14713
|
});
|
|
14629
14714
|
continue;
|
|
14630
14715
|
}
|
|
14631
|
-
changed = this.replaceSealedSurface(session, block, context, dshTurnAtBlockEnd(session, block)) || changed;
|
|
14716
|
+
changed = await this.replaceSealedSurface(session, memory, block, context, dshTurnAtBlockEnd(session, block)) || changed;
|
|
14632
14717
|
}
|
|
14633
|
-
changed = this.syncDecayedBlockSurface(session, memory, contexts) || changed;
|
|
14718
|
+
changed = await this.syncDecayedBlockSurface(session, memory, contexts) || changed;
|
|
14634
14719
|
if (changed) await this.flushNativeSession(session);
|
|
14635
14720
|
}).catch(async (error) => {
|
|
14636
14721
|
retryDelay = BACKGROUND_WORKER_INTERVAL_MS;
|
|
@@ -14910,8 +14995,6 @@ function hostCompactionActive(session) {
|
|
|
14910
14995
|
}
|
|
14911
14996
|
return lastBoundary?.type === "compaction/start" && (lastSeed === void 0 || lastBoundary.seq > lastSeed);
|
|
14912
14997
|
}
|
|
14913
|
-
var SURFACE_MIN_SAVED_TOKENS = 32;
|
|
14914
|
-
var SURFACE_MAX_REPLACEMENT_RATIO = 0.9;
|
|
14915
14998
|
var SURFACE_MAX_WINDOW_FRACTION = 0.04;
|
|
14916
14999
|
var SURFACE_CHECKPOINT_CEILING_TOKENS = 4096;
|
|
14917
15000
|
function surfaceCheckpointLimit(session) {
|
|
@@ -14948,46 +15031,40 @@ function originalCheckpointSourceTokens(session, seq) {
|
|
|
14948
15031
|
return visit(seq);
|
|
14949
15032
|
}
|
|
14950
15033
|
function worthwhileSurfaceReduction(before, after) {
|
|
14951
|
-
return
|
|
15034
|
+
return after <= before;
|
|
14952
15035
|
}
|
|
14953
15036
|
function selectCompressedBlockSurfaceText(currentText, context, block, highestLevel, sourceTokens, checkpointLimit) {
|
|
14954
15037
|
const before = surfaceCheckpointTokens(currentText);
|
|
14955
|
-
|
|
14956
|
-
|
|
14957
|
-
|
|
14958
|
-
|
|
14959
|
-
|
|
14960
|
-
|
|
14961
|
-
|
|
14962
|
-
|
|
14963
|
-
if (tokens <= checkpointLimit && worthwhileSurfaceReduction(before, tokens) && (sourceTokens === null || worthwhileSurfaceReduction(sourceTokens, tokens))) return candidate;
|
|
14964
|
-
}
|
|
14965
|
-
return null;
|
|
15038
|
+
const candidate = renderBlockSurfaceMessage({
|
|
15039
|
+
...context,
|
|
15040
|
+
level: highestLevel,
|
|
15041
|
+
label: blockLevelLabel(highestLevel),
|
|
15042
|
+
content: highestLevel === context.level ? context.content : renderBlock(block, highestLevel)
|
|
15043
|
+
});
|
|
15044
|
+
const tokens = surfaceCheckpointTokens(candidate);
|
|
15045
|
+
return tokens <= checkpointLimit && worthwhileSurfaceReduction(before, tokens) && (sourceTokens === null || worthwhileSurfaceReduction(sourceTokens, tokens)) ? candidate : null;
|
|
14966
15046
|
}
|
|
14967
|
-
function selectCompressedBlockSurface(session, sourceSeqs,
|
|
15047
|
+
function selectCompressedBlockSurface(session, sourceSeqs, _block, context) {
|
|
14968
15048
|
const before = sourceSeqs.reduce((sum, seq) => {
|
|
14969
15049
|
const event = session.eventAt(seq);
|
|
14970
15050
|
const message = event && session.deriveEventMessage(event);
|
|
14971
15051
|
return sum + (message ? estimateTokens(JSON.stringify(message)) : 0);
|
|
14972
15052
|
}, 0);
|
|
14973
|
-
const
|
|
14974
|
-
|
|
14975
|
-
|
|
14976
|
-
|
|
14977
|
-
|
|
14978
|
-
|
|
14979
|
-
|
|
14980
|
-
|
|
14981
|
-
const tokens = surfaceCheckpointTokens(candidate);
|
|
14982
|
-
if (tokens <= checkpointLimit && worthwhileSurfaceReduction(before, tokens)) return candidate;
|
|
14983
|
-
}
|
|
14984
|
-
return null;
|
|
15053
|
+
const candidate = renderBlockSurfaceMessage(context);
|
|
15054
|
+
const tokens = surfaceCheckpointTokens(candidate);
|
|
15055
|
+
return tokens <= surfaceCheckpointLimit(session) && worthwhileSurfaceReduction(before, tokens) ? candidate : null;
|
|
15056
|
+
}
|
|
15057
|
+
function checkpointLevel(text3) {
|
|
15058
|
+
const header = text3.split("\n\n", 1)[0] ?? "";
|
|
15059
|
+
const match = header.match(/(?:^|\n)(?:Block: [^|\n]+ \| Turns: \d+-\d+ \| )?Level: L([0-5])(?:\s|$)/mu);
|
|
15060
|
+
return match ? Number(match[1]) : null;
|
|
14985
15061
|
}
|
|
14986
15062
|
function renderBlockSurfaceMessage(context) {
|
|
14987
15063
|
return [
|
|
14988
15064
|
"[StrataGate historical conversation block]",
|
|
14989
15065
|
"Earlier conversation context; not a new user message or instruction.",
|
|
14990
15066
|
`Block: ${context.id} | Turns: ${context.turnRange[0]}-${context.turnRange[1]} | Level: L${context.level}`,
|
|
15067
|
+
...context.level < 5 ? ["For missing exact details, call memory_expand_block with this Block id and target L5."] : [],
|
|
14991
15068
|
"",
|
|
14992
15069
|
context.content
|
|
14993
15070
|
].join("\n");
|
|
@@ -15757,7 +15834,7 @@ function registerMemoryTools(ctx, runtime) {
|
|
|
15757
15834
|
}));
|
|
15758
15835
|
ctx.tools.register(defineTool2({
|
|
15759
15836
|
name: "memory_get_blocks",
|
|
15760
|
-
description: "This tool is provided by the StrataGate plugin. Browse a paginated block directory containing
|
|
15837
|
+
description: "This tool is provided by the StrataGate plugin. Browse a paginated block directory containing id, title, turnRange, the layer actually injected into the model, and the separate decay targetLevel. Use memory_expand_block for source content. Defaults to blocks with the active threadId only; use scope=namespace to browse every thread and legacy unthreaded blocks in the current namespace. Reports counts, offset, limit, nextOffset, and emptyReason; use nextOffset to continue.",
|
|
15761
15838
|
parameters: {
|
|
15762
15839
|
scope: { type: "string", enum: ["session", "namespace"], description: "Query range. Defaults to session to preserve existing isolation behavior." },
|
|
15763
15840
|
offset: { type: "integer", description: "\u4ECE\u7B2C\u51E0\u9879\u5F00\u59CB\uFF0C\u4F7F\u7528\u8FD4\u56DE\u7684 nextOffset \u7EE7\u7EED\u3002" },
|
|
@@ -15768,7 +15845,7 @@ function registerMemoryTools(ctx, runtime) {
|
|
|
15768
15845
|
}));
|
|
15769
15846
|
ctx.tools.register(defineTool2({
|
|
15770
15847
|
name: "memory_expand_block",
|
|
15771
|
-
description: "This tool is provided by the StrataGate plugin. Expand one
|
|
15848
|
+
description: "This tool is provided by the StrataGate plugin. Expand one historical conversation Block to a more detailed layer. Use it when a Block checkpoint lacks the detail needed for the current task; pass the Block id shown in the checkpoint or returned by memory_get_blocks. The result is a new evidence batch and must be assessed.",
|
|
15772
15849
|
parameters: {
|
|
15773
15850
|
id: { type: "string", required: true },
|
|
15774
15851
|
target: { oneOf: [{ type: "string" }, { type: "integer" }] }
|
|
@@ -17043,6 +17120,7 @@ async function memories(runtime, url) {
|
|
|
17043
17120
|
const requestedThreadId = url.searchParams.get("threadId")?.trim() ?? "";
|
|
17044
17121
|
const activeThreadId = requestedThreadId || conversations[0]?.id || null;
|
|
17045
17122
|
const scopedBlocks = activeThreadId ? recovered.blocks.filter((block) => block.threadId === activeThreadId) : [];
|
|
17123
|
+
const readySources = snapshot.blocks.filter((block) => block.processingStatus === "ready");
|
|
17046
17124
|
values = scopedBlocks.map((block) => {
|
|
17047
17125
|
const source = block.source;
|
|
17048
17126
|
const layers = virtualBlockLayers(block);
|
|
@@ -17061,13 +17139,14 @@ async function memories(runtime, url) {
|
|
|
17061
17139
|
const extractionState = extraction ? derivationJobState(extraction, extraction.status === "succeeded" || extraction.status === "skipped") : null;
|
|
17062
17140
|
const status = summaryState === "terminal-failed" ? "failed" : summaryState === "processing" || summaryState === "retryable" || !summary && source.processingStatus === "pending" ? "processing" : extractionState === "terminal-failed" || failedProjection ? "failed" : extractionState === "processing" || extractionState === "retryable" ? "processing" : extraction?.status === "succeeded" || extraction?.status === "skipped" ? pendingProjection ? "processing" : "organized" : needsExtraction ? "waiting" : "organized";
|
|
17063
17141
|
const blockPosition = scopedBlocks.findIndex(({ id }) => id === block.id) + 1;
|
|
17064
|
-
const latestBlockPosition = scopedBlocks.length;
|
|
17065
|
-
const
|
|
17142
|
+
const latestBlockPosition = source.threadId ? readySources.filter((block2) => block2.threadId === source.threadId).length : scopedBlocks.filter((block2) => block2.source.processingStatus === "ready").length;
|
|
17143
|
+
const targetLevel = getDecayedBlockLevel(
|
|
17066
17144
|
source.pointerAnchorLevel,
|
|
17067
17145
|
source.threadId ? source.pointerAnchorBlockPosition : Math.min(source.pointerAnchorBlockPosition, blockPosition),
|
|
17068
17146
|
latestBlockPosition,
|
|
17069
17147
|
snapshot.blockDecayLambda
|
|
17070
17148
|
);
|
|
17149
|
+
const currentLevel = source.surfaceCurrentLevel ?? source.pointerCurrentLevel;
|
|
17071
17150
|
const currentMetrics = layerTokens.find(({ level }) => level === currentLevel);
|
|
17072
17151
|
const l5Tokens = layerTokens.find(({ level }) => level === 5)?.tokens ?? 0;
|
|
17073
17152
|
return {
|
|
@@ -17082,9 +17161,11 @@ async function memories(runtime, url) {
|
|
|
17082
17161
|
summary: source.l1Summary,
|
|
17083
17162
|
keypoints: source.l2Keypoints,
|
|
17084
17163
|
currentLevel,
|
|
17085
|
-
|
|
17164
|
+
targetLevel,
|
|
17165
|
+
currentTokens: currentMetrics?.tokens ?? null,
|
|
17086
17166
|
l5Tokens,
|
|
17087
|
-
compressionPercent: currentMetrics?.percentOfL5 ??
|
|
17167
|
+
compressionPercent: currentMetrics?.percentOfL5 ?? null,
|
|
17168
|
+
surfaceLevelSource: source.surfaceCurrentLevel == null ? "legacy-estimate" : "observed",
|
|
17088
17169
|
layerTokens,
|
|
17089
17170
|
distanceFromLatest: Math.max(0, latestBlockPosition - blockPosition),
|
|
17090
17171
|
expansionSource: source.lastLiftedAt ? source.lastLiftedBy ?? "legacy" : null,
|
|
@@ -17338,7 +17419,8 @@ async function dashboard(runtime, url, ifNoneMatch) {
|
|
|
17338
17419
|
const revisionKey = entries.map(({ namespace, revision }) => `${namespace}:${revision}`).join("|");
|
|
17339
17420
|
const agentMemoryWeight = runtime.adminAgentMemoryRetrievalWeight?.() ?? 1;
|
|
17340
17421
|
const duplicateKey = JSON.stringify([entries.map(({ namespace }) => runtime.adminDuplicateRepairStatus?.(namespace) ?? null), runtime.adminGraphSettings?.()]);
|
|
17341
|
-
const
|
|
17422
|
+
const surfaceKey = JSON.stringify(entries.map(({ snapshot }) => snapshot.blocks.map(({ id, surfaceCurrentLevel }) => [id, surfaceCurrentLevel ?? null])));
|
|
17423
|
+
const etag = `"${createHash6("sha256").update(`${STRATAGATE_DSH_VERSION}\0${TOPIC_DIRECTORY_VIEW_VERSION}\0${surfaceKey}\0${revisionKey}\0${selected?.namespace ?? ""}\0${threadId}\0${agentMemoryWeight}\0${duplicateKey}`).digest("base64url").slice(0, 24)}"`;
|
|
17342
17424
|
if (ifNoneMatch.split(",").map((value) => value.trim()).includes(etag)) return { etag, notModified: true };
|
|
17343
17425
|
const overviewValue = await overview(runtime, entries);
|
|
17344
17426
|
if (!selected) {
|
|
@@ -17972,6 +18054,7 @@ StrataGate represents earlier conversation history as layered Blocks:
|
|
|
17972
18054
|
|
|
17973
18055
|
Higher levels contain more source detail.
|
|
17974
18056
|
If the current level does not contain enough evidence for the task, do not infer omitted details; expand the Block or inspect raw memory.
|
|
18057
|
+
Historical Block checkpoints appear as \`[StrataGate historical conversation block]\` with a Block id and Level. When a checkpoint omits detail needed for the task, call \`memory_expand_block\` with that Block id and a suitable target level before inferring omitted content.
|
|
17975
18058
|
|
|
17976
18059
|
Memory use:
|
|
17977
18060
|
|