@aiwayds/dsh-opentui 0.26.4 → 0.27.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.
@@ -49,6 +49,9 @@
49
49
  "command.permission.noCommand": "the host offers no /permission command",
50
50
  "command.permission.failed": "/permission failed: {reason}",
51
51
  "command.permission.set": "permission preset set to {name}",
52
+ "command.permission.pickerTitle": "Select permission preset",
53
+ "command.permission.defaultMarkerHint": "● marks the default preset; the active preset is host-side",
54
+ "command.permission.noSession": "no session bound yet — send a message first, then switch permission",
52
55
  "command.cwd.description": "show the current session working directory (basename)",
53
56
  "command.cwd.unavailable": "/cwd unavailable in this session",
54
57
  "command.cwd.none": "/cwd: no working directory for the current session",
@@ -197,7 +200,7 @@
197
200
  "settings.zone.title.host": "Host settings",
198
201
  "settings.zone.title.other": "Other namespaces",
199
202
  "settings.zone.subtitle.local": "(config.json → live)",
200
- "settings.zone.subtitle.host": "(settings.mutate → cordis.patch.yml → host live)",
203
+ "settings.zone.subtitle.host": "(settings.mutate → cordis.patch.yml → host config; defaultPreset applies to new sessions only)",
201
204
  "settings.zone.subtitle.other": "(read-only · not consumed by this TUI)",
202
205
  "settings.zone.readonlyNote": "read-only · not consumed by this TUI",
203
206
  "settings.source.mergedTheme": "merged value · theme (writes config.json)",
@@ -207,15 +210,20 @@
207
210
  "settings.note.valueNotInCatalog": "current value \"{value}\" is not among the catalog default options",
208
211
  "settings.note.catalogNoOptions": "catalog declares no options — read-only, shows the effective value",
209
212
  "settings.note.noCatalog": "no preset catalog (permissionPresets/catalog unavailable) — read-only, shows the effective value",
213
+ "settings.note.permissionPresetScope": "new sessions only; switch this session with /permission <preset>",
214
+ "settings.note.maxDepthPinned": "read-only · pinned by the profile to 1 (safety constraint)",
215
+ "settings.note.hostLocalFile": "n/a — host did not serve this setting: {reason}",
210
216
  "settings.writable.noFace": "host settings face unavailable — only local preferences are writable",
211
217
  "settings.writable.describeFailed": "settings/describe failed: {detail} — host settings not writable, local preferences still writable",
212
218
  "settings.writable.readOnlyDoc": "the profile's settings document is read-only (writable: false) — all write controls disabled",
219
+ "settings.writable.localFileDegraded": "host unavailable ({reason}); host rows are read-only, local preferences still writable",
213
220
  "settings.error.notLocal": "not a local preference",
214
221
  "settings.error.notHost": "not a host setting",
215
222
  "settings.error.unknownHintSegment": "unknown hint segment \"{segment}\"",
216
223
  "settings.error.emptyValue": "value must not be empty",
217
224
  "settings.error.invalidGear": "invalid activity panel gear \"{value}\" (default, 1, 5, 7, 10, all)",
218
225
  "settings.error.expectedInteger": "expected an integer, got \"{value}\"",
226
+ "settings.error.hostEmptyNumber": "cannot clear a host number: an empty value falls back to the inherited value and would silently widen the limit — enter a number",
219
227
  "settings.error.integerOutOfRange": "integer out of range: {value}",
220
228
  "settings.error.min": "must be >= {min}",
221
229
  "settings.error.max": "must be <= {max}",
@@ -291,6 +299,8 @@
291
299
  "settings.jump.presetsNote": "agent preset rotation and selection live in /preset",
292
300
  "settings.jump.accountNote": "login / logout live in the /login flow",
293
301
  "settings.status.saved": "saved · {label}",
302
+ "settings.status.savedLive": "applied live · {label}",
303
+ "settings.status.savedLocalFile": "written to the local file · {label} (restart the host for it to take effect)",
294
304
  "settings.status.rowReadOnly": "this row is read-only",
