@narumitw/pi-sync 0.50.2 → 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/chunks/{chunk-6LP3MCR2.ts → chunk-2JZFHNLM.ts} +3 -5
- package/dist/chunks/chunk-2JZFHNLM.ts.map +7 -0
- package/dist/chunks/{chunk-LCRI3ABW.ts → chunk-2RZSQWBH.ts} +8 -19
- package/dist/chunks/chunk-2RZSQWBH.ts.map +7 -0
- package/dist/chunks/{chunk-IJ6FJFA5.ts → chunk-4AIHXRKE.ts} +11 -17
- package/dist/chunks/chunk-4AIHXRKE.ts.map +7 -0
- package/dist/chunks/{chunk-C7XY5NF5.ts → chunk-4MPIH46N.ts} +29 -51
- package/dist/chunks/chunk-4MPIH46N.ts.map +7 -0
- package/dist/chunks/{chunk-5B3FXBLE.ts → chunk-6546TS54.ts} +16 -20
- package/dist/chunks/chunk-6546TS54.ts.map +7 -0
- package/dist/chunks/{chunk-Q2TUM5X6.ts → chunk-6NT3YFGY.ts} +2 -2
- package/dist/chunks/chunk-6NT3YFGY.ts.map +7 -0
- package/dist/chunks/{chunk-2B2ELUF5.ts → chunk-7D5SF7P3.ts} +1 -1
- package/dist/chunks/chunk-7D5SF7P3.ts.map +7 -0
- package/dist/chunks/{chunk-4CHTZMEO.ts → chunk-7KHKWL3Q.ts} +37 -55
- package/dist/chunks/chunk-7KHKWL3Q.ts.map +7 -0
- package/dist/chunks/{chunk-ZI5MXMEX.ts → chunk-BVVP33U5.ts} +2 -4
- package/dist/chunks/chunk-BVVP33U5.ts.map +7 -0
- package/dist/chunks/{chunk-SZWBGPID.ts → chunk-DM4X4FIA.ts} +8 -13
- package/dist/chunks/chunk-DM4X4FIA.ts.map +7 -0
- package/dist/chunks/{chunk-SL64RLXR.ts → chunk-DZUSTGQV.ts} +8 -16
- package/dist/chunks/chunk-DZUSTGQV.ts.map +7 -0
- package/dist/chunks/{chunk-G4RNQQZS.ts → chunk-E42GXD6D.ts} +13 -19
- package/dist/chunks/chunk-E42GXD6D.ts.map +7 -0
- package/dist/chunks/{chunk-Z4DQF6L3.ts → chunk-ECYCNZOE.ts} +1 -1
- package/dist/chunks/chunk-ECYCNZOE.ts.map +7 -0
- package/dist/chunks/{chunk-OEX4ABY6.ts → chunk-EEJPYTWE.ts} +11 -21
- package/dist/chunks/chunk-EEJPYTWE.ts.map +7 -0
- package/dist/chunks/{chunk-CPEHGXJV.ts → chunk-G4RUXRWZ.ts} +3 -5
- package/dist/chunks/chunk-G4RUXRWZ.ts.map +7 -0
- package/dist/chunks/{chunk-T2B5IU74.ts → chunk-HGJH56KR.ts} +4 -4
- package/dist/chunks/chunk-HGJH56KR.ts.map +7 -0
- package/dist/chunks/{chunk-JAAKLL6M.ts → chunk-IVXEDPAD.ts} +10 -34
- package/dist/chunks/chunk-IVXEDPAD.ts.map +7 -0
- package/dist/chunks/chunk-K3RIEL6J.ts +20 -0
- package/dist/chunks/chunk-K3RIEL6J.ts.map +7 -0
- package/dist/chunks/{chunk-LTBWGSBV.ts → chunk-MSSW6F3R.ts} +1 -1
- package/dist/chunks/chunk-MSSW6F3R.ts.map +7 -0
- package/dist/chunks/{chunk-T3HH3UEJ.ts → chunk-OVDTF5CH.ts} +4 -10
- package/dist/chunks/chunk-OVDTF5CH.ts.map +7 -0
- package/dist/chunks/{chunk-NJFUIVYL.ts → chunk-PWMWOJP4.ts} +1 -1
- package/dist/chunks/chunk-PWMWOJP4.ts.map +7 -0
- package/dist/chunks/{chunk-HUDQATCL.ts → chunk-Q32CQWPM.ts} +6 -8
- package/dist/chunks/chunk-Q32CQWPM.ts.map +7 -0
- package/dist/chunks/{chunk-ETTRJDNP.ts → chunk-QLSN7AGX.ts} +6 -13
- package/dist/chunks/chunk-QLSN7AGX.ts.map +7 -0
- package/dist/chunks/{chunk-THMF4BVL.ts → chunk-SWUXA3MH.ts} +1 -1
- package/dist/chunks/chunk-SWUXA3MH.ts.map +7 -0
- package/dist/chunks/{chunk-TEN2ZBJV.ts → chunk-T2SJD3N7.ts} +2 -4
- package/dist/chunks/chunk-T2SJD3N7.ts.map +7 -0
- package/dist/chunks/{chunk-AUSDLD6F.ts → chunk-T56RNRZJ.ts} +10 -26
- package/dist/chunks/chunk-T56RNRZJ.ts.map +7 -0
- package/dist/chunks/{chunk-KW7YQEZN.ts → chunk-UA7RXOIT.ts} +48 -100
- package/dist/chunks/chunk-UA7RXOIT.ts.map +7 -0
- package/dist/chunks/{chunk-D5X27LCA.ts → chunk-UETBKTDI.ts} +1 -1
- package/dist/chunks/chunk-UETBKTDI.ts.map +7 -0
- package/dist/chunks/{chunk-CHH26D4F.ts → chunk-YFADF5ZQ.ts} +7 -6
- package/dist/chunks/chunk-YFADF5ZQ.ts.map +7 -0
- package/dist/chunks/{chunk-CCSN3F47.ts → chunk-YPXGU5OR.ts} +4 -4
- package/dist/chunks/chunk-YPXGU5OR.ts.map +7 -0
- package/dist/chunks/{file-selection-FTTKAOYX.ts → file-selection-RAVHRYFG.ts} +14 -26
- package/dist/chunks/file-selection-RAVHRYFG.ts.map +7 -0
- package/dist/chunks/{git-backend-GMVS4PD4.ts → git-backend-IAANDL3K.ts} +41 -104
- package/dist/chunks/git-backend-IAANDL3K.ts.map +7 -0
- package/dist/chunks/manager-result-dispatcher-OTUMQM26.ts +23 -0
- package/dist/chunks/{manager-ui-5KLKVMRC.ts → manager-ui-763NEKJY.ts} +124 -251
- package/dist/chunks/manager-ui-763NEKJY.ts.map +7 -0
- package/dist/chunks/remote-selection-ui-TZTJF32Y.ts +22 -0
- package/dist/chunks/{s3-backend-66O4FGBH.ts → s3-backend-XGXUOPUN.ts} +23 -54
- package/dist/chunks/s3-backend-XGXUOPUN.ts.map +7 -0
- package/dist/chunks/{setup-switch-IS2PEZ3J.ts → setup-switch-5G2VNJHL.ts} +9 -9
- package/dist/chunks/{setup-wizard-IUB6ESEU.ts → setup-wizard-YIEWGX32.ts} +12 -12
- package/dist/chunks/setup-wizard-YIEWGX32.ts.map +7 -0
- package/dist/chunks/{snapshot-HKEWCVK6.ts → snapshot-JL5DFSXI.ts} +5 -5
- package/dist/chunks/sync-inspection-P3ENJLNF.ts +20 -0
- package/dist/chunks/{sync-operations-LBX3GKCM.ts → sync-operations-AR76EB6C.ts} +85 -201
- package/dist/chunks/sync-operations-AR76EB6C.ts.map +7 -0
- package/dist/chunks/{sync-state-Q2FTXTW6.ts → sync-state-VHJUZ4YG.ts} +6 -6
- package/dist/chunks/{webdav-backend-ECIKD7SO.ts → webdav-backend-3EGUONAT.ts} +20 -51
- package/dist/chunks/webdav-backend-3EGUONAT.ts.map +7 -0
- package/dist/index.ts +49 -74
- package/dist/index.ts.map +3 -3
- package/docs/settings.md +9 -0
- package/package.json +61 -62
- package/src/backends/backend-factory.ts +15 -15
- package/src/backends/backend-identity.ts +31 -31
- package/src/backends/backend-types.ts +42 -42
- package/src/backends/git/git-backend.ts +714 -788
- package/src/backends/git/git-config.ts +104 -111
- package/src/backends/git/git-runner.ts +230 -247
- package/src/backends/git/git-storage.ts +228 -245
- package/src/backends/s3/s3-backend.ts +408 -441
- package/src/backends/s3/s3-client.ts +288 -333
- package/src/backends/sync-backend.ts +65 -65
- package/src/backends/webdav/webdav-backend.ts +542 -589
- package/src/backends/webdav/webdav-client.ts +292 -316
- package/src/backends/webdav/webdav-config.ts +57 -68
- package/src/commands/command-execution.ts +270 -289
- package/src/commands/command-handler.ts +160 -163
- package/src/commands/command-types.ts +13 -13
- package/src/commands/command.ts +190 -196
- package/src/commands/setup-completions.ts +1 -1
- package/src/paths.ts +47 -47
- package/src/settings/config-errors.ts +4 -5
- package/src/settings/config-file.ts +473 -506
- package/src/settings/config.ts +171 -174
- package/src/settings/settings-management.ts +191 -216
- package/src/settings/settings-store.ts +63 -77
- package/src/settings/settings-types.ts +78 -75
- package/src/settings/settings-validation.ts +328 -364
- package/src/snapshot/session-paths.ts +41 -55
- package/src/snapshot/snapshot-apply.ts +197 -229
- package/src/snapshot/snapshot-codec.ts +29 -31
- package/src/snapshot/snapshot-paths.ts +4 -6
- package/src/snapshot/snapshot-transaction.ts +161 -170
- package/src/snapshot/snapshot-types.ts +24 -24
- package/src/snapshot/snapshot.ts +310 -343
- package/src/state/json-file.ts +11 -11
- package/src/state/lock.ts +226 -242
- package/src/state/lockfile-fs.ts +20 -20
- package/src/state/operation-availability.ts +36 -41
- package/src/state/state-directory.ts +171 -173
- package/src/state/state-types.ts +15 -15
- package/src/state/sync-state-store.ts +23 -23
- package/src/sync/automatic-sync.ts +75 -80
- package/src/sync/remote-snapshot.ts +52 -60
- package/src/sync/setup-switch.ts +99 -114
- package/src/sync/signals.ts +3 -5
- package/src/sync/startup-check.ts +97 -111
- package/src/sync/sync-decision.ts +76 -80
- package/src/sync/sync-error-guidance.ts +41 -48
- package/src/sync/sync-errors.ts +10 -10
- package/src/sync/sync-inspection.ts +29 -33
- package/src/sync/sync-loaders.ts +28 -36
- package/src/sync/sync-mutations.ts +510 -622
- package/src/sync/sync-operations.ts +7 -7
- package/src/sync/sync-policy.ts +296 -326
- package/src/sync/sync-queries.ts +175 -194
- package/src/sync/sync-state.ts +74 -100
- package/src/sync-extension.ts +89 -101
- package/src/sync.ts +26 -26
- package/src/types.ts +37 -37
- package/src/ui/automatic-sync-summary.ts +1 -3
- package/src/ui/cancellable-operation.ts +92 -112
- package/src/ui/file-selection.ts +250 -274
- package/src/ui/manager-attention.ts +51 -63
- package/src/ui/manager-recovery.ts +48 -57
- package/src/ui/manager-result-dispatcher.ts +62 -76
- package/src/ui/manager-state.ts +200 -232
- package/src/ui/manager-ui.ts +264 -362
- package/src/ui/remote-selection-ui.ts +547 -588
- package/src/ui/secret-input.ts +198 -214
- package/src/ui/settings-ui.ts +175 -172
- package/src/ui/setup/git-ui.ts +232 -261
- package/src/ui/setup/s3-credentials-ui.ts +58 -65
- package/src/ui/setup/s3-ui.ts +171 -195
- package/src/ui/setup/setup-actions.ts +91 -101
- package/src/ui/setup/setup-location-ui.ts +121 -137
- package/src/ui/setup/setup-name-ui.ts +27 -27
- package/src/ui/setup/setup-prompts.ts +65 -65
- package/src/ui/setup/setup-review.ts +58 -59
- package/src/ui/setup/setup-switcher.ts +156 -160
- package/src/ui/setup/setup-wizard.ts +28 -28
- package/src/ui/setup/text-input.ts +54 -58
- package/src/ui/setup/webdav-ui.ts +246 -293
- package/src/ui/storage-connections-ui.ts +317 -369
- package/src/ui/sync-attention.ts +148 -164
- package/src/ui/sync-format.ts +110 -121
- package/src/ui/sync-resolution-ui.ts +147 -153
- package/src/ui/sync-setups-ui.ts +218 -238
- package/src/ui/sync-status.ts +17 -0
- package/src/ui/terminal-text.ts +2 -2
- package/dist/chunks/chunk-2B2ELUF5.ts.map +0 -7
- package/dist/chunks/chunk-4CHTZMEO.ts.map +0 -7
- package/dist/chunks/chunk-5B3FXBLE.ts.map +0 -7
- package/dist/chunks/chunk-6LP3MCR2.ts.map +0 -7
- package/dist/chunks/chunk-AUSDLD6F.ts.map +0 -7
- package/dist/chunks/chunk-C7XY5NF5.ts.map +0 -7
- package/dist/chunks/chunk-CCSN3F47.ts.map +0 -7
- package/dist/chunks/chunk-CHH26D4F.ts.map +0 -7
- package/dist/chunks/chunk-CPEHGXJV.ts.map +0 -7
- package/dist/chunks/chunk-D5X27LCA.ts.map +0 -7
- package/dist/chunks/chunk-ETTRJDNP.ts.map +0 -7
- package/dist/chunks/chunk-G4RNQQZS.ts.map +0 -7
- package/dist/chunks/chunk-HUDQATCL.ts.map +0 -7
- package/dist/chunks/chunk-IJ6FJFA5.ts.map +0 -7
- package/dist/chunks/chunk-JAAKLL6M.ts.map +0 -7
- package/dist/chunks/chunk-KW7YQEZN.ts.map +0 -7
- package/dist/chunks/chunk-LCRI3ABW.ts.map +0 -7
- package/dist/chunks/chunk-LTBWGSBV.ts.map +0 -7
- package/dist/chunks/chunk-NJFUIVYL.ts.map +0 -7
- package/dist/chunks/chunk-OEX4ABY6.ts.map +0 -7
- package/dist/chunks/chunk-Q2TUM5X6.ts.map +0 -7
- package/dist/chunks/chunk-SL64RLXR.ts.map +0 -7
- package/dist/chunks/chunk-SZWBGPID.ts.map +0 -7
- package/dist/chunks/chunk-T2B5IU74.ts.map +0 -7
- package/dist/chunks/chunk-T3HH3UEJ.ts.map +0 -7
- package/dist/chunks/chunk-TEN2ZBJV.ts.map +0 -7
- package/dist/chunks/chunk-THMF4BVL.ts.map +0 -7
- package/dist/chunks/chunk-Z4DQF6L3.ts.map +0 -7
- package/dist/chunks/chunk-ZI5MXMEX.ts.map +0 -7
- package/dist/chunks/file-selection-FTTKAOYX.ts.map +0 -7
- package/dist/chunks/git-backend-GMVS4PD4.ts.map +0 -7
- package/dist/chunks/manager-result-dispatcher-FKIBM3GO.ts +0 -22
- package/dist/chunks/manager-ui-5KLKVMRC.ts.map +0 -7
- package/dist/chunks/remote-selection-ui-D7RBRJNL.ts +0 -21
- package/dist/chunks/s3-backend-66O4FGBH.ts.map +0 -7
- package/dist/chunks/setup-wizard-IUB6ESEU.ts.map +0 -7
- package/dist/chunks/sync-inspection-CST2KL65.ts +0 -20
- package/dist/chunks/sync-operations-LBX3GKCM.ts.map +0 -7
- package/dist/chunks/webdav-backend-ECIKD7SO.ts.map +0 -7
- /package/dist/chunks/{manager-result-dispatcher-FKIBM3GO.ts.map → manager-result-dispatcher-OTUMQM26.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-D7RBRJNL.ts.map → remote-selection-ui-TZTJF32Y.ts.map} +0 -0
- /package/dist/chunks/{setup-switch-IS2PEZ3J.ts.map → setup-switch-5G2VNJHL.ts.map} +0 -0
- /package/dist/chunks/{snapshot-HKEWCVK6.ts.map → snapshot-JL5DFSXI.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-CST2KL65.ts.map → sync-inspection-P3ENJLNF.ts.map} +0 -0
- /package/dist/chunks/{sync-state-Q2FTXTW6.ts.map → sync-state-VHJUZ4YG.ts.map} +0 -0
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/sync/remote-snapshot.ts"],
|
|
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 {\n\tinspectRemoteSelection,\n\ttype RemoteSelectionState,\n\tremoteSelectionMismatch,\n\tsameSyncInclude,\n\tsnapshotSelectionInclude,\n} from \"./sync-policy.js\";\n\nexport async function readSnapshotForHead(\n\tbackend: SyncBackend,\n\thead: RemoteHead,\n\tsignal?: AbortSignal,\n) {\n\tconst snapshot = await backend.readSnapshot(head.snapshotRef, signal);\n\tif (signal?.aborted) {\n\t\tthrow signal.reason instanceof Error\n\t\t\t? signal.reason\n\t\t\t: new DOMException(\"The operation was aborted\", \"AbortError\");\n\t}\n\tif (snapshot.id !== head.snapshotId) {\n\t\tthrow new Error(\n\t\t\t`Remote head ${head.snapshotId} resolved to unexpected snapshot ${snapshot.id}.`,\n\t\t);\n\t}\n\tif (head.selection) {\n\t\tconst snapshotInclude = snapshotSelectionInclude(snapshot);\n\t\tif (!snapshotInclude || !sameSyncInclude(head.selection.include, snapshotInclude)) {\n\t\t\tthrow new Error(\"Remote head selection does not match its immutable snapshot.\");\n\t\t}\n\t}\n\treturn snapshot;\n}\n\nexport function requireCompatibleRemoteSelection(config: AnySyncConfig, snapshot: Snapshot) {\n\tconst state = inspectRemoteSelection(config.include, snapshot);\n\tif (state.kind === \"different\") {\n\t\tthrow remoteSelectionMismatch(config, state.include, syncConfigReviewFingerprint(config));\n\t}\n}\n\nexport function formatRemoteSelectionStatus(state: RemoteSelectionState | undefined) {\n\tif (!state) return \"remote included content: unavailable (remote is empty)\";\n\tif (state.kind === \"same\") return \"remote included content: matches this setup\";\n\tif (state.kind === \"legacy\") {\n\t\treturn `remote included content: unavailable in legacy snapshot (${state.discovered.length} path${state.discovered.length === 1 ? \"\" : \"s\"} discovered, partial)`;\n\t}\n\treturn [\n\t\t\"remote included content: differs from this setup\",\n\t\t`remote-only selection: ${safeList(state.remoteOnly)}`,\n\t\t`local-only selection: ${safeList(state.localOnly)}`,\n\t].join(\"\\n\");\n}\n\nfunction safeList(values: readonly string[]) {\n\treturn values.length > 0 ? values.map(safeTerminalText).join(\", \") : \"none\";\n}\n\nexport async function readRemoteSnapshot(\n\tbackend: SyncBackend,\n\tconfig: AnySyncConfig,\n\tsignal?: AbortSignal,\n\toptions: { allowSelectionDifference?: boolean } = {},\n) {\n\tconst head = await backend.readHead(signal);\n\tif (!head) return { head: undefined, snapshot: undefined, selectionState: undefined };\n\tconst snapshot = await readSnapshotForHead(backend, head, signal);\n\tconst selectionState = inspectRemoteSelection(config.include, snapshot);\n\tif (!options.allowSelectionDifference && selectionState.kind === \"different\") {\n\t\tconst configIdentity = syncConfigReviewFingerprint(config);\n\t\tthrow remoteSelectionMismatch(config, selectionState.include, configIdentity);\n\t}\n\treturn {\n\t\thead,\n\t\tsnapshot: filterSnapshotForConfigPolicy(snapshot, config),\n\t\tselectionState,\n\t};\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAcA,eAAsB,oBACrB,SACA,MACA,QACC;AACD,QAAM,WAAW,MAAM,QAAQ,aAAa,KAAK,aAAa,MAAM;AACpE,MAAI,QAAQ,SAAS;AACpB,UAAM,OAAO,kBAAkB,QAC5B,OAAO,SACP,IAAI,aAAa,6BAA6B,YAAY;AAAA,EAC9D;AACA,MAAI,SAAS,OAAO,KAAK,YAAY;AACpC,UAAM,IAAI;AAAA,MACT,eAAe,KAAK,UAAU,oCAAoC,SAAS,EAAE;AAAA,IAC9E;AAAA,EACD;AACA,MAAI,KAAK,WAAW;AACnB,UAAM,kBAAkB,yBAAyB,QAAQ;AACzD,QAAI,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IACN;AAAA,IACA,UAAU,8BAA8B,UAAU,MAAM;AAAA,IACxD;AAAA,EACD;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/snapshot/snapshot-transaction.ts"],
|
|
4
|
-
"sourcesContent": ["import { randomUUID } from \"node:crypto\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { assertWithinRoot, isPathInside } from \"../paths.js\";\nimport { withLock } from \"../state/lock.js\";\nimport { stateDir } from \"../state/state-directory.js\";\nimport { agentDir } from \"./session-paths.js\";\nimport { sessionStorageRoot } from \"./snapshot-paths.js\";\nimport type { SnapshotApplyPlan } from \"./snapshot-types.js\";\n\nconst JOURNAL_VERSION = 1;\n\ninterface TransactionEntry {\n\ttarget: string;\n\tbackupName: string;\n\tkind: \"missing\" | \"file\" | \"directory\" | \"symlink\";\n\tlinkTarget?: string;\n}\n\ninterface TransactionJournal {\n\tversion: number;\n\troot: string;\n\tsessionRoot?: string;\n\tentries: TransactionEntry[];\n}\n\nexport async function applySnapshotTransaction(\n\tplan: SnapshotApplyPlan,\n\toptions: { sessionDir?: string } = {},\n) {\n\tawait recoverPendingSnapshotTransactions();\n\tconst transaction = await prepareTransaction(plan, options.sessionDir);\n\ttry {\n\t\tfor (const target of plan.deletes) {\n\t\t\tawait fs.rm(target, { force: true, recursive: true });\n\t\t}\n\t\tfor (const item of plan.writes) {\n\t\t\tawait fs.mkdir(path.dirname(item.target), { recursive: true });\n\t\t\tawait fs.writeFile(item.target, item.content);\n\t\t}\n\t\tawait fs.rm(transaction.directory, { recursive: true, force: true });\n\t} catch (error) {\n\t\ttry {\n\t\t\tawait restoreTransaction(transaction.directory, transaction.journal);\n\t\t} catch (recoveryError) {\n\t\t\tthrow new AggregateError(\n\t\t\t\t[error, recoveryError],\n\t\t\t\t`Snapshot apply failed and automatic recovery also failed. Transaction retained at ${transaction.directory}.`,\n\t\t\t);\n\t\t}\n\t\tthrow error;\n\t}\n}\n\nexport async function recoverSnapshotTransactionsOnStartup() {\n\tif (!(await pendingTransactionEntries()).some((entry) => entry.isDirectory())) return;\n\tawait withLock(\"recovery\", recoverPendingSnapshotTransactions, { reclaimStale: true });\n}\n\nexport async function recoverPendingSnapshotTransactions() {\n\tconst directory = transactionRoot();\n\tconst entries = await pendingTransactionEntries();\n\tfor (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {\n\t\tif (!entry.isDirectory()) continue;\n\t\tconst transactionDirectory = path.join(directory, entry.name);\n\t\tconst journalPath = path.join(transactionDirectory, \"journal.json\");\n\t\tlet journal: TransactionJournal;\n\t\ttry {\n\t\t\tjournal = JSON.parse(await fs.readFile(journalPath, \"utf8\")) as TransactionJournal;\n\t\t} catch (error) {\n\t\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n\t\t\t\tawait fs.rm(transactionDirectory, { recursive: true, force: true });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthrow new Error(`Cannot recover malformed pi-sync transaction: ${journalPath}`, {\n\t\t\t\tcause: error,\n\t\t\t});\n\t\t}\n\t\tawait restoreTransaction(transactionDirectory, journal);\n\t}\n}\n\nasync function pendingTransactionEntries() {\n\ttry {\n\t\treturn await fs.readdir(transactionRoot(), { withFileTypes: true });\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n\t\tthrow error;\n\t}\n}\n\nasync function prepareTransaction(plan: SnapshotApplyPlan, sessionDir?: string) {\n\tconst root = path.resolve(agentDir());\n\tconst sessionRoot = sessionDir ? path.resolve(sessionStorageRoot(root, sessionDir)) : undefined;\n\tconst directory = path.join(transactionRoot(), randomUUID());\n\tconst backupDirectory = path.join(directory, \"before\");\n\tawait fs.mkdir(backupDirectory, { recursive: true, mode: 0o700 });\n\tconst targets = [...new Set([...plan.deletes, ...plan.writes.map((item) => item.target)])].sort();\n\tconst entries: TransactionEntry[] = [];\n\tfor (let index = 0; index < targets.length; index += 1) {\n\t\tconst target = targets[index];\n\t\tif (!target) continue;\n\t\tassertAllowedTarget(root, sessionRoot, target);\n\t\tconst backupName = `${index}`;\n\t\tconst backupPath = path.join(backupDirectory, backupName);\n\t\ttry {\n\t\t\tconst stat = await fs.lstat(target);\n\t\t\tif (stat.isSymbolicLink()) {\n\t\t\t\tentries.push({\n\t\t\t\t\ttarget,\n\t\t\t\t\tbackupName,\n\t\t\t\t\tkind: \"symlink\",\n\t\t\t\t\tlinkTarget: await fs.readlink(target),\n\t\t\t\t});\n\t\t\t} else if (stat.isDirectory()) {\n\t\t\t\tawait fs.cp(target, backupPath, {\n\t\t\t\t\trecursive: true,\n\t\t\t\t\tdereference: false,\n\t\t\t\t\tpreserveTimestamps: true,\n\t\t\t\t});\n\t\t\t\tentries.push({ target, backupName, kind: \"directory\" });\n\t\t\t} else if (stat.isFile()) {\n\t\t\t\tawait fs.copyFile(target, backupPath);\n\t\t\t\tawait fs.chmod(backupPath, stat.mode);\n\t\t\t\tentries.push({ target, backupName, kind: \"file\" });\n\t\t\t} else {\n\t\t\t\tthrow new Error(`Unsupported existing snapshot target: ${target}`);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst code = (error as NodeJS.ErrnoException).code;\n\t\t\tif (code !== \"ENOENT\" && code !== \"ENOTDIR\") throw error;\n\t\t\tentries.push({ target, backupName, kind: \"missing\" });\n\t\t}\n\t}\n\tconst journal: TransactionJournal = {\n\t\tversion: JOURNAL_VERSION,\n\t\troot,\n\t\tsessionRoot,\n\t\tentries,\n\t};\n\tawait fs.writeFile(\n\t\tpath.join(directory, \"journal.json\"),\n\t\t`${JSON.stringify(journal, null, \"\\t\")}\\n`,\n\t\t{\n\t\t\tmode: 0o600,\n\t\t},\n\t);\n\treturn { directory, journal };\n}\n\nasync function restoreTransaction(directory: string, journal: TransactionJournal) {\n\tvalidateJournal(directory, journal);\n\tfor (const entry of [...journal.entries].sort(\n\t\t(left, right) => right.target.length - left.target.length,\n\t)) {\n\t\tawait fs.rm(entry.target, { recursive: true, force: true });\n\t}\n\tfor (const entry of journal.entries) {\n\t\tif (entry.kind === \"missing\") continue;\n\t\tawait fs.mkdir(path.dirname(entry.target), { recursive: true });\n\t\tconst backupPath = path.join(directory, \"before\", entry.backupName);\n\t\tassertWithinRoot(directory, backupPath);\n\t\tif (entry.kind === \"file\") await fs.copyFile(backupPath, entry.target);\n\t\telse if (entry.kind === \"directory\") {\n\t\t\tawait fs.cp(backupPath, entry.target, {\n\t\t\t\trecursive: true,\n\t\t\t\tdereference: false,\n\t\t\t\tpreserveTimestamps: true,\n\t\t\t});\n\t\t} else if (entry.kind === \"symlink\" && entry.linkTarget !== undefined) {\n\t\t\tawait fs.symlink(entry.linkTarget, entry.target);\n\t\t}\n\t}\n\tawait fs.rm(directory, { recursive: true, force: true });\n}\n\nfunction validateJournal(directory: string, journal: TransactionJournal) {\n\tif (journal.version !== JOURNAL_VERSION || !Array.isArray(journal.entries)) {\n\t\tthrow new Error(`Unsupported pi-sync transaction journal: ${directory}`);\n\t}\n\tconst expectedRoot = path.resolve(agentDir());\n\tif (path.resolve(journal.root) !== expectedRoot) {\n\t\tthrow new Error(`Transaction root no longer matches the Pi agent directory: ${directory}`);\n\t}\n\tfor (const entry of journal.entries) {\n\t\tif (\n\t\t\t!entry ||\n\t\t\ttypeof entry.target !== \"string\" ||\n\t\t\ttypeof entry.backupName !== \"string\" ||\n\t\t\t!/^\\d+$/u.test(entry.backupName)\n\t\t) {\n\t\t\tthrow new Error(`Invalid pi-sync transaction entry: ${directory}`);\n\t\t}\n\t\tassertAllowedTarget(journal.root, journal.sessionRoot, entry.target);\n\t}\n}\n\nfunction assertAllowedTarget(root: string, sessionRoot: string | undefined, target: string) {\n\tconst resolved = path.resolve(target);\n\tif (isPathInside(root, resolved)) {\n\t\tassertWithinRoot(root, resolved);\n\t\treturn;\n\t}\n\tif (sessionRoot && isPathInside(sessionRoot, resolved)) {\n\t\tassertWithinRoot(sessionRoot, resolved);\n\t\treturn;\n\t}\n\tthrow new Error(`Transaction target is outside configured roots: ${target}`);\n}\n\nfunction transactionRoot() {\n\treturn path.join(stateDir(), \"transactions\");\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,OAAO,QAAQ;AACf,OAAO,UAAU;AAQjB,IAAM,kBAAkB;AAgBxB,eAAsB,yBACrB,MACA,UAAmC,CAAC,GACnC;AACD,QAAM,mCAAmC;AACzC,QAAM,cAAc,MAAM,mBAAmB,MAAM,QAAQ,UAAU;AACrE,MAAI;AACH,eAAW,UAAU,KAAK,SAAS;AAClC,YAAM,GAAG,GAAG,QAAQ,EAAE,OAAO,MAAM,WAAW,KAAK,CAAC;AAAA,IACrD;AACA,eAAW,QAAQ,KAAK,QAAQ;AAC/B,YAAM,GAAG,MAAM,KAAK,QAAQ,KAAK,MAAM,GAAG,EAAE,WAAW,KAAK,CAAC;AAC7D,YAAM,GAAG,UAAU,KAAK,QAAQ,KAAK,OAAO;AAAA,IAC7C;AACA,UAAM,GAAG,GAAG,YAAY,WAAW,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAAA,EACpE,SAAS,OAAO;AACf,QAAI;AACH,YAAM,mBAAmB,YAAY,WAAW,YAAY,OAAO;AAAA,IACpE,SAAS,eAAe;AACvB,YAAM,IAAI;AAAA,QACT,CAAC,OAAO,aAAa;AAAA,QACrB,qFAAqF,YAAY,SAAS;AAAA,MAC3G;AAAA,IACD;AACA,UAAM;AAAA,EACP;AACD;AAEA,eAAsB,uCAAuC;AAC5D,MAAI,EAAE,MAAM,0BAA0B,GAAG,KAAK,CAAC,UAAU,MAAM,YAAY,CAAC,EAAG;AAC/E,QAAM,SAAS,YAAY,oCAAoC,EAAE,cAAc,KAAK,CAAC;AACtF;AAEA,eAAsB,qCAAqC;AAC1D,QAAM,YAAY,gBAAgB;AAClC,QAAM,UAAU,MAAM,0BAA0B;AAChD,aAAW,SA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AAS,CAAC;AAC5C,MAAI,KAAK,QAAQ,QAAQ,IAAI,MAAM,cAAc;AAChD,UAAM,IAAI,MAAM,8DAA8D,SAAS,EAAE;AAAA,EAC1F;AACA,aAAW,SAAS,QAAQ,SAAS;AACpC,QACC,CAAC,SACD,OAAO,MAAM,WAAW,YACxB,OAAO,MAAM,eAAe,YAC5B,CAAC,SAAS,KAAK,MAAM,UAAU,GAC9B;AACD,YAAM,IAAI,MAAM,sCAAsC,SAAS,EAAE;AAAA,IAClE;AACA,wBAAoB,QAAQ,MAAM,QAAQ,aAAa,MAAM,MAAM;AAAA,EACpE;AACD;AAEA,SAAS,oBAAoB,MAAc,aAAiC,QAAgB;AAC3F,QAAM,WAAW,KAAK,QAAQ,MAAM;AACpC,MAAI,aAAa,MAAM,QAAQ,GAAG;AACjC,qBAAiB,MAAM,QAAQ;AAC/B;AAAA,EACD;AACA,MAAI,eAAe,aAAa,aAAa,QAAQ,GAAG;AACvD,qBAAiB,aAAa,QAAQ;AACtC;AAAA,EACD;AACA,QAAM,IAAI,MAAM,mDAAmD,MAAM,EAAE;AAC5E;AAEA,SAAS,kBAAkB;AAC1B,SAAO,KAAK,KAAK,SAAS,GAAG,cAAc;AAC5C;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/paths.ts", "../../src/sync/sync-policy.ts"],
|
|
4
|
-
"sourcesContent": ["import path from \"node:path\";\n\nexport function isDeniedPath(relativePath: string) {\n\tconst normalized = toPosix(relativePath);\n\tconst lower = normalized.toLowerCase();\n\tconst segments = lower.split(\"/\");\n\tconst base = path.posix.basename(lower);\n\treturn (\n\t\tsegments.includes(\"node_modules\") ||\n\t\tsegments.includes(\".git\") ||\n\t\tsegments.includes(\".pisync\") ||\n\t\tsegments.includes(\"pi-sync\") ||\n\t\tsegments.includes(\".pi-sync-state-migration.lock\") ||\n\t\tbase === \".env\" ||\n\t\tbase.startsWith(\".env.\") ||\n\t\tbase.endsWith(\".env\") ||\n\t\tbase.includes(\"secret\") ||\n\t\tbase.includes(\"token\") ||\n\t\tbase === \"pi-sync.json\" ||\n\t\tbase.startsWith(\"pi-sync.json.\") ||\n\t\tbase.startsWith(\".pi-sync.json.\") ||\n\t\tbase === \"pi-sync.local.json\" ||\n\t\tbase.startsWith(\"pi-sync.local.json.\") ||\n\t\tbase.startsWith(\".pi-sync.local.json.\")\n\t);\n}\n\nexport function isPathInside(parent: string, child: string) {\n\tconst relative = path.relative(path.resolve(parent), path.resolve(child));\n\treturn relative === \"\" || (!relative.startsWith(\"..\") && !path.isAbsolute(relative));\n}\n\nexport function safeJoin(root: string, relativePath: string) {\n\tconst target = path.resolve(root, relativePath);\n\tassertWithinRoot(root, target, relativePath);\n\treturn target;\n}\n\nexport function assertWithinRoot(root: string, target: string, label = target) {\n\tconst resolvedRoot = path.resolve(root);\n\tconst resolvedTarget = path.resolve(target);\n\tif (resolvedTarget !== resolvedRoot && !resolvedTarget.startsWith(`${resolvedRoot}${path.sep}`)) {\n\t\tthrow new Error(`Unsafe path in snapshot: ${label}`);\n\t}\n}\n\nexport function encodeKey(key: string) {\n\treturn key.split(\"/\").map(encodeURIComponent).join(\"/\");\n}\n\nexport function posixJoin(...parts: string[]) {\n\treturn parts\n\t\t.map((part) => trimSlashes(part))\n\t\t.filter(Boolean)\n\t\t.join(\"/\");\n}\n\nexport function parentPaths(relativePath: string) {\n\tconst results: string[] = [];\n\tlet index = relativePath.lastIndexOf(\"/\");\n\twhile (index > 0) {\n\t\tresults.push(relativePath.slice(0, index));\n\t\tindex = relativePath.lastIndexOf(\"/\", index - 1);\n\t}\n\treturn results;\n}\n\nexport function toPosix(value: string) {\n\treturn value.split(path.sep).join(\"/\");\n}\n\nfunction trimSlashes(value: string) {\n\treturn value.replace(/^\\/+|\\/+$/g, \"\");\n}\n\nexport function safeName(value: string) {\n\treturn value.replace(/[^A-Za-z0-9._-]/g, \"_\");\n}\n", "import path from \"node:path\";\nimport { isDeniedPath, toPosix } from \"../paths.js\";\nimport type { Snapshot, SnapshotSelection } from \"../snapshot/snapshot-types.js\";\n\nexport const BUILT_IN_SYNC_ROOTS = [\n\t\"settings.json\",\n\t\"keybindings.json\",\n\t\"models.json\",\n\t\"AGENTS.md\",\n\t\"APPEND_SYSTEM.md\",\n\t\"skills\",\n\t\"prompts\",\n\t\"themes\",\n\t\"extensions\",\n] as const;\n\nexport const DEFAULT_SYNC_INCLUDE = [...BUILT_IN_SYNC_ROOTS] as const;\nexport type BuiltInSyncFile = (typeof BUILT_IN_SYNC_ROOTS)[number];\nconst SNAPSHOT_SELECTION_VERSION = 1;\nconst MAX_SYNC_INCLUDE_ITEMS = 1_024;\nconst MAX_SYNC_INCLUDE_PATH_BYTES = 4_096;\nconst MAX_SYNC_INCLUDE_TOTAL_BYTES = 256 * 1_024;\n\ninterface IncludePathNode {\n\tselected?: string;\n\tchildren: Map<string, IncludePathNode>;\n}\n\nconst BUILT_IN_BY_LOWER = new Map<string, BuiltInSyncFile>(\n\tBUILT_IN_SYNC_ROOTS.map((fileName) => [fileName.toLowerCase(), fileName]),\n);\nconst TOP_LEVEL_FILE_PATHS = new Map<string, string>(\n\tBUILT_IN_SYNC_ROOTS.filter((fileName) => fileName.includes(\".\")).map((fileName) => [\n\t\tfileName.toLowerCase(),\n\t\tfileName,\n\t]),\n);\nconst TOP_LEVEL_DIRS = new Set<string>(\n\tBUILT_IN_SYNC_ROOTS.filter((fileName) => !fileName.includes(\".\")),\n);\nconst RESERVED_TOP_LEVEL_NAMES = new Set<string>([...BUILT_IN_BY_LOWER.keys(), \"sessions\"]);\n\nexport function normalizeSyncInclude(value: unknown): string[] {\n\tif (!Array.isArray(value)) {\n\t\tthrow new Error(\"Invalid pi-sync settings: sync.include must be an array.\");\n\t}\n\tif (value.length > MAX_SYNC_INCLUDE_ITEMS) {\n\t\tthrow new Error(\n\t\t\t`Invalid pi-sync settings: sync.include has too many items; limit: ${MAX_SYNC_INCLUDE_ITEMS}.`,\n\t\t);\n\t}\n\tconst result: string[] = [];\n\tconst seen = new Set<string>();\n\tconst pathRoot: IncludePathNode = { children: new Map() };\n\tlet totalBytes = 0;\n\tfor (const item of value) {\n\t\tif (typeof item !== \"string\") {\n\t\t\tthrow new Error(\"Invalid pi-sync settings: sync.include items must be strings.\");\n\t\t}\n\t\tconst itemBytes = Buffer.byteLength(item, \"utf8\");\n\t\tif (itemBytes > MAX_SYNC_INCLUDE_PATH_BYTES) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid pi-sync settings: sync.include item is too long; limit: ${MAX_SYNC_INCLUDE_PATH_BYTES} bytes.`,\n\t\t\t);\n\t\t}\n\t\ttotalBytes += itemBytes;\n\t\tif (totalBytes > MAX_SYNC_INCLUDE_TOTAL_BYTES) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid pi-sync settings: sync.include is too large; limit: ${MAX_SYNC_INCLUDE_TOTAL_BYTES} bytes.`,\n\t\t\t);\n\t\t}\n\t\tconst trimmed = item.trim();\n\t\tconst builtIn = BUILT_IN_BY_LOWER.get(trimmed.toLowerCase());\n\t\tconst normalized = builtIn ?? (trimmed.toLowerCase() === \"sessions\" ? \"sessions\" : trimmed);\n\t\tif (!builtIn && normalized !== \"sessions\") validateAgentRelativeInclude(normalized);\n\t\tconst identity = normalized.toLowerCase();\n\t\tif (seen.has(identity)) {\n\t\t\tthrow new Error(`Invalid pi-sync settings: duplicate sync.include item: ${item}`);\n\t\t}\n\t\taddIncludePath(pathRoot, identity, item);\n\t\tseen.add(identity);\n\t\tresult.push(normalized);\n\t}\n\treturn result;\n}\n\nfunction addIncludePath(root: IncludePathNode, identity: string, source: string) {\n\tlet node = root;\n\tfor (const segment of identity.split(\"/\")) {\n\t\tif (node.selected !== undefined) throwOverlappingInclude(source);\n\t\tlet child = node.children.get(segment);\n\t\tif (!child) {\n\t\t\tchild = { children: new Map() };\n\t\t\tnode.children.set(segment, child);\n\t\t}\n\t\tnode = child;\n\t}\n\tif (node.children.size > 0) throwOverlappingInclude(source);\n\tnode.selected = identity;\n}\n\nfunction throwOverlappingInclude(item: string): never {\n\tthrow new Error(\n\t\t`Invalid pi-sync settings: overlapping sync.include items are ambiguous: ${item}`,\n\t);\n}\n\nfunction validateAgentRelativeInclude(value: string) {\n\tconst normalized = toPosix(value);\n\tconst topLevel = normalized.split(\"/\")[0]?.toLowerCase();\n\tif (\n\t\t!normalized ||\n\t\tnormalized === \".\" ||\n\t\tnormalized === \"..\" ||\n\t\tnormalized.startsWith(\"../\") ||\n\t\tpath.posix.isAbsolute(normalized) ||\n\t\tnormalized.includes(\"\\\\\") ||\n\t\tpath.posix.normalize(normalized) !== normalized ||\n\t\t// biome-ignore lint/suspicious/noControlCharactersInRegex: Include paths cannot contain controls.\n\t\t/[\\u0000-\\u001f\\u007f-\\u009f]/u.test(normalized)\n\t) {\n\t\tthrow new Error(\n\t\t\t`Invalid pi-sync settings: sync.include item must be a safe agent-relative path: ${value}`,\n\t\t);\n\t}\n\tif (isDeniedPath(normalized)) {\n\t\tthrow new Error(`Invalid pi-sync settings: ${value} cannot be synced.`);\n\t}\n\tif (topLevel && RESERVED_TOP_LEVEL_NAMES.has(topLevel)) {\n\t\tthrow new Error(\n\t\t\t`Invalid pi-sync settings: use the canonical ${topLevel} root instead of a nested sync.include path.`,\n\t\t);\n\t}\n}\n\nexport function portableSnapshotSelection(value: unknown): SnapshotSelection {\n\tconst selection = value as Partial<SnapshotSelection> | null;\n\tif (\n\t\t!selection ||\n\t\ttypeof selection !== \"object\" ||\n\t\tArray.isArray(selection) ||\n\t\tselection.version !== SNAPSHOT_SELECTION_VERSION ||\n\t\t!Object.hasOwn(selection, \"include\") ||\n\t\tObject.keys(selection).some((key) => key !== \"version\" && key !== \"include\")\n\t) {\n\t\tthrow new Error(\"Invalid snapshot selection policy.\");\n\t}\n\treturn {\n\t\tversion: SNAPSHOT_SELECTION_VERSION,\n\t\tinclude: normalizeSyncInclude(selection.include),\n\t};\n}\n\nexport function snapshotSelectionInclude(snapshot: Pick<Snapshot, \"selection\">) {\n\treturn snapshot.selection === undefined\n\t\t? undefined\n\t\t: portableSnapshotSelection(snapshot.selection).include;\n}\n\nexport function selectionForSnapshot(include: unknown): SnapshotSelection {\n\treturn { version: SNAPSHOT_SELECTION_VERSION, include: normalizeSyncInclude(include) };\n}\n\nexport function sameSyncInclude(left: unknown, right: unknown) {\n\tconst normalizedLeft = normalizeSyncInclude(left);\n\tconst normalizedRight = normalizeSyncInclude(right);\n\treturn (\n\t\tnormalizedLeft.length === normalizedRight.length &&\n\t\tnormalizedLeft.every((item, index) => item === normalizedRight[index])\n\t);\n}\n\nexport function compareSyncInclude(local: unknown, remote: unknown) {\n\tconst localInclude = normalizeSyncInclude(local);\n\tconst remoteInclude = normalizeSyncInclude(remote);\n\tconst localSet = new Set(localInclude);\n\tconst remoteSet = new Set(remoteInclude);\n\treturn {\n\t\tsame: sameSyncInclude(localInclude, remoteInclude),\n\t\tremoteOnly: remoteInclude.filter((item) => !localSet.has(item)),\n\t\tlocalOnly: localInclude.filter((item) => !remoteSet.has(item)),\n\t};\n}\n\nexport type RemoteSelectionState =\n\t| { kind: \"legacy\"; discovered: string[] }\n\t| { kind: \"same\"; include: string[] }\n\t| {\n\t\t\tkind: \"different\";\n\t\t\tinclude: string[];\n\t\t\tremoteOnly: string[];\n\t\t\tlocalOnly: string[];\n\t };\n\nexport function inspectRemoteSelection(\n\tlocalInclude: unknown,\n\tsnapshot: Pick<Snapshot, \"selection\" | \"files\">,\n): RemoteSelectionState {\n\tconst remoteInclude = snapshotSelectionInclude(snapshot);\n\tif (!remoteInclude) {\n\t\treturn { kind: \"legacy\", discovered: discoverLegacySnapshotInclude(snapshot) };\n\t}\n\tconst comparison = compareSyncInclude(localInclude, remoteInclude);\n\treturn comparison.same\n\t\t? { kind: \"same\", include: remoteInclude }\n\t\t: { kind: \"different\", include: remoteInclude, ...comparison };\n}\n\nexport interface RemoteSelectionDecision {\n\tsetupName: string;\n\tconfigIdentity: string;\n\tlocalInclude: readonly string[];\n\tremoteInclude: readonly string[];\n}\n\nexport class RemoteSelectionMismatchError extends Error {\n\treadonly decision: RemoteSelectionDecision;\n\treadonly setupName: string;\n\treadonly localInclude: string[];\n\treadonly remoteInclude: string[];\n\n\tconstructor(\n\t\tsetupName: string,\n\t\tlocalInclude: unknown,\n\t\tremoteInclude: unknown,\n\t\tconfigIdentity = JSON.stringify([setupName, normalizeSyncInclude(localInclude)]),\n\t) {\n\t\tconst local = normalizeSyncInclude(localInclude);\n\t\tconst remote = normalizeSyncInclude(remoteInclude);\n\t\tsuper(formatRemoteSelectionMismatch(setupName, local, remote));\n\t\tthis.name = \"RemoteSelectionMismatchError\";\n\t\tthis.setupName = setupName;\n\t\tthis.localInclude = local;\n\t\tthis.remoteInclude = remote;\n\t\tthis.decision = {\n\t\t\tsetupName,\n\t\t\tconfigIdentity,\n\t\t\tlocalInclude: [...local],\n\t\t\tremoteInclude: [...remote],\n\t\t};\n\t}\n}\n\nexport function remoteSelectionMismatch(\n\tconfig: { setupName: string; include: unknown },\n\tremoteInclude: unknown,\n\tconfigIdentity?: string,\n) {\n\treturn new RemoteSelectionMismatchError(\n\t\tconfig.setupName,\n\t\tconfig.include,\n\t\tremoteInclude,\n\t\tconfigIdentity,\n\t);\n}\n\nexport function formatRemoteSelectionMismatch(\n\tsetupName: string,\n\tlocalInclude: readonly string[],\n\tremoteInclude: readonly string[],\n) {\n\tconst comparison = compareSyncInclude(localInclude, remoteInclude);\n\tconst lines = [\n\t\t`Synced content differs for sync setup \u201C${stripTerminalControls(setupName)}\u201D.`,\n\t\t`Remote-only: ${comparison.remoteOnly.join(\", \") || \"none\"}`,\n\t\t`This-device-only: ${comparison.localOnly.join(\", \") || \"none\"}`,\n\t];\n\tif (comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0) {\n\t\tlines.push(\n\t\t\t\"Only ordering differs.\",\n\t\t\t`Remote order: ${remoteInclude.join(\", \") || \"none\"}`,\n\t\t\t`This device order: ${localInclude.join(\", \") || \"none\"}`,\n\t\t);\n\t}\n\tlines.push(\"Run /sync in TUI to review both content lists and choose what happens next.\");\n\treturn lines.join(\"\\n\");\n}\n\nfunction stripTerminalControls(value: string) {\n\t// biome-ignore lint/suspicious/noControlCharactersInRegex: Escape untrusted terminal controls.\n\treturn value.replace(/[\\u0000-\\u001f\\u007f-\\u009f]/gu, \"?\");\n}\n\nexport function discoverLegacySnapshotInclude(snapshot: Pick<Snapshot, \"files\">) {\n\tconst builtIns = new Set<BuiltInSyncFile>();\n\tconst custom = new Set<string>();\n\tlet sessions = false;\n\tfor (const file of snapshot.files) {\n\t\tconst normalized = toPosix(file.path);\n\t\tif (\n\t\t\t!normalized ||\n\t\t\tfile.path.includes(\"\\\\\") ||\n\t\t\tnormalized.length > 4096 ||\n\t\t\tnormalized.startsWith(\"../\") ||\n\t\t\tpath.posix.isAbsolute(normalized) ||\n\t\t\tpath.posix.normalize(normalized) !== normalized ||\n\t\t\t// biome-ignore lint/suspicious/noControlCharactersInRegex: Ignore unsafe legacy paths.\n\t\t\t/[\\u0000-\\u001f\\u007f-\\u009f]/u.test(normalized) ||\n\t\t\tisDeniedPath(normalized)\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst [topLevel, ...rest] = normalized.split(\"/\");\n\t\tif (!topLevel) continue;\n\t\tif (topLevel === \"sessions\" && rest.length > 0) {\n\t\t\tsessions = true;\n\t\t\tcontinue;\n\t\t}\n\t\tconst builtIn = BUILT_IN_BY_LOWER.get(topLevel.toLowerCase());\n\t\tif (\n\t\t\tbuiltIn &&\n\t\t\t((TOP_LEVEL_DIRS.has(builtIn) && rest.length > 0) ||\n\t\t\t\t(!TOP_LEVEL_DIRS.has(builtIn) && rest.length === 0))\n\t\t) {\n\t\t\tbuiltIns.add(builtIn);\n\t\t\tcontinue;\n\t\t}\n\t\tif (isSafeCustomIncludePath(topLevel)) custom.add(topLevel);\n\t}\n\treturn [\n\t\t...BUILT_IN_SYNC_ROOTS.filter((item) => builtIns.has(item)),\n\t\t...[...custom].sort((left, right) => left.localeCompare(right)),\n\t\t...(sessions ? [\"sessions\"] : []),\n\t];\n}\n\nexport function syncIncludeSelection(value: unknown) {\n\tconst include = normalizeSyncInclude(value);\n\tconst builtIns = include.filter((item): item is BuiltInSyncFile =>\n\t\tBUILT_IN_BY_LOWER.has(item.toLowerCase()),\n\t);\n\tconst custom = include.filter(\n\t\t(item) => item !== \"sessions\" && !BUILT_IN_BY_LOWER.has(item.toLowerCase()),\n\t);\n\treturn { include, builtIns, custom, sessions: include.includes(\"sessions\") };\n}\n\nexport function customIncludePathsByLower(value: unknown) {\n\treturn new Map(\n\t\tsyncIncludeSelection(value).custom.map((relativePath) => [\n\t\t\trelativePath.toLowerCase(),\n\t\t\trelativePath,\n\t\t]),\n\t);\n}\n\nexport interface SyncSelectionConfig {\n\tinclude?: unknown;\n\tsyncFiles?: unknown;\n\tsyncSessions?: boolean;\n\textraFiles?: unknown;\n}\n\nexport function includeFromSelectionConfig(config: SyncSelectionConfig) {\n\tif (config.include !== undefined) return normalizeSyncInclude(config.include);\n\treturn [\n\t\t...normalizeSyncFiles(config.syncFiles),\n\t\t...normalizeExtraFiles(config.extraFiles),\n\t\t...(config.syncSessions ? [\"sessions\"] : []),\n\t];\n}\n\nexport function isConfiguredSnapshotPath(\n\trelativePath: string,\n\tconfig: SyncSelectionConfig,\n\t_legacyExtraFiles?: Set<string>,\n) {\n\tconst normalized = toPosix(relativePath);\n\tconst selection = syncIncludeSelection(includeFromSelectionConfig(config));\n\tif (normalized.startsWith(\"sessions/\")) return selection.sessions;\n\tconst lower = normalized.toLowerCase();\n\tif (!normalized.includes(\"/\")) {\n\t\tconst builtIn = BUILT_IN_BY_LOWER.get(lower);\n\t\tif (builtIn) return selection.builtIns.includes(builtIn) && !TOP_LEVEL_DIRS.has(builtIn);\n\t}\n\tconst topLevel = normalized.slice(0, normalized.indexOf(\"/\"));\n\tif (selection.builtIns.includes(topLevel as BuiltInSyncFile) && TOP_LEVEL_DIRS.has(topLevel)) {\n\t\treturn true;\n\t}\n\treturn selection.custom.some((candidate) => {\n\t\tconst candidateLower = candidate.toLowerCase();\n\t\treturn lower === candidateLower || lower.startsWith(`${candidateLower}/`);\n\t});\n}\n\nexport function canonicalSnapshotPathForConfig(\n\trelativePath: string,\n\tincludePaths: Map<string, string>,\n) {\n\tconst normalized = toPosix(relativePath);\n\tconst lower = normalized.toLowerCase();\n\treturn TOP_LEVEL_FILE_PATHS.get(lower) ?? includePaths.get(lower) ?? normalized;\n}\n\nexport function isPreservableUnmanagedSnapshotPath(relativePath: string) {\n\tconst normalized = toPosix(relativePath);\n\tif (!normalized || isDeniedPath(normalized)) return false;\n\tif (normalized.startsWith(\"sessions/\")) return normalized.endsWith(\".jsonl\");\n\tif (!normalized.includes(\"/\")) {\n\t\tconst lower = normalized.toLowerCase();\n\t\treturn TOP_LEVEL_FILE_PATHS.has(lower) || !RESERVED_TOP_LEVEL_NAMES.has(lower);\n\t}\n\treturn true;\n}\n\nexport function isSafeCustomIncludePath(relativePath: string) {\n\ttry {\n\t\tvalidateAgentRelativeInclude(relativePath);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport function isBuiltInTopLevelFile(fileName: string) {\n\treturn TOP_LEVEL_FILE_PATHS.has(path.posix.basename(fileName).toLowerCase());\n}\n\n/** Compatibility projection for backend-neutral output while callers move to sync.include. */\nexport function normalizeSyncFiles(value: unknown): BuiltInSyncFile[] {\n\tif (value === undefined) return [...DEFAULT_SYNC_INCLUDE];\n\tif (Array.isArray(value)) {\n\t\treturn normalizeSyncInclude(value).filter((item): item is BuiltInSyncFile =>\n\t\t\tBUILT_IN_BY_LOWER.has(item.toLowerCase()),\n\t\t);\n\t}\n\tthrow new Error(\"Invalid pi-sync settings: expected an include array.\");\n}\n\n/** Compatibility projection for old rendering helpers; v3 persistence never writes this split field. */\nexport function normalizeExtraFiles(value: unknown) {\n\tif (!Array.isArray(value)) return [];\n\treturn value.filter(\n\t\t(item): item is string => typeof item === \"string\" && isSafeCustomIncludePath(item),\n\t);\n}\n\nexport const extraFilePathsByLower = customIncludePathsByLower;\nexport const isSafeExtraFileName = isSafeCustomIncludePath;\nexport const selectedSyncFileSet = (value: unknown) => new Set(normalizeSyncFiles(value));\n"],
|
|
5
|
-
"mappings": ";;;;AAAA,OAAO,UAAU;AAEV,SAAS,aAAa,cAAsB;AAClD,QAAM,aAAa,QAAQ,YAAY;AACvC,QAAM,QAAQ,WAAW,YAAY;AACrC,QAAM,WAAW,MAAM,MAAM,GAAG;AAChC,QAAM,OAAO,KAAK,MAAM,SAAS,KAAK;AACtC,SACC,SAAS,SAAS,cAAc,KAChC,SAAS,SAAS,MAAM,KACxB,SAAS,SAAS,SAAS,KAC3B,SAAS,SAAS,SAAS,KAC3B,SAAS,SAAS,+BAA+B,KACjD,SAAS,UACT,KAAK,WAAW,OAAO,KACvB,KAAK,SAAS,MAAM,KACpB,KAAK,SAAS,QAAQ,KACtB,KAAK,SAAS,OAAO,KACrB,SAAS,kBACT,KAAK,WAAW,eAAe,KAC/B,KAAK,WAAW,gBAAgB,KAChC,SAAS,wBACT,KAAK,WAAW,qBAAqB,KACrC,KAAK,WAAW,sBAAsB;AAExC;AAEO,SAAS,aAAa,QAAgB,OAAe;AAC3D,QAAM,WAAW,KAAK,SAAS,KAAK,QAAQ,MAAM,GAAG,KAAK,QAAQ,KAAK,CAAC;AACxE,SAAO,aAAa,MAAO,CAAC,SAAS,WAAW,IAAI,KAAK,CAAC,KAAK,WAAW,QAAQ;AACnF;AAEO,SAAS,SAAS,MAAc,cAAsB;AAC5D,QAAM,SAAS,KAAK,QAAQ,MAAM,YAAY;AAC9C,mBAAiB,MAAM,QAAQ,YAAY;AAC3C,SAAO;AACR;AAEO,SAAS,iBAAiB,MAAc,QAAgB,QAAQ,QAAQ;AAC9E,QAAM,eAAe,KAAK,QAAQ,IAAI;AACtC,QAAM,iBAAiB,KAAK,QAAQ,MAA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AC,SAAyB,OAAO,SAAS,YAAY,wBAAwB,IAAI;AAAA,EACnF;AACD;",
|
|
6
|
-
"names": ["path", "path"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/commands/setup-completions.ts", "../../src/ui/setup/text-input.ts", "../../src/ui/setup/setup-location-ui.ts", "../../src/ui/setup/setup-prompts.ts", "../../src/ui/setup/setup-review.ts", "../../src/ui/setup/git-ui.ts", "../../src/ui/secret-input.ts", "../../src/ui/setup/s3-credentials-ui.ts", "../../src/ui/setup/s3-ui.ts", "../../src/ui/setup/webdav-ui.ts"],
|
|
4
|
-
"sourcesContent": ["import { configuredSyncSetupNames } from \"../settings/settings-store.js\";\nimport { setSyncSetupCompletions } from \"./command.js\";\n\nexport async function refreshTargetCompletions() {\n\tsetSyncSetupCompletions(await configuredSyncSetupNames());\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { normalizeS3Bucket, requiredString } from \"../../settings/settings-validation.js\";\nimport { errorMessage } from \"../../sync/sync-errors.js\";\nimport { safeTerminalText } from \"../terminal-text.js\";\n\nexport type ValidateInput = (value: string) => string | Promise<string>;\n\nexport async function requiredExistingBucket(\n\tctx: ExtensionCommandContext,\n\texample: string,\n\tsignal?: AbortSignal,\n) {\n\treturn requiredValueInput(\n\t\tctx,\n\t\t\"Existing bucket\\n\\nThe bucket must already exist; pi-sync will not create it.\",\n\t\texample,\n\t\tsignal,\n\t\tnormalizeS3Bucket,\n\t);\n}\n\nexport async function requiredInput(\n\tctx: ExtensionCommandContext,\n\ttitle: string,\n\tdefaultValue: string,\n\tsignal?: AbortSignal,\n\tvalidate?: ValidateInput,\n) {\n\treturn promptTextInput(ctx, title, { defaultValue, validate, rejectPlaceholders: true }, signal);\n}\n\nexport async function requiredValueInput(\n\tctx: ExtensionCommandContext,\n\ttitle: string,\n\texample: string,\n\tsignal?: AbortSignal,\n\tvalidate?: ValidateInput,\n) {\n\treturn promptTextInput(ctx, title, { example, validate, rejectPlaceholders: true }, signal);\n}\n\nexport async function promptTextInput(\n\tctx: ExtensionCommandContext,\n\ttitle: string,\n\toptions: {\n\t\tdefaultValue?: string;\n\t\texample?: string;\n\t\tvalidate?: ValidateInput;\n\t\trejectPlaceholders?: boolean;\n\t},\n\tsignal?: AbortSignal,\n) {\n\t// Pi ignores placeholders. Keep defaults/examples visible; only an explicit blank accepts a default.\n\tconst hint =\n\t\toptions.defaultValue !== undefined\n\t\t\t? `Default: ${safeTerminalText(options.defaultValue)} (leave blank to keep)`\n\t\t\t: `Example: ${safeTerminalText(options.example ?? \"\")}\\nEnter your own value; this example is not a default.`;\n\twhile (true) {\n\t\tsignal?.throwIfAborted();\n\t\tconst value = await ctx.ui.input(`${title}\\n\\n${hint}`, undefined, { signal });\n\t\tsignal?.throwIfAborted();\n\t\tif (value === undefined) return undefined;\n\t\ttry {\n\t\t\tconst normalized = value.trim() || options.defaultValue;\n\t\t\tif (!normalized) throw new Error(`${title.split(\"\\n\")[0]} is required.`);\n\t\t\tif (options.rejectPlaceholders && /[<>]/u.test(normalized)) {\n\t\t\t\tthrow new Error(\"Replace example placeholders such as <account-id> with your own value.\");\n\t\t\t}\n\t\t\tconst checked = requiredString(normalized, title.split(\"\\n\")[0] ?? \"value\");\n\t\t\tconst result = options.validate ? await options.validate(checked) : checked;\n\t\t\tsignal?.throwIfAborted();\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tsignal?.throwIfAborted();\n\t\t\tctx.ui.notify(`${errorMessage(error)} Enter a corrected value, or cancel.`, \"warning\");\n\t\t}\n\t}\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { normalizeGitBranch } from \"../../backends/git/git-config.js\";\nimport { readLocalConfigObject } from \"../../settings/settings-store.js\";\nimport type {\n\tStorageConnectionSettings,\n\tSyncSetupSettings,\n} from \"../../settings/settings-types.js\";\nimport {\n\teffectiveSyncSetupRemoteIdentity,\n\tnormalizeStoragePath,\n\townRecord,\n} from \"../../settings/settings-validation.js\";\nimport { errorMessage } from \"../../sync/sync-errors.js\";\nimport { safeTerminalText } from \"../terminal-text.js\";\nimport {\n\tpromptTextInput,\n\trequiredExistingBucket,\n\trequiredInput,\n\trequiredValueInput,\n} from \"./text-input.js\";\n\ninterface ChosenRemoteLocation {\n\tconnectionName: string;\n\tbucket: string;\n\tpath: string;\n}\n\nexport async function chooseInitialRemoteLocation(\n\tctx: ExtensionCommandContext,\n\t_preset: string,\n\tsetupName: string,\n\tsignal?: AbortSignal,\n): Promise<ChosenRemoteLocation | undefined> {\n\tconst choice = await ctx.ui.select(\n\t\t\"Choose storage location\\n\\nUse an existing bucket. ./ stores snapshots at the bucket root; a custom path keeps them in a separate folder.\",\n\t\t[\"Use an existing bucket at ./\", \"Customize remote location\", \"Cancel\"],\n\t\t{ signal },\n\t);\n\tif (signal?.aborted || !choice || choice === \"Cancel\") return undefined;\n\tif (choice === \"Customize remote location\")\n\t\treturn chooseCustomRemoteLocation(ctx, setupName, signal);\n\tconst bucket = await requiredExistingBucket(ctx, \"pi-sync\", signal);\n\treturn bucket ? { connectionName: setupName, bucket, path: \"./\" } : undefined;\n}\n\nexport async function chooseAdditionalRemoteLocation(\n\tctx: ExtensionCommandContext,\n\tsettings: Record<string, unknown>,\n\tconnectionName: string,\n\tsetupName: string,\n\tsignal?: AbortSignal,\n): Promise<Omit<ChosenRemoteLocation, \"connectionName\"> | undefined> {\n\tconst setups = ownRecord(settings.syncSetups) ?? {};\n\tconst currentSetup =\n\t\ttypeof settings.activeSyncSetup === \"string\" ? settings.activeSyncSetup : undefined;\n\tconst candidates = Object.entries(setups)\n\t\t.map(([name, value]) => ({ name, storage: ownRecord(ownRecord(value)?.storage) }))\n\t\t.filter(\n\t\t\t(item): item is { name: string; storage: Record<string, unknown> } =>\n\t\t\t\titem.storage?.connection === connectionName && typeof item.storage.bucket === \"string\",\n\t\t);\n\tconst source =\n\t\tcandidates.find((item) => item.name === currentSetup) ??\n\t\tcandidates.sort((left, right) => left.name.localeCompare(right.name))[0];\n\tif (source) {\n\t\tconst suggestedPath = \"./\";\n\t\tconst sameBucketLabel = `Same bucket as \u201C${safeTerminalText(source.name)}\u201D`;\n\t\tconst choice = await ctx.ui.select(\n\t\t\t[\n\t\t\t\t`Storage location for \u201C${safeTerminalText(setupName)}\u201D`,\n\t\t\t\t\"\",\n\t\t\t\t`Existing bucket: ${safeTerminalText(String(source.storage.bucket))}`,\n\t\t\t\t`Remote path: ${safeTerminalText(suggestedPath)}`,\n\t\t\t\t\"./ uses the bucket root. Use a different path or bucket for independent setups.\",\n\t\t\t].join(\"\\n\"),\n\t\t\t[sameBucketLabel, \"Use a different bucket\", \"Customize remote location\", \"Cancel\"],\n\t\t\t{ signal },\n\t\t);\n\t\tif (signal?.aborted || !choice || choice === \"Cancel\") return undefined;\n\t\tif (choice === sameBucketLabel) {\n\t\t\treturn { bucket: String(source.storage.bucket), path: suggestedPath };\n\t\t}\n\t\tif (choice === \"Use a different bucket\") {\n\t\t\tconst bucket = await requiredExistingBucket(ctx, \"pi-sync\", signal);\n\t\t\treturn bucket ? { bucket, path: \"./\" } : undefined;\n\t\t}\n\t\tconst custom = await chooseCustomRemoteLocation(ctx, connectionName, signal);\n\t\treturn custom ? { bucket: custom.bucket, path: custom.path } : undefined;\n\t}\n\n\tconst location = await chooseInitialRemoteLocation(ctx, \"S3\", setupName, signal);\n\treturn location ? { bucket: location.bucket, path: location.path } : undefined;\n}\n\nasync function chooseCustomRemoteLocation(\n\tctx: ExtensionCommandContext,\n\tconnectionName: string,\n\tsignal?: AbortSignal,\n): Promise<ChosenRemoteLocation | undefined> {\n\tconst bucket = await requiredExistingBucket(ctx, \"pi-sync\", signal);\n\tif (!bucket) return undefined;\n\tconst storagePath = await requiredInput(\n\t\tctx,\n\t\t\"Storage path\\n\\nPath inside the bucket, not your local filesystem.\\n./ uses the bucket root. Use different paths for independent setups.\",\n\t\t\"./\",\n\t\tsignal,\n\t\tnormalizeStoragePath,\n\t);\n\tif (!storagePath) return undefined;\n\treturn { connectionName, bucket, path: normalizeStoragePath(storagePath) };\n}\n\n/** Early UI check only; the settings writer still validates uniqueness under its lock. */\nexport async function promptAvailableSetupStorage<T extends SyncSetupSettings[\"storage\"]>(\n\tctx: ExtensionCommandContext,\n\tinitial: T,\n\tsignal?: AbortSignal,\n): Promise<T | undefined> {\n\tlet storage = initial;\n\twhile (!signal?.aborted) {\n\t\tconst settings = await readLocalConfigObject();\n\t\tif (signal?.aborted) return undefined;\n\t\tconst connection = settings?.storageConnections[storage.connection];\n\t\tif (!settings || !connection) throw new Error(\"Storage connection changed; reopen setup.\");\n\t\tconst identity = setupPublicationIdentity(storage, connection);\n\t\tconst occupied = Object.entries(settings.syncSetups).find(\n\t\t\t([, setup]) =>\n\t\t\t\tsetupPublicationIdentity(\n\t\t\t\t\tsetup.storage,\n\t\t\t\t\tsettings.storageConnections[setup.storage.connection],\n\t\t\t\t) === identity,\n\t\t);\n\t\tif (!occupied) return storage;\n\t\tconst git = connection.type === \"git\";\n\t\tconst message = `${git ? \"Git branch\" : \"Storage location\"} is already used by \u201C${safeTerminalText(occupied[0])}\u201D. ${git ? \"Use a different branch; pi-sync owns the entire branch.\" : \"Enter a different storage path, or cancel to choose another connection or bucket.\"}`;\n\t\tctx.ui.notify(message, \"warning\");\n\t\tconst title = `${git ? \"Git branch for the new setup\" : \"Storage path for the new setup\"}\\n\\n${message}`;\n\t\tconst example = git ? \"pi-sync/work\" : \"backups/work\";\n\t\tconst value =\n\t\t\tconnection.type === \"webdav\"\n\t\t\t\t? await promptTextInput(ctx, title, { example }, signal)\n\t\t\t\t: await requiredValueInput(ctx, title, example, signal);\n\t\tif (signal?.aborted || value === undefined) return undefined;\n\t\ttry {\n\t\t\tstorage = git\n\t\t\t\t? { ...storage, branch: normalizeGitBranch(value) }\n\t\t\t\t: { ...storage, path: normalizeStoragePath(value) };\n\t\t} catch (error) {\n\t\t\tctx.ui.notify(safeTerminalText(errorMessage(error)), \"warning\");\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction setupPublicationIdentity(\n\tstorage: SyncSetupSettings[\"storage\"],\n\tconnection: StorageConnectionSettings,\n) {\n\t// Git publications own a complete branch tree; changing only its directory is not isolation.\n\treturn effectiveSyncSetupRemoteIdentity(\n\t\t{\n\t\t\tstorage: connection.type === \"git\" ? { ...storage, path: \"./\" } : storage,\n\t\t\tsync: { include: [], automatic: false },\n\t\t},\n\t\tconnection,\n\t);\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { readLocalConfigObject } from \"../../settings/settings-store.js\";\nimport { validateConfigName } from \"../../settings/settings-validation.js\";\nimport { DEFAULT_SYNC_INCLUDE } from \"../../sync/sync-policy.js\";\nimport { safeTerminalText } from \"../terminal-text.js\";\nimport { promptTextInput } from \"./text-input.js\";\n\nexport async function readSetupConnection(name: string, signal?: AbortSignal) {\n\tconst connection = (await readLocalConfigObject())?.storageConnections[name];\n\tsignal?.throwIfAborted();\n\tif (!connection) throw new Error(\"Storage connection changed; reopen setup.\");\n\treturn connection;\n}\n\nexport const AUTOMATIC_SYNC_DESCRIPTION =\n\t\"Check the current setup in the background at startup; review changes in /sync before transferring. At shutdown, automatically push selected content only when sessions are included. No startup dialogs.\";\n\nexport async function chooseSetupContent(ctx: ExtensionCommandContext, signal?: AbortSignal) {\n\tconst choice = await ctx.ui.select(\n\t\t\"Choose included content\\n\\nRecommended: Pi settings, instructions, skills, prompts, themes, and extensions.\\nMinimal: settings.json and AGENTS.md.\\nReview the exact paths before saving.\",\n\t\t[\"Recommended Pi settings\", \"Minimal settings\", \"Cancel\"],\n\t\t{ signal },\n\t);\n\tsignal?.throwIfAborted();\n\tif (!choice || choice === \"Cancel\") return undefined;\n\treturn choice === \"Minimal settings\" ? [\"settings.json\", \"AGENTS.md\"] : [...DEFAULT_SYNC_INCLUDE];\n}\n\nexport async function chooseAutomaticSync(ctx: ExtensionCommandContext, signal?: AbortSignal) {\n\tconst choice = await ctx.ui.select(\n\t\t`Automatic sync for this setup\\n\\n${AUTOMATIC_SYNC_DESCRIPTION}`,\n\t\t[\"Keep automatic sync off\", \"Enable automatic sync\", \"Cancel\"],\n\t\t{ signal },\n\t);\n\tsignal?.throwIfAborted();\n\treturn !choice || choice === \"Cancel\" ? undefined : choice === \"Enable automatic sync\";\n}\n\nexport async function chooseSessions(ctx: ExtensionCommandContext, signal?: AbortSignal) {\n\tconst choice = await ctx.ui.select(\n\t\t\"Session conversations\\n\\nSessions can contain prompts, tool output, paths, screenshots, and secrets.\",\n\t\t[\"Keep sessions off (recommended)\", \"Include session conversations\", \"Cancel\"],\n\t\t{ signal },\n\t);\n\tsignal?.throwIfAborted();\n\tif (!choice || choice === \"Cancel\") return undefined;\n\tif (choice !== \"Include session conversations\") return false;\n\tconst confirmed = await ctx.ui.confirm(\n\t\t\"Include session conversations?\",\n\t\t\"I understand that session JSONL can contain prompts, tool output, paths, screenshots, and secrets.\",\n\t\t{ signal },\n\t);\n\tsignal?.throwIfAborted();\n\treturn confirmed ? true : undefined;\n}\n\nexport function includedContentLines(include: readonly string[], sessions = false) {\n\tconst paths = [...include, ...(sessions && !include.includes(\"sessions\") ? [\"sessions\"] : [])];\n\treturn [\n\t\t`Included content: ${paths.length} paths`,\n\t\t...paths.map((item) => ` ${safeTerminalText(item)}`),\n\t\t`Sessions: ${sessions ? \"On \u2014 privacy warning acknowledged\" : \"Off\"}`,\n\t];\n}\n\nexport async function promptResourceName(\n\tctx: ExtensionCommandContext,\n\tkind: \"sync setup\" | \"storage connection\",\n\tdefaultValue: string,\n\tsignal?: AbortSignal,\n\tliteralBrackets = false,\n) {\n\treturn promptTextInput(\n\t\tctx,\n\t\t`Name this ${kind}\\n\\nA local label, such as home or work.`,\n\t\t{\n\t\t\tdefaultValue,\n\t\t\trejectPlaceholders: !literalBrackets,\n\t\t\tvalidate: async (name) => {\n\t\t\t\tvalidateConfigName(name, kind);\n\t\t\t\tconst settings = await readLocalConfigObject();\n\t\t\t\tsignal?.throwIfAborted();\n\t\t\t\tconst names = kind === \"sync setup\" ? settings?.syncSetups : settings?.storageConnections;\n\t\t\t\tif (names && Object.hasOwn(names, name)) {\n\t\t\t\t\tthrow new Error(`A ${kind} with this name already exists. Choose a different name.`);\n\t\t\t\t}\n\t\t\t\treturn name;\n\t\t\t},\n\t\t},\n\t\tsignal,\n\t);\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { defineMenu, runMenu } from \"@narumitw/pi-tui-kit\";\nimport { syncErrorGuidance } from \"../../sync/sync-error-guidance.js\";\n\n/** A settings draft is committed only after review; retryable I/O failures retain the same draft. */\nexport async function saveReviewedDraft(\n\tctx: ExtensionCommandContext,\n\ttitle: string,\n\tlines: readonly string[],\n\tlabel: string,\n\tsave: (signal: AbortSignal) => Promise<unknown>,\n\tsignal?: AbortSignal,\n) {\n\tlet saved = false;\n\tlet failure: unknown;\n\tlet failureText: string | undefined;\n\tconst menu = defineMenu<undefined, \"review\", \"save\", ExtensionCommandContext>({\n\t\tstart: \"review\",\n\t\tscreens: {\n\t\t\treview: () => ({\n\t\t\t\tkind: \"review\",\n\t\t\t\ttitle,\n\t\t\t\tcontent: [...(failureText ? [failureText, \"\"] : []), ...lines].join(\"\\n\"),\n\t\t\t\tlines: [\"Review before saving. Back cancels this draft.\"],\n\t\t\t\tformat: { kind: \"text\" },\n\t\t\t\tviewportSize: \"adaptive\",\n\t\t\t\tconfirm: { id: \"save\", label, action: \"save\" },\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\tsave: async ({ signal: actionSignal }) => {\n\t\t\t\ttry {\n\t\t\t\t\tactionSignal.throwIfAborted();\n\t\t\t\t\tawait save(actionSignal);\n\t\t\t\t\tsaved = true;\n\t\t\t\t\treturn { kind: \"close\" };\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (actionSignal.aborted) return { kind: \"close\" };\n\t\t\t\t\t// Do not silently rebase a stale review or overwrite an invalid settings file.\n\t\t\t\t\t// The caller must reopen current settings for those failures.\n\t\t\t\t\tif (!retryableSettingsError(error)) {\n\t\t\t\t\t\tfailure = error;\n\t\t\t\t\t\treturn { kind: \"close\" };\n\t\t\t\t\t}\n\t\t\t\t\tfailureText = `Not saved. ${syncErrorGuidance(error)}\\nYour draft is retained. Fix the problem, then save again, or cancel.`;\n\t\t\t\t\tctx.ui.notify(failureText, \"error\");\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t});\n\tconst result = await runMenu(ctx, menu, {\n\t\tgetState: () => undefined,\n\t\tsignal,\n\t\tisCurrent: () => !signal?.aborted,\n\t});\n\tif (signal?.aborted) return false;\n\tif (failure) throw failure;\n\tif (result.kind === \"error\") throw result.error;\n\treturn saved;\n}\n\nfunction retryableSettingsError(error: unknown) {\n\tconst code = (error as NodeJS.ErrnoException | undefined)?.code;\n\treturn (\n\t\tcode !== undefined &&\n\t\t[\"EACCES\", \"EPERM\", \"ENOSPC\", \"EBUSY\", \"EIO\", \"EMFILE\", \"ENFILE\", \"EROFS\"].includes(code)\n\t);\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport {\n\tnormalizeGitBranch,\n\tnormalizeGitDirectory,\n\tnormalizeGitRemote,\n} from \"../../backends/git/git-config.js\";\nimport {\n\taddStorageConnection,\n\taddSyncSetup,\n\tsaveNewV3Settings,\n\tupdateStorageConnection,\n\tupdateSyncSetup,\n} from \"../../settings/settings-management.js\";\nimport type { PartialConfig } from \"../../settings/settings-types.js\";\nimport { automaticSyncSummary } from \"../automatic-sync-summary.js\";\nimport { safeTerminalText } from \"../terminal-text.js\";\nimport { promptAvailableSetupStorage } from \"./setup-location-ui.js\";\nimport {\n\tchooseAutomaticSync,\n\tchooseSetupContent,\n\tincludedContentLines,\n\tpromptResourceName,\n\treadSetupConnection,\n} from \"./setup-prompts.js\";\nimport { saveReviewedDraft } from \"./setup-review.js\";\nimport { requiredInput, requiredValueInput } from \"./text-input.js\";\n\nexport async function showGitSetup(\n\tctx: ExtensionCommandContext,\n\ttargetName: string,\n\tsignal?: AbortSignal,\n) {\n\tconst remote = await promptGitRemote(ctx, signal);\n\tif (!remote) return false;\n\tconst destination = await promptGitDestination(ctx, signal);\n\tif (!destination) return false;\n\tconst include = await chooseSetupContent(ctx, signal);\n\tif (!include) return false;\n\tconst automatic = await chooseAutomaticSync(ctx, signal);\n\tif (automatic === undefined) return false;\n\tconst saved = await saveReviewedDraft(\n\t\tctx,\n\t\t\"Review Git sync setup\",\n\t\t[\n\t\t\t`Sync setup: ${safeTerminalText(targetName)}`,\n\t\t\t`Storage connection: ${safeTerminalText(targetName)} (Git)`,\n\t\t\t`Remote: ${safeTerminalText(remote)}`,\n\t\t\t`Sync branch: ${safeTerminalText(destination.branch)}`,\n\t\t\t`Storage location: ${safeTerminalText(destination.directory)}`,\n\t\t\t...includedContentLines(include),\n\t\t\t`Automatic sync: ${automaticSyncSummary(automatic)}`,\n\t\t\t\"Authentication: existing Git credential helper or SSH configuration (not stored by pi-sync).\",\n\t\t\t\"pi-sync manages the entire branch. The repository must already exist; a new branch is created on first push.\",\n\t\t\t\"Saving does not contact remote storage or start syncing.\",\n\t\t],\n\t\t\"Save setup\",\n\t\t(saveSignal) =>\n\t\t\tsaveNewV3Settings(\n\t\t\t\t{\n\t\t\t\t\tsetupName: targetName,\n\t\t\t\t\tconnectionName: targetName,\n\t\t\t\t\tconnection: { type: \"git\", remote },\n\t\t\t\t\tsetup: {\n\t\t\t\t\t\tstorage: {\n\t\t\t\t\t\t\tconnection: targetName,\n\t\t\t\t\t\t\tbranch: destination.branch,\n\t\t\t\t\t\t\tpath: destination.directory,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tsync: { include, automatic },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tsaveSignal,\n\t\t\t),\n\t\tsignal,\n\t);\n\tif (saved && !signal?.aborted)\n\t\tctx.ui.notify(\n\t\t\t`Saved Git sync setup \u201C${safeTerminalText(targetName)}\u201D. Choose Sync now to start.`,\n\t\t\t\"info\",\n\t\t);\n\treturn saved;\n}\n\nexport async function showAddGitStorageProfile(ctx: ExtensionCommandContext, signal?: AbortSignal) {\n\tconst name = await promptResourceName(ctx, \"storage connection\", \"git\", signal);\n\tif (!name) return false;\n\tconst remote = await promptGitRemote(ctx, signal);\n\tif (!remote) return false;\n\tconst saved = await saveReviewedDraft(\n\t\tctx,\n\t\t\"Review storage connection\",\n\t\t[\n\t\t\t`Name: ${safeTerminalText(name)}`,\n\t\t\t\"Type: Git\",\n\t\t\t`Remote: ${safeTerminalText(remote)}`,\n\t\t\t\"Credentials: existing Git/SSH authentication (not stored)\",\n\t\t\t\"Adding a connection does not contact the remote or start syncing.\",\n\t\t],\n\t\t\"Add storage connection\",\n\t\t(saveSignal) => addStorageConnection(name, { type: \"git\", remote }, saveSignal),\n\t\tsignal,\n\t);\n\tif (saved && !signal?.aborted)\n\t\tctx.ui.notify(`Added storage connection \u201C${safeTerminalText(name)}\u201D.`, \"info\");\n\treturn saved;\n}\n\nexport async function showEditGitStorageProfile(\n\tctx: ExtensionCommandContext,\n\tname: string,\n\tprofile: Record<string, unknown>,\n\tsignal?: AbortSignal,\n\taffectedSetups?: string[],\n) {\n\tconst remote = await promptGitRemote(\n\t\tctx,\n\t\tsignal,\n\t\ttypeof profile.remote === \"string\" ? profile.remote : undefined,\n\t);\n\tif (!remote) return false;\n\tconst saved = await saveReviewedDraft(\n\t\tctx,\n\t\t\"Review storage connection\",\n\t\t[\n\t\t\t`Storage connection: ${safeTerminalText(name)}`,\n\t\t\t`Remote: ${safeTerminalText(String(profile.remote ?? \"missing\"))} \u2192 ${safeTerminalText(remote)}`,\n\t\t\t`Affected sync setups: ${affectedSetups?.length ? affectedSetups.map(safeTerminalText).join(\", \") : \"None\"}`,\n\t\t\t\"Saving changes future storage access for every affected setup; it does not move or delete remote history.\",\n\t\t],\n\t\t\"Save storage connection\",\n\t\t(saveSignal) =>\n\t\t\tupdateStorageConnection(\n\t\t\t\tname,\n\t\t\t\t(current) => {\n\t\t\t\t\tif (current.type !== \"git\" || current.remote !== profile.remote)\n\t\t\t\t\t\tthrow new Error(\"Storage connection changed while it was open; reopen it.\");\n\t\t\t\t\treturn { ...current, remote };\n\t\t\t\t},\n\t\t\t\taffectedSetups,\n\t\t\t\tsaveSignal,\n\t\t\t),\n\t\tsignal,\n\t);\n\tif (saved && !signal?.aborted)\n\t\tctx.ui.notify(`Saved storage connection \u201C${safeTerminalText(name)}\u201D.`, \"info\");\n\treturn saved;\n}\n\nexport async function showAddGitTarget(\n\tctx: ExtensionCommandContext,\n\tname: string,\n\tprofile: string,\n\tsignal?: AbortSignal,\n) {\n\tconst selected = await promptGitDestination(ctx, signal);\n\tif (!selected) return false;\n\tconst storage = await promptAvailableSetupStorage(\n\t\tctx,\n\t\t{ connection: profile, branch: selected.branch, path: selected.directory },\n\t\tsignal,\n\t);\n\tif (!storage) return false;\n\tconst include = await chooseSetupContent(ctx, signal);\n\tif (!include) return false;\n\tconst automatic = await chooseAutomaticSync(ctx, signal);\n\tif (automatic === undefined) return false;\n\tconst connection = await readSetupConnection(profile, signal);\n\tif (connection?.type !== \"git\") throw new Error(\"Storage connection changed; reopen setup.\");\n\tconst saved = await saveReviewedDraft(\n\t\tctx,\n\t\t\"Review Git sync setup\",\n\t\t[\n\t\t\t`Sync setup: ${safeTerminalText(name)}`,\n\t\t\t`Storage connection: ${safeTerminalText(profile)}`,\n\t\t\t`Remote: ${safeTerminalText(connection.remote)}`,\n\t\t\t`Sync branch: ${safeTerminalText(storage.branch)}`,\n\t\t\t`Storage location: ${safeTerminalText(storage.path)}`,\n\t\t\t...includedContentLines(include),\n\t\t\t`Automatic sync: ${automaticSyncSummary(automatic)}`,\n\t\t\t\"pi-sync manages the entire branch. Adding this setup does not sync or modify remote data.\",\n\t\t],\n\t\t\"Add sync setup\",\n\t\t(saveSignal) =>\n\t\t\taddSyncSetup(name, { storage, sync: { include, automatic } }, saveSignal, connection),\n\t\tsignal,\n\t);\n\tif (saved && !signal?.aborted)\n\t\tctx.ui.notify(`Added sync setup \u201C${safeTerminalText(name)}\u201D.`, \"info\");\n\treturn saved;\n}\n\nexport async function showEditGitTarget(\n\tctx: ExtensionCommandContext,\n\tpartial: PartialConfig,\n\tsignal?: AbortSignal,\n) {\n\tlet destination = await promptGitDestination(ctx, signal, partial);\n\tif (!destination) return false;\n\twhile (destination.directory !== partial.storagePath && destination.branch === partial.branch) {\n\t\tctx.ui.notify(\n\t\t\t\"Changing a Git storage path requires a new Git branch so the existing branch remains readable.\",\n\t\t\t\"warning\",\n\t\t);\n\t\tconst branch = await requiredValueInput(\n\t\t\tctx,\n\t\t\t\"New Git branch\\n\\nKeep the previous branch unchanged; enter a new branch for this path.\",\n\t\t\t\"pi-sync/archive\",\n\t\t\tsignal,\n\t\t\tnormalizeGitBranch,\n\t\t);\n\t\tif (!branch) return false;\n\t\tdestination = { ...destination, branch };\n\t}\n\tconst chosen = destination;\n\tconst connection = await readSetupConnection(partial.connectionName, signal);\n\tif (connection.type !== \"git\") throw new Error(\"Storage connection changed; reopen setup.\");\n\tconst saved = await saveReviewedDraft(\n\t\tctx,\n\t\t\"Review sync setup\",\n\t\t[\n\t\t\t`Sync setup: ${safeTerminalText(partial.setupName)}`,\n\t\t\t`Storage connection: ${safeTerminalText(partial.connectionName)}`,\n\t\t\t`Remote: ${safeTerminalText(connection.remote)}`,\n\t\t\t`Branch: ${safeTerminalText(partial.branch ?? \"missing\")} \u2192 ${safeTerminalText(chosen.branch)}`,\n\t\t\t`Storage path: ${safeTerminalText(partial.storagePath)} \u2192 ${safeTerminalText(chosen.directory)}`,\n\t\t\t\"Saving changes the future storage location only; it does not move or delete remote history.\",\n\t\t],\n\t\t\"Save sync setup\",\n\t\t(saveSignal) =>\n\t\t\tupdateSyncSetup(\n\t\t\t\tpartial.setupName,\n\t\t\t\t(setup) => {\n\t\t\t\t\tif (typeof setup.storage.branch !== \"string\")\n\t\t\t\t\t\tthrow new Error(\"Sync setup storage type changed; reopen it.\");\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...setup,\n\t\t\t\t\t\tstorage: { ...setup.storage, branch: chosen.branch, path: chosen.directory },\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\t{ expectedStorage: partial, expectedConnection: connection, signal: saveSignal },\n\t\t\t),\n\t\tsignal,\n\t);\n\tif (saved && !signal?.aborted)\n\t\tctx.ui.notify(`Saved sync setup \u201C${safeTerminalText(partial.setupName)}\u201D.`, \"info\");\n\treturn saved;\n}\n\nasync function promptGitRemote(\n\tctx: ExtensionCommandContext,\n\tsignal?: AbortSignal,\n\tcurrent?: string,\n) {\n\tconst title =\n\t\t\"Git remote URL (SSH or HTTPS)\\n\\nUse an existing private repository with Git/SSH authentication already configured.\";\n\tconst validate = (value: string) => {\n\t\tconst remote = normalizeGitRemote(value);\n\t\tif (!remote) throw new Error(\"Git remote URL is required.\");\n\t\treturn remote;\n\t};\n\treturn current\n\t\t? requiredInput(ctx, title, current, signal, validate)\n\t\t: requiredValueInput(\n\t\t\t\tctx,\n\t\t\t\ttitle,\n\t\t\t\t\"git@github.com:owner/private-pi-sync.git (SSH) or https://github.com/owner/private-pi-sync.git (HTTPS)\",\n\t\t\t\tsignal,\n\t\t\t\tvalidate,\n\t\t\t);\n}\n\nasync function promptGitDestination(\n\tctx: ExtensionCommandContext,\n\tsignal?: AbortSignal,\n\tcurrent: Partial<PartialConfig> = {},\n) {\n\tconst branch = await requiredInput(\n\t\tctx,\n\t\t\"Git branch for sync snapshots\\n\\npi-sync manages this entire branch, not your local working branch.\\nUse a new branch or one already used by pi-sync; unrelated content is rejected.\",\n\t\tcurrent.branch ?? \"main\",\n\t\tsignal,\n\t\tnormalizeGitBranch,\n\t);\n\tif (!branch) return undefined;\n\tconst directory = await requiredInput(\n\t\tctx,\n\t\t\"Git storage path\\n\\nRelative to the repository root, not your local filesystem.\\n./ stores manifest.json and files/ at the repository root.\",\n\t\tcurrent.storagePath ?? \"./\",\n\t\tsignal,\n\t\tnormalizeGitDirectory,\n\t);\n\treturn directory ? { branch, directory } : undefined;\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport {\n\tCURSOR_MARKER,\n\tdecodeKittyPrintable,\n\ttype Focusable,\n\tKey,\n\ttype KeybindingsManager,\n\tmatchesKey,\n\tText,\n\ttruncateToWidth,\n} from \"@earendil-works/pi-tui\";\nimport { runCustomInteraction } from \"@narumitw/pi-tui-kit\";\n\nconst MASK = \"\u2022\";\n\nexport async function promptSecret(\n\tctx: ExtensionCommandContext,\n\ttitle: string,\n\toptions: { required?: boolean; signal?: AbortSignal } = { required: true },\n) {\n\tif (ctx.mode !== \"tui\" || options.signal?.aborted) return undefined;\n\tconst result = await runCustomInteraction<string | undefined>(ctx, {\n\t\tsignal: options.signal,\n\t\tisCurrent: () => !options.signal?.aborted,\n\t\tcreate: ({ tui, theme, keybindings, complete }) => {\n\t\t\tconst heading = new Text(\"\", 0, 0);\n\t\t\tconst hint = new Text(\"\", 0, 0);\n\t\t\tconst submitKey = keybindingText(keybindings, \"tui.input.submit\", \"enter\");\n\t\t\tconst cancelKey = keybindingText(keybindings, \"tui.select.cancel\", \"esc\", [\"ctrl+c\"]);\n\t\t\tconst applyTheme = () => {\n\t\t\t\theading.setText(theme.fg(\"accent\", theme.bold(title)));\n\t\t\t\thint.setText(\n\t\t\t\t\ttheme.fg(\"dim\", `${submitKey} continue \u2022 ${cancelKey} cancel \u2022 Input is hidden`),\n\t\t\t\t);\n\t\t\t};\n\t\t\tapplyTheme();\n\t\t\tconst input = new MaskedInput(keybindings);\n\t\t\tconst component: Focusable & {\n\t\t\t\trender(width: number): string[];\n\t\t\t\tinvalidate(): void;\n\t\t\t\thandleInput(data: string): void;\n\t\t\t\tdispose(): void;\n\t\t\t} = {\n\t\t\t\tget focused() {\n\t\t\t\t\treturn input.focused;\n\t\t\t\t},\n\t\t\t\tset focused(focused: boolean) {\n\t\t\t\t\tinput.focused = focused;\n\t\t\t\t},\n\t\t\t\trender(width: number) {\n\t\t\t\t\tconst safeWidth = Math.max(1, width);\n\t\t\t\t\treturn [\n\t\t\t\t\t\t...heading.render(safeWidth),\n\t\t\t\t\t\t...input.render(safeWidth),\n\t\t\t\t\t\t...hint.render(safeWidth),\n\t\t\t\t\t].map((line) => truncateToWidth(line, safeWidth));\n\t\t\t\t},\n\t\t\t\tinvalidate() {\n\t\t\t\t\tapplyTheme();\n\t\t\t\t\theading.invalidate();\n\t\t\t\t\tinput.invalidate();\n\t\t\t\t\thint.invalidate();\n\t\t\t\t},\n\t\t\t\thandleInput(data: string) {\n\t\t\t\t\tif (matchesKey(data, Key.ctrl(\"c\"))) {\n\t\t\t\t\t\tcomplete(undefined);\n\t\t\t\t\t} else if (input.isPasting || data.includes(\"\\u001b[200~\")) {\n\t\t\t\t\t\tinput.handleInput(data);\n\t\t\t\t\t} else if (keybindings.matches(data, \"tui.select.cancel\")) {\n\t\t\t\t\t\tcomplete(undefined);\n\t\t\t\t\t} else if (keybindings.matches(data, \"tui.input.submit\")) {\n\t\t\t\t\t\tif (options.required !== false && input.getValue().length === 0) {\n\t\t\t\t\t\t\tctx.ui.notify(`${title} is required. Enter a value, or cancel.`, \"warning\");\n\t\t\t\t\t\t} else if (hasControlCharacter(input.getValue())) {\n\t\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\t\t`${title} contains control characters. Remove them or re-enter the value, then continue.`,\n\t\t\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else complete(input.getValue());\n\t\t\t\t\t} else input.handleInput(data);\n\t\t\t\t\ttui.requestRender();\n\t\t\t\t},\n\t\t\t\tdispose() {\n\t\t\t\t\tinput.clear();\n\t\t\t\t},\n\t\t\t};\n\t\t\treturn component;\n\t\t},\n\t});\n\tif (result.kind === \"error\") throw result.error;\n\tif (result.kind !== \"completed\" || result.value === undefined) return undefined;\n\tconst value = result.value;\n\tif (options.required !== false && value.length === 0) {\n\t\tctx.ui.notify(`${title} is required.`, \"warning\");\n\t\treturn undefined;\n\t}\n\treturn value;\n}\n\nclass MaskedInput implements Focusable {\n\tfocused = false;\n\tprivate value: string[] = [];\n\tprivate cursor = 0;\n\tprivate paste = \"\";\n\tprivate pasting = false;\n\n\tconstructor(private readonly keybindings: KeybindingsManager) {}\n\n\tget isPasting() {\n\t\treturn this.pasting;\n\t}\n\n\tgetValue() {\n\t\treturn this.value.join(\"\");\n\t}\n\n\thandleInput(data: string) {\n\t\tif (data.includes(\"\\u001b[200~\")) {\n\t\t\tthis.pasting = true;\n\t\t\tthis.paste = \"\";\n\t\t\tdata = data.replace(\"\\u001b[200~\", \"\");\n\t\t}\n\t\tif (this.pasting) {\n\t\t\tthis.paste += data;\n\t\t\tconst end = this.paste.indexOf(\"\\u001b[201~\");\n\t\t\tif (end < 0) return;\n\t\t\tconst pasted = this.paste\n\t\t\t\t.slice(0, end)\n\t\t\t\t.replace(/[\\r\\n]/gu, \"\")\n\t\t\t\t.replace(/\\t/gu, \" \");\n\t\t\tthis.insert(pasted);\n\t\t\tconst remaining = this.paste.slice(end + 6);\n\t\t\tthis.paste = \"\";\n\t\t\tthis.pasting = false;\n\t\t\tif (remaining) this.handleInput(remaining);\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.editor.deleteCharBackward\")) {\n\t\t\tif (this.cursor > 0) this.value.splice(--this.cursor, 1);\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.editor.deleteCharForward\")) {\n\t\t\tif (this.cursor < this.value.length) this.value.splice(this.cursor, 1);\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.editor.cursorLeft\")) {\n\t\t\tthis.cursor = Math.max(0, this.cursor - 1);\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.editor.cursorRight\")) {\n\t\t\tthis.cursor = Math.min(this.value.length, this.cursor + 1);\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.editor.cursorLineStart\")) {\n\t\t\tthis.cursor = 0;\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.editor.cursorLineEnd\")) {\n\t\t\tthis.cursor = this.value.length;\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.editor.deleteToLineStart\")) {\n\t\t\tthis.value.splice(0, this.cursor);\n\t\t\tthis.cursor = 0;\n\t\t\treturn;\n\t\t}\n\t\tif (this.keybindings.matches(data, \"tui.editor.deleteToLineEnd\")) {\n\t\t\tthis.value.splice(this.cursor);\n\t\t\treturn;\n\t\t}\n\t\tconst printable = decodeKittyPrintable(data) ?? data;\n\t\tif (!hasControlCharacter(printable)) this.insert(printable);\n\t}\n\n\trender(width: number) {\n\t\tconst prompt = \"> \";\n\t\tconst available = width - prompt.length;\n\t\tif (available <= 0) return [truncateToWidth(prompt, Math.max(1, width))];\n\t\tconst contentWidth = Math.max(0, available - 1);\n\t\tlet start = 0;\n\t\tif (this.value.length > contentWidth) {\n\t\t\tstart = Math.max(\n\t\t\t\t0,\n\t\t\t\tMath.min(this.cursor - Math.floor(contentWidth / 2), this.value.length - contentWidth),\n\t\t\t);\n\t\t}\n\t\tconst end = Math.min(this.value.length, start + contentWidth);\n\t\tconst visibleCursor = Math.max(0, Math.min(this.cursor - start, end - start));\n\t\tconst masks = Array.from({ length: end - start }, () => MASK);\n\t\tconst before = masks.slice(0, visibleCursor).join(\"\");\n\t\tconst atCursor = visibleCursor < masks.length ? MASK : \" \";\n\t\tconst after = masks.slice(visibleCursor + (visibleCursor < masks.length ? 1 : 0)).join(\"\");\n\t\tconst marker = this.focused ? CURSOR_MARKER : \"\";\n\t\tconst line = `${prompt}${before}${marker}\\u001b[7m${atCursor}\\u001b[27m${after}`;\n\t\treturn [truncateToWidth(line, width, \"\")];\n\t}\n\n\tinvalidate() {}\n\n\tclear() {\n\t\tthis.value.fill(\"\");\n\t\tthis.value = [];\n\t\tthis.paste = \"\";\n\t\tthis.cursor = 0;\n\t\tthis.pasting = false;\n\t}\n\n\tprivate insert(value: string) {\n\t\tconst characters = Array.from(value);\n\t\tthis.value.splice(this.cursor, 0, ...characters);\n\t\tthis.cursor += characters.length;\n\t}\n}\n\nfunction keybindingText(\n\tkeybindings: Pick<KeybindingsManager, \"getKeys\">,\n\tbinding: Parameters<KeybindingsManager[\"getKeys\"]>[0],\n\tfallback: string,\n\tadditionalKeys: readonly string[] = [],\n) {\n\tconst keys = [...new Set([...keybindings.getKeys(binding), ...additionalKeys])]\n\t\t.map(String)\n\t\t.map((key) => {\n\t\t\tif (key === \"return\") return \"enter\";\n\t\t\tif (key === \"escape\") return \"esc\";\n\t\t\treturn hasControlCharacter(key) ? \"\" : key;\n\t\t})\n\t\t.filter(Boolean);\n\treturn keys.join(\"/\") || fallback;\n}\n\nfunction hasControlCharacter(value: string) {\n\treturn [...value].some((character) => {\n\t\tconst code = character.codePointAt(0) ?? 0;\n\t\treturn code < 0x20 || (code >= 0x7f && code <= 0x9f);\n\t});\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { promptSecret } from \"../secret-input.js\";\nimport { requiredValueInput } from \"./text-input.js\";\n\nexport interface ChosenS3Credentials {\n\tprofileFields: { accessKeyId?: string; secretAccessKey?: string };\n\tsummary: string;\n\tready: boolean;\n\treplace?: boolean;\n}\n\nexport async function chooseS3CredentialUpdate(\n\tctx: ExtensionCommandContext,\n\tprofile: Record<string, unknown>,\n\tsignal?: AbortSignal,\n) {\n\tconst hasStored =\n\t\ttypeof profile.accessKeyId === \"string\" &&\n\t\tprofile.accessKeyId.length > 0 &&\n\t\ttypeof profile.secretAccessKey === \"string\" &&\n\t\tprofile.secretAccessKey.length > 0;\n\tif (hasStored) {\n\t\tconst action = await ctx.ui.select(\n\t\t\t\"Credentials\",\n\t\t\t[\"Keep current credentials\", \"Replace credentials\", \"Cancel\"],\n\t\t\t{ signal },\n\t\t);\n\t\tthrowIfAborted(signal);\n\t\tif (!action || action === \"Cancel\") return undefined;\n\t\tif (action === \"Keep current credentials\") {\n\t\t\treturn { profileFields: {}, summary: \"Unchanged (values hidden)\", ready: true };\n\t\t}\n\t}\n\tconst selected = await chooseS3Credentials(ctx, signal);\n\treturn selected ? { ...selected, replace: true } : undefined;\n}\n\nexport function applyS3CredentialUpdate(\n\tprofile: Record<string, unknown>,\n\tcredentials: ChosenS3Credentials,\n) {\n\tconst next = { ...profile };\n\tif (credentials.replace) {\n\t\tdelete next.accessKeyId;\n\t\tdelete next.secretAccessKey;\n\t\tdelete next.sessionToken;\n\t}\n\treturn { ...next, ...credentials.profileFields };\n}\n\nexport async function chooseS3Credentials(\n\tctx: ExtensionCommandContext,\n\tsignal?: AbortSignal,\n): Promise<ChosenS3Credentials | undefined> {\n\tconst choice = await ctx.ui.select(\n\t\t\"Credentials\\n\\nCredentials are stored in the private pi-sync settings file. Secret values are masked during input and never shown afterward.\",\n\t\t[\"Store credentials privately\", \"Cancel\"],\n\t\t{ signal },\n\t);\n\tthrowIfAborted(signal);\n\tif (choice !== \"Store credentials privately\") return undefined;\n\tconst accessKeyId = await requiredValueInput(\n\t\tctx,\n\t\t\"Access key ID\\n\\nUse the S3 API access key ID issued by your provider, not the secret access key.\",\n\t\t\"access-key-id\",\n\t\tsignal,\n\t);\n\tif (!accessKeyId) return undefined;\n\tconst secretAccessKey = await promptSecret(ctx, \"Secret access key\", { signal });\n\tthrowIfAborted(signal);\n\tif (secretAccessKey === undefined) return undefined;\n\treturn {\n\t\tprofileFields: { accessKeyId, secretAccessKey },\n\t\tsummary: \"Stored privately (values hidden)\",\n\t\tready: true,\n\t};\n}\n\nfunction throwIfAborted(signal?: AbortSignal) {\n\tif (!signal?.aborted) return;\n\tthrow signal.reason instanceof Error\n\t\t? signal.reason\n\t\t: new DOMException(\"The operation was aborted\", \"AbortError\");\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { refreshTargetCompletions } from \"../../commands/setup-completions.js\";\nimport {\n\taddSyncSetup,\n\tsaveNewV3Settings,\n\tupdateSyncSetup,\n} from \"../../settings/settings-management.js\";\nimport type { PartialConfig } from \"../../settings/settings-types.js\";\nimport {\n\tnormalizeS3Bucket,\n\tnormalizeS3Endpoint,\n\tnormalizeStoragePath,\n} from \"../../settings/settings-validation.js\";\nimport { automaticSyncSummary } from \"../automatic-sync-summary.js\";\nimport { safeTerminalText } from \"../terminal-text.js\";\nimport { chooseS3Credentials } from \"./s3-credentials-ui.js\";\nimport {\n\tchooseAdditionalRemoteLocation,\n\tchooseInitialRemoteLocation,\n\tpromptAvailableSetupStorage,\n} from \"./setup-location-ui.js\";\nimport {\n\tchooseAutomaticSync,\n\tchooseSessions,\n\tchooseSetupContent,\n\tincludedContentLines,\n\treadSetupConnection,\n} from \"./setup-prompts.js\";\nimport { saveReviewedDraft } from \"./setup-review.js\";\nimport { requiredInput, requiredValueInput } from \"./text-input.js\";\n\nexport async function showS3Setup(\n\tctx: ExtensionCommandContext,\n\tpreset: string,\n\ttargetName: string,\n\tsignal?: AbortSignal,\n) {\n\tconst endpoint = await requiredValueInput(\n\t\tctx,\n\t\tpreset === \"Cloudflare R2\"\n\t\t\t? \"Cloudflare R2 endpoint\\n\\nCopy the S3 API endpoint from your R2 account; replace <account-id>.\"\n\t\t\t: \"S3-compatible endpoint\\n\\nUse your provider's S3 API URL, not its web console.\",\n\t\tpreset === \"Cloudflare R2\"\n\t\t\t? \"https://<account-id>.r2.cloudflarestorage.com\"\n\t\t\t: \"https://s3.example.com\",\n\t\tsignal,\n\t\tnormalizeS3Endpoint,\n\t);\n\tif (!endpoint) return false;\n\tconst region =\n\t\tpreset === \"Cloudflare R2\"\n\t\t\t? \"auto\"\n\t\t\t: await requiredInput(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"Storage region\\n\\nUse the region assigned to your bucket by the provider.\",\n\t\t\t\t\t\"us-east-1\",\n\t\t\t\t\tsignal,\n\t\t\t\t);\n\tif (!region) return false;\n\tconst location = await chooseInitialRemoteLocation(ctx, preset, targetName, signal);\n\tif (!location) return false;\n\tconst credentials = await chooseS3Credentials(ctx, signal);\n\tif (!credentials) return false;\n\tconst include = await chooseSetupContent(ctx, signal);\n\tif (!include) return false;\n\tconst automatic = await chooseAutomaticSync(ctx, signal);\n\tif (automatic === undefined) return false;\n\tconst sessions = await chooseSessions(ctx, signal);\n\tif (sessions === undefined) return false;\n\tconst saved = await saveReviewedDraft(\n\t\tctx,\n\t\t\"Review sync setup\",\n\t\t[\n\t\t\t`Sync setup: ${safeTerminalText(targetName)}`,\n\t\t\t`Storage connection: ${safeTerminalText(location.connectionName)} (${preset})`,\n\t\t\t`Endpoint: ${safeTerminalText(endpoint)}`,\n\t\t\t`Region: ${safeTerminalText(region)}`,\n\t\t\t`Bucket: ${safeTerminalText(location.bucket)}`,\n\t\t\t`Storage location: ${safeTerminalText(location.path)}`,\n\t\t\t...includedContentLines(include, sessions),\n\t\t\t`Automatic sync: ${automaticSyncSummary(automatic)}`,\n\t\t\t`Credentials: ${credentials.summary}`,\n\t\t\t\"The bucket must already exist. Saving does not contact remote storage or start syncing.\",\n\t\t],\n\t\t\"Save sync setup\",\n\t\t(saveSignal) =>\n\t\t\tsaveNewV3Settings(\n\t\t\t\t{\n\t\t\t\t\tsetupName: targetName,\n\t\t\t\t\tconnectionName: location.connectionName,\n\t\t\t\t\tconnection: {\n\t\t\t\t\t\ttype: \"s3\",\n\t\t\t\t\t\tendpoint,\n\t\t\t\t\t\tregion,\n\t\t\t\t\t\tcredentials: {\n\t\t\t\t\t\t\taccessKeyId: credentials.profileFields.accessKeyId ?? \"\",\n\t\t\t\t\t\t\tsecretAccessKey: credentials.profileFields.secretAccessKey ?? \"\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tsetup: {\n\t\t\t\t\t\tstorage: {\n\t\t\t\t\t\t\tconnection: location.connectionName,\n\t\t\t\t\t\t\tbucket: location.bucket,\n\t\t\t\t\t\t\tpath: location.path,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tsync: { include: [...include, ...(sessions ? [\"sessions\"] : [])], automatic },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tsaveSignal,\n\t\t\t),\n\t\tsignal,\n\t);\n\tif (!saved || signal?.aborted) return false;\n\tawait refreshTargetCompletions();\n\tif (!signal?.aborted)\n\t\tctx.ui.notify(\n\t\t\t`Sync setup \u201C${safeTerminalText(targetName)}\u201D saved. Choose Sync now to start.`,\n\t\t\t\"info\",\n\t\t);\n\treturn true;\n}\n\nexport async function showAddS3Target(\n\tctx: ExtensionCommandContext,\n\traw: Record<string, unknown>,\n\tprofile: string,\n\tname: string,\n\tsignal?: AbortSignal,\n) {\n\tconst location = await chooseAdditionalRemoteLocation(ctx, raw, profile, name, signal);\n\tif (!location) return;\n\tconst storage = await promptAvailableSetupStorage(\n\t\tctx,\n\t\t{ connection: profile, ...location },\n\t\tsignal,\n\t);\n\tif (!storage) return;\n\tconst include = await chooseSetupContent(ctx, signal);\n\tif (!include) return;\n\tconst automatic = await chooseAutomaticSync(ctx, signal);\n\tif (automatic === undefined) return;\n\tconst connection = await readSetupConnection(profile, signal);\n\tif (connection.type !== \"s3\") throw new Error(\"Storage connection changed; reopen setup.\");\n\tconst saved = await saveReviewedDraft(\n\t\tctx,\n\t\t\"Review new sync setup\",\n\t\t[\n\t\t\t`Sync setup: ${safeTerminalText(name)}`,\n\t\t\t`Storage connection: ${safeTerminalText(profile)}`,\n\t\t\t`Endpoint: ${safeTerminalText(connection.endpoint)}`,\n\t\t\t`Bucket: ${safeTerminalText(storage.bucket)}`,\n\t\t\t`Storage location: ${safeTerminalText(storage.path)}`,\n\t\t\t...includedContentLines(include),\n\t\t\t`Automatic sync: ${automaticSyncSummary(automatic)}`,\n\t\t\t\"Only the current setup is checked at startup. Shutdown can push selected content when sessions are included.\",\n\t\t\t\"The bucket must already exist. Adding this setup does not sync or modify remote data.\",\n\t\t],\n\t\t\"Add sync setup\",\n\t\t(saveSignal) =>\n\t\t\taddSyncSetup(name, { storage, sync: { include, automatic } }, saveSignal, connection),\n\t\tsignal,\n\t);\n\tif (!saved || signal?.aborted) return;\n\tawait refreshTargetCompletions();\n\tif (!signal?.aborted) ctx.ui.notify(`Added sync setup \u201C${safeTerminalText(name)}\u201D.`, \"info\");\n}\n\nexport async function showEditS3Target(\n\tctx: ExtensionCommandContext,\n\tpartial: PartialConfig,\n\tsignal?: AbortSignal,\n) {\n\tconst bucket = await requiredInput(\n\t\tctx,\n\t\t\"Bucket\\n\\nUse an existing bucket; pi-sync will not create it.\",\n\t\tpartial.bucket ?? \"pi-sync\",\n\t\tsignal,\n\t\tnormalizeS3Bucket,\n\t);\n\tif (!bucket) return;\n\tconst storagePath = await requiredInput(\n\t\tctx,\n\t\t\"Storage path\\n\\nPath inside the bucket, not your local filesystem. ./ uses the bucket root.\",\n\t\tpartial.storagePath,\n\t\tsignal,\n\t\tnormalizeStoragePath,\n\t);\n\tif (!storagePath) return;\n\tconst connection = await readSetupConnection(partial.connectionName, signal);\n\tif (connection.type !== \"s3\") throw new Error(\"Storage connection changed; reopen setup.\");\n\tconst saved = await saveReviewedDraft(\n\t\tctx,\n\t\t\"Review sync setup\",\n\t\t[\n\t\t\t`Sync setup: ${safeTerminalText(partial.setupName)}`,\n\t\t\t`Storage connection: ${safeTerminalText(partial.connectionName)}`,\n\t\t\t`Endpoint: ${safeTerminalText(connection.endpoint)}`,\n\t\t\t`Bucket: ${safeTerminalText(partial.bucket ?? \"missing\")} \u2192 ${safeTerminalText(bucket)}`,\n\t\t\t`Storage path: ${safeTerminalText(partial.storagePath)} \u2192 ${safeTerminalText(storagePath)}`,\n\t\t\t\"Saving changes the future storage location only; it does not move or delete remote data.\",\n\t\t],\n\t\t\"Save sync setup\",\n\t\t(saveSignal) =>\n\t\t\tupdateSyncSetup(\n\t\t\t\tpartial.setupName,\n\t\t\t\t(setup) => {\n\t\t\t\t\tif (typeof setup.storage.bucket !== \"string\")\n\t\t\t\t\t\tthrow new Error(\"Sync setup storage type changed; reopen it.\");\n\t\t\t\t\treturn { ...setup, storage: { ...setup.storage, bucket, path: storagePath } };\n\t\t\t\t},\n\t\t\t\t{ expectedStorage: partial, expectedConnection: connection, signal: saveSignal },\n\t\t\t),\n\t\tsignal,\n\t);\n\tif (saved && !signal?.aborted)\n\t\tctx.ui.notify(`Saved sync setup \u201C${safeTerminalText(partial.setupName)}\u201D.`, \"info\");\n}\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport {\n\tnormalizeWebDavPath,\n\tnormalizeWebDavUrl,\n\tvalidateWebDavCredentials,\n} from \"../../backends/webdav/webdav-config.js\";\nimport {\n\taddStorageConnection,\n\taddSyncSetup,\n\tsaveNewV3Settings,\n\tupdateStorageConnection,\n\tupdateSyncSetup,\n} from \"../../settings/settings-management.js\";\nimport type { PartialConfig } from \"../../settings/settings-types.js\";\nimport { automaticSyncSummary } from \"../automatic-sync-summary.js\";\nimport { promptSecret } from \"../secret-input.js\";\nimport { safeTerminalText as safe } from \"../terminal-text.js\";\nimport { promptAvailableSetupStorage } from \"./setup-location-ui.js\";\nimport {\n\tchooseAutomaticSync,\n\tchooseSessions,\n\tchooseSetupContent,\n\tincludedContentLines,\n\tpromptResourceName,\n\treadSetupConnection,\n} from \"./setup-prompts.js\";\nimport { saveReviewedDraft } from \"./setup-review.js\";\nimport { promptTextInput } from \"./text-input.js\";\n\nexport async function showWebDavSetup(\n\tctx: ExtensionCommandContext,\n\ttargetName: string,\n\tsignal?: AbortSignal,\n) {\n\tconst url = await promptWebDavUrl(ctx, signal);\n\tif (!url) return false;\n\tconst username = await promptUsername(ctx, signal);\n\tif (!username) return false;\n\tconst password = await promptSecret(ctx, \"WebDAV password\", { signal });\n\tsignal?.throwIfAborted();\n\tif (password === undefined) return false;\n\tconst remotePath = await chooseDestination(ctx, signal);\n\tif (!remotePath) return false;\n\tconst include = await chooseSetupContent(ctx, signal);\n\tif (!include) return false;\n\tconst automatic = await chooseAutomaticSync(ctx, signal);\n\tif (automatic === undefined) return false;\n\tconst sessions = await chooseSessions(ctx, signal);\n\tif (sessions === undefined) return false;\n\tconst saved = await saveReviewedDraft(\n\t\tctx,\n\t\t\"Review WebDAV setup\",\n\t\t[\n\t\t\t`Sync setup: ${safe(targetName)}`,\n\t\t\t`Storage connection: ${safe(targetName)} (WebDAV)`,\n\t\t\t`URL: ${safe(url)}`,\n\t\t\t`Storage location: ${safe(remotePath)}`,\n\t\t\t\"Username and password: stored privately (values hidden)\",\n\t\t\t...includedContentLines(include, sessions),\n\t\t\t`Automatic sync: ${automaticSyncSummary(automatic)}`,\n\t\t\t\"Check setup tests whether this server can safely save sync updates using a temporary probe.\",\n\t\t\t\"Saving does not contact remote storage or start syncing.\",\n\t\t],\n\t\t\"Save setup\",\n\t\t(saveSignal) =>\n\t\t\tsaveNewV3Settings(\n\t\t\t\t{\n\t\t\t\t\tsetupName: targetName,\n\t\t\t\t\tconnectionName: targetName,\n\t\t\t\t\tconnection: { type: \"webdav\", url, credentials: { username, password } },\n\t\t\t\t\tsetup: {\n\t\t\t\t\t\tstorage: { connection: targetName, path: remotePath },\n\t\t\t\t\t\tsync: { include: [...include, ...(sessions ? [\"sessions\"] : [])], automatic },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tsaveSignal,\n\t\t\t),\n\t\tsignal,\n\t);\n\tif (saved && !signal?.aborted)\n\t\tctx.ui.notify(`Sync setup \u201C${safe(targetName)}\u201D saved. Choose Sync now to start.`, \"info\");\n\treturn saved;\n}\n\nexport async function showAddWebDavTarget(\n\tctx: ExtensionCommandContext,\n\tname: string,\n\tprofile: string,\n\tsignal?: AbortSignal,\n) {\n\tconst remotePath = await chooseDestination(ctx, signal);\n\tif (!remotePath) return false;\n\tconst storage = await promptAvailableSetupStorage(\n\t\tctx,\n\t\t{ connection: profile, path: remotePath },\n\t\tsignal,\n\t);\n\tif (!storage) return false;\n\tconst include = await chooseSetupContent(ctx, signal);\n\tif (!include) return false;\n\tconst automatic = await chooseAutomaticSync(ctx, signal);\n\tif (automatic === undefined) return false;\n\tconst connection = await readSetupConnection(profile, signal);\n\tif (connection.type !== \"webdav\") throw new Error(\"Storage connection changed; reopen setup.\");\n\tconst saved = await saveReviewedDraft(\n\t\tctx,\n\t\t\"Review WebDAV sync setup\",\n\t\t[\n\t\t\t`Sync setup: ${safe(name)}`,\n\t\t\t`Storage connection: ${safe(profile)}`,\n\t\t\t`URL: ${safe(connection.url)}`,\n\t\t\t`Storage location: ${safe(storage.path)}`,\n\t\t\t...includedContentLines(include),\n\t\t\t`Automatic sync: ${automaticSyncSummary(automatic)}`,\n\t\t\t\"Adding this setup does not sync or modify remote data.\",\n\t\t],\n\t\t\"Add sync setup\",\n\t\t(saveSignal) =>\n\t\t\taddSyncSetup(name, { storage, sync: { include, automatic } }, saveSignal, connection),\n\t\tsignal,\n\t);\n\tif (saved && !signal?.aborted) ctx.ui.notify(`Added sync setup \u201C${safe(name)}\u201D.`, \"info\");\n\treturn saved;\n}\n\nexport async function showEditWebDavTarget(\n\tctx: ExtensionCommandContext,\n\tpartial: PartialConfig,\n\tsignal?: AbortSignal,\n) {\n\tconst remotePath = await chooseDestination(ctx, signal, partial.storagePath);\n\tif (!remotePath) return false;\n\tconst connection = await readSetupConnection(partial.connectionName, signal);\n\tif (connection.type !== \"webdav\") throw new Error(\"Storage connection changed; reopen setup.\");\n\tconst saved = await saveReviewedDraft(\n\t\tctx,\n\t\t\"Review sync setup\",\n\t\t[\n\t\t\t`Sync setup: ${safe(partial.setupName)}`,\n\t\t\t`Storage connection: ${safe(partial.connectionName)}`,\n\t\t\t`URL: ${safe(connection.url)}`,\n\t\t\t`Storage path: ${safe(partial.storagePath)} \u2192 ${safe(remotePath)}`,\n\t\t\t\"Saving changes the future storage location only; it does not move or delete remote data.\",\n\t\t],\n\t\t\"Save sync setup\",\n\t\t(saveSignal) =>\n\t\t\tupdateSyncSetup(\n\t\t\t\tpartial.setupName,\n\t\t\t\t(setup) => ({\n\t\t\t\t\t...setup,\n\t\t\t\t\tstorage: { ...setup.storage, path: remotePath },\n\t\t\t\t}),\n\t\t\t\t{ expectedStorage: partial, expectedConnection: connection, signal: saveSignal },\n\t\t\t),\n\t\tsignal,\n\t);\n\tif (saved && !signal?.aborted)\n\t\tctx.ui.notify(`Saved sync setup \u201C${safe(partial.setupName)}\u201D.`, \"info\");\n\treturn saved;\n}\n\nexport async function showAddWebDavStorageProfile(\n\tctx: ExtensionCommandContext,\n\tsignal?: AbortSignal,\n) {\n\tconst name = await promptResourceName(ctx, \"storage connection\", \"webdav\", signal, true);\n\tif (!name) return false;\n\tconst url = await promptWebDavUrl(ctx, signal);\n\tif (!url) return false;\n\tconst username = await promptUsername(ctx, signal);\n\tif (!username) return false;\n\tconst password = await promptSecret(ctx, \"WebDAV password\", { signal });\n\tsignal?.throwIfAborted();\n\tif (password === undefined) return false;\n\tconst saved = await saveReviewedDraft(\n\t\tctx,\n\t\t\"Review storage connection\",\n\t\t[\n\t\t\t`Name: ${safe(name)}`,\n\t\t\t\"Type: WebDAV\",\n\t\t\t`URL: ${safe(url)}`,\n\t\t\t\"Username and password: stored privately (values hidden)\",\n\t\t\t\"Adding a connection does not contact the server or start syncing.\",\n\t\t],\n\t\t\"Add storage connection\",\n\t\t(saveSignal) =>\n\t\t\taddStorageConnection(\n\t\t\t\tname,\n\t\t\t\t{ type: \"webdav\", url, credentials: { username, password } },\n\t\t\t\tsaveSignal,\n\t\t\t),\n\t\tsignal,\n\t);\n\tif (saved && !signal?.aborted) ctx.ui.notify(`Added storage connection \u201C${safe(name)}\u201D.`, \"info\");\n\treturn saved;\n}\n\nexport async function showEditWebDavStorageProfile(\n\tctx: ExtensionCommandContext,\n\tname: string,\n\tprofile: Record<string, unknown>,\n\tsignal?: AbortSignal,\n\taffectedSetups?: string[],\n) {\n\tconst url = await promptWebDavUrl(\n\t\tctx,\n\t\tsignal,\n\t\ttypeof profile.url === \"string\" ? profile.url : undefined,\n\t);\n\tif (!url) return false;\n\tconst username = await promptUsername(ctx, signal);\n\tif (!username) return false;\n\tconst hasPassword = typeof profile.password === \"string\" && profile.password.length > 0;\n\tconst passwordAction = hasPassword\n\t\t? await select(\n\t\t\t\tctx,\n\t\t\t\t\"WebDAV password\",\n\t\t\t\t[\"Keep current password\", \"Replace password\", \"Cancel\"],\n\t\t\t\tsignal,\n\t\t\t)\n\t\t: \"Replace password\";\n\tif (!passwordAction || passwordAction === \"Cancel\") return false;\n\tconst replacePassword = passwordAction === \"Replace password\";\n\tconst password = replacePassword\n\t\t? await promptSecret(ctx, \"New WebDAV password\", { signal })\n\t\t: undefined;\n\tsignal?.throwIfAborted();\n\tif (replacePassword && password === undefined) return false;\n\tconst saved = await saveReviewedDraft(\n\t\tctx,\n\t\t\"Review storage connection\",\n\t\t[\n\t\t\t`Storage connection: ${safe(name)}`,\n\t\t\t`URL: ${safe(String(profile.url))} \u2192 ${safe(url)}`,\n\t\t\t\"Username: stored privately (value hidden)\",\n\t\t\t`Password: ${replacePassword ? \"will be replaced\" : \"unchanged\"} (value hidden)`,\n\t\t\t`Affected sync setups: ${affectedSetups?.length ? affectedSetups.map(safe).join(\", \") : \"None\"}`,\n\t\t\t\"Saving changes future storage access for every affected setup; it does not move remote data.\",\n\t\t],\n\t\t\"Save storage connection\",\n\t\t(saveSignal) =>\n\t\t\tupdateStorageConnection(\n\t\t\t\tname,\n\t\t\t\t(current) => {\n\t\t\t\t\tif (\n\t\t\t\t\t\tcurrent.type !== \"webdav\" ||\n\t\t\t\t\t\tcurrent.url !== profile.url ||\n\t\t\t\t\t\tcurrent.credentials.username !== profile.username ||\n\t\t\t\t\t\tcurrent.credentials.password !== profile.password\n\t\t\t\t\t)\n\t\t\t\t\t\tthrow new Error(\"Storage connection changed while it was open; reopen it.\");\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...current,\n\t\t\t\t\t\turl,\n\t\t\t\t\t\tcredentials: {\n\t\t\t\t\t\t\t...current.credentials,\n\t\t\t\t\t\t\tusername,\n\t\t\t\t\t\t\tpassword: password ?? current.credentials.password,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\taffectedSetups,\n\t\t\t\tsaveSignal,\n\t\t\t),\n\t\tsignal,\n\t);\n\tif (saved && !signal?.aborted) ctx.ui.notify(`Saved storage connection \u201C${safe(name)}\u201D.`, \"info\");\n\treturn saved;\n}\n\nasync function chooseDestination(\n\tctx: ExtensionCommandContext,\n\tsignal?: AbortSignal,\n\tcurrent = \"./\",\n) {\n\treturn promptTextInput(\n\t\tctx,\n\t\t\"WebDAV storage path\\n\\nFolder relative to the collection URL, not your local filesystem.\\n./ uses the collection root. Use different folders for independent setups.\",\n\t\t{ defaultValue: current, validate: normalizeWebDavPath },\n\t\tsignal,\n\t);\n}\n\nasync function promptUsername(ctx: ExtensionCommandContext, signal?: AbortSignal) {\n\treturn promptTextInput(\n\t\tctx,\n\t\t\"WebDAV username\\n\\nEnter the account username; stored values remain hidden.\",\n\t\t{\n\t\t\texample: \"user\",\n\t\t\tvalidate: (value) => {\n\t\t\t\tvalidateWebDavCredentials(value);\n\t\t\t\treturn value;\n\t\t\t},\n\t\t},\n\t\tsignal,\n\t);\n}\n\nasync function promptWebDavUrl(\n\tctx: ExtensionCommandContext,\n\tsignal?: AbortSignal,\n\tcurrent?: string,\n) {\n\treturn promptTextInput(\n\t\tctx,\n\t\t\"WebDAV collection URL\\n\\nUse the HTTPS WebDAV URL from your provider, not its web login page.\",\n\t\t{\n\t\t\t...(current\n\t\t\t\t? { defaultValue: current }\n\t\t\t\t: { example: \"https://cloud.example.com/remote.php/dav/files/user\" }),\n\t\t\tvalidate: (value) => {\n\t\t\t\tconst url = normalizeWebDavUrl(value);\n\t\t\t\tif (!url) throw new Error(\"WebDAV URL is required.\");\n\t\t\t\treturn url;\n\t\t\t},\n\t\t},\n\t\tsignal,\n\t);\n}\n\nasync function select(\n\tctx: ExtensionCommandContext,\n\ttitle: string,\n\toptions: string[],\n\tsignal?: AbortSignal,\n) {\n\tconst value = await ctx.ui.select(title, options, { signal });\n\tsignal?.throwIfAborted();\n\treturn value;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,eAAsB,2BAA2B;AAChD,0BAAwB,MAAM,yBAAyB,CAAC;AACzD;;;ACEA,eAAsB,uBACrB,KACA,SACA,QACC;AACD,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEA,eAAsB,cACrB,KACA,OACA,cACA,QACA,UACC;AACD,SAAO,gBAAgB,KAAK,OAAO,EAAE,cAAc,UAAU,oBAAoB,KAAK,GAAG,MAAM;AAChG;AAEA,eAAsB,mBACrB,KACA,OACA,SACA,QACA,UACC;AACD,SAAO,gBAAgB,KAAK,OAAO,EAAE,SAAS,UAAU,oBAAoB,KAAK,GAAG,MAAM;AAC3F;AAEA,eAAsB,gBACrB,KACA,OACA,SAMA,QACC;AAED,QAAM,OACL,QAAQ,iBAAiB,SACtB,YAAY,iBAAiB,QAAQ,YAAY,CAAC,2BAClD,YAAY,iBAAiB,QAAQ,WAAW,EAAE,CAAC;AAAA;AACvD,SAAO,MAAM;AACZ,YAAQ,eAAe;AACvB,UAAM,QAAQ,MAAM,IAAI,GAAG,MAAM,GAAG,KAAK;AAAA;AAAA,EAAO,IAAI,IAAI,QAAW,EAAE,OAAO,CAAC;AAC7E,YAAQ,eAAe;AACvB,QAAI,UAAU,OAAW,QAAO;AAChC,QAAI;AACH,YAAM,aAAa,MAAM,KAAK,KAAK,QAAQ;AAC3C,UAAI,CAAC,WAAY,OAAM,IAAI,MAAM,GAAG,MAAM,MAAM,IAAI,EAAE,CAAC,CAAC,eAAe;AACvE,UAAI,QAAQ,sBAAsB,QAAQ,KAAK,UAAU,GAAG;AAC3D,cAAM,IAAI,MAAM,wEAAwE;AAAA,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AM,MAAM;AAChG,SAAO;AACR;AAEA,eAAe,kBACd,KACA,QACA,UAAU,MACT;AACD,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA,EAAE,cAAc,SAAS,UAAU,oBAAoB;AAAA,IACvD;AAAA,EACD;AACD;AAEA,eAAe,eAAe,KAA8B,QAAsB;AACjF,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,MACC,SAAS;AAAA,MACT,UAAU,CAAC,UAAU;AACpB,kCAA0B,KAAK;AAC/B,eAAO;AAAA,MACR;AAAA,IACD;AAAA,IACA;AAAA,EACD;AACD;AAEA,eAAe,gBACd,KACA,QACA,SACC;AACD,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,MACC,GAAI,UACD,EAAE,cAAc,QAAQ,IACxB,EAAE,SAAS,sDAAsD;AAAA,MACpE,UAAU,CAAC,UAAU;AACpB,cAAM,MAAM,mBAAmB,KAAK;AACpC,YAAI,CAAC,IAAK,OAAM,IAAI,MAAM,yBAAyB;AACnD,eAAO;AAAA,MACR;AAAA,IACD;AAAA,IACA;AAAA,EACD;AACD;AAEA,eAAe,OACd,KACA,OACA,SACA,QACC;AACD,QAAM,QAAQ,MAAM,IAAI,GAAG,OAAO,OAAO,SAAS,EAAE,OAAO,CAAC;AAC5D,UAAQ,eAAe;AACvB,SAAO;AACR;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/settings/settings-management.ts"],
|
|
4
|
-
"sourcesContent": ["import { isDeepStrictEqual } from \"node:util\";\nimport { normalizeSyncInclude } from \"../sync/sync-policy.js\";\nimport { type SyncSetupStorageReview, syncSetupStorageReview } from \"./config.js\";\nimport { localConfigPath } from \"./config-file.js\";\nimport { updateLocalConfig } from \"./settings-store.js\";\nimport type {\n\tPiSyncSettingsV3,\n\tStorageConnectionSettings,\n\tSyncSetupSettings,\n} from \"./settings-types.js\";\nimport { effectiveSyncSetupRemoteIdentity, validateConfigName } from \"./settings-validation.js\";\n\nexport class SyncSetupReviewChangedError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"SyncSetupReviewChangedError\";\n\t}\n}\n\nexport async function saveNewV3Settings(\n\tinput: {\n\t\tsetupName: string;\n\t\tconnectionName: string;\n\t\tconnection: StorageConnectionSettings;\n\t\tsetup: SyncSetupSettings;\n\t},\n\tsignal?: AbortSignal,\n) {\n\tvalidateConfigName(input.setupName, \"sync setup\");\n\tvalidateConfigName(input.connectionName, \"storage connection\");\n\tconst settings: PiSyncSettingsV3 = {\n\t\tversion: 3,\n\t\tactiveSyncSetup: input.setupName,\n\t\tonSwitch: \"ask-before-pull\",\n\t\tskipSecretScan: false,\n\t\tstorageConnections: { [input.connectionName]: structuredClone(input.connection) },\n\t\tsyncSetups: {\n\t\t\t[input.setupName]: {\n\t\t\t\t...structuredClone(input.setup),\n\t\t\t\tstorage: { ...input.setup.storage, connection: input.connectionName },\n\t\t\t},\n\t\t},\n\t};\n\treturn updateLocalConfig((current) => {\n\t\tif (Object.keys(current.storageConnections).length || Object.keys(current.syncSetups).length) {\n\t\t\tthrow new Error(`Settings already exist: ${localConfigPath()}`);\n\t\t}\n\t\treturn { ...current, ...settings };\n\t}, signal);\n}\n\nexport async function addStorageConnection(\n\tname: string,\n\tconnection: StorageConnectionSettings,\n\tsignal?: AbortSignal,\n) {\n\tvalidateConfigName(name, \"storage connection\");\n\tawait updateSettings((settings) => {\n\t\tif (Object.hasOwn(settings.storageConnections, name)) {\n\t\t\tthrow new Error(`Storage connection already exists: ${name}`);\n\t\t}\n\t\treturn {\n\t\t\t...settings,\n\t\t\tstorageConnections: {\n\t\t\t\t...settings.storageConnections,\n\t\t\t\t[name]: structuredClone(connection),\n\t\t\t},\n\t\t};\n\t}, signal);\n}\n\nexport async function updateStorageConnection(\n\tname: string,\n\tupdate: (connection: StorageConnectionSettings) => StorageConnectionSettings,\n\texpectedSetups?: readonly string[],\n\tsignal?: AbortSignal,\n) {\n\tvalidateConfigName(name, \"storage connection\");\n\tawait updateSettings((settings) => {\n\t\tconst connection = settings.storageConnections[name];\n\t\tif (!connection) throw new Error(`Storage connection not found: ${name}`);\n\t\tconst currentSetups = referencingSetupNames(settings.syncSetups, name);\n\t\tif (expectedSetups && !sameNames(currentSetups, expectedSetups)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Storage connection \u201C${name}\u201D usage changed while it was open; reopen it and review the affected sync setups.`,\n\t\t\t);\n\t\t}\n\t\tconst nextConnection = update(structuredClone(connection));\n\t\tconst nextConnections = { ...settings.storageConnections, [name]: nextConnection };\n\t\tassertUniqueLocations(settings.syncSetups, nextConnections);\n\t\treturn { ...settings, storageConnections: nextConnections };\n\t}, signal);\n}\n\nexport async function addSyncSetup(\n\tname: string,\n\tsetup: SyncSetupSettings,\n\tsignal?: AbortSignal,\n\texpectedConnection?: StorageConnectionSettings,\n) {\n\tvalidateConfigName(name, \"sync setup\");\n\tawait updateSettings((settings) => {\n\t\tif (Object.hasOwn(settings.syncSetups, name))\n\t\t\tthrow new Error(`Sync setup already exists: ${name}`);\n\t\tif (!Object.hasOwn(settings.storageConnections, setup.storage.connection)) {\n\t\t\tthrow new Error(`Storage connection not found: ${setup.storage.connection}`);\n\t\t}\n\t\tif (\n\t\t\texpectedConnection &&\n\t\t\t!isDeepStrictEqual(settings.storageConnections[setup.storage.connection], expectedConnection)\n\t\t) {\n\t\t\tthrow new SyncSetupReviewChangedError(\n\t\t\t\t\"Storage connection changed while the setup review was open; reopen it.\",\n\t\t\t);\n\t\t}\n\t\tconst nextSetups = { ...settings.syncSetups, [name]: structuredClone(setup) };\n\t\tassertUniqueLocations(nextSetups, settings.storageConnections);\n\t\treturn {\n\t\t\t...settings,\n\t\t\tsyncSetups: nextSetups,\n\t\t\t...(settings.activeSyncSetup ? {} : { activeSyncSetup: name }),\n\t\t};\n\t}, signal);\n}\n\nexport async function updateSyncSetup(\n\tname: string,\n\tupdate: (setup: SyncSetupSettings) => SyncSetupSettings,\n\toptions: {\n\t\texpectedStorage?: SyncSetupStorageReview;\n\t\texpectedInclude?: readonly string[];\n\t\texpectedConnection?: StorageConnectionSettings;\n\t\tsignal?: AbortSignal;\n\t} = {},\n) {\n\tvalidateConfigName(name, \"sync setup\");\n\tawait updateSettings((settings) => {\n\t\tconst setup = settings.syncSetups[name];\n\t\tif (!setup) throw new Error(`Sync setup not found: ${name}`);\n\t\tif (\n\t\t\toptions.expectedInclude &&\n\t\t\t!sameNames(normalizeSyncInclude(setup.sync.include), options.expectedInclude)\n\t\t) {\n\t\t\tthrow new SyncSetupReviewChangedError(\n\t\t\t\t`Sync setup \u201C${name}\u201D included content changed while it was open; reopen it and review the current selection.`,\n\t\t\t);\n\t\t}\n\t\tif (options.expectedStorage) {\n\t\t\tconst connectionName = setup.storage.connection;\n\t\t\tconst connection = settings.storageConnections[connectionName];\n\t\t\tif (\n\t\t\t\t!connection ||\n\t\t\t\t!sameStorageReview(\n\t\t\t\t\tsyncSetupStorageReview(name, setup, connectionName, connection),\n\t\t\t\t\toptions.expectedStorage,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthrow new SyncSetupReviewChangedError(\n\t\t\t\t\t`Sync setup \u201C${name}\u201D storage changed while it was open; reopen it and review the current storage location.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (\n\t\t\toptions.expectedConnection &&\n\t\t\t!isDeepStrictEqual(\n\t\t\t\tsettings.storageConnections[setup.storage.connection],\n\t\t\t\toptions.expectedConnection,\n\t\t\t)\n\t\t) {\n\t\t\tthrow new SyncSetupReviewChangedError(\n\t\t\t\t\"Storage connection changed while the setup review was open; reopen it.\",\n\t\t\t);\n\t\t}\n\t\tconst nextSetup = update(structuredClone(setup));\n\t\tif (!Object.hasOwn(settings.storageConnections, nextSetup.storage.connection)) {\n\t\t\tthrow new Error(`Storage connection not found: ${nextSetup.storage.connection}`);\n\t\t}\n\t\tconst nextSetups = { ...settings.syncSetups, [name]: nextSetup };\n\t\tassertUniqueLocations(nextSetups, settings.storageConnections);\n\t\treturn { ...settings, syncSetups: nextSetups };\n\t}, options.signal);\n}\n\nexport async function removeSyncSetup(name: string, signal?: AbortSignal) {\n\tvalidateConfigName(name, \"sync setup\");\n\tawait updateSettings((settings) => {\n\t\tif (!Object.hasOwn(settings.syncSetups, name)) throw new Error(`Sync setup not found: ${name}`);\n\t\tconst isCurrent = settings.activeSyncSetup === name;\n\t\tif (isCurrent && Object.keys(settings.syncSetups).length > 1) {\n\t\t\tthrow new Error(\"Switch to another sync setup before removing the current setup.\");\n\t\t}\n\t\tconst syncSetups = { ...settings.syncSetups };\n\t\tdelete syncSetups[name];\n\t\tconst next = { ...settings, syncSetups };\n\t\tif (isCurrent) delete next.activeSyncSetup;\n\t\treturn next;\n\t}, signal);\n}\n\nexport async function removeStorageConnection(name: string, signal?: AbortSignal) {\n\tvalidateConfigName(name, \"storage connection\");\n\tawait updateSettings((settings) => {\n\t\tconst referenced = referencingSetupNames(settings.syncSetups, name)[0];\n\t\tif (referenced) {\n\t\t\tthrow new Error(`Storage connection \u201C${name}\u201D is used by sync setup \u201C${referenced}\u201D.`);\n\t\t}\n\t\tif (!Object.hasOwn(settings.storageConnections, name)) {\n\t\t\tthrow new Error(`Storage connection not found: ${name}`);\n\t\t}\n\t\tconst storageConnections = { ...settings.storageConnections };\n\t\tdelete storageConnections[name];\n\t\treturn { ...settings, storageConnections };\n\t}, signal);\n}\n\nasync function updateSettings(\n\tupdate: (settings: PiSyncSettingsV3) => PiSyncSettingsV3,\n\tsignal?: AbortSignal,\n) {\n\treturn updateLocalConfig((settings) => {\n\t\tif (settings.version !== 3) {\n\t\t\tthrow new Error(\"Storage connections and sync setups require version 3 pi-sync settings.\");\n\t\t}\n\t\treturn update(settings);\n\t}, signal);\n}\n\nfunction referencingSetupNames(setups: Record<string, SyncSetupSettings>, connection: string) {\n\treturn Object.entries(setups)\n\t\t.filter(([, setup]) => setup.storage.connection === connection)\n\t\t.map(([name]) => name)\n\t\t.sort((left, right) => left.localeCompare(right));\n}\n\nfunction assertUniqueLocations(\n\tsetups: Record<string, SyncSetupSettings>,\n\tconnections: Record<string, StorageConnectionSettings>,\n) {\n\tconst identities = new Map<string, string>();\n\tfor (const [name, setup] of Object.entries(setups)) {\n\t\tconst connection = connections[setup.storage.connection];\n\t\tif (!connection) throw new Error(`Storage connection not found: ${setup.storage.connection}`);\n\t\tconst identity = effectiveSyncSetupRemoteIdentity(setup, connection);\n\t\tconst previous = identities.get(identity);\n\t\tif (previous) {\n\t\t\tthrow new Error(`Sync setup \u201C${name}\u201D duplicates the storage location of \u201C${previous}\u201D.`);\n\t\t}\n\t\tidentities.set(identity, name);\n\t}\n}\n\nfunction sameNames(left: readonly string[], right: readonly string[]) {\n\treturn left.length === right.length && left.every((name, index) => name === right[index]);\n}\n\nfunction sameStorageReview(left: SyncSetupStorageReview, right: SyncSetupStorageReview) {\n\treturn (\n\t\tleft.connectionName === right.connectionName &&\n\t\tleft.storageKind === right.storageKind &&\n\t\tleft.storagePath === right.storagePath &&\n\t\tleft.bucket === right.bucket &&\n\t\tleft.branch === right.branch\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;AAAA,SAAS,yBAAyB;AAY3B,IAAM,8BAAN,cAA0C,MAAM;AAAA,EACtD,YAAY,SAAiB;AAC5B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACb;AACD;AAEA,eAAsB,kBACrB,OAMA,QACC;AACD,qBAAmB,MAAM,WAAW,YAAY;AAChD,qBAAmB,MAAM,gBAAgB,oBAAoB;AAC7D,QAAM,WAA6B;AAAA,IAClC,SAAS;AAAA,IACT,iBAAiB,MAAM;AAAA,IACvB,UAAU;AAAA,IACV,gBAAgB;AAAA,IAChB,oBAAoB,EAAE,CAAC,MAAM,cAAc,GAAG,gBAAgB,MAAM,UAAU,EAAE;AAAA,IAChF,YAAY;AAAA,MACX,CAAC,MAAM,SAAS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;AAC5F,UAAM,WAAW,iCAAiC,OAAO,UAAU;AACnE,UAAM,WAAW,WAAW,IAAI,QAAQ;AACxC,QAAI,UAAU;AACb,YAAM,IAAI,MAAM,oBAAe,IAAI,mDAAyC,QAAQ,SAAI;AAAA,IACzF;AACA,eAAW,IAAI,UAAU,IAAI;AAAA,EAC9B;AACD;AAEA,SAAS,UAAU,MAAyB,OAA0B;AACrE,SAAO,KAAK,WAAW,MAAM,UAAU,KAAK,MAAM,CAAC,MAAM,UAAU,SAAS,MAAM,KAAK,CAAC;AACzF;AAEA,SAAS,kBAAkB,MAA8B,OAA+B;AACvF,SACC,KAAK,mBAAmB,MAAM,kBAC9B,KAAK,gBAAgB,MAAM,eAC3B,KAAK,gBAAgB,MAAM,eAC3B,KAAK,WAAW,MAAM,UACtB,KAAK,WAAW,MAAM;AAExB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/ui/terminal-text.ts"],
|
|
4
|
-
"sourcesContent": ["export function safeTerminalText(value: string) {\n\t// biome-ignore lint/suspicious/noControlCharactersInRegex: Escape untrusted terminal controls.\n\treturn value.replace(/[\\u0000-\\u001f\\u007f-\\u009f]/gu, \"?\");\n}\n"],
|
|
5
|
-
"mappings": ";;;;AAAO,SAAS,iBAAiB,OAAe;AAE/C,SAAO,MAAM,QAAQ,kCAAkC,GAAG;AAC3D;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/sync/signals.ts"],
|
|
4
|
-
"sourcesContent": ["export function throwIfAborted(signal?: AbortSignal) {\n\tif (!signal?.aborted) return;\n\tthrow signal.reason instanceof Error\n\t\t? signal.reason\n\t\t: new DOMException(\"The operation was aborted\", \"AbortError\");\n}\n\nexport function combineSignals(primary: AbortSignal, secondary?: AbortSignal) {\n\treturn secondary ? AbortSignal.any([primary, secondary]) : primary;\n}\n"],
|
|
5
|
-
"mappings": ";;;;AAAO,SAAS,eAAe,QAAsB;AACpD,MAAI,CAAC,QAAQ,QAAS;AACtB,QAAM,OAAO,kBAAkB,QAC5B,OAAO,SACP,IAAI,aAAa,6BAA6B,YAAY;AAC9D;AAEO,SAAS,eAAe,SAAsB,WAAyB;AAC7E,SAAO,YAAY,YAAY,IAAI,CAAC,SAAS,SAAS,CAAC,IAAI;AAC5D;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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\tcanonicalSnapshotPathForConfig,\n\tcustomIncludePathsByLower,\n\tDEFAULT_SYNC_INCLUDE,\n\tincludeFromSelectionConfig,\n\tisConfiguredSnapshotPath,\n\tisPreservableUnmanagedSnapshotPath,\n\tnormalizeExtraFiles,\n\tnormalizeSyncFiles,\n\ttype SyncSelectionConfig,\n\tselectionForSnapshot,\n\tsnapshotSelectionInclude,\n\tsyncIncludeSelection,\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) =>\n\tname.includes(\".\"),\n);\nconst TOP_LEVEL_DIRS = new Set<string>(DEFAULT_SYNC_INCLUDE.filter((name) => !name.includes(\".\")));\nconst SECRET_PATTERNS = [\n\t/AWS_SECRET_ACCESS_KEY\\s*[=:]\\s*['\"]?[A-Za-z0-9/+]{35,}/i,\n\t/(ANTHROPIC|OPENAI|GEMINI|GOOGLE|FIRECRAWL|GITHUB|CLOUDFLARE|R2|S3)_[A-Z0-9_]*(KEY|TOKEN|SECRET)\\s*[=:]\\s*['\"]?[^\\s'\"]{12,}/i,\n\t/sk-ant-[A-Za-z0-9_-]{20,}/,\n\t/sk-[A-Za-z0-9]{20,}/,\n\t/gh[pousr]_[A-Za-z0-9_]{20,}/,\n];\n\nfunction selectTopLevelFileEntry(entries: Dirent[], fileName: string) {\n\tconst exact = entries.find((entry) => entry.isFile() && entry.name === fileName);\n\tif (exact) return exact;\n\tconst lower = fileName.toLowerCase();\n\treturn entries\n\t\t.filter((entry) => entry.isFile() && entry.name.toLowerCase() === lower)\n\t\t.sort((left, right) => left.name.localeCompare(right.name))[0];\n}\n\nfunction sha256(value: Buffer) {\n\treturn createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\nfunction isSafeSnapshotPath(relativePath: string) {\n\tif (relativePath.includes(\"\\\\\")) return false;\n\tconst normalized = toPosix(relativePath);\n\treturn (\n\t\tBoolean(normalized) &&\n\t\tnormalized !== \".\" &&\n\t\tnormalized !== \"..\" &&\n\t\t!normalized.startsWith(\"../\") &&\n\t\t!path.posix.isAbsolute(normalized) &&\n\t\tpath.posix.normalize(normalized) === normalized &&\n\t\t!isDeniedPath(normalized)\n\t);\n}\n\nfunction snapshotsMatch(left: Snapshot, right: Snapshot) {\n\tconst leftHashes = new Map(left.files.map((file) => [file.path, file.sha256]));\n\tconst rightHashes = new Map(right.files.map((file) => [file.path, file.sha256]));\n\treturn (\n\t\tleft.syncSessions === right.syncSessions &&\n\t\tsameOptionalInclude(snapshotSelectionInclude(left), snapshotSelectionInclude(right)) &&\n\t\tleftHashes.size === rightHashes.size &&\n\t\t[...leftHashes].every(([filePath, hash]) => rightHashes.get(filePath) === hash)\n\t);\n}\n\nfunction snapshotId() {\n\treturn `${new Date().toISOString().replace(/[:.]/g, \"-\")}-${randomUUID().slice(0, 8)}`;\n}\n\nexport function regenerateSnapshotIdentity(snapshot: Snapshot): Snapshot {\n\treturn {\n\t\t...snapshot,\n\t\tid: snapshotId(),\n\t\tcreatedAt: new Date().toISOString(),\n\t\tmachine: os.hostname(),\n\t};\n}\n\nexport async function createSnapshot(\n\tprofile: string,\n\toptions: SnapshotOptions = {},\n): Promise<Snapshot> {\n\toptions.signal?.throwIfAborted();\n\tconst include = effectiveInclude(options);\n\tconst syncSessions = include.includes(\"sessions\");\n\tconst sessionDir = options.sessionDir ?? (await configuredSessionDir());\n\toptions.signal?.throwIfAborted();\n\tconst files = await collectFiles(agentDir(), { include, sessionDir, signal: options.signal });\n\toptions.signal?.throwIfAborted();\n\treturn {\n\t\tversion: VERSION,\n\t\tid: snapshotId(),\n\t\tcreatedAt: new Date().toISOString(),\n\t\tmachine: os.hostname(),\n\t\tprofile,\n\t\tsyncSessions,\n\t\tselection: selectionForSnapshot(include),\n\t\tfiles,\n\t};\n}\n\nfunction effectiveInclude(options: SnapshotOptions) {\n\tif (options.include) return options.include;\n\treturn [\n\t\t...normalizeSyncFiles(options.syncFiles),\n\t\t...normalizeExtraFiles(options.extraFiles),\n\t\t...(options.syncSessions ? [\"sessions\"] : []),\n\t];\n}\n\nexport async function collectFiles(\n\troot: string,\n\toptions: SnapshotOptions = {},\n): Promise<SnapshotFile[]> {\n\tconst signal = options.signal;\n\tsignal?.throwIfAborted();\n\tconst results: SnapshotFile[] = [];\n\tconst entries = await fs.readdir(root, { withFileTypes: true });\n\tsignal?.throwIfAborted();\n\tconst selection = syncIncludeSelection(effectiveInclude(options));\n\tconst selectedFiles = new Set<string>(selection.builtIns);\n\tfor (const entry of entries) {\n\t\tif (entry.isDirectory() && TOP_LEVEL_DIRS.has(entry.name) && selectedFiles.has(entry.name)) {\n\t\t\tawait collectDirectory(results, root, entry.name, { signal });\n\t\t}\n\t}\n\tfor (const fileName of TOP_LEVEL_FILES) {\n\t\tif (!selectedFiles.has(fileName)) continue;\n\t\tconst entry = selectTopLevelFileEntry(entries, fileName);\n\t\tif (entry) await addFile(results, root, entry.name, fileName, signal);\n\t}\n\tfor (const relativePath of selection.custom) {\n\t\tawait collectIncludedPath(results, root, relativePath, signal);\n\t}\n\tif (selection.sessions) {\n\t\ttry {\n\t\t\tawait collectDirectory(results, sessionStorageRoot(root, options.sessionDir), \"\", {\n\t\t\t\tsessionsOnly: true,\n\t\t\t\tvirtualPrefix: \"sessions\",\n\t\t\t\tsignal,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n\t\t}\n\t}\n\tsignal?.throwIfAborted();\n\treturn results.sort((left, right) => left.path.localeCompare(right.path));\n}\n\nasync function collectIncludedPath(\n\tresults: SnapshotFile[],\n\troot: string,\n\trelativePath: string,\n\tsignal?: AbortSignal,\n) {\n\tsignal?.throwIfAborted();\n\tconst absolutePath = safeJoin(root, relativePath);\n\ttry {\n\t\tconst stat = await fs.lstat(absolutePath);\n\t\tsignal?.throwIfAborted();\n\t\tif (stat.isFile()) await addFile(results, root, relativePath, relativePath, signal);\n\t\telse if (stat.isDirectory()) await collectDirectory(results, root, relativePath, { signal });\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n\t\tif (!relativePath.includes(\"/\")) {\n\t\t\tconst entries = await fs.readdir(root, { withFileTypes: true });\n\t\t\tsignal?.throwIfAborted();\n\t\t\tconst entry = selectTopLevelFileEntry(entries, relativePath);\n\t\t\tif (entry) await addFile(results, root, entry.name, relativePath, signal);\n\t\t}\n\t}\n}\n\nasync function collectDirectory(\n\tresults: SnapshotFile[],\n\troot: string,\n\trelativeDirectory: string,\n\toptions: { sessionsOnly?: boolean; virtualPrefix?: string; signal?: AbortSignal } = {},\n) {\n\toptions.signal?.throwIfAborted();\n\tconst absoluteDirectory = path.join(root, relativeDirectory);\n\tfor (const entry of await fs.readdir(absoluteDirectory, { withFileTypes: true })) {\n\t\toptions.signal?.throwIfAborted();\n\t\tconst relativePath = relativeDirectory ? posixJoin(relativeDirectory, entry.name) : entry.name;\n\t\tconst snapshotPath = options.virtualPrefix\n\t\t\t? posixJoin(options.virtualPrefix, relativePath)\n\t\t\t: relativePath;\n\t\tif (isDeniedPath(snapshotPath)) continue;\n\t\tif (entry.isDirectory()) {\n\t\t\tawait collectDirectory(results, root, relativePath, options);\n\t\t} else if (entry.isFile() && (!options.sessionsOnly || isSessionFilePath(snapshotPath))) {\n\t\t\tawait addFile(results, root, relativePath, snapshotPath, options.signal);\n\t\t}\n\t}\n}\n\nasync function addFile(\n\tresults: SnapshotFile[],\n\troot: string,\n\trelativePath: string,\n\tsnapshotPath = relativePath,\n\tsignal?: AbortSignal,\n) {\n\tsignal?.throwIfAborted();\n\tif (!isSafeSnapshotPath(snapshotPath)) return;\n\tconst absolutePath = safeJoin(root, relativePath);\n\tconst content = await fs.readFile(absolutePath, { signal });\n\tsignal?.throwIfAborted();\n\tresults.push({\n\t\tpath: snapshotPath,\n\t\tcontentBase64: content.toString(\"base64\"),\n\t\tsha256: sha256(content),\n\t});\n}\n\nexport function isSessionPath(relativePath: string) {\n\treturn toPosix(relativePath).startsWith(\"sessions/\");\n}\n\nexport function isSessionFilePath(relativePath: string) {\n\tconst normalized = toPosix(relativePath);\n\treturn isSessionPath(normalized) && normalized.endsWith(\".jsonl\");\n}\n\nexport function sessionSnapshotPathFromAbsolute(\n\tsessionFile: string,\n\tconfiguredSessionDir?: string,\n) {\n\tconst relativePath = toPosix(\n\t\tpath.relative(sessionStorageRoot(agentDir(), configuredSessionDir), sessionFile),\n\t);\n\tif (!relativePath || relativePath.startsWith(\"../\") || path.posix.isAbsolute(relativePath)) {\n\t\treturn undefined;\n\t}\n\tconst snapshotPath = posixJoin(\"sessions\", relativePath);\n\treturn isSessionFilePath(snapshotPath) ? snapshotPath : undefined;\n}\n\nexport function snapshotTarget(root: string, relativePath: string, configuredSessionDir?: string) {\n\tif (isSessionPath(relativePath)) {\n\t\treturn safeJoin(\n\t\t\tsessionStorageRoot(root, configuredSessionDir),\n\t\t\trelativePath.slice(\"sessions/\".length),\n\t\t);\n\t}\n\treturn safeJoin(root, relativePath);\n}\n\nexport function snapshotIncludesSessions(snapshot: Snapshot) {\n\treturn (\n\t\tsnapshot.syncSessions === true ||\n\t\tsnapshotSelectionInclude(snapshot)?.includes(\"sessions\") === true ||\n\t\tsnapshot.files.some((file) => isSessionPath(file.path))\n\t);\n}\n\nexport function filterSnapshotForConfigPolicy(\n\tsnapshot: Snapshot,\n\tconfig: SyncSelectionConfig,\n\toptions: { regenerateId?: boolean } = {},\n) {\n\tconst include = includeFromSelectionConfig(config);\n\tconst includePaths = customIncludePathsByLower(include);\n\tconst filtered = {\n\t\t...snapshot,\n\t\tsyncSessions: include.includes(\"sessions\") ? snapshot.syncSessions : false,\n\t\tselection: selectionForSnapshot(include),\n\t\tfiles: canonicalizeSnapshotFilesForConfig(snapshot.files, config, includePaths),\n\t};\n\tif (!options.regenerateId || snapshotsMatch(snapshot, filtered)) return filtered;\n\treturn {\n\t\t...filtered,\n\t\tid: snapshotId(),\n\t\tcreatedAt: new Date().toISOString(),\n\t\tmachine: os.hostname(),\n\t};\n}\n\nfunction canonicalizeSnapshotFilesForConfig(\n\tfiles: SnapshotFile[],\n\tconfig: SyncSelectionConfig,\n\tincludePaths: Map<string, string>,\n) {\n\tconst configuredFiles: SnapshotFile[] = [];\n\tconst extraCandidates = new Map<\n\t\tstring,\n\t\t{ exact: boolean; file: SnapshotFile; originalPath: string }\n\t>();\n\tfor (const file of files) {\n\t\tconst normalized = toPosix(file.path);\n\t\tif (!isSafeSnapshotPath(file.path) || !isConfiguredSnapshotPath(normalized, config)) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (normalized.includes(\"/\")) {\n\t\t\tconfiguredFiles.push(normalized === file.path ? file : { ...file, path: normalized });\n\t\t\tcontinue;\n\t\t}\n\t\tconst topLevelPath = canonicalSnapshotPathForConfig(normalized, includePaths);\n\t\tconst candidate = {\n\t\t\texact: normalized === topLevelPath,\n\t\t\tfile: { ...file, path: topLevelPath },\n\t\t\toriginalPath: normalized,\n\t\t};\n\t\tconst current = extraCandidates.get(topLevelPath.toLowerCase());\n\t\tif (!current || isPreferredExtraCandidate(candidate, current)) {\n\t\t\textraCandidates.set(topLevelPath.toLowerCase(), candidate);\n\t\t}\n\t}\n\treturn [\n\t\t...configuredFiles,\n\t\t...[...extraCandidates.values()].map((candidate) => candidate.file),\n\t].sort((left, right) => left.path.localeCompare(right.path));\n}\n\nfunction isPreferredExtraCandidate(\n\tleft: { exact: boolean; originalPath: string },\n\tright: { exact: boolean; originalPath: string },\n) {\n\tif (left.exact !== right.exact) return left.exact;\n\treturn left.originalPath.localeCompare(right.originalPath) < 0;\n}\n\nexport function snapshotWithoutSessions(snapshot: Snapshot) {\n\tconst files = snapshot.files.filter((file) => !isSessionPath(file.path));\n\tconst include = snapshotSelectionInclude(snapshot)?.filter((item) => item !== \"sessions\");\n\tif (\n\t\tfiles.length === snapshot.files.length &&\n\t\tsnapshot.syncSessions !== true &&\n\t\tinclude?.length === snapshot.selection?.include.length\n\t) {\n\t\treturn snapshot;\n\t}\n\treturn {\n\t\t...snapshot,\n\t\tid: snapshotId(),\n\t\tcreatedAt: new Date().toISOString(),\n\t\tmachine: os.hostname(),\n\t\tsyncSessions: false,\n\t\t...(include ? { selection: selectionForSnapshot(include) } : {}),\n\t\tfiles,\n\t};\n}\n\nexport function scanSnapshot(snapshot: Snapshot) {\n\tconst findings: string[] = [];\n\tfor (const file of snapshot.files) {\n\t\tconst content = Buffer.from(file.contentBase64, \"base64\");\n\t\tif (content.includes(0)) continue;\n\t\tconst text = content.toString(\"utf8\");\n\t\tfor (const pattern of SECRET_PATTERNS) {\n\t\t\tif (pattern.test(text)) {\n\t\t\t\tfindings.push(file.path);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\treturn findings;\n}\n\nexport function mergeRemotePreservedFiles(\n\tlocal: Snapshot,\n\tremote: Snapshot,\n\tconfig: SyncSelectionConfig,\n) {\n\tconst localPathNames = new Set(local.files.map((file) => file.path.toLowerCase()));\n\tconst preservedPathNames = new Set<string>();\n\tconst preserved = remote.files.filter((file) => {\n\t\tconst normalized = toPosix(file.path);\n\t\tconst lower = normalized.toLowerCase();\n\t\tif (\n\t\t\tlocalPathNames.has(lower) ||\n\t\t\tpreservedPathNames.has(lower) ||\n\t\t\t!isSafeSnapshotPath(file.path) ||\n\t\t\tisConfiguredSnapshotPath(normalized, config) ||\n\t\t\t!isPreservableUnmanagedSnapshotPath(normalized)\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t\tpreservedPathNames.add(lower);\n\t\treturn true;\n\t});\n\tif (preserved.length === 0) return local;\n\treturn {\n\t\t...local,\n\t\tid: snapshotId(),\n\t\tcreatedAt: new Date().toISOString(),\n\t\tmachine: os.hostname(),\n\t\tsyncSessions: snapshotIncludesSessions(local) || snapshotIncludesSessions(remote),\n\t\tfiles: [...local.files, ...preserved].sort((left, right) =>\n\t\t\tleft.path.localeCompare(right.path),\n\t\t),\n\t};\n}\n\nexport function mergeRemoteSessionFiles(local: Snapshot, remote: Snapshot) {\n\tconst remoteSessions = remote.files.filter((file) => {\n\t\tconst normalized = toPosix(file.path);\n\t\treturn isSessionFilePath(normalized) && isSafeSnapshotPath(file.path);\n\t});\n\tif (remoteSessions.length === 0 && !snapshotIncludesSessions(remote)) return local;\n\tconst localInclude = snapshotSelectionInclude(local);\n\treturn {\n\t\t...local,\n\t\tid: snapshotId(),\n\t\tcreatedAt: new Date().toISOString(),\n\t\tmachine: os.hostname(),\n\t\tsyncSessions: true,\n\t\t...(localInclude\n\t\t\t? {\n\t\t\t\t\tselection: selectionForSnapshot(\n\t\t\t\t\t\tlocalInclude.includes(\"sessions\") ? localInclude : [...localInclude, \"sessions\"],\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\tfiles: [...local.files.filter((file) => !isSessionPath(file.path)), ...remoteSessions].sort(\n\t\t\t(left, right) => left.path.localeCompare(right.path),\n\t\t),\n\t};\n}\n\nfunction sameOptionalInclude(left: string[] | undefined, right: string[] | undefined) {\n\tif (!left || !right) return left === right;\n\treturn 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;AAAA,EAAO,CAAC,SACvE,KAAK,SAAS,GAAG;AAClB;AACA,IAAM,iBAAiB,IAAI,IAAY,qBAAqB,OAAO,CAAC,SAAS,CAAC,KAAK,SAAS,GAAG,CAAC,CAAC;AACjG,IAAM,kBAAkB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAEA,SAAS,wBAAwB,SAAmB,UAAkB;AACrE,QAAM,QAAQ,QAAQ,KAAK,CAAC,UAAU,MAAM,OAAO,KAAK,MAAM,SAAS,QAAQ;AAC/E,MAAI,MAAO,QAAO;AAClB,QAAM,QAAQ,SAAS,YAAY;AACnC,SAAO,QACL,OAAO,CAAC,UAAU,MAAM,OAAO,KAAK,MAAM,KAAK,YAAY,MAAM,KAAK,EACtE,KAAK,CAAC,MAAM,UAAU,KAAK,KAAK,cAAc,MAAM,IAAI,CAAC,EAAE,CAAC;AAC/D;AAEA,SAAS,OAAO,OAAe;AAC9B,SAAO,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK;AACvD;AAEA,SAAS,mBAAmB,cAAsB;AACjD,MAAI,aAAa,SAA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,MAAM,UACjD,KAAK,KAAK,cAAc,MAAM,IAAI;AAAA,IACnC;AAAA,EACD;AACD;AAEO,SAAS,wBAAwB,OAAiB,QAAkB;AAC1E,QAAM,iBAAiB,OAAO,MAAM,OAAO,CAAC,SAAS;AACpD,UAAM,aAAa,QAAQ,KAAK,IAAI;AACpC,WAAO,kBAAkB,UAAU,KAAK,mBAAmB,KAAK,IAAI;AAAA,EACrE,CAAC;AACD,MAAI,eAAe,WAAW,KAAK,CAAC,yBAAyB,MAAM,EAAG,QAAO;AAC7E,QAAM,eAAe,yBAAyB,KAAK;AACnD,SAAO;AAAA,IACN,GAAG;AAAA,IACH,IAAI,WAAW;AAAA,IACf,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,IAClC,SAAS,GAAG,SAAS;AAAA,IACrB,cAAc;AAAA,IACd,GAAI,eACD;AAAA,MACA,WAAW;AAAA,QACV,aAAa,SAAS,UAAU,IAAI,eAAe,CAAC,GAAG,cAAc,UAAU;AAAA,MAChF;AAAA,IACD,IACC,CAAC;AAAA,IACJ,OAAO,CAAC,GAAG,MAAM,MAAM,OAAO,CAAC,SAAS,CAAC,cAAc,KAAK,IAAI,CAAC,GAAG,GAAG,cAAc,EAAE;AAAA,MACtF,CAAC,MAAM,UAAU,KAAK,KAAK,cAAc,MAAM,IAAI;AAAA,IACpD;AAAA,EACD;AACD;AAEA,SAAS,oBAAoB,MAA4B,OAA6B;AACrF,MAAI,CAAC,QAAQ,CAAC,MAAO,QAAO,SAAS;AACrC,SAAO,KAAK,WAAW,MAAM,UAAU,KAAK,MAAM,CAAC,MAAM,UAAU,SAAS,MAAM,KAAK,CAAC;AACzF;",
|
|
6
|
-
"names": ["configuredSessionDir"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/snapshot/snapshot-codec.ts"],
|
|
4
|
-
"sourcesContent": ["import { Readable, Writable } from \"node:stream\";\nimport { pipeline } from \"node:stream/promises\";\nimport { promisify } from \"node:util\";\nimport { createGunzip, gzip } from \"node:zlib\";\nimport { snapshotSelectionInclude } from \"../sync/sync-policy.js\";\nimport type { Snapshot } from \"./snapshot-types.js\";\n\nconst VERSION = 1;\nconst MAX_DECOMPRESSED_SNAPSHOT_BYTES = 512 * 1024 * 1024;\nconst gzipAsync = promisify(gzip);\n\nexport async function encodeSnapshot(snapshot: Snapshot) {\n\tsnapshotSelectionInclude(snapshot);\n\treturn gzipAsync(Buffer.from(JSON.stringify(snapshot), \"utf8\"));\n}\n\nexport async function decodeSnapshot(\n\tbuffer: Buffer,\n\toptions: { signal?: AbortSignal; maxOutputLength?: number } = {},\n): Promise<Snapshot> {\n\tthrowIfAborted(options.signal);\n\tconst limit = options.maxOutputLength ?? MAX_DECOMPRESSED_SNAPSHOT_BYTES;\n\tconst chunks: Buffer[] = [];\n\tlet total = 0;\n\tconst sink = new Writable({\n\t\twrite(chunk: Buffer, _encoding, callback) {\n\t\t\ttotal += chunk.byteLength;\n\t\t\tif (total > limit) {\n\t\t\t\tcallback(new Error(`Decompressed snapshot exceeds the ${limit}-byte limit.`));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tchunks.push(Buffer.from(chunk));\n\t\t\tcallback();\n\t\t},\n\t});\n\tawait pipeline(Readable.from([buffer]), createGunzip(), sink, { signal: options.signal });\n\tthrowIfAborted(options.signal);\n\tconst parsed = JSON.parse(Buffer.concat(chunks, total).toString(\"utf8\")) as Snapshot;\n\tif (parsed.version !== VERSION || !Array.isArray(parsed.files)) {\n\t\tthrow new Error(\"Unsupported snapshot format.\");\n\t}\n\tsnapshotSelectionInclude(parsed);\n\treturn parsed;\n}\n\nfunction throwIfAborted(signal?: AbortSignal) {\n\tif (!signal?.aborted) return;\n\tthrow signal.reason instanceof Error\n\t\t? signal.reason\n\t\t: new DOMException(\"The operation was aborted\", \"AbortError\");\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;AAAA,SAAS,UAAU,gBA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,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/sync/setup-switch.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { setSyncSetupCompletions } from \"../commands/command.js\";\nimport {\n\tloadConfig,\n\tsyncConfigReviewIdentity,\n\tsyncSetupReviewIdentity,\n} from \"../settings/config.js\";\nimport { configuredSyncSetupNames, updateLocalConfig } from \"../settings/settings-store.js\";\nimport type { OnSwitchAction } from \"../settings/settings-types.js\";\nimport { normalizeOnSwitch } from \"../settings/settings-validation.js\";\nimport { safeTerminalText } from \"../ui/terminal-text.js\";\nimport { SetupPullRequiresUiError } from \"./sync-errors.js\";\n\nexport { SetupPullRequiresUiError } from \"./sync-errors.js\";\n\nexport const SETUP_SWITCH_ACTION_OPTIONS: ReadonlyArray<{\n\tlabel: string;\n\tvalue: OnSwitchAction;\n}> = [\n\t{ label: \"Ask before pull\", value: \"ask-before-pull\" },\n\t{ label: \"Start pull\", value: \"pull-after-switch\" },\n\t{ label: \"Switch only\", value: \"switch-only\" },\n];\n\nexport function setupSwitchActionLabel(action: OnSwitchAction) {\n\treturn SETUP_SWITCH_ACTION_OPTIONS.find((option) => option.value === action)?.label ?? action;\n}\n\nexport function setupSwitchActionFromLabel(label: string): OnSwitchAction | undefined {\n\treturn SETUP_SWITCH_ACTION_OPTIONS.find((option) => option.label === label)?.value;\n}\n\nexport async function saveOnSwitch(action: OnSwitchAction, signal?: AbortSignal) {\n\tawait updateLocalConfig((settings) => ({ ...settings, onSwitch: action }), signal);\n}\n\nexport type SetupPullOutcome = \"applied\" | \"cancelled\";\n\nexport interface SetupSwitchResult {\n\tpullApplied: boolean;\n}\n\nexport async function useSyncSetup(\n\tctx: ExtensionCommandContext,\n\tname: string,\n\tpullCurrentSetup?: (setup: string) => Promise<SetupPullOutcome | undefined>,\n\texpectedAction?: OnSwitchAction,\n\tsignal?: AbortSignal,\n\texpectedSetupIdentity?: string,\n): Promise<SetupSwitchResult> {\n\tconst normalized = name.trim();\n\tif (!normalized) throw new Error(\"Usage: /sync use <setup>\");\n\tconst loadedConfig = await loadConfig(normalized);\n\tconst reviewedSetupIdentity = expectedSetupIdentity ?? syncConfigReviewIdentity(loadedConfig);\n\tthrowIfAborted(signal);\n\tconst switchResult: { action: OnSwitchAction; switched: boolean } = {\n\t\taction: \"ask-before-pull\",\n\t\tswitched: false,\n\t};\n\tawait updateLocalConfig((current) => {\n\t\tthrowIfAborted(signal);\n\t\tconst setup = current.syncSetups[normalized];\n\t\tif (!setup) {\n\t\t\tthrow new Error(`Sync setup \u201C${safeTerminalText(normalized)}\u201D no longer exists.`);\n\t\t}\n\t\tconst connectionName = setup.storage.connection;\n\t\tconst connection = current.storageConnections[connectionName];\n\t\tif (\n\t\t\t!connection ||\n\t\t\tsyncSetupReviewIdentity(normalized, setup, connectionName, connection) !==\n\t\t\t\treviewedSetupIdentity\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`Sync setup \u201C${safeTerminalText(normalized)}\u201D changed while the switch preview was open; reopen it and review the current destination.`,\n\t\t\t);\n\t\t}\n\t\tswitchResult.action = normalizeOnSwitch(current.onSwitch);\n\t\tif (expectedAction !== undefined && switchResult.action !== expectedAction) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Setup-switch behavior changed while the preview was open; reopen it and retry.\",\n\t\t\t);\n\t\t}\n\t\tif (switchResult.action === \"pull-after-switch\" && !ctx.hasUI) {\n\t\t\tthrow new SetupPullRequiresUiError(\n\t\t\t\t`Automatic setup pulls require interactive confirmation; sync setup \u201C${safeTerminalText(normalized)}\u201D was not switched. Use TUI or RPC mode.`,\n\t\t\t);\n\t\t}\n\t\tif (current.activeSyncSetup === normalized) return current;\n\t\tswitchResult.switched = true;\n\t\treturn { ...current, activeSyncSetup: normalized };\n\t}, signal);\n\tthrowIfAborted(signal);\n\tif (!switchResult.switched) {\n\t\tctx.ui.notify(`Sync setup \u201C${safeTerminalText(normalized)}\u201D is already current.`, \"info\");\n\t\treturn { pullApplied: false };\n\t}\n\tsetSyncSetupCompletions(await configuredSyncSetupNames());\n\tthrowIfAborted(signal);\n\n\tif (switchResult.action === \"switch-only\") {\n\t\tctx.ui.notify(`Switched to \u201C${safeTerminalText(normalized)}\u201D. No files were pulled.`, \"info\");\n\t\treturn { pullApplied: false };\n\t}\n\tif (switchResult.action === \"ask-before-pull\") {\n\t\tif (ctx.mode !== \"tui\") {\n\t\t\tctx.ui.notify(\n\t\t\t\t`Switched to \u201C${safeTerminalText(normalized)}\u201D. No files were pulled because confirmation requires TUI mode; run /sync pull to apply this setup.`,\n\t\t\t\t\"info\",\n\t\t\t);\n\t\t\treturn { pullApplied: false };\n\t\t}\n\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t`Review a pull for sync setup \u201C${safeTerminalText(normalized)}\u201D now?`,\n\t\t\t\"pi-sync will check the remote snapshot and show the exact local writes and deletions before applying anything.\",\n\t\t\t{ signal },\n\t\t);\n\t\tthrowIfAborted(signal);\n\t\tif (!confirmed) {\n\t\t\tctx.ui.notify(\n\t\t\t\t`Switched to \u201C${safeTerminalText(normalized)}\u201D; files were not pulled.`,\n\t\t\t\t\"info\",\n\t\t\t);\n\t\t\treturn { pullApplied: false };\n\t\t}\n\t}\n\n\tctx.ui.notify(\n\t\t`Switched to \u201C${safeTerminalText(normalized)}\u201D. Checking remote files for a reviewed pull\u2026`,\n\t\t\"info\",\n\t);\n\tif (!pullCurrentSetup) {\n\t\tthrow new Error(`Switched to \u201C${safeTerminalText(normalized)}\u201D, but pull is unavailable.`);\n\t}\n\tconst pullOutcome = await pullCurrentSetup(normalized);\n\tthrowIfAborted(signal);\n\tif (pullOutcome === \"cancelled\") {\n\t\tctx.ui.notify(\n\t\t\t`Pull cancelled; sync setup \u201C${safeTerminalText(normalized)}\u201D remains current and synced files were not changed.`,\n\t\t\t\"info\",\n\t\t);\n\t}\n\treturn { pullApplied: pullOutcome === \"applied\" };\n}\n\nfunction throwIfAborted(signal?: AbortSignal) {\n\tif (!signal?.aborted) return;\n\tthrow signal.reason instanceof Error\n\t\t? signal.reason\n\t\t: new DOMException(\"The operation was aborted\", \"AbortError\");\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAeO,IAAM,8BAGR;AAAA,EACJ,EAAE,OAAO,mBAAmB,OAAO,kBAAkB;AAAA,EACrD,EAAE,OAAO,cAAc,OAAO,oBAAoB;AAAA,EAClD,EAAE,OAAO,eAAe,OAAO,cAAc;AAC9C;AAEO,SAAS,uBAAuB,QAAwB;AAC9D,SAAO,4BAA4B,KAAK,CAAC,WAAW,OAAO,UAAU,MAAM,GAAG,SAAS;AACxF;AAEO,SAAS,2BAA2B,OAA2C;AACrF,SAAO,4BAA4B,KAAK,CAAC,WAAW,OAAO,UAAU,KAAK,GAAG;AAC9E;AAEA,eAAsB,aAAa,QAAwB,QAAsB;AAChF,QAAM,kBAAkB,CAAC,cAAc,EAAE,GAAG,UAAU,UAAU,OAAO,IAAI,MAAM;AAClF;AAQA,eAAsB,aACrB,KACA,MACA,kBACA,gBACA,QACA,uBAC6B;AAC7B,QAAM,aAAa,KAAK,KAAK;AAC7B,MAAI,CAAC,WAAY,OAAM,IAAI,MAAM,0BAA0B;AAC3D,QAAM,eAAe,MAAM,WAAW,UAAU;AAChD,QAAM,wBAAwB,yBAAyB,yBAAyB,YAAY;AAC5F,iBAAe,MAAM;AACrB,QAAM,eAA8D;AAAA,IACnE,QAAQ;AAAA,IACR,UAAU;AAAA,EACX;AACA,QAAM,kBAAkB,CAAC,YAAY;AACpC,mBAAe,MAAM;AACrB,UAAM,QAAQ,QAAQ,WAAW,UAAU;AAC3C,QAAI,CAAC,OAAO;AACX,YAAM,IAAI,MAAM,oBAAe,iBAAiB,UAAU,CAAC,0BAAqB;AAAA,IACjF;AACA,UAAM,iBAAiB,MAAM,QAAQ;AACrC,UAAM,aAAa,QAAQ,mBAAmB,cAAc;AAC5D,QACC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AAC,WAAW;AACf,UAAI,GAAG;AAAA,QACN,qBAAgB,iBAAiB,UAAU,CAAC;AAAA,QAC5C;AAAA,MACD;AACA,aAAO,EAAE,aAAa,MAAM;AAAA,IAC7B;AAAA,EACD;AAEA,MAAI,GAAG;AAAA,IACN,qBAAgB,iBAAiB,UAAU,CAAC;AAAA,IAC5C;AAAA,EACD;AACA,MAAI,CAAC,kBAAkB;AACtB,UAAM,IAAI,MAAM,qBAAgB,iBAAiB,UAAU,CAAC,kCAA6B;AAAA,EAC1F;AACA,QAAM,cAAc,MAAM,iBAAiB,UAAU;AACrD,iBAAe,MAAM;AACrB,MAAI,gBAAgB,aAAa;AAChC,QAAI,GAAG;AAAA,MACN,oCAA+B,iBAAiB,UAAU,CAAC;AAAA,MAC3D;AAAA,IACD;AAAA,EACD;AACA,SAAO,EAAE,aAAa,gBAAgB,UAAU;AACjD;AAEA,SAAS,eAAe,QAAsB;AAC7C,MAAI,CAAC,QAAQ,QAAS;AACtB,QAAM,OAAO,kBAAkB,QAC5B,OAAO,SACP,IAAI,aAAa,6BAA6B,YAAY;AAC9D;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/sync/sync-inspection.ts"],
|
|
4
|
-
"sourcesContent": ["import { createSyncBackend, type SyncBackendFactory } from \"../backends/backend-factory.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport { createSnapshot } from \"../snapshot/snapshot.js\";\nimport type { SnapshotOptions } from \"../snapshot/snapshot-types.js\";\nimport { readStateForConfig, syncStateFingerprint } from \"../state/sync-state-store.js\";\nimport { throwIfAborted } from \"./signals.js\";\nimport { inspectRemoteSelection } from \"./sync-policy.js\";\nimport { hasLocalChanges, remoteChangedSinceState } from \"./sync-state.js\";\n\n/** Advisory baseline-relative observation, never an authorization to transfer files. */\nexport async function inspectSync(\n\tconfig: AnySyncConfig,\n\toptions: SnapshotOptions,\n\tsignal?: AbortSignal,\n\tfactory: SyncBackendFactory = createSyncBackend,\n) {\n\tthrowIfAborted(signal);\n\tconst backend = await factory(config);\n\tthrowIfAborted(signal);\n\tconst local = await createSnapshot(config.snapshotIdentity, { ...options, signal });\n\tthrowIfAborted(signal);\n\tconst state = await readStateForConfig(config);\n\tthrowIfAborted(signal);\n\tconst head = await backend.readHead(signal);\n\tthrowIfAborted(signal);\n\treturn {\n\t\thead,\n\t\tselectionState: head\n\t\t\t? inspectRemoteSelection(config.include, { selection: head.selection, files: [] })\n\t\t\t: undefined,\n\t\tlocalFiles: local.files.length,\n\t\tlocalChanged: hasLocalChanges(local, state, config),\n\t\tremoteChanged: remoteChangedSinceState(head, state, config, (left, right) =>\n\t\t\tbackend.sameRevision(left, right),\n\t\t),\n\t\tfirstSync: !state.lastAppliedSnapshot,\n\t\temptyInclude: config.include.length === 0,\n\t\tstateIdentity: syncStateFingerprint(state),\n\t\tdestination: backend.destination,\n\t\tcapability: backend.capability,\n\t};\n}\n\nexport type SyncInspection = Awaited<ReturnType<typeof inspectSync>>;\n\nexport interface StartupObservation {\n\tsetupName: string;\n\tconfigIdentity: string;\n\tcheckedAt: string;\n\tinspection: SyncInspection;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAUA,eAAsB,YACrB,QACA,SACA,QACA,UAA8B,mBAC7B;AACD,iBAAe,MAAM;AACrB,QAAM,UAAU,MAAM,QAAQ,MAAM;AACpC,iBAAe,MAAM;AACrB,QAAM,QAAQ,MAAM,eAAe,OAAO,kBAAkB,EAAE,GAAG,SAAS,OAAO,CAAC;AAClF,iBAAe,MAAM;AACrB,QAAM,QAAQ,MAAM,mBAAmB,MAAM;AAC7C,iBAAe,MAAM;AACrB,QAAM,OAAO,MAAM,QAAQ,SAAS,MAAM;AAC1C,iBAAe,MAAM;AACrB,SAAO;AAAA,IACN;AAAA,IACA,gBAAgB,OACb,uBAAuB,OAAO,SAAS,EAAE,WAAW,KAAK,WAAW,OAAO,CAAC,EAAE,CAAC,IAC/E;AAAA,IACH,YAAY,MAAM,MAAM;AAAA,IACxB,cAAc,gBAAgB,OAAO,OAAO,MAAM;AAAA,IAClD,eAAe;AAAA,MAAwB;AAAA,MAAM;AAAA,MAAO;AAAA,MAAQ,CAAC,MAAM,UAClE,QAAQ,aAAa,MAAM,KAAK;AAAA,IACjC;AAAA,IACA,WAAW,CAAC,MAAM;AAAA,IAClB,cAAc,OAAO,QAAQ,WAAW;AAAA,IACxC,eAAe,qBAAqB,KAAK;AAAA,IACzC,aAAa,QAAQ;AAAA,IACrB,YAAY,QAAQ;AAAA,EACrB;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/backends/backend-factory.ts"],
|
|
4
|
-
"sourcesContent": ["import type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport type { SyncBackend } from \"./sync-backend.js\";\n\nexport type SyncBackendFactory = {\n\tbivarianceHack(config: AnySyncConfig): SyncBackend | Promise<SyncBackend>;\n}[\"bivarianceHack\"];\n\nexport const createSyncBackend: SyncBackendFactory = async (config) => {\n\tswitch (config.backend.type) {\n\t\tcase \"s3\": {\n\t\t\tconst { S3SyncBackend } = await import(\"./s3/s3-backend.js\");\n\t\t\treturn new S3SyncBackend(config.backend);\n\t\t}\n\t\tcase \"webdav\": {\n\t\t\tconst { WebDavSyncBackend } = await import(\"./webdav/webdav-backend.js\");\n\t\t\treturn new WebDavSyncBackend(config.backend);\n\t\t}\n\t\tcase \"git\": {\n\t\t\tconst { GitSyncBackend } = await import(\"./git/git-backend.js\");\n\t\t\treturn new GitSyncBackend(config.backend);\n\t\t}\n\t}\n};\n"],
|
|
5
|
-
"mappings": ";;;;AAOO,IAAM,oBAAwC,OAAO,WAAW;AACtE,UAAQ,OAAO,QAAQ,MAAM;AAAA,IAC5B,KAAK,MAAM;AACV,YAAM,EAAE,cAAc,IAAI,MAAM,OAAO,0BAAoB;AAC3D,aAAO,IAAI,cAAc,OAAO,OAAO;AAAA,IACxC;AAAA,IACA,KAAK,UAAU;AACd,YAAM,EAAE,kBAAkB,IAAI,MAAM,OAAO,8BAA4B;AACvE,aAAO,IAAI,kBAAkB,OAAO,OAAO;AAAA,IAC5C;AAAA,IACA,KAAK,OAAO;AACX,YAAM,EAAE,eAAe,IAAI,MAAM,OAAO,2BAAsB;AAC9D,aAAO,IAAI,eAAe,OAAO,OAAO;AAAA,IACzC;AAAA,EACD;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/snapshot/session-paths.ts", "../../src/state/json-file.ts"],
|
|
4
|
-
"sourcesContent": ["import os from \"node:os\";\nimport path from \"node:path\";\nimport {\n\ttype ExtensionCommandContext,\n\ttype ExtensionContext,\n\tgetAgentDir,\n} from \"@earendil-works/pi-coding-agent\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport { readJsonIfExists } from \"../state/json-file.js\";\nimport type { Snapshot, SnapshotOptions } from \"./snapshot-types.js\";\n\nexport function sessionDirFromContext(ctx: ExtensionCommandContext | ExtensionContext) {\n\tconst manager = ctx.sessionManager as typeof ctx.sessionManager & {\n\t\tusesDefaultSessionDir?: () => boolean;\n\t};\n\tconst usesDefaultSessionDir = manager.usesDefaultSessionDir;\n\tif (typeof usesDefaultSessionDir === \"function\" && usesDefaultSessionDir.call(manager)) {\n\t\treturn undefined;\n\t}\n\tconst getSessionDir = manager.getSessionDir;\n\treturn typeof getSessionDir === \"function\"\n\t\t? (getSessionDir.call(manager) as string | undefined)\n\t\t: undefined;\n}\n\nexport async function configuredSessionDir() {\n\tconst settings = await readJsonIfExists<{ sessionDir?: string }>(\n\t\tpath.join(agentDir(), \"settings.json\"),\n\t);\n\treturn settings?.sessionDir ? expandHome(settings.sessionDir) : undefined;\n}\n\nexport async function sessionDirForApply(\n\tctx: ExtensionCommandContext | ExtensionContext,\n\tsnapshot: Snapshot,\n) {\n\tconst contextSessionDir = sessionDirFromContext(ctx);\n\tconst localSessionDir = await configuredSessionDir();\n\tif (\n\t\tcontextSessionDir &&\n\t\tpath.resolve(contextSessionDir) !== path.resolve(localSessionDir ?? \"\")\n\t) {\n\t\treturn contextSessionDir;\n\t}\n\treturn sessionDirFromSnapshot(snapshot) ?? contextSessionDir;\n}\n\nfunction sessionDirFromSnapshot(snapshot: Snapshot) {\n\tconst settingsFile = snapshot.files.find((file) => file.path === \"settings.json\");\n\tif (!settingsFile) return undefined;\n\ttry {\n\t\tconst settings = JSON.parse(\n\t\t\tdecodeBase64Strict(settingsFile.contentBase64, settingsFile.path).toString(\"utf8\"),\n\t\t) as { sessionDir?: string };\n\t\treturn settings.sessionDir ? expandHome(settings.sessionDir) : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction decodeBase64Strict(value: string, filePath: string) {\n\tif (!/^[A-Za-z0-9+/]*={0,2}$/.test(value) || value.length % 4 !== 0) {\n\t\tthrow new Error(`Invalid base64 content in snapshot file: ${filePath}`);\n\t}\n\treturn Buffer.from(value, \"base64\");\n}\n\nexport function agentDir() {\n\treturn getAgentDir();\n}\n\nfunction expandHome(value: string) {\n\treturn value === \"~\" || value.startsWith(\"~/\") ? path.join(os.homedir(), value.slice(2)) : value;\n}\n\nexport function snapshotOptionsForContext(\n\tctx: ExtensionCommandContext | ExtensionContext,\n\tconfig: AnySyncConfig,\n): SnapshotOptions {\n\treturn {\n\t\tinclude: config.include,\n\t\tsessionDir: sessionDirFromContext(ctx),\n\t};\n}\n", "import { randomUUID } from \"node:crypto\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\n\nexport async function readJsonIfExists<T>(filePath: string): Promise<T | undefined> {\n\ttry {\n\t\treturn JSON.parse(await fs.readFile(filePath, \"utf8\")) as T;\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n\t\tthrow error;\n\t}\n}\n\nexport async function writeJson(filePath: string, value: unknown) {\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\tconst temp = `${filePath}.${process.pid}.${randomUUID()}.tmp`;\n\tawait fs.writeFile(temp, `${JSON.stringify(value, null, \"\\t\")}\\n`, { mode: 0o600 });\n\tif (process.platform !== \"win32\") await fs.chmod(temp, 0o600);\n\tawait fs.rename(temp, filePath);\n}\n"],
|
|
5
|
-
"mappings": ";;;;AAAA,OAAO,QAAQ;AACf,OAAOA,WAAU;AACjB;AAAA,EAGC;AAAA,OACM;;;ACNP,SAAS,kBAAkB;AAC3B,OAAO,QAAQ;AACf,OAAO,UAAU;AAEjB,eAAsB,iBAAoB,UAA0C;AACnF,MAAI;AACH,WAAO,KAAK,MAAM,MAAM,GAAG,SAAS,UAAU,MAAM,CAAC;AAAA,EACtD,SAAS,OAAO;AACf,QAAK,MAAgC,SAAS,SAAU,QAAO;AAC/D,UAAM;AAAA,EACP;AACD;AAEA,eAAsB,UAAU,UAAkB,OAAgB;AACjE,QAAM,GAAG,MAAM,KAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;AAC1D,QAAM,OAAO,GAAG,QAAQ,IAAI,QAAQ,GAAG,IAAI,WAAW,CAAC;AACvD,QAAM,GAAG,UAAU,MAAM,GAAG,KAAK,UAAU,OAAO,MAAM,GAAI,CAAC;AAAA,GAAM,EAAE,MAAM,IAAM,CAAC;AAClF,MAAI,QAAQ,aAAa,QAAS,OAAM,GAAG,MAAM,MAAM,GAAK;AAC5D,QAAM,GAAG,OAAO,MAAM,QAAQ;AAC/B;;;ADRO,SAAS,sBAAsB,KAAiD;AACtF,QAAM,UAAU,IAAI;AAGpB,QAAM,wBAAwB,QAAQ;AACtC,MAAI,OAAO,0BAA0B,cAAc,sBAAsB,KAAK,OAAO,GAAG;AACvF,WAAO;AAAA,EACR;AACA,QAAM,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