fuli-context 0.27.0 → 0.27.2
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/dist/web/assets/{AboutPage-Bp2Edkdg.js → AboutPage-Bgcf03U0.js} +1 -1
- package/dist/web/assets/{AboutSectionHeading-DFfY2f_Z.js → AboutSectionHeading-BaQBY_Xs.js} +1 -1
- package/dist/web/assets/AgentAppsPage-DNuujLT2.js +1 -0
- package/dist/web/assets/{AgentAvatar-w-2A3nsJ.js → AgentAvatar-DGXedNUs.js} +1 -1
- package/dist/web/assets/{AgentHand-BGGU49Jt.js → AgentHand-BwE2VGth.js} +1 -1
- package/dist/web/assets/AgentManagement-2r8DUS1N.js +7 -0
- package/dist/web/assets/AgentManagement-hRkMpjvY.css +1 -0
- package/dist/web/assets/{AgentMentionCopy-BAHZjubz.js → AgentMentionCopy-y3JD1Cef.js} +1 -1
- package/dist/web/assets/{AgentName-CXlsC-4o.js → AgentName-XrBcHq4R.js} +1 -1
- package/dist/web/assets/AgentProfilePage-DE7z980p.js +5 -0
- package/dist/web/assets/AgentServicesPage-CWfGSxcb.js +1 -0
- package/dist/web/assets/{AppViewerPage-6gWP6nAf.js → AppViewerPage-BaKMk9pp.js} +1 -1
- package/dist/web/assets/{BackToTop-Cs5_rV99.js → BackToTop-DITd9y7X.js} +1 -1
- package/dist/web/assets/{BoardCardFieldsMenu-CvFrsIgy.js → BoardCardFieldsMenu-CWtHiVR-.js} +1 -1
- package/dist/web/assets/{BoardMoveMenu-B5isxIcK.js → BoardMoveMenu-CEDdltY7.js} +1 -1
- package/dist/web/assets/Breadcrumb-C98voz9V.js +1 -0
- package/dist/web/assets/{CaptureChangePage-Ca72_PHc.js → CaptureChangePage-CE8tJfiQ.js} +1 -1
- package/dist/web/assets/{CopyFixPrompt-wGATZKOq.js → CopyFixPrompt-C2hC04lV.js} +1 -1
- package/dist/web/assets/DataFormatPage-BjZkck9o.js +2 -0
- package/dist/web/assets/DebugTurnPage-B82geu1y.js +1 -0
- package/dist/web/assets/DebugTurnsPage-BlDDz1Fk.js +1 -0
- package/dist/web/assets/DialogTitle-fpANsAcy.js +1 -0
- package/dist/web/assets/{EmployeeRedirectPage-C2SHpAEF.js → EmployeeRedirectPage-CSSuvAqx.js} +1 -1
- package/dist/web/assets/EmployeeScopeDialog-BoEMQOEj.js +1 -0
- package/dist/web/assets/EmployeeWorkbench-DvEojWb7.js +4 -0
- package/dist/web/assets/{EmployeeWorkbench-Bp9pUkfS.css → EmployeeWorkbench-rhY970vW.css} +1 -1
- package/dist/web/assets/FieldRoot-D3lnRut5.js +1 -0
- package/dist/web/assets/{FlaGrowth-DGnUPN7D.js → FlaGrowth-OdlmgEVi.js} +1 -1
- package/dist/web/assets/{FlaOccupationKit-DAJjSrmL.js → FlaOccupationKit-CnouVWnU.js} +1 -1
- package/dist/web/assets/{FlaTaskSheets-DRLgfrVC.js → FlaTaskSheets-rSIdCtzz.js} +1 -1
- package/dist/web/assets/FlasPage-BZ791caF.js +1 -0
- package/dist/web/assets/{FlasPage-H99IZ9M6.css → FlasPage-D3CcJcvN.css} +1 -1
- package/dist/web/assets/{GrowthLoading-NLj2W4jj.js → GrowthLoading-BYOSvxZY.js} +1 -1
- package/dist/web/assets/{HowtoPage-CrvMmT6K.css → HowtoPage-DNTwYQCD.css} +1 -1
- package/dist/web/assets/HowtoPage-lYwzi4Vm.js +1 -0
- package/dist/web/assets/InboxPage-C3cSvJjB.js +6 -0
- package/dist/web/assets/{KnowledgeDeleteButton-DaT-gTmm.js → KnowledgeDeleteButton-yc8Gi-BH.js} +1 -1
- package/dist/web/assets/{KnowledgeHardDeleteSection-C9d7DVLa.js → KnowledgeHardDeleteSection-D9Ktc-uC.js} +1 -1
- package/dist/web/assets/KnowledgeItemEditPage-Csy4oOxD.js +1 -0
- package/dist/web/assets/{KnowledgeItemSummaryCard-eLzjKvgN.js → KnowledgeItemSummaryCard-BH5UYmde.js} +1 -1
- package/dist/web/assets/KnowledgeOrganizerPage-BTeQX0gH.js +1 -0
- package/dist/web/assets/KnowledgePage-BuukvNxz.js +1 -0
- package/dist/web/assets/KnowledgePeek-D0pcU7U5.js +1 -0
- package/dist/web/assets/KnowledgeTurnReceiptPage-Bd_LIdCc.js +1 -0
- package/dist/web/assets/{KnowledgeWorkspace-DDg3tUb3.css → KnowledgeWorkspace-Be2gUul5.css} +1 -1
- package/dist/web/assets/KnowledgeWorkspace-Dr-zYpDQ.js +4 -0
- package/dist/web/assets/{MeAvatar-f6qxg9dN.js → MeAvatar-CmhuRFOf.js} +1 -1
- package/dist/web/assets/{MeLink-DTvFYaYE.js → MeLink-BesUihiS.js} +1 -1
- package/dist/web/assets/MenuSeparator-BGo0DgyF.js +1 -0
- package/dist/web/assets/{ModelSettingsPage-B38R-kBZ.css → ModelSettingsPage-BZcyT7Vy.css} +1 -1
- package/dist/web/assets/ModelSettingsPage-CBPwuIBM.js +1 -0
- package/dist/web/assets/{NewSessionPanel-9yINjwyx.js → NewSessionPanel-Bvp9ElzU.js} +1 -1
- package/dist/web/assets/{NotFoundPage-CqevPz0_.js → NotFoundPage-BrolI2fz.js} +1 -1
- package/dist/web/assets/{workbench-card-Dt0820yW.css → NoticeRow-DD-J76Yo.css} +1 -1
- package/dist/web/assets/NoticeRow-Q9QT5NqB.js +1 -0
- package/dist/web/assets/OccupationsPage-CZCeeihl.js +1 -0
- package/dist/web/assets/{PageOutline-HHUlu2x3.js → PageOutline-DULpqEwg.js} +1 -1
- package/dist/web/assets/PageStack-BMzrkyV4.css +1 -0
- package/dist/web/assets/PageStack-DTzWJuae.js +1 -0
- package/dist/web/assets/{PersonalProfilePage-DnjNX2xK.css → PersonalProfilePage-BE5q2bqc.css} +1 -1
- package/dist/web/assets/PersonalProfilePage-DbXWycCQ.js +1 -0
- package/dist/web/assets/PersonalProjectsPage-pdAJpnZd.js +1 -0
- package/dist/web/assets/{PinIcon-DP-9Iisk.js → PinIcon-YYoaYKTx.js} +1 -1
- package/dist/web/assets/PopperContent-CnNwFMIA.js +1 -0
- package/dist/web/assets/Presence-CuIoA2sH.js +3 -0
- package/dist/web/assets/{ProfileAuthorChip-BKZJC_N2.js → ProfileAuthorChip-BEfiuJbm.js} +1 -1
- package/dist/web/assets/ProjectAgentsPage-BPf2RLsw.js +5 -0
- package/dist/web/assets/{ProjectJudgmentPolicy-BJ5sVuFI.js → ProjectJudgmentPolicy-CCzHtmOb.js} +1 -1
- package/dist/web/assets/{RoundtablesPage-D5Xc3yun.js → RoundtablesPage-BDU4W-bg.js} +1 -1
- package/dist/web/assets/RovingFocusGroup-DS4v3bEq.js +1 -0
- package/dist/web/assets/RovingFocusItem-bLEnnw2Y.js +1 -0
- package/dist/web/assets/SessionMigrationPage-DrK4df0L.js +1 -0
- package/dist/web/assets/{SessionRecordsPage-C6U5YGSt.js → SessionRecordsPage-CFAgM65g.js} +1 -1
- package/dist/web/assets/SettingsPage-CsJxhhsu.js +1 -0
- package/dist/web/assets/SettingsPage-VX_e4ty2.css +1 -0
- package/dist/web/assets/SharedJefaReportPage-DbTPYwa_.js +1 -0
- package/dist/web/assets/StatementCalendarPage-CIo5R14R.js +1 -0
- package/dist/web/assets/StatementCalendarPage-t8pJI4G6.css +1 -0
- package/dist/web/assets/StatementRows-CubaC9KG.js +1 -0
- package/dist/web/assets/StatementRows-TQ2i_uXU.css +1 -0
- package/dist/web/assets/{TagVocabularyPage-Brpr-Q-y.js → TagVocabularyPage-BVlLmKv2.js} +1 -1
- package/dist/web/assets/TaskBlockerNotice-YSvmy6B4.js +1 -0
- package/dist/web/assets/{TaskReason-RKKs4Kb5.js → TaskReason-CrLPeiOg.js} +1 -1
- package/dist/web/assets/{TeamCard-8hjo1h0x.js → TeamCard-SBMJMd7P.js} +1 -1
- package/dist/web/assets/TeamCardsWidget-CGLW04TH.js +1 -0
- package/dist/web/assets/TeamIsland-jJKTwCJD.js +9 -0
- package/dist/web/assets/Teleport-CRjWb-eC.js +1 -0
- package/dist/web/assets/{TextField-G2fJ4aFQ.js → TextField-Cd8UOHKv.js} +1 -1
- package/dist/web/assets/TodayPage-BvbZCEFJ.js +1 -0
- package/dist/web/assets/TodayPage-EJ8SWFE0.css +1 -0
- package/dist/web/assets/TonborgDelegationSwitch-BFb1JkWe.css +1 -0
- package/dist/web/assets/TonborgDelegationSwitch-BOidSjkk.js +1 -0
- package/dist/web/assets/{UiChip-BHEJVA6L.js → UiChip-B2z0UERX.js} +1 -1
- package/dist/web/assets/{UiDisclosure-B1pd8qXW.js → UiDisclosure-Bw4Wu0Dm.js} +1 -1
- package/dist/web/assets/{UiIcon-K7OhYTSy.js → UiIcon-BuaIQ57Z.js} +1 -1
- package/dist/web/assets/UiSegmented-DlI1vR3k.js +1 -0
- package/dist/web/assets/{UiWeight-eAw682rH.js → UiWeight-DpBexUUy.js} +1 -1
- package/dist/web/assets/{VirtualDirectoryList-BGum1GZc.js → VirtualDirectoryList-RV2XtTPO.js} +1 -1
- package/dist/web/assets/{VisuallyHidden-Ck6D7rq-.js → VisuallyHidden-DciDIEua.js} +1 -1
- package/dist/web/assets/{VisuallyHiddenInput-DXWhIUlB.js → VisuallyHiddenInput-mfi7gVBu.js} +1 -1
- package/dist/web/assets/WidgetSlot-xFZKjZ5z.js +2 -0
- package/dist/web/assets/WorkbenchListPage-BKT03RRO.css +1 -0
- package/dist/web/assets/WorkbenchListPage-suawrzji.js +1 -0
- package/dist/web/assets/_plugin-vue_export-helper-CYsAcErn.js +9 -0
- package/dist/web/assets/{agent-apps-D0eG1aMx.js → agent-apps-B_0syRPr.js} +1 -1
- package/dist/web/assets/agent-occupation-C-9THmIG.js +1 -0
- package/dist/web/assets/{agent-pins-OYjJQ38F.js → agent-pins-B9wMvxGh.js} +1 -1
- package/dist/web/assets/{agent-roster-records-CsYjmaNn.js → agent-roster-records-CY0aSUNq.js} +1 -1
- package/dist/web/assets/{agent-work-summary-BOeJ4JXc.js → agent-work-summary-Cs8jPFL0.js} +1 -1
- package/dist/web/assets/{attach-closest-edge-C75rKXiz.js → attach-closest-edge-BRDsvYPn.js} +1 -1
- package/dist/web/assets/{attention-store-k4mPCefZ.js → attention-store-HMiJ1K6M.js} +1 -1
- package/dist/web/assets/{badge-B2rll-68.js → badge-jafr8Jg1.js} +1 -1
- package/dist/web/assets/{button-q6JhonlL.js → button-d6TCVE0s.js} +1 -1
- package/dist/web/assets/{card-CPQiMHSu.js → card-ebnaJXQA.js} +1 -1
- package/dist/web/assets/{catalog-CBPcEkXC.js → catalog-CvdvPGYk.js} +1 -1
- package/dist/web/assets/checkbox-CdIozFRY.js +1 -0
- package/dist/web/assets/{client-KFFphxpK.js → client--hZxcKYo.js} +1 -1
- package/dist/web/assets/{client-links-store-Cw9c8MWc.js → client-links-store-XyR0EzJi.js} +1 -1
- package/dist/web/assets/combobox-DzLSYxyO.js +1 -0
- package/dist/web/assets/{console-BCR2S3AF.js → console-D597wx3f.js} +1 -1
- package/dist/web/assets/conversation-launcher-settings-CFFH9C2y.js +1 -0
- package/dist/web/assets/copy-mention-CWsw8po1.js +1 -0
- package/dist/web/assets/dialog-SLa8cPbS.js +1 -0
- package/dist/web/assets/{dist-CaVgk2QB.js → dist-B78L06NL.js} +1 -1
- package/dist/web/assets/{dist-D73EXNtz.js → dist-Dy5JoHWF.js} +1 -1
- package/dist/web/assets/dropdown-menu-C-PcZxRY.js +1 -0
- package/dist/web/assets/{field-BaUOZtN5.js → field-DeguT8it.js} +1 -1
- package/dist/web/assets/{format-bytes-D5eCtdg1.js → format-bytes-Br4RwHnA.js} +1 -1
- package/dist/web/assets/hover-card-B-H7mMvg.js +1 -0
- package/dist/web/assets/identity-V8oA_IuB.js +1 -0
- package/dist/web/assets/{index-HRZACEmh.css → index-CHDkJLQR.css} +1 -1
- package/dist/web/assets/index-DdAVEwQV.js +24 -0
- package/dist/web/assets/{input-Dxh25T4M.js → input-CRCpCN_c.js} +1 -1
- package/dist/web/assets/label-DwMBzI2m.js +1 -0
- package/dist/web/assets/label-table-DiaZlHIp.js +1 -0
- package/dist/web/assets/{model-ZwOxwk2m.js → model-B4AuKvPj.js} +1 -1
- package/dist/web/assets/model-BwOv-HBS.js +1 -0
- package/dist/web/assets/{model-Blk5Wgg2.js → model-C-60EMcI.js} +1 -1
- package/dist/web/assets/{model-Bgh75q3j.js → model-CB4ObIOH.js} +1 -1
- package/dist/web/assets/{model--lR9icA_.js → model-CUAxIOXR.js} +1 -1
- package/dist/web/assets/{model-jC3F-J2F.js → model-CjQPAeCy.js} +1 -1
- package/dist/web/assets/{model-D4DkvMH-.js → model-CwFZ_IgV.js} +1 -1
- package/dist/web/assets/{model-CWMP5GOL.js → model-D-vak-m0.js} +1 -1
- package/dist/web/assets/{motion-BL3lek9c.js → motion-Cr9JChF9.js} +1 -1
- package/dist/web/assets/motion-D5Fs3-ut.js +1 -0
- package/dist/web/assets/{motion-preference-D3UMHojT.js → motion-preference-DgdzdVh8.js} +1 -1
- package/dist/web/assets/{occupation-catalog-BeJ2O9nm.js → occupation-catalog-DHsjkd_q.js} +1 -1
- package/dist/web/assets/{occupation-kits-Bkiu6MzD.js → occupation-kits-BVLLRN4V.js} +1 -1
- package/dist/web/assets/{option-Crs2MA88.js → option-DhAwzags.js} +1 -1
- package/dist/web/assets/{orchestration-filters-3AfjDoHQ.js → orchestration-filters-lhR2CHlQ.js} +1 -1
- package/dist/web/assets/overview-data-QDnygL-x.js +1 -0
- package/dist/web/assets/{page-refresh-Bz5r7A_Q.js → page-refresh-BVRlo-dI.js} +1 -1
- package/dist/web/assets/{page-title-KYZApNys.js → page-title-ReSXziuS.js} +1 -1
- package/dist/web/assets/{person-profile-mhLxWtq7.js → person-profile-BgUfg57K.js} +1 -1
- package/dist/web/assets/popover-UYksnAeH.js +1 -0
- package/dist/web/assets/popup-host-DMoMkD3v.js +1 -0
- package/dist/web/assets/preference-conflicts-a-H51vUw.js +1 -0
- package/dist/web/assets/{profile-model-DWutKuCZ.js → profile-model-CM98TJsj.js} +1 -1
- package/dist/web/assets/{project-board-layout-CWMHQuUA.js → project-board-layout-RH6UXkCA.js} +1 -1
- package/dist/web/assets/{project-capture-CebFSnn0.js → project-capture-DcQ8cXIt.js} +1 -1
- package/dist/web/assets/{project-origin-BnUVE0be.js → project-origin-BNzeAazi.js} +1 -1
- package/dist/web/assets/{quick-edit-api-YwzoODMc.js → quick-edit-api-COKVNuPk.js} +1 -1
- package/dist/web/assets/radio-group-DfegNkLG.js +1 -0
- package/dist/web/assets/review-api-CAKGInLD.js +1 -0
- package/dist/web/assets/{review-list-_PN7ljSY.js → review-list-CbpXvBp-.js} +1 -1
- package/dist/web/assets/{review-store-CobX9No6.js → review-store-BzrmqVoj.js} +1 -1
- package/dist/web/assets/{role-names-wD9l8uz5.js → role-names-Ba0c6AbS.js} +1 -1
- package/dist/web/assets/{roundtable-live-Dm4Vwo75.js → roundtable-live-CoKmaXKd.js} +1 -1
- package/dist/web/assets/{runtime-dom.esm-bundler-DzfwnSj8.js → runtime-dom.esm-bundler-CaYBCU9Y.js} +1 -1
- package/dist/web/assets/select-Bq2TQ0Gw.js +1 -0
- package/dist/web/assets/{session-launch-offers-C9UkoKUJ.js → session-launch-offers-C-oBkMKe.js} +1 -1
- package/dist/web/assets/{settings-autosave-L0zSXnBO.js → settings-autosave-C3bTildI.js} +1 -1
- package/dist/web/assets/settings-tabs-DFZcxOaQ.js +1 -0
- package/dist/web/assets/shared-report-Ci1jBiYV.js +3 -0
- package/dist/web/assets/{source-adapters-r-NIqO77.js → source-adapters-CunVF9JG.js} +1 -1
- package/dist/web/assets/switch-DaUSEDq0.js +1 -0
- package/dist/web/assets/tabs-B_7xQRfl.js +1 -0
- package/dist/web/assets/{task-card-fields-B1z1PmTT.js → task-card-fields-Ce11pWnv.js} +1 -1
- package/dist/web/assets/{task-evidence-DydhKn9x.js → task-evidence-D0XkNnb8.js} +1 -1
- package/dist/web/assets/{task-labels-DTc5OuFF.js → task-labels-BulIuDQB.js} +1 -1
- package/dist/web/assets/{task-reason-CneTZWRv.js → task-reason-gHlp8KHO.js} +1 -1
- package/dist/web/assets/{team-sheets-CUt3Vp2s.js → team-sheets-BzV1WjjK.js} +1 -1
- package/dist/web/assets/{textarea-DJ0ucCir.js → textarea-D6czUY3a.js} +1 -1
- package/dist/web/assets/ui-BCHzwL4X.js +1 -0
- package/dist/web/assets/ui-CgwSWg1F.css +1 -0
- package/dist/web/assets/{useAgentRecords-CwkwZy8H.js → useAgentRecords-DijrJ79w.js} +1 -1
- package/dist/web/assets/{useAgentWorkSummary-DoiCqME7.js → useAgentWorkSummary-CUv88AVP.js} +1 -1
- package/dist/web/assets/{useApi-CROJJdhE-CenjhnR5.js → useApi-CROJJdhE-CxqsMZ6P.js} +1 -1
- package/dist/web/assets/{useClipboardCopy-Ba86PzjA.js → useClipboardCopy-uGyNKuWB.js} +1 -1
- package/dist/web/assets/useDirection-Bi78LycK.js +1 -0
- package/dist/web/assets/{useFocusReturn-B0ErBkt_.js → useFocusReturn-7BKdKvqF.js} +1 -1
- package/dist/web/assets/{useForwardPropsEmits-D1vvIUcB.js → useForwardPropsEmits-BMeknK03.js} +1 -1
- package/dist/web/assets/useForwardScopeId-DHGSyWlZ.js +1 -0
- package/dist/web/assets/{useKnowledgeConfirm-781LUhoU.js → useKnowledgeConfirm-mFWI8EbK.js} +1 -1
- package/dist/web/assets/{useKnowledgeItemPeek-CnuCvJKQ.js → useKnowledgeItemPeek-DtazLM2s.js} +1 -1
- package/dist/web/assets/{useMinimumLoadingDisplay-DCC9EfQ9.js → useMinimumLoadingDisplay-D5UC2KRz.js} +1 -1
- package/dist/web/assets/{usePageTools-BaB021q0.js → usePageTools-BXkR_gpB.js} +1 -1
- package/dist/web/assets/usePrimitiveElement-BxOn-Fn_.js +1 -0
- package/dist/web/assets/{useProjectAgentRoster-M3wbWpS-.js → useProjectAgentRoster-blZ5REnH.js} +1 -1
- package/dist/web/assets/{useRoutePeek-CYg5JyYt.js → useRoutePeek-D_j5KVFv.js} +1 -1
- package/dist/web/assets/useTeamWork-e57CKhLW.js +1 -0
- package/dist/web/assets/{useTypeahead-DYb5kVkH.js → useTypeahead-6a1q-4Oq.js} +1 -1
- package/dist/web/assets/{utils-Cli0RsEd.js → utils-BQtZ8ZUw.js} +1 -1
- package/dist/web/assets/{utils-B7sUn8rD.js → utils-DBsOpQt4.js} +1 -1
- package/dist/web/assets/{verification-DY7kllTI.js → verification-BlF0avgs.js} +1 -1
- package/dist/web/assets/{version-CBgUEmnM.js → version-oG6VyAd6.js} +1 -1
- package/dist/web/assets/{vue-router-ab7kABlJ.js → vue-router-CCvxNose.js} +1 -1
- package/dist/web/index.html +75 -79
- package/docs/agent-roundtable.md +45 -3
- package/docs/judgment-and-autonomy.md +2 -0
- package/graph-provider/fuli_graph/app.py +6 -0
- package/graph-provider/fuli_graph/knowledge_duplicates.py +27 -14
- package/graph-provider/fuli_graph/knowledge_search.py +31 -32
- package/graph-provider/fuli_graph/knowledge_semantic.py +38 -11
- package/graph-provider/fuli_graph/knowledge_statement.py +230 -0
- package/graph-provider/fuli_graph/knowledge_statement_days.py +109 -0
- package/graph-provider/fuli_graph/models.py +15 -0
- package/graph-provider/fuli_graph/preference_organizing.py +162 -0
- package/graph-provider/fuli_graph/project_agent_routes.py +22 -0
- package/graph-provider/fuli_graph/project_agent_task_models.py +26 -2
- package/graph-provider/fuli_graph/store_project_agent_task_activity.py +51 -11
- package/graph-provider/fuli_graph/store_project_agent_task_blockers.py +13 -6
- package/graph-provider/fuli_graph/store_project_agent_task_person_close.py +82 -0
- package/graph-provider/fuli_graph/store_project_agent_tasks.py +18 -1
- package/graph-provider/fuli_graph/task_blocker.py +10 -0
- package/graph-provider/pyproject.toml +1 -1
- package/native/win32/fuli-win-helper.exe +0 -0
- package/npm-shrinkwrap.json +57 -9
- package/package.json +4 -3
- package/packages/roundtable/package.json +1 -0
- package/packages/roundtable/src/agents/claude-code/wake.js +4 -2
- package/packages/roundtable/src/agents/codex/wake.js +1 -0
- package/packages/roundtable/src/host.js +4 -1
- package/packages/roundtable/src/peer/control-cli.js +103 -2
- package/packages/roundtable/src/peer/control.js +29 -3
- package/packages/roundtable/src/peer/coordinator-http.js +23 -2
- package/packages/roundtable/src/peer/coordinator-service.js +92 -14
- package/packages/roundtable/src/peer/coordinator-store.js +2 -1
- package/packages/roundtable/src/peer/lan-addresses.js +43 -0
- package/packages/roundtable/src/peer/nearby-attempts.js +73 -0
- package/packages/roundtable/src/peer/nearby-discovery.js +132 -0
- package/packages/roundtable/src/peer/nearby-pairing.js +422 -0
- package/packages/roundtable/src/peer/nearby-presence.js +93 -0
- package/packages/roundtable/src/peer/node-store.js +10 -0
- package/packages/roundtable/src/peer/pairing-share.js +139 -0
- package/packages/roundtable/src/peer/peer-runtime.js +684 -89
- package/packages/roundtable/src/peer/peer-transport.js +58 -3
- package/packages/roundtable/src/peer/protocol.js +24 -1
- package/packages/roundtable/src/roundtable/chat-service.js +14 -3
- package/packages/roundtable/src/roundtable/chat.js +1 -0
- package/packages/roundtable/src/roundtable/delivery-state.js +2 -1
- package/packages/roundtable/src/roundtable/group-discussion-store.js +130 -5
- package/packages/roundtable/src/roundtable/group-discussion.js +596 -111
- package/packages/roundtable/src/roundtable/service.js +10 -2
- package/packages/roundtable/src/roundtable/store.js +11 -1
- package/packages/roundtable/src/roundtable/wake.js +3 -1
- package/packages/roundtable/src/standalone/cli.js +1 -1
- package/skills/capturing-session-knowledge/SKILL.md +1 -1
- package/skills/capturing-session-knowledge/references/coordination.md +28 -4
- package/skills/grilling-project/references/project-profile.md +13 -5
- package/skills/operating-fuli/SKILL.md +30 -5
- package/skills/operating-fuli/references/workflow-recipes.md +6 -2
- package/src/agent-apps/host-tools/catalog.js +2 -0
- package/src/agent-delegation/operation-log.js +15 -1
- package/src/agent-delegation/port.js +2 -3
- package/src/agent-delegation/refusals.js +12 -4
- package/src/agent-roundtable/task-context.js +1 -1
- package/src/agent-roundtable/tools.js +5 -2
- package/src/agent-tools/graph-definitions.js +2 -0
- package/src/agent-tools/graph-handlers.js +6 -3
- package/src/agent-tools/interface-catalog.js +11 -1
- package/src/agent-tools/interface-definitions.js +3 -2
- package/src/agent-tools/project-agent-definitions.js +2 -1
- package/src/agent-tools/project-organizing-definitions.js +7 -4
- package/src/agent-tools/project-space-definitions.js +2 -0
- package/src/agent-tools/session-fuli-gate.js +6 -1
- package/src/agent-tools/statement-definitions.js +18 -0
- package/src/agents/codex/lifecycle-hook.js +3 -1
- package/src/agents/identity-receipt.js +3 -1
- package/src/agents/native-session-env.js +7 -0
- package/src/conversations/entry-budget.js +3 -2
- package/src/conversations/entry-inline-budget.js +40 -10
- package/src/conversations/preference-lifecycle.js +3 -3
- package/src/conversations/turn-findings.js +9 -2
- package/src/graphiti/agent-project-resolution.js +18 -0
- package/src/graphiti/collaboration-preference-entry.js +5 -2
- package/src/graphiti/current-project-knowledge-search.js +3 -3
- package/src/graphiti/fla-mention.js +48 -9
- package/src/graphiti/local-runtimes.js +5 -0
- package/src/graphiti/project-agent-task-sessions.js +49 -0
- package/src/graphiti/project-agent-task-summaries.js +82 -0
- package/src/graphiti/project-agent-workflows.js +8 -5
- package/src/graphiti/project-path-context.js +23 -9
- package/src/graphiti/provider-client.js +23 -1
- package/src/graphiti/repository-remote.js +34 -8
- package/src/graphiti/roundtable-host.js +13 -1
- package/src/graphiti/task-context-entry.js +14 -7
- package/src/graphiti/task-entry-group-discussion.js +111 -25
- package/src/graphiti/task-entry-owner-change.js +22 -2
- package/src/graphiti/task-entry-preferences.js +9 -4
- package/src/graphiti/task-entry-project-scope.js +19 -0
- package/src/graphiti/task-preference-pages.js +3 -3
- package/src/graphiti/task-preference-reader.js +44 -9
- package/src/graphiti/worker-task-context.js +1 -1
- package/src/http/api-router.js +5 -0
- package/src/http/graph-api-router.js +5 -2
- package/src/http/statement-api-router.js +27 -0
- package/src/http/task-blocker-api-router.js +11 -1
- package/src/http/task-close-api-router.js +59 -0
- package/src/judgment/engine.js +6 -1
- package/src/judgment/http.js +2 -2
- package/src/judgment/review-delegation.js +16 -4
- package/src/judgment/review-egress.js +25 -0
- package/src/judgment/service.js +1 -1
- package/src/judgment/store.js +9 -0
- package/src/knowledge-impressions/store.js +72 -9
- package/src/mcp/create-mcp-server.js +2 -2
- package/src/mcp/direct-call.js +3 -2
- package/src/mcp/preference-delivery.js +64 -6
- package/src/mcp/session-id.js +12 -4
- package/src/mcp/tool-annotations.js +1 -0
- package/src/mcp/tool-result.js +8 -6
- package/src/model-backends/config.js +7 -0
- package/src/model-backends/egress.js +8 -0
- package/src/model-backends/failures.js +8 -0
- package/src/model-backends/port.js +39 -16
- package/src/model-backends/role-trust.js +3 -9
- package/src/model-backends/usage-ledger.js +20 -9
- package/src/notices/recent-notices.js +2 -1
- package/src/presence/windows-helper-pin.js +1 -1
- package/src/project-organizing/agent-tool.js +34 -7
- package/src/server.js +7 -0
- package/src/statement/agent-tool.js +29 -0
- package/src/statement/compounding-statement.js +134 -0
- package/src/task-blockers/agent-resume.js +73 -0
- package/src/task-blockers/console-port.js +5 -2
- package/src/task-blockers/resume-status.js +2 -0
- package/src/task-closing/console-port.js +26 -0
- package/src/whats-new/lines/0.27.1.json +13 -0
- package/src/whats-new/lines/0.27.2.json +13 -0
- package/dist/web/assets/AgentAppsPage-CjyvPZSs.js +0 -1
- package/dist/web/assets/AgentManagement-Cc00RLSO.css +0 -1
- package/dist/web/assets/AgentManagement-MMGrwdD2.js +0 -7
- package/dist/web/assets/AgentProfilePage-eDKbJJwY.js +0 -5
- package/dist/web/assets/AgentServicesPage-CZwsN5U2.js +0 -1
- package/dist/web/assets/Breadcrumb-BXTA4e-W.js +0 -1
- package/dist/web/assets/DataFormatPage-CQKkFhcH.js +0 -2
- package/dist/web/assets/DebugTurnPage-CUqbuhgX.js +0 -1
- package/dist/web/assets/DebugTurnsPage-HwaTG8Fa.js +0 -1
- package/dist/web/assets/DialogTitle-HYzAHbGg.js +0 -1
- package/dist/web/assets/EmployeeScopeDialog-yUCgujKT.js +0 -1
- package/dist/web/assets/EmployeeWorkbench-CbRJhkJO.js +0 -4
- package/dist/web/assets/FieldRoot-BLcsuPMA.js +0 -1
- package/dist/web/assets/FlasPage-CMv2awKJ.js +0 -1
- package/dist/web/assets/HowtoPage-CkGRrKpf.js +0 -1
- package/dist/web/assets/InboxPage-DfQvtnyq.js +0 -6
- package/dist/web/assets/KnowledgeItemEditPage-BUKQK37o.js +0 -1
- package/dist/web/assets/KnowledgeOrganizerPage-CiZ9JlNX.js +0 -1
- package/dist/web/assets/KnowledgePage-C3_Cvz4g.js +0 -1
- package/dist/web/assets/KnowledgePeek-DtOOiARX.js +0 -1
- package/dist/web/assets/KnowledgeTurnReceiptPage-Dne5NQ9q.js +0 -1
- package/dist/web/assets/KnowledgeWorkspace-Cq_XYcma.js +0 -4
- package/dist/web/assets/MenuSeparator-CLmsZ9rj.js +0 -1
- package/dist/web/assets/ModelSettingsPage-COVaW4eh.js +0 -1
- package/dist/web/assets/NoticeRow-D5MWTeBY.js +0 -1
- package/dist/web/assets/NoticeRow-ktVO_9Es.css +0 -1
- package/dist/web/assets/OccupationsPage-BKd051j1.js +0 -1
- package/dist/web/assets/OverviewPage-C90G_adj.js +0 -1
- package/dist/web/assets/OverviewPage-KVt4LcE-.css +0 -1
- package/dist/web/assets/PageColumns-DEideeB7.css +0 -1
- package/dist/web/assets/PageColumns-Df60nEzj.js +0 -1
- package/dist/web/assets/PersonalProfilePage-DIDgG3NH.js +0 -1
- package/dist/web/assets/PersonalProjectsPage-DwhlEpNg.js +0 -1
- package/dist/web/assets/PopperContent-DWCMeKSL.js +0 -1
- package/dist/web/assets/Presence-Ba3jqPYx.js +0 -3
- package/dist/web/assets/ProjectAgentsPage-BefVF9ZP.js +0 -5
- package/dist/web/assets/RecentNotices-CDHGIky1.js +0 -1
- package/dist/web/assets/RovingFocusGroup-DoGybG5V.js +0 -1
- package/dist/web/assets/RovingFocusItem-B455TzUI.js +0 -1
- package/dist/web/assets/SessionMigrationPage-BAzXqxxO.js +0 -1
- package/dist/web/assets/SettingsPage-7mNL3bwe.js +0 -1
- package/dist/web/assets/SettingsPage-Cku8SoLk.css +0 -1
- package/dist/web/assets/SharedJefaReportPage-rH6I4cI9.js +0 -1
- package/dist/web/assets/TaskBlockerClear-BBmPbomO.css +0 -1
- package/dist/web/assets/TaskBlockerClear-BHOMZYwm.js +0 -1
- package/dist/web/assets/TaskBlockerNotice-POmS2neR.js +0 -1
- package/dist/web/assets/TeamCardsWidget-DIHFUDrF.js +0 -1
- package/dist/web/assets/TeamIsland-DdhEcVOZ.js +0 -9
- package/dist/web/assets/Teleport-CukHuRhz.js +0 -1
- package/dist/web/assets/TonborgDelegationSwitch-BA3Qb8Wr.js +0 -1
- package/dist/web/assets/TonborgDelegationSwitch-DeqERWoo.css +0 -1
- package/dist/web/assets/UiDialog-bUwGQz96.js +0 -1
- package/dist/web/assets/UiIconButton-D3R6WwwI.css +0 -1
- package/dist/web/assets/UiIconButton-DlLZ5_Yc.js +0 -1
- package/dist/web/assets/UiSegmented-CYrTxDn1.js +0 -1
- package/dist/web/assets/WidgetSlot-D6vCSWaz.js +0 -2
- package/dist/web/assets/WorkbenchListHead-CR_fDYYr.js +0 -1
- package/dist/web/assets/WorkbenchListPage-BX6Z9gkB.css +0 -1
- package/dist/web/assets/WorkbenchListPage-Zr5PW-cf.js +0 -1
- package/dist/web/assets/_plugin-vue_export-helper-BRS32yXs.js +0 -9
- package/dist/web/assets/agent-occupation-CEd3bAhb.js +0 -1
- package/dist/web/assets/agent-workflows-D3VeY6Yz.js +0 -1
- package/dist/web/assets/checkbox-C67upxzl.js +0 -1
- package/dist/web/assets/combobox-yHRJ-zN-.js +0 -1
- package/dist/web/assets/conversation-launcher-settings-28CqC1Gn.js +0 -1
- package/dist/web/assets/copy-mention-C4Nos381.js +0 -1
- package/dist/web/assets/dialog-Cjoy4nsv.js +0 -1
- package/dist/web/assets/dropdown-menu-Dto6hjoc.js +0 -1
- package/dist/web/assets/hover-card-Bg0dulGq.js +0 -1
- package/dist/web/assets/index-B-aRUs9w.js +0 -24
- package/dist/web/assets/label-CbrduZla.js +0 -1
- package/dist/web/assets/label-table-_YAtPkRI.js +0 -1
- package/dist/web/assets/model-DcsCYhXk.js +0 -1
- package/dist/web/assets/motion-_MepnmMC.js +0 -1
- package/dist/web/assets/overview-data-BIeNATEJ.js +0 -1
- package/dist/web/assets/popover-CMahoDLo.js +0 -1
- package/dist/web/assets/popup-host-DKN99Od3.js +0 -1
- package/dist/web/assets/radio-group-vRt8y8mF.js +0 -1
- package/dist/web/assets/review-api-WhNB3ppo.js +0 -1
- package/dist/web/assets/select-B9mVptgx.js +0 -1
- package/dist/web/assets/settings-tabs-DTbgqX8g.js +0 -1
- package/dist/web/assets/shared-report-0FO_y0sa.js +0 -3
- package/dist/web/assets/switch-BCzrGc4W.js +0 -1
- package/dist/web/assets/tabs-CB38D8N0.js +0 -1
- package/dist/web/assets/ui-D4nAhcmu.css +0 -1
- package/dist/web/assets/ui-M_UKzb_A.js +0 -1
- package/dist/web/assets/useForwardExpose-DJ6fcpI2.js +0 -1
- package/dist/web/assets/useForwardScopeId-CoSQtoUU.js +0 -1
- package/dist/web/assets/usePrimitiveElement-iRKqOVuY.js +0 -1
- package/dist/web/assets/useTeamPeople-CPC62La3.js +0 -1
- package/dist/web/assets/useTeamWork-Dql3_qLV.js +0 -1
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import { randomBytes, randomUUID } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
import { cleanName } from './coordinator-service.js';
|
|
4
|
+
import { isAuthorityKey } from './origin-proof.js';
|
|
5
|
+
import { PeerError, sha256Hex, shortFingerprint } from './protocol.js';
|
|
6
|
+
|
|
7
|
+
export const NEARBY_PROTOCOL = 1;
|
|
8
|
+
const PAIRING_MS = 2 * 60_000;
|
|
9
|
+
// A request whose initiator has not revealed its nonce by then is abandoned.
|
|
10
|
+
const CONNECTING_MS = 10_000;
|
|
11
|
+
const POLL_MS = 1_000;
|
|
12
|
+
const REQUEST_MS = 5_000;
|
|
13
|
+
const COMMITMENT = /^[0-9a-f]{64}$/;
|
|
14
|
+
const NONCE = /^[A-Za-z0-9_-]{43}$/;
|
|
15
|
+
const REQUEST_ID = /^[A-Za-z0-9-]{1,64}$/;
|
|
16
|
+
const OPEN_STATES = new Set(['connecting', 'confirm', 'finishing']);
|
|
17
|
+
|
|
18
|
+
// What the other computer may say when it refuses, in this computer's own
|
|
19
|
+
// words; its own code, message and status are never shown or passed on.
|
|
20
|
+
const REMOTE_REFUSALS = new Map(Object.entries({
|
|
21
|
+
pairing_busy: ['The other computer is already pairing; try again in two minutes', 409],
|
|
22
|
+
pairing_rate_limited: ['The other computer takes no more pairing attempts for now', 429],
|
|
23
|
+
already_paired: ['These computers are already paired', 409],
|
|
24
|
+
both_coordinate: ['Both computers already coordinate other devices; turn the LAN roundtable off on one first', 409],
|
|
25
|
+
not_found: ['The other computer is not open for nearby pairing', 404],
|
|
26
|
+
device_not_trusted: ['The other computer is not open for nearby pairing', 404],
|
|
27
|
+
pairing_not_found: ['The other computer no longer has this pairing request', 404],
|
|
28
|
+
pairing_mismatch: ['The other computer refused the pairing answer', 409],
|
|
29
|
+
unsupported_protocol: ['The other computer pairs with another protocol version', 409],
|
|
30
|
+
}));
|
|
31
|
+
// How the other computer may say a pairing ended; anything else reads as failed there.
|
|
32
|
+
const REMOTE_REASONS = new Set(['code_mismatch', 'expired', 'no_answer', 'coordinator_unreachable', 'trust_failed', 'join_failed']);
|
|
33
|
+
|
|
34
|
+
// Pairing two computers that see each other on the LAN, with a 6-digit code
|
|
35
|
+
// each person compares by eye and confirms on their own computer (rec issue 127).
|
|
36
|
+
//
|
|
37
|
+
// Threat model. Anyone on the LAN sees the advertisement and can reach these
|
|
38
|
+
// routes, so:
|
|
39
|
+
// - A request alone changes nothing. Trust is written only after the person on
|
|
40
|
+
// each computer confirmed on that computer (a local-only control); until then
|
|
41
|
+
// the request lives in memory, one at a time, and the target's screen shows it
|
|
42
|
+
// (who and a short fingerprint) from the moment it arrives.
|
|
43
|
+
// - The code is derived from both full certificate fingerprints, the chosen
|
|
44
|
+
// coordinator and a fresh nonce from each side. The initiator commits to its
|
|
45
|
+
// nonce before it sees the target's, so a device in the middle can only try a
|
|
46
|
+
// fresh target nonce by starting a new handshake: 1 chance in 10^6 per
|
|
47
|
+
// handshake, and only one handshake is open at a time.
|
|
48
|
+
// - Every handshake is an attempt, counted in this computer's own store before
|
|
49
|
+
// any nonce leaves it (nearby-attempts.js): at most 3 per device and address
|
|
50
|
+
// and 5 in all per 10 minutes, and 10 per rolling 24 hours. Turning nearby
|
|
51
|
+
// pairing off and on, an Agent, or a restart does not clear them; only time or
|
|
52
|
+
// the person on this computer does. So a device in the middle wins with a
|
|
53
|
+
// chance of at most 10 in 10^6 per computer per 24 hours (each of its tries
|
|
54
|
+
// shows on the screens), until the person here clears the count. Time is
|
|
55
|
+
// the process's monotonic clock while FULI runs, and never earlier than the
|
|
56
|
+
// latest stored attempt across restarts; the bound assumes the system clock
|
|
57
|
+
// is not moved forward while FULI is stopped (that ages the count once).
|
|
58
|
+
// - The nearby list is keyed by a fingerprint prefix nobody vouches for: a
|
|
59
|
+
// device can pose as another in the list, which can only block or misdirect
|
|
60
|
+
// a pairing, never grant one, since the code binds both full fingerprints.
|
|
61
|
+
// Requests arriving on a virtual or VPN adapter are not answered.
|
|
62
|
+
// - This computer accepts "paired" from the other side only after its own
|
|
63
|
+
// person confirmed, and, when it coordinates, only after it wrote its trust.
|
|
64
|
+
// - A wrong commitment, or a code that differs from this computer's, cancels the
|
|
65
|
+
// request. There is no weaker fallback: an unknown protocol version is refused.
|
|
66
|
+
// - Paired devices get the same mutual-TLS and origin-authority records an
|
|
67
|
+
// invitation writes; a device already trusted, or this device itself, is
|
|
68
|
+
// refused. While nearby pairing is off these routes answer as unknown paths.
|
|
69
|
+
//
|
|
70
|
+
// Which computer coordinates is not the person's choice: the one that already
|
|
71
|
+
// coordinates other devices keeps doing so; otherwise the computer that was
|
|
72
|
+
// picked from the list (the target), since the initiator just proved it can
|
|
73
|
+
// reach it. Two computers that both coordinate others are refused.
|
|
74
|
+
export function createNearbyPairing({ local, attempts, connect, clock = Date.now, nonce = () => randomBytes(32).toString('base64url'),
|
|
75
|
+
idFactory = randomUUID, pollMs = POLL_MS, onPaired = () => {}, onError = () => {} }) {
|
|
76
|
+
let slot = null;
|
|
77
|
+
|
|
78
|
+
function sweep() {
|
|
79
|
+
if (!slot) return;
|
|
80
|
+
const now = clock();
|
|
81
|
+
if (slot.direction === 'incoming' && slot.state === 'connecting' && slot.connectingUntil <= now) end(slot, 'failed', 'no_answer');
|
|
82
|
+
else if (OPEN_STATES.has(slot.state) && slot.expiresAt <= now) end(slot, slot.applied ? 'paired' : 'expired', slot.applied ? null : 'expired');
|
|
83
|
+
else if (!OPEN_STATES.has(slot.state) && slot.endedAt + PAIRING_MS <= now) slot = null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function open() {
|
|
87
|
+
sweep();
|
|
88
|
+
return slot && OPEN_STATES.has(slot.state) ? slot : null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function end(current, state, reason = null) {
|
|
92
|
+
if (!OPEN_STATES.has(current.state)) return;
|
|
93
|
+
current.state = state;
|
|
94
|
+
current.reason = reason;
|
|
95
|
+
current.endedAt = clock();
|
|
96
|
+
clearTimeout(current.timer);
|
|
97
|
+
current.client?.close();
|
|
98
|
+
current.client = null;
|
|
99
|
+
if (state === 'paired') Promise.resolve().then(() => onPaired(current.peer)).catch(onError);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function codeOf(current) {
|
|
103
|
+
const [initiator, target] = current.direction === 'outgoing' ? [current.self, current.peer.fingerprint]
|
|
104
|
+
: [current.peer.fingerprint, current.self];
|
|
105
|
+
const digest = sha256Hex(['fuli-pair-code', NEARBY_PROTOCOL, initiator, target, current.coordinator,
|
|
106
|
+
current.initiatorNonce, current.targetNonce].join('|'));
|
|
107
|
+
return String(Number.parseInt(digest.slice(0, 8), 16) % 1_000_000).padStart(6, '0');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ---- The computer that was picked (target): routes on its listener ----
|
|
111
|
+
|
|
112
|
+
async function receiveRequest(body, peer) {
|
|
113
|
+
const self = await local.identity();
|
|
114
|
+
const authority = await local.authority();
|
|
115
|
+
// Everything awaited is done: from here to the nonce nothing yields, so no
|
|
116
|
+
// parallel request passes the slot and budget checks between them.
|
|
117
|
+
const role = local.role();
|
|
118
|
+
if (!role.listening) throw unknownPath();
|
|
119
|
+
if (body.protocol !== NEARBY_PROTOCOL) throw new PeerError('unsupported_protocol', 'This FULI pairs with nearby protocol 1 only');
|
|
120
|
+
if (peer.fingerprint === self.fingerprint) throw new PeerError('invalid_pairing', 'A device cannot pair with itself');
|
|
121
|
+
if (local.trusted(peer.fingerprint)) throw new PeerError('already_paired', 'These computers are already paired', 409);
|
|
122
|
+
if (!COMMITMENT.test(body.commit ?? '') || !isAuthorityKey(body.authority) || typeof body.coordinates !== 'boolean'
|
|
123
|
+
|| (body.coordinates && !validPort(body.port))) throw new PeerError('invalid_pairing', 'Invalid nearby pairing request');
|
|
124
|
+
if (body.coordinates && role.coordinatesOthers) {
|
|
125
|
+
throw new PeerError('both_coordinate', 'Both computers already coordinate other devices; turn the LAN roundtable off on one first', 409);
|
|
126
|
+
}
|
|
127
|
+
if (open()) throw new PeerError('pairing_busy', 'This computer is already pairing; try again in two minutes', 409);
|
|
128
|
+
attempts.take(deviceKey(peer));
|
|
129
|
+
const now = clock();
|
|
130
|
+
slot = { id: idFactory(), direction: 'incoming', self: self.fingerprint, state: 'connecting',
|
|
131
|
+
peer: { fingerprint: peer.fingerprint, certPem: peer.certPem, name: cleanName(body.name) || `FULI ${peer.fingerprint.slice(0, 4)}`,
|
|
132
|
+
authority: { keyId: body.authority.keyId, publicKey: body.authority.publicKey }, address: peer.address,
|
|
133
|
+
port: body.coordinates ? body.port : null, reachedAt: peer.localAddress ?? null },
|
|
134
|
+
coordinator: body.coordinates ? 'initiator' : 'target', commit: body.commit, targetNonce: nonce(),
|
|
135
|
+
connectingUntil: now + CONNECTING_MS, expiresAt: now + PAIRING_MS, here: false, there: false, applied: false };
|
|
136
|
+
return { value: { protocol: NEARBY_PROTOCOL, requestId: slot.id, nonce: slot.targetNonce, name: local.name(), authority,
|
|
137
|
+
coordinator: slot.coordinator, expiresAt: new Date(slot.expiresAt).toISOString() } };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function incoming(requestId, peer) {
|
|
141
|
+
sweep();
|
|
142
|
+
if (!slot || slot.direction !== 'incoming' || slot.id !== requestId || slot.peer.fingerprint !== peer.fingerprint) {
|
|
143
|
+
throw new PeerError('pairing_not_found', 'This pairing request is no longer open', 404);
|
|
144
|
+
}
|
|
145
|
+
return slot;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function receiveReveal(body, peer) {
|
|
149
|
+
const current = incoming(body.requestId, peer);
|
|
150
|
+
if (!OPEN_STATES.has(current.state)) throw new PeerError('pairing_not_found', 'This pairing request is no longer open', 404);
|
|
151
|
+
if (current.state !== 'connecting' || typeof body.nonce !== 'string' || sha256Hex(commitmentText(body.nonce)) !== current.commit) {
|
|
152
|
+
end(current, 'failed', 'code_mismatch');
|
|
153
|
+
throw new PeerError('pairing_mismatch', 'The pairing answer does not match its commitment', 403);
|
|
154
|
+
}
|
|
155
|
+
current.initiatorNonce = body.nonce;
|
|
156
|
+
current.code = codeOf(current);
|
|
157
|
+
current.state = 'confirm';
|
|
158
|
+
return { value: { state: 'confirm' } };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async function receivePoll(body, peer) {
|
|
162
|
+
const current = incoming(body.requestId, peer);
|
|
163
|
+
if (!OPEN_STATES.has(current.state)) return { value: { state: current.state, reason: current.reason ?? null } };
|
|
164
|
+
if (body.cancel === true) {
|
|
165
|
+
end(current, 'cancelled', 'cancelled_there');
|
|
166
|
+
return { value: { state: 'cancelled' } };
|
|
167
|
+
}
|
|
168
|
+
current.there = body.confirmed === true;
|
|
169
|
+
if (current.state === 'connecting' || !(current.here && current.there)) return { value: { state: current.state, confirmed: current.here } };
|
|
170
|
+
if (current.coordinator === 'target') {
|
|
171
|
+
current.applying ??= Promise.resolve().then(() => local.trustDevice(current.peer));
|
|
172
|
+
try { await current.applying; }
|
|
173
|
+
catch (error) {
|
|
174
|
+
end(current, 'failed', 'trust_failed');
|
|
175
|
+
onError(error);
|
|
176
|
+
return { value: { state: 'failed', reason: 'trust_failed' } };
|
|
177
|
+
}
|
|
178
|
+
current.applied = true;
|
|
179
|
+
// A cancel that arrived while the trust was written takes it back.
|
|
180
|
+
if (!OPEN_STATES.has(current.state)) {
|
|
181
|
+
await local.untrustDevice(current.peer.fingerprint);
|
|
182
|
+
return { value: { state: current.state, reason: current.reason ?? null } };
|
|
183
|
+
}
|
|
184
|
+
end(current, 'paired');
|
|
185
|
+
return { value: { state: current.state, reason: current.reason ?? null } };
|
|
186
|
+
}
|
|
187
|
+
if (body.applied !== true) {
|
|
188
|
+
current.state = 'finishing';
|
|
189
|
+
return { value: { state: 'confirmed', confirmed: true } };
|
|
190
|
+
}
|
|
191
|
+
if (current.joining) return { value: { state: 'paired' } };
|
|
192
|
+
// This computer joins the initiator: first check that it answers where it said.
|
|
193
|
+
const reachable = await local.reachable(current.peer).catch(() => false);
|
|
194
|
+
// Either person may have cancelled while this computer checked.
|
|
195
|
+
if (!OPEN_STATES.has(current.state)) return { value: { state: current.state, reason: current.reason ?? null } };
|
|
196
|
+
if (!reachable) {
|
|
197
|
+
end(current, 'failed', 'coordinator_unreachable');
|
|
198
|
+
return { value: { state: 'failed', reason: 'coordinator_unreachable' } };
|
|
199
|
+
}
|
|
200
|
+
current.joining = true;
|
|
201
|
+
return { value: { state: 'paired' }, after: () => {
|
|
202
|
+
// The pairing reads as paired only once this computer actually joined.
|
|
203
|
+
Promise.resolve().then(() => local.joinCoordinator(current.peer)).then(async () => {
|
|
204
|
+
// Cancelled while joining: leave again, which also makes the other side drop its trust.
|
|
205
|
+
if (!OPEN_STATES.has(current.state)) { await local.leaveCoordinator(current.peer); return; }
|
|
206
|
+
current.applied = true;
|
|
207
|
+
end(current, 'paired');
|
|
208
|
+
}, (error) => {
|
|
209
|
+
end(current, 'failed', 'join_failed');
|
|
210
|
+
onError(error);
|
|
211
|
+
});
|
|
212
|
+
} };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function handle(pathname, body, peer) {
|
|
216
|
+
// Off, or reached on a virtual or VPN adapter: answered as an unknown path.
|
|
217
|
+
if (!local.role().listening || !local.answersOn(peer.localAddress)) throw unknownPath();
|
|
218
|
+
switch (pathname) {
|
|
219
|
+
case '/peer/1/nearby/request': return receiveRequest(body, peer);
|
|
220
|
+
case '/peer/1/nearby/reveal': return receiveReveal(body, peer);
|
|
221
|
+
case '/peer/1/nearby/poll': return receivePoll(body, peer);
|
|
222
|
+
default: throw unknownPath();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// ---- The computer where the person clicked 配对 (initiator) ----
|
|
227
|
+
|
|
228
|
+
async function start(target) {
|
|
229
|
+
const role = local.role();
|
|
230
|
+
if (!role.listening) throw new PeerError('nearby_unavailable', role.reason ?? 'Turn nearby pairing on first', 409);
|
|
231
|
+
if (open()) throw new PeerError('pairing_busy', 'A pairing is already waiting for confirmation', 409);
|
|
232
|
+
attempts.take(`${target.fingerprint}|${target.addresses?.[0] ?? ''}`);
|
|
233
|
+
const current = { id: null, direction: 'outgoing', state: 'connecting', expiresAt: clock() + PAIRING_MS,
|
|
234
|
+
peer: { name: target.name, fingerprint: null, shortFingerprint: target.shortFingerprint },
|
|
235
|
+
coordinator: role.coordinatesOthers ? 'initiator' : 'target', here: false, there: false, applied: false };
|
|
236
|
+
slot = current;
|
|
237
|
+
const stillOpen = () => {
|
|
238
|
+
if (current.state !== 'connecting') throw new PeerError('pairing_cancelled', 'The pairing was cancelled', 409);
|
|
239
|
+
};
|
|
240
|
+
try {
|
|
241
|
+
current.client = await connect(target);
|
|
242
|
+
stillOpen();
|
|
243
|
+
if (local.trusted(current.client.fingerprint)) throw new PeerError('already_paired', 'These computers are already paired', 409);
|
|
244
|
+
const self = await local.identity();
|
|
245
|
+
const authority = await local.authority();
|
|
246
|
+
const initiatorNonce = nonce();
|
|
247
|
+
const answer = await remote(current.client.post('/peer/1/nearby/request', { protocol: NEARBY_PROTOCOL,
|
|
248
|
+
commit: sha256Hex(commitmentText(initiatorNonce)), name: local.name(), authority, coordinates: role.coordinatesOthers,
|
|
249
|
+
...(role.coordinatesOthers ? { port: role.listenPort } : {}) }, { timeoutMs: REQUEST_MS }));
|
|
250
|
+
stillOpen();
|
|
251
|
+
if (answer.protocol !== NEARBY_PROTOCOL || !REQUEST_ID.test(answer.requestId ?? '') || !NONCE.test(answer.nonce ?? '')
|
|
252
|
+
|| !isAuthorityKey(answer.authority) || answer.coordinator !== current.coordinator) {
|
|
253
|
+
throw new PeerError('invalid_pairing', 'The nearby computer answered with an invalid pairing request', 502);
|
|
254
|
+
}
|
|
255
|
+
Object.assign(current, { id: answer.requestId, self: self.fingerprint, initiatorNonce, targetNonce: answer.nonce,
|
|
256
|
+
peer: { fingerprint: current.client.fingerprint, certPem: current.client.certPem,
|
|
257
|
+
name: cleanName(answer.name) || target.name, authority: { keyId: answer.authority.keyId, publicKey: answer.authority.publicKey },
|
|
258
|
+
address: current.client.address, port: current.client.port, reachedAt: current.client.localAddress ?? null } });
|
|
259
|
+
await remote(current.client.post('/peer/1/nearby/reveal', { requestId: current.id, nonce: initiatorNonce }, { timeoutMs: REQUEST_MS }));
|
|
260
|
+
stillOpen();
|
|
261
|
+
current.code = codeOf(current);
|
|
262
|
+
current.state = 'confirm';
|
|
263
|
+
schedulePoll(current);
|
|
264
|
+
} catch (error) {
|
|
265
|
+
// A cancel while connecting leaves a client end() no longer closes.
|
|
266
|
+
current.client?.close();
|
|
267
|
+
current.client = null;
|
|
268
|
+
end(current, 'failed', error.code);
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
return view();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function schedulePoll(current, delayMs = pollMs) {
|
|
275
|
+
clearTimeout(current.timer);
|
|
276
|
+
current.timer = setTimeout(() => poll(current).catch((error) => {
|
|
277
|
+
onError(error);
|
|
278
|
+
end(current, 'failed', 'pairing_failed');
|
|
279
|
+
}), delayMs);
|
|
280
|
+
current.timer.unref?.();
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async function poll(current) {
|
|
284
|
+
if (!OPEN_STATES.has(current.state)) return;
|
|
285
|
+
if (current.expiresAt <= clock()) { settleExpired(current); return; }
|
|
286
|
+
let answer;
|
|
287
|
+
try {
|
|
288
|
+
answer = await remote(current.client.post('/peer/1/nearby/poll', { requestId: current.id, confirmed: current.here,
|
|
289
|
+
applied: current.applied }, { timeoutMs: REQUEST_MS }));
|
|
290
|
+
} catch (error) {
|
|
291
|
+
if (!OPEN_STATES.has(current.state)) return;
|
|
292
|
+
if (error.status === 404) { settleExpired(current, 'cancelled_there'); return; }
|
|
293
|
+
schedulePoll(current);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (!OPEN_STATES.has(current.state)) return;
|
|
297
|
+
current.there = answer.confirmed === true;
|
|
298
|
+
if (answer.state === 'paired') {
|
|
299
|
+
// Accepted only once the person here confirmed, and, when this computer
|
|
300
|
+
// coordinates, only after it wrote its own trust; anything earlier is refused.
|
|
301
|
+
if (!current.here || (current.coordinator === 'initiator' && !current.applied)) {
|
|
302
|
+
end(current, 'failed', 'unconfirmed_answer');
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
current.there = true;
|
|
306
|
+
if (current.coordinator === 'target') {
|
|
307
|
+
await local.joinCoordinator(current.peer);
|
|
308
|
+
if (!OPEN_STATES.has(current.state)) { await local.leaveCoordinator(current.peer); return; }
|
|
309
|
+
}
|
|
310
|
+
end(current, 'paired');
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (['failed', 'cancelled', 'expired'].includes(answer.state)) {
|
|
314
|
+
if (current.applied) await local.untrustDevice(current.peer.fingerprint);
|
|
315
|
+
end(current, answer.state === 'failed' ? 'failed' : 'cancelled', REMOTE_REASONS.has(answer.reason) ? answer.reason
|
|
316
|
+
: answer.state === 'failed' ? 'failed_there' : 'cancelled_there');
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (answer.state === 'confirmed' && current.coordinator === 'initiator' && current.here && !current.applied) {
|
|
320
|
+
current.there = true;
|
|
321
|
+
current.state = 'finishing';
|
|
322
|
+
await local.trustDevice(current.peer);
|
|
323
|
+
current.applied = true;
|
|
324
|
+
if (!OPEN_STATES.has(current.state)) { await local.untrustDevice(current.peer.fingerprint); return; }
|
|
325
|
+
schedulePoll(current, 0);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
schedulePoll(current);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// Once this computer wrote its trust, a lost answer leaves the outcome open:
|
|
332
|
+
// the runtime takes the trust back when the other computer never connects.
|
|
333
|
+
function settleExpired(current, reason = 'expired') {
|
|
334
|
+
if (current.applied) end(current, 'paired');
|
|
335
|
+
else end(current, reason === 'expired' ? 'expired' : 'cancelled', reason);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// ---- The person's own controls on either computer (local only) ----
|
|
339
|
+
|
|
340
|
+
function confirm({ requestId, code }) {
|
|
341
|
+
const current = open();
|
|
342
|
+
if (!current || current.id !== requestId) throw new PeerError('pairing_not_found', 'No pairing is waiting for confirmation here', 404);
|
|
343
|
+
if (current.state !== 'confirm') throw new PeerError('pairing_not_ready', 'The pairing code is not ready yet', 409);
|
|
344
|
+
if (String(code ?? '').replace(/\s+/g, '') !== current.code) {
|
|
345
|
+
stop(current, 'code_mismatch');
|
|
346
|
+
throw new PeerError('code_mismatch', 'That code is not the one on this computer; the pairing was cancelled', 409);
|
|
347
|
+
}
|
|
348
|
+
current.here = true;
|
|
349
|
+
if (current.direction === 'outgoing') schedulePoll(current, 0);
|
|
350
|
+
return view();
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function cancel() {
|
|
354
|
+
const current = open();
|
|
355
|
+
if (current) stop(current, 'cancelled_here');
|
|
356
|
+
return view();
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// Tells the other computer when this one started the pairing; the target's
|
|
360
|
+
// side is seen by the initiator on its next poll. Trust this computer already
|
|
361
|
+
// wrote for it is taken back.
|
|
362
|
+
function stop(current, reason) {
|
|
363
|
+
const { client, id, applied } = current;
|
|
364
|
+
current.client = null;
|
|
365
|
+
end(current, reason === 'code_mismatch' ? 'failed' : 'cancelled', reason);
|
|
366
|
+
if (applied) Promise.resolve().then(() => local.untrustDevice(current.peer.fingerprint)).catch(onError);
|
|
367
|
+
if (!client) return;
|
|
368
|
+
if (!id) { client.close(); return; }
|
|
369
|
+
client.post('/peer/1/nearby/poll', { requestId: id, cancel: true }, { timeoutMs: REQUEST_MS })
|
|
370
|
+
.catch(() => {}).finally(() => client.close());
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function view() {
|
|
374
|
+
sweep();
|
|
375
|
+
if (!slot) return null;
|
|
376
|
+
const fingerprint = slot.peer.fingerprint;
|
|
377
|
+
const thisCoordinates = (slot.coordinator === 'target') === (slot.direction === 'incoming');
|
|
378
|
+
return { requestId: slot.id, direction: slot.direction, state: slot.state, reason: slot.reason ?? null,
|
|
379
|
+
device: { name: slot.peer.name, fingerprint: fingerprint ?? null,
|
|
380
|
+
shortFingerprint: fingerprint ? shortFingerprint(fingerprint) : slot.peer.shortFingerprint ?? null },
|
|
381
|
+
code: ['confirm', 'finishing'].includes(slot.state) ? slot.code : null,
|
|
382
|
+
coordinator: thisCoordinates ? 'this' : 'other', confirmedHere: slot.here, confirmedThere: slot.there,
|
|
383
|
+
expiresAt: new Date(slot.expiresAt).toISOString() };
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// Ends the session's open request; the attempt count stays (it is the store's).
|
|
387
|
+
function close() {
|
|
388
|
+
if (slot && OPEN_STATES.has(slot.state)) stop(slot, 'cancelled_here');
|
|
389
|
+
slot = null;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return { handle, start, confirm, cancel, view, close };
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// The other computer's refusal in this computer's own words and status.
|
|
396
|
+
async function remote(request) {
|
|
397
|
+
try { return await request; }
|
|
398
|
+
catch (error) {
|
|
399
|
+
if (!error?.remote) throw error;
|
|
400
|
+
// A Map, so a code such as __proto__ or toString is just an unknown code.
|
|
401
|
+
const known = typeof error.code === 'string' && REMOTE_REFUSALS.has(error.code);
|
|
402
|
+
const [message, status] = known ? REMOTE_REFUSALS.get(error.code) : ['The other computer refused the pairing', 409];
|
|
403
|
+
throw new PeerError(known ? error.code : 'nearby_refused', message, status);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// What an unknown path answers on the coordinator listener.
|
|
408
|
+
function unknownPath() {
|
|
409
|
+
return new PeerError('not_found', 'Not found', 404);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function deviceKey(peer) {
|
|
413
|
+
return `${peer.fingerprint}|${peer.address ?? ''}`;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function commitmentText(nonce) {
|
|
417
|
+
return `fuli-pair-commit:${NEARBY_PROTOCOL}:${nonce}`;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function validPort(value) {
|
|
421
|
+
return Number.isSafeInteger(value) && value > 0 && value <= 65535;
|
|
422
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { isIP } from 'node:net';
|
|
3
|
+
|
|
4
|
+
import { cleanName } from './coordinator-service.js';
|
|
5
|
+
import { NEARBY_PROTOCOL } from './nearby-pairing.js';
|
|
6
|
+
import { shortFingerprint } from './protocol.js';
|
|
7
|
+
|
|
8
|
+
const PREFIX_LENGTH = 16;
|
|
9
|
+
const PREFIX = /^[0-9a-f]{16}$/;
|
|
10
|
+
// At most this many other computers are listed; the least recently seen goes first.
|
|
11
|
+
const LIST_LIMIT = 32;
|
|
12
|
+
const ADDRESS_LIMIT = 8;
|
|
13
|
+
// Every computer still there answers a fresh query this often; one that has
|
|
14
|
+
// not answered for longer than STALE_MS is no longer listed.
|
|
15
|
+
const REFRESH_MS = 60_000;
|
|
16
|
+
const STALE_MS = 150_000;
|
|
17
|
+
|
|
18
|
+
// While nearby pairing is on, this computer says on the LAN that it runs FULI
|
|
19
|
+
// and lists the others that do. The advertisement carries the service type,
|
|
20
|
+
// the name the person chose, the listening port, a 16-hex fingerprint prefix
|
|
21
|
+
// and the protocol version. The instance and host names are a random id made
|
|
22
|
+
// each time nearby pairing turns on, never the computer's own name; the
|
|
23
|
+
// fingerprint prefix stays the same while it is on, so already paired
|
|
24
|
+
// computers are recognised and a connection can be checked before the code.
|
|
25
|
+
export function createNearbyPresence({ discovery, clock = Date.now }) {
|
|
26
|
+
const seen = new Map();
|
|
27
|
+
let advert = null;
|
|
28
|
+
let browser = null;
|
|
29
|
+
let refresher = null;
|
|
30
|
+
let selfPrefix = null;
|
|
31
|
+
let instanceId = null;
|
|
32
|
+
|
|
33
|
+
function browse(fingerprint) {
|
|
34
|
+
selfPrefix = fingerprint.slice(0, PREFIX_LENGTH);
|
|
35
|
+
if (browser) return;
|
|
36
|
+
browser = discovery.browse({
|
|
37
|
+
onUp: (service) => {
|
|
38
|
+
const entry = entryOf(service);
|
|
39
|
+
if (!entry || entry.fingerprint === selfPrefix) return;
|
|
40
|
+
seen.delete(entry.fingerprint);
|
|
41
|
+
seen.set(entry.fingerprint, { ...entry, seenAt: clock() });
|
|
42
|
+
while (seen.size > LIST_LIMIT) seen.delete(seen.keys().next().value);
|
|
43
|
+
},
|
|
44
|
+
onDown: (service) => { seen.delete(service.txt?.fp); },
|
|
45
|
+
});
|
|
46
|
+
refresher = setInterval(() => browser?.refresh?.(), REFRESH_MS);
|
|
47
|
+
refresher.unref?.();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function advertise({ name, port, fingerprint, addresses = null }) {
|
|
51
|
+
stopAdvertising();
|
|
52
|
+
const prefix = fingerprint.slice(0, PREFIX_LENGTH);
|
|
53
|
+
instanceId ??= randomBytes(4).toString('hex');
|
|
54
|
+
advert = discovery.advertise({ name: `FULI ${instanceId}`, host: `fuli-${instanceId}.local`, port, addresses,
|
|
55
|
+
txt: { v: String(NEARBY_PROTOCOL), fp: prefix, n: name } });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function stopAdvertising() {
|
|
59
|
+
advert?.stop();
|
|
60
|
+
advert = null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function list() {
|
|
64
|
+
const now = clock();
|
|
65
|
+
for (const [key, entry] of seen) if (entry.seenAt + STALE_MS <= now) seen.delete(key);
|
|
66
|
+
return [...seen.values()].map(({ seenAt: _seenAt, ...entry }) => entry);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function stop() {
|
|
70
|
+
stopAdvertising();
|
|
71
|
+
clearInterval(refresher);
|
|
72
|
+
refresher = null;
|
|
73
|
+
browser?.stop();
|
|
74
|
+
browser = null;
|
|
75
|
+
seen.clear();
|
|
76
|
+
instanceId = null;
|
|
77
|
+
discovery.close();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return { browse, advertise, stopAdvertising, stop, list };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Only a well-formed record of this protocol version is listed; anything else
|
|
84
|
+
// on the LAN under the same service type is ignored.
|
|
85
|
+
function entryOf(service) {
|
|
86
|
+
const txt = service?.txt ?? {};
|
|
87
|
+
const port = Number(service?.port);
|
|
88
|
+
const addresses = [...new Set(service?.addresses ?? [])].filter((address) => isIP(address) === 4).slice(0, ADDRESS_LIMIT);
|
|
89
|
+
if (txt.v !== String(NEARBY_PROTOCOL) || !PREFIX.test(txt.fp ?? '') || !Number.isSafeInteger(port)
|
|
90
|
+
|| port < 1 || port > 65535 || !addresses.length) return null;
|
|
91
|
+
return { fingerprint: txt.fp, shortFingerprint: shortFingerprint(txt.fp), name: cleanName(txt.n) || `FULI ${txt.fp.slice(12, 16).toUpperCase()}`,
|
|
92
|
+
addresses, port };
|
|
93
|
+
}
|
|
@@ -54,6 +54,16 @@ export function createNodeStore(path = ':memory:') {
|
|
|
54
54
|
ON CONFLICT(key) DO UPDATE SET value_json = excluded.value_json, updated_at = excluded.updated_at`)
|
|
55
55
|
.run(key, JSON.stringify(value), now());
|
|
56
56
|
},
|
|
57
|
+
// Reads and writes one setting in one immediate transaction, so two
|
|
58
|
+
// processes on the same data directory never both act on the same value.
|
|
59
|
+
// change(current) returns the new value; a throw writes nothing.
|
|
60
|
+
updateSetting(key, change) {
|
|
61
|
+
return transaction(() => {
|
|
62
|
+
const next = change(this.setting(key));
|
|
63
|
+
this.setSetting(key, next);
|
|
64
|
+
return next;
|
|
65
|
+
});
|
|
66
|
+
},
|
|
57
67
|
shares: () => database.prepare('SELECT * FROM shares WHERE revoked_at IS NULL ORDER BY created_at').all().map(shareView),
|
|
58
68
|
share: (bindingId) => shareView(database.prepare('SELECT * FROM shares WHERE binding_id = ? AND revoked_at IS NULL').get(bindingId)),
|
|
59
69
|
// Replaces the owner's share list; a removed share is kept as revoked history.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// Sharing the leads of the projects both computers have, once per pairing.
|
|
2
|
+
//
|
|
3
|
+
// Confirming a pairing (the 6 digits on each computer, or joining with an
|
|
4
|
+
// invitation) is the person's consent, said before they confirm, to share the
|
|
5
|
+
// leads of at most AUTO_SHARE_LIMIT projects the other computer reports having
|
|
6
|
+
// too (the same own repository, matched on the coordinator). It happens only in
|
|
7
|
+
// a group of exactly these two computers: a share is published to the whole
|
|
8
|
+
// group, so with a third computer the person shares with one click instead,
|
|
9
|
+
// told that the others can ask too. More matches than the limit share nothing
|
|
10
|
+
// and leave the same one click, with the number in front of the person.
|
|
11
|
+
//
|
|
12
|
+
// What counts as an answer: the coordinator holds both computers' digests
|
|
13
|
+
// under its current key (a coordinator that moved its listener has a new key,
|
|
14
|
+
// and the other computer sends its digests again only at its next publish).
|
|
15
|
+
// Until then it asks again every attemptMs, for at most `attempts` times; only
|
|
16
|
+
// a real answer or that bound writes the record, which stays until the person
|
|
17
|
+
// turns the LAN roundtable off or revokes the device, so it runs once per
|
|
18
|
+
// paired device. An existing share is never changed and none is removed; a
|
|
19
|
+
// project the person shared or unticked since the pairing keeps their choice.
|
|
20
|
+
export const AUTO_SHARE_LIMIT = 8;
|
|
21
|
+
const ATTEMPT_MS = 10_000;
|
|
22
|
+
// 18 attempts 10 s apart: three minutes, three publish intervals of the other computer.
|
|
23
|
+
const ATTEMPTS = 18;
|
|
24
|
+
const RECORDS = 'autoShared';
|
|
25
|
+
|
|
26
|
+
// port: setting(key), setSetting(key, value), paired(), match(fingerprint),
|
|
27
|
+
// prepare(projects), sharedProjectIds(), touchedSince(projectId, since),
|
|
28
|
+
// writeShares(shares), afterWrite().
|
|
29
|
+
export function createPairingShare({ port, clock = Date.now, attemptMs = ATTEMPT_MS, attempts = ATTEMPTS, onError = () => {} }) {
|
|
30
|
+
// One waiting timer per device, and the pairing (its `since`) an attempt is
|
|
31
|
+
// running for: a new pairing of the same device runs its own attempt, and
|
|
32
|
+
// the older one stops at its next check, so nothing waits on a stale run.
|
|
33
|
+
const timers = new Map();
|
|
34
|
+
const running = new Map();
|
|
35
|
+
const records = () => port.setting(RECORDS) ?? {};
|
|
36
|
+
const write = (fingerprint, record) => port.setSetting(RECORDS, { ...records(), [fingerprint]: record });
|
|
37
|
+
|
|
38
|
+
// A new pairing with this device: nothing happens when it already ran.
|
|
39
|
+
function start(fingerprint) {
|
|
40
|
+
if (records()[fingerprint]) return;
|
|
41
|
+
cancel(fingerprint);
|
|
42
|
+
const since = clock();
|
|
43
|
+
write(fingerprint, { state: 'pending', since, until: since + attemptMs * (attempts - 1) });
|
|
44
|
+
return attempt(fingerprint);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function cancel(fingerprint) {
|
|
48
|
+
clearTimeout(timers.get(fingerprint));
|
|
49
|
+
timers.delete(fingerprint);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function later(fingerprint) {
|
|
53
|
+
cancel(fingerprint);
|
|
54
|
+
const timer = setTimeout(() => {
|
|
55
|
+
timers.delete(fingerprint);
|
|
56
|
+
attempt(fingerprint).catch(onError);
|
|
57
|
+
}, attemptMs);
|
|
58
|
+
timer.unref?.();
|
|
59
|
+
timers.set(fingerprint, timer);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const pending = (fingerprint, since) => {
|
|
63
|
+
const record = records()[fingerprint];
|
|
64
|
+
return record?.state === 'pending' && (since === undefined || record.since === since) ? record : null;
|
|
65
|
+
};
|
|
66
|
+
// Still this pairing, still paired: checked after every wait.
|
|
67
|
+
const current = (fingerprint, record) => Boolean(pending(fingerprint, record.since)) && port.paired();
|
|
68
|
+
|
|
69
|
+
async function attempt(fingerprint) {
|
|
70
|
+
const record = pending(fingerprint);
|
|
71
|
+
if (!record || running.get(fingerprint) === record.since || !port.paired()) return;
|
|
72
|
+
running.set(fingerprint, record.since);
|
|
73
|
+
try {
|
|
74
|
+
const match = await port.match(fingerprint);
|
|
75
|
+
if (!current(fingerprint, record)) return;
|
|
76
|
+
if (!match.settled) return waitMore(fingerprint, record);
|
|
77
|
+
if (match.others > 0) return finish(fingerprint, record, { projects: [], skipped: 'group', matched: match.common.length });
|
|
78
|
+
if (match.common.length > AUTO_SHARE_LIMIT) {
|
|
79
|
+
return finish(fingerprint, record, { projects: [], skipped: 'too_many', matched: match.common.length });
|
|
80
|
+
}
|
|
81
|
+
const fresh = (project) => !port.sharedProjectIds().has(project.projectId) && !port.touchedSince(project.projectId, record.since);
|
|
82
|
+
const prepared = await port.prepare(match.common.filter(fresh));
|
|
83
|
+
if (!current(fingerprint, record)) return;
|
|
84
|
+
// The group is read again: a device that joined while the shares were prepared would see them too.
|
|
85
|
+
const again = await port.match(fingerprint);
|
|
86
|
+
// Checked again right before writing, with no wait in between: a revoke, a
|
|
87
|
+
// turn-off or the person's own save may have come meanwhile.
|
|
88
|
+
if (!current(fingerprint, record)) return;
|
|
89
|
+
if (!again.settled) return waitMore(fingerprint, record);
|
|
90
|
+
if (again.others > 0) return finish(fingerprint, record, { projects: [], skipped: 'group', matched: match.common.length });
|
|
91
|
+
const added = prepared.filter((entry) => fresh(entry.share));
|
|
92
|
+
if (added.length) port.writeShares(added.map((entry) => entry.share));
|
|
93
|
+
finish(fingerprint, record, { projects: added.map(({ share, projectName }) => ({ projectId: share.projectId, projectName })) });
|
|
94
|
+
if (added.length) await port.afterWrite();
|
|
95
|
+
} finally { if (running.get(fingerprint) === record.since) running.delete(fingerprint); }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function waitMore(fingerprint, record) {
|
|
99
|
+
if (clock() < record.until) later(fingerprint);
|
|
100
|
+
else finish(fingerprint, record, { projects: [], skipped: 'unanswered' });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function finish(fingerprint, record, outcome) {
|
|
104
|
+
write(fingerprint, { state: 'done', since: record.since, at: new Date(clock()).toISOString(), ...outcome });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// After a restart a pairing still waiting for its answer asks again.
|
|
108
|
+
function resume() {
|
|
109
|
+
for (const fingerprint of Object.keys(records())) if (pending(fingerprint)) attempt(fingerprint).catch(onError);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// A device revoked here or that left: its record and its waiting end.
|
|
113
|
+
function forget(fingerprint) {
|
|
114
|
+
cancel(fingerprint);
|
|
115
|
+
const { [fingerprint]: gone, ...rest } = records();
|
|
116
|
+
if (gone) port.setSetting(RECORDS, Object.keys(rest).length ? rest : null);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// The LAN roundtable turned off: every record and every waiting end.
|
|
120
|
+
function clear() {
|
|
121
|
+
close();
|
|
122
|
+
port.setSetting(RECORDS, null);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// What each finished pairing shared without a separate tick, or why it shared nothing.
|
|
126
|
+
const view = () => Object.entries(records()).filter(([, record]) => record.state === 'done')
|
|
127
|
+
.map(([nodeId, record]) => ({ nodeId, at: record.at, projects: record.projects,
|
|
128
|
+
...(record.skipped ? { skipped: record.skipped, matched: record.matched ?? 0 } : {}) }));
|
|
129
|
+
|
|
130
|
+
// A pairing still waiting for the coordinator's answer, so the card keeps reading status.
|
|
131
|
+
const waiting = () => Object.keys(records()).some((fingerprint) => pending(fingerprint));
|
|
132
|
+
|
|
133
|
+
function close() {
|
|
134
|
+
for (const timer of timers.values()) clearTimeout(timer);
|
|
135
|
+
timers.clear();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return { start, resume, forget, clear, view, waiting, close };
|
|
139
|
+
}
|