295
305
  "settings.status.refreshFailed": "⚠ written, but the settings refresh failed (still showing the old document)",
296
306
  "settings.status.instantSave": "changes are saved instantly",
@@ -312,6 +322,7 @@
312
322
  "panel.agents.value.inherit": "(inherit)",
313
323
  "panel.agents.value.inheritDefault": "(inherit — default model)",
314
324
  "panel.agents.value.na": "n/a",
325
+ "panel.agents.capsUnavailable": "host did not serve caps: {reason}",
315
326
  "panel.agents.value.on": "on",
316
327
  "panel.agents.value.off": "off",
317
328
  "panel.agents.column.name": "NAME",
@@ -352,6 +363,7 @@
352
363
  "panel.agents.title.viewerAgent": "{name} · system prompt",
353
364
  "panel.agents.limits.target": "target: {name}",
354
365
  "panel.agents.status.error": "✘ {error}",
366
+ "panel.agents.status.capsUnavailable": "host did not serve the settings; open /settings for details (no local values are shown)",
355
367
  "panel.agents.status.backgroundOn": "background on — this agent runs in background sessions",
356
368
  "panel.agents.status.backgroundOff": "background off — foreground dispatch",
357
369
  "panel.agents.status.maxRoundsSaved": "maxRounds → {value} saved — applies to future subagent spawns",
@@ -651,6 +663,8 @@
651
663
  "overlay.ask.invalidatedAck": "OK",
652
664
  "overlay.ask.allowAlways": "always",
653
665
  "overlay.ask.allowSession": "session",
666
+ "overlay.ask.alwaysHint": "[a] this tool: no more asks this session",
667
+ "overlay.ask.sessionHint": "[s] all write tools: no more asks this session",
654
668
  "overlay.ask.reviewRow": "⏎ Review answers",
655
669
  "overlay.ask.reviewTitle": "Review answers",
656
670
  "overlay.ask.submitRow": "⏎ Submit answers",
@@ -686,6 +700,9 @@
686
700
  "overlay.widgets.activityTitle": "┃ activity",
687
701
  "overlay.widgets.activityWithThink": "┃ activity · {text}",
688
702
  "overlay.widgets.frameTitle": "activity",
703
+ "overlay.widgets.subagentBrief": "subagent *{running} {elapsedSec}s",
704
+ "overlay.widgets.tab.main": "1 main",
705
+ "overlay.widgets.tab.todo": "2 todo",
689
706
  "overlay.widgets.taskColumn": "Task",
690
707
  "overlay.widgets.thinkCollapsed": "💭 thought · {secs} · {line}",
691
708
  "overlay.widgets.thinkStreaming": "💭 thinking · {secs} · {line}",
@@ -49,6 +49,9 @@
49
49
  "command.permission.noCommand": "宿主未提供 /permission 命令",
50
50
  "command.permission.failed": "/permission 失败:{reason}",
51
51
  "command.permission.set": "权限预设已设为 {name}",
52
+ "command.permission.pickerTitle": "选择权限预设",
53
+ "command.permission.defaultMarkerHint": "● 为默认档;当前档以宿主为准",
54
+ "command.permission.noSession": "尚未绑定会话:先发一条消息再切换权限",
52
55
  "command.cwd.description": "显示当前会话的工作目录(目录名)",
53
56
  "command.cwd.unavailable": "本会话中 /cwd 不可用",
54
57
  "command.cwd.none": "/cwd:当前会话没有工作目录",
@@ -197,7 +200,7 @@
197
200
  "settings.zone.title.host": "Host 设置",
198
201
  "settings.zone.title.other": "其他命名空间",
199
202
  "settings.zone.subtitle.local": "(config.json → 实时生效)",
200
- "settings.zone.subtitle.host": "(settings.mutate → cordis.patch.yml → host 实时生效)",
203
+ "settings.zone.subtitle.host": "(settings.mutate → cordis.patch.yml → 写入 host 配置;defaultPreset 仅对新会话生效)",
201
204
  "settings.zone.subtitle.other": "(只读 · 本 TUI 不消费)",
