@narumitw/pi-sync 0.67.3 → 0.68.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +26 -48
- 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-HLJIRWFL.ts → chunk-BCDBT4X3.ts} +7 -7
- package/dist/chunks/{chunk-AVTW6WNP.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-X344HTVV.ts → chunk-WCGLU526.ts} +39 -118
- package/dist/chunks/chunk-WCGLU526.ts.map +7 -0
- package/dist/chunks/{chunk-CQ4DMLH3.ts → chunk-WQXUZSY5.ts} +25 -83
- package/dist/chunks/chunk-WQXUZSY5.ts.map +7 -0
- package/dist/chunks/{chunk-JREGWM2B.ts → chunk-XNUARYLR.ts} +1 -2
- package/dist/chunks/{command-handler-WF2TDDRZ.ts → command-handler-5LDTCUJE.ts} +64 -59
- package/dist/chunks/command-handler-5LDTCUJE.ts.map +7 -0
- package/dist/chunks/{conflict-review-GWEL4S6C.ts → conflict-review-SZ3AWTX6.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-BXN46NRC.ts → manager-result-dispatcher-A4IWLS4J.ts} +7 -7
- package/dist/chunks/{manager-ui-FS4QIKRA.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-DOYKUMER.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-PI45SF2C.ts → setup-wizard-2NRPR433.ts} +11 -16
- package/dist/chunks/{setup-wizard-PI45SF2C.ts.map → setup-wizard-2NRPR433.ts.map} +1 -1
- package/dist/chunks/{sync-inspection-DI5J6EUH.ts → sync-inspection-OTI4JDQ2.ts} +5 -5
- package/dist/chunks/{sync-operations-AGNL7QXA.ts → sync-operations-ZUYJLWUN.ts} +2 -2
- package/dist/daemon/dist/build-id.json +1 -1
- package/dist/daemon/dist/cli.js +22 -3
- package/dist/daemon/dist/client-transport.js +2 -0
- package/dist/daemon/dist/client.js +2 -10
- package/dist/daemon/dist/consent.js +13 -135
- 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 +12 -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 +25 -118
- package/dist/daemon/dist/engine/sync/sync-policy.js +26 -150
- package/dist/daemon/dist/engine/sync/sync-queries.js +81 -65
- 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/ui/sync-format.js +1 -1
- package/dist/daemon/dist/engine-service.js +60 -219
- package/dist/daemon/dist/foreground-queue-outcome.js +0 -4
- package/dist/daemon/dist/legacy-consent-guard.js +34 -0
- package/dist/daemon/dist/server.js +4 -8
- package/dist/daemon/dist/service-host.js +4 -10
- package/dist/daemon/package.json +1 -1
- package/dist/index.ts +45 -46
- package/dist/index.ts.map +3 -3
- package/docs/continuous-sync-verification.md +1 -1
- package/docs/daemon-migration.md +7 -5
- package/docs/tui-contract.md +4 -6
- package/package.json +2 -3
- package/skills/configure-pi-sync/SKILL.md +18 -77
- package/skills/configure-pi-sync/references/configuration.md +60 -77
- package/src/commands/command-execution.ts +13 -29
- package/src/commands/command-handler.ts +0 -4
- package/src/commands/command.ts +2 -1
- package/src/daemon/directional-recovery.ts +4 -33
- package/src/daemon/pi-client.ts +28 -90
- package/src/settings/config.ts +0 -1
- package/src/sync/setup-switch.ts +1 -4
- package/src/sync-extension.ts +10 -24
- 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-33EDXDLC.ts +0 -106
- package/dist/chunks/chunk-33EDXDLC.ts.map +0 -7
- package/dist/chunks/chunk-AVTW6WNP.ts.map +0 -7
- package/dist/chunks/chunk-CQ4DMLH3.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-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-WFBHWYI6.ts +0 -18
- package/dist/chunks/chunk-WFBHWYI6.ts.map +0 -7
- package/dist/chunks/chunk-X344HTVV.ts.map +0 -7
- package/dist/chunks/command-handler-WF2TDDRZ.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-BEZZZIEE.ts +0 -21
- package/dist/chunks/manager-ui-FS4QIKRA.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-DOYKUMER.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-HLJIRWFL.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-GWEL4S6C.ts.map → conflict-review-SZ3AWTX6.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-BEZZZIEE.ts.map → remote-selection-ui-F6NJBQ3Y.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-BXN46NRC.ts.map → setup-switch-7LMIRMZ7.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-DI5J6EUH.ts.map → sync-inspection-OTI4JDQ2.ts.map} +0 -0
- /package/dist/chunks/{sync-operations-AGNL7QXA.ts.map → sync-operations-ZUYJLWUN.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,92 +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, syncCheckConfigFingerprint } = 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
|
-
if (!
|
|
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") {
|
|
329
254
|
execution.noteDebugOutcome?.("blocked");
|
|
330
|
-
throw new Error("
|
|
255
|
+
throw new Error("Startup transfer requires a fresh initialized baseline, matching selection, and idle ready clients; use the reviewed foreground command.");
|
|
331
256
|
}
|
|
332
|
-
const approved = await reviewAutomaticPolicy(execution, config, consentFingerprint(root, config), "retry");
|
|
333
|
-
execution.validate();
|
|
334
|
-
if (!approved)
|
|
335
|
-
return "cancelled";
|
|
336
|
-
monitor.reviewedPolicy(config);
|
|
337
|
-
}
|
|
338
|
-
if (options.agentRetryRefusal) {
|
|
339
|
-
const fingerprint = syncCheckConfigFingerprint(config);
|
|
340
|
-
options.validateAgentRetryPolicy = (current) => {
|
|
341
|
-
execution.validate();
|
|
342
|
-
if (syncCheckConfigFingerprint(current) !== fingerprint || !automaticPolicyAuthorized(root, current))
|
|
343
|
-
throw new Error("Sync setup or automatic transfer approval changed; reopen the retry.");
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
else if (operation === "sync")
|
|
347
|
-
monitor.explicitSync(config, execution);
|
|
348
|
-
const binding = JSON.stringify(execution.facts()?.model);
|
|
349
|
-
const resolver = await prepareResolverHost(root, config.agentMode ? execution.facts()?.model : undefined, execution.signal);
|
|
350
|
-
try {
|
|
351
|
-
await automatic?.refresh();
|
|
352
|
-
ctx.modelUnavailableReason = resolver.unavailable;
|
|
353
|
-
Object.defineProperty(ctx, "model", {
|
|
354
|
-
get: () => (JSON.stringify(execution.facts()?.model) === binding ? resolver.model : undefined),
|
|
355
|
-
});
|
|
356
|
-
ctx.validateModel = async () => {
|
|
357
|
-
const fresh = await execution.request("model-binding", {});
|
|
358
|
-
await automatic?.refresh();
|
|
359
|
-
execution.validate();
|
|
360
|
-
if (JSON.stringify(fresh ?? undefined) !== binding)
|
|
361
|
-
throw new Error("Selected provider/model capability changed before dispatch.");
|
|
362
|
-
};
|
|
363
|
-
ctx.modelRegistry = {
|
|
364
|
-
streamSimple: (model, context, options) => {
|
|
365
|
-
automatic?.validate();
|
|
366
|
-
execution.validate();
|
|
367
|
-
if (JSON.stringify(execution.facts()?.model) !== binding)
|
|
368
|
-
throw new Error("Selected model changed before dispatch.");
|
|
369
|
-
if (resolver.unavailable)
|
|
370
|
-
throw new Error(resolver.unavailable);
|
|
371
|
-
return resolver.registry.streamSimple(model, context, options);
|
|
372
|
-
},
|
|
373
|
-
};
|
|
374
|
-
const { withAgentSyncLock } = await import("./engine/sync/agent-sync.js");
|
|
375
|
-
return await withAgentSyncLock(ctx, options, async (current) => {
|
|
376
|
-
if (operation === "startup-transfer") {
|
|
377
|
-
const { startupTransferEnabled } = await import("./engine/sync/agent-policy.js");
|
|
378
|
-
if (!automatic)
|
|
379
|
-
throw new Error("Missing startup transfer authorization.");
|
|
380
|
-
await automatic.refresh();
|
|
381
|
-
const config = automatic.config;
|
|
382
|
-
execution.validate();
|
|
383
|
-
const { inspectSync } = await import("./engine/sync/sync-inspection.js");
|
|
384
|
-
const { snapshotOptionsForContext } = await import("./engine/snapshot/session-paths.js");
|
|
385
|
-
await automatic.refresh();
|
|
386
|
-
const inspection = await inspectSync(config, snapshotOptionsForContext(ctx, config), current.signal);
|
|
387
|
-
await automatic.refresh();
|
|
388
|
-
execution.validate();
|
|
389
|
-
if (!startupTransferEnabled(config) ||
|
|
390
|
-
!ctx.isIdle() ||
|
|
391
|
-
execution.participants().some((peer) => peer.ready !== true) ||
|
|
392
|
-
inspection.firstSync ||
|
|
393
|
-
!inspection.head ||
|
|
394
|
-
inspection.selectionState?.kind !== "same") {
|
|
395
|
-
execution.noteDebugOutcome?.("blocked");
|
|
396
|
-
throw new Error("Startup transfer requires a fresh initialized baseline, matching selection, and idle ready clients; use the reviewed foreground command.");
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
return operations.syncBoth(ctx, current);
|
|
400
|
-
});
|
|
401
257
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
}
|
|
405
|
-
};
|
|
258
|
+
return operations.syncBoth(ctx, options);
|
|
259
|
+
});
|
|
406
260
|
return operation === "startup-transfer"
|
|
407
261
|
? withJobTimings(ctx, execution, "daemon transfer", async (timings) => {
|
|
408
262
|
options.startupTimings = timings;
|
|
@@ -422,7 +276,9 @@ export function createEngineService(root, ignoreFileSettingsAvailable = false) {
|
|
|
422
276
|
});
|
|
423
277
|
return {
|
|
424
278
|
execute,
|
|
425
|
-
bind
|
|
279
|
+
bind(value) {
|
|
280
|
+
server = value;
|
|
281
|
+
},
|
|
426
282
|
hooks: {
|
|
427
283
|
diagnostic: createDaemonDebug(root),
|
|
428
284
|
startup: {
|
|
@@ -432,14 +288,14 @@ export function createEngineService(root, ignoreFileSettingsAvailable = false) {
|
|
|
432
288
|
return captureStartupBootstrap(root, fingerprint, signal, reviewLock);
|
|
433
289
|
},
|
|
434
290
|
},
|
|
435
|
-
factsChanged
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
failure:
|
|
441
|
-
foregroundRecoveryAllowed:
|
|
442
|
-
upgradeAllowed: () => !host.cleanupRequired() &&
|
|
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(),
|
|
443
299
|
},
|
|
444
300
|
};
|
|
445
301
|
}
|
|
@@ -449,22 +305,17 @@ async function runForegroundDirectional(host, execution, ctx, direction, payload
|
|
|
449
305
|
!ctx.hasUI ||
|
|
450
306
|
!["tui", "rpc"].includes(ctx.mode) ||
|
|
451
307
|
!record(payload) ||
|
|
452
|
-
Object.keys(payload).some((key) => !["setup", "fingerprint", "retryCheckpoint"
|
|
308
|
+
Object.keys(payload).some((key) => !["setup", "fingerprint", "retryCheckpoint"].includes(key)) ||
|
|
453
309
|
typeof payload.setup !== "string" ||
|
|
454
310
|
!payload.setup ||
|
|
455
311
|
payload.setup.length > 512 ||
|
|
456
312
|
typeof payload.fingerprint !== "string" ||
|
|
457
313
|
!fingerprintPattern.test(payload.fingerprint) ||
|
|
458
314
|
(payload.retryCheckpoint !== undefined &&
|
|
459
|
-
(typeof payload.retryCheckpoint !== "string" || !fingerprintPattern.test(payload.retryCheckpoint)))
|
|
460
|
-
(payload.retryAdoptionJournal !== undefined &&
|
|
461
|
-
(direction !== "pull" ||
|
|
462
|
-
payload.retryCheckpoint !== undefined ||
|
|
463
|
-
typeof payload.retryAdoptionJournal !== "string" ||
|
|
464
|
-
!fingerprintPattern.test(payload.retryAdoptionJournal)))) {
|
|
315
|
+
(typeof payload.retryCheckpoint !== "string" || !fingerprintPattern.test(payload.retryCheckpoint)))) {
|
|
465
316
|
throw new Error("Invalid foreground directional request.");
|
|
466
317
|
}
|
|
467
|
-
const { setup, fingerprint, retryCheckpoint
|
|
318
|
+
const { setup, fingerprint, retryCheckpoint } = payload;
|
|
468
319
|
const { withStateDirectoryAccess } = await import("./engine/state/state-directory.js");
|
|
469
320
|
const { withLock } = await import("./engine/state/lock.js");
|
|
470
321
|
const { loadConfigForCheck, syncCheckConfigFingerprint } = await import("./engine/settings/config.js");
|
|
@@ -477,7 +328,7 @@ async function runForegroundDirectional(host, execution, ctx, direction, payload
|
|
|
477
328
|
execution.validate();
|
|
478
329
|
return withStateDirectoryAccess(async () => {
|
|
479
330
|
validate(await loadConfigForCheck(undefined, execution.signal));
|
|
480
|
-
if (retryCheckpoint === undefined
|
|
331
|
+
if (retryCheckpoint === undefined) {
|
|
481
332
|
await requireHandover(execution);
|
|
482
333
|
validate(await loadConfigForCheck(undefined, execution.signal));
|
|
483
334
|
await initialize(ctx, execution, false);
|
|
@@ -487,29 +338,19 @@ async function runForegroundDirectional(host, execution, ctx, direction, payload
|
|
|
487
338
|
throw new Error("Daemon handover is no longer valid; the transfer was not replayed.");
|
|
488
339
|
await requireStartupRecoveryCleared(execution);
|
|
489
340
|
}
|
|
490
|
-
return host.runForeground(execution, (
|
|
341
|
+
return host.runForeground(execution, () => withLock(direction, async () => {
|
|
491
342
|
validate(await loadConfigForCheck(undefined, execution.signal));
|
|
492
343
|
let message;
|
|
493
|
-
let adoptionRecovery = false;
|
|
494
344
|
const outcome = await operations[direction](ctx, {
|
|
495
345
|
...optionsFrom({ setup, args: [] }, execution, false),
|
|
496
346
|
directionalAction: {
|
|
497
347
|
validate,
|
|
498
|
-
expectedAdoptionJournal: retryAdoptionJournal,
|
|
499
|
-
setAdoptionResume(journal) {
|
|
500
|
-
if (adoptionRecovery)
|
|
501
|
-
setAdoptionResume(journal);
|
|
502
|
-
},
|
|
503
348
|
async checkpoint(current) {
|
|
504
349
|
execution.validate();
|
|
505
350
|
if (retryCheckpoint !== undefined && retryCheckpoint !== current)
|
|
506
351
|
throw new Error("The transfer source or destination changed during recovery. The transfer was not replayed.");
|
|
507
|
-
const accepted = await execution.request("directional-checkpoint", {
|
|
508
|
-
|
|
509
|
-
...(direction === "pull" ? { adoptionRecovery: 1 } : {}),
|
|
510
|
-
});
|
|
511
|
-
adoptionRecovery = direction === "pull" && record(accepted) && accepted.adoptionRecovery === 1;
|
|
512
|
-
if (accepted !== true && !adoptionRecovery)
|
|
352
|
+
const accepted = await execution.request("directional-checkpoint", { fingerprint: current });
|
|
353
|
+
if (accepted !== true)
|
|
513
354
|
throw new Error("The original transfer could not be retained for recovery. No transfer was started.");
|
|
514
355
|
execution.validate();
|
|
515
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
|
}
|
|
@@ -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
|
+
}
|
|
@@ -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
|
});
|
|
@@ -712,6 +706,8 @@ export async function startServer(root, execute, hooks = {}) {
|
|
|
712
706
|
if (method === "hello")
|
|
713
707
|
return {
|
|
714
708
|
version: PROTOCOL_VERSION,
|
|
709
|
+
ignoreFilesRetired: true,
|
|
710
|
+
autonomousSyncRetired: true,
|
|
715
711
|
buildVersion: DAEMON_BUILD_VERSION,
|
|
716
712
|
...(DAEMON_BUILD_ID && { buildId: DAEMON_BUILD_ID }),
|
|
717
713
|
upgradeStop: 1,
|
|
@@ -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 });
|
|
@@ -234,7 +228,7 @@ export function createServiceContext(execution) {
|
|
|
234
228
|
await ask("reload", {});
|
|
235
229
|
},
|
|
236
230
|
ui: {
|
|
237
|
-
notify: (message, level = "info") => execution.emit("notify", { message, level }),
|
|
231
|
+
notify: (message, level = "info", layout) => execution.emit("notify", { message, level, ...(layout ? { layout } : {}) }),
|
|
238
232
|
setStatus: (_key, value) => execution.emit("status", { value }),
|
|
239
233
|
confirm: async (title, message, options) => (await ask("confirm", { title, message }, options?.signal)) === true,
|
|
240
234
|
select: async (title, items, options) => {
|
package/dist/daemon/package.json
CHANGED