apexrest 1.3.0-beta.1 → 1.3.0

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 (182) hide show
  1. package/README.md +90 -140
  2. package/dist/codex-compat/.claude-plugin/marketplace.json +20 -0
  3. package/dist/codex-compat/plugins/apexrest-apex/.claude-plugin/plugin.json +28 -0
  4. package/dist/codex-compat/plugins/apexrest-apex/.codex-plugin/plugin.json +7 -7
  5. package/dist/codex-compat/plugins/apexrest-apex/resources/blocks/generator.json +1 -1
  6. package/dist/codex-compat/plugins/apexrest-apex/resources/blocks/manifest.json +6 -6
  7. package/dist/codex-compat/plugins/apexrest-apex/resources/blocks/packages/analytics/status-summary/1.0.0/block.yaml +1 -1
  8. package/dist/codex-compat/plugins/apexrest-apex/resources/blocks/packages/crud/report-dialog/1.0.0/block.yaml +1 -1
  9. package/dist/codex-compat/plugins/apexrest-apex/resources/blocks/packages/read/detail/1.0.0/block.yaml +1 -1
  10. package/dist/codex-compat/plugins/apexrest-apex/resources/blocks/packages/read/filtered-list/1.0.0/block.yaml +1 -1
  11. package/dist/codex-compat/plugins/apexrest-apex/resources/blocks/packages/read/history/1.0.0/block.yaml +1 -1
  12. package/dist/codex-compat/plugins/apexrest-apex/resources/blocks/packages/read/master-detail/1.0.0/block.yaml +1 -1
  13. package/dist/codex-compat/plugins/apexrest-apex/resources/schemas/composer-blueprint.schema.json +5 -4
  14. package/dist/codex-compat/plugins/apexrest-apex/resources/schemas/composer-contract.schema.json +2 -2
  15. package/dist/codex-compat/plugins/apexrest-apex/resources/schemas/composer-entity.schema.json +2 -1
  16. package/dist/codex-compat/plugins/apexrest-apex/resources/schemas/composer-field.schema.json +2 -1
  17. package/dist/codex-compat/plugins/apexrest-apex/resources/schemas/composer-instance.schema.json +1 -1
  18. package/dist/codex-compat/plugins/apexrest-apex/resources/schemas/composer-operation.schema.json +1 -1
  19. package/dist/codex-compat/plugins/apexrest-apex/resources/schemas/composer-plan.schema.json +5 -4
  20. package/dist/codex-compat/plugins/apexrest-apex/resources/schemas/deploy-plan.schema.json +18 -24
  21. package/dist/codex-compat/plugins/apexrest-apex/resources/schemas/operations.schema.json +352 -569
  22. package/dist/codex-compat/plugins/apexrest-apex/resources/schemas/policy.schema.json +21 -0
  23. package/dist/codex-compat/plugins/apexrest-apex/resources/schemas/project.schema.json +4 -7
  24. package/dist/codex-compat/plugins/apexrest-apex/resources/templates/blank-app/README.md +0 -2
  25. package/dist/codex-compat/plugins/apexrest-apex/resources/templates/customer-crm/README.md +1 -3
  26. package/dist/codex-compat/plugins/apexrest-apex/resources/templates/existing-app/README.md +0 -2
  27. package/dist/codex-compat/plugins/apexrest-apex/runtime/apexrest.mjs +70 -44
  28. package/dist/codex-compat/plugins/apexrest-apex/runtime/chunk-5PCC7GZM.mjs +4090 -0
  29. package/dist/codex-compat/plugins/apexrest-apex/runtime/chunk-BVPAS3TD.mjs +18 -0
  30. package/dist/codex-compat/plugins/apexrest-apex/runtime/chunk-CVMECW6D.mjs +65 -0
  31. package/dist/codex-compat/plugins/apexrest-apex/runtime/{chunk-EBBEN4AV.mjs → chunk-JYN3YHP3.mjs} +4220 -10639
  32. package/dist/codex-compat/plugins/apexrest-apex/runtime/chunk-KGTE7Q5Y.mjs +23 -0
  33. package/dist/{runtime/chunk-33GE2NWZ.mjs → codex-compat/plugins/apexrest-apex/runtime/chunk-KKRFM7Q7.mjs} +21 -4
  34. package/dist/codex-compat/plugins/apexrest-apex/runtime/{chunk-2VBZESVC.mjs → chunk-MNU54A7W.mjs} +7 -1
  35. package/dist/codex-compat/plugins/apexrest-apex/runtime/chunk-N4C2SKCN.mjs +6912 -0
  36. package/dist/{runtime/chunk-KQ5IDT7Z.mjs → codex-compat/plugins/apexrest-apex/runtime/chunk-P3CVQAZW.mjs} +822 -102
  37. package/dist/{runtime/chunk-BAHECVGO.mjs → codex-compat/plugins/apexrest-apex/runtime/chunk-QKYF6N6U.mjs} +192 -114
  38. package/dist/codex-compat/plugins/apexrest-apex/runtime/{chunk-G3KR57BY.mjs → chunk-RBJJNQ5O.mjs} +7 -7
  39. package/dist/codex-compat/plugins/apexrest-apex/runtime/{chunk-YPLIIQ4Y.mjs → chunk-TMSMKVRP.mjs} +486 -352
  40. package/dist/codex-compat/plugins/apexrest-apex/runtime/{chunk-2Z3BZF66.mjs → chunk-WPS3CSQJ.mjs} +124 -11
  41. package/dist/codex-compat/plugins/apexrest-apex/runtime/mcp.mjs +5 -10
  42. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-apexlang/SKILL.md +22 -25
  43. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-apexlang/agents/openai.yaml +3 -3
  44. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-apexlang/references/component-routes.md +1 -5
  45. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-pattern-catalog/SKILL.md +4 -4
  46. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-pattern-catalog/agents/openai.yaml +1 -1
  47. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-pattern-catalog/references/capture-and-curation.md +2 -2
  48. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-safety/SKILL.md +18 -0
  49. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-safety/agents/openai.yaml +4 -0
  50. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-setup/SKILL.md +20 -10
  51. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-setup/agents/openai.yaml +3 -3
  52. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-work/SKILL.md +11 -8
  53. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-work/agents/openai.yaml +3 -3
  54. package/dist/resources/blocks/generator.json +1 -1
  55. package/dist/resources/blocks/manifest.json +6 -6
  56. package/dist/resources/blocks/packages/analytics/status-summary/1.0.0/block.yaml +1 -1
  57. package/dist/resources/blocks/packages/crud/report-dialog/1.0.0/block.yaml +1 -1
  58. package/dist/resources/blocks/packages/read/detail/1.0.0/block.yaml +1 -1
  59. package/dist/resources/blocks/packages/read/filtered-list/1.0.0/block.yaml +1 -1
  60. package/dist/resources/blocks/packages/read/history/1.0.0/block.yaml +1 -1
  61. package/dist/resources/blocks/packages/read/master-detail/1.0.0/block.yaml +1 -1
  62. package/dist/resources/schemas/composer-blueprint.schema.json +5 -4
  63. package/dist/resources/schemas/composer-contract.schema.json +2 -2
  64. package/dist/resources/schemas/composer-entity.schema.json +2 -1
  65. package/dist/resources/schemas/composer-field.schema.json +2 -1
  66. package/dist/resources/schemas/composer-instance.schema.json +1 -1
  67. package/dist/resources/schemas/composer-operation.schema.json +1 -1
  68. package/dist/resources/schemas/composer-plan.schema.json +5 -4
  69. package/dist/resources/schemas/deploy-plan.schema.json +18 -24
  70. package/dist/resources/schemas/operations.schema.json +352 -569
  71. package/dist/resources/schemas/policy.schema.json +21 -0
  72. package/dist/resources/schemas/project.schema.json +4 -7
  73. package/dist/resources/templates/blank-app/README.md +0 -2
  74. package/dist/resources/templates/customer-crm/README.md +1 -3
  75. package/dist/resources/templates/existing-app/README.md +0 -2
  76. package/dist/runtime/apexrest.mjs +70 -44
  77. package/dist/runtime/chunk-5PCC7GZM.mjs +4090 -0
  78. package/dist/runtime/chunk-BVPAS3TD.mjs +18 -0
  79. package/dist/runtime/chunk-CVMECW6D.mjs +65 -0
  80. package/dist/runtime/{chunk-EBBEN4AV.mjs → chunk-JYN3YHP3.mjs} +4220 -10639
  81. package/dist/runtime/chunk-KGTE7Q5Y.mjs +23 -0
  82. package/dist/{codex-compat/plugins/apexrest-apex/runtime/chunk-33GE2NWZ.mjs → runtime/chunk-KKRFM7Q7.mjs} +21 -4
  83. package/dist/runtime/{chunk-2VBZESVC.mjs → chunk-MNU54A7W.mjs} +7 -1
  84. package/dist/runtime/chunk-N4C2SKCN.mjs +6912 -0
  85. package/dist/{codex-compat/plugins/apexrest-apex/runtime/chunk-KQ5IDT7Z.mjs → runtime/chunk-P3CVQAZW.mjs} +822 -102
  86. package/dist/{codex-compat/plugins/apexrest-apex/runtime/chunk-BAHECVGO.mjs → runtime/chunk-QKYF6N6U.mjs} +192 -114
  87. package/dist/runtime/{chunk-G3KR57BY.mjs → chunk-RBJJNQ5O.mjs} +7 -7
  88. package/dist/runtime/{chunk-YPLIIQ4Y.mjs → chunk-TMSMKVRP.mjs} +486 -352
  89. package/dist/runtime/{chunk-2Z3BZF66.mjs → chunk-WPS3CSQJ.mjs} +124 -11
  90. package/dist/runtime/mcp.mjs +5 -10
  91. package/package.json +6 -6
  92. package/README.uk.md +0 -212
  93. package/dist/codex-compat/plugins/apexrest-apex/resources/panel/index.html +0 -68
  94. package/dist/codex-compat/plugins/apexrest-apex/resources/panel/panel.css +0 -627
  95. package/dist/codex-compat/plugins/apexrest-apex/resources/panel/panel.js +0 -861
  96. package/dist/codex-compat/plugins/apexrest-apex/resources/templates/blank-app/README.uk.md +0 -5
  97. package/dist/codex-compat/plugins/apexrest-apex/resources/templates/customer-crm/README.uk.md +0 -7
  98. package/dist/codex-compat/plugins/apexrest-apex/resources/templates/database-control/install.sql +0 -17
  99. package/dist/codex-compat/plugins/apexrest-apex/resources/templates/existing-app/README.uk.md +0 -9
  100. package/dist/codex-compat/plugins/apexrest-apex/resources/third-party/node_modules__@playwright__test__LICENSE +0 -202
  101. package/dist/codex-compat/plugins/apexrest-apex/resources/third-party/node_modules__@playwright__test__NOTICE +0 -5
  102. package/dist/codex-compat/plugins/apexrest-apex/resources/third-party/node_modules__@types__node__LICENSE +0 -21
  103. package/dist/codex-compat/plugins/apexrest-apex/resources/third-party/node_modules__@types__yauzl__LICENSE +0 -21
  104. package/dist/codex-compat/plugins/apexrest-apex/resources/third-party/node_modules__@typescript__typescript-darwin-arm64__LICENSE +0 -55
  105. package/dist/codex-compat/plugins/apexrest-apex/resources/third-party/node_modules__@typescript__typescript-darwin-arm64__NOTICE.txt +0 -436
  106. package/dist/codex-compat/plugins/apexrest-apex/resources/third-party/node_modules__esbuild__LICENSE.md +0 -21
  107. package/dist/codex-compat/plugins/apexrest-apex/resources/third-party/node_modules__fflate__LICENSE +0 -21
  108. package/dist/codex-compat/plugins/apexrest-apex/resources/third-party/node_modules__marked__LICENSE +0 -44
  109. package/dist/codex-compat/plugins/apexrest-apex/resources/third-party/node_modules__playwright-core__LICENSE +0 -202
  110. package/dist/codex-compat/plugins/apexrest-apex/resources/third-party/node_modules__playwright-core__NOTICE +0 -5
  111. package/dist/codex-compat/plugins/apexrest-apex/resources/third-party/node_modules__playwright__LICENSE +0 -202
  112. package/dist/codex-compat/plugins/apexrest-apex/resources/third-party/node_modules__playwright__NOTICE +0 -5
  113. package/dist/codex-compat/plugins/apexrest-apex/resources/third-party/node_modules__prettier__LICENSE +0 -7
  114. package/dist/codex-compat/plugins/apexrest-apex/resources/third-party/node_modules__typescript__LICENSE +0 -55
  115. package/dist/codex-compat/plugins/apexrest-apex/resources/third-party/node_modules__typescript__NOTICE.txt +0 -436
  116. package/dist/codex-compat/plugins/apexrest-apex/resources/third-party/node_modules__undici-types__LICENSE +0 -21
  117. package/dist/codex-compat/plugins/apexrest-apex/runtime/chunk-2BBNJVKW.mjs +0 -1996
  118. package/dist/codex-compat/plugins/apexrest-apex/runtime/chunk-5JI3XEAK.mjs +0 -14
  119. package/dist/codex-compat/plugins/apexrest-apex/runtime/chunk-CYPFCUNE.mjs +0 -150
  120. package/dist/codex-compat/plugins/apexrest-apex/runtime/chunk-ESDVN7DS.mjs +0 -14
  121. package/dist/codex-compat/plugins/apexrest-apex/runtime/chunk-FTTPESNK.mjs +0 -203
  122. package/dist/codex-compat/plugins/apexrest-apex/runtime/chunk-HKJVCGQQ.mjs +0 -1302
  123. package/dist/codex-compat/plugins/apexrest-apex/runtime/chunk-RWGJITHZ.mjs +0 -992
  124. package/dist/codex-compat/plugins/apexrest-apex/runtime/chunk-TLYYCRQA.mjs +0 -329
  125. package/dist/codex-compat/plugins/apexrest-apex/runtime/chunk-WXP75UUP.mjs +0 -18
  126. package/dist/codex-compat/plugins/apexrest-apex/runtime/chunk-YQHHPRJH.mjs +0 -14
  127. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-compose/SKILL.md +0 -18
  128. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-compose/agents/openai.yaml +0 -4
  129. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-compose/references/workflow.md +0 -15
  130. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-database/SKILL.md +0 -9
  131. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-database/agents/openai.yaml +0 -4
  132. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-debug/SKILL.md +0 -9
  133. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-debug/agents/openai.yaml +0 -4
  134. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-deploy/SKILL.md +0 -21
  135. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-deploy/agents/openai.yaml +0 -4
  136. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-install-dependencies/SKILL.md +0 -38
  137. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-install-dependencies/agents/openai.yaml +0 -4
  138. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-menu/SKILL.md +0 -30
  139. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-menu/agents/openai.yaml +0 -4
  140. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-menu/references/cli-catalog.md +0 -30
  141. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-panel/SKILL.md +0 -14
  142. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-panel/agents/openai.yaml +0 -4
  143. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-project/SKILL.md +0 -11
  144. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-project/agents/openai.yaml +0 -4
  145. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-review/SKILL.md +0 -11
  146. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-review/agents/openai.yaml +0 -4
  147. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-test/SKILL.md +0 -29
  148. package/dist/codex-compat/plugins/apexrest-apex/skills/apexrest-test/agents/openai.yaml +0 -4
  149. package/dist/resources/panel/index.html +0 -68
  150. package/dist/resources/panel/panel.css +0 -627
  151. package/dist/resources/panel/panel.js +0 -861
  152. package/dist/resources/templates/blank-app/README.uk.md +0 -5
  153. package/dist/resources/templates/customer-crm/README.uk.md +0 -7
  154. package/dist/resources/templates/database-control/install.sql +0 -17
  155. package/dist/resources/templates/existing-app/README.uk.md +0 -9
  156. package/dist/resources/third-party/node_modules__@playwright__test__LICENSE +0 -202
  157. package/dist/resources/third-party/node_modules__@playwright__test__NOTICE +0 -5
  158. package/dist/resources/third-party/node_modules__@types__node__LICENSE +0 -21
  159. package/dist/resources/third-party/node_modules__@types__yauzl__LICENSE +0 -21
  160. package/dist/resources/third-party/node_modules__@typescript__typescript-darwin-arm64__LICENSE +0 -55
  161. package/dist/resources/third-party/node_modules__@typescript__typescript-darwin-arm64__NOTICE.txt +0 -436
  162. package/dist/resources/third-party/node_modules__esbuild__LICENSE.md +0 -21
  163. package/dist/resources/third-party/node_modules__fflate__LICENSE +0 -21
  164. package/dist/resources/third-party/node_modules__marked__LICENSE +0 -44
  165. package/dist/resources/third-party/node_modules__playwright-core__LICENSE +0 -202
  166. package/dist/resources/third-party/node_modules__playwright-core__NOTICE +0 -5
  167. package/dist/resources/third-party/node_modules__playwright__LICENSE +0 -202
  168. package/dist/resources/third-party/node_modules__playwright__NOTICE +0 -5
  169. package/dist/resources/third-party/node_modules__prettier__LICENSE +0 -7
  170. package/dist/resources/third-party/node_modules__typescript__LICENSE +0 -55
  171. package/dist/resources/third-party/node_modules__typescript__NOTICE.txt +0 -436
  172. package/dist/resources/third-party/node_modules__undici-types__LICENSE +0 -21
  173. package/dist/runtime/chunk-2BBNJVKW.mjs +0 -1996
  174. package/dist/runtime/chunk-5JI3XEAK.mjs +0 -14
  175. package/dist/runtime/chunk-CYPFCUNE.mjs +0 -150
  176. package/dist/runtime/chunk-ESDVN7DS.mjs +0 -14
  177. package/dist/runtime/chunk-FTTPESNK.mjs +0 -203
  178. package/dist/runtime/chunk-HKJVCGQQ.mjs +0 -1302
  179. package/dist/runtime/chunk-RWGJITHZ.mjs +0 -992
  180. package/dist/runtime/chunk-TLYYCRQA.mjs +0 -329
  181. package/dist/runtime/chunk-WXP75UUP.mjs +0 -18
  182. package/dist/runtime/chunk-YQHHPRJH.mjs +0 -14