202
205
  "settings.zone.readonlyNote": "只读 · 本 TUI 不消费",
203
206
  "settings.source.mergedTheme": "合并值 · theme(写入 config.json)",
@@ -207,15 +210,20 @@
207
210
  "settings.note.valueNotInCatalog": "当前值 \"{value}\" 不在目录默认选项中",
208
211
  "settings.note.catalogNoOptions": "目录未声明选项 — 只读,显示生效值",
209
212
  "settings.note.noCatalog": "没有 preset 目录(permissionPresets/catalog 不可用)— 只读,显示生效值",
213
+ "settings.note.permissionPresetScope": "仅影响新会话;当前会话用 /permission <档位> 立即切换",
214
+ "settings.note.maxDepthPinned": "只读 · 由 profile 钉死为 1(安全约束)",
215
+ "settings.note.hostLocalFile": "无 — 宿主未提供该设置:{reason}",
210
216
  "settings.writable.noFace": "host 设置面不可用 — 仅本地偏好可写",
211
217
  "settings.writable.describeFailed": "settings/describe 失败:{detail} — host 设置不可写,本地偏好仍可写",
212
218
  "settings.writable.readOnlyDoc": "该 profile 的设置文档为只读(writable: false)— 所有写入控件已禁用",
219
+ "settings.writable.localFileDegraded": "宿主不可用({reason});宿主行只读,本地偏好仍可写",
213
220
  "settings.error.notLocal": "不是本地偏好",
214
221
  "settings.error.notHost": "不是 host 设置",
215
222
  "settings.error.unknownHintSegment": "未知提示段 \"{segment}\"",
216
223
  "settings.error.emptyValue": "值不能为空",
217
224
  "settings.error.invalidGear": "无效的 activity 面板档位 \"{value}\"(default、1、5、7、10、all)",
218
225
  "settings.error.expectedInteger": "应为整数,收到 \"{value}\"",
226
+ "settings.error.hostEmptyNumber": "不能清空宿主数字项:空值会回落到继承值、静默放宽上限 — 请输入数字",
219
227
  "settings.error.integerOutOfRange": "整数超出范围:{value}",
220
228
  "settings.error.min": "必须 >= {min}",
221
229
  "settings.error.max": "必须 <= {max}",
@@ -291,6 +299,8 @@
291
299
  "settings.jump.presetsNote": "agent preset 轮换与选择在 /preset",
292
300
  "settings.jump.accountNote": "登录 / 登出走 /login 流程",
293
301
  "settings.status.saved": "已保存 · {label}",
302
+ "settings.status.savedLive": "已即时生效 · {label}",
303
+ "settings.status.savedLocalFile": "已写入本地文件 · {label}(需重启宿主生效)",
294
304
  "settings.status.rowReadOnly": "此行只读",
295
305
  "settings.status.refreshFailed": "⚠ 已写入,但设置刷新失败(仍显示旧文档)",
296
306
  "settings.status.instantSave": "变更即时保存",
@@ -312,6 +322,7 @@
312
322
  "panel.agents.value.inherit": "(继承)",
313
323
  "panel.agents.value.inheritDefault": "(继承 — 默认模型)",
314
324
  "panel.agents.value.na": "无",
325
+ "panel.agents.capsUnavailable": "宿主未提供上限:{reason}",
315
326
  "panel.agents.value.on": "开",
316
327
  "panel.agents.value.off": "关",
317
328
  "panel.agents.column.name": "名称",
@@ -352,6 +363,7 @@
352
363
  "panel.agents.title.viewerAgent": "{name} · system prompt",
353
364
  "panel.agents.limits.target": "目标:{name}",
354
365
  "panel.agents.status.error": "✘ {error}",
366
+ "panel.agents.status.capsUnavailable": "宿主未提供设置;详见 /settings(不显示本地文件数字)",
355
367
  "panel.agents.status.backgroundOn": "后台已开 — 此 agent 在后台会话中运行",
