@narumitw/pi-sync-daemon 0.6.2 → 0.8.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 (97) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +17 -3
  3. package/dist/consent.js +26 -1
  4. package/dist/engine/backends/git/git-backend.d.ts +1 -1
  5. package/dist/engine/backends/git/git-backend.js +17 -2
  6. package/dist/engine/backends/git/git-storage.d.ts +1 -1
  7. package/dist/engine/backends/git/git-storage.js +39 -13
  8. package/dist/engine/backends/s3/s3-backend.js +8 -0
  9. package/dist/engine/backends/sync-backend.d.ts +1 -0
  10. package/dist/engine/backends/webdav/webdav-backend.js +8 -0
  11. package/dist/engine/ignore/effective-ignore-policy.d.ts +10 -0
  12. package/dist/engine/ignore/effective-ignore-policy.js +33 -0
  13. package/dist/engine/ignore/ignore-edit.d.ts +13 -0
  14. package/dist/engine/ignore/ignore-edit.js +102 -0
  15. package/dist/engine/ignore/ignore-initialization.d.ts +6 -0
  16. package/dist/engine/ignore/ignore-initialization.js +186 -0
  17. package/dist/engine/ignore/ignore-migration-prompt.d.ts +7 -0
  18. package/dist/engine/ignore/ignore-migration-prompt.js +139 -0
  19. package/dist/engine/ignore/ignore-settings.d.ts +15 -0
  20. package/dist/engine/ignore/ignore-settings.js +322 -0
  21. package/dist/engine/ignore/ignore-source.d.ts +27 -0
  22. package/dist/engine/ignore/ignore-source.js +250 -0
  23. package/dist/engine/paths.js +1 -1
  24. package/dist/engine/settings/config-file.d.ts +9 -2
  25. package/dist/engine/settings/config-file.js +126 -28
  26. package/dist/engine/settings/config.d.ts +5 -4
  27. package/dist/engine/settings/config.js +114 -13
  28. package/dist/engine/settings/settings-management.js +34 -32
  29. package/dist/engine/settings/settings-types.d.ts +40 -5
  30. package/dist/engine/settings/settings-validation.js +52 -24
  31. package/dist/engine/snapshot/session-paths.d.ts +6 -4
  32. package/dist/engine/snapshot/session-paths.js +84 -15
  33. package/dist/engine/snapshot/snapshot-apply.d.ts +7 -8
  34. package/dist/engine/snapshot/snapshot-apply.js +107 -21
  35. package/dist/engine/snapshot/snapshot-bounds.d.ts +4 -0
  36. package/dist/engine/snapshot/snapshot-bounds.js +20 -0
  37. package/dist/engine/snapshot/snapshot-codec.d.ts +1 -1
  38. package/dist/engine/snapshot/snapshot-codec.js +15 -7
  39. package/dist/engine/snapshot/snapshot-entry-projection.d.ts +10 -0
  40. package/dist/engine/snapshot/snapshot-entry-projection.js +78 -0
  41. package/dist/engine/snapshot/snapshot-exclude-safety.d.ts +9 -2
  42. package/dist/engine/snapshot/snapshot-exclude-safety.js +239 -24
  43. package/dist/engine/snapshot/snapshot-payload.d.ts +2 -0
  44. package/dist/engine/snapshot/snapshot-payload.js +10 -0
  45. package/dist/engine/snapshot/snapshot-reviewed-preimages.d.ts +2 -0
  46. package/dist/engine/snapshot/snapshot-reviewed-preimages.js +60 -0
  47. package/dist/engine/snapshot/snapshot-root-transition.d.ts +4 -0
  48. package/dist/engine/snapshot/snapshot-root-transition.js +16 -0
  49. package/dist/engine/snapshot/snapshot-transaction-images.d.ts +39 -0
  50. package/dist/engine/snapshot/snapshot-transaction-images.js +387 -0
  51. package/dist/engine/snapshot/snapshot-transaction-policy.d.ts +73 -0
  52. package/dist/engine/snapshot/snapshot-transaction-policy.js +276 -0
  53. package/dist/engine/snapshot/snapshot-transaction-stage.d.ts +32 -0
  54. package/dist/engine/snapshot/snapshot-transaction-stage.js +303 -0
  55. package/dist/engine/snapshot/snapshot-transaction-verification.d.ts +7 -0
  56. package/dist/engine/snapshot/snapshot-transaction-verification.js +78 -0
  57. package/dist/engine/snapshot/snapshot-transaction.d.ts +1 -11
  58. package/dist/engine/snapshot/snapshot-transaction.js +390 -364
  59. package/dist/engine/snapshot/snapshot-types.d.ts +47 -2
  60. package/dist/engine/snapshot/snapshot-types.js +9 -1
  61. package/dist/engine/snapshot/snapshot.d.ts +22 -3
  62. package/dist/engine/snapshot/snapshot.js +357 -43
  63. package/dist/engine/state/merge-baseline-store.js +20 -9
  64. package/dist/engine/state/state-types.d.ts +3 -0
  65. package/dist/engine/sync/apply-review.d.ts +3 -3
  66. package/dist/engine/sync/apply-review.js +5 -4
  67. package/dist/engine/sync/continuous-sync.js +37 -12
  68. package/dist/engine/sync/continuous-watch.d.ts +4 -1
  69. package/dist/engine/sync/continuous-watch.js +90 -15
  70. package/dist/engine/sync/exclude-policy.d.ts +4 -0
  71. package/dist/engine/sync/exclude-policy.js +8 -1
  72. package/dist/engine/sync/initialization.js +9 -4
  73. package/dist/engine/sync/local-fields.d.ts +3 -1
  74. package/dist/engine/sync/local-fields.js +88 -8
  75. package/dist/engine/sync/merge-apply.js +190 -47
  76. package/dist/engine/sync/merge-journal.d.ts +18 -4
  77. package/dist/engine/sync/merge-journal.js +126 -10
  78. package/dist/engine/sync/merged-sync.d.ts +1 -1
  79. package/dist/engine/sync/merged-sync.js +124 -68
  80. package/dist/engine/sync/partial-progress.js +5 -3
  81. package/dist/engine/sync/remote-snapshot.d.ts +10 -2
  82. package/dist/engine/sync/remote-snapshot.js +59 -17
  83. package/dist/engine/sync/session-push.js +7 -6
  84. package/dist/engine/sync/sync-decision.d.ts +4 -0
  85. package/dist/engine/sync/sync-decision.js +17 -2
  86. package/dist/engine/sync/sync-inspection.js +8 -6
  87. package/dist/engine/sync/sync-mutations.d.ts +10 -2
  88. package/dist/engine/sync/sync-mutations.js +245 -101
  89. package/dist/engine/sync/sync-policy.d.ts +36 -10
  90. package/dist/engine/sync/sync-policy.js +285 -20
  91. package/dist/engine/sync/sync-queries.js +49 -32
  92. package/dist/engine/sync/sync-state.d.ts +11 -0
  93. package/dist/engine/sync/sync-state.js +42 -5
  94. package/dist/engine/ui/sync-format.js +22 -7
  95. package/dist/engine-service.js +24 -2
  96. package/docs/architecture.md +28 -0
  97. package/package.json +2 -1
