@narumitw/pi-sync-daemon 0.9.0 → 0.9.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @narumitw/pi-sync-daemon
2
2
 
3
+ ## 0.9.1
4
+
5
+ ### Patch Changes
6
+
7
+ - eb17fcc: Explain how to reduce sync scope when the agent-directory scan exceeds its limit. Replace outdated Check setup directions with current Diagnostics and storage settings paths.
8
+ - aa99878: Let Up and Down select sync confirmation actions immediately. Show directional counts and safety notes in the summary, with exact file paths available in View details instead of requiring a scroll through the entire file list.
9
+ - 8e32b4b: Exclude top-level `git/` package checkouts in new `.syncignore` starter files and list the starter rules in alphabetical order. Preserve existing rule files and recover interrupted creation with its original rules.
10
+
3
11
  ## 0.9.0
4
12
 
5
13
  ### Minor Changes
@@ -2,8 +2,12 @@ import { type IgnoreSource } from "./ignore-source.js";
2
2
  export declare class AutomaticIgnoreCreationUnavailable extends Error {
3
3
  }
4
4
  export declare function checkAutomaticIgnoreCreation(root: string, signal: AbortSignal): Promise<void>;
5
+ export declare function readPendingIgnoreCreation(root: string, signal: AbortSignal): Promise<{
6
+ token: string;
7
+ text: string;
8
+ }>;
5
9
  export declare function initializeDefaultIgnoreSource(root: string, signal?: AbortSignal): Promise<IgnoreSource>;
6
- export declare function prepareDefaultIgnoreSource(root: string, signal?: AbortSignal): Promise<{
10
+ export declare function prepareDefaultIgnoreSource(root: string, signal?: AbortSignal, reviewedCreation?: string | null): Promise<{
7
11
  source: IgnoreSource;
8
12
  created: boolean;
9
13
  }>;
@@ -2,8 +2,11 @@ import { constants, lstatSync, realpathSync, unlinkSync } from "node:fs";
2
2
  import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { DEFAULT_IGNORE_CREATION_RECORD, DEFAULT_IGNORE_FILENAME, DEFAULT_IGNORE_RULES, ignoreFileIdentity, readIgnoreSource, sameFile, sameIdentity, } from "./ignore-source.js";
5
- const starter = Buffer.from(DEFAULT_IGNORE_RULES);
6
- const record = Buffer.from(`pi-sync-ignore-creation-v1\n${DEFAULT_IGNORE_RULES}`);
5
+ const recordPrefix = "pi-sync-ignore-creation-v1\n";
6
+ const records = [
7
+ Buffer.from(`${recordPrefix}${DEFAULT_IGNORE_RULES}`),
8
+ Buffer.from(`${recordPrefix}/npm/\n/sessions/\n/auth.json\n/truth.json\n`),
9
+ ];
7
10
  const noFollow = (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0);
8
11
  const openRead = constants.O_RDONLY | noFollow;
9
12
  const openExisting = process.platform === "win32" ? constants.O_RDWR | noFollow : openRead;
@@ -28,10 +31,35 @@ export async function checkAutomaticIgnoreCreation(root, signal) {
28
31
  signal.throwIfAborted();
29
32
  }
30
33
  }
34
+ function creationRecordToken(stat) {
35
+ return `${ignoreFileIdentity(stat)}:${stat.size}:${stat.ctimeNs}:${stat.mtimeNs}`;
36
+ }
37
+ export async function readPendingIgnoreCreation(root, signal) {
38
+ signal.throwIfAborted();
39
+ root = path.resolve(root);
40
+ const initialRoot = await fs.lstat(root, { bigint: true });
41
+ const checkRoot = () => {
42
+ signal.throwIfAborted();
43
+ assertRoot(root, initialRoot);
44
+ };
45
+ checkRoot();
46
+ const target = path.join(root, DEFAULT_IGNORE_CREATION_RECORD);
47
+ const prior = await fs.lstat(target, { bigint: true });
48
+ assertOwned(prior, DEFAULT_IGNORE_CREATION_RECORD, true);
49
+ const marker = await fs.open(target, openRead);
50
+ try {
51
+ const { stat, bytes } = await verifyCreationFile(marker, target, target, records, checkRoot, prior, false);
52
+ return { token: creationRecordToken(stat), text: bytes.toString("utf8", recordPrefix.length) };
53
+ }
54
+ finally {
55
+ await marker.close();
56
+ signal.throwIfAborted();
57
+ }
58
+ }
31
59
  export async function initializeDefaultIgnoreSource(root, signal) {
32
60
  return (await prepareDefaultIgnoreSource(root, signal)).source;
33
61
  }
