Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(hook-server): read a native Windows curl's code-page escapes instead of failing silently
Fabricio Casalifa4c4367a931
diff --git a/src/core/agents/hook-server-form.test.ts b/src/core/agents/hook-server-form.test.tsnew file mode 100644index 000000000..b5af88111--- /dev/null+++ b/src/core/agents/hook-server-form.test.ts@@ -0,0 +1,19 @@+import { describe, it, expect } from 'vitest'+import { parseControlBody } from './hook-server'++const FORM = 'application/x-www-form-urlencoded'++describe('parseControlBody — form bodies from a native Windows curl', () => {+ // Git Bash hands the shim's argv to a native curl, which reads it in the ANSI code page: an+ // accented prompt arrives as windows-1252 bytes. It used to throw a URIError that surfaced as an+ // empty 204, and the open failed with no message at all.+ it('reads windows-1252 escapes instead of throwing', () => {+ const body = 'nodeId=n1&arg.prompt=n%E3o+edite%2C+s%F3+diga+%93oi%94'+ expect(parseControlBody(body, FORM).args).toEqual({ prompt: 'não edite, só diga “oi”' })+ })++ it('still reads UTF-8 escapes as UTF-8', () => {+ const body = 'nodeId=n1&arg.prompt=n%C3%A3o+%E2%86%92+sim'+ expect(parseControlBody(body, FORM).args).toEqual({ prompt: 'não → sim' })+ })+})diff --git a/src/core/agents/hook-server.ts b/src/core/agents/hook-server.tsindex 30d256536..e08890485 100644--- a/src/core/agents/hook-server.ts+++ b/src/core/agents/hook-server.ts@@ -122,13 +122,33 @@ function withTimeout<T>(p: Promise<T>, ms: number, fallback: T): Promise<T> {]).finally(() => clearTimeout(timer))}+const CP1252 = new TextDecoder('windows-1252')++/**+ * `decodeURIComponent`, except it never throws. On Windows the shims run under Git Bash but post+ * through a NATIVE curl, which reads its argv in the ANSI code page: `--data-urlencode "arg.prompt=é"`+ * goes out as `%E9`, not `%C3%A9`. `decodeURIComponent` rejects that with a URIError, which escaped+ * the request handler and came back as an empty 204 — the shim exited 1 with no message, and every+ * `open-claude --prompt` holding one accented letter failed silently. Bytes that are not UTF-8 are+ * read as windows-1252, the code page that produced them; characters outside it were already lost+ * to `?` by the argv conversion, before the request existed.+ */+function decodeFormComponent(s: string): string {+ try {+ return decodeURIComponent(s)+ } catch {+ const latin1 = s.replace(/%([0-9a-fA-F]{2})/g, (_, hex: string) => String.fromCharCode(parseInt(hex, 16)))+ return CP1252.decode(Buffer.from(latin1, 'latin1'))+ }+}+// Parses application/x-www-form-urlencoded bodies (what the managed script posts).function parseForm(body: string): Record<string, string> {const out: Record<string, string> = {}for (const pair of body.split('&')) {const i = pair.indexOf('=')if (i < 0) continue- out[decodeURIComponent(pair.slice(0, i))] = decodeURIComponent(pair.slice(i + 1).replace(/\+/g, ' '))+ out[decodeFormComponent(pair.slice(0, i))] = decodeFormComponent(pair.slice(i + 1).replace(/\+/g, ' '))}return out}