@minhspark/codex-mcp-bridge 1.20.1 → 1.21.1

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 (53) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +41 -0
  3. package/README.md +57 -15
  4. package/assets/README.md +30 -0
  5. package/assets/agent-pets.svg +1 -0
  6. package/docs/daily-handoffs.md +106 -0
  7. package/docs/desktop-handoff-design.md +180 -0
  8. package/docs/new-machine-setup.md +112 -0
  9. package/docs/project-onboarding.md +122 -0
  10. package/package.json +9 -3
  11. package/plugin.json +1 -1
  12. package/scripts/bridge-projects.mjs +41 -0
  13. package/scripts/check.mjs +2 -1
  14. package/scripts/collect-repo-analytics.mjs +5 -2
  15. package/scripts/configure-message-automation.mjs +18 -0
  16. package/scripts/install-claude-code.mjs +77 -0
  17. package/scripts/install-claude-desktop.mjs +48 -5
  18. package/scripts/install-native-relay.mjs +6 -1
  19. package/scripts/install-npm-footer.mjs +13 -1
  20. package/scripts/publish-repo-analytics.mjs +24 -1
  21. package/src/app-server-client.mjs +5 -2
  22. package/src/bridge-readiness.mjs +23 -0
  23. package/src/card-settings-sync.mjs +125 -0
  24. package/src/claude-bridge.mjs +54 -20
  25. package/src/claude-code-registration.mjs +54 -0
  26. package/src/claude-sender-context.mjs +1 -1
  27. package/src/claude-session-creation.mjs +10 -2
  28. package/src/codex-mcp-registration.mjs +1 -1
  29. package/src/codex-native-response.mjs +139 -107
  30. package/src/codex-sender-context.mjs +62 -61
  31. package/src/desktop-reply-receipts.mjs +93 -0
  32. package/src/desktop-task-receipts.mjs +30 -7
  33. package/src/hardened-root-policy.mjs +5 -0
  34. package/src/index.mjs +97 -19
  35. package/src/mcp-supervisor.mjs +6 -2
  36. package/src/message-automation.mjs +92 -0
  37. package/src/native-creation-receipts.mjs +159 -0
  38. package/src/native-relay-companion.mjs +37 -6
  39. package/src/native-relay.mjs +12 -3
  40. package/src/peer-protocol.mjs +192 -18
  41. package/src/project-manager-registration.mjs +31 -0
  42. package/src/project-onboarding-tools.mjs +30 -0
  43. package/src/project-onboarding.mjs +174 -0
  44. package/src/project-policy.mjs +256 -0
  45. package/src/project-scope.mjs +33 -5
  46. package/src/prompt-guidance.mjs +2 -0
  47. package/src/release-snapshot.mjs +30 -5
  48. package/src/rollout-reader.mjs +59 -0
  49. package/src/rollout-segments.mjs +65 -0
  50. package/src/security-policy.mjs +4 -2
  51. package/src/sites-connector.mjs +17 -2
  52. package/src/telemetry.mjs +10 -8
  53. package/src/thread-delivery.mjs +134 -35