34
- export async function prepareDefaultIgnoreSource(root, signal) {
62
+ export async function prepareDefaultIgnoreSource(root, signal, reviewedCreation) {
35
63
  signal?.throwIfAborted();
36
64
  root = path.resolve(root);
37
65
  try {
@@ -43,6 +71,10 @@ export async function prepareDefaultIgnoreSource(root, signal) {
43
71
  };
44
72
  checkRoot();
45
73
  const priorRecord = statAt(path.join(root, DEFAULT_IGNORE_CREATION_RECORD));
74
+ if (reviewedCreation !== undefined &&
75
+ reviewedCreation !== (priorRecord ? creationRecordToken(priorRecord) : null)) {
76
+ changed(DEFAULT_IGNORE_CREATION_RECORD);
77
+ }
46
78
  if (!priorRecord) {
47
79
  const source = await readIgnoreSource(root, DEFAULT_IGNORE_FILENAME, signal);
48
80
  checkRoot();
@@ -67,7 +99,8 @@ export async function prepareDefaultIgnoreSource(root, signal) {
67
99
  throw error;
68
100
  });
69
101
  try {
70
- const markerStat = await flushAndVerify(marker, markerPath, path.join(root, DEFAULT_IGNORE_CREATION_RECORD), record, priorRecord ? checkRoot : verifyRoot, priorRecord, true);
102
+ const { stat: markerStat, bytes } = await verifyCreationFile(marker, markerPath, path.join(root, DEFAULT_IGNORE_CREATION_RECORD), records, priorRecord ? checkRoot : verifyRoot, priorRecord);
103
+ const starter = bytes.subarray(recordPrefix.length);
71
104
  await flushDirectory();
72
105
  checkRoot();
73
106
  assertCurrent(markerPath, markerStat);
@@ -85,7 +118,7 @@ export async function prepareDefaultIgnoreSource(root, signal) {
85
118
  });
86
119
  try {
87
120
  const checkTargetRoot = priorFile ? checkRoot : verifyRoot;
88
- const fileStat = await flushAndVerify(file, target, path.join(root, DEFAULT_IGNORE_FILENAME), starter, () => {
121
+ const { stat: fileStat } = await verifyCreationFile(file, target, path.join(root, DEFAULT_IGNORE_FILENAME), [starter], () => {
89
122
  checkTargetRoot();
90
123
  assertCurrent(markerPath, markerStat);
91
124
  }, priorFile);
@@ -98,7 +131,7 @@ export async function prepareDefaultIgnoreSource(root, signal) {
98
131
  checkRoot();
99
132
  const source = await readIgnoreSource(root, DEFAULT_IGNORE_FILENAME, signal);
100
133
  checkRoot();
101
- if (source.identity !== ignoreFileIdentity(fileStat) || source.text !== DEFAULT_IGNORE_RULES) {
134
+ if (source.identity !== ignoreFileIdentity(fileStat) || source.text !== starter.toString("utf8")) {
102
135
  changed(DEFAULT_IGNORE_FILENAME);
103
136
  }
104
137
  return { source, created: priorFile === undefined };
@@ -210,8 +243,9 @@ function assertOwned(stat, name, privateRecord) {
210
243
  throw new Error(`unsafe "${name}"; preserve it for manual recovery`);
211
244
  }
212
245
  }
213
- async function flushAndVerify(handle, target, canonical, expected, checkRoot, prior, privateRecord = false) {
246
+ async function verifyCreationFile(handle, target, canonical, expected, checkRoot, prior, persist = true) {
214
247
  const name = path.basename(target);
248
+ const privateRecord = name === DEFAULT_IGNORE_CREATION_RECORD;
215
249
  const opened = await handle.stat({ bigint: true });
216
250
  assertOwned(opened, name, privateRecord);
217
251
  if (prior && !sameFile(prior, opened))
@@ -221,15 +255,15 @@ async function flushAndVerify(handle, target, canonical, expected, checkRoot, pr
221
255
  throw new Error(`use the exact on-disk filename "${name}"`);
222
256
  checkRoot();
223
257
  assertCurrent(target, opened);
224
- if (!prior)
225
- await handle.writeFile(expected);
258
+ if (!prior && persist)
259
+ await handle.writeFile(expected[0]);
226
260
  const before = await handle.stat({ bigint: true });
227
261
  assertOwned(before, name, privateRecord);
228
262
  if (!(prior ? sameFile(opened, before) : sameIdentity(opened, before)))
229
263
  changed(name);
230
264
  checkRoot();
231
265
  assertCurrent(target, before);
232
- const observed = Buffer.alloc(expected.length + 1);
266
+ const observed = Buffer.alloc(Math.max(...expected.map((bytes) => bytes.length)) + 1);
233
267
  let count = 0;
234
268
  while (count < observed.length) {
235
269
  checkRoot();
@@ -238,15 +272,17 @@ async function flushAndVerify(handle, target, canonical, expected, checkRoot, pr
238
272
  break;
239
273
  count += bytesRead;
240
274
  }
241
- if (count !== expected.length || !observed.subarray(0, count).equals(expected)) {
275
+ const bytes = expected.find((candidate) => observed.subarray(0, count).equals(candidate));
276
+ if (!bytes) {
242
277
  throw new Error(privateRecord
243
278
  ? `invalid creation record "${name}"; preserve it for manual recovery`
244
- : `unfinished creation of "${name}"; move the incomplete file outside the Pi agent directory or restore the full starter rules, then retry confirmed setup or migration`);
279
+ : `unfinished creation of "${name}"; move the incomplete file outside the Pi agent directory or restore the full starter rules recorded in "${DEFAULT_IGNORE_CREATION_RECORD}", then retry confirmed setup or migration`);
245
280
  }
246
- await handle.sync();
281
+ if (persist)
282
+ await handle.sync();
247
283
  if (!sameFile(before, await handle.stat({ bigint: true })))
248
284
  changed(name);
249
285
  checkRoot();
250
286
  assertCurrent(target, before);
251
- return before;
287
+ return { stat: before, bytes };
252
288
  }
@@ -21,7 +21,7 @@ import { requireNoMergeJournal } from "../sync/merge-journal.js";
21
21
  import { configuredSnapshotPathMatcher } from "../sync/sync-policy.js";
22
22
  import { safeTerminalText, snapshotPathLabel } from "../ui/terminal-text.js";
23
23
  import { compileEffectiveIgnorePolicy } from "./effective-ignore-policy.js";
24
- import { AutomaticIgnoreCreationUnavailable, checkAutomaticIgnoreCreation, prepareDefaultIgnoreSource, } from "./ignore-initialization.js";
24
+ import { AutomaticIgnoreCreationUnavailable, checkAutomaticIgnoreCreation, prepareDefaultIgnoreSource, readPendingIgnoreCreation, } from "./ignore-initialization.js";
25
25
  import { assertCurrentIgnoreMigrationOffer } from "./ignore-migration-prompt.js";
26
26
  import { compileIgnoreRules, DEFAULT_IGNORE_CREATION_RECORD, DEFAULT_IGNORE_FILENAME, DEFAULT_IGNORE_RULES, IgnoreCreationPendingError, ignoreSourceDigest, readIgnoreSource, validateIgnoreFilename, } from "./ignore-source.js";
27
27
  export function runIgnorePolicyChange(operation, payload, execution) {
@@ -93,18 +93,14 @@ async function readSetupSource(root, filename, signal) {
93
93
  !(error instanceof Error) ||
94
94
  !(error.cause instanceof IgnoreCreationPendingError))
95
95
  throw error;
96
- if ((await fs.realpath(root)) !== root)
97
- throw error;
98
- const marker = await fs.lstat(path.join(root, DEFAULT_IGNORE_CREATION_RECORD), { bigint: true });
96
+ const { text, token } = await readPendingIgnoreCreation(root, signal);
99
97
  signal.throwIfAborted();
100
- if (!marker.isFile() || marker.nlink !== 1n)
101
- throw error;
102
98
  return {
103
99
  filename,
104
100
  present: false,
105
- text: DEFAULT_IGNORE_RULES,
106
- sourceDigest: ignoreSourceDigest(filename, false, Buffer.from(DEFAULT_IGNORE_RULES)),
107
- pendingCreation: `${marker.dev}:${marker.ino}:${marker.size}:${marker.ctimeNs}:${marker.mtimeNs}`,
101
+ text,
102
+ sourceDigest: ignoreSourceDigest(filename, false, Buffer.from(text)),
103
+ pendingCreation: token,
108
104
  };
109
105
  }
110
106
  }
@@ -170,7 +166,7 @@ export async function prepareReviewedIgnoreSource(root, reviewed, execution) {
170
166
  stale();
171
167
  if (current.present)
172
168
  return { source: current, created: false };
173
- const prepared = await prepareDefaultIgnoreSource(root, execution.signal).catch((error) => {
169
+ const prepared = await prepareDefaultIgnoreSource(root, execution.signal, current.pendingCreation ?? null).catch((error) => {
174
170
  execution.validate();
175
171
  throw creationFailure(root, current, error);
176
172
  });
@@ -342,11 +338,12 @@ export async function migrateIgnoreSetup(execution, setupName, offerToken) {
342
338
  }));
343
339
  }
344
340
  function describeSource(source) {
345
- if (source.pendingCreation)
346
- return "Verify or complete the interrupted creation of the starter rules. Incomplete content will not be used.";
347
- return source.present
348
- ? "Keep the existing rule file unchanged."
341
+ if (source.present)
342
+ return "Keep the existing rule file unchanged.";
343
+ const action = source.pendingCreation
344
+ ? "Verify or complete the interrupted creation of the starter rules. Incomplete content will not be used."
349
345
  : "Create the default rule file with the starter rules.";
346
+ return `${action}\n${source.text.trimEnd()}`;
350
347
  }
351
348
  function describeChanges(label, before, after) {
352
349
  const oldPaths = new Set(before);
@@ -1,7 +1,7 @@
1
1
  import { type BigIntStats } from "node:fs";
2
2
  export declare const DEFAULT_IGNORE_FILENAME = ".syncignore";
3
3
  export declare const DEFAULT_IGNORE_CREATION_RECORD = ".pi-sync.json.syncignore-creation";
4
- export declare const DEFAULT_IGNORE_RULES = "/npm/\n/sessions/\n/auth.json\n/truth.json\n";
4
+ export declare const DEFAULT_IGNORE_RULES = "/auth.json\n/git/\n/npm/\n/sessions/\n/truth.json\n";
5
5
  export declare const MAX_IGNORE_BYTES: number;
6
6
  export type IgnoreSource = {
7
7
  filename: string;
@@ -6,7 +6,7 @@ import ignore from "ignore";
6
6
  import { isDeniedPath } from "../paths.js";
7
7
  export const DEFAULT_IGNORE_FILENAME = ".syncignore";
8
8
  export const DEFAULT_IGNORE_CREATION_RECORD = ".pi-sync.json.syncignore-creation";
9
- export const DEFAULT_IGNORE_RULES = "/npm/\n/sessions/\n/auth.json\n/truth.json\n";
9
+ export const DEFAULT_IGNORE_RULES = "/auth.json\n/git/\n/npm/\n/sessions/\n/truth.json\n";
10
10
  export const MAX_IGNORE_BYTES = 64 * 1024;
11
11
  const MAX_MATCH_PATH_BYTES = 4_096;
12
12
  const MATCH_CACHE_PATH_BUDGET = 2_048;
@@ -15,20 +15,33 @@ export function syncErrorGuidance(error) {
15
15
  else if (code && ["EBUSY", "EIO", "EMFILE", "ENFILE"].includes(code)) {
16
16
  next = "Check local disk availability and other processes using the private settings file, then retry.";
17
17
  }
18
+ else if (/\bagent directory exceeds the scan entry bound\b/iu.test(message)) {
19
+ next =
20
+ "Reduce the number of entries Pi Sync must scan before retrying. Exclude whole subdirectories to skip their contents. Use /sync config to review the active scope.";
21
+ }
22
+ else if (/\bprojected agent directory exceeds the (64 MiB scan byte|scan file) bound\b/iu.test(message)) {
23
+ next =
24
+ "The resulting files would exceed the sync limit. Review the current scope with /sync config and reduce the local or incoming sync content before retrying.";
25
+ }
26
+ else if (/\bagent directory exceeds the (64 MiB scan byte|scan file) bound\b/iu.test(message)) {
27
+ next =
28
+ "Reduce the files managed by this setup before retrying. Use /sync config to find the active ignore file, or edit Agent directory scope in /sync → Settings for legacy rules.";
29
+ }
18
30
  else if (/changed while|type changed|reopen/iu.test(message)) {
19
31
  next = "Reopen the item in /sync and review its current settings before saving again.";
20
32
  }
21
33
  else if (status === 401 ||
22
34
  status === 403 ||
23
35
  /Permission denied|Authentication failed|HTTP (401|403)|failed \((401|403)\)/iu.test(message)) {
24
- next = "Check the storage connection's credentials and remote permissions in /sync → More → Storage connections.";
36
+ next =
37
+ "Check the storage connection's credentials and remote permissions. In the TUI, open /sync → Settings → Manage storage connections.";
25
38
  }
26
39
  else if (status === 404 || /HTTP 404|failed \(404\)/iu.test(message)) {
27
40
  next =
28
41
  "Verify the connection address and setup's bucket, branch, or path with your provider; this response alone does not prove which resource is missing.";
29
42
  }
30
43
  else if (status !== undefined && status >= 500) {
31
- next = "Check your storage provider's service status, then retry Check setup before syncing.";
44
+ next = "Check your storage provider's service status, then run /sync doctor before syncing.";
32
45
  }
33
46
  else if (/timed out|timeout|request failed|resolve host|Could not resolve|ENOTFOUND|ECONNREFUSED/iu.test(message)) {
34
47
  next = "Check the server address and network connection, then run /sync doctor for the affected setup.";
@@ -49,7 +62,7 @@ export function syncErrorGuidance(error) {
49
62
  "Correct the named field or item in /sync. If the settings file is invalid, repair it before retrying; do not replace it with defaults.";
50
63
  }
51
64
  else {
52
- next = "Open /sync → More → Check setup and review the reported checks before retrying.";
65
+ next = "For setup and storage checks, run /sync doctor or choose Diagnostics in /sync.";
53
66
  }
54
67
  return `${message}\n${next}`;
55
68
  }
@@ -7,7 +7,7 @@ import { applySnapshot } from "../snapshot/snapshot-apply.js";
7
7
  import { ignorePolicyValidator } from "../snapshot/snapshot-transaction-policy.js";
8
8
  import { pruneMergeBaselines } from "../state/merge-baseline-store.js";
9
9
  import { readStateForConfig, syncStateFingerprint, writeStateForConfig } from "../state/sync-state-store.js";
10
- import { countPreservedRemoteFiles, formatPublicationPreview, formatPullSummary, formatPushSummary, formatRollbackSummary, } from "../ui/sync-format.js";
10
+ import { countPreservedRemoteFiles, formatPublicationPreview, formatPullSummary, formatPushSummary, formatRollbackSummary, formatTransferReview, } from "../ui/sync-format.js";
11
11
  import { setSyncStatus } from "../ui/sync-status.js";
12
12
  import { confirmTransferReview } from "../ui/transfer-review.js";
13
13
  import { startupTransferEnabled } from "./agent-policy.js";
@@ -605,8 +605,8 @@ export async function rollback(ctx, options, factory = createSyncBackend, expect
605
605
  const title = snapshotIncludesSessions(remote) ? "Rollback pi settings and sessions?" : "Rollback pi settings?";
606
606
  const summary = formatRollbackSummary(config, backend.destination, local, physical, target, reviewedProtectedPaths, caseCleanup.map((item) => item.path));
607
607
  const confirmed = config.ignorePolicy
608
- ? await confirmTransferReview(ctx, title, `Historical files are projected through this device's current ignore rules. Historical rules are not adopted. Retained history is not erased.\n\n${summary}\n\nRemote publication:\n${formatPublicationPreview(currentRemote, upload)}`, options.signal, validateMutation)
609
- : await ctx.ui.confirm(title, summary, { signal: options.signal });
608
+ ? await confirmTransferReview(ctx, title, formatTransferReview("Historical files are projected through this device's current ignore rules. Historical rules are not adopted. Retained history is not erased.", "", summary, "", "Remote publication:", formatPublicationPreview(currentRemote, upload)), options.signal, validateMutation)
609
+ : await ctx.ui.confirm(title, summary.content, { signal: options.signal });
610
610
  validateMutation();
611
611
  if (!confirmed) {
612
612
  ctx.ui.notify("Rollback cancelled.", "info");
@@ -739,7 +739,7 @@ async function confirmPush(ctx, options, config, backend, local, upload, head, r
739
739
  ? inspectRemoteSelection(config.include, remote, config.exclude, config).ignorePolicyComparison
740
740
  : undefined;
741
741
  const confirmed = await confirmTransferReview(ctx, title, comparison && comparison !== "match"
742
- ? `${formatIgnorePolicyComparison(comparison)}\nOnly files selected by this device's rules are published. Remote rules are not adopted.\n\n${summary}`
742
+ ? formatTransferReview(formatIgnorePolicyComparison(comparison), "Only files selected by this device's rules are published. Remote rules are not adopted.", "", summary)
743
743
  : summary, options.signal, validateMutation);
744
744
  throwIfAborted(options.signal);
745
745
  if (confirmed)
@@ -3,11 +3,22 @@ import type { CommonSyncConfig } from "../settings/settings-types.js";
3
3
  import type { Snapshot } from "../snapshot/snapshot-types.js";
4
4
  export declare function formatDiff(local: Snapshot, remote: Snapshot): string;
5
5
  export declare function formatSnapshotOnlyDiff(title: string, snapshot: Snapshot): string;
6
- export declare function formatPushSummary(config: CommonSyncConfig, destination: string, upload: Snapshot, head: RemoteHead | undefined, preservedRemoteFileCount?: number, remote?: Snapshot): string;
7
- export declare function formatApplyPreview(local: Snapshot, remote: Snapshot, protectedPaths?: ReadonlySet<string>, additionalRemovals?: readonly string[]): string;
8
- export declare function formatPullSummary(config: CommonSyncConfig, destination: string, local: Snapshot, remote: Snapshot, protectedPaths: ReadonlySet<string>, additionalRemovals?: readonly string[]): string;
9
- export declare function formatRollbackSummary(config: CommonSyncConfig, destination: string, local: Snapshot, remote: Snapshot, requestedSnapshot: string, protectedPaths: ReadonlySet<string>, additionalRemovals?: readonly string[]): string;
10
- export declare function formatPublicationPreview(remote: Snapshot | undefined, upload: Snapshot): string;
6
+ export interface TransferReview {
7
+ lines: readonly string[];
8
+ content: string;
9
+ }
10
+ export declare function formatTransferReview(...sections: (string | TransferReview)[]): TransferReview;
11
+ export declare function formatPushSummary(config: CommonSyncConfig, destination: string, upload: Snapshot, head: RemoteHead | undefined, preservedRemoteFileCount?: number, remote?: Snapshot): TransferReview;
12
+ export declare function formatApplyPreview(local: Snapshot, remote: Snapshot, protectedPaths?: ReadonlySet<string>, additionalRemovals?: readonly string[]): {
13
+ lines: string[];
14
+ content: string;
15
+ };
16
+ export declare function formatPullSummary(config: CommonSyncConfig, destination: string, local: Snapshot, remote: Snapshot, protectedPaths: ReadonlySet<string>, additionalRemovals?: readonly string[]): TransferReview;
17
+ export declare function formatRollbackSummary(config: CommonSyncConfig, destination: string, local: Snapshot, remote: Snapshot, requestedSnapshot: string, protectedPaths: ReadonlySet<string>, additionalRemovals?: readonly string[]): TransferReview;
18
+ export declare function formatPublicationPreview(remote: Snapshot | undefined, upload: Snapshot): {
19
+ lines: string[];
20
+ content: string;
21
+ };
11
22
  export declare function countPreservedRemoteFiles(local: Snapshot, upload: Snapshot): number;
12
23
  export declare function publicationCapabilityDescription(capability: PublicationCapability): "atomic-conditional (verified atomic precondition)" | "conditional-required (read-only until atomic preconditions are verified)" | "lease-protected (exact expected-ref update)" | "read-check-write-verify (visible races rejected; simultaneous unseen races remain possible)";
13
24
  export declare function redact(value: string): string;
@@ -37,29 +37,22 @@ export function formatSnapshotOnlyDiff(title, snapshot) {
37
37
  ...snapshot.files.map((file) => `Add: ${snapshotPathLabel(file.path)}`),
38
38
  ].join("\n");
39
39
  }
40
+ export function formatTransferReview(...sections) {
41
+ return {
42
+ lines: sections.flatMap((section) => (typeof section === "string" ? section.split("\n") : section.lines)),
43
+ content: sections.map((section) => (typeof section === "string" ? section : section.content)).join("\n"),
44
+ };
45
+ }
40
46
  export function formatPushSummary(config, destination, upload, head, preservedRemoteFileCount = 0, remote) {
41
- return [
42
- `Sync setup: ${safeTerminalText(config.setupName)}`,
43
- `Storage location: ${safeTerminalText(destination)}`,
44
- `Direction: Local → Remote. Source: ${safeTerminalText(agentDir())}.`,
45
- `Publish a snapshot containing ${upload.files.length} files; unchanged and preserved files are not counted as changes.`,
46
- `Sessions: ${upload.syncSessions ? "included — may contain private conversations" : "not included"}`,
47
- ...excludedPolicyLines(config),
48
- head ? `Remote latest: ${safeTerminalText(head.snapshotId)}` : "Remote latest: empty",
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, config).kind === "different"
51
- ? ["Included-content policy effect: replace the differing remote selection with this setup's local selection."]
52
- : []),
53
- formatPublicationPreview(remote, upload),
54
- config.skipSecretScan
55
- ? "Warning: possible-secret scanning is disabled for this push."
56
- : preservedRemoteFileCount > 0
57
- ? `Possible secrets in locally managed files were scanned before this prompt; ${preservedRemoteFileCount} preserved remote file(s) were not rescanned.`
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
- : []),
62
- ].join("\n");
47
+ return formatTransferReview(`Sync setup: ${safeTerminalText(config.setupName)}`, `Storage location: ${safeTerminalText(destination)}`, `Direction: Local → Remote. Source: ${safeTerminalText(agentDir())}.`, `Publish a snapshot containing ${upload.files.length} files; unchanged and preserved files are not counted as changes.`, `Sessions: ${upload.syncSessions ? "included — may contain private conversations" : "not included"}`, ...excludedPolicyLines(config), head ? `Remote latest: ${safeTerminalText(head.snapshotId)}` : "Remote latest: empty", "Publication effect: the backend's active head will reference the new immutable snapshot. Removed paths leave the active snapshot; retained history is not erased.", ...(remote && inspectRemoteSelection(config.include, remote, config.exclude, config).kind === "different"
48
+ ? ["Included-content policy effect: replace the differing remote selection with this setup's local selection."]
49
+ : []), formatPublicationPreview(remote, upload), config.skipSecretScan
50
+ ? "Warning: possible-secret scanning is disabled for this push."
51
+ : preservedRemoteFileCount > 0
52
+ ? `Possible secrets in locally managed files were scanned before this prompt; ${preservedRemoteFileCount} preserved remote file(s) were not rescanned.`
53
+ : "Possible secrets were scanned before this prompt.", ...(config.scope === "agent-directory"
54
+ ? ["Warning: synced files may contain secrets or other sensitive data that the scanner cannot identify."]
55
+ : []));
63
56
  }
64
57
  function excludedPolicyLines(config) {
65
58
  const scoped = config.scope === "agent-directory";
@@ -89,36 +82,10 @@ export function formatApplyPreview(local, remote, protectedPaths = new Set(), ad
89
82
  }, protectedPaths, additionalRemovals);
90
83
  }
91
84
  export function formatPullSummary(config, destination, local, remote, protectedPaths, additionalRemovals = []) {
92
- return [
93
- `Sync setup: ${safeTerminalText(config.setupName)}`,
94
- `Storage location: ${safeTerminalText(destination)}`,
95
- "Direction: Remote → Local.",
96
- `Snapshot: ${safeTerminalText(remote.id)}`,
97
- ...excludedPolicyLines(config),
98
- `Sessions: ${remote.syncSessions ? "included — may contain private conversations" : "not included"}`,
99
- `Protected live sessions: ${protectedPaths.size || "none"}`,
100
- formatApplyPreview(local, remote, protectedPaths, additionalRemovals),
101
- ...(additionalRemovals.length
102
- ? ["Case-variant aliases listed above are removed before writing canonical paths."]
103
- : []),
104
- "A local backup is created before these writes/deletes. The remote active snapshot is unchanged.",
105
- ].join("\n");
85
+ return formatTransferReview(`Sync setup: ${safeTerminalText(config.setupName)}`, `Storage location: ${safeTerminalText(destination)}`, "Direction: Remote → Local.", `Snapshot: ${safeTerminalText(remote.id)}`, ...excludedPolicyLines(config), `Sessions: ${remote.syncSessions ? "included — may contain private conversations" : "not included"}`, `Protected live sessions: ${protectedPaths.size || "none"}`, formatApplyPreview(local, remote, protectedPaths, additionalRemovals), ...(additionalRemovals.length ? ["Case-variant aliases are removed before writing canonical paths."] : []), "A local backup is created before these writes/deletes. The remote active snapshot is unchanged.");
106
86
  }
107
87
  export function formatRollbackSummary(config, destination, local, remote, requestedSnapshot, protectedPaths, additionalRemovals = []) {
108
- return [
109
- `Sync setup: ${safeTerminalText(config.setupName)}`,
110
- `Storage location: ${safeTerminalText(destination)}`,
111
- "Direction: Historical snapshot → Local and remote active head.",
112
- `Snapshot: ${safeTerminalText(requestedSnapshot)}`,
113
- ...excludedPolicyLines(config),
114
- `Sessions: ${remote.syncSessions ? "included — may contain private conversations" : "not included"}`,
115
- `Protected live sessions: ${protectedPaths.size || "none"}`,
116
- formatApplyPreview(local, remote, protectedPaths, additionalRemovals),
117
- ...(additionalRemovals.length
118
- ? ["Case-variant aliases listed above are removed before writing canonical paths."]
119
- : []),
120
- "A local backup is created before applying; the backend's active head will change.",
121
- ].join("\n");
88
+ return formatTransferReview(`Sync setup: ${safeTerminalText(config.setupName)}`, `Storage location: ${safeTerminalText(destination)}`, "Direction: Historical snapshot → Local and remote active head.", `Snapshot: ${safeTerminalText(requestedSnapshot)}`, ...excludedPolicyLines(config), `Sessions: ${remote.syncSessions ? "included — may contain private conversations" : "not included"}`, `Protected live sessions: ${protectedPaths.size || "none"}`, formatApplyPreview(local, remote, protectedPaths, additionalRemovals), ...(additionalRemovals.length ? ["Case-variant aliases are removed before writing canonical paths."] : []), "A local backup is created before applying; the backend's active head will change.");
122
89
  }
123
90
  export function formatPublicationPreview(remote, upload) {
124
91
  return formatDirectionalChanges(remote, upload, {
@@ -138,11 +105,12 @@ function formatDirectionalChanges(before, after, labels, protectedPaths = new Se
138
105
  }
139
106
  const counts = transferCounts(changes);
140
107
  const label = { Add: labels.add, Update: labels.update, Delete: labels.remove };
141
- return [
142
- `Changes: ${counts.add} add · ${counts.update} update · ${counts.remove} remove`,
143
- ...changes.map((change) => `${label[change.action]}: ${snapshotPathLabel(change.path)}`),
144
- ...(changes.length ? [] : ["No file changes."]),
145
- ].join("\n");
108
+ const heading = `Changes: ${counts.add} add · ${counts.update} update · ${counts.remove} remove`;
109
+ const lines = changes.length ? [heading] : [heading, "No file changes."];
110
+ return {
111
+ lines,
112
+ content: [...lines, ...changes.map((change) => `${label[change.action]}: ${snapshotPathLabel(change.path)}`)].join("\n"),
113
+ };
146
114
  }
147
115
  export function countPreservedRemoteFiles(local, upload) {
148
116
  const localPaths = new Set(local.files.map((file) => file.path));
@@ -1,3 +1,4 @@
1
1
  import type { EngineContext } from "../host.js";
2
+ import type { TransferReview } from "./sync-format.js";
2
3
  /** Presentation is supplied by the host; RPC keeps its existing directional confirmation. */
3
- export declare function confirmTransferReview(ctx: EngineContext, title: string, content: string, signal: AbortSignal | undefined, validate: () => void): Promise<boolean>;
4
+ export declare function confirmTransferReview(ctx: EngineContext, title: string, review: TransferReview, signal: AbortSignal | undefined, validate: () => void): Promise<boolean>;
@@ -1,6 +1,6 @@
1
1
  import { confirmMergeReview } from "./merge-review.js";
2
2
  /** Presentation is supplied by the host; RPC keeps its existing directional confirmation. */
3
- export async function confirmTransferReview(ctx, title, content, signal, validate) {
3
+ export async function confirmTransferReview(ctx, title, review, signal, validate) {
4
4
  validate();
5
5
  const isCurrent = () => {
6
6
  try {
@@ -12,8 +12,8 @@ export async function confirmTransferReview(ctx, title, content, signal, validat
12
12
  }
13
13
  };
14
14
  const confirmed = ctx.mode === "tui" && ctx.hasUI
15
- ? await confirmMergeReview(ctx, title, content, signal, isCurrent, "apply reviewed transfer", content.split("\n"))
16
- : await ctx.ui.confirm(title, content, { signal });
15
+ ? await confirmMergeReview(ctx, title, review.content, signal, isCurrent, "apply reviewed transfer", review.lines)
16
+ : await ctx.ui.confirm(title, review.content, { signal });
17
17
  validate();
18
18
  return confirmed;
19
19
  }
@@ -64,7 +64,7 @@ A version 6 snapshot carries portable intent (a versioned fingerprint of ordered
64
64
  | `ctx.isIdle()` | Current participating-client facts, not a captured Pi context | `service-host.ts` |
65
65
  | Protected sessions and missing-settings guard | All live client PIDs, including retired clients; separate from active participation | `server.ts`, `service-host.ts` |
66
66
  | `ctx.ui.notify`, status | Bounded events | `server.ts`, `service-host.ts` |
67
- | Confirm/select/exact merge review | Job-bound callbacks; revalidation after response | `service-host.ts`, `engine/ui/merge-review.ts` |
67
+ | Confirm/select/exact merge review | Job-bound callbacks; revalidation after response; directional TUI review sends compact summary lines and the full path list as separate fields | `service-host.ts`, `engine/ui/transfer-review.ts` |
68
68
  | Reload | Explicit client callback after the existing user confirmation | `engine/sync/sync-mutations.ts` |
69
69
  | `ctx.model`, `modelRegistry.streamSimple` | Explicit selected model identity/signature; independent public SDK runtime | `model-signature.ts`, `resolver-host.ts` |
70
70
  | `withFileMutationQueue` | Participating Pi queue grants plus daemon-local queue | `service-host.ts`, Pi adapter `daemon/apply-gate.ts` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-sync-daemon",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "A local synchronization daemon with a versioned client API.",
5
5
  "type": "module",
6
6
  "license": "MIT",