@orchestraai/agent-tools 0.10.15 → 0.10.17

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 (188) hide show
  1. package/.agents/plugins/marketplace.json +1 -1
  2. package/.claude-plugin/marketplace.json +1 -1
  3. package/.claude-plugin/plugin.json +1 -1
  4. package/.codex-plugin/plugin.json +1 -1
  5. package/.cursor-plugin/plugin.json +1 -1
  6. package/.devin/adapter.json +1 -1
  7. package/.hermes/adapter.json +1 -1
  8. package/.opencode/adapter.json +1 -1
  9. package/README.md +9 -0
  10. package/dist/commands/claude-setup.d.ts +1 -1
  11. package/dist/onboarding/init.js +6 -2
  12. package/dist/onboarding/init.js.map +1 -1
  13. package/dist/runtime/conversation/command-guard.js +1023 -63
  14. package/dist/runtime/conversation/command-guard.js.map +1 -1
  15. package/dist/runtime/conversation/shell-parse.d.ts +42 -0
  16. package/dist/runtime/conversation/shell-parse.js +517 -0
  17. package/dist/runtime/conversation/shell-parse.js.map +1 -0
  18. package/docs/security.md +11 -2
  19. package/install.sh +41 -7
  20. package/node_modules/@hono/node-server/dist/index.cjs +63 -17
  21. package/node_modules/@hono/node-server/dist/index.mjs +63 -17
  22. package/node_modules/@hono/node-server/dist/serve-static.cjs +1 -1
  23. package/node_modules/@hono/node-server/dist/serve-static.mjs +1 -1
  24. package/node_modules/@hono/node-server/package.json +1 -1
  25. package/node_modules/cross-spawn/README.md +19 -3
  26. package/node_modules/cross-spawn/lib/parse.js +38 -10
  27. package/node_modules/cross-spawn/lib/util/escape.js +84 -25
  28. package/node_modules/cross-spawn/lib/util/readShebang.js +8 -2
  29. package/node_modules/cross-spawn/lib/util/resolveCommand.js +8 -1
  30. package/node_modules/cross-spawn/package.json +21 -24
  31. package/node_modules/hono/README.md +2 -3
  32. package/node_modules/hono/dist/adapter/aws-lambda/handler.js +2 -2
  33. package/node_modules/hono/dist/adapter/bun/websocket.js +19 -4
  34. package/node_modules/hono/dist/adapter/lambda-edge/handler.js +5 -1
  35. package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +2 -2
  36. package/node_modules/hono/dist/cjs/adapter/bun/websocket.js +19 -4
  37. package/node_modules/hono/dist/cjs/adapter/lambda-edge/handler.js +5 -1
  38. package/node_modules/hono/dist/cjs/client/fetch-result-please.js +1 -1
  39. package/node_modules/hono/dist/cjs/client/utils.js +9 -5
  40. package/node_modules/hono/dist/cjs/context.js +1 -1
  41. package/node_modules/hono/dist/cjs/helper/accepts/accepts.js +7 -1
  42. package/node_modules/hono/dist/cjs/helper/css/common.js +11 -8
  43. package/node_modules/hono/dist/cjs/helper/css/index.js +1 -1
  44. package/node_modules/hono/dist/cjs/helper/proxy/index.js +2 -0
  45. package/node_modules/hono/dist/cjs/helper/route/index.js +3 -1
  46. package/node_modules/hono/dist/cjs/helper/ssg/ssg.js +5 -3
  47. package/node_modules/hono/dist/cjs/helper/streaming/sse.js +6 -2
  48. package/node_modules/hono/dist/cjs/hono-base.js +9 -10
  49. package/node_modules/hono/dist/cjs/hono.js +0 -1
  50. package/node_modules/hono/dist/cjs/jsx/base.js +51 -32
  51. package/node_modules/hono/dist/cjs/jsx/components.js +2 -2
  52. package/node_modules/hono/dist/cjs/jsx/constants.js +2 -0
  53. package/node_modules/hono/dist/cjs/jsx/context.js +15 -2
  54. package/node_modules/hono/dist/cjs/jsx/dom/components.js +1 -1
  55. package/node_modules/hono/dist/cjs/jsx/dom/hooks/index.js +38 -8
  56. package/node_modules/hono/dist/cjs/jsx/dom/intrinsic-element/components.js +8 -5
  57. package/node_modules/hono/dist/cjs/jsx/dom/render.js +9 -3
  58. package/node_modules/hono/dist/cjs/jsx/jsx-runtime.js +13 -17
  59. package/node_modules/hono/dist/cjs/middleware/basic-auth/index.js +3 -1
  60. package/node_modules/hono/dist/cjs/middleware/bearer-auth/index.js +9 -1
  61. package/node_modules/hono/dist/cjs/middleware/body-limit/index.js +9 -10
  62. package/node_modules/hono/dist/cjs/middleware/combine/index.js +4 -0
  63. package/node_modules/hono/dist/cjs/middleware/compress/index.js +2 -3
  64. package/node_modules/hono/dist/cjs/middleware/csrf/index.js +2 -2
  65. package/node_modules/hono/dist/cjs/middleware/etag/index.js +3 -1
  66. package/node_modules/hono/dist/cjs/middleware/jwk/jwk.js +2 -2
  67. package/node_modules/hono/dist/cjs/middleware/jwt/jwt.js +2 -2
  68. package/node_modules/hono/dist/cjs/middleware/method-not-allowed/index.js +1 -1
  69. package/node_modules/hono/dist/cjs/middleware/method-override/index.js +35 -12
  70. package/node_modules/hono/dist/cjs/middleware/mount/index.js +5 -4
  71. package/node_modules/hono/dist/cjs/middleware/pretty-json/index.js +1 -0
  72. package/node_modules/hono/dist/cjs/middleware/request-id/request-id.js +3 -3
  73. package/node_modules/hono/dist/cjs/middleware/secure-headers/secure-headers.js +6 -3
  74. package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +4 -2
  75. package/node_modules/hono/dist/cjs/middleware/timing/timing.js +4 -3
  76. package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +13 -11
  77. package/node_modules/hono/dist/cjs/router/reg-exp-router/prepared-router.js +4 -4
  78. package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +39 -51
  79. package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +15 -5
  80. package/node_modules/hono/dist/cjs/router/trie-router/node.js +6 -4
  81. package/node_modules/hono/dist/cjs/utils/body.js +2 -1
  82. package/node_modules/hono/dist/cjs/utils/cookie.js +3 -3
  83. package/node_modules/hono/dist/cjs/utils/html.js +5 -0
  84. package/node_modules/hono/dist/cjs/utils/jwt/jwt.js +8 -5
  85. package/node_modules/hono/dist/cjs/utils/mime.js +3 -2
  86. package/node_modules/hono/dist/cjs/utils/mount.js +59 -0
  87. package/node_modules/hono/dist/cjs/utils/url.js +23 -11
  88. package/node_modules/hono/dist/cjs/validator/validator.js +5 -5
  89. package/node_modules/hono/dist/client/fetch-result-please.js +1 -1
  90. package/node_modules/hono/dist/client/utils.js +9 -5
  91. package/node_modules/hono/dist/context.js +1 -1
  92. package/node_modules/hono/dist/helper/accepts/accepts.js +7 -1
  93. package/node_modules/hono/dist/helper/css/common.js +11 -8
  94. package/node_modules/hono/dist/helper/css/index.js +1 -1
  95. package/node_modules/hono/dist/helper/proxy/index.js +2 -0
  96. package/node_modules/hono/dist/helper/route/index.js +3 -1
  97. package/node_modules/hono/dist/helper/ssg/ssg.js +5 -3
  98. package/node_modules/hono/dist/helper/streaming/sse.js +6 -2
  99. package/node_modules/hono/dist/hono-base.js +9 -10
  100. package/node_modules/hono/dist/hono.js +0 -1
  101. package/node_modules/hono/dist/jsx/base.js +51 -34
  102. package/node_modules/hono/dist/jsx/components.js +2 -2
  103. package/node_modules/hono/dist/jsx/constants.js +2 -1
  104. package/node_modules/hono/dist/jsx/context.js +15 -2
  105. package/node_modules/hono/dist/jsx/dom/components.js +2 -2
  106. package/node_modules/hono/dist/jsx/dom/hooks/index.js +39 -9
  107. package/node_modules/hono/dist/jsx/dom/intrinsic-element/components.js +8 -5
  108. package/node_modules/hono/dist/jsx/dom/render.js +9 -3
  109. package/node_modules/hono/dist/jsx/jsx-runtime.js +15 -19
  110. package/node_modules/hono/dist/middleware/basic-auth/index.js +3 -1
  111. package/node_modules/hono/dist/middleware/bearer-auth/index.js +9 -1
  112. package/node_modules/hono/dist/middleware/body-limit/index.js +9 -10
  113. package/node_modules/hono/dist/middleware/combine/index.js +4 -0
  114. package/node_modules/hono/dist/middleware/compress/index.js +2 -3
  115. package/node_modules/hono/dist/middleware/csrf/index.js +2 -2
  116. package/node_modules/hono/dist/middleware/etag/index.js +3 -1
  117. package/node_modules/hono/dist/middleware/jwk/jwk.js +2 -2
  118. package/node_modules/hono/dist/middleware/jwt/jwt.js +2 -2
  119. package/node_modules/hono/dist/middleware/method-not-allowed/index.js +1 -1
  120. package/node_modules/hono/dist/middleware/method-override/index.js +35 -12
  121. package/node_modules/hono/dist/middleware/mount/index.js +5 -4
  122. package/node_modules/hono/dist/middleware/pretty-json/index.js +1 -0
  123. package/node_modules/hono/dist/middleware/request-id/request-id.js +3 -3
  124. package/node_modules/hono/dist/middleware/secure-headers/secure-headers.js +6 -3
  125. package/node_modules/hono/dist/middleware/serve-static/index.js +4 -2
  126. package/node_modules/hono/dist/middleware/timing/timing.js +4 -3
  127. package/node_modules/hono/dist/router/reg-exp-router/node.js +13 -11
  128. package/node_modules/hono/dist/router/reg-exp-router/prepared-router.js +5 -5
  129. package/node_modules/hono/dist/router/reg-exp-router/router.js +40 -52
  130. package/node_modules/hono/dist/router/reg-exp-router/trie.js +15 -5
  131. package/node_modules/hono/dist/router/trie-router/node.js +6 -4
  132. package/node_modules/hono/dist/types/adapter/aws-lambda/conninfo.d.ts +1 -1
  133. package/node_modules/hono/dist/types/adapter/bun/conninfo.d.ts +1 -1
  134. package/node_modules/hono/dist/types/adapter/bun/ssg.d.ts +1 -1
  135. package/node_modules/hono/dist/types/adapter/cloudflare-pages/conninfo.d.ts +1 -1
  136. package/node_modules/hono/dist/types/adapter/cloudflare-workers/conninfo.d.ts +1 -1
  137. package/node_modules/hono/dist/types/adapter/deno/conninfo.d.ts +1 -1
  138. package/node_modules/hono/dist/types/adapter/deno/ssg.d.ts +1 -1
  139. package/node_modules/hono/dist/types/adapter/lambda-edge/conninfo.d.ts +1 -1
  140. package/node_modules/hono/dist/types/adapter/netlify/conninfo.d.ts +1 -1
  141. package/node_modules/hono/dist/types/adapter/vercel/conninfo.d.ts +1 -1
  142. package/node_modules/hono/dist/types/helper/accepts/accepts.d.ts +5 -0
  143. package/node_modules/hono/dist/types/helper/factory/index.d.ts +1 -1
  144. package/node_modules/hono/dist/types/helper/ssg/ssg.d.ts +6 -1
  145. package/node_modules/hono/dist/types/helper/streaming/sse.d.ts +1 -1
  146. package/node_modules/hono/dist/types/helper/streaming/stream.d.ts +1 -1
  147. package/node_modules/hono/dist/types/helper/streaming/text.d.ts +1 -1
  148. package/node_modules/hono/dist/types/helper/testing/index.d.ts +2 -1
  149. package/node_modules/hono/dist/types/helper/websocket/index.d.ts +13 -3
  150. package/node_modules/hono/dist/types/hono-base.d.ts +23 -9
  151. package/node_modules/hono/dist/types/index.d.ts +1 -1
  152. package/node_modules/hono/dist/types/jsx/base.d.ts +6 -3
  153. package/node_modules/hono/dist/types/jsx/components.d.ts +2 -2
  154. package/node_modules/hono/dist/types/jsx/constants.d.ts +1 -0
  155. package/node_modules/hono/dist/types/jsx/context.d.ts +2 -2
  156. package/node_modules/hono/dist/types/jsx/dom/components.d.ts +2 -2
  157. package/node_modules/hono/dist/types/jsx/dom/css.d.ts +2 -2
  158. package/node_modules/hono/dist/types/jsx/dom/hooks/index.d.ts +5 -3
  159. package/node_modules/hono/dist/types/jsx/dom/index.d.ts +1 -1
  160. package/node_modules/hono/dist/types/jsx/dom/server.d.ts +1 -1
  161. package/node_modules/hono/dist/types/jsx/index.d.ts +1 -1
  162. package/node_modules/hono/dist/types/jsx/jsx-runtime.d.ts +2 -1
  163. package/node_modules/hono/dist/types/jsx/streaming.d.ts +4 -3
  164. package/node_modules/hono/dist/types/middleware/basic-auth/index.d.ts +1 -0
  165. package/node_modules/hono/dist/types/middleware/bearer-auth/index.d.ts +2 -1
  166. package/node_modules/hono/dist/types/middleware/ip-restriction/index.d.ts +3 -3
  167. package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +3 -3
  168. package/node_modules/hono/dist/types/middleware/mount/index.d.ts +2 -0
  169. package/node_modules/hono/dist/types/middleware/request-id/request-id.d.ts +3 -3
  170. package/node_modules/hono/dist/types/middleware/secure-headers/secure-headers.d.ts +2 -0
  171. package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +3 -3
  172. package/node_modules/hono/dist/types/router/reg-exp-router/trie.d.ts +1 -1
  173. package/node_modules/hono/dist/types/utils/cookie.d.ts +1 -1
  174. package/node_modules/hono/dist/types/utils/ipaddr.d.ts +1 -1
  175. package/node_modules/hono/dist/types/utils/jwt/jwt.d.ts +4 -2
  176. package/node_modules/hono/dist/types/utils/mount.d.ts +4 -0
  177. package/node_modules/hono/dist/types/utils/types.d.ts +12 -2
  178. package/node_modules/hono/dist/utils/body.js +2 -1
  179. package/node_modules/hono/dist/utils/cookie.js +3 -3
  180. package/node_modules/hono/dist/utils/html.js +5 -0
  181. package/node_modules/hono/dist/utils/jwt/jwt.js +8 -5
  182. package/node_modules/hono/dist/utils/mime.js +3 -2
  183. package/node_modules/hono/dist/utils/mount.js +58 -0
  184. package/node_modules/hono/dist/utils/url.js +23 -11
  185. package/node_modules/hono/dist/validator/validator.js +5 -5
  186. package/node_modules/hono/package.json +1 -1
  187. package/package.json +1 -1
  188. package/skills/install-agent-adapter/reference.md +8 -0