356
368
  "panel.agents.status.backgroundOff": "后台已关 — 前台派发",
357
369
  "panel.agents.status.maxRoundsSaved": "maxRounds → {value} 已保存 — 适用于后续 subagent 派生",
@@ -649,8 +661,10 @@
649
661
  "overlay.ask.invalidated": "此请求已失效:{reason}",
650
662
  "overlay.ask.invalidated.disconnected": "连接已断开,bridge 进程已终止",
651
663
  "overlay.ask.invalidatedAck": "知道了",
652
- "overlay.ask.allowAlways": "始终允许",
653
- "overlay.ask.allowSession": "本会话允许",
664
+ "overlay.ask.allowAlways": "always",
665
+ "overlay.ask.allowSession": "session",
666
+ "overlay.ask.alwaysHint": "[a] 此工具本会话不再问",
667
+ "overlay.ask.sessionHint": "[s] 本会话放行全部写操作",
654
668
  "overlay.ask.reviewRow": "⏎ 查看答案",
655
669
  "overlay.ask.reviewTitle": "确认答案",
656
670
  "overlay.ask.submitRow": "⏎ 提交答案",
@@ -686,6 +700,9 @@
686
700
  "overlay.widgets.activityTitle": "┃ 活动",
687
701
  "overlay.widgets.activityWithThink": "┃ 活动 · {text}",
688
702
  "overlay.widgets.frameTitle": "活动",
703
+ "overlay.widgets.subagentBrief": "subagent *{running} {elapsedSec}s",
704
+ "overlay.widgets.tab.main": "1 main",
705
+ "overlay.widgets.tab.todo": "2 todo",
689
706
  "overlay.widgets.taskColumn": "任务",
690
707
  "overlay.widgets.thinkCollapsed": "💭 thought · {secs} · {line}",
691
708
  "overlay.widgets.thinkStreaming": "💭 thinking · {secs} · {line}",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiwayds/dsh-opentui",
