@narumitw/pi-sync 0.57.8 → 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 +306 -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-AH7TXOQT.ts → agent-refusal-retry-C2HQROTP.ts} +12 -9
- package/dist/chunks/{agent-refusal-retry-AH7TXOQT.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-N5TFMPB5.ts → chunk-2VSN3MFX.ts} +71 -63
- package/dist/chunks/{chunk-N5TFMPB5.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-5XZOC7FD.ts → chunk-KHBPED6W.ts} +4 -1
- package/dist/chunks/chunk-KHBPED6W.ts.map +7 -0
- 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-WD6FJHCK.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-UC5AGVER.ts → conflict-review-BQSHSJB3.ts} +32 -26
- package/dist/chunks/{conflict-review-UC5AGVER.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-POEQXR25.ts → continuous-sync-ZT3UEQLK.ts} +33 -28
- package/dist/chunks/{continuous-sync-POEQXR25.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-26LEINEX.ts → manager-ui-DGRTG76I.ts} +47 -41
- package/dist/chunks/{manager-ui-26LEINEX.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-ZHA6HQDB.ts → sync-operations-X4AOXMBT.ts} +66 -57
- package/dist/chunks/{sync-operations-ZHA6HQDB.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 +5 -4
- 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/src/ui/sync-confirmation.ts +3 -0
- package/dist/chunks/chunk-5XZOC7FD.ts.map +0 -7
- 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-WD6FJHCK.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
|
@@ -60,6 +60,9 @@ function createSyncConfirmation(options) {
|
|
|
60
60
|
if (item.value === choice && (choice !== "approve" || reviewed)) finish(choice);
|
|
61
61
|
};
|
|
62
62
|
const component = {
|
|
63
|
+
get capturesViewportInput() {
|
|
64
|
+
return list.capturesViewportInput;
|
|
65
|
+
},
|
|
63
66
|
render(width, expose = true) {
|
|
64
67
|
if (!Number.isFinite(width) || width <= 0) {
|
|
65
68
|
reviewed = false;
|
|
@@ -212,4 +215,4 @@ async function confirmMergeReview(ctx, title, content, signal, isCurrent, confir
|
|
|
212
215
|
export {
|
|
213
216
|
confirmMergeReview
|
|
214
217
|
};
|
|
215
|
-
//# sourceMappingURL=chunk-
|
|
218
|
+
//# sourceMappingURL=chunk-KHBPED6W.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/ui/merge-review.ts", "../../src/ui/sync-confirmation.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ExtensionCommandContext, ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { truncateToWidth } from \"@earendil-works/pi-tui\";\nimport { defineMenu, runCustomInteraction, runDocumentReview, runMenu } from \"@narumitw/pi-tui-kit\";\nimport { createSyncConfirmation, type SyncConfirmationChoice } from \"./sync-confirmation.js\";\nimport { safeTerminalText } from \"./terminal-text.js\";\n\ntype ReviewContext = ExtensionCommandContext | ExtensionContext;\n\n/** One approval screen; full details are optional and never authorize a transfer. */\nexport async function confirmMergeReview(\n ctx: ReviewContext,\n title: string,\n content: string,\n signal: AbortSignal | undefined,\n isCurrent: () => boolean,\n confirmationLabel = \"apply changes\",\n summaryLines?: readonly string[],\n) {\n const lines = summaryLines ?? [\n ...content\n .split(\"\\n\")\n .slice(0, 6)\n .map((line) => truncateToWidth(safeTerminalText(line), 100)),\n \"View details for the complete review.\",\n ];\n while (isCurrent() && !signal?.aborted) {\n const choice: { value: \"cancel\" | \"approve\" | \"details\" } = { value: \"cancel\" };\n const menu = defineMenu<undefined, \"confirm\", \"choose\", ReviewContext>({\n start: \"confirm\",\n screens: {\n confirm: () => ({\n kind: \"choice\",\n title,\n lines,\n initialItemId: \"cancel\",\n items: [\n { id: \"cancel\", label: \"No, cancel\" },\n { id: \"approve\", label: `Yes, ${confirmationLabel}` },\n { id: \"details\", label: \"View details\" },\n ],\n action: \"choose\",\n hint: \"close\",\n }),\n },\n actions: {\n choose: ({ itemId }) => {\n if (itemId === \"approve\" || itemId === \"details\") choice.value = itemId;\n return { kind: \"close\" };\n },\n },\n });\n const result =\n ctx.mode === \"tui\" && ctx.hasUI\n ? await runCustomInteraction<SyncConfirmationChoice, ReviewContext>(ctx, {\n create: ({ tui, theme, keybindings, complete }) =>\n createSyncConfirmation({ title, lines, confirmationLabel, tui, theme, keybindings, complete }),\n signal,\n isCurrent,\n onError: () => {},\n })\n : await runMenu(ctx, menu, { getState: () => undefined, signal, isCurrent, onError: () => {} });\n if (!isCurrent() || signal?.aborted) return false;\n if (result.kind === \"error\") throw new Error(\"Sync review failed; no transfer was performed.\");\n if (result.kind === \"unsupported\")\n throw new Error(\"Sync review requires observable TUI or RPC; review the plan before using --yes.\");\n if (result.kind === \"completed\") choice.value = result.value;\n else if (result.kind !== \"closed\") return false;\n // Keep authorization separate from UI termination in both adapters.\n if (choice.value === \"approve\") return true;\n if (choice.value !== \"details\") return false;\n const detail = await runDocumentReview(ctx, {\n title: \"Sync change details\",\n content,\n format: { kind: \"text\" },\n viewportSize: \"adaptive\",\n hint: \"back\",\n signal,\n isCurrent,\n onError: () => {},\n });\n if (!isCurrent() || signal?.aborted) return false;\n if (detail.kind === \"error\") throw new Error(\"Sync review failed; no transfer was performed.\");\n if (detail.kind !== \"cancelled\" || detail.reason !== \"back\") return false;\n // A fresh menu discards remembered selection: returning from details always selects No.\n // Unlike Pi's native Yes-first dialog, approval requires moving off the safe default.\n }\n return false;\n}\n", "import type { KeybindingsManager, Theme } from \"@earendil-works/pi-coding-agent\";\nimport { Key, matchesKey, SelectList, type TUI, type TuiMouseEvent, truncateToWidth } from \"@earendil-works/pi-tui\";\nimport { HorizontalRule, hardWrapTerminalDocument, sanitizeTerminalText } from \"@narumitw/pi-tui-kit\";\n\nexport type SyncConfirmationChoice = \"cancel\" | \"approve\" | \"details\";\n\n/** Kit choice context is clipped on short terminals; this summary must remain reviewable. */\nexport function createSyncConfirmation(options: {\n title: string;\n lines: readonly string[];\n confirmationLabel: string;\n tui: TUI;\n theme: Theme;\n keybindings: KeybindingsManager;\n complete(choice: SyncConfirmationChoice): void;\n}) {\n const { tui, theme, keybindings } = options;\n const choices: SyncConfirmationChoice[] = [\"cancel\", \"approve\", \"details\"];\n const list = new SelectList(\n [\n { value: \"cancel\", label: \"No, cancel\" },\n { value: \"approve\", label: `Yes, ${sanitizeTerminalText(options.confirmationLabel)}` },\n { value: \"details\", label: \"View details\" },\n ],\n 3,\n {\n selectedPrefix: (text) => theme.fg(\"accent\", text),\n selectedText: (text) => theme.fg(\"accent\", text),\n description: (text) => theme.fg(\"muted\", text),\n scrollInfo: (text) => theme.fg(\"dim\", text),\n noMatch: (text) => theme.fg(\"muted\", text),\n },\n );\n const rule = new HorizontalRule({ ruleStyle: (text) => theme.fg(\"border\", text) });\n let selected = 0;\n let offset = 0;\n let maximumOffset = 0;\n let lastWidth = 0;\n let lastRows = 0;\n let seen = new Set<number>();\n let summary: readonly string[] = [];\n let reviewed = false;\n let disposed = false;\n let finished = false;\n let summaryStart = 0;\n let summaryEnd = 0;\n let actionsStart = 0;\n const finish = (choice: SyncConfirmationChoice) => {\n if (disposed || finished) return;\n finished = true;\n options.complete(choice);\n };\n const select = (index: number) => {\n selected = (index + choices.length) % choices.length;\n list.setSelectedIndex(selected);\n };\n list.onSelectionChange = (item) => {\n selected = Math.max(0, choices.indexOf(item.value as SyncConfirmationChoice));\n };\n list.onSelect = (item) => {\n const choice = choices[selected] ?? \"cancel\";\n if (item.value === choice && (choice !== \"approve\" || reviewed)) finish(choice);\n };\n const component = {\n get capturesViewportInput() {\n return list.capturesViewportInput;\n },\n render(width: number, expose = true): string[] {\n if (!Number.isFinite(width) || width <= 0) {\n reviewed = false;\n return [];\n }\n const cells = Math.floor(width);\n const rows = Math.max(1, Math.floor(tui.terminal.rows) - 3);\n if (cells !== lastWidth || rows !== lastRows) {\n // Reflow can expose previously unseen rows or hide the selected action.\n // Reset proof and selection rather than carry approval across a resize.\n summary = options.lines.flatMap((line) => hardWrapTerminalDocument(line, cells));\n seen = new Set();\n offset = 0;\n select(0);\n lastWidth = cells;\n lastRows = rows;\n }\n const framed = rows >= 9;\n const actions = list.render(cells);\n const viewport = Math.max(0, rows - actions.length - 3 - (framed ? 2 : 0));\n maximumOffset = Math.max(0, summary.length - viewport);\n offset = Math.min(offset, maximumOffset);\n const visible = summary.slice(offset, offset + viewport);\n if (expose) for (let index = offset; index < offset + visible.length; index++) seen.add(index);\n reviewed = viewport > 0 && seen.size === summary.length;\n // Describe actions without advertising configured keys that can be invalid,\n // aliased, or shadowed by an earlier cancellation/navigation binding.\n const hint = reviewed ? \"Select an action.\" : \"Navigation keys scroll the summary before selecting Yes.\";\n const body = [\n theme.fg(\"accent\", theme.bold(hardWrapTerminalDocument(options.title, cells).join(\" \"))),\n ...visible.map((line) => theme.fg(\"text\", line)),\n theme.fg(\n \"muted\",\n `Summary ${visible.length ? offset + 1 : 0}-${offset + visible.length}/${summary.length}${reviewed ? \"\" : \" \u2014 review before Yes\"}`,\n ),\n ...actions,\n theme.fg(\"dim\", hint),\n ];\n summaryStart = Number(framed) + 1;\n summaryEnd = summaryStart + visible.length;\n actionsStart = summaryEnd + 1;\n const frame = framed ? [...rule.render(cells), ...body, ...rule.render(cells)] : body;\n // Very small terminals cannot display the summary and all choices together.\n // Keep cancellation available, but never approve a zero-row summary viewport.\n return frame.slice(0, rows).map((line) => truncateToWidth(line, cells, \"\"));\n },\n invalidate() {\n list.invalidate();\n rule.invalidate();\n },\n handleInput(data: string) {\n if (disposed || finished) return;\n if (matchesKey(data, Key.ctrl(\"c\")) || keybindings.matches(data, \"tui.select.cancel\")) {\n finish(\"cancel\");\n return;\n }\n // Refresh height/width proof before handling an input racing with terminal resize.\n component.render(tui.terminal.columns ?? lastWidth, false);\n if (keybindings.matches(data, \"tui.select.up\")) {\n if (!reviewed || (selected === 0 && offset > 0)) offset = Math.max(0, offset - 1);\n else select(selected - 1);\n } else if (keybindings.matches(data, \"tui.select.down\")) {\n if (!reviewed || (selected === 0 && offset < maximumOffset)) offset = Math.min(maximumOffset, offset + 1);\n else select(selected + 1);\n } else if (keybindings.matches(data, \"tui.select.confirm\")) {\n const choice = choices[selected] ?? \"cancel\";\n if (choice !== \"approve\" || reviewed) finish(choice);\n }\n tui.requestRender();\n },\n handleMouse(event: TuiMouseEvent) {\n if (disposed || finished || event.width !== lastWidth) return undefined;\n component.render(event.width, false);\n if (event.y >= summaryStart && event.y < summaryEnd && event.type === \"wheel\" && event.wheelDelta) {\n offset = Math.max(0, Math.min(maximumOffset, offset + (event.wheelDelta < 0 ? -1 : 1)));\n select(0);\n tui.requestRender();\n return { handled: true, render: true };\n }\n if (event.y < actionsStart || event.y >= actionsStart + choices.length || event.y >= lastRows) return undefined;\n return list.handleMouse({ ...event, y: event.y - actionsStart, height: choices.length });\n },\n dispose() {\n disposed = true;\n seen.clear();\n },\n };\n return component;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;AACA,SAAS,mBAAAA,wBAAuB;AAChC,SAAS,YAAY,sBAAsB,mBAAmB,eAAe;;;ACD7E,SAAS,KAAK,YAAY,YAA0C,uBAAuB;AAC3F,SAAS,gBAAgB,0BAA0B,4BAA4B;AAKxE,SAAS,uBAAuB,SAQpC;AACD,QAAM,EAAE,KAAK,OAAO,YAAY,IAAI;AACpC,QAAM,UAAoC,CAAC,UAAU,WAAW,SAAS;AACzE,QAAM,OAAO,IAAI;AAAA,IACf;AAAA,MACE,EAAE,OAAO,UAAU,OAAO,aAAa;AAAA,MACvC,EAAE,OAAO,WAAW,OAAO,QAAQ,qBAAqB,QAAQ,iBAAiB,CAAC,GAAG;AAAA,MACrF,EAAE,OAAO,WAAW,OAAO,eAAe;AAAA,IAC5C;AAAA,IACA;AAAA,IACA;AAAA,MACE,gBAAgB,CAAC,SAAS,MAAM,GAAG,UAAU,IAAI;AAAA,MACjD,cAAc,CAAC,SAAS,MAAM,GAAG,UAAU,IAAI;AAAA,MAC/C,aAAa,CAAC,SAAS,MAAM,GAAG,SAAS,IAAI;AAAA,MAC7C,YAAY,CAAC,SAAS,MAAM,GAAG,OAAO,IAAI;AAAA,MAC1C,SAAS,CAAC,SAAS,MAAM,GAAG,SAAS,IAAI;AAAA,IAC3C;AAAA,EACF;AACA,QAA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AE,OAAO,OAAO,mBAAmB,KAAK,OAAO,aAAa,SAAS,CAAC;AAAA,MAC/F;AAAA,MACA;AAAA,MACA,SAAS,MAAM;AAAA,MAAC;AAAA,IAClB,CAAC,IACD,MAAM,QAAQ,KAAK,MAAM,EAAE,UAAU,MAAM,QAAW,QAAQ,WAAW,SAAS,MAAM;AAAA,IAAC,EAAE,CAAC;AAClG,QAAI,CAAC,UAAU,KAAK,QAAQ,QAAS,QAAO;AAC5C,QAAI,OAAO,SAAS,QAAS,OAAM,IAAI,MAAM,gDAAgD;AAC7F,QAAI,OAAO,SAAS;AAClB,YAAM,IAAI,MAAM,iFAAiF;AACnG,QAAI,OAAO,SAAS,YAAa,QAAO,QAAQ,OAAO;AAAA,aAC9C,OAAO,SAAS,SAAU,QAAO;AAE1C,QAAI,OAAO,UAAU,UAAW,QAAO;AACvC,QAAI,OAAO,UAAU,UAAW,QAAO;AACvC,UAAM,SAAS,MAAM,kBAAkB,KAAK;AAAA,MAC1C,OAAO;AAAA,MACP;AAAA,MACA,QAAQ,EAAE,MAAM,OAAO;AAAA,MACvB,cAAc;AAAA,MACd,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA,SAAS,MAAM;AAAA,MAAC;AAAA,IAClB,CAAC;AACD,QAAI,CAAC,UAAU,KAAK,QAAQ,QAAS,QAAO;AAC5C,QAAI,OAAO,SAAS,QAAS,OAAM,IAAI,MAAM,gDAAgD;AAC7F,QAAI,OAAO,SAAS,eAAe,OAAO,WAAW,OAAQ,QAAO;AAAA,EAGtE;AACA,SAAO;AACT;",
|
|
6
|
+
"names": ["truncateToWidth", "truncateToWidth"]
|
|
7
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import {
|
|
4
4
|
runCancellableOperation,
|
|
5
5
|
showRemoteSelectionReview
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-BJXSCGQK.ts";
|
|
7
7
|
import {
|
|
8
8
|
safeTerminalText
|
|
9
9
|
} from "./chunk-AMJRUXFT.ts";
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
import {
|
|
14
14
|
loadConfig,
|
|
15
15
|
syncConfigReviewIdentity
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-RX3WGWVL.ts";
|
|
17
17
|
|
|
18
18
|
// src/ui/sync-resolution-ui.ts
|
|
19
19
|
import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
|
|
@@ -206,4 +206,4 @@ async function dispatchManagerResult(ctx, initialResult, origin, runRoute, signa
|
|
|
206
206
|
export {
|
|
207
207
|
dispatchManagerResult
|
|
208
208
|
};
|
|
209
|
-
//# sourceMappingURL=chunk-
|
|
209
|
+
//# sourceMappingURL=chunk-M5IV3KL2.ts.map
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
ensureStateDir,
|
|
8
8
|
lockPath
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-73MDIVYJ.ts";
|
|
10
10
|
import {
|
|
11
11
|
LOCKFILE_FS_ADAPTER,
|
|
12
12
|
LOCK_GUARD_STALE_MS,
|
|
@@ -255,4 +255,4 @@ export {
|
|
|
255
255
|
isStaleLock,
|
|
256
256
|
unlock
|
|
257
257
|
};
|
|
258
|
-
//# sourceMappingURL=chunk-
|
|
258
|
+
//# sourceMappingURL=chunk-MDUORMCK.ts.map
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from "./chunk-PWMWOJP4.ts";
|
|
6
6
|
import {
|
|
7
7
|
snapshotSelectionInclude
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-DFJGTVPX.ts";
|
|
9
9
|
|
|
10
10
|
// src/snapshot/snapshot-codec.ts
|
|
11
11
|
import { Readable, Writable } from "node:stream";
|
|
@@ -42,7 +42,7 @@ async function decodeSnapshot(buffer, options = {}) {
|
|
|
42
42
|
throw new Error("Unsupported snapshot format.");
|
|
43
43
|
}
|
|
44
44
|
if (parsed.version === 2 || parsed.version === 3) {
|
|
45
|
-
const { normalizeLocalFields, validatePortableSnapshot } = await import("./local-fields-
|
|
45
|
+
const { normalizeLocalFields, validatePortableSnapshot } = await import("./local-fields-B6JWLPAE.ts");
|
|
46
46
|
validatePortableSnapshot(parsed);
|
|
47
47
|
if (parsed.localFields !== void 0) parsed.localFields = normalizeLocalFields(parsed.localFields);
|
|
48
48
|
} else if (parsed.localFields !== void 0) throw new Error("Portable field policy requires snapshot version 2.");
|
|
@@ -54,4 +54,4 @@ export {
|
|
|
54
54
|
encodeSnapshot,
|
|
55
55
|
decodeSnapshot
|
|
56
56
|
};
|
|
57
|
-
//# sourceMappingURL=chunk-
|
|
57
|
+
//# sourceMappingURL=chunk-MRIPZGPR.ts.map
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from "./chunk-K3RIEL6J.ts";
|
|
9
9
|
import {
|
|
10
10
|
withLock
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-MDUORMCK.ts";
|
|
12
12
|
import {
|
|
13
13
|
ContinuousError
|
|
14
14
|
} from "./chunk-DT7M4VQS.ts";
|
|
@@ -29,8 +29,8 @@ async function withAgentSyncLock(ctx, options, run) {
|
|
|
29
29
|
if (!(error instanceof AgentResolutionRequired)) throw error;
|
|
30
30
|
request = error;
|
|
31
31
|
}
|
|
32
|
-
const { withAgentClaim, readAgentCandidate, saveAgentCandidate, replaceRefusedAgentCandidate } = await import("./agent-store-
|
|
33
|
-
const { parseAgentCandidate } = await import("./agent-candidate-
|
|
32
|
+
const { withAgentClaim, readAgentCandidate, saveAgentCandidate, replaceRefusedAgentCandidate } = await import("./agent-store-UT52DS7B.ts");
|
|
33
|
+
const { parseAgentCandidate } = await import("./agent-candidate-EYB35AGL.ts");
|
|
34
34
|
const { runAgentResolver } = await import("./agent-runner-WMSCKSCB.ts");
|
|
35
35
|
return withAgentClaim(async (assertOwner) => {
|
|
36
36
|
const clearStatus = () => setSyncStatus(ctx, void 0);
|
|
@@ -69,7 +69,7 @@ async function withAgentSyncLock(ctx, options, run) {
|
|
|
69
69
|
expectedRefusal = parseAgentCandidate(JSON.stringify(cached), request.evidence);
|
|
70
70
|
if (!expectedRefusal.results.some((row) => "refuse" in row))
|
|
71
71
|
throw new Error("The current cached result is not a refusal. Use Sync now.");
|
|
72
|
-
const { confirmAgentRefusalRetry } = await import("./agent-refusal-retry-
|
|
72
|
+
const { confirmAgentRefusalRetry } = await import("./agent-refusal-retry-C2HQROTP.ts");
|
|
73
73
|
options.signal?.throwIfAborted();
|
|
74
74
|
if (!await confirmAgentRefusalRetry(ctx, options.setup, request.evidence, validate, options.signal))
|
|
75
75
|
return "cancelled";
|
|
@@ -137,4 +137,4 @@ async function withAgentSyncLock(ctx, options, run) {
|
|
|
137
137
|
export {
|
|
138
138
|
withAgentSyncLock
|
|
139
139
|
};
|
|
140
|
-
//# sourceMappingURL=chunk-
|
|
140
|
+
//# sourceMappingURL=chunk-ODF2M4RF.ts.map
|
|
@@ -0,0 +1,348 @@
|
|
|
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
|
+
DEFAULT_SYNC_INCLUDE,
|
|
5
|
+
canonicalSnapshotPathForConfig,
|
|
6
|
+
customIncludePathsByLower,
|
|
7
|
+
includeFromSelectionConfig,
|
|
8
|
+
isConfiguredSnapshotPath,
|
|
9
|
+
isPreservableUnmanagedSnapshotPath,
|
|
10
|
+
normalizeExtraFiles,
|
|
11
|
+
normalizeSyncFiles,
|
|
12
|
+
selectionForSnapshot,
|
|
13
|
+
snapshotSelectionInclude,
|
|
14
|
+
syncIncludeSelection
|
|
15
|
+
} from "./chunk-DFJGTVPX.ts";
|
|
16
|
+
import {
|
|
17
|
+
agentDir,
|
|
18
|
+
configuredSessionDir,
|
|
19
|
+
sessionStorageRoot
|
|
20
|
+
} from "./chunk-DO55XUNU.ts";
|
|
21
|
+
import {
|
|
22
|
+
isDeniedPath,
|
|
23
|
+
posixJoin,
|
|
24
|
+
safeJoin,
|
|
25
|
+
toPosix
|
|
26
|
+
} from "./chunk-YZ5BQNRZ.ts";
|
|
27
|
+
|
|
28
|
+
// src/snapshot/snapshot.ts
|
|
29
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
30
|
+
import fs from "node:fs/promises";
|
|
31
|
+
import os from "node:os";
|
|
32
|
+
import path from "node:path";
|
|
33
|
+
var VERSION = 1;
|
|
34
|
+
var TOP_LEVEL_FILES = DEFAULT_SYNC_INCLUDE.filter((name) => name.includes("."));
|
|
35
|
+
var TOP_LEVEL_DIRS = new Set(DEFAULT_SYNC_INCLUDE.filter((name) => !name.includes(".")));
|
|
36
|
+
var SECRET_PATTERNS = [
|
|
37
|
+
/AWS_SECRET_ACCESS_KEY\s*[=:]\s*['"]?[A-Za-z0-9/+]{35,}/i,
|
|
38
|
+
/(ANTHROPIC|OPENAI|GEMINI|GOOGLE|FIRECRAWL|GITHUB|CLOUDFLARE|R2|S3)_[A-Z0-9_]*(KEY|TOKEN|SECRET)\s*[=:]\s*['"]?[^\s'"]{12,}/i,
|
|
39
|
+
/sk-ant-[A-Za-z0-9_-]{20,}/,
|
|
40
|
+
/sk-[A-Za-z0-9]{20,}/,
|
|
41
|
+
/gh[pousr]_[A-Za-z0-9_]{20,}/
|
|
42
|
+
];
|
|
43
|
+
function selectTopLevelFileEntry(entries, fileName) {
|
|
44
|
+
const exact = entries.find((entry) => entry.isFile() && entry.name === fileName);
|
|
45
|
+
if (exact) return exact;
|
|
46
|
+
const lower = fileName.toLowerCase();
|
|
47
|
+
return entries.filter((entry) => entry.isFile() && entry.name.toLowerCase() === lower).sort((left, right) => left.name.localeCompare(right.name))[0];
|
|
48
|
+
}
|
|
49
|
+
function sha256(value) {
|
|
50
|
+
return createHash("sha256").update(value).digest("hex");
|
|
51
|
+
}
|
|
52
|
+
function isSafeSnapshotPath(relativePath) {
|
|
53
|
+
if (relativePath.includes("\\")) return false;
|
|
54
|
+
const normalized = toPosix(relativePath);
|
|
55
|
+
return Boolean(normalized) && normalized !== "." && normalized !== ".." && !normalized.startsWith("../") && !path.posix.isAbsolute(normalized) && path.posix.normalize(normalized) === normalized && !isDeniedPath(normalized);
|
|
56
|
+
}
|
|
57
|
+
function snapshotsMatch(left, right) {
|
|
58
|
+
const leftHashes = new Map(left.files.map((file) => [file.path, file.sha256]));
|
|
59
|
+
const rightHashes = new Map(right.files.map((file) => [file.path, file.sha256]));
|
|
60
|
+
return left.syncSessions === right.syncSessions && sameOptionalInclude(snapshotSelectionInclude(left), snapshotSelectionInclude(right)) && leftHashes.size === rightHashes.size && [...leftHashes].every(([filePath, hash]) => rightHashes.get(filePath) === hash);
|
|
61
|
+
}
|
|
62
|
+
function snapshotId() {
|
|
63
|
+
return `${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}-${randomUUID().slice(0, 8)}`;
|
|
64
|
+
}
|
|
65
|
+
function regenerateSnapshotIdentity(snapshot) {
|
|
66
|
+
return {
|
|
67
|
+
...snapshot,
|
|
68
|
+
id: snapshotId(),
|
|
69
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
70
|
+
machine: os.hostname()
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async function createSnapshot(profile, options = {}) {
|
|
74
|
+
options.signal?.throwIfAborted();
|
|
75
|
+
const include = effectiveInclude(options);
|
|
76
|
+
const syncSessions = include.includes("sessions");
|
|
77
|
+
const sessionDir = options.sessionDir ?? await configuredSessionDir();
|
|
78
|
+
options.signal?.throwIfAborted();
|
|
79
|
+
const files = await collectFiles(agentDir(), { include, sessionDir, signal: options.signal });
|
|
80
|
+
options.signal?.throwIfAborted();
|
|
81
|
+
return {
|
|
82
|
+
version: VERSION,
|
|
83
|
+
id: snapshotId(),
|
|
84
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
85
|
+
machine: os.hostname(),
|
|
86
|
+
profile,
|
|
87
|
+
syncSessions,
|
|
88
|
+
selection: selectionForSnapshot(include),
|
|
89
|
+
files
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function effectiveInclude(options) {
|
|
93
|
+
if (options.include) return options.include;
|
|
94
|
+
return [
|
|
95
|
+
...normalizeSyncFiles(options.syncFiles),
|
|
96
|
+
...normalizeExtraFiles(options.extraFiles),
|
|
97
|
+
...options.syncSessions ? ["sessions"] : []
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
async function collectFiles(root, options = {}) {
|
|
101
|
+
const signal = options.signal;
|
|
102
|
+
signal?.throwIfAborted();
|
|
103
|
+
const results = [];
|
|
104
|
+
const entries = await fs.readdir(root, { withFileTypes: true });
|
|
105
|
+
signal?.throwIfAborted();
|
|
106
|
+
const selection = syncIncludeSelection(effectiveInclude(options));
|
|
107
|
+
const selectedFiles = new Set(selection.builtIns);
|
|
108
|
+
for (const entry of entries) {
|
|
109
|
+
if (entry.isDirectory() && TOP_LEVEL_DIRS.has(entry.name) && selectedFiles.has(entry.name)) {
|
|
110
|
+
await collectDirectory(results, root, entry.name, { signal });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
for (const fileName of TOP_LEVEL_FILES) {
|
|
114
|
+
if (!selectedFiles.has(fileName)) continue;
|
|
115
|
+
const entry = selectTopLevelFileEntry(entries, fileName);
|
|
116
|
+
if (entry) await addFile(results, root, entry.name, fileName, signal);
|
|
117
|
+
}
|
|
118
|
+
for (const relativePath of selection.custom) {
|
|
119
|
+
await collectIncludedPath(results, root, relativePath, signal);
|
|
120
|
+
}
|
|
121
|
+
if (selection.sessions) {
|
|
122
|
+
try {
|
|
123
|
+
await collectDirectory(results, sessionStorageRoot(root, options.sessionDir), "", {
|
|
124
|
+
sessionsOnly: true,
|
|
125
|
+
virtualPrefix: "sessions",
|
|
126
|
+
signal
|
|
127
|
+
});
|
|
128
|
+
} catch (error) {
|
|
129
|
+
if (error.code !== "ENOENT") throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
signal?.throwIfAborted();
|
|
133
|
+
return results.sort((left, right) => left.path.localeCompare(right.path));
|
|
134
|
+
}
|
|
135
|
+
async function collectIncludedPath(results, root, relativePath, signal) {
|
|
136
|
+
signal?.throwIfAborted();
|
|
137
|
+
const absolutePath = safeJoin(root, relativePath);
|
|
138
|
+
try {
|
|
139
|
+
const stat = await fs.lstat(absolutePath);
|
|
140
|
+
signal?.throwIfAborted();
|
|
141
|
+
if (stat.isFile()) await addFile(results, root, relativePath, relativePath, signal);
|
|
142
|
+
else if (stat.isDirectory()) await collectDirectory(results, root, relativePath, { signal });
|
|
143
|
+
} catch (error) {
|
|
144
|
+
if (error.code !== "ENOENT") throw error;
|
|
145
|
+
if (!relativePath.includes("/")) {
|
|
146
|
+
const entries = await fs.readdir(root, { withFileTypes: true });
|
|
147
|
+
signal?.throwIfAborted();
|
|
148
|
+
const entry = selectTopLevelFileEntry(entries, relativePath);
|
|
149
|
+
if (entry) await addFile(results, root, entry.name, relativePath, signal);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async function collectDirectory(results, root, relativeDirectory, options = {}) {
|
|
154
|
+
options.signal?.throwIfAborted();
|
|
155
|
+
const absoluteDirectory = path.join(root, relativeDirectory);
|
|
156
|
+
for (const entry of await fs.readdir(absoluteDirectory, { withFileTypes: true })) {
|
|
157
|
+
options.signal?.throwIfAborted();
|
|
158
|
+
const relativePath = relativeDirectory ? posixJoin(relativeDirectory, entry.name) : entry.name;
|
|
159
|
+
const snapshotPath = options.virtualPrefix ? posixJoin(options.virtualPrefix, relativePath) : relativePath;
|
|
160
|
+
if (isDeniedPath(snapshotPath)) continue;
|
|
161
|
+
if (entry.isDirectory()) {
|
|
162
|
+
await collectDirectory(results, root, relativePath, options);
|
|
163
|
+
} else if (entry.isFile() && (!options.sessionsOnly || isSessionFilePath(snapshotPath))) {
|
|
164
|
+
await addFile(results, root, relativePath, snapshotPath, options.signal);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async function addFile(results, root, relativePath, snapshotPath = relativePath, signal) {
|
|
169
|
+
signal?.throwIfAborted();
|
|
170
|
+
if (!isSafeSnapshotPath(snapshotPath)) return;
|
|
171
|
+
const absolutePath = safeJoin(root, relativePath);
|
|
172
|
+
const content = await fs.readFile(absolutePath, { signal });
|
|
173
|
+
signal?.throwIfAborted();
|
|
174
|
+
results.push({
|
|
175
|
+
path: snapshotPath,
|
|
176
|
+
contentBase64: content.toString("base64"),
|
|
177
|
+
sha256: sha256(content)
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
function isSessionPath(relativePath) {
|
|
181
|
+
return toPosix(relativePath).startsWith("sessions/");
|
|
182
|
+
}
|
|
183
|
+
function isSessionFilePath(relativePath) {
|
|
184
|
+
const normalized = toPosix(relativePath);
|
|
185
|
+
return isSessionPath(normalized) && normalized.endsWith(".jsonl");
|
|
186
|
+
}
|
|
187
|
+
function sessionSnapshotPathFromAbsolute(sessionFile, configuredSessionDir2) {
|
|
188
|
+
const relativePath = toPosix(path.relative(sessionStorageRoot(agentDir(), configuredSessionDir2), sessionFile));
|
|
189
|
+
if (!relativePath || relativePath.startsWith("../") || path.posix.isAbsolute(relativePath)) {
|
|
190
|
+
return void 0;
|
|
191
|
+
}
|
|
192
|
+
const snapshotPath = posixJoin("sessions", relativePath);
|
|
193
|
+
return isSessionFilePath(snapshotPath) ? snapshotPath : void 0;
|
|
194
|
+
}
|
|
195
|
+
function snapshotTarget(root, relativePath, configuredSessionDir2) {
|
|
196
|
+
if (isSessionPath(relativePath)) {
|
|
197
|
+
return safeJoin(sessionStorageRoot(root, configuredSessionDir2), relativePath.slice("sessions/".length));
|
|
198
|
+
}
|
|
199
|
+
return safeJoin(root, relativePath);
|
|
200
|
+
}
|
|
201
|
+
function snapshotIncludesSessions(snapshot) {
|
|
202
|
+
return snapshot.syncSessions === true || snapshotSelectionInclude(snapshot)?.includes("sessions") === true || snapshot.files.some((file) => isSessionPath(file.path));
|
|
203
|
+
}
|
|
204
|
+
function filterSnapshotForConfigPolicy(snapshot, config, options = {}) {
|
|
205
|
+
const include = includeFromSelectionConfig(config);
|
|
206
|
+
const includePaths = customIncludePathsByLower(include);
|
|
207
|
+
const filtered = {
|
|
208
|
+
...snapshot,
|
|
209
|
+
syncSessions: include.includes("sessions") ? snapshot.syncSessions : false,
|
|
210
|
+
selection: selectionForSnapshot(include),
|
|
211
|
+
files: canonicalizeSnapshotFilesForConfig(snapshot.files, config, includePaths)
|
|
212
|
+
};
|
|
213
|
+
if (!options.regenerateId || snapshotsMatch(snapshot, filtered)) return filtered;
|
|
214
|
+
return {
|
|
215
|
+
...filtered,
|
|
216
|
+
id: snapshotId(),
|
|
217
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
218
|
+
machine: os.hostname()
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function canonicalizeSnapshotFilesForConfig(files, config, includePaths) {
|
|
222
|
+
const configuredFiles = [];
|
|
223
|
+
const extraCandidates = /* @__PURE__ */ new Map();
|
|
224
|
+
for (const file of files) {
|
|
225
|
+
const normalized = toPosix(file.path);
|
|
226
|
+
if (!isSafeSnapshotPath(file.path) || !isConfiguredSnapshotPath(normalized, config)) {
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (normalized.includes("/")) {
|
|
230
|
+
configuredFiles.push(normalized === file.path ? file : { ...file, path: normalized });
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
const topLevelPath = canonicalSnapshotPathForConfig(normalized, includePaths);
|
|
234
|
+
const candidate = {
|
|
235
|
+
exact: normalized === topLevelPath,
|
|
236
|
+
file: { ...file, path: topLevelPath },
|
|
237
|
+
originalPath: normalized
|
|
238
|
+
};
|
|
239
|
+
const current = extraCandidates.get(topLevelPath.toLowerCase());
|
|
240
|
+
if (!current || isPreferredExtraCandidate(candidate, current)) {
|
|
241
|
+
extraCandidates.set(topLevelPath.toLowerCase(), candidate);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return [...configuredFiles, ...[...extraCandidates.values()].map((candidate) => candidate.file)].sort(
|
|
245
|
+
(left, right) => left.path.localeCompare(right.path)
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
function isPreferredExtraCandidate(left, right) {
|
|
249
|
+
if (left.exact !== right.exact) return left.exact;
|
|
250
|
+
return left.originalPath.localeCompare(right.originalPath) < 0;
|
|
251
|
+
}
|
|
252
|
+
function snapshotWithoutSessions(snapshot) {
|
|
253
|
+
const files = snapshot.files.filter((file) => !isSessionPath(file.path));
|
|
254
|
+
const include = snapshotSelectionInclude(snapshot)?.filter((item) => item !== "sessions");
|
|
255
|
+
if (files.length === snapshot.files.length && snapshot.syncSessions !== true && include?.length === snapshot.selection?.include.length) {
|
|
256
|
+
return snapshot;
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
...snapshot,
|
|
260
|
+
id: snapshotId(),
|
|
261
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
262
|
+
machine: os.hostname(),
|
|
263
|
+
syncSessions: false,
|
|
264
|
+
...include ? { selection: selectionForSnapshot(include) } : {},
|
|
265
|
+
files
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
function scanSnapshot(snapshot) {
|
|
269
|
+
const findings = [];
|
|
270
|
+
for (const file of snapshot.files) {
|
|
271
|
+
const content = Buffer.from(file.contentBase64, "base64");
|
|
272
|
+
if (content.includes(0)) continue;
|
|
273
|
+
const text = content.toString("utf8");
|
|
274
|
+
for (const pattern of SECRET_PATTERNS) {
|
|
275
|
+
if (pattern.test(text)) {
|
|
276
|
+
findings.push(file.path);
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return findings;
|
|
282
|
+
}
|
|
283
|
+
function mergeRemotePreservedFiles(local, remote, config) {
|
|
284
|
+
const localPathNames = new Set(local.files.map((file) => file.path.toLowerCase()));
|
|
285
|
+
const preservedPathNames = /* @__PURE__ */ new Set();
|
|
286
|
+
const preserved = remote.files.filter((file) => {
|
|
287
|
+
const normalized = toPosix(file.path);
|
|
288
|
+
const lower = normalized.toLowerCase();
|
|
289
|
+
if (localPathNames.has(lower) || preservedPathNames.has(lower) || !isSafeSnapshotPath(file.path) || isConfiguredSnapshotPath(normalized, config) || !isPreservableUnmanagedSnapshotPath(normalized)) {
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
preservedPathNames.add(lower);
|
|
293
|
+
return true;
|
|
294
|
+
});
|
|
295
|
+
if (preserved.length === 0) return local;
|
|
296
|
+
return {
|
|
297
|
+
...local,
|
|
298
|
+
id: snapshotId(),
|
|
299
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
300
|
+
machine: os.hostname(),
|
|
301
|
+
syncSessions: snapshotIncludesSessions(local) || snapshotIncludesSessions(remote),
|
|
302
|
+
files: [...local.files, ...preserved].sort((left, right) => left.path.localeCompare(right.path))
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function mergeRemoteSessionFiles(local, remote) {
|
|
306
|
+
const remoteSessions = remote.files.filter((file) => {
|
|
307
|
+
const normalized = toPosix(file.path);
|
|
308
|
+
return isSessionFilePath(normalized) && isSafeSnapshotPath(file.path);
|
|
309
|
+
});
|
|
310
|
+
if (remoteSessions.length === 0 && !snapshotIncludesSessions(remote)) return local;
|
|
311
|
+
const localInclude = snapshotSelectionInclude(local);
|
|
312
|
+
return {
|
|
313
|
+
...local,
|
|
314
|
+
id: snapshotId(),
|
|
315
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
316
|
+
machine: os.hostname(),
|
|
317
|
+
syncSessions: true,
|
|
318
|
+
...localInclude ? {
|
|
319
|
+
selection: selectionForSnapshot(
|
|
320
|
+
localInclude.includes("sessions") ? localInclude : [...localInclude, "sessions"]
|
|
321
|
+
)
|
|
322
|
+
} : {},
|
|
323
|
+
files: [...local.files.filter((file) => !isSessionPath(file.path)), ...remoteSessions].sort(
|
|
324
|
+
(left, right) => left.path.localeCompare(right.path)
|
|
325
|
+
)
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function sameOptionalInclude(left, right) {
|
|
329
|
+
if (!left || !right) return left === right;
|
|
330
|
+
return left.length === right.length && left.every((item, index) => item === right[index]);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export {
|
|
334
|
+
regenerateSnapshotIdentity,
|
|
335
|
+
createSnapshot,
|
|
336
|
+
collectFiles,
|
|
337
|
+
isSessionPath,
|
|
338
|
+
isSessionFilePath,
|
|
339
|
+
sessionSnapshotPathFromAbsolute,
|
|
340
|
+
snapshotTarget,
|
|
341
|
+
snapshotIncludesSessions,
|
|
342
|
+
filterSnapshotForConfigPolicy,
|
|
343
|
+
snapshotWithoutSessions,
|
|
344
|
+
scanSnapshot,
|
|
345
|
+
mergeRemotePreservedFiles,
|
|
346
|
+
mergeRemoteSessionFiles
|
|
347
|
+
};
|
|
348
|
+
//# sourceMappingURL=chunk-PHANBTVM.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/snapshot/snapshot.ts"],
|
|
4
|
+
"sourcesContent": ["import { createHash, randomUUID } from \"node:crypto\";\nimport type { Dirent } from \"node:fs\";\nimport fs from \"node:fs/promises\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { isDeniedPath, posixJoin, safeJoin, toPosix } from \"../paths.js\";\nimport { agentDir, configuredSessionDir } from \"./session-paths.js\";\nimport { sessionStorageRoot } from \"./snapshot-paths.js\";\n\nexport { isDeniedPath } from \"../paths.js\";\nexport { sessionStorageRoot } from \"./snapshot-paths.js\";\n\nimport {\n canonicalSnapshotPathForConfig,\n customIncludePathsByLower,\n DEFAULT_SYNC_INCLUDE,\n includeFromSelectionConfig,\n isConfiguredSnapshotPath,\n isPreservableUnmanagedSnapshotPath,\n normalizeExtraFiles,\n normalizeSyncFiles,\n type SyncSelectionConfig,\n selectionForSnapshot,\n snapshotSelectionInclude,\n syncIncludeSelection,\n} from \"../sync/sync-policy.js\";\nimport type { Snapshot, SnapshotFile, SnapshotOptions } from \"./snapshot-types.js\";\n\nexport { canonicalSnapshotPathForConfig, isConfiguredSnapshotPath } from \"../sync/sync-policy.js\";\n\nconst VERSION = 1;\nconst TOP_LEVEL_FILES: readonly string[] = DEFAULT_SYNC_INCLUDE.filter((name) => name.includes(\".\"));\nconst TOP_LEVEL_DIRS = new Set<string>(DEFAULT_SYNC_INCLUDE.filter((name) => !name.includes(\".\")));\nconst SECRET_PATTERNS = [\n /AWS_SECRET_ACCESS_KEY\\s*[=:]\\s*['\"]?[A-Za-z0-9/+]{35,}/i,\n /(ANTHROPIC|OPENAI|GEMINI|GOOGLE|FIRECRAWL|GITHUB|CLOUDFLARE|R2|S3)_[A-Z0-9_]*(KEY|TOKEN|SECRET)\\s*[=:]\\s*['\"]?[^\\s'\"]{12,}/i,\n /sk-ant-[A-Za-z0-9_-]{20,}/,\n /sk-[A-Za-z0-9]{20,}/,\n /gh[pousr]_[A-Za-z0-9_]{20,}/,\n];\n\nfunction selectTopLevelFileEntry(entries: Dirent[], fileName: string) {\n const exact = entries.find((entry) => entry.isFile() && entry.name === fileName);\n if (exact) return exact;\n const lower = fileName.toLowerCase();\n return entries\n .filter((entry) => entry.isFile() && entry.name.toLowerCase() === lower)\n .sort((left, right) => left.name.localeCompare(right.name))[0];\n}\n\nfunction sha256(value: Buffer) {\n return createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\nfunction isSafeSnapshotPath(relativePath: string) {\n if (relativePath.includes(\"\\\\\")) return false;\n const normalized = toPosix(relativePath);\n return (\n Boolean(normalized) &&\n normalized !== \".\" &&\n normalized !== \"..\" &&\n !normalized.startsWith(\"../\") &&\n !path.posix.isAbsolute(normalized) &&\n path.posix.normalize(normalized) === normalized &&\n !isDeniedPath(normalized)\n );\n}\n\nfunction snapshotsMatch(left: Snapshot, right: Snapshot) {\n const leftHashes = new Map(left.files.map((file) => [file.path, file.sha256]));\n const rightHashes = new Map(right.files.map((file) => [file.path, file.sha256]));\n return (\n left.syncSessions === right.syncSessions &&\n sameOptionalInclude(snapshotSelectionInclude(left), snapshotSelectionInclude(right)) &&\n leftHashes.size === rightHashes.size &&\n [...leftHashes].every(([filePath, hash]) => rightHashes.get(filePath) === hash)\n );\n}\n\nfunction snapshotId() {\n return `${new Date().toISOString().replace(/[:.]/g, \"-\")}-${randomUUID().slice(0, 8)}`;\n}\n\nexport function regenerateSnapshotIdentity(snapshot: Snapshot): Snapshot {\n return {\n ...snapshot,\n id: snapshotId(),\n createdAt: new Date().toISOString(),\n machine: os.hostname(),\n };\n}\n\nexport async function createSnapshot(profile: string, options: SnapshotOptions = {}): Promise<Snapshot> {\n options.signal?.throwIfAborted();\n const include = effectiveInclude(options);\n const syncSessions = include.includes(\"sessions\");\n const sessionDir = options.sessionDir ?? (await configuredSessionDir());\n options.signal?.throwIfAborted();\n const files = await collectFiles(agentDir(), { include, sessionDir, signal: options.signal });\n options.signal?.throwIfAborted();\n return {\n version: VERSION,\n id: snapshotId(),\n createdAt: new Date().toISOString(),\n machine: os.hostname(),\n profile,\n syncSessions,\n selection: selectionForSnapshot(include),\n files,\n };\n}\n\nfunction effectiveInclude(options: SnapshotOptions) {\n if (options.include) return options.include;\n return [\n ...normalizeSyncFiles(options.syncFiles),\n ...normalizeExtraFiles(options.extraFiles),\n ...(options.syncSessions ? [\"sessions\"] : []),\n ];\n}\n\nexport async function collectFiles(root: string, options: SnapshotOptions = {}): Promise<SnapshotFile[]> {\n const signal = options.signal;\n signal?.throwIfAborted();\n const results: SnapshotFile[] = [];\n const entries = await fs.readdir(root, { withFileTypes: true });\n signal?.throwIfAborted();\n const selection = syncIncludeSelection(effectiveInclude(options));\n const selectedFiles = new Set<string>(selection.builtIns);\n for (const entry of entries) {\n if (entry.isDirectory() && TOP_LEVEL_DIRS.has(entry.name) && selectedFiles.has(entry.name)) {\n await collectDirectory(results, root, entry.name, { signal });\n }\n }\n for (const fileName of TOP_LEVEL_FILES) {\n if (!selectedFiles.has(fileName)) continue;\n const entry = selectTopLevelFileEntry(entries, fileName);\n if (entry) await addFile(results, root, entry.name, fileName, signal);\n }\n for (const relativePath of selection.custom) {\n await collectIncludedPath(results, root, relativePath, signal);\n }\n if (selection.sessions) {\n try {\n await collectDirectory(results, sessionStorageRoot(root, options.sessionDir), \"\", {\n sessionsOnly: true,\n virtualPrefix: \"sessions\",\n signal,\n });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n }\n }\n signal?.throwIfAborted();\n return results.sort((left, right) => left.path.localeCompare(right.path));\n}\n\nasync function collectIncludedPath(results: SnapshotFile[], root: string, relativePath: string, signal?: AbortSignal) {\n signal?.throwIfAborted();\n const absolutePath = safeJoin(root, relativePath);\n try {\n const stat = await fs.lstat(absolutePath);\n signal?.throwIfAborted();\n if (stat.isFile()) await addFile(results, root, relativePath, relativePath, signal);\n else if (stat.isDirectory()) await collectDirectory(results, root, relativePath, { signal });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n if (!relativePath.includes(\"/\")) {\n const entries = await fs.readdir(root, { withFileTypes: true });\n signal?.throwIfAborted();\n const entry = selectTopLevelFileEntry(entries, relativePath);\n if (entry) await addFile(results, root, entry.name, relativePath, signal);\n }\n }\n}\n\nasync function collectDirectory(\n results: SnapshotFile[],\n root: string,\n relativeDirectory: string,\n options: { sessionsOnly?: boolean; virtualPrefix?: string; signal?: AbortSignal } = {},\n) {\n options.signal?.throwIfAborted();\n const absoluteDirectory = path.join(root, relativeDirectory);\n for (const entry of await fs.readdir(absoluteDirectory, { withFileTypes: true })) {\n options.signal?.throwIfAborted();\n const relativePath = relativeDirectory ? posixJoin(relativeDirectory, entry.name) : entry.name;\n const snapshotPath = options.virtualPrefix ? posixJoin(options.virtualPrefix, relativePath) : relativePath;\n if (isDeniedPath(snapshotPath)) continue;\n if (entry.isDirectory()) {\n await collectDirectory(results, root, relativePath, options);\n } else if (entry.isFile() && (!options.sessionsOnly || isSessionFilePath(snapshotPath))) {\n await addFile(results, root, relativePath, snapshotPath, options.signal);\n }\n }\n}\n\nasync function addFile(\n results: SnapshotFile[],\n root: string,\n relativePath: string,\n snapshotPath = relativePath,\n signal?: AbortSignal,\n) {\n signal?.throwIfAborted();\n if (!isSafeSnapshotPath(snapshotPath)) return;\n const absolutePath = safeJoin(root, relativePath);\n const content = await fs.readFile(absolutePath, { signal });\n signal?.throwIfAborted();\n results.push({\n path: snapshotPath,\n contentBase64: content.toString(\"base64\"),\n sha256: sha256(content),\n });\n}\n\nexport function isSessionPath(relativePath: string) {\n return toPosix(relativePath).startsWith(\"sessions/\");\n}\n\nexport function isSessionFilePath(relativePath: string) {\n const normalized = toPosix(relativePath);\n return isSessionPath(normalized) && normalized.endsWith(\".jsonl\");\n}\n\nexport function sessionSnapshotPathFromAbsolute(sessionFile: string, configuredSessionDir?: string) {\n const relativePath = toPosix(path.relative(sessionStorageRoot(agentDir(), configuredSessionDir), sessionFile));\n if (!relativePath || relativePath.startsWith(\"../\") || path.posix.isAbsolute(relativePath)) {\n return undefined;\n }\n const snapshotPath = posixJoin(\"sessions\", relativePath);\n return isSessionFilePath(snapshotPath) ? snapshotPath : undefined;\n}\n\nexport function snapshotTarget(root: string, relativePath: string, configuredSessionDir?: string) {\n if (isSessionPath(relativePath)) {\n return safeJoin(sessionStorageRoot(root, configuredSessionDir), relativePath.slice(\"sessions/\".length));\n }\n return safeJoin(root, relativePath);\n}\n\nexport function snapshotIncludesSessions(snapshot: Snapshot) {\n return (\n snapshot.syncSessions === true ||\n snapshotSelectionInclude(snapshot)?.includes(\"sessions\") === true ||\n snapshot.files.some((file) => isSessionPath(file.path))\n );\n}\n\nexport function filterSnapshotForConfigPolicy(\n snapshot: Snapshot,\n config: SyncSelectionConfig,\n options: { regenerateId?: boolean } = {},\n) {\n const include = includeFromSelectionConfig(config);\n const includePaths = customIncludePathsByLower(include);\n const filtered = {\n ...snapshot,\n syncSessions: include.includes(\"sessions\") ? snapshot.syncSessions : false,\n selection: selectionForSnapshot(include),\n files: canonicalizeSnapshotFilesForConfig(snapshot.files, config, includePaths),\n };\n if (!options.regenerateId || snapshotsMatch(snapshot, filtered)) return filtered;\n return {\n ...filtered,\n id: snapshotId(),\n createdAt: new Date().toISOString(),\n machine: os.hostname(),\n };\n}\n\nfunction canonicalizeSnapshotFilesForConfig(\n files: SnapshotFile[],\n config: SyncSelectionConfig,\n includePaths: Map<string, string>,\n) {\n const configuredFiles: SnapshotFile[] = [];\n const extraCandidates = new Map<string, { exact: boolean; file: SnapshotFile; originalPath: string }>();\n for (const file of files) {\n const normalized = toPosix(file.path);\n if (!isSafeSnapshotPath(file.path) || !isConfiguredSnapshotPath(normalized, config)) {\n continue;\n }\n if (normalized.includes(\"/\")) {\n configuredFiles.push(normalized === file.path ? file : { ...file, path: normalized });\n continue;\n }\n const topLevelPath = canonicalSnapshotPathForConfig(normalized, includePaths);\n const candidate = {\n exact: normalized === topLevelPath,\n file: { ...file, path: topLevelPath },\n originalPath: normalized,\n };\n const current = extraCandidates.get(topLevelPath.toLowerCase());\n if (!current || isPreferredExtraCandidate(candidate, current)) {\n extraCandidates.set(topLevelPath.toLowerCase(), candidate);\n }\n }\n return [...configuredFiles, ...[...extraCandidates.values()].map((candidate) => candidate.file)].sort((left, right) =>\n left.path.localeCompare(right.path),\n );\n}\n\nfunction isPreferredExtraCandidate(\n left: { exact: boolean; originalPath: string },\n right: { exact: boolean; originalPath: string },\n) {\n if (left.exact !== right.exact) return left.exact;\n return left.originalPath.localeCompare(right.originalPath) < 0;\n}\n\nexport function snapshotWithoutSessions(snapshot: Snapshot) {\n const files = snapshot.files.filter((file) => !isSessionPath(file.path));\n const include = snapshotSelectionInclude(snapshot)?.filter((item) => item !== \"sessions\");\n if (\n files.length === snapshot.files.length &&\n snapshot.syncSessions !== true &&\n include?.length === snapshot.selection?.include.length\n ) {\n return snapshot;\n }\n return {\n ...snapshot,\n id: snapshotId(),\n createdAt: new Date().toISOString(),\n machine: os.hostname(),\n syncSessions: false,\n ...(include ? { selection: selectionForSnapshot(include) } : {}),\n files,\n };\n}\n\nexport function scanSnapshot(snapshot: Snapshot) {\n const findings: string[] = [];\n for (const file of snapshot.files) {\n const content = Buffer.from(file.contentBase64, \"base64\");\n if (content.includes(0)) continue;\n const text = content.toString(\"utf8\");\n for (const pattern of SECRET_PATTERNS) {\n if (pattern.test(text)) {\n findings.push(file.path);\n break;\n }\n }\n }\n return findings;\n}\n\nexport function mergeRemotePreservedFiles(local: Snapshot, remote: Snapshot, config: SyncSelectionConfig) {\n const localPathNames = new Set(local.files.map((file) => file.path.toLowerCase()));\n const preservedPathNames = new Set<string>();\n const preserved = remote.files.filter((file) => {\n const normalized = toPosix(file.path);\n const lower = normalized.toLowerCase();\n if (\n localPathNames.has(lower) ||\n preservedPathNames.has(lower) ||\n !isSafeSnapshotPath(file.path) ||\n isConfiguredSnapshotPath(normalized, config) ||\n !isPreservableUnmanagedSnapshotPath(normalized)\n ) {\n return false;\n }\n preservedPathNames.add(lower);\n return true;\n });\n if (preserved.length === 0) return local;\n return {\n ...local,\n id: snapshotId(),\n createdAt: new Date().toISOString(),\n machine: os.hostname(),\n syncSessions: snapshotIncludesSessions(local) || snapshotIncludesSessions(remote),\n files: [...local.files, ...preserved].sort((left, right) => left.path.localeCompare(right.path)),\n };\n}\n\nexport function mergeRemoteSessionFiles(local: Snapshot, remote: Snapshot) {\n const remoteSessions = remote.files.filter((file) => {\n const normalized = toPosix(file.path);\n return isSessionFilePath(normalized) && isSafeSnapshotPath(file.path);\n });\n if (remoteSessions.length === 0 && !snapshotIncludesSessions(remote)) return local;\n const localInclude = snapshotSelectionInclude(local);\n return {\n ...local,\n id: snapshotId(),\n createdAt: new Date().toISOString(),\n machine: os.hostname(),\n syncSessions: true,\n ...(localInclude\n ? {\n selection: selectionForSnapshot(\n localInclude.includes(\"sessions\") ? localInclude : [...localInclude, \"sessions\"],\n ),\n }\n : {}),\n files: [...local.files.filter((file) => !isSessionPath(file.path)), ...remoteSessions].sort((left, right) =>\n left.path.localeCompare(right.path),\n ),\n };\n}\n\nfunction sameOptionalInclude(left: string[] | undefined, right: string[] | undefined) {\n if (!left || !right) return left === right;\n return left.length === right.length && left.every((item, index) => item === right[index]);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,kBAAkB;AAEvC,OAAO,QAAQ;AACf,OAAO,QAAQ;AACf,OAAO,UAAU;AA0BjB,IAAM,UAAU;AAChB,IAAM,kBAAqC,qBAAqB,OAAO,CAAC,SAAS,KAAK,SAAS,GAAG,CAAC;AACnG,IAAM,iBAAiB,IAAI,IAAY,qBAAqB,OAAO,CAAC,SAAS,CAAC,KAAK,SAAS,GAAG,CAAC,CAAC;AACjG,IAAM,kBAAkB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAAS,wBAAwB,SAAmB,UAAkB;AACpE,QAAM,QAAQ,QAAQ,KAAK,CAAC,UAAU,MAAM,OAAO,KAAK,MAAM,SAAS,QAAQ;AAC/E,MAAI,MAAO,QAAO;AAClB,QAAM,QAAQ,SAAS,YAAY;AACnC,SAAO,QACJ,OAAO,CAAC,UAAU,MAAM,OAAO,KAAK,MAAM,KAAK,YAAY,MAAM,KAAK,EACtE,KAAK,CAAC,MAAM,UAAU,KAAK,KAAK,cAAc,MAAM,IAAI,CAAC,EAAE,CAAC;AACjE;AAEA,SAAS,OAAO,OAAe;AAC7B,SAAO,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK;AACxD;AAEA,SAAS,mBAAmB,cAAsB;AAChD,MAAI,aAAa,SAAS,IAAI,EAAG,QAAO;AACxC,QAAM,aAAa,QAAQ,YAAY;AACvC,SACE,QAAQ,UAAU,KAClB,eAAe,OACf,e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B,OAAiB,QAAkB;AACzE,QAAM,iBAAiB,OAAO,MAAM,OAAO,CAAC,SAAS;AACnD,UAAM,aAAa,QAAQ,KAAK,IAAI;AACpC,WAAO,kBAAkB,UAAU,KAAK,mBAAmB,KAAK,IAAI;AAAA,EACtE,CAAC;AACD,MAAI,eAAe,WAAW,KAAK,CAAC,yBAAyB,MAAM,EAAG,QAAO;AAC7E,QAAM,eAAe,yBAAyB,KAAK;AACnD,SAAO;AAAA,IACL,GAAG;AAAA,IACH,IAAI,WAAW;AAAA,IACf,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,IAClC,SAAS,GAAG,SAAS;AAAA,IACrB,cAAc;AAAA,IACd,GAAI,eACA;AAAA,MACE,WAAW;AAAA,QACT,aAAa,SAAS,UAAU,IAAI,eAAe,CAAC,GAAG,cAAc,UAAU;AAAA,MACjF;AAAA,IACF,IACA,CAAC;AAAA,IACL,OAAO,CAAC,GAAG,MAAM,MAAM,OAAO,CAAC,SAAS,CAAC,cAAc,KAAK,IAAI,CAAC,GAAG,GAAG,cAAc,EAAE;AAAA,MAAK,CAAC,MAAM,UACjG,KAAK,KAAK,cAAc,MAAM,IAAI;AAAA,IACpC;AAAA,EACF;AACF;AAEA,SAAS,oBAAoB,MAA4B,OAA6B;AACpF,MAAI,CAAC,QAAQ,CAAC,MAAO,QAAO,SAAS;AACrC,SAAO,KAAK,WAAW,MAAM,UAAU,KAAK,MAAM,CAAC,MAAM,UAAU,SAAS,MAAM,KAAK,CAAC;AAC1F;",
|
|
6
|
+
"names": ["configuredSessionDir"]
|
|
7
|
+
}
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
syncConfigReviewIdentity,
|
|
17
17
|
syncSetupReviewIdentity,
|
|
18
18
|
updateLocalConfig
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-RX3WGWVL.ts";
|
|
20
20
|
import {
|
|
21
21
|
throwIfAborted
|
|
22
22
|
} from "./chunk-PWMWOJP4.ts";
|
|
@@ -124,4 +124,4 @@ export {
|
|
|
124
124
|
saveOnSwitch,
|
|
125
125
|
useSyncSetup
|
|
126
126
|
};
|
|
127
|
-
//# sourceMappingURL=chunk-
|
|
127
|
+
//# sourceMappingURL=chunk-PWA3YN5Z.ts.map
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
2
|
// @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
|
|
3
|
+
import {
|
|
4
|
+
sameLocalFields,
|
|
5
|
+
validatePortableSnapshot
|
|
6
|
+
} from "./chunk-UGSSZWQ6.ts";
|
|
3
7
|
import {
|
|
4
8
|
safeTerminalText
|
|
5
9
|
} from "./chunk-AMJRUXFT.ts";
|
|
6
10
|
import {
|
|
7
11
|
syncConfigReviewFingerprint
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import {
|
|
10
|
-
sameLocalFields,
|
|
11
|
-
validatePortableSnapshot
|
|
12
|
-
} from "./chunk-A6HU4ERM.ts";
|
|
12
|
+
} from "./chunk-RX3WGWVL.ts";
|
|
13
13
|
import {
|
|
14
14
|
throwIfAborted
|
|
15
15
|
} from "./chunk-PWMWOJP4.ts";
|
|
16
16
|
import {
|
|
17
|
-
filterSnapshotForConfigPolicy
|
|
17
|
+
filterSnapshotForConfigPolicy
|
|
18
|
+
} from "./chunk-PHANBTVM.ts";
|
|
19
|
+
import {
|
|
18
20
|
inspectRemoteSelection,
|
|
19
21
|
remoteSelectionMismatch,
|
|
20
22
|
sameSyncInclude,
|
|
21
23
|
snapshotSelectionInclude
|
|
22
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-DFJGTVPX.ts";
|
|
23
25
|
|
|
24
26
|
// src/sync/remote-snapshot.ts
|
|
25
27
|
async function readSnapshotForHead(backend, head, signal) {
|
|
@@ -84,4 +86,4 @@ export {
|
|
|
84
86
|
formatRemoteSelectionStatus,
|
|
85
87
|
readRemoteSnapshot
|
|
86
88
|
};
|
|
87
|
-
//# sourceMappingURL=chunk-
|
|
89
|
+
//# sourceMappingURL=chunk-QWV3XKNJ.ts.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/sync/remote-snapshot.ts"],
|
|
4
4
|
"sourcesContent": ["import type { RemoteHead, SyncBackend } from \"../backends/sync-backend.js\";\nimport { syncConfigReviewFingerprint } from \"../settings/config.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport { filterSnapshotForConfigPolicy } from \"../snapshot/snapshot.js\";\nimport type { Snapshot } from \"../snapshot/snapshot-types.js\";\nimport { safeTerminalText } from \"../ui/terminal-text.js\";\nimport { sameLocalFields, validatePortableSnapshot } from \"./local-fields.js\";\nimport { throwIfAborted } from \"./signals.js\";\nimport {\n inspectRemoteSelection,\n type RemoteSelectionState,\n remoteSelectionMismatch,\n sameSyncInclude,\n snapshotSelectionInclude,\n} from \"./sync-policy.js\";\n\nexport async function readSnapshotForHead(backend: SyncBackend, head: RemoteHead, signal?: AbortSignal) {\n const snapshot = await backend.readSnapshot(head.snapshotRef, signal);\n throwIfAborted(signal);\n validatePortableSnapshot(snapshot);\n if (snapshot.id !== head.snapshotId) {\n throw new Error(`Remote head ${head.snapshotId} resolved to unexpected snapshot ${snapshot.id}.`);\n }\n if (head.selection) {\n const snapshotInclude = snapshotSelectionInclude(snapshot);\n if (!snapshotInclude || !sameSyncInclude(head.selection.include, snapshotInclude)) {\n throw new Error(\"Remote head selection does not match its immutable snapshot.\");\n }\n }\n return snapshot;\n}\n\nexport function requireCompatibleRemoteSelection(config: AnySyncConfig, snapshot: Snapshot) {\n if (!sameLocalFields(config.localFields, snapshot.localFields))\n throw new Error(\n \"Remote local-field policy differs; confirm a reviewed directional migration. Old history is not erased.\",\n );\n const state = inspectRemoteSelection(config.include, snapshot);\n if (state.kind === \"different\") {\n throw remoteSelectionMismatch(config, state.include, syncConfigReviewFingerprint(config));\n }\n}\n\nexport function formatRemoteSelectionStatus(state: RemoteSelectionState | undefined) {\n if (!state) return \"remote included content: unavailable (remote is empty)\";\n if (state.kind === \"same\") return \"remote included content: matches this setup\";\n if (state.kind === \"legacy\") {\n return `remote included content: unavailable in legacy snapshot (${state.discovered.length} path${state.discovered.length === 1 ? \"\" : \"s\"} discovered, partial)`;\n }\n return [\n \"remote included content: differs from this setup\",\n `remote-only selection: ${safeList(state.remoteOnly)}`,\n `local-only selection: ${safeList(state.localOnly)}`,\n ].join(\"\\n\");\n}\n\nfunction safeList(values: readonly string[]) {\n return values.length > 0 ? values.map(safeTerminalText).join(\", \") : \"none\";\n}\n\nexport async function readRemoteSnapshot(\n backend: SyncBackend,\n config: AnySyncConfig,\n signal?: AbortSignal,\n options: { allowSelectionDifference?: boolean } = {},\n) {\n const head = await backend.readHead(signal);\n if (!head) return { head: undefined, snapshot: undefined, selectionState: undefined };\n const snapshot = await readSnapshotForHead(backend, head, signal);\n const selectionState = inspectRemoteSelection(config.include, snapshot);\n if (!options.allowSelectionDifference && selectionState.kind === \"different\") {\n const configIdentity = syncConfigReviewFingerprint(config);\n throw remoteSelectionMismatch(config, selectionState.include, configIdentity);\n }\n return {\n head,\n snapshot: filterSnapshotForConfigPolicy(snapshot, config),\n selectionState,\n };\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,eAAsB,oBAAoB,SAAsB,MAAkB,QAAsB;AACtG,QAAM,WAAW,MAAM,QAAQ,aAAa,KAAK,aAAa,MAAM;AACpE,iBAAe,MAAM;AACrB,2BAAyB,QAAQ;AACjC,MAAI,SAAS,OAAO,KAAK,YAAY;AACnC,UAAM,IAAI,MAAM,eAAe,KAAK,UAAU,oCAAoC,SAAS,EAAE,GAAG;AAAA,EAClG;AACA,MAAI,KAAK,WAAW;AAClB,UAAM,kBAAkB,yBAAyB,QAAQ;AACzD,QAAI,CAAC,mBAAmB,CAAC,gBAAgB,KAAK,UAAU,SAAS,eAAe,G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