@@ -1,6 +1,6 @@
1
1
  import { createSyncBackend } from "../backends/backend-factory.js";
2
2
  import { loadConfig, syncSessionsWarnings } from "../settings/config.js";
3
- import { snapshotOptionsForContext } from "../snapshot/session-paths.js";
3
+ import { resolvedSnapshotOptionsForContext } from "../snapshot/session-paths.js";
4
4
  import { createSnapshot, scanSnapshot } from "../snapshot/snapshot.js";
5
5
  import { inspectLock, isLockGuardHeld, isStaleLock, withLock } from "../state/lock.js";
6
6
  import { readStateForConfig } from "../state/sync-state-store.js";
@@ -14,12 +14,26 @@ import { errorMessage } from "./sync-errors.js";
14
14
  import { inspectSync } from "./sync-inspection.js";
15
15
  import { rollback } from "./sync-mutations.js";
16
16
  import { syncSessionsSelected } from "./sync-policy.js";
17
- const DEFAULT_PROFILE = "default";
17
+ function contentLines(config) {
18
+ return [
19
+ config.scope === "agent-directory"
20
+ ? "included content: eligible files in the Pi agent directory"
21
+ : `included content: ${config.include.map(safeTerminalText).join(", ") || "none"}`,
22
+ ...(config.ignorePolicy ? ["path policy: local ignore file (rule text is not published)"] : []),
23
+ ...(config.exclude === undefined
24
+ ? []
25
+ : [`excluded paths: ${config.exclude.map(safeTerminalText).join(", ") || "none"}`]),
26
+ ...(config.reinclude === undefined
27
+ ? []
28
+ : [`re-included paths: ${config.reinclude.map(safeTerminalText).join(", ") || "none"}`]),
29
+ `sessions: ${syncSessionsSelected(config) ? "included" : "excluded"}`,
30
+ ];
31
+ }
18
32
  export async function status(ctx, options, factory = createSyncBackend) {
19
33
  const config = await loadConfig(options.setup);
20
34
  throwIfAborted(options.signal);
21
35
  setSyncStatus(ctx, `checking ${config.setupName}`, { activity: "checking" });
22
- const { head, selectionState, localChanged, remoteChanged, localFiles, destination, capability } = await inspectSync(config, snapshotOptionsForContext(ctx, config), options.signal, factory);
36
+ const { head, selectionState, localChanged, remoteChanged, localFiles, destination, capability } = await inspectSync(config, await resolvedSnapshotOptionsForContext(ctx, config, options.signal), options.signal, factory);
23
37
  throwIfAborted(options.signal);
24
38
  const continuous = config.continuous
25
39
  ? await (await import("./continuous-record.js")).continuousStatusLines(config)
@@ -33,11 +47,7 @@ export async function status(ctx, options, factory = createSyncBackend) {
33
47
  `storage connection: ${config.connectionName}`,
34
48
  `storage location: ${safeTerminalText(destination)}`,
35
49
  `publication safety: ${publicationCapabilityDescription(capability)}`,
36
- `included content: ${config.include.join(", ") || "none"}`,
37
- ...(config.exclude === undefined
38
- ? []
39
- : [`excluded paths: ${config.exclude.map(safeTerminalText).join(", ") || "none"}`]),
40
- `sessions: ${syncSessionsSelected(config) ? "included" : "excluded"}`,
50
+ ...contentLines(config),
41
51
  ...continuous,
42
52
  remoteText,
43
53
  formatRemoteSelectionStatus(selectionState),
@@ -52,10 +62,12 @@ export async function diff(ctx, options, factory = createSyncBackend) {
52
62
  throwIfAborted(options.signal);
53
63
  setSyncStatus(ctx, `checking ${config.setupName}`, { activity: "checking" });
54
64
  const backend = await factory(config);
55
- const local = portableSnapshot(await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config)), config.localFields);
65
+ const snapshotOptions = await resolvedSnapshotOptionsForContext(ctx, config, options.signal);
66
+ const local = portableSnapshot(await createSnapshot(config.snapshotIdentity, snapshotOptions), config.localFields);
56
67
  throwIfAborted(options.signal);
57
68
  const { snapshot: remote, selectionState } = await readRemoteSnapshot(backend, config, options.signal, {
58
69
  allowSelectionDifference: true,
70
+ sessionDir: snapshotOptions.sessionDir,
59
71
  });
60
72
  throwIfAborted(options.signal);
61
73
  setSyncStatus(ctx, undefined);
@@ -64,37 +76,37 @@ export async function diff(ctx, options, factory = createSyncBackend) {
64
76
  `sync setup: ${config.setupName}`,
65
77
  `storage connection: ${config.connectionName}`,
66
78
  `storage location: ${safeTerminalText(backend.destination)}`,
67
- `included content: ${config.include.join(", ") || "none"}`,
68
- ...(config.exclude === undefined
69
- ? []
70
- : [`excluded paths: ${config.exclude.map(safeTerminalText).join(", ") || "none"}`]),
71
- `sessions: ${syncSessionsSelected(config) ? "included" : "excluded"}`,
79
+ ...contentLines(config),
72
80
  formatRemoteSelectionStatus(selectionState),
73
81
  ...warnings,
74
82
  ].join("\n");
75
83
  const level = warnings.length > 0 || selectionState?.kind === "different" ? "warning" : "info";
84
+ if (selectionState?.ignorePolicyComparison === "local-legacy-remote-ignore") {
85
+ ctx.ui.notify(`${header}\n\nFile comparison requires a configured local ignore-file policy.`, level);
86
+ return;
87
+ }
76
88
  if (!remote) {
77
89
  ctx.ui.notify(`${header}\n\n${formatSnapshotOnlyDiff("Remote is empty. Local push would upload", local)}`, level);
78
90
  return;
79
91
  }
80
- ctx.ui.notify(`${header}\n\n${formatDiff(local, portableSnapshot(remote, remote.localFields))}`, level);
92
+ const projection = config.ignorePolicy ? "Remote paths shown under this device's ignore rules.\n\n" : "";
93
+ ctx.ui.notify(`${header}\n\n${projection}${formatDiff(local, portableSnapshot(remote, remote.localFields))}`, level);
81
94
  }
