@yuriai/web 0.2.40-beta.5 → 0.2.40-beta.7
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/assets/{AgentAvatar-B7KbxN8Y.js → AgentAvatar-BTLQDhXH.js} +1 -1
- package/dist/assets/AssistantConversationSurface-B59k-lXE.css +1 -0
- package/dist/assets/AssistantConversationSurface-CMMUXPIG.js +3 -0
- package/dist/assets/AssistantSessionCard-CZWiX3PR.js +2 -0
- package/dist/assets/{AssistantUnreadBadge-vu4ZhTft.js → AssistantUnreadBadge-B5I8avUG.js} +1 -1
- package/dist/assets/{AssistantView-CEfEWUIr.js → AssistantView-COHkH9qm.js} +1 -1
- package/dist/assets/{DiagramView-Dlzr08J_.js → DiagramView-DiwpnazQ.js} +1 -1
- package/dist/assets/{FadeInOnReveal-DMRmNsau.js → FadeInOnReveal-BxelcK76.js} +1 -1
- package/dist/assets/{GuiPluginPage-DVug4z_p.js → GuiPluginPage-CLD3qMom.js} +1 -1
- package/dist/assets/{GuiPluginSurface-L43o6Xv8.js → GuiPluginSurface-Cra2RdI2.js} +1 -1
- package/dist/assets/{GuiPluginWindow-tHXkS18H.js → GuiPluginWindow-CX4PYIEy.js} +1 -1
- package/dist/assets/{Icon-DizeYahT.js → Icon-BN1Zz-it.js} +1 -1
- package/dist/assets/{ImageLoadingPlaceholder-BZC5m_km.js → ImageLoadingPlaceholder-CZFYt1Xf.js} +1 -1
- package/dist/assets/{LoadingImage-Csw4L-Dr.js → LoadingImage-BCMztEsC.js} +1 -1
- package/dist/assets/{MarkdownRenderer-D_0iKhQN.js → MarkdownRenderer-194nc-0S.js} +2 -2
- package/dist/assets/{MarkdownRendererImpl-BZ0XgjS0.js → MarkdownRendererImpl-0-mJL1TL.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-DBd6Glg9.js → MarkstreamRendererImpl-DaTyfTOH.js} +1 -1
- package/dist/assets/MobileDetailNavigation-CXAtNLak.js +1 -0
- package/dist/assets/{MobileResizableSheet-CQQ7O-2X.js → MobileResizableSheet-BvwMTE7L.js} +1 -1
- package/dist/assets/{MobileShareBridge-IO45gM2G.js → MobileShareBridge-BpO-ZEFG.js} +1 -1
- package/dist/assets/MobileSurface-DIhzZpb9.js +2 -0
- package/dist/assets/{MultiRunWindow-fJ3XfntS.js → MultiRunWindow-ErbLasVC.js} +1 -1
- package/dist/assets/{OnboardingScreen-MJS5T5rL.js → OnboardingScreen-C_rigW9c.js} +1 -1
- package/dist/assets/{OverlayScrollbar-jtMYTn1y.js → OverlayScrollbar-BopzmDhe.js} +1 -1
- package/dist/assets/RemoteAssistantSessionCard-6ktwRL7R.js +1 -0
- package/dist/assets/{SettingsView-ZWFLpPSI.js → SettingsView--qdcJENp.js} +10 -10
- package/dist/assets/{SettingsWindow-DGRmrIWz.js → SettingsWindow-BbJoqFSB.js} +1 -1
- package/dist/assets/{SetupTourDialog-BYbAubwA.js → SetupTourDialog-CT3NmpEw.js} +1 -1
- package/dist/assets/{TerminalView-CoJ6_9P1.js → TerminalView-Cw-p34fv.js} +1 -1
- package/dist/assets/{ToolOutputDialog-5xBwOJ6a.js → ToolOutputDialog-Bph7Tjg_.js} +1 -1
- package/dist/assets/{VoiceSettings-CN33koSc.js → VoiceSettings-B8jYVsYS.js} +2 -2
- package/dist/assets/{YuriLogo-CvyJy_R9.js → YuriLogo-VXtP1vhh.js} +1 -1
- package/dist/assets/{YuriWordmark-DnFAS-Ko.js → YuriWordmark-B7lmpLRB.js} +1 -1
- package/dist/assets/{capgoAdapter-CCLtBZL1.js → capgoAdapter-BQCbf31K.js} +1 -1
- package/dist/assets/{checkbox-rOV6DjeG.js → checkbox-q45nTdJl.js} +1 -1
- package/dist/assets/{client-uz8O6TPX.js → client-1Fk5IbQR.js} +3 -3
- package/dist/assets/{collapsible-CKswuqAw.js → collapsible-GtMRfwfw.js} +1 -1
- package/dist/assets/{context-menu-B4njwT_M.js → context-menu-efudajQ5.js} +1 -1
- package/dist/assets/{diagram-BppQ_USn.js → diagram-D39tZKkF.js} +1 -1
- package/dist/assets/{dialog-Bg8MJnOV.js → dialog-BtnUw5J1.js} +1 -1
- package/dist/assets/{es-Ba3NUCtE.js → es-DuTK1iYh.js} +1 -1
- package/dist/assets/{fileMentionTouchSelection-D-AdTJVr.js → fileMentionTouchSelection-CJ78x95X.js} +1 -1
- package/dist/assets/{fr-CRhp3hyT.js → fr-C_XToFWm.js} +1 -1
- package/dist/assets/{gitApi-DVx_V1x6.js → gitApi-CBnJOeVr.js} +1 -1
- package/dist/assets/gitApiHttp-B0FJaIhU.js +3 -0
- package/dist/assets/{gui-DN2sVP96.js → gui-BMN3-WPc.js} +1 -1
- package/dist/assets/{host-DrGjjO6K.js → host-D9EDWNmx.js} +1 -1
- package/dist/assets/{i18n-RH7UieOS.js → i18n-qHllte6P.js} +1 -1
- package/dist/assets/{input-DRjuZMeA.js → input-KETIwVja.js} +1 -1
- package/dist/assets/{input-store-CjUOfpyA.js → input-store-CsY-uaSj.js} +1 -1
- package/dist/assets/insertionBoundaries-CodoJFbE.js +1 -0
- package/dist/assets/{ja-D-UPjDY2.js → ja-D0pDybpB.js} +1 -1
- package/dist/assets/{ko-x-z9J5z7.js → ko-CAzlaaDJ.js} +1 -1
- package/dist/assets/main-Cgg4eDdr.js +2 -0
- package/dist/assets/{main-D2s9J_jN.js → main-D4t2Tw1D.js} +14 -14
- package/dist/assets/{markdownHeightCache-BL99DlhC.js → markdownHeightCache-BCzMmJds.js} +1 -1
- package/dist/assets/{mcpQueries-HzYMEVWd.js → mcpQueries-BIvH9V8j.js} +1 -1
- package/dist/assets/miniChat-CKw0itTX.js +2 -0
- package/dist/assets/mobile-w1JspRFK.js +2 -0
- package/dist/assets/{mobileBackNavigation--ZdrI-Yj.js → mobileBackNavigation-qI9CYpqm.js} +1 -1
- package/dist/assets/{mobileConnections-C3eGEOPy.js → mobileConnections-Cbt8y7gt.js} +2 -2
- package/dist/assets/{multirun-CDYNyLBH.js → multirun-DOmwPpvA.js} +1 -1
- package/dist/assets/{native-DsqzO52u.js → native-CDqNKjmz.js} +1 -1
- package/dist/assets/{native-config-DOawZfln.js → native-config-BIePc5av.js} +1 -1
- package/dist/assets/{navigation-Ibk_Pw-q.js → navigation-CxKtO3Tu.js} +2 -2
- package/dist/assets/openRemoteProjectSession-DbQYpcai.js +1 -0
- package/dist/assets/{pl-Cqo1FJwM.js → pl-BvjbUcJV.js} +1 -1
- package/dist/assets/{projectMeta-D1Ytss9U.js → projectMeta-AxnyOG6N.js} +1 -1
- package/dist/assets/prompt-attachment-upload-9fjmgafL.js +1 -0
- package/dist/assets/{pt-BR-C930XU1k.js → pt-BR-D71qrP91.js} +1 -1
- package/dist/assets/{pwa-CXupOTsD.js → pwa-BGo_AGpg.js} +1 -1
- package/dist/assets/{queue-abort-optimistic-CQXpIlq6.js → queue-abort-optimistic-CZ3DN-Qo.js} +1 -1
- package/dist/assets/{react-CgRToPwO.js → react-CTU-HLp4.js} +1 -1
- package/dist/assets/{readiness-BfuZm6Yw.js → readiness-Bu7mTG2d.js} +2 -2
- package/dist/assets/reference-history-n4Bw_yN2.js +1 -0
- package/dist/assets/{remote-input-store-BOdCWpQY.js → remote-input-store-84i8uDyM.js} +1 -1
- package/dist/assets/remoteProjectQueries-BZjiHj-6.js +1 -0
- package/dist/assets/remoteSessionReference-CQ0m6LgV.js +1 -0
- package/dist/assets/renderElectronMiniChatApp-B8nOPC1J.js +2 -0
- package/dist/assets/renderMobileApp-BvamjumJ.js +29 -0
- package/dist/assets/{runtimeConfig-tHm7o_0I.js → runtimeConfig-CbHzjd7l.js} +1 -1
- package/dist/assets/runtimeEndpointReset-CMyx_9Vr.js +151 -0
- package/dist/assets/scheduledTaskNavigation-y5g8D2ee.js +1 -0
- package/dist/assets/{select-B1On-Y4Z.js → select-Df_svQ9u.js} +1 -1
- package/dist/assets/sessionLookup-BN82Y0hu.js +1 -0
- package/dist/assets/{sortable-tabs-strip-nD1Me06z.js → sortable-tabs-strip-ByO3KYNT.js} +1 -1
- package/dist/assets/{speechSettingsQueries-BYhNpzDJ.js → speechSettingsQueries-DRAueMIJ.js} +1 -1
- package/dist/assets/src-INJJ62RE.css +2 -0
- package/dist/assets/{store-DunGyOfe.js → store-BOD3jjMl.js} +3 -3
- package/dist/assets/{terminalApi-madXrfqA.js → terminalApi-Cq0vjFe1.js} +1 -1
- package/dist/assets/{textarea-Qt06OhhX.js → textarea-BYUo-pZK.js} +1 -1
- package/dist/assets/{tooltip-D382RCy1.js → tooltip-CBCE3mxe.js} +1 -1
- package/dist/assets/tour-CMXP3Kif.js +1 -0
- package/dist/assets/{types-CHszLAS3.js → types-Bj4r_-Qe.js} +1 -1
- package/dist/assets/{uk-OXQSdzuT.js → uk-C7c1Zece.js} +1 -1
- package/dist/assets/{useAppFontEffects-CqXrCJVt.js → useAppFontEffects-DxY0a-0K.js} +61 -61
- package/dist/assets/useDesktopWindowControlsLayout-I02la7LE.js +1 -0
- package/dist/assets/{useDictation-Bs7TWO9r.js → useDictation-De8WB_Z7.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-CCKRdyK9.js → useEffectiveDirectory-CYzFju6z.js} +1 -1
- package/dist/assets/{useFontPreferences-CPrl1_3z.js → useFontPreferences-CO-L-Gd7.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-BNtVrnSw.js → useMobileNavigationStore-7nhBtrXS.js} +9 -9
- package/dist/assets/{usePluginsStore-bMuGciUE.js → usePluginsStore-1D6-GAgq.js} +1 -1
- package/dist/assets/{useProjectRuntimeAPIs-BFCXBu2J.js → useProjectRuntimeAPIs-CNOqSvoZ.js} +1 -1
- package/dist/assets/{useStreamingTextThrottle-C8xAqcgP.js → useStreamingTextThrottle-BsaiiBxk.js} +1 -1
- package/dist/assets/{vendor-opencode-client-cQ47ywrT.js → vendor-opencode-client-BM2r1f0o.js} +3 -3
- package/dist/assets/{vendor-opencode-plugin-BmdTE4Te.js → vendor-opencode-plugin-ZhpPgHCL.js} +1 -1
- package/dist/assets/{vendor-solid-js-D98iXT7C.js → vendor-solid-js-BBVUd3Hw.js} +1 -1
- package/dist/assets/{zh-CN-B5X8yCZV.js → zh-CN-D2ENuI1-.js} +1 -1
- package/dist/assets/{zh-TW-CF6zr1fk.js → zh-TW-C40BXFhK.js} +1 -1
- package/dist/index.html +11 -11
- package/dist/mini-chat.html +11 -11
- package/dist/mobile.html +2 -2
- package/package.json +1 -1
- package/server/index.js +1 -0
- package/server/lib/assistants/DOCUMENTATION.md +87 -0
- package/server/lib/assistants/assign.js +10 -7
- package/server/lib/assistants/builtin-skills.js +1 -0
- package/server/lib/assistants/builtin-skills.test.js +1 -1
- package/server/lib/assistants/cards.js +6 -1
- package/server/lib/assistants/contact-store.js +22 -5
- package/server/lib/assistants/contact-tools.js +46 -26
- package/server/lib/assistants/execution-target.js +136 -0
- package/server/lib/assistants/opencode-tools.js +22 -9
- package/server/lib/assistants/remote-execution.test.js +378 -0
- package/server/lib/assistants/remote-watch-reconciler.js +43 -0
- package/server/lib/assistants/remote-watch-reconciler.test.js +88 -0
- package/server/lib/assistants/routes.js +1 -0
- package/server/lib/assistants/service.js +302 -99
- package/server/lib/assistants/yuri-project.http.test.js +2 -2
- package/server/lib/gui-customization/DOCUMENTATION.md +8 -2
- package/server/lib/gui-customization/projects-client.mjs +10 -8
- package/server/lib/gui-customization/projects-remote.js +101 -0
- package/server/lib/gui-customization/projects-remote.test.js +125 -0
- package/server/lib/gui-customization/projects.js +30 -6
- package/server/lib/gui-customization/projects.test.js +66 -1
- package/server/lib/gui-customization/session-skill.js +2 -2
- package/server/lib/gui-customization/session-skill.test.js +4 -0
- package/server/lib/gui-customization/skill/SKILL.md +3 -1
- package/server/lib/gui-customization/skill/references/projects.md +30 -3
- package/server/lib/gui-customization/skill/references/remote-connections.md +2 -0
- package/server/lib/opencode/DOCUMENTATION.md +6 -0
- package/server/lib/opencode/feature-routes-runtime.js +2 -0
- package/server/lib/opencode/v2-client.js +9 -4
- package/server/lib/remote-hosts/DOCUMENTATION.md +58 -0
- package/server/lib/remote-hosts/gateway.js +149 -40
- package/server/lib/remote-hosts/json-lifecycle.test.js +35 -0
- package/server/lib/remote-hosts/routes.js +10 -13
- package/server/lib/remote-hosts/routes.test.js +302 -1
- package/server/lib/remote-hosts/store.js +17 -3
- package/server/lib/remote-hosts/store.test.js +19 -0
- package/server/lib/remote-hosts/task-client.js +25 -0
- package/server/lib/remote-hosts/task-client.test.js +60 -0
- package/server/lib/remote-hosts/transport.js +7 -2
- package/server/lib/request-cors.js +1 -1
- package/server/lib/request-cors.test.js +1 -0
- package/server/lib/scheduled-tasks/session-skill.test.js +33 -2
- package/dist/assets/AssistantConversationSurface-BnK_KTBO.js +0 -3
- package/dist/assets/AssistantConversationSurface-n9w_Av0k.css +0 -1
- package/dist/assets/MobileDetailNavigation-xgwvsQuR.js +0 -1
- package/dist/assets/MobileSurface-DmYgZONB.js +0 -2
- package/dist/assets/gitApiHttp-DvTBxvX8.js +0 -3
- package/dist/assets/insertionBoundaries-DZtQt2Ah.js +0 -1
- package/dist/assets/main-BMFY9mtb.js +0 -2
- package/dist/assets/miniChat-BbJ0GKpk.js +0 -2
- package/dist/assets/mobile-_zUth69Z.js +0 -2
- package/dist/assets/prompt-attachment-upload-BNhDXymd.js +0 -1
- package/dist/assets/remoteProjectQueries-CkxdZNw4.js +0 -1
- package/dist/assets/renderElectronMiniChatApp-pJ59iC34.js +0 -2
- package/dist/assets/renderMobileApp-BQFC-gOA.js +0 -29
- package/dist/assets/runtimeEndpointReset-BhHWFNvo.js +0 -150
- package/dist/assets/scheduledTaskNavigation-BIDtQ4wN.js +0 -1
- package/dist/assets/sessionLookup-RcyTTDOy.js +0 -1
- package/dist/assets/src-BZCFf9_1.css +0 -2
- package/dist/assets/tour-CQMBn8gJ.js +0 -1
- package/dist/assets/useDesktopWindowControlsLayout-KH4UP7Gj.js +0 -1
- /package/dist/assets/{sessionLookup-8C8nv-EP.css → reference-history-8C8nv-EP.css} +0 -0
|
@@ -11,6 +11,8 @@ A helper result with `terminal:true` ends the workflow immediately. HTTP 401/403
|
|
|
11
11
|
3. Start each target independently, then poll `list` until every requested instance has `running:false`. Setup saves/reuses the instance, installs or aligns the managed Yuri/OpenCode runtime, establishes SSH forwarding and pushes configuration. A repeated active setup shares the same target operation. A failed target does not cancel the others.
|
|
12
12
|
4. Report each target separately: `phase:ready` confirms SSH/service readiness, `sync:complete` confirms transfer, and `magpie:ready` confirms gateway health. Warnings and failed/missing checks mean partial completion, not success. Authentication/host-key interaction uses the existing native prompt where available; otherwise the user must prepare their SSH key/agent or saved settings. Keep the other targets progressing.
|
|
13
13
|
|
|
14
|
+
If the user also requested a project on that machine, continue with [remote project registration](projects.md#connected-remote-projects-and-sessions) through the separately bound project helper. Rediscover the authenticated target with `remote-hosts` after setup; an SSH readiness receipt alone does not register a project or supply its Hub/Host/instance identity.
|
|
15
|
+
|
|
14
16
|
The local Host is the configuration source, regardless of other windows' selected runtimes. If Magpie is **installed**, setup selects its native configuration/authorization transfer when available, provisions the remote headless CLI and verifies its server gateway. An installed but unconfigured source reports `magpie_source_not_configured`; it does not silently switch to a different credential source. Without Magpie, setup uses OpenCode's credential API. Local-path/file plugins are filtered from SSH configuration copies; registry plugins remain.
|
|
15
17
|
|
|
16
18
|
Remote Magpie startup reuses a healthy gateway or the `yuri-magpie` tmux session. Automatic startup requires a POSIX target with tmux. No desktop environment is needed. Missing tmux, gateway health failure or sync failure leaves a working SSH connection intact with warnings; retry setup after fixing that target. Configuration/accounts already applied remain and existing sync backup rules apply. External/probe-only SSH instances are not modified by this workflow.
|
|
@@ -38,6 +38,12 @@ diagnostics use provider/location/session-active V2 routes and location query
|
|
|
38
38
|
encoding, not removed V1 endpoints.
|
|
39
39
|
|
|
40
40
|
## Entrypoints and structure
|
|
41
|
+
- `v2-client.js` retains default Hub-local runtime write admission. Its internal
|
|
42
|
+
`executionAdmission: 'target-yuri-proxy'` option requires an explicit scoped
|
|
43
|
+
transport and delegates admission to an authenticated target Yuri proxy, never
|
|
44
|
+
to a guessed OpenCode endpoint. `../remote-hosts/task-client.js` is the shared
|
|
45
|
+
official SDK factory for that boundary; Assistant and bound-project helpers use
|
|
46
|
+
it instead of copying SDK requests or inheriting the Hub's runtime contract.
|
|
41
47
|
- `feature-routes-runtime.js` registers the Host-owned history importer before
|
|
42
48
|
the generic proxy, using the official client, project registry and session
|
|
43
49
|
index. Its domain contract is in `../history-import/DOCUMENTATION.md`.
|
|
@@ -307,6 +307,7 @@ export const createFeatureRoutesRuntime = (dependencies) => {
|
|
|
307
307
|
await refreshAssistantAllowedRoots();
|
|
308
308
|
const projectRegistry = createProjectRegistry({ persistSettings, validateDirectoryPath });
|
|
309
309
|
registerProjectsSkill(app, {
|
|
310
|
+
remoteHostGateway: routeDependencies.remoteHostGateway,
|
|
310
311
|
express, getIsSharedOpenCodeService, getOpenCodeAuthHeaders,
|
|
311
312
|
createClient: () => makeOpenCodeV2Client({ baseUrl: buildOpenCodeUrl('/', ''), authHeaders: getOpenCodeAuthHeaders(), getRuntimeContract }),
|
|
312
313
|
registerProject: (input) => projectRegistry.register(input), readSettingsFromDiskStrict, sanitizeProjects,
|
|
@@ -340,6 +341,7 @@ export const createFeatureRoutesRuntime = (dependencies) => {
|
|
|
340
341
|
onSystemSessionPersisted,
|
|
341
342
|
});
|
|
342
343
|
assistantRoutesRuntime = registerAssistantRoutes(app, {
|
|
344
|
+
remoteHostGateway: routeDependencies.remoteHostGateway,
|
|
343
345
|
yuriDataDir,
|
|
344
346
|
dbPath: path.join(yuriDataDir, 'assistants.sqlite'),
|
|
345
347
|
buildOpenCodeUrl,
|
|
@@ -20,19 +20,24 @@ import { wrapFetchWithRuntimeContractGate } from './server-opencode-fetch.js';
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Create the single server-side client for official OpenCode v2 APIs.
|
|
23
|
-
*
|
|
24
|
-
*
|
|
23
|
+
* Local fetch is wrapped with runtime-contract write admission so Host background
|
|
24
|
+
* clients share the proxy gate. Remote task clients explicitly delegate admission
|
|
25
|
+
* to their authenticated target Yuri proxy through a supplied scoped transport.
|
|
25
26
|
*
|
|
26
27
|
* @param {{
|
|
27
28
|
* baseUrl: string,
|
|
28
29
|
* authHeaders?: Record<string, string>,
|
|
29
30
|
* fetchImpl?: typeof fetch,
|
|
30
31
|
* getRuntimeContract?: () => (object | null | undefined),
|
|
32
|
+
* executionAdmission?: 'target-yuri-proxy',
|
|
31
33
|
* }} input
|
|
32
34
|
* @returns {OpenCodeV2Client}
|
|
33
35
|
*/
|
|
34
|
-
export function makeOpenCodeV2Client({ baseUrl, authHeaders, fetchImpl, getRuntimeContract }) {
|
|
35
|
-
|
|
36
|
+
export function makeOpenCodeV2Client({ baseUrl, authHeaders, fetchImpl, getRuntimeContract, executionAdmission }) {
|
|
37
|
+
// A lease-backed remote forwarding client terminates at another Yuri proxy.
|
|
38
|
+
// That proxy, not this process's OpenCode lifecycle, owns live write admission.
|
|
39
|
+
if (executionAdmission === 'target-yuri-proxy' && typeof fetchImpl !== 'function') throw new Error('Target proxy admission requires an explicit scoped transport');
|
|
40
|
+
const gatedFetch = executionAdmission === 'target-yuri-proxy' ? fetchImpl : wrapFetchWithRuntimeContractGate(fetchImpl || fetch, {
|
|
36
41
|
...(typeof getRuntimeContract === 'function' ? { getRuntimeContract } : {}),
|
|
37
42
|
});
|
|
38
43
|
const client = OpenCode.make({
|
|
@@ -9,6 +9,34 @@ SSH-managed PC instances expose the local-project authority protocol.
|
|
|
9
9
|
|
|
10
10
|
## Ownership and persistence
|
|
11
11
|
|
|
12
|
+
Resource authority is distinct from a connection: `remote_host_authority` pins a
|
|
13
|
+
saved `hostId` to the first authenticated capabilities `instanceId`. Reopening,
|
|
14
|
+
credential rotation and transport reconnection preserve the pin. A different
|
|
15
|
+
instance returns `remote_instance_mismatch` before resource reads or mutations;
|
|
16
|
+
old project references and snapshots remain available. Existing databases acquire
|
|
17
|
+
this pin on their first successful admission. Separate SSH/Relay connection records
|
|
18
|
+
and credentials remain separate, even when their `instanceId` matches. Public Hosts
|
|
19
|
+
and project references expose the pinned identity. The optional Hub-only
|
|
20
|
+
`X-Yuri-Target-Instance` request header checks an explicit resource reference and
|
|
21
|
+
is stripped before forwarding upstream.
|
|
22
|
+
|
|
23
|
+
Server-owned work uses `acquireTask(hostId, { instanceId, signal, onEvent })`.
|
|
24
|
+
The returned immutable lease owns its authenticated target, fenced request/JSON
|
|
25
|
+
methods and idempotent release. Plain reads retain a short HTTP demand; `onEvent`
|
|
26
|
+
retains only that Host's existing shared status reader independently of UI windows.
|
|
27
|
+
Task callbacks receive metadata/status events, never a second transcript mirror.
|
|
28
|
+
Tasks release on completion/cancellation; persistent watches own their lease until
|
|
29
|
+
settlement and re-acquire from their explicit target during recovery. No UI and no
|
|
30
|
+
task demand still means zero remote readers/transports. Revocation/retargeting
|
|
31
|
+
rejects stale leases; it never dispatches against the Hub's local OpenCode service.
|
|
32
|
+
Official SDK task mutations use the existing long-running operation budget; reads
|
|
33
|
+
retain the short budget. Status projection retains only allowlisted interruption
|
|
34
|
+
reasons and a `MessageAbortedError` name marker, never raw error messages/stacks.
|
|
35
|
+
Task status also covers authorized remote sessions whose project has not been
|
|
36
|
+
associated with the Hub sidebar. Those events go only to the task consumer and do
|
|
37
|
+
not create project references or index rows. Content-channel messages never reach
|
|
38
|
+
task status callbacks.
|
|
39
|
+
|
|
12
40
|
- `store.js` owns `remote-hosts.sqlite`: stable Hub identity, remote-project
|
|
13
41
|
references, safe presentation fields, connection receipts and bounded-shape
|
|
14
42
|
unread/folder/order snapshots. `(hostId, path)` is unique. Missing hosts retain
|
|
@@ -35,6 +63,9 @@ SSH-managed PC instances expose the local-project authority protocol.
|
|
|
35
63
|
normative E2EE Relay client. `build:remote-host-relay` compiles that client once;
|
|
36
64
|
normal web build/prepack and `build:llm-bridge` include the build. The generated
|
|
37
65
|
bundle ships inside the web server resources, not as a new dependency.
|
|
66
|
+
Both direct and Relay normalize Fetch `HeadersInit` (Headers/record/pairs)
|
|
67
|
+
before merging target authentication case-insensitively; SDK content-type and
|
|
68
|
+
directory headers survive without forwarding the caller's authorization.
|
|
38
69
|
- `routes.js` owns external authorization, host-scoped HTTP/WS routing and demand
|
|
39
70
|
tracking on the existing global client stream. `preview-scope.js` carries only
|
|
40
71
|
a relative host prefix and a nonsecret marker across the remote preview pipe;
|
|
@@ -50,9 +81,31 @@ not proxy capabilities.
|
|
|
50
81
|
|
|
51
82
|
## HTTP protocol
|
|
52
83
|
|
|
84
|
+
The client proxy permits `PUT /api/yuri/sessions/:id/archive` for Host-owned
|
|
85
|
+
archive/unarchive writes and `PUT /api/yuri/sessions/:id/metadata` for metadata
|
|
86
|
+
patches. These are exact method/path capabilities, not a blanket
|
|
87
|
+
allowance for `/api/yuri/sessions/*`; normal client/Host authorization and target
|
|
88
|
+
authority fences still apply.
|
|
89
|
+
|
|
90
|
+
`task-client.js` exports `makeRemoteTaskOpenCodeClient(lease)` for trusted
|
|
91
|
+
in-process Assistant and bound-project consumers. It preserves official SDK
|
|
92
|
+
Request method, headers, JSON body, query and abort signal through `lease.request`.
|
|
93
|
+
The synthetic SDK base origin is never fetched; every route terminates at the
|
|
94
|
+
lease's authenticated target Yuri proxy. That proxy's current runtime gate owns
|
|
95
|
+
write admission (`executionAdmission: 'target-yuri-proxy'`), not the Hub's unrelated
|
|
96
|
+
OpenCode availability. Target rejection propagates without fallback/retry. This
|
|
97
|
+
factory owns neither the lease lifetime nor body persistence; consumers release
|
|
98
|
+
short reads in `finally` and retain background watch demand until settlement.
|
|
99
|
+
|
|
53
100
|
- `GET /api/hosts`: `{supported, hubId, hosts, projects, reason?}`; local SQLite /
|
|
54
101
|
saved descriptors only, no probe. Public hosts contain id/name/source/state,
|
|
55
102
|
available, generation, safe error/timestamps/version, never URLs/credentials.
|
|
103
|
+
Optional `preparationPhase` is live-only, allowlisted SSH bootstrap progress
|
|
104
|
+
while `state` is `connecting`: connecting/checking/installing/updating/starting.
|
|
105
|
+
Phase-only changes use the existing `yuri:host-status` channel; they do not alter
|
|
106
|
+
scope/wire identity or start a new stream. Late callbacks after admission,
|
|
107
|
+
cancellation or failure are ignored; admission/failure clears the phase. Hosts
|
|
108
|
+
without native SSH preparation omit it, retaining generic connection status.
|
|
56
109
|
`scopeGeneration` is an opaque in-process authorization/configuration epoch,
|
|
57
110
|
independent of `generation`, which identifies the physical event connection.
|
|
58
111
|
Releasing an unreferenced short HTTP transport leaves its scope epoch intact;
|
|
@@ -66,6 +119,11 @@ not proxy capabilities.
|
|
|
66
119
|
- `POST /api/hosts/:hostId/projects {path,label?}`: remote register first, then
|
|
67
120
|
upsert the Hub reference. A Hub disk failure leaves the remote project intact;
|
|
68
121
|
retry associates the same canonical remote path and deterministic Hub ID.
|
|
122
|
+
The UI route and bound session `add-remote` share `gateway.registerProject`.
|
|
123
|
+
It captures an authenticated task lease (and checks an explicit instance ID),
|
|
124
|
+
validates the remote response, persists the reference and emits the same
|
|
125
|
+
project-order tip. Every outcome releases the lease. Route resource-expiry
|
|
126
|
+
tracking listens to this tip, including when an Agent creates the first reference.
|
|
69
127
|
- `PATCH /api/hosts/:hostId/projects/:projectId`: remote metadata write-through;
|
|
70
128
|
cache updates only on successful authority response.
|
|
71
129
|
- `DELETE` on that path removes only the reference.
|
|
@@ -8,7 +8,7 @@ import { remoteDeadlineSignal } from './deadline.js';
|
|
|
8
8
|
export const remoteFailure = (code, status = 503) => Object.assign(new Error(code), { code, status });
|
|
9
9
|
const publicError = (error) => {
|
|
10
10
|
const code = error?.status === 401 || error?.status === 403 ? 'remote_authorization_required'
|
|
11
|
-
: ['remote_incompatible', 'remote_ssh_authentication_failed', 'remote_ssh_unavailable', 'remote_relay_unavailable', 'remote_service_starting'].includes(error?.code) ? error.code
|
|
11
|
+
: ['remote_incompatible', 'remote_instance_mismatch', 'remote_ssh_authentication_failed', 'remote_ssh_unavailable', 'remote_relay_unavailable', 'remote_service_starting'].includes(error?.code) ? error.code
|
|
12
12
|
: error?.code === 'host_unavailable' ? 'host_unavailable' : 'remote_unavailable';
|
|
13
13
|
return { code, message: code };
|
|
14
14
|
};
|
|
@@ -32,7 +32,8 @@ export const projectRemoteStatusEvent = (payload) => {
|
|
|
32
32
|
Object.fromEntries(['assistantID', 'name', 'from', 'taskID', 'purpose', 'archivedAt', 'activityUpdatedAt', 'type', 'changedAt']
|
|
33
33
|
.filter((field) => ['string', 'number'].includes(typeof yuri[key][field])).map((field) => [field, yuri[key][field]]))])) };
|
|
34
34
|
}
|
|
35
|
-
if (
|
|
35
|
+
if (['user', 'shutdown', 'superseded', 'inactivity'].includes(value.reason)) result.reason = value.reason;
|
|
36
|
+
if (value.error?.name === 'MessageAbortedError') result.error = { name: 'MessageAbortedError' };
|
|
36
37
|
return result;
|
|
37
38
|
};
|
|
38
39
|
return { type: payload.type, ...(payload.created ? { created: payload.created } : {}),
|
|
@@ -50,6 +51,7 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
50
51
|
const leases = new Map();
|
|
51
52
|
const observers = new Map();
|
|
52
53
|
const statusObservers = new Set();
|
|
54
|
+
const taskObservers = new Map();
|
|
53
55
|
const interactiveHosts = new Map();
|
|
54
56
|
const priorityRequests = new Map();
|
|
55
57
|
const contentChannels = new Map();
|
|
@@ -59,6 +61,16 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
59
61
|
let reconcilePending = false;
|
|
60
62
|
let refreshActive = 0;
|
|
61
63
|
const refreshQueue = new Set();
|
|
64
|
+
const hasTaskStatus = (id) => [...(taskObservers.get(id) || [])].some((task) => task.onEvent);
|
|
65
|
+
const hasStatusDemand = (id) => hasTaskStatus(id) || (statusObservers.size > 0 && store.projects(id).length > 0);
|
|
66
|
+
const notifyTasks = (id, event) => {
|
|
67
|
+
const connection = connections.get(id);
|
|
68
|
+
for (const task of [...(taskObservers.get(id) || [])]) {
|
|
69
|
+
if (!task.onEvent || !task.scopeGeneration || task.scopeGeneration !== connection?.scopeGeneration) continue;
|
|
70
|
+
try { Promise.resolve(task.onEvent(event)).catch(() => {}); }
|
|
71
|
+
catch { /* A task consumer cannot interrupt another owner's event delivery. */ }
|
|
72
|
+
}
|
|
73
|
+
};
|
|
62
74
|
const indexFor = (hostId) => {
|
|
63
75
|
let service = indexes.get(hostId);
|
|
64
76
|
if (!service) {
|
|
@@ -109,21 +121,30 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
109
121
|
};
|
|
110
122
|
const hostView = (host) => ({ id: host.id, name: host.name || host.label || host.id,
|
|
111
123
|
source: host.source, available: true, state: stateFor(host.id), ...store.receipt(host.id),
|
|
124
|
+
...(store.instanceFor(host.id) ? { instanceId: store.instanceFor(host.id) } : {}),
|
|
112
125
|
scopeGeneration: scopes.get(host.id)?.generation,
|
|
113
126
|
generation: connections.get(host.id)?.generation,
|
|
127
|
+
...(connections.get(host.id)?.preparationPhase ? { preparationPhase: connections.get(host.id).preparationPhase } : {}),
|
|
114
128
|
...(connections.get(host.id)?.version ? { version: connections.get(host.id).version,
|
|
115
129
|
capabilities: { remoteProjects: true } } : {}) });
|
|
116
|
-
const setState = (connection, state, error) => {
|
|
130
|
+
const setState = (connection, state, error, preparationPhase) => {
|
|
117
131
|
if (connections.get(connection.host.id) !== connection || stopped) return;
|
|
118
|
-
const changed = connection.state !== state;
|
|
132
|
+
const changed = connection.state !== state || connection.preparationPhase !== preparationPhase;
|
|
119
133
|
connection.state = state;
|
|
134
|
+
connection.preparationPhase = preparationPhase;
|
|
120
135
|
if (error) store.saveReceipt(connection.host.id, { lastError: publicError(error) });
|
|
121
136
|
if (changed || error) broadcast({ type: 'yuri:host-status', properties: {
|
|
122
137
|
hubId: store.hubId, hostId: connection.host.id, host: hostView(connection.host) } });
|
|
138
|
+
if (changed || error) notifyTasks(connection.host.id, { payload: { type: 'yuri:host-status', properties: {
|
|
139
|
+
hubId: store.hubId, hostId: connection.host.id, host: hostView(connection.host) } } });
|
|
140
|
+
};
|
|
141
|
+
const emit = (hostId, payload, directory) => {
|
|
142
|
+
broadcast({ type: 'yuri:host-event', properties: {
|
|
143
|
+
hubId: store.hubId, hostId, generation: connections.get(hostId)?.generation,
|
|
144
|
+
...(directory ? { directory } : {}), payload } });
|
|
145
|
+
const status = projectRemoteStatusEvent(payload);
|
|
146
|
+
if (status) notifyTasks(hostId, { ...(directory ? { directory } : {}), payload: status });
|
|
123
147
|
};
|
|
124
|
-
const emit = (hostId, payload, directory) => broadcast({ type: 'yuri:host-event', properties: {
|
|
125
|
-
hubId: store.hubId, hostId, generation: connections.get(hostId)?.generation,
|
|
126
|
-
...(directory ? { directory } : {}), payload } });
|
|
127
148
|
const closeConnection = (connection) => {
|
|
128
149
|
connection.controller.abort();
|
|
129
150
|
connection.reader?.stop();
|
|
@@ -136,7 +157,9 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
136
157
|
const current = (connection) => !stopped && !connection.controller.signal.aborted
|
|
137
158
|
&& connections.get(connection.host.id) === connection;
|
|
138
159
|
const resolveHost = async (id) => {
|
|
160
|
+
if (stopped) throw remoteFailure('host_unavailable', 404);
|
|
139
161
|
const host = (await descriptors()).find((entry) => entry.id === id);
|
|
162
|
+
if (stopped) throw remoteFailure('host_unavailable', 404);
|
|
140
163
|
if (!host) {
|
|
141
164
|
const old = connections.get(id);
|
|
142
165
|
if (old) closeConnection(old);
|
|
@@ -163,8 +186,14 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
163
186
|
setState(connection, 'connecting');
|
|
164
187
|
connection.ready = (async () => {
|
|
165
188
|
if (connection.host.source === 'ssh' && adapter.prepareHost) {
|
|
166
|
-
|
|
167
|
-
|
|
189
|
+
const preparation = {};
|
|
190
|
+
connection.preparing = preparation;
|
|
191
|
+
const prepared = await adapter.prepareHost(id, { onProgress: (phase) => {
|
|
192
|
+
if (current(connection) && connection.preparing === preparation
|
|
193
|
+
&& ['connecting', 'checking', 'installing', 'updating', 'starting'].includes(phase)) {
|
|
194
|
+
setState(connection, 'connecting', undefined, phase);
|
|
195
|
+
}
|
|
196
|
+
} });
|
|
168
197
|
const latest = await resolveHost(id);
|
|
169
198
|
if (!current(connection) || fingerprint(prepared) !== fingerprint(latest)) throw remoteFailure('stale_host', 409);
|
|
170
199
|
connection.host = prepared;
|
|
@@ -172,6 +201,7 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
172
201
|
connection.scopeGeneration = scopes.get(id)?.generation;
|
|
173
202
|
store.saveHost(prepared);
|
|
174
203
|
connection.preparing = false;
|
|
204
|
+
setState(connection, 'connecting');
|
|
175
205
|
}
|
|
176
206
|
const transport = await transportFactory(connection.host, { signal: connection.controller.signal });
|
|
177
207
|
if (!current(connection)) { transport.close(); throw remoteFailure('stale_host', 409); }
|
|
@@ -188,9 +218,9 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
188
218
|
|| capability.opencode?.compatible === false) throw remoteFailure('remote_incompatible', 409);
|
|
189
219
|
if (capability.opencode?.ready === false && !capability.opencode?.version) throw remoteFailure('remote_service_starting');
|
|
190
220
|
connection.version = capability.version;
|
|
191
|
-
connection.instanceId = capability.instanceId;
|
|
192
221
|
await resolveHost(id);
|
|
193
222
|
if (!current(connection)) throw remoteFailure('stale_host', 409);
|
|
223
|
+
connection.instanceId = store.bindInstance(id, capability.instanceId);
|
|
194
224
|
return connection;
|
|
195
225
|
})().catch((error) => {
|
|
196
226
|
connection.preparing = false;
|
|
@@ -204,7 +234,7 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
204
234
|
}
|
|
205
235
|
return connection.ready;
|
|
206
236
|
};
|
|
207
|
-
const request = async (id, route, init = {}, { refresh = false, streaming = false, longRunning = false } = {}) => {
|
|
237
|
+
const request = async (id, route, init = {}, { refresh = false, streaming = false, longRunning = false, instanceId, scopeGeneration } = {}) => {
|
|
208
238
|
init.signal?.throwIfAborted();
|
|
209
239
|
if (!refresh && (/^\/api\/session(?:\/|\?)/.test(route) || (init.method && !['GET', 'HEAD'].includes(init.method)))) {
|
|
210
240
|
for (const connection of connections.values()) {
|
|
@@ -212,6 +242,8 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
212
242
|
}
|
|
213
243
|
}
|
|
214
244
|
const connection = await ensure(id);
|
|
245
|
+
if (instanceId !== undefined && instanceId !== connection.instanceId) throw remoteFailure('remote_instance_mismatch', 409);
|
|
246
|
+
if (scopeGeneration !== undefined && scopeGeneration !== connection.scopeGeneration) throw remoteFailure('stale_host', 409);
|
|
215
247
|
const generation = connection.fingerprint;
|
|
216
248
|
const deadlineMs = longRunning ? operationTimeoutMs : requestTimeoutMs;
|
|
217
249
|
const headerDeadline = new AbortController();
|
|
@@ -294,7 +326,7 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
294
326
|
return changed;
|
|
295
327
|
};
|
|
296
328
|
const refresh = async (connection) => {
|
|
297
|
-
if (!current(connection)) return;
|
|
329
|
+
if (!current(connection) || !store.projects(connection.host.id).length) return;
|
|
298
330
|
const controller = new AbortController();
|
|
299
331
|
connection.refreshController = controller;
|
|
300
332
|
try {
|
|
@@ -349,7 +381,7 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
349
381
|
if (!controller.signal.aborted) setState(connection, 'degraded', error);
|
|
350
382
|
} finally {
|
|
351
383
|
if (connection.refreshController === controller) connection.refreshController = null;
|
|
352
|
-
if (connection.refreshPreempted && current(connection) &&
|
|
384
|
+
if (connection.refreshPreempted && current(connection) && hasStatusDemand(connection.host.id)) {
|
|
353
385
|
connection.refreshPreempted = false; refreshQueue.add(connection.host.id);
|
|
354
386
|
}
|
|
355
387
|
}
|
|
@@ -372,7 +404,7 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
372
404
|
};
|
|
373
405
|
const enqueueRefresh = (connection) => { refreshQueue.add(connection.host.id); pump(); };
|
|
374
406
|
const startStatus = (connection) => {
|
|
375
|
-
if (connection.reader || !
|
|
407
|
+
if (connection.reader || !hasStatusDemand(connection.host.id)) return;
|
|
376
408
|
const id = connection.host.id;
|
|
377
409
|
connection.reader = createUpstreamSseReader({
|
|
378
410
|
buildUrl: () => 'http://remote.invalid/api/hosts/status-stream',
|
|
@@ -403,7 +435,11 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
403
435
|
const directory = event.directory && event.directory !== 'global' ? event.directory
|
|
404
436
|
: data.location?.directory || data.directory || data.info?.directory
|
|
405
437
|
|| (sessionId ? indexFor(id).findBySessionId(sessionId)?.directory : null);
|
|
406
|
-
if (sessionId && (!directory || !directoryResolver(id)(directory)))
|
|
438
|
+
if (sessionId && (!directory || !directoryResolver(id)(directory))) {
|
|
439
|
+
const payload = projectRemoteStatusEvent(event.payload);
|
|
440
|
+
if (payload) notifyTasks(id, { ...(directory ? { directory } : {}), payload });
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
407
443
|
if (applySessionIndexEvent(indexFor(id), event, Date.now())) {
|
|
408
444
|
store.saveReceipt(id, { lastSyncedAt: Date.now() });
|
|
409
445
|
}
|
|
@@ -443,6 +479,7 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
443
479
|
const hosts = await descriptors();
|
|
444
480
|
if (stopped) return;
|
|
445
481
|
const needed = new Set(statusObservers.size ? store.projects().map((p) => p.hostId) : []);
|
|
482
|
+
for (const id of taskObservers.keys()) if (hasTaskStatus(id)) needed.add(id);
|
|
446
483
|
for (const project of store.projects()) if (!hosts.some((host) => host.id === project.hostId)) store.markProject(project.id, 'host-unavailable');
|
|
447
484
|
for (const connection of connections.values()) {
|
|
448
485
|
const host = hosts.find((h) => h.id === connection.host.id);
|
|
@@ -495,6 +532,7 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
495
532
|
if (!statusObservers.size) {
|
|
496
533
|
refreshQueue.clear();
|
|
497
534
|
for (const connection of connections.values()) {
|
|
535
|
+
if (hasTaskStatus(connection.host.id)) continue;
|
|
498
536
|
connection.reader?.stop(); connection.reader = null;
|
|
499
537
|
connection.refreshController?.abort();
|
|
500
538
|
}
|
|
@@ -505,6 +543,28 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
505
543
|
}
|
|
506
544
|
};
|
|
507
545
|
};
|
|
546
|
+
const retainHost = (hostId, resource, priority = false) => {
|
|
547
|
+
let consumers = interactiveHosts.get(hostId);
|
|
548
|
+
if (!consumers) { consumers = new Set(); interactiveHosts.set(hostId, consumers); }
|
|
549
|
+
consumers.add(resource);
|
|
550
|
+
if (priority) priorityRequests.set(resource, hostId);
|
|
551
|
+
let released = false;
|
|
552
|
+
return () => {
|
|
553
|
+
if (released) return;
|
|
554
|
+
released = true;
|
|
555
|
+
consumers.delete(resource);
|
|
556
|
+
priorityRequests.delete(resource);
|
|
557
|
+
if (!consumers.size) {
|
|
558
|
+
interactiveHosts.delete(hostId);
|
|
559
|
+
if (!stopped && !store.projects(hostId).length) {
|
|
560
|
+
refreshQueue.delete(hostId);
|
|
561
|
+
const connection = connections.get(hostId);
|
|
562
|
+
if (connection) closeConnection(connection);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
pump();
|
|
566
|
+
};
|
|
567
|
+
};
|
|
508
568
|
const unsubscribeAdapter = adapter?.subscribe?.(() => {
|
|
509
569
|
if (stopped || (!scopes.size && !store.projects().length && !connections.size)) return;
|
|
510
570
|
// Observe each saved-catalog change, even while no transport is retained, so
|
|
@@ -515,44 +575,91 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
515
575
|
if (!stopped && (store.projects().length || connections.size)) void reconcile();
|
|
516
576
|
});
|
|
517
577
|
}) || (() => {});
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
578
|
+
const acquireTask = async (id, { instanceId, signal, onEvent } = {}) => {
|
|
579
|
+
signal?.throwIfAborted();
|
|
580
|
+
if (stopped || !adapter) throw remoteFailure('host_unavailable', 404);
|
|
581
|
+
const task = { onEvent, scopeGeneration: null, release: null };
|
|
582
|
+
let tasks = taskObservers.get(id);
|
|
583
|
+
if (!tasks) { tasks = new Set(); taskObservers.set(id, tasks); }
|
|
584
|
+
tasks.add(task);
|
|
585
|
+
const owner = `task:${crypto.randomUUID()}`;
|
|
586
|
+
const controller = new AbortController();
|
|
587
|
+
const releaseObserver = observe(task, owner, { status: false });
|
|
588
|
+
const releaseHost = retainHost(id, task);
|
|
589
|
+
let released = false;
|
|
590
|
+
const release = () => {
|
|
591
|
+
if (released) return;
|
|
592
|
+
released = true;
|
|
593
|
+
signal?.removeEventListener('abort', release);
|
|
594
|
+
controller.abort();
|
|
595
|
+
tasks.delete(task);
|
|
596
|
+
if (!tasks.size) taskObservers.delete(id);
|
|
597
|
+
releaseObserver();
|
|
598
|
+
// Private task owners never acquire client content leases or leave pending lease admissions.
|
|
599
|
+
ownerGenerations.delete(owner);
|
|
600
|
+
releaseHost();
|
|
601
|
+
if (!stopped) void reconcile();
|
|
602
|
+
};
|
|
603
|
+
task.release = release;
|
|
604
|
+
signal?.addEventListener('abort', release, { once: true });
|
|
605
|
+
try {
|
|
606
|
+
const connection = await ensure(id);
|
|
607
|
+
if (released || signal?.aborted) throw remoteFailure('stale_host', 409);
|
|
608
|
+
if (instanceId !== undefined && instanceId !== connection.instanceId) throw remoteFailure('remote_instance_mismatch', 409);
|
|
609
|
+
task.scopeGeneration = connection.scopeGeneration;
|
|
610
|
+
const target = Object.freeze({ hubId: store.hubId, hostId: id, instanceId: connection.instanceId });
|
|
611
|
+
const capturedOptions = (options) => ({ ...options, instanceId: target.instanceId, scopeGeneration: task.scopeGeneration });
|
|
612
|
+
const capturedInit = (init) => {
|
|
613
|
+
controller.signal.throwIfAborted();
|
|
614
|
+
return { ...init, signal: init?.signal ? AbortSignal.any([controller.signal, init.signal]) : controller.signal };
|
|
542
615
|
};
|
|
543
|
-
|
|
616
|
+
startStatus(connection);
|
|
617
|
+
return Object.freeze({ target,
|
|
618
|
+
request: async (route, init, options) => request(id, route, capturedInit(init), capturedOptions(options)),
|
|
619
|
+
json: async (route, init, options) => json(id, route, capturedInit(init), capturedOptions(options)),
|
|
620
|
+
release });
|
|
621
|
+
} catch (error) { release(); throw error; }
|
|
622
|
+
};
|
|
623
|
+
const projectReferencesChanged = (id) => {
|
|
624
|
+
const connection = connections.get(id);
|
|
625
|
+
if (connection && hasStatusDemand(id)) { connection.topologyDirty = true; enqueueRefresh(connection); }
|
|
626
|
+
void reconcile();
|
|
627
|
+
};
|
|
628
|
+
const registerProject = async (id, input, { instanceId, signal } = {}) => {
|
|
629
|
+
const lease = await acquireTask(id, { instanceId, signal });
|
|
630
|
+
try {
|
|
631
|
+
const remote = await lease.json('/api/projects', { method: 'POST', signal,
|
|
632
|
+
headers: { 'content-type': 'application/json' }, body: JSON.stringify({ path: input?.path, label: input?.label }) });
|
|
633
|
+
signal?.throwIfAborted();
|
|
634
|
+
if (typeof remote?.project?.id !== 'string' || !remote.project.id
|
|
635
|
+
|| typeof remote.project.path !== 'string' || !remote.project.path || remote.project.hostId) throw remoteFailure('remote_invalid_project');
|
|
636
|
+
const existed = store.projects(id).some((project) => project.path === remote.project.path);
|
|
637
|
+
const project = store.saveProject(id, remote.project);
|
|
638
|
+
projectReferencesChanged(id);
|
|
639
|
+
if (!existed) broadcast({ type: 'yuri:project-order-changed', properties: { occurredAt: Date.now() } });
|
|
640
|
+
return { project, created: !existed };
|
|
641
|
+
} finally { lease.release(); }
|
|
642
|
+
};
|
|
643
|
+
return {
|
|
644
|
+
store, request, json, reconcile, observe, ensure, releaseOwner, assertProjectDirectory, acquireTask, registerProject,
|
|
645
|
+
projectReferencesChanged, supported: Boolean(adapter),
|
|
646
|
+
retainHost,
|
|
544
647
|
async list() {
|
|
648
|
+
if (stopped) throw remoteFailure('host_unavailable', 404);
|
|
545
649
|
const hosts = await descriptors();
|
|
650
|
+
if (stopped) throw remoteFailure('host_unavailable', 404);
|
|
546
651
|
for (const host of hosts) store.saveHost(host);
|
|
547
652
|
for (const p of store.projects()) if (!hosts.some((h) => h.id === p.hostId)) store.markProject(p.id, 'host-unavailable');
|
|
548
653
|
const removed = new Set(store.projects().filter((p) => p.remoteState === 'host-unavailable' && !hosts.some((h) => h.id === p.hostId)).map((p) => p.hostId));
|
|
549
654
|
const unavailable = [...removed].map((id) => ({ ...(store.savedHosts().find((host) => host.id === id) || { id, name: id, source: 'direct' }),
|
|
655
|
+
...(store.instanceFor(id) ? { instanceId: store.instanceFor(id) } : {}),
|
|
550
656
|
...store.receipt(id), state: 'offline', available: false }));
|
|
551
657
|
return { supported: Boolean(adapter), hubId: store.hubId, hosts: [...hosts.map(hostView), ...unavailable], projects: store.projects(),
|
|
552
658
|
...(!adapter ? { reason: 'pc_hub_required' } : {}) };
|
|
553
659
|
},
|
|
554
660
|
async connect(id) { const connection = await ensure(id); startStatus(connection); return hostView(connection.host); },
|
|
555
661
|
summaries(id) {
|
|
662
|
+
if (stopped) throw remoteFailure('host_unavailable', 404);
|
|
556
663
|
const references = new Set(store.projects(id).map((p) => directoryKey(p.path)));
|
|
557
664
|
if (!references.size) throw remoteFailure('project_not_found', 404);
|
|
558
665
|
const stale = stateFor(id) !== 'connected' || !connections.get(id)?.snapshotReady;
|
|
@@ -633,8 +740,10 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
633
740
|
return socket;
|
|
634
741
|
},
|
|
635
742
|
stop() {
|
|
743
|
+
if (stopped) return;
|
|
636
744
|
unsubscribeAdapter();
|
|
637
745
|
stopped = true; refreshQueue.clear(); observers.clear(); statusObservers.clear();
|
|
746
|
+
for (const tasks of [...taskObservers.values()]) for (const task of [...tasks]) task.release();
|
|
638
747
|
for (const connection of [...connections.values()]) closeConnection(connection);
|
|
639
748
|
for (const service of indexes.values()) service.close();
|
|
640
749
|
scopes.clear();
|
|
@@ -53,3 +53,38 @@ it('credential ABA after body headers still rejects a late parsed value and clea
|
|
|
53
53
|
await bodyStarted; host.clientToken = 'fixture-b'; await gateway.list(); host.clientToken = 'fixture-a'; await gateway.list();
|
|
54
54
|
finish({ value: 'stale' }); await assertion; expect(vi.getTimerCount()).toBe(0);
|
|
55
55
|
});
|
|
56
|
+
|
|
57
|
+
it.each(['abort', 'retarget'])('remote registration never persists a late project after %s', async (mode) => {
|
|
58
|
+
let finish; let started;
|
|
59
|
+
const bodyStarted = new Promise(resolve => { started = resolve; });
|
|
60
|
+
const host = await setup(async () => ({ ok: true, json: () => { started(); return new Promise(resolve => { finish = resolve; }); } }));
|
|
61
|
+
const controller = new AbortController();
|
|
62
|
+
const pending = gateway.registerProject('host', { path: '/repo' }, { instanceId: 'fixture', signal: controller.signal });
|
|
63
|
+
const assertion = expect(pending).rejects.toThrow();
|
|
64
|
+
await bodyStarted;
|
|
65
|
+
if (mode === 'abort') controller.abort();
|
|
66
|
+
else { host.clientToken = 'replacement'; await gateway.list(); }
|
|
67
|
+
finish({ project: { id: 'remote', path: '/repo' } });
|
|
68
|
+
await assertion;
|
|
69
|
+
expect(gateway.store.projects()).toEqual([]);
|
|
70
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it.each([{}, { project: { id: 'remote', path: '/repo', hostId: 'nested-host' } }, { project: { id: 'remote', path: {} } }])('rejects malformed remote registration responses without saving a reference: %j', async (response) => {
|
|
74
|
+
await setup(async () => Response.json(response));
|
|
75
|
+
await expect(gateway.registerProject('host', { path: '/repo' }, { instanceId: 'fixture' })).rejects.toMatchObject({ code: 'remote_invalid_project' });
|
|
76
|
+
expect(gateway.store.projects()).toEqual([]);
|
|
77
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('uses only the remote canonical path when deduplicating registrations from different aliases', async () => {
|
|
81
|
+
const fetch = vi.fn(async () => Response.json({ project: { id: 'remote', path: '/remote-canonical', label: 'Preserved' } }));
|
|
82
|
+
await setup(fetch);
|
|
83
|
+
const first = await gateway.registerProject('host', { path: '/remote-alias' }, { instanceId: 'fixture' });
|
|
84
|
+
const second = await gateway.registerProject('host', { path: '/another-remote-alias' }, { instanceId: 'fixture' });
|
|
85
|
+
expect(first).toMatchObject({ created: true, project: { path: '/remote-canonical' } });
|
|
86
|
+
expect(second).toEqual({ project: first.project, created: false });
|
|
87
|
+
expect(gateway.store.projects()).toEqual([first.project]);
|
|
88
|
+
expect(fetch.mock.calls.map(([, init]) => JSON.parse(init.body).path)).toEqual(['/remote-alias', '/another-remote-alias']);
|
|
89
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
90
|
+
});
|
|
@@ -24,6 +24,7 @@ const safeRoute = (route, method) => {
|
|
|
24
24
|
if (/^\/api\/(hosts|client-auth|system|gui-network|remote-desktop|assistants|scheduled-tasks)(\/|$)/.test(pathname)
|
|
25
25
|
|| /^\/api\/yuri\/(transcript-cache|config-sync|relay|realtime-proxy)(\/|$)/.test(pathname)) return false;
|
|
26
26
|
if (method !== 'GET' && method !== 'HEAD' && /^\/api\/(config|provider|plugin|mcp|global|agent|command|skill|settings|opencode|push)(\/|$)/.test(pathname)) return false;
|
|
27
|
+
if (/^\/api\/yuri\/sessions\/[^/]+\/(archive|metadata)$/.test(pathname)) return method === 'PUT';
|
|
27
28
|
return /^\/api\/(info|fs|git|terminal|preview|session|sessions|session-folders|session-order|permission|permission-auto-accept|question|question-auto-delegate|form|command|agent|provider|config|plugin|skill|mcp|find|file|vcs|path|project|projects|experimental|location|session-activity)(\/|$)/.test(pathname)
|
|
28
29
|
|| /^\/api\/yuri\/(session|session-index|session-unread|session-folders|session-order|message-queue|content-search|events)(\/|$)/.test(pathname);
|
|
29
30
|
};
|
|
@@ -32,7 +33,7 @@ const report = (res, error) => {
|
|
|
32
33
|
const code = error?.code || 'remote_unavailable';
|
|
33
34
|
// Transport failures may contain URL credentials or content. Never serialize
|
|
34
35
|
// arbitrary upstream Error.message or log the request/response body.
|
|
35
|
-
const allowed = new Set(['remote_incompatible', 'remote_authorization_required', 'host_unavailable',
|
|
36
|
+
const allowed = new Set(['remote_incompatible', 'remote_instance_mismatch', 'remote_authorization_required', 'host_unavailable',
|
|
36
37
|
'project_not_found', 'validation_error', 'stale_host', 'subscription_not_found', 'content_capacity', 'remote_request_failed',
|
|
37
38
|
'remote_ssh_authentication_failed', 'remote_ssh_unavailable', 'remote_relay_unavailable', 'remote_service_starting']);
|
|
38
39
|
const publicCode = allowed.has(code) ? code : 'remote_unavailable';
|
|
@@ -71,6 +72,9 @@ export function registerRemoteHostRoutes(app, { gateway, getAuth, server, isRequ
|
|
|
71
72
|
}, Math.min(delay, 2147483647));
|
|
72
73
|
timer.unref?.(); expiryTimers.set(owner, timer);
|
|
73
74
|
};
|
|
75
|
+
const unsubscribeProjectChanges = broadcaster.subscribe((payload) => {
|
|
76
|
+
if (payload.type === 'yuri:project-order-changed') for (const owner of resources.keys()) armExpiry(owner);
|
|
77
|
+
});
|
|
74
78
|
const authorize = async (req, res, { aggregate = true } = {}) => {
|
|
75
79
|
const clientRequest = Object.create(req);
|
|
76
80
|
clientRequest.headers = { ...req.headers };
|
|
@@ -225,17 +229,9 @@ export function registerRemoteHostRoutes(app, { gateway, getAuth, server, isRequ
|
|
|
225
229
|
});
|
|
226
230
|
app.post('/api/hosts/:hostId/projects', parseMutation, async (req, res) => {
|
|
227
231
|
try {
|
|
228
|
-
|
|
229
|
-
signal: req.remoteHostSignal,
|
|
230
|
-
|
|
231
|
-
if (req.remoteHostSignal.aborted) throw remoteFailure('remote_authorization_required', 401);
|
|
232
|
-
if (!remote.project?.id || !remote.project?.path || remote.project.hostId) throw remoteFailure('remote_invalid_project');
|
|
233
|
-
const existed = store.projects(req.params.hostId).some((p) => p.path === remote.project.path);
|
|
234
|
-
const project = store.saveProject(req.params.hostId, remote.project);
|
|
235
|
-
for (const owner of resources.keys()) armExpiry(owner);
|
|
236
|
-
gateway.projectReferencesChanged(req.params.hostId);
|
|
237
|
-
if (!existed) broadcaster({ type: 'yuri:project-order-changed', properties: { occurredAt: Date.now() } });
|
|
238
|
-
res.json({ project, created: !existed });
|
|
232
|
+
res.json(await gateway.registerProject(req.params.hostId, req.body, {
|
|
233
|
+
signal: req.remoteHostSignal, instanceId: req.get('x-yuri-target-instance') || undefined,
|
|
234
|
+
}));
|
|
239
235
|
} catch (error) { report(res, error); }
|
|
240
236
|
});
|
|
241
237
|
app.patch('/api/hosts/:hostId/projects/:projectId', parseMutation, async (req, res) => {
|
|
@@ -317,6 +313,7 @@ export function registerRemoteHostRoutes(app, { gateway, getAuth, server, isRequ
|
|
|
317
313
|
|| url.pathname === '/api/yuri/events';
|
|
318
314
|
const response = await gateway.request(req.params.hostId, `${url.pathname}${url.search}`, init, {
|
|
319
315
|
streaming, longRunning: streaming || !['GET', 'HEAD'].includes(req.method),
|
|
316
|
+
...(req.headers['x-yuri-target-instance'] !== undefined ? { instanceId: req.headers['x-yuri-target-instance'] } : {}),
|
|
320
317
|
});
|
|
321
318
|
res.status(response.status);
|
|
322
319
|
const location = response.headers.get('location');
|
|
@@ -423,7 +420,7 @@ export function registerRemoteHostRoutes(app, { gateway, getAuth, server, isRequ
|
|
|
423
420
|
return Boolean(owner && (!expirations.has(owner) || expirations.get(owner) > Date.now()));
|
|
424
421
|
},
|
|
425
422
|
stop() {
|
|
426
|
-
revoke(); server.off('upgrade', onUpgrade);
|
|
423
|
+
revoke(); unsubscribeProjectChanges(); server.off('upgrade', onUpgrade);
|
|
427
424
|
for (const timer of expiryTimers.values()) clearTimeout(timer);
|
|
428
425
|
authorizedResources.clear();
|
|
429
426
|
for (const entries of resources.values()) for (const close of [...entries]) close();
|