@yuriai/web 0.2.40-beta.5 → 0.2.40-beta.6
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-XDXiFZvA.js} +1 -1
- package/dist/assets/AssistantConversationSurface-B59k-lXE.css +1 -0
- package/dist/assets/AssistantConversationSurface-CQnJaKTn.js +3 -0
- package/dist/assets/AssistantSessionCard-DXY8-wyP.js +2 -0
- package/dist/assets/{AssistantUnreadBadge-vu4ZhTft.js → AssistantUnreadBadge-B-G015yE.js} +1 -1
- package/dist/assets/{AssistantView-CEfEWUIr.js → AssistantView-CasyQbii.js} +1 -1
- package/dist/assets/{DiagramView-Dlzr08J_.js → DiagramView-DhWnsM9v.js} +1 -1
- package/dist/assets/{FadeInOnReveal-DMRmNsau.js → FadeInOnReveal-Ca9EVP3a.js} +1 -1
- package/dist/assets/{GuiPluginPage-DVug4z_p.js → GuiPluginPage-DKOsUpVL.js} +1 -1
- package/dist/assets/{GuiPluginSurface-L43o6Xv8.js → GuiPluginSurface-BfXMBqdD.js} +1 -1
- package/dist/assets/{GuiPluginWindow-tHXkS18H.js → GuiPluginWindow-Dmg2Qui6.js} +1 -1
- package/dist/assets/{Icon-DizeYahT.js → Icon-ChyA050P.js} +1 -1
- package/dist/assets/{ImageLoadingPlaceholder-BZC5m_km.js → ImageLoadingPlaceholder-C8QUF5aV.js} +1 -1
- package/dist/assets/{LoadingImage-Csw4L-Dr.js → LoadingImage-BxRq1dMQ.js} +1 -1
- package/dist/assets/{MarkdownRenderer-D_0iKhQN.js → MarkdownRenderer-CvWLikEO.js} +2 -2
- package/dist/assets/{MarkdownRendererImpl-BZ0XgjS0.js → MarkdownRendererImpl-CcNsQOEn.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-DBd6Glg9.js → MarkstreamRendererImpl-D9W5XXPo.js} +1 -1
- package/dist/assets/MobileDetailNavigation-CnwIZn5g.js +1 -0
- package/dist/assets/{MobileResizableSheet-CQQ7O-2X.js → MobileResizableSheet-Bpp079l7.js} +1 -1
- package/dist/assets/{MobileShareBridge-IO45gM2G.js → MobileShareBridge-C-GpJfF6.js} +1 -1
- package/dist/assets/MobileSurface-CrNI8cYQ.js +2 -0
- package/dist/assets/{MultiRunWindow-fJ3XfntS.js → MultiRunWindow-DvywQkz9.js} +1 -1
- package/dist/assets/{OnboardingScreen-MJS5T5rL.js → OnboardingScreen-BvueSxVk.js} +1 -1
- package/dist/assets/{OverlayScrollbar-jtMYTn1y.js → OverlayScrollbar-CPaH_j8g.js} +1 -1
- package/dist/assets/RemoteAssistantSessionCard-CFWE00xD.js +1 -0
- package/dist/assets/{SettingsView-ZWFLpPSI.js → SettingsView-Df6GCFPI.js} +10 -10
- package/dist/assets/{SettingsWindow-DGRmrIWz.js → SettingsWindow-BpaRjeR-.js} +1 -1
- package/dist/assets/{SetupTourDialog-BYbAubwA.js → SetupTourDialog-DD_4qiTz.js} +1 -1
- package/dist/assets/{TerminalView-CoJ6_9P1.js → TerminalView-CRTtNAfA.js} +1 -1
- package/dist/assets/{ToolOutputDialog-5xBwOJ6a.js → ToolOutputDialog-omGmWntf.js} +1 -1
- package/dist/assets/{VoiceSettings-CN33koSc.js → VoiceSettings-Du-Yd5MF.js} +2 -2
- package/dist/assets/{YuriWordmark-DnFAS-Ko.js → YuriWordmark-B7lmpLRB.js} +1 -1
- package/dist/assets/{capgoAdapter-CCLtBZL1.js → capgoAdapter-CqMX4zC-.js} +1 -1
- package/dist/assets/{checkbox-rOV6DjeG.js → checkbox-KNAgqjPZ.js} +1 -1
- package/dist/assets/{client-uz8O6TPX.js → client-1Fk5IbQR.js} +3 -3
- package/dist/assets/{collapsible-CKswuqAw.js → collapsible-CdiLY07j.js} +1 -1
- package/dist/assets/{context-menu-B4njwT_M.js → context-menu-CO_VRWeV.js} +1 -1
- package/dist/assets/{diagram-BppQ_USn.js → diagram-9b-Aaful.js} +1 -1
- package/dist/assets/{dialog-Bg8MJnOV.js → dialog-8YYmYPFP.js} +1 -1
- package/dist/assets/{fileMentionTouchSelection-D-AdTJVr.js → fileMentionTouchSelection-CLQBqWR8.js} +1 -1
- package/dist/assets/{gitApi-DVx_V1x6.js → gitApi-uhoLUa-e.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/{input-DRjuZMeA.js → input-DK8VTvJw.js} +1 -1
- package/dist/assets/{input-store-CjUOfpyA.js → input-store-CsY-uaSj.js} +1 -1
- package/dist/assets/insertionBoundaries-rYqUxuB-.js +1 -0
- package/dist/assets/{main-D2s9J_jN.js → main-BMx-2MjO.js} +14 -14
- package/dist/assets/main-DzqojuZ1.js +2 -0
- package/dist/assets/{markdownHeightCache-BL99DlhC.js → markdownHeightCache-DAvnT6xF.js} +1 -1
- package/dist/assets/{mcpQueries-HzYMEVWd.js → mcpQueries-CpH8vPf1.js} +1 -1
- package/dist/assets/miniChat-BTE_XpRk.js +2 -0
- package/dist/assets/mobile-BBZOulQ1.js +2 -0
- package/dist/assets/{mobileBackNavigation--ZdrI-Yj.js → mobileBackNavigation-Cq08UPxZ.js} +1 -1
- package/dist/assets/{mobileConnections-C3eGEOPy.js → mobileConnections-ZehAozpe.js} +2 -2
- package/dist/assets/{multirun-CDYNyLBH.js → multirun-Cll2Meol.js} +1 -1
- package/dist/assets/{native-DsqzO52u.js → native-CDqNKjmz.js} +1 -1
- package/dist/assets/{native-config-DOawZfln.js → native-config-DtUZFauV.js} +1 -1
- package/dist/assets/{navigation-Ibk_Pw-q.js → navigation-J3d8PQcs.js} +2 -2
- package/dist/assets/openRemoteProjectSession-oJZpCDPT.js +1 -0
- package/dist/assets/{projectMeta-D1Ytss9U.js → projectMeta-BBpfOmij.js} +1 -1
- package/dist/assets/prompt-attachment-upload-9fjmgafL.js +1 -0
- package/dist/assets/{pwa-CXupOTsD.js → pwa-C8B1Mf_t.js} +1 -1
- package/dist/assets/{queue-abort-optimistic-CQXpIlq6.js → queue-abort-optimistic-B1Uskf6F.js} +1 -1
- package/dist/assets/{react-CgRToPwO.js → react-45rBMaUm.js} +1 -1
- package/dist/assets/{readiness-BfuZm6Yw.js → readiness-CrjBrUa_.js} +2 -2
- package/dist/assets/reference-history-DqfMBWzF.js +1 -0
- package/dist/assets/{remote-input-store-BOdCWpQY.js → remote-input-store-84i8uDyM.js} +1 -1
- package/dist/assets/remoteProjectQueries-B6lrEDMq.js +1 -0
- package/dist/assets/remoteSessionReference-YiGvdabX.js +1 -0
- package/dist/assets/renderElectronMiniChatApp-BuHQB0V8.js +2 -0
- package/dist/assets/renderMobileApp-D_VswCi0.js +29 -0
- package/dist/assets/{runtimeConfig-tHm7o_0I.js → runtimeConfig-CMbNyYbK.js} +1 -1
- package/dist/assets/runtimeEndpointReset-zo-HZQgX.js +151 -0
- package/dist/assets/scheduledTaskNavigation-y5g8D2ee.js +1 -0
- package/dist/assets/{select-B1On-Y4Z.js → select-VWoGVTBZ.js} +1 -1
- package/dist/assets/sessionLookup-JAf5UU7-.js +1 -0
- package/dist/assets/{sortable-tabs-strip-nD1Me06z.js → sortable-tabs-strip-Dbt3TTAs.js} +1 -1
- package/dist/assets/{speechSettingsQueries-BYhNpzDJ.js → speechSettingsQueries-Bidfcv0W.js} +1 -1
- package/dist/assets/{terminalApi-madXrfqA.js → terminalApi-Cq0vjFe1.js} +1 -1
- package/dist/assets/{textarea-Qt06OhhX.js → textarea-vyMsAV5p.js} +1 -1
- package/dist/assets/{tooltip-D382RCy1.js → tooltip-DWqHWi4N.js} +1 -1
- package/dist/assets/{types-CHszLAS3.js → types-DeOkRCgE.js} +1 -1
- package/dist/assets/{useAppFontEffects-CqXrCJVt.js → useAppFontEffects-z382Lhm_.js} +60 -60
- package/dist/assets/useDesktopWindowControlsLayout-BEs7i5qj.js +1 -0
- package/dist/assets/{useDictation-Bs7TWO9r.js → useDictation-e68rFA6y.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-CCKRdyK9.js → useEffectiveDirectory-CcM3S1OQ.js} +1 -1
- package/dist/assets/{useFontPreferences-CPrl1_3z.js → useFontPreferences-CO-L-Gd7.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-BNtVrnSw.js → useMobileNavigationStore-BA0IaUi_.js} +9 -9
- package/dist/assets/{usePluginsStore-bMuGciUE.js → usePluginsStore-BG5MW5LR.js} +1 -1
- package/dist/assets/{useProjectRuntimeAPIs-BFCXBu2J.js → useProjectRuntimeAPIs-Be4gXG7P.js} +1 -1
- package/dist/assets/{useStreamingTextThrottle-C8xAqcgP.js → useStreamingTextThrottle-DylP9HFC.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/index.html +10 -10
- package/dist/mini-chat.html +10 -10
- package/dist/mobile.html +1 -1
- 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 +52 -0
- package/server/lib/remote-hosts/gateway.js +136 -36
- 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 +251 -0
- 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/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,6 +81,22 @@ 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.
|
|
@@ -66,6 +113,11 @@ not proxy capabilities.
|
|
|
66
113
|
- `POST /api/hosts/:hostId/projects {path,label?}`: remote register first, then
|
|
67
114
|
upsert the Hub reference. A Hub disk failure leaves the remote project intact;
|
|
68
115
|
retry associates the same canonical remote path and deterministic Hub ID.
|
|
116
|
+
The UI route and bound session `add-remote` share `gateway.registerProject`.
|
|
117
|
+
It captures an authenticated task lease (and checks an explicit instance ID),
|
|
118
|
+
validates the remote response, persists the reference and emits the same
|
|
119
|
+
project-order tip. Every outcome releases the lease. Route resource-expiry
|
|
120
|
+
tracking listens to this tip, including when an Agent creates the first reference.
|
|
69
121
|
- `PATCH /api/hosts/:hostId/projects/:projectId`: remote metadata write-through;
|
|
70
122
|
cache updates only on successful authority response.
|
|
71
123
|
- `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,6 +121,7 @@ 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,
|
|
114
127
|
...(connections.get(host.id)?.version ? { version: connections.get(host.id).version,
|
|
@@ -120,10 +133,16 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
120
133
|
if (error) store.saveReceipt(connection.host.id, { lastError: publicError(error) });
|
|
121
134
|
if (changed || error) broadcast({ type: 'yuri:host-status', properties: {
|
|
122
135
|
hubId: store.hubId, hostId: connection.host.id, host: hostView(connection.host) } });
|
|
136
|
+
if (changed || error) notifyTasks(connection.host.id, { payload: { type: 'yuri:host-status', properties: {
|
|
137
|
+
hubId: store.hubId, hostId: connection.host.id, host: hostView(connection.host) } } });
|
|
138
|
+
};
|
|
139
|
+
const emit = (hostId, payload, directory) => {
|
|
140
|
+
broadcast({ type: 'yuri:host-event', properties: {
|
|
141
|
+
hubId: store.hubId, hostId, generation: connections.get(hostId)?.generation,
|
|
142
|
+
...(directory ? { directory } : {}), payload } });
|
|
143
|
+
const status = projectRemoteStatusEvent(payload);
|
|
144
|
+
if (status) notifyTasks(hostId, { ...(directory ? { directory } : {}), payload: status });
|
|
123
145
|
};
|
|
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
146
|
const closeConnection = (connection) => {
|
|
128
147
|
connection.controller.abort();
|
|
129
148
|
connection.reader?.stop();
|
|
@@ -136,7 +155,9 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
136
155
|
const current = (connection) => !stopped && !connection.controller.signal.aborted
|
|
137
156
|
&& connections.get(connection.host.id) === connection;
|
|
138
157
|
const resolveHost = async (id) => {
|
|
158
|
+
if (stopped) throw remoteFailure('host_unavailable', 404);
|
|
139
159
|
const host = (await descriptors()).find((entry) => entry.id === id);
|
|
160
|
+
if (stopped) throw remoteFailure('host_unavailable', 404);
|
|
140
161
|
if (!host) {
|
|
141
162
|
const old = connections.get(id);
|
|
142
163
|
if (old) closeConnection(old);
|
|
@@ -188,9 +209,9 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
188
209
|
|| capability.opencode?.compatible === false) throw remoteFailure('remote_incompatible', 409);
|
|
189
210
|
if (capability.opencode?.ready === false && !capability.opencode?.version) throw remoteFailure('remote_service_starting');
|
|
190
211
|
connection.version = capability.version;
|
|
191
|
-
connection.instanceId = capability.instanceId;
|
|
192
212
|
await resolveHost(id);
|
|
193
213
|
if (!current(connection)) throw remoteFailure('stale_host', 409);
|
|
214
|
+
connection.instanceId = store.bindInstance(id, capability.instanceId);
|
|
194
215
|
return connection;
|
|
195
216
|
})().catch((error) => {
|
|
196
217
|
connection.preparing = false;
|
|
@@ -204,7 +225,7 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
204
225
|
}
|
|
205
226
|
return connection.ready;
|
|
206
227
|
};
|
|
207
|
-
const request = async (id, route, init = {}, { refresh = false, streaming = false, longRunning = false } = {}) => {
|
|
228
|
+
const request = async (id, route, init = {}, { refresh = false, streaming = false, longRunning = false, instanceId, scopeGeneration } = {}) => {
|
|
208
229
|
init.signal?.throwIfAborted();
|
|
209
230
|
if (!refresh && (/^\/api\/session(?:\/|\?)/.test(route) || (init.method && !['GET', 'HEAD'].includes(init.method)))) {
|
|
210
231
|
for (const connection of connections.values()) {
|
|
@@ -212,6 +233,8 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
212
233
|
}
|
|
213
234
|
}
|
|
214
235
|
const connection = await ensure(id);
|
|
236
|
+
if (instanceId !== undefined && instanceId !== connection.instanceId) throw remoteFailure('remote_instance_mismatch', 409);
|
|
237
|
+
if (scopeGeneration !== undefined && scopeGeneration !== connection.scopeGeneration) throw remoteFailure('stale_host', 409);
|
|
215
238
|
const generation = connection.fingerprint;
|
|
216
239
|
const deadlineMs = longRunning ? operationTimeoutMs : requestTimeoutMs;
|
|
217
240
|
const headerDeadline = new AbortController();
|
|
@@ -294,7 +317,7 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
294
317
|
return changed;
|
|
295
318
|
};
|
|
296
319
|
const refresh = async (connection) => {
|
|
297
|
-
if (!current(connection)) return;
|
|
320
|
+
if (!current(connection) || !store.projects(connection.host.id).length) return;
|
|
298
321
|
const controller = new AbortController();
|
|
299
322
|
connection.refreshController = controller;
|
|
300
323
|
try {
|
|
@@ -349,7 +372,7 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
349
372
|
if (!controller.signal.aborted) setState(connection, 'degraded', error);
|
|
350
373
|
} finally {
|
|
351
374
|
if (connection.refreshController === controller) connection.refreshController = null;
|
|
352
|
-
if (connection.refreshPreempted && current(connection) &&
|
|
375
|
+
if (connection.refreshPreempted && current(connection) && hasStatusDemand(connection.host.id)) {
|
|
353
376
|
connection.refreshPreempted = false; refreshQueue.add(connection.host.id);
|
|
354
377
|
}
|
|
355
378
|
}
|
|
@@ -372,7 +395,7 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
372
395
|
};
|
|
373
396
|
const enqueueRefresh = (connection) => { refreshQueue.add(connection.host.id); pump(); };
|
|
374
397
|
const startStatus = (connection) => {
|
|
375
|
-
if (connection.reader || !
|
|
398
|
+
if (connection.reader || !hasStatusDemand(connection.host.id)) return;
|
|
376
399
|
const id = connection.host.id;
|
|
377
400
|
connection.reader = createUpstreamSseReader({
|
|
378
401
|
buildUrl: () => 'http://remote.invalid/api/hosts/status-stream',
|
|
@@ -403,7 +426,11 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
403
426
|
const directory = event.directory && event.directory !== 'global' ? event.directory
|
|
404
427
|
: data.location?.directory || data.directory || data.info?.directory
|
|
405
428
|
|| (sessionId ? indexFor(id).findBySessionId(sessionId)?.directory : null);
|
|
406
|
-
if (sessionId && (!directory || !directoryResolver(id)(directory)))
|
|
429
|
+
if (sessionId && (!directory || !directoryResolver(id)(directory))) {
|
|
430
|
+
const payload = projectRemoteStatusEvent(event.payload);
|
|
431
|
+
if (payload) notifyTasks(id, { ...(directory ? { directory } : {}), payload });
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
407
434
|
if (applySessionIndexEvent(indexFor(id), event, Date.now())) {
|
|
408
435
|
store.saveReceipt(id, { lastSyncedAt: Date.now() });
|
|
409
436
|
}
|
|
@@ -443,6 +470,7 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
443
470
|
const hosts = await descriptors();
|
|
444
471
|
if (stopped) return;
|
|
445
472
|
const needed = new Set(statusObservers.size ? store.projects().map((p) => p.hostId) : []);
|
|
473
|
+
for (const id of taskObservers.keys()) if (hasTaskStatus(id)) needed.add(id);
|
|
446
474
|
for (const project of store.projects()) if (!hosts.some((host) => host.id === project.hostId)) store.markProject(project.id, 'host-unavailable');
|
|
447
475
|
for (const connection of connections.values()) {
|
|
448
476
|
const host = hosts.find((h) => h.id === connection.host.id);
|
|
@@ -495,6 +523,7 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
495
523
|
if (!statusObservers.size) {
|
|
496
524
|
refreshQueue.clear();
|
|
497
525
|
for (const connection of connections.values()) {
|
|
526
|
+
if (hasTaskStatus(connection.host.id)) continue;
|
|
498
527
|
connection.reader?.stop(); connection.reader = null;
|
|
499
528
|
connection.refreshController?.abort();
|
|
500
529
|
}
|
|
@@ -505,6 +534,28 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
505
534
|
}
|
|
506
535
|
};
|
|
507
536
|
};
|
|
537
|
+
const retainHost = (hostId, resource, priority = false) => {
|
|
538
|
+
let consumers = interactiveHosts.get(hostId);
|
|
539
|
+
if (!consumers) { consumers = new Set(); interactiveHosts.set(hostId, consumers); }
|
|
540
|
+
consumers.add(resource);
|
|
541
|
+
if (priority) priorityRequests.set(resource, hostId);
|
|
542
|
+
let released = false;
|
|
543
|
+
return () => {
|
|
544
|
+
if (released) return;
|
|
545
|
+
released = true;
|
|
546
|
+
consumers.delete(resource);
|
|
547
|
+
priorityRequests.delete(resource);
|
|
548
|
+
if (!consumers.size) {
|
|
549
|
+
interactiveHosts.delete(hostId);
|
|
550
|
+
if (!stopped && !store.projects(hostId).length) {
|
|
551
|
+
refreshQueue.delete(hostId);
|
|
552
|
+
const connection = connections.get(hostId);
|
|
553
|
+
if (connection) closeConnection(connection);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
pump();
|
|
557
|
+
};
|
|
558
|
+
};
|
|
508
559
|
const unsubscribeAdapter = adapter?.subscribe?.(() => {
|
|
509
560
|
if (stopped || (!scopes.size && !store.projects().length && !connections.size)) return;
|
|
510
561
|
// Observe each saved-catalog change, even while no transport is retained, so
|
|
@@ -515,44 +566,91 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
515
566
|
if (!stopped && (store.projects().length || connections.size)) void reconcile();
|
|
516
567
|
});
|
|
517
568
|
}) || (() => {});
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
569
|
+
const acquireTask = async (id, { instanceId, signal, onEvent } = {}) => {
|
|
570
|
+
signal?.throwIfAborted();
|
|
571
|
+
if (stopped || !adapter) throw remoteFailure('host_unavailable', 404);
|
|
572
|
+
const task = { onEvent, scopeGeneration: null, release: null };
|
|
573
|
+
let tasks = taskObservers.get(id);
|
|
574
|
+
if (!tasks) { tasks = new Set(); taskObservers.set(id, tasks); }
|
|
575
|
+
tasks.add(task);
|
|
576
|
+
const owner = `task:${crypto.randomUUID()}`;
|
|
577
|
+
const controller = new AbortController();
|
|
578
|
+
const releaseObserver = observe(task, owner, { status: false });
|
|
579
|
+
const releaseHost = retainHost(id, task);
|
|
580
|
+
let released = false;
|
|
581
|
+
const release = () => {
|
|
582
|
+
if (released) return;
|
|
583
|
+
released = true;
|
|
584
|
+
signal?.removeEventListener('abort', release);
|
|
585
|
+
controller.abort();
|
|
586
|
+
tasks.delete(task);
|
|
587
|
+
if (!tasks.size) taskObservers.delete(id);
|
|
588
|
+
releaseObserver();
|
|
589
|
+
// Private task owners never acquire client content leases or leave pending lease admissions.
|
|
590
|
+
ownerGenerations.delete(owner);
|
|
591
|
+
releaseHost();
|
|
592
|
+
if (!stopped) void reconcile();
|
|
593
|
+
};
|
|
594
|
+
task.release = release;
|
|
595
|
+
signal?.addEventListener('abort', release, { once: true });
|
|
596
|
+
try {
|
|
597
|
+
const connection = await ensure(id);
|
|
598
|
+
if (released || signal?.aborted) throw remoteFailure('stale_host', 409);
|
|
599
|
+
if (instanceId !== undefined && instanceId !== connection.instanceId) throw remoteFailure('remote_instance_mismatch', 409);
|
|
600
|
+
task.scopeGeneration = connection.scopeGeneration;
|
|
601
|
+
const target = Object.freeze({ hubId: store.hubId, hostId: id, instanceId: connection.instanceId });
|
|
602
|
+
const capturedOptions = (options) => ({ ...options, instanceId: target.instanceId, scopeGeneration: task.scopeGeneration });
|
|
603
|
+
const capturedInit = (init) => {
|
|
604
|
+
controller.signal.throwIfAborted();
|
|
605
|
+
return { ...init, signal: init?.signal ? AbortSignal.any([controller.signal, init.signal]) : controller.signal };
|
|
542
606
|
};
|
|
543
|
-
|
|
607
|
+
startStatus(connection);
|
|
608
|
+
return Object.freeze({ target,
|
|
609
|
+
request: async (route, init, options) => request(id, route, capturedInit(init), capturedOptions(options)),
|
|
610
|
+
json: async (route, init, options) => json(id, route, capturedInit(init), capturedOptions(options)),
|
|
611
|
+
release });
|
|
612
|
+
} catch (error) { release(); throw error; }
|
|
613
|
+
};
|
|
614
|
+
const projectReferencesChanged = (id) => {
|
|
615
|
+
const connection = connections.get(id);
|
|
616
|
+
if (connection && hasStatusDemand(id)) { connection.topologyDirty = true; enqueueRefresh(connection); }
|
|
617
|
+
void reconcile();
|
|
618
|
+
};
|
|
619
|
+
const registerProject = async (id, input, { instanceId, signal } = {}) => {
|
|
620
|
+
const lease = await acquireTask(id, { instanceId, signal });
|
|
621
|
+
try {
|
|
622
|
+
const remote = await lease.json('/api/projects', { method: 'POST', signal,
|
|
623
|
+
headers: { 'content-type': 'application/json' }, body: JSON.stringify({ path: input?.path, label: input?.label }) });
|
|
624
|
+
signal?.throwIfAborted();
|
|
625
|
+
if (typeof remote?.project?.id !== 'string' || !remote.project.id
|
|
626
|
+
|| typeof remote.project.path !== 'string' || !remote.project.path || remote.project.hostId) throw remoteFailure('remote_invalid_project');
|
|
627
|
+
const existed = store.projects(id).some((project) => project.path === remote.project.path);
|
|
628
|
+
const project = store.saveProject(id, remote.project);
|
|
629
|
+
projectReferencesChanged(id);
|
|
630
|
+
if (!existed) broadcast({ type: 'yuri:project-order-changed', properties: { occurredAt: Date.now() } });
|
|
631
|
+
return { project, created: !existed };
|
|
632
|
+
} finally { lease.release(); }
|
|
633
|
+
};
|
|
634
|
+
return {
|
|
635
|
+
store, request, json, reconcile, observe, ensure, releaseOwner, assertProjectDirectory, acquireTask, registerProject,
|
|
636
|
+
projectReferencesChanged, supported: Boolean(adapter),
|
|
637
|
+
retainHost,
|
|
544
638
|
async list() {
|
|
639
|
+
if (stopped) throw remoteFailure('host_unavailable', 404);
|
|
545
640
|
const hosts = await descriptors();
|
|
641
|
+
if (stopped) throw remoteFailure('host_unavailable', 404);
|
|
546
642
|
for (const host of hosts) store.saveHost(host);
|
|
547
643
|
for (const p of store.projects()) if (!hosts.some((h) => h.id === p.hostId)) store.markProject(p.id, 'host-unavailable');
|
|
548
644
|
const removed = new Set(store.projects().filter((p) => p.remoteState === 'host-unavailable' && !hosts.some((h) => h.id === p.hostId)).map((p) => p.hostId));
|
|
549
645
|
const unavailable = [...removed].map((id) => ({ ...(store.savedHosts().find((host) => host.id === id) || { id, name: id, source: 'direct' }),
|
|
646
|
+
...(store.instanceFor(id) ? { instanceId: store.instanceFor(id) } : {}),
|
|
550
647
|
...store.receipt(id), state: 'offline', available: false }));
|
|
551
648
|
return { supported: Boolean(adapter), hubId: store.hubId, hosts: [...hosts.map(hostView), ...unavailable], projects: store.projects(),
|
|
552
649
|
...(!adapter ? { reason: 'pc_hub_required' } : {}) };
|
|
553
650
|
},
|
|
554
651
|
async connect(id) { const connection = await ensure(id); startStatus(connection); return hostView(connection.host); },
|
|
555
652
|
summaries(id) {
|
|
653
|
+
if (stopped) throw remoteFailure('host_unavailable', 404);
|
|
556
654
|
const references = new Set(store.projects(id).map((p) => directoryKey(p.path)));
|
|
557
655
|
if (!references.size) throw remoteFailure('project_not_found', 404);
|
|
558
656
|
const stale = stateFor(id) !== 'connected' || !connections.get(id)?.snapshotReady;
|
|
@@ -633,8 +731,10 @@ export function createRemoteHostGateway({ store, indexDbPath, adapter, broadcast
|
|
|
633
731
|
return socket;
|
|
634
732
|
},
|
|
635
733
|
stop() {
|
|
734
|
+
if (stopped) return;
|
|
636
735
|
unsubscribeAdapter();
|
|
637
736
|
stopped = true; refreshQueue.clear(); observers.clear(); statusObservers.clear();
|
|
737
|
+
for (const tasks of [...taskObservers.values()]) for (const task of [...tasks]) task.release();
|
|
638
738
|
for (const connection of [...connections.values()]) closeConnection(connection);
|
|
639
739
|
for (const service of indexes.values()) service.close();
|
|
640
740
|
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();
|