3
- "version": "0.26.4",
3
+ "version": "0.27.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,172 @@
1
+ /**
2
+ * B1 S3 — provisioner runtime-field merge (design 05 §4.3(a)).
3
+ *
4
+ * The host config service writes volatile scalars into the inproc profile patch
5
+ * at runtime. provisionPatch() rewrites that file from its embedded template on
6
+ * every launch; without a field-level merge the runtime value is lost on the
7
+ * next restart. This module performs a LINE-BASED merge of an allow-listed set
8
+ * of volatile scalars into a fresh template copy.
9
+ *
10
+ * Deliberately NOT a YAML parse/serialize round-trip: the template carries
11
+ * `!!js` tags (DSH_OPENTUI_APPROVAL_GATE escape hatch) that a plain loader
12
+ * cannot reproduce, and a full rewrite would reorder/requote unrelated lines.
13
+ * Only the exact matched line is replaced; every other byte is preserved.
14
+ *
15
+ * Pure + env-independent: no fs, no clock, no process.env reads. The caller
16
+ * supplies both texts; tests drive it with a temp-dir fixture.
17
+ */
18
+
19
+ /** Match a whitelisted scalar line anchored to a whole line (no substring hits). */
20
+ const MAX_ACTIVE_RE = /^([ \t]*)maxActiveSubagents:([ \t]*)(\S.*?)[ \t]*$/gm
21
+ const DEFAULT_PRESET_RE = /^([ \t]*)defaultPreset:([ \t]*)(\S.*?)[ \t]*$/gm
22
+
23
+ function allMatches(text, re) {
24
+ re.lastIndex = 0
25
+ return [...text.matchAll(re)]
26
+ }
27
+
28
+ /** Validate an unquoted YAML scalar is a safe identifier/number, not an injection. */
29
+ function safeScalar(raw) {
30
+ const value = raw.trim()
31
+ const core = value.replace(/^(['"])(.*)\1$/, '$2')
32
+ return /^[A-Za-z0-9_][A-Za-z0-9_.-]*$/.test(core) ? value : undefined
33
+ }
34
+
35
+ /** Replace exactly one line in `text`; bail out if the needle is not unique. */
36
+ function replaceOnce(text, needle, replacement) {
37
+ const count = text.split(needle).length - 1
38
+ if (count !== 1) return { text, ok: false, count }
39
+ return { text: text.replace(needle, replacement), ok: true, count: 1 }
40
+ }
41
+
42
+ /** Locate the single `enabled:` line inside a top-level `- id: <id>` sequence item.
43
+ * Scoped to the entry block so the approval-gate `enabled: !!js ...` line (a
44
+ * different entry) is never mistaken for session-log-deepseek's boolean. */
45
+ function findEntryEnabled(text, id) {
46
+ const idRe = new RegExp(`^- id: ${id}[ \\t]*$`, 'm')
47
+ const idMatch = idRe.exec(text)
48
+ if (idMatch === null) return undefined
49
+ const blockStart = idMatch.index + idMatch[0].length
50
+ const rest = text.slice(blockStart)
51
+ const nextEntry = /^- (?:id|insert):/m.exec(rest)
52
+ const blockEnd = nextEntry === null ? text.length : blockStart + nextEntry.index
53
+ const block = text.slice(blockStart, blockEnd)
54
+ const re = /^([ \t]*)enabled:([ \t]*)(\S.*?)[ \t]*$/gm
55
+ const matches = allMatches(block, re)
56
+ if (matches.length !== 1) return undefined // absent or duplicate → refuse
57
+ const m = matches[0]
58
+ return { absoluteIndex: blockStart + m.index, full: m[0], indent: m[1], gap: m[2], value: m[3] }
59
+ }
60
+
61
+ /** Accept only a boolean scalar (bare or quoted), never an expression/injection. */
62
+ function safeBoolean(raw) {
63
+ const core = raw.trim().replace(/^(['"])(.*)\1$/, '$2')
64
+ return core === 'true' || core === 'false' ? core : undefined
65
+ }
66
+
67
+ /**
68
+ * Merge runtime-written volatile fields from `current` into a fresh `template`.
69
+ *
70
+ * @returns {{content: string, mergedFields: string[], notes: string[]}}
71
+ * content - template with allow-listed runtime values substituted in
72
+ * mergedFields - field ids actually carried over (empty when none)
73
+ * notes - WARN lines for the caller to surface (guard/skip decisions)
74
+ */
75
+ export function mergeRuntimeFields(template, current) {
76
+ const out = { content: template, mergedFields: [], notes: [] }
77
+ if (typeof current !== 'string' || current.length === 0) return out
78
+
79
+ // --- subagent.maxActiveSubagents ------------------------------------------
80
+ {
81
+ const tmpl = allMatches(template, MAX_ACTIVE_RE)
82
+ const curr = allMatches(current, MAX_ACTIVE_RE)
83
+ // Exactly one template line and one current line; duplicates are refused
84
+ // rather than guessed (design §8.1.2: bad indent / duplicate key -> WARN).
85
+ if (tmpl.length === 1 && curr.length === 1) {
86
+ const tmplValue = tmpl[0][3]
87
+ const currRaw = curr[0][3]
88
+ const currValue = safeScalar(currRaw)
89
+ if (currValue !== undefined && /^\d+$/.test(currValue) && currValue !== tmplValue) {
90
+ const needle = tmpl[0][0]
91
+ const replacement = `${tmpl[0][1]}maxActiveSubagents:${tmpl[0][2]}${currValue}`
92
+ const res = replaceOnce(out.content, needle, replacement)
93
+ if (res.ok) {
94
+ out.content = res.text
95
+ out.mergedFields.push('subagent.maxActiveSubagents')
96
+ } else {
97
+ out.notes.push('subagent.maxActiveSubagents: template line not unique; runtime value not merged')
98
+ }
99
+ } else if (currRaw !== tmplValue) {
100
+ out.notes.push('subagent.maxActiveSubagents: runtime value failed the scalar allow-list; template value kept')
101
+ }
102
+ } else if (curr.length > 1) {
103
+ out.notes.push('subagent.maxActiveSubagents: duplicate lines in current patch; runtime value not merged')
104
+ }
105
+ }
106
+
107
+ // --- permission.defaultPreset (with !!js escape-hatch guard) --------------
108
+ {
109
+ const tmpl = allMatches(template, DEFAULT_PRESET_RE)
110
+ const curr = allMatches(current, DEFAULT_PRESET_RE)
111
+ if (tmpl.length === 1 && curr.length === 1) {
112
+ const tmplValue = tmpl[0][3]
113
+ const currValue = curr[0][3]
114
+ // Guard: current still carries the template's !!js expression -> the
115
+ // DSH_OPENTUI_APPROVAL_GATE escape hatch is intact; leave it alone.
116
+ if (currValue !== tmplValue) {
117
+ const plain = safeScalar(currValue)
118
+ if (plain !== undefined && !currValue.includes('!!js')) {
119
+ const needle = tmpl[0][0]
120
+ const replacement = `${tmpl[0][1]}defaultPreset:${tmpl[0][2]}${plain}`
121
+ const res = replaceOnce(out.content, needle, replacement)
122
+ if (res.ok) {
123
+ out.content = res.text
124
+ out.mergedFields.push('permission.defaultPreset')
125
+ out.notes.push(
126
+ `permission.defaultPreset: runtime plain scalar ${plain} overrides the template !!js DSH_OPENTUI_APPROVAL_GATE escape hatch; merged as plain value`,
127
+ )
128
+ } else {
129
+ out.notes.push('permission.defaultPreset: template line not unique; runtime value not merged')
130
+ }
131
+ } else {
132
+ out.notes.push('permission.defaultPreset: runtime value failed the scalar allow-list; template !!js line kept')
133
+ }
134
+ }
135
+ } else if (curr.length > 1) {
136
+ out.notes.push('permission.defaultPreset: duplicate lines in current patch; runtime value not merged')
137
+ }
138
+ }
139
+
140
+ // --- session-log-deepseek.enabled (boolean, entry-scoped) ------------------
141
+ {
142
+ const tmpl = findEntryEnabled(template, 'session-log-deepseek')
143
+ const curr = findEntryEnabled(current, 'session-log-deepseek')
144
+ if (tmpl !== undefined && curr !== undefined) {
145
+ const tmplValue = tmpl.value.trim()
146
+ const currValue = curr.value.trim()
147
+ // B1 S4-S6 / design 05 §4.3a: carry the host-written boolean across
148
+ // launcher restarts. A `!!js` expression or any non-boolean is refused
149
+ // (same scalar allow-list discipline as the other two fields).
150
+ if (currValue !== tmplValue) {
151
+ const plain = safeBoolean(currValue)
152
+ if (plain !== undefined) {
153
+ const needle = tmpl.full
154
+ const replacement = `${tmpl.indent}enabled:${tmpl.gap}${plain}`
155
+ const res = replaceOnce(out.content, needle, replacement)
156
+ if (res.ok) {
157
+ out.content = res.text
158
+ out.mergedFields.push('session-log-deepseek.enabled')
159
+ } else {
160
+ out.notes.push('session-log-deepseek.enabled: template line not unique; runtime value not merged')
161
+ }
162
+ } else {
163
+ out.notes.push('session-log-deepseek.enabled: runtime value failed the boolean allow-list; template value kept')
164
+ }
165
+ }
166
+ } else if (curr === undefined && /^- id: session-log-deepseek[ \t]*$/m.test(current)) {
167
+ out.notes.push('session-log-deepseek.enabled: duplicate or missing enabled line in current patch; runtime value not merged')
168
+ }
169
+ }
170
+
171
+ return out
172
+ }
@@ -632,6 +632,18 @@ const PATCH_TEMPLATE = `# model route (managed by provision-opentui-profile.mjs
632
632
  name: '@aiwayds/dsh-opentui-session-shim'
633
633
  - id: session-controller
634
634
  name: '@deepseek-ai/dsh-api-session-controller'
635
+
636
+ # B1 S4-S6 (design 05 4.3a): explicit config row for the host-writable volatile
637
+ # session-log-deepseek.enabled. The host config service (dsh-settings.mutate ->
638
+ # configEditor.edit) writes this value into the profile patch at runtime; naming
639
+ # the row here gives provisionPatch() a stable merge landing spot so the value
640
+ # survives launcher restarts. Appended at the END of the template (after the
641
+ # ledger-evidenced 566-578 block) so those line numbers never shift.
642
+ # enabled is volatile + defaults true (dsh-session-log-deepseek Config schema).
643
+ - id: session-log-deepseek
644
+ name: "@deepseek-ai/dsh-session-log-deepseek"
645
+ config:
646
+ enabled: true
635
647
  `
636
648
  const PATCH_REVISION = createHash('sha256').update(PATCH_TEMPLATE).digest('hex').slice(0, 16)
637
649
  const PATCH_HEADER = `# dsh-opentui inproc profile patch — GENERATED by provision-inproc-profile.mjs; edit the script, not this file.\n${PATCH_REVISION_MARKER}${PATCH_REVISION}\n`
@@ -1248,6 +1260,11 @@ function verifyHostCompatibility(bridgeDir) {
1248
1260
  }
1249
1261
  }
1250
1262
 
1263
+ // B1 S3 — runtime-field merge. Static import placed AFTER the template block
1264
+ // (ESM import declarations are hoisted and may sit at any top-level position)
1265
+ // so the ledger-evidenced template lines 566-578 never shift.
1266
+ import { mergeRuntimeFields } from './lib/patch-runtime-merge.mjs'
1267
+
1251
1268
  // --- Inproc cordis.patch.yml ownership ------------------------------------
1252
1269
  /** Read the profileRevision stamped by this script, if present. */
1253
1270
  function readPatchRevision(content) {
@@ -1273,10 +1290,20 @@ function provisionPatch() {
1273
1290
  }
1274
1291
 
1275
1292
  const localRevision = readPatchRevision(current)
1276
- if (current === PATCH_CONTENT && localRevision === PATCH_REVISION) {
1293
+ // B1 S3 (design 05 §4.3a): carry runtime-written volatile scalars into the
1294
+ // fresh template copy instead of discarding them on every launch. The merge
1295
+ // is line-based and allow-listed (see lib/patch-runtime-merge.mjs); every
1296
+ // other byte — including the ledger-evidenced template section — is intact.
1297
+ const merged = mergeRuntimeFields(PATCH_CONTENT, current)
1298
+ const nextContent = merged.content
1299
+ if (current === nextContent && localRevision === PATCH_REVISION) {
1277
1300
  say(7, 'patch', 'already current, skipping')
1278
1301
  return
1279
1302
  }
1303
+ for (const note of merged.notes) warn(`cordis.patch.yml: ${note}`)
1304
+ if (merged.mergedFields.length > 0) {
1305
+ say(7, 'patch', `preserved runtime fields: ${merged.mergedFields.join(', ')}`)
1306
+ }
1280
1307
 
1281
1308
  if (current !== undefined && current.length > 0) {
1282
1309
  const md5 = createHash('md5').update(current).digest('hex')
@@ -1289,7 +1316,7 @@ function provisionPatch() {
1289
1316
 
1290
1317
  // Atomic write: temp file in the same dir, then rename.
1291
1318
  const tmpPath = `${patchPath}.tmp-${process.pid}-${Date.now()}`
1292
- writeFileSync(tmpPath, PATCH_CONTENT)
1319
+ writeFileSync(tmpPath, nextContent)
1293
1320
  renameSync(tmpPath, patchPath)
1294
1321
  say(7, 'patch', `wrote ${patchPath} (profileRevision ${PATCH_REVISION})`)
1295
1322
  }