@narumitw/pi-sync 0.65.0 → 0.67.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 (84) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +13 -4
  3. package/dist/chunks/{chunk-OWEOZZZE.ts → chunk-5YOLQKNZ.ts} +38 -2
  4. package/dist/chunks/chunk-5YOLQKNZ.ts.map +7 -0
  5. package/dist/chunks/{chunk-OBVJTKVY.ts → chunk-ASU3GZPW.ts} +10 -92
  6. package/dist/chunks/chunk-ASU3GZPW.ts.map +7 -0
  7. package/dist/chunks/{chunk-IOM6E5FW.ts → chunk-BESRBKVO.ts} +2 -2
  8. package/dist/chunks/{chunk-TZMVSTAM.ts → chunk-BYVHABNR.ts} +4 -4
  9. package/dist/chunks/chunk-ECYCNZOE.ts +12 -0
  10. package/dist/chunks/chunk-ECYCNZOE.ts.map +7 -0
  11. package/dist/chunks/{chunk-MANNB4WZ.ts → chunk-KNEUL4XN.ts} +1 -7
  12. package/dist/chunks/chunk-KNEUL4XN.ts.map +7 -0
  13. package/dist/chunks/chunk-Z5JMOXJM.ts +106 -0
  14. package/dist/chunks/chunk-Z5JMOXJM.ts.map +7 -0
  15. package/dist/chunks/{command-handler-YZ4DXQ7N.ts → command-handler-SQC2L2FJ.ts} +9 -7
  16. package/dist/chunks/{command-handler-YZ4DXQ7N.ts.map → command-handler-SQC2L2FJ.ts.map} +1 -1
  17. package/dist/chunks/{file-selection-DDQN4LVD.ts → file-selection-XWACUTAH.ts} +8 -8
  18. package/dist/chunks/ignore-file-ui-OHFISFVC.ts +21 -0
  19. package/dist/chunks/{manager-result-dispatcher-XB75YLEG.ts → manager-result-dispatcher-WXE2BAQO.ts} +3 -3
  20. package/dist/chunks/{manager-ui-RGA26Z6G.ts → manager-ui-DWOMAJKE.ts} +170 -45
  21. package/dist/chunks/manager-ui-DWOMAJKE.ts.map +7 -0
  22. package/dist/chunks/{remote-selection-ui-WVMET5RI.ts → remote-selection-ui-E4XZCQ7A.ts} +2 -2
  23. package/dist/chunks/remote-selection-ui-E4XZCQ7A.ts.map +7 -0
  24. package/dist/chunks/{setup-wizard-YP2KF2WQ.ts → setup-wizard-IEW56AZE.ts} +7 -5
  25. package/dist/chunks/{setup-wizard-YP2KF2WQ.ts.map → setup-wizard-IEW56AZE.ts.map} +1 -1
  26. package/dist/daemon/dist/consent.js +14 -2
  27. package/dist/daemon/dist/engine/backends/git/git-backend.js +5 -3
  28. package/dist/daemon/dist/engine/backends/git/git-storage.js +15 -3
  29. package/dist/daemon/dist/engine/ignore/adoption-journal.js +143 -0
  30. package/dist/daemon/dist/engine/ignore/ignore-edit.js +2 -2
  31. package/dist/daemon/dist/engine/ignore/ignore-settings.js +2 -1
  32. package/dist/daemon/dist/engine/ignore/snapshot-ignore-rules.js +39 -0
  33. package/dist/daemon/dist/engine/settings/config-file.js +3 -0
  34. package/dist/daemon/dist/engine/settings/config.js +5 -5
  35. package/dist/daemon/dist/engine/settings/settings-management.js +6 -1
  36. package/dist/daemon/dist/engine/settings/settings-validation.js +21 -2
  37. package/dist/daemon/dist/engine/snapshot/snapshot-apply.js +2 -2
  38. package/dist/daemon/dist/engine/snapshot/snapshot-codec.js +6 -6
  39. package/dist/daemon/dist/engine/snapshot/snapshot-types.js +5 -1
  40. package/dist/daemon/dist/engine/snapshot/snapshot.js +5 -2
  41. package/dist/daemon/dist/engine/sync/conflict-review.js +2 -0
  42. package/dist/daemon/dist/engine/sync/continuous-errors.js +6 -0
  43. package/dist/daemon/dist/engine/sync/continuous-sync.js +4 -2
  44. package/dist/daemon/dist/engine/sync/continuous-watch.js +3 -2
  45. package/dist/daemon/dist/engine/sync/directional-action.js +3 -8
  46. package/dist/daemon/dist/engine/sync/ignore-adoption-recovery.js +50 -0
  47. package/dist/daemon/dist/engine/sync/ignore-adoption.js +410 -0
  48. package/dist/daemon/dist/engine/sync/ignore-publication.js +23 -0
  49. package/dist/daemon/dist/engine/sync/initialization.js +12 -0
  50. package/dist/daemon/dist/engine/sync/local-fields.js +6 -3
  51. package/dist/daemon/dist/engine/sync/merge-apply.js +18 -1
  52. package/dist/daemon/dist/engine/sync/merge-journal.js +2 -2
  53. package/dist/daemon/dist/engine/sync/merged-sync.js +50 -7
  54. package/dist/daemon/dist/engine/sync/push-review.js +33 -0
  55. package/dist/daemon/dist/engine/sync/sync-local.js +2 -1
  56. package/dist/daemon/dist/engine/sync/sync-mutations.js +108 -55
  57. package/dist/daemon/dist/engine/sync/sync-policy.js +5 -5
  58. package/dist/daemon/dist/engine/sync/sync-queries.js +1 -1
  59. package/dist/daemon/dist/engine/sync/sync-rollback.js +25 -5
  60. package/dist/daemon/dist/engine/sync/transfer-freshness.js +3 -2
  61. package/dist/daemon/dist/engine/sync/transfer-size-limits.js +92 -0
  62. package/dist/daemon/dist/engine/ui/ignore-rule-preview.js +18 -0
  63. package/dist/daemon/dist/engine-service.js +1 -1
  64. package/dist/daemon/package.json +1 -1
  65. package/dist/index.ts +1 -1
  66. package/docs/daemon-migration.md +6 -0
  67. package/docs/tui-contract.md +6 -5
  68. package/package.json +2 -2
  69. package/skills/configure-pi-sync/SKILL.md +1 -1
  70. package/skills/configure-pi-sync/references/configuration.md +43 -14
  71. package/src/ui/ignore-file-ui.ts +13 -5
  72. package/src/ui/manager-state.ts +15 -8
  73. package/src/ui/manager-ui.ts +1 -1
  74. package/src/ui/remote-selection-ui.ts +43 -2
  75. package/src/ui/settings-ui.ts +156 -32
  76. package/dist/chunks/chunk-MANNB4WZ.ts.map +0 -7
  77. package/dist/chunks/chunk-OBVJTKVY.ts.map +0 -7
  78. package/dist/chunks/chunk-OWEOZZZE.ts.map +0 -7
  79. package/dist/chunks/manager-ui-RGA26Z6G.ts.map +0 -7
  80. /package/dist/chunks/{chunk-IOM6E5FW.ts.map → chunk-BESRBKVO.ts.map} +0 -0
  81. /package/dist/chunks/{chunk-TZMVSTAM.ts.map → chunk-BYVHABNR.ts.map} +0 -0
  82. /package/dist/chunks/{file-selection-DDQN4LVD.ts.map → file-selection-XWACUTAH.ts.map} +0 -0
  83. /package/dist/chunks/{manager-result-dispatcher-XB75YLEG.ts.map → ignore-file-ui-OHFISFVC.ts.map} +0 -0
  84. /package/dist/chunks/{remote-selection-ui-WVMET5RI.ts.map → manager-result-dispatcher-WXE2BAQO.ts.map} +0 -0
