@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
@@ -210,6 +210,7 @@ export async function remoteOperation(ctx: ExtensionContext, operation: string,
210
210
  const payload = {
211
211
  args,
212
212
  ...(setup === undefined ? {} : { setup }),
213
+ ...(options.automaticFingerprint === undefined ? {} : { automaticFingerprint: options.automaticFingerprint }),
213
214
  yes: options.yes,
214
215
  force: options.force,
215
216
  stale: options.stale,
@@ -329,13 +330,14 @@ export class PiDaemonClient {
329
330
  model: protectionOnly ? undefined : this.modelBinding(),
330
331
  };
331
332
  }
332
- async configured() {
333
+ async configured(matches?: (settings: ReturnType<typeof validateSettingsDocument>) => boolean) {
333
334
  this.validate();
334
335
  await settingsQueue;
335
336
  this.validate();
336
337
  const document = await peekLocalConfigDocument();
337
338
  this.validate();
338
- return Boolean(document && validateSettingsDocument(document.parsed).activeSyncSetup);
339
+ const settings = document && validateSettingsDocument(document.parsed);
340
+ return Boolean(settings?.activeSyncSetup && (matches?.(settings) ?? true));
339
341
  }
340
342
  async pauseForSessionChange() {
341
343
  this.validate();
@@ -12,6 +12,7 @@ export {
12
12
  syncConfigReviewFingerprint,
13
13
  syncConfigReviewIdentity,
14
14
  syncSessionsWarnings,
15
+ syncSettingsConfigFingerprint,
15
16
  syncSetupReviewIdentity,
16
17
  syncSetupStorageReview,
17
18
  } from "@narumitw/pi-sync-daemon/engine/settings/config";
@@ -1,6 +1,7 @@
1
1
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
2
  import { setSyncSetupCompletions } from "../commands/command.js";
3
3
  import { piDaemonClient } from "../daemon/pi-client.js";
4
+ import { configFromSettings, loadConfigForCheck, syncCheckConfigFingerprint } from "../settings/config.js";
4
5
  import { isMissingConfigError } from "../settings/config-errors.js";
5
6
  import type { AnySyncConfig, PiSyncSettingsV3 } from "../settings/settings-types.js";
6
7
  import { configureSyncStatus } from "../ui/sync-status.js";
@@ -9,6 +10,7 @@ import { throwIfAborted } from "./signals.js";
9
10
  import { createStartupTimings, type StartupTimingPublisher } from "./startup-timings.js";
10
11
  import { errorMessage } from "./sync-errors.js";
11
12
  import type { SyncLoaders } from "./sync-loaders.js";
13
+ import { syncSessionsSelected } from "./sync-policy.js";
12
14
 
13
15
  export async function startSession(
14
16
  ctx: ExtensionContext,
@@ -65,11 +67,16 @@ export async function startSession(
65
67
  export async function autoPushSessions(ctx: ExtensionContext, signal: AbortSignal, _loaders: SyncLoaders) {
66
68
  try {
67
69
  const client = piDaemonClient(ctx);
68
- if (!(await client.configured())) return;
70
+ const eligible = (config: AnySyncConfig) => config.automatic && syncSessionsSelected(config);
71
+ if (!(await client.configured((settings) => eligible(configFromSettings(settings))))) return;
69
72
  throwIfAborted(signal);
73
+ const config = await loadConfigForCheck(undefined, signal);
74
+ throwIfAborted(signal);
75
+ if (!eligible(config)) return;
76
+ const automaticFingerprint = syncCheckConfigFingerprint(config);
70
77
  await client.run(
71
78
  "shutdown",
72
- { args: [], yes: true, force: false, stale: false, silent: true, reload: false },
79
+ { args: [], yes: true, force: false, stale: false, silent: true, reload: false, automaticFingerprint },
73
80
  signal,
74
81
  );
75
82
  } catch (error) {
@@ -1,12 +1,18 @@
1
1
  import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
2
2
  import { setSyncSetupCompletions } from "../commands/command.js";
3
- import { loadConfig, syncConfigReviewIdentity, syncSetupReviewIdentity } from "../settings/config.js";
3
+ import {
4
+ configFromSettings,
5
+ loadConfigForCheck,
6
+ loadSettingsConfig,
7
+ syncCheckConfigFingerprint,
8
+ syncConfigReviewIdentity,
9
+ } from "../settings/config.js";
4
10
  import { configuredSyncSetupNames, updateLocalConfig } from "../settings/settings-store.js";
5
11
  import type { OnSwitchAction } from "../settings/settings-types.js";
6
12
  import { normalizeOnSwitch } from "../settings/settings-validation.js";
7
13
  import { safeTerminalText } from "../ui/terminal-text.js";
8
- import { throwIfAborted } from "./signals.js";
9
14
  import { SetupPullRequiresUiError } from "./sync-errors.js";
15
+ import { captureMutationOwner } from "./sync-local.js";
10
16
 
11
17
  export { SetupPullRequiresUiError } from "./sync-errors.js";
12
18
 
@@ -44,27 +50,36 @@ export async function useSyncSetup(
44
50
  expectedAction?: OnSwitchAction,
45
51
  signal?: AbortSignal,
46
52
  expectedSetupIdentity?: string,
53
+ expectedOperationIdentity?: string,
47
54
  ): Promise<SetupSwitchResult> {
48
55
  const normalized = name.trim();
49
56
  if (!normalized) throw new Error("Usage: /sync use <setup>");
50
- const loadedConfig = await loadConfig(normalized);
51
- const reviewedSetupIdentity = expectedSetupIdentity ?? syncConfigReviewIdentity(loadedConfig);
52
- throwIfAborted(signal);
57
+ const validate = captureMutationOwner(ctx, signal);
58
+ const metadata = await loadSettingsConfig(normalized);
59
+ validate();
60
+ const reviewedSetupIdentity = expectedSetupIdentity ?? syncConfigReviewIdentity(metadata);
61
+ const loadedConfig = await loadConfigForCheck(normalized, signal);
62
+ validate();
63
+ const operationIdentity = syncCheckConfigFingerprint(loadedConfig);
64
+ if (expectedOperationIdentity !== undefined && operationIdentity !== expectedOperationIdentity) {
65
+ throw new Error(
66
+ "Setup settings or local rule source changed while the switch preview was open; reopen it and review again.",
67
+ );
68
+ }
53
69
  const switchResult: { action: OnSwitchAction; switched: boolean } = {
54
70
  action: "ask-before-pull",
55
71
  switched: false,
56
72
  };
57
73
  await updateLocalConfig((current) => {
58
- throwIfAborted(signal);
74
+ validate();
59
75
  const setup = current.syncSetups[normalized];
60
76
  if (!setup) {
61
77
  throw new Error(`Sync setup “${safeTerminalText(normalized)}” no longer exists.`);
62
78
  }
63
- const connectionName = setup.storage.connection;
64
- const connection = current.storageConnections[connectionName];
79
+ const latest = configFromSettings(current, normalized);
65
80
  if (
66
- !connection ||
67
- syncSetupReviewIdentity(normalized, setup, connectionName, connection) !== reviewedSetupIdentity
81
+ syncConfigReviewIdentity(latest) !== reviewedSetupIdentity ||
82
+ syncCheckConfigFingerprint(latest) !== syncCheckConfigFingerprint(metadata)
68
83
  ) {
69
84
  throw new Error(
70
85
  `Sync setup “${safeTerminalText(normalized)}” changed while the switch preview was open; reopen it and review the current destination.`,
@@ -74,6 +89,7 @@ export async function useSyncSetup(
74
89
  if (expectedAction !== undefined && switchResult.action !== expectedAction) {
75
90
  throw new Error("Setup-switch behavior changed while the preview was open; reopen it and retry.");
76
91
  }
92
+ if (loadedConfig.reservedIgnoreNames !== undefined) switchResult.action = "switch-only";
77
93
  if (switchResult.action === "pull-after-switch" && !ctx.hasUI) {
78
94
  throw new SetupPullRequiresUiError(
79
95
  `Automatic setup pulls require interactive confirmation; sync setup “${safeTerminalText(normalized)}” was not switched. Use TUI or RPC mode.`,
@@ -83,13 +99,14 @@ export async function useSyncSetup(
83
99
  switchResult.switched = true;
84
100
  return { ...current, activeSyncSetup: normalized };
85
101
  }, signal);
86
- throwIfAborted(signal);
102
+ validate();
87
103
  if (!switchResult.switched) {
88
104
  ctx.ui.notify(`Sync setup “${safeTerminalText(normalized)}” is already current.`, "info");
89
105
  return { pullApplied: false };
90
106
  }
91
- setSyncSetupCompletions(await configuredSyncSetupNames());
92
- throwIfAborted(signal);
107
+ const names = await configuredSyncSetupNames();
108
+ validate();
109
+ setSyncSetupCompletions(names);
93
110
 
94
111
  if (switchResult.action === "switch-only") {
95
112
  ctx.ui.notify(`Switched to “${safeTerminalText(normalized)}”. No files were pulled.`, "info");
@@ -108,19 +125,25 @@ export async function useSyncSetup(
108
125
  "pi-sync will check the remote snapshot and show the exact local writes and deletions before applying anything.",
109
126
  { signal },
110
127
  );
111
- throwIfAborted(signal);
128
+ validate();
112
129
  if (!confirmed) {
113
130
  ctx.ui.notify(`Switched to “${safeTerminalText(normalized)}”; files were not pulled.`, "info");
114
131
  return { pullApplied: false };
115
132
  }
116
133
  }
117
134
 
135
+ const latest = await loadConfigForCheck(undefined, signal);
136
+ validate();
137
+ if (syncCheckConfigFingerprint(latest) !== operationIdentity) {
138
+ ctx.ui.notify("The active setup or its settings changed. No files were pulled; reopen the review.", "warning");
139
+ return { pullApplied: false };
140
+ }
118
141
  ctx.ui.notify(`Switched to “${safeTerminalText(normalized)}”. Checking remote files for a reviewed pull…`, "info");
119
142
  if (!pullCurrentSetup) {
120
143
  throw new Error(`Switched to “${safeTerminalText(normalized)}”, but pull is unavailable.`);
121
144
  }
122
145
  const pullOutcome = await pullCurrentSetup(normalized);
123
- throwIfAborted(signal);
146
+ validate();
124
147
  if (pullOutcome === "cancelled") {
125
148
  ctx.ui.notify(
126
149
  `Pull cancelled; sync setup “${safeTerminalText(normalized)}” remains current and synced files were not changed.`,
@@ -76,7 +76,7 @@ export function createStartupCheck(
76
76
  .then(async () => {
77
77
  try {
78
78
  throwIfAborted(signal);
79
- config = initialConfig ?? (await loadConfigForCheck());
79
+ config = initialConfig ?? (await loadConfigForCheck(undefined, signal));
80
80
  task.transfer = startupTransferEnabled(config);
81
81
  throwIfAborted(signal);
82
82
  if (!config.automatic && !startupTransferEnabled(config)) return;
@@ -86,7 +86,7 @@ export function createStartupCheck(
86
86
  setSyncStatus(ctx, "sync ...", { activity: "checking" });
87
87
  const { inspectSync } = await timings.measure("inspection import", () => loaders.inspection());
88
88
  throwIfAborted(signal);
89
- const currentConfig = await loadConfigForCheck();
89
+ const currentConfig = await loadConfigForCheck(undefined, signal);
90
90
  throwIfAborted(signal);
91
91
  if (syncCheckConfigFingerprint(currentConfig) !== identity) return;
92
92
  // The daemon owns the operation and cache guards.
@@ -94,7 +94,7 @@ export function createStartupCheck(
94
94
  inspectSync(captured, snapshotOptionsForContext(ctx, captured), signal, undefined, timings),
95
95
  );
96
96
  throwIfAborted(signal);
97
- const latest = await loadConfigForCheck();
97
+ const latest = await loadConfigForCheck(undefined, signal);
98
98
  throwIfAborted(signal);
99
99
  if (syncCheckConfigFingerprint(latest) !== identity) return;
100
100
  const state = await withStateDirectoryAccess(() => readStateForConfig(latest));
@@ -115,7 +115,9 @@ export function createStartupCheck(
115
115
  ) {
116
116
  const operations = await timings.measure("operations import", () => loaders.operations());
117
117
  throwIfAborted(signal);
118
- if (!isCurrent()) return;
118
+ const transferConfig = await loadConfigForCheck(undefined, signal);
119
+ throwIfAborted(signal);
120
+ if (!isCurrent() || syncCheckConfigFingerprint(transferConfig) !== identity) return;
119
121
  if (!ctx.isIdle()) {
120
122
  pending = { ctx, signal: sessionSignal, config: captured };
121
123
  return;
@@ -129,6 +131,7 @@ export function createStartupCheck(
129
131
  silent: true,
130
132
  reload: false,
131
133
  auto: true,
134
+ automaticFingerprint: identity,
132
135
  signal,
133
136
  startupTimings: timings,
134
137
  onCommit: () => attention.clearObservation(),
@@ -1,6 +1,6 @@
1
1
  import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
2
2
  import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
3
- import { loadConfig, syncCheckConfigFingerprint } from "../settings/config.js";
3
+ import { loadSettingsConfig, syncCheckConfigFingerprint } from "../settings/config.js";
4
4
  import { localConfigPath } from "../settings/config-file.js";
5
5
  import { updateSyncSetup } from "../settings/settings-management.js";
6
6
  import type { AnySyncConfig } from "../settings/settings-types.js";
@@ -29,7 +29,7 @@ export async function showExcludedPaths(ctx: ExtensionCommandContext, setupName:
29
29
  }
30
30
  };
31
31
  validate();
32
- const config = await loadConfig(setupName);
32
+ const config = await loadSettingsConfig(setupName);
33
33
  validate();
34
34
  if (config.scope === "agent-directory") return showDirectoryScope(ctx, config, signal);
35
35
  if (ctx.mode !== "tui") {
@@ -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",
@@ -301,11 +313,14 @@ export function backendStorageDescription(config: AnySyncConfig) {
301
313
  config.backend.profile.kind === "r2" || isCloudflareR2Endpoint(config.backend.profile.endpoint)
302
314
  ? "Cloudflare R2"
303
315
  : "S3-compatible";
304
- return `${type} · ${connection} · ${safeTerminalText(config.backend.destination.bucket)}`;
316
+ const { bucket, prefix } = config.backend.destination;
317
+ return `${type} · ${connection} · ${safeTerminalText(bucket)} · ${safeTerminalText(prefix)}`;
305
318
  }
306
319
  case "webdav":
307
320
  return `WebDAV · ${connection} · ${safeTerminalText(config.backend.destination.path)}`;
308
- case "git":
309
- return `Git · ${connection} · ${safeTerminalText(config.backend.destination.branch)}`;
321
+ case "git": {
322
+ const { branch, directory } = config.backend.destination;
323
+ return `Git · ${connection} · ${safeTerminalText(branch)} · ${safeTerminalText(directory)}`;
324
+ }
310
325
  }
311
326
  }