@narumitw/pi-sync 0.62.0 → 0.63.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.
Files changed (110) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +29 -15
  3. package/dist/chunks/{chunk-MNYRU5U5.ts → chunk-27F5W7DX.ts} +3 -2
  4. package/dist/chunks/{chunk-MNYRU5U5.ts.map → chunk-27F5W7DX.ts.map} +2 -2
  5. package/dist/chunks/chunk-CKUGCBHP.ts +114 -0
  6. package/dist/chunks/chunk-CKUGCBHP.ts.map +7 -0
  7. package/dist/chunks/chunk-EJDDRS6O.ts +17 -0
  8. package/dist/chunks/chunk-EJDDRS6O.ts.map +7 -0
  9. package/dist/chunks/{chunk-6PFZUEUG.ts → chunk-EXDWEFIJ.ts} +52 -135
  10. package/dist/chunks/chunk-EXDWEFIJ.ts.map +7 -0
  11. package/dist/chunks/{chunk-NHFGAZEC.ts → chunk-HSCAFOT5.ts} +7 -7
  12. package/dist/chunks/chunk-HSCAFOT5.ts.map +7 -0
  13. package/dist/chunks/chunk-MANNB4WZ.ts +36 -0
  14. package/dist/chunks/chunk-MANNB4WZ.ts.map +7 -0
  15. package/dist/chunks/{chunk-ZB3GNX3P.ts → chunk-S6FUUWV5.ts} +139 -12
  16. package/dist/chunks/chunk-S6FUUWV5.ts.map +7 -0
  17. package/dist/chunks/{chunk-PWESMTH6.ts → chunk-SXCH4Q5O.ts} +38 -20
  18. package/dist/chunks/chunk-SXCH4Q5O.ts.map +7 -0
  19. package/dist/chunks/{chunk-INECVQNR.ts → chunk-UGS6RYDZ.ts} +5 -3
  20. package/dist/chunks/chunk-UGS6RYDZ.ts.map +7 -0
  21. package/dist/chunks/{chunk-3E3TR3JE.ts → chunk-V76KCWHO.ts} +6 -4
  22. package/dist/chunks/{chunk-3E3TR3JE.ts.map → chunk-V76KCWHO.ts.map} +1 -1
  23. package/dist/chunks/{chunk-GSCZ4VXV.ts → chunk-VQ47JBLF.ts} +2 -2
  24. package/dist/chunks/chunk-WFBHWYI6.ts +18 -0
  25. package/dist/chunks/chunk-WFBHWYI6.ts.map +7 -0
  26. package/dist/chunks/{command-handler-6ATREPG7.ts → command-handler-VINMQ7ZM.ts} +19 -36
  27. package/dist/chunks/command-handler-VINMQ7ZM.ts.map +7 -0
  28. package/dist/chunks/{conflict-review-MAOGTIAI.ts → conflict-review-PCDFRIVB.ts} +2 -2
  29. package/dist/chunks/{file-selection-QR2KZVGD.ts → file-selection-KID23GAD.ts} +15 -8
  30. package/dist/chunks/file-selection-KID23GAD.ts.map +7 -0
  31. package/dist/chunks/{manager-result-dispatcher-MC6EQOQY.ts → manager-result-dispatcher-GDB74IOP.ts} +6 -5
  32. package/dist/chunks/{manager-ui-AOFUNXAJ.ts → manager-ui-YHDECYKI.ts} +197 -322
  33. package/dist/chunks/manager-ui-YHDECYKI.ts.map +7 -0
  34. package/dist/chunks/{remote-selection-ui-4BTP2OJR.ts → remote-selection-ui-GPITNEBF.ts} +5 -4
  35. package/dist/chunks/{setup-switch-Y6AMFFNK.ts → setup-switch-L54X5U5I.ts} +4 -4
  36. package/dist/chunks/{setup-wizard-5G426MOZ.ts → setup-wizard-YO4MCPUF.ts} +7 -3
  37. package/dist/chunks/{setup-wizard-5G426MOZ.ts.map → setup-wizard-YO4MCPUF.ts.map} +1 -1
  38. package/dist/chunks/{sync-inspection-ITZ6Z4DE.ts → sync-inspection-H2WX5SUT.ts} +3 -3
  39. package/dist/chunks/{sync-operations-NMVKF7SE.ts → sync-operations-2MZAYHL2.ts} +2 -2
  40. package/dist/daemon/dist/cli.js +1 -1
  41. package/dist/daemon/dist/consent.js +134 -16
  42. package/dist/daemon/dist/engine/backends/git/git-backend.js +61 -30
  43. package/dist/daemon/dist/engine/ignore/ignore-initialization.js +93 -27
  44. package/dist/daemon/dist/engine/ignore/ignore-settings.js +85 -14
  45. package/dist/daemon/dist/engine/settings/config-file.js +1 -1
  46. package/dist/daemon/dist/engine/settings/config.js +71 -28
  47. package/dist/daemon/dist/engine/settings/settings-management.js +8 -2
  48. package/dist/daemon/dist/engine/snapshot/session-paths.js +7 -2
  49. package/dist/daemon/dist/engine/snapshot/snapshot-transaction-policy.js +37 -17
  50. package/dist/daemon/dist/engine/snapshot/snapshot-transaction.js +55 -13
  51. package/dist/daemon/dist/engine/sync/agent-plan.js +1 -0
  52. package/dist/daemon/dist/engine/sync/agent-sync.js +8 -1
  53. package/dist/daemon/dist/engine/sync/continuous-sync.js +32 -15
  54. package/dist/daemon/dist/engine/sync/merge-acceptance.js +29 -0
  55. package/dist/daemon/dist/engine/sync/merge-apply.js +7 -4
  56. package/dist/daemon/dist/engine/sync/merge-journal.js +33 -14
  57. package/dist/daemon/dist/engine/sync/merged-sync.js +31 -39
  58. package/dist/daemon/dist/engine/sync/remote-snapshot.js +17 -2
  59. package/dist/daemon/dist/engine/sync/session-push.js +20 -6
  60. package/dist/daemon/dist/engine/sync/sync-mutations.js +71 -50
  61. package/dist/daemon/dist/engine/sync/sync-policy.js +28 -3
  62. package/dist/daemon/dist/engine/sync/sync-state.js +3 -8
  63. package/dist/daemon/dist/engine/sync/transfer-freshness.js +82 -0
  64. package/dist/daemon/dist/engine-service.js +124 -27
  65. package/dist/daemon/dist/monitor.js +84 -32
  66. package/dist/daemon/dist/server.js +46 -5
  67. package/dist/daemon/dist/service-host.js +2 -1
  68. package/dist/daemon/package.json +1 -1
  69. package/dist/index.ts +28 -25
  70. package/dist/index.ts.map +4 -4
  71. package/package.json +3 -3
  72. package/skills/configure-pi-sync/SKILL.md +17 -64
  73. package/skills/configure-pi-sync/references/configuration.md +60 -20
  74. package/src/commands/command-execution.ts +12 -8
  75. package/src/commands/command-types.ts +1 -0
  76. package/src/daemon/pi-client.ts +4 -2
  77. package/src/settings/config.ts +1 -0
  78. package/src/sync/automatic-sync.ts +9 -2
  79. package/src/sync/setup-switch.ts +38 -15
  80. package/src/sync/startup-check.ts +7 -4
  81. package/src/ui/excluded-paths-ui.ts +2 -2
  82. package/src/ui/file-selection.ts +7 -2
  83. package/src/ui/ignore-file-guidance.ts +7 -0
  84. package/src/ui/ignore-file-ui.ts +28 -202
  85. package/src/ui/manager-state.ts +27 -15
  86. package/src/ui/manager-ui.ts +4 -1
  87. package/src/ui/remote-selection-ui.ts +51 -24
  88. package/src/ui/settings-ui.ts +132 -81
  89. package/src/ui/setup/setup-actions.ts +16 -4
  90. package/src/ui/setup/setup-prompts.ts +55 -9
  91. package/src/ui/setup/setup-switcher.ts +24 -11
  92. package/src/ui/storage-connections-ui.ts +33 -11
  93. package/src/ui/sync-setups-ui.ts +24 -7
  94. package/dist/chunks/chunk-6PFZUEUG.ts.map +0 -7
  95. package/dist/chunks/chunk-ECYCNZOE.ts +0 -12
  96. package/dist/chunks/chunk-ECYCNZOE.ts.map +0 -7
  97. package/dist/chunks/chunk-INECVQNR.ts.map +0 -7
  98. package/dist/chunks/chunk-NHFGAZEC.ts.map +0 -7
  99. package/dist/chunks/chunk-PWESMTH6.ts.map +0 -7
  100. package/dist/chunks/chunk-ZB3GNX3P.ts.map +0 -7
  101. package/dist/chunks/command-handler-6ATREPG7.ts.map +0 -7
  102. package/dist/chunks/file-selection-QR2KZVGD.ts.map +0 -7
  103. package/dist/chunks/manager-ui-AOFUNXAJ.ts.map +0 -7
  104. /package/dist/chunks/{chunk-GSCZ4VXV.ts.map → chunk-VQ47JBLF.ts.map} +0 -0
  105. /package/dist/chunks/{conflict-review-MAOGTIAI.ts.map → conflict-review-PCDFRIVB.ts.map} +0 -0
  106. /package/dist/chunks/{manager-result-dispatcher-MC6EQOQY.ts.map → manager-result-dispatcher-GDB74IOP.ts.map} +0 -0
  107. /package/dist/chunks/{remote-selection-ui-4BTP2OJR.ts.map → remote-selection-ui-GPITNEBF.ts.map} +0 -0
  108. /package/dist/chunks/{setup-switch-Y6AMFFNK.ts.map → setup-switch-L54X5U5I.ts.map} +0 -0
  109. /package/dist/chunks/{sync-inspection-ITZ6Z4DE.ts.map → sync-inspection-H2WX5SUT.ts.map} +0 -0
  110. /package/dist/chunks/{sync-operations-NMVKF7SE.ts.map → sync-operations-2MZAYHL2.ts.map} +0 -0
