The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: verify native download boundaries and document transport scope
Tekniumc86200114096
diff --git a/apps/desktop/docs/canonical-gateway-protocol.md b/apps/desktop/docs/canonical-gateway-protocol.mdindex 4c76e931928..082d4f08889 100644--- a/apps/desktop/docs/canonical-gateway-protocol.md+++ b/apps/desktop/docs/canonical-gateway-protocol.md@@ -10,11 +10,24 @@ their existing authentication paths; failure never creates a local replacement.`gateway ensure --json` returns a credential-free endpoint. Native main requestsprivate `session-ticket` grants with exactly `profile_id`, `instance_id` and-`purpose`. WebSocket grants use `interactive`; JSON HTTP requests use+`purpose`. WebSocket grants use `interactive`; JSON and file HTTP requests use`native-http`. Each HTTP retry mints a fresh grant and sends it only in`X-Hermes-Gateway-Ticket`, scoped to the endpoint's exact origin. HTTP credentialsare not stored in the renderer or attached to URLs/public connection descriptors.+Streaming `/api/fs/download` and its 404-only `/api/fs/read-data-url` fallback+use the same captured backend descriptor and session/profile selectors. Each+connection retry and fallback request obtains a new grant. Downloads do not+follow redirects or repeat the save dialog/body write after a stream failure.+The native grant remains primary-profile-only; rejected profile selectors do+not fall back to a remote credential.++Local previews and seekable `hermes-media://stream` playback read the native+filesystem, not gateway HTTP. Remote media remains on its existing token/OAuth+transport (`/api/files/stream`); remote data-URL previews use the JSON IPC API.+Native HTTP grants are never attached to arbitrary image URLs, web previews,+provider voice endpoints, or remote media requests.+## Session and input identities`src/api/canonical-protocol.ts` adapts only native canonical sockets. Creation@@ -48,7 +61,7 @@ RPC adapter and do not yet provide universal revision fencing.The canonical authority currently exposes a narrower RPC set than the fullDesktop application. Unsupported model/tool/slash/session-management RPCs,-cross-window pending-input text projection, non-JSON download authentication,+cross-window pending-input text projection,Windows validated named-pipe bootstrap, and WSL topology require furtherintegration. Successful authenticated transport is not proof of a usable mountedchat or native journal retirement. End-to-end acceptance must compose the HTTPdiff --git a/apps/desktop/electron/gateway-download-transport.test.ts b/apps/desktop/electron/gateway-download-transport.test.tsindex 3a5bb4abe4e..c5a9a9b612f 100644--- a/apps/desktop/electron/gateway-download-transport.test.ts+++ b/apps/desktop/electron/gateway-download-transport.test.ts@@ -7,6 +7,34 @@ import http from 'node:http'import { downloadViaTokenToFile } from './gateway-download-transport'import { destroyKeepaliveAgents } from './api-transport'+test('download transport never follows redirects or retries after the save phase begins', async () => {+ let requests = 0+ let finalized = 0+ const server = http.createServer((req, res) => {+ requests+++ if (req.url === '/redirect') { res.writeHead(302, { Location: '/leak' }); res.end(); return }+ res.end('bytes')+ })+ await new Promise<void>(resolve => server.listen(0, '127.0.0.1', resolve))+ const url = `http://127.0.0.1:${(server.address() as net.AddressInfo).port}`+ const finish = async (res: http.IncomingMessage) => {+ finalized+++ res.resume()+ throw Object.assign(new Error('write ECONNRESET'), { code: 'ECONNRESET' })+ }+ try {+ await expect(downloadViaTokenToFile(url + '/redirect', 'remote-static', {}, finish)).rejects.toThrow('redirect')+ expect(finalized).toBe(0)+ expect(requests).toBe(1)+ await expect(downloadViaTokenToFile(url + '/file', 'remote-static', {}, finish)).rejects.toThrow('write ECONNRESET')+ expect(finalized).toBe(1)+ expect(requests).toBe(2)+ } finally {+ destroyKeepaliveAgents()+ await new Promise<void>(resolve => server.close(() => resolve()))+ }+})+test.skipIf(process.platform === 'win32')('download retries mint a new private grant for every wire attempt and preserve remote auth', async () => {const home = await fs.mkdtemp(path.join(os.tmpdir(), 'download-auth-'))const grants: string[] = []diff --git a/apps/desktop/electron/gateway-file-download.ts b/apps/desktop/electron/gateway-file-download.tsindex ac1ea430cde..7dc5657f458 100644--- a/apps/desktop/electron/gateway-file-download.ts+++ b/apps/desktop/electron/gateway-file-download.ts@@ -2,8 +2,8 @@// main process. Extracted from main.ts so the streaming, data-URL decoding, and// filename derivation are unit-testable without spinning up Electron.//-// The transport wrappers (token / OAuth) live in main.ts because they need-// main-process singletons (https/http, electronNet, the OAuth session). They+// The native/token transport lives in gateway-download-transport.ts; OAuth+// remains in main.ts for the Electron session partition. Both transports// delegate the byte-moving to `pumpStreamToFile` here, which streams the// response into a sibling temp file with backpressure and renames it onto the// user-selected destination only once the body has landed in full — so a large