@narumitw/pi-sync 0.66.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 (31) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +10 -1
  3. package/dist/chunks/{command-handler-44EFGPWH.ts → command-handler-SQC2L2FJ.ts} +2 -2
  4. package/dist/chunks/{manager-ui-CVZLMXJ5.ts → manager-ui-DWOMAJKE.ts} +116 -3
  5. package/dist/chunks/manager-ui-DWOMAJKE.ts.map +7 -0
  6. package/dist/daemon/dist/engine/ignore/ignore-edit.js +2 -2
  7. package/dist/daemon/dist/engine/ignore/ignore-settings.js +2 -1
  8. package/dist/daemon/dist/engine/settings/config-file.js +3 -0
  9. package/dist/daemon/dist/engine/settings/config.js +5 -5
  10. package/dist/daemon/dist/engine/settings/settings-management.js +6 -1
  11. package/dist/daemon/dist/engine/settings/settings-validation.js +21 -2
  12. package/dist/daemon/dist/engine/sync/continuous-errors.js +6 -0
  13. package/dist/daemon/dist/engine/sync/continuous-sync.js +4 -2
  14. package/dist/daemon/dist/engine/sync/ignore-adoption.js +9 -0
  15. package/dist/daemon/dist/engine/sync/merge-apply.js +18 -1
  16. package/dist/daemon/dist/engine/sync/merged-sync.js +36 -4
  17. package/dist/daemon/dist/engine/sync/push-review.js +33 -0
  18. package/dist/daemon/dist/engine/sync/sync-mutations.js +38 -48
  19. package/dist/daemon/dist/engine/sync/sync-rollback.js +16 -2
  20. package/dist/daemon/dist/engine/sync/transfer-freshness.js +3 -2
  21. package/dist/daemon/dist/engine/sync/transfer-size-limits.js +92 -0
  22. package/dist/daemon/package.json +1 -1
  23. package/dist/index.ts +1 -1
  24. package/docs/daemon-migration.md +6 -0
  25. package/docs/tui-contract.md +4 -3
  26. package/package.json +2 -2
  27. package/skills/configure-pi-sync/SKILL.md +1 -1
  28. package/skills/configure-pi-sync/references/configuration.md +33 -6
  29. package/src/ui/settings-ui.ts +128 -4
  30. package/dist/chunks/manager-ui-CVZLMXJ5.ts.map +0 -7
  31. /package/dist/chunks/{command-handler-44EFGPWH.ts.map → command-handler-SQC2L2FJ.ts.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @narumitw/pi-sync
2
2
 
3
+ ## 0.67.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 93d6847: Add independent, default-off file and directory transfer size limits for each sync setup. The daemon checks the selected uncompressed content before a new transfer writes locally or publishes remotely, including automatic sync. Enabling either limit requires local settings version 9, which older processes refuse even after the limits are cleared. Remote snapshot formats are unchanged.
8
+
3
9
  ## 0.66.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -14,6 +14,7 @@ Reusable storage connections hold credentials, while named sync setups define ex
14
14
  - Uses one ordered include list for Pi roots, safe agent-relative paths, and privacy-sensitive sessions, with optional path/glob exclusions.
15
15
  - Protects changes with immutable snapshots, secret scanning, locks, conflict checks, pull backups, transactional apply, and recovery journals.
16
16
  - Keeps snapshot selection portable and free of credentials.
17
+ - Offers opt-in file and directory size limits for new local applies and remote publications.
17
18
  - Writes settings atomically, preserves unknown fields, rejects stale edits, and fails closed on unsafe configuration.
18
19
  - Offers default-off Autonomous sync for eligible startup and Sync now transfers without another transfer confirmation, with model-assisted conflict resolution and a separate Continuous sync opt-in.
19
20
  - Shares one detached synchronization service across Pi clients, with a generated split UI client runtime.
@@ -242,7 +243,7 @@ Successful transfers show one summary. They do not reload resources, activate ex
242
243
 
243
244
  **Settings → Merge settings fields** controls the per-setup `sync.mergeSettings` opt-in, default **Off**. It combines independent global `settings.json` fields, not arbitrary JSON or keybindings. Missing/corrupt ancestors, unsupported syntax, and incompatible fields retain whole-transfer review. Sensitive accepted content is cached privately under the denied state root; disabling does not delete evidence.
244
245
 
245
- **Settings → Machine-local fields** edits explicit `sync.localFields` root field names for global `settings.json` (default none). Excluded values and absence stay local; future portable snapshots omit them. An explicit array requires at least settings version 4 and snapshot version 2; legacy directory scope keeps settings version 7 or later and snapshot version 5; ignore-file setups use settings version 8 and publish snapshot version 7. Nonempty rules require `settings.json` in `sync.include` only for selected-path setups. All receiving machines must configure compatible rules. Additions/removals require a separately confirmed force-direction migration, even with `--yes`; old remote history is **not erased**. See [settings merge and local fields](./skills/configure-pi-sync/references/configuration.md#settings-field-merge-and-machine-local-fields) for formats, compatibility and recovery.
246
+ **Settings → Machine-local fields** edits explicit `sync.localFields` root field names for global `settings.json` (default none). Excluded values and absence stay local; future portable snapshots omit them. An explicit array requires at least settings version 4 and snapshot version 2; legacy directory scope keeps settings version 7 or later and snapshot version 5; ignore-file setups require settings version 8 or later and publish snapshot version 7. Nonempty rules require `settings.json` in `sync.include` only for selected-path setups. All receiving machines must configure compatible rules. Additions/removals require a separately confirmed force-direction migration, even with `--yes`; old remote history is **not erased**. See [settings merge and local fields](./skills/configure-pi-sync/references/configuration.md#settings-field-merge-and-machine-local-fields) for formats, compatibility and recovery.
246
247
 
247
248
  **Settings → Content merge / partial progress** controls independent `sync.mergeContent` and `sync.partialSync` opt-ins, both default **Off**. Saving opts into at least settings version 5; partial publications use snapshot version 3 for selected paths, version 4 with selected-path exclusions, version 5 for legacy directory scope, or version 7 for ignore-file policy. Older readers must refuse unsupported formats. Supported Markdown/plain-text resources merge bounded independent line edits without Git or conflict markers. Diff grids and hunk comparisons share an eight-million-work-unit budget across the operation and its retries; exhausted paths remain conflicts for review. Same-session reconciliation only accepts validated complete byte-prefix extensions; divergent histories and the loaded session require review. A syntactically clean text merge is **not a semantic correctness guarantee**.
248
249
 
@@ -308,6 +309,14 @@ Upgrade all peers before publishing a version 7 snapshot. When policies differ,
308
309
 
309
310
  For selected-path setups, **Settings → Excluded paths** edits `sync.exclude` rules that win over `include`; saving opts into at least settings version 6 and snapshot version 4. For directory scope, **Settings → Agent directory scope** also edits `reinclude` and session opt-in. Excluded local files remain untouched, including on rollback. New publications omit matching remote paths, but old history is **not erased**. Removing rules can expose or replace content. See [Excluded paths](./skills/configure-pi-sync/references/configuration.md#excluded-paths) for syntax, review, and recovery.
310
311
 
312
+ ### Transfer size limits
313
+
314
+ In **/sync → Settings**, use **Max file size** and **Max directory size** for the current setup. Both default to **Off**. Enter `Off` or a positive whole number of MiB. The daemon checks the uncompressed bytes selected for each new local apply or remote publication. A directory limit counts all included files below that directory, not the entire sync root. A failure stops the transfer instead of skipping files, even for automatic transfers or with `--force` or `--yes`.
315
+
316
+ **Before enabling either limit, close or upgrade older Pi Sync clients and daemon processes that use this agent directory.** Enabling a limit upgrades an older local `pi-sync.json` to version 9. Older processes refuse the entire document, even for other setups. Turning both limits Off does not downgrade the file. Remote peers need no upgrade for this setting alone; it does not change snapshots.
317
+
318
+ A save applies to subsequent transfer attempts. It neither starts a transfer nor grants automatic permission. If blocked, inspect `/sync diff`, narrow the selection with [ignore rules](#ignore-file-policy) or [legacy exclusions](#legacy-path-rules), then review a Push or Pull from the side that has the version you want. See [Transfer size limits](./skills/configure-pi-sync/references/configuration.md#transfer-size-limits) for the manual settings fields, an example, and recovery guidance.
319
+
311
320
  ### Scan limits
312
321
 
313
322
  If the agent-directory scan exceeds 64 MiB, use `/sync config` to find the active ignore file. Exclude large files or folders you do not need to sync, verify the rules, and reopen the transfer review. For a legacy agent-directory setup, use **Settings → Agent directory scope** to edit exclusions instead. Storage diagnostics do not change the local scan limit.
@@ -450,7 +450,7 @@ async function handleCommand(rawArgs, ctx, sessionSignal, loaders, attention, on
450
450
  if (!rawArgs.trim()) {
451
451
  attention.expand();
452
452
  try {
453
- const { showSyncManager } = await import("./manager-ui-CVZLMXJ5.ts");
453
+ const { showSyncManager } = await import("./manager-ui-DWOMAJKE.ts");
454
454
  if (sessionSignal.aborted) return;
455
455
  await showSyncManager(ctx, run, sessionSignal, {
456
456
  needsDaemonRecovery,
@@ -584,4 +584,4 @@ export {
584
584
  handleCommand,
585
585
  resolveSelectionAttention
586
586
  };
587
- //# sourceMappingURL=command-handler-44EFGPWH.ts.map
587
+ //# sourceMappingURL=command-handler-SQC2L2FJ.ts.map
@@ -774,6 +774,7 @@ function backendStorageDescription(config) {
774
774
  }
775
775
 
776
776
  // src/ui/settings-ui.ts
777
+ import { isKeyRelease, Key, matchesKey } from "@earendil-works/pi-tui";
777
778
  import { defineMenu as defineMenu4, runMenu as runMenu4 } from "@narumitw/pi-tui-kit";
778
779
 
779
780
  // src/sync/local-fields.ts
@@ -1484,6 +1485,18 @@ async function showRemoveTarget(ctx, name, signal) {
1484
1485
  }
1485
1486
 
1486
1487
  // src/ui/settings-ui.ts
1488
+ var transferSizeLimits = [
1489
+ {
1490
+ field: "maxFileSizeMiB",
1491
+ label: "Max file size",
1492
+ description: "Block a transfer when an included file exceeds this uncompressed size."
1493
+ },
1494
+ {
1495
+ field: "maxDirectorySizeMiB",
1496
+ label: "Max directory size",
1497
+ description: "Block a transfer when a directory below the sync root exceeds this total uncompressed size, counting included files in its subdirectories too."
1498
+ }
1499
+ ];
1487
1500
  async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1488
1501
  let disposition = "back";
1489
1502
  const exitSettings = () => {
@@ -1516,6 +1529,10 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1516
1529
  [
1517
1530
  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)}`,
1518
1531
  ...limited ? [IGNORE_SETUP_MANAGEMENT_LIMIT, ...ignoreSetupRecovery(settingsPath)] : [],
1532
+ ...!limited && config ? [
1533
+ "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.",
1534
+ "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."
1535
+ ] : [],
1519
1536
  ...!limited && config?.reservedIgnoreNames !== void 0 ? ["Use TUI Settings \u2192 Review automatic transfers to approve the current setup separately."] : [],
1520
1537
  ...config?.pathPolicy === "ignore-file" ? [manualIgnoreFileGuidance(config.ignoreFile ?? ".syncignore")] : config?.scope === "agent-directory" ? directoryScopeSummary(config) : []
1521
1538
  ].join("\n"),
@@ -1622,6 +1639,13 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1622
1639
  currentValue: `${state.localFields?.length ?? 0} fields \xB7 Edit`,
1623
1640
  action: "local-fields"
1624
1641
  },
1642
+ ...transferSizeLimits.map(({ field, label, description }) => ({
1643
+ id: field,
1644
+ label,
1645
+ description: `This setup: ${description} Also applies to automatic transfers. Saving starts no transfer.`,
1646
+ currentValue: transferSizeLimitLabel(state[field]),
1647
+ action: field
1648
+ })),
1625
1649
  {
1626
1650
  id: "storageLocation",
1627
1651
  label: "Storage location",
@@ -1738,6 +1762,8 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1738
1762
  })
1739
1763
  },
1740
1764
  actions: {
1765
+ maxFileSizeMiB: transferSizeLimitAction(transferSizeLimits[0]),
1766
+ maxDirectorySizeMiB: transferSizeLimitAction(transferSizeLimits[1]),
1741
1767
  "storage-location": async ({ signal: actionSignal }) => {
1742
1768
  const editorSignal = signal ? AbortSignal.any([signal, actionSignal]) : actionSignal;
1743
1769
  await showEditSyncSetupStorage(ctx, setupName, editorSignal);
@@ -1763,7 +1789,7 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1763
1789
  const partialSync = value === "Partial only" || value === "Merge + partial";
1764
1790
  if (!await ctx.ui.confirm(
1765
1791
  "Save content policy?",
1766
- `${previous.pathPolicy === "ignore-file" ? "Ignore-file policy keeps settings version 8 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.`,
1792
+ `${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.`,
1767
1793
  { signal: mutationSignal }
1768
1794
  ))
1769
1795
  return { kind: "rejected" };
@@ -1833,7 +1859,7 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
1833
1859
  if (sameLocalFields(previous.localFields, fields)) return { kind: "stay" };
1834
1860
  const confirmed = await ctx.ui.confirm(
1835
1861
  "Save portable field policy?",
1836
- `${previous.pathPolicy === "ignore-file" ? "Ignore-file policy keeps settings version 8 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.`,
1862
+ `${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.`,
1837
1863
  { signal: mutationSignal }
1838
1864
  );
1839
1865
  validate();
@@ -2097,6 +2123,81 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
2097
2123
  return result;
2098
2124
  };
2099
2125
  }
2126
+ function transferSizeLimitAction({ field, label }) {
2127
+ return async ({ state, signal: actionSignal }) => {
2128
+ const cancel = new AbortController();
2129
+ const mutationSignal = AbortSignal.any([actionSignal, cancel.signal, ...signal ? [signal] : []]);
2130
+ const validate = captureMutationOwner(ctx, mutationSignal);
2131
+ const rejected = { kind: "rejected" };
2132
+ const stay = { kind: "stay" };
2133
+ const setupLabel = safeTerminalText(setupName);
2134
+ let limit;
2135
+ try {
2136
+ const expectedConfigFingerprint = syncCheckConfigFingerprint(state);
2137
+ const active = await loadSettingsConfig();
2138
+ validate();
2139
+ if (active.setupName !== setupName || syncCheckConfigFingerprint(active) !== expectedConfigFingerprint) {
2140
+ throw new Error("Current sync setup changed while Settings was open; reopen Settings.");
2141
+ }
2142
+ const stop = ctx.ui.onTerminalInput((data) => {
2143
+ if (!isKeyRelease(data) && matchesKey(data, Key.ctrl("c"))) {
2144
+ cancel.abort();
2145
+ return { consume: true };
2146
+ }
2147
+ });
2148
+ try {
2149
+ const input = await ctx.ui.input(
2150
+ `${label} for \u201C${setupLabel}\u201D (current: ${transferSizeLimitLabel(state[field])})
2151
+ Enter Off or a positive whole number of MiB.`,
2152
+ void 0,
2153
+ { signal: mutationSignal }
2154
+ );
2155
+ validate();
2156
+ if (input === void 0) return rejected;
2157
+ limit = parseTransferSizeLimit(input);
2158
+ if (limit === state[field]) return stay;
2159
+ if (limit !== void 0 && active.settingsVersion < 9) {
2160
+ const confirmed = await ctx.ui.confirm(
2161
+ "Upgrade Pi Sync settings to version 9?",
2162
+ `${label} for \u201C${setupLabel}\u201D: ${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.`,
2163
+ { signal: mutationSignal }
2164
+ );
2165
+ validate();
2166
+ if (!confirmed) return rejected;
2167
+ }
2168
+ } finally {
2169
+ stop();
2170
+ }
2171
+ validate();
2172
+ ctx.ui.notify("Saving Pi Sync setting\u2026", "info");
2173
+ await updateSyncSetup(
2174
+ setupName,
2175
+ (setup) => {
2176
+ validate();
2177
+ if (limit === void 0) delete setup.sync[field];
2178
+ else setup.sync[field] = limit;
2179
+ return setup;
2180
+ },
2181
+ { expectedActiveSetup: true, expectedConfigFingerprint, signal: mutationSignal }
2182
+ );
2183
+ } catch (error) {
2184
+ if (cancel.signal.aborted) return exitSettings();
2185
+ if (!mutationSignal.aborted && isCurrent()) notifySaveFailure(ctx, error);
2186
+ return rejected;
2187
+ }
2188
+ try {
2189
+ validate();
2190
+ const approval = state.reservedIgnoreNames !== void 0 && (startupTransferEnabled(state) || state.automatic && syncSessionsSelected(state)) ? " Use Review automatic transfers to approve this policy separately." : "";
2191
+ ctx.ui.notify(
2192
+ `Saved. ${label} for \u201C${setupLabel}\u201D: ${transferSizeLimitLabel(limit)}. Applies to subsequent transfers; no transfer started.${approval}`,
2193
+ "info"
2194
+ );
2195
+ } catch {
2196
+ return stay;
2197
+ }
2198
+ return stay;
2199
+ };
2200
+ }
2100
2201
  function ignoreAction(action) {
2101
2202
  return async ({ state, signal: actionSignal }) => {
2102
2203
  if (!ignoreAvailable || state.pathPolicy === "ignore-file" === (action === "migrate"))
@@ -2129,6 +2230,18 @@ async function showSyncSettings(ctx, runRoute, signal, reviewedSetup) {
2129
2230
  });
2130
2231
  return disposition;
2131
2232
  }
2233
+ function transferSizeLimitLabel(limit) {
2234
+ return limit === void 0 ? "Off" : `${limit} MiB`;
2235
+ }
2236
+ function parseTransferSizeLimit(input) {
2237
+ const value = input.trim();
2238
+ if (value.toLowerCase() === "off") return void 0;
2239
+ const limit = Number(value);
2240
+ if (!/^[0-9]+$/u.test(value) || limit <= 0 || !Number.isSafeInteger(limit * 1048576)) {
2241
+ throw new Error("Enter Off or a positive whole number of MiB that fits in a safe byte count.");
2242
+ }
2243
+ return limit;
2244
+ }
2132
2245
  function notifySaveFailure(ctx, error) {
2133
2246
  ctx.ui.notify(
2134
2247
  `Pi Sync settings save failed: ${safeTerminalText(error instanceof Error ? error.message : String(error))}`,
@@ -2550,4 +2663,4 @@ function syncMainMenuItem(label) {
2550
2663
  export {
2551
2664
  showSyncManager
2552
2665
  };
2553
- //# sourceMappingURL=manager-ui-CVZLMXJ5.ts.map
2666
+ //# sourceMappingURL=manager-ui-DWOMAJKE.ts.map