@aria-cli/tools 1.0.12 → 1.0.14

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 (233) hide show
  1. package/dist/index.js +378 -70
  2. package/dist/network-runtime/index.js +8 -12
  3. package/dist-cjs/index.js +400 -435
  4. package/dist-cjs/network-runtime/index.js +8 -172
  5. package/package.json +8 -6
  6. package/dist/.tsbuildinfo +0 -1
  7. package/dist/ask-user-interaction.js +0 -22
  8. package/dist/cache/web-cache.js +0 -66
  9. package/dist/definitions/arion.js +0 -104
  10. package/dist/definitions/browser/browser.js +0 -418
  11. package/dist/definitions/browser/index.js +0 -4
  12. package/dist/definitions/browser/pw-downloads.js +0 -114
  13. package/dist/definitions/browser/pw-interactions.js +0 -199
  14. package/dist/definitions/browser/pw-responses.js +0 -76
  15. package/dist/definitions/browser/pw-session.js +0 -310
  16. package/dist/definitions/browser/pw-shared.js +0 -66
  17. package/dist/definitions/browser/pw-snapshot.js +0 -301
  18. package/dist/definitions/browser/pw-state.js +0 -62
  19. package/dist/definitions/browser/types.js +0 -4
  20. package/dist/definitions/code-intelligence.js +0 -470
  21. package/dist/definitions/core.js +0 -109
  22. package/dist/definitions/delegation.js +0 -512
  23. package/dist/definitions/deploy.js +0 -65
  24. package/dist/definitions/filesystem.js +0 -196
  25. package/dist/definitions/frg.js +0 -63
  26. package/dist/definitions/index.js +0 -20
  27. package/dist/definitions/memory.js +0 -123
  28. package/dist/definitions/messaging.js +0 -625
  29. package/dist/definitions/meta.js +0 -349
  30. package/dist/definitions/network.js +0 -159
  31. package/dist/definitions/outlook.js +0 -277
  32. package/dist/definitions/patch/apply-patch.js +0 -184
  33. package/dist/definitions/patch/fuzzy-match.js +0 -166
  34. package/dist/definitions/patch/index.js +0 -1
  35. package/dist/definitions/patch/patch-parser.js +0 -207
  36. package/dist/definitions/patch/sandbox-paths.js +0 -105
  37. package/dist/definitions/process/index.js +0 -4
  38. package/dist/definitions/process/process-registry.js +0 -213
  39. package/dist/definitions/process/process.js +0 -386
  40. package/dist/definitions/process/pty-keys.js +0 -254
  41. package/dist/definitions/process/session-slug.js +0 -142
  42. package/dist/definitions/quip.js +0 -195
  43. package/dist/definitions/search.js +0 -60
  44. package/dist/definitions/session-history.js +0 -69
  45. package/dist/definitions/shell.js +0 -181
  46. package/dist/definitions/slack.js +0 -180
  47. package/dist/definitions/web.js +0 -109
  48. package/dist/executors/apply-patch.js +0 -901
  49. package/dist/executors/arion.js +0 -119
  50. package/dist/executors/code-intelligence.js +0 -882
  51. package/dist/executors/deploy.js +0 -848
  52. package/dist/executors/filesystem.js +0 -1122
  53. package/dist/executors/frg-freshness.js +0 -576
  54. package/dist/executors/frg.js +0 -298
  55. package/dist/executors/index.js +0 -46
  56. package/dist/executors/learning-meta.js +0 -1146
  57. package/dist/executors/lsp-client.js +0 -296
  58. package/dist/executors/memory.js +0 -750
  59. package/dist/executors/meta.js +0 -220
  60. package/dist/executors/process-registry.js +0 -465
  61. package/dist/executors/pty-session-store.js +0 -30
  62. package/dist/executors/pty.js +0 -271
  63. package/dist/executors/restart.js +0 -119
  64. package/dist/executors/search-freshness.js +0 -195
  65. package/dist/executors/search-types.js +0 -52
  66. package/dist/executors/search.js +0 -66
  67. package/dist/executors/self-diagnose.js +0 -398
  68. package/dist/executors/session-history.js +0 -283
  69. package/dist/executors/shell-safety.js +0 -473
  70. package/dist/executors/shell.js +0 -954
  71. package/dist/executors/utils.js +0 -33
  72. package/dist/executors/web.js +0 -542
  73. package/dist/extraction/content-extraction.js +0 -235
  74. package/dist/extraction/index.js +0 -4
  75. package/dist/headless-control-contract.js +0 -967
  76. package/dist/local-control-http-auth.js +0 -2
  77. package/dist/mcp/client.js +0 -181
  78. package/dist/mcp/connection.js +0 -480
  79. package/dist/mcp/index.js +0 -10
  80. package/dist/mcp/jsonrpc.js +0 -144
  81. package/dist/mcp/types.js +0 -7
  82. package/dist/network-control-adapter.js +0 -72
  83. package/dist/network-runtime/address-types.js +0 -165
  84. package/dist/network-runtime/db-owner-fencing.js +0 -69
  85. package/dist/network-runtime/delivery-receipts.js +0 -267
  86. package/dist/network-runtime/direct-endpoint-authority.js +0 -25
  87. package/dist/network-runtime/local-control-contract.js +0 -627
  88. package/dist/network-runtime/node-store-contract.js +0 -34
  89. package/dist/network-runtime/pair-route-contract.js +0 -77
  90. package/dist/network-runtime/peer-capabilities.js +0 -28
  91. package/dist/network-runtime/peer-principal-ref.js +0 -12
  92. package/dist/network-runtime/peer-state-machine.js +0 -121
  93. package/dist/network-runtime/protocol-schemas.js +0 -205
  94. package/dist/network-runtime/runtime-bootstrap-contract.js +0 -60
  95. package/dist/outlook/desktop-session.js +0 -279
  96. package/dist/policy.js +0 -149
  97. package/dist/providers/brave.js +0 -62
  98. package/dist/providers/duckduckgo.js +0 -176
  99. package/dist/providers/exa.js +0 -63
  100. package/dist/providers/firecrawl.js +0 -55
  101. package/dist/providers/index.js +0 -7
  102. package/dist/providers/jina.js +0 -49
  103. package/dist/providers/router.js +0 -96
  104. package/dist/providers/search-provider.js +0 -32
  105. package/dist/providers/tavily.js +0 -54
  106. package/dist/quip/desktop-session.js +0 -317
  107. package/dist/registry/index.js +0 -1
  108. package/dist/registry/registry.js +0 -756
  109. package/dist/runtime-socket-local-control-client.js +0 -330
  110. package/dist/security/dns-normalization.js +0 -19
  111. package/dist/security/dns-pinning.js +0 -123
  112. package/dist/security/external-content.js +0 -91
  113. package/dist/security/ssrf.js +0 -181
  114. package/dist/slack/desktop-session.js +0 -324
  115. package/dist/tool-factory.js +0 -47
  116. package/dist/types.js +0 -7
  117. package/dist/utils/retry.js +0 -132
  118. package/dist/utils/safe-parse-json.js +0 -160
  119. package/dist/utils/url.js +0 -19
  120. package/dist-cjs/.tsbuildinfo +0 -1
  121. package/dist-cjs/ask-user-interaction.js +0 -27
  122. package/dist-cjs/cache/web-cache.js +0 -70
  123. package/dist-cjs/definitions/arion.js +0 -107
  124. package/dist-cjs/definitions/browser/browser.js +0 -421
  125. package/dist-cjs/definitions/browser/index.js +0 -8
  126. package/dist-cjs/definitions/browser/pw-downloads.js +0 -117
  127. package/dist-cjs/definitions/browser/pw-interactions.js +0 -213
  128. package/dist-cjs/definitions/browser/pw-responses.js +0 -84
  129. package/dist-cjs/definitions/browser/pw-session.js +0 -326
  130. package/dist-cjs/definitions/browser/pw-shared.js +0 -72
  131. package/dist-cjs/definitions/browser/pw-snapshot.js +0 -307
  132. package/dist-cjs/definitions/browser/pw-state.js +0 -70
  133. package/dist-cjs/definitions/browser/types.js +0 -5
  134. package/dist-cjs/definitions/code-intelligence.js +0 -473
  135. package/dist-cjs/definitions/core.js +0 -133
  136. package/dist-cjs/definitions/delegation.js +0 -515
  137. package/dist-cjs/definitions/deploy.js +0 -68
  138. package/dist-cjs/definitions/filesystem.js +0 -199
  139. package/dist-cjs/definitions/frg.js +0 -66
  140. package/dist-cjs/definitions/index.js +0 -43
  141. package/dist-cjs/definitions/memory.js +0 -126
  142. package/dist-cjs/definitions/messaging.js +0 -631
  143. package/dist-cjs/definitions/meta.js +0 -352
  144. package/dist-cjs/definitions/network.js +0 -162
  145. package/dist-cjs/definitions/outlook.js +0 -280
  146. package/dist-cjs/definitions/patch/apply-patch.js +0 -191
  147. package/dist-cjs/definitions/patch/fuzzy-match.js +0 -172
  148. package/dist-cjs/definitions/patch/index.js +0 -5
  149. package/dist-cjs/definitions/patch/patch-parser.js +0 -215
  150. package/dist-cjs/definitions/patch/sandbox-paths.js +0 -113
  151. package/dist-cjs/definitions/process/index.js +0 -8
  152. package/dist-cjs/definitions/process/process-registry.js +0 -231
  153. package/dist-cjs/definitions/process/process.js +0 -389
  154. package/dist-cjs/definitions/process/pty-keys.js +0 -259
  155. package/dist-cjs/definitions/process/session-slug.js +0 -145
  156. package/dist-cjs/definitions/quip.js +0 -198
  157. package/dist-cjs/definitions/search.js +0 -63
  158. package/dist-cjs/definitions/session-history.js +0 -72
  159. package/dist-cjs/definitions/shell.js +0 -184
  160. package/dist-cjs/definitions/slack.js +0 -183
  161. package/dist-cjs/definitions/web.js +0 -112
  162. package/dist-cjs/executors/apply-patch.js +0 -938
  163. package/dist-cjs/executors/arion.js +0 -125
  164. package/dist-cjs/executors/code-intelligence.js +0 -925
  165. package/dist-cjs/executors/deploy.js +0 -869
  166. package/dist-cjs/executors/filesystem.js +0 -1167
  167. package/dist-cjs/executors/frg-freshness.js +0 -627
  168. package/dist-cjs/executors/frg.js +0 -334
  169. package/dist-cjs/executors/index.js +0 -143
  170. package/dist-cjs/executors/learning-meta.js +0 -1165
  171. package/dist-cjs/executors/lsp-client.js +0 -310
  172. package/dist-cjs/executors/memory.js +0 -796
  173. package/dist-cjs/executors/meta.js +0 -226
  174. package/dist-cjs/executors/process-registry.js +0 -469
  175. package/dist-cjs/executors/pty-session-store.js +0 -34
  176. package/dist-cjs/executors/pty.js +0 -312
  177. package/dist-cjs/executors/restart.js +0 -155
  178. package/dist-cjs/executors/search-freshness.js +0 -234
  179. package/dist-cjs/executors/search-types.js +0 -56
  180. package/dist-cjs/executors/search.js +0 -102
  181. package/dist-cjs/executors/self-diagnose.js +0 -434
  182. package/dist-cjs/executors/session-history.js +0 -320
  183. package/dist-cjs/executors/shell-safety.js +0 -478
  184. package/dist-cjs/executors/shell.js +0 -1001
  185. package/dist-cjs/executors/utils.js +0 -73
  186. package/dist-cjs/executors/web.js +0 -547
  187. package/dist-cjs/extraction/content-extraction.js +0 -243
  188. package/dist-cjs/extraction/index.js +0 -8
  189. package/dist-cjs/headless-control-contract.js +0 -972
  190. package/dist-cjs/local-control-http-auth.js +0 -5
  191. package/dist-cjs/mcp/client.js +0 -185
  192. package/dist-cjs/mcp/connection.js +0 -484
  193. package/dist-cjs/mcp/index.js +0 -30
  194. package/dist-cjs/mcp/jsonrpc.js +0 -148
  195. package/dist-cjs/mcp/types.js +0 -8
  196. package/dist-cjs/network-control-adapter.js +0 -77
  197. package/dist-cjs/network-runtime/address-types.js +0 -168
  198. package/dist-cjs/network-runtime/db-owner-fencing.js +0 -76
  199. package/dist-cjs/network-runtime/delivery-receipts.js +0 -276
  200. package/dist-cjs/network-runtime/direct-endpoint-authority.js +0 -29
  201. package/dist-cjs/network-runtime/local-control-contract.js +0 -633
  202. package/dist-cjs/network-runtime/node-store-contract.js +0 -38
  203. package/dist-cjs/network-runtime/pair-route-contract.js +0 -80
  204. package/dist-cjs/network-runtime/peer-capabilities.js +0 -37
  205. package/dist-cjs/network-runtime/peer-principal-ref.js +0 -15
  206. package/dist-cjs/network-runtime/peer-state-machine.js +0 -129
  207. package/dist-cjs/network-runtime/protocol-schemas.js +0 -212
  208. package/dist-cjs/network-runtime/runtime-bootstrap-contract.js +0 -63
  209. package/dist-cjs/outlook/desktop-session.js +0 -318
  210. package/dist-cjs/policy.js +0 -155
  211. package/dist-cjs/providers/brave.js +0 -66
  212. package/dist-cjs/providers/duckduckgo.js +0 -180
  213. package/dist-cjs/providers/exa.js +0 -67
  214. package/dist-cjs/providers/firecrawl.js +0 -59
  215. package/dist-cjs/providers/index.js +0 -17
  216. package/dist-cjs/providers/jina.js +0 -53
  217. package/dist-cjs/providers/router.js +0 -100
  218. package/dist-cjs/providers/search-provider.js +0 -36
  219. package/dist-cjs/providers/tavily.js +0 -58
  220. package/dist-cjs/quip/desktop-session.js +0 -353
  221. package/dist-cjs/registry/index.js +0 -6
  222. package/dist-cjs/registry/registry.js +0 -761
  223. package/dist-cjs/runtime-socket-local-control-client.js +0 -367
  224. package/dist-cjs/security/dns-normalization.js +0 -22
  225. package/dist-cjs/security/dns-pinning.js +0 -160
  226. package/dist-cjs/security/external-content.js +0 -95
  227. package/dist-cjs/security/ssrf.js +0 -221
  228. package/dist-cjs/slack/desktop-session.js +0 -366
  229. package/dist-cjs/tool-factory.js +0 -50
  230. package/dist-cjs/types.js +0 -8
  231. package/dist-cjs/utils/retry.js +0 -169
  232. package/dist-cjs/utils/safe-parse-json.js +0 -164
  233. package/dist-cjs/utils/url.js +0 -23
