dsh-layers-hippocampus 1.9.8 → 1.9.9
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/CHANGELOG.md +27 -0
- package/index.js +96 -6
- package/package.json +1 -1
- package/src/context/ownership.js +103 -0
- package/src/context/peerProbe.js +97 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,33 @@ All notable changes to `dsh-layers-hippocampus` are documented here.
|
|
|
4
4
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
5
5
|
and the project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [1.9.9] — 2026-12-01
|
|
8
|
+
|
|
9
|
+
**谁是折叠的唯一负责人:探测到外部折叠者就让出,但绝不让出交接。**
|
|
10
|
+
|
|
11
|
+
本机同时有 `dsh-context-fold`、宿主 `tool-result-pruner`、`compaction-basic` 与海马体四方
|
|
12
|
+
改写同一个 context surface,各有各自的阈值。任何一方折叠后,其余各方的压力比描述的都是一个
|
|
13
|
+
已经不存在的表面 —— 这正是「到 90% 也不交接」的机制。
|
|
14
|
+
|
|
15
|
+
- **Added — `src/context/peerProbe.js`**:读 loader(`configEditor.entries()`)与宿主服务
|
|
16
|
+
(`toolResultPruner`、`compaction`),报告 `foreignFolders` / `hostPruner` /
|
|
17
|
+
`hostCompaction` / `probed`。禁用行、`mode: off`、`pruner.enabled: false` 都不算折叠者。
|
|
18
|
+
任一环节抛错只降级为 `probed: false`,绝不抛给调用方。
|
|
19
|
+
- **Added — `src/context/ownership.js`(纯函数仲裁)**:`auto`(默认)/ `lone` / `shared`。
|
|
20
|
+
`auto` 下:探测到外部折叠者 → `smartPrune` 与 `liveCompact` 全关、**交接保留**;
|
|
21
|
+
仅宿主 pruner → 只关 `liveCompact`(它只重写单个超大工具结果,不折轮次);
|
|
22
|
+
宿主 compaction 启用 → 两者全关;探测不可用 → **保持原行为并报告 `probe-unavailable`**
|
|
23
|
+
(只在「探测到」时让出,避免在没有 `configEditor` 的宿主上静默丢掉折叠)。
|
|
24
|
+
- **Changed — 让出 = 不调用**:`onceFoldDue`、`liveCompact`、`smartPrune` 三处全部前置
|
|
25
|
+
`ownership` 门;让出时**一次性折叠额度不被消费**,切回 `lone` 可立刻生效。
|
|
26
|
+
- **Changed — 可见性**:`[Task State]` 增加 `fold=on` / `fold=off(<reason>)`;状态面板与
|
|
27
|
+
`/memory status` 增加「折叠归属」一行;维护 tick 重新探测。
|
|
28
|
+
- **Config — `context.ownership`**:`auto|lone|shared`,从 RAW 配置读取(resolved 配置只保留
|
|
29
|
+
已知键,未知嵌套键被忽略而不报错)。
|
|
30
|
+
- **Tests — `test/v199.ownership.test.js`(16 例)**:仲裁矩阵 7 例、loader 探测 3 例、
|
|
31
|
+
以及 6 例集成断言 —— 让出时零折叠调用、额度不消费、peer 消失后恢复折叠、`lone` 强行折叠
|
|
32
|
+
并报冲突、86% 硬停时交接照常、状态行/面板暴露决策。
|
|
33
|
+
|
|
7
34
|
## [1.9.8] — 2026-12-01
|
|
8
35
|
|
|
9
36
|
**交接六路径收拢为一个协调器:一次事件只蒸馏一次。**
|
package/index.js
CHANGED
|
@@ -47,6 +47,8 @@ import { probeCompression, resolveEngine } from './src/compression.js';
|
|
|
47
47
|
import { LIVE_COMPACT_DEFAULTS, liveCompactSession } from './src/context/liveCompact.js';
|
|
48
48
|
import { FOLD_HARD_STOP_RATIO, foldBlocked } from './src/context/windowGuard.js';
|
|
49
49
|
import { createHandoffCoordinator, FORCE, HANDOFF_STATUS } from './src/handoff/coordinator.js';
|
|
50
|
+
import { decideOwnership, OWNERSHIP_MODE } from './src/context/ownership.js';
|
|
51
|
+
import { probeContextPeers } from './src/context/peerProbe.js';
|
|
50
52
|
// v1.9.7: how much pressure must grow before the stop line hands off AGAIN.
|
|
51
53
|
const FORCED_HANDOFF_DELTA = 0.05;
|
|
52
54
|
|
|
@@ -83,7 +85,7 @@ export { resolveConfig, DEFAULT_CONFIG };
|
|
|
83
85
|
* of letting a raw 404 reach the user.
|
|
84
86
|
*/
|
|
85
87
|
export const CAPABILITIES = Object.freeze({
|
|
86
|
-
version: '1.9.
|
|
88
|
+
version: '1.9.9',
|
|
87
89
|
spaces: true,
|
|
88
90
|
memories: true,
|
|
89
91
|
transferConsent: true,
|
|
@@ -483,6 +485,46 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
|
|
|
483
485
|
});
|
|
484
486
|
memory.setHandoffCoordinator?.(runtime.handoff);
|
|
485
487
|
|
|
488
|
+
/**
|
|
489
|
+
* v1.9.9 — who is allowed to fold this conversation?
|
|
490
|
+
*
|
|
491
|
+
* `auto` yields folding as soon as another component is mounted and able to fold:
|
|
492
|
+
* two folders invalidate each other's pressure ratio. Yielding must mean NOT CALLING
|
|
493
|
+
* the folder (see the guardRequest gates below), never "folding more gently".
|
|
494
|
+
*
|
|
495
|
+
* The mode lives in the RAW config (`context.ownership`): the resolved config only
|
|
496
|
+
* carries keys the package knows about, while `resolveConfig` ignores an unknown
|
|
497
|
+
* nested key instead of rejecting it. Reading the raw value keeps the switch usable
|
|
498
|
+
* without a schema change, and a missing key means `auto`.
|
|
499
|
+
*/
|
|
500
|
+
const OWNERSHIP_TTL_MS = 30_000;
|
|
501
|
+
runtime.refreshOwnership = () => {
|
|
502
|
+
let peers = null;
|
|
503
|
+
try {
|
|
504
|
+
peers = probeContextPeers({ ctx, logger: ctx?.logger ?? null });
|
|
505
|
+
} catch (error) {
|
|
506
|
+
// A probe that throws means "unknown", NOT "nobody else is here".
|
|
507
|
+
peers = { probed: false, foreignFolders: [], hostPruner: false, hostCompaction: 'unknown' };
|
|
508
|
+
ctx?.logger?.warn?.(`hippocampus/ownership: probe failed: ${error?.message ?? error}`);
|
|
509
|
+
}
|
|
510
|
+
let mode = OWNERSHIP_MODE.AUTO;
|
|
511
|
+
try {
|
|
512
|
+
mode = runtime.rawConfig?.context?.ownership ?? runtime.config?.context?.ownership ?? OWNERSHIP_MODE.AUTO;
|
|
513
|
+
} catch {
|
|
514
|
+
/* a broken raw config must not decide ownership */
|
|
515
|
+
}
|
|
516
|
+
const decided = decideOwnership({ mode, peers });
|
|
517
|
+
runtime.ownership = { ...decided, peers, at: runtime.memory?.clock?.now?.() ?? Date.now() };
|
|
518
|
+
return runtime.ownership;
|
|
519
|
+
};
|
|
520
|
+
runtime.ownershipOf = (force = false) => {
|
|
521
|
+
const now = runtime.memory?.clock?.now?.() ?? Date.now();
|
|
522
|
+
if (!force && runtime.ownership && now - runtime.ownership.at < OWNERSHIP_TTL_MS) return runtime.ownership;
|
|
523
|
+
return runtime.refreshOwnership();
|
|
524
|
+
};
|
|
525
|
+
// Decide once now so every caller (prompt, status, guard) sees a value, never `null`.
|
|
526
|
+
runtime.refreshOwnership();
|
|
527
|
+
|
|
486
528
|
/** Rebind the rings to the current dataDir / persistence flag (cosmetic state). */
|
|
487
529
|
runtime.resetActivityStores = () => {
|
|
488
530
|
activityStores.clear();
|
|
@@ -737,6 +779,15 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
|
|
|
737
779
|
} catch {
|
|
738
780
|
/* ignore */
|
|
739
781
|
}
|
|
782
|
+
try {
|
|
783
|
+
// v1.9.9: folding ownership is a fact about THIS turn's behaviour, so it belongs
|
|
784
|
+
// in the one line that answers "where am I now". A yielded fold that nobody can
|
|
785
|
+
// see is indistinguishable from a broken one.
|
|
786
|
+
const ownership = runtime.ownershipOf?.();
|
|
787
|
+
if (ownership) fields.fold = ownership.smartPrune === 'on' ? 'fold=on' : `fold=off(${ownership.reason})`;
|
|
788
|
+
} catch {
|
|
789
|
+
/* ignore */
|
|
790
|
+
}
|
|
740
791
|
const text = renderStateLine(fields, { maxChars: budget });
|
|
741
792
|
runtime.statePointerCache = { at: now, text };
|
|
742
793
|
return text;
|
|
@@ -1372,6 +1423,15 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
|
|
|
1372
1423
|
// outright and the handoff is forced — enforced BEFORE any folder runs, because
|
|
1373
1424
|
// those folders are what would otherwise keep the ratio down.
|
|
1374
1425
|
const gateRatio = Number.isFinite(state.projectedRatio) ? state.projectedRatio : 0;
|
|
1426
|
+
// ---- v1.9.9 ownership gate (C1) ---------------------------------------
|
|
1427
|
+
// Exactly ONE component may fold this surface. When another component is mounted
|
|
1428
|
+
// and able to fold, folding is REFUSED here — not made gentler. A second folder
|
|
1429
|
+
// resets the very ratio the handoff decision below is computed from, which is how
|
|
1430
|
+
// a conversation reaches 90% and still never hands over. The handoff is never
|
|
1431
|
+
// yielded: that is the half this plugin keeps.
|
|
1432
|
+
const ownership = runtime.ownershipOf();
|
|
1433
|
+
const foldOwned = ownership.smartPrune === 'on';
|
|
1434
|
+
const liveCompactOwned = ownership.liveCompact === 'on';
|
|
1375
1435
|
// ---- 0.1 the ONE-SHOT fold (v1.9.5) ------------------------------------
|
|
1376
1436
|
// Folding exists so a conversation can actually get smaller — but folding on
|
|
1377
1437
|
// every request is the "context drops from 10% to 7% over and over" bug that
|
|
@@ -1383,6 +1443,7 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
|
|
|
1383
1443
|
const sessionKey = session?.id ?? memory.sessionUsage()?.sessionId ?? null;
|
|
1384
1444
|
if (!runtime.onceFoldedSessions) runtime.onceFoldedSessions = new Set();
|
|
1385
1445
|
const onceFoldDue =
|
|
1446
|
+
foldOwned &&
|
|
1386
1447
|
onceFoldAt > 0 &&
|
|
1387
1448
|
Number.isFinite(gateRatio) &&
|
|
1388
1449
|
gateRatio >= onceFoldAt &&
|
|
@@ -1400,7 +1461,7 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
|
|
|
1400
1461
|
}
|
|
1401
1462
|
|
|
1402
1463
|
const liveConfig = runtime.config?.context?.liveCompact ?? {};
|
|
1403
|
-
if (liveConfig.enabled !== false && session && foldGate.allowed) {
|
|
1464
|
+
if (liveCompactOwned && liveConfig.enabled !== false && session && foldGate.allowed) {
|
|
1404
1465
|
try {
|
|
1405
1466
|
runtime.lastLiveCompact = {
|
|
1406
1467
|
source: 'hippocampus',
|
|
@@ -1419,7 +1480,7 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
|
|
|
1419
1480
|
}
|
|
1420
1481
|
|
|
1421
1482
|
const pruneThreshold = Number.isFinite(pruneConfig.threshold) ? pruneConfig.threshold : 0.85;
|
|
1422
|
-
const pruneAllowed = foldGate.allowed && (state.projectedRatio >= pruneThreshold || onceFoldDue);
|
|
1483
|
+
const pruneAllowed = foldOwned && foldGate.allowed && (state.projectedRatio >= pruneThreshold || onceFoldDue);
|
|
1423
1484
|
if (pruneConfig.enabled !== false && session && pruneAllowed) {
|
|
1424
1485
|
try {
|
|
1425
1486
|
runtime.lastSmartPrune = {
|
|
@@ -1625,6 +1686,14 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
|
|
|
1625
1686
|
runtime.maintenanceInFlight = true;
|
|
1626
1687
|
runtime.maintenanceSource = source;
|
|
1627
1688
|
runtime.touch();
|
|
1689
|
+
// v1.9.9: the maintenance tick is the routine re-probe of who else is folding. A
|
|
1690
|
+
// profile can lose context-fold (or gain host compaction) between two startups, and
|
|
1691
|
+
// a stale ownership decision would keep yielding folding for the whole process.
|
|
1692
|
+
try {
|
|
1693
|
+
runtime.refreshOwnership();
|
|
1694
|
+
} catch {
|
|
1695
|
+
/* a failed probe keeps the previous decision and the conservative default */
|
|
1696
|
+
}
|
|
1628
1697
|
try {
|
|
1629
1698
|
const report = await memory.maintain({ reason: source });
|
|
1630
1699
|
// v1.5.5: the offline Dream leg runs AFTER the read model has converged and
|
|
@@ -1774,8 +1843,16 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
|
|
|
1774
1843
|
};
|
|
1775
1844
|
|
|
1776
1845
|
runtime.status = async () => {
|
|
1777
|
-
if (runtime.phase
|
|
1778
|
-
|
|
1846
|
+
if (runtime.phase !== 'ready') throw runtime.notReady('status');
|
|
1847
|
+
const panel = { ...(await memory.status()) };
|
|
1848
|
+
// v1.9.9: "who is folding" is the first question a surprising ratio raises, and a
|
|
1849
|
+
// silent yield is indistinguishable from a broken fold. The panel answers it.
|
|
1850
|
+
try {
|
|
1851
|
+
panel.ownership = runtime.ownershipOf(true);
|
|
1852
|
+
} catch {
|
|
1853
|
+
/* the panel must survive a failed probe */
|
|
1854
|
+
}
|
|
1855
|
+
return panel;
|
|
1779
1856
|
};
|
|
1780
1857
|
|
|
1781
1858
|
runtime.start = () => {
|
|
@@ -3966,6 +4043,19 @@ export async function apply(ctx, rawConfig = {}) {
|
|
|
3966
4043
|
.map((entry) => entry.tag)
|
|
3967
4044
|
.filter(Boolean);
|
|
3968
4045
|
const feedbackStatus = runtime.hintFeedbackView();
|
|
4046
|
+
// v1.9.9: the yield must be readable, not inferred from a ratio that stopped
|
|
4047
|
+
// falling. `probe-unavailable` in particular means "we did not look".
|
|
4048
|
+
const ownership = (() => {
|
|
4049
|
+
try {
|
|
4050
|
+
return runtime.ownershipOf?.() ?? null;
|
|
4051
|
+
} catch {
|
|
4052
|
+
return null;
|
|
4053
|
+
}
|
|
4054
|
+
})();
|
|
4055
|
+
const ownershipLine = ownership
|
|
4056
|
+
? `折叠归属:smartPrune=${ownership.smartPrune} liveCompact=${ownership.liveCompact} handoff=${ownership.handoff} · ${ownership.reason}` +
|
|
4057
|
+
(ownership.foreignFolders?.length ? `(探测到:${ownership.foreignFolders.join('、')})` : '')
|
|
4058
|
+
: '折叠归属:未知';
|
|
3969
4059
|
return ok(
|
|
3970
4060
|
[
|
|
3971
4061
|
// v1.9.4: the one-liner comes FIRST — it is what a person opens this for.
|
|
@@ -3979,7 +4069,7 @@ export async function apply(ctx, rawConfig = {}) {
|
|
|
3979
4069
|
// v1.7.1: the hint loop is visible, not a mystery. A silenced tag is
|
|
3980
4070
|
// the engine's own decision and the operator must be able to see why.
|
|
3981
4071
|
`H提示反馈:追踪 ${feedbackStatus.tracked} 个标签,单向静默 ${feedbackStatus.silenced} 个${feedbackStatus.silencedTags.length ? `(${feedbackStatus.silencedTags.join('、')})` : ''}`,
|
|
3982
|
-
// v1.7.0 (M5): usage EVIDENCE, computed from in-process counters only.
|
|
4072
|
+
ownershipLine, // v1.7.0 (M5): usage EVIDENCE, computed from in-process counters only.
|
|
3983
4073
|
`工具使用(本进程):${toolUsageLine()}`,
|
|
3984
4074
|
].join('\n'),
|
|
3985
4075
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-layers-hippocampus",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Layered long-term memory for DeepSeek Harness: append-only event log, rebuildable tag index, day diaries, independent semantic layer, L2.5 trend quarantine, offline knowledge graph and a Web UI panel.",
|
|
6
6
|
"type": "module",
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1.9.9 — who owns "make the context smaller"?
|
|
3
|
+
*
|
|
4
|
+
* A profile can mount more than one component that rewrites the same context surface:
|
|
5
|
+
* this plugin (smartPrune + liveCompact), `dsh-context-fold` (tool-result folding and a
|
|
6
|
+
* compaction ledger), the host's own `tool-result-pruner`, and `compaction-basic`. Each
|
|
7
|
+
* has its own threshold and its own measure, so the moment one of them folds, the
|
|
8
|
+
* others' pressure ratio describes a surface that no longer exists.
|
|
9
|
+
*
|
|
10
|
+
* 1.9.4 already argued that folding is FAKE relief (it shrinks the prompt without
|
|
11
|
+
* reducing what was said) and made the handoff the thing that carries a conversation
|
|
12
|
+
* forward. Four writers make that argument impossible to hold: any of them can reset
|
|
13
|
+
* pressure just before our trigger. So the rule is now explicit and configurable:
|
|
14
|
+
*
|
|
15
|
+
* - `auto` (default) — exactly one component folds. If a foreign folder is present,
|
|
16
|
+
* hippocampus YIELDS folding entirely and keeps the handoff. Yielding means
|
|
17
|
+
* not calling the folder at all: a "quieter" fold is still a fold.
|
|
18
|
+
* - `lone` — hippocampus folds regardless of peers, and reports the conflict.
|
|
19
|
+
* - `shared` — observe only: no folding, no handoff. For diagnosing a profile.
|
|
20
|
+
*
|
|
21
|
+
* This module is pure: it takes the mode and a peer snapshot, and returns a decision.
|
|
22
|
+
* Reading the loader is `peerProbe.js`; using the decision is `index.js`.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export const OWNERSHIP_MODE = Object.freeze({ AUTO: 'auto', LONE: 'lone', SHARED: 'shared' });
|
|
26
|
+
|
|
27
|
+
const SWITCH = Object.freeze({ ON: 'on', OFF: 'off' });
|
|
28
|
+
|
|
29
|
+
/** Longest reason code rendered into the prompt's `[Task State]` line. */
|
|
30
|
+
const MAX_REASON = 24;
|
|
31
|
+
|
|
32
|
+
function normalizeMode(mode) {
|
|
33
|
+
const value = String(mode ?? '').toLowerCase();
|
|
34
|
+
if (value === OWNERSHIP_MODE.LONE || value === OWNERSHIP_MODE.SHARED) return value;
|
|
35
|
+
return OWNERSHIP_MODE.AUTO;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function foreignFoldersOf(peers) {
|
|
39
|
+
const list = Array.isArray(peers?.foreignFolders) ? peers.foreignFolders : [];
|
|
40
|
+
return list
|
|
41
|
+
.filter((entry) => entry && entry.foldEnabled !== false)
|
|
42
|
+
.map((entry) => String(entry.id ?? entry.name ?? 'peer'));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param {{ mode?: string, peers?: object|null }} input
|
|
47
|
+
* @returns {{
|
|
48
|
+
* mode: string,
|
|
49
|
+
* smartPrune: 'on'|'off',
|
|
50
|
+
* liveCompact: 'on'|'off',
|
|
51
|
+
* handoff: 'on'|'off',
|
|
52
|
+
* reason: string,
|
|
53
|
+
* conflict: boolean,
|
|
54
|
+
* foreignFolders: string[],
|
|
55
|
+
* peers: object|null
|
|
56
|
+
* }}
|
|
57
|
+
*/
|
|
58
|
+
export function decideOwnership({ mode = OWNERSHIP_MODE.AUTO, peers = null } = {}) {
|
|
59
|
+
const normalizedMode = normalizeMode(mode);
|
|
60
|
+
const foreign = foreignFoldersOf(peers);
|
|
61
|
+
const decision = (smartPrune, liveCompact, handoff, reason, conflict = false) => ({
|
|
62
|
+
mode: normalizedMode,
|
|
63
|
+
smartPrune,
|
|
64
|
+
liveCompact,
|
|
65
|
+
handoff,
|
|
66
|
+
reason: String(reason).slice(0, MAX_REASON),
|
|
67
|
+
conflict,
|
|
68
|
+
foreignFolders: foreign,
|
|
69
|
+
peers,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// `lone` is the escape hatch for a profile where the sibling folder is broken or
|
|
73
|
+
// unwanted. It is loud: the conflict is reported, not hidden.
|
|
74
|
+
if (normalizedMode === OWNERSHIP_MODE.LONE) {
|
|
75
|
+
return decision(SWITCH.ON, SWITCH.ON, SWITCH.ON, 'lone', foreign.length > 0);
|
|
76
|
+
}
|
|
77
|
+
// `shared` exists so an operator can watch what the other component does.
|
|
78
|
+
if (normalizedMode === OWNERSHIP_MODE.SHARED) {
|
|
79
|
+
return decision(SWITCH.OFF, SWITCH.OFF, SWITCH.OFF, 'shared');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ---- auto ---------------------------------------------------------------
|
|
83
|
+
// An unreadable loader is NOT a detected peer. Yielding on "unknown" would silently
|
|
84
|
+
// remove folding on every host that does not expose `configEditor` — a much larger
|
|
85
|
+
// and quieter failure than the one this release fixes. So: yield only on DETECTION,
|
|
86
|
+
// and make the blind state visible (`probe-unavailable`) so it can be diagnosed.
|
|
87
|
+
if (peers?.probed !== true) {
|
|
88
|
+
return decision(SWITCH.ON, SWITCH.ON, SWITCH.ON, 'probe-unavailable');
|
|
89
|
+
}
|
|
90
|
+
if (foreign.length > 0) {
|
|
91
|
+
return decision(SWITCH.OFF, SWITCH.OFF, SWITCH.ON, `peer:${foreign[0]}`);
|
|
92
|
+
}
|
|
93
|
+
if (peers?.hostCompaction === 'enabled') {
|
|
94
|
+
return decision(SWITCH.OFF, SWITCH.OFF, SWITCH.ON, 'host-compaction');
|
|
95
|
+
}
|
|
96
|
+
// The host pruner only rewrites individual oversized tool results; it does not fold
|
|
97
|
+
// turns, so R3/R5-style decisions keep describing the same surface. Our own
|
|
98
|
+
// liveCompact, however, would be the second writer on that exact surface.
|
|
99
|
+
if (peers?.hostPruner === true) {
|
|
100
|
+
return decision(SWITCH.ON, SWITCH.OFF, SWITCH.ON, 'host-pruner');
|
|
101
|
+
}
|
|
102
|
+
return decision(SWITCH.ON, SWITCH.ON, SWITCH.ON, 'owner');
|
|
103
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1.9.9 — read the loader and report which components could fold this conversation.
|
|
3
|
+
*
|
|
4
|
+
* The probe is deliberately defensive: every fact it reports is "best effort", and the
|
|
5
|
+
* ONLY thing the caller may conclude from a failure is `probed: false` (which makes
|
|
6
|
+
* `decideOwnership()` yield folding — see ownership.js for why that direction is safe).
|
|
7
|
+
*
|
|
8
|
+
* Two independent sources, because neither is always present:
|
|
9
|
+
* 1. `ctx.get('configEditor').entries()` — the loader rows. This is how a disabled
|
|
10
|
+
* row, a renamed row id and a row's own Config are all visible. index.js already
|
|
11
|
+
* uses this seam to persist config, so it is a known-good dependency.
|
|
12
|
+
* 2. Service presence — `toolResultPruner` (host pruner) and `compaction` (whichever
|
|
13
|
+
* backend holds the slot). A service can exist without a row we can read.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** Ids we recognise as "someone else folds turns". */
|
|
17
|
+
const FOREIGN_FOLDER_NAMES = ['dsh-context-fold', 'context-fold'];
|
|
18
|
+
const HOST_COMPACTION_NAMES = ['dsh-compaction-basic', 'compaction-basic'];
|
|
19
|
+
|
|
20
|
+
function rowOf(entry) {
|
|
21
|
+
const options = entry?.options ?? entry ?? {};
|
|
22
|
+
return {
|
|
23
|
+
id: options.id ?? entry?.id ?? null,
|
|
24
|
+
name: options.name ?? entry?.name ?? null,
|
|
25
|
+
disabled: options.disabled === true,
|
|
26
|
+
config: options.config && typeof options.config === 'object' ? options.config : {},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function matches(row, names) {
|
|
31
|
+
const id = String(row.id ?? '');
|
|
32
|
+
const name = String(row.name ?? '');
|
|
33
|
+
return names.some((candidate) => id === candidate || name === candidate || name.includes(candidate) || id.includes(candidate));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {{ ctx?: object|null, logger?: object|null }} input
|
|
38
|
+
* @returns {{
|
|
39
|
+
* probed: boolean,
|
|
40
|
+
* rows: number,
|
|
41
|
+
* foreignFolders: Array<{id: string, name: string|null, foldEnabled: boolean}>,
|
|
42
|
+
* hostPruner: boolean,
|
|
43
|
+
* hostCompaction: 'enabled'|'disabled'|'unknown'
|
|
44
|
+
* }}
|
|
45
|
+
*/
|
|
46
|
+
export function probeContextPeers({ ctx = null, logger = null } = {}) {
|
|
47
|
+
const peers = {
|
|
48
|
+
probed: false,
|
|
49
|
+
rows: 0,
|
|
50
|
+
foreignFolders: [],
|
|
51
|
+
hostPruner: false,
|
|
52
|
+
hostCompaction: 'unknown',
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const get = (name) => {
|
|
56
|
+
try {
|
|
57
|
+
return typeof ctx?.get === 'function' ? ctx.get(name) : null;
|
|
58
|
+
} catch {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
peers.hostPruner = Boolean(get('toolResultPruner'));
|
|
64
|
+
|
|
65
|
+
let entries = null;
|
|
66
|
+
try {
|
|
67
|
+
const editor = get('configEditor');
|
|
68
|
+
if (editor && typeof editor.entries === 'function') entries = editor.entries();
|
|
69
|
+
} catch (error) {
|
|
70
|
+
logger?.debug?.(`hippocampus/ownership: configEditor.entries failed: ${error?.message ?? error}`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (Array.isArray(entries)) {
|
|
74
|
+
peers.probed = true;
|
|
75
|
+
peers.rows = entries.length;
|
|
76
|
+
for (const entry of entries) {
|
|
77
|
+
const row = rowOf(entry);
|
|
78
|
+
if (matches(row, FOREIGN_FOLDER_NAMES)) {
|
|
79
|
+
peers.foreignFolders.push({
|
|
80
|
+
id: String(row.id ?? row.name ?? 'context-fold'),
|
|
81
|
+
name: row.name ?? null,
|
|
82
|
+
// A mounted row that is disabled, or a `mode: off`, is not folding anything.
|
|
83
|
+
foldEnabled: row.disabled !== true && row.config?.mode !== 'off' && row.config?.pruner?.enabled !== false,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (matches(row, HOST_COMPACTION_NAMES)) {
|
|
87
|
+
peers.hostCompaction = row.disabled === true ? 'disabled' : 'enabled';
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Service fallback: a compaction backend can hold the slot without a row we could
|
|
93
|
+
// read (a bundle row, an unlisted entry). Only used when the rows said nothing.
|
|
94
|
+
if (peers.hostCompaction === 'unknown' && get('compaction')) peers.hostCompaction = 'enabled';
|
|
95
|
+
|
|
96
|
+
return peers;
|
|
97
|
+
}
|