@vellumai/assistant 0.11.7-dev.202608272311.f90ed23 → 0.11.7-dev.202608281503.cbafd6c

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.
Files changed (59) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/bundled-asset.test.ts +22 -1
  3. package/src/__tests__/credential-record-write-through.test.ts +1 -4
  4. package/src/__tests__/oauth-commands-routes.test.ts +21 -0
  5. package/src/__tests__/plugin-app-serve-routes.test.ts +2 -2
  6. package/src/acp/agent-process.ts +1 -0
  7. package/src/acp/auto-install.ts +1 -0
  8. package/src/acp/client-handler.ts +1 -0
  9. package/src/bundler/app-compiler.ts +1 -0
  10. package/src/bundler/compiler-tools.ts +1 -0
  11. package/src/bundler/package-resolver.ts +1 -0
  12. package/src/cli/commands/db/refresh.ts +1 -0
  13. package/src/cli/commands/oauth/index.help.ts +6 -3
  14. package/src/cli/commands/oauth/request.test.ts +37 -0
  15. package/src/cli/commands/oauth/request.ts +7 -6
  16. package/src/cli/lib/bundled-marketplace.json +1 -1
  17. package/src/cli/lib/install-from-github.ts +2 -0
  18. package/src/cli/lib/install-plugin-dependencies.ts +1 -0
  19. package/src/cli/lib/merge-plugin-tree.ts +1 -0
  20. package/src/cli/lib/publish-plugin.ts +4 -1
  21. package/src/config/skills.ts +2 -1
  22. package/src/daemon/daemon-control.ts +1 -0
  23. package/src/daemon/install-assistant-command.ts +1 -0
  24. package/src/daemon/video-thumbnail.ts +1 -1
  25. package/src/monitoring/page-cache.ts +5 -1
  26. package/src/oauth/byo-connection.test.ts +22 -0
  27. package/src/oauth/byo-connection.ts +11 -5
  28. package/src/oauth/connection.ts +3 -2
  29. package/src/oauth/platform-connection.test.ts +35 -0
  30. package/src/oauth/platform-connection.ts +18 -13
  31. package/src/outbound-proxy/certs.ts +5 -4
  32. package/src/persistence/embeddings/qdrant-manager.ts +1 -0
  33. package/src/runtime/routes/archive-utils.ts +6 -1
  34. package/src/runtime/routes/debug-bash-routes.ts +1 -0
  35. package/src/runtime/routes/migration-routes.ts +1 -3
  36. package/src/runtime/routes/oauth-commands-routes.ts +18 -5
  37. package/src/schedule/run-script.ts +1 -0
  38. package/src/skills/catalog-install.ts +3 -1
  39. package/src/skills/clawhub.ts +1 -0
  40. package/src/skills/inline-command-runner.ts +1 -0
  41. package/src/tools/browser/browser-manager.ts +1 -0
  42. package/src/tools/browser/runtime-check.ts +2 -0
  43. package/src/tools/credentials/metadata-store.ts +6 -9
  44. package/src/tools/credentials/store.ts +0 -2
  45. package/src/tools/host-terminal/host-shell.ts +2 -0
  46. package/src/tools/skills/sandbox-runner.ts +1 -0
  47. package/src/tools/terminal/shell.ts +2 -0
  48. package/src/util/bun-runtime.ts +1 -0
  49. package/src/util/bundled-asset.ts +9 -1
  50. package/src/util/disk-usage.ts +1 -0
  51. package/src/util/file-use.ts +4 -1
  52. package/src/util/image-conversion.ts +1 -0
  53. package/src/util/oauth-request-body.test.ts +59 -0
  54. package/src/util/oauth-request-body.ts +56 -5
  55. package/src/util/process-table.ts +2 -0
  56. package/src/util/read-stdin.ts +5 -0
  57. package/src/util/spawn.ts +1 -0
  58. package/src/workspace/git-service.ts +1 -0
  59. package/src/workspace/migrations/010-app-dir-rename.ts +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.11.7-dev.202608272311.f90ed23",
3
+ "version": "0.11.7-dev.202608281503.cbafd6c",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -3,7 +3,7 @@ import { tmpdir } from "node:os";
3
3
  import { join } from "node:path";
4
4
  import { afterEach, beforeEach, describe, expect, test } from "bun:test";
5
5
 
6
- import { resolveBundledDir } from "../util/bundled-asset.js";
6
+ import { isBunVirtualPath, resolveBundledDir } from "../util/bundled-asset.js";
7
7
 
8
8
  let tempDir: string;
9
9
 
@@ -17,6 +17,13 @@ afterEach(() => {
17
17
  });
18
18
 
