@narumitw/pi-sync 0.62.0 → 0.63.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 +26 -0
- package/README.md +40 -23
- package/dist/chunks/{chunk-MNYRU5U5.ts → chunk-27F5W7DX.ts} +3 -2
- package/dist/chunks/{chunk-MNYRU5U5.ts.map → chunk-27F5W7DX.ts.map} +2 -2
- package/dist/chunks/{chunk-INECVQNR.ts → chunk-B5F3JLD3.ts} +6 -4
- package/dist/chunks/chunk-B5F3JLD3.ts.map +7 -0
- package/dist/chunks/chunk-CKUGCBHP.ts +114 -0
- package/dist/chunks/chunk-CKUGCBHP.ts.map +7 -0
- package/dist/chunks/chunk-EJDDRS6O.ts +17 -0
- package/dist/chunks/chunk-EJDDRS6O.ts.map +7 -0
- package/dist/chunks/{chunk-6PFZUEUG.ts → chunk-EXDWEFIJ.ts} +52 -135
- package/dist/chunks/chunk-EXDWEFIJ.ts.map +7 -0
- package/dist/chunks/{chunk-NHFGAZEC.ts → chunk-HSCAFOT5.ts} +7 -7
- package/dist/chunks/chunk-HSCAFOT5.ts.map +7 -0
- package/dist/chunks/{chunk-ZB3GNX3P.ts → chunk-LBNC5AOM.ts} +140 -13
- package/dist/chunks/chunk-LBNC5AOM.ts.map +7 -0
- package/dist/chunks/chunk-MANNB4WZ.ts +36 -0
- package/dist/chunks/chunk-MANNB4WZ.ts.map +7 -0
- package/dist/chunks/{chunk-GSQGBVKG.ts → chunk-POWOMJ7S.ts} +87 -50
- package/dist/chunks/chunk-POWOMJ7S.ts.map +7 -0
- package/dist/chunks/{chunk-PWESMTH6.ts → chunk-SXCH4Q5O.ts} +38 -20
- package/dist/chunks/chunk-SXCH4Q5O.ts.map +7 -0
- package/dist/chunks/{chunk-3E3TR3JE.ts → chunk-V76KCWHO.ts} +6 -4
- package/dist/chunks/{chunk-3E3TR3JE.ts.map → chunk-V76KCWHO.ts.map} +1 -1
- package/dist/chunks/{chunk-GSCZ4VXV.ts → chunk-VQ47JBLF.ts} +2 -2
- package/dist/chunks/chunk-WFBHWYI6.ts +18 -0
- package/dist/chunks/chunk-WFBHWYI6.ts.map +7 -0
- package/dist/chunks/{command-handler-6ATREPG7.ts → command-handler-GMRRFWOL.ts} +19 -36
- package/dist/chunks/command-handler-GMRRFWOL.ts.map +7 -0
- package/dist/chunks/{conflict-review-MAOGTIAI.ts → conflict-review-JWEA7DPQ.ts} +2 -2
- package/dist/chunks/{file-selection-QR2KZVGD.ts → file-selection-KID23GAD.ts} +15 -8
- package/dist/chunks/file-selection-KID23GAD.ts.map +7 -0
- package/dist/chunks/{manager-result-dispatcher-MC6EQOQY.ts → manager-result-dispatcher-GDB74IOP.ts} +6 -5
- package/dist/chunks/{manager-ui-AOFUNXAJ.ts → manager-ui-T5J5WG7T.ts} +227 -343
- package/dist/chunks/manager-ui-T5J5WG7T.ts.map +7 -0
- package/dist/chunks/{merge-review-SGDLMVS4.ts → merge-review-OQDXNTJU.ts} +2 -2
- package/dist/chunks/{remote-selection-ui-4BTP2OJR.ts → remote-selection-ui-GPITNEBF.ts} +5 -4
- package/dist/chunks/{setup-switch-Y6AMFFNK.ts → setup-switch-L54X5U5I.ts} +4 -4
- package/dist/chunks/{setup-wizard-5G426MOZ.ts → setup-wizard-LL6YMGUR.ts} +7 -3
- package/dist/chunks/{setup-wizard-5G426MOZ.ts.map → setup-wizard-LL6YMGUR.ts.map} +1 -1
- package/dist/chunks/{sync-inspection-ITZ6Z4DE.ts → sync-inspection-SRU6HGGK.ts} +3 -3
- package/dist/chunks/{sync-operations-NMVKF7SE.ts → sync-operations-UGSCONZ7.ts} +2 -2
- package/dist/daemon/dist/cli.js +1 -1
- package/dist/daemon/dist/consent.js +134 -16
- package/dist/daemon/dist/engine/backends/git/git-backend.js +61 -30
- package/dist/daemon/dist/engine/ignore/ignore-initialization.js +142 -40
- package/dist/daemon/dist/engine/ignore/ignore-settings.js +94 -26
- package/dist/daemon/dist/engine/ignore/ignore-source.js +1 -1
- package/dist/daemon/dist/engine/settings/config-file.js +1 -1
- package/dist/daemon/dist/engine/settings/config.js +71 -28
- package/dist/daemon/dist/engine/settings/settings-management.js +8 -2
- package/dist/daemon/dist/engine/snapshot/session-paths.js +7 -2
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-policy.js +37 -17
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction.js +55 -13
- package/dist/daemon/dist/engine/sync/agent-plan.js +1 -0
- package/dist/daemon/dist/engine/sync/agent-sync.js +8 -1
- package/dist/daemon/dist/engine/sync/continuous-sync.js +32 -15
- package/dist/daemon/dist/engine/sync/merge-acceptance.js +29 -0
- package/dist/daemon/dist/engine/sync/merge-apply.js +7 -4
- package/dist/daemon/dist/engine/sync/merge-journal.js +33 -14
- package/dist/daemon/dist/engine/sync/merged-sync.js +31 -39
- package/dist/daemon/dist/engine/sync/remote-snapshot.js +17 -2
- package/dist/daemon/dist/engine/sync/session-push.js +20 -6
- package/dist/daemon/dist/engine/sync/sync-error-guidance.js +16 -3
- package/dist/daemon/dist/engine/sync/sync-mutations.js +75 -54
- package/dist/daemon/dist/engine/sync/sync-policy.js +28 -3
- package/dist/daemon/dist/engine/sync/sync-state.js +3 -8
- package/dist/daemon/dist/engine/sync/transfer-freshness.js +82 -0
- package/dist/daemon/dist/engine/ui/sync-format.js +23 -55
- package/dist/daemon/dist/engine/ui/transfer-review.js +3 -3
- package/dist/daemon/dist/engine-service.js +124 -27
- package/dist/daemon/dist/monitor.js +84 -32
- package/dist/daemon/dist/server.js +46 -5
- package/dist/daemon/dist/service-host.js +2 -1
- package/dist/daemon/package.json +1 -1
- package/dist/index.ts +28 -25
- package/dist/index.ts.map +4 -4
- package/docs/tui-contract.md +1 -1
- package/package.json +3 -3
- package/skills/configure-pi-sync/SKILL.md +128 -74
- package/skills/configure-pi-sync/references/configuration.md +115 -45
- package/src/commands/command-execution.ts +12 -8
- package/src/commands/command-types.ts +1 -0
- package/src/daemon/pi-client.ts +4 -2
- package/src/settings/config.ts +1 -0
- package/src/sync/automatic-sync.ts +9 -2
- package/src/sync/setup-switch.ts +38 -15
- package/src/sync/startup-check.ts +7 -4
- package/src/ui/excluded-paths-ui.ts +2 -2
- package/src/ui/file-selection.ts +7 -2
- package/src/ui/ignore-file-guidance.ts +7 -0
- package/src/ui/ignore-file-ui.ts +28 -202
- package/src/ui/manager-state.ts +33 -18
- package/src/ui/manager-ui.ts +27 -18
- package/src/ui/merge-review.ts +28 -1
- package/src/ui/remote-selection-ui.ts +51 -24
- package/src/ui/settings-ui.ts +132 -81
- package/src/ui/setup/setup-actions.ts +16 -4
- package/src/ui/setup/setup-prompts.ts +55 -9
- package/src/ui/setup/setup-switcher.ts +24 -11
- package/src/ui/setup/webdav-ui.ts +1 -1
- package/src/ui/storage-connections-ui.ts +33 -11
- package/src/ui/sync-confirmation.ts +67 -48
- package/src/ui/sync-setups-ui.ts +24 -7
- package/dist/chunks/chunk-6PFZUEUG.ts.map +0 -7
- package/dist/chunks/chunk-ECYCNZOE.ts +0 -12
- package/dist/chunks/chunk-ECYCNZOE.ts.map +0 -7
- package/dist/chunks/chunk-GSQGBVKG.ts.map +0 -7
- package/dist/chunks/chunk-INECVQNR.ts.map +0 -7
- package/dist/chunks/chunk-NHFGAZEC.ts.map +0 -7
- package/dist/chunks/chunk-PWESMTH6.ts.map +0 -7
- package/dist/chunks/chunk-ZB3GNX3P.ts.map +0 -7
- package/dist/chunks/command-handler-6ATREPG7.ts.map +0 -7
- package/dist/chunks/file-selection-QR2KZVGD.ts.map +0 -7
- package/dist/chunks/manager-ui-AOFUNXAJ.ts.map +0 -7
- /package/dist/chunks/{chunk-GSCZ4VXV.ts.map → chunk-VQ47JBLF.ts.map} +0 -0
- /package/dist/chunks/{conflict-review-MAOGTIAI.ts.map → conflict-review-JWEA7DPQ.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-MC6EQOQY.ts.map → manager-result-dispatcher-GDB74IOP.ts.map} +0 -0
- /package/dist/chunks/{merge-review-SGDLMVS4.ts.map → merge-review-OQDXNTJU.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-4BTP2OJR.ts.map → remote-selection-ui-GPITNEBF.ts.map} +0 -0
- /package/dist/chunks/{setup-switch-Y6AMFFNK.ts.map → setup-switch-L54X5U5I.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-ITZ6Z4DE.ts.map → sync-inspection-SRU6HGGK.ts.map} +0 -0
- /package/dist/chunks/{sync-operations-NMVKF7SE.ts.map → sync-operations-UGSCONZ7.ts.map} +0 -0
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/ui/setup/setup-name-ui.ts", "../../src/ui/setup/setup-wizard.ts"],
|
|
4
4
|
"sourcesContent": ["import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { validateConfigName } from \"../../settings/settings-validation.js\";\nimport { throwIfAborted } from \"../../sync/signals.js\";\nimport { errorMessage } from \"../../sync/sync-errors.js\";\nimport { safeTerminalText } from \"../terminal-text.js\";\n\nexport async function promptInitialSetupName(ctx: ExtensionCommandContext, signal?: AbortSignal) {\n while (!signal?.aborted) {\n const hint = \"For example: home or work. Leave blank for default.\";\n // Pi styles the whole input title as accent; give only the guidance a muted role.\n const guidance = ctx.mode === \"tui\" ? ctx.ui.theme.fg(\"muted\", hint) : hint;\n // This compact prompt owns its default hint; the general helper would repeat it.\n const value = await ctx.ui.input(`Sync setup name\\n${guidance}`, undefined, { signal });\n throwIfAborted(signal);\n if (value === undefined) return undefined;\n const name = value.trim() || \"default\";\n try {\n if (name.includes(\"<\") || name.includes(\">\")) {\n throw new Error(\"Replace example placeholders with your own name.\");\n }\n validateConfigName(name, \"sync setup\");\n return name;\n } catch (error) {\n ctx.ui.notify(\n `This name cannot be used for the sync setup. ${safeTerminalText(errorMessage(error))} Enter another name (for example, default).`,\n \"warning\",\n );\n }\n }\n return undefined;\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { refreshTargetCompletions } from \"../../commands/setup-completions.js\";\nimport { localConfigPath } from \"../../settings/config-file.js\";\nimport { safeTerminalText } from \"../terminal-text.js\";\nimport { showGitSetup } from \"./git-ui.js\";\nimport { showS3Setup } from \"./s3-ui.js\";\nimport { promptInitialSetupName } from \"./setup-name-ui.js\";\nimport { showWebDavSetup } from \"./webdav-ui.js\";\n\nexport async function showSetupWizard(ctx: ExtensionCommandContext, signal?: AbortSignal) {\n if (ctx.mode !== \"tui\") {\n if (ctx.hasUI)\n ctx.ui.notify(\n `Guided sync setup requires TUI mode for masked credential input. Create settings in ${safeTerminalText(localConfigPath())} (version 7 for agent-directory scope).`,\n \"warning\",\n );\n return false;\n }\n const preset = await ctx.ui.select(\n \"Set up sync\\n\\nWhere will Pi settings be stored?\",\n [\"Cloudflare R2\", \"Other S3-compatible storage\", \"WebDAV\", \"Git\", \"Cancel\"],\n { signal },\n );\n if (signal?.aborted || !preset || preset === \"Cancel\") return false;\n const targetName = await promptInitialSetupName(ctx, signal);\n if (!targetName) return false;\n if (preset === \"WebDAV\") {\n const saved = await showWebDavSetup(ctx, targetName, signal);\n if (signal?.aborted) return false;\n if (saved) await refreshTargetCompletions();\n return saved;\n }\n if (preset === \"Git\") {\n const saved = await showGitSetup(ctx, targetName, signal);\n if (signal?.aborted) return false;\n if (saved) await refreshTargetCompletions();\n return saved;\n }\n return showS3Setup(ctx, preset, targetName, signal);\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,eAAsB,uBAAuB,KAA8B,QAAsB;AAC/F,SAAO,CAAC,QAAQ,SAAS;AACvB,UAAM,OAAO;AAEb,UAAM,WAAW,IAAI,SAAS,QAAQ,IAAI,GAAG,MAAM,GAAG,SAAS,IAAI,IAAI;AAEvE,UAAM,QAAQ,MAAM,IAAI,GAAG,MAAM;AAAA,EAAoB,QAAQ,IAAI,QAAW,EAAE,OAAO,CAAC;AACtF,mBAAe,MAAM;AACrB,QAAI,UAAU,OAAW,QAAO;AAChC,UAAM,OAAO,MAAM,KAAK,KAAK;AAC7B,QAAI;AACF,UAAI,KAAK,SAAS,GAAG,KAAK,KAAK,SAAS,GAAG,GAAG;AAC5C,cAAM,IAAI,MAAM,kDAAkD;AAAA,MACpE;AACA,yBAAmB,MAAM,YAAY;AACrC,aAAO;AAAA,IACT,SAAS,OAAO;AACd,UAAI,GAAG;AAAA,QACL,gDAAgD,iBAAiB,aAAa,KAAK,CAAC,CAAC;AAAA,QACrF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;;;ACrBA,eAAsB,gBAAgB,KAA8B,QAAsB;AACxF,MAAI,IAAI,SAAS,OAAO;AACtB,QAAI,IAAI;AACN,UAAI,GAAG;AAAA,QACL,uFAAuF,iBAAiB,gBAAgB,CAAC,CAAC;AAAA,QAC1H;AAAA,MACF;AACF,WAAO;AAAA,EACT;AACA,QAAM,SAAS,MAAM,IAAI,GAAG;AAAA,IAC1B;AAAA,IACA,CAAC,iBAAiB,+BAA+B,UAAU,OAAO,QAAQ;AAAA,IAC1E,EAAE,OAAO;AAAA,EACX;AACA,MAAI,QAAQ,WAAW,CAAC,UAAU,WAAW,SAAU,QAAO;AAC9D,QAAM,aAAa,MAAM,uBAAuB,KAAK,MAAM;AAC3D,MAAI,CAAC,WAAY,QAAO;AACxB,MAAI,WAAW,UAAU;AACvB,UAAM,QAAQ,MAAM,gBAAgB,KAAK,YAAY,MAAM;AAC3D,QAAI,QAAQ,QAAS,QAAO;AAC5B,QAAI,MAAO,OAAM,yBAAyB;AAC1C,WAAO;AAAA,EACT;AACA,MAAI,WAAW,OAAO;AACpB,UAAM,QAAQ,MAAM,aAAa,KAAK,YAAY,MAAM;AACxD,QAAI,QAAQ,QAAS,QAAO;AAC5B,QAAI,MAAO,OAAM,yBAAyB;AAC1C,WAAO;AAAA,EACT;AACA,SAAO,YAAY,KAAK,QAAQ,YAAY,MAAM;AACpD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
|
|
3
3
|
import {
|
|
4
4
|
currentPiDaemonClient
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-B5F3JLD3.ts";
|
|
6
6
|
import {
|
|
7
7
|
syncCheckConfigFingerprint
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-27F5W7DX.ts";
|
|
9
9
|
import "./chunk-H7VOTY5N.ts";
|
|
10
10
|
import "./chunk-6YKOHBSC.ts";
|
|
11
11
|
import "./chunk-R3SAMXB6.ts";
|
|
@@ -20,4 +20,4 @@ var inspectSync = async (config, _options, signal) => await currentPiDaemonClien
|
|
|
20
20
|
export {
|
|
21
21
|
inspectSync
|
|
22
22
|
};
|
|
23
|
-
//# sourceMappingURL=sync-inspection-
|
|
23
|
+
//# sourceMappingURL=sync-inspection-SRU6HGGK.ts.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
|
|
3
3
|
import {
|
|
4
4
|
remoteOperation
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-B5F3JLD3.ts";
|
|
6
6
|
import "./chunk-H7VOTY5N.ts";
|
|
7
7
|
import "./chunk-6YKOHBSC.ts";
|
|
8
8
|
import "./chunk-R3SAMXB6.ts";
|
|
@@ -46,4 +46,4 @@ export {
|
|
|
46
46
|
status,
|
|
47
47
|
syncBoth
|
|
48
48
|
};
|
|
49
|
-
//# sourceMappingURL=sync-operations-
|
|
49
|
+
//# sourceMappingURL=sync-operations-UGSCONZ7.ts.map
|
package/dist/daemon/dist/cli.js
CHANGED
|
@@ -40,7 +40,7 @@ export async function main(args) {
|
|
|
40
40
|
log?.close(); /* Never follow a replaced diagnostic path. */
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
const service = createEngineService(paths.root);
|
|
43
|
+
const service = createEngineService(paths.root, true);
|
|
44
44
|
let server;
|
|
45
45
|
try {
|
|
46
46
|
server = await startServer(paths.root, service.execute, {
|
|
@@ -3,6 +3,8 @@ 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";
|
|
6
8
|
import { safeTerminalText } from "./engine/ui/terminal-text.js";
|
|
7
9
|
import { record } from "./protocol.js";
|
|
8
10
|
function file(root) {
|
|
@@ -82,7 +84,9 @@ export function revokeChangedBindings(root, peers) {
|
|
|
82
84
|
if (changed)
|
|
83
85
|
publishConsent(consent);
|
|
84
86
|
}
|
|
85
|
-
|
|
87
|
+
export function revokeAfterExitGrants(root) {
|
|
88
|
+
return revokeRetainedGrants(root);
|
|
89
|
+
}
|
|
86
90
|
export function revokeRetainedGrants(root) {
|
|
87
91
|
const consent = readConsent(root);
|
|
88
92
|
if (!consent)
|
|
@@ -129,6 +133,8 @@ export function readConsent(root) {
|
|
|
129
133
|
if (!record(entry) ||
|
|
130
134
|
typeof entry.fingerprint !== "string" ||
|
|
131
135
|
!/^[a-f0-9]{64}$/u.test(entry.fingerprint) ||
|
|
136
|
+
(entry.automaticFingerprint !== undefined &&
|
|
137
|
+
(typeof entry.automaticFingerprint !== "string" || !/^[a-f0-9]{64}$/u.test(entry.automaticFingerprint))) ||
|
|
132
138
|
typeof entry.afterExit !== "boolean" ||
|
|
133
139
|
(entry.cwd !== undefined &&
|
|
134
140
|
(typeof entry.cwd !== "string" || !path.isAbsolute(entry.cwd) || entry.cwd.includes("\0"))) ||
|
|
@@ -167,6 +173,119 @@ export function consentFingerprint(root, config) {
|
|
|
167
173
|
.update(syncCheckConfigFingerprint(config))
|
|
168
174
|
.digest("hex");
|
|
169
175
|
}
|
|
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
|
+
export async function reviewAutomaticPolicy(execution, config, expectedFingerprint) {
|
|
183
|
+
if (consentFingerprint(execution.root, config) !== expectedFingerprint)
|
|
184
|
+
throw new Error("Setup changed; reopen the automatic transfer review.");
|
|
185
|
+
if (config.reservedIgnoreNames === undefined || automaticPolicyAuthorized(execution.root, config))
|
|
186
|
+
return false;
|
|
187
|
+
const consent = readConsent(execution.root);
|
|
188
|
+
if (!consent)
|
|
189
|
+
return false;
|
|
190
|
+
const consentToken = JSON.stringify(consent);
|
|
191
|
+
const peers = participantBinding(execution);
|
|
192
|
+
const binding = JSON.stringify(execution.facts());
|
|
193
|
+
const { loadConfigForCheck } = await import("./engine/settings/config.js");
|
|
194
|
+
const fingerprint = syncCheckConfigFingerprint(config);
|
|
195
|
+
const validate = () => {
|
|
196
|
+
execution.validate();
|
|
197
|
+
execution.signal.throwIfAborted();
|
|
198
|
+
if (participantBinding(execution) !== peers ||
|
|
199
|
+
JSON.stringify(execution.facts()) !== binding ||
|
|
200
|
+
JSON.stringify(readConsent(execution.root)) !== consentToken)
|
|
201
|
+
throw new Error("Participants or consent changed during automatic transfer review.");
|
|
202
|
+
};
|
|
203
|
+
const current = await loadConfigForCheck(undefined, execution.signal);
|
|
204
|
+
validate();
|
|
205
|
+
if (syncCheckConfigFingerprint(current) !== fingerprint)
|
|
206
|
+
return false;
|
|
207
|
+
const modes = [
|
|
208
|
+
startupTransferEnabled(config) && "Automatic transfer at startup",
|
|
209
|
+
config.automatic &&
|
|
210
|
+
syncSessionsSelected(config) &&
|
|
211
|
+
"Push selected files on shutdown (including sessions when selected)",
|
|
212
|
+
config.continuous && config.agentMode && "Continuous sync and Autonomous model requests",
|
|
213
|
+
].filter(Boolean);
|
|
214
|
+
if (modes.length === 0)
|
|
215
|
+
throw new Error("No automatic transfer mode is enabled under the current local rules.");
|
|
216
|
+
const accepted = await execution.request("confirm", {
|
|
217
|
+
title: "Allow the enabled automatic sync modes for this setup?",
|
|
218
|
+
message: [
|
|
219
|
+
`Setup: ${safeTerminalText(config.setupName)}`,
|
|
220
|
+
`Destination: ${safeTerminalText(config.connectionName)} · ${safeTerminalText(config.storagePath)}`,
|
|
221
|
+
...(config.ignorePolicy
|
|
222
|
+
? [
|
|
223
|
+
`Local ignore file: ${safeTerminalText(config.ignorePolicy.filename)}`,
|
|
224
|
+
"Review this file before you approve its scope.",
|
|
225
|
+
]
|
|
226
|
+
: []),
|
|
227
|
+
`Enabled modes: ${modes.join("; ")}`,
|
|
228
|
+
"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.",
|
|
229
|
+
].join("\n"),
|
|
230
|
+
});
|
|
231
|
+
validate();
|
|
232
|
+
if (accepted !== true)
|
|
233
|
+
return false;
|
|
234
|
+
const latest = await loadConfigForCheck(undefined, execution.signal);
|
|
235
|
+
await config.validateIgnorePolicy?.();
|
|
236
|
+
validate();
|
|
237
|
+
if (syncCheckConfigFingerprint(latest) !== fingerprint)
|
|
238
|
+
throw new Error("Setup changed during automatic transfer review.");
|
|
239
|
+
const saved = consent.setups[config.setupName];
|
|
240
|
+
const automaticFingerprint = consentFingerprint(execution.root, config);
|
|
241
|
+
publishConsent({
|
|
242
|
+
...consent,
|
|
243
|
+
setups: {
|
|
244
|
+
...consent.setups,
|
|
245
|
+
[config.setupName]: {
|
|
246
|
+
...saved,
|
|
247
|
+
fingerprint: saved?.fingerprint ?? automaticFingerprint,
|
|
248
|
+
afterExit: saved?.afterExit ?? false,
|
|
249
|
+
automaticFingerprint,
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
export async function captureAutomaticAuthorization(execution, expectedFingerprint) {
|
|
256
|
+
const consent = readConsent(execution.root);
|
|
257
|
+
if (!consent)
|
|
258
|
+
throw new Error("Automatic work requires reviewed daemon handover first.");
|
|
259
|
+
const consentToken = JSON.stringify(consent);
|
|
260
|
+
const peers = participantBinding(execution);
|
|
261
|
+
const { loadConfigForCheck } = await import("./engine/settings/config.js");
|
|
262
|
+
const validateParticipants = () => {
|
|
263
|
+
execution.validate();
|
|
264
|
+
if (participantBinding(execution) !== peers || JSON.stringify(readConsent(execution.root)) !== consentToken)
|
|
265
|
+
throw new Error("Daemon participants or consent changed before automatic work completed.");
|
|
266
|
+
};
|
|
267
|
+
validateParticipants();
|
|
268
|
+
const config = await loadConfigForCheck(undefined, execution.signal);
|
|
269
|
+
validateParticipants();
|
|
270
|
+
const fingerprint = syncCheckConfigFingerprint(config);
|
|
271
|
+
if (expectedFingerprint !== undefined ? fingerprint !== expectedFingerprint : config.reservedIgnoreNames !== undefined)
|
|
272
|
+
throw new Error("Settings changed before automatic work; use the reviewed foreground command.");
|
|
273
|
+
if (!automaticPolicyAuthorized(execution.root, config))
|
|
274
|
+
throw new Error("Automatic transfer requires separate approval for the current setup and policy. Run reviewed /sync first.");
|
|
275
|
+
const validate = (current) => {
|
|
276
|
+
validateParticipants();
|
|
277
|
+
if (current && syncCheckConfigFingerprint(current) !== fingerprint)
|
|
278
|
+
throw new Error("Settings changed before automatic work completed.");
|
|
279
|
+
};
|
|
280
|
+
const refresh = async () => {
|
|
281
|
+
validate();
|
|
282
|
+
validate(await loadConfigForCheck(undefined, execution.signal));
|
|
283
|
+
};
|
|
284
|
+
return { config, validate, refresh };
|
|
285
|
+
}
|
|
286
|
+
export function participantBinding(execution) {
|
|
287
|
+
return JSON.stringify(execution.participants().toSorted((left, right) => left.id.localeCompare(right.id)));
|
|
288
|
+
}
|
|
170
289
|
export async function requireHandover(execution) {
|
|
171
290
|
if (readConsent(execution.root))
|
|
172
291
|
return;
|
|
@@ -194,9 +313,12 @@ export async function authorizeAfterExit(execution, payload) {
|
|
|
194
313
|
if (!record(payload) || typeof payload.afterExit !== "boolean" || typeof payload.fingerprint !== "string")
|
|
195
314
|
throw new Error("Invalid daemon authorization.");
|
|
196
315
|
await requireHandover(execution);
|
|
197
|
-
const
|
|
198
|
-
const
|
|
316
|
+
const peers = participantBinding(execution);
|
|
317
|
+
const { loadConfigForCheck } = await import("./engine/settings/config.js");
|
|
318
|
+
const config = await loadConfigForCheck(undefined, execution.signal);
|
|
199
319
|
execution.validate();
|
|
320
|
+
if (participantBinding(execution) !== peers)
|
|
321
|
+
throw new Error("Participants changed during daemon authorization.");
|
|
200
322
|
const facts = execution.facts();
|
|
201
323
|
const binding = JSON.stringify({ model: facts?.model, sessionDir: facts?.sessionDir, cwd: facts?.cwd });
|
|
202
324
|
const fingerprint = consentFingerprint(execution.root, config);
|
|
@@ -222,22 +344,17 @@ export async function authorizeAfterExit(execution, payload) {
|
|
|
222
344
|
: `Selected content: ${paths(config.include)}`;
|
|
223
345
|
const accepted = await execution.request("confirm", {
|
|
224
346
|
title: payload.afterExit ? "Allow continuous sync after all Pi clients exit?" : "Revoke unattended sync?",
|
|
225
|
-
message: `Setup: ${safeTerminalText(config.setupName)}\n${selection}\nModel: ${safeTerminalText(facts?.model?.provider ?? "unavailable")}/${safeTerminalText(facts?.model?.id ?? "unavailable")}\n\n${payload.afterExit ?
|
|
347
|
+
message: `Setup: ${safeTerminalText(config.setupName)}\n${selection}\nModel: ${safeTerminalText(facts?.model?.provider ?? "unavailable")}/${safeTerminalText(facts?.model?.id ?? "unavailable")}\n\n${payload.afterExit ? `The daemon may transfer selected private content and send conflict evidence to this independently available provider after Pi exits. Existing budgets, exclusions, journals, and stale-evidence checks still apply. No parent conversation or tools are sent. Changing this setup or model invalidates this permission.${config.reservedIgnoreNames !== undefined ? " This also approves the enabled automatic modes for this setup while Pi clients are attached." : ""}` : "The daemon may remain alive, but no new transfer or model request may start with zero clients."}`,
|
|
226
348
|
});
|
|
227
349
|
execution.validate();
|
|
228
350
|
if (accepted !== true)
|
|
229
|
-
return
|
|
230
|
-
const latest = await
|
|
351
|
+
return undefined;
|
|
352
|
+
const latest = await loadConfigForCheck(undefined, execution.signal);
|
|
231
353
|
execution.validate();
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
signal: execution.signal,
|
|
237
|
-
validateMutation: () => execution.validate(),
|
|
238
|
-
})?.();
|
|
239
|
-
}
|
|
240
|
-
if (consentFingerprint(execution.root, latest) !== fingerprint ||
|
|
354
|
+
await config.validateIgnorePolicy?.();
|
|
355
|
+
execution.validate();
|
|
356
|
+
if (participantBinding(execution) !== peers ||
|
|
357
|
+
consentFingerprint(execution.root, latest) !== fingerprint ||
|
|
241
358
|
JSON.stringify({
|
|
242
359
|
model: execution.facts()?.model,
|
|
243
360
|
sessionDir: execution.facts()?.sessionDir,
|
|
@@ -258,8 +375,9 @@ export async function authorizeAfterExit(execution, payload) {
|
|
|
258
375
|
sessionDir: facts?.sessionDir,
|
|
259
376
|
cwd: facts?.cwd,
|
|
260
377
|
afterExit: payload.afterExit,
|
|
378
|
+
...(payload.afterExit && config.reservedIgnoreNames !== undefined ? { automaticFingerprint: fingerprint } : {}),
|
|
261
379
|
},
|
|
262
380
|
},
|
|
263
381
|
});
|
|
264
|
-
return
|
|
382
|
+
return { config, afterExit: payload.afterExit };
|
|
265
383
|
}
|
|
@@ -9,10 +9,12 @@ import { throwIfAborted } from "../../sync/signals.js";
|
|
|
9
9
|
import { syncErrorGuidance } from "../../sync/sync-error-guidance.js";
|
|
10
10
|
import { SyncBackendConflictError, SyncBackendPublicationOutcomeUnknownError, } from "../sync-backend.js";
|
|
11
11
|
import { normalizeGitBranch, normalizeGitDirectory, normalizeGitRemote, normalizeGitRemoteIdentity, validateGitNamespace, } from "./git-config.js";
|
|
12
|
-
import { GitCommandError, readGitBlobs, runGit } from "./git-runner.js";
|
|
12
|
+
import { GitCommandError, parseGitBlobBatch, readGitBlobs, runGit } from "./git-runner.js";
|
|
13
13
|
import { GIT_MANIFEST_VERSION, MAX_GIT_MANIFEST_BYTES, MAX_GIT_TREE_OUTPUT_BYTES, parseGitTree, prepareGitSnapshot, requireGitManifest, validateGitPublicationTree, validateGitSnapshot, } from "./git-storage.js";
|
|
14
14
|
const COMMAND_TIMEOUT_MS = 30_000;
|
|
15
15
|
const POST_COMMIT_TIMEOUT_MS = 45_000;
|
|
16
|
+
const HISTORY_MANIFEST_BATCH_SIZE = 8;
|
|
17
|
+
const MANIFEST_BATCH_FRAME_BYTES = 96;
|
|
16
18
|
const gitCacheMutationQueues = new Map();
|
|
17
19
|
export class GitSyncBackend {
|
|
18
20
|
config;
|
|
@@ -182,20 +184,28 @@ export class GitSyncBackend {
|
|
|
182
184
|
}
|
|
183
185
|
async listHistory(signal) {
|
|
184
186
|
const sha = await this.fetchRemoteHead(signal);
|
|
187
|
+
throwIfAborted(signal);
|
|
185
188
|
if (!sha)
|
|
186
189
|
return [];
|
|
187
190
|
const result = await this.git(["rev-list", "--first-parent", "--reverse", "--max-count=100", sha], { signal });
|
|
188
191
|
const commits = result.stdout.toString("utf8").trim().split("\n").filter(Boolean);
|
|
189
192
|
const entries = [];
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
193
|
+
throwIfAborted(signal);
|
|
194
|
+
for (let offset = 0; offset < commits.length; offset += HISTORY_MANIFEST_BATCH_SIZE) {
|
|
195
|
+
const group = commits.slice(offset, offset + HISTORY_MANIFEST_BATCH_SIZE);
|
|
196
|
+
const manifests = await this.tryReadHistoryManifestBatch(group, signal);
|
|
197
|
+
for (const [index, commit] of group.entries()) {
|
|
198
|
+
throwIfAborted(signal);
|
|
199
|
+
const { manifest } = await this.readPublication(commit, signal, manifests?.[index]);
|
|
200
|
+
throwIfAborted(signal);
|
|
201
|
+
entries.push({
|
|
202
|
+
snapshotRef: commit,
|
|
203
|
+
snapshotId: manifest.snapshotId,
|
|
204
|
+
createdAt: manifest.createdAt,
|
|
205
|
+
machine: manifest.machine,
|
|
206
|
+
syncSessions: manifest.syncSessions,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
199
209
|
}
|
|
200
210
|
return entries;
|
|
201
211
|
}
|
|
@@ -314,27 +324,27 @@ export class GitSyncBackend {
|
|
|
314
324
|
}
|
|
315
325
|
}, signal);
|
|
316
326
|
}
|
|
317
|
-
async
|
|
318
|
-
requireCommitSha(commit);
|
|
319
|
-
const bytes = await this.showFile(commit, this.manifestPath(), signal, MAX_GIT_MANIFEST_BYTES);
|
|
320
|
-
let parsed;
|
|
327
|
+
async tryReadHistoryManifestBatch(commits, signal) {
|
|
321
328
|
try {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
329
|
+
for (const commit of commits)
|
|
330
|
+
requireCommitSha(commit);
|
|
331
|
+
const manifestPath = this.manifestPath();
|
|
332
|
+
const maxContentBytes = commits.length * MAX_GIT_MANIFEST_BYTES;
|
|
333
|
+
const result = await this.git(["cat-file", "--batch"], {
|
|
334
|
+
input: `${commits.map((commit) => `${commit}:${manifestPath}`).join("\n")}\n`,
|
|
335
|
+
maxOutputBytes: maxContentBytes + commits.length * MANIFEST_BATCH_FRAME_BYTES,
|
|
336
|
+
signal,
|
|
337
|
+
});
|
|
338
|
+
throwIfAborted(signal);
|
|
339
|
+
if (result.stderr.length > 0)
|
|
340
|
+
return undefined;
|
|
341
|
+
const blobs = parseGitBlobBatch(result.stdout, commits.length, maxContentBytes);
|
|
342
|
+
return blobs.every((blob) => blob.length <= MAX_GIT_MANIFEST_BYTES) ? blobs : undefined;
|
|
326
343
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
parsed.snapshotVersion === IGNORE_SNAPSHOT_VERSION &&
|
|
331
|
-
!isUtf8(bytes)) {
|
|
332
|
-
throw new Error("Git publication manifest is not valid UTF-8.");
|
|
344
|
+
catch {
|
|
345
|
+
throwIfAborted(signal);
|
|
346
|
+
return undefined;
|
|
333
347
|
}
|
|
334
|
-
return requireGitManifest(parsed);
|
|
335
|
-
}
|
|
336
|
-
showFile(commit, filePath, signal, maxOutputBytes) {
|
|
337
|
-
return this.git(["show", `${commit}:${filePath}`], { signal, maxOutputBytes }).then((result) => result.stdout);
|
|
338
348
|
}
|
|
339
349
|
async createCommit(snapshot, files, manifest, parent, signal) {
|
|
340
350
|
const manifestBytes = Buffer.from(`${JSON.stringify(manifest)}\n`, "utf8");
|
|
@@ -514,8 +524,12 @@ export class GitSyncBackend {
|
|
|
514
524
|
filePath(filePath) {
|
|
515
525
|
return posixJoin(this.publicationPath(), "files", filePath);
|
|
516
526
|
}
|
|
517
|
-
async readPublication(commit, signal) {
|
|
518
|
-
|
|
527
|
+
async readPublication(commit, signal, manifestBytes) {
|
|
528
|
+
requireCommitSha(commit);
|
|
529
|
+
const bytes = manifestBytes ??
|
|
530
|
+
(await this.git(["show", `${commit}:${this.manifestPath()}`], { signal, maxOutputBytes: MAX_GIT_MANIFEST_BYTES }))
|
|
531
|
+
.stdout;
|
|
532
|
+
const manifest = parseGitManifest(bytes);
|
|
519
533
|
const entries = await this.readPublicationTree(commit, signal, manifest.snapshotVersion === IGNORE_SNAPSHOT_VERSION);
|
|
520
534
|
const payloadEntries = validateGitPublicationTree(entries, manifest, this.manifestPath(), (filePath) => this.filePath(filePath));
|
|
521
535
|
return { manifest, payloadEntries };
|
|
@@ -572,6 +586,23 @@ function gitDestination(config) {
|
|
|
572
586
|
}
|
|
573
587
|
return `${host} · ${config.destination.branch}:${config.destination.directory}`;
|
|
574
588
|
}
|
|
589
|
+
function parseGitManifest(bytes) {
|
|
590
|
+
let parsed;
|
|
591
|
+
try {
|
|
592
|
+
parsed = JSON.parse(bytes.toString("utf8"));
|
|
593
|
+
}
|
|
594
|
+
catch (error) {
|
|
595
|
+
throw new Error("Git publication manifest is malformed.", { cause: error });
|
|
596
|
+
}
|
|
597
|
+
if (parsed &&
|
|
598
|
+
typeof parsed === "object" &&
|
|
599
|
+
"snapshotVersion" in parsed &&
|
|
600
|
+
parsed.snapshotVersion === IGNORE_SNAPSHOT_VERSION &&
|
|
601
|
+
!isUtf8(bytes)) {
|
|
602
|
+
throw new Error("Git publication manifest is not valid UTF-8.");
|
|
603
|
+
}
|
|
604
|
+
return requireGitManifest(parsed);
|
|
605
|
+
}
|
|
575
606
|
function remoteHead(sha, manifest, identity) {
|
|
576
607
|
return {
|
|
577
608
|
snapshotRef: sha,
|