grok-bot-cli 0.4.1 → 0.4.2

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/bin/gbot.mjs CHANGED
@@ -11456,6 +11456,140 @@ __webpack_require__.d(__webpack_exports__, {
11456
11456
  });
11457
11457
 
11458
11458
 
11459
+ },
11460
+ "./src/cli/codex/desktop-shim.tsx"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
11461
+ __webpack_require__.r(__webpack_exports__);
11462
+ /* import */ var react_jsx_runtime__rspack_import_0 = __webpack_require__("./node_modules/react/jsx-runtime.js");
11463
+ /* import */ var _agent_bundle_runtime__rspack_import_3 = __webpack_require__("./node_modules/@agent-bundle/runtime/dist/506.js");
11464
+ /* import */ var zod__rspack_import_2 = __webpack_require__("./node_modules/zod/v4/classic/schemas.js");
11465
+ /* import */ var _core_desktop_shim_js__rspack_import_1 = __webpack_require__("./src/core/desktop-shim.js");
11466
+ /* import */ var _core_format_js__rspack_import_4 = __webpack_require__("./src/core/format.js");
11467
+
11468
+
11469
+
11470
+
11471
+
11472
+ const config = {
11473
+ description: 'Install, remove, or check the ChatGPT Desktop shim: a CODEX_CLI_PATH wrapper that bridges Desktop stdio onto the managed Codex daemon (stock app-server proxy hangs). macOS persists via LaunchAgent; always fails open to real Codex.',
11474
+ exitCode: 'result',
11475
+ inputJsonSchema: {
11476
+ additionalProperties: false,
11477
+ properties: {
11478
+ action: {
11479
+ description: 'install | uninstall | status',
11480
+ enum: [
11481
+ 'install',
11482
+ 'uninstall',
11483
+ 'status'
11484
+ ],
11485
+ type: 'string'
11486
+ }
11487
+ },
11488
+ required: [
11489
+ 'action'
11490
+ ],
11491
+ type: 'object'
11492
+ },
11493
+ positionals: [
11494
+ 'action'
11495
+ ]
11496
+ };
11497
+ const inputSchema = zod__rspack_import_2/* .object */.Ikc({
11498
+ action: zod__rspack_import_2/* ["enum"] */.k5n([
11499
+ 'install',
11500
+ 'uninstall',
11501
+ 'status'
11502
+ ])
11503
+ }).strict();
11504
+ const resultSchema = zod__rspack_import_2/* .object */.Ikc({
11505
+ exitCode: zod__rspack_import_2/* .union */.KCZ([
11506
+ zod__rspack_import_2/* .literal */.euz(0),
11507
+ zod__rspack_import_2/* .literal */.euz(1)
11508
+ ])
11509
+ }).passthrough();
11510
+ const formatWarnings = (warnings)=>warnings.length === 0 ? '' : `\nwarnings:\n${warnings.map((w)=>` - ${String(w)}`).join('\n')}`;
11511
+ async function codexDesktopShim({ input }) {
11512
+ switch(input.action){
11513
+ case 'install':
11514
+ {
11515
+ let out;
11516
+ try {
11517
+ out = (0,_core_desktop_shim_js__rspack_import_1/* .installDesktopShim */.B0)();
11518
+ } catch (error) {
11519
+ const message = error instanceof Error ? error.message : String(error);
11520
+ return /*#__PURE__*/ (0,react_jsx_runtime__rspack_import_0.jsx)(_agent_bundle_runtime__rspack_import_3/* .Agent.Result */.g6.Result, {
11521
+ value: {
11522
+ action: 'install',
11523
+ error: message,
11524
+ exitCode: 1
11525
+ },
11526
+ children: /*#__PURE__*/ (0,react_jsx_runtime__rspack_import_0.jsx)(_agent_bundle_runtime__rspack_import_3/* .Agent.Text */.g6.Text, {
11527
+ children: `Desktop shim install failed: ${message}`
11528
+ })
11529
+ });
11530
+ }
11531
+ const text = `Installed ChatGPT Desktop shim:\n` + ` wrapper: ${out.wrapperPath}\n` + ` bridge: ${out.bridgePath}\n` + ` login env: ${out.envScriptPath}` + (out.plistPath ? `\n LaunchAgent: ${out.plistPath}` : '\n LaunchAgent: n/a (macOS-only)') + `\nFully quit and relaunch ChatGPT.app so it inherits CODEX_CLI_PATH; ` + `Desktop falls back to stock Codex if the shim is ever removed.` + formatWarnings(out.warnings);
11532
+ return /*#__PURE__*/ (0,react_jsx_runtime__rspack_import_0.jsx)(_agent_bundle_runtime__rspack_import_3/* .Agent.Result */.g6.Result, {
11533
+ value: out,
11534
+ children: /*#__PURE__*/ (0,react_jsx_runtime__rspack_import_0.jsx)(_agent_bundle_runtime__rspack_import_3/* .Agent.Text */.g6.Text, {
11535
+ children: text
11536
+ })
11537
+ });
11538
+ }
11539
+ case 'uninstall':
11540
+ {
11541
+ let out;
11542
+ try {
11543
+ out = (0,_core_desktop_shim_js__rspack_import_1/* .uninstallDesktopShim */.gM)();
11544
+ } catch (error) {
11545
+ const message = error instanceof Error ? error.message : String(error);
11546
+ return /*#__PURE__*/ (0,react_jsx_runtime__rspack_import_0.jsx)(_agent_bundle_runtime__rspack_import_3/* .Agent.Result */.g6.Result, {
11547
+ value: {
11548
+ action: 'uninstall',
11549
+ error: message,
11550
+ exitCode: 1
11551
+ },
11552
+ children: /*#__PURE__*/ (0,react_jsx_runtime__rspack_import_0.jsx)(_agent_bundle_runtime__rspack_import_3/* .Agent.Text */.g6.Text, {
11553
+ children: `Desktop shim uninstall failed: ${message}`
11554
+ })
11555
+ });
11556
+ }
11557
+ const removed = out.removed.length === 0 ? '(nothing installed)' : out.removed.join(', ');
11558
+ const text = `Removed ChatGPT Desktop shim: ${removed}. ` + `Desktop and Codex fall back to stock behavior; relaunch ChatGPT.app to pick it up.` + formatWarnings(out.warnings);
11559
+ return /*#__PURE__*/ (0,react_jsx_runtime__rspack_import_0.jsx)(_agent_bundle_runtime__rspack_import_3/* .Agent.Result */.g6.Result, {
11560
+ value: out,
11561
+ children: /*#__PURE__*/ (0,react_jsx_runtime__rspack_import_0.jsx)(_agent_bundle_runtime__rspack_import_3/* .Agent.Text */.g6.Text, {
11562
+ children: text
11563
+ })
11564
+ });
11565
+ }
11566
+ case 'status':
11567
+ {
11568
+ const out = (0,_core_desktop_shim_js__rspack_import_1/* .desktopShimStatus */.em)();
11569
+ return /*#__PURE__*/ (0,react_jsx_runtime__rspack_import_0.jsx)(_agent_bundle_runtime__rspack_import_3/* .Agent.Result */.g6.Result, {
11570
+ value: out,
11571
+ children: /*#__PURE__*/ (0,react_jsx_runtime__rspack_import_0.jsx)(_agent_bundle_runtime__rspack_import_3/* .Agent.Text */.g6.Text, {
11572
+ children: (0,_core_format_js__rspack_import_4/* .formatDesktopShimStatus */.fX)(out)
11573
+ })
11574
+ });
11575
+ }
11576
+ default:
11577
+ {
11578
+ const _exhaustive = input.action;
11579
+ throw new Error(`unknown desktop-shim action: ${String(_exhaustive)}`);
11580
+ }
11581
+ }
11582
+ }
11583
+
11584
+ __webpack_require__.d(__webpack_exports__, {
11585
+ "default": () => (codexDesktopShim)
11586
+ }, {
11587
+ config: config,
11588
+ inputSchema: inputSchema,
11589
+ resultSchema: resultSchema
11590
+ });
11591
+
11592
+
11459
11593
  },
11460
11594
  "./src/cli/codex/list-threads.tsx"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
11461
11595
  __webpack_require__.r(__webpack_exports__);