@@ -0,0 +1,517 @@
1
+ // A small POSIX/bash-style shell parser used by the command guard.
2
+ //
3
+ // It does not evaluate anything. It splits a command line into pipelines and
4
+ // simple commands, removes quoting the way the shell would, separates
5
+ // redirects from arguments, reads heredocs, and parses command and process
6
+ // substitutions into nested scripts so that every command the shell would
7
+ // run can be checked.
8
+ export class ShellParseError extends Error {
9
+ }
10
+ export const MAX_SHELL_NESTING = 12;
11
+ const WORD_BREAK = new Set([" ", "\t", "\n", ";", "&", "|", "<", ">", "(", ")"]);
12
+ const REDIRECT_OPS = ["<<<", "<<-", "&>>", "<<", "<>", "<&", ">>", ">|", ">&", "&>", "<", ">"];
13
+ /** Words that can come before `case` at the start of a command. */
14
+ const CASE_PREFIX_WORDS = new Set(["!", "{", "then", "do", "else", "elif", "if", "while", "until", "time", "-p"]);
15
+ const MAX_BRACE_WORDS = 64;
16
+ /** Expands comma brace groups (`a{b,c}d`, several groups) the way bash does, dropping empty results. */
17
+ function expandBraces(value) {
18
+ let words = [value];
19
+ for (let round = 0; round < 8; round += 1) {
20
+ const next = [];
21
+ let changed = false;
22
+ for (const word of words) {
23
+ const group = /\{([^{}]*,[^{}]*)\}/.exec(word);
24
+ if (!group) {
25
+ next.push(word);
26
+ continue;
27
+ }
28
+ changed = true;
29
+ const before = word.slice(0, group.index);
30
+ const after = word.slice(group.index + group[0].length);
31
+ for (const item of group[1].split(","))
32
+ next.push(`${before}${item}${after}`);
33
+ }
34
+ words = next.slice(0, MAX_BRACE_WORDS);
35
+ if (!changed)
36
+ break;
37
+ }
38
+ return words.filter((word) => word !== "");
39
+ }
40
+ class Parser {
41
+ src;
42
+ base;
43
+ depth;
44
+ pos = 0;
45
+ parenDepth = 0;
46
+ /** Paren depth at each open `case`, so `pattern)` is not read as a closing paren. */
47
+ caseStack = [];
48
+ pendingHeredocs = [];
49
+ pipelines = [];
50
+ comments = [];
51
+ commands = [];
52
+ words = [];
53
+ redirects = [];
54
+ constructor(src, base, depth) {
55
+ this.src = src;
56
+ this.base = base;
57
+ this.depth = depth;
58
+ if (depth > MAX_SHELL_NESTING)
59
+ throw new ShellParseError("nesting too deep");
60
+ }
61
+ /** Parse until end of input, or until an unmatched `)` when `untilParen` is set. Returns the script and the index after it. */
62
+ parse(untilParen) {
63
+ const src = this.src;
64
+ while (this.pos < src.length) {
65
+ const c = src[this.pos];
66
+ // Only space and tab are blanks; bash reads a carriage return as an ordinary character.
67
+ if (c === " " || c === "\t") {
68
+ this.pos += 1;
69
+ }
70
+ else if (this.startsWith("\\\n") || this.startsWith("\\\r\n")) {
71
+ // Line continuation.
72
+ this.pos += src[this.pos + 1] === "\r" ? 3 : 2;
73
+ }
74
+ else if (c === "\n") {
75
+ this.endPipeline();
76
+ this.pos += 1;
77
+ this.readHeredocBodies();
78
+ }
79
+ else if (c === "#") {
80
+ const start = this.pos;
81
+ while (this.pos < src.length && src[this.pos] !== "\n")
82
+ this.pos += 1;
83
+ this.comments.push([this.base + start, this.base + this.pos]);
84
+ }
85
+ else if (c === ")") {
86
+ this.pos += 1;
87
+ if (this.caseStack.length && this.caseStack[this.caseStack.length - 1] === this.parenDepth) {
88
+ // End of a case pattern such as `a)` or `a|b)`.
89
+ this.endCommand();
90
+ for (const patternCommand of this.commands)
91
+ patternCommand.casePattern = true;
92
+ this.endPipeline();
93
+ continue;
94
+ }
95
+ if (this.parenDepth === 0 && untilParen) {
96
+ this.endPipeline();
97
+ return { script: this.finish(), end: this.pos };
98
+ }
99
+ if (this.parenDepth > 0)
100
+ this.parenDepth -= 1;
101
+ this.endPipeline();
102
+ }
103
+ else if (c === "(") {
104
+ this.pos += 1;
105
+ this.parenDepth += 1;
106
+ this.endPipeline();
107
+ }
108
+ else if (this.tryRedirect()) {
109
+ // handled
110
+ }
111
+ else if (this.startsWith("<(") || this.startsWith(">(")) {
112
+ this.words.push(this.readWord());
113
+ }
114
+ else if (this.startsWith("||") || this.startsWith("&&") || this.startsWith(";;") || this.startsWith(";&")) {
115
+ this.pos += 2;
116
+ this.endPipeline();
117
+ }
118
+ else if (this.startsWith("|&") || c === "|") {
119
+ this.pos += c === "|" && src[this.pos + 1] === "&" ? 2 : 1;
120
+ this.endCommand();
121
+ }
122
+ else if (c === ";" || c === "&") {
123
+ this.pos += 1;
124
+ this.endPipeline();
125
+ }
126
+ else {
127
+ const word = this.readWord();
128
+ this.words.push(word);
129
+ const leading = this.words.slice(0, -1);
130
+ if (this.redirects.length === 0 && leading.every((w) => CASE_PREFIX_WORDS.has(w.raw)))
131
+ this.trackCase(word);
132
+ }
133
+ }
134
+ if (untilParen)
135
+ throw new ShellParseError("unterminated substitution");
136
+ if (this.pendingHeredocs.length)
137
+ this.readHeredocBodies();
138
+ this.endPipeline();
139
+ return { script: this.finish(), end: this.pos };
140
+ }
141
+ trackCase(word) {
142
+ const raw = word.raw;
143
+ if (raw === "case")
144
+ this.caseStack.push(this.parenDepth);
145
+ else if (raw === "esac" && this.caseStack.length)
146
+ this.caseStack.pop();
147
+ }
148
+ finish() {
149
+ return { pipelines: this.pipelines, comments: this.comments };
150
+ }
151
+ startsWith(token) {
152
+ return this.src.startsWith(token, this.pos);
153
+ }
154
+ endCommand() {
155
+ if (this.words.length || this.redirects.length) {
156
+ this.commands.push({ words: this.words, redirects: this.redirects });
157
+ }
158
+ this.words = [];
159
+ this.redirects = [];
160
+ }
161
+ endPipeline() {
162
+ this.endCommand();
163
+ if (this.commands.length)
164
+ this.pipelines.push({ commands: this.commands });
165
+ this.commands = [];
166
+ }
167
+ tryRedirect() {
168
+ const src = this.src;
169
+ let cursor = this.pos;
170
+ while (cursor < src.length && /[0-9]/.test(src[cursor]))
171
+ cursor += 1;
172
+ if (src.startsWith("<(", cursor) || src.startsWith(">(", cursor))
173
+ return false;
174
+ const op = REDIRECT_OPS.find((candidate) => src.startsWith(candidate, cursor));
175
+ if (!op)
176
+ return false;
177
+ this.pos = cursor + op.length;
178
+ this.skipBlanks();
179
+ const redirect = { op };
180
+ if (op === "<<" || op === "<<-") {
181
+ const delimiterWord = this.readWord();
182
+ const raw = src.slice(delimiterWord.start - this.base, delimiterWord.end - this.base);
183
+ this.pendingHeredocs.push({
184
+ delimiter: delimiterWord.value,
185
+ stripTabs: op === "<<-",
186
+ quoted: /['"\\]/.test(raw),
187
+ redirect,
188
+ });
189
+ }
190
+ else {
191
+ const procSub = this.startsWith("<(") || this.startsWith(">(");
192
+ if (this.pos >= src.length || (WORD_BREAK.has(src[this.pos]) && !procSub)) {
193
+ throw new ShellParseError("redirect without target");
194
+ }
195
+ redirect.target = this.readWord();
196
+ }
197
+ this.redirects.push(redirect);
198
+ return true;
199
+ }
200
+ skipBlanks() {
201
+ while (this.pos < this.src.length && (this.src[this.pos] === " " || this.src[this.pos] === "\t")) {
202
+ this.pos += 1;
203
+ }
204
+ }
205
+ readHeredocBodies() {
206
+ const src = this.src;
207
+ for (const pending of this.pendingHeredocs) {
208
+ const start = this.pos;
209
+ let end = src.length;
210
+ let next = src.length;
211
+ while (this.pos < src.length) {
212
+ const lineEnd = src.indexOf("\n", this.pos);
213
+ const stop = lineEnd === -1 ? src.length : lineEnd;
214
+ let line = src.slice(this.pos, stop);
215
+ if (pending.stripTabs)
216
+ line = line.replace(/^\t+/, "");
217
+ if (line === pending.delimiter) {
218
+ end = this.pos;
219
+ next = lineEnd === -1 ? src.length : lineEnd + 1;
220
+ break;
221
+ }
222
+ this.pos = lineEnd === -1 ? src.length : lineEnd + 1;
223
+ }
224
+ if (next === src.length && end === src.length)
225
+ end = src.length;
226
+ const body = src.slice(start, end);
227
+ pending.redirect.heredoc = {
228
+ body,
229
+ start: this.base + start,
230
+ end: this.base + end,
231
+ quoted: pending.quoted,
232
+ substitutions: pending.quoted ? [] : expansionsIn(body, this.base + start, this.depth),
233
+ };
234
+ this.pos = next;
235
+ }
236
+ this.pendingHeredocs = [];
237
+ }
238
+ readWord() {
239
+ const src = this.src;
240
+ const start = this.pos;
241
+ let value = "";
242
+ let plain = true;
243
+ const substitutions = [];
244
+ while (this.pos < src.length) {
245
+ const c = src[this.pos];
246
+ if (c !== "\\" && c !== "'" && c !== "\"" && c !== "$" && c !== "`" && !WORD_BREAK.has(c)) {
247
+ value += c;
248
+ this.pos += 1;
249
+ continue;
250
+ }
251
+ if (!WORD_BREAK.has(c))
252
+ plain = false;
253
+ if ((c === "<" || c === ">") && src[this.pos + 1] === "(") {
254
+ plain = false;
255
+ const inner = this.readNested(this.pos + 2);
256
+ substitutions.push(inner.script);
257
+ value += src.slice(this.pos, inner.end);
258
+ this.pos = inner.end;
259
+ continue;
260
+ }
261
+ if (WORD_BREAK.has(c))
262
+ break;
263
+ if (c === "\\") {
264
+ const next = src[this.pos + 1];
265
+ if (next === "\n") {
266
+ this.pos += 2;
267
+ continue;
268
+ }
269
+ if (next === "\r" && src[this.pos + 2] === "\n") {
270
+ this.pos += 3;
271
+ continue;
272
+ }
273
+ if (next !== undefined)
274
+ value += next;
275
+ this.pos += 2;
276
+ }
277
+ else if (c === "'") {
278
+ const close = src.indexOf("'", this.pos + 1);
279
+ if (close === -1)
280
+ throw new ShellParseError("unterminated single quote");
281
+ value += src.slice(this.pos + 1, close);
282
+ this.pos = close + 1;
283
+ }
284
+ else if (c === "$" && src[this.pos + 1] === "'") {
285
+ value += this.readAnsiC();
286
+ }
287
+ else if (c === "\"" || (c === "$" && src[this.pos + 1] === "\"")) {
288
+ this.pos += c === "$" ? 2 : 1;
289
+ value += this.readDoubleQuoted(substitutions);
290
+ }
291
+ else if (c === "$" || c === "`") {
292
+ value += this.readExpansion(substitutions);
293
+ }
294
+ else {
295
+ value += c;
296
+ this.pos += 1;
297
+ }
298
+ }
299
+ const word = {
300
+ value,
301
+ raw: src.slice(start, this.pos),
302
+ start: this.base + start,
303
+ end: this.base + this.pos,
304
+ substitutions,
305
+ };
306
+ if (plain && /\{[^{}]*,[^{}]*\}/.test(value))
307
+ word.braceExpansion = expandBraces(value);
308
+ return word;
309
+ }
310
+ readAnsiC() {
311
+ const src = this.src;
312
+ this.pos += 2;
313
+ let out = "";
314
+ while (this.pos < src.length && src[this.pos] !== "'") {
315
+ const c = src[this.pos];
316
+ if (c !== "\\") {
317
+ out += c;
318
+ this.pos += 1;
319
+ continue;
320
+ }
321
+ const next = src[this.pos + 1] ?? "";
322
+ const simple = {
323
+ n: "\n", t: "\t", r: "\r", a: "\x07", b: "\b", e: "\x1b", E: "\x1b", f: "\f", v: "\v",
324
+ "\\": "\\", "'": "'", "\"": "\"", "?": "?",
325
+ };
326
+ if (next in simple) {
327
+ out += simple[next];
328
+ this.pos += 2;
329
+ }
330
+ else if (next === "x") {
331
+ const hex = /^[0-9a-fA-F]{1,2}/.exec(src.slice(this.pos + 2))?.[0] ?? "";
332
+ out += hex ? String.fromCharCode(parseInt(hex, 16)) : "\\x";
333
+ this.pos += 2 + hex.length;
334
+ }
335
+ else if (next === "u" || next === "U") {
336
+ const hex = new RegExp(`^[0-9a-fA-F]{1,${next === "u" ? 4 : 8}}`).exec(src.slice(this.pos + 2))?.[0] ?? "";
337
+ const codePoint = hex ? parseInt(hex, 16) : -1;
338
+ out += codePoint >= 0 && codePoint <= 0x10ffff ? String.fromCodePoint(codePoint) : `\\${next}${hex}`;
339
+ this.pos += 2 + hex.length;
340
+ }
341
+ else if (/[0-7]/.test(next)) {
342
+ const oct = /^[0-7]{1,3}/.exec(src.slice(this.pos + 1))?.[0] ?? "";
343
+ out += String.fromCharCode(parseInt(oct, 8));
344
+ this.pos += 1 + oct.length;
345
+ }
346
+ else {
347
+ out += `\\${next}`;
348
+ this.pos += 2;
349
+ }
350
+ }
351
+ if (this.pos >= src.length)
352
+ throw new ShellParseError("unterminated quote");
353
+ this.pos += 1;
354
+ return out;
355
+ }
356
+ readDoubleQuoted(substitutions) {
357
+ const src = this.src;
358
+ let out = "";
359
+ while (this.pos < src.length && src[this.pos] !== "\"") {
360
+ const c = src[this.pos];
361
+ if (c === "\\") {
362
+ const next = src[this.pos + 1];
363
+ if (next !== undefined && "$`\"\\\n".includes(next)) {
364
+ out += next === "\n" ? "" : next;
365
+ }
366
+ else {
367
+ out += `\\${next ?? ""}`;
368
+ }
369
+ this.pos += 2;
370
+ }
371
+ else if (c === "$" || c === "`") {
372
+ out += this.readExpansion(substitutions);
373
+ }
374
+ else {
375
+ out += c;
376
+ this.pos += 1;
377
+ }
378
+ }
379
+ if (this.pos >= src.length)
380
+ throw new ShellParseError("unterminated double quote");
381
+ this.pos += 1;
382
+ return out;
383
+ }
384
+ /** Reads $..., ${...}, $(...), $((...)) or `...` starting at this.pos; returns its source text. */
385
+ readExpansion(substitutions) {
386
+ const src = this.src;
387
+ const start = this.pos;
388
+ if (src[this.pos] === "`") {
389
+ let raw = "";
390
+ let cursor = this.pos + 1;
391
+ while (cursor < src.length && src[cursor] !== "`") {
392
+ if (src[cursor] === "\\" && cursor + 1 < src.length && "$`\\".includes(src[cursor + 1])) {
393
+ raw += src[cursor + 1];
394
+ cursor += 2;
395
+ }
396
+ else {
397
+ raw += src[cursor];
398
+ cursor += 1;
399
+ }
400
+ }
401
+ if (cursor >= src.length)
402
+ throw new ShellParseError("unterminated backquote");
403
+ substitutions.push(parseShell(raw, this.base + this.pos + 1, this.depth + 1));
404
+ this.pos = cursor + 1;
405
+ return src.slice(start, this.pos);
406
+ }
407
+ if (src.startsWith("$((", this.pos) && this.isArithmetic()) {
408
+ let depth = 0;
409
+ let cursor = this.pos + 1;
410
+ for (; cursor < src.length; cursor += 1) {
411
+ if (src[cursor] === "(")
412
+ depth += 1;
413
+ else if (src[cursor] === ")") {
414
+ depth -= 1;
415
+ if (depth === 0)
416
+ break;
417
+ }
418
+ }
419
+ // Arithmetic can itself contain command substitutions.
420
+ substitutions.push(...expansionsIn(src.slice(this.pos + 3, cursor - 1), this.base + this.pos + 3, this.depth));
421
+ this.pos = cursor + 1;
422
+ return src.slice(start, this.pos);
423
+ }
424
+ if (src.startsWith("$(", this.pos)) {
425
+ const inner = this.readNested(this.pos + 2);
426
+ substitutions.push(inner.script);
427
+ this.pos = inner.end;
428
+ return src.slice(start, this.pos);
429
+ }
430
+ if (src.startsWith("${", this.pos)) {
431
+ this.pos += 2;
432
+ let depth = 1;
433
+ while (this.pos < src.length && depth > 0) {
434
+ const c = src[this.pos];
435
+ if (c === "}") {
436
+ depth -= 1;
437
+ this.pos += 1;
438
+ }
439
+ else if (c === "$" && src[this.pos + 1] === "{") {
440
+ depth += 1;
441
+ this.pos += 2;
442
+ }
443
+ else if (c === "$" || c === "`") {
444
+ this.readExpansion(substitutions);
445
+ }
446
+ else if (c === "'") {
447
+ const close = src.indexOf("'", this.pos + 1);
448
+ if (close === -1)
449
+ throw new ShellParseError("unterminated single quote");
450
+ this.pos = close + 1;
451
+ }
452
+ else if (c === "\"") {
453
+ this.pos += 1;
454
+ this.readDoubleQuoted(substitutions);
455
+ }
456
+ else if (c === "\\") {
457
+ this.pos += 2;
458
+ }
459
+ else {
460
+ this.pos += 1;
461
+ }
462
+ }
463
+ if (depth > 0)
464
+ throw new ShellParseError("unterminated parameter expansion");
465
+ return src.slice(start, this.pos);
466
+ }
467
+ this.pos += 1;
468
+ return "$";
469
+ }
470
+ /**
471
+ * `$((` starts arithmetic only when the matching close is `))`. Otherwise
472
+ * it is a command substitution whose first command is a subshell.
473
+ */
474
+ isArithmetic() {
475
+ const src = this.src;
476
+ let depth = 0;
477
+ for (let cursor = this.pos + 1; cursor < src.length; cursor += 1) {
478
+ if (src[cursor] === "(")
479
+ depth += 1;
480
+ else if (src[cursor] === ")") {
481
+ depth -= 1;
482
+ // The first time the depth falls back to 1 must be the first half of `))`.
483
+ if (depth === 1)
484
+ return src[cursor + 1] === ")";
485
+ }
486
+ }
487
+ return false;
488
+ }
489
+ /** Scans the whole input as double-quote-like text and returns its substitutions. */
490
+ collectExpansions() {
491
+ const found = [];
492
+ while (this.pos < this.src.length) {
493
+ const c = this.src[this.pos];
494
+ if (c === "\\")
495
+ this.pos += 2;
496
+ else if (c === "$" || c === "`")
497
+ this.readExpansion(found);
498
+ else
499
+ this.pos += 1;
500
+ }
501
+ return found;
502
+ }
503
+ readNested(innerStart) {
504
+ const nested = new Parser(this.src, this.base, this.depth + 1);
505
+ nested.pos = innerStart;
506
+ return nested.parse(true);
507
+ }
508
+ }
509
+ /** Finds command substitutions in text that the shell expands like a double-quoted string (unquoted heredocs, arithmetic). */
510
+ function expansionsIn(text, base, depth) {
511
+ return new Parser(text, base, depth).collectExpansions();
512
+ }
513
+ /** Parses a shell command line. `offset` is added to every recorded position. */
514
+ export function parseShell(source, offset = 0, depth = 0) {
515
+ return new Parser(source, offset, depth).parse(false).script;
516
+ }
517
+ //# sourceMappingURL=shell-parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell-parse.js","sourceRoot":"","sources":["../../../src/runtime/conversation/shell-parse.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,EAAE;AACF,6EAA6E;AAC7E,sEAAsE;AACtE,2EAA2E;AAC3E,0EAA0E;AAC1E,sBAAsB;AAwCtB,MAAM,OAAO,eAAgB,SAAQ,KAAK;CAAG;AAE7C,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAEpC,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,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AC;YAClC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC7B,IAAI,CAAC,KAAK,IAAI;gBAAE,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;iBACzB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG;gBAAE,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;;gBACtD,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QACrB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,UAAU,CAAC,UAAkB;QACnC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAC/D,MAAM,CAAC,GAAG,GAAG,UAAU,CAAC;QACxB,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;CACF;AAED,8HAA8H;AAC9H,SAAS,YAAY,CAAC,IAAY,EAAE,IAAY,EAAE,KAAa;IAC7D,OAAO,IAAI,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,iBAAiB,EAAE,CAAC;AAC3D,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,MAAM,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC;IAC9D,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;AAC/D,CAAC"}
package/docs/security.md CHANGED
@@ -83,8 +83,17 @@ aliases), the runtime applies a small app-owned command guard:
83
83
  allowed.