@@ -4,6 +4,7 @@ import {
4
4
  applyS3CredentialUpdate,
5
5
  chooseS3CredentialUpdate,
6
6
  chooseS3Credentials,
7
+ ignoreFileSettingsAvailable,
7
8
  promptResourceName,
8
9
  refreshTargetCompletions,
9
10
  requiredInput,
@@ -17,18 +18,19 @@ import {
17
18
  showEditGitTarget,
18
19
  showEditS3Target,
19
20
  showEditWebDavStorageProfile,
20
- showEditWebDavTarget
21
- } from "./chunk-ZB3GNX3P.ts";
21
+ showEditWebDavTarget,
22
+ showIgnoreFileAction
23
+ } from "./chunk-S6FUUWV5.ts";
22
24
  import {
23
25
  dispatchManagerResult
24
- } from "./chunk-3E3TR3JE.ts";
26
+ } from "./chunk-V76KCWHO.ts";
25
27
  import {
26
28
  SETUP_SWITCH_ACTION_OPTIONS,
27
29
  saveOnSwitch,
28
30
  setupSwitchActionFromLabel,
29
31
  setupSwitchActionLabel,
30
32
  useSyncSetup
31
- } from "./chunk-PWESMTH6.ts";
33
+ } from "./chunk-SXCH4Q5O.ts";
32
34
  import {
33
35
  isCloudflareR2Endpoint,
34
36
  normalizeS3Endpoint,
@@ -37,20 +39,23 @@ import {
37
39
  } from "./chunk-APZVJAEW.ts";
38
40
  import {
39
41
  automaticSyncSummary
40
- } from "./chunk-ECYCNZOE.ts";
42
+ } from "./chunk-MANNB4WZ.ts";
41
43
  import {
42
44
  loadOnSwitch,
43
45
  readLocalConfigObject,
44
46
  requireSettings,
45
47
  updateLocalConfig
46
48
  } from "./chunk-WBIOSK76.ts";
49
+ import {
50
+ startupTransferEnabled
51
+ } from "./chunk-WFBHWYI6.ts";
47
52
  import {
48
53
  observationMatchesConfig,
49
54
  observationSummary,
50
55
  readStateForConfig,
51
56
  syncAttentionMatchesConfig,
52
57
  syncStateFingerprint
53
- } from "./chunk-GSCZ4VXV.ts";
58
+ } from "./chunk-VQ47JBLF.ts";
54
59
  import {
55
60
  AUTOMATIC_SYNC_DESCRIPTION,
56
61
  STARTUP_TRANSFER_DESCRIPTION,
@@ -62,11 +67,14 @@ import {
62
67
  import {
63
68
  directoryScopeSummary,
64
69
  showExcludedPaths
65
- } from "./chunk-NHFGAZEC.ts";
70
+ } from "./chunk-HSCAFOT5.ts";
66
71
  import {
67
72
  directorySessionOptInLine,
68
73
  saveReviewedDraft
69
74
  } from "./chunk-JREGWM2B.ts";
75
+ import {
76
+ manualIgnoreFileGuidance
77
+ } from "./chunk-EJDDRS6O.ts";
70
78
  import {
71
79
  activeLocalConfigPath,
72
80
  localConfigPath,
@@ -75,17 +83,14 @@ import {
75
83
  } from "./chunk-IBXEM35O.ts";
76
84
  import {
77
85
  piDaemonClient
78
- } from "./chunk-INECVQNR.ts";
86
+ } from "./chunk-UGS6RYDZ.ts";
87
+ import "./chunk-EXDWEFIJ.ts";
79
88
  import {
80
- runCancellableOperation,
81
- runCancellableTask
82
- } from "./chunk-6PFZUEUG.ts";
89
+ runCancellableOperation
90
+ } from "./chunk-CKUGCBHP.ts";
83
91
  import {
84
92
  throwIfAborted
85
93
  } from "./chunk-UMPA5S7X.ts";
86
- import {
87
- captureMutationOwner
88
- } from "./chunk-GELYN4UC.ts";
89
94
  import {
90
95
  addStorageConnection,
91
96
  removeStorageConnection,
@@ -93,17 +98,21 @@ import {
93
98
  updateStorageConnection,
94
99
  updateSyncSetup
95
100
  } from "./chunk-NXWHPVXR.ts";
101
+ import {
102
+ captureMutationOwner
103
+ } from "./chunk-GELYN4UC.ts";
96
104
  import {
97
105
  sameSyncExclude
98
106
  } from "./chunk-ZO52JM4H.ts";
99
107
  import {
100
108
  configFromSettings,
101
109
  loadConfig,
110
+ loadConfigForCheck,
102
111
  loadPartialConfig,
103
112
  loadSettingsConfig,
104
113
  syncCheckConfigFingerprint,
105
114
  syncConfigReviewIdentity
106
- } from "./chunk-MNYRU5U5.ts";
115
+ } from "./chunk-27F5W7DX.ts";
107
116
  import {
108
117
  configureSyncStatus
109
118
  } from "./chunk-H7VOTY5N.ts";
@@ -131,227 +140,6 @@ import {
131
140
  operationCanRecover
132
141
  } from "#pi-sync-daemon/engine/state/operation-availability";
133
142
 
