@narumitw/pi-sync 0.70.6 → 0.71.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/CHANGELOG.md +16 -0
- package/README.md +34 -105
- package/dist/chunks/agent-plan-A6CS3XXA.ts +337 -0
- package/dist/chunks/agent-plan-A6CS3XXA.ts.map +7 -0
- package/dist/chunks/chunk-2BMTS5OW.ts +229 -0
- package/dist/chunks/chunk-2BMTS5OW.ts.map +7 -0
- package/dist/chunks/chunk-2G6GTIWW.ts +188 -0
- package/dist/chunks/chunk-2G6GTIWW.ts.map +7 -0
- package/dist/chunks/chunk-2YHXXWUF.ts +18 -0
- package/dist/chunks/chunk-2YHXXWUF.ts.map +7 -0
- package/dist/chunks/chunk-3GL7LBNB.ts +3 -0
- package/dist/chunks/chunk-3M3KQFSQ.ts +215 -0
- package/dist/chunks/chunk-3M3KQFSQ.ts.map +7 -0
- package/dist/chunks/chunk-3PFWVSV3.ts +3 -0
- package/dist/chunks/chunk-4S5CGN4M.ts +54 -0
- package/dist/chunks/chunk-4S5CGN4M.ts.map +7 -0
- package/dist/chunks/{chunk-H7VOTY5N.ts → chunk-53AFFVTT.ts} +2 -24
- package/dist/chunks/{chunk-H7VOTY5N.ts.map → chunk-53AFFVTT.ts.map} +1 -1
- package/dist/chunks/chunk-53IKSWLZ.ts +3 -0
- package/dist/chunks/{chunk-ZWP6HAYV.ts → chunk-5ERTMRNE.ts} +1 -1
- package/dist/chunks/chunk-5ERTMRNE.ts.map +7 -0
- package/dist/chunks/chunk-5WUWHDCJ.ts +12 -0
- package/dist/chunks/chunk-5WUWHDCJ.ts.map +7 -0
- package/dist/chunks/{chunk-WRS3SUNZ.ts → chunk-6VGQ6THO.ts} +8 -10
- package/dist/chunks/{chunk-WRS3SUNZ.ts.map → chunk-6VGQ6THO.ts.map} +1 -1
- package/dist/chunks/chunk-6WVJIIXQ.ts +154 -0
- package/dist/chunks/chunk-6WVJIIXQ.ts.map +7 -0
- package/dist/chunks/chunk-A3NEEVNA.ts +3 -0
- package/dist/chunks/chunk-A7KJUFLX.ts +2120 -0
- package/dist/chunks/chunk-A7KJUFLX.ts.map +7 -0
- package/dist/chunks/{chunk-4A34OGXY.ts → chunk-AA2G3HTW.ts} +12 -16
- package/dist/chunks/{chunk-4A34OGXY.ts.map → chunk-AA2G3HTW.ts.map} +1 -1
- package/dist/chunks/chunk-AITZUACB.ts +3 -0
- package/dist/chunks/chunk-AVLYLWA7.ts +1414 -0
- package/dist/chunks/chunk-AVLYLWA7.ts.map +7 -0
- package/dist/chunks/chunk-B4JNUYZ2.ts +12 -0
- package/dist/chunks/chunk-B4JNUYZ2.ts.map +7 -0
- package/dist/chunks/chunk-BEO3THWZ.ts +3 -0
- package/dist/chunks/chunk-BEO3THWZ.ts.map +7 -0
- package/dist/chunks/chunk-C2YD64T6.ts +167 -0
- package/dist/chunks/chunk-C2YD64T6.ts.map +7 -0
- package/dist/chunks/chunk-C66HLRRZ.ts +72 -0
- package/dist/chunks/chunk-C66HLRRZ.ts.map +7 -0
- package/dist/chunks/chunk-CFXAA65U.ts +53 -0
- package/dist/chunks/chunk-CFXAA65U.ts.map +7 -0
- package/dist/chunks/chunk-D34Y5JSL.ts +152 -0
- package/dist/chunks/chunk-D34Y5JSL.ts.map +7 -0
- package/dist/chunks/chunk-D3DMJSFU.ts +125 -0
- package/dist/chunks/chunk-D3DMJSFU.ts.map +7 -0
- package/dist/chunks/chunk-DFC3WJP5.ts +3 -0
- package/dist/chunks/chunk-DFC3WJP5.ts.map +7 -0
- package/dist/chunks/chunk-DH52CVRD.ts +2499 -0
- package/dist/chunks/chunk-DH52CVRD.ts.map +7 -0
- package/dist/chunks/chunk-DLA5RPFP.ts +50 -0
- package/dist/chunks/chunk-DLA5RPFP.ts.map +7 -0
- package/dist/chunks/chunk-ES4FIIHZ.ts +50 -0
- package/dist/chunks/chunk-ES4FIIHZ.ts.map +7 -0
- package/dist/chunks/chunk-ESUMO4TW.ts +55 -0
- package/dist/chunks/chunk-ESUMO4TW.ts.map +7 -0
- package/dist/chunks/chunk-FIEW5453.ts +77 -0
- package/dist/chunks/chunk-FIEW5453.ts.map +7 -0
- package/dist/chunks/chunk-FT45DX6E.ts +163 -0
- package/dist/chunks/chunk-FT45DX6E.ts.map +7 -0
- package/dist/chunks/chunk-G7U6BPP4.ts +137 -0
- package/dist/chunks/chunk-G7U6BPP4.ts.map +7 -0
- package/dist/chunks/{chunk-5BE6LBDC.ts → chunk-GC5XDUVA.ts} +25 -34
- package/dist/chunks/{chunk-5BE6LBDC.ts.map → chunk-GC5XDUVA.ts.map} +3 -3
- package/dist/chunks/{chunk-VERMBZGL.ts → chunk-GDA35HWZ.ts} +12 -14
- package/dist/chunks/{chunk-VERMBZGL.ts.map → chunk-GDA35HWZ.ts.map} +1 -1
- package/dist/chunks/chunk-HOFEC5FH.ts +54 -0
- package/dist/chunks/chunk-HOFEC5FH.ts.map +7 -0
- package/dist/chunks/{chunk-WE3KJ7JS.ts → chunk-IFJXUHHC.ts} +7 -7
- package/dist/chunks/chunk-INUH2UXN.ts +53 -0
- package/dist/chunks/chunk-INUH2UXN.ts.map +7 -0
- package/dist/chunks/chunk-JPLT2DG6.ts +122 -0
- package/dist/chunks/chunk-JPLT2DG6.ts.map +7 -0
- package/dist/chunks/chunk-KDTDGAOM.ts +76 -0
- package/dist/chunks/chunk-KDTDGAOM.ts.map +7 -0
- package/dist/chunks/chunk-LBDUDSHD.ts +3 -0
- package/dist/chunks/chunk-LBDUDSHD.ts.map +7 -0
- package/dist/chunks/{chunk-VQTYTUBU.ts → chunk-LHQIQIWL.ts} +4 -22
- package/dist/chunks/chunk-LHQIQIWL.ts.map +7 -0
- package/dist/chunks/chunk-MHERAG42.ts +150 -0
- package/dist/chunks/chunk-MHERAG42.ts.map +7 -0
- package/dist/chunks/chunk-MS6HLJFR.ts +61 -0
- package/dist/chunks/chunk-MS6HLJFR.ts.map +7 -0
- package/dist/chunks/{chunk-AXN3B5KC.ts → chunk-MTUR4H7S.ts} +31 -41
- package/dist/chunks/chunk-MTUR4H7S.ts.map +7 -0
- package/dist/chunks/chunk-NFW5HLKA.ts +84 -0
- package/dist/chunks/chunk-NFW5HLKA.ts.map +7 -0
- package/dist/chunks/chunk-NFZMKZ2D.ts +345 -0
- package/dist/chunks/chunk-NFZMKZ2D.ts.map +7 -0
- package/dist/chunks/chunk-OTI4XVCS.ts +618 -0
- package/dist/chunks/chunk-OTI4XVCS.ts.map +7 -0
- package/dist/chunks/chunk-QIL27OLJ.ts +28 -0
- package/dist/chunks/chunk-QIL27OLJ.ts.map +7 -0
- package/dist/chunks/chunk-QJTU5SCJ.ts +27 -0
- package/dist/chunks/chunk-QJTU5SCJ.ts.map +7 -0
- package/dist/chunks/chunk-QNU4RFCN.ts +225 -0
- package/dist/chunks/chunk-QNU4RFCN.ts.map +7 -0
- package/dist/chunks/chunk-QRSESWT2.ts +26 -0
- package/dist/chunks/chunk-QRSESWT2.ts.map +7 -0
- package/dist/chunks/chunk-RFJWUIV5.ts +1622 -0
- package/dist/chunks/chunk-RFJWUIV5.ts.map +7 -0
- package/dist/chunks/chunk-RRFW2UAD.ts +347 -0
- package/dist/chunks/chunk-RRFW2UAD.ts.map +7 -0
- package/dist/chunks/chunk-SD3D6BTF.ts +3 -0
- package/dist/chunks/chunk-SD3D6BTF.ts.map +7 -0
- package/dist/chunks/chunk-SPRHJBJC.ts +17 -0
- package/dist/chunks/chunk-SPRHJBJC.ts.map +7 -0
- package/dist/chunks/chunk-T22OVZSI.ts +347 -0
- package/dist/chunks/chunk-T22OVZSI.ts.map +7 -0
- package/dist/chunks/chunk-TAOYC2YG.ts +113 -0
- package/dist/chunks/chunk-TAOYC2YG.ts.map +7 -0
- package/dist/chunks/chunk-U6CORBHU.ts +205 -0
- package/dist/chunks/chunk-U6CORBHU.ts.map +7 -0
- package/dist/chunks/chunk-ULNEZ53E.ts +105 -0
- package/dist/chunks/chunk-ULNEZ53E.ts.map +7 -0
- package/dist/chunks/chunk-UPP54ATP.ts +3 -0
- package/dist/chunks/chunk-UPP54ATP.ts.map +7 -0
- package/dist/chunks/chunk-V66NV2HZ.ts +70 -0
- package/dist/chunks/chunk-V66NV2HZ.ts.map +7 -0
- package/dist/chunks/chunk-W3YS4Y2Q.ts +545 -0
- package/dist/chunks/chunk-W3YS4Y2Q.ts.map +7 -0
- package/dist/chunks/chunk-WETDHZAD.ts +815 -0
- package/dist/chunks/chunk-WETDHZAD.ts.map +7 -0
- package/dist/chunks/chunk-WT2722L4.ts +61 -0
- package/dist/chunks/chunk-WT2722L4.ts.map +7 -0
- package/dist/chunks/chunk-XHJ3AVIT.ts +12 -0
- package/dist/chunks/chunk-XHJ3AVIT.ts.map +7 -0
- package/dist/chunks/{chunk-HFMGK6A6.ts → chunk-YLVRV6NM.ts} +5 -5
- package/dist/chunks/chunk-YV776ZPN.ts +49 -0
- package/dist/chunks/chunk-YV776ZPN.ts.map +7 -0
- package/dist/chunks/chunk-YVHXQZIH.ts +411 -0
- package/dist/chunks/chunk-YVHXQZIH.ts.map +7 -0
- package/dist/chunks/chunk-ZWJMVLQ3.ts +3 -0
- package/dist/chunks/chunk-ZWJMVLQ3.ts.map +7 -0
- package/dist/chunks/chunk-ZWOKNJDT.ts +25 -0
- package/dist/chunks/chunk-ZWOKNJDT.ts.map +7 -0
- package/dist/chunks/{command-handler-GERC7LOE.ts → command-handler-SMARANCT.ts} +128 -155
- package/dist/chunks/command-handler-SMARANCT.ts.map +7 -0
- package/dist/chunks/{chunk-LNZRNXNQ.ts → config-PUZS2ZBP.ts} +15 -6
- package/dist/chunks/config-PUZS2ZBP.ts.map +7 -0
- package/dist/chunks/conflict-artifacts-77PI6IXK.ts +33 -0
- package/dist/chunks/conflict-artifacts-77PI6IXK.ts.map +7 -0
- package/dist/chunks/conflict-review-HHGVL5TP.ts +188 -0
- package/dist/chunks/conflict-review-HHGVL5TP.ts.map +7 -0
- package/dist/chunks/conflict-review-OO57TGMR.ts +40 -0
- package/dist/chunks/conflict-review-OO57TGMR.ts.map +7 -0
- package/dist/chunks/continuous-record-QIIFQNKP.ts +277 -0
- package/dist/chunks/continuous-record-QIIFQNKP.ts.map +7 -0
- package/dist/chunks/debug-check-ETFFIDW5.ts +14 -0
- package/dist/chunks/debug-check-ETFFIDW5.ts.map +7 -0
- package/dist/chunks/debug-log-QGBO6XHF.ts +17 -0
- package/dist/chunks/debug-log-QGBO6XHF.ts.map +7 -0
- package/dist/chunks/debug-tool-execution-AIQAGPMJ.ts +95 -0
- package/dist/chunks/debug-tool-execution-AIQAGPMJ.ts.map +7 -0
- package/dist/chunks/{diff-review-GB4NO53B.ts → diff-review-QRHOHG5C.ts} +12 -5
- package/dist/chunks/diff-review-QRHOHG5C.ts.map +7 -0
- package/dist/chunks/{file-selection-DGC5UJVI.ts → file-selection-ZEBPDRHG.ts} +33 -16
- package/dist/chunks/{file-selection-DGC5UJVI.ts.map → file-selection-ZEBPDRHG.ts.map} +1 -1
- package/dist/chunks/git-backend-I2IJ5ULJ.ts +1151 -0
- package/dist/chunks/git-backend-I2IJ5ULJ.ts.map +7 -0
- package/dist/chunks/initialization-XGYWRNPQ.ts +106 -0
- package/dist/chunks/initialization-XGYWRNPQ.ts.map +7 -0
- package/dist/chunks/local-diff-review-OGZM3TA7.ts +525 -0
- package/dist/chunks/local-diff-review-OGZM3TA7.ts.map +7 -0
- package/dist/chunks/local-fields-PIKOEXWR.ts +31 -0
- package/dist/chunks/local-fields-PIKOEXWR.ts.map +7 -0
- package/dist/chunks/manager-result-dispatcher-72YGSLHL.ts +42 -0
- package/dist/chunks/manager-result-dispatcher-72YGSLHL.ts.map +7 -0
- package/dist/chunks/{manager-ui-3CQU37XY.ts → manager-ui-5SXPS4SE.ts} +130 -92
- package/dist/chunks/manager-ui-5SXPS4SE.ts.map +7 -0
- package/dist/chunks/merge-baseline-store-MI7SHGDH.ts +26 -0
- package/dist/chunks/merge-baseline-store-MI7SHGDH.ts.map +7 -0
- package/dist/chunks/merge-journal-46QC5N7D.ts +38 -0
- package/dist/chunks/merge-journal-46QC5N7D.ts.map +7 -0
- package/dist/chunks/{merge-review-DXSERTCK.ts → merge-review-RMDYVNBK.ts} +2 -2
- package/dist/chunks/remote-selection-ui-4BXJAZUD.ts +41 -0
- package/dist/chunks/remote-selection-ui-4BXJAZUD.ts.map +7 -0
- package/dist/chunks/s3-backend-ZRMOWH5R.ts +866 -0
- package/dist/chunks/s3-backend-ZRMOWH5R.ts.map +7 -0
- package/dist/chunks/session-push-55IV4IW3.ts +101 -0
- package/dist/chunks/session-push-55IV4IW3.ts.map +7 -0
- package/dist/chunks/setup-switch-DXDUBDQI.ts +43 -0
- package/dist/chunks/setup-switch-DXDUBDQI.ts.map +7 -0
- package/dist/chunks/{setup-wizard-FRIR2EOR.ts → setup-wizard-ICPQERAE.ts} +34 -18
- package/dist/chunks/{setup-wizard-FRIR2EOR.ts.map → setup-wizard-ICPQERAE.ts.map} +1 -1
- package/dist/chunks/{snapshot-ZUJJZCFW.ts → snapshot-HDARHOQZ.ts} +14 -8
- package/dist/chunks/snapshot-HDARHOQZ.ts.map +7 -0
- package/dist/chunks/snapshot-LZ6XKFA4.ts +63 -0
- package/dist/chunks/snapshot-LZ6XKFA4.ts.map +7 -0
- package/dist/chunks/snapshot-transaction-LYR5OFLR.ts +27 -0
- package/dist/chunks/snapshot-transaction-LYR5OFLR.ts.map +7 -0
- package/dist/chunks/sync-inspection-N6TELULU.ts +29 -0
- package/dist/chunks/sync-inspection-N6TELULU.ts.map +7 -0
- package/dist/chunks/sync-inspection-PMEXXLDK.ts +26 -0
- package/dist/chunks/sync-inspection-PMEXXLDK.ts.map +7 -0
- package/dist/chunks/sync-operations-KKSIS2CI.ts +69 -0
- package/dist/chunks/sync-operations-KKSIS2CI.ts.map +7 -0
- package/dist/chunks/sync-operations-VSMA5GSA.ts +47 -0
- package/dist/chunks/sync-operations-VSMA5GSA.ts.map +7 -0
- package/dist/chunks/{sync-state-QIT64TKV.ts → sync-state-72ZDKUQW.ts} +13 -5
- package/dist/chunks/sync-state-72ZDKUQW.ts.map +7 -0
- package/dist/chunks/{sync-state-store-TZE7XDV5.ts → sync-state-store-YTMAZQ3Z.ts} +8 -2
- package/dist/chunks/sync-state-store-YTMAZQ3Z.ts.map +7 -0
- package/dist/chunks/webdav-backend-3AZOECVQ.ts +948 -0
- package/dist/chunks/webdav-backend-3AZOECVQ.ts.map +7 -0
- package/dist/index.ts +286 -421
- package/dist/index.ts.map +4 -4
- package/docs/agent-continuous-hardening.md +3 -1
- package/docs/agent-quality-verification.md +3 -1
- package/docs/continuous-sync-verification.md +1 -1
- package/docs/daemon-migration.md +3 -1
- package/docs/daemon-retirement.md +15 -0
- package/docs/merge-implementation-audit.md +2 -0
- package/docs/settings-merge-audit.md +1 -1
- package/docs/tui-contract.md +12 -14
- package/package.json +1 -3
- package/skills/configure-pi-sync/SKILL.md +14 -60
- package/skills/configure-pi-sync/references/configuration.md +38 -46
- package/src/backends/backend-factory.ts +2 -2
- package/src/backends/backend-identity.ts +2 -2
- package/src/backends/backend-types.ts +1 -1
- package/src/backends/git/git-backend.ts +2 -2
- package/src/backends/git/git-config.ts +2 -2
- package/src/backends/git/git-runner.ts +2 -2
- package/src/backends/git/git-storage.ts +2 -2
- package/src/backends/s3/s3-backend.ts +2 -2
- package/src/backends/s3/s3-client.ts +2 -2
- package/src/backends/s3/s3-conditions.ts +2 -2
- package/src/backends/snapshot-pointer.ts +2 -2
- package/src/backends/sync-backend.ts +2 -2
- package/src/backends/webdav/webdav-backend.ts +2 -2
- package/src/backends/webdav/webdav-client.ts +2 -2
- package/src/backends/webdav/webdav-config.ts +2 -2
- package/src/commands/command-execution.ts +66 -62
- package/src/commands/command-handler.ts +3 -10
- package/src/commands/command-types.ts +1 -0
- package/src/commands/command.ts +3 -24
- package/src/engine/backends/backend-factory.ts +23 -0
- package/src/engine/backends/backend-identity.ts +40 -0
- package/src/engine/backends/backend-types.ts +75 -0
- package/src/engine/backends/git/git-backend.ts +863 -0
- package/src/engine/backends/git/git-config.ts +130 -0
- package/src/engine/backends/git/git-runner.ts +260 -0
- package/src/engine/backends/git/git-storage.ts +295 -0
- package/src/engine/backends/publication-encoding.ts +19 -0
- package/src/engine/backends/s3/s3-backend.ts +528 -0
- package/src/engine/backends/s3/s3-client.ts +398 -0
- package/src/engine/backends/s3/s3-conditions.ts +64 -0
- package/src/engine/backends/snapshot-pointer.ts +26 -0
- package/src/engine/backends/sync-backend.ts +133 -0
- package/src/engine/backends/webdav/webdav-backend.ts +691 -0
- package/src/engine/backends/webdav/webdav-client.ts +390 -0
- package/src/engine/backends/webdav/webdav-config.ts +82 -0
- package/src/engine/commands/command-types.ts +37 -0
- package/src/engine/debug-check.ts +83 -0
- package/src/engine/debug-log.ts +272 -0
- package/src/engine/diff-review-types.ts +16 -0
- package/src/engine/foreground-transfer.ts +15 -0
- package/src/engine/host.ts +95 -0
- package/src/engine/paths.ts +90 -0
- package/src/engine/record.ts +3 -0
- package/src/engine/settings/config-errors.ts +6 -0
- package/src/engine/settings/config-file.ts +907 -0
- package/src/engine/settings/config.ts +315 -0
- package/src/engine/settings/retired-ignore-policy.ts +15 -0
- package/src/engine/settings/retired-ignore-recovery.ts +18 -0
- package/src/engine/settings/settings-management.ts +261 -0
- package/src/engine/settings/settings-store.ts +48 -0
- package/src/engine/settings/settings-types.ts +164 -0
- package/src/engine/settings/settings-validation.ts +472 -0
- package/src/engine/snapshot/session-paths.ts +179 -0
- package/src/engine/snapshot/snapshot-apply.ts +443 -0
- package/src/engine/snapshot/snapshot-bounds.ts +23 -0
- package/src/engine/snapshot/snapshot-capture-limit.ts +110 -0
- package/src/engine/snapshot/snapshot-case-replacement.ts +77 -0
- package/src/engine/snapshot/snapshot-codec.ts +69 -0
- package/src/engine/snapshot/snapshot-difference.ts +25 -0
- package/src/engine/snapshot/snapshot-entry-projection.ts +101 -0
- package/src/engine/snapshot/snapshot-exclude-safety.ts +203 -0
- package/src/engine/snapshot/snapshot-mutation-queues.ts +152 -0
- package/src/engine/snapshot/snapshot-paths.ts +11 -0
- package/src/engine/snapshot/snapshot-payload.ts +50 -0
- package/src/engine/snapshot/snapshot-reviewed-preimages.ts +68 -0
- package/src/engine/snapshot/snapshot-root-transition.ts +170 -0
- package/src/engine/snapshot/snapshot-transaction-directory.ts +16 -0
- package/src/engine/snapshot/snapshot-transaction-images.ts +424 -0
- package/src/engine/snapshot/snapshot-transaction-plan.ts +69 -0
- package/src/engine/snapshot/snapshot-transaction-policy.ts +278 -0
- package/src/engine/snapshot/snapshot-transaction-stage.ts +342 -0
- package/src/engine/snapshot/snapshot-transaction-verification.ts +109 -0
- package/src/engine/snapshot/snapshot-transaction.ts +961 -0
- package/src/engine/snapshot/snapshot-types.ts +67 -0
- package/src/engine/snapshot/snapshot.ts +847 -0
- package/src/engine/state/json-file.ts +46 -0
- package/src/engine/state/lock.ts +421 -0
- package/src/engine/state/lockfile-fs.ts +25 -0
- package/src/engine/state/merge-baseline-store.ts +213 -0
- package/src/engine/state/mutation-directory-sync.ts +33 -0
- package/src/engine/state/operation-availability.ts +59 -0
- package/src/engine/state/state-directory.ts +245 -0
- package/src/engine/state/state-types.ts +26 -0
- package/src/engine/state/sync-state-store.ts +77 -0
- package/src/engine/sync/agent-candidate.ts +252 -0
- package/src/engine/sync/agent-plan.ts +114 -0
- package/{dist/daemon/dist/engine/sync/agent-policy.js → src/engine/sync/agent-policy.ts} +5 -3
- package/src/engine/sync/agent-refusal-retry.ts +53 -0
- package/src/engine/sync/agent-request.ts +17 -0
- package/src/engine/sync/agent-runner.ts +208 -0
- package/src/engine/sync/agent-store.ts +175 -0
- package/src/engine/sync/agent-sync.ts +145 -0
- package/src/engine/sync/apply-review.ts +63 -0
- package/src/engine/sync/conflict-artifact-ownership.ts +58 -0
- package/src/engine/sync/conflict-artifacts.ts +193 -0
- package/src/engine/sync/conflict-groups.ts +67 -0
- package/src/engine/sync/conflict-preview.ts +54 -0
- package/src/engine/sync/conflict-resolution.ts +93 -0
- package/src/engine/sync/conflict-retention.ts +71 -0
- package/src/engine/sync/conflict-review.ts +95 -0
- package/src/engine/sync/content-conflicts.ts +73 -0
- package/src/engine/sync/continuous-errors.ts +91 -0
- package/src/engine/sync/continuous-lease.ts +213 -0
- package/src/engine/sync/continuous-record.ts +255 -0
- package/src/engine/sync/continuous-storage.ts +63 -0
- package/src/engine/sync/continuous-sync.ts +646 -0
- package/src/engine/sync/continuous-watch.ts +123 -0
- package/src/engine/sync/diff-review-capture.ts +259 -0
- package/src/engine/sync/diff-review-preview.ts +111 -0
- package/src/engine/sync/diff-review-store.ts +72 -0
- package/src/engine/sync/directional-action.ts +169 -0
- package/src/engine/sync/directional-conflict.ts +53 -0
- package/src/engine/sync/exclude-policy.ts +88 -0
- package/src/engine/sync/field-migration.ts +39 -0
- package/src/engine/sync/file-merge-planner.ts +138 -0
- package/src/engine/sync/initialization.ts +81 -0
- package/src/engine/sync/json-document.ts +179 -0
- package/src/engine/sync/local-field-policy.ts +28 -0
- package/src/engine/sync/local-fields.ts +171 -0
- package/src/engine/sync/merge-acceptance.ts +56 -0
- package/src/engine/sync/merge-apply.ts +585 -0
- package/src/engine/sync/merge-journal.ts +259 -0
- package/src/engine/sync/merge-transfer-error.ts +68 -0
- package/src/engine/sync/merged-sync.ts +912 -0
- package/src/engine/sync/mutation-owner.ts +22 -0
- package/src/engine/sync/package-merge.ts +81 -0
- package/src/engine/sync/partial-progress.ts +56 -0
- package/src/engine/sync/pull-outcome.ts +16 -0
- package/src/engine/sync/push-review.ts +47 -0
- package/src/engine/sync/remote-snapshot.ts +185 -0
- package/src/engine/sync/resolver-stream.ts +34 -0
- package/src/engine/sync/session-merge.ts +192 -0
- package/src/engine/sync/session-push.ts +68 -0
- package/src/engine/sync/settings-conflicts.ts +64 -0
- package/src/engine/sync/settings-merge.ts +118 -0
- package/src/engine/sync/signals.ts +8 -0
- package/src/engine/sync/startup-recovery-evidence.ts +37 -0
- package/src/engine/sync/startup-timings.ts +135 -0
- package/src/engine/sync/sync-decision.ts +134 -0
- package/src/engine/sync/sync-error-guidance.ts +56 -0
- package/src/engine/sync/sync-errors.ts +50 -0
- package/src/engine/sync/sync-inspection.ts +61 -0
- package/src/engine/sync/sync-loaders.ts +14 -0
- package/src/engine/sync/sync-local.ts +117 -0
- package/src/engine/sync/sync-mutations.ts +940 -0
- package/src/engine/sync/sync-operations.ts +10 -0
- package/src/engine/sync/sync-policy.ts +695 -0
- package/src/engine/sync/sync-queries.ts +404 -0
- package/src/engine/sync/sync-rollback.ts +245 -0
- package/src/engine/sync/sync-state.ts +197 -0
- package/src/engine/sync/text-merge.ts +132 -0
- package/src/engine/sync/transfer-freshness.ts +151 -0
- package/src/engine/sync/transfer-size-limits.ts +100 -0
- package/src/engine/types.ts +45 -0
- package/src/engine/ui/merge-review.ts +14 -0
- package/src/engine/ui/merged-sync-summary.ts +111 -0
- package/src/engine/ui/sync-format.ts +222 -0
- package/src/engine/ui/sync-status.ts +29 -0
- package/src/engine/ui/terminal-text.ts +9 -0
- package/src/engine/ui/transfer-changes.ts +32 -0
- package/src/engine/ui/transfer-review.ts +28 -0
- package/src/paths.ts +2 -2
- package/src/runtime/identity.ts +152 -0
- package/src/runtime/legacy-owner.ts +223 -0
- package/src/runtime/lifecycle.ts +17 -0
- package/src/runtime/local-host.ts +157 -0
- package/src/{daemon/session-presence.ts → runtime/session-presence-binding.ts} +1 -2
- package/src/runtime/session-presence.ts +258 -0
- package/src/settings/config-errors.ts +2 -2
- package/src/settings/config-file.ts +2 -2
- package/src/settings/config.ts +2 -2
- package/src/settings/settings-management.ts +2 -2
- package/src/settings/settings-store.ts +2 -2
- package/src/settings/settings-types.ts +1 -1
- package/src/settings/settings-validation.ts +2 -2
- package/src/snapshot/session-paths.ts +2 -2
- package/src/snapshot/snapshot-apply.ts +2 -2
- package/src/snapshot/snapshot-case-replacement.ts +2 -2
- package/src/snapshot/snapshot-codec.ts +2 -2
- package/src/snapshot/snapshot-exclude-safety.ts +2 -2
- package/src/snapshot/snapshot-mutation-queues.ts +2 -2
- package/src/snapshot/snapshot-paths.ts +2 -2
- package/src/snapshot/snapshot-root-transition.ts +2 -2
- package/src/snapshot/snapshot-transaction-directory.ts +2 -2
- package/src/snapshot/snapshot-transaction-plan.ts +2 -2
- package/src/snapshot/snapshot-transaction.ts +2 -2
- package/src/snapshot/snapshot-types.ts +1 -1
- package/src/snapshot/snapshot.ts +2 -2
- package/src/state/json-file.ts +2 -2
- package/src/state/lock-policy.ts +2 -2
- package/src/state/lock.ts +2 -2
- package/src/state/lockfile-fs.ts +2 -2
- package/src/state/merge-baseline-store.ts +2 -2
- package/src/state/mutation-directory-sync.ts +2 -2
- package/src/state/operation-availability.ts +2 -2
- package/src/state/state-directory.ts +2 -2
- package/src/state/state-types.ts +1 -1
- package/src/state/sync-state-store.ts +2 -2
- package/src/sync/agent-candidate.ts +2 -2
- package/src/sync/agent-plan.ts +2 -2
- package/src/sync/agent-policy.ts +2 -2
- package/src/sync/agent-refusal-retry.ts +2 -2
- package/src/sync/agent-request.ts +2 -2
- package/src/sync/agent-runner.ts +2 -2
- package/src/sync/agent-store.ts +2 -2
- package/src/sync/agent-sync.ts +2 -2
- package/src/sync/apply-review.ts +2 -2
- package/src/sync/automatic-sync.ts +58 -120
- package/src/sync/conflict-artifact-ownership.ts +2 -2
- package/src/sync/conflict-artifacts.ts +2 -2
- package/src/sync/conflict-groups.ts +2 -2
- package/src/sync/conflict-preview.ts +2 -2
- package/src/sync/conflict-resolution.ts +2 -2
- package/src/sync/conflict-retention.ts +2 -2
- package/src/sync/conflict-review.ts +5 -2
- package/src/sync/content-conflicts.ts +2 -2
- package/src/sync/continuous-errors.ts +2 -2
- package/src/sync/continuous-lease.ts +2 -2
- package/src/sync/continuous-record.ts +2 -2
- package/src/sync/continuous-storage.ts +2 -2
- package/src/sync/continuous-sync.ts +2 -2
- package/src/sync/continuous-watch.ts +2 -2
- package/src/sync/debug-tool-execution.ts +21 -22
- package/src/sync/debug-tool.ts +12 -15
- package/src/sync/exclude-policy.ts +2 -2
- package/src/sync/field-migration.ts +2 -2
- package/src/sync/file-merge-planner.ts +2 -2
- package/src/sync/json-document.ts +2 -2
- package/src/sync/local-diff-review.ts +115 -0
- package/src/sync/local-field-policy.ts +2 -2
- package/src/sync/local-fields.ts +2 -2
- package/src/sync/local-recovery.ts +53 -0
- package/src/sync/merge-apply.ts +2 -2
- package/src/sync/merge-journal.ts +2 -2
- package/src/sync/merge-transfer-error.ts +2 -2
- package/src/sync/merged-sync.ts +2 -2
- package/src/sync/mutation-owner.ts +2 -2
- package/src/sync/package-merge.ts +2 -2
- package/src/sync/partial-progress.ts +2 -2
- package/src/sync/remote-snapshot.ts +2 -2
- package/src/sync/session-merge.ts +2 -2
- package/src/sync/settings-conflicts.ts +2 -2
- package/src/sync/settings-merge.ts +2 -2
- package/src/sync/signals.ts +2 -2
- package/src/sync/startup-timings.ts +2 -2
- package/src/sync/sync-decision.ts +2 -2
- package/src/sync/sync-error-guidance.ts +2 -2
- package/src/sync/sync-errors.ts +2 -2
- package/src/sync/sync-inspection.ts +46 -11
- package/src/sync/sync-local.ts +2 -2
- package/src/sync/sync-mutations.ts +2 -2
- package/src/sync/sync-operations.ts +143 -33
- package/src/sync/sync-policy.ts +2 -2
- package/src/sync/sync-queries.ts +2 -2
- package/src/sync/sync-state.ts +2 -2
- package/src/sync/text-merge.ts +2 -2
- package/src/sync-extension.ts +193 -278
- package/src/ui/cancellable-operation.ts +1 -1
- package/src/ui/diff-review.ts +4 -3
- package/src/ui/manager-ui.ts +2 -22
- package/dist/chunks/chunk-6YKOHBSC.ts +0 -18
- package/dist/chunks/chunk-6YKOHBSC.ts.map +0 -7
- package/dist/chunks/chunk-A43CJYG4.ts +0 -26
- package/dist/chunks/chunk-A43CJYG4.ts.map +0 -7
- package/dist/chunks/chunk-APZVJAEW.ts +0 -34
- package/dist/chunks/chunk-APZVJAEW.ts.map +0 -7
- package/dist/chunks/chunk-AXN3B5KC.ts.map +0 -7
- package/dist/chunks/chunk-GELYN4UC.ts +0 -14
- package/dist/chunks/chunk-GELYN4UC.ts.map +0 -7
- package/dist/chunks/chunk-IBXEM35O.ts +0 -34
- package/dist/chunks/chunk-IBXEM35O.ts.map +0 -7
- package/dist/chunks/chunk-KN4NY2VV.ts +0 -1524
- package/dist/chunks/chunk-KN4NY2VV.ts.map +0 -7
- package/dist/chunks/chunk-LNZRNXNQ.ts.map +0 -7
- package/dist/chunks/chunk-NXWHPVXR.ts +0 -26
- package/dist/chunks/chunk-NXWHPVXR.ts.map +0 -7
- package/dist/chunks/chunk-P4GI7LTT.ts +0 -20
- package/dist/chunks/chunk-P4GI7LTT.ts.map +0 -7
- package/dist/chunks/chunk-R3SAMXB6.ts +0 -60
- package/dist/chunks/chunk-R3SAMXB6.ts.map +0 -7
- package/dist/chunks/chunk-R7PN3KIY.ts +0 -22
- package/dist/chunks/chunk-R7PN3KIY.ts.map +0 -7
- package/dist/chunks/chunk-T3LABNHF.ts +0 -20
- package/dist/chunks/chunk-T3LABNHF.ts.map +0 -7
- package/dist/chunks/chunk-UMPA5S7X.ts +0 -11
- package/dist/chunks/chunk-UMPA5S7X.ts.map +0 -7
- package/dist/chunks/chunk-VQTYTUBU.ts.map +0 -7
- package/dist/chunks/chunk-ZO52JM4H.ts +0 -15
- package/dist/chunks/chunk-ZO52JM4H.ts.map +0 -7
- package/dist/chunks/chunk-ZWP6HAYV.ts.map +0 -7
- package/dist/chunks/client-debug-F4WFP2YJ.ts +0 -40
- package/dist/chunks/client-debug-F4WFP2YJ.ts.map +0 -7
- package/dist/chunks/command-handler-GERC7LOE.ts.map +0 -7
- package/dist/chunks/conflict-review-XZI7RYZX.ts +0 -18
- package/dist/chunks/conflict-review-XZI7RYZX.ts.map +0 -7
- package/dist/chunks/debug-tool-execution-7N4H6K3X.ts +0 -67
- package/dist/chunks/debug-tool-execution-7N4H6K3X.ts.map +0 -7
- package/dist/chunks/diff-review-FLWC5VOT.ts +0 -68
- package/dist/chunks/diff-review-FLWC5VOT.ts.map +0 -7
- package/dist/chunks/diff-review-GB4NO53B.ts.map +0 -7
- package/dist/chunks/manager-result-dispatcher-6MOJPLIS.ts +0 -20
- package/dist/chunks/manager-ui-3CQU37XY.ts.map +0 -7
- package/dist/chunks/ownership-recovery-5KXAMFSL.ts +0 -59
- package/dist/chunks/ownership-recovery-5KXAMFSL.ts.map +0 -7
- package/dist/chunks/remote-selection-ui-2V53UBHM.ts +0 -19
- package/dist/chunks/setup-switch-WSKVGW7L.ts +0 -27
- package/dist/chunks/snapshot-ZUJJZCFW.ts.map +0 -7
- package/dist/chunks/snapshot-transaction-directory-F46JWRAU.ts +0 -13
- package/dist/chunks/snapshot-transaction-directory-F46JWRAU.ts.map +0 -7
- package/dist/chunks/state-directory-CMAIF34J.ts +0 -17
- package/dist/chunks/sync-inspection-ECI4BY5N.ts +0 -23
- package/dist/chunks/sync-inspection-ECI4BY5N.ts.map +0 -7
- package/dist/chunks/sync-operations-KWXZZEPT.ts +0 -52
- package/dist/chunks/sync-operations-KWXZZEPT.ts.map +0 -7
- package/dist/chunks/sync-state-QIT64TKV.ts.map +0 -7
- package/dist/daemon/LICENSE +0 -21
- package/dist/daemon/dist/build-id.json +0 -1
- package/dist/daemon/dist/build-version.js +0 -28
- package/dist/daemon/dist/child-sdk.mjs +0 -17
- package/dist/daemon/dist/cli.js +0 -156
- package/dist/daemon/dist/client-transport.js +0 -77
- package/dist/daemon/dist/client.js +0 -950
- package/dist/daemon/dist/consent.js +0 -304
- package/dist/daemon/dist/daemon-debug.js +0 -40
- package/dist/daemon/dist/daemon-recovery.js +0 -160
- package/dist/daemon/dist/daemon-startup.js +0 -350
- package/dist/daemon/dist/daemon-status.js +0 -57
- package/dist/daemon/dist/daemon-upgrade-error.js +0 -14
- package/dist/daemon/dist/diff-review-binding.js +0 -11
- package/dist/daemon/dist/diff-review-protocol.js +0 -85
- package/dist/daemon/dist/diff-review-rpc.js +0 -37
- package/dist/daemon/dist/diff-review-store.js +0 -89
- package/dist/daemon/dist/document.js +0 -6
- package/dist/daemon/dist/endpoint.js +0 -91
- package/dist/daemon/dist/engine/backends/backend-factory.js +0 -16
- package/dist/daemon/dist/engine/backends/backend-identity.js +0 -38
- package/dist/daemon/dist/engine/backends/backend-types.js +0 -1
- package/dist/daemon/dist/engine/backends/git/git-backend.js +0 -775
- package/dist/daemon/dist/engine/backends/git/git-config.js +0 -118
- package/dist/daemon/dist/engine/backends/git/git-runner.js +0 -237
- package/dist/daemon/dist/engine/backends/git/git-storage.js +0 -227
- package/dist/daemon/dist/engine/backends/publication-encoding.js +0 -19
- package/dist/daemon/dist/engine/backends/s3/s3-backend.js +0 -453
- package/dist/daemon/dist/engine/backends/s3/s3-client.js +0 -362
- package/dist/daemon/dist/engine/backends/s3/s3-conditions.js +0 -66
- package/dist/daemon/dist/engine/backends/snapshot-pointer.js +0 -22
- package/dist/daemon/dist/engine/backends/sync-backend.js +0 -39
- package/dist/daemon/dist/engine/backends/webdav/webdav-backend.js +0 -605
- package/dist/daemon/dist/engine/backends/webdav/webdav-client.js +0 -349
- package/dist/daemon/dist/engine/backends/webdav/webdav-config.js +0 -73
- package/dist/daemon/dist/engine/commands/command-types.js +0 -1
- package/dist/daemon/dist/engine/debug-check.js +0 -59
- package/dist/daemon/dist/engine/debug-log.js +0 -252
- package/dist/daemon/dist/engine/host.js +0 -20
- package/dist/daemon/dist/engine/paths.js +0 -77
- package/dist/daemon/dist/engine/settings/config-errors.js +0 -4
- package/dist/daemon/dist/engine/settings/config-file.js +0 -784
- package/dist/daemon/dist/engine/settings/config.js +0 -246
- package/dist/daemon/dist/engine/settings/retired-ignore-policy.js +0 -16
- package/dist/daemon/dist/engine/settings/retired-ignore-recovery.js +0 -14
- package/dist/daemon/dist/engine/settings/settings-management.js +0 -196
- package/dist/daemon/dist/engine/settings/settings-store.js +0 -41
- package/dist/daemon/dist/engine/settings/settings-types.js +0 -1
- package/dist/daemon/dist/engine/settings/settings-validation.js +0 -390
- package/dist/daemon/dist/engine/snapshot/session-paths.js +0 -146
- package/dist/daemon/dist/engine/snapshot/snapshot-apply.js +0 -347
- package/dist/daemon/dist/engine/snapshot/snapshot-bounds.js +0 -20
- package/dist/daemon/dist/engine/snapshot/snapshot-capture-limit.js +0 -99
- package/dist/daemon/dist/engine/snapshot/snapshot-case-replacement.js +0 -82
- package/dist/daemon/dist/engine/snapshot/snapshot-codec.js +0 -62
- package/dist/daemon/dist/engine/snapshot/snapshot-difference.js +0 -13
- package/dist/daemon/dist/engine/snapshot/snapshot-entry-projection.js +0 -78
- package/dist/daemon/dist/engine/snapshot/snapshot-exclude-safety.js +0 -205
- package/dist/daemon/dist/engine/snapshot/snapshot-mutation-queues.js +0 -153
- package/dist/daemon/dist/engine/snapshot/snapshot-paths.js +0 -11
- package/dist/daemon/dist/engine/snapshot/snapshot-payload.js +0 -42
- package/dist/daemon/dist/engine/snapshot/snapshot-reviewed-preimages.js +0 -60
- package/dist/daemon/dist/engine/snapshot/snapshot-root-transition.js +0 -138
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-directory.js +0 -16
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-images.js +0 -415
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-plan.js +0 -68
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-policy.js +0 -202
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-stage.js +0 -303
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-verification.js +0 -78
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction.js +0 -830
- package/dist/daemon/dist/engine/snapshot/snapshot-types.js +0 -3
- package/dist/daemon/dist/engine/snapshot/snapshot.js +0 -695
- package/dist/daemon/dist/engine/state/json-file.js +0 -49
- package/dist/daemon/dist/engine/state/lock.js +0 -399
- package/dist/daemon/dist/engine/state/lockfile-fs.js +0 -13
- package/dist/daemon/dist/engine/state/merge-baseline-store.js +0 -198
- package/dist/daemon/dist/engine/state/mutation-directory-sync.js +0 -34
- package/dist/daemon/dist/engine/state/operation-availability.js +0 -40
- package/dist/daemon/dist/engine/state/state-directory.js +0 -227
- package/dist/daemon/dist/engine/state/state-types.js +0 -1
- package/dist/daemon/dist/engine/state/sync-state-store.js +0 -58
- package/dist/daemon/dist/engine/sync/agent-candidate.js +0 -207
- package/dist/daemon/dist/engine/sync/agent-plan.js +0 -84
- package/dist/daemon/dist/engine/sync/agent-refusal-retry.js +0 -39
- package/dist/daemon/dist/engine/sync/agent-request.js +0 -13
- package/dist/daemon/dist/engine/sync/agent-runner.js +0 -183
- package/dist/daemon/dist/engine/sync/agent-store.js +0 -177
- package/dist/daemon/dist/engine/sync/agent-sync.js +0 -139
- package/dist/daemon/dist/engine/sync/apply-review.js +0 -52
- package/dist/daemon/dist/engine/sync/conflict-artifact-ownership.js +0 -53
- package/dist/daemon/dist/engine/sync/conflict-artifacts.js +0 -158
- package/dist/daemon/dist/engine/sync/conflict-groups.js +0 -76
- package/dist/daemon/dist/engine/sync/conflict-preview.js +0 -53
- package/dist/daemon/dist/engine/sync/conflict-resolution.js +0 -53
- package/dist/daemon/dist/engine/sync/conflict-retention.js +0 -61
- package/dist/daemon/dist/engine/sync/conflict-review.js +0 -73
- package/dist/daemon/dist/engine/sync/content-conflicts.js +0 -70
- package/dist/daemon/dist/engine/sync/continuous-errors.js +0 -72
- package/dist/daemon/dist/engine/sync/continuous-lease.js +0 -206
- package/dist/daemon/dist/engine/sync/continuous-record.js +0 -199
- package/dist/daemon/dist/engine/sync/continuous-storage.js +0 -59
- package/dist/daemon/dist/engine/sync/continuous-sync.js +0 -549
- package/dist/daemon/dist/engine/sync/continuous-watch.js +0 -137
- package/dist/daemon/dist/engine/sync/diff-review-capture.js +0 -210
- package/dist/daemon/dist/engine/sync/diff-review-preview.js +0 -114
- package/dist/daemon/dist/engine/sync/directional-action.js +0 -101
- package/dist/daemon/dist/engine/sync/directional-conflict.js +0 -29
- package/dist/daemon/dist/engine/sync/exclude-policy.js +0 -86
- package/dist/daemon/dist/engine/sync/field-migration.js +0 -20
- package/dist/daemon/dist/engine/sync/file-merge-planner.js +0 -123
- package/dist/daemon/dist/engine/sync/initialization.js +0 -81
- package/dist/daemon/dist/engine/sync/json-document.js +0 -172
- package/dist/daemon/dist/engine/sync/local-field-policy.js +0 -26
- package/dist/daemon/dist/engine/sync/local-fields.js +0 -161
- package/dist/daemon/dist/engine/sync/merge-acceptance.js +0 -29
- package/dist/daemon/dist/engine/sync/merge-apply.js +0 -530
- package/dist/daemon/dist/engine/sync/merge-journal.js +0 -204
- package/dist/daemon/dist/engine/sync/merge-transfer-error.js +0 -64
- package/dist/daemon/dist/engine/sync/merged-sync.js +0 -655
- package/dist/daemon/dist/engine/sync/mutation-owner.js +0 -18
- package/dist/daemon/dist/engine/sync/package-merge.js +0 -82
- package/dist/daemon/dist/engine/sync/partial-progress.js +0 -41
- package/dist/daemon/dist/engine/sync/push-review.js +0 -18
- package/dist/daemon/dist/engine/sync/remote-snapshot.js +0 -119
- package/dist/daemon/dist/engine/sync/resolver-stream.js +0 -34
- package/dist/daemon/dist/engine/sync/session-merge.js +0 -178
- package/dist/daemon/dist/engine/sync/session-push.js +0 -56
- package/dist/daemon/dist/engine/sync/settings-conflicts.js +0 -56
- package/dist/daemon/dist/engine/sync/settings-merge.js +0 -93
- package/dist/daemon/dist/engine/sync/signals.js +0 -8
- package/dist/daemon/dist/engine/sync/startup-bootstrap.js +0 -105
- package/dist/daemon/dist/engine/sync/startup-recovery-evidence.js +0 -37
- package/dist/daemon/dist/engine/sync/startup-timings.js +0 -116
- package/dist/daemon/dist/engine/sync/sync-decision.js +0 -81
- package/dist/daemon/dist/engine/sync/sync-error-guidance.js +0 -74
- package/dist/daemon/dist/engine/sync/sync-errors.js +0 -38
- package/dist/daemon/dist/engine/sync/sync-inspection.js +0 -42
- package/dist/daemon/dist/engine/sync/sync-loaders.js +0 -8
- package/dist/daemon/dist/engine/sync/sync-local.js +0 -96
- package/dist/daemon/dist/engine/sync/sync-mutations.js +0 -723
- package/dist/daemon/dist/engine/sync/sync-operations.js +0 -3
- package/dist/daemon/dist/engine/sync/sync-policy.js +0 -530
- package/dist/daemon/dist/engine/sync/sync-queries.js +0 -316
- package/dist/daemon/dist/engine/sync/sync-rollback.js +0 -180
- package/dist/daemon/dist/engine/sync/sync-state.js +0 -119
- package/dist/daemon/dist/engine/sync/text-merge.js +0 -124
- package/dist/daemon/dist/engine/sync/transfer-freshness.js +0 -79
- package/dist/daemon/dist/engine/sync/transfer-size-limits.js +0 -88
- package/dist/daemon/dist/engine/types.js +0 -2
- package/dist/daemon/dist/engine/ui/merge-review.js +0 -7
- package/dist/daemon/dist/engine/ui/merged-sync-summary.js +0 -86
- package/dist/daemon/dist/engine/ui/sync-format.js +0 -123
- package/dist/daemon/dist/engine/ui/sync-status.js +0 -30
- package/dist/daemon/dist/engine/ui/terminal-text.js +0 -9
- package/dist/daemon/dist/engine/ui/transfer-changes.js +0 -24
- package/dist/daemon/dist/engine/ui/transfer-review.js +0 -18
- package/dist/daemon/dist/engine-service.js +0 -506
- package/dist/daemon/dist/foreground-queue-outcome.js +0 -9
- package/dist/daemon/dist/foreground-transfer.js +0 -10
- package/dist/daemon/dist/identity.js +0 -275
- package/dist/daemon/dist/idle-exit.js +0 -77
- package/dist/daemon/dist/index.js +0 -27
- package/dist/daemon/dist/legacy-consent-guard.js +0 -34
- package/dist/daemon/dist/lifecycle-log.js +0 -54
- package/dist/daemon/dist/lifecycle.js +0 -21
- package/dist/daemon/dist/model-signature.js +0 -7
- package/dist/daemon/dist/paged-review.js +0 -177
- package/dist/daemon/dist/participant-admission.js +0 -30
- package/dist/daemon/dist/participant-ledger.js +0 -149
- package/dist/daemon/dist/protocol.js +0 -108
- package/dist/daemon/dist/resolver-host.js +0 -78
- package/dist/daemon/dist/server.js +0 -1374
- package/dist/daemon/dist/service-host.js +0 -260
- package/dist/daemon/dist/session-presence.js +0 -207
- package/dist/daemon/dist/state-wait-jobs.js +0 -23
- package/dist/daemon/dist/state-wait.js +0 -34
- package/dist/daemon/dist/upgrade-repair.js +0 -55
- package/dist/daemon/package.json +0 -3
- package/dist/package.json +0 -6
- package/src/daemon/apply-gate.ts +0 -146
- package/src/daemon/client-debug.ts +0 -50
- package/src/daemon/daemon-status-ui.ts +0 -64
- package/src/daemon/diff-review.ts +0 -68
- package/src/daemon/directional-recovery.ts +0 -106
- package/src/daemon/ownership-recovery.ts +0 -50
- package/src/daemon/pi-client.ts +0 -1300
- package/src/daemon/queue-release-ui.ts +0 -88
- package/src/daemon/recovery.ts +0 -103
- package/src/daemon/startup-bootstrap-client.ts +0 -26
- /package/dist/chunks/{manager-result-dispatcher-6MOJPLIS.ts.map → chunk-3GL7LBNB.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-2V53UBHM.ts.map → chunk-3PFWVSV3.ts.map} +0 -0
- /package/dist/chunks/{setup-switch-WSKVGW7L.ts.map → chunk-53IKSWLZ.ts.map} +0 -0
- /package/dist/chunks/{state-directory-CMAIF34J.ts.map → chunk-A3NEEVNA.ts.map} +0 -0
- /package/dist/chunks/{sync-state-store-TZE7XDV5.ts.map → chunk-AITZUACB.ts.map} +0 -0
- /package/dist/chunks/{chunk-WE3KJ7JS.ts.map → chunk-IFJXUHHC.ts.map} +0 -0
- /package/dist/chunks/{chunk-HFMGK6A6.ts.map → chunk-YLVRV6NM.ts.map} +0 -0
- /package/dist/chunks/{merge-review-DXSERTCK.ts.map → merge-review-RMDYVNBK.ts.map} +0 -0
- /package/{dist/daemon/dist/engine/state/lock-policy.js → src/engine/state/lock-policy.ts} +0 -0
|
@@ -1,950 +0,0 @@
|
|
|
1
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
-
import { setTimeout as delay } from "node:timers/promises";
|
|
3
|
-
import { DaemonError, requestDaemon } from "./client-transport.js";
|
|
4
|
-
import { sameDiffReviewBinding } from "./diff-review-binding.js";
|
|
5
|
-
import { DIFF_REVIEW_REQUEST_MS, isDiffReviewId, parseDiffReviewInventory, readDiffReviewPreview, } from "./diff-review-protocol.js";
|
|
6
|
-
import { isForegroundDirection, isForegroundQueueOutcome } from "./foreground-queue-outcome.js";
|
|
7
|
-
import { canonicalRootGuard, readProcessBirth } from "./identity.js";
|
|
8
|
-
import { withCleanup } from "./lifecycle.js";
|
|
9
|
-
import { MAX_REVIEW_BYTES, OWNERSHIP_CLEANUP_REQUIRED, operationPrefix, REVIEW_PAGE_CHARS, record, UNKNOWN_JOB_RESULT, } from "./protocol.js";
|
|
10
|
-
import { STATE_WAIT_FAILURE_LIMIT, stateWaitJobs, stateWaitResult } from "./state-wait-jobs.js";
|
|
11
|
-
export { DaemonError, hello, requestDaemon } from "./client-transport.js";
|
|
12
|
-
export { acquireStartupLock, checkUpgradeConsent, ensureDaemon, findDaemon, finishUpgrade, stopDaemon, waitForDaemonExit, } from "./daemon-startup.js";
|
|
13
|
-
const MAX_COMPLETED_CALLBACKS = 4096;
|
|
14
|
-
const RELEASE_ATTEMPT_MS = 2_000;
|
|
15
|
-
const RELEASE_BUDGET_MS = 25_000;
|
|
16
|
-
const RELEASE_MAX_ATTEMPTS = 20;
|
|
17
|
-
const FOREGROUND_RPC_MS = 3_000;
|
|
18
|
-
const FOREGROUND_DRAIN_MS = 30_000;
|
|
19
|
-
const FOREGROUND_RECOVERY_MS = 45_000;
|
|
20
|
-
const FOREGROUND_UNKNOWN_RESULT = "The daemon's transfer result could not be verified. Changes may have been made; recovery evidence was retained.";
|
|
21
|
-
const TRANSIENT_RELEASE_ERRORS = new Set(["ECONNRESET", "ECONNREFUSED", "EPIPE", "ENOENT", "ETIMEDOUT", "EAGAIN"]);
|
|
22
|
-
export class DaemonConnection {
|
|
23
|
-
paths;
|
|
24
|
-
identity;
|
|
25
|
-
facts;
|
|
26
|
-
options;
|
|
27
|
-
cursor = 0;
|
|
28
|
-
controller = new AbortController();
|
|
29
|
-
callbacks = new Map();
|
|
30
|
-
callbackIO = new AbortController();
|
|
31
|
-
diffReviewIO;
|
|
32
|
-
diffReviewPaused = false;
|
|
33
|
-
diffReviewBinding;
|
|
34
|
-
callbackTasks = new Set();
|
|
35
|
-
updates = Promise.resolve();
|
|
36
|
-
attached = false;
|
|
37
|
-
admitting = false;
|
|
38
|
-
observedContact;
|
|
39
|
-
contactRevision = 0;
|
|
40
|
-
lifecycleRevision = 0;
|
|
41
|
-
resuming;
|
|
42
|
-
resumeUncertain = false;
|
|
43
|
-
pendingJobs = new Set();
|
|
44
|
-
foregroundRecovery;
|
|
45
|
-
observesState = false;
|
|
46
|
-
stateRevision;
|
|
47
|
-
terminalJobs = new Set();
|
|
48
|
-
jobWaiters = new Map();
|
|
49
|
-
uncertain = false;
|
|
50
|
-
reportedError = false;
|
|
51
|
-
commits = new Map();
|
|
52
|
-
completedCallbacks = new Set();
|
|
53
|
-
// Keep drain answers deduplicated even after the lifetime callback ledger fills.
|
|
54
|
-
// The daemon limits each peer to 64 pending callbacks. A newer snapshot retires
|
|
55
|
-
// releases it no longer lists, and older snapshots cannot add them back.
|
|
56
|
-
completedReleases = new Set();
|
|
57
|
-
pausing;
|
|
58
|
-
disposing;
|
|
59
|
-
polling;
|
|
60
|
-
closed = false;
|
|
61
|
-
constructor(paths, identity, facts, options) {
|
|
62
|
-
this.paths = paths;
|
|
63
|
-
this.identity = identity;
|
|
64
|
-
this.facts = facts;
|
|
65
|
-
this.options = options;
|
|
66
|
-
}
|
|
67
|
-
setFacts(facts) {
|
|
68
|
-
const changed = !sameDiffReviewBinding(this.facts, facts);
|
|
69
|
-
for (const key of Object.keys(this.facts))
|
|
70
|
-
if (!Object.hasOwn(facts, key))
|
|
71
|
-
delete this.facts[key];
|
|
72
|
-
Object.assign(this.facts, facts);
|
|
73
|
-
this.diffReviewBinding = { ...facts };
|
|
74
|
-
if (changed)
|
|
75
|
-
this.retireDiffReviewIO();
|
|
76
|
-
}
|
|
77
|
-
/** Latest owner observation, or undefined if contact is unsupported or not observed. */
|
|
78
|
-
get contactState() {
|
|
79
|
-
return this.observedContact;
|
|
80
|
-
}
|
|
81
|
-
/** An uncertain attempt must not be retried or turned into a new attach. */
|
|
82
|
-
get contactResumeState() {
|
|
83
|
-
return this.resumeUncertain ? "uncertain" : this.resuming ? "running" : "idle";
|
|
84
|
-
}
|
|
85
|
-
/** Original submitted jobs must finish (or be reconciled) before repairing contact. */
|
|
86
|
-
get hasPendingWork() {
|
|
87
|
-
return this.pendingJobs.size > 0 || this.uncertain || this.foregroundRecovery !== undefined;
|
|
88
|
-
}
|
|
89
|
-
async attach(signal) {
|
|
90
|
-
if (this.closed ||
|
|
91
|
-
this.hasPendingWork ||
|
|
92
|
-
this.contactResumeState !== "idle" ||
|
|
93
|
-
this.admitting ||
|
|
94
|
-
this.pausing ||
|
|
95
|
-
this.disposing)
|
|
96
|
-
throw new Error("Daemon client is unavailable; reconnect after draining work.");
|
|
97
|
-
this.admitting = true;
|
|
98
|
-
this.diffReviewPaused = false;
|
|
99
|
-
this.diffReviewBinding = undefined;
|
|
100
|
-
this.retireDiffReviewIO();
|
|
101
|
-
this.lifecycleRevision++;
|
|
102
|
-
this.contactRevision++;
|
|
103
|
-
const facts = { ...this.facts };
|
|
104
|
-
const request = requestDaemon(this.paths, this.identity, "attach", facts, signal ? AbortSignal.any([signal, this.controller.signal]) : this.controller.signal, this.options.mergeReview ? { reviewDetails: 1 } : undefined);
|
|
105
|
-
// Poll during attach: stopping a previous controller may need release answers
|
|
106
|
-
// from this reattached participant before the attach response can complete.
|
|
107
|
-
this.polling ??= this.poll();
|
|
108
|
-
let admitted = false;
|
|
109
|
-
try {
|
|
110
|
-
const result = await request;
|
|
111
|
-
admitted = true;
|
|
112
|
-
if (this.closed || this.disposing)
|
|
113
|
-
throw new Error("Daemon client closed during attach.");
|
|
114
|
-
this.publishContact(this.consume(result));
|
|
115
|
-
this.observesState = record(result) && result.stateWait === 1;
|
|
116
|
-
this.stateRevision = undefined;
|
|
117
|
-
this.terminalJobs.clear();
|
|
118
|
-
this.attached = true;
|
|
119
|
-
this.diffReviewBinding = facts;
|
|
120
|
-
return this;
|
|
121
|
-
}
|
|
122
|
-
catch (error) {
|
|
123
|
-
return withCleanup(async () => {
|
|
124
|
-
throw error;
|
|
125
|
-
}, async () => {
|
|
126
|
-
try {
|
|
127
|
-
await this.dispose();
|
|
128
|
-
}
|
|
129
|
-
catch (cleanupError) {
|
|
130
|
-
if (!admitted &&
|
|
131
|
-
!this.attached &&
|
|
132
|
-
this.closed &&
|
|
133
|
-
!this.callbacks.size &&
|
|
134
|
-
!this.callbackTasks.size &&
|
|
135
|
-
!this.completedCallbacks.size &&
|
|
136
|
-
error instanceof DaemonError &&
|
|
137
|
-
error.remote.name === "DaemonStoppingError") {
|
|
138
|
-
// The fenced first attach owned no grants, and local tasks have drained.
|
|
139
|
-
// Keep its retry marker even if the owner closes the cleanup transport.
|
|
140
|
-
error.cause = cleanupError;
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
throw cleanupError;
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
finally {
|
|
148
|
-
this.admitting = false;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
async update(facts) {
|
|
152
|
-
const lifecycle = this.lifecycleRevision;
|
|
153
|
-
if (this.admitting || this.pausing || this.disposing)
|
|
154
|
-
throw new Error("Daemon client is changing; wait before updating facts.");
|
|
155
|
-
facts = structuredClone(facts);
|
|
156
|
-
const update = this.updates.then(async () => {
|
|
157
|
-
if (this.closed || this.uncertain || this.resumeUncertain || lifecycle !== this.lifecycleRevision)
|
|
158
|
-
throw new Error("Daemon client is unavailable; reconnect after draining work.");
|
|
159
|
-
const revision = this.contactRevision;
|
|
160
|
-
if (!this.diffReviewBinding || !sameDiffReviewBinding(this.diffReviewBinding, facts)) {
|
|
161
|
-
this.diffReviewBinding = undefined;
|
|
162
|
-
this.retireDiffReviewIO();
|
|
163
|
-
}
|
|
164
|
-
let result;
|
|
165
|
-
try {
|
|
166
|
-
result = await requestDaemon(this.paths, this.identity, "update", { facts }, this.controller.signal);
|
|
167
|
-
}
|
|
168
|
-
catch (error) {
|
|
169
|
-
if (this.attached &&
|
|
170
|
-
revision === this.contactRevision &&
|
|
171
|
-
this.sameClient(facts) &&
|
|
172
|
-
error instanceof DaemonError &&
|
|
173
|
-
error.remote.name === "ClientContactExpiredError")
|
|
174
|
-
this.publishContact("expired");
|
|
175
|
-
throw error;
|
|
176
|
-
}
|
|
177
|
-
if (this.closed)
|
|
178
|
-
throw new Error("Daemon client closed during update.");
|
|
179
|
-
if (revision !== this.contactRevision)
|
|
180
|
-
throw new Error("Daemon client changed during update.");
|
|
181
|
-
const contact = this.consume(result);
|
|
182
|
-
if (revision !== this.contactRevision)
|
|
183
|
-
throw new Error("Daemon client changed during update.");
|
|
184
|
-
this.setFacts(facts);
|
|
185
|
-
this.publishContact(contact);
|
|
186
|
-
});
|
|
187
|
-
this.updates = update.catch(() => { });
|
|
188
|
-
return update;
|
|
189
|
-
}
|
|
190
|
-
/** Resume this participant without replacing its callbacks, jobs, or polling. */
|
|
191
|
-
async resumeContact(facts, signal) {
|
|
192
|
-
signal?.throwIfAborted();
|
|
193
|
-
if (this.contactResumeState !== "idle")
|
|
194
|
-
throw new Error("Daemon contact resume is running or uncertain.");
|
|
195
|
-
const check = () => {
|
|
196
|
-
if (!this.attached || this.admitting || this.pausing || this.disposing || this.closed || this.hasPendingWork)
|
|
197
|
-
throw new Error("Daemon client is unavailable; reconnect after draining work.");
|
|
198
|
-
if (!this.sameClient(facts) || this.contactState !== "expired")
|
|
199
|
-
throw new Error("No confirmed contact expiry for this daemon client.");
|
|
200
|
-
};
|
|
201
|
-
facts = structuredClone(facts);
|
|
202
|
-
check();
|
|
203
|
-
const resume = new AbortController();
|
|
204
|
-
this.resuming = resume;
|
|
205
|
-
const ownedSignal = signal ? AbortSignal.any([signal, resume.signal]) : resume.signal;
|
|
206
|
-
let sent = false;
|
|
207
|
-
const attempt = this.updates.then(async () => {
|
|
208
|
-
ownedSignal.throwIfAborted();
|
|
209
|
-
check();
|
|
210
|
-
sent = true;
|
|
211
|
-
const reply = await requestDaemon(this.paths, this.identity, "resume-contact", facts, ownedSignal);
|
|
212
|
-
ownedSignal.throwIfAborted();
|
|
213
|
-
const contact = this.consume(reply);
|
|
214
|
-
ownedSignal.throwIfAborted();
|
|
215
|
-
if (contact !== "active")
|
|
216
|
-
throw new Error("Daemon did not confirm resumed contact.");
|
|
217
|
-
this.setFacts(facts);
|
|
218
|
-
this.publishContact(contact);
|
|
219
|
-
});
|
|
220
|
-
this.updates = attempt.catch(() => { });
|
|
221
|
-
// Reject a queued repair on cancellation even if the earlier update has not finished.
|
|
222
|
-
const cancellation = Promise.withResolvers();
|
|
223
|
-
const abort = () => cancellation.reject(ownedSignal.reason);
|
|
224
|
-
ownedSignal.addEventListener("abort", abort, { once: true });
|
|
225
|
-
try {
|
|
226
|
-
await Promise.race([attempt, cancellation.promise]);
|
|
227
|
-
}
|
|
228
|
-
catch (error) {
|
|
229
|
-
if (sent) {
|
|
230
|
-
// The protocol does not distinguish definite pre-publication refusal from a lost acknowledgement.
|
|
231
|
-
this.resumeUncertain = true;
|
|
232
|
-
for (const { controller, kind } of this.callbacks.values())
|
|
233
|
-
if (kind !== "queue-release")
|
|
234
|
-
controller.abort();
|
|
235
|
-
}
|
|
236
|
-
throw error;
|
|
237
|
-
}
|
|
238
|
-
finally {
|
|
239
|
-
this.resuming = undefined;
|
|
240
|
-
ownedSignal.removeEventListener("abort", abort);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
sameClient(facts) {
|
|
244
|
-
return facts.id === this.facts.id && facts.pid === this.facts.pid && facts.generation === this.facts.generation;
|
|
245
|
-
}
|
|
246
|
-
async run(operation, payload, signal, onCommit, onSubmit) {
|
|
247
|
-
if (this.closed ||
|
|
248
|
-
this.uncertain ||
|
|
249
|
-
this.foregroundRecovery ||
|
|
250
|
-
this.contactResumeState !== "idle" ||
|
|
251
|
-
this.pausing ||
|
|
252
|
-
this.disposing ||
|
|
253
|
-
this.contactState === "expired" ||
|
|
254
|
-
this.contactState === "inactive")
|
|
255
|
-
throw new Error("Daemon client is unavailable; confirm contact and drain work before submitting.");
|
|
256
|
-
signal?.throwIfAborted();
|
|
257
|
-
if (operation === "diff.review" && !this.hasConfirmedDiffReviewBinding())
|
|
258
|
-
throw new Error("The daemon file review session is unconfirmed. Update session facts or reload Pi.");
|
|
259
|
-
const { paths, identity } = this;
|
|
260
|
-
const id = `${operationPrefix(identity)}${randomUUID()}`;
|
|
261
|
-
const jobParams = { id, client: this.facts.id };
|
|
262
|
-
const transport = this.controller.signal;
|
|
263
|
-
const foreground = isForegroundDirection(operation);
|
|
264
|
-
const assertRoot = foreground ? canonicalRootGuard(paths.root) : undefined;
|
|
265
|
-
const generation = this.facts.generation;
|
|
266
|
-
let birth;
|
|
267
|
-
const rpc = async (method, params) => {
|
|
268
|
-
if (!foreground)
|
|
269
|
-
return requestDaemon(paths, identity, method, params, transport);
|
|
270
|
-
const timeout = method === "cancel" ? FOREGROUND_DRAIN_MS : FOREGROUND_RPC_MS;
|
|
271
|
-
const attempt = () => requestDaemon(paths, identity, method, params, AbortSignal.any([transport, AbortSignal.timeout(timeout)]));
|
|
272
|
-
try {
|
|
273
|
-
return await attempt();
|
|
274
|
-
}
|
|
275
|
-
catch (error) {
|
|
276
|
-
if (transport.aborted ||
|
|
277
|
-
error instanceof DaemonError ||
|
|
278
|
-
method === "cancel" ||
|
|
279
|
-
(method === "submit" && signal?.aborted))
|
|
280
|
-
throw error;
|
|
281
|
-
return attempt().catch((retryError) => {
|
|
282
|
-
if (method === "submit")
|
|
283
|
-
throw new AggregateError([error, retryError], FOREGROUND_UNKNOWN_RESULT);
|
|
284
|
-
throw retryError;
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
this.pendingJobs.add(id);
|
|
289
|
-
const abort = () => {
|
|
290
|
-
void requestDaemon(paths, identity, "cancel", jobParams, transport).catch(() => { });
|
|
291
|
-
};
|
|
292
|
-
let terminal = false;
|
|
293
|
-
const finish = (job) => {
|
|
294
|
-
terminal = true;
|
|
295
|
-
if (job.phase === "failed")
|
|
296
|
-
throw new DaemonError(job.error ?? { name: "Error", message: "Daemon operation failed." });
|
|
297
|
-
if (!foreground)
|
|
298
|
-
signal?.throwIfAborted();
|
|
299
|
-
if (operation === "diff.review") {
|
|
300
|
-
try {
|
|
301
|
-
return parseDiffReviewInventory(job.result);
|
|
302
|
-
}
|
|
303
|
-
catch (error) {
|
|
304
|
-
abort();
|
|
305
|
-
throw error;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
if (assertRoot && isForegroundQueueOutcome(job.result))
|
|
309
|
-
this.foregroundRecovery = {
|
|
310
|
-
job: id,
|
|
311
|
-
generation,
|
|
312
|
-
birth,
|
|
313
|
-
assertRoot,
|
|
314
|
-
};
|
|
315
|
-
return job.result;
|
|
316
|
-
};
|
|
317
|
-
if (onCommit)
|
|
318
|
-
this.commits.set(id, { notify: onCommit, signal });
|
|
319
|
-
signal?.addEventListener("abort", abort, { once: true });
|
|
320
|
-
if (signal?.aborted)
|
|
321
|
-
abort();
|
|
322
|
-
return withCleanup(async () => {
|
|
323
|
-
try {
|
|
324
|
-
onSubmit?.(id);
|
|
325
|
-
}
|
|
326
|
-
catch { }
|
|
327
|
-
if (foreground) {
|
|
328
|
-
birth = await readProcessBirth(identity.pid);
|
|
329
|
-
signal?.throwIfAborted();
|
|
330
|
-
transport.throwIfAborted();
|
|
331
|
-
assertRoot?.();
|
|
332
|
-
}
|
|
333
|
-
let lostSubmit = false;
|
|
334
|
-
try {
|
|
335
|
-
await rpc("submit", { ...jobParams, operation, payload });
|
|
336
|
-
}
|
|
337
|
-
catch (error) {
|
|
338
|
-
if (!foreground || error instanceof DaemonError || transport.aborted)
|
|
339
|
-
throw error;
|
|
340
|
-
lostSubmit = true;
|
|
341
|
-
}
|
|
342
|
-
let terminalObserved = this.observesState && !lostSubmit;
|
|
343
|
-
if (terminalObserved && !this.terminalJobs.has(id)) {
|
|
344
|
-
const completion = Promise.withResolvers();
|
|
345
|
-
this.jobWaiters.set(id, completion);
|
|
346
|
-
const keepAlive = setInterval(() => { }, 30_000);
|
|
347
|
-
try {
|
|
348
|
-
terminalObserved = (await completion.promise) === "terminal";
|
|
349
|
-
}
|
|
350
|
-
finally {
|
|
351
|
-
this.jobWaiters.delete(id);
|
|
352
|
-
clearInterval(keepAlive);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
while (!this.closed) {
|
|
356
|
-
let reply;
|
|
357
|
-
try {
|
|
358
|
-
reply = await rpc("poll", { client: jobParams.client, cursor: this.cursor, job: id });
|
|
359
|
-
}
|
|
360
|
-
catch (error) {
|
|
361
|
-
if (foreground && !transport.aborted) {
|
|
362
|
-
const drained = await rpc("cancel", jobParams).catch(() => undefined);
|
|
363
|
-
const job = drained;
|
|
364
|
-
if (job?.id === id && (job.phase === "done" || job.phase === "failed"))
|
|
365
|
-
return finish(job);
|
|
366
|
-
this.markWorkUncertain();
|
|
367
|
-
throw new Error(FOREGROUND_UNKNOWN_RESULT, { cause: error });
|
|
368
|
-
}
|
|
369
|
-
if (error instanceof DaemonError && error.message === UNKNOWN_JOB_RESULT)
|
|
370
|
-
this.markWorkUncertain();
|
|
371
|
-
throw error;
|
|
372
|
-
}
|
|
373
|
-
const job = record(reply) ? reply.job : undefined;
|
|
374
|
-
const missing = terminalObserved && (job?.id !== id || (job.phase !== "done" && job.phase !== "failed"));
|
|
375
|
-
if (missing)
|
|
376
|
-
this.markWorkUncertain();
|
|
377
|
-
this.consume(reply);
|
|
378
|
-
if (missing)
|
|
379
|
-
throw new Error(foreground ? FOREGROUND_UNKNOWN_RESULT : UNKNOWN_JOB_RESULT);
|
|
380
|
-
if (job?.id === id && (job.phase === "done" || job.phase === "failed"))
|
|
381
|
-
return finish(job);
|
|
382
|
-
await this.wait(25, true);
|
|
383
|
-
}
|
|
384
|
-
throw new Error("Daemon client closed before operation completed.");
|
|
385
|
-
}, async () => {
|
|
386
|
-
signal?.removeEventListener("abort", abort);
|
|
387
|
-
this.commits.delete(id);
|
|
388
|
-
if (!terminal && !this.closed) {
|
|
389
|
-
for (const callback of this.callbacks.values())
|
|
390
|
-
if (callback.job === id && !callback.kind.startsWith("queue-"))
|
|
391
|
-
callback.controller.abort();
|
|
392
|
-
try {
|
|
393
|
-
if (foreground) {
|
|
394
|
-
if (!this.uncertain)
|
|
395
|
-
await rpc("cancel", jobParams);
|
|
396
|
-
}
|
|
397
|
-
else
|
|
398
|
-
await requestDaemon(paths, identity, "cancel", jobParams);
|
|
399
|
-
}
|
|
400
|
-
catch (error) {
|
|
401
|
-
this.markWorkUncertain();
|
|
402
|
-
throw new Error(foreground
|
|
403
|
-
? FOREGROUND_UNKNOWN_RESULT
|
|
404
|
-
: "Operation outcome is uncertain; reload to reconnect and reconcile, never replay the write.", { cause: error });
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
})
|
|
408
|
-
.catch((error) => {
|
|
409
|
-
if (operation !== "diff.review")
|
|
410
|
-
throw error;
|
|
411
|
-
if (error instanceof DaemonError && error.remote.properties?.code === OWNERSHIP_CLEANUP_REQUIRED) {
|
|
412
|
-
throw new DaemonError({
|
|
413
|
-
name: "Error",
|
|
414
|
-
message: "Daemon ownership cleanup must be confirmed before opening a file review.",
|
|
415
|
-
properties: { code: OWNERSHIP_CLEANUP_REQUIRED },
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
if (this.uncertain)
|
|
419
|
-
throw new Error("The daemon diff review outcome is uncertain. Reload Pi to reconnect before opening a review.");
|
|
420
|
-
signal?.throwIfAborted();
|
|
421
|
-
if (error instanceof DaemonError && error.message === "Unsupported engine operation.")
|
|
422
|
-
throw new DaemonError({ name: "Error", message: "Unsupported engine operation." });
|
|
423
|
-
throw new Error("Could not open the daemon diff review. Check the connection and try again.");
|
|
424
|
-
})
|
|
425
|
-
.finally(() => {
|
|
426
|
-
this.pendingJobs.delete(id);
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
retireDiffReviewIO() {
|
|
430
|
-
const io = this.diffReviewIO;
|
|
431
|
-
this.diffReviewIO = undefined;
|
|
432
|
-
io?.abort();
|
|
433
|
-
}
|
|
434
|
-
hasConfirmedDiffReviewBinding() {
|
|
435
|
-
return this.diffReviewBinding !== undefined && sameDiffReviewBinding(this.diffReviewBinding, this.facts);
|
|
436
|
-
}
|
|
437
|
-
canReadDiffReview() {
|
|
438
|
-
return (this.attached &&
|
|
439
|
-
!this.admitting &&
|
|
440
|
-
!this.closed &&
|
|
441
|
-
!this.pausing &&
|
|
442
|
-
!this.diffReviewPaused &&
|
|
443
|
-
this.hasConfirmedDiffReviewBinding() &&
|
|
444
|
-
!this.disposing &&
|
|
445
|
-
!this.uncertain &&
|
|
446
|
-
this.contactResumeState === "idle" &&
|
|
447
|
-
this.contactState !== "expired" &&
|
|
448
|
-
this.contactState !== "inactive" &&
|
|
449
|
-
this.facts.mode === "tui" &&
|
|
450
|
-
this.facts.hasUI);
|
|
451
|
-
}
|
|
452
|
-
async diffReviewRequest(method, id, fileId, signal, stale, decode) {
|
|
453
|
-
signal?.throwIfAborted();
|
|
454
|
-
if (!isDiffReviewId(id) || (method === "diff-review-read" && !isDiffReviewId(fileId)))
|
|
455
|
-
throw new Error("Invalid diff review identity.");
|
|
456
|
-
if (!this.canReadDiffReview())
|
|
457
|
-
return stale;
|
|
458
|
-
const binding = { ...this.facts };
|
|
459
|
-
this.diffReviewIO ??= new AbortController();
|
|
460
|
-
const io = this.diffReviewIO;
|
|
461
|
-
const current = () => this.diffReviewIO === io && this.canReadDiffReview() && sameDiffReviewBinding(binding, this.facts);
|
|
462
|
-
const owned = AbortSignal.any([
|
|
463
|
-
this.controller.signal,
|
|
464
|
-
io.signal,
|
|
465
|
-
AbortSignal.timeout(DIFF_REVIEW_REQUEST_MS),
|
|
466
|
-
...(signal ? [signal] : []),
|
|
467
|
-
]);
|
|
468
|
-
let reply;
|
|
469
|
-
try {
|
|
470
|
-
reply = await requestDaemon(this.paths, this.identity, method, { client: binding.id, generation: binding.generation, id, fileId }, owned);
|
|
471
|
-
owned.throwIfAborted();
|
|
472
|
-
}
|
|
473
|
-
catch {
|
|
474
|
-
signal?.throwIfAborted();
|
|
475
|
-
if (!current())
|
|
476
|
-
return stale;
|
|
477
|
-
throw new Error("Daemon file review request failed. Try again or reopen the review.");
|
|
478
|
-
}
|
|
479
|
-
return current() ? decode(reply) : stale;
|
|
480
|
-
}
|
|
481
|
-
readDiffReview(id, fileId, signal) {
|
|
482
|
-
return this.diffReviewRequest("diff-review-read", id, fileId, signal, { kind: "stale" }, readDiffReviewPreview);
|
|
483
|
-
}
|
|
484
|
-
closeDiffReview(id, signal) {
|
|
485
|
-
return this.diffReviewRequest("diff-review-close", id, undefined, signal, undefined, (reply) => {
|
|
486
|
-
if (reply !== true)
|
|
487
|
-
throw new Error("Invalid daemon diff review release acknowledgement.");
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
canRecoverForeground(job) {
|
|
491
|
-
return !this.foregroundRecovery?.attempted && this.ownsForegroundRecovery(job);
|
|
492
|
-
}
|
|
493
|
-
ownsForegroundRecovery(job) {
|
|
494
|
-
const target = this.foregroundRecovery;
|
|
495
|
-
return (!!target &&
|
|
496
|
-
target.job === job &&
|
|
497
|
-
target.generation === this.facts.generation &&
|
|
498
|
-
this.attached &&
|
|
499
|
-
!this.closed &&
|
|
500
|
-
!this.admitting &&
|
|
501
|
-
!this.disposing &&
|
|
502
|
-
!this.pausing &&
|
|
503
|
-
this.pendingJobs.size === 0 &&
|
|
504
|
-
!this.uncertain &&
|
|
505
|
-
this.contactResumeState === "idle");
|
|
506
|
-
}
|
|
507
|
-
async recoverForeground(job, signal) {
|
|
508
|
-
signal.throwIfAborted();
|
|
509
|
-
const target = this.foregroundRecovery;
|
|
510
|
-
if (!target || !this.canRecoverForeground(job))
|
|
511
|
-
throw new Error("The current Pi session could not verify a completed transfer for daemon recovery.");
|
|
512
|
-
target.assertRoot();
|
|
513
|
-
target.attempted = true;
|
|
514
|
-
const facts = { ...this.facts };
|
|
515
|
-
const lifecycle = this.lifecycleRevision;
|
|
516
|
-
const owned = AbortSignal.any([signal, this.controller.signal, AbortSignal.timeout(FOREGROUND_RECOVERY_MS)]);
|
|
517
|
-
const { stopDaemonAfterForegroundQueueFailure } = await import("./daemon-recovery.js");
|
|
518
|
-
owned.throwIfAborted();
|
|
519
|
-
if (lifecycle !== this.lifecycleRevision ||
|
|
520
|
-
!sameDiffReviewBinding(facts, this.facts) ||
|
|
521
|
-
this.foregroundRecovery !== target ||
|
|
522
|
-
!this.ownsForegroundRecovery(job))
|
|
523
|
-
throw new Error("The current Pi session could not verify a completed transfer for daemon recovery.");
|
|
524
|
-
target.assertRoot();
|
|
525
|
-
await stopDaemonAfterForegroundQueueFailure(this.paths, this.identity, { ...target, client: facts.id }, owned);
|
|
526
|
-
await this.closeLocal();
|
|
527
|
-
target.assertRoot();
|
|
528
|
-
}
|
|
529
|
-
markWorkUncertain() {
|
|
530
|
-
this.uncertain = true;
|
|
531
|
-
this.retireDiffReviewIO();
|
|
532
|
-
for (const callback of this.callbacks.values())
|
|
533
|
-
if (callback.kind !== "queue-release")
|
|
534
|
-
callback.controller.abort();
|
|
535
|
-
}
|
|
536
|
-
publishContact(contact) {
|
|
537
|
-
this.contactRevision++;
|
|
538
|
-
this.observedContact = contact;
|
|
539
|
-
if (contact === "expired" || contact === "inactive")
|
|
540
|
-
this.retireDiffReviewIO();
|
|
541
|
-
}
|
|
542
|
-
consume(reply) {
|
|
543
|
-
if (!record(reply) ||
|
|
544
|
-
typeof reply.cursor !== "number" ||
|
|
545
|
-
!Number.isSafeInteger(reply.cursor) ||
|
|
546
|
-
reply.cursor < 0 ||
|
|
547
|
-
!Array.isArray(reply.callbacks) ||
|
|
548
|
-
!Array.isArray(reply.events))
|
|
549
|
-
throw new Error("Invalid daemon poll response.");
|
|
550
|
-
const { contact } = reply;
|
|
551
|
-
if (contact !== undefined && contact !== "active" && contact !== "expired" && contact !== "inactive")
|
|
552
|
-
throw new Error("Invalid daemon contact state.");
|
|
553
|
-
if (reply.cursor < this.cursor)
|
|
554
|
-
return contact;
|
|
555
|
-
for (const event of reply.events)
|
|
556
|
-
if (event.id > this.cursor) {
|
|
557
|
-
if (event.kind === "commit" && record(event.payload) && typeof event.payload.job === "string") {
|
|
558
|
-
const current = this.commits.get(event.payload.job);
|
|
559
|
-
this.commits.delete(event.payload.job);
|
|
560
|
-
if (current && !current.signal?.aborted)
|
|
561
|
-
current.notify();
|
|
562
|
-
}
|
|
563
|
-
this.options.event?.(event);
|
|
564
|
-
}
|
|
565
|
-
const latest = reply.cursor >= this.cursor;
|
|
566
|
-
const present = new Set(reply.callbacks.map((callback) => callback.id));
|
|
567
|
-
if (reply.cursor > this.cursor) {
|
|
568
|
-
for (const id of this.completedReleases)
|
|
569
|
-
if (!present.has(id))
|
|
570
|
-
this.completedReleases.delete(id);
|
|
571
|
-
this.cursor = reply.cursor;
|
|
572
|
-
}
|
|
573
|
-
for (const [id, pending] of this.callbacks) {
|
|
574
|
-
if (pending.releaseCursor !== undefined) {
|
|
575
|
-
// A job poll and the background poll can arrive out of order.
|
|
576
|
-
if (!latest || reply.cursor <= pending.releaseCursor)
|
|
577
|
-
continue;
|
|
578
|
-
if (present.has(id)) {
|
|
579
|
-
pending.releaseCursor = reply.cursor;
|
|
580
|
-
continue;
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
else if (present.has(id))
|
|
584
|
-
continue;
|
|
585
|
-
pending.controller.abort(new DOMException("Callback is no longer current", "AbortError"));
|
|
586
|
-
}
|
|
587
|
-
for (const callback of reply.callbacks) {
|
|
588
|
-
if (this.callbacks.has(callback.id) || this.completedCallbacks.has(callback.id))
|
|
589
|
-
continue;
|
|
590
|
-
const release = callback.kind === "queue-release";
|
|
591
|
-
if (release && (!latest || this.completedReleases.has(callback.id)))
|
|
592
|
-
continue;
|
|
593
|
-
if (this.completedCallbacks.size + this.callbacks.size >= MAX_COMPLETED_CALLBACKS)
|
|
594
|
-
this.uncertain = true;
|
|
595
|
-
const controller = new AbortController();
|
|
596
|
-
const foreground = this.pendingJobs.has(callback.job);
|
|
597
|
-
const reviewOwner = callback.review?.offer !== undefined
|
|
598
|
-
? { facts: { ...this.facts }, lifecycle: this.lifecycleRevision }
|
|
599
|
-
: undefined;
|
|
600
|
-
this.callbacks.set(callback.id, {
|
|
601
|
-
controller,
|
|
602
|
-
kind: callback.kind,
|
|
603
|
-
job: callback.job,
|
|
604
|
-
...(release && { releaseCursor: reply.cursor }),
|
|
605
|
-
});
|
|
606
|
-
const task = (async () => {
|
|
607
|
-
let value;
|
|
608
|
-
let failed = false;
|
|
609
|
-
try {
|
|
610
|
-
if ((this.uncertain || this.resumeUncertain) && callback.kind !== "queue-release")
|
|
611
|
-
throw new Error("Client is draining uncertain work.");
|
|
612
|
-
value = await (reviewOwner
|
|
613
|
-
? this.performExactReview(callback, controller.signal, reviewOwner)
|
|
614
|
-
: this.performCallback(callback, controller.signal));
|
|
615
|
-
}
|
|
616
|
-
catch {
|
|
617
|
-
failed = true;
|
|
618
|
-
}
|
|
619
|
-
if (release) {
|
|
620
|
-
if (!failed && value === true) {
|
|
621
|
-
await this.deliverRelease(callback, foreground, controller.signal);
|
|
622
|
-
return;
|
|
623
|
-
}
|
|
624
|
-
failed = true;
|
|
625
|
-
}
|
|
626
|
-
try {
|
|
627
|
-
await requestDaemon(this.paths, this.identity, "answer", {
|
|
628
|
-
client: reviewOwner?.facts.id ?? this.facts.id,
|
|
629
|
-
id: callback.id,
|
|
630
|
-
...(reviewOwner ? { generation: reviewOwner.facts.generation } : {}),
|
|
631
|
-
...(failed || (reviewOwner && !this.ownsExactReview(callback, controller.signal, reviewOwner))
|
|
632
|
-
? { error: "Client callback cancelled or failed." }
|
|
633
|
-
: { value }),
|
|
634
|
-
}, this.callbackIO.signal);
|
|
635
|
-
}
|
|
636
|
-
finally {
|
|
637
|
-
if (release)
|
|
638
|
-
this.reportRelease(callback, foreground, "unconfirmed");
|
|
639
|
-
}
|
|
640
|
-
})()
|
|
641
|
-
.catch((error) => {
|
|
642
|
-
if (!this.closed && !controller.signal.aborted)
|
|
643
|
-
this.reportError(error);
|
|
644
|
-
})
|
|
645
|
-
.finally(() => {
|
|
646
|
-
if (this.completedCallbacks.size < MAX_COMPLETED_CALLBACKS)
|
|
647
|
-
this.completedCallbacks.add(callback.id);
|
|
648
|
-
else if (release && !controller.signal.aborted)
|
|
649
|
-
this.completedReleases.add(callback.id);
|
|
650
|
-
this.callbacks.delete(callback.id);
|
|
651
|
-
this.callbackTasks.delete(task);
|
|
652
|
-
});
|
|
653
|
-
this.callbackTasks.add(task);
|
|
654
|
-
}
|
|
655
|
-
return contact;
|
|
656
|
-
}
|
|
657
|
-
reportRelease(callback, foreground, state) {
|
|
658
|
-
if (this.callbackIO.signal.aborted)
|
|
659
|
-
return;
|
|
660
|
-
try {
|
|
661
|
-
this.options.queueRelease?.({ id: callback.id, job: callback.job, foreground, state });
|
|
662
|
-
}
|
|
663
|
-
catch {
|
|
664
|
-
// Presentation must not own a queue or a callback task.
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
async deliverRelease(callback, foreground, pending) {
|
|
668
|
-
const signal = AbortSignal.any([pending, this.callbackIO.signal]);
|
|
669
|
-
const deadline = performance.now() + RELEASE_BUDGET_MS;
|
|
670
|
-
let retrying = false;
|
|
671
|
-
let state = "unconfirmed";
|
|
672
|
-
try {
|
|
673
|
-
for (let attempt = 0; attempt < RELEASE_MAX_ATTEMPTS; attempt++) {
|
|
674
|
-
const remaining = Math.floor(deadline - performance.now());
|
|
675
|
-
if (remaining <= 0 || signal.aborted)
|
|
676
|
-
break;
|
|
677
|
-
const controller = new AbortController();
|
|
678
|
-
const timer = setTimeout(() => controller.abort(), Math.min(remaining, RELEASE_ATTEMPT_MS));
|
|
679
|
-
timer.unref?.();
|
|
680
|
-
try {
|
|
681
|
-
await requestDaemon(this.paths, this.identity, "answer", { client: this.facts.id, id: callback.id, value: true }, AbortSignal.any([signal, controller.signal]));
|
|
682
|
-
state = "finished";
|
|
683
|
-
return;
|
|
684
|
-
}
|
|
685
|
-
catch (error) {
|
|
686
|
-
if (signal.aborted)
|
|
687
|
-
break;
|
|
688
|
-
if (error instanceof DaemonError) {
|
|
689
|
-
// The v1 server uses this reply for absent as well as foreign callbacks.
|
|
690
|
-
// Do not infer whether the original release succeeded.
|
|
691
|
-
if (error.message === "Stale or foreign callback response.")
|
|
692
|
-
state = "finished";
|
|
693
|
-
return;
|
|
694
|
-
}
|
|
695
|
-
if (!controller.signal.aborted &&
|
|
696
|
-
(!(error instanceof Error) || !TRANSIENT_RELEASE_ERRORS.has(error.code ?? "")))
|
|
697
|
-
return;
|
|
698
|
-
}
|
|
699
|
-
finally {
|
|
700
|
-
clearTimeout(timer);
|
|
701
|
-
}
|
|
702
|
-
if (!retrying) {
|
|
703
|
-
retrying = true;
|
|
704
|
-
this.reportRelease(callback, foreground, "retrying");
|
|
705
|
-
}
|
|
706
|
-
const wait = Math.min(100 * 2 ** attempt, 2_000, deadline - performance.now());
|
|
707
|
-
if (wait <= 0 || attempt + 1 >= RELEASE_MAX_ATTEMPTS)
|
|
708
|
-
break;
|
|
709
|
-
await delay(wait, undefined, { signal, ref: false }).catch(() => { });
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
finally {
|
|
713
|
-
if (pending.aborted && !this.callbackIO.signal.aborted)
|
|
714
|
-
state = "finished";
|
|
715
|
-
if (retrying || state === "unconfirmed")
|
|
716
|
-
this.reportRelease(callback, foreground, state);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
ownsExactReview(callback, signal, owner) {
|
|
720
|
-
return (!signal.aborted &&
|
|
721
|
-
!this.callbackIO.signal.aborted &&
|
|
722
|
-
owner.lifecycle === this.lifecycleRevision &&
|
|
723
|
-
!this.closed &&
|
|
724
|
-
!this.pausing &&
|
|
725
|
-
!this.disposing &&
|
|
726
|
-
!this.uncertain &&
|
|
727
|
-
this.contactResumeState === "idle" &&
|
|
728
|
-
this.contactState !== "expired" &&
|
|
729
|
-
this.contactState !== "inactive" &&
|
|
730
|
-
this.callbacks.get(callback.id)?.controller.signal === signal &&
|
|
731
|
-
sameDiffReviewBinding(owner.facts, this.facts));
|
|
732
|
-
}
|
|
733
|
-
async performExactReview(callback, signal, owner) {
|
|
734
|
-
const present = this.options.mergeReview;
|
|
735
|
-
if (!present)
|
|
736
|
-
throw new Error("Exact review offer requires an opted-in presenter.");
|
|
737
|
-
const owned = AbortSignal.any([signal, this.callbackIO.signal]);
|
|
738
|
-
const requireCurrent = () => {
|
|
739
|
-
owned.throwIfAborted();
|
|
740
|
-
if (!this.ownsExactReview(callback, signal, owner))
|
|
741
|
-
throw new Error("Exact review participant changed.");
|
|
742
|
-
};
|
|
743
|
-
owned.throwIfAborted();
|
|
744
|
-
const { presentPagedReview, reviewScope } = await import("./paged-review.js");
|
|
745
|
-
requireCurrent();
|
|
746
|
-
return presentPagedReview(reviewScope(this.identity, owner.facts, callback), callback, owned, present, (params, pageSignal) => {
|
|
747
|
-
requireCurrent();
|
|
748
|
-
return requestDaemon(this.paths, this.identity, "review-page", params, pageSignal);
|
|
749
|
-
});
|
|
750
|
-
}
|
|
751
|
-
async performCallback(callback, signal) {
|
|
752
|
-
const reference = callback.review;
|
|
753
|
-
if (!reference)
|
|
754
|
-
return this.options.callback(callback, signal);
|
|
755
|
-
if (callback.kind !== "merge-review" ||
|
|
756
|
-
!record(callback.payload) ||
|
|
757
|
-
!Number.isSafeInteger(reference.pages) ||
|
|
758
|
-
reference.pages < 1 ||
|
|
759
|
-
reference.pages > Math.ceil(MAX_REVIEW_BYTES / REVIEW_PAGE_CHARS) ||
|
|
760
|
-
!Number.isSafeInteger(reference.bytes) ||
|
|
761
|
-
reference.bytes > MAX_REVIEW_BYTES ||
|
|
762
|
-
reference.bytes < 1 ||
|
|
763
|
-
!/^[a-f0-9]{64}$/u.test(reference.sha256))
|
|
764
|
-
throw new Error("Invalid exact-review reference.");
|
|
765
|
-
const ownedSignal = AbortSignal.any([signal, this.callbackIO.signal]);
|
|
766
|
-
const pages = [];
|
|
767
|
-
for (let index = 0; index < reference.pages; index++) {
|
|
768
|
-
ownedSignal.throwIfAborted();
|
|
769
|
-
const page = await requestDaemon(this.paths, this.identity, "review-page", { client: this.facts.id, id: callback.id, index }, ownedSignal);
|
|
770
|
-
ownedSignal.throwIfAborted();
|
|
771
|
-
if (!record(page) ||
|
|
772
|
-
page.id !== callback.id ||
|
|
773
|
-
page.index !== index ||
|
|
774
|
-
typeof page.content !== "string" ||
|
|
775
|
-
page.content.length > REVIEW_PAGE_CHARS)
|
|
776
|
-
throw new Error("Invalid exact-review page.");
|
|
777
|
-
pages.push(page.content);
|
|
778
|
-
}
|
|
779
|
-
const content = pages.join("");
|
|
780
|
-
if (Buffer.byteLength(content) !== reference.bytes ||
|
|
781
|
-
createHash("sha256").update(content).digest("hex") !== reference.sha256)
|
|
782
|
-
throw new Error("Exact-review contents changed; approval was refused.");
|
|
783
|
-
ownedSignal.throwIfAborted();
|
|
784
|
-
return this.options.callback({ ...callback, review: undefined, payload: { ...callback.payload, content } }, signal);
|
|
785
|
-
}
|
|
786
|
-
async wait(ms, keepAlive = false) {
|
|
787
|
-
const signal = this.controller.signal;
|
|
788
|
-
signal.throwIfAborted();
|
|
789
|
-
await new Promise((resolve, reject) => {
|
|
790
|
-
const timer = setTimeout(done, ms);
|
|
791
|
-
if (!keepAlive)
|
|
792
|
-
timer.unref?.();
|
|
793
|
-
const abort = () => {
|
|
794
|
-
clearTimeout(timer);
|
|
795
|
-
signal.removeEventListener("abort", abort);
|
|
796
|
-
reject(signal.reason);
|
|
797
|
-
};
|
|
798
|
-
function done() {
|
|
799
|
-
signal.removeEventListener("abort", abort);
|
|
800
|
-
resolve();
|
|
801
|
-
}
|
|
802
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
reportError(error) {
|
|
806
|
-
if (this.reportedError)
|
|
807
|
-
return;
|
|
808
|
-
this.reportedError = true;
|
|
809
|
-
try {
|
|
810
|
-
this.options.error?.(error);
|
|
811
|
-
}
|
|
812
|
-
catch {
|
|
813
|
-
/* Error presentation must not own a task. */
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
async observeState() {
|
|
817
|
-
const jobs = stateWaitJobs(this.jobWaiters);
|
|
818
|
-
const reply = await requestDaemon(this.paths, this.identity, "state-wait", {
|
|
819
|
-
client: this.facts.id,
|
|
820
|
-
generation: this.facts.generation,
|
|
821
|
-
cursor: this.cursor,
|
|
822
|
-
revision: this.stateRevision,
|
|
823
|
-
jobs,
|
|
824
|
-
}, this.controller.signal, { onSocket: (socket) => socket.unref() });
|
|
825
|
-
return stateWaitResult(reply);
|
|
826
|
-
}
|
|
827
|
-
async poll() {
|
|
828
|
-
await withCleanup(() => this.pollUntilClosed(), async () => {
|
|
829
|
-
for (const waiter of this.jobWaiters.values())
|
|
830
|
-
waiter.reject(this.controller.signal.reason ?? new Error("Daemon client closed."));
|
|
831
|
-
});
|
|
832
|
-
}
|
|
833
|
-
async pollUntilClosed() {
|
|
834
|
-
let failures = 0;
|
|
835
|
-
while (!this.closed) {
|
|
836
|
-
try {
|
|
837
|
-
const revision = this.contactRevision;
|
|
838
|
-
const state = this.observesState && !this.admitting ? await this.observeState() : undefined;
|
|
839
|
-
const reply = state?.reply ??
|
|
840
|
-
(await requestDaemon(this.paths, this.identity, "poll", { client: this.facts.id, cursor: this.cursor }, this.controller.signal));
|
|
841
|
-
// An older poll must not undo typed update expiry or a successful resume.
|
|
842
|
-
if (revision === this.contactRevision) {
|
|
843
|
-
if (state?.missing.some((id) => this.jobWaiters.has(id)))
|
|
844
|
-
this.markWorkUncertain();
|
|
845
|
-
const contact = this.consume(reply);
|
|
846
|
-
if (state) {
|
|
847
|
-
this.stateRevision = state.version;
|
|
848
|
-
this.terminalJobs = new Set(state.finished);
|
|
849
|
-
for (const id of state.missing)
|
|
850
|
-
this.jobWaiters.get(id)?.reject(new Error(UNKNOWN_JOB_RESULT));
|
|
851
|
-
for (const id of state.finished)
|
|
852
|
-
this.jobWaiters.get(id)?.resolve("terminal");
|
|
853
|
-
}
|
|
854
|
-
this.reportedError = false;
|
|
855
|
-
if (revision === this.contactRevision &&
|
|
856
|
-
this.attached &&
|
|
857
|
-
!this.admitting &&
|
|
858
|
-
!this.pausing &&
|
|
859
|
-
!this.disposing &&
|
|
860
|
-
!this.closed) {
|
|
861
|
-
// A new observation fences older facts replies; identical polls do not.
|
|
862
|
-
if (contact !== this.observedContact)
|
|
863
|
-
this.publishContact(contact);
|
|
864
|
-
if (contact !== undefined)
|
|
865
|
-
this.options.contact?.(contact);
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
failures = 0;
|
|
869
|
-
if (!state)
|
|
870
|
-
await this.wait(100);
|
|
871
|
-
}
|
|
872
|
-
catch (error) {
|
|
873
|
-
if (this.closed)
|
|
874
|
-
return;
|
|
875
|
-
if (++failures >= STATE_WAIT_FAILURE_LIMIT)
|
|
876
|
-
for (const waiter of this.jobWaiters.values())
|
|
877
|
-
waiter.resolve("poll");
|
|
878
|
-
if (this.attached)
|
|
879
|
-
this.reportError(error);
|
|
880
|
-
try {
|
|
881
|
-
await this.wait(100);
|
|
882
|
-
}
|
|
883
|
-
catch {
|
|
884
|
-
return;
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
async pause() {
|
|
890
|
-
if (this.closed || this.disposing)
|
|
891
|
-
throw new Error("Daemon client is closed.");
|
|
892
|
-
if (this.pausing)
|
|
893
|
-
return this.pausing;
|
|
894
|
-
this.resuming?.abort(new DOMException("Client paused", "AbortError"));
|
|
895
|
-
this.retireDiffReviewIO();
|
|
896
|
-
this.lifecycleRevision++;
|
|
897
|
-
this.contactRevision++;
|
|
898
|
-
this.pausing = (async () => {
|
|
899
|
-
const reply = await requestDaemon(this.paths, this.identity, "pause", { client: this.facts.id });
|
|
900
|
-
if (this.closed || this.disposing)
|
|
901
|
-
return;
|
|
902
|
-
const contact = this.consume(reply);
|
|
903
|
-
this.diffReviewPaused = true;
|
|
904
|
-
if (!this.disposing)
|
|
905
|
-
this.publishContact(contact);
|
|
906
|
-
})().finally(() => {
|
|
907
|
-
this.pausing = undefined;
|
|
908
|
-
});
|
|
909
|
-
return this.pausing;
|
|
910
|
-
}
|
|
911
|
-
async dispose(handoff) {
|
|
912
|
-
if (this.disposing)
|
|
913
|
-
return this.disposing;
|
|
914
|
-
if (this.closed)
|
|
915
|
-
return;
|
|
916
|
-
this.resuming?.abort(new DOMException("Client disposed", "AbortError"));
|
|
917
|
-
this.retireDiffReviewIO();
|
|
918
|
-
this.lifecycleRevision++;
|
|
919
|
-
this.contactRevision++;
|
|
920
|
-
this.disposing = (async () => {
|
|
921
|
-
this.polling ??= this.poll();
|
|
922
|
-
// Cancel UI before drain, but keep polling for acknowledged queue-release callbacks.
|
|
923
|
-
for (const { controller, kind } of this.callbacks.values())
|
|
924
|
-
if (!kind.startsWith("queue-"))
|
|
925
|
-
controller.abort();
|
|
926
|
-
try {
|
|
927
|
-
const reply = await requestDaemon(this.paths, this.identity, handoff ? "handoff" : "detach", {
|
|
928
|
-
client: this.facts.id,
|
|
929
|
-
generation: this.facts.generation,
|
|
930
|
-
pid: this.facts.pid,
|
|
931
|
-
handoff,
|
|
932
|
-
});
|
|
933
|
-
this.consume(reply);
|
|
934
|
-
}
|
|
935
|
-
finally {
|
|
936
|
-
await this.closeLocal();
|
|
937
|
-
}
|
|
938
|
-
})();
|
|
939
|
-
return this.disposing;
|
|
940
|
-
}
|
|
941
|
-
async closeLocal() {
|
|
942
|
-
this.closed = true;
|
|
943
|
-
this.retireDiffReviewIO();
|
|
944
|
-
this.controller.abort(new DOMException("Client disposed", "AbortError"));
|
|
945
|
-
this.callbackIO.abort(new DOMException("Client callback transport disposed", "AbortError"));
|
|
946
|
-
for (const { controller } of this.callbacks.values())
|
|
947
|
-
controller.abort();
|
|
948
|
-
await Promise.allSettled([this.polling, this.updates, ...this.callbackTasks]);
|
|
949
|
-
}
|
|
950
|
-
}
|