82
95
  export async function doctor(ctx, options, factory = createSyncBackend) {
83
96
  const messages = [];
84
97
  let level = "info";
85
- let snapshotOptions = {};
86
- let profile = DEFAULT_PROFILE;
98
+ let localConfig;
87
99
  let backend;
88
100
  let backendSummary = [];
89
101
  try {
90
102
  const config = await loadConfig(options.setup);
91
103
  throwIfAborted(options.signal);
104
+ localConfig = {
105
+ profile: config.snapshotIdentity,
106
+ snapshotOptions: await resolvedSnapshotOptionsForContext(ctx, config, options.signal),
107
+ };
92
108
  backend = await factory(config);
93
- profile = config.snapshotIdentity;
94
- snapshotOptions = snapshotOptionsForContext(ctx, config);
95
- messages.push(`config: ok (sync setup ${config.setupName})`, `included content: ${config.include.join(", ") || "none"}`, ...(config.exclude === undefined
96
- ? []
97
- : [`excluded paths: ${config.exclude.map(safeTerminalText).join(", ") || "none"}`]), `sessions: ${syncSessionsSelected(config) ? "included" : "excluded"}`);
109
+ messages.push(`config: ok (sync setup ${config.setupName})`, ...contentLines(config));
98
110
  backendSummary = [
99
111
  `storage location: ${safeTerminalText(backend.destination)}`,
100
112
  `publication safety: ${publicationCapabilityDescription(backend.capability)}`,
@@ -110,17 +122,21 @@ export async function doctor(ctx, options, factory = createSyncBackend) {
110
122
  level = "warning";
111
123
  messages.push(`config: ${errorMessage(error)}`);
112
124
  }
113
- const local = await createSnapshot(profile, snapshotOptions);
114
- throwIfAborted(options.signal);
115
- const secrets = scanSnapshot(local);
116
- if (secrets.length > 0) {
117
- level = "warning";
118
- messages.push("secret scan: possible secrets found:");
119
- messages.push(...secrets.map((secret) => `- ${secret}`));
120
- }
121
- else {
122
- messages.push(`secret scan: ok (${local.files.length} files checked)`);
125
+ if (localConfig) {
126
+ const local = await createSnapshot(localConfig.profile, localConfig.snapshotOptions);
127
+ throwIfAborted(options.signal);
128
+ const secrets = scanSnapshot(local);
129
+ if (secrets.length > 0) {
130
+ level = "warning";
131
+ messages.push("secret scan: possible secrets found:");
132
+ messages.push(...secrets.map((secret) => `- ${safeTerminalText(secret)}`));
133
+ }
134
+ else {
135
+ messages.push(`secret scan: ok (${local.files.length} files checked)`);
136
+ }
123
137
  }
138
+ else
139
+ messages.push("secret scan: skipped without a valid content policy");
124
140
  const lock = await inspectLock();
125
141
  throwIfAborted(options.signal);
126
142
  if (lock.status === "valid" && isStaleLock(lock.lock)) {
@@ -185,6 +201,7 @@ export async function history(ctx, options, factory = createSyncBackend) {
185
201
  await withLock("rollback", () => rollback(ctx, { ...options, args: [snapshot.snapshotRef], yes: false }, factory, {
186
202
  backendIdentity: backend.identity,
187
203
  setup: config.setupName,
204
+ snapshotId: snapshot.snapshotId,
188
205
  }));
189
206
  return;
190
207
  }
@@ -16,6 +16,17 @@ export declare function snapshotHashesMatchState(snapshot: Snapshot, state: Sync
16
16
  export declare function snapshotsMatch(left: Snapshot, right: Snapshot): boolean;
17
17
  export declare function syncPolicyChanged(state: SyncState, config: SyncPolicyConfig): boolean;
18
18
  export declare function shouldRefreshSyncedState(remote: Snapshot, head: RemoteHead | undefined, state: SyncState, config: SyncPolicyConfig, sameRevision: (left: string, right: string) => boolean): boolean;
19
+ export declare function acceptedSelection(config: SyncPolicyConfig & {
20
+ include: string[];
21
+ exclude?: string[];
22
+ reinclude?: string[];
23
+ }): {
24
+ include: string[];
25
+ ignorePolicyKey?: string | undefined;
26
+ exclude?: string[] | undefined;
27
+ scope?: "agent-directory" | undefined;
28
+ reinclude?: string[] | undefined;
29
+ };
19
30
  export declare function settingsHashMap(snapshot: Snapshot): {
20
31
  [k: string]: string;
21
32
  };
@@ -1,16 +1,28 @@
1
+ import { createHash } from "node:crypto";
1
2
  import { toPosix } from "../paths.js";
2
3
  import { canonicalSnapshotPathForConfig, filterSnapshotForConfigPolicy, isSessionPath } from "../snapshot/snapshot.js";
3
4
  import { sameSyncExclude } from "./exclude-policy.js";
4
5
  import { portableSnapshot, sameLocalFields } from "./local-fields.js";
5
- import { configuredSnapshotPathMatcher, customIncludePathsByLower, includeFromSelectionConfig, normalizeSyncInclude, syncSessionsSelected, } from "./sync-policy.js";
6
+ import { compareIgnorePolicy, configuredSnapshotPathMatcher, customIncludePathsByLower, includeFromSelectionConfig, normalizeSyncInclude, syncDirectoryPolicyKey, syncSessionsSelected, } from "./sync-policy.js";
7
+ function ignorePolicyKey(config) {
8
+ const key = config.ignorePolicy && syncDirectoryPolicyKey(config);
9
+ return key === undefined ? undefined : createHash("sha256").update(key).digest("hex");
10
+ }
6
11
  export function hasLocalChanges(local, state, config) {
7
12
  return ((Boolean(state.lastAppliedSnapshot) &&
8
- (!sameLocalFields(state.localFields, config.localFields) || !sameSyncExclude(state.exclude, config.exclude))) ||
13
+ (state.scope !== config.scope ||
14
+ !sameLocalFields(state.localFields, config.localFields) ||
15
+ !sameSelectionRules(state, config))) ||
9
16
  !sameHashes(fileHashMap(portableSnapshot(local, config.localFields)), stateHashMapForConfig(state, config)));
10
17
  }
11
18
  export function remoteChangedSinceState(head, state, config, sameRevision) {
12
19
  if (!head)
13
20
  return Boolean(state.lastAppliedSnapshot);
21
+ if (head.selection) {
22
+ const comparison = compareIgnorePolicy(config.ignorePolicy, head.selection);
23
+ if (comparison && comparison !== "match")
24
+ return true;
25
+ }
14
26
  if (head.snapshotId !== state.lastAppliedSnapshot)
15
27
  return true;
16
28
  if (state.lastRemoteRevision && !sameRevision(head.revision, state.lastRemoteRevision))
@@ -22,6 +34,9 @@ export function remoteChangedSinceState(head, state, config, sameRevision) {
22
34
  head.syncSessions);
23
35
  }
24
36
  export function hasRemoteChanges(remote, state, config, ignoredPaths = new Set()) {
37
+ const comparison = compareIgnorePolicy(config.ignorePolicy, remote.selection);
38
+ if (comparison && comparison !== "match")
39
+ return true;
25
40
  if (remote.id === state.lastAppliedSnapshot && !syncPolicyChanged(state, config))
26
41
  return false;
27
42
  return !snapshotHashesMatchState(portableSnapshot(filterSnapshotForConfigPolicy(remote, config), remote.localFields), state, config, ignoredPaths);
@@ -41,7 +56,10 @@ function stateHashMapForConfig(state, config) {
41
56
  const configured = configuredSnapshotPathMatcher(config);
42
57
  return Object.fromEntries(Object.entries(state.lastFileHashes)
43
58
  .filter(([filePath]) => configured(filePath))
44
- .map(([filePath, hash]) => [canonicalSnapshotPathForConfig(filePath, includePaths), hash]));
59
+ .map(([filePath, hash]) => [
60
+ config.scope === "agent-directory" ? filePath : canonicalSnapshotPathForConfig(filePath, includePaths),
61
+ hash,
62
+ ]));
45
63
  }
46
64
  export function snapshotHashesMatchState(snapshot, state, config, ignoredPaths = new Set()) {
47
65
  return sameHashes(withoutHashPaths(fileHashMap(snapshot), ignoredPaths), withoutHashPaths(stateHashMapForConfig(state, config), ignoredPaths));
@@ -55,8 +73,9 @@ function withoutHashPaths(hashes, ignoredPaths) {
55
73
  return Object.fromEntries(Object.entries(hashes).filter(([filePath]) => !ignoredPaths.has(toPosix(filePath))));
56
74
  }
57
75
  export function syncPolicyChanged(state, config) {
58
- return (syncIncludeChanged(state, config) ||
59
- !sameSyncExclude(state.exclude, config.exclude) ||
76
+ return (state.scope !== config.scope ||
77
+ syncIncludeChanged(state, config) ||
78
+ !sameSelectionRules(state, config) ||
60
79
  !sameLocalFields(state.localFields, config.localFields));
61
80
  }
62
81
  export function shouldRefreshSyncedState(remote, head, state, config, sameRevision) {
@@ -64,6 +83,24 @@ export function shouldRefreshSyncedState(remote, head, state, config, sameRevisi
64
83
  Boolean(head && (!state.lastRemoteRevision || !sameRevision(head.revision, state.lastRemoteRevision))) ||
65
84
  syncPolicyChanged(state, config));
66
85
  }
86
+ export function acceptedSelection(config) {
87
+ const key = ignorePolicyKey(config);
88
+ return {
89
+ include: config.ignorePolicy ? includeFromSelectionConfig(config) : [...config.include],
90
+ ...(key === undefined ? {} : { ignorePolicyKey: key }),
91
+ ...(config.exclude === undefined ? {} : { exclude: [...config.exclude] }),
92
+ ...(config.scope === undefined ? {} : { scope: config.scope }),
93
+ ...(config.reinclude === undefined ? {} : { reinclude: [...config.reinclude] }),
94
+ };
95
+ }
96
+ function sameSelectionRules(state, config) {
97
+ const key = ignorePolicyKey(config);
98
+ if (key !== undefined || state.ignorePolicyKey !== undefined)
99
+ return key === state.ignorePolicyKey;
100
+ return config.scope === "agent-directory" && state.scope === config.scope
101
+ ? syncDirectoryPolicyKey(state) === syncDirectoryPolicyKey(config)
102
+ : sameSyncExclude(state.exclude, config.exclude);
103
+ }
67
104
  function syncIncludeChanged(state, config) {
68
105
  const stored = state.include ? normalizeSyncInclude(state.include) : includeFromSelectionConfig(state);
69
106
  const current = includeFromSelectionConfig(config);
@@ -47,7 +47,7 @@ export function formatPushSummary(config, destination, upload, head, preservedRe
47
47
  ...excludedPolicyLines(config),
48
48
  head ? `Remote latest: ${safeTerminalText(head.snapshotId)}` : "Remote latest: empty",
49
49
  "Publication effect: the backend's active head will reference the new immutable snapshot. Removed paths leave the active snapshot; retained history is not erased.",
50
- ...(remote && inspectRemoteSelection(config.include, remote, config.exclude).kind === "different"
50
+ ...(remote && inspectRemoteSelection(config.include, remote, config.exclude, config).kind === "different"
51
51
  ? ["Included-content policy effect: replace the differing remote selection with this setup's local selection."]
52
52
  : []),
53
53
  formatPublicationPreview(remote, upload),
@@ -56,15 +56,30 @@ export function formatPushSummary(config, destination, upload, head, preservedRe
56
56
  : preservedRemoteFileCount > 0
57
57
  ? `Possible secrets in locally managed files were scanned before this prompt; ${preservedRemoteFileCount} preserved remote file(s) were not rescanned.`
58
58
  : "Possible secrets were scanned before this prompt.",
59
+ ...(config.scope === "agent-directory"
60
+ ? ["Warning: synced files may contain secrets or other sensitive data that the scanner cannot identify."]
61
+ : []),
59
62
  ].join("\n");
60
63
  }
61
64
  function excludedPolicyLines(config) {
62
- return config.exclude === undefined
63
- ? []
64
- : [
65
- `Excluded paths: ${config.exclude.map(safeTerminalText).join(", ") || "none"}`,
66
- "Excluded local files remain untouched; matching paths are omitted from new publications, not erased from history.",
67
- ];
65
+ const scoped = config.scope === "agent-directory";
66
+ return [
67
+ ...(scoped
68
+ ? [
69
+ "Scope: eligible files in the Pi agent directory.",
70
+ "Always local: Pi credentials (auth.json), project trust (trust.json), their lock files, and Pi Sync settings and service state.",
71
+ ]
72
+ : []),
73
+ ...(config.exclude === undefined && !scoped
74
+ ? []
75
+ : [`Excluded paths: ${(config.exclude ?? []).map(safeTerminalText).join(", ") || "none"}`]),
76
+ ...(scoped ? [`Re-included paths: ${(config.reinclude ?? []).map(safeTerminalText).join(", ") || "none"}`] : []),
77
+ ...(scoped || config.exclude !== undefined
78
+ ? [
79
+ "Excluded local files remain untouched; matching paths are omitted from new publications, not erased from history.",
80
+ ]
81
+ : []),
82
+ ];
68
83
  }
69
84
  export function formatApplyPreview(local, remote, protectedPaths = new Set(), additionalRemovals = []) {
70
85
  return formatDirectionalChanges(local, remote, {
@@ -32,6 +32,21 @@ export function createEngineService(root) {
32
32
  const host = installServiceHost(root);
33
33
  const monitor = createMonitor(root, host);
34
34
  const execute = (operation, payload, execution) => host.run(execution, async () => {
35
+ if (operation === "ignore.capabilities") {
36
+ execution.validate();
37
+ return { available: false };
38
+ }
39
+ if (operation === "ignore.migration-offer" || operation === "ignore.migration-defer") {
40
+ execution.validate();
41
+ const { readIgnoreMigrationOffer, deferIgnoreMigrationOffer } = await import("./engine/ignore/ignore-migration-prompt.js");
42
+ return operation === "ignore.migration-offer"
43
+ ? readIgnoreMigrationOffer(payload, execution)
44
+ : deferIgnoreMigrationOffer(payload, execution);
45
+ }
46
+ if (operation === "ignore.save") {
47
+ execution.validate();
48
+ throw new Error("Daemon ignore-file saves are unavailable. Edit the existing rule file manually.");
49
+ }
35
50
  await monitor.pause();
36
51
  execution.validate();
37
52
  if (operation === "daemon.authorize")
@@ -58,6 +73,11 @@ export function createEngineService(root) {
58
73
  }
59
74
  if (operation === "monitor.pause")
60
75
  return;
76
+ if (operation === "ignore.read") {
77
+ const { readIgnoreFileEdit } = await import("./engine/ignore/ignore-edit.js");
78
+ execution.validate();
79
+ return readIgnoreFileEdit(payload, execution);
80
+ }
61
81
  if (operation === "settings.read" || operation === "settings.repair-read") {
62
82
  const { readLocalConfigDocument } = await import("./engine/settings/settings-store.js");
63
83
  const { readActiveLocalConfigDocumentForRepair } = await import("./engine/settings/config-file.js");
@@ -81,8 +101,10 @@ export function createEngineService(root) {
81
101
  const { updateLocalConfigDocument, peekLocalConfigDocument } = await import("./engine/settings/config-file.js");
82
102
  const { localConfigTemplate } = await import("./engine/settings/settings-store.js");
83
103
  const { validateSettingsDocument } = await import("./engine/settings/settings-validation.js");
84
- const next = payload.next;
85
- validateSettingsDocument(next);
104
+ const next = validateSettingsDocument(payload.next);
105
+ if (Object.values(next.syncSetups).some((setup) => setup.sync.pathPolicy === "ignore-file")) {
106
+ throw new Error("Ignore-file setup activation is not available in this Daemon build.");
107
+ }
86
108
  if (Buffer.byteLength(JSON.stringify(next)) > MAX_SETTINGS_BYTES)
87
109
  throw new Error("Settings exceed the editable local API byte limit; no fields were dropped.");
88
110
  const validateSource = (document) => {
@@ -33,6 +33,20 @@ flowchart LR
33
33
 
34
34
  Read-only display state is not a second settings writer. A client proposes a validated new document with the exact source fingerprint; the authoritative writer checks the fingerprint under its settings lock. A stale editor must reopen rather than merge a stale approval automatically. Invalid existing JSON remains intact. Unknown fields remain in the proposed source clone.
35
35
 
36
+ The prepared ignore-file switch and migration require an existing `pi-sync.json`. They do not promote `pi-sync.local.json` or install an absent settings file: Node does not provide an atomic no-replace rename, and hard-link publication is not portable to Termux. The legacy file and any competing canonical file stay untouched by these operations. The writer rechecks the active path, identity, and exact bytes before replacing the canonical document. The shared lock orders cooperating writers but does not make a file check and rename atomic against external editors. The existing legacy settings workflow is unchanged.
37
+
38
+ ### Reviewed ignore policy changes (not enabled)
39
+
40
+ The internal switch and migration flows use the same settings writer. Migration keeps the resolved session opt-in; the rules can still exclude sessions. After preparing the files, migration checks the remote head before and after comparing the local paths under both policies. It omits only the starter file created by that operation from the prior policy's paths. It then rechecks the rule source and settings before publication. Policy validation reads the rule source under the shared settings lock and rechecks the settings document before accepting the source digest. A late refusal does not save the new policy or start a transfer; a verified starter file or private settings backup already prepared can remain. The remote head, filesystem inventory, and settings publication are not one atomic transaction.
41
+
42
+ Opening Settings can show an existing rule file path without reading or writing the rules. The daemon rejects `ignore.save`: Node does not provide an atomic rename conditional on the destination still matching the reviewed file. The daemon's locks do not extend to external editors. `ignore.read` checks reported live session files by device and inode so aliases cannot expose session text as rules.
43
+
44
+ ### Local ignore migration deferral
45
+
46
+ `ignore.migration-offer` and `ignore.migration-defer` require a current attached TUI client. The read returns an opaque token only for the requested active legacy setup without a deferral. Opening or dismissing a prompt does not persist a choice. An explicit decline must present the same setup and token, which binds the active document's path, file identity, and bytes to the migration version. `ignore.capabilities` reports `{ available: false }`; it does not enable migration. None of these operations pause the monitor, take the sync lock, contact a backend, or change settings or rules.
47
+
48
+ The local settings queue orders both operations. A read checks the active document under the cross-process config lock when settings or a writer lock are present. A decline always holds that lock. Before publishing a decline, the daemon rechecks the source and client and exclusively creates an empty private marker in the canonical root. This serializes cooperating writers; it is an optimistic check, not an atomic comparison against external editors or parent-directory replacement. Existing markers must be regular, private, single-link, and empty; unsafe paths are not overwritten. The marker name is denied by the snapshot path policy and stores only a hash of the setup name and migration version. Declining applies to that name on this device, including across settings edits and daemon restarts. Success waits for the file flush and, on POSIX, the root directory flush. Once created, the marker stays in place if its durability is uncertain; the operation reports the failure without modifying settings or removing the marker.
49
+
36
50
  ## Context inventory
37
51
 
38
52
  | Former Pi dependency | Engine host boundary | Source |
@@ -189,6 +203,20 @@ Pi core's settings storage has separate existing-file and missing-file branches
189
203
 
190
204
  These guarantees cover cooperating registered clients. Unregistered old Pi versions, external editors, shell commands, and arbitrary extensions remain independent writers. Preserve conservative preimage checks, recovery evidence, and explicit upgrade preconditions.
191
205
 
206
+ ### Agent-directory recovery evidence
207
+
208
+ Version 10 journals use unique workspace slots. Scratch files get separate unique slots in private directories on the destination filesystem. Recovery reads only the names that the durable journal or scratch record identifies. A failed publication can leave unrecorded objects, but it cannot block a new slot or authorize deleting the old one. The synced path policy excludes these private objects. Older journals keep their exact paths and identity checks; an upgrade does not adopt unrecorded data.
209
+
210
+ The ignore-file apply engine uses version 11 with the same workspace layout. It records local source evidence separately from the portable policy digest. Pending recovery requires the same reviewed rule source and a fresh source check under mutation ownership. Completed cleanup still uses the recorded workspace identity and does not replay file changes. The ignore-file policy is not yet enabled through setup or transfer routing; see [ADR 0008](../../../docs/adr/0008-pi-sync-ignore-file.md) for the proposed activation contract.
211
+
212
+ A merge journal can be retired when its recorded commit is already the accepted baseline, even if the remote policy has changed. This does not apply files from the newer head. The prepared ignore-policy merge engine also supports an archive-only review for a pending journal whose original remote head and accepted baseline still match. Directional force cannot skip that recovery. The review can keep newer local edits and archive the journal without changing the backup, the baseline, or the remote. Before retiring an inactive journal without review, recovery checks the baseline and policy, takes a fresh local snapshot, and rechecks the remote head. After archive-only approval, it checks the baseline and policy before the final remote read and rechecks session ownership before archiving. The operation lock orders daemon work but cannot make these reads atomic with external editors or remote writers. If the evidence is uncertain, recovery leaves the journal in place.
213
+
214
+ On macOS, setting a modification time earlier than a file's creation time can also move its creation time back. Before recording an empty scratch file's identity, recovery sets and flushes the backup's timestamps on that file. It reapplies the same timestamps after copying the bytes, then verifies the recorded identity and content before installation.
215
+
216
+ An identity that must survive edits uses the filesystem device, inode, and creation time. A change timestamp is not creation time: libuv's Unix stat fallback can report `ctime` as `birthtimeNs`, and Linux `statx` can report zero when birth time is absent. With equal positive timestamps on Linux or Android, the engine rechecks the object with synchronous `lstat` and looks for a same-device ancestor with a distinct birth time. These calls share libuv's synchronous `statx` path, which disables itself after falling back. If the engine cannot verify creation time, it stops before an action that needs durable identity. Atomic unlink and empty-directory removal do not need that proof. No identity check makes path-based operations atomic with respect to unrelated writers.
217
+
218
+ On Windows, NTFS can change a file's creation time when recovery renames it to a recently deleted name. An installed recovery vacancy can therefore match the recorded device and file ID when its exact restored bytes and original spelling also match. This exception applies only to the installed file. Recovery stages, removal ownership, and observations before rename retain their complete identity checks. Journal formats do not change, and a different file ID or changed content still blocks recovery.
219
+
192
220
  ## Explicit Continuous retry
193
221
 
194
222
  Validated `/sync sync` and manager **Sync now** requests record the requesting client's last target setup. Startup transfers, status reads, and separate refusal retries do not set this intent. Keep intents separate across clients, and retain them while another client is busy. Cancellation, session-generation replacement, disabled Continuous policy, and service shutdown cannot carry an old intent into a later activation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-sync-daemon",
3
- "version": "0.6.2",
3
+ "version": "0.8.0",
4
4
  "description": "A local synchronization daemon with a versioned client API.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -39,6 +39,7 @@
39
39
  "@earendil-works/pi-coding-agent": "1.6.0",
40
40
  "@earendil-works/pi-tui": "1.6.0",
41
41
  "fast-xml-parser": "^5.12.1",
42
+ "ignore": "^7.0.16",
42
43
  "minimatch": "^11.0.9",
43
44
  "proper-lockfile": "^4.1.2",
44
45
  "semver": "^7.8.6"