84
84
 
85
85
  The guard covers high-confidence destructive filesystem, disk, process, Git,
86
- database, infrastructure, cloud-delete, and remote-script-pipe patterns. It is
87
- not a shell parser or a sandbox. Before arbitrary shell access becomes a public
86
+ database, infrastructure, cloud-delete, and remote-script-pipe patterns, and
87
+ rejects options that make an allowed tool start another program (for example
88
+ `rg --pre` or `git -c core.pager=...`). It parses common shell syntax
89
+ (quoting, redirects, chains, heredocs, substitutions, simple `{a,b}` brace
90
+ lists, and wrappers such as `sudo`, `env`, `xargs` and `sh -c`) and checks the
91
+ commands it finds. A line it cannot parse is blocked, and so is a program name
92
+ that is quoted, escaped or built from an expansion, because the guard cannot
93
+ tell which program it names. It is a best-effort
94
+ check, not a full shell: it does not evaluate variables, aliases or functions
95
+ defined earlier, nested brace or sequence expansion, or resolve paths, and it
96
+ is not a sandbox. Before arbitrary shell access becomes a public
88
97
  feature, add an explicit consent flow bound to the exact command hash, a scoped
89
98
  working directory, environment filtering, execution timeouts, and output caps.
90
99
 
package/install.sh CHANGED
@@ -481,7 +481,9 @@ detect_cursor() {
481
481
  [ -d "$HOME/Applications/Cursor.app" ]
482
482
  }