@@ -1,954 +0,0 @@
1
- /**
2
- * @aria/tools - Shell tool executors
3
- *
4
- * Implementation of shell operations for ARIA tool system.
5
- */
6
- import { spawn } from "node:child_process";
7
- import { constants as osConstants } from "node:os";
8
- import { success, fail, getErrorMessage } from "./utils.js";
9
- import { classifyCommand, classifyExecInvocation } from "./shell-safety.js";
10
- /**
11
- * Environment variables that are dangerous in ALL contexts — including
12
- * the host's own process.env. These enable code injection or library
13
- * hijacking and should never reach child processes.
14
- */
15
- export const BLOCKED_ENV_VARS = new Set([
16
- "LD_PRELOAD",
17
- "LD_LIBRARY_PATH",
18
- "DYLD_INSERT_LIBRARIES",
19
- "DYLD_FRAMEWORK_PATH",
20
- "DYLD_LIBRARY_PATH",
21
- "BASH_ENV",
22
- "ENV",
23
- "CDPATH",
24
- "GLOBIGNORE",
25
- "PROMPT_COMMAND",
26
- "SHELLOPTS",
27
- "BASHOPTS",
28
- // Git context hijacks: inherited vars can redirect repository resolution.
29
- "GIT_DIR",
30
- "GIT_WORK_TREE",
31
- "GIT_INDEX_FILE",
32
- "GIT_OBJECT_DIRECTORY",
33
- "GIT_ALTERNATE_OBJECT_DIRECTORIES",
34
- "GIT_COMMON_DIR",
35
- "GIT_PREFIX",
36
- "GIT_INTERNAL_SUPER_PREFIX",
37
- "GIT_CONFIG",
38
- "GIT_CONFIG_GLOBAL",
39
- "GIT_CONFIG_SYSTEM",
40
- "GIT_CONFIG_COUNT",
41
- "GIT_CEILING_DIRECTORIES",
42
- ]);
43
- /**
44
- * Git environment keys that can redirect repository/config context or mutate
45
- * commit identity unexpectedly when inherited by child processes.
46
- *
47
- * NOTE: We intentionally keep transport/debug keys like GIT_SSH_COMMAND and
48
- * GIT_TRACE untouched to avoid breaking legitimate workflows.
49
- */
50
- const GIT_BLOCKED_EXACT_KEYS = new Set([
51
- "GIT_DIR",
52
- "GIT_WORK_TREE",
53
- "GIT_INDEX_FILE",
54
- "GIT_INDEX_VERSION",
55
- "GIT_COMMON_DIR",
56
- "GIT_OBJECT_DIRECTORY",
57
- "GIT_ALTERNATE_OBJECT_DIRECTORIES",
58
- "GIT_CEILING_DIRECTORIES",
59
- "GIT_DISCOVERY_ACROSS_FILESYSTEM",
60
- "GIT_NAMESPACE",
61
- "GIT_CONFIG",
62
- "GIT_CONFIG_GLOBAL",
63
- "GIT_CONFIG_SYSTEM",
64
- "GIT_CONFIG_NOSYSTEM",
65
- "GIT_CONFIG_COUNT",
66
- "GIT_CONFIG_PARAMETERS",
67
- ]);
68
- const GIT_BLOCKED_PREFIXES = [
69
- "GIT_CONFIG_KEY_",
70
- "GIT_CONFIG_VALUE_",
71
- "GIT_AUTHOR_",
72
- "GIT_COMMITTER_",
73
- ];
74
- export function isBlockedGitEnvVar(key) {
75
- const upper = key.toUpperCase();
76
- if (GIT_BLOCKED_EXACT_KEYS.has(upper)) {
77
- return true;
78
- }
79
- return GIT_BLOCKED_PREFIXES.some((prefix) => upper.startsWith(prefix));
80
- }
81
- /**
82
- * Strip git-context env keys from a source env object.
83
- */
84
- export function sanitizeGitEnv(env = process.env) {
85
- const sanitized = {};
86
- for (const [key, value] of Object.entries(env)) {
87
- if (value === undefined)
88
- continue;
89
- if (isBlockedGitEnvVar(key))
90
- continue;
91
- sanitized[key] = value;
92
- }
93
- return sanitized;
94
- }
95
- /**
96
- * Additional variables blocked from tool-injected input (inputEnv, ctx.env)
97
- * but NOT from process.env. The host's PATH/HOME/SHELL are legitimate —
98
- * only tool-provided overrides are dangerous (hijacking resolution paths).
99
- */
100
- export const BLOCKED_INPUT_ENV_VARS = new Set([
101
- ...BLOCKED_ENV_VARS,
102
- // Executable/module resolution hijacks (aria-mx5)
103
- "PATH",
104
- "NODE_OPTIONS",
105
- "NODE_PATH",
106
- "PYTHONPATH",
107
- // Shell/environment manipulation
108
- "IFS",
109
- "HOME",
110
- "SHELL",
111
- "EDITOR",
112
- "VISUAL",
113
- // Java runtime hijacks (aria-skg)
114
- "JAVA_TOOL_OPTIONS",
115
- "_JAVA_OPTIONS",
116
- "CLASSPATH",
117
- // Ruby runtime hijacks (aria-skg)
118
- "RUBYOPT",
119
- "GEM_HOME",
120
- "GEM_PATH",
121
- // Perl runtime hijacks (aria-skg)
122
- "PERL5OPT",
123
- "PERL5LIB",
124
- // Python startup hijack (aria-skg) — PYTHONPATH already covered above
125
- "PYTHONSTARTUP",
126
- ]);
127
- function isBlockedProcessEnvVar(key) {
128
- return BLOCKED_ENV_VARS.has(key.toUpperCase()) || isBlockedGitEnvVar(key);
129
- }
130
- function isBlockedInputEnvVar(key) {
131
- return BLOCKED_INPUT_ENV_VARS.has(key.toUpperCase()) || isBlockedGitEnvVar(key);
132
- }
133
- /**
134
- * Merges environment variables from context and input.
135
- *
136
- * Three-tier filtering:
137
- * - process.env: filtered through BLOCKED_ENV_VARS (injection-only vars like LD_PRELOAD)
138
- * - ctx.env / inputEnv: filtered through BLOCKED_INPUT_ENV_VARS (also blocks PATH/HOME/SHELL hijacking)
139
- */
140
- export function mergeEnv(ctx, inputEnv) {
141
- let sanitizedInput = inputEnv;
142
- if (inputEnv) {
143
- sanitizedInput = {};
144
- for (const [key, value] of Object.entries(inputEnv)) {
145
- if (isBlockedInputEnvVar(key)) {
146
- continue;
147
- }
148
- sanitizedInput[key] = value;
149
- }
150
- }
151
- let sanitizedCtxEnv = ctx.env;
152
- if (ctx.env) {
153
- sanitizedCtxEnv = {};
154
- for (const [key, value] of Object.entries(ctx.env)) {
155
- if (isBlockedInputEnvVar(key)) {
156
- continue;
157
- }
158
- sanitizedCtxEnv[key] = value;
159
- }
160
- }
161
- // Filter process.env through the base blocklist only — the host's
162
- // PATH/HOME/SHELL are legitimate and needed by child processes.
163
- const sanitizedProcessEnv = {};
164
- for (const [key, value] of Object.entries(process.env)) {
165
- if (value === undefined)
166
- continue;
167
- if (isBlockedProcessEnvVar(key)) {
168
- continue;
169
- }
170
- sanitizedProcessEnv[key] = value;
171
- }
172
- return {
173
- ...sanitizedProcessEnv,
174
- ...sanitizedCtxEnv,
175
- ...sanitizedInput,
176
- };
177
- }
178
- /**
179
- * Sanitize environment for child processes without requiring a ToolContext.
180
- *
181
- * Applies the same two-tier filtering as mergeEnv:
182
- * - process.env is filtered through BLOCKED_ENV_VARS
183
- * - inputEnv (caller-supplied overrides) is filtered through BLOCKED_INPUT_ENV_VARS
184
- *
185
- * Intended for executors (e.g. PTY) that do not have a ToolContext.
186
- */
187
- export function sanitizeEnv(inputEnv) {
188
- // Filter process.env through the base blocklist
189
- const sanitizedProcessEnv = {};
190
- for (const [key, value] of Object.entries(process.env)) {
191
- if (value === undefined)
192
- continue;
193
- if (isBlockedProcessEnvVar(key)) {
194
- continue;
195
- }
196
- sanitizedProcessEnv[key] = value;
197
- }
198
- // Filter inputEnv through the stricter input blocklist
199
- let sanitizedInput;
200
- if (inputEnv) {
201
- sanitizedInput = {};
202
- for (const [key, value] of Object.entries(inputEnv)) {
203
- if (isBlockedInputEnvVar(key)) {
204
- continue;
205
- }
206
- sanitizedInput[key] = value;
207
- }
208
- }
209
- return {
210
- ...sanitizedProcessEnv,
211
- ...sanitizedInput,
212
- };
213
- }
214
- /**
215
- * Executes a command through bash shell.
216
- * Supports shell features like pipes, redirection, and variable expansion.
217
- */
218
- export async function executeBash(input, ctx) {
219
- // Shell safety: block catastrophic commands before any execution
220
- const risk = classifyCommand(input.command);
221
- if (risk === "blocked") {
222
- return fail(`Command blocked by shell safety policy: ${input.command}`);
223
- }
224
- // Check if already aborted before starting
225
- if (ctx.abortSignal?.aborted) {
226
- return fail("Command cancelled");
227
- }
228
- const cwd = input.cwd ?? ctx.workingDir;
229
- const env = mergeEnv(ctx, input.env);
230
- const timeout = input.timeout ?? 120_000;
231
- return executeExec({
232
- program: "/bin/bash",
233
- args: ["-lc", input.command],
234
- cwd,
235
- env: input.env,
236
- timeout,
237
- }, {
238
- ...ctx,
239
- workingDir: cwd,
240
- env,
241
- });
242
- }
243
- function signalExecProcessTree(pid, signal, detachedProcessGroup) {
244
- if (!pid) {
245
- return;
246
- }
247
- if (detachedProcessGroup) {
248
- try {
249
- process.kill(-pid, signal);
250
- return;
251
- }
252
- catch {
253
- // Fall back to the leader PID if the process group is already gone or unsupported.
254
- }
255
- }
256
- try {
257
- process.kill(pid, signal);
258
- }
259
- catch {
260
- // Process may already be dead.
261
- }
262
- }
263
- function isExecProcessTreeAlive(pid, detachedProcessGroup) {
264
- if (!pid) {
265
- return false;
266
- }
267
- if (detachedProcessGroup) {
268
- try {
269
- process.kill(-pid, 0);
270
- return true;
271
- }
272
- catch {
273
- // Fall through to the leader PID check in case the group probe is unsupported.
274
- }
275
- }
276
- try {
277
- process.kill(pid, 0);
278
- return true;
279
- }
280
- catch {
281
- return false;
282
- }
283
- }
284
- async function waitForExecProcessTreeExit(pid, detachedProcessGroup, timeoutMs = 1_000) {
285
- if (!pid) {
286
- return;
287
- }
288
- const deadline = Date.now() + timeoutMs;
289
- while (Date.now() < deadline) {
290
- if (!isExecProcessTreeAlive(pid, detachedProcessGroup)) {
291
- return;
292
- }
293
- await new Promise((resolve) => setTimeout(resolve, 25));
294
- }
295
- }
296
- /**
297
- * Executes a program directly without shell interpretation.
298
- * Safer than bash as it doesn't expand shell metacharacters.
299
- */
300
- export async function executeExec(input, ctx) {
301
- const args = input.args ?? [];
302
- // Shell safety: block catastrophic commands before any execution.
303
- // For explicit shell wrappers (e.g. bash -c ...), classify payload command.
304
- const reconstructed = [input.program, ...args].join(" ");
305
- const risk = classifyExecInvocation(input.program, args);
306
- if (risk === "blocked") {
307
- return fail(`Command blocked by shell safety policy: ${reconstructed}`, {
308
- stdout: "",
309
- stderr: "",
310
- exitCode: 1,
311
- });
312
- }
313
- // Check if already aborted before starting
314
- if (ctx.abortSignal?.aborted) {
315
- return fail("Command cancelled", {
316
- stdout: "",
317
- stderr: "",
318
- exitCode: 1,
319
- });
320
- }
321
- const cwd = input.cwd ?? ctx.workingDir;
322
- const env = mergeEnv(ctx, input.env);
323
- const timeout = input.timeout ?? 120_000;
324
- return new Promise((resolve) => {
325
- const detachedProcessGroup = process.platform !== "win32";
326
- const proc = spawn(input.program, args, {
327
- cwd,
328
- env,
329
- detached: detachedProcessGroup,
330
- });
331
- // Track PID in process registry for cleanup on session close
332
- if (proc.pid && ctx.processRegistry) {
333
- ctx.processRegistry.add(proc.pid, {
334
- command: input.program,
335
- args,
336
- cwd,
337
- interactive: false,
338
- });
339
- }
340
- let stdout = "";
341
- let stderr = "";
342
- let timedOut = false;
343
- let cancelled = false;
344
- let resolved = false;
345
- let timeoutId;
346
- let killTimeoutId;
347
- const doResolve = (result, exit) => {
348
- if (resolved)
349
- return;
350
- resolved = true;
351
- if (timeoutId)
352
- clearTimeout(timeoutId);
353
- if (killTimeoutId)
354
- clearTimeout(killTimeoutId);
355
- // Clean up abort listener
356
- if (ctx.abortSignal && onAbort) {
357
- ctx.abortSignal.removeEventListener("abort", onAbort);
358
- }
359
- // Keep detached process groups tracked until the whole group is gone.
360
- ctx.processRegistry?.recordExitMetadata?.(proc.pid ?? 0, exit);
361
- if (proc.pid &&
362
- ctx.processRegistry &&
363
- !(detachedProcessGroup && isExecProcessTreeAlive(proc.pid, detachedProcessGroup))) {
364
- ctx.processRegistry.remove(proc.pid, exit);
365
- }
366
- resolve(result);
367
- };
368
- // Wire abort signal to kill the process
369
- let onAbort;
370
- if (ctx.abortSignal) {
371
- onAbort = () => {
372
- cancelled = true;
373
- signalExecProcessTree(proc.pid, "SIGTERM", detachedProcessGroup);
374
- // Follow up with SIGKILL if SIGTERM doesn't work
375
- killTimeoutId = setTimeout(() => {
376
- signalExecProcessTree(proc.pid, "SIGKILL", detachedProcessGroup);
377
- }, 1000);
378
- };
379
- ctx.abortSignal.addEventListener("abort", onAbort, { once: true });
380
- }
381
- if (timeout) {
382
- timeoutId = setTimeout(() => {
383
- timedOut = true;
384
- signalExecProcessTree(proc.pid, "SIGTERM", detachedProcessGroup);
385
- // If SIGTERM doesn't work, follow up with SIGKILL after 1 second
386
- killTimeoutId = setTimeout(() => {
387
- signalExecProcessTree(proc.pid, "SIGKILL", detachedProcessGroup);
388
- }, 1000);
389
- }, timeout);
390
- }
391
- proc.stdout?.on("data", (data) => {
392
- stdout += data.toString();
393
- });
394
- proc.stderr?.on("data", (data) => {
395
- stderr += data.toString();
396
- });
397
- proc.on("error", (err) => {
398
- const exitCode = typeof err === "object" &&
399
- err &&
400
- "code" in err &&
401
- err.code === "ENOENT"
402
- ? 127
403
- : 1;
404
- doResolve(fail(getErrorMessage(err), {
405
- stdout: "",
406
- stderr,
407
- exitCode,
408
- }));
409
- });
410
- proc.on("close", (code, signal) => {
411
- void (async () => {
412
- if (cancelled || timedOut) {
413
- if (killTimeoutId) {
414
- clearTimeout(killTimeoutId);
415
- killTimeoutId = undefined;
416
- }
417
- signalExecProcessTree(proc.pid, "SIGKILL", detachedProcessGroup);
418
- await waitForExecProcessTreeExit(proc.pid, detachedProcessGroup);
419
- }
420
- if (cancelled) {
421
- doResolve(fail("Command cancelled", {
422
- stdout,
423
- stderr,
424
- exitCode: code ?? 1,
425
- }), { exitCode: code, signal });
426
- return;
427
- }
428
- if (timedOut) {
429
- doResolve(fail("Command timed out", {
430
- stdout,
431
- stderr,
432
- exitCode: code ?? 1,
433
- }), { exitCode: code, signal });
434
- return;
435
- }
436
- if (signal) {
437
- const signaledExitCode = osConstants.signals[signal] ?? 1;
438
- doResolve(fail(`Command exited due to signal ${signal}`, {
439
- stdout,
440
- stderr,
441
- exitCode: code ?? signaledExitCode,
442
- }), { exitCode: code, signal });
443
- return;
444
- }
445
- const exitCode = code ?? 0;
446
- if (exitCode === 0) {
447
- doResolve(success("Command executed successfully", {
448
- stdout,
449
- stderr,
450
- exitCode,
451
- }), { exitCode, signal });
452
- }
453
- else {
454
- doResolve(fail(`Command exited with code ${exitCode}`, {
455
- stdout,
456
- stderr,
457
- exitCode,
458
- }), { exitCode, signal });
459
- }
460
- })();
461
- });
462
- });
463
- }
464
- /**
465
- * Spawns a background process and returns immediately with its PID.
466
- * The process is detached and will continue running after the parent exits.
467
- */
468
- export async function executeSpawn(input, ctx) {
469
- // Shell safety: block catastrophic commands before spawning.
470
- // Detached processes are especially dangerous — they outlive the session.
471
- // For explicit shell wrappers (e.g. bash -c ...), classify payload command.
472
- const args = input.args ?? [];
473
- const reconstructed = [input.program, ...args].join(" ");
474
- const risk = classifyExecInvocation(input.program, args);
475
- if (risk === "blocked") {
476
- return fail(`Command blocked by shell safety policy: ${reconstructed}`);
477
- }
478
- // Check if already aborted before spawning
479
- if (ctx.abortSignal?.aborted) {
480
- return fail("Command cancelled");
481
- }
482
- // Check for interactive mode — use PTY instead of detached spawn
483
- if (input.interactive === true) {
484
- if (!ctx.ptySessionStore) {
485
- return fail("PTY session store not available — interactive mode requires runner wiring");
486
- }
487
- // Import createPTYSession dynamically to avoid circular deps at module level
488
- const { createPTYSession } = await import("./pty.js");
489
- const session = await createPTYSession({
490
- command: input.program,
491
- args: input.args,
492
- cwd: input.cwd ?? ctx.workingDir,
493
- env: mergeEnv(ctx, input.env),
494
- });
495
- const pid = session.pid;
496
- if (!pid) {
497
- session.close();
498
- return fail("Failed to start interactive session: no PID");
499
- }
500
- // Register in both stores
501
- ctx.ptySessionStore.add(pid, session);
502
- if (ctx.processRegistry) {
503
- ctx.processRegistry.add(pid, {
504
- command: input.program,
505
- args: input.args ?? [],
506
- cwd: input.cwd ?? ctx.workingDir,
507
- interactive: true,
508
- });
509
- }
510
- const deregisterInteractiveSession = () => {
511
- ctx.ptySessionStore?.remove(pid);
512
- if (ctx.processRegistry?.has(pid)) {
513
- ctx.processRegistry.remove(pid, {
514
- exitCode: session.exitCode ?? null,
515
- });
516
- }
517
- };
518
- if (!session.isRunning) {
519
- deregisterInteractiveSession();
520
- }
521
- else {
522
- const lifecycleCheckInterval = setInterval(() => {
523
- if (!session.isRunning) {
524
- clearInterval(lifecycleCheckInterval);
525
- deregisterInteractiveSession();
526
- }
527
- }, 50);
528
- lifecycleCheckInterval.unref?.();
529
- // Wire abort signal to PTY cleanup so ESC/Ctrl+C kills the session
530
- if (ctx.abortSignal) {
531
- const onAbort = () => {
532
- clearInterval(lifecycleCheckInterval);
533
- session.close();
534
- deregisterInteractiveSession();
535
- };
536
- ctx.abortSignal.addEventListener("abort", onAbort, { once: true });
537
- }
538
- }
539
- return success(`Started interactive session with PID ${pid}`, { pid });
540
- }
541
- const cwd = input.cwd ?? ctx.workingDir;
542
- const env = mergeEnv(ctx, input.env);
543
- return new Promise((resolve) => {
544
- let resolved = false;
545
- let fallbackTimeoutId;
546
- const doResolve = (result) => {
547
- if (resolved)
548
- return;
549
- resolved = true;
550
- if (fallbackTimeoutId)
551
- clearTimeout(fallbackTimeoutId);
552
- resolve(result);
553
- };
554
- // Wire abort signal to kill the spawned process.
555
- // The listener is NOT removed in doResolve because the spawned process
556
- // outlives the function call. The { once: true } option auto-cleans it.
557
- let spawnedPid;
558
- if (ctx.abortSignal) {
559
- ctx.abortSignal.addEventListener("abort", () => {
560
- if (spawnedPid) {
561
- try {
562
- // Kill the process group (negative PID) since process is detached
563
- process.kill(-spawnedPid, "SIGTERM");
564
- }
565
- catch {
566
- try {
567
- process.kill(spawnedPid, "SIGTERM");
568
- }
569
- catch {
570
- // Process may already be dead
571
- }
572
- }
573
- }
574
- }, { once: true });
575
- }
576
- try {
577
- const proc = spawn(input.program, args, {
578
- cwd,
579
- env,
580
- detached: true,
581
- stdio: "ignore",
582
- });
583
- // Handle spawn errors (e.g., program not found)
584
- proc.on("error", (err) => {
585
- doResolve(fail(getErrorMessage(err)));
586
- });
587
- // If we have a PID, the spawn was successful
588
- if (proc.pid) {
589
- spawnedPid = proc.pid;
590
- proc.on("exit", (code, signal) => {
591
- ctx.processRegistry?.recordExitMetadata?.(proc.pid, {
592
- exitCode: code,
593
- signal,
594
- });
595
- if (ctx.processRegistry && !isExecProcessTreeAlive(proc.pid, true)) {
596
- ctx.processRegistry.remove(proc.pid, {
597
- exitCode: code,
598
- signal,
599
- });
600
- }
601
- });
602
- // Track PID in process registry for cleanup on session close.
603
- // Spawned (detached) processes are never deregistered here —
604
- // they live until exit, killAll(), or the user explicitly kills them.
605
- if (ctx.processRegistry) {
606
- ctx.processRegistry.add(proc.pid, {
607
- command: input.program,
608
- args,
609
- cwd,
610
- interactive: false,
611
- });
612
- }
613
- // Unref to allow parent to exit independently
614
- proc.unref();
615
- doResolve(success(`Spawned process with PID ${proc.pid}`, {
616
- pid: proc.pid,
617
- }));
618
- }
619
- else {
620
- // This shouldn't normally happen, but handle it just in case
621
- // Wait briefly for error event
622
- fallbackTimeoutId = setTimeout(() => {
623
- doResolve(fail("Failed to spawn process: no PID returned"));
624
- }, 100);
625
- }
626
- }
627
- catch (err) {
628
- doResolve(fail(getErrorMessage(err)));
629
- }
630
- });
631
- }
632
- /**
633
- * Sends a signal to terminate a process by PID.
634
- */
635
- export async function executeKill(input, ctx) {
636
- const signal = input.signal ?? "SIGTERM";
637
- try {
638
- // Validate and normalize the signal
639
- const validatedSignal = validateSignal(signal);
640
- if (validatedSignal === undefined) {
641
- return fail(`Invalid signal: ${signal}`);
642
- }
643
- // Use process-tree signaling only for ARIA-tracked processes. Generic pid
644
- // kills must preserve pid-only semantics for foreign process groups.
645
- if (ctx.processRegistry?.has(input.pid)) {
646
- signalProcessTree(input.pid, validatedSignal);
647
- }
648
- else {
649
- process.kill(input.pid, validatedSignal);
650
- }
651
- // Keep tracked processes authoritative until exit is actually observed.
652
- const registry = ctx.processRegistry;
653
- if (registry?.waitForExit && shouldUntrackAfterSignal(validatedSignal)) {
654
- await registry.waitForExit(input.pid, 2_000);
655
- }
656
- const signalName = typeof validatedSignal === "number" ? signal : validatedSignal;
657
- return success(`Sent ${signalName} to process ${input.pid}`, {
658
- pid: input.pid,
659
- signal: signalName,
660
- });
661
- }
662
- catch (err) {
663
- if (err instanceof Error && "code" in err) {
664
- const nodeErr = err;
665
- if (nodeErr.code === "ESRCH") {
666
- return fail(`Process not found: ${input.pid}`);
667
- }
668
- if (nodeErr.code === "EPERM") {
669
- return fail(`Permission denied to kill process: ${input.pid}`);
670
- }
671
- }
672
- return fail(getErrorMessage(err));
673
- }
674
- }
675
- /**
676
- * Valid signal names that can be used with process.kill.
677
- */
678
- const VALID_SIGNALS = [
679
- "SIGHUP",
680
- "SIGINT",
681
- "SIGQUIT",
682
- "SIGILL",
683
- "SIGTRAP",
684
- "SIGABRT",
685
- "SIGBUS",
686
- "SIGFPE",
687
- "SIGKILL",
688
- "SIGUSR1",
689
- "SIGSEGV",
690
- "SIGUSR2",
691
- "SIGPIPE",
692
- "SIGALRM",
693
- "SIGTERM",
694
- "SIGSTKFLT",
695
- "SIGCHLD",
696
- "SIGCONT",
697
- "SIGSTOP",
698
- "SIGTSTP",
699
- "SIGTTIN",
700
- "SIGTTOU",
701
- "SIGURG",
702
- "SIGXCPU",
703
- "SIGXFSZ",
704
- "SIGVTALRM",
705
- "SIGPROF",
706
- "SIGWINCH",
707
- "SIGIO",
708
- "SIGPWR",
709
- "SIGSYS",
710
- ];
711
- const NON_TERMINATING_SIGNALS = new Set([
712
- "SIGCHLD",
713
- "SIGCONT",
714
- "SIGSTOP",
715
- "SIGTSTP",
716
- "SIGTTIN",
717
- "SIGTTOU",
718
- "SIGURG",
719
- "SIGWINCH",
720
- ]);
721
- /**
722
- * Type guard to check if a string is a valid signal name.
723
- */
724
- function isValidSignalName(signal) {
725
- return VALID_SIGNALS.includes(signal.toUpperCase());
726
- }
727
- /**
728
- * Validates a signal and returns either the validated signal name or number.
729
- * Returns undefined for invalid signals.
730
- */
731
- function validateSignal(signal) {
732
- // Handle numeric signal
733
- if (/^\d+$/.test(signal)) {
734
- const num = parseInt(signal, 10);
735
- if (num >= 1 && num <= 31) {
736
- return num;
737
- }
738
- return undefined;
739
- }
740
- // Handle signal names
741
- const upperSignal = signal.toUpperCase();
742
- if (isValidSignalName(upperSignal)) {
743
- return upperSignal;
744
- }
745
- return undefined;
746
- }
747
- function shouldUntrackAfterSignal(signal) {
748
- if (typeof signal === "number") {
749
- const signalName = resolveSignalName(signal);
750
- if (!signalName) {
751
- // Unknown numeric signals are treated conservatively.
752
- return false;
753
- }
754
- return !NON_TERMINATING_SIGNALS.has(signalName);
755
- }
756
- return !NON_TERMINATING_SIGNALS.has(signal);
757
- }
758
- function signalProcessTree(pid, signal) {
759
- try {
760
- if (pid > 0) {
761
- process.kill(-pid, signal);
762
- return;
763
- }
764
- }
765
- catch {
766
- // Fall back to the tracked pid itself when there is no process group to target.
767
- }
768
- process.kill(pid, signal);
769
- }
770
- function resolveSignalName(signal) {
771
- for (const [name, value] of Object.entries(osConstants.signals)) {
772
- if (value === signal) {
773
- return name;
774
- }
775
- }
776
- return undefined;
777
- }
778
- function hasLegacyGetAll(registry) {
779
- return typeof registry.getAll === "function";
780
- }
781
- export async function executeListProcesses(rawInput, ctx) {
782
- const input = toRecord(rawInput);
783
- const includeExited = typeof input?.includeExited === "boolean" ? input.includeExited : false;
784
- if (!ctx.processRegistry) {
785
- return fail("Process registry not available");
786
- }
787
- const registry = ctx.processRegistry;
788
- const processes = typeof registry.listProcesses === "function"
789
- ? registry.listProcesses({ includeExited })
790
- : hasLegacyGetAll(registry)
791
- ? registry.getAll().map((pid) => ({
792
- pid,
793
- command: null,
794
- args: [],
795
- cwd: null,
796
- interactive: false,
797
- startedAt: new Date().toISOString(),
798
- runtimeMs: 0,
799
- status: "running",
800
- exitCode: null,
801
- signal: null,
802
- endedAt: null,
803
- }))
804
- : [];
805
- return success(`Found ${processes.length} tracked process${processes.length === 1 ? "" : "es"}`, {
806
- processes,
807
- count: processes.length,
808
- });
809
- }
810
- export async function executeWaitProcess(rawInput, ctx) {
811
- const input = toRecord(rawInput);
812
- if (!input) {
813
- return fail("Invalid input: expected an object");
814
- }
815
- const pid = typeof input.pid === "number" ? input.pid : NaN;
816
- if (!pid || pid <= 0 || !Number.isInteger(pid)) {
817
- return fail("Invalid PID: must be a positive integer");
818
- }
819
- if (pid === process.pid) {
820
- return fail("Cannot wait on own process");
821
- }
822
- const timeoutMsInput = input.timeoutMs;
823
- if (timeoutMsInput !== undefined &&
824
- (typeof timeoutMsInput !== "number" || Number.isNaN(timeoutMsInput))) {
825
- return fail("Invalid timeoutMs: must be a number");
826
- }
827
- const timeoutInput = input.timeout;
828
- if (timeoutInput !== undefined &&
829
- (typeof timeoutInput !== "number" || Number.isNaN(timeoutInput))) {
830
- return fail("Invalid timeout: must be a number");
831
- }
832
- const timeoutMs = Math.min(Math.max(0, timeoutMsInput ?? timeoutInput ?? 30_000), 300_000);
833
- if (!ctx.processRegistry) {
834
- return fail("Process registry not available");
835
- }
836
- if (typeof ctx.processRegistry.waitForExit !== "function") {
837
- return fail("Process registry does not support waiting");
838
- }
839
- const startedAt = Date.now();
840
- const waitResult = await ctx.processRegistry.waitForExit(pid, timeoutMs);
841
- const waitedMs = Math.max(0, Date.now() - startedAt);
842
- if (waitResult.status === "not_found" || !waitResult.process) {
843
- return fail(`Process not tracked: ${pid}`, {
844
- pid,
845
- exited: false,
846
- status: "not_found",
847
- timedOut: false,
848
- waitedMs,
849
- });
850
- }
851
- const data = mapWaitResult(waitResult, waitedMs);
852
- if (waitResult.status === "running" || waitResult.timedOut) {
853
- return fail(`Timed out waiting for process ${pid}`, data);
854
- }
855
- return success(`Process ${pid} exited`, data);
856
- }
857
- function mapWaitResult(waitResult, waitedMs) {
858
- const processInfo = waitResult.process;
859
- const status = waitResult.status === "exited" ? "exited" : "running";
860
- return {
861
- pid: waitResult.pid,
862
- status,
863
- exited: status === "exited",
864
- timedOut: waitResult.timedOut,
865
- waitedMs,
866
- command: processInfo.command,
867
- args: processInfo.args,
868
- cwd: processInfo.cwd,
869
- interactive: processInfo.interactive,
870
- startedAt: processInfo.startedAt,
871
- endedAt: processInfo.endedAt,
872
- runtimeMs: processInfo.runtimeMs,
873
- exitCode: processInfo.exitCode,
874
- signal: processInfo.signal,
875
- };
876
- }
877
- function toRecord(rawInput) {
878
- if (!rawInput || typeof rawInput !== "object") {
879
- return undefined;
880
- }
881
- return rawInput;
882
- }
883
- /**
884
- * Sends input to an interactive PTY session by PID.
885
- * Requires the process to have been spawned with interactive=true.
886
- */
887
- export async function executeWriteStdin(rawInput, ctx) {
888
- // Validate input shape at runtime
889
- if (!rawInput || typeof rawInput !== "object") {
890
- return fail("Invalid input: expected an object");
891
- }
892
- const input = rawInput;
893
- const pid = typeof input.pid === "number" ? input.pid : NaN;
894
- const inputStr = typeof input.input === "string" ? input.input : undefined;
895
- const timeout = typeof input.timeout === "number" ? input.timeout : undefined;
896
- // Validate PID
897
- if (!pid || pid <= 0 || !Number.isInteger(pid)) {
898
- return fail("Invalid PID: must be a positive integer");
899
- }
900
- if (pid === process.pid) {
901
- return fail("Cannot write to own process");
902
- }
903
- // Validate input string
904
- if (inputStr === undefined) {
905
- return fail("Input must be a string");
906
- }
907
- // Look up PTY session store
908
- if (!ctx.ptySessionStore) {
909
- return fail("PTY session store not available");
910
- }
911
- if (!ctx.ptySessionStore.has(pid)) {
912
- return fail(`No interactive session found for PID ${pid}. Use spawn with interactive=true first.`);
913
- }
914
- // The ptySessionStore ref uses `unknown` return to avoid circular deps,
915
- // but the concrete store returns PTYSession instances.
916
- const session = ctx.ptySessionStore.get(pid);
917
- if (!session) {
918
- return fail(`No interactive session found for PID ${pid}. Use spawn with interactive=true first.`);
919
- }
920
- if (!session.isRunning) {
921
- return fail(`Process ${pid} has exited (code: ${session.exitCode ?? "unknown"})`);
922
- }
923
- try {
924
- // Capture output length before write to extract new output after
925
- const outputLenBefore = session.output.length;
926
- // Write input to the PTY session
927
- session.write(inputStr);
928
- // If timeout specified, poll for new output with early return
929
- if (timeout && timeout > 0) {
930
- const waitMs = Math.min(timeout, 30_000);
931
- const deadline = Date.now() + waitMs;
932
- const pollInterval = 50; // Check every 50ms
933
- while (Date.now() < deadline) {
934
- await new Promise((resolve) => setTimeout(resolve, pollInterval));
935
- if (session.output.length > outputLenBefore)
936
- break;
937
- if (!session.isRunning)
938
- break;
939
- }
940
- }
941
- // Extract output produced after the write
942
- const fullOutput = session.output;
943
- const newOutput = fullOutput.slice(outputLenBefore);
944
- // Cap returned output to 10KB to avoid bloating tool results
945
- const cappedOutput = newOutput.length > 10_000 ? newOutput.slice(-10_000) : newOutput;
946
- return success(`Wrote ${inputStr.length} bytes to PID ${pid}`, {
947
- output: cappedOutput,
948
- });
949
- }
950
- catch (error) {
951
- const msg = error instanceof Error ? error.message : String(error);
952
- return fail(`Failed to write to PID ${pid}: ${msg}`);
953
- }
954
- }