134
- // src/ui/ignore-file-ui.ts
135
- import { resolve } from "node:path";
136
- import { getAgentDir } from "@earendil-works/pi-coding-agent";
137
- import { CURSOR_MARKER, Editor, isKeyRelease, Key, matchesKey, truncateToWidth } from "@earendil-works/pi-tui";
138
- import { HorizontalRule, hardWrapTerminalDocument, runCustomInteraction } from "@narumitw/pi-tui-kit";
139
- async function ignoreFileSettingsAvailable(ctx, signal) {
140
- if (signal?.aborted) return false;
141
- try {
142
- const client = piDaemonClient(ctx);
143
- const result = await client.run("ignore.capabilities", {}, signal, ctx);
144
- client.validate();
145
- return !signal?.aborted && result?.available === true;
146
- } catch {
147
- return false;
148
- }
149
- }
150
- function manualIgnoreFileGuidance(filename) {
151
- return `Edit existing ignore rules manually: ${safeTerminalText(resolve(getAgentDir(), filename))}`;
152
- }
153
- async function showIgnoreFileAction(ctx, setup, action, filename, signal, offerToken) {
154
- if (signal.aborted || !ctx.hasUI) return;
155
- if (ctx.mode !== "tui") {
156
- if (ctx.mode === "rpc" && action === "edit") ctx.ui.notify(manualIgnoreFileGuidance(filename), "info");
157
- return;
158
- }
159
- const validateOwner = captureMutationOwner(ctx, signal);
160
- const client = piDaemonClient(ctx);
161
- const isCurrent = () => {
162
- try {
163
- validateOwner();
164
- client.validate();
165
- return true;
166
- } catch {
167
- return false;
168
- }
169
- };
170
- const work = async (method, message, payload = {}) => {
171
- const result = await runCancellableTask(
172
- ctx,
173
- message,
174
- (workSignal, onCommit) => client.run(`ignore.${method}`, { setup, ...payload }, workSignal, ctx, onCommit),
175
- {
176
- signal,
177
- isCurrent,
178
- cancelledMessage: null,
179
- commitAware: method !== "read",
180
- cancelAcrossDialogs: method !== "read"
181
- }
182
- );
183
- return isCurrent() && result.kind === "completed" ? result : void 0;
184
- };
185
- try {
186
- if (action === "migrate") {
187
- const result2 = await work("migrate", "Preparing ignore-file migration review\u2026", offerToken ? { offerToken } : {});
188
- if (isCurrent() && result2?.value === "saved")
189
- ctx.ui.notify("Ignore-file policy saved locally. No transfer started.", "info");
190
- return;
191
- }
192
- if (action === "switch") {
193
- const entered = await askIgnoreFilename(ctx, filename, signal);
194
- if (!isCurrent() || !entered || entered === filename) return;
195
- const result2 = await work("switch", "Checking the selected ignore file for review\u2026", {
196
- filename: entered,
197
- expectedFilename: filename
198
- });
199
- if (isCurrent() && result2?.value === "saved") ctx.ui.notify("Ignore file selected. No transfer started.", "info");
200
- return;
201
- }
202
- const result = await work("read", "Opening existing ignore file\u2026");
203
- if (!isCurrent() || !result) return;
204
- const source = decodeIgnoreFile(result.value);
205
- const path = safeTerminalText(source.path);
206
- if (!isEditorSafe(source.text)) {
207
- ctx.ui.notify(
208
- `Pi cannot edit this file without changing or hiding some characters. Edit ${path} manually.`,
209
- "warning"
210
- );
211
- return;
212
- }
213
- const sharing = source.sharingSetups.length ? `Also used by: ${source.sharingSetups.map((name) => `\u201C${safeTerminalText(name)}\u201D`).join(", ")}` : void 0;
214
- const draft = await editIgnoreText(ctx, source.text, path, sharing, signal, isCurrent);
215
- if (!isCurrent() || draft.kind !== "completed") return;
216
- if (draft.value.kind === "unsafe") {
217
- ctx.ui.notify(`Unsafe terminal characters in the draft. No save; edit ${path} manually.`, "warning");
218
- return;
219
- }
220
- if (draft.value.kind !== "draft" || draft.value.text === source.text) return;
221
- const text = draft.value.text;
222
- const lines = [
223
- path,
224
- ...sharing ? [sharing] : [],
225
- "This replaces the local rules. Removing rules may expose more files on a later sync.",
226
- "No transfer starts; remote history is retained."
227
- ];
228
- const confirmed = await confirmMergeReview(ctx, "Save ignore rules?", text, signal, isCurrent, "save rules", lines);
229
- if (!isCurrent() || !confirmed) return;
230
- const saved = await work("save", "Saving ignore rules\u2026", {
231
- text,
232
- sourceDigest: source.sourceDigest,
233
- identity: source.identity
234
- });
235
- if (isCurrent() && saved) ctx.ui.notify("Ignore rules saved. No transfer started.", "info");
236
- } catch (error) {
237
- if (isCurrent())
238
- ctx.ui.notify(`Pi Sync: ${safeTerminalText(error instanceof Error ? error.message : String(error))}`, "error");
239
- }
240
- }
241
- function decodeIgnoreFile(value) {
242
- const file = value;
243
- if (!file || typeof file.filename !== "string" || typeof file.path !== "string")
244
- throw new Error("Invalid ignore-file response from the daemon.");
245
- if (file.identity === void 0 && file.text === void 0)
246
- throw new Error(`Ignore file does not exist: ${file.path}. No file was created.`);
247
- if (typeof file.text !== "string" || typeof file.identity !== "string" || file.identity.length === 0 || typeof file.sourceDigest !== "string" || !Array.isArray(file.sharingSetups) || !file.sharingSetups.every((setup) => typeof setup === "string"))
248
- throw new Error("Invalid ignore-file response from the daemon.");
249
- return file;
250
- }
251
- async function askIgnoreFilename(ctx, filename, signal) {
252
- const cancel = new AbortController();
253
- const stop = ctx.ui.onTerminalInput((data) => {
254
- if (!isKeyRelease(data) && matchesKey(data, Key.ctrl("c"))) {
255
- cancel.abort();
256
- return { consume: true };
257
- }
258
- });
259
- const inputSignal = AbortSignal.any([signal, cancel.signal]);
260
- try {
261
- const entered = await ctx.ui.input(`Existing ignore filename (current: ${safeTerminalText(filename)})`, void 0, {
262
- signal: inputSignal
263
- });
264
- return inputSignal.aborted ? void 0 : entered;
265
- } finally {
266
- stop();
267
- }
268
- }
269
- function isEditorSafe(text) {
270
- const flattened = text.replaceAll("\n", "");
271
- return flattened === safeTerminalText(flattened);
272
- }
273
- function editIgnoreText(ctx, original, path, sharing, signal, isCurrent) {
274
- return runCustomInteraction(ctx, {
275
- signal,
276
- isCurrent,
277
- create: ({ tui, theme, keybindings, complete, signal: editorSignal }) => {
278
- const muted = (line) => theme.fg("muted", line);
279
- const editor = new Editor(tui, {
280
- borderColor: (line) => theme.fg("borderMuted", line),
281
- selectList: {
282
- selectedPrefix: (line) => theme.fg("accent", line),
283
- selectedText: (line) => theme.fg("accent", line),
284
- description: muted,
285
- scrollInfo: muted,
286
- noMatch: muted
287
- }
288
- });
289
- editor.setText(original);
290
- let text = original;
291
- let beforeChange = original;
292
- editor.onChange = () => {
293
- beforeChange = text;
294
- text = editor.getExpandedText();
295
- if (!isEditorSafe(text)) complete({ kind: "unsafe" });
296
- };
297
- editor.onSubmit = () => complete({ kind: "draft", text: beforeChange });
298
- const rule = new HorizontalRule({ ruleStyle: (line) => theme.fg("border", line) });
299
- let layout;
300
- return {
301
- get focused() {
302
- return editor.focused;
303
- },
304
- set focused(value) {
305
- editor.focused = value;
306
- },
307
- get capturesViewportInput() {
308
- return true;
309
- },
310
- render(width) {
311
- layout = void 0;
312
- if (editorSignal.aborted || !Number.isFinite(width) || width <= 0) return [];
313
- const terminalRows = Number.isFinite(tui.terminal.rows) ? Math.floor(tui.terminal.rows) : 24;
314
- const rows = Math.max(1, terminalRows - 3);
315
- const border = rows >= 5 ? rule.render(width) : [];
316
- const editorRows = editor.render(width).slice(1, -1);
317
- const header = [
318
- theme.fg("accent", theme.bold("Edit ignore rules")),
319
- muted("Submit to review; cancel to discard."),
320
- ...[path, ...sharing ? [sharing] : []].flatMap(
321
- (line) => hardWrapTerminalDocument(line, width).map(muted)
322
- )
323
- ].slice(0, rows - 2 * border.length - 1);
324
- const available = rows - 2 * border.length - header.length;
325
- const cursorRow = editorRows.findIndex((line) => line.includes(CURSOR_MARKER));
326
- const offset = Math.max(0, cursorRow - available + 1);
327
- const body = editorRows.slice(offset, offset + available);
328
- layout = { width, first: border.length + header.length, count: body.length, editorOffset: offset + 1 };
329
- return [...border, ...header, ...body, ...border].map((line) => truncateToWidth(line, width, ""));
330
- },
331
- invalidate() {
332
- layout = void 0;
333
- rule.invalidate();
334
- editor.invalidate();
335
- },
336
- handleInput(data) {
337
- if (editorSignal.aborted || isKeyRelease(data)) return;
338
- if (matchesKey(data, Key.ctrl("c")) || keybindings.matches(data, "tui.select.cancel")) {
339
- complete({ kind: "cancelled" });
340
- return;
341
- }
342
- editor.handleInput(data);
343
- if (!editorSignal.aborted) tui.requestRender();
344
- },
345
- handleMouse(event) {
346
- if (editorSignal.aborted || !layout || layout.width !== event.width) return;
347
- const y = event.y - layout.first;
348
- if (y >= 0 && y < layout.count) return editor.handleMouse({ ...event, y: y + layout.editorOffset });
349
- }
350
- };
351
- }
352
- });
353
- }
354
-
355
143
  // src/ui/ignore-migration-prompt.ts
