@xmoon76/dsh-pi-tui 0.5.6 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +33 -0
- package/README.en.md +103 -814
- package/README.md +102 -711
- package/cordis.patch.yml +186 -0
- package/dist/acp-preferences.d.mts +29 -0
- package/dist/acp-preferences.mjs +15 -0
- package/dist/{bootstrap-DQ4YPL-7.mjs → bootstrap-CMIjGyuk.mjs} +33515 -7587
- package/dist/builtins.mjs +3 -3
- package/dist/{client-bootstrap-Cr1JCaF5.mjs → client-bootstrap-BjGPc-DM.mjs} +4637 -492
- package/dist/client-extension-loader-probe-BUw7q8bJ.mjs +119 -0
- package/dist/command-trust-DChWUamk.mjs +406 -0
- package/dist/daemon-launcher-Dult7Jxv.mjs +1932 -0
- package/dist/daemon-launcher.d.mts +159 -0
- package/dist/daemon-launcher.mjs +2 -0
- package/dist/diagnostics-D5jwc-q1.d.mts +11 -0
- package/dist/{dist-CIsR7cz4.mjs → dist-BFgC-5tL.mjs} +938 -487
- package/dist/entry-control-DjNsE3I0.mjs +190 -0
- package/dist/extension/advanced.d.mts +1 -1
- package/dist/extension/unstable.d.mts +1 -1
- package/dist/extension-config-probe-BDdvutkG.mjs +95 -0
- package/dist/extension-config.d.mts +29 -0
- package/dist/extension-config.mjs +22 -0
- package/dist/{extensions-Bp0L37lP.mjs → extensions-B4uLpSTv.mjs} +1109 -100
- package/dist/{extensions-Bte3XOt5.d.mts → extensions-C8eAM0gX.d.mts} +1 -1
- package/dist/extensions.d.mts +2 -2
- package/dist/extensions.mjs +1 -1
- package/dist/{host-bootstrap-DilsvA6f.mjs → host-bootstrap-MVxks641.mjs} +129 -24
- package/dist/{host-foundation-probe--5jtvHVe.mjs → host-foundation-probe-DMNTmNrH.mjs} +2 -2
- package/dist/host-runtime.d.mts +11 -5
- package/dist/host-runtime.mjs +4171 -920
- package/dist/index.d.mts +86 -174
- package/dist/index.mjs +38087 -9967
- package/dist/local-acp-listener-B65J0Bx4.mjs +3115 -0
- package/dist/local-client.mjs +1158 -59
- package/dist/local-daemon-control-C14q9KnD.mjs +1588 -0
- package/dist/local-daemon-control-TCnERL7n.mjs +1424 -0
- package/dist/local-discovery-DOSsCh9q.mjs +2883 -0
- package/dist/local-discovery-egN4_gsQ.mjs +2 -0
- package/dist/local-discovery-uOBfFq5j.mjs +2764 -0
- package/dist/local-host.mjs +812 -89
- package/dist/local-profile-daemon-admin-BmQSdzT0.mjs +210 -0
- package/dist/local-scope-DamiMqPd.mjs +1340 -0
- package/dist/{local-transport-BVwFYq_Y.mjs → local-transport-Iwo0mtu3.mjs} +313 -38
- package/dist/local-web-control-DMrjwCkl.mjs +454 -0
- package/dist/local-workspace-object-D06GL0UO.mjs +248 -0
- package/dist/native/darwin/prebuilds/darwin-arm64/darwin-platform.node +0 -0
- package/dist/native/darwin/prebuilds/darwin-x64/darwin-platform.node +0 -0
- package/dist/open-CmOBxSjN.mjs +63 -0
- package/dist/persisted-setting-probe-DWZLtWoB.mjs +145 -0
- package/dist/pi-tui-acp-access-contract-BdLwduU6.mjs +75 -0
- package/dist/pi-tui-remote-contribution-Do8ECrUy.mjs +1492 -0
- package/dist/pi-tui-terminal-progress-contract-B3RoEzjK.mjs +146 -0
- package/dist/preferences.d.mts +17 -0
- package/dist/preferences.mjs +20 -0
- package/dist/preset-BcWqOtY7.mjs +46 -0
- package/dist/profile-preferences-migration-BfUGdPZx.mjs +500 -0
- package/dist/profile-preferences-migration-CThz4rHH.mjs +2 -0
- package/dist/prompt-sections-DUKmWb8g.mjs +2232 -0
- package/dist/prompt-sections-DXmjB58H.mjs +634 -0
- package/dist/{public-types-Dgf1bDke.d.mts → public-types-C1YgFtwC.d.mts} +56 -3
- package/dist/row-id-DPbyt9Nn.mjs +24 -0
- package/dist/{runtime-status-Cj1nFOdS.mjs → runtime-status-v-FTnWcD.mjs} +49 -3
- package/dist/schema-BTGYn8_X.d.mts +54 -0
- package/dist/schema-qE_P09zJ.mjs +124 -0
- package/dist/{session-BKGXyh80.mjs → session-C6tSs86s.mjs} +9672 -7270
- package/dist/{session-CPt_U8_f.mjs → session-CstInGIA.mjs} +9674 -7273
- package/dist/startup-CarQxWwi.d.mts +213 -0
- package/dist/{startup-7BYWuvBU.mjs → startup-EG5UqIcd.mjs} +341 -26
- package/dist/startup.d.mts +2 -99
- package/dist/startup.mjs +2 -2
- package/dist/{terminal-progress-source-DrqQhtT8.mjs → terminal-progress-source-CpfpQO_h.mjs} +2038 -67
- package/dist/{pasted-path-range-CMnxuGPx.mjs → transcript-view-C1YtJ49Y.mjs} +11590 -6718
- package/dist/{pasted-path-range-r6qzV_tC.mjs → transcript-view-CuJYWkhp.mjs} +12296 -6923
- package/dist/version-B9yC7bBk.mjs +83 -0
- package/dist/visual-tools.d.mts +1 -1
- package/dist/visual-tools.mjs +1 -1
- package/dist/web-preferences.d.mts +1 -1
- package/dist/{web-roster-CjqnUXNk.mjs → web-roster-Dis7BhrA.mjs} +63 -3
- package/generated/dsh-presets/cordis.patch.yml +4 -2
- package/generated/dsh-presets/ptc.patch.yml +4 -0
- package/generated/dsh-presets/standard.patch.yml +7 -0
- package/generated/web-access/cordis.patch.yml +239 -0
- package/package.json +217 -170
- package/dist/entry-control-DnduyDiw.mjs +0 -92
- package/dist/local-discovery-C9VMjc0K.mjs +0 -759
- package/dist/local-discovery-CDaQHA_R.mjs +0 -2
- package/dist/pi-tui-remote-contribution-B0EQsP0N.mjs +0 -85
- package/dist/pi-tui-terminal-progress-contract-CdBH9j78.mjs +0 -70
- package/dist/pi-tui-terminal-progress-contract-MLXZ-i3t.mjs +0 -905
- package/dist/version-a-eF-QER.mjs +0 -80
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
import { i as resolveDisplayPreset } from "./preset-BcWqOtY7.mjs";
|
|
2
|
+
import { l as isFooterLayout, t as parseFooterCommandConfig, u as parseFooterLayout } from "./command-trust-DChWUamk.mjs";
|
|
3
|
+
import { n as PREFERENCE_FIELD_NAMES, r as PreferencesConfig } from "./schema-qE_P09zJ.mjs";
|
|
4
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { readFile } from "node:fs/promises";
|
|
7
|
+
import { isDeepStrictEqual } from "node:util";
|
|
8
|
+
import { parse } from "yaml";
|
|
9
|
+
//#region src/app/config/legacy-settings-migration.ts
|
|
10
|
+
/**
|
|
11
|
+
* Legacy persisted-data readers shared by the Host-owned TUI preference
|
|
12
|
+
* migration (DSH 0.1.7 PR A): the retired `$DSH_HOME/settings.yaml` document
|
|
13
|
+
* and the historical `agent-presets.default` preference.
|
|
14
|
+
*
|
|
15
|
+
* This module owns ONLY the legacy parsing/normalization helpers. The
|
|
16
|
+
* profile-level precedence, conflict handling, write transaction and marker
|
|
17
|
+
* live in `profile-preferences-migration.ts`; the canonical
|
|
18
|
+
* `pi-tui-preferences` row is the sole runtime authority.
|
|
19
|
+
*
|
|
20
|
+
* Contract highlights:
|
|
21
|
+
* - READ ONLY on the legacy file: the upstream Settings importer may already
|
|
22
|
+
* have renamed `settings.yaml` to `settings.yaml.imported`, so the reader
|
|
23
|
+
* prefers the live file and falls back to the renamed backup; it NEVER
|
|
24
|
+
* renames, rewrites, deletes or truncates either.
|
|
25
|
+
* - field-level fail-soft: a malformed optional field never blocks the rest
|
|
26
|
+
* (the runtime parsers own validation), while the caller keeps the original
|
|
27
|
+
* sources untouched.
|
|
28
|
+
* - `focusMode` exists here ONLY as a legacy input: it converges into
|
|
29
|
+
* `displayPreset` (canonical valid → copy, else focusMode 'on' → focus,
|
|
30
|
+
* else full) and is never carried as a canonical field.
|
|
31
|
+
*
|
|
32
|
+
* @module @xmoon76/dsh-pi-tui/app/config/legacy-settings-migration
|
|
33
|
+
*/
|
|
34
|
+
/** The normalized, schema-clean footerCommand value for a legacy raw field:
|
|
35
|
+
* the runtime parser's CANONICAL output (fail-soft repairs applied) wrapped
|
|
36
|
+
* in the versioned shape the strict Config schema requires. undefined means
|
|
37
|
+
* the legacy value is unusable (skip with a diagnostic). Writing the raw
|
|
38
|
+
* legacy object instead would let a repaired-at-runtime field (e.g. a
|
|
39
|
+
* string timeoutMs) reach the strict z.number() schema and fail the WHOLE
|
|
40
|
+
* migration batch at ConfigEditor validation. */
|
|
41
|
+
function normalizedFooterCommand(value) {
|
|
42
|
+
const parsed = parseFooterCommandConfig(value);
|
|
43
|
+
if (parsed === void 0) return void 0;
|
|
44
|
+
return {
|
|
45
|
+
schemaVersion: 1,
|
|
46
|
+
...parsed
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** String preference fields copied verbatim from the legacy section (the
|
|
50
|
+
* consumers' parsers stay the fail-soft authority on every value). */
|
|
51
|
+
const COPIED_STRING_FIELDS = [
|
|
52
|
+
"theme",
|
|
53
|
+
"iconStyle",
|
|
54
|
+
"footer",
|
|
55
|
+
"footerFallbackMode",
|
|
56
|
+
"fullscreen",
|
|
57
|
+
"busyEnter",
|
|
58
|
+
"localShellSandbox",
|
|
59
|
+
"homeEndKeys",
|
|
60
|
+
"notificationMode",
|
|
61
|
+
"notificationMethod",
|
|
62
|
+
"wheelScrollLines",
|
|
63
|
+
"progressUpdates",
|
|
64
|
+
"responseStyle"
|
|
65
|
+
];
|
|
66
|
+
/** Whole-value fields copied verbatim (raw data — unknown/future entries
|
|
67
|
+
* must survive the migration untouched). */
|
|
68
|
+
const COPIED_RAW_FIELDS = [
|
|
69
|
+
"footerLayout",
|
|
70
|
+
"footerCustomItems",
|
|
71
|
+
"footerCommand",
|
|
72
|
+
"keybindings"
|
|
73
|
+
];
|
|
74
|
+
/** Fields whose new Config schema is a STRICT z.object: a malformed legacy
|
|
75
|
+
* value would fail the whole mutate batch at SettingsForms validation, so
|
|
76
|
+
* each is validated through its existing parser BEFORE joining the batch
|
|
77
|
+
* (plan §8.9: one malformed optional field never blocks the rest). */
|
|
78
|
+
function strictFieldValid(field, value) {
|
|
79
|
+
if (field === "footerLayout") return isFooterLayout(parseFooterLayout(value));
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
/** Read the retired legacy document: prefer the live `settings.yaml`; when
|
|
83
|
+
* the upstream importer's rename wins the read race (the file can vanish
|
|
84
|
+
* between the existence check and the open), fall back to opening the
|
|
85
|
+
* `.imported` backup. A missing file on either path means "no legacy
|
|
86
|
+
* document" (the sync checks keep the common no-legacy boot free of
|
|
87
|
+
* asynchronous I/O before the TUI mounts); any OTHER read error propagates
|
|
88
|
+
* so the caller reports a visible migration failure. */
|
|
89
|
+
async function readLegacyDocument(home) {
|
|
90
|
+
const live = join(home, "settings.yaml");
|
|
91
|
+
if (existsSync(live)) try {
|
|
92
|
+
return await readFile(live, "utf8");
|
|
93
|
+
} catch (error) {
|
|
94
|
+
if (error.code !== "ENOENT") throw error;
|
|
95
|
+
}
|
|
96
|
+
const imported = `${live}.imported`;
|
|
97
|
+
if (existsSync(imported)) try {
|
|
98
|
+
return await readFile(imported, "utf8");
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (error.code !== "ENOENT") throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** Synchronous variant for a startup barrier that must decide whether any
|
|
104
|
+
* legacy value survives before it may continue without a write surface. Same
|
|
105
|
+
* read contract as {@link readLegacyDocument}: live file first, `.imported`
|
|
106
|
+
* backup second, ENOENT means absent, every other error propagates. */
|
|
107
|
+
function readLegacyDocumentSync(home) {
|
|
108
|
+
const live = join(home, "settings.yaml");
|
|
109
|
+
if (existsSync(live)) try {
|
|
110
|
+
return readFileSync(live, "utf8");
|
|
111
|
+
} catch (error) {
|
|
112
|
+
if (error.code !== "ENOENT") throw error;
|
|
113
|
+
}
|
|
114
|
+
const imported = `${live}.imported`;
|
|
115
|
+
if (existsSync(imported)) try {
|
|
116
|
+
return readFileSync(imported, "utf8");
|
|
117
|
+
} catch (error) {
|
|
118
|
+
if (error.code !== "ENOENT") throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** One plain-object section of the legacy document, or undefined. */
|
|
122
|
+
function legacySection(document, section) {
|
|
123
|
+
if (document === null || typeof document !== "object" || Array.isArray(document)) return void 0;
|
|
124
|
+
const value = document[section];
|
|
125
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
/** The historical `agent-presets.default` preference, or undefined. */
|
|
129
|
+
function legacyPresetDefault(document) {
|
|
130
|
+
const value = legacySection(document, "agent-presets")?.default;
|
|
131
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Derive the canonical preference values from the legacy `dsh-pi-tui`
|
|
135
|
+
* section. Field-level fail-soft: a malformed optional field never blocks the
|
|
136
|
+
* rest (the runtime parsers own validation). An absent section produces no
|
|
137
|
+
* values — the schema defaults already express the same effective values, and
|
|
138
|
+
* the profile override must not pin them.
|
|
139
|
+
*/
|
|
140
|
+
function legacyPreferenceValues(section, diag) {
|
|
141
|
+
if (section === void 0) return {};
|
|
142
|
+
const values = {};
|
|
143
|
+
for (const field of COPIED_STRING_FIELDS) {
|
|
144
|
+
const value = section[field];
|
|
145
|
+
if (typeof value === "string") values[field] = value;
|
|
146
|
+
}
|
|
147
|
+
for (const field of COPIED_RAW_FIELDS) {
|
|
148
|
+
const value = section[field];
|
|
149
|
+
if (value === void 0) continue;
|
|
150
|
+
if (field === "footerCommand") {
|
|
151
|
+
const normalized = normalizedFooterCommand(value);
|
|
152
|
+
if (normalized === void 0) {
|
|
153
|
+
diag.warn("legacy TUI field is malformed and was skipped", { field });
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
values[field] = normalized;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (!strictFieldValid(field, value)) {
|
|
160
|
+
diag.warn("legacy TUI field is malformed and was skipped", { field });
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
values[field] = value;
|
|
164
|
+
}
|
|
165
|
+
if (section.displayPreset !== void 0 || section.focusMode !== void 0) values.displayPreset = resolveDisplayPreset({
|
|
166
|
+
displayPreset: typeof section.displayPreset === "string" ? section.displayPreset : void 0,
|
|
167
|
+
focusMode: typeof section.focusMode === "string" ? section.focusMode : void 0
|
|
168
|
+
}).preset;
|
|
169
|
+
return values;
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/app/config/profile-preferences-migration.ts
|
|
173
|
+
/**
|
|
174
|
+
* The Host-owned migration of the persisted TUI preferences into the
|
|
175
|
+
* canonical `pi-tui-preferences` profile row (M6 PR-A).
|
|
176
|
+
*
|
|
177
|
+
* Sources, in precedence order, for every one of the 20 canonical fields:
|
|
178
|
+
*
|
|
179
|
+
* 1. the canonical profile USER field, when it is explicitly present;
|
|
180
|
+
* 2. the legacy Direct (`tui-app`) or Split Host
|
|
181
|
+
* (`split-host-pi-tui-runtime`) profile USER field — a single source wins,
|
|
182
|
+
* two RAW-equal sources migrate once, two different sources are a
|
|
183
|
+
* fail-closed conflict;
|
|
184
|
+
* 3. the retired `$DSH_HOME/settings.yaml(.imported)` document (read-only,
|
|
185
|
+
* historical opinion is lower than any explicit profile USER value);
|
|
186
|
+
* 4. otherwise the field stays inherited (its schema default is NOT pinned
|
|
187
|
+
* into the profile).
|
|
188
|
+
*
|
|
189
|
+
* When every source is readable and consistent, ONE official
|
|
190
|
+
* `ConfigEditor.edit(canonicalEntry, change)` transaction writes the migrated
|
|
191
|
+
* fields plus `legacySettingsMigrationVersion: 2`. The callback re-reads the
|
|
192
|
+
* raw profile patch INSIDE the official profile file lock, so a concurrent
|
|
193
|
+
* settings write (including the official `settings.yaml` importer) cannot be
|
|
194
|
+
* overwritten by a stale snapshot. Nothing else is written: the old profile
|
|
195
|
+
* rows and the `.imported` document stay untouched for downgrade/diagnosis.
|
|
196
|
+
*
|
|
197
|
+
* The migrator is Host-owned. A Split Client never reads the Host Profile and
|
|
198
|
+
* never triggers it.
|
|
199
|
+
*
|
|
200
|
+
* @module @xmoon76/dsh-pi-tui/app/config/profile-preferences-migration
|
|
201
|
+
*/
|
|
202
|
+
/** The canonical Loader row id / Settings namespace. */
|
|
203
|
+
const TUI_PREFERENCES_NAMESPACE = "pi-tui-preferences";
|
|
204
|
+
/** The canonical row's published package identity. */
|
|
205
|
+
const TUI_PREFERENCES_ROW_NAME = "@xmoon76/dsh-pi-tui/preferences";
|
|
206
|
+
/** The retired Direct profile row (read only, migration source). */
|
|
207
|
+
const LEGACY_DIRECT_NAMESPACE = "tui-app";
|
|
208
|
+
/** The retired Split Host profile row (read only, migration source). */
|
|
209
|
+
const LEGACY_SPLIT_NAMESPACE = "split-host-pi-tui-runtime";
|
|
210
|
+
/** A fail-closed migration failure: the marker is NOT advanced and the raw
|
|
211
|
+
* sources are left untouched. Diagnostics carry codes, profile ownership and
|
|
212
|
+
* FIELD NAMES only — never command bodies, custom values or secrets. */
|
|
213
|
+
var TuiPreferencesMigrationError = class extends Error {
|
|
214
|
+
code;
|
|
215
|
+
fields;
|
|
216
|
+
constructor(code, message, fields = []) {
|
|
217
|
+
super(message);
|
|
218
|
+
this.name = "TuiPreferencesMigrationError";
|
|
219
|
+
this.code = code;
|
|
220
|
+
this.fields = fields;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
/** Sentinel: a concurrent Host already completed this migration. */
|
|
224
|
+
var MigrationAlreadyCurrent = class extends Error {};
|
|
225
|
+
const JS_TAG = "tag:yaml.org,2002:js";
|
|
226
|
+
/** The schemastery schema's callable validation form (the schema object is
|
|
227
|
+
* invoked directly; the declared Config type is the OUTPUT, not the input). */
|
|
228
|
+
const validatePreferences = PreferencesConfig;
|
|
229
|
+
/** Reject any `!!js` expression inside a profile USER value: a macro is not a
|
|
230
|
+
* trusted user scalar, and must never be evaluated or copied as one. */
|
|
231
|
+
function assertNoJsExpression(value, source, fields) {
|
|
232
|
+
const visit = (node) => {
|
|
233
|
+
if (node === null || typeof node !== "object") return false;
|
|
234
|
+
if (!Array.isArray(node)) {
|
|
235
|
+
const record = node;
|
|
236
|
+
if (typeof record.__jsExpr === "string") return true;
|
|
237
|
+
return Object.values(record).some(visit);
|
|
238
|
+
}
|
|
239
|
+
return node.some(visit);
|
|
240
|
+
};
|
|
241
|
+
if (visit(value)) throw new TuiPreferencesMigrationError("TUI_PREFERENCES_MIGRATION_SOURCE", `profile row "${source}" carries a !!js expression, which is not a trusted USER value`, fields);
|
|
242
|
+
}
|
|
243
|
+
/** One plain-object USER config of a named profile row (last declaration wins,
|
|
244
|
+
* exactly like the official `findLast` override rule). */
|
|
245
|
+
function rawUserConfigs(text) {
|
|
246
|
+
let document;
|
|
247
|
+
try {
|
|
248
|
+
document = parse(text, { customTags: [{
|
|
249
|
+
tag: JS_TAG,
|
|
250
|
+
resolve: (value) => ({ __jsExpr: value })
|
|
251
|
+
}] });
|
|
252
|
+
} catch (error) {
|
|
253
|
+
throw new TuiPreferencesMigrationError("TUI_PREFERENCES_MIGRATION_SOURCE", `profile patch is not readable YAML: ${error instanceof Error ? error.message : String(error)}`);
|
|
254
|
+
}
|
|
255
|
+
const rows = document === null ? [] : document;
|
|
256
|
+
if (!Array.isArray(rows)) throw new TuiPreferencesMigrationError("TUI_PREFERENCES_MIGRATION_SOURCE", "profile patch must be a YAML sequence");
|
|
257
|
+
const configs = /* @__PURE__ */ new Map();
|
|
258
|
+
for (const row of rows) {
|
|
259
|
+
if (row === null || typeof row !== "object" || Array.isArray(row)) continue;
|
|
260
|
+
const record = row;
|
|
261
|
+
if (Object.hasOwn(record, "insert")) continue;
|
|
262
|
+
const id = record.id;
|
|
263
|
+
if (typeof id !== "string") continue;
|
|
264
|
+
const config = record.config;
|
|
265
|
+
if (config === void 0) {
|
|
266
|
+
if (configs.has(id) && configs.get(id) !== void 0) continue;
|
|
267
|
+
configs.set(id, {});
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
if (config === null || typeof config !== "object" || Array.isArray(config)) throw new TuiPreferencesMigrationError("TUI_PREFERENCES_MIGRATION_SOURCE", `profile row "${id}" has a non-object config`, [id]);
|
|
271
|
+
configs.set(id, config);
|
|
272
|
+
}
|
|
273
|
+
for (const id of [
|
|
274
|
+
TUI_PREFERENCES_NAMESPACE,
|
|
275
|
+
LEGACY_DIRECT_NAMESPACE,
|
|
276
|
+
LEGACY_SPLIT_NAMESPACE
|
|
277
|
+
]) {
|
|
278
|
+
const config = configs.get(id);
|
|
279
|
+
if (config !== void 0) assertNoJsExpression(config, id, []);
|
|
280
|
+
}
|
|
281
|
+
return configs;
|
|
282
|
+
}
|
|
283
|
+
/** The explicit migration marker of one raw USER section (absent/invalid = 0). */
|
|
284
|
+
function markerOf(config) {
|
|
285
|
+
const value = config?.legacySettingsMigrationVersion;
|
|
286
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : 0;
|
|
287
|
+
}
|
|
288
|
+
/** The fields a Settings form's USER override currently owns. */
|
|
289
|
+
function ownedFields(user) {
|
|
290
|
+
if (user === null || typeof user !== "object" || Array.isArray(user)) return /* @__PURE__ */ new Set();
|
|
291
|
+
return new Set(Object.keys(user));
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Whether a migration is still OUTSTANDING when no write surface is available.
|
|
295
|
+
* This is the admission fact, not mere legacy-row presence:
|
|
296
|
+
* - a canonical marker >= 2 proves the one-shot migration completed, so the
|
|
297
|
+
* intentionally preserved legacy rows are diagnosis only;
|
|
298
|
+
* - otherwise only preference fields the canonical USER row does NOT already
|
|
299
|
+
* own count (a retired `sessionId` or an old marker is not a preference);
|
|
300
|
+
* - the legacy `agent-presets.default` destination counts unless the registry
|
|
301
|
+
* USER row already owns `selectedDefault` (the migration never overwrites an
|
|
302
|
+
* owned registry value);
|
|
303
|
+
* - an unreadable/malformed legacy document cannot prove completion, so it
|
|
304
|
+
* fails closed instead of claiming a safe no-op.
|
|
305
|
+
*/
|
|
306
|
+
function migrationOutstanding(input) {
|
|
307
|
+
let profileText = "";
|
|
308
|
+
try {
|
|
309
|
+
profileText = readFileSync(input.patchPath, "utf8");
|
|
310
|
+
} catch (error) {
|
|
311
|
+
if (error.code !== "ENOENT") throw error;
|
|
312
|
+
}
|
|
313
|
+
const sources = rawUserConfigs(profileText);
|
|
314
|
+
const canonicalRaw = sources.get("pi-tui-preferences") ?? {};
|
|
315
|
+
if (markerOf(canonicalRaw) >= 2) return false;
|
|
316
|
+
const directRaw = sources.get("tui-app") ?? {};
|
|
317
|
+
const splitRaw = sources.get("split-host-pi-tui-runtime") ?? {};
|
|
318
|
+
const legacyText = readLegacyDocumentSync(input.home);
|
|
319
|
+
let legacyValues = {};
|
|
320
|
+
let presetDefault;
|
|
321
|
+
if (legacyText !== void 0) {
|
|
322
|
+
let document;
|
|
323
|
+
try {
|
|
324
|
+
document = parse(legacyText);
|
|
325
|
+
} catch (error) {
|
|
326
|
+
throw new TuiPreferencesMigrationError("TUI_PREFERENCES_MIGRATION_SOURCE", `legacy settings document is malformed: ${error instanceof Error ? error.message : String(error)}`);
|
|
327
|
+
}
|
|
328
|
+
legacyValues = legacyPreferenceValues(legacySection(document, "dsh-pi-tui"), input.diag);
|
|
329
|
+
presetDefault = legacyPresetDefault(document);
|
|
330
|
+
}
|
|
331
|
+
for (const field of PREFERENCE_FIELD_NAMES) {
|
|
332
|
+
if (Object.hasOwn(canonicalRaw, field)) continue;
|
|
333
|
+
if (Object.hasOwn(directRaw, field) || Object.hasOwn(splitRaw, field) || Object.hasOwn(legacyValues, field)) return true;
|
|
334
|
+
}
|
|
335
|
+
if (presetDefault !== void 0) {
|
|
336
|
+
const registryRaw = sources.get("agent-preset-registry") ?? {};
|
|
337
|
+
if (!Object.hasOwn(registryRaw, "selectedDefault")) return true;
|
|
338
|
+
}
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Run the Host-owned migration barrier.
|
|
343
|
+
*
|
|
344
|
+
* Callers MUST await this before the first TUI/Agent/Host-business read of
|
|
345
|
+
* the canonical preferences: Direct in `app/bootstrap.ts` (before display
|
|
346
|
+
* resolution / agent compose), the Split Host entry after the profile settled
|
|
347
|
+
* and before Web/ACP startup preferences and Ready.
|
|
348
|
+
*/
|
|
349
|
+
async function migrateProfileTuiPreferences(input) {
|
|
350
|
+
const { forms, configEditor, diag } = input;
|
|
351
|
+
if (forms === void 0 || configEditor === void 0) {
|
|
352
|
+
const reason = forms === void 0 ? "settings service unavailable" : "config editor unavailable";
|
|
353
|
+
if (migrationOutstanding(input)) throw new TuiPreferencesMigrationError("TUI_PREFERENCES_MIGRATION_UNAVAILABLE", `cannot migrate legacy TUI preferences: ${reason}; refusing to start with defaults`);
|
|
354
|
+
diag.warn("canonical TUI preference migration unavailable; no outstanding legacy migration, canonical values remain usable", { reason });
|
|
355
|
+
return {
|
|
356
|
+
status: "unavailable",
|
|
357
|
+
reason
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
const entry = configEditor.entries().find((candidate) => candidate.options.id === TUI_PREFERENCES_NAMESPACE);
|
|
361
|
+
if (entry === void 0) {
|
|
362
|
+
const reason = `no "${TUI_PREFERENCES_NAMESPACE}" Loader entry in this composition`;
|
|
363
|
+
if (migrationOutstanding(input)) throw new TuiPreferencesMigrationError("TUI_PREFERENCES_MIGRATION_UNAVAILABLE", `cannot migrate legacy TUI preferences: ${reason}; refusing to start with defaults`);
|
|
364
|
+
diag.warn("canonical TUI preference migration unavailable; no outstanding legacy migration, canonical values remain usable", { reason });
|
|
365
|
+
return {
|
|
366
|
+
status: "unavailable",
|
|
367
|
+
reason: "canonical preferences row is not Loader-managed"
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
if (entry.options.name !== "@xmoon76/dsh-pi-tui/preferences") throw new TuiPreferencesMigrationError("TUI_PREFERENCES_MIGRATION_SOURCE", `the "${TUI_PREFERENCES_NAMESPACE}" entry loads ${JSON.stringify(entry.options.name ?? null)}, expected "${TUI_PREFERENCES_ROW_NAME}"; refusing to write the canonical preference authority`);
|
|
371
|
+
const canonical = forms.describe()?.find((descriptor) => descriptor.ns === TUI_PREFERENCES_NAMESPACE);
|
|
372
|
+
if (canonical === void 0) throw new TuiPreferencesMigrationError("TUI_PREFERENCES_MIGRATION_SOURCE", `the active profile projects no "${TUI_PREFERENCES_NAMESPACE}" settings row`);
|
|
373
|
+
if (markerOf(canonical.user) >= 2) return { status: "current" };
|
|
374
|
+
let legacyValues = {};
|
|
375
|
+
let presetDefault;
|
|
376
|
+
let legacyText;
|
|
377
|
+
try {
|
|
378
|
+
legacyText = await readLegacyDocument(input.home);
|
|
379
|
+
} catch (error) {
|
|
380
|
+
throw new TuiPreferencesMigrationError("TUI_PREFERENCES_MIGRATION_SOURCE", `legacy settings document read failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
381
|
+
}
|
|
382
|
+
if (legacyText !== void 0) {
|
|
383
|
+
let document;
|
|
384
|
+
try {
|
|
385
|
+
document = parse(legacyText);
|
|
386
|
+
} catch (error) {
|
|
387
|
+
throw new TuiPreferencesMigrationError("TUI_PREFERENCES_MIGRATION_SOURCE", `legacy settings document is malformed: ${error instanceof Error ? error.message : String(error)}`);
|
|
388
|
+
}
|
|
389
|
+
legacyValues = legacyPreferenceValues(legacySection(document, "dsh-pi-tui"), diag);
|
|
390
|
+
presetDefault = legacyPresetDefault(document);
|
|
391
|
+
}
|
|
392
|
+
let migratedPreset;
|
|
393
|
+
if (presetDefault !== void 0) try {
|
|
394
|
+
await input.resolvePreset(presetDefault);
|
|
395
|
+
migratedPreset = presetDefault;
|
|
396
|
+
} catch (error) {
|
|
397
|
+
diag.warn("legacy agent preset default is invalid or unavailable; keeping the official default", {
|
|
398
|
+
preset: presetDefault,
|
|
399
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
if (migratedPreset !== void 0) {
|
|
403
|
+
const registry = forms.describe()?.find((descriptor) => descriptor.ns === "agent-preset-registry");
|
|
404
|
+
if (!ownedFields(registry?.user).has("selectedDefault")) try {
|
|
405
|
+
await forms.mutate("agent-preset-registry", [{
|
|
406
|
+
op: "set",
|
|
407
|
+
path: ["selectedDefault"],
|
|
408
|
+
value: migratedPreset
|
|
409
|
+
}], registry?.revision);
|
|
410
|
+
} catch (error) {
|
|
411
|
+
throw new TuiPreferencesMigrationError("TUI_PREFERENCES_MIGRATION_WRITE", `agent-preset-registry.selectedDefault write failed: ${error instanceof Error ? error.message : String(error)}`, ["agent-preset-registry.selectedDefault"]);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
let plan;
|
|
415
|
+
try {
|
|
416
|
+
await configEditor.edit(entry, (current, _inherited) => {
|
|
417
|
+
let before = "";
|
|
418
|
+
try {
|
|
419
|
+
before = readFileSync(input.patchPath, "utf8");
|
|
420
|
+
} catch (error) {
|
|
421
|
+
if (error.code !== "ENOENT") throw error;
|
|
422
|
+
}
|
|
423
|
+
const sources = rawUserConfigs(before);
|
|
424
|
+
const canonicalRaw = sources.get("pi-tui-preferences") ?? {};
|
|
425
|
+
if (markerOf(canonicalRaw) >= 2) throw new MigrationAlreadyCurrent();
|
|
426
|
+
const directRaw = sources.get("tui-app") ?? {};
|
|
427
|
+
const splitRaw = sources.get("split-host-pi-tui-runtime") ?? {};
|
|
428
|
+
const migrated = {};
|
|
429
|
+
const conflicts = [];
|
|
430
|
+
for (const field of PREFERENCE_FIELD_NAMES) {
|
|
431
|
+
if (Object.hasOwn(canonicalRaw, field)) continue;
|
|
432
|
+
const hasDirect = Object.hasOwn(directRaw, field);
|
|
433
|
+
const hasSplit = Object.hasOwn(splitRaw, field);
|
|
434
|
+
if (hasDirect && hasSplit) {
|
|
435
|
+
if (isDeepStrictEqual(directRaw[field], splitRaw[field])) migrated[field] = directRaw[field];
|
|
436
|
+
else conflicts.push(field);
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
if (hasDirect) {
|
|
440
|
+
migrated[field] = directRaw[field];
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
if (hasSplit) {
|
|
444
|
+
migrated[field] = splitRaw[field];
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
if (Object.hasOwn(legacyValues, field)) migrated[field] = legacyValues[field];
|
|
448
|
+
}
|
|
449
|
+
if (conflicts.length > 0) throw new TuiPreferencesMigrationError("TUI_PREFERENCES_MIGRATION_CONFLICT", `legacy TUI preference sources disagree for: ${conflicts.join(", ")}. Set the canonical "${TUI_PREFERENCES_NAMESPACE}" USER field explicitly to resolve it.`, conflicts);
|
|
450
|
+
const next = {
|
|
451
|
+
...canonicalRaw,
|
|
452
|
+
...migrated,
|
|
453
|
+
legacySettingsMigrationVersion: 2
|
|
454
|
+
};
|
|
455
|
+
try {
|
|
456
|
+
validatePreferences(next);
|
|
457
|
+
} catch (error) {
|
|
458
|
+
throw new TuiPreferencesMigrationError("TUI_PREFERENCES_MIGRATION_SOURCE", `legacy TUI preference value is invalid: ${error instanceof Error ? error.message : String(error)}`, Object.keys(migrated));
|
|
459
|
+
}
|
|
460
|
+
plan = {
|
|
461
|
+
migrated,
|
|
462
|
+
fields: [...Object.keys(migrated), "legacySettingsMigrationVersion"],
|
|
463
|
+
...migratedPreset === void 0 ? {} : { presetDefault: migratedPreset }
|
|
464
|
+
};
|
|
465
|
+
return next;
|
|
466
|
+
});
|
|
467
|
+
} catch (error) {
|
|
468
|
+
if (error instanceof MigrationAlreadyCurrent) return { status: "current" };
|
|
469
|
+
if (error instanceof TuiPreferencesMigrationError) {
|
|
470
|
+
diag.warn("canonical TUI preference migration failed; will retry on next start", {
|
|
471
|
+
code: error.code,
|
|
472
|
+
fields: error.fields,
|
|
473
|
+
reason: error.message
|
|
474
|
+
});
|
|
475
|
+
throw error;
|
|
476
|
+
}
|
|
477
|
+
const wrapped = new TuiPreferencesMigrationError("TUI_PREFERENCES_MIGRATION_WRITE", `canonical "${TUI_PREFERENCES_NAMESPACE}" write failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
478
|
+
diag.warn("canonical TUI preference migration failed; will retry on next start", {
|
|
479
|
+
code: wrapped.code,
|
|
480
|
+
reason: wrapped.message
|
|
481
|
+
});
|
|
482
|
+
throw wrapped;
|
|
483
|
+
}
|
|
484
|
+
if (plan === void 0) throw new TuiPreferencesMigrationError("TUI_PREFERENCES_MIGRATION_WRITE", "the canonical preferences edit settled without a migration plan");
|
|
485
|
+
diag.info("canonical TUI preferences migrated", {
|
|
486
|
+
fields: plan.fields,
|
|
487
|
+
...plan.presetDefault === void 0 ? {} : { presetDefault: plan.presetDefault }
|
|
488
|
+
});
|
|
489
|
+
if (plan.fields.length === 1) return {
|
|
490
|
+
status: "absent",
|
|
491
|
+
fields: plan.fields
|
|
492
|
+
};
|
|
493
|
+
return {
|
|
494
|
+
status: "migrated",
|
|
495
|
+
fields: plan.fields,
|
|
496
|
+
...plan.presetDefault === void 0 ? {} : { presetDefault: plan.presetDefault }
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
//#endregion
|
|
500
|
+
export { TuiPreferencesMigrationError as a, TUI_PREFERENCES_ROW_NAME as i, LEGACY_SPLIT_NAMESPACE as n, migrateProfileTuiPreferences as o, TUI_PREFERENCES_NAMESPACE as r, LEGACY_DIRECT_NAMESPACE as t };
|