@narumitw/pi-sync 0.63.1 → 0.64.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 +11 -0
- package/README.md +12 -5
- package/dist/chunks/{chunk-HLCML3OW.ts → chunk-4VKWHVUO.ts} +4 -3
- package/dist/chunks/chunk-4VKWHVUO.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-V76KCWHO.ts → chunk-F3VODLVQ.ts} +3 -3
- package/dist/chunks/{chunk-VQ47JBLF.ts → chunk-FI2F5JBS.ts} +2 -2
- package/dist/chunks/{chunk-LBNC5AOM.ts → chunk-NDEZ52SS.ts} +12 -12
- package/dist/chunks/{chunk-B5F3JLD3.ts → chunk-RW44KNFD.ts} +304 -70
- package/dist/chunks/chunk-RW44KNFD.ts.map +7 -0
- package/dist/chunks/{chunk-EXDWEFIJ.ts → chunk-TJ7YNITN.ts} +5 -5
- package/dist/chunks/{chunk-HSCAFOT5.ts → chunk-TZMVSTAM.ts} +5 -5
- package/dist/chunks/{chunk-SXCH4Q5O.ts → chunk-VPSC7BXM.ts} +3 -3
- package/dist/chunks/{chunk-POWOMJ7S.ts → chunk-YT6PDRMM.ts} +58 -31
- package/dist/chunks/chunk-YT6PDRMM.ts.map +7 -0
- package/dist/chunks/{command-handler-GMRRFWOL.ts → command-handler-N45GY7AV.ts} +39 -27
- package/dist/chunks/command-handler-N45GY7AV.ts.map +7 -0
- package/dist/chunks/{conflict-review-JWEA7DPQ.ts → conflict-review-5E4M44BA.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-FKW55L7I.ts} +5 -5
- package/dist/chunks/{manager-ui-T5J5WG7T.ts → manager-ui-EV23DPZQ.ts} +75 -57
- package/dist/chunks/manager-ui-EV23DPZQ.ts.map +7 -0
- package/dist/chunks/{merge-review-OQDXNTJU.ts → merge-review-6YSLSMGS.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-N4NMWFT2.ts} +4 -4
- package/dist/chunks/{setup-switch-L54X5U5I.ts → setup-switch-HY7K3442.ts} +4 -4
- package/dist/chunks/{setup-wizard-LL6YMGUR.ts → setup-wizard-LEKDQ3HK.ts} +9 -9
- package/dist/chunks/{sync-inspection-SRU6HGGK.ts → sync-inspection-OS2LVOLV.ts} +5 -5
- package/dist/chunks/{sync-operations-UGSCONZ7.ts → sync-operations-D3MDJUQQ.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 +116 -86
- package/dist/daemon/dist/consent.js +33 -11
- package/dist/daemon/dist/daemon-debug.js +33 -0
- package/dist/daemon/dist/daemon-recovery.js +75 -0
- package/dist/daemon/dist/engine/backends/git/git-backend.js +39 -12
- 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 +10 -12
- package/dist/daemon/dist/engine/backends/webdav/webdav-backend.js +15 -26
- 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/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 +18 -3
- 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-inspection.js +4 -7
- package/dist/daemon/dist/engine/sync/sync-local.js +3 -1
- package/dist/daemon/dist/engine/sync/sync-mutations.js +9 -3
- package/dist/daemon/dist/engine/sync/sync-policy.js +9 -1
- package/dist/daemon/dist/engine/sync/sync-state.js +12 -4
- package/dist/daemon/dist/engine-service.js +54 -10
- package/dist/daemon/dist/identity.js +36 -6
- package/dist/daemon/dist/index.js +2 -1
- package/dist/daemon/dist/monitor.js +20 -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 +268 -120
- package/dist/daemon/dist/service-host.js +29 -9
- 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 +30 -2
- 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 +11 -3
- package/src/commands/command-handler.ts +10 -3
- package/src/commands/command.ts +3 -2
- package/src/daemon/client-debug.ts +45 -0
- package/src/daemon/ownership-recovery.ts +50 -0
- package/src/daemon/pi-client.ts +288 -63
- 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/manager-state.ts +29 -21
- package/src/ui/manager-ui.ts +16 -1
- package/src/ui/merge-review.ts +52 -16
- package/src/ui/settings-ui.ts +2 -2
- package/src/ui/sync-confirmation.ts +16 -19
- 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-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-V76KCWHO.ts.map → chunk-F3VODLVQ.ts.map} +0 -0
- /package/dist/chunks/{chunk-VQ47JBLF.ts.map → chunk-FI2F5JBS.ts.map} +0 -0
- /package/dist/chunks/{chunk-LBNC5AOM.ts.map → chunk-NDEZ52SS.ts.map} +0 -0
- /package/dist/chunks/{chunk-EXDWEFIJ.ts.map → chunk-TJ7YNITN.ts.map} +0 -0
- /package/dist/chunks/{chunk-HSCAFOT5.ts.map → chunk-TZMVSTAM.ts.map} +0 -0
- /package/dist/chunks/{chunk-SXCH4Q5O.ts.map → chunk-VPSC7BXM.ts.map} +0 -0
- /package/dist/chunks/{conflict-review-JWEA7DPQ.ts.map → conflict-review-5E4M44BA.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-FKW55L7I.ts.map} +0 -0
- /package/dist/chunks/{merge-review-OQDXNTJU.ts.map → merge-review-6YSLSMGS.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-GPITNEBF.ts.map → remote-selection-ui-N4NMWFT2.ts.map} +0 -0
- /package/dist/chunks/{setup-switch-L54X5U5I.ts.map → setup-switch-HY7K3442.ts.map} +0 -0
- /package/dist/chunks/{setup-wizard-LL6YMGUR.ts.map → setup-wizard-LEKDQ3HK.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-SRU6HGGK.ts.map → sync-inspection-OS2LVOLV.ts.map} +0 -0
- /package/dist/chunks/{sync-operations-UGSCONZ7.ts.map → sync-operations-D3MDJUQQ.ts.map} +0 -0
|
@@ -7,6 +7,10 @@ import { readConsent } from "./consent.js";
|
|
|
7
7
|
import { configureEngineHost } from "./engine/host.js";
|
|
8
8
|
import { canonicalRootGuard, processExists } from "./identity.js";
|
|
9
9
|
import { withCleanup } from "./lifecycle.js";
|
|
10
|
+
import { OWNERSHIP_CLEANUP_REQUIRED } from "./protocol.js";
|
|
11
|
+
class OwnershipCleanupError extends Error {
|
|
12
|
+
code = OWNERSHIP_CLEANUP_REQUIRED;
|
|
13
|
+
}
|
|
10
14
|
const scope = new AsyncLocalStorage();
|
|
11
15
|
/** One service process owns one root; tests must use a separate process per root. */
|
|
12
16
|
export function installServiceHost(root, ignoreFileOperationsAvailable) {
|
|
@@ -27,7 +31,7 @@ export function installServiceHost(root, ignoreFileOperationsAvailable) {
|
|
|
27
31
|
const owner = current();
|
|
28
32
|
assertRoot();
|
|
29
33
|
if (poisoned)
|
|
30
|
-
throw new
|
|
34
|
+
throw new OwnershipCleanupError("Daemon ownership cleanup is uncertain; stop and reconcile before retrying.");
|
|
31
35
|
const missing = [...new Set(targets)].filter((target) => !owner.held.has(target)).sort();
|
|
32
36
|
if (!missing.length)
|
|
33
37
|
return action();
|
|
@@ -52,16 +56,17 @@ export function installServiceHost(root, ignoreFileOperationsAvailable) {
|
|
|
52
56
|
}, async () => {
|
|
53
57
|
// Release by request identity even when a grant response was lost. A cancelled
|
|
54
58
|
// prompt is not evidence that a granted remote writer stopped.
|
|
55
|
-
const results = await Promise.allSettled(requested.map(({ client, reservation }) => {
|
|
59
|
+
const results = await Promise.allSettled(requested.map(async ({ client, reservation }) => {
|
|
56
60
|
const peer = peers.find((peer) => peer.id === client);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
if (peer && !processExists(peer.pid))
|
|
62
|
+
return;
|
|
63
|
+
if ((await owner.execution.request("queue-release", { reservation }, client)) !== true)
|
|
64
|
+
throw new Error("File-queue release was not acknowledged.");
|
|
60
65
|
}));
|
|
61
66
|
const failure = results.find((result) => result.status === "rejected");
|
|
62
67
|
if (failure?.status === "rejected") {
|
|
63
68
|
poisoned = true;
|
|
64
|
-
throw new
|
|
69
|
+
throw new OwnershipCleanupError("File-queue release is uncertain; stop the daemon and keep grants quarantined until owner exit.", { cause: failure.reason });
|
|
65
70
|
}
|
|
66
71
|
});
|
|
67
72
|
}
|
|
@@ -71,7 +76,7 @@ export function installServiceHost(root, ignoreFileOperationsAvailable) {
|
|
|
71
76
|
root: () => {
|
|
72
77
|
assertRoot();
|
|
73
78
|
if (poisoned)
|
|
74
|
-
throw new
|
|
79
|
+
throw new OwnershipCleanupError("Daemon ownership cleanup is uncertain; stop and reconcile before restarting.");
|
|
75
80
|
return root;
|
|
76
81
|
},
|
|
77
82
|
reserveTargets: reserve,
|
|
@@ -106,7 +111,9 @@ export function installServiceHost(root, ignoreFileOperationsAvailable) {
|
|
|
106
111
|
}
|
|
107
112
|
catch (error) {
|
|
108
113
|
poisoned = true;
|
|
109
|
-
throw
|
|
114
|
+
throw new OwnershipCleanupError("Pi settings lock release failed; stop and reconcile before restarting.", {
|
|
115
|
+
cause: error,
|
|
116
|
+
});
|
|
110
117
|
}
|
|
111
118
|
});
|
|
112
119
|
});
|
|
@@ -120,8 +127,21 @@ export function installServiceHost(root, ignoreFileOperationsAvailable) {
|
|
|
120
127
|
status: (_ctx, value, presentation) => current().execution.emit("status", { value, presentation }),
|
|
121
128
|
});
|
|
122
129
|
return {
|
|
130
|
+
cleanupRequired: () => poisoned,
|
|
123
131
|
run(execution, action) {
|
|
124
|
-
return scope.run({ execution, held: new Set() },
|
|
132
|
+
return scope.run({ execution, held: new Set() }, async () => {
|
|
133
|
+
try {
|
|
134
|
+
return await action();
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
if (error instanceof AggregateError) {
|
|
138
|
+
const cleanup = error.errors.find((entry) => entry instanceof OwnershipCleanupError);
|
|
139
|
+
if (cleanup)
|
|
140
|
+
throw new OwnershipCleanupError(`${error.message} ${cleanup.message}`, { cause: error });
|
|
141
|
+
}
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
125
145
|
},
|
|
126
146
|
};
|
|
127
147
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DAEMON_JOB_CAPACITY, record, validId } from "./protocol.js";
|
|
2
|
+
export const STATE_WAIT_FAILURE_LIMIT = 3;
|
|
3
|
+
export function stateWaitResult(reply) {
|
|
4
|
+
if (!record(reply) ||
|
|
5
|
+
typeof reply.stateRevision !== "string" ||
|
|
6
|
+
!/^[0-9]{1,40}$/u.test(reply.stateRevision) ||
|
|
7
|
+
!Array.isArray(reply.finished) ||
|
|
8
|
+
!Array.isArray(reply.missing) ||
|
|
9
|
+
!reply.finished.every(validId) ||
|
|
10
|
+
!reply.missing.every(validId))
|
|
11
|
+
throw new Error("Invalid daemon state-wait response.");
|
|
12
|
+
return { reply, version: reply.stateRevision, finished: reply.finished, missing: reply.missing };
|
|
13
|
+
}
|
|
14
|
+
export function stateWaitJobs(waiters) {
|
|
15
|
+
if (waiters.size <= DAEMON_JOB_CAPACITY)
|
|
16
|
+
return [...waiters.keys()];
|
|
17
|
+
const batch = [...waiters.entries()].slice(0, DAEMON_JOB_CAPACITY);
|
|
18
|
+
return batch.map(([id, waiter]) => {
|
|
19
|
+
waiters.delete(id);
|
|
20
|
+
waiters.set(id, waiter);
|
|
21
|
+
return id;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { STATE_WAIT_HEARTBEAT_MS } from "./protocol.js";
|
|
2
|
+
export class ParticipantStateWait {
|
|
3
|
+
revision = 0n;
|
|
4
|
+
wake;
|
|
5
|
+
get version() {
|
|
6
|
+
return this.revision.toString();
|
|
7
|
+
}
|
|
8
|
+
changed() {
|
|
9
|
+
this.revision++;
|
|
10
|
+
this.wake?.();
|
|
11
|
+
}
|
|
12
|
+
wait(version, signal) {
|
|
13
|
+
signal?.throwIfAborted();
|
|
14
|
+
this.wake?.();
|
|
15
|
+
if (version !== this.version)
|
|
16
|
+
return;
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const finish = () => {
|
|
19
|
+
clearTimeout(timer);
|
|
20
|
+
signal?.removeEventListener("abort", abort);
|
|
21
|
+
this.wake = undefined;
|
|
22
|
+
resolve();
|
|
23
|
+
};
|
|
24
|
+
const abort = () => {
|
|
25
|
+
reject(signal?.reason);
|
|
26
|
+
finish();
|
|
27
|
+
};
|
|
28
|
+
const timer = setTimeout(finish, STATE_WAIT_HEARTBEAT_MS);
|
|
29
|
+
timer.unref();
|
|
30
|
+
this.wake = finish;
|
|
31
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
package/dist/daemon/package.json
CHANGED
package/dist/index.ts
CHANGED
|
@@ -7,34 +7,34 @@ import {
|
|
|
7
7
|
createSyncAttentionController,
|
|
8
8
|
readStateForConfig,
|
|
9
9
|
syncStateFingerprint
|
|
10
|
-
} from "./chunks/chunk-
|
|
10
|
+
} from "./chunks/chunk-FI2F5JBS.ts";
|
|
11
|
+
import {
|
|
12
|
+
combineSignals,
|
|
13
|
+
throwIfAborted
|
|
14
|
+
} from "./chunks/chunk-UMPA5S7X.ts";
|
|
11
15
|
import {
|
|
12
16
|
completeSyncArguments,
|
|
13
17
|
setSyncSetupCompletions,
|
|
14
18
|
splitArgs
|
|
15
|
-
} from "./chunks/chunk-
|
|
19
|
+
} from "./chunks/chunk-4VKWHVUO.ts";
|
|
16
20
|
import {
|
|
17
21
|
withStateDirectoryAccess
|
|
18
22
|
} from "./chunks/chunk-T3LABNHF.ts";
|
|
19
23
|
import {
|
|
20
24
|
snapshotOptionsForContext
|
|
21
25
|
} from "./chunks/chunk-P4GI7LTT.ts";
|
|
22
|
-
import {
|
|
23
|
-
bindPiDaemonClient,
|
|
24
|
-
installPiDaemonHost,
|
|
25
|
-
piDaemonClient,
|
|
26
|
-
withPiDaemonClient
|
|
27
|
-
} from "./chunks/chunk-B5F3JLD3.ts";
|
|
28
|
-
import {
|
|
29
|
-
combineSignals,
|
|
30
|
-
throwIfAborted
|
|
31
|
-
} from "./chunks/chunk-UMPA5S7X.ts";
|
|
32
26
|
import "./chunks/chunk-ZO52JM4H.ts";
|
|
33
27
|
import {
|
|
34
28
|
configFromSettings,
|
|
35
29
|
loadConfigForCheck,
|
|
36
30
|
syncCheckConfigFingerprint
|
|
37
|
-
} from "./chunks/chunk-
|
|
31
|
+
} from "./chunks/chunk-DAZZ5BEJ.ts";
|
|
32
|
+
import {
|
|
33
|
+
bindPiDaemonClient,
|
|
34
|
+
installPiDaemonHost,
|
|
35
|
+
piDaemonClient,
|
|
36
|
+
withPiDaemonClient
|
|
37
|
+
} from "./chunks/chunk-RW44KNFD.ts";
|
|
38
38
|
import {
|
|
39
39
|
configureSyncStatus,
|
|
40
40
|
createSyncStatusPublisher,
|
|
@@ -66,24 +66,59 @@ async function startSession(ctx, signal, publish) {
|
|
|
66
66
|
return { debug: false };
|
|
67
67
|
}
|
|
68
68
|
const timings = createStartupTimings(publish);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
69
|
+
let showLocalTimings = false;
|
|
70
|
+
let localStartupComplete = false;
|
|
71
|
+
try {
|
|
72
|
+
const { document, settings } = await timings.measure("settings read", () => client.readStartupSettings(signal));
|
|
73
|
+
client.validate();
|
|
74
|
+
throwIfAborted(signal);
|
|
75
|
+
const debug = settings?.debug ?? false;
|
|
76
|
+
client.setDebugPreference(debug);
|
|
77
|
+
configureSyncStatus(ctx, settings?.showStatus ?? true);
|
|
78
|
+
const { stateDirectoryMigrationNotice } = await import("./chunks/state-directory-CMAIF34J.ts");
|
|
79
|
+
client.validate();
|
|
80
|
+
throwIfAborted(signal);
|
|
81
|
+
const notice = stateDirectoryMigrationNotice();
|
|
82
|
+
if (settings?.activeSyncSetup && document) {
|
|
83
|
+
const ready = !notice && await client.tryStartupBootstrap(document, debug, signal);
|
|
84
|
+
client.validate();
|
|
85
|
+
throwIfAborted(signal);
|
|
86
|
+
if (ready) {
|
|
87
|
+
setSyncSetupCompletions(Object.keys(settings.syncSetups).sort((a, b) => a.localeCompare(b)));
|
|
88
|
+
showLocalTimings = debug;
|
|
89
|
+
localStartupComplete = true;
|
|
90
|
+
return { debug, config: configFromSettings(settings) };
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
const { pendingTransactionEntries } = await import("./chunks/snapshot-transaction-directory-F46JWRAU.ts");
|
|
94
|
+
const recoveryNeeded = (await pendingTransactionEntries()).length > 0;
|
|
95
|
+
client.validate();
|
|
96
|
+
throwIfAborted(signal);
|
|
97
|
+
if (!recoveryNeeded) {
|
|
98
|
+
if (notice) ctx.ui.notify(notice, "warning");
|
|
99
|
+
setSyncSetupCompletions([]);
|
|
100
|
+
await client.markReady(debug);
|
|
101
|
+
client.validate();
|
|
102
|
+
throwIfAborted(signal);
|
|
103
|
+
client.recordDebug({ event: "job", operation: "initialize", outcome: "skipped" });
|
|
104
|
+
showLocalTimings = debug;
|
|
105
|
+
localStartupComplete = true;
|
|
106
|
+
return { debug };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
localStartupComplete = true;
|
|
110
|
+
} finally {
|
|
111
|
+
timings.publish(
|
|
112
|
+
ctx,
|
|
113
|
+
showLocalTimings,
|
|
114
|
+
signal,
|
|
115
|
+
"local initialization",
|
|
116
|
+
localStartupComplete ? "completed" : "stopped",
|
|
117
|
+
client.debugEnabled && !signal.aborted ? (report) => client.recordDebug({ event: "startup-timings", report }) : void 0
|
|
118
|
+
);
|
|
84
119
|
}
|
|
85
|
-
throwIfAborted(signal);
|
|
86
120
|
const result = await client.run("initialize", {}, signal);
|
|
121
|
+
client.validate();
|
|
87
122
|
throwIfAborted(signal);
|
|
88
123
|
configureSyncStatus(ctx, result.settings?.showStatus ?? true);
|
|
89
124
|
setSyncSetupCompletions(Object.keys(result.settings?.syncSetups ?? {}).sort((a, b) => a.localeCompare(b)));
|
|
@@ -102,11 +137,17 @@ async function autoPushSessions(ctx, signal, _loaders) {
|
|
|
102
137
|
try {
|
|
103
138
|
const client = piDaemonClient(ctx);
|
|
104
139
|
const eligible = (config2) => config2.automatic && syncSessionsSelected(config2);
|
|
105
|
-
if (!await client.configured((settings) => eligible(configFromSettings(settings))))
|
|
140
|
+
if (!await client.configured((settings) => eligible(configFromSettings(settings)))) {
|
|
141
|
+
client.recordDebug({ event: "job", operation: "shutdown", outcome: "skipped" });
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
106
144
|
throwIfAborted(signal);
|
|
107
145
|
const config = await loadConfigForCheck(void 0, signal);
|
|
108
146
|
throwIfAborted(signal);
|
|
109
|
-
if (!eligible(config))
|
|
147
|
+
if (!eligible(config)) {
|
|
148
|
+
client.recordDebug({ event: "job", operation: "shutdown", outcome: "skipped" });
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
110
151
|
const automaticFingerprint = syncCheckConfigFingerprint(config);
|
|
111
152
|
await client.run(
|
|
112
153
|
"shutdown",
|
|
@@ -134,12 +175,12 @@ function createStartupCheck(loaders, attention, timeoutMs = 3e4, publish) {
|
|
|
134
175
|
const queued = pending;
|
|
135
176
|
if (!queued || queued.ctx.sessionManager !== ctx.sessionManager || queued.signal.aborted || !ctx.isIdle()) return;
|
|
136
177
|
pending = void 0;
|
|
137
|
-
controllerApi.start(ctx, queued.signal, queued.config);
|
|
178
|
+
controllerApi.start(ctx, queued.signal, queued.config, queued.logTimings);
|
|
138
179
|
},
|
|
139
|
-
start(ctx, sessionSignal, initialConfig) {
|
|
180
|
+
start(ctx, sessionSignal, initialConfig, logTimings) {
|
|
140
181
|
if (!ctx.hasUI || sessionSignal.aborted) return;
|
|
141
182
|
if (initialConfig && startupTransferEnabled(initialConfig) && !ctx.isIdle()) {
|
|
142
|
-
pending = { ctx, signal: sessionSignal, config: initialConfig };
|
|
183
|
+
pending = { ctx, signal: sessionSignal, config: initialConfig, logTimings };
|
|
143
184
|
return;
|
|
144
185
|
}
|
|
145
186
|
if (active) throw new Error("Previous startup check has not been drained.");
|
|
@@ -203,7 +244,7 @@ function createStartupCheck(loaders, attention, timeoutMs = 3e4, publish) {
|
|
|
203
244
|
throwIfAborted(signal);
|
|
204
245
|
if (!isCurrent() || syncCheckConfigFingerprint(transferConfig) !== identity) return;
|
|
205
246
|
if (!ctx.isIdle()) {
|
|
206
|
-
pending = { ctx, signal: sessionSignal, config: captured };
|
|
247
|
+
pending = { ctx, signal: sessionSignal, config: captured, logTimings };
|
|
207
248
|
return;
|
|
208
249
|
}
|
|
209
250
|
await timings.measure(
|
|
@@ -268,7 +309,8 @@ function createStartupCheck(loaders, attention, timeoutMs = 3e4, publish) {
|
|
|
268
309
|
config?.debug ?? false,
|
|
269
310
|
sessionSignal,
|
|
270
311
|
"background startup",
|
|
271
|
-
signal.aborted || stopped ? "stopped" : "completed"
|
|
312
|
+
signal.aborted || stopped ? "stopped" : "completed",
|
|
313
|
+
logTimings
|
|
272
314
|
);
|
|
273
315
|
}
|
|
274
316
|
if (active === task) active = void 0;
|
|
@@ -292,12 +334,12 @@ function createStartupCheck(loaders, attention, timeoutMs = 3e4, publish) {
|
|
|
292
334
|
// src/sync/sync-loaders.ts
|
|
293
335
|
function createSyncLoaders(dependencies) {
|
|
294
336
|
const loaders = {
|
|
295
|
-
commands: cachedModuleLoader(dependencies.loadCommandHandler ?? (() => import("./chunks/command-handler-
|
|
296
|
-
inspection: cachedModuleLoader(dependencies.loadSyncInspection ?? (() => import("./chunks/sync-inspection-
|
|
297
|
-
setupSwitch: cachedModuleLoader(dependencies.loadSetupSwitch ?? (() => import("./chunks/setup-switch-
|
|
337
|
+
commands: cachedModuleLoader(dependencies.loadCommandHandler ?? (() => import("./chunks/command-handler-N45GY7AV.ts"))),
|
|
338
|
+
inspection: cachedModuleLoader(dependencies.loadSyncInspection ?? (() => import("./chunks/sync-inspection-OS2LVOLV.ts"))),
|
|
339
|
+
setupSwitch: cachedModuleLoader(dependencies.loadSetupSwitch ?? (() => import("./chunks/setup-switch-HY7K3442.ts"))),
|
|
298
340
|
snapshot: cachedModuleLoader(dependencies.loadSnapshot ?? (() => import("./chunks/snapshot-ZUJJZCFW.ts"))),
|
|
299
341
|
syncState: cachedModuleLoader(dependencies.loadSyncState ?? (() => import("./chunks/sync-state-QIT64TKV.ts"))),
|
|
300
|
-
operations: cachedModuleLoader(dependencies.loadSyncOperations ?? (() => import("./chunks/sync-operations-
|
|
342
|
+
operations: cachedModuleLoader(dependencies.loadSyncOperations ?? (() => import("./chunks/sync-operations-D3MDJUQQ.ts")))
|
|
301
343
|
};
|
|
302
344
|
return loaders;
|
|
303
345
|
}
|
|
@@ -372,9 +414,29 @@ function sync(pi, dependencies = {}) {
|
|
|
372
414
|
await withPiDaemonClient(
|
|
373
415
|
ctx,
|
|
374
416
|
async (ctx2) => {
|
|
375
|
-
const command = splitArgs(args)
|
|
376
|
-
const
|
|
417
|
+
const [command, action, ...extra] = splitArgs(args);
|
|
418
|
+
const recover = command === "daemon" && action === "recover";
|
|
419
|
+
const ready = recover ? void 0 : await initialization;
|
|
377
420
|
if (signal.aborted || owner !== client) return;
|
|
421
|
+
const needsDaemonRecovery = () => client.ownershipCleanupRequired;
|
|
422
|
+
if (recover || !command && needsDaemonRecovery()) {
|
|
423
|
+
if (recover && extra.length) {
|
|
424
|
+
ctx2.ui.notify("Usage: /sync daemon recover", "error");
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
const commands = await loaders.commands();
|
|
428
|
+
if (signal.aborted || owner !== client) return;
|
|
429
|
+
await commands.handleCommand(
|
|
430
|
+
args,
|
|
431
|
+
ctx2,
|
|
432
|
+
commandSignal,
|
|
433
|
+
loaders,
|
|
434
|
+
attention,
|
|
435
|
+
void 0,
|
|
436
|
+
needsDaemonRecovery
|
|
437
|
+
);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
378
440
|
const requiresContact = !["help", "unlock", "migrate-state"].includes(command ?? "");
|
|
379
441
|
let busyPublished = false;
|
|
380
442
|
try {
|
|
@@ -397,8 +459,17 @@ function sync(pi, dependencies = {}) {
|
|
|
397
459
|
}
|
|
398
460
|
const commands = await loaders.commands();
|
|
399
461
|
if (signal.aborted || owner !== client) return;
|
|
400
|
-
await commands.handleCommand(
|
|
462
|
+
await commands.handleCommand(
|
|
463
|
+
args,
|
|
464
|
+
ctx2,
|
|
465
|
+
commandSignal,
|
|
466
|
+
loaders,
|
|
467
|
+
attention,
|
|
468
|
+
void 0,
|
|
469
|
+
needsDaemonRecovery
|
|
470
|
+
);
|
|
401
471
|
} catch (error) {
|
|
472
|
+
client.recordOwnershipFailure(error);
|
|
402
473
|
if (!commandSignal.aborted && owner === client) {
|
|
403
474
|
ctx2.ui.notify(`pi-sync command unavailable: ${safeTerminalText(errorMessage(error))}`, "error");
|
|
404
475
|
if (command === "unlock" || command === "migrate-state") throw error;
|
|
@@ -406,7 +477,7 @@ function sync(pi, dependencies = {}) {
|
|
|
406
477
|
} finally {
|
|
407
478
|
if (!signal.aborted && owner === client) {
|
|
408
479
|
const publish = busyPublished || command === "unlock" || command === "migrate-state";
|
|
409
|
-
await client.setBusy("command", false, publish).catch(() => {
|
|
480
|
+
await client.setBusy("command", false, publish && !needsDaemonRecovery()).catch(() => {
|
|
410
481
|
});
|
|
411
482
|
}
|
|
412
483
|
}
|
|
@@ -456,9 +527,12 @@ function sync(pi, dependencies = {}) {
|
|
|
456
527
|
} catch (error) {
|
|
457
528
|
if (!signal.aborted && owner === client) {
|
|
458
529
|
try {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
530
|
+
ctx.isIdle();
|
|
531
|
+
client.recordOwnershipFailure(error);
|
|
532
|
+
if (ctx.hasUI) {
|
|
533
|
+
const advice = client.ownershipCleanupRequired ? " Open /sync to recover the daemon." : "";
|
|
534
|
+
ctx.ui.notify(`pi-sync recovery required: ${safeTerminalText(errorMessage(error))}${advice}`, "error");
|
|
535
|
+
}
|
|
462
536
|
} catch {
|
|
463
537
|
}
|
|
464
538
|
}
|
|
@@ -473,7 +547,12 @@ function sync(pi, dependencies = {}) {
|
|
|
473
547
|
}
|
|
474
548
|
if (ready && !signal.aborted && owner === client && !(ready.continuous && ready.agentMode) && (ready.automatic || startupTransferEnabled(ready)))
|
|
475
549
|
await withPiDaemonClient(ctx, async () => {
|
|
476
|
-
check.start(
|
|
550
|
+
check.start(
|
|
551
|
+
ctx,
|
|
552
|
+
signal,
|
|
553
|
+
ready,
|
|
554
|
+
client.debugEnabled ? (report) => client.recordDebug({ event: "startup-timings", report }) : void 0
|
|
555
|
+
);
|
|
477
556
|
});
|
|
478
557
|
} catch (error) {
|
|
479
558
|
client.disableQueueReleaseUI();
|
|
@@ -537,6 +616,7 @@ function sync(pi, dependencies = {}) {
|
|
|
537
616
|
if (signal.aborted || owner !== client) return;
|
|
538
617
|
if (reason !== "reload") {
|
|
539
618
|
shutdownClient = bindPiDaemonClient(ctx, signal, publishTimings);
|
|
619
|
+
shutdownClient.setDebugPreference(client.debugEnabled);
|
|
540
620
|
await shutdownClient.setBusy("shutdown", true);
|
|
541
621
|
const attached = await shutdownClient.attachExisting();
|
|
542
622
|
if (!signal.aborted && owner === client && attached)
|