356
144
  var reviewNow = "Review migration now";
357
145
  var notNow = "Not now";
@@ -433,7 +221,7 @@ function blockedSyncMenuItem(label, manager) {
433
221
  };
434
222
  }
435
223
  async function showManagerAttention(ctx, attention, runRoute, signal, onSelectionResolved) {
436
- const { showRemoteSelectionReview } = await import("./remote-selection-ui-4BTP2OJR.ts");
224
+ const { showRemoteSelectionReview } = await import("./remote-selection-ui-GPITNEBF.ts");
437
225
  if (signal?.aborted) return "close";
438
226
  const review = await showRemoteSelectionReview(ctx, attention.decision.setupName, signal, void 0, {
439
227
  decision: attention.decision,
@@ -496,7 +284,7 @@ async function recoverSyncAccess(ctx, manager, runRoute, sessionSignal, actionSi
496
284
  }
497
285
 
498
286
  // src/ui/manager-state.ts
499
- import { truncateToWidth as truncateToWidth2 } from "@earendil-works/pi-tui";
287
+ import { truncateToWidth } from "@earendil-works/pi-tui";
500
288
 
501
289
  // src/ui/sync-setups-ui.ts
502
290
  import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
@@ -537,6 +325,15 @@ async function countValidSyncSetups(setups, signal) {
537
325
  return count;
538
326
  }
539
327
  async function showSyncSetups(ctx, actions, signal) {
328
+ const validateOwner = captureMutationOwner(ctx, signal);
329
+ const isCurrent = () => {
330
+ try {
331
+ validateOwner();
332
+ return true;
333
+ } catch {
334
+ return false;
335
+ }
336
+ };
540
337
  let selectedName;
541
338
  let exit = false;
542
339
  const nameById = /* @__PURE__ */ new Map();
@@ -645,18 +442,19 @@ async function showSyncSetups(ctx, actions, signal) {
645
442
  }
646
443
  });
647
444
  await runMenu(ctx, menu, {
648
- getState: async () => loadSetupMenuState(selectedName, signal),
445
+ getState: async ({ signal: loadSignal }) => loadSetupMenuState(ctx, selectedName, loadSignal),
649
446
  signal,
650
- isCurrent: () => !signal?.aborted
447
+ isCurrent
651
448
  });
652
449
  return exit ? "exit" : void 0;
653
450
  }
654
- async function loadSetupMenuState(selectedName, signal) {
451
+ async function loadSetupMenuState(ctx, selectedName, signal) {
655
452
  const catalog = await loadSettingsCatalog();
656
453
  throwIfAborted(signal);
657
454
  if (!catalog) return { setups: {} };
658
455
  const { syncSetups: setups, activeSyncSetup: active } = catalog.settings;
659
- const recovery = catalog.ignoreSetups.length ? [IGNORE_SETUP_MANAGEMENT_LIMIT, ...ignoreSetupRecovery(catalog.path)] : void 0;
456
+ const recovery = catalog.ignoreSetups.length && !await ignoreFileSettingsAvailable(ctx, signal) ? [IGNORE_SETUP_MANAGEMENT_LIMIT, ...ignoreSetupRecovery(catalog.path)] : void 0;
457
+ throwIfAborted(signal);
660
458
  if (!selectedName || !Object.hasOwn(setups, selectedName)) return { setups, active, recovery };
661
459
  const setupCount = Object.keys(setups).length;
662
460
  const isCurrent = selectedName === active;
@@ -690,7 +488,7 @@ async function loadSetupMenuState(selectedName, signal) {
690
488
  }
691
489
  const removeNeedsSwitch = isCurrent && setupCount > 1;
692
490
  const ignoreSetupsRemain = catalog.ignoreSetups.some((name) => name !== selectedName);
693
- const removeUnavailable = removeNeedsSwitch || ignoreSetupsRemain;
491
+ const removeUnavailable = removeNeedsSwitch || Boolean(recovery && ignoreSetupsRemain);
694
492
  if (recovery) {
695
493
  if (removeUnavailable) detail.unshift("Remove unavailable here; use manual recovery.");
696
494
  detail.unshift(...recovery);
@@ -750,7 +548,7 @@ var MAIN_MENU_ACTIONS = [
750
548
  "History",
751
549
  "Diagnostics"
752
550
  ];
753
- async function describeManagerState(signal, attention, inspectOperation = inspectOperationAvailability, observation) {
551
+ async function describeManagerState(signal, attention, inspectOperation = inspectOperationAvailability, observation, canUseIgnoreSettings) {
754
552
  let raw;
755
553
  try {
756
554
  const document = await readActiveLocalConfigDocumentForRepair();
@@ -791,23 +589,15 @@ async function describeManagerState(signal, attention, inspectOperation = inspec
791
589
  actions: ["Sync setups\u2026", "Storage connections\u2026", "Help"]
792
590
  };
793
591
  }
592
+ let settingsConfig;
794
593
  try {
795
- const settingsConfig = configFromSettings(raw);
796
- if (settingsConfig.reservedIgnoreNames !== void 0) {
797
- return {
798
- title: [
799
- "Manage sync",
800
- `Current sync setup: ${safeTerminalText(settingsConfig.setupName)}`,
801
- "Transfers are unavailable while ignore-file setups are configured."
802
- ].join("\n"),
803
- actions: ["Settings", "Sync setups\u2026", "Storage connections\u2026", "Help"],
804
- settingsReview: {
805
- setupName: settingsConfig.setupName,
806
- fingerprint: syncCheckConfigFingerprint(settingsConfig)
807
- }
808
- };
594
+ settingsConfig = configFromSettings(raw);
595
+ if (settingsConfig.reservedIgnoreNames && canUseIgnoreSettings && !await canUseIgnoreSettings()) {
596
+ throw new Error("the connected daemon does not support ignore-file setups");
809
597
  }
598
+ signal?.throwIfAborted();
810
599
  const config = await loadConfig();
600
+ signal?.throwIfAborted();
811
601
  const operation = await inspectOperation();
812
602
  const changesBlocked = operationBlocksChanges(operation);
813
603
  let currentAttention;
@@ -826,7 +616,7 @@ async function describeManagerState(signal, attention, inspectOperation = inspec
826
616
  const noSyncedContent = !syncSelectionHasContent(config);
827
617
  const syncState = changesBlocked ? void 0 : await readStateForConfig(config).catch(() => void 0);
828
618
  const currentObservation = observation && observationMatchesConfig(observation, config) && syncState && syncStateFingerprint(syncState) === observation.inspection.stateIdentity ? observation : void 0;
829
- const lastAppliedSnapshot = changesBlocked ? "Unavailable while operations are locked" : syncState?.lastAppliedSnapshot ? `${truncateToWidth2(safeTerminalText(syncState.lastAppliedSnapshot), 12, "\u2026")} \xB7 application time unavailable` : syncState ? "Never synced" : "Unavailable";
619
+ const lastAppliedSnapshot = changesBlocked ? "Unavailable while operations are locked" : syncState?.lastAppliedSnapshot ? `${truncateToWidth(safeTerminalText(syncState.lastAppliedSnapshot), 12, "\u2026")} \xB7 application time unavailable` : syncState ? "Never synced" : "Unavailable";
830
620
  const canSwitch = await countValidSyncSetups(configuredTargets, signal) > 1;
831
621
  const mainActions = [...MAIN_MENU_ACTIONS];
832
622
  if (config.agentMode && !noSyncedContent) mainActions.splice(1, 0, "Retry refused model result\u2026");
@@ -838,7 +628,7 @@ async function describeManagerState(signal, attention, inspectOperation = inspec
838
628
  "Manage sync",
839
629
  `Current sync setup: ${safeTerminalText(config.setupName)}`,
840
630
  `Storage: ${backendStorageDescription(config)}`,
841
- ...config.scope ? ["Sync scope: Pi agent directory, with exclusions"] : [],
631
+ ...config.pathPolicy === "ignore-file" ? [`Sync scope: Pi agent directory \xB7 ignore file: ${safeTerminalText(config.ignoreFile ?? ".syncignore")}`] : config.scope ? ["Sync scope: Pi agent directory, with exclusions"] : [],
842
632
  ...syncState?.unresolved?.length ? [`Unresolved: ${syncState.unresolved.length} dependency groups \xB7 review needed`] : [],
843
633
  ...currentAttention ? [
844
634
  currentAttention.decision.setupName === config.setupName ? "Sync status: Review needed" : `Sync status: Review needed for setup ${safeTerminalText(currentAttention.decision.setupName)}`,
@@ -853,6 +643,7 @@ async function describeManagerState(signal, attention, inspectOperation = inspec
853
643
  title: (changesBlocked ? ["Manage sync", ...operationStatusLines(operation)] : ordinaryTitle).join("\n"),
854
644
  actions: operationActions(operation, noSyncedContent, canSwitch, mainActions),
855
645
  configReview: { setupName: config.setupName, fingerprint: syncCheckConfigFingerprint(config) },
646
+ settingsReview: { setupName: settingsConfig.setupName, fingerprint: syncCheckConfigFingerprint(settingsConfig) },
856
647
  operation,
857
648
  ...currentObservation ? { observation: currentObservation } : {},
858
649
  ...currentAttention ? {
@@ -863,6 +654,20 @@ async function describeManagerState(signal, attention, inspectOperation = inspec
863
654
  };
864
655
  } catch (error) {
865
656
  if (signal?.aborted) throw error;
657
+ if (settingsConfig?.reservedIgnoreNames !== void 0) {
658
+ return {
659
+ title: [
660
+ "Manage sync",
661
+ `Current sync setup: ${safeTerminalText(settingsConfig.setupName)}`,
662
+ `Transfers are unavailable: ${safeTerminalText(errorMessage(error))}`
663
+ ].join("\n"),
664
+ actions: ["Settings", "Sync setups\u2026", "Storage connections\u2026", "Help"],
665
+ settingsReview: {
666
+ setupName: settingsConfig.setupName,
667
+ fingerprint: syncCheckConfigFingerprint(settingsConfig)
668
+ }
669
+ };
670
+ }
866
671
  return {
867
672
  title: [
868
673
  "Manage sync",
@@ -918,7 +723,7 @@ function operationStatusLines(operation) {
918
723
  case "free":
919
724
  return [];
920
725
  case "live": {
921
- const command = truncateToWidth2(safeTerminalText(operation.lock.command), 16, "\u2026");
726
+ const command = truncateToWidth(safeTerminalText(operation.lock.command), 16, "\u2026");
922
727
  return [
923
728
  `Running: ${command} (pid ${operation.lock.pid}). Wait, then refresh; Transfer actions and Settings return.`
924
729
  ];
@@ -1079,6 +884,15 @@ function boundedSettingsUI(ctx) {
1079
884
  import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
1080
885
  import { defineMenu as defineMenu2, runMenu as runMenu2 } from "@narumitw/pi-tui-kit";
1081
886
  async function showStorageConnections(ctx, signal) {
887
+ const validateOwner = captureMutationOwner(ctx, signal);
888
+ const isCurrent = () => {
889
+ try {
890
+ validateOwner();
891
+ return true;
892
+ } catch {
893
+ return false;
894
+ }
895
+ };
1082
896
  let selectedName;
1083
897
  const nameById = /* @__PURE__ */ new Map();
1084
898
  const menu = defineMenu2({
@@ -1150,22 +964,24 @@ async function showStorageConnections(ctx, signal) {
1150
964
  }
1151
965
  return { kind: "stay" };
1152
966
  },
1153
- remove: async ({ state }) => {
967
+ remove: async ({ state, signal: actionSignal }) => {
1154
968
  if (state.recovery || !state.selected || state.selected.name !== selectedName) return { kind: "rejected" };
1155
969
  const name = state.selected.name;
1156
970
  const confirmed = await ctx.ui.confirm(
1157
971
  "Remove storage connection?",
1158
972
  `Remove local storage connection \u201C${safeTerminalText(name)}\u201D? Remote data and history are not deleted.`,
1159
- { signal }
973
+ { signal: actionSignal }
1160
974
  );
1161
- if (!confirmed || signal?.aborted) return { kind: "rejected" };
975
+ if (!confirmed || actionSignal.aborted || !isCurrent()) return { kind: "rejected" };
1162
976
  try {
1163
- await removeStorageConnection(name, signal);
977
+ await removeStorageConnection(name, actionSignal);
978
+ if (actionSignal.aborted || !isCurrent()) return { kind: "close" };
1164
979
  ctx.ui.notify(`Removed storage connection \u201C${safeTerminalText(name)}\u201D.`, "info");
1165
980
  selectedName = void 0;
1166
981
  return { kind: "back" };
1167
982
  } catch (error) {
1168
- notifyConnectionError(ctx, name, error, signal);
983
+ if (actionSignal.aborted || !isCurrent()) return { kind: "close" };
984
+ notifyConnectionError(ctx, name, error, actionSignal);
1169
985
  return { kind: "stay" };
1170
986
  }
1171
987
  },
@@ -1176,17 +992,21 @@ async function showStorageConnections(ctx, signal) {
1176
992
  }
1177
993
  });
1178
994
  await runMenu2(ctx, menu, {
1179
- getState: () => loadStorageMenuState(selectedName, signal),
995
+ getState: ({ signal: loadSignal }) => loadStorageMenuState(ctx, selectedName, loadSignal),
1180
996
  signal,
1181
- isCurrent: () => !signal?.aborted
997
+ isCurrent
1182
998
  });
1183
999
  }
1184
- async function loadStorageMenuState(selectedName, signal) {
1000
+ async function loadStorageMenuState(ctx, selectedName, signal) {
1185
1001
  const catalog = await loadSettingsCatalog();
1186
1002
  signal?.throwIfAborted();
1187
1003
  const raw = catalog?.settings;
1188
1004
  const profiles = raw?.storageConnections ?? {};
1189
- const recovery = catalog?.ignoreSetups.length ? ["Connection changes are unavailable while any setup uses an ignore file.", ...ignoreSetupRecovery(catalog.path)] : void 0;
1005
+ const recovery = catalog?.ignoreSetups.length && !await ignoreFileSettingsAvailable(ctx, signal) ? [
1006
+ "Connection changes are unavailable while any setup uses an ignore file.",
1007
+ ...ignoreSetupRecovery(catalog.path)
1008
+ ] : void 0;
1009
+ signal.throwIfAborted();
1190
1010
  const profile = selectedName ? ownRecord(profiles[selectedName]) : void 0;
1191
1011
  if (!selectedName || !profile) {
1192
1012
  return {
@@ -1467,8 +1287,11 @@ async function showSetupSwitcher(ctx, runRoute, selectedName, signal) {
1467
1287
  return false;
1468
1288
  }
1469
1289
  let config;
1290
+ let metadata;
1470
1291
  try {
1471
- config = await loadConfig(name);
1292
+ metadata = await loadSettingsConfig(name);
1293
+ if (signal?.aborted) return false;
1294
+ config = await loadConfigForCheck(name, signal);
1472
1295
  if (signal?.aborted) return false;
1473
1296
  } catch (error) {
1474
1297
  ctx.ui.notify(
@@ -1479,14 +1302,14 @@ async function showSetupSwitcher(ctx, runRoute, selectedName, signal) {
1479
1302
  }
1480
1303
  const onSwitch = await loadOnSwitch();
1481
1304
  if (signal?.aborted) return false;
1482
- const switchEffect = onSwitch === "ask-before-pull" ? "After switching, pi-sync will ask whether to review a pull for this setup." : onSwitch === "pull-after-switch" ? "After switching, pi-sync will check this setup and show exact changes before applying them." : "After switching, pi-sync will not pull or modify synced files.";
1305
+ const switchEffect = config.reservedIgnoreNames !== void 0 ? "This switch only saves the active setup. To transfer, use a reviewed /sync command." : onSwitch === "ask-before-pull" ? "After switching, pi-sync will ask whether to review a pull for this setup." : onSwitch === "pull-after-switch" ? "After switching, pi-sync will check this setup and show exact changes before applying them." : "After switching, pi-sync will not pull or modify synced files.";
1483
1306
  const confirmed = await ctx.ui.confirm(
1484
1307
  "Switch sync setup?",
1485
1308
  [
1486
1309
  `From: ${safeTerminalText(active ?? "none")}`,
1487
1310
  `To: ${safeTerminalText(name)}`,
1488
1311
  `Storage: ${backendStorageDescription(config)}`,
1489
- config.scope === "agent-directory" ? `Scope: Pi agent directory \xB7 ${config.exclude?.length ?? 0} excluded and ${config.reinclude?.length ?? 0} re-included rules` : `Included content: ${config.include.length} paths`,
1312
+ config.pathPolicy === "ignore-file" ? `Scope: Pi agent directory \xB7 ignore file: ${safeTerminalText(config.ignoreFile ?? ".syncignore")}` : config.scope === "agent-directory" ? `Scope: Pi agent directory \xB7 ${config.exclude?.length ?? 0} excluded and ${config.reinclude?.length ?? 0} re-included rules` : `Included content: ${config.include.length} paths`,
1490
1313
  `Automatic sync: ${automaticSyncSummary(config.automatic)} \xB7 Sessions: ${syncSessionsSelected(config) ? "On" : "Off"}`,
1491
1314
  `Automatic transfer at startup: ${config.automaticTransfer ? "On \u2014 may upload, replace, or delete selected files; no reload" : "Off"}`,
1492
1315
  `Autonomous sync: ${config.agentMode ? "On (autonomous merged sync)" : "Off"}`,
@@ -1525,7 +1348,8 @@ async function showSetupSwitcher(ctx, runRoute, selectedName, signal) {
1525
1348
  },
1526
1349
  onSwitch,
1527
1350
  signal,
1528
- syncConfigReviewIdentity(config)
1351
+ syncConfigReviewIdentity(metadata),
1352
+ syncCheckConfigFingerprint(config)
1529
1353
  );
1530
1354
  if (pullClosed) return "closed";
1531
1355
  return result.pullApplied ? "pull-attempted" : "switched";
@@ -1622,17 +1446,26 @@ async function showEditSyncSetupStorage(ctx, name, signal) {
1622
1446
  await showEditS3Target(ctx, partial, signal);
1623
1447
  }
1624
1448
  async function showRemoveTarget(ctx, name, signal) {
1449
+ const validate = captureMutationOwner(ctx, signal);
1625
1450
  const confirmed = await ctx.ui.confirm(
1626
1451
  "Remove sync setup?",
1627
1452
  `Remove local sync setup \u201C${safeTerminalText(name)}\u201D? Remote data and history are not deleted.`,
1628
1453
  { signal }
1629
1454
  );
1630
1455
  if (signal?.aborted || !confirmed) return;
1631
- await removeSyncSetup(name, signal);
1632
- if (signal?.aborted) return;
1456
+ validate();
1457
+ const { revertedToLegacyOnly } = await removeSyncSetup(name, signal);
1458
+ try {
1459
+ validate();
1460
+ } catch {
1461
+ return;
1462
+ }
1463
+ const message = `Removed sync setup \u201C${safeTerminalText(name)}\u201D; remote data was not deleted.`;
1464
+ ctx.ui.notify(
1465
+ revertedToLegacyOnly ? `${message} To resume Continuous sync if enabled, close /sync and run /reload in an attached TUI session, or reopen one Pi client.` : message,
1466
+ "info"
1467
+ );
1633
1468
  await refreshTargetCompletions();
1634
- if (signal?.aborted) return;
1635
- ctx.ui.notify(`Removed sync setup \u201C${safeTerminalText(name)}\u201D; remote data was not deleted.`, "info");
1636
1469
  }
1637
1470
 
1638
1471
  // src/ui/settings-ui.ts
@@ -1662,10 +1495,13 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1662
1495
  } catch {
1663
1496
  config = void 0;
1664
1497
  }
1498
+ const limited = config?.reservedIgnoreNames !== void 0 && !await ignoreFileSettingsAvailable(ctx, signal);
1499
+ if (!isCurrent()) return disposition;
1665
1500
  ctx.ui.notify(
1666
1501
  [
1667
1502
  document === null ? "Could not read the active pi-sync settings file. Check file access or repair the JSON before reopening /sync." : `Edit pi-sync settings manually: ${safeTerminalText(settingsPath)}`,
1668
- ...config?.reservedIgnoreNames !== void 0 ? [IGNORE_SETUP_MANAGEMENT_LIMIT, ...ignoreSetupRecovery(settingsPath)] : [],
1503
+ ...limited ? [IGNORE_SETUP_MANAGEMENT_LIMIT, ...ignoreSetupRecovery(settingsPath)] : [],
1504
+ ...!limited && config?.reservedIgnoreNames !== void 0 ? ["Use TUI Settings \u2192 Review automatic transfers to approve the current setup separately."] : [],
1669
1505
  ...config?.pathPolicy === "ignore-file" ? [manualIgnoreFileGuidance(config.ignoreFile ?? ".syncignore")] : config?.scope === "agent-directory" ? directoryScopeSummary(config) : []
1670
1506
  ].join("\n"),
1671
1507
  "info"
@@ -1711,36 +1547,19 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1711
1547
  title: "Pi Sync Settings",
1712
1548
  lines: [
1713
1549
  `Setup: ${safeTerminalText(state.setupName)} \xB7 Connection: ${safeTerminalText(state.connectionName)}`,
1714
- ...state.reservedIgnoreNames !== void 0 ? [
1715
- "Setup preferences are read-only; adding, editing, and switching setups are unavailable.",
1716
- state.pathPolicy === "ignore-file" && !ignoreAvailable ? manualIgnoreFileGuidance(state.ignoreFile ?? ".syncignore") : "Open Manage sync setups for manual recovery."
1717
- ] : [saveStatus]
1550
+ ...state.reservedIgnoreNames !== void 0 && !ignoreAvailable ? ["Setup preferences are read-only; adding, editing, and switching setups are unavailable."] : [saveStatus],
1551
+ ...state.pathPolicy === "ignore-file" ? [manualIgnoreFileGuidance(state.ignoreFile ?? ".syncignore")] : []
1718
1552
  ],
1719
1553
  items: [
1720
1554
  ...state.pathPolicy === "ignore-file" ? ignoreAvailable ? [
1721
1555
  {
1722
1556
  id: "ignoreFile",
1723
1557
  label: "Ignore file",
1724
- description: "Select another existing file in the Pi agent directory. No transfer starts.",
1558
+ description: `Select another existing local file. Sessions: ${state.include.includes("sessions") ? "opted in (rules still apply)" : "off"}. No transfer starts.`,
1725
1559
  currentValue: safeTerminalText(state.ignoreFile ?? ".syncignore"),
1726
1560
  action: "ignore-switch"
1727
- },
1728
- {
1729
- id: "ignoreRules",
1730
- label: "Edit ignore rules\u2026",
1731
- description: `Edit the existing local rules, then confirm separately. Sessions: ${state.include.includes("sessions") ? "opted in (ignore rules still apply)" : "off"}.`,
1732
- currentValue: "Edit",
1733
- action: "ignore-edit"
1734
- }
1735
- ] : [] : ignoreAvailable ? [
1736
- {
1737
- id: "migrateIgnoreFile",
1738
- label: "Migrate to ignore file\u2026",
1739
- description: "Review the scope change for this legacy setup. Migration does not start a transfer.",
1740
- currentValue: "Review",
1741
- action: "ignore-migrate"
1742
1561
  }
1743
- ] : state.reservedIgnoreNames !== void 0 ? [] : state.scope === "agent-directory" ? [
1562
+ ] : [] : state.reservedIgnoreNames !== void 0 && !ignoreAvailable ? [] : state.scope === "agent-directory" ? [
1744
1563
  {
1745
1564
  id: "include",
1746
1565
  label: "Agent directory scope",
@@ -1764,11 +1583,20 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1764
1583
  action: "exclude"
1765
1584
  }
1766
1585
  ],
1767
- ...state.reservedIgnoreNames !== void 0 ? [] : [
1586
+ ...ignoreAvailable && state.pathPolicy !== "ignore-file" ? [
1587
+ {
1588
+ id: "migrateIgnoreFile",
1589
+ label: "Migrate to ignore file\u2026",
1590
+ description: "Review the scope change for this legacy setup. Migration does not start a transfer.",
1591
+ currentValue: "Review",
1592
+ action: "ignore-migrate"
1593
+ }
1594
+ ] : [],
1595
+ ...state.reservedIgnoreNames !== void 0 && !ignoreAvailable ? [] : [
1768
1596
  {
1769
1597
  id: "remoteInclude",
1770
1598
  label: ignoreAvailable || state.scope === "agent-directory" ? "Compare sync policies" : "Compare included paths",
1771
- description: "Compare what sync manages on this device and the remote, not file contents. No files transfer unless you explicitly Continue.",
1599
+ description: state.pathPolicy === "ignore-file" ? "Read-only comparison of local and remote policy, not file contents." : "Compare what sync manages on this device and the remote, not file contents. No files transfer unless you explicitly Continue.",
1772
1600
  currentValue: "Review",
1773
1601
  action: "remote-include"
1774
1602
  }
@@ -1790,14 +1618,14 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1790
1618
  {
1791
1619
  id: "setups",
1792
1620
  label: "Manage sync setups",
1793
- description: state.reservedIgnoreNames !== void 0 ? "Review configured setups and recovery options. Adding, editing, and switching are unavailable." : "This device: add, switch, edit, or remove sync setups. Each edit identifies its owner before saving.",
1621
+ description: state.reservedIgnoreNames !== void 0 && !ignoreAvailable ? "Review configured setups and recovery options. Adding, editing, and switching are unavailable." : "This device: add, switch, edit, or remove sync setups. Each edit identifies its owner before saving.",
1794
1622
  currentValue: "Open",
1795
1623
  action: "setups"
1796
1624
  },
1797
1625
  {
1798
1626
  id: "connections",
1799
1627
  label: "Manage storage connections",
1800
- description: state.reservedIgnoreNames !== void 0 ? "Review shared connections. Connection changes are unavailable while ignore-file setups are configured." : "Shared connections on this device: review affected setups before saving server or credential changes.",
1628
+ description: state.reservedIgnoreNames !== void 0 && !ignoreAvailable ? "Review shared connections. Connection changes are unavailable while ignore-file setups are configured." : "Shared connections on this device: review affected setups before saving server or credential changes.",
1801
1629
  currentValue: "Open",
1802
1630
  action: "connections"
1803
1631
  },
@@ -1833,10 +1661,19 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1833
1661
  values: ["On", "Off"],
1834
1662
  action: "continuous"
1835
1663
  },
1664
+ ...ignoreAvailable && state.reservedIgnoreNames !== void 0 && (startupTransferEnabled(state) || state.automatic && syncSessionsSelected(state)) ? [
1665
+ {
1666
+ id: "authorizeAutomatic",
1667
+ label: "Review automatic transfers",
1668
+ description: "Separate approval for the enabled modes and exact current policy. Saving settings alone does not grant permission.",
1669
+ currentValue: "Review",
1670
+ action: "authorize-automatic"
1671
+ }
1672
+ ] : [],
1836
1673
  {
1837
1674
  id: "onSwitch",
1838
1675
  label: "On setup switch",
1839
- description: "All setups on this device: ask before a pull review, open it automatically, or switch without pulling. Applies to subsequent switches.",
1676
+ description: state.reservedIgnoreNames === void 0 ? "All setups on this device: ask before a pull review, open it automatically, or switch without pulling. Applies to subsequent switches." : "While ignore-file setups exist, switching saves only the active setup. Run a reviewed pull separately.",
1840
1677
  currentValue: setupSwitchActionLabel(state.onSwitch),
1841
1678
  values: SETUP_SWITCH_ACTION_OPTIONS.map(({ label }) => label),
1842
1679
  action: "on-switch"
@@ -1882,7 +1719,7 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1882
1719
  action: "debug"
1883
1720
  }
1884
1721
  ].map(
1885
- (item) => state.reservedIgnoreNames !== void 0 && !["setups", "connections", "ignoreFile", "ignoreRules", "migrateIgnoreFile"].includes(item.id) ? { ...item, disabled: true } : item
1722
+ (item) => state.reservedIgnoreNames !== void 0 && !ignoreAvailable && !["setups", "connections"].includes(item.id) ? { ...item, disabled: true } : item
1886
1723
  )
1887
1724
  })
1888
1725
  },
@@ -1906,13 +1743,13 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1906
1743
  const mutationSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
1907
1744
  const validate = captureMutationOwner(ctx, mutationSignal);
1908
1745
  try {
1909
- const previous = await loadConfig(setupName);
1746
+ const previous = await loadSettingsConfig(setupName);
1910
1747
  validate();
1911
1748
  const mergeContent = value === "Merge only" || value === "Merge + partial";
1912
1749
  const partialSync = value === "Partial only" || value === "Merge + partial";
1913
1750
  if (!await ctx.ui.confirm(
1914
1751
  "Save content policy?",
1915
- `${previous.scope === "agent-directory" ? "Agent directory scope keeps settings version 7 and snapshot version 5; older clients must refuse them." : "This explicitly upgrades settings to at least version 5; partial snapshots use version 3, or version 4 with exclusions, and older clients must refuse them."} Text/session merge is conservative. Partial sync preserves withheld versions and old baselines. Disabling does not clear unresolved groups or recovery evidence. Review a directional migration first if portable policy changes.`,
1752
+ `${previous.pathPolicy === "ignore-file" ? "Ignore-file policy keeps settings version 8 and snapshot version 6; older clients must refuse them." : previous.scope === "agent-directory" ? "Agent directory scope uses snapshot version 5; older clients must refuse it." : "This explicitly upgrades settings to at least version 5; partial snapshots use version 3, or version 4 with exclusions, and older clients must refuse them."} Text/session merge is conservative. Partial sync preserves withheld versions and old baselines. Disabling does not clear unresolved groups or recovery evidence. Review a directional migration first if portable policy changes.`,
1916
1753
  { signal: mutationSignal }
1917
1754
  ))
1918
1755
  return { kind: "rejected" };
@@ -1962,7 +1799,7 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1962
1799
  const mutationSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
1963
1800
  const validate = captureMutationOwner(ctx, mutationSignal);
1964
1801
  try {
1965
- const previous = await loadConfig(setupName);
1802
+ const previous = await loadSettingsConfig(setupName);
1966
1803
  validate();
1967
1804
  const input = await ctx.ui.input(
1968
1805
  "Machine-local settings.json root fields (JSON string array)",
@@ -1980,7 +1817,7 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1980
1817
  if (sameLocalFields(previous.localFields, fields)) return { kind: "stay" };
1981
1818
  const confirmed = await ctx.ui.confirm(
1982
1819
  "Save portable field policy?",
1983
- `${previous.scope === "agent-directory" ? "Agent directory scope keeps settings version 7 and snapshot version 5." : "This opts into at least settings/snapshot version 4/2; exclude-enabled setups retain snapshot version 4."} Older clients must refuse unsupported formats. Future snapshots omit these fields, but old remote history is NOT erased. Review an explicit force push/pull migration before further sync. Removed rules can expose or replace local-only values.`,
1820
+ `${previous.pathPolicy === "ignore-file" ? "Ignore-file policy keeps settings version 8 and snapshot version 6." : previous.scope === "agent-directory" ? "Agent directory scope uses snapshot version 5." : "This opts into at least settings/snapshot version 4/2; exclude-enabled setups retain snapshot version 4."} Older clients must refuse unsupported formats. Future snapshots omit these fields, but old remote history is NOT erased. Review an explicit force push/pull migration before further sync. Removed rules can expose or replace local-only values.`,
1984
1821
  { signal: mutationSignal }
1985
1822
  );
1986
1823
  validate();
@@ -2013,7 +1850,7 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
2013
1850
  const automatic = value === "On";
2014
1851
  const mutationSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
2015
1852
  try {
2016
- const latest = await loadConfig(setupName);
1853
+ const latest = await loadSettingsConfig(setupName);
2017
1854
  if (mutationSignal.aborted) return { kind: "rejected" };
2018
1855
  if (latest.automatic === automatic) return { kind: "stay" };
2019
1856
  await updateSyncSetup(setupName, (setup) => ({ ...setup, sync: { ...setup.sync, automatic } }), {
@@ -2102,7 +1939,7 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
2102
1939
  const skipSecretScan = value === "On";
2103
1940
  const mutationSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
2104
1941
  try {
2105
- const latest = await loadConfig(setupName);
1942
+ const latest = await loadSettingsConfig(setupName);
2106
1943
  if (mutationSignal.aborted) return { kind: "rejected" };
2107
1944
  if (latest.skipSecretScan === skipSecretScan) return { kind: "stay" };
2108
1945
  await updateLocalConfig((settings) => ({ ...settings, skipSecretScan }), mutationSignal);
@@ -2118,7 +1955,7 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
2118
1955
  const showStatus = value === "On";
2119
1956
  const mutationSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
2120
1957
  try {
2121
- const latest = await loadConfig(setupName);
1958
+ const latest = await loadSettingsConfig(setupName);
2122
1959
  if (mutationSignal.aborted) return { kind: "rejected" };
2123
1960
  if (latest.showStatus === showStatus) return { kind: "stay" };
2124
1961
  await updateLocalConfig((settings) => ({ ...settings, showStatus }), mutationSignal);
@@ -2148,7 +1985,7 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
2148
1985
  if (!action) return { kind: "rejected" };
2149
1986
  const mutationSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
2150
1987
  try {
2151
- const latest = await loadConfig(setupName);
1988
+ const latest = await loadSettingsConfig(setupName);
2152
1989
  if (mutationSignal.aborted) return { kind: "rejected" };
2153
1990
  if (latest.onSwitch === action) return { kind: "stay" };
2154
1991
  await saveOnSwitch(action, mutationSignal);
@@ -2170,17 +2007,43 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
2170
2007
  await showExcludedPaths(ctx, setupName, editorSignal);
2171
2008
  return resumeSettings(editorSignal);
2172
2009
  },
2010
+ "authorize-automatic": async ({ state, signal: actionSignal }) => {
2011
+ const reviewSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
2012
+ const validate = captureMutationOwner(ctx, reviewSignal);
2013
+ const client = piDaemonClient(ctx);
2014
+ try {
2015
+ validate();
2016
+ const policy = await client.run("daemon.policy", {}, reviewSignal);
2017
+ validate();
2018
+ if (policy.setup !== state.setupName) return exitSettings();
2019
+ if (policy.automatic) {
2020
+ ctx.ui.notify("Automatic work is already approved for this setup and policy.", "info");
2021
+ return { kind: "stay" };
2022
+ }
2023
+ const accepted = await client.run(
2024
+ "daemon.authorize-connected",
2025
+ { fingerprint: policy.fingerprint },
2026
+ reviewSignal
2027
+ );
2028
+ validate();
2029
+ if (accepted === true) ctx.ui.notify("Automatic work approved for this setup and policy.", "info");
2030
+ return { kind: "stay" };
2031
+ } catch (error) {
2032
+ if (reviewSignal.aborted || !isCurrent()) return exitSettings();
2033
+ notifySaveFailure(ctx, error);
2034
+ return { kind: "rejected" };
2035
+ }
2036
+ },
2173
2037
  "ignore-switch": ignoreAction("switch"),
2174
- "ignore-edit": ignoreAction("edit"),
2175
2038
  "ignore-migrate": ignoreAction("migrate"),
2176
2039
  "remote-include": async ({ state, signal: actionSignal }) => {
2177
- if (state.reservedIgnoreNames !== void 0) return { kind: "rejected" };
2040
+ if (state.reservedIgnoreNames !== void 0 && !ignoreAvailable) return { kind: "rejected" };
2178
2041
  const reviewSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
2179
- const { showRemoteSelectionReview } = await import("./remote-selection-ui-4BTP2OJR.ts");
2042
+ const { showRemoteSelectionReview } = await import("./remote-selection-ui-GPITNEBF.ts");
2180
2043
  if (reviewSignal.aborted) return { kind: "rejected" };
2181
2044
  const review = await showRemoteSelectionReview(ctx, setupName, reviewSignal, void 0, {
2182
2045
  origin: "settings",
2183
- runRoute
2046
+ ...state.pathPolicy === "ignore-file" ? { readOnly: true } : { runRoute }
2184
2047
  });
2185
2048
  if (reviewSignal.aborted) return { kind: "rejected" };
2186
2049
  if (review.kind === "route-result") {
@@ -2208,7 +2071,7 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
2208
2071
  const result = await save(action);
2209
2072
  if (action.signal.aborted || signal?.aborted) return { kind: "rejected" };
2210
2073
  validate();
2211
- saveStatus = result?.kind === "rejected" ? "Save failed or rejected. Previous value retained; retry is available." : id === "automatic-transfer" || id === "automatic" || id === "debug" ? "Saved. Enabling startup work applies next session start; completed transfers are not undone." : "Saved. Applies to subsequent operations; status visibility applies immediately.";
2074
+ saveStatus = result?.kind === "rejected" ? "Save failed or rejected. Previous value retained; retry is available." : id === "automatic-transfer" || id === "automatic" || id === "debug" ? action.state.reservedIgnoreNames !== void 0 ? "Saved. Review automatic transfers separately before enabling automatic work for this policy." : "Saved. Enabling startup work applies next session start; completed transfers are not undone." : "Saved. Applies to subsequent operations; status visibility applies immediately.";
2212
2075
  ctx.ui.notify(saveStatus, result?.kind === "rejected" ? "warning" : "info");
2213
2076
  return result;
2214
2077
  };
@@ -2218,6 +2081,12 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
2218
2081
  if (!ignoreAvailable || state.pathPolicy === "ignore-file" === (action === "migrate"))
2219
2082
  return { kind: "rejected" };
2220
2083
  const editorSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
2084
+ const latest = await loadSettingsConfig();
2085
+ if (editorSignal.aborted || !isCurrent()) return { kind: "close" };
2086
+ if (syncCheckConfigFingerprint(latest) !== syncCheckConfigFingerprint(state)) {
2087
+ ctx.ui.notify("Sync setup changed while Settings was open; reopen it before changing the policy.", "warning");
2088
+ return { kind: "close" };
2089
+ }
2221
2090
  await showIgnoreFileAction(ctx, setupName, action, state.ignoreFile ?? ".syncignore", editorSignal);
2222
2091
  return resumeSettings(editorSignal);
2223
2092
  };
@@ -2300,7 +2169,7 @@ async function showSyncManager(ctx, runRoute, sessionSignal, options = {}) {
2300
2169
  if (!attention) {
2301
2170
  const observation = state.manager.observation;
2302
2171
  if (!observation) return { kind: "stay" };
2303
- const { showRemoteSelectionReview } = await import("./remote-selection-ui-4BTP2OJR.ts");
2172
+ const { showRemoteSelectionReview } = await import("./remote-selection-ui-GPITNEBF.ts");
2304
2173
  if (sessionSignal?.aborted) return { kind: "close" };
2305
2174
  const config = await loadConfig();
2306
2175
  if (sessionSignal?.aborted) return { kind: "close" };
@@ -2559,7 +2428,13 @@ S3/R2 reads the latest pointer without writing. Git reads remote snapshots and c
2559
2428
  const describe = async (signal) => {
2560
2429
  const pendingAttention = options.getAttention?.();
2561
2430
  const observation = options.getObservation?.();
2562
- const manager = await describeManagerState(signal, pendingAttention, void 0, observation);
2431
+ const manager = await describeManagerState(
2432
+ signal,
2433
+ pendingAttention,
2434
+ void 0,
2435
+ observation,
2436
+ () => ignoreFileSettingsAvailable(ctx, signal)
2437
+ );
2563
2438
  if (signal.aborted || !isCurrent()) return manager;
2564
2439
  if (observation && options.getObservation?.() === observation && !manager.observation && !(manager.operation && operationBlocksChanges(manager.operation))) {
2565
2440
  options.onObservationInvalidated?.();
@@ -2634,4 +2509,4 @@ function syncMainMenuItem(label) {
2634
2509
  export {
2635
2510
  showSyncManager
2636
2511
  };
2637
- //# sourceMappingURL=manager-ui-AOFUNXAJ.ts.map
2512
+ //# sourceMappingURL=manager-ui-YHDECYKI.ts.map