483
483
  detect_codex() {
484
- need codex
484
+ need codex ||
485
+ [ -d "/Applications/ChatGPT.app" ] || [ -d "$HOME/Applications/ChatGPT.app" ] ||
486
+ [ -d "/Applications/Codex.app" ] || [ -d "$HOME/Applications/Codex.app" ]
485
487
  }
486
488
  detect_opencode() {
487
489
  need opencode ||
@@ -1644,12 +1646,6 @@ install_codex_plugin() {
1644
1646
  record_adapter "codex" "skipped" "not selected or not detected"
1645
1647
  return 0
1646
1648
  fi
1647
- if ! need codex; then
1648
- say "Codex CLI not found; skipping Codex marketplace registration."
1649
- say "Later, from a checkout, run: codex plugin marketplace add <repo>"
1650
- adapter_prereq_missing "codex" "the codex CLI is not on PATH"
1651
- return 0
1652
- fi
1653
1649
 
1654
1650
  local repo
1655
1651
  if ! repo="$(resolve_plugin_repo ".codex-plugin")"; then
@@ -1673,6 +1669,44 @@ install_codex_plugin() {
1673
1669
  return 0
1674
1670
  fi
1675
1671
 
1672
+ if ! need codex; then
1673
+ # Desktop reads the documented personal marketplace without the Codex CLI.
1674
+ if node - "$HOME" "$repo" >>"$LOG_FILE" 2>&1 <<'NODE'
1675
+ const fs = require("node:fs"), path = require("node:path");
1676
+ const [home, repo] = process.argv.slice(2);
1677
+ const dir = path.join(home, ".agents", "plugins"), file = path.join(dir, "marketplace.json");
1678
+ try {
1679
+ for (const target of [path.join(home, ".agents"), dir, file]) {
1680
+ if (fs.existsSync(target) && fs.lstatSync(target).isSymbolicLink()) throw Error("Personal marketplace is symlinked; configure its owner directly.");
1681
+ }
1682
+ const previous = fs.existsSync(file) ? fs.readFileSync(file, "utf8") : undefined;
1683
+ const catalog = previous === undefined ? { name: "personal", plugins: [] } : JSON.parse(previous);
1684
+ if (!catalog || typeof catalog.name !== "string" || !Array.isArray(catalog.plugins)) throw Error("Personal marketplace is invalid; existing content was preserved.");
1685
+ const entry = catalog.plugins.find(p => p.name === "orchestra");
1686
+ if (entry && (entry.source?.source !== "npm" || entry.source?.package !== "@orchestraai/agent-tools")) throw Error("An existing Orchestra entry has a different source; existing content was preserved.");
1687
+ const version = JSON.parse(fs.readFileSync(path.join(repo, "package.json"), "utf8")).version;
1688
+ const plugin = { ...(entry || {}), name: "orchestra", source: { source: "npm", package: "@orchestraai/agent-tools", version }, policy: entry?.policy || { installation: "AVAILABLE", authentication: "ON_INSTALL" }, interface: { ...entry?.interface, displayName: "Orchestra" } };
1689
+ catalog.plugins = catalog.plugins.filter(p => p.name !== "orchestra");
1690
+ catalog.plugins.push(plugin);
1691
+ fs.mkdirSync(dir, { recursive: true });
1692
+ if (previous !== undefined && !fs.existsSync(file + ".orchestra-backup")) fs.writeFileSync(file + ".orchestra-backup", previous, { mode: 0o600, flag: "wx" });
1693
+ const temp = file + ".orchestra-" + process.pid;
1694
+ fs.writeFileSync(temp, JSON.stringify(catalog, null, 2) + "\n", { mode: 0o600, flag: "wx" });
1695
+ fs.renameSync(temp, file);
1696
+ } catch (error) { console.error(error.message); process.exitCode = 1; }
1697
+ NODE
1698
+ then
1699
+ ok "Orchestra registered in the Codex Desktop personal marketplace (no Codex CLI required)."
1700
+ record_adapter "codex" "installed" "Desktop marketplace registered; enable in Plugins"
1701
+ say "Restart Codex Desktop or ChatGPT, open Plugins, select your personal marketplace, and install or enable Orchestra. Start a new chat."
1702
+ say "This adds Orchestra skills; it does not change Desktop model routing."
1703
+ else
1704
+ record_adapter_failure "codex" "Desktop marketplace registration failed; inspect the install log"
1705
+ warn "Could not register the Desktop plugin. Your existing marketplace was preserved. See $LOG_FILE"
1706
+ fi
1707
+ return 0
1708
+ fi
1709
+
1676
1710
  say "Registering the Orchestra Codex marketplace from $repo."
1677
1711
  # The marketplace was understudy-skills before the rename and points at the
1678
1712
  # same checkout; drop it so Codex doesn't list the skills twice.