@@ -492,7 +492,7 @@ function syncMainMenuItem(
492
492
  push: "This device → remote; replaces conflicting remote files.",
493
493
  diff: "Inspect changes; no transfer.",
494
494
  status: "Check remote; no transfer.",
495
- settings: "Change sync settings.",
495
+ settings: "Edit settings, setups, and storage connections.",
496
496
  history: "Review snapshots and rollback.",
497
497
  doctor: "Review backend diagnostics.",
498
498
  switch: "Choose another sync setup.",
@@ -179,12 +179,19 @@ async function showSelectionDifference(
179
179
  validateOwner: () => void,
180
180
  ): Promise<DifferenceFlowResult> {
181
181
  type Screen = "choice" | "review" | "saved";
182
- type Action = "adopt" | "keep" | "cancel" | "continue" | "done";
182
+ type Action = "adopt" | "keep" | "pull-rules" | "cancel" | "continue" | "done";
183
183
  interface FlowState {
184
184
  decision: RemoteSelectionDecision;
185
185
  saved: boolean;
186
186
  }
187
187
  const isCurrent = () => isReviewOwnerCurrent(validateOwner);
188
+ const canReviewPull = Boolean(
189
+ runRoute &&
190
+ !options.readOnly &&
191
+ initialDecision.ignorePolicyComparison === "mismatch" &&
192
+ (await (await import("./ignore-file-ui.js")).portableIgnoreRulesAvailable(ctx, sessionSignal)),
193
+ );
194
+ if (!isCurrent()) return { kind: "stale" };
188
195
  let flowState: FlowState = { decision: initialDecision, saved: false };
189
196
  let continuationFingerprint: string | undefined;
190
197
  let nextResult: RemoteSelectionReviewResult | undefined;
@@ -218,6 +225,16 @@ async function showSelectionDifference(
218
225
  action: "adopt" as const,
219
226
  },
220
227
  ]),
