@narumitw/pi-sync 0.57.9 → 0.57.10
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 +8 -0
- package/README.md +2 -0
- package/dist/chunks/{agent-candidate-GNEYR225.ts → agent-candidate-EYB35AGL.ts} +12 -9
- package/dist/chunks/{agent-plan-3L7CRFDM.ts → agent-plan-KO43GTOR.ts} +22 -18
- package/dist/chunks/{agent-plan-3L7CRFDM.ts.map → agent-plan-KO43GTOR.ts.map} +1 -1
- package/dist/chunks/{agent-refusal-retry-RPTMUQXK.ts → agent-refusal-retry-C2HQROTP.ts} +11 -8
- package/dist/chunks/{agent-refusal-retry-RPTMUQXK.ts.map → agent-refusal-retry-C2HQROTP.ts.map} +1 -1
- package/dist/chunks/{agent-store-55CZOCPX.ts → agent-store-UT52DS7B.ts} +12 -11
- package/dist/chunks/{agent-store-55CZOCPX.ts.map → agent-store-UT52DS7B.ts.map} +1 -1
- package/dist/chunks/agent-sync-VM3TXWA3.ts +22 -0
- package/dist/chunks/{chunk-6FVVRTL5.ts → chunk-2VSN3MFX.ts} +71 -63
- package/dist/chunks/{chunk-6FVVRTL5.ts.map → chunk-2VSN3MFX.ts.map} +1 -1
- package/dist/chunks/{chunk-PG7NMFP2.ts → chunk-4RLATUP4.ts} +7 -7
- package/dist/chunks/chunk-5SFMBY5P.ts +26 -0
- package/dist/chunks/chunk-5SFMBY5P.ts.map +7 -0
- package/dist/chunks/chunk-5WJQ6XOW.ts +27 -0
- package/dist/chunks/chunk-5WJQ6XOW.ts.map +7 -0
- package/dist/chunks/{chunk-GNH73BJ5.ts → chunk-66GAUVDL.ts} +7 -7
- package/dist/chunks/{chunk-UPNVIUBN.ts → chunk-73MDIVYJ.ts} +3 -3
- package/dist/chunks/{chunk-CRKTAPSL.ts → chunk-AAPAHANE.ts} +24 -29
- package/dist/chunks/chunk-AAPAHANE.ts.map +7 -0
- package/dist/chunks/{chunk-S7QS4AWK.ts → chunk-AO6EDUA6.ts} +5 -5
- package/dist/chunks/chunk-AR2DGDUI.ts +55 -0
- package/dist/chunks/chunk-AR2DGDUI.ts.map +7 -0
- package/dist/chunks/{chunk-JCH3VXIO.ts → chunk-BJXSCGQK.ts} +9 -9
- package/dist/chunks/{chunk-IWZH5KYS.ts → chunk-CDQGSZL3.ts} +7 -7
- package/dist/chunks/chunk-DFJGTVPX.ts +319 -0
- package/dist/chunks/chunk-DFJGTVPX.ts.map +7 -0
- package/dist/chunks/chunk-DO55XUNU.ts +104 -0
- package/dist/chunks/chunk-DO55XUNU.ts.map +7 -0
- package/dist/chunks/{chunk-ED3TYIVW.ts → chunk-DOJRPBQU.ts} +5 -5
- package/dist/chunks/{chunk-5QAE3G3K.ts → chunk-IMMMZUFC.ts} +6 -6
- package/dist/chunks/{chunk-B4QZBDBT.ts → chunk-JXWTEJS5.ts} +3 -3
- package/dist/chunks/{chunk-BDB4IDM3.ts → chunk-JY2RVOUL.ts} +8 -6
- package/dist/chunks/{chunk-BDB4IDM3.ts.map → chunk-JY2RVOUL.ts.map} +1 -1
- package/dist/chunks/{chunk-P7DD5PWZ.ts → chunk-M5IV3KL2.ts} +3 -3
- package/dist/chunks/{chunk-AAEEHR7H.ts → chunk-MDUORMCK.ts} +2 -2
- package/dist/chunks/{chunk-UBV24CG4.ts → chunk-MRIPZGPR.ts} +3 -3
- package/dist/chunks/{chunk-MKKF4IMY.ts → chunk-ODF2M4RF.ts} +5 -5
- package/dist/chunks/chunk-PHANBTVM.ts +348 -0
- package/dist/chunks/chunk-PHANBTVM.ts.map +7 -0
- package/dist/chunks/{chunk-GP5DU62N.ts → chunk-PWA3YN5Z.ts} +2 -2
- package/dist/chunks/{chunk-YK52VDXG.ts → chunk-QWV3XKNJ.ts} +10 -8
- package/dist/chunks/{chunk-YK52VDXG.ts.map → chunk-QWV3XKNJ.ts.map} +1 -1
- package/dist/chunks/{chunk-ORGBI36T.ts → chunk-RAMHGOX2.ts} +4 -4
- package/dist/chunks/{chunk-QO333NM4.ts → chunk-RX3WGWVL.ts} +5 -5
- package/dist/chunks/chunk-RX3WGWVL.ts.map +7 -0
- package/dist/chunks/{chunk-PQW6GS4J.ts → chunk-STVQQ5KG.ts} +12 -10
- package/dist/chunks/{chunk-PQW6GS4J.ts.map → chunk-STVQQ5KG.ts.map} +1 -1
- package/dist/chunks/{chunk-76NB4R7U.ts → chunk-TO2GMX3K.ts} +2 -2
- package/dist/chunks/{chunk-GSNPASKB.ts → chunk-U77DWNRH.ts} +6 -6
- package/dist/chunks/{chunk-U3XRI2HF.ts → chunk-UCD7TQDT.ts} +11 -11
- package/dist/chunks/{chunk-A6HU4ERM.ts → chunk-UGSSZWQ6.ts} +6 -23
- package/dist/chunks/chunk-UGSSZWQ6.ts.map +7 -0
- package/dist/chunks/chunk-X7R6DCVF.ts +28 -0
- package/dist/chunks/chunk-X7R6DCVF.ts.map +7 -0
- package/dist/chunks/{chunk-HUZ5CR4W.ts → chunk-YZ5BQNRZ.ts} +2 -51
- package/dist/chunks/{chunk-HUZ5CR4W.ts.map → chunk-YZ5BQNRZ.ts.map} +4 -4
- package/dist/chunks/{chunk-UOHR7LRO.ts → chunk-Z5O2TLNF.ts} +9 -21
- package/dist/chunks/chunk-Z5O2TLNF.ts.map +7 -0
- package/dist/chunks/command-handler-FO6F2APH.ts +543 -0
- package/dist/chunks/command-handler-FO6F2APH.ts.map +7 -0
- package/dist/chunks/{config-KGIYTTXQ.ts → config-B37W7FXW.ts} +5 -6
- package/dist/chunks/{conflict-artifacts-FXFIIBCB.ts → conflict-artifacts-6XGSSU5S.ts} +13 -9
- package/dist/chunks/{conflict-review-3X37QEIT.ts → conflict-review-BQSHSJB3.ts} +31 -25
- package/dist/chunks/{conflict-review-3X37QEIT.ts.map → conflict-review-BQSHSJB3.ts.map} +1 -1
- package/dist/chunks/{continuous-record-SQJ47CXN.ts → continuous-record-4DQ2EAZS.ts} +8 -7
- package/dist/chunks/{continuous-sync-Q6QUD6TY.ts → continuous-sync-ZT3UEQLK.ts} +33 -28
- package/dist/chunks/{continuous-sync-Q6QUD6TY.ts.map → continuous-sync-ZT3UEQLK.ts.map} +1 -1
- package/dist/chunks/{file-selection-3JJYOVNR.ts → file-selection-FBLKM25V.ts} +12 -10
- package/dist/chunks/{file-selection-3JJYOVNR.ts.map → file-selection-FBLKM25V.ts.map} +1 -1
- package/dist/chunks/{git-backend-NYKSG5X6.ts → git-backend-7PCWECRN.ts} +16 -12
- package/dist/chunks/{git-backend-NYKSG5X6.ts.map → git-backend-7PCWECRN.ts.map} +1 -1
- package/dist/chunks/{local-fields-6DGYOOIK.ts → local-fields-B6JWLPAE.ts} +10 -5
- package/dist/chunks/manager-result-dispatcher-NODX3KKH.ts +28 -0
- package/dist/chunks/{manager-ui-ZH6DEC2G.ts → manager-ui-DGRTG76I.ts} +46 -40
- package/dist/chunks/{manager-ui-ZH6DEC2G.ts.map → manager-ui-DGRTG76I.ts.map} +1 -1
- package/dist/chunks/{merge-baseline-store-RFCAH7KL.ts → merge-baseline-store-HL3VLMAM.ts} +6 -5
- package/dist/chunks/{remote-selection-ui-YFPGYGNE.ts → remote-selection-ui-OHMIQ32X.ts} +14 -10
- package/dist/chunks/{s3-backend-F7PR5FB3.ts → s3-backend-CJXBEWWU.ts} +21 -17
- package/dist/chunks/{s3-backend-F7PR5FB3.ts.map → s3-backend-CJXBEWWU.ts.map} +1 -1
- package/dist/chunks/{setup-switch-E7PHKI6J.ts → setup-switch-66GWMBNH.ts} +6 -7
- package/dist/chunks/{setup-wizard-OVHZYXNW.ts → setup-wizard-OHZXJVQZ.ts} +8 -9
- package/dist/chunks/{setup-wizard-OVHZYXNW.ts.map → setup-wizard-OHZXJVQZ.ts.map} +1 -1
- package/dist/chunks/{snapshot-THS5EY2L.ts → snapshot-VRHNAUUH.ts} +11 -6
- package/dist/chunks/snapshot-transaction-EUGA4VX6.ts +24 -0
- package/dist/chunks/sync-inspection-4WFQEJOE.ts +25 -0
- package/dist/chunks/sync-inspection-4WFQEJOE.ts.map +7 -0
- package/dist/chunks/{sync-operations-Y72GNIQ2.ts → sync-operations-X4AOXMBT.ts} +66 -57
- package/dist/chunks/{sync-operations-Y72GNIQ2.ts.map → sync-operations-X4AOXMBT.ts.map} +1 -1
- package/dist/chunks/{sync-state-CFL4RRRB.ts → sync-state-SWLSMK4G.ts} +9 -5
- package/dist/chunks/sync-state-SWLSMK4G.ts.map +7 -0
- package/dist/chunks/{webdav-backend-TGFUH3SF.ts → webdav-backend-2Q5ZEBST.ts} +16 -12
- package/dist/chunks/{webdav-backend-TGFUH3SF.ts.map → webdav-backend-2Q5ZEBST.ts.map} +1 -1
- package/dist/index.ts +54 -537
- package/dist/index.ts.map +3 -3
- package/package.json +2 -2
- package/src/settings/config.ts +1 -1
- package/src/settings/settings-validation.ts +1 -1
- package/src/snapshot/snapshot-transaction-directory.ts +16 -0
- package/src/snapshot/snapshot-transaction.ts +1 -12
- package/src/sync/automatic-sync.ts +12 -6
- package/src/sync/local-field-policy.ts +29 -0
- package/src/sync/local-fields.ts +3 -29
- package/src/sync/mutation-owner.ts +22 -0
- package/src/sync/startup-check.ts +3 -2
- package/src/sync/sync-loaders.ts +4 -0
- package/src/sync/sync-local.ts +2 -19
- package/src/sync-extension.ts +7 -2
- package/dist/chunks/chunk-A6HU4ERM.ts.map +0 -7
- package/dist/chunks/chunk-CRKTAPSL.ts.map +0 -7
- package/dist/chunks/chunk-QO333NM4.ts.map +0 -7
- package/dist/chunks/chunk-QOFMXPM5.ts +0 -735
- package/dist/chunks/chunk-QOFMXPM5.ts.map +0 -7
- package/dist/chunks/chunk-UOHR7LRO.ts.map +0 -7
- package/dist/chunks/manager-result-dispatcher-HOCM2GDA.ts +0 -24
- package/dist/chunks/sync-inspection-J25EEKZK.ts +0 -21
- /package/dist/chunks/{agent-candidate-GNEYR225.ts.map → agent-candidate-EYB35AGL.ts.map} +0 -0
- /package/dist/chunks/{config-KGIYTTXQ.ts.map → agent-sync-VM3TXWA3.ts.map} +0 -0
- /package/dist/chunks/{chunk-PG7NMFP2.ts.map → chunk-4RLATUP4.ts.map} +0 -0
- /package/dist/chunks/{chunk-GNH73BJ5.ts.map → chunk-66GAUVDL.ts.map} +0 -0
- /package/dist/chunks/{chunk-UPNVIUBN.ts.map → chunk-73MDIVYJ.ts.map} +0 -0
- /package/dist/chunks/{chunk-S7QS4AWK.ts.map → chunk-AO6EDUA6.ts.map} +0 -0
- /package/dist/chunks/{chunk-JCH3VXIO.ts.map → chunk-BJXSCGQK.ts.map} +0 -0
- /package/dist/chunks/{chunk-IWZH5KYS.ts.map → chunk-CDQGSZL3.ts.map} +0 -0
- /package/dist/chunks/{chunk-ED3TYIVW.ts.map → chunk-DOJRPBQU.ts.map} +0 -0
- /package/dist/chunks/{chunk-5QAE3G3K.ts.map → chunk-IMMMZUFC.ts.map} +0 -0
- /package/dist/chunks/{chunk-B4QZBDBT.ts.map → chunk-JXWTEJS5.ts.map} +0 -0
- /package/dist/chunks/{chunk-P7DD5PWZ.ts.map → chunk-M5IV3KL2.ts.map} +0 -0
- /package/dist/chunks/{chunk-AAEEHR7H.ts.map → chunk-MDUORMCK.ts.map} +0 -0
- /package/dist/chunks/{chunk-UBV24CG4.ts.map → chunk-MRIPZGPR.ts.map} +0 -0
- /package/dist/chunks/{chunk-MKKF4IMY.ts.map → chunk-ODF2M4RF.ts.map} +0 -0
- /package/dist/chunks/{chunk-GP5DU62N.ts.map → chunk-PWA3YN5Z.ts.map} +0 -0
- /package/dist/chunks/{chunk-ORGBI36T.ts.map → chunk-RAMHGOX2.ts.map} +0 -0
- /package/dist/chunks/{chunk-76NB4R7U.ts.map → chunk-TO2GMX3K.ts.map} +0 -0
- /package/dist/chunks/{chunk-GSNPASKB.ts.map → chunk-U77DWNRH.ts.map} +0 -0
- /package/dist/chunks/{chunk-U3XRI2HF.ts.map → chunk-UCD7TQDT.ts.map} +0 -0
- /package/dist/chunks/{conflict-artifacts-FXFIIBCB.ts.map → config-B37W7FXW.ts.map} +0 -0
- /package/dist/chunks/{continuous-record-SQJ47CXN.ts.map → conflict-artifacts-6XGSSU5S.ts.map} +0 -0
- /package/dist/chunks/{local-fields-6DGYOOIK.ts.map → continuous-record-4DQ2EAZS.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-HOCM2GDA.ts.map → local-fields-B6JWLPAE.ts.map} +0 -0
- /package/dist/chunks/{merge-baseline-store-RFCAH7KL.ts.map → manager-result-dispatcher-NODX3KKH.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-YFPGYGNE.ts.map → merge-baseline-store-HL3VLMAM.ts.map} +0 -0
- /package/dist/chunks/{setup-switch-E7PHKI6J.ts.map → remote-selection-ui-OHMIQ32X.ts.map} +0 -0
- /package/dist/chunks/{snapshot-THS5EY2L.ts.map → setup-switch-66GWMBNH.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-J25EEKZK.ts.map → snapshot-VRHNAUUH.ts.map} +0 -0
- /package/dist/chunks/{sync-state-CFL4RRRB.ts.map → snapshot-transaction-EUGA4VX6.ts.map} +0 -0
|
@@ -2,22 +2,23 @@
|
|
|
2
2
|
// @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
|
|
3
3
|
import {
|
|
4
4
|
encodeSnapshot
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-MRIPZGPR.ts";
|
|
6
6
|
import {
|
|
7
7
|
throwIfAborted
|
|
8
8
|
} from "./chunk-PWMWOJP4.ts";
|
|
9
9
|
import {
|
|
10
|
-
|
|
10
|
+
stateDir
|
|
11
|
+
} from "./chunk-SWRVXVFD.ts";
|
|
12
|
+
import {
|
|
11
13
|
createSnapshot,
|
|
12
|
-
sessionDirFromContext,
|
|
13
14
|
sessionSnapshotPathFromAbsolute
|
|
14
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-PHANBTVM.ts";
|
|
15
16
|
import {
|
|
16
|
-
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
sessionDirFromContext
|
|
18
|
+
} from "./chunk-DO55XUNU.ts";
|
|
18
19
|
import {
|
|
19
20
|
syncDirectory
|
|
20
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-AR2DGDUI.ts";
|
|
21
22
|
|
|
22
23
|
// src/sync/sync-local.ts
|
|
23
24
|
import fs from "node:fs/promises";
|
|
@@ -29,18 +30,6 @@ function protectedSessionPaths(ctx, sessionRoot = sessionDirFromContext(ctx)) {
|
|
|
29
30
|
const snapshotPath = sessionFile ? sessionSnapshotPathFromAbsolute(sessionFile, sessionRoot) : void 0;
|
|
30
31
|
return snapshotPath ? /* @__PURE__ */ new Set([snapshotPath]) : /* @__PURE__ */ new Set();
|
|
31
32
|
}
|
|
32
|
-
function captureMutationOwner(ctx, signal) {
|
|
33
|
-
const manager = ctx.sessionManager;
|
|
34
|
-
const file = manager.getSessionFile?.();
|
|
35
|
-
const id = manager.getSessionId?.();
|
|
36
|
-
const cwd = manager.getCwd?.();
|
|
37
|
-
const root = agentDir();
|
|
38
|
-
return () => {
|
|
39
|
-
throwIfAborted(signal);
|
|
40
|
-
if (ctx.sessionManager !== manager || manager.getSessionFile?.() !== file || manager.getSessionId?.() !== id || manager.getCwd?.() !== cwd || agentDir() !== root)
|
|
41
|
-
throw new Error("Session changed during file mutation; evidence retained for review.");
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
33
|
async function backupLocal(profile, options = {}, signal) {
|
|
45
34
|
throwIfAborted(signal);
|
|
46
35
|
const snapshot = await createSnapshot(profile, { ...options, signal });
|
|
@@ -64,7 +53,6 @@ async function backupLocal(profile, options = {}, signal) {
|
|
|
64
53
|
|
|
65
54
|
export {
|
|
66
55
|
protectedSessionPaths,
|
|
67
|
-
captureMutationOwner,
|
|
68
56
|
backupLocal
|
|
69
57
|
};
|
|
70
|
-
//# sourceMappingURL=chunk-
|
|
58
|
+
//# sourceMappingURL=chunk-Z5O2TLNF.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/sync/sync-local.ts"],
|
|
4
|
+
"sourcesContent": ["import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { ExtensionCommandContext, ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { sessionDirFromContext } from \"../snapshot/session-paths.js\";\nimport { createSnapshot, sessionSnapshotPathFromAbsolute } from \"../snapshot/snapshot.js\";\nimport { encodeSnapshot } from \"../snapshot/snapshot-codec.js\";\nimport type { SnapshotOptions } from \"../snapshot/snapshot-types.js\";\nimport { syncDirectory } from \"../state/json-file.js\";\nimport { stateDir } from \"../state/state-directory.js\";\nimport { throwIfAborted } from \"./signals.js\";\n\nexport function protectedSessionPaths(\n ctx: ExtensionCommandContext | ExtensionContext,\n sessionRoot = sessionDirFromContext(ctx),\n) {\n const getSessionFile = ctx.sessionManager.getSessionFile;\n if (typeof getSessionFile !== \"function\") return new Set<string>();\n const sessionFile = getSessionFile.call(ctx.sessionManager) as string | undefined;\n const snapshotPath = sessionFile ? sessionSnapshotPathFromAbsolute(sessionFile, sessionRoot) : undefined;\n return snapshotPath ? new Set([snapshotPath]) : new Set<string>();\n}\n\nexport { captureMutationOwner } from \"./mutation-owner.js\";\n\nexport async function backupLocal(profile: string, options: SnapshotOptions = {}, signal?: AbortSignal) {\n throwIfAborted(signal);\n const snapshot = await createSnapshot(profile, { ...options, signal });\n throwIfAborted(signal);\n const backupDirectory = path.join(stateDir(), \"backups\");\n await fs.mkdir(backupDirectory, { recursive: true, mode: 0o700 });\n throwIfAborted(signal);\n const backupPath = path.join(backupDirectory, `${snapshot.id}.json.gz`);\n const encoded = await encodeSnapshot(snapshot);\n throwIfAborted(signal);\n const handle = await fs.open(backupPath, \"wx\", 0o600);\n try {\n await handle.writeFile(encoded);\n await handle.sync();\n } finally {\n await handle.close();\n }\n await syncDirectory(backupDirectory);\n return backupPath;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AAUV,SAAS,sBACd,KACA,cAAc,sBAAsB,GAAG,GACvC;AACA,QAAM,iBAAiB,IAAI,eAAe;AAC1C,MAAI,OAAO,mBAAmB,WAAY,QAAO,oBAAI,IAAY;AACjE,QAAM,cAAc,eAAe,KAAK,IAAI,cAAc;AAC1D,QAAM,eAAe,cAAc,gCAAgC,aAAa,WAAW,IAAI;AAC/F,SAAO,eAAe,oBAAI,IAAI,CAAC,YAAY,CAAC,IAAI,oBAAI,IAAY;AAClE;AAIA,eAAsB,YAAY,SAAiB,UAA2B,CAAC,GAAG,QAAsB;AACtG,iBAAe,MAAM;AACrB,QAAM,WAAW,MAAM,eAAe,SAAS,EAAE,GAAG,SAAS,OAAO,CAAC;AACrE,iBAAe,MAAM;AACrB,QAAM,kBAAkB,KAAK,KAAK,SAAS,GAAG,SAAS;AACvD,QAAM,GAAG,MAAM,iBAAiB,EAAE,WAAW,MAAM,MAAM,IAAM,CAAC;AAChE,iBAAe,MAAM;AACrB,QAAM,aAAa,KAAK,KAAK,iBAAiB,GAAG,SAAS,EAAE,UAAU;AACtE,QAAM,UAAU,MAAM,eAAe,QAAQ;AAC7C,iBAAe,MAAM;AACrB,QAAM,SAAS,MAAM,GAAG,KAAK,YAAY,MAAM,GAAK;AACpD,MAAI;AACF,UAAM,OAAO,UAAU,OAAO;AAC9B,UAAM,OAAO,KAAK;AAAA,EACpB,UAAE;AACA,UAAM,OAAO,MAAM;AAAA,EACrB;AACA,QAAM,cAAc,eAAe;AACnC,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
|
+
// @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
|
|
3
|
+
import {
|
|
4
|
+
automaticSyncSummary
|
|
5
|
+
} from "./chunk-ECYCNZOE.ts";
|
|
6
|
+
import {
|
|
7
|
+
withAgentSyncLock
|
|
8
|
+
} from "./chunk-ODF2M4RF.ts";
|
|
9
|
+
import "./chunk-3ST7RSYN.ts";
|
|
10
|
+
import {
|
|
11
|
+
syncErrorGuidance
|
|
12
|
+
} from "./chunk-G4RUXRWZ.ts";
|
|
13
|
+
import {
|
|
14
|
+
observationMatchesConfig,
|
|
15
|
+
syncAttentionMatchesConfig
|
|
16
|
+
} from "./chunk-U77DWNRH.ts";
|
|
17
|
+
import {
|
|
18
|
+
parseOptions,
|
|
19
|
+
resolveSyncCommand,
|
|
20
|
+
splitArgs,
|
|
21
|
+
startupTransferSummary,
|
|
22
|
+
usage,
|
|
23
|
+
validateCommandOptions
|
|
24
|
+
} from "./chunk-NLWS55B6.ts";
|
|
25
|
+
import {
|
|
26
|
+
safeTerminalText
|
|
27
|
+
} from "./chunk-AMJRUXFT.ts";
|
|
28
|
+
import {
|
|
29
|
+
setSyncStatus
|
|
30
|
+
} from "./chunk-K3RIEL6J.ts";
|
|
31
|
+
import {
|
|
32
|
+
SetupPullRequiresUiError,
|
|
33
|
+
errorMessage,
|
|
34
|
+
isSyncDecisionRequiredError
|
|
35
|
+
} from "./chunk-7D5SF7P3.ts";
|
|
36
|
+
import {
|
|
37
|
+
activeLocalConfigPath,
|
|
38
|
+
createLocalConfigDocument,
|
|
39
|
+
loadConfig,
|
|
40
|
+
localConfigPath,
|
|
41
|
+
localConfigTemplate,
|
|
42
|
+
readLocalConfigObject,
|
|
43
|
+
sessionTokenWarnings,
|
|
44
|
+
syncSessionsWarnings
|
|
45
|
+
} from "./chunk-RX3WGWVL.ts";
|
|
46
|
+
import "./chunk-X7R6DCVF.ts";
|
|
47
|
+
import {
|
|
48
|
+
unlock,
|
|
49
|
+
withLock
|
|
50
|
+
} from "./chunk-MDUORMCK.ts";
|
|
51
|
+
import {
|
|
52
|
+
combineSignals,
|
|
53
|
+
throwIfAborted
|
|
54
|
+
} from "./chunk-PWMWOJP4.ts";
|
|
55
|
+
import {
|
|
56
|
+
readStateForConfig,
|
|
57
|
+
syncStateFingerprint
|
|
58
|
+
} from "./chunk-73MDIVYJ.ts";
|
|
59
|
+
import {
|
|
60
|
+
migrateLegacyStateDirectory,
|
|
61
|
+
stateDirectoryMigrationNotice
|
|
62
|
+
} from "./chunk-SWRVXVFD.ts";
|
|
63
|
+
import "./chunk-2JZFHNLM.ts";
|
|
64
|
+
import "./chunk-T2SJD3N7.ts";
|
|
65
|
+
import {
|
|
66
|
+
RemoteSelectionMismatchError,
|
|
67
|
+
formatRemoteSelectionMismatch
|
|
68
|
+
} from "./chunk-DFJGTVPX.ts";
|
|
69
|
+
import "./chunk-AR2DGDUI.ts";
|
|
70
|
+
import "./chunk-YZ5BQNRZ.ts";
|
|
71
|
+
import "./chunk-DT7M4VQS.ts";
|
|
72
|
+
import "./chunk-YDVQYUHE.ts";
|
|
73
|
+
import "./chunk-PRUEIIK7.ts";
|
|
74
|
+
|
|
75
|
+
// src/ui/operation-dialogs.ts
|
|
76
|
+
function trackOperationDialogs(ctx, onDialog) {
|
|
77
|
+
if (!onDialog) return ctx;
|
|
78
|
+
const runDialog = async (task) => {
|
|
79
|
+
onDialog(true);
|
|
80
|
+
try {
|
|
81
|
+
return await task();
|
|
82
|
+
} finally {
|
|
83
|
+
onDialog(false);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const ui = {
|
|
87
|
+
...ctx.ui,
|
|
88
|
+
select: (...args) => runDialog(() => ctx.ui.select(...args)),
|
|
89
|
+
confirm: (...args) => runDialog(() => ctx.ui.confirm(...args))
|
|
90
|
+
};
|
|
91
|
+
return new Proxy(ctx, {
|
|
92
|
+
get(target, key, receiver) {
|
|
93
|
+
return key === "ui" ? ui : Reflect.get(target, key, receiver);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// src/commands/command-execution.ts
|
|
99
|
+
async function executeRecoveryCommand(rawArgs, ctx, signal, loaders, onCommit, setup) {
|
|
100
|
+
try {
|
|
101
|
+
const [subcommand, ...rest] = splitArgs(rawArgs);
|
|
102
|
+
if (subcommand !== "sync" && subcommand !== "pull" && subcommand !== "push") {
|
|
103
|
+
throw new Error(`Unsupported sync recovery route: ${subcommand ?? "missing"}`);
|
|
104
|
+
}
|
|
105
|
+
const options = parseOptions(rest);
|
|
106
|
+
if (setup !== void 0) options.setup = setup;
|
|
107
|
+
if (signal) options.signal = signal;
|
|
108
|
+
if (onCommit) options.onCommit = onCommit;
|
|
109
|
+
options.reload = false;
|
|
110
|
+
options.auto = false;
|
|
111
|
+
validateCommandOptions(subcommand, options);
|
|
112
|
+
const operations = await loaders.operations();
|
|
113
|
+
throwIfAborted(options.signal);
|
|
114
|
+
if (subcommand === "push") {
|
|
115
|
+
const outcome = await withLock("push", () => operations.push(ctx, options));
|
|
116
|
+
return { kind: "completed", ...outcome ? { outcome } : {} };
|
|
117
|
+
}
|
|
118
|
+
if (subcommand === "pull") {
|
|
119
|
+
const outcome = await withLock("pull", () => operations.pull(ctx, options));
|
|
120
|
+
return { kind: "completed", ...outcome ? { outcome } : {} };
|
|
121
|
+
}
|
|
122
|
+
await withAgentSyncLock(ctx, options, (current) => operations.syncBoth(ctx, current));
|
|
123
|
+
return { kind: "completed" };
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (signal?.aborted) return { kind: "failed" };
|
|
126
|
+
setSyncStatus(ctx, void 0);
|
|
127
|
+
if (error instanceof RemoteSelectionMismatchError) {
|
|
128
|
+
return { kind: "remote-selection-required", decision: error.decision };
|
|
129
|
+
}
|
|
130
|
+
if (isSyncDecisionRequiredError(error)) {
|
|
131
|
+
return { kind: "decision-required", decision: error.decision };
|
|
132
|
+
}
|
|
133
|
+
ctx.ui.notify(syncErrorGuidance(error), "error");
|
|
134
|
+
return { kind: "failed" };
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async function executeCommand(rawArgs, ctx, signal, loaders, onCommit, setup, onDialog, retryRefusal = false) {
|
|
138
|
+
ctx = trackOperationDialogs(ctx, onDialog);
|
|
139
|
+
try {
|
|
140
|
+
const command = await resolveSyncCommand(rawArgs, ctx);
|
|
141
|
+
if (signal?.aborted || !command) return { kind: "completed" };
|
|
142
|
+
const { subcommand, rest } = command;
|
|
143
|
+
const options = parseOptions(rest);
|
|
144
|
+
if (setup !== void 0) options.setup = setup;
|
|
145
|
+
if (signal) options.signal = signal;
|
|
146
|
+
if (onCommit) options.onCommit = onCommit;
|
|
147
|
+
validateCommandOptions(subcommand, options);
|
|
148
|
+
if (retryRefusal) {
|
|
149
|
+
if (subcommand !== "sync") throw new Error("A refused-model retry is available only for merged sync.");
|
|
150
|
+
options.agentRetryRefusal = true;
|
|
151
|
+
}
|
|
152
|
+
switch (subcommand) {
|
|
153
|
+
case "help":
|
|
154
|
+
ctx.ui.notify(usage(), "info");
|
|
155
|
+
return { kind: "completed" };
|
|
156
|
+
case "use": {
|
|
157
|
+
const { useSyncSetup } = await loaders.setupSwitch();
|
|
158
|
+
throwIfAborted(options.signal);
|
|
159
|
+
await useSyncSetup(
|
|
160
|
+
ctx,
|
|
161
|
+
options.args[0] ?? "",
|
|
162
|
+
async (selectedSetup) => {
|
|
163
|
+
const operations = await loaders.operations();
|
|
164
|
+
throwIfAborted(options.signal);
|
|
165
|
+
return withLock("pull", () => operations.pull(ctx, { ...options, setup: selectedSetup }));
|
|
166
|
+
},
|
|
167
|
+
void 0,
|
|
168
|
+
options.signal
|
|
169
|
+
);
|
|
170
|
+
return { kind: "completed" };
|
|
171
|
+
}
|
|
172
|
+
case "init":
|
|
173
|
+
await initConfig(ctx, signal);
|
|
174
|
+
return { kind: "completed" };
|
|
175
|
+
case "config":
|
|
176
|
+
await showConfig(ctx, options);
|
|
177
|
+
return { kind: "completed" };
|
|
178
|
+
case "files": {
|
|
179
|
+
const { showFileSelection } = await import("./file-selection-FBLKM25V.ts");
|
|
180
|
+
throwIfAborted(options.signal);
|
|
181
|
+
await showFileSelection(ctx, options.setup, options.signal);
|
|
182
|
+
return { kind: "completed" };
|
|
183
|
+
}
|
|
184
|
+
case "status": {
|
|
185
|
+
const operations = await loaders.operations();
|
|
186
|
+
throwIfAborted(options.signal);
|
|
187
|
+
await operations.status(ctx, options);
|
|
188
|
+
return { kind: "completed" };
|
|
189
|
+
}
|
|
190
|
+
case "diff": {
|
|
191
|
+
const operations = await loaders.operations();
|
|
192
|
+
throwIfAborted(options.signal);
|
|
193
|
+
await operations.diff(ctx, options);
|
|
194
|
+
return { kind: "completed" };
|
|
195
|
+
}
|
|
196
|
+
case "conflicts": {
|
|
197
|
+
const { showConflicts } = await import("./conflict-review-BQSHSJB3.ts");
|
|
198
|
+
throwIfAborted(options.signal);
|
|
199
|
+
await withLock("sync", () => showConflicts(ctx, options));
|
|
200
|
+
return { kind: "completed" };
|
|
201
|
+
}
|
|
202
|
+
case "doctor": {
|
|
203
|
+
const operations = await loaders.operations();
|
|
204
|
+
throwIfAborted(options.signal);
|
|
205
|
+
await operations.doctor(ctx, options);
|
|
206
|
+
return { kind: "completed" };
|
|
207
|
+
}
|
|
208
|
+
case "push": {
|
|
209
|
+
const operations = await loaders.operations();
|
|
210
|
+
throwIfAborted(options.signal);
|
|
211
|
+
const outcome = await withLock("push", () => operations.push(ctx, options));
|
|
212
|
+
return { kind: "completed", ...outcome ? { outcome } : {} };
|
|
213
|
+
}
|
|
214
|
+
case "pull": {
|
|
215
|
+
const operations = await loaders.operations();
|
|
216
|
+
throwIfAborted(options.signal);
|
|
217
|
+
const outcome = await withLock("pull", () => operations.pull(ctx, options));
|
|
218
|
+
return { kind: "completed", ...outcome ? { outcome } : {} };
|
|
219
|
+
}
|
|
220
|
+
case "sync": {
|
|
221
|
+
const operations = await loaders.operations();
|
|
222
|
+
throwIfAborted(options.signal);
|
|
223
|
+
const outcome = await withAgentSyncLock(ctx, options, (current) => operations.syncBoth(ctx, current));
|
|
224
|
+
return { kind: "completed", ...retryRefusal && outcome ? { outcome } : {} };
|
|
225
|
+
}
|
|
226
|
+
case "history": {
|
|
227
|
+
const operations = await loaders.operations();
|
|
228
|
+
throwIfAborted(options.signal);
|
|
229
|
+
await operations.history(ctx, options);
|
|
230
|
+
return { kind: "completed" };
|
|
231
|
+
}
|
|
232
|
+
case "rollback": {
|
|
233
|
+
const operations = await loaders.operations();
|
|
234
|
+
throwIfAborted(options.signal);
|
|
235
|
+
await withLock("rollback", () => operations.rollback(ctx, options));
|
|
236
|
+
return { kind: "completed" };
|
|
237
|
+
}
|
|
238
|
+
case "migrate-state":
|
|
239
|
+
await migrateStateDirectory(ctx, options);
|
|
240
|
+
return { kind: "completed" };
|
|
241
|
+
case "unlock":
|
|
242
|
+
await unlock(ctx, options);
|
|
243
|
+
return { kind: "completed" };
|
|
244
|
+
default:
|
|
245
|
+
ctx.ui.notify(`Unknown /sync command: ${subcommand}
|
|
246
|
+
|
|
247
|
+
${usage()}`, "warning");
|
|
248
|
+
return { kind: "failed" };
|
|
249
|
+
}
|
|
250
|
+
} catch (error) {
|
|
251
|
+
if (signal?.aborted) return { kind: "failed" };
|
|
252
|
+
setSyncStatus(ctx, void 0);
|
|
253
|
+
if (error instanceof SetupPullRequiresUiError) throw error;
|
|
254
|
+
if (error instanceof RemoteSelectionMismatchError) {
|
|
255
|
+
return { kind: "remote-selection-required", decision: error.decision };
|
|
256
|
+
}
|
|
257
|
+
if (isSyncDecisionRequiredError(error)) {
|
|
258
|
+
return { kind: "decision-required", decision: error.decision };
|
|
259
|
+
}
|
|
260
|
+
ctx.ui.notify(syncErrorGuidance(error), "error");
|
|
261
|
+
return { kind: "failed" };
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
async function migrateStateDirectory(ctx, options) {
|
|
265
|
+
const notice = stateDirectoryMigrationNotice();
|
|
266
|
+
if (!notice) {
|
|
267
|
+
ctx.ui.notify("pi-sync already uses the canonical pi-sync/ state directory.", "info");
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (!options.yes && !await ctx.ui.confirm(
|
|
271
|
+
"Migrate pi-sync state directory",
|
|
272
|
+
"Confirm that every other Pi process is closed. pi-sync will atomically rename .pisync/ to pi-sync/ without merging or deleting either root.",
|
|
273
|
+
{ signal: options.signal }
|
|
274
|
+
)) {
|
|
275
|
+
ctx.ui.notify("pi-sync state migration cancelled.", "info");
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
throwIfAborted(options.signal);
|
|
279
|
+
const result = await migrateLegacyStateDirectory();
|
|
280
|
+
throwIfAborted(options.signal);
|
|
281
|
+
if (result.status === "ready") {
|
|
282
|
+
ctx.ui.notify("pi-sync already uses the canonical pi-sync/ state directory.", "info");
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
ctx.ui.notify(result.message, result.status === "migrated" ? "info" : "warning");
|
|
286
|
+
}
|
|
287
|
+
async function initConfig(ctx, signal) {
|
|
288
|
+
const configPath = localConfigPath();
|
|
289
|
+
if (await readLocalConfigObject()) {
|
|
290
|
+
ctx.ui.notify(`Config already exists: ${await activeLocalConfigPath()}`, "info");
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (ctx.mode === "tui") {
|
|
294
|
+
const { showSetupWizard } = await import("./setup-wizard-OHZXJVQZ.ts");
|
|
295
|
+
throwIfAborted(signal);
|
|
296
|
+
await showSetupWizard(ctx, signal);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
await createLocalConfigDocument(localConfigTemplate());
|
|
300
|
+
ctx.ui.notify(`Created ${configPath}. Add a storage connection and sync setup before syncing.`, "info");
|
|
301
|
+
}
|
|
302
|
+
async function showConfig(ctx, options) {
|
|
303
|
+
const config = await loadConfig(options.setup);
|
|
304
|
+
const warnings = [
|
|
305
|
+
...config.backend.type === "s3" ? sessionTokenWarnings(config.backend.profile) : [],
|
|
306
|
+
...syncSessionsWarnings(config)
|
|
307
|
+
];
|
|
308
|
+
const storageLines = configStorageLines(config);
|
|
309
|
+
ctx.ui.notify(
|
|
310
|
+
[
|
|
311
|
+
"pi-sync config:",
|
|
312
|
+
`sync setup: ${config.setupName}`,
|
|
313
|
+
`storage connection: ${config.connectionName}`,
|
|
314
|
+
...storageLines,
|
|
315
|
+
`storage path: ${config.storagePath}`,
|
|
316
|
+
`automatic sync: ${automaticSyncSummary(config.automatic)}`,
|
|
317
|
+
`settings field merge: ${config.mergeSettings ? "On (experimental)" : "Off"}`,
|
|
318
|
+
`machine-local settings.json fields: ${(config.localFields ?? []).map(safeTerminalText).join(", ") || "none"}`,
|
|
319
|
+
`startup transfer: ${startupTransferSummary(config)}`,
|
|
320
|
+
`agent mode: ${config.agentMode ? "On (experimental)" : "Off"}`,
|
|
321
|
+
`continuous sync: ${config.continuous ? config.agentMode ? "On (experimental)" : "paused; Agent mode is Off" : "Off"}`,
|
|
322
|
+
`included content: ${config.include.join(", ") || "none"}`,
|
|
323
|
+
`sessions: ${config.include.includes("sessions") ? "included" : "not included"}`,
|
|
324
|
+
`settings file: ${localConfigPath()}`,
|
|
325
|
+
...warnings
|
|
326
|
+
].join("\n"),
|
|
327
|
+
warnings.length > 0 ? "warning" : "info"
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
function configStorageLines(config) {
|
|
331
|
+
switch (config.backend.type) {
|
|
332
|
+
case "git":
|
|
333
|
+
return [
|
|
334
|
+
"kind: git",
|
|
335
|
+
`remote: ${displayGitRemote(config.backend.profile.remote)}`,
|
|
336
|
+
"authentication: existing Git/SSH credentials (not stored)",
|
|
337
|
+
`branch: ${config.backend.destination.branch}`
|
|
338
|
+
];
|
|
339
|
+
case "webdav":
|
|
340
|
+
return [
|
|
341
|
+
"kind: webdav",
|
|
342
|
+
`url: ${displayWebDavUrl(config.backend.profile.url, config.backend.profile.username)}`,
|
|
343
|
+
"username: configured (value hidden)",
|
|
344
|
+
"password: configured"
|
|
345
|
+
];
|
|
346
|
+
case "s3":
|
|
347
|
+
return [
|
|
348
|
+
"kind: s3",
|
|
349
|
+
`endpoint: ${config.backend.profile.endpoint}`,
|
|
350
|
+
`bucket: ${config.backend.destination.bucket}`,
|
|
351
|
+
`region: ${config.backend.profile.region}`,
|
|
352
|
+
"access key id: configured",
|
|
353
|
+
"secret access key: configured",
|
|
354
|
+
`session token: ${config.backend.profile.sessionToken ? "configured" : "not configured"}`
|
|
355
|
+
];
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
function displayGitRemote(value) {
|
|
359
|
+
if (!value) return "missing";
|
|
360
|
+
try {
|
|
361
|
+
const url = new URL(value);
|
|
362
|
+
url.username = "";
|
|
363
|
+
url.password = "";
|
|
364
|
+
url.search = "";
|
|
365
|
+
url.hash = "";
|
|
366
|
+
return url.toString();
|
|
367
|
+
} catch {
|
|
368
|
+
return value.replace(/^(?:[^@\s]+@)?(?<host>[^:]+):.+$/u, "$<host>:\u2026");
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
function displayWebDavUrl(value, username) {
|
|
372
|
+
if (!value) return "missing";
|
|
373
|
+
try {
|
|
374
|
+
const url = new URL(value);
|
|
375
|
+
url.username = "";
|
|
376
|
+
url.password = "";
|
|
377
|
+
url.search = "";
|
|
378
|
+
url.hash = "";
|
|
379
|
+
return username ? `${url.origin}/\u2026` : `${url.origin}${url.pathname}`;
|
|
380
|
+
} catch {
|
|
381
|
+
return "invalid (value hidden)";
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// src/commands/command-handler.ts
|
|
386
|
+
async function handleCommand(rawArgs, ctx, sessionSignal, loaders, attention, onExplicitSync) {
|
|
387
|
+
await reconcileObservation(attention, sessionSignal);
|
|
388
|
+
if (sessionSignal.aborted) return;
|
|
389
|
+
const run = (route, signal, onCommit, target, onDialog, retryRefusal = false) => {
|
|
390
|
+
const [command, ...args] = splitArgs(route);
|
|
391
|
+
if (command === "sync" && !retryRefusal) {
|
|
392
|
+
try {
|
|
393
|
+
const options = parseOptions(args);
|
|
394
|
+
validateCommandOptions("sync", options);
|
|
395
|
+
onExplicitSync?.(target ?? options.setup);
|
|
396
|
+
} catch {
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return executeCommand(
|
|
400
|
+
route,
|
|
401
|
+
ctx,
|
|
402
|
+
combineSignals(sessionSignal, signal),
|
|
403
|
+
loaders,
|
|
404
|
+
observationCommitCallback(attention, sessionSignal, onCommit),
|
|
405
|
+
target,
|
|
406
|
+
onDialog,
|
|
407
|
+
retryRefusal
|
|
408
|
+
);
|
|
409
|
+
};
|
|
410
|
+
if (!rawArgs.trim()) {
|
|
411
|
+
try {
|
|
412
|
+
const { showSyncManager } = await import("./manager-ui-DGRTG76I.ts");
|
|
413
|
+
if (sessionSignal.aborted) return;
|
|
414
|
+
await showSyncManager(ctx, run, sessionSignal, {
|
|
415
|
+
getAttention: () => attention.current(),
|
|
416
|
+
getObservation: () => attention.observation(),
|
|
417
|
+
onObservationInvalidated: () => attention.clearObservation(),
|
|
418
|
+
onSelectionResolved: (expected) => {
|
|
419
|
+
if (attention.current() === expected) attention.clear(ctx);
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
} catch (error) {
|
|
423
|
+
if (sessionSignal.aborted) return;
|
|
424
|
+
setSyncStatus(ctx, void 0);
|
|
425
|
+
ctx.ui.notify(errorMessage(error), "error");
|
|
426
|
+
}
|
|
427
|
+
await reconcileObservation(attention, sessionSignal);
|
|
428
|
+
if (!sessionSignal.aborted) await attention.publish(ctx, sessionSignal);
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
const result = await run(rawArgs);
|
|
432
|
+
if (result.kind === "decision-required") {
|
|
433
|
+
ctx.ui.notify(result.decision.directMessage, "error");
|
|
434
|
+
} else if (result.kind === "remote-selection-required") {
|
|
435
|
+
const origin = directSelectionOrigin(rawArgs);
|
|
436
|
+
if (origin) attention.set(result.decision, origin);
|
|
437
|
+
const deterministic = splitArgs(rawArgs).some((arg) => arg === "--yes" || arg === "-y");
|
|
438
|
+
if (origin && ctx.mode === "tui" && !deterministic) {
|
|
439
|
+
await resolveSelectionAttention(ctx, attention, sessionSignal, loaders);
|
|
440
|
+
} else {
|
|
441
|
+
ctx.ui.notify(
|
|
442
|
+
formatRemoteSelectionMismatch(
|
|
443
|
+
result.decision.setupName,
|
|
444
|
+
result.decision.localInclude,
|
|
445
|
+
result.decision.remoteInclude
|
|
446
|
+
),
|
|
447
|
+
"error"
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
await clearAttentionAfterCompletedOperation(rawArgs, result, ctx, attention, sessionSignal);
|
|
452
|
+
await reconcileSelectionAttention(ctx, attention, sessionSignal);
|
|
453
|
+
await reconcileObservation(attention, sessionSignal);
|
|
454
|
+
if (!sessionSignal.aborted) await attention.publish(ctx, sessionSignal);
|
|
455
|
+
}
|
|
456
|
+
function observationCommitCallback(attention, sessionSignal, onCommit) {
|
|
457
|
+
const observed = attention.observation();
|
|
458
|
+
return () => {
|
|
459
|
+
if (!sessionSignal.aborted && attention.observation() === observed) attention.clearObservation();
|
|
460
|
+
onCommit?.();
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
async function reconcileObservation(attention, signal) {
|
|
464
|
+
const observed = attention.observation();
|
|
465
|
+
if (!observed || signal.aborted) return;
|
|
466
|
+
try {
|
|
467
|
+
const config = await loadConfig();
|
|
468
|
+
if (signal.aborted || attention.observation() !== observed) return;
|
|
469
|
+
if (!observationMatchesConfig(observed, config)) {
|
|
470
|
+
attention.clearObservation();
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
const state = await readStateForConfig(config);
|
|
474
|
+
if (signal.aborted || attention.observation() !== observed) return;
|
|
475
|
+
if (syncStateFingerprint(state) !== observed.inspection.stateIdentity) attention.clearObservation();
|
|
476
|
+
} catch {
|
|
477
|
+
if (!signal.aborted && attention.observation() === observed) attention.clearObservation();
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
async function clearAttentionAfterCompletedOperation(rawArgs, result, ctx, attention, signal) {
|
|
481
|
+
if (result.kind !== "completed" || result.outcome === "cancelled" || signal.aborted) return;
|
|
482
|
+
const [command, ...rest] = splitArgs(rawArgs);
|
|
483
|
+
if (command !== "sync" && command !== "pull" && command !== "push") return;
|
|
484
|
+
const current = attention.current();
|
|
485
|
+
if (!current) return;
|
|
486
|
+
try {
|
|
487
|
+
const options = parseOptions(rest);
|
|
488
|
+
const setupName = options.setup ?? (await loadConfig()).setupName;
|
|
489
|
+
if (signal.aborted || attention.current() !== current) return;
|
|
490
|
+
if (current.decision.setupName === setupName) attention.clear(ctx);
|
|
491
|
+
} catch {
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
async function reconcileSelectionAttention(ctx, attention, signal) {
|
|
495
|
+
const current = attention.current();
|
|
496
|
+
if (!current || signal.aborted) return;
|
|
497
|
+
try {
|
|
498
|
+
const config = await loadConfig(current.decision.setupName);
|
|
499
|
+
if (signal.aborted || attention.current() !== current) return;
|
|
500
|
+
if (!syncAttentionMatchesConfig(current, config)) attention.clear(ctx);
|
|
501
|
+
} catch {
|
|
502
|
+
if (!signal.aborted && attention.current() === current) attention.clear(ctx);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
function directSelectionOrigin(rawArgs) {
|
|
506
|
+
const command = splitArgs(rawArgs)[0];
|
|
507
|
+
return command === "sync" || command === "pull" || command === "push" ? command : void 0;
|
|
508
|
+
}
|
|
509
|
+
async function resolveSelectionAttention(ctx, attention, signal, loaders, options = {}) {
|
|
510
|
+
const current = attention.current();
|
|
511
|
+
if (!current || signal.aborted) return;
|
|
512
|
+
const { dispatchManagerResult } = await import("./manager-result-dispatcher-NODX3KKH.ts");
|
|
513
|
+
if (signal.aborted || attention.current() !== current) return;
|
|
514
|
+
await dispatchManagerResult(
|
|
515
|
+
ctx,
|
|
516
|
+
{ kind: "remote-selection-required", decision: current.decision },
|
|
517
|
+
current.origin,
|
|
518
|
+
(route, actionSignal, onCommit, target) => {
|
|
519
|
+
const execute = () => executeRecoveryCommand(
|
|
520
|
+
route,
|
|
521
|
+
ctx,
|
|
522
|
+
combineSignals(signal, actionSignal),
|
|
523
|
+
loaders,
|
|
524
|
+
observationCommitCallback(attention, signal, onCommit),
|
|
525
|
+
target
|
|
526
|
+
);
|
|
527
|
+
return options.withStateAccess ? options.withStateAccess(execute) : execute();
|
|
528
|
+
},
|
|
529
|
+
signal,
|
|
530
|
+
{
|
|
531
|
+
cancelLabel: options.cancelLabel,
|
|
532
|
+
withStateAccess: options.withStateAccess,
|
|
533
|
+
onSelectionResolved: () => {
|
|
534
|
+
if (attention.current() === current) attention.clear(ctx);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
export {
|
|
540
|
+
handleCommand,
|
|
541
|
+
resolveSelectionAttention
|
|
542
|
+
};
|
|
543
|
+
//# sourceMappingURL=command-handler-FO6F2APH.ts.map
|