@narumitw/pi-sync 0.63.1 → 0.65.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.
- package/CHANGELOG.md +21 -0
- package/README.md +86 -10
- package/dist/chunks/{chunk-CKUGCBHP.ts → chunk-AYGMIMCV.ts} +2 -2
- package/dist/chunks/chunk-AYGMIMCV.ts.map +7 -0
- package/dist/chunks/{chunk-27F5W7DX.ts → chunk-DAZZ5BEJ.ts} +3 -1
- package/dist/chunks/chunk-DAZZ5BEJ.ts.map +7 -0
- package/dist/chunks/{chunk-VQ47JBLF.ts → chunk-FI2F5JBS.ts} +2 -2
- package/dist/chunks/{chunk-V76KCWHO.ts → chunk-IOM6E5FW.ts} +4 -4
- package/dist/chunks/{chunk-B5F3JLD3.ts → chunk-JQ5BAWW2.ts} +482 -78
- package/dist/chunks/chunk-JQ5BAWW2.ts.map +7 -0
- package/dist/chunks/{chunk-LBNC5AOM.ts → chunk-OBVJTKVY.ts} +12 -12
- package/dist/chunks/{chunk-EXDWEFIJ.ts → chunk-OWEOZZZE.ts} +6 -6
- package/dist/chunks/{chunk-SXCH4Q5O.ts → chunk-SZJOUVCL.ts} +3 -3
- package/dist/chunks/{chunk-HSCAFOT5.ts → chunk-TZMVSTAM.ts} +5 -5
- package/dist/chunks/{chunk-POWOMJ7S.ts → chunk-WJQ4TGN5.ts} +58 -31
- package/dist/chunks/chunk-WJQ4TGN5.ts.map +7 -0
- package/dist/chunks/{chunk-HLCML3OW.ts → chunk-XUZV4OGI.ts} +5 -3
- package/dist/chunks/chunk-XUZV4OGI.ts.map +7 -0
- package/dist/chunks/{command-handler-GMRRFWOL.ts → command-handler-YZ4DXQ7N.ts} +81 -30
- package/dist/chunks/command-handler-YZ4DXQ7N.ts.map +7 -0
- package/dist/chunks/{conflict-review-JWEA7DPQ.ts → conflict-review-J7L7S4AR.ts} +2 -2
- package/dist/chunks/{file-selection-KID23GAD.ts → file-selection-DDQN4LVD.ts} +9 -9
- package/dist/chunks/{manager-result-dispatcher-GDB74IOP.ts → manager-result-dispatcher-XB75YLEG.ts} +5 -5
- package/dist/chunks/{manager-ui-T5J5WG7T.ts → manager-ui-RGA26Z6G.ts} +103 -83
- package/dist/chunks/manager-ui-RGA26Z6G.ts.map +7 -0
- package/dist/chunks/{merge-review-OQDXNTJU.ts → merge-review-AAC674C6.ts} +3 -2
- package/dist/chunks/ownership-recovery-UDDHSDSZ.ts +59 -0
- package/dist/chunks/ownership-recovery-UDDHSDSZ.ts.map +7 -0
- package/dist/chunks/{remote-selection-ui-GPITNEBF.ts → remote-selection-ui-WVMET5RI.ts} +4 -4
- package/dist/chunks/{setup-switch-L54X5U5I.ts → setup-switch-644T6KHG.ts} +4 -4
- package/dist/chunks/{setup-wizard-LL6YMGUR.ts → setup-wizard-YP2KF2WQ.ts} +9 -9
- package/dist/chunks/{sync-inspection-SRU6HGGK.ts → sync-inspection-NBBTSMKR.ts} +5 -5
- package/dist/chunks/{sync-operations-UGSCONZ7.ts → sync-operations-AIEM2KL2.ts} +2 -2
- package/dist/daemon/dist/cli.js +2 -0
- package/dist/daemon/dist/client-transport.js +66 -0
- package/dist/daemon/dist/client.js +222 -354
- package/dist/daemon/dist/consent.js +33 -11
- package/dist/daemon/dist/daemon-debug.js +33 -0
- package/dist/daemon/dist/daemon-recovery.js +158 -0
- package/dist/daemon/dist/daemon-startup.js +257 -0
- package/dist/daemon/dist/engine/backends/git/git-backend.js +49 -13
- package/dist/daemon/dist/engine/backends/git/git-runner.js +6 -1
- package/dist/daemon/dist/engine/backends/git/git-storage.js +5 -9
- package/dist/daemon/dist/engine/backends/publication-encoding.js +19 -0
- package/dist/daemon/dist/engine/backends/s3/s3-backend.js +30 -21
- package/dist/daemon/dist/engine/backends/sync-backend.js +16 -0
- package/dist/daemon/dist/engine/backends/webdav/webdav-backend.js +34 -32
- package/dist/daemon/dist/engine/backends/webdav/webdav-client.js +10 -0
- package/dist/daemon/dist/engine/debug-log.js +134 -0
- package/dist/daemon/dist/engine/paths.js +7 -1
- package/dist/daemon/dist/engine/settings/config-file.js +62 -17
- package/dist/daemon/dist/engine/settings/config.js +49 -14
- package/dist/daemon/dist/engine/snapshot/snapshot-apply.js +30 -8
- package/dist/daemon/dist/engine/snapshot/snapshot-codec.js +3 -1
- package/dist/daemon/dist/engine/snapshot/snapshot-payload.js +32 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-images.js +34 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction.js +50 -7
- package/dist/daemon/dist/engine/snapshot/snapshot.js +64 -25
- package/dist/daemon/dist/engine/state/lock.js +157 -17
- package/dist/daemon/dist/engine/sync/continuous-sync.js +35 -11
- package/dist/daemon/dist/engine/sync/directional-action.js +124 -0
- package/dist/daemon/dist/engine/sync/initialization.js +2 -2
- package/dist/daemon/dist/engine/sync/local-fields.js +42 -19
- package/dist/daemon/dist/engine/sync/merged-sync.js +13 -10
- package/dist/daemon/dist/engine/sync/remote-snapshot.js +21 -4
- package/dist/daemon/dist/engine/sync/session-push.js +13 -4
- package/dist/daemon/dist/engine/sync/startup-bootstrap.js +105 -0
- package/dist/daemon/dist/engine/sync/startup-recovery-evidence.js +37 -0
- package/dist/daemon/dist/engine/sync/startup-timings.js +80 -8
- package/dist/daemon/dist/engine/sync/sync-error-guidance.js +6 -1
- package/dist/daemon/dist/engine/sync/sync-errors.js +20 -0
- package/dist/daemon/dist/engine/sync/sync-inspection.js +4 -7
- package/dist/daemon/dist/engine/sync/sync-local.js +59 -4
- package/dist/daemon/dist/engine/sync/sync-mutations.js +309 -337
- package/dist/daemon/dist/engine/sync/sync-policy.js +9 -1
- package/dist/daemon/dist/engine/sync/sync-queries.js +2 -1
- package/dist/daemon/dist/engine/sync/sync-rollback.js +198 -0
- package/dist/daemon/dist/engine/sync/sync-state.js +12 -4
- package/dist/daemon/dist/engine/sync/transfer-freshness.js +11 -5
- package/dist/daemon/dist/engine-service.js +122 -10
- package/dist/daemon/dist/foreground-queue-outcome.js +9 -0
- package/dist/daemon/dist/identity.js +36 -6
- package/dist/daemon/dist/index.js +2 -1
- package/dist/daemon/dist/monitor.js +21 -1
- package/dist/daemon/dist/paged-review.js +177 -0
- package/dist/daemon/dist/participant-ledger.js +149 -0
- package/dist/daemon/dist/protocol.js +4 -0
- package/dist/daemon/dist/server.js +340 -127
- package/dist/daemon/dist/service-host.js +83 -15
- package/dist/daemon/dist/state-wait-jobs.js +23 -0
- package/dist/daemon/dist/state-wait.js +34 -0
- package/dist/daemon/package.json +1 -1
- package/dist/index.ts +128 -48
- package/dist/index.ts.map +2 -2
- package/docs/continuous-sync-verification.md +2 -0
- package/docs/daemon-migration.md +31 -6
- package/docs/tui-contract.md +7 -1
- package/package.json +2 -2
- package/skills/configure-pi-sync/references/configuration.md +23 -13
- package/src/commands/command-execution.ts +67 -5
- package/src/commands/command-handler.ts +12 -3
- package/src/commands/command.ts +4 -2
- package/src/daemon/client-debug.ts +45 -0
- package/src/daemon/directional-recovery.ts +103 -0
- package/src/daemon/ownership-recovery.ts +50 -0
- package/src/daemon/pi-client.ts +399 -71
- package/src/daemon/startup-bootstrap-client.ts +26 -0
- package/src/settings/config.ts +1 -0
- package/src/sync/automatic-sync.ts +61 -18
- package/src/sync/startup-check.ts +13 -5
- package/src/sync-extension.ts +46 -8
- package/src/ui/cancellable-operation.ts +5 -2
- package/src/ui/manager-state.ts +31 -23
- package/src/ui/manager-ui.ts +45 -25
- package/src/ui/merge-review.ts +53 -18
- package/src/ui/settings-ui.ts +2 -2
- package/src/ui/sync-confirmation.ts +14 -17
- package/src/ui/sync-setups-ui.ts +15 -12
- package/dist/chunks/chunk-27F5W7DX.ts.map +0 -7
- package/dist/chunks/chunk-B5F3JLD3.ts.map +0 -7
- package/dist/chunks/chunk-CKUGCBHP.ts.map +0 -7
- package/dist/chunks/chunk-HLCML3OW.ts.map +0 -7
- package/dist/chunks/chunk-POWOMJ7S.ts.map +0 -7
- package/dist/chunks/command-handler-GMRRFWOL.ts.map +0 -7
- package/dist/chunks/manager-ui-T5J5WG7T.ts.map +0 -7
- /package/dist/chunks/{chunk-VQ47JBLF.ts.map → chunk-FI2F5JBS.ts.map} +0 -0
- /package/dist/chunks/{chunk-V76KCWHO.ts.map → chunk-IOM6E5FW.ts.map} +0 -0
- /package/dist/chunks/{chunk-LBNC5AOM.ts.map → chunk-OBVJTKVY.ts.map} +0 -0
- /package/dist/chunks/{chunk-EXDWEFIJ.ts.map → chunk-OWEOZZZE.ts.map} +0 -0
- /package/dist/chunks/{chunk-SXCH4Q5O.ts.map → chunk-SZJOUVCL.ts.map} +0 -0
- /package/dist/chunks/{chunk-HSCAFOT5.ts.map → chunk-TZMVSTAM.ts.map} +0 -0
- /package/dist/chunks/{conflict-review-JWEA7DPQ.ts.map → conflict-review-J7L7S4AR.ts.map} +0 -0
- /package/dist/chunks/{file-selection-KID23GAD.ts.map → file-selection-DDQN4LVD.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-GDB74IOP.ts.map → manager-result-dispatcher-XB75YLEG.ts.map} +0 -0
- /package/dist/chunks/{merge-review-OQDXNTJU.ts.map → merge-review-AAC674C6.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-GPITNEBF.ts.map → remote-selection-ui-WVMET5RI.ts.map} +0 -0
- /package/dist/chunks/{setup-switch-L54X5U5I.ts.map → setup-switch-644T6KHG.ts.map} +0 -0
- /package/dist/chunks/{setup-wizard-LL6YMGUR.ts.map → setup-wizard-YP2KF2WQ.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-SRU6HGGK.ts.map → sync-inspection-NBBTSMKR.ts.map} +0 -0
- /package/dist/chunks/{sync-operations-UGSCONZ7.ts.map → sync-operations-AIEM2KL2.ts.map} +0 -0
|
@@ -23,8 +23,14 @@ export async function handleCommand(
|
|
|
23
23
|
loaders: SyncLoaders,
|
|
24
24
|
attention: SyncAttentionController,
|
|
25
25
|
onExplicitSync?: (setup?: string) => void,
|
|
26
|
+
needsDaemonRecovery?: () => boolean,
|
|
26
27
|
) {
|
|
27
|
-
|
|
28
|
+
const args = splitArgs(rawArgs);
|
|
29
|
+
if (args[0] === "daemon" && args[1] === "recover") {
|
|
30
|
+
await executeCommand(rawArgs, ctx, sessionSignal, loaders);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!needsDaemonRecovery?.()) await reconcileObservation(attention, sessionSignal);
|
|
28
34
|
if (sessionSignal.aborted) return;
|
|
29
35
|
const run = (
|
|
30
36
|
route: string,
|
|
@@ -33,6 +39,7 @@ export async function handleCommand(
|
|
|
33
39
|
target?: string,
|
|
34
40
|
onDialog?: (active: boolean) => void,
|
|
35
41
|
retryRefusal = false,
|
|
42
|
+
directionalFingerprint?: string,
|
|
36
43
|
) => {
|
|
37
44
|
const [command, ...args] = splitArgs(route);
|
|
38
45
|
if (command === "sync" && !retryRefusal) {
|
|
@@ -53,6 +60,7 @@ export async function handleCommand(
|
|
|
53
60
|
target,
|
|
54
61
|
onDialog,
|
|
55
62
|
retryRefusal,
|
|
63
|
+
directionalFingerprint,
|
|
56
64
|
);
|
|
57
65
|
};
|
|
58
66
|
if (!rawArgs.trim()) {
|
|
@@ -61,6 +69,7 @@ export async function handleCommand(
|
|
|
61
69
|
const { showSyncManager } = await import("../ui/manager-ui.js");
|
|
62
70
|
if (sessionSignal.aborted) return;
|
|
63
71
|
await showSyncManager(ctx, run, sessionSignal, {
|
|
72
|
+
needsDaemonRecovery,
|
|
64
73
|
getAttention: () => attention.current(),
|
|
65
74
|
getObservation: () => attention.observation(),
|
|
66
75
|
onObservationInvalidated: () => attention.clearObservation(),
|
|
@@ -73,13 +82,13 @@ export async function handleCommand(
|
|
|
73
82
|
setSyncStatus(ctx, undefined);
|
|
74
83
|
ctx.ui.notify(errorMessage(error), "error");
|
|
75
84
|
}
|
|
76
|
-
if (sessionSignal.aborted) return;
|
|
85
|
+
if (sessionSignal.aborted || needsDaemonRecovery?.()) return;
|
|
77
86
|
await reconcileObservation(attention, sessionSignal);
|
|
78
87
|
if (!sessionSignal.aborted) await attention.publish(ctx, sessionSignal);
|
|
79
88
|
return;
|
|
80
89
|
}
|
|
81
90
|
const result = await run(rawArgs);
|
|
82
|
-
if (sessionSignal.aborted) return;
|
|
91
|
+
if (sessionSignal.aborted || needsDaemonRecovery?.()) return;
|
|
83
92
|
if (result.kind === "decision-required") {
|
|
84
93
|
ctx.ui.notify(result.decision.directMessage, "error");
|
|
85
94
|
} else if (result.kind === "remote-selection-required") {
|
package/src/commands/command.ts
CHANGED
|
@@ -19,7 +19,7 @@ export const SYNC_COMMANDS = [
|
|
|
19
19
|
{
|
|
20
20
|
name: "daemon",
|
|
21
21
|
description: "Review service handover and unattended permission",
|
|
22
|
-
usageSuffix: " [status|handover|allow-after-exit|revoke-after-exit]",
|
|
22
|
+
usageSuffix: " [status|recover|handover|allow-after-exit|revoke-after-exit]",
|
|
23
23
|
},
|
|
24
24
|
{ name: "push", description: "Upload local settings" },
|
|
25
25
|
{ name: "pull", description: "Apply remote settings" },
|
|
@@ -152,7 +152,7 @@ export function validateCommandOptions(command: string, options: CommandOptions)
|
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
const DAEMON_ACTIONS = ["status", "handover", "allow-after-exit", "revoke-after-exit"] as const;
|
|
155
|
+
const DAEMON_ACTIONS = ["status", "recover", "handover", "allow-after-exit", "revoke-after-exit"] as const;
|
|
156
156
|
|
|
157
157
|
export function completeSyncArguments(argumentPrefix: string): CommandArgumentCompletion[] | null {
|
|
158
158
|
const prefix = argumentPrefix.trimStart();
|
|
@@ -255,6 +255,8 @@ export function usage() {
|
|
|
255
255
|
return [
|
|
256
256
|
"Usage: /sync <command>",
|
|
257
257
|
`Commands: ${commands}`,
|
|
258
|
+
"In the /sync manager, Push to remote and Pull from remote use the chosen source and preserve a restore point without a second confirmation. Direct commands retain their existing review and flags.",
|
|
259
|
+
"Daemon diagnostics: /sync daemon recover reviews and stops the existing daemon. It does not start a replacement or retry a transfer.",
|
|
258
260
|
`Automatic sync: ${AUTOMATIC_SYNC_DESCRIPTION}`,
|
|
259
261
|
`Startup transfer: ${STARTUP_TRANSFER_DESCRIPTION}`,
|
|
260
262
|
"Automatic transfer at startup is a separate opt-in: one conflict-free established-baseline transfer at idle in TUI/RPC, with conditional/lease publication and no resource reload.",
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type DebugEvent, debugOperation } from "@narumitw/pi-sync-daemon/engine/debug-log";
|
|
2
|
+
|
|
3
|
+
export function observeDebugJob(operation: string, append: (event: DebugEvent) => void) {
|
|
4
|
+
const kind = debugOperation(operation);
|
|
5
|
+
if (!kind) return undefined;
|
|
6
|
+
let operationId: string | undefined;
|
|
7
|
+
const record = (outcome: Extract<DebugEvent, { event: "job" }>["outcome"]) =>
|
|
8
|
+
append({ event: "job", operation: kind, outcome, ...(operationId ? { operationId } : {}) });
|
|
9
|
+
return {
|
|
10
|
+
onSubmit(id: string) {
|
|
11
|
+
operationId = id;
|
|
12
|
+
record("started");
|
|
13
|
+
},
|
|
14
|
+
returned(result: unknown) {
|
|
15
|
+
if (result === "cancelled") record("cancelled");
|
|
16
|
+
else if (
|
|
17
|
+
result === "archived" ||
|
|
18
|
+
(kind === "initialize" &&
|
|
19
|
+
typeof result === "object" &&
|
|
20
|
+
result !== null &&
|
|
21
|
+
"handoverRequired" in result &&
|
|
22
|
+
result.handoverRequired === true)
|
|
23
|
+
)
|
|
24
|
+
record("blocked");
|
|
25
|
+
else if (
|
|
26
|
+
kind === "migrate-state" &&
|
|
27
|
+
typeof result === "object" &&
|
|
28
|
+
result !== null &&
|
|
29
|
+
"status" in result &&
|
|
30
|
+
result.status === "cancelled"
|
|
31
|
+
)
|
|
32
|
+
record("cancelled");
|
|
33
|
+
else record("completed");
|
|
34
|
+
},
|
|
35
|
+
rejected(error: unknown, cancelled: boolean) {
|
|
36
|
+
if (cancelled || (error instanceof Error && error.name === "AbortError")) record("cancelled");
|
|
37
|
+
else if (
|
|
38
|
+
error instanceof Error &&
|
|
39
|
+
(error.name === "SyncDecisionRequiredError" || error.name === "RemoteSelectionMismatchError")
|
|
40
|
+
)
|
|
41
|
+
record("blocked");
|
|
42
|
+
else record("failed");
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { DaemonConnection } from "@narumitw/pi-sync-daemon";
|
|
2
|
+
import { errorMessage } from "../sync/sync-errors.js";
|
|
3
|
+
|
|
4
|
+
export function isForegroundDirection(operation: string) {
|
|
5
|
+
return operation === "push.foreground" || operation === "pull.foreground";
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class DirectionalCheckpoint {
|
|
9
|
+
job?: string;
|
|
10
|
+
fingerprint?: string;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
readonly connection: DaemonConnection,
|
|
14
|
+
private readonly expected?: string,
|
|
15
|
+
) {}
|
|
16
|
+
|
|
17
|
+
accept(connection: DaemonConnection, job: string, fingerprint: unknown) {
|
|
18
|
+
if (
|
|
19
|
+
connection !== this.connection ||
|
|
20
|
+
this.job !== job ||
|
|
21
|
+
typeof fingerprint !== "string" ||
|
|
22
|
+
!/^[a-f0-9]{64}$/u.test(fingerprint) ||
|
|
23
|
+
(this.expected !== undefined && fingerprint !== this.expected) ||
|
|
24
|
+
(this.fingerprint !== undefined && fingerprint !== this.fingerprint)
|
|
25
|
+
)
|
|
26
|
+
return false;
|
|
27
|
+
this.fingerprint = fingerprint;
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function recoveryOutcome(value: unknown) {
|
|
33
|
+
if (!value || typeof value !== "object" || !("foregroundQueueCleanup" in value)) return;
|
|
34
|
+
if (value.foregroundQueueCleanup === "before-mutation") return { phase: "unchanged" as const };
|
|
35
|
+
if (value.foregroundQueueCleanup === "verified-result" && "result" in value)
|
|
36
|
+
return { phase: "completed" as const, result: value.result };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function restoreMessage(value: unknown): string {
|
|
40
|
+
return value && typeof value === "object" && "message" in value && typeof value.message === "string"
|
|
41
|
+
? ` ${value.message}`
|
|
42
|
+
: "";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export class CompletedDirectionalRecoveryError extends Error {}
|
|
46
|
+
|
|
47
|
+
function cancelledAfterCompletion(result: unknown, cause: unknown) {
|
|
48
|
+
const error = new CompletedDirectionalRecoveryError(
|
|
49
|
+
`The transfer finished, but file-queue recovery was cancelled.${restoreMessage(result)}`,
|
|
50
|
+
{ cause },
|
|
51
|
+
);
|
|
52
|
+
error.name = "AbortError";
|
|
53
|
+
return error;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function runDirectionalRecovery(
|
|
57
|
+
connection: DaemonConnection,
|
|
58
|
+
signal: AbortSignal,
|
|
59
|
+
run: (checkpoint: DirectionalCheckpoint, retryCheckpoint?: string) => Promise<unknown>,
|
|
60
|
+
recover: (connection: DaemonConnection, job: string, signal: AbortSignal) => Promise<DaemonConnection>,
|
|
61
|
+
markCleanupRequired: () => void,
|
|
62
|
+
) {
|
|
63
|
+
signal.throwIfAborted();
|
|
64
|
+
const attempt = new DirectionalCheckpoint(connection);
|
|
65
|
+
const result = await run(attempt);
|
|
66
|
+
const primary = recoveryOutcome(result);
|
|
67
|
+
if (!primary) return result;
|
|
68
|
+
markCleanupRequired();
|
|
69
|
+
let replacement: DaemonConnection;
|
|
70
|
+
const bounded = AbortSignal.any([signal, AbortSignal.timeout(45_000)]);
|
|
71
|
+
try {
|
|
72
|
+
bounded.throwIfAborted();
|
|
73
|
+
if (!attempt.job || (primary.phase === "unchanged" && !attempt.fingerprint))
|
|
74
|
+
throw new Error("The original transfer scope could not be verified.");
|
|
75
|
+
replacement = await recover(connection, attempt.job, bounded);
|
|
76
|
+
bounded.throwIfAborted();
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (signal.aborted) {
|
|
79
|
+
if (primary.phase === "completed") throw cancelledAfterCompletion(primary.result, signal.reason);
|
|
80
|
+
throw signal.reason;
|
|
81
|
+
}
|
|
82
|
+
const detail = bounded.aborted ? "The daemon did not recover in time." : errorMessage(error);
|
|
83
|
+
if (primary.phase === "completed")
|
|
84
|
+
throw new CompletedDirectionalRecoveryError(
|
|
85
|
+
`The transfer finished, but file-queue recovery stopped. ${detail}${restoreMessage(primary.result)}`,
|
|
86
|
+
{ cause: error },
|
|
87
|
+
);
|
|
88
|
+
throw new Error(`No transfer was applied, but file-queue recovery stopped. ${detail}`, { cause: error });
|
|
89
|
+
}
|
|
90
|
+
if (primary.phase === "completed") return primary.result;
|
|
91
|
+
const retry = new DirectionalCheckpoint(replacement, attempt.fingerprint);
|
|
92
|
+
const retried = await run(retry, attempt.fingerprint);
|
|
93
|
+
const remaining = recoveryOutcome(retried);
|
|
94
|
+
if (!remaining) return retried;
|
|
95
|
+
markCleanupRequired();
|
|
96
|
+
if (remaining.phase === "completed") {
|
|
97
|
+
if (signal.aborted) throw cancelledAfterCompletion(remaining.result, signal.reason);
|
|
98
|
+
throw new CompletedDirectionalRecoveryError(
|
|
99
|
+
`Transfer finished, but file-queue cleanup is still uncertain after one recovery attempt.${restoreMessage(remaining.result)}`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
throw new Error("File-queue release could not be verified after one recovery attempt. No transfer was applied.");
|
|
103
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { inspectDaemonRecovery, stopDaemonForRecovery } from "@narumitw/pi-sync-daemon";
|
|
3
|
+
import { errorMessage } from "../sync/sync-errors.js";
|
|
4
|
+
import { safeTerminalText } from "../ui/terminal-text.js";
|
|
5
|
+
import type { PiDaemonClient } from "./pi-client.js";
|
|
6
|
+
|
|
7
|
+
export async function recoverDaemonOwnership(
|
|
8
|
+
ctx: ExtensionContext,
|
|
9
|
+
client: Pick<PiDaemonClient, "root" | "validate" | "confirmRecoveryExit">,
|
|
10
|
+
signal: AbortSignal | undefined,
|
|
11
|
+
) {
|
|
12
|
+
function current() {
|
|
13
|
+
signal?.throwIfAborted();
|
|
14
|
+
client.validate();
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
current();
|
|
18
|
+
if (!ctx.hasUI || !["tui", "rpc"].includes(ctx.mode)) throw new Error("Daemon recovery requires TUI or RPC mode.");
|
|
19
|
+
const owner = await inspectDaemonRecovery(client.root, signal);
|
|
20
|
+
current();
|
|
21
|
+
if (!owner) {
|
|
22
|
+
ctx.ui.notify("No daemon is running for this agent directory. Use /reload before syncing.", "info");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const approved = await ctx.ui.confirm(
|
|
26
|
+
"Stop Pi Sync daemon for recovery?",
|
|
27
|
+
`Agent directory: ${safeTerminalText(owner.root)}\nPID: ${owner.pid}\n\nStop sync work for all Pi sessions using this daemon. This does not start a replacement, remove sync evidence, or retry a transfer.`,
|
|
28
|
+
{ signal },
|
|
29
|
+
);
|
|
30
|
+
current();
|
|
31
|
+
if (!approved) return;
|
|
32
|
+
await stopDaemonForRecovery(owner, signal);
|
|
33
|
+
current();
|
|
34
|
+
client.confirmRecoveryExit(owner);
|
|
35
|
+
ctx.ui.notify(
|
|
36
|
+
"Pi Sync daemon exited. Use /reload, then open /sync. If a stale lock remains, choose Restore sync access. Check the sync state before retrying any transfer.",
|
|
37
|
+
"info",
|
|
38
|
+
);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
try {
|
|
41
|
+
current();
|
|
42
|
+
} catch {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
ctx.ui.notify(
|
|
46
|
+
`Pi Sync daemon recovery could not finish: ${safeTerminalText(errorMessage(error))}\nKeep recovery files. Use /sync daemon recover to review the owner again, or follow the daemon CLI recovery guide.`,
|
|
47
|
+
"error",
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|