@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
@@ -1,7 +1,7 @@
1
1
  import fs from "node:fs/promises";
2
2
  import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
3
3
  import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
4
- import { loadConfig, syncCheckConfigFingerprint } from "../settings/config.js";
4
+ import { loadSettingsConfig, syncCheckConfigFingerprint } from "../settings/config.js";
5
5
  import { localConfigPath } from "../settings/config-file.js";
6
6
  import { updateSyncSetup } from "../settings/settings-management.js";
7
7
  import { agentDir } from "../snapshot/session-paths.js";
@@ -13,6 +13,7 @@ import {
13
13
  syncIncludeSelection,
14
14
  } from "../sync/sync-policy.js";
15
15
  import { showDirectoryScope } from "./excluded-paths-ui.js";
16
+ import { manualIgnoreFileGuidance } from "./ignore-file-guidance.js";
16
17
 
17
18
  const BUILT_IN_PREFIX = "builtin:";
18
19
  const CUSTOM_PREFIX = "custom:";
@@ -27,9 +28,13 @@ interface SelectionDraft {
27
28
 
28
29
  export async function showFileSelection(ctx: ExtensionCommandContext, setupName?: string, signal?: AbortSignal) {
29
30
  const validate = captureMutationOwner(ctx, signal);
30
- const config = await loadConfig(setupName);
31
+ const config = await loadSettingsConfig(setupName);
31
32
  if (signal?.aborted) return;
32
33
  validate();
34
+ if (config.pathPolicy === "ignore-file") {
35
+ if (ctx.hasUI) ctx.ui.notify(manualIgnoreFileGuidance(config.ignoreFile ?? ".syncignore"), "info");
36
+ return;
37
+ }
33
38
  if (config.scope === "agent-directory") return showDirectoryScope(ctx, config, signal);
34
39
  const selection = syncIncludeSelection(config.include);
35
40
  const original: SelectionDraft = {
@@ -0,0 +1,7 @@
1
+ import { resolve } from "node:path";
2
+ import { getAgentDir } from "@earendil-works/pi-coding-agent";
3
+ import { safeTerminalText } from "./terminal-text.js";
4
+
5
+ export function manualIgnoreFileGuidance(filename: string) {
6
+ return `Edit existing ignore rules manually: ${safeTerminalText(resolve(getAgentDir(), filename))}. Edits apply to every setup using this local file on its next sync; they do not rewrite remote history.`;
7
+ }
@@ -1,25 +1,12 @@
1
- import { resolve } from "node:path";
2
- import { type ExtensionCommandContext, getAgentDir } from "@earendil-works/pi-coding-agent";
3
- import { CURSOR_MARKER, Editor, isKeyRelease, Key, matchesKey, truncateToWidth } from "@earendil-works/pi-tui";
4
- import { HorizontalRule, hardWrapTerminalDocument, runCustomInteraction } from "@narumitw/pi-tui-kit";
1
+ import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
2
+ import { isKeyRelease, Key, matchesKey } from "@earendil-works/pi-tui";
5
3
  import { piDaemonClient } from "../daemon/pi-client.js";
6
4
  import { captureMutationOwner } from "../sync/sync-local.js";
7
5
  import { runCancellableTask } from "./cancellable-operation.js";
8
- import { confirmMergeReview } from "./merge-review.js";
6
+ import { trackOperationDialogs } from "./operation-dialogs.js";
9
7
  import { safeTerminalText } from "./terminal-text.js";
10
8
 
11
- interface IgnoreFile {
12
- filename: string;
13
- path: string;
14
- text: string;
15
- sourceDigest: string;
16
- identity: string;
17
- sharingSetups: string[];
18
- }
19
-
20
- type IgnoreOperation = "edit" | "switch" | "migrate";
21
-
22
- type EditorResult = { kind: "draft"; text: string } | { kind: "cancelled" | "unsafe" };
9
+ type IgnoreOperation = "switch" | "migrate";
23
10
 
24
11
  export async function ignoreFileSettingsAvailable(ctx: ExtensionCommandContext, signal?: AbortSignal) {
25
12
  if (signal?.aborted) return false;
@@ -33,10 +20,6 @@ export async function ignoreFileSettingsAvailable(ctx: ExtensionCommandContext,
33
20
  }
34
21
  }
35
22
 
36
- export function manualIgnoreFileGuidance(filename: string) {
37
- return `Edit existing ignore rules manually: ${safeTerminalText(resolve(getAgentDir(), filename))}`;
38
- }
39
-
40
23
  export async function showIgnoreFileAction(
41
24
  ctx: ExtensionCommandContext,
42
25
  setup: string,
@@ -45,11 +28,7 @@ export async function showIgnoreFileAction(
45
28
  signal: AbortSignal,
46
29
  offerToken?: string,
47
30
  ) {
48
- if (signal.aborted || !ctx.hasUI) return;
49
- if (ctx.mode !== "tui") {
50
- if (ctx.mode === "rpc" && action === "edit") ctx.ui.notify(manualIgnoreFileGuidance(filename), "info");
51
- return;
52
- }
31
+ if (signal.aborted || !ctx.hasUI || ctx.mode !== "tui") return;
53
32
  const validateOwner = captureMutationOwner(ctx, signal);
54
33
  const client = piDaemonClient(ctx);
55
34
  const isCurrent = () => {
@@ -61,102 +40,43 @@ export async function showIgnoreFileAction(
61
40
  return false;
62
41
  }
63
42
  };
64
- const work = async (
65
- method: "read" | "save" | "switch" | "migrate",
66
- message: string,
67
- payload: Record<string, unknown> = {},
68
- ) => {
69
- const result = await runCancellableTask(
70
- ctx,
71
- message,
72
- (workSignal, onCommit) => client.run(`ignore.${method}`, { setup, ...payload }, workSignal, ctx, onCommit),
73
- {
74
- signal,
75
- isCurrent,
76
- cancelledMessage: null,
77
- commitAware: method !== "read",
78
- cancelAcrossDialogs: method !== "read",
79
- },
80
- );
81
- return isCurrent() && result.kind === "completed" ? result : undefined;
82
- };
83
43
  try {
84
- if (action === "migrate") {
85
- const result = await work("migrate", "Preparing ignore-file migration review…", offerToken ? { offerToken } : {});
86
- if (isCurrent() && result?.value === "saved")
87
- ctx.ui.notify("Ignore-file policy saved locally. No transfer started.", "info");
88
- return;
89
- }
44
+ let payload: Record<string, unknown> = offerToken ? { offerToken } : {};
90
45
  if (action === "switch") {
91
46
  const entered = await askIgnoreFilename(ctx, filename, signal);
92
47
  if (!isCurrent() || !entered || entered === filename) return;
93
- const result = await work("switch", "Checking the selected ignore file for review…", {
94
- filename: entered,
95
- expectedFilename: filename,
96
- });
97
- if (isCurrent() && result?.value === "saved") ctx.ui.notify("Ignore file selected. No transfer started.", "info");
98
- return;
48
+ payload = { filename: entered, expectedFilename: filename };
99
49
  }
100
- const result = await work("read", "Opening existing ignore file…");
101
- if (!isCurrent() || !result) return;
102
- const source = decodeIgnoreFile(result.value);
103
- const path = safeTerminalText(source.path);
104
- if (!isEditorSafe(source.text)) {
50
+ if (!isCurrent()) return;
51
+ const result = await runCancellableTask(
52
+ ctx,
53
+ action === "migrate"
54
+ ? "Preparing ignore-file migration review…"
55
+ : "Checking the selected ignore file for review…",
56
+ (workSignal, onCommit, onDialog) =>
57
+ client.run(
58
+ `ignore.${action}`,
59
+ { setup, ...payload },
60
+ workSignal,
61
+ trackOperationDialogs(ctx, onDialog),
62
+ onCommit,
63
+ ),
64
+ { signal, isCurrent, cancelledMessage: null, commitAware: true, cancelAcrossDialogs: true },
65
+ );
66
+ if (isCurrent() && result.kind === "completed" && result.value === "saved") {
105
67
  ctx.ui.notify(
106
- `Pi cannot edit this file without changing or hiding some characters. Edit ${path} manually.`,
107
- "warning",
68
+ action === "migrate"
69
+ ? "Ignore-file policy saved locally. No transfer started."
70
+ : "Ignore file selected. No transfer started.",
71
+ "info",
108
72
  );
109
- return;
110
- }
111
- const sharing = source.sharingSetups.length
112
- ? `Also used by: ${source.sharingSetups.map((name) => `“${safeTerminalText(name)}”`).join(", ")}`
113
- : undefined;
114
- const draft = await editIgnoreText(ctx, source.text, path, sharing, signal, isCurrent);
115
- if (!isCurrent() || draft.kind !== "completed") return;
116
- if (draft.value.kind === "unsafe") {
117
- ctx.ui.notify(`Unsafe terminal characters in the draft. No save; edit ${path} manually.`, "warning");
118
- return;
119
73
  }
120
- if (draft.value.kind !== "draft" || draft.value.text === source.text) return;
121
- const text = draft.value.text;
122
- const lines = [
123
- path,
124
- ...(sharing ? [sharing] : []),
125
- "This replaces the local rules. Removing rules may expose more files on a later sync.",
126
- "No transfer starts; remote history is retained.",
127
- ];
128
- const confirmed = await confirmMergeReview(ctx, "Save ignore rules?", text, signal, isCurrent, "save rules", lines);
129
- if (!isCurrent() || !confirmed) return;
130
- const saved = await work("save", "Saving ignore rules…", {
131
- text,
132
- sourceDigest: source.sourceDigest,
133
- identity: source.identity,
134
- });
135
- if (isCurrent() && saved) ctx.ui.notify("Ignore rules saved. No transfer started.", "info");
136
74
  } catch (error) {
137
75
  if (isCurrent())
138
76
  ctx.ui.notify(`Pi Sync: ${safeTerminalText(error instanceof Error ? error.message : String(error))}`, "error");
139
77
  }
140
78
  }
141
79
 
142
- function decodeIgnoreFile(value: unknown): IgnoreFile {
143
- const file = value as Partial<IgnoreFile> | null;
144
- if (!file || typeof file.filename !== "string" || typeof file.path !== "string")
145
- throw new Error("Invalid ignore-file response from the daemon.");
146
- if (file.identity === undefined && file.text === undefined)
147
- throw new Error(`Ignore file does not exist: ${file.path}. No file was created.`);
148
- if (
149
- typeof file.text !== "string" ||
150
- typeof file.identity !== "string" ||
151
- file.identity.length === 0 ||
152
- typeof file.sourceDigest !== "string" ||
153
- !Array.isArray(file.sharingSetups) ||
154
- !file.sharingSetups.every((setup) => typeof setup === "string")
155
- )
156
- throw new Error("Invalid ignore-file response from the daemon.");
157
- return file as IgnoreFile;
158
- }
159
-
160
80
  async function askIgnoreFilename(ctx: ExtensionCommandContext, filename: string, signal: AbortSignal) {
161
81
  const cancel = new AbortController();
162
82
  const stop = ctx.ui.onTerminalInput((data) => {
@@ -175,97 +95,3 @@ async function askIgnoreFilename(ctx: ExtensionCommandContext, filename: string,
175
95
  stop();
176
96
  }
177
97
  }
178
-
179
- function isEditorSafe(text: string) {
180
- const flattened = text.replaceAll("\n", "");
181
- return flattened === safeTerminalText(flattened);
182
- }
183
-
184
- function editIgnoreText(
185
- ctx: ExtensionCommandContext,
186
- original: string,
187
- path: string,
188
- sharing: string | undefined,
189
- signal: AbortSignal,
190
- isCurrent: () => boolean,
191
- ) {
192
- return runCustomInteraction<EditorResult, ExtensionCommandContext>(ctx, {
193
- signal,
194
- isCurrent,
195
- create: ({ tui, theme, keybindings, complete, signal: editorSignal }) => {
196
- const muted = (line: string) => theme.fg("muted", line);
197
- const editor = new Editor(tui, {
198
- borderColor: (line) => theme.fg("borderMuted", line),
199
- selectList: {
200
- selectedPrefix: (line) => theme.fg("accent", line),
201
- selectedText: (line) => theme.fg("accent", line),
202
- description: muted,
203
- scrollInfo: muted,
204
- noMatch: muted,
205
- },
206
- });
207
- editor.setText(original);
208
- let text = original;
209
- let beforeChange = original;
210
- editor.onChange = () => {
211
- beforeChange = text;
212
- text = editor.getExpandedText();
213
- if (!isEditorSafe(text)) complete({ kind: "unsafe" });
214
- };
215
- editor.onSubmit = () => complete({ kind: "draft", text: beforeChange });
216
- const rule = new HorizontalRule({ ruleStyle: (line) => theme.fg("border", line) });
217
- let layout: { width: number; first: number; count: number; editorOffset: number } | undefined;
218
- return {
219
- get focused() {
220
- return editor.focused;
221
- },
222
- set focused(value: boolean) {
223
- editor.focused = value;
224
- },
225
- get capturesViewportInput() {
226
- return true;
227
- },
228
- render(width: number) {
229
- layout = undefined;
230
- if (editorSignal.aborted || !Number.isFinite(width) || width <= 0) return [];
231
- const terminalRows = Number.isFinite(tui.terminal.rows) ? Math.floor(tui.terminal.rows) : 24;
232
- const rows = Math.max(1, terminalRows - 3);
233
- const border = rows >= 5 ? rule.render(width) : [];
234
- const editorRows = editor.render(width).slice(1, -1);
235
- const header = [
236
- theme.fg("accent", theme.bold("Edit ignore rules")),
237
- muted("Submit to review; cancel to discard."),
238
- ...[path, ...(sharing ? [sharing] : [])].flatMap((line) =>
239
- hardWrapTerminalDocument(line, width).map(muted),
240
- ),
241
- ].slice(0, rows - 2 * border.length - 1);
242
- const available = rows - 2 * border.length - header.length;
243
- const cursorRow = editorRows.findIndex((line) => line.includes(CURSOR_MARKER));
244
- const offset = Math.max(0, cursorRow - available + 1);
245
- const body = editorRows.slice(offset, offset + available);
246
- layout = { width, first: border.length + header.length, count: body.length, editorOffset: offset + 1 };
247
- return [...border, ...header, ...body, ...border].map((line) => truncateToWidth(line, width, ""));
248
- },
249
- invalidate() {
250
- layout = undefined;
251
- rule.invalidate();
252
- editor.invalidate();
253
- },
254
- handleInput(data: string) {
255
- if (editorSignal.aborted || isKeyRelease(data)) return;
256
- if (matchesKey(data, Key.ctrl("c")) || keybindings.matches(data, "tui.select.cancel")) {
257
- complete({ kind: "cancelled" });
258
- return;
259
- }
260
- editor.handleInput(data);
261
- if (!editorSignal.aborted) tui.requestRender();
262
- },
263
- handleMouse(event: Parameters<Editor["handleMouse"]>[0]) {
264
- if (editorSignal.aborted || !layout || layout.width !== event.width) return;
265
- const y = event.y - layout.first;
266
- if (y >= 0 && y < layout.count) return editor.handleMouse({ ...event, y: y + layout.editorOffset });
267
- },
268
- };
269
- },
270
- });
271
- }
@@ -51,6 +51,7 @@ export async function describeManagerState(
51
51
  attention?: SyncAttentionState,
52
52
  inspectOperation: () => Promise<OperationAvailability> = inspectOperationAvailability,
53
53
  observation?: StartupObservation,
54
+ canUseIgnoreSettings?: () => Promise<boolean>,
54
55
  ): Promise<ManagerDescription> {
55
56
  let raw: PiSyncSettingsV3 | undefined;
56
57
  try {
@@ -92,23 +93,15 @@ export async function describeManagerState(
92
93
  actions: ["Sync setups…", "Storage connections…", "Help"],
93
94
  };
94
95
  }
96
+ let settingsConfig: AnySyncConfig | undefined;
95
97
  try {
96
- const settingsConfig = configFromSettings(raw);
97
- if (settingsConfig.reservedIgnoreNames !== undefined) {
98
- return {
99
- title: [
100
- "Manage sync",
101
- `Current sync setup: ${safeTerminalText(settingsConfig.setupName)}`,
102
- "Transfers are unavailable while ignore-file setups are configured.",
103
- ].join("\n"),
104
- actions: ["Settings", "Sync setups…", "Storage connections…", "Help"],
105
- settingsReview: {
106
- setupName: settingsConfig.setupName,
107
- fingerprint: syncCheckConfigFingerprint(settingsConfig),
108
- },
109
- };
98
+ settingsConfig = configFromSettings(raw);
99
+ if (settingsConfig.reservedIgnoreNames && canUseIgnoreSettings && !(await canUseIgnoreSettings())) {
100
+ throw new Error("the connected daemon does not support ignore-file setups");
110
101
  }
102
+ signal?.throwIfAborted();
111
103
  const config = await loadConfig();
104
+ signal?.throwIfAborted();
112
105
  const operation = await inspectOperation();
113
106
  const changesBlocked = operationBlocksChanges(operation);
114
107
  let currentAttention: SyncAttentionState | undefined;
@@ -157,7 +150,11 @@ export async function describeManagerState(
157
150
  "Manage sync",
158
151
  `Current sync setup: ${safeTerminalText(config.setupName)}`,
159
152
  `Storage: ${backendStorageDescription(config)}`,
160
- ...(config.scope ? ["Sync scope: Pi agent directory, with exclusions"] : []),
153
+ ...(config.pathPolicy === "ignore-file"
154
+ ? [`Sync scope: Pi agent directory · ignore file: ${safeTerminalText(config.ignoreFile ?? ".syncignore")}`]
155
+ : config.scope
156
+ ? ["Sync scope: Pi agent directory, with exclusions"]
157
+ : []),
161
158
  ...(syncState?.unresolved?.length
162
159
  ? [`Unresolved: ${syncState.unresolved.length} dependency groups · review needed`]
163
160
  : []),
@@ -192,6 +189,7 @@ export async function describeManagerState(
192
189
  title: (changesBlocked ? ["Manage sync", ...operationStatusLines(operation)] : ordinaryTitle).join("\n"),
193
190
  actions: operationActions(operation, noSyncedContent, canSwitch, mainActions),
194
191
  configReview: { setupName: config.setupName, fingerprint: syncCheckConfigFingerprint(config) },
192
+ settingsReview: { setupName: settingsConfig.setupName, fingerprint: syncCheckConfigFingerprint(settingsConfig) },
195
193
  operation,
196
194
  ...(currentObservation ? { observation: currentObservation } : {}),
197
195
  ...(currentAttention
@@ -204,6 +202,20 @@ export async function describeManagerState(
204
202
  };
205
203
  } catch (error) {
206
204
  if (signal?.aborted) throw error;
205
+ if (settingsConfig?.reservedIgnoreNames !== undefined) {
206
+ return {
207
+ title: [
208
+ "Manage sync",
209
+ `Current sync setup: ${safeTerminalText(settingsConfig.setupName)}`,
210
+ `Transfers are unavailable: ${safeTerminalText(errorMessage(error))}`,
211
+ ].join("\n"),
212
+ actions: ["Settings", "Sync setups…", "Storage connections…", "Help"],
213
+ settingsReview: {
214
+ setupName: settingsConfig.setupName,
215
+ fingerprint: syncCheckConfigFingerprint(settingsConfig),
216
+ },
217
+ };
218
+ }
207
219
  return {
208
220
  title: [
209
221
  "Manage sync",
@@ -5,6 +5,7 @@ import { loadConfig, loadSettingsConfig, syncCheckConfigFingerprint } from "../s
5
5
  import { operationBlocksChanges } from "../state/operation-availability.js";
6
6
  import { captureMutationOwner } from "../sync/sync-local.js";
7
7
  import { type RunRoute, runCancellableOperation } from "./cancellable-operation.js";
8
+ import { ignoreFileSettingsAvailable } from "./ignore-file-ui.js";
8
9
  import { showIgnoreMigrationPrompt } from "./ignore-migration-prompt.js";
9
10
  import {
10
11
  attentionMainMenuItems,
@@ -373,7 +374,9 @@ export async function showSyncManager(
373
374
  const describe = async (signal: AbortSignal) => {
374
375
  const pendingAttention = options.getAttention?.();
375
376
  const observation = options.getObservation?.();
376
- const manager = await describeManagerState(signal, pendingAttention, undefined, observation);
377
+ const manager = await describeManagerState(signal, pendingAttention, undefined, observation, () =>
378
+ ignoreFileSettingsAvailable(ctx, signal),
379
+ );
377
380
  if (signal.aborted || !isCurrent()) return manager;
378
381
  // A busy operation suppresses baseline reads, not the stored check-time hint.
379
382
  if (
@@ -2,7 +2,7 @@ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
2
  import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
3
3
  import { createSyncBackend, type SyncBackendFactory } from "../backends/backend-factory.js";
4
4
  import type { RemoteHead, SyncBackend } from "../backends/sync-backend.js";
5
- import { loadConfig, syncCheckConfigFingerprint, syncConfigReviewFingerprint } from "../settings/config.js";
5
+ import { loadConfig, syncConfigReviewFingerprint, syncSettingsConfigFingerprint } from "../settings/config.js";
6
6
  import { SyncSetupReviewChangedError, updateSyncSetup } from "../settings/settings-management.js";
7
7
  import type { AnySyncConfig } from "../settings/settings-types.js";
8
8
  import { sameSyncExclude } from "../sync/exclude-policy.js";
@@ -14,6 +14,7 @@ import {
14
14
  compareSyncInclude,
15
15
  inspectRemoteSelection,
16
16
  type RemoteSelectionDecision,
17
+ RemoteSelectionMismatchError,
17
18
  type RemoteSelectionState,
18
19
  sameSyncInclude,
19
20
  syncDirectoryPolicyKey,
@@ -33,6 +34,7 @@ export interface RemoteSelectionReviewOptions {
33
34
  decision?: RemoteSelectionDecision;
34
35
  origin?: RemoteSelectionOrigin;
35
36
  runRoute?: RunRoute;
37
+ readOnly?: boolean;
36
38
  cancelLabel?: string;
37
39
  /** The explicit mismatch is resolved or superseded; this does not imply file equality. */
38
40
  onSelectionResolved?: () => void;
@@ -72,26 +74,33 @@ export async function showRemoteSelectionReview(
72
74
  if (!inspected) return { kind: "stale" };
73
75
  // A successful fresh read can supersede an old explicit mismatch without
74
76
  // changing local settings. This is not user cancellation or proof of file equality.
75
- if (inspected.kind === "empty" || inspected.state.kind !== "different") {
77
+ if (inspected.kind === "empty" || (inspected.kind === "selection" && inspected.state.kind !== "different")) {
76
78
  options.onSelectionResolved?.();
77
79
  }
78
80
  if (inspected.kind === "empty") {
79
81
  ctx.ui.notify("Remote storage has no snapshot or synced-content list yet.", "info");
80
82
  return { kind: "back" };
81
83
  }
82
- if (inspected.state.kind === "same") {
83
- ctx.ui.notify("Remote synced content already matches this sync setup.", "info");
84
+ if (inspected.kind === "decision") {
85
+ decision = inspected.decision;
86
+ } else if (inspected.state.kind === "same") {
87
+ ctx.ui.notify(
88
+ inspected.state.ignorePolicyComparison === "match"
89
+ ? "Remote ignore-file policy matches this device."
90
+ : "Remote synced content already matches this sync setup.",
91
+ "info",
92
+ );
84
93
  return { kind: "back" };
85
- }
86
- if (inspected.state.kind === "legacy") {
94
+ } else if (inspected.state.kind === "legacy") {
87
95
  if (ctx.mode !== "tui") {
88
96
  ctx.ui.notify(formatLegacySummary(inspected.config, inspected.state.discovered), "info");
89
97
  return { kind: "back" };
90
98
  }
91
99
  await showLegacyDiscovery(ctx, inspected.config, inspected.state.discovered, signal);
92
100
  return signal?.aborted ? { kind: "stale" } : { kind: "back" };
101
+ } else {
102
+ decision = decisionFromState(inspected.config, inspected.state);
93
103
  }
94
- decision = decisionFromState(inspected.config, inspected.state);
95
104
  }
96
105
 
97
106
  if (ctx.mode !== "tui") {
@@ -132,6 +141,10 @@ export async function showRemoteSelectionReview(
132
141
  ctx.ui.notify("Remote storage no longer has a snapshot or synced-content list.", "warning");
133
142
  return { kind: "back" };
134
143
  }
144
+ if (refreshed.kind === "decision") {
145
+ currentDecision = refreshed.decision;
146
+ continue;
147
+ }
135
148
  if (refreshed.state.kind !== "different") {
136
149
  ctx.ui.notify(
137
150
  refreshed.state.kind === "same"
@@ -162,7 +175,7 @@ async function showSelectionDifference(
162
175
  runRoute: RunRoute | undefined,
163
176
  sessionSignal: AbortSignal | undefined,
164
177
  factory: SyncBackendFactory,
165
- options: Pick<RemoteSelectionReviewOptions, "cancelLabel" | "onSelectionResolved" | "withStateAccess">,
178
+ options: Pick<RemoteSelectionReviewOptions, "readOnly" | "cancelLabel" | "onSelectionResolved" | "withStateAccess">,
166
179
  validateOwner: () => void,
167
180
  ): Promise<DifferenceFlowResult> {
168
181
  type Screen = "choice" | "review" | "saved";
@@ -195,7 +208,7 @@ async function showSelectionDifference(
195
208
  : "Compare exact remote-only, device-only, and ordered lists.",
196
209
  to: "review",
197
210
  },
198
- ...(adoptionUnavailable(state.decision)
211
+ ...(options.readOnly || adoptionUnavailable(state.decision)
199
212
  ? []
200
213
  : [
201
214
  {
@@ -205,7 +218,7 @@ async function showSelectionDifference(
205
218
  action: "adopt" as const,
206
219
  },
207
220
  ]),
208
- ...(!canPublishLocalPolicy(state.decision)
221
+ ...(options.readOnly || !canPublishLocalPolicy(state.decision)
209
222
  ? []
210
223
  : [
211
224
  {
@@ -255,6 +268,7 @@ async function showSelectionDifference(
255
268
  },
256
269
  actions: {
257
270
  adopt: async ({ state, signal: actionSignal }) => {
271
+ if (options.readOnly) return { kind: "rejected" };
258
272
  const signal = combineSignals(sessionSignal, actionSignal);
259
273
  try {
260
274
  const adoption = await runCancellableTask(
@@ -323,7 +337,7 @@ async function showSelectionDifference(
323
337
  if (adoption.kind === "cancelled" || !adoption.value) return { kind: "stay" as const };
324
338
  validateOwner();
325
339
  options.onSelectionResolved?.();
326
- continuationFingerprint = syncCheckConfigFingerprint({
340
+ continuationFingerprint = syncSettingsConfigFingerprint({
327
341
  ...adoption.value.config,
328
342
  include: [...state.decision.remoteInclude],
329
343
  exclude: adoptedExclude(state.decision),
@@ -345,6 +359,7 @@ async function showSelectionDifference(
345
359
  }
346
360
  },
347
361
  keep: async ({ state, signal: actionSignal }) => {
362
+ if (options.readOnly) return { kind: "rejected" };
348
363
  if (!canPublishLocalPolicy(state.decision)) return { kind: "stay" as const };
349
364
  if (!runRoute) {
350
365
  ctx.ui.notify("The reviewed update-remote route is unavailable.", "error");
@@ -383,13 +398,14 @@ async function showSelectionDifference(
383
398
  }
384
399
  },
385
400
  continue: async ({ state, signal: actionSignal }) => {
401
+ if (options.readOnly) return { kind: "rejected" };
386
402
  if (!runRoute || !continuationFingerprint) return { kind: "stay" as const };
387
403
  const signal = combineSignals(sessionSignal, actionSignal);
388
404
  try {
389
405
  const latest = await loadConfig(state.decision.setupName);
390
406
  if (signal.aborted) return { kind: "close" as const };
391
407
  validateOwner();
392
- if (syncCheckConfigFingerprint(latest) !== continuationFingerprint) {
408
+ if (syncSettingsConfigFingerprint(latest) !== continuationFingerprint) {
393
409
  throw new StaleRemoteSelectionReviewError(
394
410
  `Sync setup “${safeTerminalText(state.decision.setupName)}” changed after the remote content list was saved.`,
395
411
  );
@@ -546,7 +562,7 @@ async function revalidateAndAdopt(
546
562
  };
547
563
  },
548
564
  {
549
- expectedConfigFingerprint: syncCheckConfigFingerprint(review.config),
565
+ expectedConfigFingerprint: syncSettingsConfigFingerprint(review.config),
550
566
  expectedInclude: decision.localInclude,
551
567
  upgradeExclude: adoptedExclude(decision) !== undefined,
552
568
  signal,
@@ -563,6 +579,7 @@ async function inspectConfiguredRemoteSelection(
563
579
  ): Promise<
564
580
  | { kind: "empty"; config: AnySyncConfig }
565
581
  | { kind: "selection"; config: AnySyncConfig; state: RemoteSelectionState }
582
+ | { kind: "decision"; decision: RemoteSelectionDecision }
566
583
  | undefined
567
584
  > {
568
585
  const config = await loadConfig(setupName);
@@ -576,14 +593,21 @@ async function inspectConfiguredRemoteSelection(
576
593
  if (signal?.aborted) return undefined;
577
594
  validateOwner();
578
595
  if (!head) return { kind: "empty", config };
579
- const snapshot = await readSnapshotForHead(backend, head, signal);
580
- if (signal?.aborted) return undefined;
581
- validateOwner();
582
- return {
583
- kind: "selection",
584
- config,
585
- state: inspectRemoteSelection(config.include, snapshot, config.exclude, config),
586
- };
596
+ try {
597
+ const snapshot = await readSnapshotForHead(backend, head, signal, config);
598
+ if (signal?.aborted) return undefined;
599
+ validateOwner();
600
+ return {
601
+ kind: "selection",
602
+ config,
603
+ state: inspectRemoteSelection(config.include, snapshot, config.exclude, config),
604
+ };
605
+ } catch (error) {
606
+ if (signal?.aborted) return undefined;
607
+ validateOwner();
608
+ if (error instanceof RemoteSelectionMismatchError) return { kind: "decision", decision: error.decision };
609
+ throw error;
610
+ }
587
611
  }
588
612
 
589
613
  async function showLegacyDiscovery(
@@ -699,9 +723,12 @@ function selectionSummaryLines(decision: RemoteSelectionDecision) {
699
723
  return [
700
724
  `Sync setup: ${safeTerminalText(decision.setupName)}`,
701
725
  adoptionUnavailable(decision) ?? "Nothing changed.",
702
- decision.ignorePolicyComparison === "local-legacy-remote-ignore"
703
- ? "The remote uses an ignore policy. Migrate and review your local setup before transferring."
704
- : "Review a fresh push before publishing this device's policy. No files or settings have changed.",
726
+ ...(decision.ignorePolicyComparison === "local-legacy-remote-ignore"
727
+ ? ["The remote uses an ignore-file policy; this device uses a legacy policy."]
728
+ : decision.ignorePolicyComparison === "local-ignore-remote-legacy"
729
+ ? ["This device uses an ignore-file policy; the remote uses a legacy policy."]
730
+ : ["The ordered rules or session opt-in differ."]),
731
+ "No files or settings have changed.",
705
732
  ];
706
733
  }
707
734
  const comparison = compareSyncInclude(decision.localInclude, decision.remoteInclude);