@@ -0,0 +1,159 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { createHash, createHmac, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
4
+ import { execFileSync } from "node:child_process";
5
+ import { homeDir } from "./platform.mjs";
6
+
7
+ const sameFile = (left, right) => ["dev", "ino", "size", "mode", "uid", "nlink", "mtimeMs", "ctimeMs"].every(field => left[field] === right[field]);
8
+
9
+ export const creationIdValid = value => typeof value === "string" && /^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/.test(value);
10
+ export function creationRequestHash(args) {
11
+ const canonical = value => Array.isArray(value) ? value.map(canonical) : value && typeof value === "object"
12
+ ? Object.fromEntries(Object.keys(value).sort().filter(k => value[k] !== undefined).map(k => [k, canonical(value[k])])) : value;
13
+ return createHash("sha256").update(JSON.stringify(canonical(args))).digest("hex");
14
+ }
15
+
16
+ // Stores only exact native creation requests and their results. A missing or
17
+ // pending receipt never permits dispatch again, including after a restart.
18
+ export class NativeCreationReceipts {
19
+ #key;
20
+ #keyBoundary;
21
+ #keyDirectoryBoundary;
22
+ #keyDirectory;
23
+ constructor({ directory = path.join(process.env.CODEX_HOME ?? path.join(homeDir(), ".codex"), "bridge-native-creations") } = {}) {
24
+ this.directory = path.resolve(directory);
25
+ this.#keyDirectory = path.join(path.dirname(this.directory), "bridge-native-creation-authority");
26
+ }
27
+ #signingKey(create = false) {
28
+ if (create) {
29
+ try {
30
+ fs.mkdirSync(this.#keyDirectory, { mode: 0o700 });
31
+ if (process.platform === "win32") this.#protectWindowsPrivate(this.#keyDirectory, true);
32
+ } catch (error) { if (error.code !== "EEXIST") throw error; }
33
+ }
34
+ const directory = fs.lstatSync(this.#keyDirectory);
35
+ const canonical = fs.realpathSync.native(this.#keyDirectory);
36
+ if (!directory.isDirectory() || directory.isSymbolicLink() ||
37
+ process.platform !== "win32" && ((directory.mode & 0o077) || directory.uid !== process.getuid()) ||
38
+ this.#keyDirectoryBoundary && (this.#keyDirectoryBoundary.path !== canonical || this.#keyDirectoryBoundary.dev !== directory.dev || this.#keyDirectoryBoundary.ino !== directory.ino)) {
39
+ throw Error("Unsafe native creation authority directory");
40
+ }
41
+ if (process.platform === "win32" && !this.#keyDirectoryBoundary) {
42
+ this.#assertWindowsPrivate(canonical, true);
43
+ }
44
+ this.#keyDirectoryBoundary ??= { path: canonical, dev: directory.dev, ino: directory.ino };
45
+ const file = path.join(canonical, "signing-key");
46
+ if (create) {
47
+ let created, createdBoundary;
48
+ try {
49
+ created = fs.openSync(file, "wx", 0o600);
50
+ createdBoundary = fs.fstatSync(created);
51
+ if (process.platform === "win32") this.#protectWindowsPrivate(file, false);
52
+ fs.writeFileSync(created, randomBytes(32));
53
+ fs.fsyncSync(created);
54
+ }
55
+ catch (error) {
56
+ if (created !== undefined) {
57
+ fs.closeSync(created);
58
+ created = undefined;
59
+ const failed = fs.lstatSync(file);
60
+ if (failed.dev === createdBoundary.dev && failed.ino === createdBoundary.ino && !failed.isSymbolicLink()) fs.unlinkSync(file);
61
+ }
62
+ if (error.code !== "EEXIST") throw error;
63
+ }
64
+ finally { if (created !== undefined) fs.closeSync(created); }
65
+ }
66
+ const before = fs.lstatSync(file);
67
+ if (!before.isFile() || before.isSymbolicLink() || before.nlink !== 1 || before.size !== 32 ||
68
+ process.platform !== "win32" && ((before.mode & 0o077) || before.uid !== process.getuid())) throw Error("Unsafe native creation signing key");
69
+ if (process.platform === "win32" && !this.#keyBoundary) this.#assertWindowsPrivate(file, false);
70
+ const fd = fs.openSync(file, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0));
71
+ let key;
72
+ try {
73
+ const opened = fs.fstatSync(fd);
74
+ if (!opened.isFile() || !sameFile(before, opened)) throw Error("Native creation signing key changed");
75
+ const bytes = Buffer.alloc(33);
76
+ let count = 0, read;
77
+ while (count < bytes.length && (read = fs.readSync(fd, bytes, count, bytes.length - count, count))) count += read;
78
+ key = bytes.subarray(0, count);
79
+ const after = fs.fstatSync(fd);
80
+ const current = fs.lstatSync(file);
81
+ if (key.length !== 32 || current.isSymbolicLink() || !sameFile(opened, after) || !sameFile(after, current)) throw Error("Native creation signing key changed");
82
+ } finally { fs.closeSync(fd); }
83
+ if (this.#keyBoundary && (this.#keyBoundary.dev !== before.dev || this.#keyBoundary.ino !== before.ino || !timingSafeEqual(this.#key, key))) throw Error("Native creation signing key changed");
84
+ this.#keyBoundary ??= { dev: before.dev, ino: before.ino };
85
+ this.#key ??= key;
86
+ return this.#key;
87
+ }
88
+ #protectWindowsPrivate(file, directory) {
89
+ const encodedPath = Buffer.from(file, "utf8").toString("base64");
90
+ const securityType = directory ? "DirectorySecurity" : "FileSecurity";
91
+ const inheritance = directory ? "ContainerInherit,ObjectInherit" : "None";
92
+ const script = `$ErrorActionPreference='Stop';$s=[Security.Principal.WindowsIdentity]::GetCurrent().User;$a=New-Object Security.AccessControl.${securityType};$a.SetOwner($s);$a.SetAccessRuleProtection($true,$false);$r=New-Object Security.AccessControl.FileSystemAccessRule($s,'FullControl','${inheritance}','None','Allow');$a.AddAccessRule($r);Set-Acl -LiteralPath ([Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${encodedPath}'))) -AclObject $a`;
93
+ this.#runWindowsAclScript(script);
94
+ }
95
+ #assertWindowsPrivate(file, directory) {
96
+ const encodedPath = Buffer.from(file, "utf8").toString("base64");
97
+ const script = `$ErrorActionPreference='Stop';$a=Get-Acl -LiteralPath ([Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${encodedPath}')));$s=[Security.Principal.WindowsIdentity]::GetCurrent().User.Value;if(${directory ? "$true" : "$false"} -and !$a.AreAccessRulesProtected){throw 'Unprotected native authority'};if($a.GetOwner([Security.Principal.SecurityIdentifier]).Value -ne $s){throw 'Unexpected native authority owner'};foreach($r in $a.Access){if($r.IdentityReference.Translate([Security.Principal.SecurityIdentifier]).Value -ne $s -or $r.AccessControlType -ne 'Allow'){throw 'Unexpected native authority access'}};if($a.Access.Count -ne 1){throw 'Ambiguous native authority access'}`;
98
+ this.#runWindowsAclScript(script);
99
+ }
100
+ #runWindowsAclScript(script) {
101
+ const shellDirectory = path.win32.join(process.env.SystemRoot ?? "C:\\Windows", "System32", "WindowsPowerShell", "v1.0");
102
+ const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => key.toLowerCase() !== "psmodulepath"));
103
+ env.PSModulePath = path.win32.join(shellDirectory, "Modules");
104
+ execFileSync(path.win32.join(shellDirectory, "powershell.exe"), ["-NoProfile", "-NonInteractive", "-EncodedCommand", Buffer.from(script, "utf16le").toString("base64")], { env, stdio: "pipe", windowsHide: true, timeout: 10000 });
105
+ }
106
+ #signature(row, create = false) {
107
+ const { signature, ...payload } = row;
108
+ return createHmac("sha256", this.#signingKey(create)).update("native-creation-receipt-v1\0").update(creationRequestHash(payload)).digest("hex");
109
+ }
110
+ file(id) {
111
+ if (!creationIdValid(id)) throw Error("Invalid native creation receipt id");
112
+ fs.mkdirSync(this.directory, { recursive: true, mode: 0o700 });
113
+ const st = fs.lstatSync(this.directory);
114
+ if (!st.isDirectory() || st.isSymbolicLink()) throw Error("Unsafe native creation receipt directory");
115
+ const canonical = fs.realpathSync.native(this.directory);
116
+ if (this.boundary && (this.boundary.path !== canonical || this.boundary.dev !== st.dev || this.boundary.ino !== st.ino)) throw Error("Native creation receipt directory changed");
117
+ this.boundary ??= { path: canonical, dev: st.dev, ino: st.ino };
118
+ this.directory = canonical;
119
+ return path.join(canonical, id + ".json");
120
+ }
121
+ read(id, accounts, hash) {
122
+ const file = this.file(id);
123
+ let fd, receiptFound = false;
124
+ try {
125
+ const before = fs.lstatSync(file);
126
+ receiptFound = true;
127
+ if (!before.isFile() || before.isSymbolicLink() || before.nlink !== 1 || before.size > 1024 * 1024) throw Error("Unsafe native creation receipt");
128
+ fd = fs.openSync(file, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0));
129
+ const opened = fs.fstatSync(fd);
130
+ if (!opened.isFile() || !sameFile(before, opened)) throw Error("Native creation receipt changed");
131
+ const bytes = Buffer.alloc(1024 * 1024 + 1);
132
+ let count = 0, n;
133
+ while ((n = fs.readSync(fd, bytes, count, bytes.length - count, count))) { count += n; if (count > 1024 * 1024) throw Error("Oversized native creation receipt"); }
134
+ const after = fs.fstatSync(fd);
135
+ const current = fs.lstatSync(this.file(id));
136
+ if (current.isSymbolicLink() || !sameFile(opened, after) || !sameFile(after, current) || count !== opened.size) throw Error("Native creation receipt changed");
137
+ const row = JSON.parse(bytes.subarray(0, count).toString());
138
+ if (row.version !== 1 || row.id !== id || row.hash !== hash || creationRequestHash(row.args) !== hash ||
139
+ !accounts || ["claude", "codex"].some(k => !accounts[k] || row.accounts?.[k] !== accounts[k]) ||
140
+ typeof row.executorThreadId !== "string" || !["pending", "completed", "failed"].includes(row.state)) throw Error("Native creation receipt binding mismatch");
141
+ if (typeof row.signature !== "string" || !/^[a-f0-9]{64}$/.test(row.signature) ||
142
+ !timingSafeEqual(Buffer.from(row.signature, "hex"), Buffer.from(this.#signature(row), "hex"))) throw Error("Native creation receipt signature is invalid; ownership recovery is blocked");
143
+ return row;
144
+ } catch (e) { if (e.code === "ENOENT" && !receiptFound) return null; throw e; }
145
+ finally { if (fd !== undefined) fs.closeSync(fd); }
146
+ }
147
+ reserve(id, args, accounts, executorThreadId) {
148
+ const row = { version: 1, id, hash: creationRequestHash(args), args, accounts, executorThreadId, state: "pending" };
149
+ this.write(row, true); return row;
150
+ }
151
+ write(row, exclusive = false) {
152
+ const file = this.file(row.id), tmp = exclusive ? file : file + "." + randomUUID() + ".pending";
153
+ const bytes = JSON.stringify({ ...row, signature: this.#signature(row, exclusive) });
154
+ if (Buffer.byteLength(bytes) > 1024 * 1024) throw Error("Oversized native creation receipt");
155
+ const fd = fs.openSync(tmp, "wx", 0o600);
156
+ try { fs.writeFileSync(fd, bytes); fs.fsyncSync(fd); } finally { fs.closeSync(fd); }
157
+ if (!exclusive) fs.renameSync(tmp, file);
158
+ }
159
+ }
@@ -32,9 +32,11 @@ import { hardenedBridgeEnabled } from "./hardened-root-policy.mjs";
32
32
  import { protectCurrentUserPipe } from "./windows-pipe-acl.mjs";
33
33
  import { createHardenedRootPolicy } from "./hardened-root-policy.mjs";
34
34
 
35
+ import { NativeCreationReceipts, creationIdValid } from "./native-creation-receipts.mjs";
36
+
35
37
  exitForVersionRequest(import.meta.url);
36
38
 
37
- const VERSION = "1.20.1";
39
+ const VERSION = "1.21.1";
38
40
  const log = (msg) => process.stderr.write(`[native-relay] ${msg}\n`);
39
41
 
40
42
  function errorResponse(code, message, sent) {
@@ -238,12 +240,12 @@ export function createNativeScopeAuthorizer({ dispatchDesktop, env = process.env
238
240
  */
239
241
  export async function handleRelayRequest(
240
242
  payload,
241
- { dispatch, dispatchDesktop, resolveExecutor = resolveRelayThreadId, env = process.env, assertAccount = assertAccountIdentity, authorize, strict = hardenedBridgeEnabled(env) } = {},
243
+ { dispatch, dispatchDesktop, resolveExecutor = resolveRelayThreadId, env = process.env, assertAccount = assertAccountIdentity, authorize, creationReceipts = new NativeCreationReceipts(), strict = hardenedBridgeEnabled(env) } = {},
242
244
  ) {
243
245
  if (strict && (!boundRequest(payload) || !validProtocol(payload))) return errorResponse("RELAY_BAD_REQUEST", "Hardened relay accepts only protocol 2 requests with account context", false);
244
246
  if (strict && typeof authorize !== "function") return errorResponse("NATIVE_SCOPE_UNVERIFIED", "Hardened relay requires verified current native project and task metadata; no dispatch was attempted", false);
245
247
  if (payload && typeof payload === "object" && Object.hasOwn(payload, "operation")) {
246
- return handleDesktopRequest(payload, { dispatchDesktop, resolveExecutor, env, assertAccount, authorize, strict });
248
+ return handleDesktopRequest(payload, { dispatchDesktop, resolveExecutor, env, assertAccount, authorize, creationReceipts, strict });
247
249
  }
248
250
  if (!payload || typeof payload !== "object" || Array.isArray(payload) ||
249
251
  Object.keys(payload).some((key) => !["v", "targetThreadId", "message", "accountContext"].includes(key)) || !validProtocol(payload)) {
@@ -295,14 +297,15 @@ export async function handleRelayRequest(
295
297
  }
296
298
  }
297
299
 
298
- async function handleDesktopRequest(payload, { dispatchDesktop, resolveExecutor, env, assertAccount, authorize, strict = hardenedBridgeEnabled(env) }) {
300
+ async function handleDesktopRequest(payload, { dispatchDesktop, resolveExecutor, env, assertAccount, authorize, creationReceipts, strict = hardenedBridgeEnabled(env) }) {
299
301
  if (strict && !boundRequest(payload)) return errorResponse("RELAY_BAD_REQUEST", "Hardened relay accepts only protocol 2 Desktop operations", false);
300
302
  if (Array.isArray(payload) || ![RELAY_PROTOCOL_VERSION, ACCOUNT_RELAY_PROTOCOL_VERSION].includes(payload.v) || !validProtocol(payload) ||
301
- Object.keys(payload).some((key) => !["v", "operation", "arguments", "accountContext"].includes(key))) {
303
+ Object.keys(payload).some((key) => !["v", "operation", "arguments", "accountContext", "creationReceiptId"].includes(key))) {
302
304
  return errorResponse("RELAY_BAD_REQUEST", "expected an allowlisted Desktop operation");
303
305
  }
304
306
  try {
305
307
  validateDesktopOperation(payload.operation, payload.arguments);
308
+ if (payload.creationReceiptId !== undefined && (payload.operation !== "create_thread" || !boundRequest(payload) || !creationIdValid(payload.creationReceiptId))) throw new NativeRelayError("Invalid creation receipt binding", "RELAY_BAD_REQUEST");
306
309
  let accountContext;
307
310
  try {
308
311
  accountContext = await checkAccountContext(payload, assertAccount);
@@ -313,12 +316,29 @@ async function handleDesktopRequest(payload, { dispatchDesktop, resolveExecutor,
313
316
  return errorResponse("NATIVE_OPERATION_UNAVAILABLE", "This companion does not support Desktop operations; reload the native relay");
314
317
  }
315
318
  const executorThreadId = resolveExecutor(env).threadId;
319
+ if (payload.operation === "get_creation_receipt") {
320
+ if (!accountContext) throw new NativeRelayError("Creation receipts require bound accounts", "RELAY_BAD_REQUEST");
321
+ const row = creationReceipts.read(payload.arguments.receiptId, accountContext, payload.arguments.requestHash);
322
+ if (row && row.executorThreadId !== executorThreadId) throw new NativeRelayError("Creation receipt executor changed", "NATIVE_SCOPE_UNVERIFIED");
323
+ const original = row ? { executorThreadId, operation: "create_thread", arguments: row.args, accountContext } : { executorThreadId, operation: "list_projects", arguments: {}, accountContext };
324
+ if (strict) {
325
+ const initial = await authorize(original);
326
+ if (row?.state === "completed") await authorize({ ...original, phase: "return", expected: initial, result: row.result });
327
+ }
328
+ await assertAccount(accountContext);
329
+ return { ok: true, v: payload.v, operation: payload.operation, executorThreadId,
330
+ result: { status: row?.state ?? "missing", ...(row?.state === "completed" ? { result: row.result } : {}), ...(row?.state === "failed" ? { error: row.error } : {}) } };
331
+ }
316
332
  const request = { executorThreadId, targetThreadId: payload.arguments?.threadId, operation: payload.operation, arguments: payload.arguments, accountContext };
317
333
  const authorization = strict ? await authorize(request) : null;
318
334
  if (payload.operation === "send_message_to_thread" && payload.arguments.threadId === executorThreadId) {
319
335
  return errorResponse("RELAY_BAD_REQUEST", "The relay executor cannot receive its own relayed message");
320
336
  }
321
- const nativeResult = await dispatchDesktop({
337
+ // Reserve before dispatch. A disconnected caller must not discard a late
338
+ // result, and even identical duplicate writes must not dispatch twice.
339
+ const creation = payload.creationReceiptId ? creationReceipts.reserve(payload.creationReceiptId, payload.arguments, accountContext, executorThreadId) : null;
340
+ let nativeResult;
341
+ try { nativeResult = await dispatchDesktop({
322
342
  executorThreadId,
323
343
  operation: payload.operation,
324
344
  arguments: payload.arguments,
@@ -328,6 +348,10 @@ async function handleDesktopRequest(payload, { dispatchDesktop, resolveExecutor,
328
348
  });
329
349
  const decoded = decodeNativeToolResult(nativeResult);
330
350
  const checked = strict ? await authorize({ ...request, phase: "return", expected: authorization, result: decoded }) : null;
351
+ if (creation) {
352
+ await assertAccount(accountContext);
353
+ creationReceipts.write({ ...creation, state: "completed", result: checked?.result ?? decoded });
354
+ }
331
355
  return {
332
356
  ok: true,
333
357
  v: boundRequest(payload) ? ACCOUNT_RELAY_PROTOCOL_VERSION : RELAY_PROTOCOL_VERSION,
@@ -335,6 +359,10 @@ async function handleDesktopRequest(payload, { dispatchDesktop, resolveExecutor,
335
359
  executorThreadId,
336
360
  result: checked?.result ?? decoded,
337
361
  };
362
+ } catch (error) {
363
+ if (creation) creationReceipts.write({ ...creation, state: "failed", error: { code: errorCode(error), message: error.message } });
364
+ throw error;
365
+ }
338
366
  } catch (err) {
339
367
  return errorResponse(errorCode(err), err?.message ?? String(err), err?.sent === false && err?.reachedCompanion !== true ? false : undefined);
340
368
  }
@@ -354,6 +382,7 @@ export class RelaySocketServer {
354
382
  resolveExecutor = resolveRelayThreadId,
355
383
  assertAccount = assertAccountIdentity,
356
384
  authorize,
385
+ creationReceipts = new NativeCreationReceipts(),
357
386
  requireAccountContext = false,
358
387
  strict = hardenedBridgeEnabled(),
359
388
  protectSocket = protectCurrentUserPipe,
@@ -368,6 +397,7 @@ export class RelaySocketServer {
368
397
  this.resolveExecutor = resolveExecutor;
369
398
  this.assertAccount = assertAccount;
370
399
  this.authorize = authorize;
400
+ this.creationReceipts = creationReceipts;
371
401
  this.requireAccountContext = requireAccountContext;
372
402
  this.strict = strict;
373
403
  this.protectSocket = protectSocket;
@@ -574,6 +604,7 @@ export class RelaySocketServer {
574
604
  assertAccount: this.assertAccount,
575
605
  authorize: this.authorize,
576
606
  strict: this.strict,
607
+ creationReceipts: this.creationReceipts,
577
608
  });
578
609
  if (!response.ok) this.log(`relay refused ${payload?.targetThreadId ?? "?"}: ${response.error.message}`);
579
610
  else this.log(response.operation ? `completed Desktop operation ${response.operation}` : `relayed a message into thread ${response.targetThreadId}`);
@@ -177,6 +177,8 @@ export function nativeDispatchParams({ executorThreadId, targetThreadId, message
177
177
  };
178
178
  }
179
179
 
180
+ import { creationIdValid } from "./native-creation-receipts.mjs";
181
+
180
182
  const DESKTOP_EFFORTS = new Set(["none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"]);
181
183
 
182
184
  function exactObject(value, keys) {
@@ -201,6 +203,9 @@ export function validateDesktopOperation(operation, args) {
201
203
  const modelSettings = () => optionalText(args.model) &&
202
204
  (args.thinking === undefined || DESKTOP_EFFORTS.has(args.thinking));
203
205
  switch (operation) {
206
+ case "get_creation_receipt":
207
+ valid = exactObject(args, ["receiptId", "requestHash"]) && creationIdValid(args.receiptId) && /^[a-f0-9]{64}$/.test(args.requestHash);
208
+ break;
204
209
  case "list_projects":
205
210
  valid = exactObject(args, []);
206
211
  break;
@@ -540,7 +545,10 @@ export async function resolveNativeToolsPipePath({
540
545
  const remaining = deadline - Date.now();
541
546
  if (remaining <= 0) break;
542
547
  try {
543
- if (await probeWindowsPipe(candidate, { env, timeoutMs: Math.min(750, remaining) })) return candidate;
548
+ // Cold Desktop metadata reads can take over a second. Keep the shared
549
+ // seven-second discovery budget, but do not reject a valid endpoint
550
+ // merely because its first read exceeds the old 750ms probe window.
551
+ if (await probeWindowsPipe(candidate, { env, timeoutMs: Math.min(3000, remaining) })) return candidate;
544
552
  } catch {}
545
553
  }
546
554
  return null;
@@ -801,11 +809,12 @@ export class NativeDesktopRelay {
801
809
  return this.#request(request, timeoutMs, beforeSend);
802
810
  }
803
811
 
804
- async requestDesktop(operation, args, { timeoutMs = this.timeoutMs, beforeSend, accountContext } = {}) {
812
+ async requestDesktop(operation, args, { timeoutMs = this.timeoutMs, beforeSend, accountContext, creationReceiptId } = {}) {
805
813
  validateDesktopOperation(operation, args);
806
814
  const accounts = relayAccountContext(accountContext);
807
815
  if (hardenedBridgeEnabled(this.env) && !accounts) throw beforeWriteError(new NativeRelayError("Hardened relay requires protocol 2 account context", "RELAY_BAD_REQUEST"));
808
- return this.#request({ v: accounts ? ACCOUNT_RELAY_PROTOCOL_VERSION : RELAY_PROTOCOL_VERSION, operation, arguments: args, ...(accounts ? { accountContext: accounts } : {}) }, timeoutMs, beforeSend);
816
+ if (creationReceiptId !== undefined && (operation !== "create_thread" || !accounts || !creationIdValid(creationReceiptId))) throw beforeWriteError(new NativeRelayError("Invalid creation receipt binding", "RELAY_BAD_REQUEST"));
817
+ return this.#request({ v: accounts ? ACCOUNT_RELAY_PROTOCOL_VERSION : RELAY_PROTOCOL_VERSION, operation, arguments: args, ...(accounts ? { accountContext: accounts } : {}), ...(creationReceiptId ? { creationReceiptId } : {}) }, timeoutMs, beforeSend);
809
818
  }
810
819
 
811
820
  async #request(request, timeoutMs, beforeSend) {