dsh-thinking-levels 4.5.0 → 4.7.0
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 +52 -0
- package/README.md +3 -1
- package/dsh.plugin.json +1 -1
- package/lib/auto-schedule-projection.d.ts +164 -6
- package/lib/auto-schedule-projection.js +252 -19
- package/lib/billing-projection.d.ts +7 -7
- package/lib/client.js +1473 -176
- package/lib/client.js.map +1 -1
- package/lib/index.d.ts +12 -0
- package/lib/index.js +34 -0
- package/lib/plugin-records.d.ts +85 -0
- package/lib/plugin-records.js +181 -0
- package/lib/strict-step-schedule.d.ts +2 -0
- package/lib/strict-step-schedule.js +1 -0
- package/lib/thinking-level.d.ts +38 -0
- package/lib/thinking-level.js +58 -16
- package/package.json +155 -155
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.7.0 (2026-11-24)
|
|
4
|
+
|
|
5
|
+
- **新增首次使用引导(3 步)**:设置卡顶部三步——按难度挑档位(简单问答降 low、复杂任务抬 high,默认自动就够用)、允许上浮(别一上来钉死 max,贵且慢)、圆环读数怎么看。底部恒定重开入口;Skip 与「开始使用」都写 `dsh.guide.thinking-levels.skipped`。
|
|
6
|
+
- **引导十语外壳**:七个外壳词自带 zh·en·ja·ko·fr·de·it·ru·es·pt,按 `<html lang>` 取词、认不出落 en;步骤正文 zh/en,其余语种回退 en。
|
|
7
|
+
- **上下文圆环文案全部搬进字典**:`context-ring.tsx` 此前用 `lang ? zh : en` 内联双语(ru/es 见中文),现收进 `ring.*` 组(29 键 ×10 语),并顺带统一该文件行尾为 LF(HEAD 本就是 LF,工作树漂成 CRLF 制造了整文件假 diff)。
|
|
8
|
+
- **附带语言守卫棘轮**:硬编码 CJK 计数只降不升,引导两文件按设计登记白名单。
|
|
9
|
+
- **全量**:365 tests / 365 pass。
|
|
10
|
+
|
|
11
|
+
## Unreleased
|
|
12
|
+
|
|
13
|
+
- **配色加深:方向色改用固定语义色,降档从琥珀改红。** 之前两处都用主题令牌(`--dsw-alias-state-success-primary` / `-warn-*`),问题有两个:一是这些令牌是为大面积背景调的柔和色,落在 18px 圆环和一个字形上就发灰;二是琥珀色配绿箭头读起来像「警告」,而降档其实只是相反方向,不该是警告色。
|
|
14
|
+
- 方向色:升档 `#18a058`、降档 `#d03050`(红)、起始 `#2b6cb0`、持平沿用弱化灰。方向是固定语义,不跟主题走。
|
|
15
|
+
- 归属色:`scheduler` 用最饱和的 `#0e9f6e`(已知写入者里证据最硬的一档,就该最醒目)、`auto` `#18a058`、`manual` `#2b6cb0`、`unknown` `#d48806`(琥珀,需要留意)。
|
|
16
|
+
- 圆环加重:描边 1px→1.5px、字形 11px→12px 且 700 字重——半透明行底上原来箭头几乎看不见,「往哪边动」读不出来。
|
|
17
|
+
|
|
18
|
+
- **插件调度现在能真正打标记了(`scheduler` 归属)。** 上一版把无法归属的档位诚实标成「未记录」,但那是「说不清」,不是「说清了」。这次用宿主正式开放的机制把它坐实:
|
|
19
|
+
- 机制:`@deepseek-ai/dsh-session` 的 `appendPluginRecord(session, type, data)` 可写入 `ignorable` 的 `plugin:` 记录——不进模型可见面、fork/resume 随日志保留、不认识的读者跳过而不是拒读。插件每次自写档位后追加一条 `plugin:dsh-thinking-levels/scheduler-write`,投影见到标记就把**下一条** `request/header` 归因为 `scheduler`。
|
|
20
|
+
- 归属优先级:`scheduler`(有标记,证据)> `manual`(记录值 == 本次档位)> `auto` > `default` > `unknown`(无标记且对不上,退路)。标记只声明「是谁写的」,档位永远取自实际发出的 header——不会伪造。
|
|
21
|
+
- 软耦合:宿主包用**变量化说明符的动态 import** 取用(字面量会让它变成硬编译依赖,而这 API 在旧线上不存在);一切失败——包不可解析、session 不可追加、payload 被拒、logger 抛异常——都解析成 `false`,绝不 reject,因为调用点在一轮对话中间。首次写入探针打一行日志,标明通道 ready / unavailable,避免「静默没标记」和「调度器没写过」无法区分。
|
|
22
|
+
- 视图:新增 `trace.intent.scheduler`(10 语),用成功色而非警示色——它和 `manual` 都是「已知写入者」,「未记录」才是警示。
|
|
23
|
+
- `stateVersion` 5→6(state 新增 `pendingSchedulerWrite`,仅宿主侧,不进 wire)。
|
|
24
|
+
- 测试 +19(标记消费与一次性、跨档位不伪造、foreign record 忽略、wire 不外泄、软耦合四类降级、logger 抛异常不 reject、payload 严格归一化、渲染与汇总)。
|
|
25
|
+
|
|
26
|
+
- **修复归属造假:档位变化不再一律标「手动」,并全程记录 provider/model。** 现场取证(会话 `7f321902`):`model/selection` 事件只有 **1 条**(high),而 `request/header` 有 **30 条**、high/low 交替。旧规则是「会话里记录的档位不是 auto ⇒ 每次请求都算 manual」,于是 29 次插件自己的调度全被标成「手动」——那是个伪命题:0.2.2+ 严格线上本插件自己就是 `model/selection` 的写入者,而 `agent.model.select()` 的写入**不进日志**(宿主只在用户主动选择时 append)。
|
|
27
|
+
- 归属改为四值、且以「相等」而非「存在」为判据(`attributionOf`):记录值 == 本次档位 → `manual`;记录值是 `auto` → `auto`;无任何记录 → `default`;**有记录但对不上 → `unknown`(未记录)**。同一份真实数据:旧规则 30×manual,新规则 15×manual + 15×unknown。
|
|
28
|
+
- 视图面:`unknown` 用中性警示色并带解释性 tooltip(说明严格线写入不进日志),绝不与 `manual` 同色——把它染成决策色就是第二次说谎。汇总条新增「N 未记录」计数。
|
|
29
|
+
- **provider/model 全程记录**:`request/header.config.provider/model` 每个请求都带,此前被丢弃,导致轨迹说不清「这档位发给了哪个模型」。现在折叠进 `lastProvider`/`lastModel`/`modelSwitches`,并给每段 run 打上 `provider`/`model`;同一档位跨模型切换会**拆段**(`foldTrace` 把 route 纳入 run 身份),否则切换会被抹平。视图面每段显示 `provider/model` 徽标,汇总条显示切换次数。
|
|
30
|
+
- `stateVersion` 4→5(state 形状变更)。冷读自动重建,无迁移负担。
|
|
31
|
+
|
|
32
|
+
- **Effort 轨迹页与「权限审批记录」对齐呈现,并补上 turn/step 位置坐标。** 此前只有一列裸文本(`手动 low`),既看不出是第几轮第几步变的,也没有变化方向的视觉提示;同一条标签栏里的两个页签长得像两个产品。
|
|
33
|
+
- 呈现:标题 + 副标题、汇总条(请求数 / 段数 / auto 段数 / 峰值档位)、每段一张卡片——圆环字形(↑升 / ↓降 / =持平 / •起始)走左侧连线轨,档位用等宽字,意图色标(auto 绿、降档琥珀、持平/起始中性),`× N` 次数徽标,右侧对齐的墙钟时间;全部走 `--dsw-alias-*` 设计令牌与 perm-gate 同款圆角/间距/字号。
|
|
34
|
+
- 位置:`tlAutoSchedule` 新增 `turn` / `step` 折叠(`turn/start`、`step/start`),每段首条请求记下 `T{轮}·S{步}` 与 `time`;`stateVersion` 3→4。历史会话冷读自动重建,无迁移负担。
|
|
35
|
+
- 归属诚实化:页脚常驻提示——0.2.2 起宿主禁止在请求阶段改档位,本插件(严格线)自己会写 `model/selection` 提前一步排程,故「手动」只表示日志最后一笔选择是具体档位,未必是人为点击。这条不写清楚,页签会公然说谎(截图里 auto 摆动被标成「手动」)。
|
|
36
|
+
|
|
37
|
+
- **修复:投影缺少 `wire`,浏览器侧永远读不到(Effort 轨迹恒为空态)。** 宿主只在 unit 声明了 `wire` 时才把投影送到客户端——`snapshot()` / `cachedSnapshot()` 均 `continue` 于 `def.wire === undefined`(`packages/session/session-projection/src/index.ts`,「Omit for host-only units」)。`tlAutoSchedule` 自 4.5.0 起一直没有 `wire`,于是它是 host-only:`traceOf`(轨迹页签)和 `lastEffectiveOf`(chip 的 issue #11 修复)在真实宿主上全是死读——投影里明明有数据,界面恒渲染空态。`tlCacheBilling` 从一开始就有 `wire`,所以计费卡看得见。
|
|
38
|
+
- 新增 `wire: { viewSchema, view }`:视图只带客户端要渲染的三项(`userEffort` / `lastEffective` / `trace`),`samples` 留在宿主侧(只供调度器读)。
|
|
39
|
+
- 视图带单槽内容 memo:`tool/call` 只增长 `samples`,客户端相关字段没变时复用同一对象身份,`Object.is` 闸门保持关闭——否则每个工具调用都会唤醒每个订阅端(长会话上千次)。
|
|
40
|
+
- 该次只加 `wire`,`stateVersion` 未动;随后位置坐标(turn/step/time)进来才升到 4。
|
|
41
|
+
- 测试 +4(wire 存在性与 schema 校验、samples-only 变更不换身份、同一状态重复读复用、畸形载荷被拒)。
|
|
42
|
+
|
|
43
|
+
- **修复:投影 face 的读取按 settings 句柄形状解包,读取恒为 `undefined`。** 宿主 `ProjectionValueStore` 的 face 是 `getSnapshot: () => rows.get(key)?.value`,返回的就是**投影状态本身**(`packages/api/session-controller/src/client/sessions/projection-store.ts` 的 `channel()`;宿主内部消费者都是直接强转,如 `faceOf('permissions').getSnapshot() as PermissionSelection`)。`effort-trace.tsx` 与 `index.ts` 却按 `{ status, value }` 的设置句柄形状取 `.value`——那套形状属于 `configForms` / `settingsScope`(`card.tsx` / `model-panel.tsx` 里的 `.value` 是对的)。两套 API 混淆,结果同样是空态。
|
|
44
|
+
- 新增 `src/client/projection-value.ts`:`projectionValueOf()` **正向识别裸状态**(`trace` / `lastEffective` / `userEffort` / `samples` 任一命中即是),包装形状永远不会被误认成状态,反之亦然;同时兼容旧的 `{ value }` 包裹(老宿主 / 测试替身)。
|
|
45
|
+
- 测试替身此前写成与错误实现**同一个**错形状,所以 316 例全绿而读取是死的——这正是本次「假全绿」的成因;替身已改为真实宿主形态,并补两条回归(裸状态必读出、旧包裹仍兼容)。
|
|
46
|
+
|
|
47
|
+
## 4.6.0
|
|
48
|
+
|
|
49
|
+
- **新增 `Config.simpleToolsRegex`:简单工具 regex 名单(issue #12)。** 第三方工具家族(如 dsh-ops 的 `ops_*`)可一条 `^ops_.*` 整族进白名单,不再逐个枚举。每条按原生 JavaScript regex 编译(`i` flag、**不自动加锚点**,建议自写 `^`),与字面量名单并存、进同一 ratio 统计;编译失败的条目跳过并告警一次(配置变更粒度,非每请求)。
|
|
50
|
+
- **双面匹配**:regex 与字面量名单统一测完整工具名与剥 `ops_` 后的裸名两面——regex 路径的硬前提(裸名无 `ops_` 前缀,`ops_.*` 对裸名永不命中),顺带修复字面量条目 `ops_bash` 式写法「因剥前缀而永不命中」的隐性坑(行为修复:此前无效的命名空间字面量现在生效)。
|
|
51
|
+
- **内置表语义不动**:`SIMPLE_TOOL_RE` 仍只测裸名(issue #8 契约);`shell`/`pwsh`/`cmd`/`sh`(terminal 插件)与 `ops_shell` 剥前缀路径逐字不变。
|
|
52
|
+
- **调度双 gate 不动**:simpleRatio 的 `argsSize < HEAVY_ARGS` 二道门与升档面(heaviest args → max)独立驱动——家族级白名单只作用于降档面的 ratio 统计,最坏后果是档位偏好偏一档(会话内自愈),不会把重调用拉进低档、也不会把轻会话推上 max。
|
|
53
|
+
- 实现:`SimpleToolMatcher` 统一分类器替代链路上的裸 `RegExp`;`planStrictStep`/`resolveEffortInjection`/`decideEffort` 加 `extraSimpleRegex` 输入。新增 9 例(家族命中/双面修复/无效跳过+告警/双 gate/终端适配),全量 314/314。
|
|
54
|
+
|
|
3
55
|
## 4.5.0
|
|
4
56
|
|
|
5
57
|
- **新增「Effort 轨迹」标签页(conversation.view)**:会话时间线旁以 run-length 时间线展示本会话每次请求实际发出的档位——`↑ auto max ×1` / `= auto high ×12` / `↓ auto low ×3` 式标签,↑/↓/= 为相对上一 run 的升降(escalation 序,复用 effort slider 的显示序表),最新在前。issue #11 的延伸:chip 只回答「最后一发是什么」,标签页回答「一路是怎么变过来的」。
|
package/README.md
CHANGED
|
@@ -154,13 +154,15 @@ The hub is `high` (the official default). `auto` schedules between `low` / `high
|
|
|
154
154
|
|
|
155
155
|
| Recent tool calls | Level |
|
|
156
156
|
|---|---|
|
|
157
|
-
| none (fresh prompt,
|
|
157
|
+
| none (fresh prompt — the first step decides the plan, no downgrade without evidence) | `high` |
|
|
158
158
|
| ≥75% simple tools, small args, downgrades allowed | `low` |
|
|
159
159
|
| mixed / heavy tools | `high` |
|
|
160
160
|
| very heavy payloads, upgrades allowed | `max` |
|
|
161
161
|
|
|
162
162
|
The scheduling policy is the same source as [dsh-tool-turbo](https://github.com/drscrewdriver/dsh-tool-turbo) (same simple-tool whitelist / payload thresholds / 75% ratio rule).
|
|
163
163
|
|
|
164
|
+
**Whitelisting third-party tool families (4.6.0).** `Config.simpleTools` (literal names) and `Config.simpleToolsRegex` (one JavaScript regex per entry, case-insensitive, no auto-anchoring — write your own `^`) both feed the same simple-ratio. The extra lists match BOTH the full tool name and the namespace-stripped bare name, so one pattern covers a whole family: `^ops_.*` whitelists every `ops_` tool at once, while `grep` keeps matching through the strip. Invalid patterns are skipped with a one-time warning; the built-in table and both scheduler gates (args threshold, args-driven upgrade) are untouched — a family whitelist only biases the downgrade ratio, never lifts a heavy call to `low` or a light session to `max`.
|
|
165
|
+
|
|
164
166
|
**Where the samples come from (4.4.7+).** The scheduler folds `tool/call` events into a Session projection (`tlAutoSchedule`), so it sees real tool history on every host from 0.1.2-rc.1 on; the pre-4.4.7 `session.events` read only ever produced samples on 0.1.0-rc.8. The session's explicit pick is folded from `model/selection` events, so a level the host echoes back can never be mistaken for a manual choice. Known limitation: host `0.1.0-rc.8` exposes no `stateOf` on its projection registry (legacy plane contract), so that one line keeps the old array read — scheduling works there, the echo correction does not.
|
|
165
167
|
|
|
166
168
|
## Effort trace tab
|
package/dsh.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "dsh-external/dsh-thinking-levels",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"description": "thinking-level (reasoning_effort) control — auto-adjust per tool round, with optional manual lock and per-tool timing telemetry.",
|
|
6
6
|
"engines": {
|
|
@@ -47,13 +47,40 @@ export interface EffortRun {
|
|
|
47
47
|
/** The wire level this run's requests went out with. */
|
|
48
48
|
level: string;
|
|
49
49
|
/**
|
|
50
|
-
* Why
|
|
51
|
-
*
|
|
52
|
-
*
|
|
50
|
+
* Why this level was sent. Four-valued on purpose — the old three-valued
|
|
51
|
+
* form LIED:
|
|
52
|
+
*
|
|
53
|
+
* - `'auto'` — the scheduler's `auto` sentinel resolved it.
|
|
54
|
+
* - `'manual'` — a `model/selection` event in the log carries exactly this
|
|
55
|
+
* level at fold time, i.e. someone actually selected it.
|
|
56
|
+
* - `'default'` — the session never picked anything; the configured default
|
|
57
|
+
* applied.
|
|
58
|
+
* - `'scheduler'` — THIS PLUGIN wrote it, proven by a
|
|
59
|
+
* `plugin:dsh-thinking-levels/scheduler-write` mark committed just before
|
|
60
|
+
* the header (see plugin-records.ts). The strongest attribution available.
|
|
61
|
+
* - `'unknown'` — the level changed with NO recorded selection behind it and
|
|
62
|
+
* no scheduler mark. This is the honest fallback for the 0.2.2+ strict
|
|
63
|
+
* line's unmarked writes (measured on a live session: 30 headers,
|
|
64
|
+
* high/low alternating, ONE `model/selection` event). Calling that
|
|
65
|
+
* "manual" was a fabrication.
|
|
53
66
|
*/
|
|
54
|
-
intent: 'auto' | 'manual' |
|
|
67
|
+
intent: 'auto' | 'manual' | 'default' | 'unknown' | 'scheduler';
|
|
55
68
|
/** How many consecutive committed requests the run covers. */
|
|
56
69
|
count: number;
|
|
70
|
+
/**
|
|
71
|
+
* The turn the run's FIRST request belonged to, folded from the preceding
|
|
72
|
+
* `turn/start`. Optional: runs folded before stateVersion 4 (a cached row
|
|
73
|
+
* that predates it) simply lack it and the tab omits the position chip.
|
|
74
|
+
*/
|
|
75
|
+
turn?: number;
|
|
76
|
+
/** The step the run's first request belonged to (folded from `step/start`). */
|
|
77
|
+
step?: number;
|
|
78
|
+
/** Wall-clock ms of the run's first committed request. */
|
|
79
|
+
time?: number;
|
|
80
|
+
/** Provider route of the run's first request, folded from the request header. */
|
|
81
|
+
provider?: string;
|
|
82
|
+
/** Model id of the run's first request, folded from the request header. */
|
|
83
|
+
model?: string;
|
|
57
84
|
}
|
|
58
85
|
/** Runs kept in the trace ring; run-length lets 64 runs cover very long sessions. */
|
|
59
86
|
export declare const TRACE_MAX = 64;
|
|
@@ -87,6 +114,38 @@ export interface AutoScheduleState {
|
|
|
87
114
|
* implicitly end the current run. At most {@link TRACE_MAX} runs.
|
|
88
115
|
*/
|
|
89
116
|
trace: readonly EffortRun[];
|
|
117
|
+
/**
|
|
118
|
+
* The turn in progress at fold time (folded from `turn/start`), so a
|
|
119
|
+
* `request/header` can be stamped with the turn it belongs to. `0` before the
|
|
120
|
+
* session's first turn.
|
|
121
|
+
*/
|
|
122
|
+
turn: number;
|
|
123
|
+
/** The step in progress at fold time (folded from `step/start`). `0` before it. */
|
|
124
|
+
step: number;
|
|
125
|
+
/**
|
|
126
|
+
* The provider route the last committed request went out on, folded from the
|
|
127
|
+
* header's `config.provider`. `null` until the first request.
|
|
128
|
+
*
|
|
129
|
+
* The header carries it on every request, so the model a level was sent to is
|
|
130
|
+
* always recoverable — dropping it (as the first version did) left the trace
|
|
131
|
+
* unable to say WHICH model a switch happened on.
|
|
132
|
+
*/
|
|
133
|
+
lastProvider: string | null;
|
|
134
|
+
/** The model id the last committed request went out on. `null` until the first. */
|
|
135
|
+
lastModel: string | null;
|
|
136
|
+
/**
|
|
137
|
+
* Count of provider/model switches observed in this session's committed
|
|
138
|
+
* requests. `0` means one route throughout.
|
|
139
|
+
*/
|
|
140
|
+
modelSwitches: number;
|
|
141
|
+
/**
|
|
142
|
+
* One-shot flag: a scheduler-write mark was seen and the next committed
|
|
143
|
+
* `request/header` should be attributed to the scheduler. Cleared by that
|
|
144
|
+
* header (or by another `model/selection`, which supersedes the write).
|
|
145
|
+
*
|
|
146
|
+
* Host-side only — the browser never needs it, so it stays out of the wire.
|
|
147
|
+
*/
|
|
148
|
+
pendingSchedulerWrite: boolean;
|
|
90
149
|
}
|
|
91
150
|
/**
|
|
92
151
|
* Append one committed request's effective level to the run-length trace.
|
|
@@ -98,10 +157,20 @@ export interface AutoScheduleState {
|
|
|
98
157
|
* reach this function (see {@link applyAutoSchedule}).
|
|
99
158
|
* @param trace - trace before the header.
|
|
100
159
|
* @param level - the effective wire level the header committed.
|
|
101
|
-
* @param intent - why
|
|
160
|
+
* @param intent - why this level was sent (see {@link EffortRun.intent}).
|
|
161
|
+
* @param at - where the request sat (turn/step), when it went out, and which
|
|
162
|
+
* provider/model route it targeted: stamped onto a run's FIRST request only,
|
|
163
|
+
* because a run means "this level held for these consecutive steps starting
|
|
164
|
+
* here".
|
|
102
165
|
* @returns the advanced trace.
|
|
103
166
|
*/
|
|
104
|
-
export declare function foldTrace(trace: readonly EffortRun[], level: string, intent: EffortRun['intent']
|
|
167
|
+
export declare function foldTrace(trace: readonly EffortRun[], level: string, intent: EffortRun['intent'], at?: {
|
|
168
|
+
turn?: number;
|
|
169
|
+
step?: number;
|
|
170
|
+
time?: number;
|
|
171
|
+
provider?: string;
|
|
172
|
+
model?: string;
|
|
173
|
+
}): readonly EffortRun[];
|
|
105
174
|
/**
|
|
106
175
|
* Fold one committed Session event into the auto-schedule state.
|
|
107
176
|
*
|
|
@@ -114,11 +183,69 @@ export declare function foldTrace(trace: readonly EffortRun[], level: string, in
|
|
|
114
183
|
* @returns the original or advanced state.
|
|
115
184
|
*/
|
|
116
185
|
export declare function applyAutoSchedule(state: AutoScheduleState, event: unknown): AutoScheduleState;
|
|
186
|
+
/**
|
|
187
|
+
* Attribute one committed header's level to whoever actually chose it.
|
|
188
|
+
*
|
|
189
|
+
* The old rule was "the session's recorded pick is a concrete level → the
|
|
190
|
+
* request was manual", which is a non-sequitur: a session can carry ONE
|
|
191
|
+
* recorded pick and then send THIRTY headers at alternating levels (measured
|
|
192
|
+
* live: `7f321902` had `model/selection = [high]` and headers
|
|
193
|
+
* `high,low,high,low,…`). On the 0.2.2+ strict line the plugin itself is a
|
|
194
|
+
* `model/selection` writer through `agent.model.select()`, and those writes do
|
|
195
|
+
* not reach the log — so "manual" was a fabrication for 29 of 30 requests.
|
|
196
|
+
*
|
|
197
|
+
* The honest rule is equality, not existence:
|
|
198
|
+
* - the recorded pick IS this level → `manual` (someone selected exactly this);
|
|
199
|
+
* - the recorded pick is `auto` → `auto` (the scheduler resolved it);
|
|
200
|
+
* - no pick at all → `default` (the configured default applied);
|
|
201
|
+
* - a pick exists but is a DIFFERENT level → `unknown`: the level came from a
|
|
202
|
+
* writer the log does not record. Saying "manual" here would be a lie and
|
|
203
|
+
* saying "auto" would be a guess, so the UI shows a neutral "未记录" tag.
|
|
204
|
+
*
|
|
205
|
+
* @param userEffort - the session's recorded pick at fold time, or null.
|
|
206
|
+
* @param level - the level this header actually carried.
|
|
207
|
+
* @returns the attribution.
|
|
208
|
+
*/
|
|
209
|
+
export declare function attributionOf(userEffort: string | null, level: string): Exclude<EffortRun['intent'], 'scheduler'>;
|
|
210
|
+
/**
|
|
211
|
+
* The state -> client payload. `samples` stays host-side (only the scheduler
|
|
212
|
+
* reads it), so the wire carries exactly what the browser renders.
|
|
213
|
+
*/
|
|
214
|
+
export interface AutoScheduleView {
|
|
215
|
+
/** The session's explicit pick, or null when it never picked. */
|
|
216
|
+
userEffort: string | null;
|
|
217
|
+
/** The level the last committed request actually carried, or null. */
|
|
218
|
+
lastEffective: string | null;
|
|
219
|
+
/** Run-length effort trace, oldest run first. */
|
|
220
|
+
trace: readonly EffortRun[];
|
|
221
|
+
/** Provider route of the last committed request, or null. */
|
|
222
|
+
lastProvider: string | null;
|
|
223
|
+
/** Model id of the last committed request, or null. */
|
|
224
|
+
lastModel: string | null;
|
|
225
|
+
/** How many provider/model switches the session's committed requests show. */
|
|
226
|
+
modelSwitches: number;
|
|
227
|
+
}
|
|
117
228
|
/**
|
|
118
229
|
* Build the `tlAutoSchedule` projection definition. Registered soft-coupled
|
|
119
230
|
* (runtime inject), exactly like `tlCacheBilling`: hosts whose registry cannot
|
|
120
231
|
* serve `stateOf` simply never register it and the scheduler falls back to the
|
|
121
232
|
* legacy array read.
|
|
233
|
+
*
|
|
234
|
+
* ## Why `wire` is not optional here (the empty-tab bug)
|
|
235
|
+
*
|
|
236
|
+
* The registry ships a unit to the browser ONLY when it declares `wire` —
|
|
237
|
+
* `snapshot()` / `cachedSnapshot()` both `continue` on
|
|
238
|
+
* `def.wire === undefined` (`packages/session/session-projection/src/index.ts`,
|
|
239
|
+
* "Omit for host-only units"), and the client's `faceOf(key)` then reads
|
|
240
|
+
* `undefined` forever. Without `wire` this unit was host-only, so the effort
|
|
241
|
+
* tab's `traceOf` and the composer chip's `lastEffective` were dead reads on
|
|
242
|
+
* every real host — a filled projection behind an empty UI. `tlCacheBilling`
|
|
243
|
+
* always had `wire`; this unit did not.
|
|
244
|
+
*
|
|
245
|
+
* The `view` keeps a one-entry content memo so a `tool/call` (which only grows
|
|
246
|
+
* `samples`) republishes nothing: the drive compares raw view results with
|
|
247
|
+
* `Object.is`, so returning the SAME object for unchanged client-relevant
|
|
248
|
+
* state is what suppresses the wake.
|
|
122
249
|
*/
|
|
123
250
|
export declare function buildAutoScheduleDefinition(): {
|
|
124
251
|
key: string;
|
|
@@ -134,10 +261,41 @@ export declare function buildAutoScheduleDefinition(): {
|
|
|
134
261
|
level: z.ZodString;
|
|
135
262
|
intent: z.ZodNullable<z.ZodString>;
|
|
136
263
|
count: z.ZodNumber;
|
|
264
|
+
turn: z.ZodOptional<z.ZodNumber>;
|
|
265
|
+
step: z.ZodOptional<z.ZodNumber>;
|
|
266
|
+
time: z.ZodOptional<z.ZodNumber>;
|
|
267
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
268
|
+
model: z.ZodOptional<z.ZodString>;
|
|
137
269
|
}, z.core.$strip>>;
|
|
270
|
+
turn: z.ZodNumber;
|
|
271
|
+
step: z.ZodNumber;
|
|
272
|
+
lastProvider: z.ZodNullable<z.ZodString>;
|
|
273
|
+
lastModel: z.ZodNullable<z.ZodString>;
|
|
274
|
+
modelSwitches: z.ZodNumber;
|
|
275
|
+
pendingSchedulerWrite: z.ZodBoolean;
|
|
138
276
|
}, z.core.$strip>;
|
|
139
277
|
init: () => AutoScheduleState;
|
|
140
278
|
apply: typeof applyAutoSchedule;
|
|
279
|
+
wire: {
|
|
280
|
+
viewSchema: z.ZodObject<{
|
|
281
|
+
userEffort: z.ZodNullable<z.ZodString>;
|
|
282
|
+
lastEffective: z.ZodNullable<z.ZodString>;
|
|
283
|
+
trace: z.ZodArray<z.ZodObject<{
|
|
284
|
+
level: z.ZodString;
|
|
285
|
+
intent: z.ZodNullable<z.ZodString>;
|
|
286
|
+
count: z.ZodNumber;
|
|
287
|
+
turn: z.ZodOptional<z.ZodNumber>;
|
|
288
|
+
step: z.ZodOptional<z.ZodNumber>;
|
|
289
|
+
time: z.ZodOptional<z.ZodNumber>;
|
|
290
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
291
|
+
model: z.ZodOptional<z.ZodString>;
|
|
292
|
+
}, z.core.$strip>>;
|
|
293
|
+
lastProvider: z.ZodNullable<z.ZodString>;
|
|
294
|
+
lastModel: z.ZodNullable<z.ZodString>;
|
|
295
|
+
modelSwitches: z.ZodNumber;
|
|
296
|
+
}, z.core.$strip>;
|
|
297
|
+
view: (state: AutoScheduleState) => AutoScheduleView;
|
|
298
|
+
};
|
|
141
299
|
};
|
|
142
300
|
/**
|
|
143
301
|
* Read the folded auto-schedule state for a session.
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
*/
|
|
41
41
|
import { z } from 'zod';
|
|
42
42
|
import { TOOL_SAMPLE_WINDOW, toolSampleOf } from "./session-events.js";
|
|
43
|
+
import { schedulerWriteOf } from "./plugin-records.js";
|
|
43
44
|
import { isEffortId } from "./thinking-level.js";
|
|
44
45
|
/** Projection key. `tl` matches the plugin's other unit (`tlCacheBilling`). */
|
|
45
46
|
export const AUTO_SCHEDULE_KEY = 'tlAutoSchedule';
|
|
@@ -49,10 +50,36 @@ const stateSchema = z.object({
|
|
|
49
50
|
samples: z.array(z.object({ name: z.string(), argsSize: z.number() })),
|
|
50
51
|
userEffort: z.string().nullable(),
|
|
51
52
|
lastEffective: z.string().nullable(),
|
|
52
|
-
trace: z.array(z.object({
|
|
53
|
+
trace: z.array(z.object({
|
|
54
|
+
level: z.string(),
|
|
55
|
+
intent: z.string().nullable(),
|
|
56
|
+
count: z.number(),
|
|
57
|
+
turn: z.number().optional(),
|
|
58
|
+
step: z.number().optional(),
|
|
59
|
+
time: z.number().optional(),
|
|
60
|
+
provider: z.string().optional(),
|
|
61
|
+
model: z.string().optional(),
|
|
62
|
+
})),
|
|
63
|
+
turn: z.number(),
|
|
64
|
+
step: z.number(),
|
|
65
|
+
lastProvider: z.string().nullable(),
|
|
66
|
+
lastModel: z.string().nullable(),
|
|
67
|
+
modelSwitches: z.number(),
|
|
68
|
+
pendingSchedulerWrite: z.boolean(),
|
|
53
69
|
});
|
|
54
70
|
/** Initial folded state (also the shape every cold read starts from). */
|
|
55
|
-
const initAutoSchedule = () => ({
|
|
71
|
+
const initAutoSchedule = () => ({
|
|
72
|
+
samples: [],
|
|
73
|
+
userEffort: null,
|
|
74
|
+
lastEffective: null,
|
|
75
|
+
trace: [],
|
|
76
|
+
turn: 0,
|
|
77
|
+
step: 0,
|
|
78
|
+
lastProvider: null,
|
|
79
|
+
lastModel: null,
|
|
80
|
+
modelSwitches: 0,
|
|
81
|
+
pendingSchedulerWrite: false,
|
|
82
|
+
});
|
|
56
83
|
/**
|
|
57
84
|
* Append one committed request's effective level to the run-length trace.
|
|
58
85
|
*
|
|
@@ -63,15 +90,37 @@ const initAutoSchedule = () => ({ samples: [], userEffort: null, lastEffective:
|
|
|
63
90
|
* reach this function (see {@link applyAutoSchedule}).
|
|
64
91
|
* @param trace - trace before the header.
|
|
65
92
|
* @param level - the effective wire level the header committed.
|
|
66
|
-
* @param intent - why
|
|
93
|
+
* @param intent - why this level was sent (see {@link EffortRun.intent}).
|
|
94
|
+
* @param at - where the request sat (turn/step), when it went out, and which
|
|
95
|
+
* provider/model route it targeted: stamped onto a run's FIRST request only,
|
|
96
|
+
* because a run means "this level held for these consecutive steps starting
|
|
97
|
+
* here".
|
|
67
98
|
* @returns the advanced trace.
|
|
68
99
|
*/
|
|
69
|
-
export function foldTrace(trace, level, intent) {
|
|
100
|
+
export function foldTrace(trace, level, intent, at = {}) {
|
|
70
101
|
const last = trace[trace.length - 1];
|
|
71
|
-
|
|
72
|
-
|
|
102
|
+
// A run means "this level held on this ROUTE for these consecutive steps".
|
|
103
|
+
// The route is part of the identity: folding `trae/high` and `deepseek/high`
|
|
104
|
+
// into one run would erase the model switch the tab exists to show.
|
|
105
|
+
if (last !== undefined
|
|
106
|
+
&& last.level === level
|
|
107
|
+
&& last.intent === intent
|
|
108
|
+
&& last.provider === at.provider
|
|
109
|
+
&& last.model === at.model) {
|
|
110
|
+
return [...trace.slice(0, -1), { ...last, count: last.count + 1 }];
|
|
73
111
|
}
|
|
74
|
-
const
|
|
112
|
+
const run = { level, intent, count: 1 };
|
|
113
|
+
if (at.turn !== undefined)
|
|
114
|
+
run.turn = at.turn;
|
|
115
|
+
if (at.step !== undefined)
|
|
116
|
+
run.step = at.step;
|
|
117
|
+
if (at.time !== undefined)
|
|
118
|
+
run.time = at.time;
|
|
119
|
+
if (at.provider !== undefined)
|
|
120
|
+
run.provider = at.provider;
|
|
121
|
+
if (at.model !== undefined)
|
|
122
|
+
run.model = at.model;
|
|
123
|
+
const pushed = [...trace, run];
|
|
75
124
|
return pushed.length > TRACE_MAX ? pushed.slice(pushed.length - TRACE_MAX) : pushed;
|
|
76
125
|
}
|
|
77
126
|
/**
|
|
@@ -89,6 +138,13 @@ export function applyAutoSchedule(state, event) {
|
|
|
89
138
|
if (typeof event !== 'object' || event === null)
|
|
90
139
|
return state;
|
|
91
140
|
const type = event.type;
|
|
141
|
+
// Scheduler-write mark (`plugin:dsh-thinking-levels/scheduler-write`): this
|
|
142
|
+
// plugin wrote a `model/selection` that the host never logged. Arming a
|
|
143
|
+
// one-shot flag lets the NEXT committed header be attributed to the
|
|
144
|
+
// scheduler instead of falling into the `unknown` bucket.
|
|
145
|
+
if (schedulerWriteOf(event) !== undefined) {
|
|
146
|
+
return state.pendingSchedulerWrite ? state : { ...state, pendingSchedulerWrite: true };
|
|
147
|
+
}
|
|
92
148
|
if (type === 'tool/call') {
|
|
93
149
|
const sample = toolSampleOf(event);
|
|
94
150
|
if (sample === undefined)
|
|
@@ -107,6 +163,22 @@ export function applyAutoSchedule(state, event) {
|
|
|
107
163
|
const userEffort = typeof raw === 'string' && raw.length > 0 ? raw : null;
|
|
108
164
|
return userEffort === state.userEffort ? state : { ...state, userEffort };
|
|
109
165
|
}
|
|
166
|
+
if (type === 'turn/start') {
|
|
167
|
+
// Position bookkeeping only: the tab stamps each run with the turn/step it
|
|
168
|
+
// started in, so "when did auto drop to low" is answerable in the UI.
|
|
169
|
+
const data = event.data;
|
|
170
|
+
const raw = typeof data === 'object' && data !== null ? data.turn : undefined;
|
|
171
|
+
if (typeof raw !== 'number')
|
|
172
|
+
return state;
|
|
173
|
+
return raw === state.turn && state.step === 0 ? state : { ...state, turn: raw, step: 0 };
|
|
174
|
+
}
|
|
175
|
+
if (type === 'step/start') {
|
|
176
|
+
const data = event.data;
|
|
177
|
+
const step = typeof data === 'object' && data !== null ? data.step : undefined;
|
|
178
|
+
if (typeof step !== 'number')
|
|
179
|
+
return state;
|
|
180
|
+
return step === state.step ? state : { ...state, step };
|
|
181
|
+
}
|
|
110
182
|
if (type === 'request/header') {
|
|
111
183
|
// Issue #11: the header carries the effort this request actually went out
|
|
112
184
|
// with — the host resolves and commits the effective value here, so it is
|
|
@@ -118,6 +190,20 @@ export function applyAutoSchedule(state, event) {
|
|
|
118
190
|
const config = typeof header === 'object' && header !== null
|
|
119
191
|
? header.config
|
|
120
192
|
: undefined;
|
|
193
|
+
const route = typeof config === 'object' && config !== null
|
|
194
|
+
? config
|
|
195
|
+
: undefined;
|
|
196
|
+
const provider = typeof route?.provider === 'string' && route.provider.length > 0
|
|
197
|
+
? route.provider
|
|
198
|
+
: undefined;
|
|
199
|
+
const model = typeof route?.model === 'string' && route.model.length > 0
|
|
200
|
+
? route.model
|
|
201
|
+
: undefined;
|
|
202
|
+
// A model switch is a route change between two consecutive committed
|
|
203
|
+
// requests. Recorded on EVERY header (both ids), so the trace can name the
|
|
204
|
+
// model each level was sent to instead of guessing.
|
|
205
|
+
const switched = state.lastProvider !== null
|
|
206
|
+
&& (state.lastProvider !== provider || state.lastModel !== model);
|
|
121
207
|
const raw = typeof config === 'object' && config !== null
|
|
122
208
|
? config.reasoningEffort
|
|
123
209
|
: undefined;
|
|
@@ -125,37 +211,184 @@ export function applyAutoSchedule(state, event) {
|
|
|
125
211
|
// A header without an effort (non-reasoning model, stripped) records
|
|
126
212
|
// nothing in the trace and keeps the old same-reference semantics when
|
|
127
213
|
// lastEffective is already null.
|
|
128
|
-
|
|
214
|
+
const unchanged = state.lastEffective === null
|
|
215
|
+
&& !switched
|
|
216
|
+
&& state.lastProvider === (provider ?? null)
|
|
217
|
+
&& state.lastModel === (model ?? null);
|
|
218
|
+
if (unchanged)
|
|
219
|
+
return state;
|
|
220
|
+
return {
|
|
221
|
+
...state,
|
|
222
|
+
lastEffective: null,
|
|
223
|
+
lastProvider: provider ?? null,
|
|
224
|
+
lastModel: model ?? null,
|
|
225
|
+
modelSwitches: switched ? state.modelSwitches + 1 : state.modelSwitches,
|
|
226
|
+
// The marked write never produced a level (non-reasoning model): the
|
|
227
|
+
// mark is spent, nothing to attribute.
|
|
228
|
+
pendingSchedulerWrite: false,
|
|
229
|
+
};
|
|
129
230
|
}
|
|
130
|
-
//
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
const intent = state.
|
|
134
|
-
? '
|
|
135
|
-
: state.userEffort
|
|
136
|
-
|
|
231
|
+
// A pending scheduler-write mark claims THIS header: the plugin wrote the
|
|
232
|
+
// level the host then sent. That is evidence, not a guess — it beats the
|
|
233
|
+
// `unknown` fallback, which exists only for writes we cannot account for.
|
|
234
|
+
const intent = state.pendingSchedulerWrite
|
|
235
|
+
? 'scheduler'
|
|
236
|
+
: attributionOf(state.userEffort, raw);
|
|
237
|
+
const time = event.time;
|
|
238
|
+
return {
|
|
239
|
+
...state,
|
|
240
|
+
lastEffective: raw,
|
|
241
|
+
lastProvider: provider ?? null,
|
|
242
|
+
lastModel: model ?? null,
|
|
243
|
+
modelSwitches: switched ? state.modelSwitches + 1 : state.modelSwitches,
|
|
244
|
+
pendingSchedulerWrite: false,
|
|
245
|
+
trace: foldTrace(state.trace, raw, intent, {
|
|
246
|
+
// A header that arrives before any `turn/start` (a synthetic or
|
|
247
|
+
// inherited cut) carries no position rather than a bogus T0·S0.
|
|
248
|
+
...(state.turn > 0 ? { turn: state.turn, step: state.step } : {}),
|
|
249
|
+
...(typeof time === 'number' ? { time } : {}),
|
|
250
|
+
...(provider !== undefined ? { provider } : {}),
|
|
251
|
+
...(model !== undefined ? { model } : {}),
|
|
252
|
+
}),
|
|
253
|
+
};
|
|
137
254
|
}
|
|
138
255
|
return state;
|
|
139
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Attribute one committed header's level to whoever actually chose it.
|
|
259
|
+
*
|
|
260
|
+
* The old rule was "the session's recorded pick is a concrete level → the
|
|
261
|
+
* request was manual", which is a non-sequitur: a session can carry ONE
|
|
262
|
+
* recorded pick and then send THIRTY headers at alternating levels (measured
|
|
263
|
+
* live: `7f321902` had `model/selection = [high]` and headers
|
|
264
|
+
* `high,low,high,low,…`). On the 0.2.2+ strict line the plugin itself is a
|
|
265
|
+
* `model/selection` writer through `agent.model.select()`, and those writes do
|
|
266
|
+
* not reach the log — so "manual" was a fabrication for 29 of 30 requests.
|
|
267
|
+
*
|
|
268
|
+
* The honest rule is equality, not existence:
|
|
269
|
+
* - the recorded pick IS this level → `manual` (someone selected exactly this);
|
|
270
|
+
* - the recorded pick is `auto` → `auto` (the scheduler resolved it);
|
|
271
|
+
* - no pick at all → `default` (the configured default applied);
|
|
272
|
+
* - a pick exists but is a DIFFERENT level → `unknown`: the level came from a
|
|
273
|
+
* writer the log does not record. Saying "manual" here would be a lie and
|
|
274
|
+
* saying "auto" would be a guess, so the UI shows a neutral "未记录" tag.
|
|
275
|
+
*
|
|
276
|
+
* @param userEffort - the session's recorded pick at fold time, or null.
|
|
277
|
+
* @param level - the level this header actually carried.
|
|
278
|
+
* @returns the attribution.
|
|
279
|
+
*/
|
|
280
|
+
export function attributionOf(userEffort, level) {
|
|
281
|
+
if (userEffort === null)
|
|
282
|
+
return 'default';
|
|
283
|
+
if (userEffort === 'auto')
|
|
284
|
+
return 'auto';
|
|
285
|
+
return userEffort === level ? 'manual' : 'unknown';
|
|
286
|
+
}
|
|
287
|
+
const viewSchema = z.object({
|
|
288
|
+
userEffort: z.string().nullable(),
|
|
289
|
+
lastEffective: z.string().nullable(),
|
|
290
|
+
trace: z.array(z.object({
|
|
291
|
+
level: z.string(),
|
|
292
|
+
intent: z.string().nullable(),
|
|
293
|
+
count: z.number(),
|
|
294
|
+
turn: z.number().optional(),
|
|
295
|
+
step: z.number().optional(),
|
|
296
|
+
time: z.number().optional(),
|
|
297
|
+
provider: z.string().optional(),
|
|
298
|
+
model: z.string().optional(),
|
|
299
|
+
})),
|
|
300
|
+
lastProvider: z.string().nullable(),
|
|
301
|
+
lastModel: z.string().nullable(),
|
|
302
|
+
modelSwitches: z.number(),
|
|
303
|
+
});
|
|
304
|
+
/** Content comparison for the wire identity gate (see {@link buildAutoScheduleDefinition}). */
|
|
305
|
+
function sameView(a, b) {
|
|
306
|
+
if (a.userEffort !== b.userEffort || a.lastEffective !== b.lastEffective)
|
|
307
|
+
return false;
|
|
308
|
+
if (a.lastProvider !== b.lastProvider || a.lastModel !== b.lastModel)
|
|
309
|
+
return false;
|
|
310
|
+
if (a.modelSwitches !== b.modelSwitches)
|
|
311
|
+
return false;
|
|
312
|
+
if (a.trace === b.trace)
|
|
313
|
+
return true;
|
|
314
|
+
if (a.trace.length !== b.trace.length)
|
|
315
|
+
return false;
|
|
316
|
+
for (let i = 0; i < a.trace.length; i += 1) {
|
|
317
|
+
const x = a.trace[i];
|
|
318
|
+
const y = b.trace[i];
|
|
319
|
+
if (x.level !== y.level || x.intent !== y.intent || x.count !== y.count)
|
|
320
|
+
return false;
|
|
321
|
+
// Position/time/route ride the run's first request, so they only ever
|
|
322
|
+
// change with a new run — compare them so a re-fold after a cold read stays
|
|
323
|
+
// identical.
|
|
324
|
+
if (x.turn !== y.turn || x.step !== y.step || x.time !== y.time)
|
|
325
|
+
return false;
|
|
326
|
+
if (x.provider !== y.provider || x.model !== y.model)
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
return true;
|
|
330
|
+
}
|
|
140
331
|
/**
|
|
141
332
|
* Build the `tlAutoSchedule` projection definition. Registered soft-coupled
|
|
142
333
|
* (runtime inject), exactly like `tlCacheBilling`: hosts whose registry cannot
|
|
143
334
|
* serve `stateOf` simply never register it and the scheduler falls back to the
|
|
144
335
|
* legacy array read.
|
|
336
|
+
*
|
|
337
|
+
* ## Why `wire` is not optional here (the empty-tab bug)
|
|
338
|
+
*
|
|
339
|
+
* The registry ships a unit to the browser ONLY when it declares `wire` —
|
|
340
|
+
* `snapshot()` / `cachedSnapshot()` both `continue` on
|
|
341
|
+
* `def.wire === undefined` (`packages/session/session-projection/src/index.ts`,
|
|
342
|
+
* "Omit for host-only units"), and the client's `faceOf(key)` then reads
|
|
343
|
+
* `undefined` forever. Without `wire` this unit was host-only, so the effort
|
|
344
|
+
* tab's `traceOf` and the composer chip's `lastEffective` were dead reads on
|
|
345
|
+
* every real host — a filled projection behind an empty UI. `tlCacheBilling`
|
|
346
|
+
* always had `wire`; this unit did not.
|
|
347
|
+
*
|
|
348
|
+
* The `view` keeps a one-entry content memo so a `tool/call` (which only grows
|
|
349
|
+
* `samples`) republishes nothing: the drive compares raw view results with
|
|
350
|
+
* `Object.is`, so returning the SAME object for unchanged client-relevant
|
|
351
|
+
* state is what suppresses the wake.
|
|
145
352
|
*/
|
|
146
353
|
export function buildAutoScheduleDefinition() {
|
|
354
|
+
let lastState;
|
|
355
|
+
let lastView;
|
|
356
|
+
const view = (state) => {
|
|
357
|
+
if (lastView !== undefined && state === lastState)
|
|
358
|
+
return lastView;
|
|
359
|
+
const next = {
|
|
360
|
+
userEffort: state.userEffort,
|
|
361
|
+
lastEffective: state.lastEffective,
|
|
362
|
+
trace: state.trace,
|
|
363
|
+
lastProvider: state.lastProvider,
|
|
364
|
+
lastModel: state.lastModel,
|
|
365
|
+
modelSwitches: state.modelSwitches,
|
|
366
|
+
};
|
|
367
|
+
if (lastView !== undefined && sameView(lastView, next)) {
|
|
368
|
+
// Client-irrelevant change (e.g. the samples ring): reuse the identity so
|
|
369
|
+
// the Object.is gate stays closed.
|
|
370
|
+
lastState = state;
|
|
371
|
+
return lastView;
|
|
372
|
+
}
|
|
373
|
+
lastState = state;
|
|
374
|
+
lastView = next;
|
|
375
|
+
return next;
|
|
376
|
+
};
|
|
147
377
|
return {
|
|
148
378
|
key: AUTO_SCHEDULE_KEY,
|
|
149
379
|
// Bumped 1 → 2 when `lastEffective` joined the state (issue #11), 2 → 3
|
|
150
|
-
// when the run-length `trace` joined (conversation-view tab)
|
|
380
|
+
// when the run-length `trace` joined (conversation-view tab), 3 → 4 when
|
|
381
|
+
// the trace gained turn/step/time position stamps, 4 → 5 when runs gained
|
|
382
|
+
// provider/model plus the four-valued intent, 5 → 6 when the state gained
|
|
383
|
+
// the scheduler-write flag (and runs the `scheduler` attribution): the host
|
|
151
384
|
// validates against `stateSchema` per version, so a shape change must raise
|
|
152
385
|
// it. Historical sessions are not lost — the state is a fold over the log,
|
|
153
|
-
// so a cold read rebuilds
|
|
154
|
-
|
|
155
|
-
stateVersion: 3,
|
|
386
|
+
// so a cold read rebuilds everything from the events.
|
|
387
|
+
stateVersion: 6,
|
|
156
388
|
stateSchema,
|
|
157
389
|
init: initAutoSchedule,
|
|
158
390
|
apply: applyAutoSchedule,
|
|
391
|
+
wire: { viewSchema, view },
|
|
159
392
|
};
|
|
160
393
|
}
|
|
161
394
|
/**
|