dsh-context-truth 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README-en.md +3 -1
- package/README.md +8 -1
- package/lib/index.js +76 -14
- package/package.json +1 -1
- package/test/index.test.js +126 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
* **修 `handoff` 模式折叠后从不激活轮次:命令通道读错了宿主的返回值形状。** 现场(Linux,stock 部署,
|
|
6
|
+
realm 里没有可注入的 `compaction` 服务,命令通道是唯一能折的路):`/compact` 真的折了 1295 条 /
|
|
7
|
+
~506,473 tokens,`command/done` 明确 `{kind: "success", sourceEventSeq: 3436}`,但会话停在 idle,
|
|
8
|
+
**没有激活轮**,`state.json` 停在 `foldNo: 0 / ready 未消费 / pending: null`。
|
|
9
|
+
根因:`dsh-commands` 的 `settle()` 返回 `Object.freeze({ commandId, result })`(类型 `CommandExecution`),
|
|
10
|
+
`sourceEventSeq` 在 `result` 里;`requestFold()` 直接读 `execution.sourceEventSeq`,恒为 `undefined`,
|
|
11
|
+
于是每次成功折叠都被判成"没有可折叠范围"(`folded: false`)→ 不记 `foldNo`、不建 `pending`、不 `followup`。
|
|
12
|
+
* 一处修三件事(`requestFold` 的命令分支):
|
|
13
|
+
1. 解包 `execution.result`(新增 `commandResultOf()`,同时兼容直接返回 `CommandResult` 的桩/老宿主);
|
|
14
|
+
2. `execute()` 对"命令未注册"是 **resolve `undefined`**,不是 throw(`dsh-commands`:
|
|
15
|
+
`if (parsed === void 0) return void 0`),而旧代码只在 catch 里回退服务通道 → 文档承诺的
|
|
16
|
+
"先命令、再服务"在没有 `/compact` 的 realm 上是死的;现在 `undefined` 明确走回退并记日志,
|
|
17
|
+
`foldAtIdleMethod: command` 时则记"不允许其它通道";
|
|
18
|
+
3. `kind: error` / `cancelled` 的拒绝与"没有可折叠范围"分开记日志(带 `kind` 与原文);折叠未提交时,
|
|
19
|
+
消费者按 `error` 记 `warn`、其余记 `info`,并写明 `reason`。
|
|
20
|
+
* **为什么过去的演练没抓到**:本仓库 profile 用 `foldAtIdleMethod: service`,0.3.x 的激活演练全部走服务通道
|
|
21
|
+
(判定只需 `compactNow()` 非 null,天然正确)。命令分支是 0.3.0(`e3318ab`)引入的,而 `dsh-commands`
|
|
22
|
+
从 0.2.0-rc.2 起就是两层形状 —— **命令分支上线第一天起判定就恒为 false**,只是从没人走过这条路。
|
|
23
|
+
这次把"命令通道也必须激活"变成回归用例,不再依赖演练选哪条通道。
|
|
24
|
+
* 测试:85(新增 3 条:真实两层契约必须激活;`execute` resolve `undefined` 必须回退服务并激活;
|
|
25
|
+
`kind: error` 必须保留档、不激活、记 `warn`)。三处变异分别失败 2 / 1 / 1 例,隔离副本按字节恢复。
|
|
26
|
+
* 顺带更正 `thresholdRatio` 的注释:原文把 0.7 写成"本 profile 跑 dsh-dcp"的事实,而现场那台机器并没有该包;
|
|
27
|
+
改为说明 0.7 是 dsh-dcp 的取值、stock 是 0.8,应按实际挂载的引擎设置。
|
|
28
|
+
* ⚠ 命令通道的实机验收要等重启(HMR 缺陷 #13623 让 link 插件的源码改动只能靠重启生效);本机待做,
|
|
29
|
+
现场(Linux)需 `npm i dsh-context-truth@0.4.1` 后重启复验 `foldNo: 1` + 激活轮。
|
|
30
|
+
|
|
3
31
|
## 0.4.0
|
|
4
32
|
|
|
5
33
|
* **委派会话(子代理)也能写交接档了:`subagentHandoff`,默认关。** 动机是量出来的,不是猜的:
|
package/README-en.md
CHANGED
|
@@ -108,6 +108,8 @@ The chain is:
|
|
|
108
108
|
|
|
109
109
|
Guards: at most 3 reminders per cycle; if a round ends past the prep point with no note registered, the plugin **wakes** a round with `followup` (dynamic context is only read by requests that actually happen, and a round that ends issues no further request, so the reminder would otherwise wait for a human — measured, and that is why the wake exists). The wake message is a **single line** naming the note path, and `prepare` re-publishes the full checklist into the runtime-context handoff block of that same request — so the transcript never gets the whole reminder as a user message. If the reading has already dropped below the prep point when the wake round starts (for example the host folded first), only the one-liner remains and the log says why. Notes are temporary, recycled when the next handoff is created with a 7-day sweep; a registered note whose fold did not happen is kept and never activates a turn.
|
|
110
110
|
|
|
111
|
+
The command channel decides "did it fold" from the host's own shape: `commands.execute()` resolves `CommandExecution = { commandId, result }`, so the evidence is `execution.result.sourceEventSeq`. Before 0.4.1 the plugin read `execution.sourceEventSeq` (always `undefined`), so on that channel **a successful fold never activated the post-fold turn** — on a stock deployment (no injectable `compaction` service in the realm) that reads as "it folded but no turn ever follows". A realm without `/compact` makes `execute()` resolve `undefined` instead of throwing; that case now falls back to the compaction service explicitly instead of being taken for "no compactable range".
|
|
112
|
+
|
|
111
113
|
#### Notes in delegated sessions (`subagentHandoff`, off by default)
|
|
112
114
|
|
|
113
115
|
The root-session handoff leans on two things a child does not have: this plugin performs the fold, and this plugin opens the activation turn. A child therefore gets a reduced shape, not the same one:
|
|
@@ -252,7 +254,7 @@ What you get for it: the model stops halting or handing off because it *thinks*
|
|
|
252
254
|
## Verify
|
|
253
255
|
|
|
254
256
|
```sh
|
|
255
|
-
npm test #
|
|
257
|
+
npm test # 85 unit tests: banding, hysteresis, quantization, free window, fold definition, idle fold and its guards, live settings changes, schema-default parity, pace estimate, degradation, directive patching, look-alike rejection, idempotence, handoff folding (reminder, registration, round-end fold, single activation, restart recovery, recycling, round-end wake, the command channel's real contract and its fallback), notes in delegated sessions (the file as the registration, fold detection, the pointer back, off by default), client card shape, the handoff reminder travelling in runtime context rather than as a message, and a live mode switch dropping it
|
|
256
258
|
```
|
|
257
259
|
|
|
258
260
|
After installing, open a new session and send one message: expanding that turn's runtime context block should show `Context occupancy (host-measured): …`, and the log carries `context-truth: none -> ample (used=… window=1000000 compactionAt=678464)`.
|
package/README.md
CHANGED
|
@@ -168,6 +168,13 @@ this in as few commands as possible, then a short answer."。数字它读对了
|
|
|
168
168
|
交接档是临时文件,下一次交接生成时回收旧的、7 天兜底清理;登记了档但没折成(引擎拒绝、被别的东西
|
|
169
169
|
先折了)时不会激活,档保留。
|
|
170
170
|
|
|
171
|
+
命令通道判定"折没折成"的依据是**宿主自己的返回形状**:`commands.execute()` 返回
|
|
172
|
+
`CommandExecution = { commandId, result }`,所以要看 `execution.result.sourceEventSeq`。0.4.1 之前误读成
|
|
173
|
+
`execution.sourceEventSeq`(恒为 `undefined`),导致**命令通道上折叠成功也不会激活轮次**——stock 部署
|
|
174
|
+
(realm 里没有可注入的 `compaction` 服务)上就是"折了但永远没有下一轮"。另外 `/compact` 未注册时
|
|
175
|
+
`execute()` 是 resolve `undefined` 而不是抛错,这种情形现在会明确回退到 compaction 服务,不再被当成
|
|
176
|
+
"没有可折叠范围"。
|
|
177
|
+
|
|
171
178
|
#### 委派会话的交接档(`subagentHandoff`,默认关)
|
|
172
179
|
|
|
173
180
|
根会话的 handoff 依赖两件子会话没有的东西:折叠是本插件做的,激活轮是本插件开的。所以给子会话的不是同一套,
|
|
@@ -360,7 +367,7 @@ runtime-context 快照**字节不变就不会重发**,所以读数按台阶量
|
|
|
360
367
|
## 验证
|
|
361
368
|
|
|
362
369
|
```sh
|
|
363
|
-
npm test #
|
|
370
|
+
npm test # 85 项单测:分档/迟滞/量化/自由窗口/折叠定义/空闲折叠与护栏/配置热更新/schema 默认值一致性/节奏估算/降级/摘要改写/形似请求排除/幂等/交接式折叠(提醒、登记、轮末折叠、单次激活、重启恢复、回收、轮末唤醒、命令通道的真实契约与回退)/委派会话的交接档(写文件即登记、折叠判定、折叠后指回、默认关)/客户端设置卡结构/交接提醒走 runtime context 而非消息,以及实时切模式后提醒随模式消失
|
|
364
371
|
```
|
|
365
372
|
|
|
366
373
|
装好后开一个新会话发一条消息,展开该轮的 runtime context 块应看到
|
package/lib/index.js
CHANGED
|
@@ -146,11 +146,13 @@ const DEFAULT_OPTIONS = {
|
|
|
146
146
|
* profile's compaction config; the line only reports the point, it never
|
|
147
147
|
* enforces it.
|
|
148
148
|
*
|
|
149
|
-
* 0.7
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
149
|
+
* 0.7 is the value a `@aiwayds/dsh-dcp` bundle sets (verified against a live
|
|
150
|
+
* engine: thresholdRatio=0.7, headroomTokens=65536, retainRatio=0.16); stock
|
|
151
|
+
* compaction uses 0.8. ✗ Do not read this default as a statement about "this
|
|
152
|
+
* machine": a profile that mounts no such provider (e.g. a stock Linux box) should
|
|
153
|
+
* set `thresholdRatio: 0.8` to match what it actually runs. The displayed point is
|
|
154
|
+
* often unchanged either way — the budget term binds at 727,040 on a 1M window with
|
|
155
|
+
* 256K reserved — but the mirror must match for the cases where it does not.
|
|
154
156
|
*/
|
|
155
157
|
thresholdRatio: 0.7,
|
|
156
158
|
headroomTokens: 65536,
|
|
@@ -1385,6 +1387,27 @@ function installIdleFold(ctx, resolve, services) {
|
|
|
1385
1387
|
})
|
|
1386
1388
|
}
|
|
1387
1389
|
|
|
1390
|
+
/**
|
|
1391
|
+
* Unwrap the host's `commands.execute()` answer.
|
|
1392
|
+
*
|
|
1393
|
+
* `dsh-commands` settles a run as `Object.freeze({ commandId, result })` — a
|
|
1394
|
+
* `CommandExecution`, not the `CommandResult` — and the RPC schema is the same two
|
|
1395
|
+
* layers. Reading `execution.sourceEventSeq` therefore always misses, and because a
|
|
1396
|
+
* missing `sourceEventSeq` is exactly how this plugin recognises "the fold found
|
|
1397
|
+
* nothing to compact", **every** successful fold through the command channel looked
|
|
1398
|
+
* like a no-op: handoff mode kept the note and never activated the post-fold turn
|
|
1399
|
+
* (live: session b28499cb on 2026-11-22 01:22, where `/compact` really folded 1295
|
|
1400
|
+
* items / ~506k tokens and `state.json` still said `foldNo: 0`).
|
|
1401
|
+
*
|
|
1402
|
+
* Both shapes are accepted, so a stub or an older host that answers with the
|
|
1403
|
+
* `CommandResult` itself keeps working.
|
|
1404
|
+
*/
|
|
1405
|
+
function commandResultOf(execution) {
|
|
1406
|
+
if (execution === null || execution === undefined) return undefined
|
|
1407
|
+
const nested = execution.result
|
|
1408
|
+
return nested !== null && nested !== undefined && typeof nested === 'object' ? nested : execution
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1388
1411
|
/**
|
|
1389
1412
|
* Ask for one fold, at the agent's own idle boundary.
|
|
1390
1413
|
*
|
|
@@ -1408,16 +1431,50 @@ function installIdleFold(ctx, resolve, services) {
|
|
|
1408
1431
|
* a follow-up turn on the strength of a fold that never happened.
|
|
1409
1432
|
*/
|
|
1410
1433
|
async function requestFold(ctx, agent, options, services, signal) {
|
|
1434
|
+
const session = agent === null || agent === undefined ? undefined : agent.session
|
|
1411
1435
|
if (options.foldAtIdleMethod !== 'service') {
|
|
1412
1436
|
const commands = safeGet(ctx, 'commands')
|
|
1413
1437
|
if (commands !== undefined && typeof commands.execute === 'function') {
|
|
1414
1438
|
try {
|
|
1415
|
-
const
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1439
|
+
const execution = await commands.execute(agent, '/compact', [], signal)
|
|
1440
|
+
if (execution === undefined) {
|
|
1441
|
+
// `execute()` RESOLVES `undefined` — it does not throw — when the line
|
|
1442
|
+
// does not parse or the command is not registered in the agent's realm
|
|
1443
|
+
// (`dsh-commands`: `if (parsed === void 0) return void 0`). Only a throw
|
|
1444
|
+
// used to fall through to the service, so the documented "command, then
|
|
1445
|
+
// service" order was dead on a realm without `/compact`.
|
|
1446
|
+
if (options.foldAtIdleMethod === 'command') {
|
|
1447
|
+
logLine(
|
|
1448
|
+
ctx,
|
|
1449
|
+
'info',
|
|
1450
|
+
'context-truth: /compact is not registered for %s and the fold method is "command"; no other channel is allowed',
|
|
1451
|
+
sessionIdOf(session),
|
|
1452
|
+
)
|
|
1453
|
+
return undefined
|
|
1454
|
+
}
|
|
1455
|
+
logLine(
|
|
1456
|
+
ctx,
|
|
1457
|
+
'info',
|
|
1458
|
+
'context-truth: /compact is not registered for %s; falling back to the compaction service',
|
|
1459
|
+
sessionIdOf(session),
|
|
1460
|
+
)
|
|
1461
|
+
} else {
|
|
1462
|
+
const result = commandResultOf(execution)
|
|
1463
|
+
const kind = result === null || result === undefined ? undefined : result.kind
|
|
1464
|
+
// `sourceEventSeq` correlates the committed summary with `compaction/summary`
|
|
1465
|
+
// and is absent on the "No compactable history yet" success.
|
|
1466
|
+
const folded = result !== null && result !== undefined && result.sourceEventSeq !== undefined
|
|
1467
|
+
if (!folded && (kind === 'error' || kind === 'cancelled')) {
|
|
1468
|
+
logLine(
|
|
1469
|
+
ctx,
|
|
1470
|
+
'info',
|
|
1471
|
+
'context-truth: /compact did not fold for %s (%s): %s',
|
|
1472
|
+
sessionIdOf(session),
|
|
1473
|
+
kind,
|
|
1474
|
+
result.text === undefined ? 'no text' : result.text,
|
|
1475
|
+
)
|
|
1476
|
+
}
|
|
1477
|
+
return { how: 'command', folded, reason: folded ? 'ok' : (kind ?? 'no-range') }
|
|
1421
1478
|
}
|
|
1422
1479
|
} catch (error) {
|
|
1423
1480
|
// A realm without the command, or a refusal, is not fatal: the service
|
|
@@ -1465,7 +1522,8 @@ async function requestFold(ctx, agent, options, services, signal) {
|
|
|
1465
1522
|
if (compaction === undefined) return undefined
|
|
1466
1523
|
const result = await compaction.compactNow(agent, signal)
|
|
1467
1524
|
// `null` is the engine's documented "no safe useful range" answer.
|
|
1468
|
-
|
|
1525
|
+
const folded = result !== null && result !== undefined
|
|
1526
|
+
return { how: 'service', folded, reason: folded ? 'ok' : 'no-range' }
|
|
1469
1527
|
}
|
|
1470
1528
|
|
|
1471
1529
|
// ---------------------------------------------------------------------------
|
|
@@ -2458,11 +2516,15 @@ function installHandoffFold(ctx, resolve, services, notices) {
|
|
|
2458
2516
|
return
|
|
2459
2517
|
}
|
|
2460
2518
|
if (!outcome.folded) {
|
|
2519
|
+
// The channel has already logged *why* it did not commit (refused,
|
|
2520
|
+
// cancelled, nothing to compact); this line records the consequence.
|
|
2521
|
+
const reason = outcome.reason === undefined ? 'no-range' : outcome.reason
|
|
2461
2522
|
logLine(
|
|
2462
2523
|
ctx,
|
|
2463
|
-
'info',
|
|
2464
|
-
'context-truth: the fold
|
|
2524
|
+
reason === 'error' ? 'warn' : 'info',
|
|
2525
|
+
'context-truth: the fold did not commit for %s (%s); the note at %s is kept for the next round end',
|
|
2465
2526
|
sessionId,
|
|
2527
|
+
reason,
|
|
2466
2528
|
note.path,
|
|
2467
2529
|
)
|
|
2468
2530
|
return
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-context-truth",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "DeepSeek Harness plugin: tells the model its real, host-measured context occupancy every turn — and keeps compaction summaries from carrying false \"context is nearly exhausted\" claims.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|
package/test/index.test.js
CHANGED
|
@@ -1523,6 +1523,132 @@ test('handoff mode folds at the round end and activates exactly one turn', async
|
|
|
1523
1523
|
assert.ok(state.pending.deliveredAt > 0)
|
|
1524
1524
|
})
|
|
1525
1525
|
|
|
1526
|
+
test('a fold through the real /compact contract activates the post-fold turn', async (t) => {
|
|
1527
|
+
// 宿主契约:`dsh-commands` 的 `settle()` 返回 `Object.freeze({ commandId, result })`,
|
|
1528
|
+
// 所以 `sourceEventSeq` 在 `result` 里,不在 `execute()` 的返回值上。0.4.0 之前按扁平读,
|
|
1529
|
+
// 于是每一次成功折叠都被判成“没有可折叠范围” → handoff 从不激活(现场 session b28499cb,
|
|
1530
|
+
// 2026-11-22 01:22:`/compact` 真的折了 1295 条 / ~506k tokens,state.json 仍是 foldNo 0)。
|
|
1531
|
+
const root = scratchRoot(t)
|
|
1532
|
+
const { box, meter } = movableMeter(500000)
|
|
1533
|
+
const executions = []
|
|
1534
|
+
const logs = []
|
|
1535
|
+
const commands = {
|
|
1536
|
+
execute: (...args) => {
|
|
1537
|
+
executions.push(args)
|
|
1538
|
+
// 与现场 `command/done` 逐字一致的两层形状。
|
|
1539
|
+
return Promise.resolve({
|
|
1540
|
+
commandId: 'cmd-repro-1',
|
|
1541
|
+
result: {
|
|
1542
|
+
kind: 'success',
|
|
1543
|
+
text: 'Compacted 1295 history items (~506473 tokens).',
|
|
1544
|
+
sourceEventSeq: 3436,
|
|
1545
|
+
},
|
|
1546
|
+
})
|
|
1547
|
+
},
|
|
1548
|
+
}
|
|
1549
|
+
const agent = handoffAgent(handoffSession('session-contract'))
|
|
1550
|
+
// 现场是 stock 部署:只有命令通道可用,没有任何 compaction 服务可注入。
|
|
1551
|
+
const { ctx, registered } = stubContext({ meter, commands, logs })
|
|
1552
|
+
apply(ctx, { foldMode: 'handoff', handoffDir: root })
|
|
1553
|
+
|
|
1554
|
+
const notePath = handoffPathFor(root, 'session-contract', 1)
|
|
1555
|
+
box.used = 600000
|
|
1556
|
+
await requestStep(registered, agent, 2, 1)
|
|
1557
|
+
assert.ok(handoffBlock(registered, agent).includes(notePath), 'the reminder names the path')
|
|
1558
|
+
|
|
1559
|
+
mkdirSync(join(root, 'session-contract'), { recursive: true })
|
|
1560
|
+
writeFileSync(notePath, `# note\n${'x'.repeat(400)}`, 'utf8')
|
|
1561
|
+
const tool = registered.tools.find((definition) => definition.name === HANDOFF_TOOL_NAME)
|
|
1562
|
+
assert.match(tool.execute({ path: notePath }, { agent }), /handoff registered/)
|
|
1563
|
+
|
|
1564
|
+
await idleBoundary(registered, agent)
|
|
1565
|
+
|
|
1566
|
+
assert.equal(executions.length, 1, 'the fold must go through the command channel')
|
|
1567
|
+
assert.equal(executions[0][1], '/compact', 'the fold is the session\'s own /compact')
|
|
1568
|
+
assert.deepEqual(executions[0][2], [], 'submitted attachments must be an empty list')
|
|
1569
|
+
assert.ok(executions[0][3] !== undefined, 'the command must receive an abort signal')
|
|
1570
|
+
assert.equal(
|
|
1571
|
+
agent.followed.length,
|
|
1572
|
+
1,
|
|
1573
|
+
`the post-fold turn must be activated (logs: ${JSON.stringify(logs.map((entry) => entry.slice(0, 2)))})`,
|
|
1574
|
+
)
|
|
1575
|
+
assert.ok(agent.followed[0].content[0].text.includes(notePath), 'the activation points at the note')
|
|
1576
|
+
|
|
1577
|
+
const state = JSON.parse(readFileSync(join(root, 'session-contract', HANDOFF_STATE_FILE), 'utf8'))
|
|
1578
|
+
assert.equal(state.foldNo, 1, 'the fold must be recorded')
|
|
1579
|
+
assert.equal(state.ready, null, 'the registered note must be consumed')
|
|
1580
|
+
assert.ok(state.pending !== null && state.pending.deliveredAt !== null, 'the activation must be marked delivered')
|
|
1581
|
+
})
|
|
1582
|
+
|
|
1583
|
+
test('an unregistered /compact falls back to the compaction service instead of answering "no range"', async (t) => {
|
|
1584
|
+
// `dsh-commands.execute()` 对“命令没注册/语法不认识”是 resolve undefined,不 throw。
|
|
1585
|
+
// 只有 throw 才回退 → realm 里没有 /compact 的部署上,`auto` 的第二条腿是死的。
|
|
1586
|
+
const root = scratchRoot(t)
|
|
1587
|
+
const { meter } = movableMeter(600000)
|
|
1588
|
+
const folds = []
|
|
1589
|
+
const logs = []
|
|
1590
|
+
const commands = { execute: () => Promise.resolve(undefined) }
|
|
1591
|
+
const session = handoffSession('session-fallback')
|
|
1592
|
+
const agent = handoffAgent(session)
|
|
1593
|
+
const { ctx, registered } = stubContext({
|
|
1594
|
+
meter,
|
|
1595
|
+
commands,
|
|
1596
|
+
logs,
|
|
1597
|
+
compaction: { compactNow: (...args) => (folds.push(args), Promise.resolve({ shadowedSeqs: [1] })) },
|
|
1598
|
+
})
|
|
1599
|
+
apply(ctx, { foldMode: 'handoff', handoffDir: root })
|
|
1600
|
+
|
|
1601
|
+
const notePath = handoffPathFor(root, 'session-fallback', 1)
|
|
1602
|
+
await requestStep(registered, agent, 2, 1)
|
|
1603
|
+
mkdirSync(join(root, 'session-fallback'), { recursive: true })
|
|
1604
|
+
writeFileSync(notePath, `# note\n${'x'.repeat(400)}`, 'utf8')
|
|
1605
|
+
const tool = registered.tools.find((definition) => definition.name === HANDOFF_TOOL_NAME)
|
|
1606
|
+
assert.match(tool.execute({ path: notePath }, { agent }), /handoff registered/)
|
|
1607
|
+
|
|
1608
|
+
await idleBoundary(registered, agent)
|
|
1609
|
+
|
|
1610
|
+
assert.equal(folds.length, 1, 'the service channel must be reached after an unresolved /compact')
|
|
1611
|
+
assert.equal(agent.followed.length, 1, 'and the activation still happens')
|
|
1612
|
+
assert.ok(
|
|
1613
|
+
logs.some(([, message]) => String(message).includes('falling back to the compaction service')),
|
|
1614
|
+
'the fallback is logged, not silent',
|
|
1615
|
+
)
|
|
1616
|
+
})
|
|
1617
|
+
|
|
1618
|
+
test('a refused /compact keeps the note, activates nothing, and warns', async (t) => {
|
|
1619
|
+
const root = scratchRoot(t)
|
|
1620
|
+
const { meter } = movableMeter(600000)
|
|
1621
|
+
const logs = []
|
|
1622
|
+
const commands = {
|
|
1623
|
+
execute: () => Promise.resolve({ commandId: 'cmd-1', result: { kind: 'error', text: 'session is busy' } }),
|
|
1624
|
+
}
|
|
1625
|
+
const agent = handoffAgent(handoffSession('session-refused'))
|
|
1626
|
+
const { ctx, registered } = stubContext({ meter, commands, logs })
|
|
1627
|
+
apply(ctx, { foldMode: 'handoff', handoffDir: root })
|
|
1628
|
+
|
|
1629
|
+
const notePath = handoffPathFor(root, 'session-refused', 1)
|
|
1630
|
+
await requestStep(registered, agent, 2, 1)
|
|
1631
|
+
mkdirSync(join(root, 'session-refused'), { recursive: true })
|
|
1632
|
+
writeFileSync(notePath, `# note\n${'x'.repeat(400)}`, 'utf8')
|
|
1633
|
+
const tool = registered.tools.find((definition) => definition.name === HANDOFF_TOOL_NAME)
|
|
1634
|
+
tool.execute({ path: notePath }, { agent })
|
|
1635
|
+
|
|
1636
|
+
await idleBoundary(registered, agent)
|
|
1637
|
+
|
|
1638
|
+
assert.equal(agent.followed.length, 0, 'a refusal must not activate a turn')
|
|
1639
|
+
const state = JSON.parse(readFileSync(join(root, 'session-refused', HANDOFF_STATE_FILE), 'utf8'))
|
|
1640
|
+
assert.equal(state.foldNo, 0)
|
|
1641
|
+
assert.equal(state.ready.path, notePath, 'the note survives for the next round end')
|
|
1642
|
+
assert.ok(
|
|
1643
|
+
logs.some(([level, message]) => level === 'warn' && String(message).includes('the fold did not commit')),
|
|
1644
|
+
'the consequence is a warn, not an info line among the happy-path noise',
|
|
1645
|
+
)
|
|
1646
|
+
assert.ok(
|
|
1647
|
+
logs.some(([, message, , kind, text]) => String(message).includes('/compact did not fold') && kind === 'error' && text === 'session is busy'),
|
|
1648
|
+
'the refusal kind and text are preserved',
|
|
1649
|
+
)
|
|
1650
|
+
})
|
|
1651
|
+
|
|
1526
1652
|
test('a round that ends past the prep point wakes one reminder turn, bounded by the budget', async (t) => {
|
|
1527
1653
|
const root = scratchRoot(t)
|
|
1528
1654
|
const { box, meter } = movableMeter(600000)
|