@narumitw/pi-sync 0.62.0 → 0.63.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +40 -23
  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-INECVQNR.ts → chunk-B5F3JLD3.ts} +6 -4
  6. package/dist/chunks/chunk-B5F3JLD3.ts.map +7 -0
  7. package/dist/chunks/chunk-CKUGCBHP.ts +114 -0
  8. package/dist/chunks/chunk-CKUGCBHP.ts.map +7 -0
  9. package/dist/chunks/chunk-EJDDRS6O.ts +17 -0
  10. package/dist/chunks/chunk-EJDDRS6O.ts.map +7 -0
  11. package/dist/chunks/{chunk-6PFZUEUG.ts → chunk-EXDWEFIJ.ts} +52 -135
  12. package/dist/chunks/chunk-EXDWEFIJ.ts.map +7 -0
  13. package/dist/chunks/{chunk-NHFGAZEC.ts → chunk-HSCAFOT5.ts} +7 -7
  14. package/dist/chunks/chunk-HSCAFOT5.ts.map +7 -0
  15. package/dist/chunks/{chunk-ZB3GNX3P.ts → chunk-LBNC5AOM.ts} +140 -13
  16. package/dist/chunks/chunk-LBNC5AOM.ts.map +7 -0
  17. package/dist/chunks/chunk-MANNB4WZ.ts +36 -0
  18. package/dist/chunks/chunk-MANNB4WZ.ts.map +7 -0
  19. package/dist/chunks/{chunk-GSQGBVKG.ts → chunk-POWOMJ7S.ts} +87 -50
  20. package/dist/chunks/chunk-POWOMJ7S.ts.map +7 -0
  21. package/dist/chunks/{chunk-PWESMTH6.ts → chunk-SXCH4Q5O.ts} +38 -20
  22. package/dist/chunks/chunk-SXCH4Q5O.ts.map +7 -0
  23. package/dist/chunks/{chunk-3E3TR3JE.ts → chunk-V76KCWHO.ts} +6 -4
  24. package/dist/chunks/{chunk-3E3TR3JE.ts.map → chunk-V76KCWHO.ts.map} +1 -1
  25. package/dist/chunks/{chunk-GSCZ4VXV.ts → chunk-VQ47JBLF.ts} +2 -2
  26. package/dist/chunks/chunk-WFBHWYI6.ts +18 -0
  27. package/dist/chunks/chunk-WFBHWYI6.ts.map +7 -0
  28. package/dist/chunks/{command-handler-6ATREPG7.ts → command-handler-GMRRFWOL.ts} +19 -36
  29. package/dist/chunks/command-handler-GMRRFWOL.ts.map +7 -0
  30. package/dist/chunks/{conflict-review-MAOGTIAI.ts → conflict-review-JWEA7DPQ.ts} +2 -2
  31. package/dist/chunks/{file-selection-QR2KZVGD.ts → file-selection-KID23GAD.ts} +15 -8
  32. package/dist/chunks/file-selection-KID23GAD.ts.map +7 -0
  33. package/dist/chunks/{manager-result-dispatcher-MC6EQOQY.ts → manager-result-dispatcher-GDB74IOP.ts} +6 -5
  34. package/dist/chunks/{manager-ui-AOFUNXAJ.ts → manager-ui-T5J5WG7T.ts} +227 -343
  35. package/dist/chunks/manager-ui-T5J5WG7T.ts.map +7 -0
  36. package/dist/chunks/{merge-review-SGDLMVS4.ts → merge-review-OQDXNTJU.ts} +2 -2
  37. package/dist/chunks/{remote-selection-ui-4BTP2OJR.ts → remote-selection-ui-GPITNEBF.ts} +5 -4
  38. package/dist/chunks/{setup-switch-Y6AMFFNK.ts → setup-switch-L54X5U5I.ts} +4 -4
  39. package/dist/chunks/{setup-wizard-5G426MOZ.ts → setup-wizard-LL6YMGUR.ts} +7 -3
  40. package/dist/chunks/{setup-wizard-5G426MOZ.ts.map → setup-wizard-LL6YMGUR.ts.map} +1 -1
  41. package/dist/chunks/{sync-inspection-ITZ6Z4DE.ts → sync-inspection-SRU6HGGK.ts} +3 -3
  42. package/dist/chunks/{sync-operations-NMVKF7SE.ts → sync-operations-UGSCONZ7.ts} +2 -2
  43. package/dist/daemon/dist/cli.js +1 -1
  44. package/dist/daemon/dist/consent.js +134 -16
  45. package/dist/daemon/dist/engine/backends/git/git-backend.js +61 -30
  46. package/dist/daemon/dist/engine/ignore/ignore-initialization.js +142 -40
  47. package/dist/daemon/dist/engine/ignore/ignore-settings.js +94 -26
  48. package/dist/daemon/dist/engine/ignore/ignore-source.js +1 -1
  49. package/dist/daemon/dist/engine/settings/config-file.js +1 -1
  50. package/dist/daemon/dist/engine/settings/config.js +71 -28
  51. package/dist/daemon/dist/engine/settings/settings-management.js +8 -2
  52. package/dist/daemon/dist/engine/snapshot/session-paths.js +7 -2
  53. package/dist/daemon/dist/engine/snapshot/snapshot-transaction-policy.js +37 -17
  54. package/dist/daemon/dist/engine/snapshot/snapshot-transaction.js +55 -13
  55. package/dist/daemon/dist/engine/sync/agent-plan.js +1 -0
  56. package/dist/daemon/dist/engine/sync/agent-sync.js +8 -1
  57. package/dist/daemon/dist/engine/sync/continuous-sync.js +32 -15
  58. package/dist/daemon/dist/engine/sync/merge-acceptance.js +29 -0
  59. package/dist/daemon/dist/engine/sync/merge-apply.js +7 -4
  60. package/dist/daemon/dist/engine/sync/merge-journal.js +33 -14
  61. package/dist/daemon/dist/engine/sync/merged-sync.js +31 -39
  62. package/dist/daemon/dist/engine/sync/remote-snapshot.js +17 -2
  63. package/dist/daemon/dist/engine/sync/session-push.js +20 -6
  64. package/dist/daemon/dist/engine/sync/sync-error-guidance.js +16 -3
  65. package/dist/daemon/dist/engine/sync/sync-mutations.js +75 -54
  66. package/dist/daemon/dist/engine/sync/sync-policy.js +28 -3
  67. package/dist/daemon/dist/engine/sync/sync-state.js +3 -8
  68. package/dist/daemon/dist/engine/sync/transfer-freshness.js +82 -0
  69. package/dist/daemon/dist/engine/ui/sync-format.js +23 -55
  70. package/dist/daemon/dist/engine/ui/transfer-review.js +3 -3
  71. package/dist/daemon/dist/engine-service.js +124 -27
  72. package/dist/daemon/dist/monitor.js +84 -32
  73. package/dist/daemon/dist/server.js +46 -5
  74. package/dist/daemon/dist/service-host.js +2 -1
  75. package/dist/daemon/package.json +1 -1
  76. package/dist/index.ts +28 -25
  77. package/dist/index.ts.map +4 -4
  78. package/docs/tui-contract.md +1 -1
  79. package/package.json +3 -3
  80. package/skills/configure-pi-sync/SKILL.md +128 -74
  81. package/skills/configure-pi-sync/references/configuration.md +115 -45
  82. package/src/commands/command-execution.ts +12 -8
  83. package/src/commands/command-types.ts +1 -0
  84. package/src/daemon/pi-client.ts +4 -2
  85. package/src/settings/config.ts +1 -0
  86. package/src/sync/automatic-sync.ts +9 -2
  87. package/src/sync/setup-switch.ts +38 -15
  88. package/src/sync/startup-check.ts +7 -4
  89. package/src/ui/excluded-paths-ui.ts +2 -2
  90. package/src/ui/file-selection.ts +7 -2
  91. package/src/ui/ignore-file-guidance.ts +7 -0
  92. package/src/ui/ignore-file-ui.ts +28 -202
  93. package/src/ui/manager-state.ts +33 -18
  94. package/src/ui/manager-ui.ts +27 -18
  95. package/src/ui/merge-review.ts +28 -1
  96. package/src/ui/remote-selection-ui.ts +51 -24
  97. package/src/ui/settings-ui.ts +132 -81
  98. package/src/ui/setup/setup-actions.ts +16 -4
  99. package/src/ui/setup/setup-prompts.ts +55 -9
  100. package/src/ui/setup/setup-switcher.ts +24 -11
  101. package/src/ui/setup/webdav-ui.ts +1 -1
  102. package/src/ui/storage-connections-ui.ts +33 -11
  103. package/src/ui/sync-confirmation.ts +67 -48
  104. package/src/ui/sync-setups-ui.ts +24 -7
  105. package/dist/chunks/chunk-6PFZUEUG.ts.map +0 -7
  106. package/dist/chunks/chunk-ECYCNZOE.ts +0 -12
  107. package/dist/chunks/chunk-ECYCNZOE.ts.map +0 -7
  108. package/dist/chunks/chunk-GSQGBVKG.ts.map +0 -7
  109. package/dist/chunks/chunk-INECVQNR.ts.map +0 -7
  110. package/dist/chunks/chunk-NHFGAZEC.ts.map +0 -7
  111. package/dist/chunks/chunk-PWESMTH6.ts.map +0 -7
  112. package/dist/chunks/chunk-ZB3GNX3P.ts.map +0 -7
  113. package/dist/chunks/command-handler-6ATREPG7.ts.map +0 -7
  114. package/dist/chunks/file-selection-QR2KZVGD.ts.map +0 -7
  115. package/dist/chunks/manager-ui-AOFUNXAJ.ts.map +0 -7
  116. /package/dist/chunks/{chunk-GSCZ4VXV.ts.map → chunk-VQ47JBLF.ts.map} +0 -0
  117. /package/dist/chunks/{conflict-review-MAOGTIAI.ts.map → conflict-review-JWEA7DPQ.ts.map} +0 -0
  118. /package/dist/chunks/{manager-result-dispatcher-MC6EQOQY.ts.map → manager-result-dispatcher-GDB74IOP.ts.map} +0 -0
  119. /package/dist/chunks/{merge-review-SGDLMVS4.ts.map → merge-review-OQDXNTJU.ts.map} +0 -0
  120. /package/dist/chunks/{remote-selection-ui-4BTP2OJR.ts.map → remote-selection-ui-GPITNEBF.ts.map} +0 -0
  121. /package/dist/chunks/{setup-switch-Y6AMFFNK.ts.map → setup-switch-L54X5U5I.ts.map} +0 -0
  122. /package/dist/chunks/{sync-inspection-ITZ6Z4DE.ts.map → sync-inspection-SRU6HGGK.ts.map} +0 -0
  123. /package/dist/chunks/{sync-operations-NMVKF7SE.ts.map → sync-operations-UGSCONZ7.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-LBNC5AOM.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,
@@ -58,15 +63,18 @@ import {
58
63
  } from "./chunk-HLCML3OW.ts";
59
64
  import {
60
65
  confirmMergeReview
61
- } from "./chunk-GSQGBVKG.ts";
66
+ } from "./chunk-POWOMJ7S.ts";
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-B5F3JLD3.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
  ];
