@narumitw/pi-sync 0.67.2 → 0.68.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 +17 -0
- package/README.md +29 -49
- package/dist/chunks/{chunk-XUZV4OGI.ts → chunk-335XTMMZ.ts} +3 -2
- package/dist/chunks/{chunk-XUZV4OGI.ts.map → chunk-335XTMMZ.ts.map} +2 -2
- package/dist/chunks/{chunk-PUSMSKIM.ts → chunk-AYGMIMCV.ts} +2 -11
- package/dist/chunks/chunk-AYGMIMCV.ts.map +7 -0
- package/dist/chunks/{chunk-2MSJDLSM.ts → chunk-BCDBT4X3.ts} +7 -7
- package/dist/chunks/{chunk-GRXNUC6O.ts → chunk-FQKWGVMA.ts} +20 -54
- package/dist/chunks/chunk-FQKWGVMA.ts.map +7 -0
- package/dist/chunks/{chunk-DGVZYS7T.ts → chunk-FR6A7ASZ.ts} +8 -11
- package/dist/chunks/chunk-FR6A7ASZ.ts.map +7 -0
- package/dist/chunks/{chunk-3NS4PMCI.ts → chunk-J52GYZO6.ts} +2 -8
- package/dist/chunks/{chunk-3NS4PMCI.ts.map → chunk-J52GYZO6.ts.map} +2 -2
- package/dist/chunks/{chunk-2MUAR5GH.ts → chunk-KAIVTJIQ.ts} +7 -10
- package/dist/chunks/chunk-KAIVTJIQ.ts.map +7 -0
- package/dist/chunks/{chunk-WBIOSK76.ts → chunk-R7PN3KIY.ts} +1 -2
- package/dist/chunks/{chunk-3Q3DMMID.ts → chunk-TLYT6HVI.ts} +8 -8
- package/dist/chunks/{chunk-UF2HU2NM.ts → chunk-WCGLU526.ts} +39 -118
- package/dist/chunks/chunk-WCGLU526.ts.map +7 -0
- package/dist/chunks/{chunk-JREGWM2B.ts → chunk-XNUARYLR.ts} +1 -2
- package/dist/chunks/{chunk-C3E75DXW.ts → chunk-YV2R5SJU.ts} +73 -85
- package/dist/chunks/chunk-YV2R5SJU.ts.map +7 -0
- package/dist/chunks/{command-handler-HWRPH3K3.ts → command-handler-S6BRZMPW.ts} +117 -69
- package/dist/chunks/command-handler-S6BRZMPW.ts.map +7 -0
- package/dist/chunks/{conflict-review-OBBBSVQD.ts → conflict-review-3XMYDJIK.ts} +2 -2
- package/dist/chunks/{file-selection-GASCVN45.ts → file-selection-4BOQBXS7.ts} +10 -17
- package/dist/chunks/file-selection-4BOQBXS7.ts.map +7 -0
- package/dist/chunks/{manager-result-dispatcher-MJ6G2CEI.ts → manager-result-dispatcher-A4IWLS4J.ts} +7 -7
- package/dist/chunks/{manager-ui-Z3B5ZTA6.ts → manager-ui-KHMCSLLV.ts} +114 -581
- package/dist/chunks/manager-ui-KHMCSLLV.ts.map +7 -0
- package/dist/chunks/{chunk-ECUCXF5Y.ts → merge-review-LWMUE5IW.ts} +2 -3
- package/dist/chunks/{remote-selection-ui-34WC7OFE.ts → remote-selection-ui-F6NJBQ3Y.ts} +6 -6
- package/dist/chunks/{setup-switch-JZDFQPVW.ts → setup-switch-7LMIRMZ7.ts} +6 -6
- package/dist/chunks/{setup-wizard-YOXLXLBY.ts → setup-wizard-2NRPR433.ts} +11 -16
- package/dist/chunks/{setup-wizard-YOXLXLBY.ts.map → setup-wizard-2NRPR433.ts.map} +1 -1
- package/dist/chunks/{sync-inspection-NIITROKS.ts → sync-inspection-QGM54YCM.ts} +5 -5
- package/dist/chunks/{sync-operations-FFI4ZZQL.ts → sync-operations-DTQMKVRQ.ts} +2 -2
- package/dist/daemon/dist/build-id.json +1 -0
- package/dist/daemon/dist/build-version.js +24 -4
- package/dist/daemon/dist/cli.js +51 -67
- package/dist/daemon/dist/client-transport.js +15 -5
- package/dist/daemon/dist/client.js +2 -10
- package/dist/daemon/dist/consent.js +13 -126
- package/dist/daemon/dist/daemon-startup.js +135 -30
- package/dist/daemon/dist/daemon-status.js +56 -0
- package/dist/daemon/dist/engine/backends/git/git-backend.js +4 -17
- package/dist/daemon/dist/engine/backends/git/git-storage.js +11 -44
- package/dist/daemon/dist/engine/backends/s3/s3-backend.js +6 -6
- package/dist/daemon/dist/engine/backends/webdav/webdav-backend.js +6 -6
- package/dist/daemon/dist/engine/settings/config.js +16 -149
- package/dist/daemon/dist/engine/settings/retired-ignore-policy.js +16 -0
- package/dist/daemon/dist/engine/settings/retired-ignore-recovery.js +14 -0
- package/dist/daemon/dist/engine/settings/settings-management.js +2 -10
- package/dist/daemon/dist/engine/settings/settings-validation.js +8 -21
- package/dist/daemon/dist/engine/snapshot/session-paths.js +13 -41
- package/dist/daemon/dist/engine/snapshot/snapshot-apply.js +8 -24
- package/dist/daemon/dist/engine/snapshot/snapshot-codec.js +7 -11
- package/dist/daemon/dist/engine/snapshot/snapshot-exclude-safety.js +19 -76
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-images.js +1 -7
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-policy.js +8 -102
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction.js +20 -100
- package/dist/daemon/dist/engine/snapshot/snapshot-types.js +1 -11
- package/dist/daemon/dist/engine/snapshot/snapshot.js +26 -78
- package/dist/daemon/dist/engine/state/sync-state-store.js +5 -1
- package/dist/daemon/dist/engine/sync/agent-plan.js +0 -1
- package/dist/daemon/dist/engine/sync/agent-policy.js +1 -1
- package/dist/daemon/dist/engine/sync/conflict-review.js +0 -2
- package/dist/daemon/dist/engine/sync/continuous-sync.js +2 -17
- package/dist/daemon/dist/engine/sync/continuous-watch.js +3 -7
- package/dist/daemon/dist/engine/sync/directional-action.js +3 -21
- package/dist/daemon/dist/engine/sync/initialization.js +4 -15
- package/dist/daemon/dist/engine/sync/local-fields.js +4 -65
- package/dist/daemon/dist/engine/sync/merge-apply.js +8 -31
- package/dist/daemon/dist/engine/sync/merge-journal.js +8 -118
- package/dist/daemon/dist/engine/sync/merged-sync.js +13 -70
- package/dist/daemon/dist/engine/sync/push-review.js +1 -16
- package/dist/daemon/dist/engine/sync/remote-snapshot.js +48 -65
- package/dist/daemon/dist/engine/sync/startup-bootstrap.js +3 -3
- package/dist/daemon/dist/engine/sync/sync-error-guidance.js +1 -1
- package/dist/daemon/dist/engine/sync/sync-inspection.js +1 -2
- package/dist/daemon/dist/engine/sync/sync-mutations.js +26 -118
- package/dist/daemon/dist/engine/sync/sync-policy.js +26 -150
- package/dist/daemon/dist/engine/sync/sync-queries.js +1 -8
- package/dist/daemon/dist/engine/sync/sync-rollback.js +12 -50
- package/dist/daemon/dist/engine/sync/sync-state.js +2 -15
- package/dist/daemon/dist/engine/sync/transfer-freshness.js +7 -17
- package/dist/daemon/dist/engine/sync/transfer-size-limits.js +3 -7
- package/dist/daemon/dist/engine-service.js +62 -205
- package/dist/daemon/dist/foreground-queue-outcome.js +0 -4
- package/dist/daemon/dist/index.js +2 -0
- package/dist/daemon/dist/legacy-consent-guard.js +34 -0
- package/dist/daemon/dist/server.js +99 -11
- package/dist/daemon/dist/service-host.js +3 -9
- package/dist/daemon/package.json +1 -1
- package/dist/index.ts +49 -49
- package/dist/index.ts.map +3 -3
- package/docs/agent-continuous-hardening.md +2 -0
- package/docs/continuous-sync-verification.md +1 -1
- package/docs/daemon-migration.md +17 -15
- package/docs/tui-contract.md +4 -6
- package/package.json +2 -3
- package/skills/configure-pi-sync/SKILL.md +23 -78
- package/skills/configure-pi-sync/references/configuration.md +59 -76
- package/src/commands/command-execution.ts +15 -38
- package/src/commands/command-handler.ts +0 -4
- package/src/commands/command.ts +2 -1
- package/src/daemon/daemon-status-ui.ts +64 -0
- package/src/daemon/directional-recovery.ts +4 -33
- package/src/daemon/pi-client.ts +87 -94
- package/src/settings/config.ts +0 -1
- package/src/sync/setup-switch.ts +1 -4
- package/src/sync-extension.ts +14 -27
- package/src/ui/cancellable-operation.ts +2 -13
- package/src/ui/excluded-paths-ui.ts +1 -4
- package/src/ui/file-selection.ts +0 -5
- package/src/ui/manager-state.ts +12 -75
- package/src/ui/manager-ui.ts +7 -96
- package/src/ui/remote-selection-ui.ts +29 -130
- package/src/ui/settings-ui.ts +169 -388
- package/src/ui/setup/setup-actions.ts +4 -16
- package/src/ui/setup/setup-prompts.ts +12 -49
- package/src/ui/setup/setup-switcher.ts +8 -14
- package/src/ui/storage-connections-ui.ts +21 -32
- package/src/ui/sync-setups-ui.ts +27 -53
- package/dist/chunks/chunk-2MUAR5GH.ts.map +0 -7
- package/dist/chunks/chunk-C3E75DXW.ts.map +0 -7
- package/dist/chunks/chunk-DGVZYS7T.ts.map +0 -7
- package/dist/chunks/chunk-EJDDRS6O.ts +0 -17
- package/dist/chunks/chunk-EJDDRS6O.ts.map +0 -7
- package/dist/chunks/chunk-GRXNUC6O.ts.map +0 -7
- package/dist/chunks/chunk-I72HGZJJ.ts +0 -106
- package/dist/chunks/chunk-I72HGZJJ.ts.map +0 -7
- package/dist/chunks/chunk-KNEUL4XN.ts +0 -30
- package/dist/chunks/chunk-KNEUL4XN.ts.map +0 -7
- package/dist/chunks/chunk-PUSMSKIM.ts.map +0 -7
- package/dist/chunks/chunk-UF2HU2NM.ts.map +0 -7
- package/dist/chunks/chunk-WFBHWYI6.ts +0 -18
- package/dist/chunks/chunk-WFBHWYI6.ts.map +0 -7
- package/dist/chunks/command-handler-HWRPH3K3.ts.map +0 -7
- package/dist/chunks/config-P54GGMXY.ts +0 -39
- package/dist/chunks/continuous-record-3SKJ6I3V.ts +0 -23
- package/dist/chunks/continuous-record-3SKJ6I3V.ts.map +0 -7
- package/dist/chunks/continuous-storage-3EU6I7Z3.ts +0 -27
- package/dist/chunks/continuous-storage-3EU6I7Z3.ts.map +0 -7
- package/dist/chunks/file-selection-GASCVN45.ts.map +0 -7
- package/dist/chunks/ignore-file-ui-5BWA6LBC.ts +0 -21
- package/dist/chunks/manager-ui-Z3B5ZTA6.ts.map +0 -7
- package/dist/chunks/merge-review-C2KETZKY.ts +0 -11
- package/dist/chunks/merge-review-C2KETZKY.ts.map +0 -7
- package/dist/chunks/remote-selection-ui-34WC7OFE.ts.map +0 -7
- package/dist/chunks/setup-switch-JZDFQPVW.ts.map +0 -7
- package/dist/daemon/dist/engine/ignore/adoption-journal.js +0 -146
- package/dist/daemon/dist/engine/ignore/effective-ignore-policy.js +0 -33
- package/dist/daemon/dist/engine/ignore/ignore-edit.js +0 -102
- package/dist/daemon/dist/engine/ignore/ignore-initialization.js +0 -288
- package/dist/daemon/dist/engine/ignore/ignore-migration-prompt.js +0 -139
- package/dist/daemon/dist/engine/ignore/ignore-settings.js +0 -391
- package/dist/daemon/dist/engine/ignore/ignore-source.js +0 -250
- package/dist/daemon/dist/engine/ignore/snapshot-ignore-rules.js +0 -39
- package/dist/daemon/dist/engine/sync/ignore-adoption-recovery.js +0 -50
- package/dist/daemon/dist/engine/sync/ignore-adoption.js +0 -416
- package/dist/daemon/dist/engine/sync/ignore-publication.js +0 -23
- package/dist/daemon/dist/engine/ui/ignore-rule-preview.js +0 -18
- package/dist/daemon/dist/monitor.js +0 -344
- package/src/ui/agent-mode-setting.ts +0 -99
- package/src/ui/ignore-file-guidance.ts +0 -7
- package/src/ui/ignore-file-ui.ts +0 -105
- package/src/ui/ignore-migration-prompt.ts +0 -65
- package/src/ui/settings-review.ts +0 -26
- /package/dist/chunks/{chunk-2MSJDLSM.ts.map → chunk-BCDBT4X3.ts.map} +0 -0
- /package/dist/chunks/{chunk-WBIOSK76.ts.map → chunk-R7PN3KIY.ts.map} +0 -0
- /package/dist/chunks/{chunk-3Q3DMMID.ts.map → chunk-TLYT6HVI.ts.map} +0 -0
- /package/dist/chunks/{chunk-JREGWM2B.ts.map → chunk-XNUARYLR.ts.map} +0 -0
- /package/dist/chunks/{conflict-review-OBBBSVQD.ts.map → conflict-review-3XMYDJIK.ts.map} +0 -0
- /package/dist/chunks/{config-P54GGMXY.ts.map → manager-result-dispatcher-A4IWLS4J.ts.map} +0 -0
- /package/dist/chunks/{chunk-ECUCXF5Y.ts.map → merge-review-LWMUE5IW.ts.map} +0 -0
- /package/dist/chunks/{ignore-file-ui-5BWA6LBC.ts.map → remote-selection-ui-F6NJBQ3Y.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-MJ6G2CEI.ts.map → setup-switch-7LMIRMZ7.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-NIITROKS.ts.map → sync-inspection-QGM54YCM.ts.map} +0 -0
- /package/dist/chunks/{sync-operations-FFI4ZZQL.ts.map → sync-operations-DTQMKVRQ.ts.map} +0 -0
|
@@ -2,7 +2,27 @@ import { readFileSync } from "node:fs";
|
|
|
2
2
|
import { valid } from "semver";
|
|
3
3
|
// Capture the installed build at module load. A later package update must not
|
|
4
4
|
// change the version advertised by an already running process.
|
|
5
|
-
const { version } =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
export const { version: DAEMON_BUILD_VERSION, id: DAEMON_BUILD_ID } = readInstalledDaemonBuild();
|
|
6
|
+
export function readInstalledDaemonBuild() {
|
|
7
|
+
const { version } = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
8
|
+
if (typeof version !== "string" || valid(version) !== version)
|
|
9
|
+
throw new Error("Invalid Pi Sync daemon build version.");
|
|
10
|
+
return { version, id: readBuildId() };
|
|
11
|
+
}
|
|
12
|
+
export function isDaemonBuildId(value) {
|
|
13
|
+
return typeof value === "string" && /^[a-f0-9]{64}$/u.test(value);
|
|
14
|
+
}
|
|
15
|
+
function readBuildId() {
|
|
16
|
+
let value;
|
|
17
|
+
try {
|
|
18
|
+
value = JSON.parse(readFileSync(new URL("./build-id.json", import.meta.url), "utf8"));
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (error.code === "ENOENT")
|
|
22
|
+
return undefined;
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
if (!isDaemonBuildId(value))
|
|
26
|
+
throw new Error("Invalid Pi Sync daemon build identifier.");
|
|
27
|
+
return value;
|
|
28
|
+
}
|
package/dist/daemon/dist/cli.js
CHANGED
|
@@ -1,22 +1,44 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import "./child-sdk.mjs";
|
|
3
|
-
import path from "node:path";
|
|
4
3
|
import { setTimeout as delay } from "node:timers/promises";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { DAEMON_BUILD_ID, DAEMON_BUILD_VERSION } from "./build-version.js";
|
|
5
|
+
import { requestDaemon } from "./client-transport.js";
|
|
6
|
+
import { DaemonUpgradeBlockedError, ensureDaemon, restartDaemon } from "./daemon-startup.js";
|
|
7
|
+
import { inspectDaemonStatus } from "./daemon-status.js";
|
|
8
|
+
import { privateDirectory, readIdentity, runtimePaths } from "./identity.js";
|
|
8
9
|
import { openLifecycleLog } from "./lifecycle-log.js";
|
|
9
|
-
|
|
10
|
+
async function retiredPolicyBlocker(root) {
|
|
11
|
+
const { RetiredIgnorePolicyError } = await import("./engine/settings/retired-ignore-policy.js");
|
|
12
|
+
try {
|
|
13
|
+
const { assertNoRetiredRuleJournal } = await import("./engine/settings/retired-ignore-recovery.js");
|
|
14
|
+
assertNoRetiredRuleJournal(root);
|
|
15
|
+
const { readLocalConfigForDiagnostics } = await import("./engine/settings/config-file.js");
|
|
16
|
+
const { validateSettingsDocument } = await import("./engine/settings/settings-validation.js");
|
|
17
|
+
const source = await readLocalConfigForDiagnostics(root);
|
|
18
|
+
if (source?.stillCurrent())
|
|
19
|
+
validateSettingsDocument(source.document.parsed);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (error instanceof RetiredIgnorePolicyError)
|
|
23
|
+
return error.message;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
function reportLaunch(message) {
|
|
28
|
+
if (process.connected)
|
|
29
|
+
process.send?.(message, () => { });
|
|
30
|
+
}
|
|
10
31
|
export async function main(args) {
|
|
11
32
|
const [command = "help", flag, root, ...extra] = args;
|
|
12
33
|
if (["help", "--help", "-h"].includes(command)) {
|
|
13
|
-
console.log("pi-sync-daemon <start|status|stop|restart|repair-upgrade|serve> --root <canonical-agent-directory>\nLocal synchronization owner; no OS service registration. status/stop/repair-upgrade never start a service.\nrepair-upgrade revokes all retained unattended grants after verified exit and archives the pending upgrade records.");
|
|
34
|
+
console.log("pi-sync-daemon <start|status|stop|restart|repair-upgrade|serve> --root <canonical-agent-directory>\nLocal synchronization owner; no OS service registration. status/stop/repair-upgrade never start a service.\nrepair-upgrade revokes all retained unattended grants after verified exit and archives the pending upgrade records.\nIf a retired ignore-file policy blocks sync, use /skill:configure-pi-sync in Pi or see the Pi Sync manual recovery guide.");
|
|
14
35
|
return;
|
|
15
36
|
}
|
|
37
|
+
const expectedBuild = command === "serve" && extra[0] === "--expect-build" && extra.length === 3;
|
|
16
38
|
if (!["start", "status", "stop", "restart", "repair-upgrade", "serve"].includes(command) ||
|
|
17
39
|
flag !== "--root" ||
|
|
18
40
|
!root ||
|
|
19
|
-
extra.length)
|
|
41
|
+
(extra.length && !expectedBuild))
|
|
20
42
|
throw new Error("Use pi-sync-daemon --help for the supported commands.");
|
|
21
43
|
if (command === "repair-upgrade") {
|
|
22
44
|
const { repairUpgrade } = await import("./upgrade-repair.js");
|
|
@@ -24,7 +46,9 @@ export async function main(args) {
|
|
|
24
46
|
return;
|
|
25
47
|
}
|
|
26
48
|
if (command === "serve") {
|
|
27
|
-
|
|
49
|
+
if (expectedBuild && (extra[1] !== DAEMON_BUILD_VERSION || extra[2] !== (DAEMON_BUILD_ID ?? "")))
|
|
50
|
+
throw new Error("Installed daemon build does not match the launch request.");
|
|
51
|
+
reportLaunch({ type: "booting" });
|
|
28
52
|
const { createEngineService } = await import("./engine-service.js");
|
|
29
53
|
const { startServer } = await import("./server.js");
|
|
30
54
|
const paths = await runtimePaths(root);
|
|
@@ -40,7 +64,7 @@ export async function main(args) {
|
|
|
40
64
|
log?.close(); /* Never follow a replaced diagnostic path. */
|
|
41
65
|
}
|
|
42
66
|
};
|
|
43
|
-
const service = createEngineService(paths.root
|
|
67
|
+
const service = createEngineService(paths.root);
|
|
44
68
|
let server;
|
|
45
69
|
try {
|
|
46
70
|
server = await startServer(paths.root, service.execute, {
|
|
@@ -83,59 +107,24 @@ export async function main(args) {
|
|
|
83
107
|
process.on("SIGTERM", stop);
|
|
84
108
|
process.on("SIGINT", stop);
|
|
85
109
|
// Parent disconnect means readiness IPC ended, not service shutdown.
|
|
86
|
-
|
|
110
|
+
reportLaunch({ type: "ready", identity: server.identity });
|
|
87
111
|
process.channel?.unref();
|
|
88
112
|
return;
|
|
89
113
|
}
|
|
90
|
-
if (command === "start") {
|
|
91
|
-
const { identity } = await ensureDaemon(root);
|
|
114
|
+
if (command === "start" || command === "restart") {
|
|
115
|
+
const { identity } = await (command === "start" ? ensureDaemon(root) : restartDaemon(root));
|
|
92
116
|
console.log(JSON.stringify({ running: true, root: identity.root, instance: identity.instance, pid: identity.pid }));
|
|
93
117
|
return;
|
|
94
118
|
}
|
|
95
|
-
const paths = await runtimePaths(root);
|
|
96
|
-
const identity = await readIdentity(paths);
|
|
97
119
|
if (command === "status") {
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
...(identity && { recordedPid: identity.pid }),
|
|
102
|
-
...(pending && { pendingUpgradePid: pending.pid }),
|
|
103
|
-
};
|
|
104
|
-
if (!identity ||
|
|
105
|
-
(pending?.instance === identity.instance && pending.pid === identity.pid && (await processExited(pending)))) {
|
|
106
|
-
console.log(JSON.stringify({ running: false, ...summary }));
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
try {
|
|
110
|
-
const status = await requestDaemon(paths, identity, "hello", {});
|
|
111
|
-
if (!record(status) ||
|
|
112
|
-
status.version !== 1 ||
|
|
113
|
-
status.root !== paths.root ||
|
|
114
|
-
status.instance !== identity.instance ||
|
|
115
|
-
status.pid !== identity.pid)
|
|
116
|
-
throw new Error("Daemon identity mismatch; no replacement was attempted.");
|
|
117
|
-
const build = typeof status.buildVersion === "string" ? valid(status.buildVersion) : null;
|
|
118
|
-
console.log(JSON.stringify({
|
|
119
|
-
running: true,
|
|
120
|
-
...summary,
|
|
121
|
-
version: status.version,
|
|
122
|
-
instance: identity.instance,
|
|
123
|
-
pid: identity.pid,
|
|
124
|
-
...(build && { buildVersion: build }),
|
|
125
|
-
lifecycleLog: path.join(paths.directory, "lifecycle.log"),
|
|
126
|
-
}));
|
|
127
|
-
}
|
|
128
|
-
catch {
|
|
129
|
-
// A failed hello does not prove the recorded owner exited.
|
|
130
|
-
console.log(JSON.stringify({ running: null, ...summary }));
|
|
131
|
-
}
|
|
120
|
+
const status = await inspectDaemonStatus(root);
|
|
121
|
+
const retiredPolicy = await retiredPolicyBlocker(status.root);
|
|
122
|
+
console.log(JSON.stringify({ ...status, ...(retiredPolicy ? { retiredPolicy } : {}) }));
|
|
132
123
|
return;
|
|
133
124
|
}
|
|
125
|
+
const paths = await runtimePaths(root);
|
|
126
|
+
const identity = await readIdentity(paths);
|
|
134
127
|
if (!identity) {
|
|
135
|
-
if (command === "restart") {
|
|
136
|
-
await main(["start", "--root", root]);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
128
|
console.log(JSON.stringify({ running: false, root: paths.root }));
|
|
140
129
|
return;
|
|
141
130
|
}
|
|
@@ -146,26 +135,21 @@ export async function main(args) {
|
|
|
146
135
|
throw new Error("Daemon did not drain; state retained. Do not force a second owner.");
|
|
147
136
|
await delay(25);
|
|
148
137
|
}
|
|
149
|
-
|
|
150
|
-
while (processExists(identity.pid)) {
|
|
151
|
-
if (Date.now() >= deadline)
|
|
152
|
-
throw new Error("Previous daemon is still exiting; restart was not attempted.");
|
|
153
|
-
await delay(25);
|
|
154
|
-
}
|
|
155
|
-
await main(["start", "--root", root]);
|
|
156
|
-
}
|
|
157
|
-
else
|
|
158
|
-
console.log(JSON.stringify({ stopped: true, root: paths.root }));
|
|
138
|
+
console.log(JSON.stringify({ stopped: true, root: paths.root }));
|
|
159
139
|
}
|
|
160
140
|
if (import.meta.main) {
|
|
161
|
-
void main(process.argv.slice(2)).catch(() => {
|
|
162
|
-
|
|
141
|
+
void main(process.argv.slice(2)).catch((error) => {
|
|
142
|
+
reportLaunch({
|
|
163
143
|
type: "error",
|
|
164
144
|
message: "Daemon initialization failed; private state retained. Check endpoint ownership and compatible versions.",
|
|
165
145
|
});
|
|
166
|
-
console.error(
|
|
167
|
-
?
|
|
168
|
-
:
|
|
146
|
+
console.error(error instanceof DaemonUpgradeBlockedError
|
|
147
|
+
? error.message
|
|
148
|
+
: process.argv[2] === "repair-upgrade"
|
|
149
|
+
? "Pi Sync upgrade repair failed. Check the pending PID, wait for confirmed exit, and check consent storage. Do not delete recovery files."
|
|
150
|
+
: process.argv[2] === "restart"
|
|
151
|
+
? "Pi Sync restart failed; private state retained. Check status, version compatibility, and retained unattended permission. Do not force a restart."
|
|
152
|
+
: "pi-sync-daemon failed; private state retained. Check root, endpoint ownership, and version compatibility.");
|
|
169
153
|
process.exitCode = 1;
|
|
170
154
|
});
|
|
171
155
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { request as httpRequest } from "node:http";
|
|
2
2
|
import { lt, valid } from "semver";
|
|
3
|
-
import { DAEMON_BUILD_VERSION } from "./build-version.js";
|
|
3
|
+
import { DAEMON_BUILD_VERSION, isDaemonBuildId } from "./build-version.js";
|
|
4
4
|
import { daemonPaths, readJsonBody } from "./identity.js";
|
|
5
5
|
import { MAX_MESSAGE_BYTES, record } from "./protocol.js";
|
|
6
6
|
export class DaemonError extends Error {
|
|
@@ -44,7 +44,7 @@ export async function requestDaemon(paths, identity, method, params, signal, opt
|
|
|
44
44
|
})
|
|
45
45
|
.catch(reject);
|
|
46
46
|
});
|
|
47
|
-
request.setTimeout(
|
|
47
|
+
request.setTimeout(["attach", "protect-session", "resume-contact"].includes(method) ? 0 : 30_000, () => request.destroy(new Error("Daemon request timed out.")));
|
|
48
48
|
request.once("error", reject);
|
|
49
49
|
if (options?.onSocket)
|
|
50
50
|
request.once("socket", options.onSocket);
|
|
@@ -59,8 +59,18 @@ export async function hello(paths, identity, signal) {
|
|
|
59
59
|
value.instance !== identity.instance ||
|
|
60
60
|
value.pid !== identity.pid)
|
|
61
61
|
throw new Error("Daemon handshake mismatch.");
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
62
|
+
const buildVersion = value.buildVersion;
|
|
63
|
+
if (buildVersion !== undefined && (typeof buildVersion !== "string" || valid(buildVersion) !== buildVersion))
|
|
64
64
|
throw new Error("Invalid daemon build version.");
|
|
65
|
-
|
|
65
|
+
const buildId = value.buildId;
|
|
66
|
+
if (buildId !== undefined && !isDaemonBuildId(buildId))
|
|
67
|
+
throw new Error("Invalid daemon build identifier.");
|
|
68
|
+
return {
|
|
69
|
+
buildVersion,
|
|
70
|
+
buildId,
|
|
71
|
+
upgradeStop: value.upgradeStop === 1,
|
|
72
|
+
ignoreFilesRetired: value.ignoreFilesRetired === true,
|
|
73
|
+
autonomousSyncRetired: value.autonomousSyncRetired === true,
|
|
74
|
+
needsUpgrade: buildVersion === undefined || lt(buildVersion, DAEMON_BUILD_VERSION),
|
|
75
|
+
};
|
|
66
76
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { setTimeout as delay } from "node:timers/promises";
|
|
3
3
|
import { DaemonError, requestDaemon } from "./client-transport.js";
|
|
4
|
-
import {
|
|
4
|
+
import { stopDaemonAfterForegroundQueueFailure } from "./daemon-recovery.js";
|
|
5
5
|
import { isForegroundDirection, isForegroundQueueOutcome } from "./foreground-queue-outcome.js";
|
|
6
6
|
import { canonicalRootGuard, readProcessBirth } from "./identity.js";
|
|
7
7
|
import { withCleanup } from "./lifecycle.js";
|
|
@@ -275,7 +275,6 @@ export class DaemonConnection {
|
|
|
275
275
|
generation,
|
|
276
276
|
birth,
|
|
277
277
|
assertRoot,
|
|
278
|
-
retryOnRefusal: job.result.foregroundQueueCleanup === "resume-adoption",
|
|
279
278
|
};
|
|
280
279
|
return job.result;
|
|
281
280
|
};
|
|
@@ -396,14 +395,7 @@ export class DaemonConnection {
|
|
|
396
395
|
target.assertRoot();
|
|
397
396
|
target.attempted = true;
|
|
398
397
|
const owned = AbortSignal.any([signal, this.controller.signal, AbortSignal.timeout(FOREGROUND_RECOVERY_MS)]);
|
|
399
|
-
|
|
400
|
-
await stopDaemonAfterForegroundQueueFailure(this.paths, this.identity, { ...target, client: this.facts.id }, owned);
|
|
401
|
-
}
|
|
402
|
-
catch (error) {
|
|
403
|
-
if (target.retryOnRefusal && error instanceof ForegroundStopRefusedError)
|
|
404
|
-
delete target.attempted;
|
|
405
|
-
throw error;
|
|
406
|
-
}
|
|
398
|
+
await stopDaemonAfterForegroundQueueFailure(this.paths, this.identity, { ...target, client: this.facts.id }, owned);
|
|
407
399
|
await this.closeLocal();
|
|
408
400
|
target.assertRoot();
|
|
409
401
|
}
|
|
@@ -3,8 +3,6 @@ import { closeSync, fstatSync, fsyncSync, lstatSync, mkdirSync, openSync, readFi
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { syncCheckConfigFingerprint } from "./engine/settings/config.js";
|
|
5
5
|
import { stateDir } from "./engine/state/state-directory.js";
|
|
6
|
-
import { startupTransferEnabled } from "./engine/sync/agent-policy.js";
|
|
7
|
-
import { syncSessionsSelected } from "./engine/sync/sync-policy.js";
|
|
8
6
|
import { safeTerminalText } from "./engine/ui/terminal-text.js";
|
|
9
7
|
import { record } from "./protocol.js";
|
|
10
8
|
function file(root) {
|
|
@@ -169,108 +167,10 @@ export function consentFingerprint(root, config) {
|
|
|
169
167
|
throw new Error("Review daemon handover first.");
|
|
170
168
|
// Keep the original digest domain across package renames; never persist the internal freshness token.
|
|
171
169
|
return createHmac("sha256", consent.nonce)
|
|
172
|
-
.update(
|
|
170
|
+
.update("sync-daemon-consent/v1")
|
|
173
171
|
.update(syncCheckConfigFingerprint(config))
|
|
174
172
|
.digest("hex");
|
|
175
173
|
}
|
|
176
|
-
export function automaticPolicyAuthorized(root, config) {
|
|
177
|
-
if (config.reservedIgnoreNames === undefined)
|
|
178
|
-
return true;
|
|
179
|
-
const saved = readConsent(root)?.setups[config.setupName];
|
|
180
|
-
return saved?.automaticFingerprint !== undefined && saved.automaticFingerprint === consentFingerprint(root, config);
|
|
181
|
-
}
|
|
182
|
-
function ignorePublicationConsentLines(config) {
|
|
183
|
-
const policy = config.ignorePolicy;
|
|
184
|
-
if (!policy)
|
|
185
|
-
return [];
|
|
186
|
-
return [
|
|
187
|
-
"Review this file before you approve its scope. Peers must be able to read snapshot version 7.",
|
|
188
|
-
policy.matches(policy.filename)
|
|
189
|
-
? "The rule file excludes itself; new snapshots omit its text."
|
|
190
|
-
: "New snapshots include the rule file, including any rule comments and private path names.",
|
|
191
|
-
];
|
|
192
|
-
}
|
|
193
|
-
export async function reviewAutomaticPolicy(execution, config, expectedFingerprint) {
|
|
194
|
-
if (consentFingerprint(execution.root, config) !== expectedFingerprint)
|
|
195
|
-
throw new Error("Setup changed; reopen the automatic transfer review.");
|
|
196
|
-
if (config.reservedIgnoreNames === undefined || automaticPolicyAuthorized(execution.root, config)) {
|
|
197
|
-
execution.noteDebugOutcome?.("skipped");
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
const consent = readConsent(execution.root);
|
|
201
|
-
if (!consent) {
|
|
202
|
-
execution.noteDebugOutcome?.("blocked");
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
const consentToken = JSON.stringify(consent);
|
|
206
|
-
const peers = participantBinding(execution);
|
|
207
|
-
const binding = JSON.stringify(execution.facts());
|
|
208
|
-
const { loadConfigForCheck } = await import("./engine/settings/config.js");
|
|
209
|
-
const fingerprint = syncCheckConfigFingerprint(config);
|
|
210
|
-
const validate = () => {
|
|
211
|
-
execution.validate();
|
|
212
|
-
execution.signal.throwIfAborted();
|
|
213
|
-
if (participantBinding(execution) !== peers ||
|
|
214
|
-
JSON.stringify(execution.facts()) !== binding ||
|
|
215
|
-
JSON.stringify(readConsent(execution.root)) !== consentToken)
|
|
216
|
-
throw new Error("Participants or consent changed during automatic transfer review.");
|
|
217
|
-
};
|
|
218
|
-
const current = await loadConfigForCheck(undefined, execution.signal);
|
|
219
|
-
validate();
|
|
220
|
-
if (syncCheckConfigFingerprint(current) !== fingerprint) {
|
|
221
|
-
execution.noteDebugOutcome?.("blocked");
|
|
222
|
-
return false;
|
|
223
|
-
}
|
|
224
|
-
const modes = [
|
|
225
|
-
startupTransferEnabled(config) && "Automatic transfer at startup",
|
|
226
|
-
config.automatic &&
|
|
227
|
-
syncSessionsSelected(config) &&
|
|
228
|
-
"Push selected files on shutdown (including sessions when selected)",
|
|
229
|
-
config.continuous && config.agentMode && "Continuous sync and Autonomous model requests",
|
|
230
|
-
].filter(Boolean);
|
|
231
|
-
if (modes.length === 0)
|
|
232
|
-
throw new Error("No automatic transfer mode is enabled under the current local rules.");
|
|
233
|
-
const accepted = await execution.request("confirm", {
|
|
234
|
-
title: "Allow the enabled automatic sync modes for this setup?",
|
|
235
|
-
message: [
|
|
236
|
-
`Setup: ${safeTerminalText(config.setupName)}`,
|
|
237
|
-
`Destination: ${safeTerminalText(config.connectionName)} · ${safeTerminalText(config.storagePath)}`,
|
|
238
|
-
...(config.ignorePolicy
|
|
239
|
-
? [
|
|
240
|
-
`Local ignore file: ${safeTerminalText(config.ignorePolicy.filename)}`,
|
|
241
|
-
...ignorePublicationConsentLines(config),
|
|
242
|
-
]
|
|
243
|
-
: []),
|
|
244
|
-
`Enabled modes: ${modes.join("; ")}`,
|
|
245
|
-
"Their usual baseline, remote selection, and ownership checks still apply. This does not allow work after the last Pi exits. A settings or rule-file change requires a new review.",
|
|
246
|
-
].join("\n"),
|
|
247
|
-
});
|
|
248
|
-
validate();
|
|
249
|
-
if (accepted !== true) {
|
|
250
|
-
execution.noteDebugOutcome?.("cancelled");
|
|
251
|
-
return false;
|
|
252
|
-
}
|
|
253
|
-
const latest = await loadConfigForCheck(undefined, execution.signal);
|
|
254
|
-
await config.validateIgnorePolicy?.();
|
|
255
|
-
validate();
|
|
256
|
-
if (syncCheckConfigFingerprint(latest) !== fingerprint)
|
|
257
|
-
throw new Error("Setup changed during automatic transfer review.");
|
|
258
|
-
const saved = consent.setups[config.setupName];
|
|
259
|
-
const automaticFingerprint = consentFingerprint(execution.root, config);
|
|
260
|
-
publishConsent({
|
|
261
|
-
...consent,
|
|
262
|
-
setups: {
|
|
263
|
-
...consent.setups,
|
|
264
|
-
[config.setupName]: {
|
|
265
|
-
...saved,
|
|
266
|
-
fingerprint: saved?.fingerprint ?? automaticFingerprint,
|
|
267
|
-
afterExit: saved?.afterExit ?? false,
|
|
268
|
-
automaticFingerprint,
|
|
269
|
-
},
|
|
270
|
-
},
|
|
271
|
-
});
|
|
272
|
-
return true;
|
|
273
|
-
}
|
|
274
174
|
export async function captureAutomaticAuthorization(execution, expectedFingerprint) {
|
|
275
175
|
const consent = readConsent(execution.root);
|
|
276
176
|
if (!consent) {
|
|
@@ -291,14 +191,10 @@ export async function captureAutomaticAuthorization(execution, expectedFingerpri
|
|
|
291
191
|
const config = await loadConfigForCheck(undefined, execution.signal);
|
|
292
192
|
validateParticipants();
|
|
293
193
|
const fingerprint = syncCheckConfigFingerprint(config);
|
|
294
|
-
if (expectedFingerprint !== undefined
|
|
194
|
+
if (expectedFingerprint !== undefined && fingerprint !== expectedFingerprint) {
|
|
295
195
|
execution.noteDebugOutcome?.("blocked");
|
|
296
196
|
throw new Error("Settings changed before automatic work; use the reviewed foreground command.");
|
|
297
197
|
}
|
|
298
|
-
if (!automaticPolicyAuthorized(execution.root, config)) {
|
|
299
|
-
execution.noteDebugOutcome?.("blocked");
|
|
300
|
-
throw new Error("Automatic transfer requires separate approval for the current setup and policy. Run reviewed /sync first.");
|
|
301
|
-
}
|
|
302
198
|
const validate = (current) => {
|
|
303
199
|
validateParticipants();
|
|
304
200
|
if (current && syncCheckConfigFingerprint(current) !== fingerprint) {
|
|
@@ -320,7 +216,7 @@ export async function requireHandover(execution) {
|
|
|
320
216
|
return;
|
|
321
217
|
const accepted = await execution.request("confirm", {
|
|
322
218
|
title: "Adopt pi-sync-daemon as the synchronization owner?",
|
|
323
|
-
message: "Close or upgrade every older Pi process before continuing. An idle older Pi cannot be detected from an absent sync lock. The daemon will own transfers; Pi keeps presentation and live file queues.
|
|
219
|
+
message: "Close or upgrade every older Pi process before continuing. An idle older Pi cannot be detected from an absent sync lock. The daemon will own transfers; Pi keeps presentation and live file queues. This does not authorize new transfers after the last Pi exits.",
|
|
324
220
|
});
|
|
325
221
|
execution.validate();
|
|
326
222
|
if (accepted !== true) {
|
|
@@ -343,6 +239,8 @@ export async function requireHandover(execution) {
|
|
|
343
239
|
export async function authorizeAfterExit(execution, payload) {
|
|
344
240
|
if (!record(payload) || typeof payload.afterExit !== "boolean" || typeof payload.fingerprint !== "string")
|
|
345
241
|
throw new Error("Invalid daemon authorization.");
|
|
242
|
+
if (payload.afterExit)
|
|
243
|
+
throw new Error("Continuous sync was retired. New after-exit grants are not supported.");
|
|
346
244
|
await requireHandover(execution);
|
|
347
245
|
const peers = participantBinding(execution);
|
|
348
246
|
const { loadConfigForCheck } = await import("./engine/settings/config.js");
|
|
@@ -356,27 +254,18 @@ export async function authorizeAfterExit(execution, payload) {
|
|
|
356
254
|
const policyGeneration = JSON.stringify(readConsent(execution.root));
|
|
357
255
|
if (fingerprint !== payload.fingerprint)
|
|
358
256
|
throw new Error("Setup changed; reopen the daemon authorization review.");
|
|
359
|
-
if (payload.afterExit && (!config.continuous || !config.agentMode))
|
|
360
|
-
throw new Error("Enable the reviewed Autonomous and Continuous policies first.");
|
|
361
257
|
const paths = (rules) => rules?.map(safeTerminalText).join(", ") || "none";
|
|
362
|
-
const selection = config.
|
|
258
|
+
const selection = config.scope === "agent-directory"
|
|
363
259
|
? [
|
|
364
|
-
"Selected content: eligible files in the Pi agent directory",
|
|
365
|
-
`
|
|
366
|
-
|
|
367
|
-
`Session opt-in: ${config.
|
|
260
|
+
"Selected content: all eligible files in the Pi agent directory",
|
|
261
|
+
`Excluded paths: ${paths(config.exclude)}`,
|
|
262
|
+
`Re-included paths: ${paths(config.reinclude)}`,
|
|
263
|
+
`Session opt-in: ${config.include.includes("sessions") ? "On — path rules still apply" : "Off"}`,
|
|
368
264
|
].join("\n")
|
|
369
|
-
: config.
|
|
370
|
-
? [
|
|
371
|
-
"Selected content: all eligible files in the Pi agent directory",
|
|
372
|
-
`Excluded paths: ${paths(config.exclude)}`,
|
|
373
|
-
`Re-included paths: ${paths(config.reinclude)}`,
|
|
374
|
-
`Session opt-in: ${config.include.includes("sessions") ? "On — path rules still apply" : "Off"}`,
|
|
375
|
-
].join("\n")
|
|
376
|
-
: `Selected content: ${paths(config.include)}`;
|
|
265
|
+
: `Selected content: ${paths(config.include)}`;
|
|
377
266
|
const accepted = await execution.request("confirm", {
|
|
378
|
-
title:
|
|
379
|
-
message: `Setup: ${safeTerminalText(config.setupName)}\n${selection}\
|
|
267
|
+
title: "Revoke unattended sync?",
|
|
268
|
+
message: `Setup: ${safeTerminalText(config.setupName)}\n${selection}\n\nThis clears the retained after-exit grant without transferring files.`,
|
|
380
269
|
});
|
|
381
270
|
execution.validate();
|
|
382
271
|
if (accepted !== true) {
|
|
@@ -385,7 +274,6 @@ export async function authorizeAfterExit(execution, payload) {
|
|
|
385
274
|
}
|
|
386
275
|
const latest = await loadConfigForCheck(undefined, execution.signal);
|
|
387
276
|
execution.validate();
|
|
388
|
-
await config.validateIgnorePolicy?.();
|
|
389
277
|
execution.validate();
|
|
390
278
|
if (participantBinding(execution) !== peers ||
|
|
391
279
|
consentFingerprint(execution.root, latest) !== fingerprint ||
|
|
@@ -409,7 +297,6 @@ export async function authorizeAfterExit(execution, payload) {
|
|
|
409
297
|
sessionDir: facts?.sessionDir,
|
|
410
298
|
cwd: facts?.cwd,
|
|
411
299
|
afterExit: payload.afterExit,
|
|
412
|
-
...(payload.afterExit && config.reservedIgnoreNames !== undefined ? { automaticFingerprint: fingerprint } : {}),
|
|
413
300
|
},
|
|
414
301
|
},
|
|
415
302
|
});
|