228
+ ...(canReviewPull
229
+ ? [
230
+ {
231
+ id: "pull-rules",
232
+ label: "Review pulling the remote rules…",
233
+ description: "Preview overwriting this device's rules and files if the snapshot includes rules.",
234
+ action: "pull-rules" as const,
235
+ },
236
+ ]
237
+ : []),
221
238
  ...(options.readOnly || !canPublishLocalPolicy(state.decision)
222
239
  ? []
223
240
  : [
@@ -358,6 +375,30 @@ async function showSelectionDifference(
358
375
  return { kind: "stay" as const };
359
376
  }
360
377
  },
378
+ "pull-rules": async ({ state, signal: actionSignal }) => {
379
+ if (!canReviewPull || !runRoute) return { kind: "rejected" };
380
+ const signal = combineSignals(sessionSignal, actionSignal);
381
+ try {
382
+ const latest = await loadConfig(state.decision.setupName);
383
+ if (signal.aborted) return { kind: "close" };
384
+ validateOwner();
385
+ if (syncConfigReviewFingerprint(latest) !== state.decision.configIdentity) {
386
+ refreshRequested = true;
387
+ return { kind: "close" };
388
+ }
389
+ const result = await runCancellableOperation(ctx, "Preparing remote policy preview…", "pull", runRoute, {
390
+ commitAware: true,
391
+ cancelAcrossDialogs: true,
392
+ target: state.decision.setupName,
393
+ signal,
394
+ });
395
+ return handleNestedRouteResult(result, "pull");
396
+ } catch (error) {
397
+ if (signal.aborted || !isCurrent()) return { kind: "close" };
398
+ ctx.ui.notify(`Could not prepare the local update: ${errorMessage(error)}`, "error");
399
+ return { kind: "stay" };
400
+ }
401
+ },
361
402
  keep: async ({ state, signal: actionSignal }) => {
362
403
  if (options.readOnly) return { kind: "rejected" };
363
404
  if (!canPublishLocalPolicy(state.decision)) return { kind: "stay" as const };
@@ -681,7 +722,7 @@ function canPublishLocalPolicy(decision: RemoteSelectionDecision) {
681
722
 
682
723
  function adoptionUnavailable(decision: RemoteSelectionDecision) {
683
724
  if (decision.ignorePolicyComparison)
684
- return "Ignore files are local. Published metadata cannot reconstruct remote rules.";
725
+ return "A policy comparison does not apply rules. A reviewed Pull can use a snapshot that contains rule text.";
685
726
  if (scopesDiffer(decision))
686
727
  return "Scope differs. Configure a setup with the remote scope to join it; this location is not migrated in place.";
687
728
  if (
@@ -1,4 +1,5 @@
1
1
  import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
2
+ import { isKeyRelease, Key, matchesKey } from "@earendil-works/pi-tui";
2
3
  import { defineMenu, type MenuSettingItem, runMenu } from "@narumitw/pi-tui-kit";
3
4
  import { piDaemonClient } from "../daemon/pi-client.js";
4
5
  import { configFromSettings, loadSettingsConfig, syncCheckConfigFingerprint } from "../settings/config.js";
@@ -37,6 +38,22 @@ import { safeTerminalText } from "./terminal-text.js";
37
38
 
38
39
  export type SyncSettingsRoute = RunRoute;
39
40
 
41
+ type SettingsState = Awaited<ReturnType<typeof loadSettingsConfig>>;
42
+ const transferSizeLimits = [
43
+ {
44
+ field: "maxFileSizeMiB",
45
+ label: "Max file size",
46
+ description: "Block a transfer when an included file exceeds this uncompressed size.",
47
+ },
48
+ {
49
+ field: "maxDirectorySizeMiB",
50
+ label: "Max directory size",
51
+ description:
52
+ "Block a transfer when a directory below the sync root exceeds this total uncompressed size, counting included files in its subdirectories too.",
53
+ },
54
+ ] as const;
55
+ type TransferSizeLimit = (typeof transferSizeLimits)[number];
56
+
40
57
  export async function showSyncSettings(
41
58
  ctx: ExtensionCommandContext,
42
59
  runRoute: SyncSettingsRoute,
@@ -63,7 +80,7 @@ export async function showSyncSettings(
63
80
  const document = await readActiveLocalConfigDocumentForRepair().catch(() => null);
64
81
  if (!isCurrent()) return disposition;
65
82
  const settingsPath = document?.path ?? localConfigPath();
66
- let config: Awaited<ReturnType<typeof loadSettingsConfig>> | undefined;
83
+ let config: ReturnType<typeof configFromSettings> | undefined;
67
84
  try {
68
85
  if (document) config = configFromSettings(validateSettingsDocument(document.parsed), reviewedSetup);
69
86
  } catch {
@@ -77,6 +94,12 @@ export async function showSyncSettings(
77
94
  ? "Could not read the active pi-sync settings file. Check file access or repair the JSON before reopening /sync."
78
95
  : `Edit pi-sync settings manually: ${safeTerminalText(settingsPath)}`,
79
96
  ...(limited ? [IGNORE_SETUP_MANAGEMENT_LIMIT, ...ignoreSetupRecovery(settingsPath)] : []),
97
+ ...(!limited && config
98
+ ? [
99
+ "In the active entry in syncSetups, set sync.maxFileSizeMiB or sync.maxDirectorySizeMiB to a positive whole number of MiB with a safe byte count. Remove a field to turn that limit Off.",
100
+ "A limit requires settings version 9. Upgrade all Pi Sync clients and daemons that share this agent directory before enabling a limit. Keep version 9 even if both limits are later Off.",
101
+ ]
102
+ : []),
80
103
  ...(!limited && config?.reservedIgnoreNames !== undefined
81
104
  ? ["Use TUI Settings → Review automatic transfers to approve the current setup separately."]
82
105
  : []),
@@ -120,8 +143,8 @@ export async function showSyncSettings(
120
143
  const ignoreAvailable = await ignoreFileSettingsAvailable(ctx, signal);
121
144
  if (!isCurrent()) return disposition;
122
145
  const setupName = initial.setupName;
123
- type SettingsState = Awaited<ReturnType<typeof loadSettingsConfig>>;
124
146
  type Action =
147
+ | TransferSizeLimit["field"]
125
148
  | "automatic"
126
149
  | "automatic-transfer"
127
150
  | "agent-mode"
@@ -142,7 +165,6 @@ export async function showSyncSettings(
142
165
  | "storage-location"
143
166
  | "setups"
144
167
  | "connections";
145
- let saveStatus = "Simple choices save immediately. Back does not undo saved changes.";
146
168
  // Keep Kit's existing settings adapter: native SettingsList has no async save/rollback
147
169
  // contract or injected keybindings. Kit preserves these safety and accessibility behaviors.
148
170
  const menu = defineMenu<SettingsState, "settings", Action, ExtensionCommandContext>({
@@ -155,7 +177,7 @@ export async function showSyncSettings(
155
177
  `Setup: ${safeTerminalText(state.setupName)} · Connection: ${safeTerminalText(state.connectionName)}`,
156
178
  ...(state.reservedIgnoreNames !== undefined && !ignoreAvailable
157
179
  ? ["Setup preferences are read-only; adding, editing, and switching setups are unavailable."]
158
- : [saveStatus]),
180
+ : ["Back does not undo saved changes."]),
159
181
  ...(state.pathPolicy === "ignore-file" ? [manualIgnoreFileGuidance(state.ignoreFile ?? ".syncignore")] : []),
160
182
  ],
161
183
  items: (
@@ -239,6 +261,13 @@ export async function showSyncSettings(
239
261
  currentValue: `${state.localFields?.length ?? 0} fields · Edit`,
240
262
  action: "local-fields",
241
263
  },
264
+ ...transferSizeLimits.map(({ field, label, description }) => ({
265
+ id: field,
266
+ label,
267
+ description: `This setup: ${description} Also applies to automatic transfers. Saving starts no transfer.`,
268
+ currentValue: transferSizeLimitLabel(state[field]),
269
+ action: field,
270
+ })),
242
271
  {
243
272
  id: "storageLocation",
244
273
  label: "Storage location",
@@ -387,6 +416,8 @@ export async function showSyncSettings(
387
416
  }),
388
417
  },
389
418
  actions: {
419
+ maxFileSizeMiB: transferSizeLimitAction(transferSizeLimits[0]),
420
+ maxDirectorySizeMiB: transferSizeLimitAction(transferSizeLimits[1]),
390
421
  "storage-location": async ({ signal: actionSignal }) => {
391
422
  const editorSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
392
423
  await showEditSyncSetupStorage(ctx, setupName, editorSignal);
@@ -413,7 +444,7 @@ export async function showSyncSettings(
413
444
  if (
414
445
  !(await ctx.ui.confirm(
415
446
  "Save content policy?",
416
- `${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.`,
447
+ `${previous.pathPolicy === "ignore-file" ? `Ignore-file policy keeps settings version ${previous.settingsVersion} and publishes snapshot version 7; upgrade older clients first.` : 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.`,
417
448
  { signal: mutationSignal },
418
449
  ))
419
450
  )
@@ -440,9 +471,10 @@ export async function showSyncSettings(
440
471
  };
441
472
  }, mutationSignal);
442
473
  validate();
443
- saveStatus =
444
- "Saved reviewed policy for this setup. Applies to subsequent sync operations; recovery evidence is retained.";
445
- ctx.ui.notify(saveStatus, "info");
474
+ ctx.ui.notify(
475
+ "Saved reviewed policy for this setup. Applies to subsequent sync operations; recovery evidence is retained.",
476
+ "info",
477
+ );
446
478
  return { kind: "stay" };
447
479
  } catch (error) {
448
480
  if (!mutationSignal.aborted) notifySaveFailure(ctx, error);
@@ -488,7 +520,7 @@ export async function showSyncSettings(
488
520
  if (sameLocalFields(previous.localFields, fields)) return { kind: "stay" };
489
521
  const confirmed = await ctx.ui.confirm(
490
522
  "Save portable field policy?",
491
- `${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.`,
523
+ `${previous.pathPolicy === "ignore-file" ? `Ignore-file policy keeps settings version ${previous.settingsVersion} and publishes snapshot version 7.` : 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.`,
492
524
  { signal: mutationSignal },
493
525
  );
494
526
  validate();
@@ -513,9 +545,10 @@ export async function showSyncSettings(
513
545
  };
514
546
  }, mutationSignal);
515
547
  validate();
516
- saveStatus =
517
- "Saved reviewed policy for this setup. Applies to subsequent sync operations; recovery evidence is retained.";
518
- ctx.ui.notify(saveStatus, "info");
548
+ ctx.ui.notify(
549
+ "Saved reviewed policy for this setup. Applies to subsequent sync operations; recovery evidence is retained.",
550
+ "info",
551
+ );
519
552
  return { kind: "stay" };
520
553
  } catch (error) {
521
554
  if (!mutationSignal.aborted) notifySaveFailure(ctx, error);
@@ -533,10 +566,6 @@ export async function showSyncSettings(
533
566
  signal: mutationSignal,
534
567
  });
535
568
  if (mutationSignal.aborted) return { kind: "rejected" };
536
- ctx.ui.notify(
537
- `Automatic sync ${automatic ? "enabled" : "disabled"} for “${safeTerminalText(setupName)}”.`,
538
- "info",
539
- );
540
569
  return { kind: "stay" };
541
570
  } catch (error) {
542
571
  if (!mutationSignal.aborted) notifySaveFailure(ctx, error);
@@ -606,10 +635,6 @@ export async function showSyncSettings(
606
635
  signal: mutationSignal,
607
636
  });
608
637
  if (mutationSignal.aborted) return { kind: "rejected" };
609
- ctx.ui.notify(
610
- `Automatic startup transfer ${automaticTransfer ? "enabled for the next session start" : "disabled"}. Completed transfers are not undone.`,
611
- "info",
612
- );
613
638
  return { kind: "stay" };
614
639
  } catch (error) {
615
640
  if (!mutationSignal.aborted) notifySaveFailure(ctx, error);
@@ -625,7 +650,6 @@ export async function showSyncSettings(
625
650
  if (latest.skipSecretScan === skipSecretScan) return { kind: "stay" };
626
651
  await updateLocalConfig((settings) => ({ ...settings, skipSecretScan }), mutationSignal);
627
652
  if (mutationSignal.aborted) return { kind: "rejected" };
628
- ctx.ui.notify(`Secret scan ${skipSecretScan ? "disabled" : "enabled"} for pushes in all setups.`, "info");
629
653
  return { kind: "stay" };
630
654
  } catch (error) {
631
655
  if (!mutationSignal.aborted) notifySaveFailure(ctx, error);
@@ -642,7 +666,6 @@ export async function showSyncSettings(
642
666
  await updateLocalConfig((settings) => ({ ...settings, showStatus }), mutationSignal);
643
667
  if (mutationSignal.aborted) return { kind: "rejected" };
644
668
  configureSyncStatus(ctx, showStatus);
645
- ctx.ui.notify(`Pi Sync status ${showStatus ? "enabled" : "disabled"} for all setups.`, "info");
646
669
  return { kind: "stay" };
647
670
  } catch (error) {
648
671
  if (!mutationSignal.aborted) notifySaveFailure(ctx, error);
@@ -671,7 +694,6 @@ export async function showSyncSettings(
671
694
  if (latest.onSwitch === action) return { kind: "stay" };
672
695
  await saveOnSwitch(action, mutationSignal);
673
696
  if (mutationSignal.aborted) return { kind: "rejected" };
674
- ctx.ui.notify(`After switching setup: ${value}.`, "info");
675
697
  return { kind: "stay" };
676
698
  } catch (error) {
677
699
  if (!mutationSignal.aborted) notifySaveFailure(ctx, error);
@@ -756,18 +778,106 @@ export async function showSyncSettings(
756
778
  const result = await save(action);
757
779
  if (action.signal.aborted || signal?.aborted) return { kind: "rejected" };
758
780
  validate();
759
- saveStatus =
760
- result?.kind === "rejected"
761
- ? "Save failed or rejected. Previous value retained; retry is available."
762
- : id === "automatic-transfer" || id === "automatic" || id === "debug"
763
- ? action.state.reservedIgnoreNames !== undefined
764
- ? "Saved. Review automatic transfers separately before enabling automatic work for this policy."
765
- : "Saved. Enabling startup work applies next session start; completed transfers are not undone."
766
- : "Saved. Applies to subsequent operations; status visibility applies immediately.";
767
- ctx.ui.notify(saveStatus, result?.kind === "rejected" ? "warning" : "info");
781
+ if (result?.kind === "stay") {
782
+ const { value, state } = action;
783
+ const enabled = value === "On";
784
+ const setup = safeTerminalText(setupName);
785
+ const approval =
786
+ enabled && state.reservedIgnoreNames !== undefined
787
+ ? " Use Review automatic transfers to approve this policy separately."
788
+ : "";
789
+ const message = {
790
+ automatic: `Automatic sync for “${setup}”: ${value}.${enabled ? " New startup checks begin next session." : ""}${approval}`,
791
+ "automatic-transfer": `Startup transfer for “${setup}”: ${value}.${enabled ? " Applies at the next session start." : ""}${approval}`,
792
+ "merge-settings": `Merge settings fields for “${setup}”: ${value}. Applies to subsequent sync operations.`,
793
+ "skip-secret-scan": `Secret scan ${enabled ? "disabled" : "enabled"} for subsequent pushes in all setups.`,
794
+ "show-status": `Show sync status: ${value}. Applies immediately to all setups.`,
795
+ debug: `Debug mode: ${value}. Pi applies it at the next session start.`,
796
+ "on-switch": `On setup switch: ${value}.${state.reservedIgnoreNames !== undefined ? " Switching still won't pull while any setup uses an ignore file." : ""}`,
797
+ }[id];
798
+ ctx.ui.notify(`Saved. ${message}`, "info");
799
+ }
768
800
  return result;
769
801
  };
770
802
  }
803
+ function transferSizeLimitAction({ field, label }: TransferSizeLimit) {
804
+ return async ({ state, signal: actionSignal }: { state: SettingsState; signal: AbortSignal }) => {
805
+ const cancel = new AbortController();
806
+ const mutationSignal = AbortSignal.any([actionSignal, cancel.signal, ...(signal ? [signal] : [])]);
807
+ const validate = captureMutationOwner(ctx, mutationSignal);
808
+ const rejected = { kind: "rejected" } as const;
809
+ const stay = { kind: "stay" } as const;
810
+ const setupLabel = safeTerminalText(setupName);
811
+ let limit: number | undefined;
812
+ try {
813
+ const expectedConfigFingerprint = syncCheckConfigFingerprint(state);
814
+ const active = await loadSettingsConfig();
815
+ validate();
816
+ if (active.setupName !== setupName || syncCheckConfigFingerprint(active) !== expectedConfigFingerprint) {
817
+ throw new Error("Current sync setup changed while Settings was open; reopen Settings.");
818
+ }
819
+ const stop = ctx.ui.onTerminalInput((data) => {
820
+ if (!isKeyRelease(data) && matchesKey(data, Key.ctrl("c"))) {
821
+ cancel.abort();
822
+ return { consume: true };
823
+ }
824
+ });
825
+ try {
826
+ const input = await ctx.ui.input(
827
+ `${label} for “${setupLabel}” (current: ${transferSizeLimitLabel(state[field])})\nEnter Off or a positive whole number of MiB.`,
828
+ undefined,
829
+ { signal: mutationSignal },
830
+ );
831
+ validate();
832
+ if (input === undefined) return rejected;
833
+ limit = parseTransferSizeLimit(input);
834
+ if (limit === state[field]) return stay;
835
+ if (limit !== undefined && active.settingsVersion < 9) {
836
+ const confirmed = await ctx.ui.confirm(
837
+ "Upgrade Pi Sync settings to version 9?",
838
+ `${label} for “${setupLabel}”: ${transferSizeLimitLabel(limit)}. Older Pi Sync clients and daemons cannot read this settings file for any setup. Upgrade all processes that share this agent directory before continuing. Turning both limits Off later does not downgrade the file. Remote snapshots are unchanged.`,
839
+ { signal: mutationSignal },
840
+ );
841
+ validate();
842
+ if (!confirmed) return rejected;
843
+ }
844
+ } finally {
845
+ stop();
846
+ }
847
+ validate();
848
+ ctx.ui.notify("Saving Pi Sync setting…", "info");
849
+ await updateSyncSetup(
850
+ setupName,
851
+ (setup) => {
852
+ validate();
853
+ if (limit === undefined) delete setup.sync[field];
854
+ else setup.sync[field] = limit;
855
+ return setup;
856
+ },
857
+ { expectedActiveSetup: true, expectedConfigFingerprint, signal: mutationSignal },
858
+ );
859
+ } catch (error) {
860
+ if (cancel.signal.aborted) return exitSettings();
861
+ if (!mutationSignal.aborted && isCurrent()) notifySaveFailure(ctx, error);
862
+ return rejected;
863
+ }
864
+ try {
865
+ validate();
866
+ const approval =
867
+ state.reservedIgnoreNames !== undefined &&
868
+ (startupTransferEnabled(state) || (state.automatic && syncSessionsSelected(state)))
869
+ ? " Use Review automatic transfers to approve this policy separately."
870
+ : "";
871
+ ctx.ui.notify(
872
+ `Saved. ${label} for “${setupLabel}”: ${transferSizeLimitLabel(limit)}. Applies to subsequent transfers; no transfer started.${approval}`,
873
+ "info",
874
+ );
875
+ } catch {
876
+ return stay;
877
+ }
878
+ return stay;
879
+ };
880
+ }
771
881
  function ignoreAction(action: Parameters<typeof showIgnoreFileAction>[2]) {
772
882
  return async ({ state, signal: actionSignal }: { state: SettingsState; signal: AbortSignal }) => {
773
883
  if (!ignoreAvailable || (state.pathPolicy === "ignore-file") === (action === "migrate"))
@@ -802,6 +912,20 @@ export async function showSyncSettings(
802
912
  return disposition;
803
913
  }
804
914
 
915
+ function transferSizeLimitLabel(limit: number | undefined) {
916
+ return limit === undefined ? "Off" : `${limit} MiB`;
917
+ }
918
+
919
+ function parseTransferSizeLimit(input: string) {
920
+ const value = input.trim();
921
+ if (value.toLowerCase() === "off") return undefined;
922
+ const limit = Number(value);
923
+ if (!/^[0-9]+$/u.test(value) || limit <= 0 || !Number.isSafeInteger(limit * 1_048_576)) {
924
+ throw new Error("Enter Off or a positive whole number of MiB that fits in a safe byte count.");
925
+ }
926
+ return limit;
927
+ }
928
+
805
929
  function notifySaveFailure(ctx: ExtensionCommandContext, error: unknown) {
806
930
  ctx.ui.notify(
807
931
  `Pi Sync settings save failed: ${safeTerminalText(error instanceof Error ? error.message : String(error))}`,
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/ui/automatic-sync-summary.ts", "../../src/ui/operation-dialogs.ts"],
4
- "sourcesContent": ["/** Keep the setting's automatic transfer scope visible in every setup summary. */\nexport function automaticSyncSummary(enabled: boolean) {\n return enabled ? \"On (startup check; shutdown pushes selected content if sessions included)\" : \"Off\";\n}\n", "import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\n\n/** Track History's Pi-owned selector/confirmation lifetime without inspecting renderer internals. */\nexport function trackOperationDialogs<Context extends ExtensionContext>(\n ctx: Context,\n onDialog?: (active: boolean) => void,\n): Context {\n if (!onDialog) return ctx;\n const runDialog = async <Value>(task: () => Promise<Value>): Promise<Value> => {\n onDialog(true);\n try {\n return await task();\n } finally {\n onDialog(false);\n }\n };\n const ui: ExtensionContext[\"ui\"] = {\n ...ctx.ui,\n select: (...args) => runDialog(() => ctx.ui.select(...args)),\n confirm: (...args) => runDialog(() => ctx.ui.confirm(...args)),\n };\n // Forward live context properties: copying the context would hide session\n // replacement from mutation-owner revalidation after a dialog settles.\n return new Proxy(ctx, {\n get(target, key, receiver) {\n return key === \"ui\" ? ui : Reflect.get(target, key, receiver);\n },\n });\n}\n"],
5
- "mappings": ";;;;AACO,SAAS,qBAAqB,SAAkB;AACrD,SAAO,UAAU,8EAA8E;AACjG;;;ACAO,SAAS,sBACd,KACA,UACS;AACT,MAAI,CAAC,SAAU,QAAO;AACtB,QAAM,YAAY,OAAc,SAA+C;AAC7E,aAAS,IAAI;AACb,QAAI;AACF,aAAO,MAAM,KAAK;AAAA,IACpB,UAAE;AACA,eAAS,KAAK;AAAA,IAChB;AAAA,EACF;AACA,QAAM,KAA6B;AAAA,IACjC,GAAG,IAAI;AAAA,IACP,QAAQ,IAAI,SAAS,UAAU,MAAM,IAAI,GAAG,OAAO,GAAG,IAAI,CAAC;AAAA,IAC3D,SAAS,IAAI,SAAS,UAAU,MAAM,IAAI,GAAG,QAAQ,GAAG,IAAI,CAAC;AAAA,EAC/D;AAGA,SAAO,IAAI,MAAM,KAAK;AAAA,IACpB,IAAI,QAAQ,KAAK,UAAU;AACzB,aAAO,QAAQ,OAAO,KAAK,QAAQ,IAAI,QAAQ,KAAK,QAAQ;AAAA,IAC9D;AAAA,EACF,CAAC;AACH;",
6
- "names": []
7
- }