@@ -944,12 +749,15 @@ function backendStorageDescription(config) {
944
749
  switch (config.backend.type) {
945
750
  case "s3": {
946
751
  const type = config.backend.profile.kind === "r2" || isCloudflareR2Endpoint(config.backend.profile.endpoint) ? "Cloudflare R2" : "S3-compatible";
947
- return `${type} \xB7 ${connection} \xB7 ${safeTerminalText(config.backend.destination.bucket)}`;
752
+ const { bucket, prefix } = config.backend.destination;
753
+ return `${type} \xB7 ${connection} \xB7 ${safeTerminalText(bucket)} \xB7 ${safeTerminalText(prefix)}`;
948
754
  }
949
755
  case "webdav":
950
756
  return `WebDAV \xB7 ${connection} \xB7 ${safeTerminalText(config.backend.destination.path)}`;
951
- case "git":
952
- return `Git \xB7 ${connection} \xB7 ${safeTerminalText(config.backend.destination.branch)}`;
757
+ case "git": {
758
+ const { branch, directory } = config.backend.destination;
759
+ return `Git \xB7 ${connection} \xB7 ${safeTerminalText(branch)} \xB7 ${safeTerminalText(directory)}`;
760
+ }
953
761
  }
954
762
  }
955
763
 
@@ -1079,6 +887,15 @@ function boundedSettingsUI(ctx) {
1079
887
  import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
1080
888
  import { defineMenu as defineMenu2, runMenu as runMenu2 } from "@narumitw/pi-tui-kit";
1081
889
  async function showStorageConnections(ctx, signal) {
890
+ const validateOwner = captureMutationOwner(ctx, signal);
891
+ const isCurrent = () => {
892
+ try {
893
+ validateOwner();
894
+ return true;
895
+ } catch {
896
+ return false;
897
+ }
898
+ };
1082
899
  let selectedName;
1083
900
  const nameById = /* @__PURE__ */ new Map();
1084
901
  const menu = defineMenu2({
@@ -1150,22 +967,24 @@ async function showStorageConnections(ctx, signal) {
1150
967
  }
1151
968
  return { kind: "stay" };
1152
969
  },
1153
- remove: async ({ state }) => {
970
+ remove: async ({ state, signal: actionSignal }) => {
1154
971
  if (state.recovery || !state.selected || state.selected.name !== selectedName) return { kind: "rejected" };
1155
972
  const name = state.selected.name;
1156
973
  const confirmed = await ctx.ui.confirm(
1157
974
  "Remove storage connection?",
1158
975
  `Remove local storage connection \u201C${safeTerminalText(name)}\u201D? Remote data and history are not deleted.`,
1159
- { signal }
976
+ { signal: actionSignal }
1160
977
  );
1161
- if (!confirmed || signal?.aborted) return { kind: "rejected" };
978
+ if (!confirmed || actionSignal.aborted || !isCurrent()) return { kind: "rejected" };
1162
979
  try {
1163
- await removeStorageConnection(name, signal);
980
+ await removeStorageConnection(name, actionSignal);
981
+ if (actionSignal.aborted || !isCurrent()) return { kind: "close" };
1164
982
  ctx.ui.notify(`Removed storage connection \u201C${safeTerminalText(name)}\u201D.`, "info");
1165
983
  selectedName = void 0;
1166
984
  return { kind: "back" };
1167
985
  } catch (error) {
1168
- notifyConnectionError(ctx, name, error, signal);
986
+ if (actionSignal.aborted || !isCurrent()) return { kind: "close" };
987
+ notifyConnectionError(ctx, name, error, actionSignal);
1169
988
  return { kind: "stay" };
1170
989
  }
1171
990
  },
@@ -1176,17 +995,21 @@ async function showStorageConnections(ctx, signal) {
1176
995
  }
1177
996
  });
1178
997
  await runMenu2(ctx, menu, {
1179
- getState: () => loadStorageMenuState(selectedName, signal),
998
+ getState: ({ signal: loadSignal }) => loadStorageMenuState(ctx, selectedName, loadSignal),
1180
999
  signal,
1181
- isCurrent: () => !signal?.aborted
1000
+ isCurrent
1182
1001
  });
1183
1002
  }
1184
- async function loadStorageMenuState(selectedName, signal) {
1003
+ async function loadStorageMenuState(ctx, selectedName, signal) {
1185
1004
  const catalog = await loadSettingsCatalog();
1186
1005
  signal?.throwIfAborted();
1187
1006
  const raw = catalog?.settings;
1188
1007
  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;
1008
+ const recovery = catalog?.ignoreSetups.length && !await ignoreFileSettingsAvailable(ctx, signal) ? [
1009
+ "Connection changes are unavailable while any setup uses an ignore file.",
1010
+ ...ignoreSetupRecovery(catalog.path)
1011
+ ] : void 0;
1012
+ signal.throwIfAborted();
1190
1013
  const profile = selectedName ? ownRecord(profiles[selectedName]) : void 0;
1191
1014
  if (!selectedName || !profile) {
1192
1015
  return {
@@ -1467,8 +1290,11 @@ async function showSetupSwitcher(ctx, runRoute, selectedName, signal) {
1467
1290
  return false;
1468
1291
  }
1469
1292
  let config;
1293
+ let metadata;
1470
1294
  try {
1471
- config = await loadConfig(name);
1295
+ metadata = await loadSettingsConfig(name);
1296
+ if (signal?.aborted) return false;
1297
+ config = await loadConfigForCheck(name, signal);
1472
1298
  if (signal?.aborted) return false;
1473
1299
  } catch (error) {
1474
1300
  ctx.ui.notify(
@@ -1479,14 +1305,14 @@ async function showSetupSwitcher(ctx, runRoute, selectedName, signal) {
1479
1305
  }
1480
1306
  const onSwitch = await loadOnSwitch();
1481
1307
  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.";
1308
+ 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
1309
  const confirmed = await ctx.ui.confirm(
1484
1310
  "Switch sync setup?",
1485
1311
  [
1486
1312
  `From: ${safeTerminalText(active ?? "none")}`,
1487
1313
  `To: ${safeTerminalText(name)}`,
1488
1314
  `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`,
1315
+ 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
1316
  `Automatic sync: ${automaticSyncSummary(config.automatic)} \xB7 Sessions: ${syncSessionsSelected(config) ? "On" : "Off"}`,
1491
1317
  `Automatic transfer at startup: ${config.automaticTransfer ? "On \u2014 may upload, replace, or delete selected files; no reload" : "Off"}`,
1492
1318
  `Autonomous sync: ${config.agentMode ? "On (autonomous merged sync)" : "Off"}`,
@@ -1525,7 +1351,8 @@ async function showSetupSwitcher(ctx, runRoute, selectedName, signal) {
1525
1351
  },
1526
1352
  onSwitch,
1527
1353
  signal,
1528
- syncConfigReviewIdentity(config)
1354
+ syncConfigReviewIdentity(metadata),
1355
+ syncCheckConfigFingerprint(config)
1529
1356
  );
1530
1357
  if (pullClosed) return "closed";
1531
1358
  return result.pullApplied ? "pull-attempted" : "switched";
@@ -1622,17 +1449,26 @@ async function showEditSyncSetupStorage(ctx, name, signal) {
1622
1449
  await showEditS3Target(ctx, partial, signal);
1623
1450
  }
1624
1451
  async function showRemoveTarget(ctx, name, signal) {
1452
+ const validate = captureMutationOwner(ctx, signal);
1625
1453
  const confirmed = await ctx.ui.confirm(
1626
1454
  "Remove sync setup?",
1627
1455
  `Remove local sync setup \u201C${safeTerminalText(name)}\u201D? Remote data and history are not deleted.`,
1628
1456
  { signal }
1629
1457
  );
1630
1458
  if (signal?.aborted || !confirmed) return;
1631
- await removeSyncSetup(name, signal);
1632
- if (signal?.aborted) return;
1459
+ validate();
1460
+ const { revertedToLegacyOnly } = await removeSyncSetup(name, signal);
1461
+ try {
1462
+ validate();
1463
+ } catch {
1464
+ return;
1465
+ }
1466
+ const message = `Removed sync setup \u201C${safeTerminalText(name)}\u201D; remote data was not deleted.`;
1467
+ ctx.ui.notify(
1468
+ revertedToLegacyOnly ? `${message} To resume Continuous sync if enabled, close /sync and run /reload in an attached TUI session, or reopen one Pi client.` : message,
1469
+ "info"
1470
+ );
1633
1471
  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
1472
  }
1637
1473
 
1638
1474
  // src/ui/settings-ui.ts
@@ -1662,10 +1498,13 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1662
1498
  } catch {
1663
1499
  config = void 0;
1664
1500
  }
1501
+ const limited = config?.reservedIgnoreNames !== void 0 && !await ignoreFileSettingsAvailable(ctx, signal);
1502
+ if (!isCurrent()) return disposition;
1665
1503
  ctx.ui.notify(
1666
1504
  [
1667
1505
  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)] : [],
1506
+ ...limited ? [IGNORE_SETUP_MANAGEMENT_LIMIT, ...ignoreSetupRecovery(settingsPath)] : [],
1507
+ ...!limited && config?.reservedIgnoreNames !== void 0 ? ["Use TUI Settings \u2192 Review automatic transfers to approve the current setup separately."] : [],
1669
1508
  ...config?.pathPolicy === "ignore-file" ? [manualIgnoreFileGuidance(config.ignoreFile ?? ".syncignore")] : config?.scope === "agent-directory" ? directoryScopeSummary(config) : []
1670
1509
  ].join("\n"),
1671
1510
  "info"
@@ -1711,36 +1550,19 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1711
1550
  title: "Pi Sync Settings",
1712
1551
  lines: [
1713
1552
  `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]
1553
+ ...state.reservedIgnoreNames !== void 0 && !ignoreAvailable ? ["Setup preferences are read-only; adding, editing, and switching setups are unavailable."] : [saveStatus],
1554
+ ...state.pathPolicy === "ignore-file" ? [manualIgnoreFileGuidance(state.ignoreFile ?? ".syncignore")] : []
1718
1555
  ],
1719
1556
  items: [
1720
1557
  ...state.pathPolicy === "ignore-file" ? ignoreAvailable ? [
1721
1558
  {
1722
1559
  id: "ignoreFile",
1723
1560
  label: "Ignore file",
1724
- description: "Select another existing file in the Pi agent directory. No transfer starts.",
1561
+ description: `Select another existing local file. Sessions: ${state.include.includes("sessions") ? "opted in (rules still apply)" : "off"}. No transfer starts.`,
1725
1562
  currentValue: safeTerminalText(state.ignoreFile ?? ".syncignore"),
1726
1563
  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
1564
  }
1743
- ] : state.reservedIgnoreNames !== void 0 ? [] : state.scope === "agent-directory" ? [
1565
+ ] : [] : state.reservedIgnoreNames !== void 0 && !ignoreAvailable ? [] : state.scope === "agent-directory" ? [
1744
1566
  {
1745
1567
  id: "include",
1746
1568
  label: "Agent directory scope",
@@ -1764,11 +1586,20 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1764
1586
  action: "exclude"
1765
1587
  }
1766
1588
  ],
1767
- ...state.reservedIgnoreNames !== void 0 ? [] : [
1589
+ ...ignoreAvailable && state.pathPolicy !== "ignore-file" ? [
1590
+ {
1591
+ id: "migrateIgnoreFile",
1592
+ label: "Migrate to ignore file\u2026",
1593
+ description: "Review the scope change for this legacy setup. Migration does not start a transfer.",
1594
+ currentValue: "Review",
1595
+ action: "ignore-migrate"
1596
+ }
1597
+ ] : [],
1598
+ ...state.reservedIgnoreNames !== void 0 && !ignoreAvailable ? [] : [
1768
1599
  {
1769
1600
  id: "remoteInclude",
1770
1601
  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.",
1602
+ 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
1603
  currentValue: "Review",
1773
1604
  action: "remote-include"
1774
1605
  }
@@ -1790,14 +1621,14 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1790
1621
  {
1791
1622
  id: "setups",
1792
1623
  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.",
1624
+ 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
1625
  currentValue: "Open",
1795
1626
  action: "setups"
1796
1627
  },
1797
1628
  {
1798
1629
  id: "connections",
1799
1630
  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.",
1631
+ 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
1632
  currentValue: "Open",
1802
1633
  action: "connections"
1803
1634
  },
@@ -1833,10 +1664,19 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1833
1664
  values: ["On", "Off"],
1834
1665
  action: "continuous"
1835
1666
  },
1667
+ ...ignoreAvailable && state.reservedIgnoreNames !== void 0 && (startupTransferEnabled(state) || state.automatic && syncSessionsSelected(state)) ? [
1668
+ {
1669
+ id: "authorizeAutomatic",
1670
+ label: "Review automatic transfers",
1671
+ description: "Separate approval for the enabled modes and exact current policy. Saving settings alone does not grant permission.",
1672
+ currentValue: "Review",
1673
+ action: "authorize-automatic"
1674
+ }
1675
+ ] : [],
1836
1676
  {
1837
1677
  id: "onSwitch",
1838
1678
  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.",
1679
+ 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
1680
  currentValue: setupSwitchActionLabel(state.onSwitch),
1841
1681
  values: SETUP_SWITCH_ACTION_OPTIONS.map(({ label }) => label),
1842
1682
  action: "on-switch"
@@ -1882,7 +1722,7 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1882
1722
  action: "debug"
1883
1723
  }
1884
1724
  ].map(
1885
- (item) => state.reservedIgnoreNames !== void 0 && !["setups", "connections", "ignoreFile", "ignoreRules", "migrateIgnoreFile"].includes(item.id) ? { ...item, disabled: true } : item
1725
+ (item) => state.reservedIgnoreNames !== void 0 && !ignoreAvailable && !["setups", "connections"].includes(item.id) ? { ...item, disabled: true } : item
1886
1726
  )
1887
1727
  })
1888
1728
  },
@@ -1906,13 +1746,13 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1906
1746
  const mutationSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
1907
1747
  const validate = captureMutationOwner(ctx, mutationSignal);
1908
1748
  try {
1909
- const previous = await loadConfig(setupName);
1749
+ const previous = await loadSettingsConfig(setupName);
1910
1750
  validate();
1911
1751
  const mergeContent = value === "Merge only" || value === "Merge + partial";
1912
1752
  const partialSync = value === "Partial only" || value === "Merge + partial";
1913
1753
  if (!await ctx.ui.confirm(
1914
1754
  "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.`,
1755
+ `${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
1756
  { signal: mutationSignal }
1917
1757
  ))
1918
1758
  return { kind: "rejected" };
@@ -1962,7 +1802,7 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1962
1802
  const mutationSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
1963
1803
  const validate = captureMutationOwner(ctx, mutationSignal);
1964
1804
  try {
1965
- const previous = await loadConfig(setupName);
1805
+ const previous = await loadSettingsConfig(setupName);
1966
1806
  validate();
1967
1807
  const input = await ctx.ui.input(
1968
1808
  "Machine-local settings.json root fields (JSON string array)",
@@ -1980,7 +1820,7 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1980
1820
  if (sameLocalFields(previous.localFields, fields)) return { kind: "stay" };
1981
1821
  const confirmed = await ctx.ui.confirm(
1982
1822
  "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.`,
1823
+ `${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
1824
  { signal: mutationSignal }
1985
1825
  );
1986
1826
  validate();
@@ -2013,7 +1853,7 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
2013
1853
  const automatic = value === "On";
2014
1854
  const mutationSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
2015
1855
  try {
2016
- const latest = await loadConfig(setupName);
1856
+ const latest = await loadSettingsConfig(setupName);
2017
1857
  if (mutationSignal.aborted) return { kind: "rejected" };
2018
1858
  if (latest.automatic === automatic) return { kind: "stay" };
2019
1859
  await updateSyncSetup(setupName, (setup) => ({ ...setup, sync: { ...setup.sync, automatic } }), {
@@ -2102,7 +1942,7 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
2102
1942
  const skipSecretScan = value === "On";
2103
1943
  const mutationSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
2104
1944
  try {
2105
- const latest = await loadConfig(setupName);
1945
+ const latest = await loadSettingsConfig(setupName);
2106
1946
  if (mutationSignal.aborted) return { kind: "rejected" };
2107
1947
  if (latest.skipSecretScan === skipSecretScan) return { kind: "stay" };
2108
1948
  await updateLocalConfig((settings) => ({ ...settings, skipSecretScan }), mutationSignal);
@@ -2118,7 +1958,7 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
2118
1958
  const showStatus = value === "On";
2119
1959
  const mutationSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
2120
1960
  try {
2121
- const latest = await loadConfig(setupName);
1961
+ const latest = await loadSettingsConfig(setupName);
2122
1962
  if (mutationSignal.aborted) return { kind: "rejected" };
2123
1963
  if (latest.showStatus === showStatus) return { kind: "stay" };
2124
1964
  await updateLocalConfig((settings) => ({ ...settings, showStatus }), mutationSignal);
@@ -2148,7 +1988,7 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
2148
1988
  if (!action) return { kind: "rejected" };
2149
1989
  const mutationSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
2150
1990
  try {
2151
- const latest = await loadConfig(setupName);
1991
+ const latest = await loadSettingsConfig(setupName);
2152
1992
  if (mutationSignal.aborted) return { kind: "rejected" };
2153
1993
  if (latest.onSwitch === action) return { kind: "stay" };
2154
1994
  await saveOnSwitch(action, mutationSignal);
@@ -2170,17 +2010,43 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
2170
2010
  await showExcludedPaths(ctx, setupName, editorSignal);
2171
2011
  return resumeSettings(editorSignal);
2172
2012
  },
2013
+ "authorize-automatic": async ({ state, signal: actionSignal }) => {
2014
+ const reviewSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
2015
+ const validate = captureMutationOwner(ctx, reviewSignal);
2016
+ const client = piDaemonClient(ctx);
2017
+ try {
2018
+ validate();
2019
+ const policy = await client.run("daemon.policy", {}, reviewSignal);
2020
+ validate();
2021
+ if (policy.setup !== state.setupName) return exitSettings();
2022
+ if (policy.automatic) {
2023
+ ctx.ui.notify("Automatic work is already approved for this setup and policy.", "info");
2024
+ return { kind: "stay" };
2025
+ }
2026
+ const accepted = await client.run(
2027
+ "daemon.authorize-connected",
2028
+ { fingerprint: policy.fingerprint },
2029
+ reviewSignal
2030
+ );
2031
+ validate();
2032
+ if (accepted === true) ctx.ui.notify("Automatic work approved for this setup and policy.", "info");
2033
+ return { kind: "stay" };
2034
+ } catch (error) {
2035
+ if (reviewSignal.aborted || !isCurrent()) return exitSettings();
2036
+ notifySaveFailure(ctx, error);
2037
+ return { kind: "rejected" };
2038
+ }
2039
+ },
2173
2040
  "ignore-switch": ignoreAction("switch"),
2174
- "ignore-edit": ignoreAction("edit"),
2175
2041
  "ignore-migrate": ignoreAction("migrate"),
2176
2042
  "remote-include": async ({ state, signal: actionSignal }) => {
2177
- if (state.reservedIgnoreNames !== void 0) return { kind: "rejected" };
2043
+ if (state.reservedIgnoreNames !== void 0 && !ignoreAvailable) return { kind: "rejected" };
2178
2044
  const reviewSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
2179
- const { showRemoteSelectionReview } = await import("./remote-selection-ui-4BTP2OJR.ts");
2045
+ const { showRemoteSelectionReview } = await import("./remote-selection-ui-GPITNEBF.ts");
2180
2046
  if (reviewSignal.aborted) return { kind: "rejected" };
2181
2047
  const review = await showRemoteSelectionReview(ctx, setupName, reviewSignal, void 0, {
2182
2048
  origin: "settings",
2183
- runRoute
2049
+ ...state.pathPolicy === "ignore-file" ? { readOnly: true } : { runRoute }
2184
2050
  });
2185
2051
  if (reviewSignal.aborted) return { kind: "rejected" };
2186
2052
  if (review.kind === "route-result") {
@@ -2208,7 +2074,7 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
2208
2074
  const result = await save(action);
2209
2075
  if (action.signal.aborted || signal?.aborted) return { kind: "rejected" };
2210
2076
  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.";
2077
+ 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
2078
  ctx.ui.notify(saveStatus, result?.kind === "rejected" ? "warning" : "info");
2213
2079
  return result;
2214
2080
  };
@@ -2218,6 +2084,12 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
2218
2084
  if (!ignoreAvailable || state.pathPolicy === "ignore-file" === (action === "migrate"))
2219
2085
  return { kind: "rejected" };
2220
2086
  const editorSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
2087
+ const latest = await loadSettingsConfig();
2088
+ if (editorSignal.aborted || !isCurrent()) return { kind: "close" };
2089
+ if (syncCheckConfigFingerprint(latest) !== syncCheckConfigFingerprint(state)) {
2090
+ ctx.ui.notify("Sync setup changed while Settings was open; reopen it before changing the policy.", "warning");
2091
+ return { kind: "close" };
2092
+ }
2221
2093
  await showIgnoreFileAction(ctx, setupName, action, state.ignoreFile ?? ".syncignore", editorSignal);
2222
2094
  return resumeSettings(editorSignal);
2223
2095
  };
@@ -2270,23 +2142,29 @@ async function showSyncManager(ctx, runRoute, sessionSignal, options = {}) {
2270
2142
  const menu = defineMenu5({
2271
2143
  start: "main",
2272
2144
  screens: {
2273
- main: ({ state }) => ({
2274
- kind: "choice",
2275
- title: "Manage sync",
2276
- lines: state.manager.title.split("\n").slice(1),
2277
- items: menuItems(state.manager).map((item) => ({
2278
- id: item.id,
2279
- label: ctx.mode === "tui" && item.id === "sync" ? "Sync\u2026" : item.label,
2280
- details: [item.description ?? "Review synced content."],
2281
- searchText: `${item.label} ${item.description ?? ""}`,
2282
- disabled: item.disabled,
2283
- disabledReason: item.disabledReason
2284
- })),
2285
- action: "activate",
2286
- enableSearch: true,
2287
- viewportSize: 5,
2288
- hint: "close"
2289
- })
2145
+ main: ({ state: { manager } }) => {
2146
+ const [title = "Manage sync", ...lines] = manager.title.split("\n");
2147
+ const setupName = ctx.mode === "tui" ? manager.configReview?.setupName : void 0;
2148
+ const setup = setupName === void 0 ? void 0 : safeTerminalText(setupName);
2149
+ const setupInHeading = setup !== void 0 && lines[0] === `Current sync setup: ${setup}`;
2150
+ return {
2151
+ kind: "choice",
2152
+ title: setupInHeading ? `${title} \xB7 ${setup}` : title,
2153
+ lines: setupInHeading ? lines.slice(1) : lines,
2154
+ items: menuItems(manager).map((item) => ({
2155
+ id: item.id,
2156
+ label: ctx.mode === "tui" && item.id === "sync" ? "Sync\u2026" : item.label,
2157
+ details: [item.description ?? "Review synced content."],
2158
+ searchText: `${item.label} ${item.description ?? ""}`,
2159
+ disabled: item.disabled,
2160
+ disabledReason: item.disabledReason
2161
+ })),
2162
+ action: "activate",
2163
+ enableSearch: true,
2164
+ viewportSize: 5,
2165
+ hint: "close"
2166
+ };
2167
+ }
2290
2168
  },
2291
2169
  actions: {
2292
2170
  activate: async (invocation) => {
@@ -2300,7 +2178,7 @@ async function showSyncManager(ctx, runRoute, sessionSignal, options = {}) {
2300
2178
  if (!attention) {
2301
2179
  const observation = state.manager.observation;
2302
2180
  if (!observation) return { kind: "stay" };
2303
- const { showRemoteSelectionReview } = await import("./remote-selection-ui-4BTP2OJR.ts");
2181
+ const { showRemoteSelectionReview } = await import("./remote-selection-ui-GPITNEBF.ts");
2304
2182
  if (sessionSignal?.aborted) return { kind: "close" };
2305
2183
  const config = await loadConfig();
2306
2184
  if (sessionSignal?.aborted) return { kind: "close" };
@@ -2559,7 +2437,13 @@ S3/R2 reads the latest pointer without writing. Git reads remote snapshots and c
2559
2437
  const describe = async (signal) => {
2560
2438
  const pendingAttention = options.getAttention?.();
2561
2439
  const observation = options.getObservation?.();
2562
- const manager = await describeManagerState(signal, pendingAttention, void 0, observation);
2440
+ const manager = await describeManagerState(
2441
+ signal,
2442
+ pendingAttention,
2443
+ void 0,
2444
+ observation,
2445
+ () => ignoreFileSettingsAvailable(ctx, signal)
2446
+ );
2563
2447
  if (signal.aborted || !isCurrent()) return manager;
2564
2448
  if (observation && options.getObservation?.() === observation && !manager.observation && !(manager.operation && operationBlocksChanges(manager.operation))) {
2565
2449
  options.onObservationInvalidated?.();
@@ -2634,4 +2518,4 @@ function syncMainMenuItem(label) {
2634
2518
  export {
2635
2519
  showSyncManager
2636
2520
  };
2637
- //# sourceMappingURL=manager-ui-AOFUNXAJ.ts.map
2521
+ //# sourceMappingURL=manager-ui-T5J5WG7T.ts.map