@@ -82746,9 +82880,9 @@ __webpack_require__.d(__webpack_exports__, {
82746
82880
  __webpack_require__.a(__webpack_module__, async function (__rspack_load_async_deps, __rspack_async_done) { try {
82747
82881
  /* import */ var agent_bundle_launch_env_layer__rspack_import_0 = __webpack_require__("./.agent-bundle-virtual/bin-gbot-0.mjs");
82748
82882
  /* import */ var agent_bundle_cli_entry__rspack_import_1 = __webpack_require__("./node_modules/agent-bundle/dist/cli-entry.js");
82749
- /* import */ var _agent_bundle_runtime__rspack_import_26 = __webpack_require__("./node_modules/@agent-bundle/runtime/dist/49.js");
82750
- /* import */ var _agent_bundle_runtime__rspack_import_27 = __webpack_require__("./node_modules/@agent-bundle/runtime/dist/736.js");
82751
- /* import */ var _agent_bundle_runtime__rspack_import_28 = __webpack_require__("./node_modules/@agent-bundle/runtime/dist/index.js");
82883
+ /* import */ var _agent_bundle_runtime__rspack_import_27 = __webpack_require__("./node_modules/@agent-bundle/runtime/dist/49.js");
82884
+ /* import */ var _agent_bundle_runtime__rspack_import_28 = __webpack_require__("./node_modules/@agent-bundle/runtime/dist/736.js");
82885
+ /* import */ var _agent_bundle_runtime__rspack_import_29 = __webpack_require__("./node_modules/@agent-bundle/runtime/dist/index.js");
82752
82886
  /* import */ var node_url__rspack_import_2 = __webpack_require__("node:url");
82753
82887
  /* import */ var node_worker_threads__rspack_import_3 = __webpack_require__("node:worker_threads");
82754
82888
  /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_bots_create_tsx__rspack_import_4 = __webpack_require__("./src/cli/bots/create.tsx");
@@ -82756,23 +82890,24 @@ __webpack_require__.a(__webpack_module__, async function (__rspack_load_async_de
82756
82890
  /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_bots_get_tsx__rspack_import_6 = __webpack_require__("./src/cli/bots/get.tsx");
82757
82891
  /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_bots_list_tsx__rspack_import_7 = __webpack_require__("./src/cli/bots/list.tsx");
82758
82892
  /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_bots_update_tsx__rspack_import_8 = __webpack_require__("./src/cli/bots/update.tsx");
82759
- /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_list_threads_tsx__rspack_import_9 = __webpack_require__("./src/cli/codex/list-threads.tsx");
82760
- /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_queue_tsx__rspack_import_10 = __webpack_require__("./src/cli/codex/queue.tsx");
82761
- /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_send_tsx__rspack_import_11 = __webpack_require__("./src/cli/codex/send.tsx");
82762
- /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_status_tsx__rspack_import_12 = __webpack_require__("./src/cli/codex/status.tsx");
82763
- /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_doctor_tsx__rspack_import_13 = __webpack_require__("./src/cli/doctor.tsx");
82764
- /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_add_tsx__rspack_import_14 = __webpack_require__("./src/cli/groups/add.tsx");
82765
- /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_create_tsx__rspack_import_15 = __webpack_require__("./src/cli/groups/create.tsx");
82766
- /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_delete_tsx__rspack_import_16 = __webpack_require__("./src/cli/groups/delete.tsx");
82767
- /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_get_tsx__rspack_import_17 = __webpack_require__("./src/cli/groups/get.tsx");
82768
- /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_list_tsx__rspack_import_18 = __webpack_require__("./src/cli/groups/list.tsx");
82769
- /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_members_tsx__rspack_import_19 = __webpack_require__("./src/cli/groups/members.tsx");
82770
- /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_remove_tsx__rspack_import_20 = __webpack_require__("./src/cli/groups/remove.tsx");
82771
- /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_set_tsx__rspack_import_21 = __webpack_require__("./src/cli/groups/set.tsx");
82772
- /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_update_tsx__rspack_import_22 = __webpack_require__("./src/cli/groups/update.tsx");
82773
- /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_history_tsx__rspack_import_23 = __webpack_require__("./src/cli/history.tsx");
82774
- /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_send_tsx__rspack_import_24 = __webpack_require__("./src/cli/send.tsx");
82775
- /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_thread_tsx__rspack_import_25 = __webpack_require__("./src/cli/thread.tsx");
82893
+ /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_desktop_shim_tsx__rspack_import_9 = __webpack_require__("./src/cli/codex/desktop-shim.tsx");
82894
+ /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_list_threads_tsx__rspack_import_10 = __webpack_require__("./src/cli/codex/list-threads.tsx");
82895
+ /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_queue_tsx__rspack_import_11 = __webpack_require__("./src/cli/codex/queue.tsx");
82896
+ /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_send_tsx__rspack_import_12 = __webpack_require__("./src/cli/codex/send.tsx");
82897
+ /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_status_tsx__rspack_import_13 = __webpack_require__("./src/cli/codex/status.tsx");
82898
+ /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_doctor_tsx__rspack_import_14 = __webpack_require__("./src/cli/doctor.tsx");
82899
+ /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_add_tsx__rspack_import_15 = __webpack_require__("./src/cli/groups/add.tsx");
82900
+ /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_create_tsx__rspack_import_16 = __webpack_require__("./src/cli/groups/create.tsx");
82901
+ /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_delete_tsx__rspack_import_17 = __webpack_require__("./src/cli/groups/delete.tsx");
82902
+ /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_get_tsx__rspack_import_18 = __webpack_require__("./src/cli/groups/get.tsx");
82903
+ /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_list_tsx__rspack_import_19 = __webpack_require__("./src/cli/groups/list.tsx");
82904
+ /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_members_tsx__rspack_import_20 = __webpack_require__("./src/cli/groups/members.tsx");
82905
+ /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_remove_tsx__rspack_import_21 = __webpack_require__("./src/cli/groups/remove.tsx");
82906
+ /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_set_tsx__rspack_import_22 = __webpack_require__("./src/cli/groups/set.tsx");
82907
+ /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_update_tsx__rspack_import_23 = __webpack_require__("./src/cli/groups/update.tsx");
82908
+ /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_history_tsx__rspack_import_24 = __webpack_require__("./src/cli/history.tsx");
82909
+ /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_send_tsx__rspack_import_25 = __webpack_require__("./src/cli/send.tsx");
82910
+ /* import */ var _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_thread_tsx__rspack_import_26 = __webpack_require__("./src/cli/thread.tsx");
82776
82911
 
82777
82912
 
82778
82913
 
@@ -82789,40 +82924,42 @@ const route3 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok
82789
82924
 
82790
82925
  const route4 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_bots_update_tsx__rspack_import_8, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_bots_update_tsx__rspack_import_8);
82791
82926
 
82792
- const route5 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_list_threads_tsx__rspack_import_9, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_list_threads_tsx__rspack_import_9);
82927
+ const route5 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_desktop_shim_tsx__rspack_import_9, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_desktop_shim_tsx__rspack_import_9);
82793
82928
 
82794
- const route6 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_queue_tsx__rspack_import_10, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_queue_tsx__rspack_import_10);
82929
+ const route6 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_list_threads_tsx__rspack_import_10, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_list_threads_tsx__rspack_import_10);
82795
82930
 
82796
- const route7 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_send_tsx__rspack_import_11, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_send_tsx__rspack_import_11);
82931
+ const route7 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_queue_tsx__rspack_import_11, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_queue_tsx__rspack_import_11);
82797
82932
 
82798
- const route8 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_status_tsx__rspack_import_12, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_status_tsx__rspack_import_12);
82933
+ const route8 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_send_tsx__rspack_import_12, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_send_tsx__rspack_import_12);
82799
82934
 
82800
- const route9 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_doctor_tsx__rspack_import_13, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_doctor_tsx__rspack_import_13);
82935
+ const route9 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_status_tsx__rspack_import_13, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_codex_status_tsx__rspack_import_13);
82801
82936
 
82802
- const route10 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_add_tsx__rspack_import_14, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_add_tsx__rspack_import_14);
82937
+ const route10 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_doctor_tsx__rspack_import_14, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_doctor_tsx__rspack_import_14);
82803
82938
 
82804
- const route11 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_create_tsx__rspack_import_15, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_create_tsx__rspack_import_15);
82939
+ const route11 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_add_tsx__rspack_import_15, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_add_tsx__rspack_import_15);
82805
82940
 
82806
- const route12 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_delete_tsx__rspack_import_16, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_delete_tsx__rspack_import_16);
82941
+ const route12 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_create_tsx__rspack_import_16, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_create_tsx__rspack_import_16);
82807
82942
 
82808
- const route13 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_get_tsx__rspack_import_17, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_get_tsx__rspack_import_17);
82943
+ const route13 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_delete_tsx__rspack_import_17, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_delete_tsx__rspack_import_17);
82809
82944
 
82810
- const route14 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_list_tsx__rspack_import_18, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_list_tsx__rspack_import_18);
82945
+ const route14 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_get_tsx__rspack_import_18, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_get_tsx__rspack_import_18);
82811
82946
 
82812
- const route15 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_members_tsx__rspack_import_19, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_members_tsx__rspack_import_19);
82947
+ const route15 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_list_tsx__rspack_import_19, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_list_tsx__rspack_import_19);
82813
82948
 
82814
- const route16 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_remove_tsx__rspack_import_20, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_remove_tsx__rspack_import_20);
82949
+ const route16 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_members_tsx__rspack_import_20, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_members_tsx__rspack_import_20);
82815
82950
 
82816
- const route17 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_set_tsx__rspack_import_21, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_set_tsx__rspack_import_21);
82951
+ const route17 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_remove_tsx__rspack_import_21, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_remove_tsx__rspack_import_21);
82817
82952
 
82818
- const route18 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_update_tsx__rspack_import_22, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_update_tsx__rspack_import_22);
82953
+ const route18 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_set_tsx__rspack_import_22, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_set_tsx__rspack_import_22);
82819
82954
 
82820
- const route19 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_history_tsx__rspack_import_23, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_history_tsx__rspack_import_23);
82955
+ const route19 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_update_tsx__rspack_import_23, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_groups_update_tsx__rspack_import_23);
82821
82956
 
82822
- const route20 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_send_tsx__rspack_import_24, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_send_tsx__rspack_import_24);
82957
+ const route20 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_history_tsx__rspack_import_24, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_history_tsx__rspack_import_24);
82823
82958
 