@@ -1,13 +1,20 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  VERSION
4
- } from "./chunk-G3KR57BY.mjs";
4
+ } from "./chunk-RBJJNQ5O.mjs";
5
5
  import {
6
- Client,
7
- StdioClientTransport,
8
6
  ToolchainService,
7
+ canonicalHome,
9
8
  managedHome,
9
+ renameWithRetry,
10
10
  requireTrust,
11
+ resourceRoot,
12
+ runCommand,
13
+ runtimeState
14
+ } from "./chunk-N4C2SKCN.mjs";
15
+ import {
16
+ Client,
17
+ ReadBuffer,
11
18
  require_applicator,
12
19
  require_codegen,
13
20
  require_compile,
@@ -24,24 +31,521 @@ import {
24
31
  require_validate,
25
32
  require_validation,
26
33
  require_validation_error,
27
- resourceRoot,
28
- runProcess,
29
- runtimeState
30
- } from "./chunk-EBBEN4AV.mjs";
34
+ serializeMessage
35
+ } from "./chunk-JYN3YHP3.mjs";
31
36
  import {
32
37
  Fault,
33
38
  __commonJS,
39
+ __require,
34
40
  __toESM,
35
41
  atomicWrite,
36
42
  canonical,
37
43
  contained,
44
+ containedChild,
38
45
  exists,
39
46
  hash,
40
47
  inventory,
41
48
  readJson,
42
49
  withLock,
43
50
  writeJson
44
- } from "./chunk-2Z3BZF66.mjs";
51
+ } from "./chunk-WPS3CSQJ.mjs";
52
+
53
+ // node_modules/isexe/windows.js
54
+ var require_windows = __commonJS({
55
+ "node_modules/isexe/windows.js"(exports, module) {
56
+ module.exports = isexe;
57
+ isexe.sync = sync;
58
+ var fs = __require("fs");
59
+ function checkPathExt(path5, options) {
60
+ var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT;
61
+ if (!pathext) {
62
+ return true;
63
+ }
64
+ pathext = pathext.split(";");
65
+ if (pathext.indexOf("") !== -1) {
66
+ return true;
67
+ }
68
+ for (var i = 0; i < pathext.length; i++) {
69
+ var p = pathext[i].toLowerCase();
70
+ if (p && path5.substr(-p.length).toLowerCase() === p) {
71
+ return true;
72
+ }
73
+ }
74
+ return false;
75
+ }
76
+ function checkStat(stat, path5, options) {
77
+ if (!stat.isSymbolicLink() && !stat.isFile()) {
78
+ return false;
79
+ }
80
+ return checkPathExt(path5, options);
81
+ }
82
+ function isexe(path5, options, cb) {
83
+ fs.stat(path5, function(er, stat) {
84
+ cb(er, er ? false : checkStat(stat, path5, options));
85
+ });
86
+ }
87
+ function sync(path5, options) {
88
+ return checkStat(fs.statSync(path5), path5, options);
89
+ }
90
+ }
91
+ });
92
+
93
+ // node_modules/isexe/mode.js
94
+ var require_mode = __commonJS({
95
+ "node_modules/isexe/mode.js"(exports, module) {
96
+ module.exports = isexe;
97
+ isexe.sync = sync;
98
+ var fs = __require("fs");
99
+ function isexe(path5, options, cb) {
100
+ fs.stat(path5, function(er, stat) {
101
+ cb(er, er ? false : checkStat(stat, options));
102
+ });
103
+ }
104
+ function sync(path5, options) {
105
+ return checkStat(fs.statSync(path5), options);
106
+ }
107
+ function checkStat(stat, options) {
108
+ return stat.isFile() && checkMode(stat, options);
109
+ }
110
+ function checkMode(stat, options) {
111
+ var mod = stat.mode;
112
+ var uid = stat.uid;
113
+ var gid = stat.gid;
114
+ var myUid = options.uid !== void 0 ? options.uid : process.getuid && process.getuid();
115
+ var myGid = options.gid !== void 0 ? options.gid : process.getgid && process.getgid();
116
+ var u = parseInt("100", 8);
117
+ var g = parseInt("010", 8);
118
+ var o = parseInt("001", 8);
119
+ var ug = u | g;
120
+ var ret = mod & o || mod & g && gid === myGid || mod & u && uid === myUid || mod & ug && myUid === 0;
121
+ return ret;
122
+ }
123
+ }
124
+ });
125
+
126
+ // node_modules/isexe/index.js
127
+ var require_isexe = __commonJS({
128
+ "node_modules/isexe/index.js"(exports, module) {
129
+ var fs = __require("fs");
130
+ var core;
131
+ if (process.platform === "win32" || global.TESTING_WINDOWS) {
132
+ core = require_windows();
133
+ } else {
134
+ core = require_mode();
135
+ }
136
+ module.exports = isexe;
137
+ isexe.sync = sync;
138
+ function isexe(path5, options, cb) {
139
+ if (typeof options === "function") {
140
+ cb = options;
141
+ options = {};
142
+ }
143
+ if (!cb) {
144
+ if (typeof Promise !== "function") {
145
+ throw new TypeError("callback not provided");
146
+ }
147
+ return new Promise(function(resolve, reject) {
148
+ isexe(path5, options || {}, function(er, is) {
149
+ if (er) {
150
+ reject(er);
151
+ } else {
152
+ resolve(is);
153
+ }
154
+ });
155
+ });
156
+ }
157
+ core(path5, options || {}, function(er, is) {
158
+ if (er) {
159
+ if (er.code === "EACCES" || options && options.ignoreErrors) {
160
+ er = null;
161
+ is = false;
162
+ }
163
+ }
164
+ cb(er, is);
165
+ });
166
+ }
167
+ function sync(path5, options) {
168
+ try {
169
+ return core.sync(path5, options || {});
170
+ } catch (er) {
171
+ if (options && options.ignoreErrors || er.code === "EACCES") {
172
+ return false;
173
+ } else {
174
+ throw er;
175
+ }
176
+ }
177
+ }
178
+ }
179
+ });
180
+
181
+ // node_modules/which/which.js
182
+ var require_which = __commonJS({
183
+ "node_modules/which/which.js"(exports, module) {
184
+ var isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
185
+ var path5 = __require("path");
186
+ var COLON = isWindows ? ";" : ":";
187
+ var isexe = require_isexe();
188
+ var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" });
189
+ var getPathInfo = (cmd, opt) => {
190
+ const colon = opt.colon || COLON;
191
+ const pathEnv = cmd.match(/\//) || isWindows && cmd.match(/\\/) ? [""] : [
192
+ // windows always checks the cwd first
193
+ ...isWindows ? [process.cwd()] : [],
194
+ ...(opt.path || process.env.PATH || /* istanbul ignore next: very unusual */
195
+ "").split(colon)
196
+ ];
197
+ const pathExtExe = isWindows ? opt.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "";
198
+ const pathExt = isWindows ? pathExtExe.split(colon) : [""];
199
+ if (isWindows) {
200
+ if (cmd.indexOf(".") !== -1 && pathExt[0] !== "")
201
+ pathExt.unshift("");
202
+ }
203
+ return {
204
+ pathEnv,
205
+ pathExt,
206
+ pathExtExe
207
+ };
208
+ };
209
+ var which = (cmd, opt, cb) => {
210
+ if (typeof opt === "function") {
211
+ cb = opt;
212
+ opt = {};
213
+ }
214
+ if (!opt)
215
+ opt = {};
216
+ const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
217
+ const found = [];
218
+ const step = (i) => new Promise((resolve, reject) => {
219
+ if (i === pathEnv.length)
220
+ return opt.all && found.length ? resolve(found) : reject(getNotFoundError(cmd));
221
+ const ppRaw = pathEnv[i];
222
+ const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
223
+ const pCmd = path5.join(pathPart, cmd);
224
+ const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
225
+ resolve(subStep(p, i, 0));
226
+ });
227
+ const subStep = (p, i, ii) => new Promise((resolve, reject) => {
228
+ if (ii === pathExt.length)
229
+ return resolve(step(i + 1));
230
+ const ext = pathExt[ii];
231
+ isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
232
+ if (!er && is) {
233
+ if (opt.all)
234
+ found.push(p + ext);
235
+ else
236
+ return resolve(p + ext);
237
+ }
238
+ return resolve(subStep(p, i, ii + 1));
239
+ });
240
+ });
241
+ return cb ? step(0).then((res) => cb(null, res), cb) : step(0);
242
+ };
243
+ var whichSync = (cmd, opt) => {
244
+ opt = opt || {};
245
+ const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
246
+ const found = [];
247
+ for (let i = 0; i < pathEnv.length; i++) {
248
+ const ppRaw = pathEnv[i];
249
+ const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
250
+ const pCmd = path5.join(pathPart, cmd);
251
+ const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
252
+ for (let j = 0; j < pathExt.length; j++) {
253
+ const cur = p + pathExt[j];
254
+ try {
255
+ const is = isexe.sync(cur, { pathExt: pathExtExe });
256
+ if (is) {
257
+ if (opt.all)
258
+ found.push(cur);
259
+ else
260
+ return cur;
261
+ }
262
+ } catch (ex) {
263
+ }
264
+ }
265
+ }
266
+ if (opt.all && found.length)
267
+ return found;
268
+ if (opt.nothrow)
269
+ return null;
270
+ throw getNotFoundError(cmd);
271
+ };
272
+ module.exports = which;
273
+ which.sync = whichSync;
274
+ }
275
+ });
276
+
277
+ // node_modules/path-key/index.js
278
+ var require_path_key = __commonJS({
279
+ "node_modules/path-key/index.js"(exports, module) {
280
+ "use strict";
281
+ var pathKey = (options = {}) => {
282
+ const environment = options.env || process.env;
283
+ const platform = options.platform || process.platform;
284
+ if (platform !== "win32") {
285
+ return "PATH";
286
+ }
287
+ return Object.keys(environment).reverse().find((key) => key.toUpperCase() === "PATH") || "Path";
288
+ };
289
+ module.exports = pathKey;
290
+ module.exports.default = pathKey;
291
+ }
292
+ });
293
+
294
+ // node_modules/cross-spawn/lib/util/resolveCommand.js
295
+ var require_resolveCommand = __commonJS({
296
+ "node_modules/cross-spawn/lib/util/resolveCommand.js"(exports, module) {
297
+ "use strict";
298
+ var path5 = __require("path");
299
+ var which = require_which();
300
+ var getPathKey = require_path_key();
301
+ function resolveCommandAttempt(parsed, withoutPathExt) {
302
+ const env = parsed.options.env || process.env;
303
+ const cwd = process.cwd();
304
+ const hasCustomCwd = parsed.options.cwd != null;
305
+ const shouldSwitchCwd = hasCustomCwd && process.chdir !== void 0 && !process.chdir.disabled;
306
+ if (shouldSwitchCwd) {
307
+ try {
308
+ process.chdir(parsed.options.cwd);
309
+ } catch (err) {
310
+ }
311
+ }
312
+ let resolved;
313
+ try {
314
+ resolved = which.sync(parsed.command, {
315
+ path: env[getPathKey({ env })],
316
+ pathExt: withoutPathExt ? path5.delimiter : void 0
317
+ });
318
+ } catch (e) {
319
+ } finally {
320
+ if (shouldSwitchCwd) {
321
+ process.chdir(cwd);
322
+ }
323
+ }
324
+ if (resolved) {
325
+ resolved = path5.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
326
+ }
327
+ return resolved;
328
+ }
329
+ function resolveCommand(parsed) {
330
+ return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true);
331
+ }
332
+ module.exports = resolveCommand;
333
+ }
334
+ });
335
+
336
+ // node_modules/cross-spawn/lib/util/escape.js
337
+ var require_escape = __commonJS({
338
+ "node_modules/cross-spawn/lib/util/escape.js"(exports, module) {
339
+ "use strict";
340
+ var metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
341
+ function escapeCommand(arg) {
342
+ arg = arg.replace(metaCharsRegExp, "^$1");
343
+ return arg;
344
+ }
345
+ function escapeArgument(arg, doubleEscapeMetaChars) {
346
+ arg = `${arg}`;
347
+ arg = arg.replace(/(?=(\\+?)?)\1"/g, '$1$1\\"');
348
+ arg = arg.replace(/(?=(\\+?)?)\1$/, "$1$1");
349
+ arg = `"${arg}"`;
350
+ arg = arg.replace(metaCharsRegExp, "^$1");
351
+ if (doubleEscapeMetaChars) {
352
+ arg = arg.replace(metaCharsRegExp, "^$1");
353
+ }
354
+ return arg;
355
+ }
356
+ module.exports.command = escapeCommand;
357
+ module.exports.argument = escapeArgument;
358
+ }
359
+ });
360
+
361
+ // node_modules/shebang-regex/index.js
362
+ var require_shebang_regex = __commonJS({
363
+ "node_modules/shebang-regex/index.js"(exports, module) {
364
+ "use strict";
365
+ module.exports = /^#!(.*)/;
366
+ }
367
+ });
368
+
369
+ // node_modules/shebang-command/index.js
370
+ var require_shebang_command = __commonJS({
371
+ "node_modules/shebang-command/index.js"(exports, module) {
372
+ "use strict";
373
+ var shebangRegex = require_shebang_regex();
374
+ module.exports = (string = "") => {
375
+ const match = string.match(shebangRegex);
376
+ if (!match) {
377
+ return null;
378
+ }
379
+ const [path5, argument] = match[0].replace(/#! ?/, "").split(" ");
380
+ const binary = path5.split("/").pop();
381
+ if (binary === "env") {
382
+ return argument;
383
+ }
384
+ return argument ? `${binary} ${argument}` : binary;
385
+ };
386
+ }
387
+ });
388
+
389
+ // node_modules/cross-spawn/lib/util/readShebang.js
390
+ var require_readShebang = __commonJS({
391
+ "node_modules/cross-spawn/lib/util/readShebang.js"(exports, module) {
392
+ "use strict";
393
+ var fs = __require("fs");
394
+ var shebangCommand = require_shebang_command();
395
+ function readShebang(command) {
396
+ const size = 150;
397
+ const buffer = Buffer.alloc(size);
398
+ let fd;
399
+ try {
400
+ fd = fs.openSync(command, "r");
401
+ fs.readSync(fd, buffer, 0, size, 0);
402
+ fs.closeSync(fd);
403
+ } catch (e) {
404
+ }
405
+ return shebangCommand(buffer.toString());
406
+ }
407
+ module.exports = readShebang;
408
+ }
409
+ });
410
+
411
+ // node_modules/cross-spawn/lib/parse.js
412
+ var require_parse = __commonJS({
413
+ "node_modules/cross-spawn/lib/parse.js"(exports, module) {
414
+ "use strict";
415
+ var path5 = __require("path");
416
+ var resolveCommand = require_resolveCommand();
417
+ var escape = require_escape();
418
+ var readShebang = require_readShebang();
419
+ var isWin = process.platform === "win32";
420
+ var isExecutableRegExp = /\.(?:com|exe)$/i;
421
+ var isCmdShimRegExp = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
422
+ function detectShebang(parsed) {
423
+ parsed.file = resolveCommand(parsed);
424
+ const shebang = parsed.file && readShebang(parsed.file);
425
+ if (shebang) {
426
+ parsed.args.unshift(parsed.file);
427
+ parsed.command = shebang;
428
+ return resolveCommand(parsed);
429
+ }
430
+ return parsed.file;
431
+ }
432
+ function parseNonShell(parsed) {
433
+ if (!isWin) {
434
+ return parsed;
435
+ }
436
+ const commandFile = detectShebang(parsed);
437
+ const needsShell = !isExecutableRegExp.test(commandFile);
438
+ if (parsed.options.forceShell || needsShell) {
439
+ const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
440
+ parsed.command = path5.normalize(parsed.command);
441
+ parsed.command = escape.command(parsed.command);
442
+ parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
443
+ const shellCommand = [parsed.command].concat(parsed.args).join(" ");
444
+ parsed.args = ["/d", "/s", "/c", `"${shellCommand}"`];
445
+ parsed.command = process.env.comspec || "cmd.exe";
446
+ parsed.options.windowsVerbatimArguments = true;
447
+ }
448
+ return parsed;
449
+ }
450
+ function parse(command, args, options) {
451
+ if (args && !Array.isArray(args)) {
452
+ options = args;
453
+ args = null;
454
+ }
455
+ args = args ? args.slice(0) : [];
456
+ options = Object.assign({}, options);
457
+ const parsed = {
458
+ command,
459
+ args,
460
+ options,
461
+ file: void 0,
462
+ original: {
463
+ command,
464
+ args
465
+ }
466
+ };
467
+ return options.shell ? parsed : parseNonShell(parsed);
468
+ }
469
+ module.exports = parse;
470
+ }
471
+ });
472
+
473
+ // node_modules/cross-spawn/lib/enoent.js
474
+ var require_enoent = __commonJS({
475
+ "node_modules/cross-spawn/lib/enoent.js"(exports, module) {
476
+ "use strict";
477
+ var isWin = process.platform === "win32";
478
+ function notFoundError(original, syscall) {
479
+ return Object.assign(new Error(`${syscall} ${original.command} ENOENT`), {
480
+ code: "ENOENT",
481
+ errno: "ENOENT",
482
+ syscall: `${syscall} ${original.command}`,
483
+ path: original.command,
484
+ spawnargs: original.args
485
+ });
486
+ }
487
+ function hookChildProcess(cp2, parsed) {
488
+ if (!isWin) {
489
+ return;
490
+ }
491
+ const originalEmit = cp2.emit;
492
+ cp2.emit = function(name, arg1) {
493
+ if (name === "exit") {
494
+ const err = verifyENOENT(arg1, parsed);
495
+ if (err) {
496
+ return originalEmit.call(cp2, "error", err);
497
+ }
498
+ }
499
+ return originalEmit.apply(cp2, arguments);
500
+ };
501
+ }
502
+ function verifyENOENT(status, parsed) {
503
+ if (isWin && status === 1 && !parsed.file) {
504
+ return notFoundError(parsed.original, "spawn");
505
+ }
506
+ return null;
507
+ }
508
+ function verifyENOENTSync(status, parsed) {
509
+ if (isWin && status === 1 && !parsed.file) {
510
+ return notFoundError(parsed.original, "spawnSync");
511
+ }
512
+ return null;
513
+ }
514
+ module.exports = {
515
+ hookChildProcess,
516
+ verifyENOENT,
517
+ verifyENOENTSync,
518
+ notFoundError
519
+ };
520
+ }
521
+ });
522
+
523
+ // node_modules/cross-spawn/index.js
524
+ var require_cross_spawn = __commonJS({
525
+ "node_modules/cross-spawn/index.js"(exports, module) {
526
+ "use strict";
527
+ var cp2 = __require("child_process");
528
+ var parse = require_parse();
529
+ var enoent = require_enoent();
530
+ function spawn2(command, args, options) {
531
+ const parsed = parse(command, args, options);
532
+ const spawned = cp2.spawn(parsed.command, parsed.args, parsed.options);
533
+ enoent.hookChildProcess(spawned, parsed);
534
+ return spawned;
535
+ }
536
+ function spawnSync(command, args, options) {
537
+ const parsed = parse(command, args, options);
538
+ const result = cp2.spawnSync(parsed.command, parsed.args, parsed.options);
539
+ result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
540
+ return result;
541
+ }
542
+ module.exports = spawn2;
543
+ module.exports.spawn = spawn2;
544
+ module.exports.sync = spawnSync;
545
+ module.exports._parse = parse;
546
+ module.exports._enoent = enoent;
547
+ }
548
+ });
45
549
 
46
550
  // node_modules/ajv/dist/vocabularies/dynamic/dynamicAnchor.js
47
551
  var require_dynamicAnchor = __commonJS({
@@ -872,9 +1376,182 @@ import path4 from "node:path";
872
1376
  import { homedir } from "node:os";
873
1377
  import { readFile as readFile2, rm as rm2 } from "node:fs/promises";
874
1378
 
875
- // packages/installer/src/native.ts
876
- import path3 from "node:path";
877
- import { cp, mkdir, readFile, rename, rm, chmod, realpath as realpath2 } from "node:fs/promises";
1379
+ // node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js
1380
+ var import_cross_spawn = __toESM(require_cross_spawn(), 1);
1381
+ import process2 from "node:process";
1382
+ import { PassThrough } from "node:stream";
1383
+ var DEFAULT_INHERITED_ENV_VARS = process2.platform === "win32" ? [
1384
+ "APPDATA",
1385
+ "HOMEDRIVE",
1386
+ "HOMEPATH",
1387
+ "LOCALAPPDATA",
1388
+ "PATH",
1389
+ "PROCESSOR_ARCHITECTURE",
1390
+ "SYSTEMDRIVE",
1391
+ "SYSTEMROOT",
1392
+ "TEMP",
1393
+ "USERNAME",
1394
+ "USERPROFILE",
1395
+ "PROGRAMFILES"
1396
+ ] : (
1397
+ /* list inspired by the default env inheritance of sudo */
1398
+ ["HOME", "LOGNAME", "PATH", "SHELL", "TERM", "USER"]
1399
+ );
1400
+ function getDefaultEnvironment() {
1401
+ const env = {};
1402
+ for (const key of DEFAULT_INHERITED_ENV_VARS) {
1403
+ const value = process2.env[key];
1404
+ if (value === void 0) {
1405
+ continue;
1406
+ }
1407
+ if (value.startsWith("()")) {
1408
+ continue;
1409
+ }
1410
+ env[key] = value;
1411
+ }
1412
+ return env;
1413
+ }
1414
+ var StdioClientTransport = class {
1415
+ constructor(server) {
1416
+ this._stderrStream = null;
1417
+ this._serverParams = server;
1418
+ this._readBuffer = new ReadBuffer({ maxBufferSize: server.maxBufferSize });
1419
+ if (server.stderr === "pipe" || server.stderr === "overlapped") {
1420
+ this._stderrStream = new PassThrough();
1421
+ }
1422
+ }
1423
+ /**
1424
+ * Starts the server process and prepares to communicate with it.
1425
+ */
1426
+ async start() {
1427
+ if (this._process) {
1428
+ throw new Error("StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.");
1429
+ }
1430
+ return new Promise((resolve, reject) => {
1431
+ this._process = (0, import_cross_spawn.default)(this._serverParams.command, this._serverParams.args ?? [], {
1432
+ // merge default env with server env because mcp server needs some env vars
1433
+ env: {
1434
+ ...getDefaultEnvironment(),
1435
+ ...this._serverParams.env
1436
+ },
1437
+ stdio: ["pipe", "pipe", this._serverParams.stderr ?? "inherit"],
1438
+ shell: false,
1439
+ windowsHide: process2.platform === "win32",
1440
+ cwd: this._serverParams.cwd
1441
+ });
1442
+ this._process.on("error", (error) => {
1443
+ reject(error);
1444
+ this.onerror?.(error);
1445
+ });
1446
+ this._process.on("spawn", () => {
1447
+ resolve();
1448
+ });
1449
+ this._process.on("close", (_code) => {
1450
+ this._process = void 0;
1451
+ this.onclose?.();
1452
+ });
1453
+ this._process.stdin?.on("error", (error) => {
1454
+ this.onerror?.(error);
1455
+ });
1456
+ this._process.stdout?.on("data", (chunk) => {
1457
+ try {
1458
+ this._readBuffer.append(chunk);
1459
+ this.processReadBuffer();
1460
+ } catch (error) {
1461
+ this.onerror?.(error);
1462
+ this.close().catch(() => {
1463
+ });
1464
+ }
1465
+ });
1466
+ this._process.stdout?.on("error", (error) => {
1467
+ this.onerror?.(error);
1468
+ });
1469
+ if (this._stderrStream && this._process.stderr) {
1470
+ this._process.stderr.pipe(this._stderrStream);
1471
+ }
1472
+ });
1473
+ }
1474
+ /**
1475
+ * The stderr stream of the child process, if `StdioServerParameters.stderr` was set to "pipe" or "overlapped".
1476
+ *
1477
+ * If stderr piping was requested, a PassThrough stream is returned _immediately_, allowing callers to
1478
+ * attach listeners before the start method is invoked. This prevents loss of any early
1479
+ * error output emitted by the child process.
1480
+ */
1481
+ get stderr() {
1482
+ if (this._stderrStream) {
1483
+ return this._stderrStream;
1484
+ }
1485
+ return this._process?.stderr ?? null;
1486
+ }
1487
+ /**
1488
+ * The child process pid spawned by this transport.
1489
+ *
1490
+ * This is only available after the transport has been started.
1491
+ */
1492
+ get pid() {
1493
+ return this._process?.pid ?? null;
1494
+ }
1495
+ processReadBuffer() {
1496
+ while (true) {
1497
+ try {
1498
+ const message = this._readBuffer.readMessage();
1499
+ if (message === null) {
1500
+ break;
1501
+ }
1502
+ this.onmessage?.(message);
1503
+ } catch (error) {
1504
+ this.onerror?.(error);
1505
+ }
1506
+ }
1507
+ }
1508
+ async close() {
1509
+ if (this._process) {
1510
+ const processToClose = this._process;
1511
+ this._process = void 0;
1512
+ const closePromise = new Promise((resolve) => {
1513
+ processToClose.once("close", () => {
1514
+ resolve();
1515
+ });
1516
+ });
1517
+ try {
1518
+ processToClose.stdin?.end();
1519
+ } catch {
1520
+ }
1521
+ await Promise.race([closePromise, new Promise((resolve) => setTimeout(resolve, 2e3).unref())]);
1522
+ if (processToClose.exitCode === null) {
1523
+ try {
1524
+ processToClose.kill("SIGTERM");
1525
+ } catch {
1526
+ }
1527
+ await Promise.race([closePromise, new Promise((resolve) => setTimeout(resolve, 2e3).unref())]);
1528
+ }
1529
+ if (processToClose.exitCode === null) {
1530
+ try {
1531
+ processToClose.kill("SIGKILL");
1532
+ } catch {
1533
+ }
1534
+ }
1535
+ }
1536
+ this._readBuffer.clear();
1537
+ }
1538
+ send(message) {
1539
+ return new Promise((resolve) => {
1540
+ if (!this._process?.stdin) {
1541
+ throw new Error("Not connected");
1542
+ }
1543
+ const json = serializeMessage(message);
1544
+ if (this._process.stdin.write(json)) {
1545
+ resolve();
1546
+ } else {
1547
+ this._process.stdin.once("drain", resolve);
1548
+ }
1549
+ });
1550
+ }
1551
+ };
1552
+
1553
+ // packages/installer/src/registration.ts
1554
+ import path2 from "node:path";
878
1555
 
879
1556
  // packages/installer/src/package-source.ts
880
1557
  var import__ = __toESM(require__(), 1);
@@ -952,9 +1629,8 @@ async function validateNative(source) {
952
1629
  }
953
1630
 
954
1631
  // packages/installer/src/registration.ts
955
- import path2 from "node:path";
956
1632
  async function checkCodex(codexHome, codex = "codex") {
957
- const result = await runProcess({
1633
+ const result = await runCommand({
958
1634
  executable: codex,
959
1635
  args: ["--version"],
960
1636
  cwd: process.cwd(),
@@ -969,15 +1645,19 @@ async function checkCodex(codexHome, codex = "codex") {
969
1645
  "dependency_missing"
970
1646
  );
971
1647
  }
1648
+ function codexRun(codexHome, cwd, codex = "codex") {
1649
+ return (args, timeoutMs = 6e4) => runCommand({
1650
+ executable: codex,
1651
+ args,
1652
+ cwd,
1653
+ env: { ...process.env, CODEX_HOME: codexHome },
1654
+ timeoutMs
1655
+ });
1656
+ }
972
1657
  function codexInvoke(codexHome, cwd, codex = "codex") {
1658
+ const run = codexRun(codexHome, cwd, codex);
973
1659
  return async (args) => {
974
- const result = await runProcess({
975
- executable: codex,
976
- args,
977
- cwd,
978
- env: { ...process.env, CODEX_HOME: codexHome },
979
- timeoutMs: 6e4
980
- });
1660
+ const result = await run(args);
981
1661
  if (result.timedOut || result.cancelled || result.truncated || result.code === null)
982
1662
  throw new Fault(
983
1663
  "CODEX_REGISTRATION_UNKNOWN",
@@ -1052,6 +1732,8 @@ async function inspectRegistration(markets, home, codexHome, destination) {
1052
1732
  }
1053
1733
 
1054
1734
  // packages/installer/src/native.ts
1735
+ import path3 from "node:path";
1736
+ import { cp, mkdir, readFile, rm, chmod } from "node:fs/promises";
1055
1737
  async function installNative(r) {
1056
1738
  const source = await resolveNativePlugin(r.source);
1057
1739
  const payload = Object.fromEntries(
@@ -1063,22 +1745,27 @@ async function installNative(r) {
1063
1745
  payload[".agents/plugins/marketplace.json"] = hash(JSON.stringify(nativeMarketplace, null, 2) + "\n");
1064
1746
  const copyDigest = hash(canonical(payload));
1065
1747
  const sourceMcpFile = await exists(path3.join(source, "plugin.json")) ? "mcp.json" : ".mcp.json";
1748
+ const mcpKey = "plugins/apexrest-apex/" + sourceMcpFile;
1749
+ const expectedFiles = canonical({ ...payload, [mcpKey]: void 0 });
1066
1750
  const sourceMcp = await readJson(path3.join(source, sourceMcpFile));
1067
1751
  const sourceServer = sourceMcp.mcpServers.apexrest;
1068
1752
  if (!sourceServer) throw new Fault("INVALID_PACKAGE", "Native package has no apexrest MCP server.", 2);
1069
1753
  sourceServer.command = "node";
1070
1754
  sourceServer.args = ["runtime/mcp.mjs"];
1071
1755
  delete sourceServer.env;
1072
- payload["plugins/apexrest-apex/" + sourceMcpFile] = hash(JSON.stringify(sourceMcp, null, 2) + "\n");
1756
+ payload[mcpKey] = hash(JSON.stringify(sourceMcp, null, 2) + "\n");
1073
1757
  const digest = hash(canonical(payload));
1074
1758
  if (!r.dryRun) {
1075
1759
  await mkdir(r.home, { recursive: true, mode: 448 });
1076
1760
  await mkdir(r.codexHome, { recursive: true, mode: 448 });
1077
1761
  }
1078
- const home = await exists(r.home) ? await realpath2(r.home) : path3.resolve(r.home);
1079
- const codexHome = await exists(r.codexHome) ? await realpath2(r.codexHome) : path3.resolve(r.codexHome);
1762
+ const home = await canonicalHome(r.home);
1763
+ const codexHome = await canonicalHome(r.codexHome);
1080
1764
  const node = r.node ?? process.execPath;
1081
1765
  const destination = path3.join(home, "native", hash(canonical({ sourceDigest: digest, node, home })));
1766
+ const root = path3.join(destination, "plugins/apexrest-apex");
1767
+ const cli = path3.join(root, "runtime/apexrest.mjs");
1768
+ const launchers = launcherScripts(home, node, cli);
1082
1769
  const invoke = codexInvoke(codexHome, await exists(home) ? home : process.cwd(), r.codex);
1083
1770
  if (!await exists(codexHome)) await checkCodex(codexHome, r.codex);
1084
1771
  const inspect = async () => inspectRegistration(
@@ -1087,7 +1774,7 @@ async function installNative(r) {
1087
1774
  codexHome,
1088
1775
  destination
1089
1776
  );
1090
- const registration = await inspect();
1777
+ let registration = await inspect();
1091
1778
  if (r.expectedRegistration && r.expectedRegistration !== registration.fingerprint)
1092
1779
  throw new Fault(
1093
1780
  "MARKETPLACE_CHANGED",
@@ -1112,6 +1799,12 @@ async function installNative(r) {
1112
1799
  const stamp = Date.now();
1113
1800
  const configBackup = path3.join(home, "config-before-install-" + stamp + ".toml");
1114
1801
  if (await exists(config)) await cp(config, configBackup);
1802
+ const repaired = await exists(destination) && !await reusable(destination, expectedFiles, mcpKey);
1803
+ if (repaired) {
1804
+ const broken = `${destination}.broken-${stamp}`;
1805
+ await renameWithRetry(destination, broken);
1806
+ await rm(broken, { recursive: true, force: true });
1807
+ }
1115
1808
  if (!await exists(destination)) {
1116
1809
  const staging = destination + ".staging";
1117
1810
  await rm(staging, { recursive: true, force: true });
@@ -1121,9 +1814,8 @@ async function installNative(r) {
1121
1814
  await writeJson(path3.join(staging, ".agents/plugins/marketplace.json"), nativeMarketplace);
1122
1815
  if (hash(canonical(await inventory(staging))) !== copyDigest)
1123
1816
  throw new Fault("PACKAGE_COPY_INVALID", "Native package copy changed.", 5);
1124
- await rename(staging, destination);
1817
+ await renameWithRetry(staging, destination);
1125
1818
  }
1126
- const root = path3.join(destination, "plugins/apexrest-apex");
1127
1819
  const portable = await exists(path3.join(root, "plugin.json"));
1128
1820
  const mcpPath = path3.join(root, portable ? "mcp.json" : ".mcp.json");
1129
1821
  const mcp = JSON.parse(await readFile(mcpPath, "utf8"));
@@ -1133,6 +1825,7 @@ async function installNative(r) {
1133
1825
  server.args = [path3.join(root, "runtime/mcp.mjs")];
1134
1826
  server.env = { APEXREST_HOME: home };
1135
1827
  await writeJson(mcpPath, mcp);
1828
+ if (repaired && registration.previousRoot === destination) registration = await inspect();
1136
1829
  const current = await inspect();
1137
1830
  if (current.fingerprint !== registration.fingerprint)
1138
1831
  throw new Fault(
@@ -1225,28 +1918,10 @@ async function installNative(r) {
1225
1918
  actions: ["CODEX_RELOAD_REQUIRED", "NATIVE_HOST_VERIFICATION_REQUIRED"]
1226
1919
  };
1227
1920
  await writeJson(path3.join(home, "installation.json"), state);
1228
- const cli = path3.join(root, "runtime/apexrest.mjs");
1229
- const quote = (value) => "'" + value.replaceAll("'", `'"'"'`) + "'";
1230
1921
  await mkdir(path3.join(home, "bin"), { recursive: true });
1231
- if (process.platform === "win32") {
1232
- const ps = (value) => "'" + value.replaceAll("'", "''") + "'";
1233
- await atomicWrite(
1234
- path3.join(home, "bin/apexrest.ps1"),
1235
- `$env:APEXREST_HOME=${ps(home)}
1236
- & ${ps(node)} ${ps(cli)} @args
1237
- exit $LASTEXITCODE
1238
- `
1239
- );
1240
- } else {
1241
- const launcher = path3.join(home, "bin/apexrest");
1242
- await atomicWrite(
1243
- launcher,
1244
- `#!/bin/sh
1245
- export APEXREST_HOME=${quote(home)}
1246
- exec ${quote(node)} ${quote(cli)} "$@"
1247
- `
1248
- );
1249
- await chmod(launcher, 448);
1922
+ for (const [name, contents] of Object.entries(launchers)) {
1923
+ await atomicWrite(path3.join(home, "bin", name), contents);
1924
+ if (name === "apexrest") await chmod(path3.join(home, "bin", name), 448);
1250
1925
  }
1251
1926
  await writeJson(transition, { status: "completed", ...record });
1252
1927
  return state;
@@ -1255,11 +1930,59 @@ exec ${quote(node)} ${quote(cli)} "$@"
1255
1930
  async function installationState(home) {
1256
1931
  return readJson(path3.join(home, "installation.json"));
1257
1932
  }
1933
+ async function reusable(destination, expectedFiles, mcpKey) {
1934
+ try {
1935
+ const files = await inventory(destination);
1936
+ if (!files[mcpKey]) return false;
1937
+ return canonical({ ...files, [mcpKey]: void 0 }) === expectedFiles;
1938
+ } catch {
1939
+ return false;
1940
+ }
1941
+ }
1942
+ var cmdUnsafe = /[%!"\x00-\x1f]/;
1943
+ function launcherScripts(home, node, cli, platform = process.platform) {
1944
+ if (platform !== "win32") {
1945
+ const quote = (value) => "'" + value.replaceAll("'", `'"'"'`) + "'";
1946
+ return {
1947
+ apexrest: `#!/bin/sh
1948
+ export APEXREST_HOME=${quote(home)}
1949
+ exec ${quote(node)} ${quote(cli)} "$@"
1950
+ `
1951
+ };
1952
+ }
1953
+ if ([home, node, cli].some((value) => cmdUnsafe.test(value)))
1954
+ throw new Fault(
1955
+ "UNSAFE_LAUNCHER_PATH",
1956
+ 'The managed home, Node.js or plugin path contains characters a Windows launcher cannot represent safely (% ! " or control characters). Choose another home directory.',
1957
+ 2,
1958
+ "blocked"
1959
+ );
1960
+ const ps = (value) => "'" + value.replaceAll("'", "''") + "'";
1961
+ return {
1962
+ // Restore the caller's APEXREST_HOME: a dot-sourced or in-session call must not leak it.
1963
+ "apexrest.ps1": `$apexrestPreviousHome = $env:APEXREST_HOME
1964
+ $env:APEXREST_HOME = ${ps(home)}
1965
+ try {
1966
+ & ${ps(node)} ${ps(cli)} @args
1967
+ $apexrestExitCode = $LASTEXITCODE
1968
+ } finally {
1969
+ $env:APEXREST_HOME = $apexrestPreviousHome
1970
+ }
1971
+ exit $apexrestExitCode
1972
+ `,
1973
+ "apexrest.cmd": `@echo off\r
1974
+ setlocal\r
1975
+ set "APEXREST_HOME=${home}"\r
1976
+ "${node}" "${cli}" %*\r
1977
+ exit /b %ERRORLEVEL%\r
1978
+ `
1979
+ };
1980
+ }
1258
1981
 
1259
1982
  // packages/installer/src/setup.ts
1260
1983
  async function setup(input) {
1261
1984
  const text = (key) => input[key];
1262
- const home = path4.resolve(
1985
+ const home = await canonicalHome(
1263
1986
  text("home") ?? (input.scope === "project" ? path4.join(text("project") ?? process.cwd(), ".apexrest/managed") : managedHome())
1264
1987
  );
1265
1988
  if (input.scope === "project") {
@@ -1279,9 +2002,10 @@ async function setup(input) {
1279
2002
  "Requested version does not match the supplied immutable package.",
1280
2003
  2
1281
2004
  );
1282
- const codexHome = path4.resolve(
2005
+ const codexHome = await canonicalHome(
1283
2006
  text("codexHome") ?? process.env.CODEX_HOME ?? path4.join(homedir(), ".codex")
1284
2007
  );
2008
+ const codex = text("codex");
1285
2009
  const request = {
1286
2010
  home,
1287
2011
  ...text("cacheDir") ? { cacheDir: text("cacheDir") } : {},
@@ -1298,6 +2022,7 @@ async function setup(input) {
1298
2022
  source,
1299
2023
  home,
1300
2024
  codexHome,
2025
+ ...codex ? { codex } : {},
1301
2026
  dryRun: true,
1302
2027
  node: existingRuntime.node ?? process.execPath
1303
2028
  });
@@ -1321,6 +2046,7 @@ async function setup(input) {
1321
2046
  source,
1322
2047
  home,
1323
2048
  codexHome,
2049
+ ...codex ? { codex } : {},
1324
2050
  node: runtime.node ?? process.execPath,
1325
2051
  expectedRegistration: nativePlan.registration.fingerprint
1326
2052
  });
@@ -1359,63 +2085,57 @@ async function setup(input) {
1359
2085
  await writeJson(path4.join(home, "setup-result.json"), result);
1360
2086
  return result;
1361
2087
  }
1362
- async function uninstallNative(home, keepRuntime) {
1363
- const state = await installationState(home);
1364
- const markets = await runProcess({
1365
- executable: "codex",
1366
- args: ["plugin", "marketplace", "list", "--json"],
1367
- cwd: home,
1368
- env: { ...process.env, CODEX_HOME: state.codexHome },
1369
- timeoutMs: 3e4
1370
- });
1371
- const owned = markets.code === 0 && JSON.parse(markets.stdout).marketplaces.some(
1372
- (m) => m.name === "apexrest" && m.root === state.destination
1373
- );
1374
- if (!owned)
2088
+ var ownedDestination = (home, destination) => {
2089
+ if (typeof destination !== "string" || !path4.isAbsolute(destination) || path4.dirname(destination) !== path4.join(home, "native") || !/^[a-f0-9]{64}$/.test(path4.basename(destination)))
1375
2090
  throw new Fault(
1376
2091
  "MARKETPLACE_OWNERSHIP_CONFLICT",
1377
- "Current marketplace no longer belongs to this installation; nothing was removed.",
1378
- 5
2092
+ "The installation record does not name a managed native payload under this home; nothing was removed.",
2093
+ 5,
2094
+ "conflict"
1379
2095
  );
1380
- const result = await runProcess({
1381
- executable: "codex",
1382
- args: ["plugin", "remove", "apexrest-apex@apexrest"],
1383
- cwd: home,
1384
- env: { ...process.env, CODEX_HOME: state.codexHome },
1385
- timeoutMs: 3e4
1386
- });
1387
- if (result.code !== 0) throw new Fault("UNINSTALL_FAILED", result.stderr, 3);
1388
- const removal = await runProcess({
1389
- executable: "codex",
1390
- args: ["plugin", "marketplace", "remove", "apexrest"],
1391
- cwd: home,
1392
- env: { ...process.env, CODEX_HOME: state.codexHome },
1393
- timeoutMs: 3e4
1394
- });
1395
- if (removal.code !== 0) throw new Fault("MARKETPLACE_REMOVE_FAILED", removal.stderr, 3);
1396
- const listing = await runProcess({
1397
- executable: "codex",
1398
- args: ["plugin", "list", "--json"],
1399
- cwd: home,
1400
- env: { ...process.env, CODEX_HOME: state.codexHome },
1401
- timeoutMs: 3e4
1402
- });
1403
- if (listing.code !== 0 || listing.stdout.includes("apexrest-apex@apexrest"))
1404
- throw new Fault("UNINSTALL_UNCONFIRMED", "Codex still lists this plugin.", 3);
1405
- const destination = await contained(home, state.destination);
1406
- if (!keepRuntime) await rm2(destination, { recursive: true, force: true });
1407
- await writeJson(path4.join(home, "uninstalled.json"), {
1408
- at: (/* @__PURE__ */ new Date()).toISOString(),
1409
- keepRuntime,
1410
- sharedRuntimePreserved: true
2096
+ return destination;
2097
+ };
2098
+ async function uninstallNative(homeInput, keepRuntime, options = {}) {
2099
+ const home = await canonicalHome(homeInput);
2100
+ return withLock(path4.join(home, "install.lock"), async () => {
2101
+ const state = await installationState(home);
2102
+ if (typeof state.codexHome !== "string" || !path4.isAbsolute(state.codexHome))
2103
+ throw new Fault("INSTALLATION_RECORD_INVALID", "The installation record has no Codex profile.", 5);
2104
+ const codexHome = state.codexHome;
2105
+ const destination = ownedDestination(home, state.destination);
2106
+ const run = codexRun(codexHome, home, options.codex);
2107
+ const markets = await listMarketplaces(codexInvoke(codexHome, home, options.codex));
2108
+ if (!markets.some((m) => m.name === "apexrest" && m.root === destination))
2109
+ throw new Fault(
2110
+ "MARKETPLACE_OWNERSHIP_CONFLICT",
2111
+ "Current marketplace no longer belongs to this installation; nothing was removed.",
2112
+ 5
2113
+ );
2114
+ const result = await run(["plugin", "remove", "apexrest-apex@apexrest"], 3e4);
2115
+ if (result.code !== 0) throw new Fault("UNINSTALL_FAILED", result.stderr, 3);
2116
+ const removal = await run(["plugin", "marketplace", "remove", "apexrest"], 3e4);
2117
+ if (removal.code !== 0) throw new Fault("MARKETPLACE_REMOVE_FAILED", removal.stderr, 3);
2118
+ const listing = await run(["plugin", "list", "--json"], 3e4);
2119
+ if (listing.code !== 0 || listing.stdout.includes("apexrest-apex@apexrest"))
2120
+ throw new Fault("UNINSTALL_UNCONFIRMED", "Codex still lists this plugin.", 3);
2121
+ if (!keepRuntime && await exists(destination))
2122
+ await rm2(await containedChild(path4.join(home, "native"), destination), {
2123
+ recursive: true,
2124
+ force: true
2125
+ });
2126
+ await writeJson(path4.join(home, "uninstalled.json"), {
2127
+ at: (/* @__PURE__ */ new Date()).toISOString(),
2128
+ keepRuntime,
2129
+ sharedRuntimePreserved: true
2130
+ });
2131
+ return {
2132
+ status: "uninstalled",
2133
+ projectsPreserved: true,
2134
+ backupsPreserved: true,
2135
+ credentialsPreserved: true,
2136
+ sharedRuntimePreserved: true
2137
+ };
1411
2138
  });
1412
- return {
1413
- status: "uninstalled",
1414
- projectsPreserved: true,
1415
- backupsPreserved: true,
1416
- credentialsPreserved: true,
1417
- sharedRuntimePreserved: true
1418
- };
1419
2139
  }
1420
2140
  export {
1421
2141
  setup,