@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
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { authorizeAfterExit,
|
|
1
|
+
import { authorizeAfterExit, captureAutomaticAuthorization, consentFingerprint, readConsent, requireHandover, } from "./consent.js";
|
|
2
2
|
import { createDaemonDebug } from "./daemon-debug.js";
|
|
3
3
|
import { documentFingerprint } from "./document.js";
|
|
4
|
+
import { retiredIgnorePolicy } from "./engine/settings/retired-ignore-policy.js";
|
|
5
|
+
import { assertNoRetiredRuleJournal } from "./engine/settings/retired-ignore-recovery.js";
|
|
4
6
|
import { captureStartupReviewLock } from "./engine/state/lock.js";
|
|
5
|
-
import {
|
|
7
|
+
import { createLegacyConsentGuard } from "./legacy-consent-guard.js";
|
|
6
8
|
import { MAX_SETTINGS_BYTES, record } from "./protocol.js";
|
|
7
9
|
import { createServiceContext, installServiceHost } from "./service-host.js";
|
|
8
10
|
function optionsFrom(value, execution, automatic) {
|
|
@@ -43,63 +45,18 @@ function optionsFrom(value, execution, automatic) {
|
|
|
43
45
|
};
|
|
44
46
|
}
|
|
45
47
|
/** Engine dispatch is loaded only by the service, never by the public IPC client. */
|
|
46
|
-
export function createEngineService(root
|
|
47
|
-
const host = installServiceHost(root
|
|
48
|
-
const
|
|
48
|
+
export function createEngineService(root) {
|
|
49
|
+
const host = installServiceHost(root);
|
|
50
|
+
const consentGuard = createLegacyConsentGuard(root);
|
|
51
|
+
let server;
|
|
49
52
|
const execute = (operation, payload, execution) => host.run(execution, async () => {
|
|
50
|
-
if (operation === "
|
|
51
|
-
|
|
52
|
-
return { available: ignoreFileSettingsAvailable, ...(ignoreFileSettingsAvailable ? { portableRules: 1 } : {}) };
|
|
53
|
-
}
|
|
54
|
-
if (operation === "ignore.migration-offer" || operation === "ignore.migration-defer") {
|
|
55
|
-
execution.validate();
|
|
56
|
-
const { readIgnoreMigrationOffer, deferIgnoreMigrationOffer } = await import("./engine/ignore/ignore-migration-prompt.js");
|
|
57
|
-
return operation === "ignore.migration-offer"
|
|
58
|
-
? readIgnoreMigrationOffer(payload, execution)
|
|
59
|
-
: deferIgnoreMigrationOffer(payload, execution);
|
|
60
|
-
}
|
|
61
|
-
if (operation === "ignore.save") {
|
|
62
|
-
execution.validate();
|
|
63
|
-
throw new Error("Daemon ignore-file saves are unavailable. Edit the existing rule file manually.");
|
|
64
|
-
}
|
|
65
|
-
const ignoreFileChange = operation === "ignore.migrate" || operation === "ignore.switch";
|
|
66
|
-
if (ignoreFileChange && !ignoreFileSettingsAvailable) {
|
|
67
|
-
execution.validate();
|
|
68
|
-
throw new Error("Unsupported engine operation.");
|
|
69
|
-
}
|
|
70
|
-
await monitor.pause();
|
|
53
|
+
if (operation.startsWith("ignore.") || operation === "daemon.authorize-connected")
|
|
54
|
+
throw retiredIgnorePolicy("settings");
|
|
71
55
|
execution.validate();
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
execution.validate();
|
|
75
|
-
return runIgnorePolicyChange(operation, payload, {
|
|
76
|
-
...execution,
|
|
77
|
-
committed() {
|
|
78
|
-
execution.committed();
|
|
79
|
-
monitor.settingsCommitted(true);
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
}
|
|
56
|
+
if (operation !== "settings.repair-read" && operation !== "monitor.pause")
|
|
57
|
+
assertNoRetiredRuleJournal();
|
|
83
58
|
if (operation === "daemon.authorize") {
|
|
84
|
-
|
|
85
|
-
if (authorized?.afterExit)
|
|
86
|
-
monitor.reviewedPolicy(authorized.config);
|
|
87
|
-
return Boolean(authorized);
|
|
88
|
-
}
|
|
89
|
-
if (operation === "daemon.authorize-connected") {
|
|
90
|
-
const facts = execution.facts();
|
|
91
|
-
if (!record(payload) ||
|
|
92
|
-
typeof payload.fingerprint !== "string" ||
|
|
93
|
-
!facts?.hasUI ||
|
|
94
|
-
!["tui", "rpc"].includes(facts.mode))
|
|
95
|
-
throw new Error("Automatic policy authorization requires an interactive review.");
|
|
96
|
-
const { loadConfigForCheck } = await import("./engine/settings/config.js");
|
|
97
|
-
const config = await loadConfigForCheck(undefined, execution.signal);
|
|
98
|
-
execution.validate();
|
|
99
|
-
const approved = await reviewAutomaticPolicy(execution, config, payload.fingerprint);
|
|
100
|
-
if (approved)
|
|
101
|
-
monitor.reviewedPolicy(config);
|
|
102
|
-
return approved;
|
|
59
|
+
return Boolean(await authorizeAfterExit(execution, payload));
|
|
103
60
|
}
|
|
104
61
|
if (operation === "daemon.handover") {
|
|
105
62
|
await requireHandover(execution);
|
|
@@ -110,26 +67,10 @@ export function createEngineService(root, ignoreFileSettingsAvailable = false) {
|
|
|
110
67
|
const config = await loadConfigForCheck(undefined, execution.signal);
|
|
111
68
|
execution.validate();
|
|
112
69
|
const fingerprint = consentFingerprint(root, config);
|
|
113
|
-
|
|
114
|
-
const facts = execution.facts();
|
|
115
|
-
return {
|
|
116
|
-
setup: config.setupName,
|
|
117
|
-
fingerprint,
|
|
118
|
-
automatic: automaticPolicyAuthorized(root, config),
|
|
119
|
-
afterExit: Boolean(saved?.afterExit &&
|
|
120
|
-
saved.fingerprint === fingerprint &&
|
|
121
|
-
JSON.stringify(saved.model) === JSON.stringify(facts?.model) &&
|
|
122
|
-
saved.sessionDir === facts?.sessionDir &&
|
|
123
|
-
saved.cwd === facts?.cwd),
|
|
124
|
-
};
|
|
70
|
+
return { setup: config.setupName, fingerprint, automatic: true, afterExit: false };
|
|
125
71
|
}
|
|
126
72
|
if (operation === "monitor.pause")
|
|
127
73
|
return;
|
|
128
|
-
if (operation === "ignore.read") {
|
|
129
|
-
const { readIgnoreFileEdit } = await import("./engine/ignore/ignore-edit.js");
|
|
130
|
-
execution.validate();
|
|
131
|
-
return readIgnoreFileEdit(payload, execution);
|
|
132
|
-
}
|
|
133
74
|
if (operation === "settings.read" || operation === "settings.repair-read") {
|
|
134
75
|
const { readLocalConfigDocument } = await import("./engine/settings/settings-store.js");
|
|
135
76
|
const { readActiveLocalConfigDocumentForRepair } = await import("./engine/settings/config-file.js");
|
|
@@ -150,14 +91,10 @@ export function createEngineService(root, ignoreFileSettingsAvailable = false) {
|
|
|
150
91
|
(typeof payload.expected !== "string" || !/^[a-f0-9]{64}$/u.test(payload.expected))) ||
|
|
151
92
|
!record(payload.next))
|
|
152
93
|
throw new Error("Invalid settings mutation.");
|
|
153
|
-
const {
|
|
94
|
+
const { updateLocalConfigDocument, peekLocalConfigDocument } = await import("./engine/settings/config-file.js");
|
|
154
95
|
const { localConfigTemplate } = await import("./engine/settings/settings-store.js");
|
|
155
96
|
const { validateSettingsDocument } = await import("./engine/settings/settings-validation.js");
|
|
156
97
|
const next = validateSettingsDocument(payload.next);
|
|
157
|
-
const nextMixed = Object.values(next.syncSetups).some((setup) => setup.sync.pathPolicy === "ignore-file");
|
|
158
|
-
if (!ignoreFileSettingsAvailable && nextMixed) {
|
|
159
|
-
throw new Error("Ignore-file setup activation is not available in this Daemon build.");
|
|
160
|
-
}
|
|
161
98
|
if (Buffer.byteLength(JSON.stringify(next)) > MAX_SETTINGS_BYTES)
|
|
162
99
|
throw new Error("Settings exceed the editable local API byte limit; no fields were dropped.");
|
|
163
100
|
const validateSource = (document) => {
|
|
@@ -168,41 +105,17 @@ export function createEngineService(root, ignoreFileSettingsAvailable = false) {
|
|
|
168
105
|
};
|
|
169
106
|
const original = await peekLocalConfigDocument();
|
|
170
107
|
validateSource(original);
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
let prepareSource;
|
|
174
|
-
if (ignoreFileSettingsAvailable && (nextMixed || wasMixed)) {
|
|
175
|
-
if (original && original.path !== localConfigPath())
|
|
176
|
-
throw new Error("This settings change requires pi-sync.json. No settings were saved; use the canonical filename and reopen the review.");
|
|
177
|
-
const { newIgnoreFilename, reviewNewIgnoreSource, prepareReviewedIgnoreSource } = await import("./engine/ignore/ignore-settings.js");
|
|
178
|
-
execution.validate();
|
|
179
|
-
const filename = newIgnoreFilename(before, next);
|
|
180
|
-
if (filename) {
|
|
181
|
-
const reviewed = await reviewNewIgnoreSource(root, filename, execution);
|
|
182
|
-
validateSource(await peekLocalConfigDocument());
|
|
183
|
-
prepareSource = async () => {
|
|
184
|
-
await prepareReviewedIgnoreSource(root, reviewed, execution);
|
|
185
|
-
execution.validate();
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
else if (wasMixed && !nextMixed) {
|
|
189
|
-
prepareSource = async () => {
|
|
190
|
-
execution.validate();
|
|
191
|
-
revokeAfterExitGrants(root);
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
}
|
|
108
|
+
if (original)
|
|
109
|
+
validateSettingsDocument(original.parsed);
|
|
195
110
|
await requireHandover(execution);
|
|
196
111
|
execution.validate();
|
|
197
112
|
const saved = await updateLocalConfigDocument(localConfigTemplate(), () => {
|
|
198
113
|
execution.validate();
|
|
199
114
|
validateSettingsDocument(next);
|
|
200
115
|
return next;
|
|
201
|
-
}, validateSettingsDocument, execution.signal, validateSource
|
|
202
|
-
if (!original || JSON.stringify(original.parsed) !== JSON.stringify(saved))
|
|
203
|
-
monitor.settingsCommitted(Boolean(wasMixed || nextMixed));
|
|
116
|
+
}, validateSettingsDocument, execution.signal, validateSource);
|
|
117
|
+
if (!original || JSON.stringify(original.parsed) !== JSON.stringify(saved))
|
|
204
118
|
execution.committed();
|
|
205
|
-
}
|
|
206
119
|
return saved;
|
|
207
120
|
}
|
|
208
121
|
const ctx = createServiceContext(execution);
|
|
@@ -248,6 +161,8 @@ export function createEngineService(root, ignoreFileSettingsAvailable = false) {
|
|
|
248
161
|
throw new Error("Unsupported engine operation.");
|
|
249
162
|
const isAutomatic = operation === "startup-transfer" || operation === "shutdown";
|
|
250
163
|
const options = optionsFrom(payload, execution, isAutomatic);
|
|
164
|
+
if (options.agentRetryRefusal)
|
|
165
|
+
throw new Error("Model retries are no longer supported. Use reviewed manual sync.");
|
|
251
166
|
if (!options.reload)
|
|
252
167
|
ctx.reload = undefined;
|
|
253
168
|
if (operation === "shutdown") {
|
|
@@ -317,77 +232,31 @@ export function createEngineService(root, ignoreFileSettingsAvailable = false) {
|
|
|
317
232
|
options.reload = false;
|
|
318
233
|
}
|
|
319
234
|
if (operation === "sync" || operation === "startup-transfer") {
|
|
320
|
-
const run = async () => {
|
|
321
|
-
const { prepareResolverHost } = await import("./resolver-host.js");
|
|
322
|
-
const { loadConfig } = await import("./engine/settings/config.js");
|
|
323
|
-
const config = await loadConfig(options.setup, execution.signal);
|
|
324
|
-
await automatic?.refresh();
|
|
325
|
-
automatic?.validate(config);
|
|
235
|
+
const run = () => withLock("sync", async () => {
|
|
326
236
|
execution.validate();
|
|
327
|
-
if (
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
await automatic
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
execution.
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
};
|
|
348
|
-
ctx.modelRegistry = {
|
|
349
|
-
streamSimple: (model, context, options) => {
|
|
350
|
-
automatic?.validate();
|
|
351
|
-
execution.validate();
|
|
352
|
-
if (JSON.stringify(execution.facts()?.model) !== binding)
|
|
353
|
-
throw new Error("Selected model changed before dispatch.");
|
|
354
|
-
if (resolver.unavailable)
|
|
355
|
-
throw new Error(resolver.unavailable);
|
|
356
|
-
return resolver.registry.streamSimple(model, context, options);
|
|
357
|
-
},
|
|
358
|
-
};
|
|
359
|
-
const { withAgentSyncLock } = await import("./engine/sync/agent-sync.js");
|
|
360
|
-
return await withAgentSyncLock(ctx, options, async (current) => {
|
|
361
|
-
if (operation === "startup-transfer") {
|
|
362
|
-
const { startupTransferEnabled } = await import("./engine/sync/agent-policy.js");
|
|
363
|
-
if (!automatic)
|
|
364
|
-
throw new Error("Missing startup transfer authorization.");
|
|
365
|
-
await automatic.refresh();
|
|
366
|
-
const config = automatic.config;
|
|
367
|
-
execution.validate();
|
|
368
|
-
const { inspectSync } = await import("./engine/sync/sync-inspection.js");
|
|
369
|
-
const { snapshotOptionsForContext } = await import("./engine/snapshot/session-paths.js");
|
|
370
|
-
await automatic.refresh();
|
|
371
|
-
const inspection = await inspectSync(config, snapshotOptionsForContext(ctx, config), current.signal);
|
|
372
|
-
await automatic.refresh();
|
|
373
|
-
execution.validate();
|
|
374
|
-
if (!startupTransferEnabled(config) ||
|
|
375
|
-
!ctx.isIdle() ||
|
|
376
|
-
execution.participants().some((peer) => peer.ready !== true) ||
|
|
377
|
-
inspection.firstSync ||
|
|
378
|
-
!inspection.head ||
|
|
379
|
-
inspection.selectionState?.kind !== "same") {
|
|
380
|
-
execution.noteDebugOutcome?.("blocked");
|
|
381
|
-
throw new Error("Startup transfer requires a fresh initialized baseline, matching selection, and idle ready clients; use the reviewed foreground command.");
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
return operations.syncBoth(ctx, current);
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
finally {
|
|
388
|
-
await resolver.settle();
|
|
237
|
+
if (operation === "startup-transfer") {
|
|
238
|
+
if (!automatic)
|
|
239
|
+
throw new Error("Missing startup transfer authorization.");
|
|
240
|
+
const { startupTransferEnabled } = await import("./engine/sync/agent-policy.js");
|
|
241
|
+
const { inspectSync } = await import("./engine/sync/sync-inspection.js");
|
|
242
|
+
const { snapshotOptionsForContext } = await import("./engine/snapshot/session-paths.js");
|
|
243
|
+
await automatic.refresh();
|
|
244
|
+
const config = automatic.config;
|
|
245
|
+
const inspection = await inspectSync(config, snapshotOptionsForContext(ctx, config), options.signal);
|
|
246
|
+
await automatic.refresh();
|
|
247
|
+
execution.validate();
|
|
248
|
+
if (!startupTransferEnabled(config) ||
|
|
249
|
+
!ctx.isIdle() ||
|
|
250
|
+
execution.participants().some((peer) => peer.ready !== true) ||
|
|
251
|
+
inspection.firstSync ||
|
|
252
|
+
!inspection.head ||
|
|
253
|
+
inspection.selectionState?.kind !== "same") {
|
|
254
|
+
execution.noteDebugOutcome?.("blocked");
|
|
255
|
+
throw new Error("Startup transfer requires a fresh initialized baseline, matching selection, and idle ready clients; use the reviewed foreground command.");
|
|
256
|
+
}
|
|
389
257
|
}
|
|
390
|
-
|
|
258
|
+
return operations.syncBoth(ctx, options);
|
|
259
|
+
});
|
|
391
260
|
return operation === "startup-transfer"
|
|
392
261
|
? withJobTimings(ctx, execution, "daemon transfer", async (timings) => {
|
|
393
262
|
options.startupTimings = timings;
|
|
@@ -407,7 +276,9 @@ export function createEngineService(root, ignoreFileSettingsAvailable = false) {
|
|
|
407
276
|
});
|
|
408
277
|
return {
|
|
409
278
|
execute,
|
|
410
|
-
bind
|
|
279
|
+
bind(value) {
|
|
280
|
+
server = value;
|
|
281
|
+
},
|
|
411
282
|
hooks: {
|
|
412
283
|
diagnostic: createDaemonDebug(root),
|
|
413
284
|
startup: {
|
|
@@ -417,13 +288,14 @@ export function createEngineService(root, ignoreFileSettingsAvailable = false) {
|
|
|
417
288
|
return captureStartupBootstrap(root, fingerprint, signal, reviewLock);
|
|
418
289
|
},
|
|
419
290
|
},
|
|
420
|
-
factsChanged
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
failure:
|
|
426
|
-
foregroundRecoveryAllowed:
|
|
291
|
+
async factsChanged() {
|
|
292
|
+
if (server)
|
|
293
|
+
consentGuard.factsChanged(server.participants());
|
|
294
|
+
},
|
|
295
|
+
lifetime: () => (host.cleanupRequired() ? Promise.resolve("pause") : consentGuard.lifetime()),
|
|
296
|
+
failure: consentGuard.block,
|
|
297
|
+
foregroundRecoveryAllowed: consentGuard.allowsRecovery,
|
|
298
|
+
upgradeAllowed: () => !host.cleanupRequired() && consentGuard.allowsRecovery(),
|
|
427
299
|
},
|
|
428
300
|
};
|
|
429
301
|
}
|
|
@@ -433,22 +305,17 @@ async function runForegroundDirectional(host, execution, ctx, direction, payload
|
|
|
433
305
|
!ctx.hasUI ||
|
|
434
306
|
!["tui", "rpc"].includes(ctx.mode) ||
|
|
435
307
|
!record(payload) ||
|
|
436
|
-
Object.keys(payload).some((key) => !["setup", "fingerprint", "retryCheckpoint"
|
|
308
|
+
Object.keys(payload).some((key) => !["setup", "fingerprint", "retryCheckpoint"].includes(key)) ||
|
|
437
309
|
typeof payload.setup !== "string" ||
|
|
438
310
|
!payload.setup ||
|
|
439
311
|
payload.setup.length > 512 ||
|
|
440
312
|
typeof payload.fingerprint !== "string" ||
|
|
441
313
|
!fingerprintPattern.test(payload.fingerprint) ||
|
|
442
314
|
(payload.retryCheckpoint !== undefined &&
|
|
443
|
-
(typeof payload.retryCheckpoint !== "string" || !fingerprintPattern.test(payload.retryCheckpoint)))
|
|
444
|
-
(payload.retryAdoptionJournal !== undefined &&
|
|
445
|
-
(direction !== "pull" ||
|
|
446
|
-
payload.retryCheckpoint !== undefined ||
|
|
447
|
-
typeof payload.retryAdoptionJournal !== "string" ||
|
|
448
|
-
!fingerprintPattern.test(payload.retryAdoptionJournal)))) {
|
|
315
|
+
(typeof payload.retryCheckpoint !== "string" || !fingerprintPattern.test(payload.retryCheckpoint)))) {
|
|
449
316
|
throw new Error("Invalid foreground directional request.");
|
|
450
317
|
}
|
|
451
|
-
const { setup, fingerprint, retryCheckpoint
|
|
318
|
+
const { setup, fingerprint, retryCheckpoint } = payload;
|
|
452
319
|
const { withStateDirectoryAccess } = await import("./engine/state/state-directory.js");
|
|
453
320
|
const { withLock } = await import("./engine/state/lock.js");
|
|
454
321
|
const { loadConfigForCheck, syncCheckConfigFingerprint } = await import("./engine/settings/config.js");
|
|
@@ -461,7 +328,7 @@ async function runForegroundDirectional(host, execution, ctx, direction, payload
|
|
|
461
328
|
execution.validate();
|
|
462
329
|
return withStateDirectoryAccess(async () => {
|
|
463
330
|
validate(await loadConfigForCheck(undefined, execution.signal));
|
|
464
|
-
if (retryCheckpoint === undefined
|
|
331
|
+
if (retryCheckpoint === undefined) {
|
|
465
332
|
await requireHandover(execution);
|
|
466
333
|
validate(await loadConfigForCheck(undefined, execution.signal));
|
|
467
334
|
await initialize(ctx, execution, false);
|
|
@@ -471,29 +338,19 @@ async function runForegroundDirectional(host, execution, ctx, direction, payload
|
|
|
471
338
|
throw new Error("Daemon handover is no longer valid; the transfer was not replayed.");
|
|
472
339
|
await requireStartupRecoveryCleared(execution);
|
|
473
340
|
}
|
|
474
|
-
return host.runForeground(execution, (
|
|
341
|
+
return host.runForeground(execution, () => withLock(direction, async () => {
|
|
475
342
|
validate(await loadConfigForCheck(undefined, execution.signal));
|
|
476
343
|
let message;
|
|
477
|
-
let adoptionRecovery = false;
|
|
478
344
|
const outcome = await operations[direction](ctx, {
|
|
479
345
|
...optionsFrom({ setup, args: [] }, execution, false),
|
|
480
346
|
directionalAction: {
|
|
481
347
|
validate,
|
|
482
|
-
expectedAdoptionJournal: retryAdoptionJournal,
|
|
483
|
-
setAdoptionResume(journal) {
|
|
484
|
-
if (adoptionRecovery)
|
|
485
|
-
setAdoptionResume(journal);
|
|
486
|
-
},
|
|
487
348
|
async checkpoint(current) {
|
|
488
349
|
execution.validate();
|
|
489
350
|
if (retryCheckpoint !== undefined && retryCheckpoint !== current)
|
|
490
351
|
throw new Error("The transfer source or destination changed during recovery. The transfer was not replayed.");
|
|
491
|
-
const accepted = await execution.request("directional-checkpoint", {
|
|
492
|
-
|
|
493
|
-
...(direction === "pull" ? { adoptionRecovery: 1 } : {}),
|
|
494
|
-
});
|
|
495
|
-
adoptionRecovery = direction === "pull" && record(accepted) && accepted.adoptionRecovery === 1;
|
|
496
|
-
if (accepted !== true && !adoptionRecovery)
|
|
352
|
+
const accepted = await execution.request("directional-checkpoint", { fingerprint: current });
|
|
353
|
+
if (accepted !== true)
|
|
497
354
|
throw new Error("The original transfer could not be retained for recovery. No transfer was started.");
|
|
498
355
|
execution.validate();
|
|
499
356
|
},
|
|
@@ -5,9 +5,5 @@ export function isForegroundQueueOutcome(value) {
|
|
|
5
5
|
if (!value || typeof value !== "object" || !("foregroundQueueCleanup" in value))
|
|
6
6
|
return false;
|
|
7
7
|
return (value.foregroundQueueCleanup === "before-mutation" ||
|
|
8
|
-
(value.foregroundQueueCleanup === "resume-adoption" &&
|
|
9
|
-
"journal" in value &&
|
|
10
|
-
typeof value.journal === "string" &&
|
|
11
|
-
/^[a-f0-9]{64}$/u.test(value.journal)) ||
|
|
12
8
|
(value.foregroundQueueCleanup === "verified-result" && Object.hasOwn(value, "result")));
|
|
13
9
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { DaemonConnection, DaemonError, ensureDaemon, findDaemon, requestDaemon, stopDaemon, waitForDaemonExit, } from "./client.js";
|
|
2
2
|
export { inspectDaemonRecovery, stopDaemonForRecovery, } from "./daemon-recovery.js";
|
|
3
|
+
export { DaemonUpgradeBlockedError } from "./daemon-startup.js";
|
|
4
|
+
export { inspectDaemonStatus } from "./daemon-status.js";
|
|
3
5
|
export { documentFingerprint } from "./document.js";
|
|
4
6
|
export { modelSignature } from "./model-signature.js";
|
|
5
7
|
export { MAX_SETTINGS_BYTES, OWNERSHIP_CLEANUP_REQUIRED, PROTOCOL_VERSION } from "./protocol.js";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ConsentPublicationError, readConsent, revokeChangedBindings } from "./consent.js";
|
|
2
|
+
import { loadConfigForCheck } from "./engine/settings/config.js";
|
|
3
|
+
export function createLegacyConsentGuard(root) {
|
|
4
|
+
let blocked = false;
|
|
5
|
+
return {
|
|
6
|
+
block() {
|
|
7
|
+
blocked = true;
|
|
8
|
+
},
|
|
9
|
+
allowsRecovery: () => !blocked,
|
|
10
|
+
async lifetime() {
|
|
11
|
+
if (blocked)
|
|
12
|
+
return "pause";
|
|
13
|
+
try {
|
|
14
|
+
const consent = readConsent(root);
|
|
15
|
+
if (consent && Object.values(consent.setups).some((saved) => saved.afterExit))
|
|
16
|
+
await loadConfigForCheck();
|
|
17
|
+
return blocked ? "pause" : "exit";
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return "pause";
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
factsChanged(peers) {
|
|
24
|
+
try {
|
|
25
|
+
revokeChangedBindings(root, peers);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
blocked = true;
|
|
29
|
+
if (error instanceof ConsentPublicationError)
|
|
30
|
+
throw new Error("Daemon authorization could not be saved. Repair and revoke retained permission before an explicit restart.", { cause: error });
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -4,7 +4,7 @@ import { lstatSync } from "node:fs";
|
|
|
4
4
|
import fs from "node:fs/promises";
|
|
5
5
|
import { createServer } from "node:http";
|
|
6
6
|
import lockfile from "proper-lockfile";
|
|
7
|
-
import { DAEMON_BUILD_VERSION } from "./build-version.js";
|
|
7
|
+
import { DAEMON_BUILD_ID, DAEMON_BUILD_VERSION } from "./build-version.js";
|
|
8
8
|
import { ConsentPublicationError, readConsent } from "./consent.js";
|
|
9
9
|
import { endpointOwner } from "./endpoint.js";
|
|
10
10
|
import { debugJobResult, debugOperation } from "./engine/debug-log.js";
|
|
@@ -371,12 +371,7 @@ export async function startServer(root, execute, hooks = {}) {
|
|
|
371
371
|
digest,
|
|
372
372
|
client,
|
|
373
373
|
generation: peer.facts.generation,
|
|
374
|
-
participantGeneration: [
|
|
375
|
-
"startup-transfer",
|
|
376
|
-
"shutdown",
|
|
377
|
-
"daemon.authorize",
|
|
378
|
-
"daemon.authorize-connected",
|
|
379
|
-
].includes(operation)
|
|
374
|
+
participantGeneration: ["startup-transfer", "shutdown", "daemon.authorize"].includes(operation)
|
|
380
375
|
? participantGeneration
|
|
381
376
|
: undefined,
|
|
382
377
|
controller: new AbortController(),
|
|
@@ -402,8 +397,7 @@ export async function startServer(root, execute, hooks = {}) {
|
|
|
402
397
|
if (Buffer.byteLength(JSON.stringify(result ?? null)) > MAX_MESSAGE_BYTES / 2)
|
|
403
398
|
throw new Error("Operation result exceeds its byte limit; use bounded inspection.");
|
|
404
399
|
if (isForegroundDirection(operation) && isForegroundQueueOutcome(result)) {
|
|
405
|
-
if (
|
|
406
|
-
(result.foregroundQueueCleanup === "resume-adoption" && (!job.committed || operation !== "pull.foreground")))
|
|
400
|
+
if (result.foregroundQueueCleanup === "before-mutation" && job.committed)
|
|
407
401
|
throw Object.assign(new Error("File-queue release and transfer outcome could not be verified."), {
|
|
408
402
|
code: OWNERSHIP_CLEANUP_REQUIRED,
|
|
409
403
|
});
|
|
@@ -625,6 +619,45 @@ export async function startServer(root, execute, hooks = {}) {
|
|
|
625
619
|
});
|
|
626
620
|
return { stopping: true };
|
|
627
621
|
}
|
|
622
|
+
function upgradeBlocker() {
|
|
623
|
+
if (ledger.failed ||
|
|
624
|
+
foregroundRecoveryJob ||
|
|
625
|
+
consentPublicationFailed ||
|
|
626
|
+
hooks.upgradeAllowed?.() === false ||
|
|
627
|
+
[...participants.values()].some((peer) => peer.resumeUnsafe))
|
|
628
|
+
return "repair";
|
|
629
|
+
if (peerOperations.size ||
|
|
630
|
+
expiring ||
|
|
631
|
+
backgroundJobs.size ||
|
|
632
|
+
pending.size ||
|
|
633
|
+
[...jobs.values()].some(({ view }) => view.phase === "queued" || view.phase === "running"))
|
|
634
|
+
return "busy";
|
|
635
|
+
if ([...participants.values()].some((peer) => peer.reservations?.size))
|
|
636
|
+
return "repair";
|
|
637
|
+
}
|
|
638
|
+
async function stopForUpgrade(params, signal) {
|
|
639
|
+
if (!record(params) || Object.keys(params).length !== 0)
|
|
640
|
+
throw new Error("Invalid upgrade stop request.");
|
|
641
|
+
const checkBarrier = (barrier) => {
|
|
642
|
+
signal?.throwIfAborted();
|
|
643
|
+
assertOwner();
|
|
644
|
+
if (barrier?.purpose || barrier?.instance !== identity.instance || barrier.pid !== identity.pid || !ownsLog())
|
|
645
|
+
throw new Error("Daemon owner or upgrade record changed; no stop was accepted.");
|
|
646
|
+
};
|
|
647
|
+
checkBarrier(await readUpgradeOwner(paths));
|
|
648
|
+
const deferred = upgradeBlocker();
|
|
649
|
+
if (deferred)
|
|
650
|
+
return { deferred };
|
|
651
|
+
return admission.run(async () => {
|
|
652
|
+
checkBarrier(await readUpgradeOwner(paths));
|
|
653
|
+
const deferred = upgradeBlocker();
|
|
654
|
+
if (deferred)
|
|
655
|
+
return { deferred };
|
|
656
|
+
if (Object.values(readConsent(paths.root)?.setups ?? {}).some((setup) => setup.afterExit))
|
|
657
|
+
return { deferred: "unattended" };
|
|
658
|
+
return stop();
|
|
659
|
+
}, signal);
|
|
660
|
+
}
|
|
628
661
|
async function stopForeground(params, signal) {
|
|
629
662
|
if (params.check !== undefined && params.check !== true)
|
|
630
663
|
throw new Error("Invalid foreground stop request.");
|
|
@@ -673,11 +706,49 @@ export async function startServer(root, execute, hooks = {}) {
|
|
|
673
706
|
if (method === "hello")
|
|
674
707
|
return {
|
|
675
708
|
version: PROTOCOL_VERSION,
|
|
709
|
+
ignoreFilesRetired: true,
|
|
710
|
+
autonomousSyncRetired: true,
|
|
676
711
|
buildVersion: DAEMON_BUILD_VERSION,
|
|
712
|
+
...(DAEMON_BUILD_ID && { buildId: DAEMON_BUILD_ID }),
|
|
713
|
+
upgradeStop: 1,
|
|
677
714
|
root: identity.root,
|
|
678
715
|
instance: identity.instance,
|
|
679
716
|
pid: identity.pid,
|
|
680
717
|
};
|
|
718
|
+
if (method === "upgrade-stop")
|
|
719
|
+
return stopForUpgrade(params, signal);
|
|
720
|
+
if (method === "protect-session") {
|
|
721
|
+
validateFacts(params);
|
|
722
|
+
const { pid, cwd, mode, sessionFile } = params;
|
|
723
|
+
if (!sessionFile)
|
|
724
|
+
throw new Error("A session file is required for protection.");
|
|
725
|
+
return admission.run(async () => {
|
|
726
|
+
assertOwner();
|
|
727
|
+
if (!processExists(pid))
|
|
728
|
+
throw new Error("Client process is not alive.");
|
|
729
|
+
const recorded = [...participants.values()].some((peer) => peer.handoff?.kind === "exit" && peer.facts.pid === pid && peer.facts.sessionFile === sessionFile);
|
|
730
|
+
if (!recorded) {
|
|
731
|
+
if (participants.size >= 64 || closedClients.size >= 10_000)
|
|
732
|
+
throw new Error("Daemon client capacity reached.");
|
|
733
|
+
const id = randomUUID();
|
|
734
|
+
participants.set(id, {
|
|
735
|
+
facts: { id, pid, generation: id, cwd, mode, sessionFile, hasUI: false, idle: false },
|
|
736
|
+
handoff: { kind: "exit" },
|
|
737
|
+
callbacks: new Map(),
|
|
738
|
+
events: [],
|
|
739
|
+
connected: false,
|
|
740
|
+
closing: false,
|
|
741
|
+
suspected: false,
|
|
742
|
+
seen: 0,
|
|
743
|
+
});
|
|
744
|
+
closedClients.add(id);
|
|
745
|
+
}
|
|
746
|
+
await savePeers(undefined, recorded);
|
|
747
|
+
signal?.throwIfAborted();
|
|
748
|
+
assertOwner();
|
|
749
|
+
return { protected: true };
|
|
750
|
+
}, signal);
|
|
751
|
+
}
|
|
681
752
|
if (method === "attach") {
|
|
682
753
|
const attached = await admission.run(async () => {
|
|
683
754
|
assertOwner();
|
|
@@ -963,14 +1034,31 @@ export async function startServer(root, execute, hooks = {}) {
|
|
|
963
1034
|
respond(response, 403, { error: { name: "Error", message: "Invalid daemon identity or protocol." } });
|
|
964
1035
|
return;
|
|
965
1036
|
}
|
|
966
|
-
if ([
|
|
1037
|
+
if ([
|
|
1038
|
+
"attach",
|
|
1039
|
+
"protect-session",
|
|
1040
|
+
"resume-contact",
|
|
1041
|
+
"startup.bootstrap",
|
|
1042
|
+
"state-wait",
|
|
1043
|
+
"foreground-stop",
|
|
1044
|
+
"upgrade-stop",
|
|
1045
|
+
].includes(body.method)) {
|
|
967
1046
|
admissionController = new AbortController();
|
|
968
1047
|
response.once("close", disconnect);
|
|
969
1048
|
if (response.destroyed)
|
|
970
1049
|
disconnect();
|
|
971
1050
|
}
|
|
972
1051
|
const operation = handle(body.method, body.params, admissionController?.signal, body.reviewDetails === 1);
|
|
973
|
-
if ([
|
|
1052
|
+
if ([
|
|
1053
|
+
"attach",
|
|
1054
|
+
"protect-session",
|
|
1055
|
+
"resume-contact",
|
|
1056
|
+
"startup.bootstrap",
|
|
1057
|
+
"update",
|
|
1058
|
+
"detach",
|
|
1059
|
+
"pause",
|
|
1060
|
+
"handoff",
|
|
1061
|
+
].includes(body.method)) {
|
|
974
1062
|
peerOperations.add(operation);
|
|
975
1063
|
void operation.finally(() => peerOperations.delete(operation)).catch(() => { });
|
|
976
1064
|
}
|
|
@@ -13,7 +13,7 @@ class OwnershipCleanupError extends Error {
|
|
|
13
13
|
}
|
|
14
14
|
const scope = new AsyncLocalStorage();
|
|
15
15
|
/** One service process owns one root; tests must use a separate process per root. */
|
|
16
|
-
export function installServiceHost(root
|
|
16
|
+
export function installServiceHost(root) {
|
|
17
17
|
let poisoned;
|
|
18
18
|
const assertRoot = canonicalRootGuard(root);
|
|
19
19
|
function current() {
|
|
@@ -93,7 +93,6 @@ export function installServiceHost(root, ignoreFileOperationsAvailable) {
|
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
configureEngineHost({
|
|
96
|
-
ignoreFileOperationsAvailable,
|
|
97
96
|
allowConfigMigration: () => Boolean(readConsent(root)),
|
|
98
97
|
root: () => {
|
|
99
98
|
assertRoot();
|
|
@@ -155,12 +154,9 @@ export function installServiceHost(root, ignoreFileOperationsAvailable) {
|
|
|
155
154
|
if (owner.execution !== execution || !execution.clientId || owner.held.size || owner.foreground)
|
|
156
155
|
throw new Error("Foreground queue recovery requires one attached directional job.");
|
|
157
156
|
const foreground = { entered: false, deferred: false };
|
|
158
|
-
let adoptionResume;
|
|
159
157
|
return scope.run({ ...owner, foreground }, async () => {
|
|
160
158
|
try {
|
|
161
|
-
const result = await action(
|
|
162
|
-
adoptionResume = journal;
|
|
163
|
-
});
|
|
159
|
+
const result = await action();
|
|
164
160
|
if (foreground.deferred && poisoned === "queue")
|
|
165
161
|
return { foregroundQueueCleanup: "verified-result", result };
|
|
166
162
|
return result;
|
|
@@ -170,9 +166,7 @@ export function installServiceHost(root, ignoreFileOperationsAvailable) {
|
|
|
170
166
|
!execution.signal.aborted &&
|
|
171
167
|
error instanceof AggregateError &&
|
|
172
168
|
error.errors.includes(foreground.beforeMutation))
|
|
173
|
-
return
|
|
174
|
-
? { foregroundQueueCleanup: "before-mutation" }
|
|
175
|
-
: { foregroundQueueCleanup: "resume-adoption", journal: adoptionResume };
|
|
169
|
+
return { foregroundQueueCleanup: "before-mutation" };
|
|
176
170
|
if (foreground.deferred && !(error instanceof OwnershipCleanupError)) {
|
|
177
171
|
const detail = error instanceof Error ? ` ${error.message}` : "";
|
|
178
172
|
throw new OwnershipCleanupError(`File-queue release was not confirmed.${detail}`, { cause: error });
|
package/dist/daemon/package.json
CHANGED