82824
- const route21 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_thread_tsx__rspack_import_25, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_thread_tsx__rspack_import_25);
82825
- const pluginRoot = (0,_agent_bundle_runtime__rspack_import_26/* .resolvePluginRoot */.E7)({
82959
+ const route21 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_send_tsx__rspack_import_25, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_send_tsx__rspack_import_25);
82960
+
82961
+ const route22 = Object.assign({}, Reflect.get(_home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_thread_tsx__rspack_import_26, 'default'), _home_runner_work_grok_bot_cli_grok_bot_cli_src_cli_thread_tsx__rspack_import_26);
82962
+ const pluginRoot = (0,_agent_bundle_runtime__rspack_import_27/* .resolvePluginRoot */.E7)({
82826
82963
  fallback: (0,node_url__rspack_import_2.fileURLToPath)(new URL('..', import.meta.url)),
82827
82964
  stateAnchor: 'user-data'
82828
82965
  });
@@ -82847,56 +82984,59 @@ const routes = Object.freeze({
82847
82984
  "cli:bots/update": Object.freeze({
82848
82985
  module: route4
82849
82986
  }),
82850
- "cli:codex/list-threads": Object.freeze({
82987
+ "cli:codex/desktop-shim": Object.freeze({
82851
82988
  module: route5
82852
82989
  }),
82853
- "cli:codex/queue": Object.freeze({
82990
+ "cli:codex/list-threads": Object.freeze({
82854
82991
  module: route6
82855
82992
  }),
82856
- "cli:codex/send": Object.freeze({
82993
+ "cli:codex/queue": Object.freeze({
82857
82994
  module: route7
82858
82995
  }),
82859
- "cli:codex/status": Object.freeze({
82996
+ "cli:codex/send": Object.freeze({
82860
82997
  module: route8
82861
82998
  }),
82862
- "cli:doctor": Object.freeze({
82999
+ "cli:codex/status": Object.freeze({
82863
83000
  module: route9
82864
83001
  }),
82865
- "cli:groups/add": Object.freeze({
83002
+ "cli:doctor": Object.freeze({
82866
83003
  module: route10
82867
83004
  }),
82868
- "cli:groups/create": Object.freeze({
83005
+ "cli:groups/add": Object.freeze({
82869
83006
  module: route11
82870
83007
  }),
82871
- "cli:groups/delete": Object.freeze({
83008
+ "cli:groups/create": Object.freeze({
82872
83009
  module: route12
82873
83010
  }),
82874
- "cli:groups/get": Object.freeze({
83011
+ "cli:groups/delete": Object.freeze({
82875
83012
  module: route13
82876
83013
  }),
82877
- "cli:groups/list": Object.freeze({
83014
+ "cli:groups/get": Object.freeze({
82878
83015
  module: route14
82879
83016
  }),
82880
- "cli:groups/members": Object.freeze({
83017
+ "cli:groups/list": Object.freeze({
82881
83018
  module: route15
82882
83019
  }),
82883
- "cli:groups/remove": Object.freeze({
83020
+ "cli:groups/members": Object.freeze({
82884
83021
  module: route16
82885
83022
  }),
82886
- "cli:groups/set": Object.freeze({
83023
+ "cli:groups/remove": Object.freeze({
82887
83024
  module: route17
82888
83025
  }),
82889
- "cli:groups/update": Object.freeze({
83026
+ "cli:groups/set": Object.freeze({
82890
83027
  module: route18
82891
83028
  }),
82892
- "cli:history": Object.freeze({
83029
+ "cli:groups/update": Object.freeze({
82893
83030
  module: route19
82894
83031
  }),
82895
- "cli:send": Object.freeze({
83032
+ "cli:history": Object.freeze({
82896
83033
  module: route20
82897
83034
  }),
82898
- "cli:thread": Object.freeze({
83035
+ "cli:send": Object.freeze({
82899
83036
  module: route21
83037
+ }),
83038
+ "cli:thread": Object.freeze({
83039
+ module: route22
82900
83040
  })
82901
83041
  });
82902
83042
  const commands = Object.freeze([
@@ -83196,6 +83336,33 @@ const commands = Object.freeze([
83196
83336
  "rendered": true,
83197
83337
  "routeId": "cli:bots/update"
83198
83338
  },
83339
+ {
83340
+ "aliases": [],
83341
+ "description": "Install, remove, or check the ChatGPT Desktop shim: a CODEX_CLI_PATH wrapper that bridges Desktop stdio onto the managed Codex daemon (stock app-server proxy hangs). macOS persists via LaunchAgent; always fails open to real Codex.",
83342
+ "exitCode": "result",
83343
+ "options": [
83344
+ {
83345
+ "choices": [
83346
+ "install",
83347
+ "uninstall",
83348
+ "status"
83349
+ ],
83350
+ "description": "install | uninstall | status",
83351
+ "key": "action",
83352
+ "kind": "enum",
83353
+ "option": "action",
83354
+ "positional": 0,
83355
+ "repeated": false,
83356
+ "required": true
83357
+ }
83358
+ ],
83359
+ "path": [
83360
+ "codex",
83361
+ "desktop-shim"
83362
+ ],
83363
+ "rendered": true,
83364
+ "routeId": "cli:codex/desktop-shim"
83365
+ },
83199
83366
  {
83200
83367
  "aliases": [],
83201
83368
  "description": "List Codex daemon-managed threads.",
@@ -84161,27 +84328,27 @@ const execute = async (command, input, context)=>{
84161
84328
  instanceId: processLifetime.instanceId,
84162
84329
  pid: processLifetime.pid
84163
84330
  };
84164
- const result = await (0,_agent_bundle_runtime__rspack_import_27/* .runAgentRequest */.iC)({
84331
+ const result = await (0,_agent_bundle_runtime__rspack_import_28/* .runAgentRequest */.iC)({
84165
84332
  capabilities: {
84166
- command: (0,_agent_bundle_runtime__rspack_import_27/* .unavailable */.hU)(),
84167
- filesystem: (0,_agent_bundle_runtime__rspack_import_27/* .unavailable */.hU)(),
84168
- network: (0,_agent_bundle_runtime__rspack_import_27/* .unavailable */.hU)(),
84169
- projectRoot: (0,_agent_bundle_runtime__rspack_import_27/* .available */.qC)({
84333
+ command: (0,_agent_bundle_runtime__rspack_import_28/* .unavailable */.hU)(),
84334
+ filesystem: (0,_agent_bundle_runtime__rspack_import_28/* .unavailable */.hU)(),
84335
+ network: (0,_agent_bundle_runtime__rspack_import_28/* .unavailable */.hU)(),
84336
+ projectRoot: (0,_agent_bundle_runtime__rspack_import_28/* .available */.qC)({
84170
84337
  root: cwd
84171
84338
  }, 'derived')
84172
84339
  },
84173
- host: (0,_agent_bundle_runtime__rspack_import_27/* .unavailable */.hU)('unsupported-surface'),
84340
+ host: (0,_agent_bundle_runtime__rspack_import_28/* .unavailable */.hU)('unsupported-surface'),
84174
84341
  invocation: {
84175
84342
  kind: 'cli',
84176
84343
  operationId: command.routeId,
84177
84344
  surface: command.path.join(' ')
84178
84345
  },
84179
- lineage: (0,_agent_bundle_runtime__rspack_import_27/* .unavailable */.hU)('unsupported-surface'),
84346
+ lineage: (0,_agent_bundle_runtime__rspack_import_28/* .unavailable */.hU)('unsupported-surface'),
84180
84347
  plugin: pluginRoot.identity,
84181
84348
  process: processHit,
84182
84349
  signal: context.signal,
84183
- terminal: (0,_agent_bundle_runtime__rspack_import_27/* .available */.qC)(context.terminal, 'native'),
84184
- workspace: (0,_agent_bundle_runtime__rspack_import_27/* .available */.qC)({
84350
+ terminal: (0,_agent_bundle_runtime__rspack_import_28/* .available */.qC)(context.terminal, 'native'),
84351
+ workspace: (0,_agent_bundle_runtime__rspack_import_28/* .available */.qC)({
84185
84352
  root: cwd
84186
84353
  }, 'derived')
84187
84354
  }, async ()=>route.module.default({
@@ -84288,7 +84455,7 @@ const openRenderedSession = ({ invocation, limits, props, request, routeId, sign
84288
84455
  return stream;
84289
84456
  }
84290
84457
  });
84291
- const dispatcher = (0,_agent_bundle_runtime__rspack_import_28/* .createAgentRenderDispatcher */.jK)(host);
84458
+ const dispatcher = (0,_agent_bundle_runtime__rspack_import_29/* .createAgentRenderDispatcher */.jK)(host);
84292
84459
  return Object.freeze({
84293
84460
  close: async ()=>{
84294
84461
  await worker.terminate();
@@ -84336,7 +84503,7 @@ if (import.meta.main) {
84336
84503
  execute,
84337
84504
  name: "gbot",
84338
84505
  render,
84339
- version: "0.4.1"
84506
+ version: "0.4.2"
84340
84507
  });
84341
84508
  }
84342
84509
 
@@ -84601,6 +84768,9 @@ const textDecoder = new TextDecoder("utf-8", {
84601
84768
  });
84602
84769
  const pkg = (0,node_module__rspack_import_6.createRequire)(import.meta.url)("../../package.json");
84603
84770
  function codexSocketPath(env = process.env) {
84771
+ // Explicit socket wins so status/send/queue agree with a shim-installed or
84772
+ // operator-exported CODEX_APP_SERVER_SOCK; otherwise derive from CODEX_HOME.
84773
+ if (env.CODEX_APP_SERVER_SOCK) return env.CODEX_APP_SERVER_SOCK;
84604
84774
  const home = env.CODEX_HOME || (0,node_path__rspack_import_4.join)((0,node_os__rspack_import_3.homedir)(), ".codex");
84605
84775
  return (0,node_path__rspack_import_4.join)(home, "app-server-control", "app-server-control.sock");
84606
84776
  }
@@ -84617,7 +84787,15 @@ function codexSocketPath(env = process.env) {
84617
84787
  /** Single-line fields (ids, names, paths, cursors, header tokens): no line breaks or tabs survive. */ function singleLine(text) {
84618
84788
  return stripTerminalControls(text).replace(/[\t\n\r\u2028\u2029]+/g, " ");
84619
84789
  }
84620
- function unreachableMessage(path) {
84790
+ function unreachableMessage(path, desktopAttached = "unknown") {
84791
+ if (desktopAttached === "private-stdio") {
84792
+ return [
84793
+ "ChatGPT Desktop is running its private stdio app-server, which external clients cannot reach",
84794
+ "(" + UPSTREAM_DESKTOP_ISSUES.join(", ") + ").",
84795
+ "No Codex app-server control socket at " + path + ": start a managed standalone daemon with `codex app-server daemon start`.",
84796
+ "gbot codex targets daemon-managed threads only."
84797
+ ].join("\n");
84798
+ }
84621
84799
  return [
84622
84800
  "No Codex app-server control socket at " + path + ".",
84623
84801
  "Either no daemon is running (start one with `codex app-server daemon start`),",
@@ -84820,6 +84998,12 @@ function isObject(value) {
84820
84998
  const sendJson = (obj)=>write(0x1, Buffer.from(JSON.stringify(obj)));
84821
84999
  const client = {
84822
85000
  refused,
85001
+ // Server-initiated requests are only *answered* once our own turn/start
85002
+ // is in flight: anything earlier belongs to another client's turn
85003
+ // (notably Desktop's) and must never be rejected on their behalf. Early
85004
+ // requests are still recorded; the connection closes right after, so a
85005
+ // pending request simply dies with it instead of denying someone's approval.
85006
+ answerServerRequests: false,
84823
85007
  request (method, params) {
84824
85008
  const id = nextId++;
84825
85009
  return new Promise((res, rej)=>{
@@ -84883,11 +85067,14 @@ function isObject(value) {
84883
85067
  };
84884
85068
  const onMessage = (msg)=>{
84885
85069
  if (msg.id != null && msg.method) {
85070
+ const answered = client.answerServerRequests;
84886
85071
  refused.push({
84887
85072
  id: msg.id,
84888
85073
  method: msg.method,
84889
- params: msg.params
85074
+ params: msg.params,
85075
+ answered
84890
85076
  });
85077
+ if (!answered) return;
84891
85078
  sendJson({
84892
85079
  jsonrpc: "2.0",
84893
85080
  id: msg.id,
@@ -85091,32 +85278,84 @@ const CODEX_VERSION_PROBE_TIMEOUT_MS = 3000;
85091
85278
  probe: "error"
85092
85279
  };
85093
85280
  }
85281
+ /** Bounded `ps` snapshot for Desktop detection: process names only, never pipes or sockets. */ const DESKTOP_PROCESS_LIST_TIMEOUT_MS = 3000;
85282
+ function listDesktopProcesses(timeoutMs = DESKTOP_PROCESS_LIST_TIMEOUT_MS) {
85283
+ if (process.platform === "win32") return "";
85284
+ try {
85285
+ const out = (0,node_child_process__rspack_import_5.spawnSync)("ps", [
85286
+ "-eo",
85287
+ "args"
85288
+ ], {
85289
+ encoding: "utf8",
85290
+ timeout: timeoutMs
85291
+ });
85292
+ if (out.error || out.status !== 0 || typeof out.stdout !== "string") return "";
85293
+ return out.stdout;
85294
+ } catch {
85295
+ return "";
85296
+ }
85297
+ }
85298
+ /**
85299
+ * Pure Desktop private-stdio detector. Returns `"private-stdio"` when the process list
85300
+ * shows Desktop's bundled `.../ChatGPT.app/.../Resources/codex` running `app-server`
85301
+ * (the `codex_app` override corroborates, the Resources path alone suffices); `"unknown"`
85302
+ * otherwise. Never `"detached"`: absence of a match means "not observed", not "not running".
85303
+ * Windows stays `"unknown"` (unsupported route, unchanged).
85304
+ *
85305
+ * @param {{ platform?: string, listProcesses?: string | string[] | null }} [opts]
85306
+ */ function detectDesktopPrivateAppServer({ platform = process.platform, listProcesses = "" } = {}) {
85307
+ if (platform === "win32") return "unknown";
85308
+ const lines = Array.isArray(listProcesses) ? listProcesses : String(listProcesses ?? "").split(/\r?\n/);
85309
+ for (const line of lines){
85310
+ if (!/app-server/.test(line)) continue;
85311
+ // Desktop's bundled binary, Mac or Windows-style separators with optional .exe.
85312
+ if (/ChatGPT\.app[\\/].*Resources[\\/]codex(\.exe)?(["'\s]|$)/.test(line)) return "private-stdio";
85313
+ // Same app-server line owned by ChatGPT.app carrying the app-tools override.
85314
+ if (/ChatGPT\.app/.test(line) && /(codex_app|mcp_servers\.codex_app|codex-app-tools)/.test(line)) return "private-stdio";
85315
+ }
85316
+ return "unknown";
85317
+ }
85094
85318
  /**
85095
85319
  * Status contract: `reachable` is endpoint reachability only. `schema.compatibility` is
85096
85320
  * `exact` when the daemon reports the pinned version, otherwise `unverified` (methods
85097
- * usually survive upgrades) or `unknown`. Whether ChatGPT Desktop owns any thread is not
85098
- * observable from the socket, so `desktopAttached` is always `"unknown"`.
85099
- */ async function codexStatus(env = process.env) {
85321
+ * usually survive upgrades) or `unknown`. `desktopAttached` is `"private-stdio"` when a
85322
+ * Desktop-bundled app-server process is visible (see `detectDesktopPrivateAppServer`),
85323
+ * otherwise `"unknown"` — whether Desktop owns any thread is never observable from the
85324
+ * socket itself, and `"detached"` is never reported.
85325
+ *
85326
+ * @param {NodeJS.ProcessEnv} [env]
85327
+ * @param {{ listProcesses?: string | string[] }} [opts] injected process list for tests;
85328
+ * defaults to a live `ps` snapshot. Never reads pipes or connects to Desktop.
85329
+ */ async function codexStatus(env = process.env, { listProcesses } = {}) {
85100
85330
  const path = codexSocketPath(env);
85101
85331
  const cli = probeLocalCodexVersion();
85332
+ const desktopAttached = detectDesktopPrivateAppServer({
85333
+ platform: process.platform,
85334
+ listProcesses: listProcesses ?? listDesktopProcesses()
85335
+ });
85102
85336
  const base = {
85103
85337
  socketPath: path,
85104
85338
  socketState: socketState(path),
85105
85339
  pinnedVersion: PINNED_CODEX_VERSION,
85106
85340
  cliVersion: cli.version,
85107
85341
  cliVersionProbe: cli.probe,
85108
- desktopAttached: "unknown"
85342
+ desktopAttached
85109
85343
  };
85110
85344
  let session;
85111
85345
  try {
85112
85346
  session = await openSession(env);
85113
85347
  } catch (err) {
85114
- if (err instanceof CodexRouteError) return (0,_codex_contract_js__rspack_import_7/* .withStatusExitCode */.AQ)({
85115
- ...base,
85116
- reachable: false,
85117
- mode: err.mode,
85118
- message: err.message
85119
- });
85348
+ if (err instanceof CodexRouteError) {
85349
+ // Name the private-stdio case explicitly: Desktop is up but unreachable, so the
85350
+ // operator needs a managed standalone daemon, not a Desktop reconnect.
85351
+ const message = err.mode === "socket-absent" ? unreachableMessage(path, desktopAttached) : err.message;
85352
+ return (0,_codex_contract_js__rspack_import_7/* .withStatusExitCode */.AQ)({
85353
+ ...base,
85354
+ reachable: false,
85355
+ mode: err.mode,
85356
+ message
85357
+ });
85358
+ }
85120
85359
  // The endpoint answered; what it said does not match the pinned schema.
85121
85360
  if (err instanceof CodexProtocolError) return (0,_codex_contract_js__rspack_import_7/* .withStatusExitCode */.AQ)({
85122
85361
  ...base,
@@ -85502,6 +85741,12 @@ async function sendToCodexThreadInner(threadId, text, { env, envelope, whenBusy
85502
85741
  // the daemon exposes no compare-and-start request. Upgrade path: thread/queue/add + thread/queue/start once stable.
85503
85742
  // Scope refusals to this turn: server requests from earlier calls belong to another context.
85504
85743
  const seenRefused = client.refused.length;
85744
+ // Arm refusal replies only now that our own turn/start is in flight: an
85745
+ // approval arriving in this window plausibly belongs to our turn. Anything
85746
+ // recorded earlier (resume, busy reject, queue) stays unanswered so gbot
85747
+ // never rejects another client's approval. Residual race: a concurrent
85748
+ // foreign approval inside this window is indistinguishable from ours.
85749
+ client.answerServerRequests = true;
85505
85750
  let turn;
85506
85751
  try {
85507
85752
  turn = await client.request("turn/start", {
@@ -85536,7 +85781,7 @@ async function sendToCodexThreadInner(threadId, text, { env, envelope, whenBusy
85536
85781
  envelope
85537
85782
  });
85538
85783
  }
85539
- const freshRefused = client.refused.slice(seenRefused).filter((r)=>!r.params || r.params.threadId == null || r.params.threadId === threadId);
85784
+ const freshRefused = client.refused.slice(seenRefused).filter((r)=>r.answered && (!r.params || r.params.threadId == null || r.params.threadId === threadId));
85540
85785
  if (freshRefused.length) {
85541
85786
  const methods = freshRefused.map((r)=>r.method).join(", ");
85542
85787
  throw new CodexSendError("Turn " + turnId + " started on thread " + threadId + " but Codex asked for " + methods + ", which gbot refused. " + "Answer it in a Codex client, or set `approval_policy = \"never\"` in the daemon's config.toml for unattended sends.", {
@@ -85566,7 +85811,8 @@ __webpack_require__.d(__webpack_exports__, {
85566
85811
  X$: () => (listCodexThreads),
85567
85812
  ZS: () => (sendToCodexThread),
85568
85813
  nq: () => (buildEnvelope),
85569
- pF: () => (singleLine)
85814
+ pF: () => (singleLine),
85815
+ ql: () => (codexSocketPath)
85570
85816
  });
85571
85817
 
85572
85818
 
@@ -85772,6 +86018,534 @@ __webpack_require__.d(__webpack_exports__, {
85772
86018
  });
85773
86019
 
85774
86020
 
86021
+ },
86022
+ "./src/core/desktop-shim-bridge.js"(__unused_rspack___webpack_module__, __webpack_exports__, __webpack_require__) {
86023
+ // Stdio JSONL (Desktop) <-> WebSocket-over-unix bridge onto the managed
86024
+ // Codex app-server control socket. Vendored from uploads/codex-stdio-to-daemon-ws.py
86025
+ // (ChatGPT Desktop -> managed daemon shim) with fail-open deltas, marked below:
86026
+ // (1) ws_connect enforces one absolute monotonic deadline for connect + HTTP
86027
+ // upgrade (CODEX_BRIDGE_CONNECT_TIMEOUT, default 10s), validates the 101 status
86028
+ // and Sec-WebSocket-Accept, and retains bytes coalesced after the upgrade
86029
+ // headers instead of discarding the first data frame.
86030
+ // (2) read_message assembles continuation frames; control frames answer inline;
86031
+ // socket writes are serialized with a lock shared by both threads.
86032
+ // (3) A first-message deadline (CODEX_BRIDGE_FIRST_MESSAGE_TIMEOUT, default
86033
+ // 30s) bounds connect-to-first-daemon-message covering the first RPC; the
86034
+ // preflight (3s) + upgrade (10s) + first RPC (30s) budget stays far below a
86035
+ // daemon-lock hang. Exits are 0 served, 1 pre-stdio (wrapper falls back to
86036
+ // real Codex), 2 mid-session (wrapper exits so Desktop reconnects).
86037
+ // (4) Byte-precise commit: os.read into a userspace line buffer counts every
86038
+ // stdin byte (buffered readline could readahead past the commit point), so the
86039
+ // fallback only ever runs on a truly pristine stdio. The reader signals a done
86040
+ // event so WS close wakes the select loop; no path leaves a thread hung.
86041
+ // Desktop stdio hangs with stock `codex app-server proxy`, so this custom
86042
+ // bridge is required. Install writes it to the CODEX_HOME bin dir. Never reads
86043
+ // Desktop private pipes (CODEX_APP_TOOLS_PIPE_PATH, /tmp/codex-browser-use/).
86044
+ const BRIDGE_SOURCE = "#!/usr/bin/env python3\n\"\"\"Stdio JSONL (Desktop) <-> WebSocket-over-unix (managed app-server daemon).\nReversible: remove CODEX_CLI_PATH wrapper. Does not read Desktop private pipes.\n\"\"\"\nfrom __future__ import annotations\nimport base64, hashlib, json, os, select, socket, struct, sys, threading, time\n\nSOCK = os.environ.get(\n \"CODEX_APP_SERVER_SOCK\",\n os.path.expanduser(\"~/.codex/app-server-control/app-server-control.sock\"),\n)\nLOG = os.environ.get(\"CODEX_STDIO_BRIDGE_LOG\", os.path.expanduser(\"~/.codex/bin/codex-stdio-to-daemon-ws.log\"))\nWS_GUID = \"258EAFA5-E914-47DA-95CA-C5AB0DC85B11\"\n\n# Wrapper contract: 0 served the session, 1 failed before any stdin was\n# consumed (wrapper falls back to real Codex on pristine stdio), 2 failed\n# mid-session (wrapper exits promptly so Desktop reconnects; the fallback\n# must never run on half-consumed stdin).\nEXIT_SERVED = 0\nEXIT_PRE_STDIO = 1\nEXIT_MID_SESSION = 2\n\nCONNECT_TIMEOUT_S = float(os.environ.get(\"CODEX_BRIDGE_CONNECT_TIMEOUT\", \"10\"))\n# Bound from connect to the first daemon message: a daemon that completes the\n# upgrade but never answers the first RPC must not hold Desktop past this.\nFIRST_MESSAGE_TIMEOUT_S = float(os.environ.get(\"CODEX_BRIDGE_FIRST_MESSAGE_TIMEOUT\", \"30\"))\n\ndef log(msg: str) -> None:\n try:\n with open(LOG, \"a\") as f:\n f.write(time.strftime(\"%Y-%m-%dT%H:%M:%SZ\", time.gmtime()) + \" \" + msg + \"\\n\")\n except OSError:\n pass\n\ndef ws_connect(path: str, timeout: float = CONNECT_TIMEOUT_S):\n \"\"\"Connect + HTTP upgrade under one absolute monotonic deadline.\n\n Returns (socket, trailing) where trailing holds bytes coalesced after the\n upgrade headers (TCP may deliver the 101 and the first WS frame together;\n discarding them would lose the first message). Validates the 101 status\n and Sec-WebSocket-Accept so a non-WebSocket listener fails fast.\n \"\"\"\n deadline = time.monotonic() + timeout\n s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)\n s.settimeout(timeout)\n try:\n s.connect(path)\n key = base64.b64encode(os.urandom(16)).decode()\n expected = base64.b64encode(hashlib.sha1((key + WS_GUID).encode()).digest()).decode()\n req = (\n f\"GET /rpc HTTP/1.1\\r\\nHost: localhost\\r\\nUpgrade: websocket\\r\\n\"\n f\"Connection: Upgrade\\r\\nSec-WebSocket-Key: {key}\\r\\nSec-WebSocket-Version: 13\\r\\n\\r\\n\"\n ).encode()\n s.sendall(req)\n buf = b\"\"\n while True:\n if b\"\\r\\n\\r\\n\" in buf:\n break\n remaining = deadline - time.monotonic()\n if remaining <= 0:\n raise TimeoutError(\"WebSocket upgrade timed out\")\n if len(buf) > 65536:\n raise ConnectionError(\"WS upgrade headers too large\")\n s.settimeout(remaining)\n chunk = s.recv(4096)\n if not chunk:\n raise ConnectionError(\"daemon closed during WS upgrade\")\n buf += chunk\n head, _, trailing = buf.partition(b\"\\r\\n\\r\\n\")\n lines = head.split(b\"\\r\\n\")\n if b\"101\" not in lines[0]:\n raise ConnectionError(f\"WS upgrade failed: {head[:200]!r}\")\n accept = None\n for line in lines[1:]:\n name, sep, value = line.partition(b\":\")\n if sep and name.strip().lower() == b\"sec-websocket-accept\":\n accept = value.strip().decode(\"latin-1\")\n if accept != expected:\n raise ConnectionError(\"WS upgrade accept mismatch\")\n except Exception:\n try:\n s.close()\n except OSError:\n pass\n raise\n s.settimeout(None)\n return s, trailing\n\ndef mask_send(sock: socket.socket, payload: bytes, opcode: int = 1) -> None:\n mask = os.urandom(4)\n ln = len(payload)\n if ln < 126:\n hdr = bytes([0x80 | opcode, 0x80 | ln])\n elif ln < 65536:\n hdr = bytes([0x80 | opcode, 0x80 | 126]) + struct.pack(\"!H\", ln)\n else:\n hdr = bytes([0x80 | opcode, 0x80 | 127]) + struct.pack(\"!Q\", ln)\n sock.sendall(hdr + mask + bytes(b ^ mask[i % 4] for i, b in enumerate(payload)))\n\ndef locked_send(sock: socket.socket, lock: threading.Lock, payload: bytes, opcode: int = 1) -> None:\n with lock:\n mask_send(sock, payload, opcode=opcode)\n\ndef _buffered_reader(sock: socket.socket, initial: bytes = b\"\"):\n buf = bytearray(initial)\n def recv(n):\n while len(buf) < n:\n chunk = sock.recv(n - len(buf))\n if not chunk:\n raise ConnectionError(\"eof\")\n buf.extend(chunk)\n out = bytes(buf[:n])\n del buf[:n]\n return out\n return recv\n\ndef read_frame(recv):\n hdr = recv(2)\n fin = bool(hdr[0] & 0x80)\n opcode = hdr[0] & 0x0F\n masked = bool(hdr[1] & 0x80)\n ln = hdr[1] & 0x7F\n if ln == 126:\n ln = struct.unpack(\"!H\", recv(2))[0]\n elif ln == 127:\n ln = struct.unpack(\"!Q\", recv(8))[0]\n mask = recv(4) if masked else b\"\"\n payload = recv(ln)\n if masked:\n payload = bytes(b ^ mask[i % 4] for i, b in enumerate(payload))\n return fin, opcode, payload\n\ndef read_message(recv, send_pong):\n \"\"\"Next complete data message, assembling continuation frames.\n\n Control frames are handled inline (pong answered, close reported) so a\n fragmented message split around a ping still reassembles.\n \"\"\"\n opcode = None\n parts = []\n while True:\n fin, op, payload = read_frame(recv)\n if op == 0x8:\n return (\"close\", None, b\"\")\n if op == 0x9:\n send_pong(payload)\n continue\n if op == 0xA:\n continue\n if op in (0x1, 0x2):\n if opcode is not None:\n raise ConnectionError(\"data frame inside fragmented message\")\n if fin:\n return (\"data\", op, payload)\n opcode = op\n parts.append(payload)\n continue\n if op == 0x0:\n if opcode is None:\n raise ConnectionError(\"stray continuation frame\")\n parts.append(payload)\n if fin:\n return (\"data\", opcode, b\"\".join(parts))\n continue\n raise ConnectionError(f\"unsupported opcode {op}\")\n\ndef stdout_writer(sock: socket.socket, recv, send_pong, done: threading.Event, first_msg: threading.Event) -> None:\n out = sys.stdout.buffer\n try:\n while True:\n kind, opcode, payload = read_message(recv, send_pong)\n if kind == \"close\":\n log(\"daemon WS close\")\n return\n if opcode == 0x1:\n # Desktop StdioConnection expects newline-delimited JSON text\n if not payload.endswith(b\"\\n\"):\n payload += b\"\\n\"\n out.write(payload)\n out.flush()\n else:\n out.write(payload)\n out.flush()\n first_msg.set()\n except Exception as e:\n log(f\"stdout_writer exit: {e}\")\n finally:\n done.set()\n\ndef main() -> int:\n log(f\"start sock={SOCK}\")\n try:\n sock, pending = ws_connect(SOCK)\n except Exception as e:\n log(f\"connect failed: {e}\")\n sys.stderr.write(f\"codex-stdio-to-daemon-ws: {e}\\n\")\n return EXIT_PRE_STDIO\n log(\"connected\")\n connected_at = time.monotonic()\n send_lock = threading.Lock()\n def send_pong(payload: bytes) -> None:\n locked_send(sock, send_lock, payload, opcode=0xA)\n recv = _buffered_reader(sock, pending)\n done = threading.Event()\n first_msg = threading.Event()\n t = threading.Thread(target=stdout_writer, args=(sock, recv, send_pong, done, first_msg), daemon=True)\n t.start()\n # Byte-precise commit point: the fallback may run only while zero stdin\n # bytes have left the pipe. Reads use os.read into a userspace line buffer\n # (buffered readline could readahead past the commit point), and every\n # byte read counts — even a blank line. first_msg bounds the first RPC.\n stdin_bytes = 0\n pending_in = b\"\"\n clean_eof = False\n try:\n fd = sys.stdin.fileno()\n while not done.is_set():\n if not first_msg.is_set() and time.monotonic() - connected_at > FIRST_MESSAGE_TIMEOUT_S:\n log(\"first daemon message timed out\")\n break\n ready, _, _ = select.select([fd], [], [], 0.5)\n if not ready:\n continue\n chunk = os.read(fd, 65536)\n if not chunk:\n clean_eof = True\n break\n stdin_bytes += len(chunk)\n pending_in += chunk\n while b\"\\n\" in pending_in:\n line, _, pending_in = pending_in.partition(b\"\\n\")\n line = line.strip()\n if not line:\n continue\n locked_send(sock, send_lock, line)\n except Exception as e:\n log(f\"stdin loop exit: {e}\")\n try:\n locked_send(sock, send_lock, b\"\", opcode=0x8)\n except Exception:\n pass\n if clean_eof:\n tail = pending_in.strip()\n if tail and not done.is_set():\n try:\n locked_send(sock, send_lock, tail)\n except Exception as e:\n log(f\"eof flush failed: {e}\")\n log(\"exit\")\n return EXIT_SERVED\n # Reader died, first RPC timed out, or stdin broke: fail open only if no\n # stdin byte was ever consumed.\n rc = EXIT_MID_SESSION if stdin_bytes else EXIT_PRE_STDIO\n log(f\"exit rc={rc}\")\n return rc\n\nif __name__ == \"__main__\":\n raise SystemExit(main())\n";
86045
+
86046
+ __webpack_require__.d(__webpack_exports__, {
86047
+ }, {
86048
+ w: BRIDGE_SOURCE
86049
+ });
86050
+
86051
+
86052
+ },
86053
+ "./src/core/desktop-shim.js"(__unused_rspack___webpack_module__, __webpack_exports__, __webpack_require__) {
86054
+ /* import */ var node_child_process__rspack_import_0 = __webpack_require__("node:child_process");
86055
+ /* import */ var node_fs__rspack_import_1 = __webpack_require__("node:fs");
86056
+ /* import */ var node_os__rspack_import_2 = __webpack_require__("node:os");
86057
+ /* import */ var node_path__rspack_import_3 = __webpack_require__("node:path");
86058
+ /* import */ var _desktop_shim_bridge_js__rspack_import_5 = __webpack_require__("./src/core/desktop-shim-bridge.js");
86059
+ /* import */ var _codex_bridge_js__rspack_import_4 = __webpack_require__("./src/core/codex-bridge.js");
86060
+
86061
+
86062
+
86063
+
86064
+
86065
+
86066
+ /**
86067
+ * ChatGPT Desktop -> managed Codex daemon shim (CODEX_CLI_PATH bridge).
86068
+ *
86069
+ * Desktop injects `codex_app` overrides so CODEX_APP_SERVER_USE_LOCAL_DAEMON=1
86070
+ * alone cannot select the managed daemon, and stock `codex app-server proxy`
86071
+ * hangs for Desktop stdio. The winning path is a wrapper on CODEX_CLI_PATH
86072
+ * that rewrites Desktop's `codex ... app-server` spawn into the stdio<->WS
86073
+ * bridge (desktop-shim-bridge.js) onto the managed control socket.
86074
+ * Provenance: uploads/codex-desktop-to-daemon + codex-desktop-shared-daemon-env.sh.
86075
+ *
86076
+ * Fail-open is the hard rule: the wrapper execs the real standalone `codex`
86077
+ * for non-app-server spawns and whenever the bridge/python/socket side is
86078
+ * missing or broken. Never touches Desktop binaries, /tmp/codex-browser-use/,
86079
+ * or CODEX_APP_TOOLS_PIPE_PATH. No protocol change: gbot already speaks the
86080
+ * managed control socket.
86081
+ */ const SHIM_LABEL = "com.zackjackson.codex-desktop-shared-daemon";
86082
+ const WRAPPER_FILENAME = "codex-desktop-to-daemon";
86083
+ const BRIDGE_FILENAME = "codex-stdio-to-daemon-ws.py";
86084
+ const ENV_SCRIPT_FILENAME = "codex-desktop-shared-daemon-env.sh";
86085
+ const BRIDGE_LOG_FILENAME = "codex-stdio-to-daemon-ws.log";
86086
+ const WRAPPER_LOG_FILENAME = "codex-desktop-to-daemon.log";
86087
+ const ENV_LOG_FILENAME = "codex-desktop-shared-daemon-env.log";
86088
+ const STANDALONE_REAL_SUFFIX = (0,node_path__rspack_import_3.join)("packages", "standalone", "current", "bin", "codex");
86089
+ function codexHomeDir(env = process.env) {
86090
+ return env.CODEX_HOME || join(env.HOME || homedir(), ".codex");
86091
+ }
86092
+ function userHomeDir(env = process.env) {
86093
+ return env.HOME || (0,node_os__rspack_import_2.homedir)();
86094
+ }
86095
+ function defaultPaths({ env = process.env, home = userHomeDir(env) } = {}) {
86096
+ const codexHome = env.CODEX_HOME || (0,node_path__rspack_import_3.join)(home, ".codex");
86097
+ const binDir = (0,node_path__rspack_import_3.join)(codexHome, "bin");
86098
+ return {
86099
+ binDir,
86100
+ bridgeLogPath: (0,node_path__rspack_import_3.join)(binDir, BRIDGE_LOG_FILENAME),
86101
+ bridgePath: (0,node_path__rspack_import_3.join)(binDir, BRIDGE_FILENAME),
86102
+ codexHome,
86103
+ envLogPath: (0,node_path__rspack_import_3.join)(binDir, ENV_LOG_FILENAME),
86104
+ envScriptPath: (0,node_path__rspack_import_3.join)(binDir, ENV_SCRIPT_FILENAME),
86105
+ label: SHIM_LABEL,
86106
+ launchAgentsDir: (0,node_path__rspack_import_3.join)(home, "Library", "LaunchAgents"),
86107
+ plistPath: (0,node_path__rspack_import_3.join)(home, "Library", "LaunchAgents", `${SHIM_LABEL}.plist`),
86108
+ realPath: (0,node_path__rspack_import_3.join)(codexHome, STANDALONE_REAL_SUFFIX),
86109
+ socketPath: (0,node_path__rspack_import_3.join)(codexHome, "app-server-control", "app-server-control.sock"),
86110
+ wrapperLogPath: (0,node_path__rspack_import_3.join)(binDir, WRAPPER_LOG_FILENAME),
86111
+ wrapperPath: (0,node_path__rspack_import_3.join)(binDir, WRAPPER_FILENAME)
86112
+ };
86113
+ }
86114
+ /**
86115
+ * Pure passthrough decision, mirroring the wrapper's argv scan. True only for
86116
+ * a bare `app-server` spawn: Desktop's private-stdio case. `daemon`, `proxy`,
86117
+ * and schema generations always exec the real Codex.
86118
+ */ function shouldBridge(argv) {
86119
+ let appServer = false;
86120
+ let daemon = false;
86121
+ let proxy = false;
86122
+ let generate = false;
86123
+ for (const arg of argv ?? []){
86124
+ if (arg === "app-server") appServer = true;
86125
+ else if (arg === "daemon") daemon = true;
86126
+ else if (arg === "proxy") proxy = true;
86127
+ else if (arg === "generate-ts" || arg === "generate-json-schema") generate = true;
86128
+ }
86129
+ return appServer && !daemon && !proxy && !generate;
86130
+ }
86131
+ function renderWrapperScript({ realPath, bridgePath, wrapperLogPath, codexHome, bridgeLogPath }) {
86132
+ return `#!/bin/bash
86133
+ # Installed by \`gbot codex desktop-shim install\`. Rewrites ChatGPT Desktop's
86134
+ # \`codex ... app-server\` spawn into a stdio<->WebSocket bridge onto the managed
86135
+ # daemon's control socket. Reversible: \`gbot codex desktop-shim uninstall\`.
86136
+ # The daemon is kept up by the LaunchAgent login script, not here: this hot path
86137
+ # never starts the daemon itself, so a wedged daemon lock cannot hang
86138
+ # Desktop. Fail-open runs ONLY before any stdin is consumed: an absent socket
86139
+ # fails the preflight and a pre-session bridge failure (exit 1) falls through
86140
+ # to the real standalone codex on pristine stdio. A mid-session bridge failure
86141
+ # (exit 2+) exits promptly so Desktop reconnects; the fallback never runs on
86142
+ # half-consumed stdin. Bridge exit 0 means it served the session. Never touches
86143
+ # Desktop binaries or its private tool pipe.
86144
+ set -u
86145
+ REAL="\${CODEX_DESKTOP_WRAPPER_REAL:-${realPath}}"
86146
+ BRIDGE="\${CODEX_DESKTOP_BRIDGE:-${bridgePath}}"
86147
+ export CODEX_HOME="\${CODEX_HOME:-${codexHome}}"
86148
+ SOCK="\${CODEX_APP_SERVER_SOCK:-$CODEX_HOME/app-server-control/app-server-control.sock}"
86149
+ BRIDGE_LOG="\${CODEX_STDIO_BRIDGE_LOG:-${bridgeLogPath}}"
86150
+ LOG="\${CODEX_DESKTOP_WRAPPER_LOG:-${wrapperLogPath}}"
86151
+ export CODEX_APP_SERVER_SOCK="$SOCK"
86152
+ export CODEX_STDIO_BRIDGE_LOG="$BRIDGE_LOG"
86153
+ ts() { date -u +%Y-%m-%dT%H:%M:%SZ; }
86154
+ echo "$(ts) argv: $*" >>"$LOG" 2>/dev/null || true
86155
+
86156
+ if [[ ! -x "$REAL" ]]; then
86157
+ FALLBACK="$(command -v codex 2>/dev/null || true)"
86158
+ if [[ -n "$FALLBACK" && -x "$FALLBACK" ]]; then
86159
+ REAL="$FALLBACK"
86160
+ fi
86161
+ fi
86162
+
86163
+ has_app_server=0; has_daemon=0; has_proxy=0; has_generate=0
86164
+ for a in "$@"; do
86165
+ case "$a" in
86166
+ app-server) has_app_server=1 ;;
86167
+ daemon) has_daemon=1 ;;
86168
+ proxy) has_proxy=1 ;;
86169
+ generate-ts|generate-json-schema) has_generate=1 ;;
86170
+ esac
86171
+ done
86172
+
86173
+ # Preflight the daemon socket with a short deadline: a refused/absent socket
86174
+ # means starting the bridge could never succeed, so skip straight to real codex.
86175
+ preflight() {
86176
+ python3 -c 'import os,socket,sys; s=socket.socket(socket.AF_UNIX,socket.SOCK_STREAM); s.settimeout(float(os.environ.get("CODEX_DESKTOP_PREFLIGHT_TIMEOUT","3"))); s.connect(sys.argv[1]); s.close()' "$SOCK" 2>/dev/null
86177
+ }
86178
+
86179
+ if [[ "$has_app_server" -eq 1 && "$has_daemon" -eq 0 && "$has_proxy" -eq 0 && "$has_generate" -eq 0 ]]; then
86180
+ if [[ -x "$REAL" && -f "$BRIDGE" ]] && command -v python3 >/dev/null 2>&1; then
86181
+ if preflight; then
86182
+ echo "$(ts) rewrite -> stdio-ws bridge" >>"$LOG" 2>/dev/null || true
86183
+ python3 "$BRIDGE"
86184
+ rc=$?
86185
+ case "$rc" in
86186
+ 0)
86187
+ echo "$(ts) bridge served session" >>"$LOG" 2>/dev/null || true
86188
+ exit 0
86189
+ ;;
86190
+ 1)
86191
+ echo "$(ts) bridge failed before session start, falling through to real codex" >>"$LOG" 2>/dev/null || true
86192
+ ;;
86193
+ *)
86194
+ echo "$(ts) bridge failed mid-session (rc=$rc); exiting so Desktop reconnects" >>"$LOG" 2>/dev/null || true
86195
+ exit "$rc"
86196
+ ;;
86197
+ esac
86198
+ else
86199
+ echo "$(ts) daemon socket unreachable, passthrough to real codex" >>"$LOG" 2>/dev/null || true
86200
+ fi
86201
+ else
86202
+ echo "$(ts) bridge unavailable, passthrough to real codex" >>"$LOG" 2>/dev/null || true
86203
+ fi
86204
+ fi
86205
+ if [[ -x "$REAL" ]]; then
86206
+ exec "$REAL" "$@"
86207
+ fi
86208
+ echo "codex-desktop-to-daemon: no runnable codex found" >&2
86209
+ exit 1
86210
+ `;
86211
+ }
86212
+ function renderEnvScript({ wrapperPath, realPath, envLogPath, codexHome }) {
86213
+ return `#!/bin/bash
86214
+ # Installed by \`gbot codex desktop-shim install\`. Re-applies the GUI-domain env
86215
+ # so ChatGPT.app inherits CODEX_CLI_PATH after login, then best-effort starts the
86216
+ # managed daemon (this login script — never Desktop's spawn hot path — owns
86217
+ # daemon upkeep). No -e: every step is best-effort so login never breaks.
86218
+ # Revert: \`gbot codex desktop-shim uninstall\`.
86219
+ set -u
86220
+ WRAPPER="${wrapperPath}"
86221
+ REAL="${realPath}"
86222
+ LOG="${envLogPath}"
86223
+ CODEX_HOME_DIR="${codexHome}"
86224
+ # One CODEX_HOME for the GUI domain and this script's own daemon start, so the
86225
+ # daemon that is kept up is the one the wrapper bridges to.
86226
+ export CODEX_HOME="$CODEX_HOME_DIR"
86227
+ ts() { date -u +%Y-%m-%dT%H:%M:%SZ; }
86228
+ {
86229
+ echo "$(ts) start"
86230
+ if [[ ! -x "$WRAPPER" ]]; then
86231
+ echo "$(ts) missing wrapper: $WRAPPER"
86232
+ exit 0
86233
+ fi
86234
+ # GUI domain setenv so ChatGPT.app inherits CODEX_CLI_PATH after login
86235
+ launchctl setenv CODEX_CLI_PATH "$WRAPPER"
86236
+ launchctl setenv CODEX_HOME "$CODEX_HOME_DIR"
86237
+ launchctl setenv CODEX_APP_SERVER_USE_LOCAL_DAEMON 1
86238
+ launchctl unsetenv CODEX_APP_SERVER_WS_URL 2>/dev/null || true
86239
+ echo "$(ts) CODEX_CLI_PATH=$(launchctl getenv CODEX_CLI_PATH)"
86240
+ if [[ -x "$REAL" ]]; then
86241
+ "$REAL" app-server daemon start >/dev/null 2>&1 || true
86242
+ echo "$(ts) daemon start attempted"
86243
+ fi
86244
+ echo "$(ts) done"
86245
+ } >>"$LOG" 2>&1
86246
+ `;
86247
+ }
86248
+ function renderPlist({ envScriptPath, label = SHIM_LABEL }) {
86249
+ return `<?xml version="1.0" encoding="UTF-8"?>
86250
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
86251
+ <plist version="1.0">
86252
+ <dict>
86253
+ \t<key>Label</key>
86254
+ \t<string>${label}</string>
86255
+ \t<key>ProgramArguments</key>
86256
+ \t<array>
86257
+ \t\t<string>/bin/bash</string>
86258
+ \t\t<string>${envScriptPath}</string>
86259
+ \t</array>
86260
+ \t<key>RunAtLoad</key>
86261
+ \t<true/>
86262
+ \t<key>LimitLoadToSessionType</key>
86263
+ \t<string>Aqua</string>
86264
+ </dict>
86265
+ </plist>
86266
+ `;
86267
+ }
86268
+ const defaultRunner = (file, args)=>{
86269
+ try {
86270
+ return (0,node_child_process__rspack_import_0.spawnSync)(file, args, {
86271
+ encoding: "utf8",
86272
+ timeout: 15000
86273
+ });
86274
+ } catch (error) {
86275
+ return {
86276
+ error,
86277
+ status: null
86278
+ };
86279
+ }
86280
+ };
86281
+ function runBestEffort(runner, warnings, what, file, args) {
86282
+ const out = runner(file, args);
86283
+ if (out && (out.error || typeof out.status === "number" && out.status !== 0)) {
86284
+ const detail = out.error && out.error.message || out.stderr && String(out.stderr).trim() || `exit ${out.status}`;
86285
+ warnings.push(`${what} failed (${detail}); continuing`);
86286
+ }
86287
+ return out;
86288
+ }
86289
+ function writeExecutable(path, content) {
86290
+ (0,node_fs__rspack_import_1.writeFileSync)(path, content, {
86291
+ mode: 493
86292
+ });
86293
+ (0,node_fs__rspack_import_1.chmodSync)(path, 493);
86294
+ }
86295
+ function isExecutable(path) {
86296
+ try {
86297
+ (0,node_fs__rspack_import_1.statSync)(path);
86298
+ } catch {
86299
+ return false;
86300
+ }
86301
+ try {
86302
+ // X_OK without throwing: accessSync is clearer; stat mode bit check is sync-safe.
86303
+ return ((0,node_fs__rspack_import_1.statSync)(path).mode & 73) !== 0;
86304
+ } catch {
86305
+ return false;
86306
+ }
86307
+ }
86308
+ function fileExists(path) {
86309
+ try {
86310
+ (0,node_fs__rspack_import_1.statSync)(path);
86311
+ return true;
86312
+ } catch {
86313
+ return false;
86314
+ }
86315
+ }
86316
+ /**
86317
+ * Copy the wrapper + bridge + login env script out of the package into durable
86318
+ * ~/.codex paths (never a git checkout), then persist CODEX_CLI_PATH for the
86319
+ * macOS Aqua session via LaunchAgent. Idempotent.
86320
+ */ function installDesktopShim({ env = process.env, home = userHomeDir(env), platform = process.platform, runner = defaultRunner } = {}) {
86321
+ const paths = defaultPaths({
86322
+ env,
86323
+ home
86324
+ });
86325
+ const warnings = [];
86326
+ (0,node_fs__rspack_import_1.mkdirSync)(paths.binDir, {
86327
+ recursive: true
86328
+ });
86329
+ writeExecutable(paths.wrapperPath, renderWrapperScript(paths));
86330
+ (0,node_fs__rspack_import_1.writeFileSync)(paths.bridgePath, _desktop_shim_bridge_js__rspack_import_5/* .BRIDGE_SOURCE.endsWith */.w.endsWith("\n") ? _desktop_shim_bridge_js__rspack_import_5/* .BRIDGE_SOURCE */.w : `${_desktop_shim_bridge_js__rspack_import_5/* .BRIDGE_SOURCE */.w}\n`, {
86331
+ mode: 420
86332
+ });
86333
+ writeExecutable(paths.envScriptPath, renderEnvScript(paths));
86334
+ let persisted = false;
86335
+ if (platform === "darwin") {
86336
+ (0,node_fs__rspack_import_1.mkdirSync)(paths.launchAgentsDir, {
86337
+ recursive: true
86338
+ });
86339
+ (0,node_fs__rspack_import_1.writeFileSync)(paths.plistPath, renderPlist({
86340
+ envScriptPath: paths.envScriptPath
86341
+ }), {
86342
+ mode: 420
86343
+ });
86344
+ const uid = typeof process.getuid === "function" ? process.getuid() : null;
86345
+ if (uid === null || uid === undefined) {
86346
+ warnings.push("could not determine uid; LaunchAgent file written but not bootstrapped — log out/in or bootstrap it manually");
86347
+ } else {
86348
+ const target = `gui/${uid}/${paths.label}`;
86349
+ runBestEffort(runner, warnings, "launchctl bootout (previous agent)", "launchctl", [
86350
+ "bootout",
86351
+ target
86352
+ ]);
86353
+ runBestEffort(runner, warnings, "launchctl bootstrap", "launchctl", [
86354
+ "bootstrap",
86355
+ `gui/${uid}`,
86356
+ paths.plistPath
86357
+ ]);
86358
+ }
86359
+ runBestEffort(runner, warnings, "launchctl setenv CODEX_CLI_PATH", "launchctl", [
86360
+ "setenv",
86361
+ "CODEX_CLI_PATH",
86362
+ paths.wrapperPath
86363
+ ]);
86364
+ runBestEffort(runner, warnings, "launchctl setenv CODEX_APP_SERVER_USE_LOCAL_DAEMON", "launchctl", [
86365
+ "setenv",
86366
+ "CODEX_APP_SERVER_USE_LOCAL_DAEMON",
86367
+ "1"
86368
+ ]);
86369
+ runBestEffort(runner, warnings, "launchctl unsetenv CODEX_APP_SERVER_WS_URL", "launchctl", [
86370
+ "unsetenv",
86371
+ "CODEX_APP_SERVER_WS_URL"
86372
+ ]);
86373
+ persisted = true;
86374
+ } else {
86375
+ warnings.push("LaunchAgent persistence is macOS-only; wrapper and bridge installed — export CODEX_CLI_PATH manually");
86376
+ }
86377
+ if (isExecutable(paths.realPath)) {
86378
+ runBestEffort(runner, warnings, "codex app-server daemon start", paths.realPath, [
86379
+ "app-server",
86380
+ "daemon",
86381
+ "start"
86382
+ ]);
86383
+ } else {
86384
+ warnings.push(`managed daemon not started: no executable at ${paths.realPath}`);
86385
+ }
86386
+ return {
86387
+ action: "install",
86388
+ bridgePath: paths.bridgePath,
86389
+ envScriptPath: paths.envScriptPath,
86390
+ exitCode: 0,
86391
+ persisted,
86392
+ plistPath: platform === "darwin" ? paths.plistPath : null,
86393
+ realPath: paths.realPath,
86394
+ warnings,
86395
+ wrapperPath: paths.wrapperPath
86396
+ };
86397
+ }
86398
+ /** Remove what install wrote and unset the GUI env; Desktop/Codex fall back to stock. */ function uninstallDesktopShim({ env = process.env, home = userHomeDir(env), platform = process.platform, runner = defaultRunner } = {}) {
86399
+ const paths = defaultPaths({
86400
+ env,
86401
+ home
86402
+ });
86403
+ const warnings = [];
86404
+ const removed = [];
86405
+ for (const path of [
86406
+ paths.wrapperPath,
86407
+ paths.bridgePath,
86408
+ paths.envScriptPath
86409
+ ]){
86410
+ try {
86411
+ if ((0,node_fs__rspack_import_1.rmSync)(path, {
86412
+ force: true
86413
+ }) === undefined && fileExists(path)) warnings.push(`could not remove ${path}`);
86414
+ else if (!fileExists(path)) removed.push(path);
86415
+ } catch (error) {
86416
+ warnings.push(`could not remove ${path} (${error instanceof Error ? error.message : String(error)})`);
86417
+ }
86418
+ }
86419
+ let plistRemoved = false;
86420
+ if (platform === "darwin") {
86421
+ const uid = typeof process.getuid === "function" ? process.getuid() : null;
86422
+ if (uid !== null && uid !== undefined) {
86423
+ runBestEffort(runner, warnings, "launchctl bootout", "launchctl", [
86424
+ "bootout",
86425
+ `gui/${uid}/${paths.label}`
86426
+ ]);
86427
+ }
86428
+ try {
86429
+ (0,node_fs__rspack_import_1.rmSync)(paths.plistPath, {
86430
+ force: true
86431
+ });
86432
+ plistRemoved = !fileExists(paths.plistPath);
86433
+ } catch (error) {
86434
+ warnings.push(`could not remove ${paths.plistPath} (${error instanceof Error ? error.message : String(error)})`);
86435
+ }
86436
+ runBestEffort(runner, warnings, "launchctl unsetenv CODEX_CLI_PATH", "launchctl", [
86437
+ "unsetenv",
86438
+ "CODEX_CLI_PATH"
86439
+ ]);
86440
+ runBestEffort(runner, warnings, "launchctl unsetenv CODEX_HOME", "launchctl", [
86441
+ "unsetenv",
86442
+ "CODEX_HOME"
86443
+ ]);
86444
+ runBestEffort(runner, warnings, "launchctl unsetenv CODEX_APP_SERVER_USE_LOCAL_DAEMON", "launchctl", [
86445
+ "unsetenv",
86446
+ "CODEX_APP_SERVER_USE_LOCAL_DAEMON"
86447
+ ]);
86448
+ runBestEffort(runner, warnings, "launchctl unsetenv CODEX_APP_SERVER_WS_URL", "launchctl", [
86449
+ "unsetenv",
86450
+ "CODEX_APP_SERVER_WS_URL"
86451
+ ]);
86452
+ }
86453
+ return {
86454
+ action: "uninstall",
86455
+ exitCode: 0,
86456
+ plistPath: platform === "darwin" ? paths.plistPath : null,
86457
+ plistRemoved,
86458
+ removed,
86459
+ warnings,
86460
+ wrapperPath: paths.wrapperPath
86461
+ };
86462
+ }
86463
+ function socketStateOf(path) {
86464
+ try {
86465
+ return (0,node_fs__rspack_import_1.statSync)(path).isSocket() ? "socket" : "not-a-socket";
86466
+ } catch (error) {
86467
+ return error && (error.code === "EACCES" || error.code === "EPERM") ? "permission-denied" : "absent";
86468
+ }
86469
+ }
86470
+ /**
86471
+ * Inspect the shim without touching Desktop, pipes, or sockets beyond a stat.
86472
+ * On macOS the Desktop-facing CODEX_CLI_PATH lives in launchd's GUI domain,
86473
+ * which a shell-spawned `gbot` does not inherit — so status queries
86474
+ * `launchctl getenv` there (via the injectable runner) and reports the caller
86475
+ * environment separately. Elsewhere the process env is the whole story.
86476
+ */ function desktopShimStatus({ env = process.env, home = userHomeDir(env), platform = process.platform, runner = defaultRunner } = {}) {
86477
+ const paths = defaultPaths({
86478
+ env,
86479
+ home
86480
+ });
86481
+ const warnings = [];
86482
+ const wrapperPresent = fileExists(paths.wrapperPath);
86483
+ const bridgePresent = fileExists(paths.bridgePath);
86484
+ const envScriptPresent = fileExists(paths.envScriptPath);
86485
+ const plistPresent = platform === "darwin" ? fileExists(paths.plistPath) : false;
86486
+ const cliPath = env.CODEX_CLI_PATH || null;
86487
+ let guiCliPath = null;
86488
+ if (platform === "darwin") {
86489
+ try {
86490
+ const out = runner("launchctl", [
86491
+ "getenv",
86492
+ "CODEX_CLI_PATH"
86493
+ ]);
86494
+ const value = out && typeof out.stdout === "string" ? out.stdout.trim() : "";
86495
+ guiCliPath = value || null;
86496
+ if (out && (out.error || typeof out.status === "number" && out.status !== 0)) {
86497
+ warnings.push("launchctl getenv CODEX_CLI_PATH failed; GUI-domain state unknown");
86498
+ guiCliPath = null;
86499
+ }
86500
+ } catch (error) {
86501
+ warnings.push(`launchctl getenv CODEX_CLI_PATH failed (${error instanceof Error ? error.message : String(error)})`);
86502
+ guiCliPath = null;
86503
+ }
86504
+ }
86505
+ // Desktop-facing value: the GUI domain on macOS, the caller env elsewhere.
86506
+ const desktopCliPath = platform === "darwin" ? guiCliPath : cliPath;
86507
+ const installed = wrapperPresent && isExecutable(paths.wrapperPath) && bridgePresent;
86508
+ // Effective socket, resolved exactly like gbot's own client so status and
86509
+ // send/queue/status never disagree: CODEX_APP_SERVER_SOCK wins, else CODEX_HOME.
86510
+ const socketPath = (0,_codex_bridge_js__rspack_import_4/* .codexSocketPath */.ql)({
86511
+ ...env,
86512
+ CODEX_HOME: paths.codexHome
86513
+ });
86514
+ return {
86515
+ action: "status",
86516
+ bridgePath: paths.bridgePath,
86517
+ bridgePresent,
86518
+ cliPath,
86519
+ codexHome: paths.codexHome,
86520
+ desktopCliPath,
86521
+ envScriptPath: paths.envScriptPath,
86522
+ envScriptPresent,
86523
+ exitCode: installed ? 0 : 1,
86524
+ guiCliPath,
86525
+ installed,
86526
+ persisted: platform === "darwin" ? plistPresent : null,
86527
+ platform,
86528
+ plistPath: platform === "darwin" ? paths.plistPath : null,
86529
+ plistPresent,
86530
+ realPath: paths.realPath,
86531
+ socketPath,
86532
+ socketSource: env.CODEX_APP_SERVER_SOCK ? "CODEX_APP_SERVER_SOCK" : "CODEX_HOME",
86533
+ socketState: socketStateOf(socketPath),
86534
+ warnings,
86535
+ wrapperExecutable: wrapperPresent && isExecutable(paths.wrapperPath),
86536
+ wrapperPath: paths.wrapperPath,
86537
+ wrapperPointsAtShim: desktopCliPath === paths.wrapperPath,
86538
+ wrapperPresent
86539
+ };
86540
+ }
86541
+
86542
+ __webpack_require__.d(__webpack_exports__, {
86543
+ B0: () => (installDesktopShim),
86544
+ em: () => (desktopShimStatus),
86545
+ gM: () => (uninstallDesktopShim)
86546
+ });
86547
+
86548
+
85775
86549
  },
85776
86550
  "./src/core/format.js"(__unused_rspack___webpack_module__, __webpack_exports__, __webpack_require__) {
85777
86551
  /* import */ var _transcript_js__rspack_import_0 = __webpack_require__("./src/core/transcript.js");
@@ -85851,7 +86625,7 @@ function formatCodexStatus(s) {
85851
86625
  lines.push("reachable: yes (daemon)");
85852
86626
  const cli = s.cliVersion ?? (s.cliVersionProbe === "ok" ? "unknown" : "unknown, probe " + s.cliVersionProbe);
85853
86627
  lines.push("daemon version: " + (s.daemonVersion ?? "unknown") + " cli version: " + cli + " pinned schema: " + s.pinnedVersion + " (" + s.schema.compatibility + ")");
85854
- lines.push("desktop attached: unknown (not observable from the socket)");
86628
+ lines.push(s.desktopAttached === "private-stdio" ? "desktop attached: private-stdio (ChatGPT Desktop runs its own private stdio app-server; start a managed daemon with `codex app-server daemon start`)" : "desktop attached: unknown (not observable from the socket)");
85855
86629
  if (s.versionMismatch) {
85856
86630
  lines.push("warning: daemon and CLI versions differ; `codex app-server daemon restart` picks up the installed CLI");
85857
86631
  }
@@ -85866,12 +86640,34 @@ function formatCodexThread(t) {
85866
86640
  const preview = t.preview ? "\n " + stripTerminalControls(String(t.preview).replace(/\s+/g, " ")).slice(0, 200) : "";
85867
86641
  return stripTerminalControls(t.id) + " " + stripTerminalControls(t.status) + title + "\n " + stripTerminalControls(t.cwd ?? "") + preview;
85868
86642
  }
86643
+ function formatDesktopShimStatus(s) {
86644
+ const mark = (ok)=>ok ? "yes" : "no";
86645
+ const cliLine = s.platform === "darwin" ? "CODEX_CLI_PATH: GUI domain " + (s.guiCliPath ?? "(unset)") + " / this shell " + (s.cliPath ?? "(unset)") + (s.wrapperPointsAtShim ? " (Desktop-facing value points at shim)" : "") : "CODEX_CLI_PATH: " + (s.cliPath ?? "(unset)") + (s.wrapperPointsAtShim ? " (points at shim)" : "");
86646
+ const lines = [
86647
+ "wrapper: " + s.wrapperPath + " (" + (s.wrapperExecutable ? "executable" : s.wrapperPresent ? "present, not executable" : "absent") + ")",
86648
+ "bridge: " + s.bridgePath + " (" + mark(s.bridgePresent) + ")",
86649
+ "login env: " + s.envScriptPath + " (" + mark(s.envScriptPresent) + ")",
86650
+ s.platform === "darwin" ? "LaunchAgent: " + s.plistPath + " (" + mark(s.plistPresent) + ")" : "LaunchAgent: n/a (macOS-only)",
86651
+ cliLine,
86652
+ "daemon socket: " + s.socketPath + " (" + s.socketState + ", from " + (s.socketSource ?? "CODEX_HOME") + ")"
86653
+ ];
86654
+ if (!s.installed) {
86655
+ lines.push("shim: not installed — run `gbot codex desktop-shim install` (Desktop keeps stock behavior until then)");
86656
+ } else if (!s.wrapperPointsAtShim) {
86657
+ lines.push("shim: installed but CODEX_CLI_PATH does not point at it — reinstall or relaunch ChatGPT.app after login");
86658
+ } else {
86659
+ lines.push("shim: active — Desktop app-server spawns bridge onto the managed daemon");
86660
+ }
86661
+ for (const warning of s.warnings ?? [])lines.push("warning: " + String(warning));
86662
+ return lines.join("\n");
86663
+ }
85869
86664
 
85870
86665
  __webpack_require__.d(__webpack_exports__, {
85871
86666
  P2: () => (formatCodexStatus),
85872
86667
  bM: () => (formatRecord),
85873
86668
  e_: () => (formatCodexQueue),
85874
86669
  eh: () => (summarize),
86670
+ fX: () => (formatDesktopShimStatus),
85875
86671
  nz: () => (formatCodexThread),
85876
86672
  oZ: () => (formatTranscript)
85877
86673
  });