19
19
  describe("resolveBundledDir", () => {
20
+ test("recognizes Bun virtual paths on Unix and Windows", () => {
21
+ expect(isBunVirtualPath("/$bunfs/root/src/config")).toBeTrue();
22
+ expect(isBunVirtualPath("B:\\~BUN\\root")).toBeTrue();
23
+ expect(isBunVirtualPath("B:/~BUN/root/src/config")).toBeTrue();
24
+ expect(isBunVirtualPath("C:\\dev\\vellum-assistant")).toBeFalse();
25
+ });
26
+
20
27
  test("source mode: returns join(callerDir, relativePath) when callerDir is a normal path", () => {
21
28
  const result = resolveBundledDir(
22
29
  "/some/source/path",
@@ -82,6 +89,20 @@ describe("resolveBundledDir", () => {
82
89
  expect(result).toBe(join(binDir, "templates"));
83
90
  });
84
91
 
92
+ test("resolves Windows Bun virtual paths beside the executable", () => {
93
+ const binDir = join(tempDir, "bin");
94
+ mkdirSync(join(binDir, "default-plugins"), { recursive: true });
95
+
96
+ process.execPath = join(binDir, "vellum-daemon.exe");
97
+
98
+ const result = resolveBundledDir(
99
+ "B:\\~BUN\\root",
100
+ ".",
101
+ "default-plugins",
102
+ );
103
+ expect(result).toBe(join(binDir, "default-plugins"));
104
+ });
105
+
85
106
  test("falls back to source path when neither Resources nor execDir have the asset", () => {
86
107
  const binDir = join(tempDir, "bin");
87
108
  mkdirSync(binDir, { recursive: true });
@@ -6,7 +6,6 @@ import type { CredentialRecord } from "@vellumai/service-contracts/credential-rp
6
6
  import type { CredentialRecordBackend } from "../security/ces-rpc-record-backend.js";
7
7
  import {
8
8
  _setMetadataPath,
9
- persistCredentialMetadata,
10
9
  setCredentialRecordBackend,
11
10
  upsertCredentialMetadata,
12
11
  } from "../tools/credentials/metadata-store.js";
@@ -54,7 +53,6 @@ describe("CES credential record write-through", () => {
54
53
  const created = upsertCredentialMetadata("slack_channel", "bot_token", {
55
54
  allowedTools: ["bash"],
56
55
  });
57
- await persistCredentialMetadata(created);
58
56
 
59
57
  const stored = backend.store.get(
60
58
  credentialKey("slack_channel", "bot_token"),
@@ -68,10 +66,9 @@ describe("CES credential record write-through", () => {
68
66
  setCredentialRecordBackend(backend);
69
67
  _setMetadataPath("/tmp/does-not-write-through-metadata.json");
70
68
 
71
- const created = upsertCredentialMetadata("github", "token", {
69
+ upsertCredentialMetadata("github", "token", {
72
70
  allowedTools: ["bash"],
73
71
  });
74
- await persistCredentialMetadata(created);
75
72
 
76
73
  expect(backend.store.size).toBe(0);
77
74
  });
@@ -717,6 +717,27 @@ describe("POST oauth/request", () => {
717
717
  expect(req.body).toEqual({ title: "Sheet" });
718
718
  });
719
719
 
720
+ test("decodes a base64 request body into a Buffer", async () => {
721
+ const binary = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0xff, 0x00]);
722
+
723
+ await getRoute("POST", "oauth/request").handler(
724
+ makeArgs({
725
+ body: {
726
+ provider: "google",
727
+ url: "https://api.google.com/upload/drive/v3/files",
728
+ method: "POST",
729
+ headers: { "Content-Type": "application/pdf" },
730
+ parsed_data: binary.toString("base64"),
731
+ body_encoding: "base64",
732
+ },
733
+ }),
734
+ );
735
+
736
+ const req = mockResolveRequests[0] as { body: unknown };
737
+ expect(Buffer.isBuffer(req.body)).toBe(true);
738
+ expect(Buffer.from(req.body as Uint8Array).equals(binary)).toBe(true);
739
+ });
740
+
720
741
  test("base64-encodes binary response bodies for the JSON envelope", async () => {
721
742
  const binary = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0xff, 0x00]);
722
743
  mockResolveResponse = {
@@ -271,10 +271,10 @@ describe("multi-file plugin apps compile on open", () => {
271
271
  expect(result.html).toContain("Compiled Board");
272
272
  expect(result.html).not.toContain("not been compiled");
273
273
  expect(result.origin).toBe("plugin:acme");
274
- // The daemon must not write dist/ into the read-only plugin tree — that is
274
+ // The daemon must not write dist/ into the read-only plugin tree. That is
275
275
  // the monitor's job. The on-open build happened in a throwaway temp dir.
276
276
  expect(existsSync(join(appDir, "dist"))).toBe(false);
277
- });
277
+ }, 15_000);
278
278
 
279
279
  test("apps_open on a malformed plugin app (no src/, no dist/) serves the fallback, not a 500", async () => {
280
280
  // An app dir with neither a root index.html nor src/ nor dist/ is
@@ -92,6 +92,7 @@ export class AcpAgentProcess {
92
92
  cwd,
93
93
  stdio: ["pipe", "pipe", "pipe"],
94
94
  env: this.spawnedEnv,
95
+ windowsHide: true,
95
96
  });
96
97
 
97
98
  const stream = acp.ndJsonStream(
@@ -86,6 +86,7 @@ function execFileWithTimeout(
86
86
  encoding: "utf8",
87
87
  cwd: options?.cwd,
88
88
  env: options?.env,
89
+ windowsHide: true,
89
90
  },
90
91
  (err, stdout) => {
91
92
  clearTimeout(timer);
@@ -380,6 +380,7 @@ export class VellumAcpClientHandler implements Client {
380
380
  cwd: params.cwd ?? undefined,
381
381
  stdio: ["ignore", "pipe", "pipe"],
382
382
  env,
383
+ windowsHide: true,
383
384
  });
384
385
 
385
386
  const state: TerminalState = {
@@ -497,6 +497,7 @@ export async function runCompile(
497
497
  stdout: "pipe",
498
498
  stderr: "pipe",
499
499
  env: { ...process.env, NODE_PATH: nodePath },
500
+ windowsHide: true,
500
501
  });
501
502
 
502
503
  await proc.exited;
@@ -170,6 +170,7 @@ async function downloadAndExtract(
170
170
  cmd: ["tar", "xzf", tmpTar, "-C", targetDir, "--strip-components=1"],
171
171
  stdout: "ignore",
172
172
  stderr: "pipe",
173
+ windowsHide: true,
173
174
  });
174
175
  await proc.exited;
175
176
  if (proc.exitCode !== 0) {
@@ -124,6 +124,7 @@ async function installPackage(
124
124
  cwd: cacheDir,
125
125
  stdout: "pipe",
126
126
  stderr: "pipe",
127
+ windowsHide: true,
127
128
  });
128
129
 
129
130
  // Race against timeout
@@ -48,6 +48,7 @@ function findHoldingPids(paths: string[]): number[] {
48
48
  encoding: "utf8",
49
49
  timeout: 5000,
50
50
  stdio: ["pipe", "pipe", "pipe"],
51
+ windowsHide: true,
51
52
  });
52
53
  for (const line of output.trim().split("\n")) {
53
54
  const pid = parseInt(line, 10);
@@ -778,8 +778,10 @@ form for any service other than the provider's default.
778
778
 
779
779
  The body (-d) is JSON by default. Give a non-JSON Content-Type and the body
780
780
  travels to the provider exactly as written, which is what multipart, XML, and
781
- form-encoded payloads need. Body files (-d @<path>) are read as UTF-8 text, so
782
- a payload that is not valid UTF-8 cannot be sent this way.
781
+ form-encoded payloads need. Body files (-d @<path>) and stdin (-d @-) are
782
+ read as raw bytes. Valid UTF-8 stays text (or JSON when the Content-Type is
783
+ JSON). Anything else, including PDFs and other binary files, is sent to the
784
+ provider byte for byte.
783
785
 
784
786
  Note: The Authorization header is set automatically. User-supplied
785
787
  -H "Authorization: ..." will be overridden by the OAuth bearer token.
@@ -790,7 +792,8 @@ Examples:
790
792
  $ assistant oauth request --provider twitter -X POST -d '{"text":"Hello"}' https://api.x.com/2/tweets
791
793
  $ assistant oauth request --provider google https://www.googleapis.com/calendar/v3/calendars/primary/events
792
794
  $ assistant oauth request --provider slack -H "Content-Type: application/json" -d '{"channel":"C123"}' /api/chat.postMessage --json
793
- $ assistant oauth request --provider google -X POST -H "Content-Type: multipart/related; boundary=b" -d @upload.txt "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart"`,
795
+ $ assistant oauth request --provider google -X POST -H "Content-Type: multipart/related; boundary=b" -d @upload.txt "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart"
796
+ $ assistant oauth request --provider google -X POST -H "Content-Type: application/pdf" -d @report.pdf "https://www.googleapis.com/upload/drive/v3/files?uploadType=media"`,
794
797
  },
795
798
  {
796
799
  name: "disconnect",
@@ -182,6 +182,43 @@ describe("oauth request body encoding", () => {
182
182
  );
183
183
  });
184
184
 
185
+ test("reads a binary @file as a Buffer without UTF-8 replacement", async () => {
186
+ const filePath = join(tempDir, "upload.bin");
187
+ writeFileSync(filePath, PNG_MAGIC);
188
+
189
+ const parsed = readBodyData(`@${filePath}`, {
190
+ "Content-Type": "application/octet-stream",
191
+ });
192
+ expect(Buffer.isBuffer(parsed)).toBe(true);
193
+ expect(Buffer.from(parsed as Uint8Array).equals(PNG_MAGIC)).toBe(true);
194
+ });
195
+
196
+ test("forwards a binary @file to the route handler as a Buffer", async () => {
197
+ const filePath = join(tempDir, "report.pdf");
198
+ writeFileSync(filePath, PNG_MAGIC);
199
+
200
+ const { exitCode } = await runRequestCommand([
201
+ "--provider",
202
+ "google",
203
+ "-s",
204
+ "-X",
205
+ "POST",
206
+ "-H",
207
+ "Content-Type: application/pdf",
208
+ "-d",
209
+ `@${filePath}`,
210
+ "https://www.googleapis.com/upload/drive/v3/files?uploadType=media",
211
+ ]);
212
+
213
+ expect(exitCode).toBe(0);
214
+ expect(handleRequestCalls).toHaveLength(1);
215
+ const call = handleRequestCalls[0] as { body: { parsed_data: unknown } };
216
+ expect(Buffer.isBuffer(call.body.parsed_data)).toBe(true);
217
+ expect(
218
+ Buffer.from(call.body.parsed_data as Uint8Array).equals(PNG_MAGIC),
219
+ ).toBe(true);
220
+ });
221
+
185
222
  test("forwards a multipart body to the route handler as a string", async () => {
186
223
  const { exitCode } = await runRequestCommand([
187
224
  "--provider",
@@ -5,9 +5,10 @@ import type { Command } from "commander";
5
5
  import { exitFromIpcResult } from "../../../ipc/cli-client.js";
6
6
  import {
7
7
  findContentTypeHeader,
8
+ parseRequestBodyBytes,
8
9
  parseRequestBodyData,
9
10
  } from "../../../util/oauth-request-body.js";
10
- import { readStdinSync } from "../../../util/read-stdin.js";
11
+ import { readStdinBytesSync } from "../../../util/read-stdin.js";
11
12
  import { subcommand } from "../../lib/cli-command-help.js";
12
13
  import { shouldOutputJson, writeOutput } from "../../output.js";
13
14
 
@@ -49,8 +50,8 @@ function parseHeader(raw: string): [string, string] {
49
50
  *
50
51
  * A non-JSON `Content-Type` keeps the payload as the exact string the caller
51
52
  * gave, so multipart, XML, and form-encoded bodies reach the provider
52
- * unchanged. Files are read as UTF-8 text, so a body that is not valid UTF-8
53
- * (a raw image, an archive) cannot travel through this flag.
53
+ * unchanged. Files and stdin are read as raw bytes: valid UTF-8 stays text
54
+ * (or JSON), and anything else travels as a Buffer.
54
55
  */
55
56
  export function readBodyData(
56
57
  data: string,
@@ -59,12 +60,12 @@ export function readBodyData(
59
60
  const contentType = findContentTypeHeader(headers);
60
61
 
61
62
  if (data === "@-") {
62
- return parseRequestBodyData(readStdinSync(), contentType);
63
+ return parseRequestBodyBytes(readStdinBytesSync(), contentType);
63
64
  }
64
65
 
65
66
  if (data.startsWith("@")) {
66
67
  const filePath = data.slice(1);
67
- return parseRequestBodyData(readFileSync(filePath, "utf-8"), contentType);
68
+ return parseRequestBodyBytes(readFileSync(filePath), contentType);
68
69
  }
69
70
 
70
71
  return parseRequestBodyData(data, contentType);
@@ -90,7 +91,7 @@ export function registerRequestCommand(oauth: Command): void {
90
91
  )
91
92
  .option(
92
93
  "-d, --data <data>",
93
- "Request body: inline JSON, @filename, or @- for stdin. Sent raw when Content-Type is not JSON",
94
+ "Request body: inline JSON, @filename, or @- for stdin. Sent raw when Content-Type is not JSON. Files keep their original bytes, including binary",
94
95
  )
95
96
  .option("-G, --get", "Force GET; body data becomes query params")
96
97
  .option("-I, --head", "Send a HEAD request")
@@ -219,7 +219,7 @@
219
219
  "source": {
220
220
  "source": "github",
221
221
  "repo": "vellum-ai/imessage",
222
- "ref": "069a8375e2a6ed069550866114a653218864bc91"
222
+ "ref": "01701eb1be4074f99371af90fc4340fdd1674efb"
223
223
  },
224
224
  "description": "iMessage and SMS channel for the Vellum assistant, backed by a Photon line.",
225
225
  "category": "productivity",
@@ -1259,6 +1259,7 @@ export const defaultPostinstallRunner: PostinstallRunner = async ({
1259
1259
  timeout: POSTINSTALL_TIMEOUT_MS,
1260
1260
  maxBuffer: 16 * 1024 * 1024,
1261
1261
  env: pluginPostinstallEnv(bun),
1262
+ windowsHide: true,
1262
1263
  });
1263
1264
  };
1264
1265
 
@@ -1377,6 +1378,7 @@ export const defaultGitRunner: GitRunner = async (args, opts) => {
1377
1378
  timeout: GIT_TIMEOUT_MS,
1378
1379
  maxBuffer: 64 * 1024 * 1024,
1379
1380
  env: pluginGitEnv(),
1381
+ windowsHide: true,
1380
1382
  });
1381
1383
  return { stdout };
1382
1384
  };
@@ -319,6 +319,7 @@ export const defaultDependencyInstaller: DependencyInstaller = async ({
319
319
  timeout: DEPENDENCY_INSTALL_TIMEOUT_MS,
320
320
  maxBuffer: 32 * 1024 * 1024,
321
321
  env: dependencyInstallEnv(bun),
322
+ windowsHide: true,
322
323
  });
323
324
  };
324
325
 
@@ -205,6 +205,7 @@ async function threeWayMergeFile(
205
205
  encoding: "buffer",
206
206
  timeout: MERGE_TIMEOUT_MS,
207
207
  maxBuffer: 64 * 1024 * 1024,
208
+ windowsHide: true,
208
209
  });
209
210
  return { content: stdout, conflicted: false, binaryConflicted: false };
210
211
  } catch (err) {
@@ -199,7 +199,10 @@ export function validatePluginForPublish(dir: string): PublishValidation {
199
199
  // ---------------------------------------------------------------------------
200
200
 
201
201
  async function runGit(dir: string, args: string[]): Promise<string> {
202
- const { stdout } = await execFileAsync("git", args, { cwd: dir });
202
+ const { stdout } = await execFileAsync("git", args, {
203
+ cwd: dir,
204
+ windowsHide: true,
205
+ });
203
206
  return stdout.trim();
204
207
  }
205
208
 
@@ -32,6 +32,7 @@ import {
32
32
  import { parseToolManifestFile } from "../skills/tool-manifest.js";
33
33
  import { computeSkillVersionHash } from "../skills/version-hash.js";
34
34
  import type { OwnerInfo } from "../tools/types.js";
35
+ import { isBunVirtualPath } from "../util/bundled-asset.js";
35
36
  import { getLogger } from "../util/logger.js";
36
37
  import {
37
38
  getWorkspaceDirDisplay,
@@ -230,7 +231,7 @@ export function getBundledSkillsDir(): string {
230
231
  // In compiled Bun binaries, import.meta.dir points into the virtual
231
232
  // /$bunfs/ filesystem where non-JS assets don't exist. Fall back to
232
233
  // the macOS .app bundle Resources dir or next to the binary.
233
- if (dir.startsWith("/$bunfs/")) {
234
+ if (isBunVirtualPath(dir)) {
234
235
  const execDir = dirname(process.execPath);
235
236
  // macOS .app bundle: binary is in Contents/MacOS/, resources in Contents/Resources/
236
237
  const resourcesPath = join(execDir, "..", "Resources", "bundled-skills");
@@ -126,6 +126,7 @@ function isVellumDaemonProcess(pid: number): boolean {
126
126
  encoding: "utf-8",
127
127
  timeout: 3000,
128
128
  stdio: ["ignore", "pipe", "ignore"],
129
+ windowsHide: true,
129
130
  }).trim();
130
131
  // The daemon is spawned as `bun run <path>/main.ts` — look for bun
131
132
  // running our daemon entry point.
@@ -262,6 +262,7 @@ function commandResolvesElsewhere(
262
262
  const resolved = execFileSync("/usr/bin/which", [commandName], {
263
263
  encoding: "utf-8",
264
264
  stdio: ["ignore", "pipe", "ignore"],
265
+ windowsHide: true,
265
266
  }).trim();
266
267
  return resolved !== "" && !candidatePaths.has(resolved);
267
268
  } catch {
@@ -35,7 +35,7 @@ async function extractThumbnail(inputPath: string): Promise<string | null> {
35
35
  "5",
36
36
  outputPath,
37
37
  ],
38
- { stderr: "pipe" },
38
+ { stderr: "pipe", windowsHide: true },
39
39
  );
40
40
 
41
41
  let timer: ReturnType<typeof setTimeout>;
@@ -143,7 +143,11 @@ export async function readFileResidency(
143
143
  const { stdout } = await execFileAsync(
144
144
  "fincore",
145
145
  ["--bytes", "--json", ...paths],
146
- { timeout: 10_000, maxBuffer: 4 * 1024 * 1024 },
146
+ {
147
+ timeout: 10_000,
148
+ maxBuffer: 4 * 1024 * 1024,
149
+ windowsHide: true,
150
+ },
147
151
  );
148
152
  return parseFincoreJson(stdout);
149
153
  } catch {
@@ -358,6 +358,28 @@ describe("BYOOAuthConnection", () => {
358
358
  expect(headers.get("Content-Type")).toBe("application/json");
359
359
  });
360
360
 
361
+ test("sends a Buffer body as raw bytes under the caller's Content-Type", async () => {
362
+ await setupCredential("google");
363
+ const conn = createConnection();
364
+ const binary = Buffer.from([
365
+ 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0xff, 0xfe,
366
+ ]);
367
+
368
+ await conn.request({
369
+ method: "POST",
370
+ path: "/upload/drive/v3/files",
371
+ headers: { "Content-Type": "application/pdf" },
372
+ body: binary,
373
+ });
374
+
375
+ const [, init] = mockFetch.mock.calls[0];
376
+ const sent = (init as RequestInit).body;
377
+ expect(Buffer.isBuffer(sent)).toBe(true);
378
+ expect(Buffer.from(sent as Buffer).equals(binary)).toBe(true);
379
+ const headers = (init as RequestInit).headers as Headers;
380
+ expect(headers.get("Content-Type")).toBe("application/pdf");
381
+ });
382
+
361
383
  test("sends a string body verbatim under the caller's Content-Type", async () => {
362
384
  await setupCredential("google");
363
385
  const conn = createConnection();
@@ -14,7 +14,7 @@ import type {
14
14
  OAuthConnectionRequest,
15
15
  OAuthConnectionResponse,
16
16
  } from "./connection.js";
17
- import { decodeOAuthResponseBytes } from "./connection.js";
17
+ import { decodeOAuthResponseBytes, isBinaryOAuthBody } from "./connection.js";
18
18
 
19
19
  const log = getLogger("byo-oauth-connection");
20
20
 
@@ -83,15 +83,17 @@ export class BYOOAuthConnection implements OAuthConnection {
83
83
 
84
84
  // A string body is already in its wire form (multipart, XML,
85
85
  // form-encoded, or pre-serialized JSON) and travels verbatim under
86
- // the caller's own Content-Type. Objects and arrays are serialized
87
- // as JSON and get the JSON Content-Type by default.
86
+ // the caller's own Content-Type. A Buffer travels as raw bytes.
87
+ // Objects and arrays are serialized as JSON and get the JSON
88
+ // Content-Type by default.
88
89
  const hasBody = req.body !== undefined && req.body !== null;
90
+ const binaryBody = isBinaryOAuthBody(req.body) ? req.body : undefined;
89
91
  const rawBody = typeof req.body === "string" ? req.body : undefined;
90
92
 
91
93
  // Use the Headers API for case-insensitive merging. Set defaults
92
94
  // first so caller-supplied headers (in any casing) override them.
93
95
  const headers = new Headers();
94
- if (hasBody && rawBody === undefined) {
96
+ if (hasBody && rawBody === undefined && binaryBody === undefined) {
95
97
  headers.set("Content-Type", "application/json");
96
98
  }
97
99
  if (req.headers) {
@@ -106,7 +108,11 @@ export class BYOOAuthConnection implements OAuthConnection {
106
108
  const resp = await fetch(fullUrl, {
107
109
  method: req.method,
108
110
  headers,
109
- body: hasBody ? (rawBody ?? JSON.stringify(req.body)) : undefined,
111
+ body: hasBody
112
+ ? (binaryBody !== undefined
113
+ ? Buffer.from(binaryBody)
114
+ : (rawBody ?? JSON.stringify(req.body)))
115
+ : undefined,
110
116
  signal: req.signal
111
117
  ? AbortSignal.any([
112
118
  req.signal,
@@ -5,8 +5,9 @@ export interface OAuthConnectionRequest {
5
5
  headers?: Record<string, string>;
6
6
  /**
7
7
  * A string is forwarded to the provider verbatim under the caller's own
8
- * `Content-Type` (multipart, XML, form-encoded). Anything else is
9
- * JSON-serialized and sent as `application/json`.
8
+ * `Content-Type` (multipart, XML, form-encoded). A Buffer or Uint8Array
9
+ * is forwarded as raw bytes. Anything else is JSON-serialized and sent
10
+ * as `application/json`.
10
11
  */
11
12
  body?: unknown;
12
13
  /**
@@ -102,6 +102,41 @@ describe("PlatformOAuthConnection", () => {
102
102
  expect(result.body).toEqual(upstreamBody);
103
103
  });
104
104
 
105
+ test("encodes a Buffer request body as base64 in the proxy envelope", async () => {
106
+ const binary = Buffer.from([
107
+ 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0xff, 0xfe, 0x00,
108
+ ]);
109
+
110
+ const client = makeMockClient(
111
+ mock(async (_url: string | URL | Request, init?: RequestInit) => {
112
+ const parsed = JSON.parse(init?.body as string);
113
+ expect(parsed.request.body).toBe(binary.toString("base64"));
114
+ expect(parsed.request.body_encoding).toBe("base64");
115
+ expect(parsed.request.headers["Content-Type"]).toBe("application/pdf");
116
+
117
+ return new Response(
118
+ JSON.stringify({
119
+ status: 200,
120
+ headers: { "content-type": "application/json" },
121
+ body: { id: "file-123" },
122
+ }),
123
+ { status: 200 },
124
+ );
125
+ }) as unknown as typeof globalThis.fetch,
126
+ );
127
+
128
+ const conn = new PlatformOAuthConnection({
129
+ ...DEFAULT_OPTIONS,
130
+ client,
131
+ });
132
+ await conn.request({
133
+ method: "POST",
134
+ path: "/upload/drive/v3/files",
135
+ headers: { "Content-Type": "application/pdf" },
136
+ body: binary,
137
+ });
138
+ });
139
+
105
140
  test("decodes base64 binary proxy bodies into a Buffer", async () => {
106
141
  const binary = Buffer.from([
107
142
  0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0xff, 0xfe, 0x00,
@@ -7,6 +7,7 @@ import type {
7
7
  OAuthConnectionRequest,
8
8
  OAuthConnectionResponse,
9
9
  } from "./connection.js";
10
+ import { isBinaryOAuthBody } from "./connection.js";
10
11
 
11
12
  const log = getLogger("platform-oauth-connection");
12
13
  const MAX_RETRIES = 3;
@@ -84,20 +85,24 @@ export class PlatformOAuthConnection implements OAuthConnection {
84
85
 
85
86
  // The envelope carries the caller's headers and body side by side. A
86
87
  // string body is placed in the envelope as a string, so the proxy forwards
87
- // those bytes verbatim under the caller's Content-Type; an object body
88
- // travels as JSON and the proxy serializes it.
89
- const body: Record<string, unknown> = {
90
- request: {
91
- method: req.method,
92
- path: req.path,
93
- query: req.query ?? {},
94
- headers: req.headers ?? {},
95
- body: req.body ?? null,
96
- ...((req.baseUrl ?? this.baseUrl)
97
- ? { base_url: req.baseUrl ?? this.baseUrl }
98
- : {}),
99
- },
88
+ // those bytes verbatim under the caller's Content-Type. A Buffer is
89
+ // base64-encoded so binary uploads survive JSON. An object body travels
90
+ // as JSON and the proxy serializes it.
91
+ const request: Record<string, unknown> = {
92
+ method: req.method,
93
+ path: req.path,
94
+ query: req.query ?? {},
95
+ headers: req.headers ?? {},
96
+ body: req.body ?? null,
97
+ ...((req.baseUrl ?? this.baseUrl)
98
+ ? { base_url: req.baseUrl ?? this.baseUrl }
99
+ : {}),
100
100
  };
101
+ if (isBinaryOAuthBody(req.body)) {
102
+ request.body = Buffer.from(req.body).toString("base64");
103
+ request.body_encoding = "base64";
104
+ }
105
+ const body: Record<string, unknown> = { request };
101
106
 
102
107
  for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
103
108
  const response = await this.client.fetch(proxyPath, {
@@ -49,6 +49,7 @@ export async function ensureLocalCA(dataDir: string): Promise<void> {
49
49
  const keyProc = Bun.spawn(["openssl", "genrsa", "-out", keyPath, "2048"], {
50
50
  stdout: "pipe",
51
51
  stderr: "pipe",
52
+ windowsHide: true,
52
53
  });
53
54
  const keyExit = await keyProc.exited;
54
55
  if (keyExit !== 0) {
@@ -76,7 +77,7 @@ export async function ensureLocalCA(dataDir: string): Promise<void> {
76
77
  "-addext",
77
78
  "keyUsage=critical,keyCertSign,cRLSign",
78
79
  ],
79
- { stdout: "pipe", stderr: "pipe" },
80
+ { stdout: "pipe", stderr: "pipe", windowsHide: true },
80
81
  );
81
82
  const certExit = await certProc.exited;
82
83
  if (certExit !== 0) {
@@ -144,7 +145,7 @@ export async function issueLeafCert(
144
145
  // Generate leaf key
145
146
  const keyProc = Bun.spawn(
146
147
  ["openssl", "genrsa", "-out", leafKeyPath, "2048"],
147
- { stdout: "pipe", stderr: "pipe" },
148
+ { stdout: "pipe", stderr: "pipe", windowsHide: true },
148
149
  );
149
150
  const keyExit = await keyProc.exited;
150
151
  if (keyExit !== 0) {
@@ -166,7 +167,7 @@ export async function issueLeafCert(
166
167
  "-subj",
167
168
  `/CN=${hostname}`,
168
169
  ],
169
- { stdout: "pipe", stderr: "pipe" },
170
+ { stdout: "pipe", stderr: "pipe", windowsHide: true },
170
171
  );
171
172
  const csrExit = await csrProc.exited;
172
173
  if (csrExit !== 0) {
@@ -198,7 +199,7 @@ export async function issueLeafCert(
198
199
  "-extfile",
199
200
  extPath,
200
201
  ],
201
- { stdout: "pipe", stderr: "pipe" },
202
+ { stdout: "pipe", stderr: "pipe", windowsHide: true },
202
203
  );
203
204
  const signExit = await signProc.exited;
204
205
  if (signExit !== 0) {
@@ -286,6 +286,7 @@ export class QdrantManager {
286
286
  cmd: ["tar", "xzf", tmpTar, "-C", binDir, release.binaryName],
287
287
  stdout: "ignore",
288
288
  stderr: "pipe",
289
+ windowsHide: true,
289
290
  });
290
291
  await proc.exited;
291
292
  if (proc.exitCode !== 0) {
@@ -25,7 +25,12 @@ export async function createTarGz(
25
25
  const { stdout } = await execFileAsync(
26
26
  "tar",
27
27
  ["czf", "-", "-C", staging, "."],
28
- { maxBuffer: maxBytes, timeout: 30_000, encoding: "buffer" },
28
+ {
29
+ maxBuffer: maxBytes,
30
+ timeout: 30_000,
31
+ encoding: "buffer",
32
+ windowsHide: true,
33
+ },
29
34
  );
30
35
  const buf = Buffer.isBuffer(stdout) ? stdout : Buffer.from(stdout);
31
36
  return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
@@ -97,6 +97,7 @@ function handleDebugBash({ body }: RouteHandlerArgs): Promise<DebugBashResult> {
97
97
  stdio: ["ignore", "pipe", "pipe"],
98
98
  detached: true,
99
99
  env: buildSanitizedEnv(),
100
+ windowsHide: true,
100
101
  });
101
102
 
102
103
  const timer = setTimeout(() => {
@@ -44,7 +44,6 @@ import {
44
44
  } from "../../security/secure-keys.js";
45
45
  import {
46
46
  getCredentialMetadata,
47
- persistCredentialMetadata,
48
47
  upsertCredentialMetadata,
49
48
  } from "../../tools/credentials/metadata-store.js";
50
49
  import { getLogger } from "../../util/logger.js";
@@ -157,8 +156,7 @@ export async function reconcileVellumMetadataFromCes(warningSink: {
157
156
  if (getCredentialMetadata("vellum", field)) {
158
157
  continue;
159
158
  }
160
- const metadata = upsertCredentialMetadata("vellum", field, {});
161
- await persistCredentialMetadata(metadata);
159
+ upsertCredentialMetadata("vellum", field, {});
162
160
  log.info(
163
161
  { field },
164
162
  "Reconciled vellum:* metadata entry from CES after import",
@@ -19,7 +19,7 @@ import {
19
19
  ServicesSchema,
20
20
  } from "../../config/schemas/services.js";
21
21
  import type { OAuthConnectionRequest } from "../../oauth/connection.js";
22
- import { jsonSafeOAuthBody } from "../../oauth/connection.js";
22
+ import { isBinaryOAuthBody, jsonSafeOAuthBody } from "../../oauth/connection.js";
23
23
  import {
24
24
  resolveOAuthConnection,
25
25
  type ResolveOAuthConnectionOptions,
@@ -42,6 +42,7 @@ import { matchHostPattern } from "../../tools/credentials/host-pattern-match.js"
42
42
  import { getLogger } from "../../util/logger.js";
43
43
  import {
44
44
  findContentTypeHeader,
45
+ parseRequestBodyBytes,
45
46
  parseRequestBodyData,
46
47
  } from "../../util/oauth-request-body.js";
47
48
  import { LOCAL_PRINCIPALS } from "../auth/route-policy.js";
@@ -729,7 +730,8 @@ async function handleToken({ body = {} }: RouteHandlerArgs) {
729
730
  /**
730
731
  * Resolve a raw `data` string into a request body. A non-JSON Content-Type
731
732
  * keeps the payload as the caller's exact string so multipart and other
732
- * byte-sensitive payloads survive; files are read as UTF-8 text.
733
+ * byte-sensitive payloads survive. Files are read as raw bytes: valid UTF-8
734
+ * stays text, and anything else stays a Buffer.
733
735
  */
734
736
  function readBodyData(data: string, contentType: string | undefined): unknown {
735
737
  if (data === "@-") {
@@ -744,7 +746,7 @@ function readBodyData(data: string, contentType: string | undefined): unknown {
744
746
 
745
747
  if (data.startsWith("@")) {
746
748
  const filePath = data.slice(1);
747
- return parseRequestBodyData(readFileSync(filePath, "utf-8"), contentType);
749
+ return parseRequestBodyBytes(readFileSync(filePath), contentType);
748
750
  }
749
751
 
750
752
  return parseRequestBodyData(data, contentType);
@@ -760,6 +762,8 @@ export async function handleRequest({ body = {} }: RouteHandlerArgs) {
760
762
  parsed_data?: unknown;
761
763
  /** Raw data string (for direct API callers, not the CLI). */
762
764
  data?: string;
765
+ /** When set to base64, `parsed_data` / `data` is a base64 string of raw bytes. */
766
+ body_encoding?: "base64";
763
767
  force_get?: boolean;
764
768
  head?: boolean;
765
769
  account?: string;
@@ -864,7 +868,15 @@ export async function handleRequest({ body = {} }: RouteHandlerArgs) {
864
868
  : undefined;
865
869
 
866
870
  if (resolvedData !== undefined) {
867
- const rawBody = resolvedData;
871
+ let rawBody = resolvedData;
872
+ if (b.body_encoding === "base64") {
873
+ if (typeof rawBody !== "string") {
874
+ throw new BadRequestError(
875
+ "body_encoding=base64 requires a string body",
876
+ );
877
+ }
878
+ rawBody = Buffer.from(rawBody, "base64");
879
+ }
868
880
 
869
881
  if (b.force_get) {
870
882
  if (typeof rawBody === "string") {
@@ -882,7 +894,8 @@ export async function handleRequest({ body = {} }: RouteHandlerArgs) {
882
894
  } else if (
883
895
  rawBody !== null &&
884
896
  typeof rawBody === "object" &&
885
- !Array.isArray(rawBody)
897
+ !Array.isArray(rawBody) &&
898
+ !isBinaryOAuthBody(rawBody)
886
899
  ) {
887
900
  for (const [key, value] of Object.entries(
888
901
  rawBody as Record<string, unknown>,
@@ -66,6 +66,7 @@ export async function runScript(
66
66
  detached: true,
67
67
  stdout: "pipe",
68
68
  stderr: "pipe",
69
+ windowsHide: true,
69
70
  env: {
70
71
  ...buildSanitizedEnv(),
71
72
  // __SCHEDULE_ID lets a saved command find its own dir; __SCHEDULE_RUN_ID
@@ -16,6 +16,7 @@ import { gunzipSync } from "node:zlib";
16
16
 
17
17
  import { getPlatformBaseUrl } from "../config/env.js";
18
18
  import { loadSkillCatalog } from "../config/skills.js";
19
+ import { isBunVirtualPath } from "../util/bundled-asset.js";
19
20
  import { getLogger } from "../util/logger.js";
20
21
  import { getWorkspaceSkillsDir } from "../util/platform.js";
21
22
  import { computeSkillHash, writeInstallMeta } from "./install-meta.js";
@@ -67,7 +68,7 @@ export interface CatalogSkill {
67
68
  export function getRepoSkillsDir(): string | undefined {
68
69
  const importDir = import.meta.dir;
69
70
 
70
- if (importDir.startsWith("/$bunfs/")) {
71
+ if (isBunVirtualPath(importDir)) {
71
72
  const execDir = dirname(process.execPath);
72
73
  // macOS .app bundle: binary in Contents/MacOS/, resources in Contents/Resources/
73
74
  const resourcesPath = join(
@@ -421,6 +422,7 @@ export async function installSkillDependenciesIfPresent(
421
422
  cwd: skillDir,
422
423
  stdio: "inherit",
423
424
  env: { ...process.env, PATH: `${bunPath}:${process.env.PATH}` },
425
+ windowsHide: true,
424
426
  });
425
427
  child.on("error", reject);
426
428
  child.on("close", (code) => {
@@ -195,6 +195,7 @@ async function runClawhub(
195
195
  env: { ...process.env, CLAWHUB_DISABLE_TELEMETRY: "1" },
196
196
  stdout: "pipe",
197
197
  stderr: "pipe",
198
+ windowsHide: true,
198
199
  });
199
200
 
200
201
  let timer: ReturnType<typeof setTimeout>;
@@ -125,6 +125,7 @@ export async function runInlineCommand(
125
125
  cwd: workingDir,
126
126
  env,
127
127
  stdio: ["ignore", "pipe", "ignore"],
128
+ windowsHide: true,
128
129
  });
129
130
  } catch (err) {
130
131
  const message = err instanceof Error ? err.message : String(err);
@@ -268,6 +268,7 @@ class BrowserManager {
268
268
  {
269
269
  stdout: "pipe",
270
270
  stderr: "pipe",
271
+ windowsHide: true,
271
272
  },
272
273
  );
273
274
  const timeoutMs = 300_000;
@@ -104,6 +104,7 @@ export async function importPlaywright(): Promise<typeof import("playwright")> {
104
104
  cwd: externalDir,
105
105
  stdout: "pipe",
106
106
  stderr: "pipe",
107
+ windowsHide: true,
107
108
  });
108
109
  const exitCode = await proc.exited;
109
110
  if (exitCode !== 0) {
@@ -168,6 +169,7 @@ export async function ensureChromiumHeadlessShell(
168
169
  stdout: "pipe",
169
170
  stderr: "pipe",
170
171
  cwd: externalPwExists ? externalDir : undefined,
172
+ windowsHide: true,
171
173
  },
172
174
  );
173
175
  const timeoutMs = 120_000;
@@ -76,7 +76,9 @@ function toRecord(metadata: CredentialMetadata): CredentialRecord {
76
76
  };
77
77
  }
78
78
 
79
- async function persistRecord(metadata: CredentialMetadata): Promise<void> {
79
+ async function persistCredentialMetadata(
80
+ metadata: CredentialMetadata,
81
+ ): Promise<void> {
80
82
  if (!_recordBackend || _overridePath) {
81
83
  return;
82
84
  }
@@ -90,13 +92,6 @@ async function persistRecord(metadata: CredentialMetadata): Promise<void> {
90
92
  }
91
93
  }
92
94
 
93
- /** Await CES write-through for a record already in the local file store. */
94
- export async function persistCredentialMetadata(
95
- metadata: CredentialMetadata,
96
- ): Promise<void> {
97
- await persistRecord(metadata);
98
- }
99
-
100
95
  export function setCredentialRecordBackend(
101
96
  backend: CredentialRecordBackend | undefined,
102
97
  ): void {
@@ -119,6 +114,8 @@ export function assertMetadataWritable(): void {
119
114
  /**
120
115
  * Create or update a credential metadata record.
121
116
  * If a record with the same service+field exists, it is updated.
117
+ * When a CES record backend is attached, the upsert also write-throughs
118
+ * to CES.
122
119
  */
123
120
  export function upsertCredentialMetadata(
124
121
  service: string,
@@ -134,7 +131,7 @@ export function upsertCredentialMetadata(
134
131
  },
135
132
  ): CredentialMetadata {
136
133
  const record = getStore().upsert(service, field, policy) as CredentialMetadata;
137
- void persistRecord(record);
134
+ void persistCredentialMetadata(record);
138
135
  return record;
139
136
  }
140
137
 
@@ -37,7 +37,6 @@ import {
37
37
  import { getLogger } from "../../util/logger.js";
38
38
  import {
39
39
  assertMetadataWritable,
40
- persistCredentialMetadata,
41
40
  upsertCredentialMetadata,
42
41
  } from "./metadata-store.js";
43
42
  import type { CredentialInjectionTemplate } from "./policy-types.js";
@@ -162,7 +161,6 @@ export async function storeCredentialValue(
162
161
  allowedDomains: input.allowedDomains,
163
162
  injectionTemplates: input.injectionTemplates,
164
163
  });
165
- await persistCredentialMetadata(metadata);
166
164
  const { syncManualTokenConnection } =
167
165
  await import("../../oauth/manual-token-connection.js");
168
166
  await syncManualTokenConnection(service);
@@ -472,6 +472,7 @@ export const hostShellTool = {
472
472
  env: hostEnv,
473
473
  stdio: ["ignore", "pipe", "pipe"],
474
474
  detached: true,
475
+ windowsHide: true,
475
476
  });
476
477
 
477
478
  const stdoutChunks: Buffer[] = [];
@@ -659,6 +660,7 @@ export const hostShellTool = {
659
660
  env: hostEnv,
660
661
  stdio: ["ignore", "pipe", "pipe"],
661
662
  detached: true,
663
+ windowsHide: true,
662
664
  });
663
665
 
664
666
  const killTree = () => terminateProcessTree(child);
@@ -161,6 +161,7 @@ function spawnRunner(
161
161
  env,
162
162
  stdio: ["ignore", "pipe", "pipe"],
163
163
  detached: true,
164
+ windowsHide: true,
164
165
  });
165
166
 
166
167
  const timer = setTimeout(() => {
@@ -327,6 +327,7 @@ export const shellTool = {
327
327
  env,
328
328
  stdio: ["ignore", "pipe", "pipe"],
329
329
  detached: true,
330
+ windowsHide: true,
330
331
  });
331
332
 
332
333
  const killTree = buildKillTree(child, {
@@ -548,6 +549,7 @@ export const shellTool = {
548
549
  env,
549
550
  stdio: ["ignore", "pipe", "pipe"],
550
551
  detached: true,
552
+ windowsHide: true,
551
553
  });
552
554
 
553
555
  const killTree = buildKillTree(child, {
@@ -165,6 +165,7 @@ async function downloadBun(installDir: string): Promise<string> {
165
165
  : ["unzip", "-o", tmpZip, "-d", installDir],
166
166
  stdout: "ignore",
167
167
  stderr: "pipe",
168
+ windowsHide: true,
168
169
  });
169
170
  await proc.exited;
170
171
  if (proc.exitCode !== 0) {
@@ -1,6 +1,14 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
3
 
4
+ export function isBunVirtualPath(value: string): boolean {
5
+ const normalized = value.replaceAll("\\", "/");
6
+ return (
7
+ normalized.startsWith("/$bunfs/") ||
8
+ /^[a-z]:\/~bun(?:\/|$)/i.test(normalized)
9
+ );
10
+ }
11
+
4
12
  /**
5
13
  * Resolve the path to a bundled asset directory, handling compiled Bun binaries
6
14
  * where `import.meta.dirname` points to the `/$bunfs/` virtual filesystem and
@@ -22,7 +30,7 @@ export function resolveBundledDir(
22
30
  relativePath: string,
23
31
  bundleName: string,
24
32
  ): string {
25
- if (callerDir.startsWith("/$bunfs/")) {
33
+ if (isBunVirtualPath(callerDir)) {
26
34
  const execDir = dirname(process.execPath);
27
35
  // macOS .app bundle: binary in Contents/MacOS/, resources in Contents/Resources/
28
36
  const resourcesPath = join(execDir, "..", "Resources", bundleName);
@@ -30,6 +30,7 @@ async function getDirectorySizeBytes(paths: string[]): Promise<number | null> {
30
30
  }
31
31
  const { stdout } = await execFileAsync("du", ["-sb", ...existing], {
32
32
  timeout: 30_000,
33
+ windowsHide: true,
33
34
  });
34
35
  let total = 0;
35
36
  for (const line of stdout.trim().split("\n")) {
@@ -48,7 +48,10 @@ type ExecFileRunner = (
48
48
  ) => Promise<ExecFileResult>;
49
49
 
50
50
  const runExecFile: ExecFileRunner = async (command, args, options) => {
51
- const { stdout } = await execFileAsync(command, args, options);
51
+ const { stdout } = await execFileAsync(command, args, {
52
+ ...options,
53
+ windowsHide: true,
54
+ });
52
55
  return { stdout };
53
56
  };
54
57
 
@@ -260,6 +260,7 @@ async function runSips(
260
260
  stdout: "ignore",
261
261
  stderr: "ignore",
262
262
  timeout: 15_000,
263
+ windowsHide: true,
263
264
  });
264
265
  await proc.exited;
265
266
  if (proc.exitCode !== 0) {
@@ -2,7 +2,9 @@ import { describe, expect, test } from "bun:test";
2
2
 
3
3
  import {
4
4
  findContentTypeHeader,
5
+ isBinaryOAuthContentType,
5
6
  isJsonContentType,
7
+ parseRequestBodyBytes,
6
8
  parseRequestBodyData,
7
9
  } from "./oauth-request-body.js";
8
10
 
@@ -72,3 +74,60 @@ describe("parseRequestBodyData", () => {
72
74
  expect(parseRequestBodyData('"hello"', undefined)).toBe('"hello"');
73
75
  });
74
76
  });
77
+
78
+ describe("isBinaryOAuthContentType", () => {
79
+ test("recognizes PDF, octet-stream, and image types", () => {
80
+ expect(isBinaryOAuthContentType("application/pdf")).toBe(true);
81
+ expect(isBinaryOAuthContentType("application/octet-stream")).toBe(true);
82
+ expect(isBinaryOAuthContentType("image/png; charset=binary")).toBe(true);
83
+ });
84
+
85
+ test("rejects JSON, multipart, and form types", () => {
86
+ expect(isBinaryOAuthContentType("application/json")).toBe(false);
87
+ expect(isBinaryOAuthContentType("multipart/related; boundary=b")).toBe(
88
+ false,
89
+ );
90
+ expect(isBinaryOAuthContentType("application/x-www-form-urlencoded")).toBe(
91
+ false,
92
+ );
93
+ expect(isBinaryOAuthContentType(undefined)).toBe(false);
94
+ });
95
+ });
96
+
97
+ describe("parseRequestBodyBytes", () => {
98
+ const png = Buffer.from([
99
+ 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0xff, 0xfe,
100
+ ]);
101
+
102
+ test("keeps invalid UTF-8 as a Buffer", () => {
103
+ const parsed = parseRequestBodyBytes(png, "multipart/related; boundary=b");
104
+ expect(Buffer.isBuffer(parsed)).toBe(true);
105
+ expect(Buffer.from(parsed as Uint8Array).equals(png)).toBe(true);
106
+ });
107
+
108
+ test("keeps a PDF Content-Type as a Buffer even when the bytes are ASCII", () => {
109
+ const asciiPdf = Buffer.from("%PDF-1.4 simple", "ascii");
110
+ const parsed = parseRequestBodyBytes(asciiPdf, "application/pdf");
111
+ expect(Buffer.isBuffer(parsed)).toBe(true);
112
+ expect(Buffer.from(parsed as Uint8Array).equals(asciiPdf)).toBe(true);
113
+ });
114
+
115
+ test("keeps valid UTF-8 multipart as the exact string", () => {
116
+ const multipart = "--b\r\nContent-Type: text/csv\r\n\r\na,b\r\n--b--\r\n";
117
+ expect(
118
+ parseRequestBodyBytes(
119
+ Buffer.from(multipart, "utf-8"),
120
+ "multipart/related; boundary=b",
121
+ ),
122
+ ).toBe(multipart);
123
+ });
124
+
125
+ test("parses UTF-8 JSON into an object", () => {
126
+ expect(
127
+ parseRequestBodyBytes(
128
+ Buffer.from('{"name":"Sheet"}', "utf-8"),
129
+ "application/json",
130
+ ),
131
+ ).toEqual({ name: "Sheet" });
132
+ });
133
+ });
@@ -1,13 +1,23 @@
1
1
  /**
2
2
  * Shared helpers for deciding how an outbound OAuth request body is encoded.
3
3
  *
4
- * A body is either structured (an object or array, serialized as JSON) or
5
- * raw (a string forwarded to the provider byte-for-byte). The Content-Type
6
- * the caller supplied decides which one a string body is: multipart, XML,
7
- * form-encoded, and CSV payloads must survive intact, while JSON text is
8
- * already in its wire form and must not be re-encoded.
4
+ * A body is structured (an object or array, serialized as JSON), raw text
5
+ * (a string forwarded to the provider as UTF-8), or raw bytes (a Buffer
6
+ * forwarded to the provider byte-for-byte). The Content-Type the caller
7
+ * supplied decides which one a string body is: multipart, XML, form-encoded,
8
+ * and CSV payloads must survive intact, while JSON text is already in its
9
+ * wire form and must not be re-encoded. Files that are not valid UTF-8, or
10
+ * that carry a binary Content-Type, stay as bytes.
9
11
  */
10
12
 
13
+ const BINARY_MEDIA_TYPES = new Set([
14
+ "application/octet-stream",
15
+ "application/pdf",
16
+ "application/zip",
17
+ "application/gzip",
18
+ "application/x-gzip",
19
+ ]);
20
+
11
21
  /** True when a Content-Type header names a JSON media type. */
12
22
  export function isJsonContentType(
13
23
  contentType: string | undefined | null,
@@ -58,3 +68,44 @@ export function parseRequestBodyData(
58
68
  // body once unquoted, so the original quoted text is kept as the wire form.
59
69
  return typeof parsed === "string" ? raw : parsed;
60
70
  }
71
+
72
+ /** True when a Content-Type names a binary media type (PDF, image, zip). */
73
+ export function isBinaryOAuthContentType(
74
+ contentType: string | undefined | null,
75
+ ): boolean {
76
+ if (!contentType) {
77
+ return false;
78
+ }
79
+ const mediaType = contentType.split(";")[0]?.trim().toLowerCase() ?? "";
80
+ if (
81
+ mediaType.startsWith("image/") ||
82
+ mediaType.startsWith("audio/") ||
83
+ mediaType.startsWith("video/")
84
+ ) {
85
+ return true;
86
+ }
87
+ return BINARY_MEDIA_TYPES.has(mediaType);
88
+ }
89
+
90
+ /**
91
+ * Decide how file or stdin bytes reach the provider.
92
+ *
93
+ * Binary Content-Types and payloads that are not valid UTF-8 stay as a
94
+ * Buffer so the original bytes survive the JSON proxy envelope. Valid UTF-8
95
+ * follows {@link parseRequestBodyData}.
96
+ */
97
+ export function parseRequestBodyBytes(
98
+ raw: Uint8Array,
99
+ contentType: string | undefined,
100
+ ): unknown {
101
+ if (isBinaryOAuthContentType(contentType)) {
102
+ return Buffer.from(raw);
103
+ }
104
+ let utf8: string;
105
+ try {
106
+ utf8 = new TextDecoder("utf-8", { fatal: true }).decode(raw);
107
+ } catch {
108
+ return Buffer.from(raw);
109
+ }
110
+ return parseRequestBodyData(utf8, contentType);
111
+ }
@@ -157,6 +157,7 @@ function runProcessTableCommand(
157
157
  cmd: command,
158
158
  stdout: "pipe",
159
159
  stderr: "ignore",
160
+ windowsHide: true,
160
161
  });
161
162
  if (result.exitCode !== 0) {
162
163
  throw new Error(
@@ -173,6 +174,7 @@ async function runProcessTableCommandAsync(
173
174
  const { stdout } = await execFileAsync(command[0], command.slice(1), {
174
175
  encoding: "utf8",
175
176
  maxBuffer: 8 * 1024 * 1024,
177
+ windowsHide: true,
176
178
  });
177
179
  return parser(stdout);
178
180
  }
@@ -25,3 +25,8 @@ export const STDIN_FD = 0;
25
25
  export function readStdinSync(encoding: BufferEncoding = "utf-8"): string {
26
26
  return readFileSync(STDIN_FD, encoding);
27
27
  }
28
+
29
+ /** Read all data currently available on stdin as raw bytes. */
30
+ export function readStdinBytesSync(): Buffer {
31
+ return readFileSync(STDIN_FD);
32
+ }
package/src/util/spawn.ts CHANGED
@@ -29,6 +29,7 @@ export function spawnWithTimeout(
29
29
  const proc = Bun.spawn(cmd, {
30
30
  stdout: "pipe",
31
31
  stderr: "pipe",
32
+ windowsHide: true,
32
33
  env: {
33
34
  ...process.env,
34
35
  PATH: [
@@ -1804,6 +1804,7 @@ export class WorkspaceGitService {
1804
1804
  timeout: timeoutMs,
1805
1805
  env: { ...cleanGitEnv(this.workspaceDir), ...options?.env },
1806
1806
  signal: options?.signal,
1807
+ windowsHide: true,
1807
1808
  });
1808
1809
  return { stdout, stderr };
1809
1810
  } catch (err) {
@@ -242,6 +242,7 @@ export const appDirRenameMigration: WorkspaceMigration = {
242
242
  cwd: appsDir,
243
243
  stdio: "ignore",
244
244
  timeout: 10_000,
245
+ windowsHide: true,
245
246
  },
246
247
  );
247
248
  }