@blogic-cz/agent-tools 0.16.0 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/dist/audit-tool/index.d.ts +3 -0
  2. package/dist/audit-tool/index.d.ts.map +1 -0
  3. package/dist/az-tool/build.d.ts +47 -0
  4. package/dist/az-tool/build.d.ts.map +1 -0
  5. package/dist/az-tool/config.d.ts +13 -0
  6. package/dist/az-tool/config.d.ts.map +1 -0
  7. package/dist/az-tool/errors.d.ts +43 -0
  8. package/dist/az-tool/errors.d.ts.map +1 -0
  9. package/dist/az-tool/extract-option-value.d.ts +2 -0
  10. package/dist/az-tool/extract-option-value.d.ts.map +1 -0
  11. package/dist/az-tool/index.d.ts +3 -0
  12. package/dist/az-tool/index.d.ts.map +1 -0
  13. package/dist/az-tool/security.d.ts +4 -0
  14. package/dist/az-tool/security.d.ts.map +1 -0
  15. package/dist/az-tool/service.d.ts +15 -0
  16. package/dist/az-tool/service.d.ts.map +1 -0
  17. package/dist/az-tool/transformers.d.ts +10 -0
  18. package/dist/az-tool/transformers.d.ts.map +1 -0
  19. package/dist/az-tool/types.d.ts +64 -0
  20. package/dist/az-tool/types.d.ts.map +1 -0
  21. package/dist/config/index.d.ts +4 -0
  22. package/dist/config/index.d.ts.map +1 -0
  23. package/dist/config/loader.d.ts +22 -0
  24. package/dist/config/loader.d.ts.map +1 -0
  25. package/dist/config/types.d.ts +189 -0
  26. package/dist/config/types.d.ts.map +1 -0
  27. package/dist/credential-guard/claude-hook.d.ts +13 -0
  28. package/dist/credential-guard/claude-hook.d.ts.map +1 -0
  29. package/dist/credential-guard/index.d.ts +77 -0
  30. package/dist/credential-guard/index.d.ts.map +1 -0
  31. package/dist/db-tool/config-service.d.ts +25 -0
  32. package/dist/db-tool/config-service.d.ts.map +1 -0
  33. package/dist/db-tool/errors.d.ts +41 -0
  34. package/dist/db-tool/errors.d.ts.map +1 -0
  35. package/dist/db-tool/index.d.ts +3 -0
  36. package/dist/db-tool/index.d.ts.map +1 -0
  37. package/dist/db-tool/schema.d.ts +21 -0
  38. package/dist/db-tool/schema.d.ts.map +1 -0
  39. package/dist/db-tool/security.d.ts +23 -0
  40. package/dist/db-tool/security.d.ts.map +1 -0
  41. package/dist/db-tool/service.d.ts +18 -0
  42. package/dist/db-tool/service.d.ts.map +1 -0
  43. package/dist/db-tool/sql-client.d.ts +24 -0
  44. package/dist/db-tool/sql-client.d.ts.map +1 -0
  45. package/dist/db-tool/transformers.d.ts +10 -0
  46. package/dist/db-tool/transformers.d.ts.map +1 -0
  47. package/dist/db-tool/types.d.ts +37 -0
  48. package/dist/db-tool/types.d.ts.map +1 -0
  49. package/dist/gh-tool/branch.d.ts +18 -0
  50. package/dist/gh-tool/branch.d.ts.map +1 -0
  51. package/dist/gh-tool/config.d.ts +7 -0
  52. package/dist/gh-tool/config.d.ts.map +1 -0
  53. package/dist/gh-tool/errors.d.ts +51 -0
  54. package/dist/gh-tool/errors.d.ts.map +1 -0
  55. package/dist/gh-tool/index.d.ts +3 -0
  56. package/dist/gh-tool/index.d.ts.map +1 -0
  57. package/dist/gh-tool/issue/commands.d.ts +68 -0
  58. package/dist/gh-tool/issue/commands.d.ts.map +1 -0
  59. package/dist/gh-tool/issue/core.d.ts +82 -0
  60. package/dist/gh-tool/issue/core.d.ts.map +1 -0
  61. package/dist/gh-tool/issue/index.d.ts +3 -0
  62. package/dist/gh-tool/issue/index.d.ts.map +1 -0
  63. package/dist/gh-tool/issue/triage.d.ts +89 -0
  64. package/dist/gh-tool/issue/triage.d.ts.map +1 -0
  65. package/dist/gh-tool/pr/commands.d.ts +384 -0
  66. package/dist/gh-tool/pr/commands.d.ts.map +1 -0
  67. package/dist/gh-tool/pr/core.d.ts +236 -0
  68. package/dist/gh-tool/pr/core.d.ts.map +1 -0
  69. package/dist/gh-tool/pr/helpers.d.ts +27 -0
  70. package/dist/gh-tool/pr/helpers.d.ts.map +1 -0
  71. package/dist/gh-tool/pr/index.d.ts +2 -0
  72. package/dist/gh-tool/pr/index.d.ts.map +1 -0
  73. package/dist/gh-tool/pr/review.d.ts +90 -0
  74. package/dist/gh-tool/pr/review.d.ts.map +1 -0
  75. package/dist/gh-tool/release.d.ts +52 -0
  76. package/dist/gh-tool/release.d.ts.map +1 -0
  77. package/dist/gh-tool/repo.d.ts +21 -0
  78. package/dist/gh-tool/repo.d.ts.map +1 -0
  79. package/dist/gh-tool/service.d.ts +25 -0
  80. package/dist/gh-tool/service.d.ts.map +1 -0
  81. package/dist/gh-tool/text-input.d.ts +22 -0
  82. package/dist/gh-tool/text-input.d.ts.map +1 -0
  83. package/dist/gh-tool/types.d.ts +271 -0
  84. package/dist/gh-tool/types.d.ts.map +1 -0
  85. package/dist/gh-tool/workflow.d.ts +157 -0
  86. package/dist/gh-tool/workflow.d.ts.map +1 -0
  87. package/dist/index.d.ts +4 -0
  88. package/dist/index.d.ts.map +1 -0
  89. package/dist/k8s-tool/context.d.ts +26 -0
  90. package/dist/k8s-tool/context.d.ts.map +1 -0
  91. package/dist/k8s-tool/errors.d.ts +43 -0
  92. package/dist/k8s-tool/errors.d.ts.map +1 -0
  93. package/dist/k8s-tool/index.d.ts +3 -0
  94. package/dist/k8s-tool/index.d.ts.map +1 -0
  95. package/dist/k8s-tool/profile.d.ts +3 -0
  96. package/dist/k8s-tool/profile.d.ts.map +1 -0
  97. package/dist/k8s-tool/security.d.ts +14 -0
  98. package/dist/k8s-tool/security.d.ts.map +1 -0
  99. package/dist/k8s-tool/service.d.ts +16 -0
  100. package/dist/k8s-tool/service.d.ts.map +1 -0
  101. package/dist/k8s-tool/transformers.d.ts +23 -0
  102. package/dist/k8s-tool/transformers.d.ts.map +1 -0
  103. package/dist/k8s-tool/types.d.ts +13 -0
  104. package/dist/k8s-tool/types.d.ts.map +1 -0
  105. package/dist/logs-tool/errors.d.ts +40 -0
  106. package/dist/logs-tool/errors.d.ts.map +1 -0
  107. package/dist/logs-tool/index.d.ts +21 -0
  108. package/dist/logs-tool/index.d.ts.map +1 -0
  109. package/dist/logs-tool/service.d.ts +17 -0
  110. package/dist/logs-tool/service.d.ts.map +1 -0
  111. package/dist/logs-tool/transformers.d.ts +2 -0
  112. package/dist/logs-tool/transformers.d.ts.map +1 -0
  113. package/dist/logs-tool/types.d.ts +39 -0
  114. package/dist/logs-tool/types.d.ts.map +1 -0
  115. package/dist/observability-tool/errors.d.ts +8 -0
  116. package/dist/observability-tool/errors.d.ts.map +1 -0
  117. package/dist/observability-tool/index.d.ts +3 -0
  118. package/dist/observability-tool/index.d.ts.map +1 -0
  119. package/dist/observability-tool/logs.d.ts +22 -0
  120. package/dist/observability-tool/logs.d.ts.map +1 -0
  121. package/dist/observability-tool/metrics.d.ts +3 -0
  122. package/dist/observability-tool/metrics.d.ts.map +1 -0
  123. package/dist/observability-tool/shared.d.ts +18 -0
  124. package/dist/observability-tool/shared.d.ts.map +1 -0
  125. package/dist/observability-tool/trace.d.ts +3 -0
  126. package/dist/observability-tool/trace.d.ts.map +1 -0
  127. package/dist/observability-tool/types.d.ts +171 -0
  128. package/dist/observability-tool/types.d.ts.map +1 -0
  129. package/dist/session-tool/claude-code.d.ts +46 -0
  130. package/dist/session-tool/claude-code.d.ts.map +1 -0
  131. package/dist/session-tool/codex.d.ts +44 -0
  132. package/dist/session-tool/codex.d.ts.map +1 -0
  133. package/dist/session-tool/config.d.ts +29 -0
  134. package/dist/session-tool/config.d.ts.map +1 -0
  135. package/dist/session-tool/errors.d.ts +27 -0
  136. package/dist/session-tool/errors.d.ts.map +1 -0
  137. package/dist/session-tool/index.d.ts +13 -0
  138. package/dist/session-tool/index.d.ts.map +1 -0
  139. package/dist/session-tool/pi.d.ts +40 -0
  140. package/dist/session-tool/pi.d.ts.map +1 -0
  141. package/dist/session-tool/service.d.ts +18 -0
  142. package/dist/session-tool/service.d.ts.map +1 -0
  143. package/dist/session-tool/summaries.d.ts +5 -0
  144. package/dist/session-tool/summaries.d.ts.map +1 -0
  145. package/dist/session-tool/types.d.ts +38 -0
  146. package/dist/session-tool/types.d.ts.map +1 -0
  147. package/dist/shared/audit.d.ts +40 -0
  148. package/dist/shared/audit.d.ts.map +1 -0
  149. package/dist/shared/binary-preflight.d.ts +27 -0
  150. package/dist/shared/binary-preflight.d.ts.map +1 -0
  151. package/dist/shared/bun.d.ts +4 -0
  152. package/dist/shared/bun.d.ts.map +1 -0
  153. package/dist/shared/cli.d.ts +18 -0
  154. package/dist/shared/cli.d.ts.map +1 -0
  155. package/dist/shared/env-template.d.ts +9 -0
  156. package/dist/shared/env-template.d.ts.map +1 -0
  157. package/dist/shared/error-renderer.d.ts +4 -0
  158. package/dist/shared/error-renderer.d.ts.map +1 -0
  159. package/dist/shared/exec.d.ts +30 -0
  160. package/dist/shared/exec.d.ts.map +1 -0
  161. package/dist/shared/format.d.ts +7 -0
  162. package/dist/shared/format.d.ts.map +1 -0
  163. package/dist/shared/index.d.ts +12 -0
  164. package/dist/shared/index.d.ts.map +1 -0
  165. package/dist/shared/k8s-probe.d.ts +11 -0
  166. package/dist/shared/k8s-probe.d.ts.map +1 -0
  167. package/dist/shared/log-transform.d.ts +2 -0
  168. package/dist/shared/log-transform.d.ts.map +1 -0
  169. package/dist/shared/path.d.ts +2 -0
  170. package/dist/shared/path.d.ts.map +1 -0
  171. package/dist/shared/prerequisites/config.d.ts +6 -0
  172. package/dist/shared/prerequisites/config.d.ts.map +1 -0
  173. package/dist/shared/prerequisites/driver-commands.d.ts +19 -0
  174. package/dist/shared/prerequisites/driver-commands.d.ts.map +1 -0
  175. package/dist/shared/prerequisites/errors.d.ts +10 -0
  176. package/dist/shared/prerequisites/errors.d.ts.map +1 -0
  177. package/dist/shared/prerequisites/guardian-entry.d.ts +2 -0
  178. package/dist/shared/prerequisites/guardian-entry.d.ts.map +1 -0
  179. package/dist/shared/prerequisites/guardian.d.ts +41 -0
  180. package/dist/shared/prerequisites/guardian.d.ts.map +1 -0
  181. package/dist/shared/prerequisites/index.d.ts +6 -0
  182. package/dist/shared/prerequisites/index.d.ts.map +1 -0
  183. package/dist/shared/prerequisites/runtime.d.ts +26 -0
  184. package/dist/shared/prerequisites/runtime.d.ts.map +1 -0
  185. package/dist/shared/prerequisites/store.d.ts +99 -0
  186. package/dist/shared/prerequisites/store.d.ts.map +1 -0
  187. package/dist/shared/prerequisites/types.d.ts +39 -0
  188. package/dist/shared/prerequisites/types.d.ts.map +1 -0
  189. package/dist/shared/prerequisites/vpn.d.ts +5 -0
  190. package/dist/shared/prerequisites/vpn.d.ts.map +1 -0
  191. package/dist/shared/schema-dump.d.ts +27 -0
  192. package/dist/shared/schema-dump.d.ts.map +1 -0
  193. package/dist/shared/throttle.d.ts +17 -0
  194. package/dist/shared/throttle.d.ts.map +1 -0
  195. package/dist/shared/transform.d.ts +49 -0
  196. package/dist/shared/transform.d.ts.map +1 -0
  197. package/dist/shared/types.d.ts +30 -0
  198. package/dist/shared/types.d.ts.map +1 -0
  199. package/package.json +77 -20
  200. package/src/az-tool/service.ts +30 -23
  201. package/src/k8s-tool/context.ts +73 -0
  202. package/src/k8s-tool/service.ts +34 -62
  203. package/src/logs-tool/service.ts +78 -87
  204. package/src/shared/bun.ts +0 -7
  205. package/src/shared/exec.ts +58 -4
  206. package/src/shared/index.ts +2 -2
@@ -1,6 +1,6 @@
1
- import { isAbsolute, posix, relative, resolve } from "node:path";
1
+ import { readFile, readdir, realpath, stat } from "node:fs/promises";
2
+ import { isAbsolute, join, posix, relative, resolve } from "node:path";
2
3
 
3
- import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
4
4
  import { Context, Effect, Layer, Result } from "effect";
5
5
 
6
6
  import type { Environment, LogFile, ReadOptions } from "./types";
@@ -9,7 +9,6 @@ import { K8sService, K8sServiceLayer } from "#k8s/service";
9
9
  import { ConfigService, ConfigServiceLayer, getToolConfig } from "#config/loader";
10
10
  import type { LogsConfig } from "#config/types";
11
11
  import { LogsNotFoundError, LogsReadError, type LogsError } from "./errors";
12
- import { collectProcessOutput } from "#shared/exec";
13
12
  import { transformLogOutput } from "./transformers";
14
13
 
15
14
  export const parseLogFiles = (output: string): LogFile[] => {
@@ -41,11 +40,36 @@ export const formatPrettyOutput = (output: string): string => {
41
40
  .join("\n---\n");
42
41
  };
43
42
 
44
- /**
45
- * Sanitize a string for safe use in shell commands by escaping single quotes
46
- * and wrapping in single quotes. This prevents shell injection.
47
- */
48
- export const sanitizeShellArg = (input: string): string => `'${input.replace(/'/g, "'\\''")}'`;
43
+ const errorText = (error: unknown): string =>
44
+ error instanceof Error ? error.message : String(error);
45
+
46
+ const takeLastLines = (contents: string, lines: number): string => {
47
+ const all = contents.split("\n");
48
+ const withoutTrailingBlank = all.at(-1) === "" ? all.slice(0, -1) : all;
49
+ return withoutTrailingBlank.slice(-lines).join("\n");
50
+ };
51
+
52
+ /** Newest first, so callers can take the head as the latest log the way `ls -t` did. */
53
+ const readLocalLogDirectory = async (localDir: string): Promise<LogFile[]> => {
54
+ const entries = await readdir(localDir, { withFileTypes: true });
55
+ const logs = entries.filter((entry) => !entry.isDirectory() && entry.name.endsWith(".log"));
56
+
57
+ const described = await Promise.all(
58
+ logs.map(async (entry) => {
59
+ const stats = await stat(join(localDir, entry.name));
60
+ return {
61
+ name: entry.name,
62
+ size: String(stats.size),
63
+ date: stats.mtime.toISOString(),
64
+ modifiedAtMs: stats.mtimeMs,
65
+ };
66
+ }),
67
+ );
68
+
69
+ return described
70
+ .toSorted((left, right) => right.modifiedAtMs - left.modifiedAtMs)
71
+ .map(({ name, size, date }) => ({ name, size, date }));
72
+ };
49
73
 
50
74
  const readCommandOutput = (output: unknown): string => (typeof output === "string" ? output : "");
51
75
  const filterLogLines = (output: string, grep: string | undefined): string => {
@@ -91,45 +115,8 @@ export class LogsService extends Context.Service<
91
115
  LogsService,
92
116
  Effect.gen(function* () {
93
117
  const k8s = yield* K8sService;
94
- const executor = yield* ChildProcessSpawner.ChildProcessSpawner;
95
118
  const config = yield* ConfigService;
96
119
 
97
- const runShellCommand = (commandStr: string) =>
98
- Effect.scoped(
99
- Effect.gen(function* () {
100
- const command = ChildProcess.make("sh", ["-c", commandStr], {
101
- stdout: "pipe",
102
- stderr: "pipe",
103
- });
104
- const process = yield* executor.spawn(command);
105
- return yield* collectProcessOutput(process);
106
- }),
107
- ).pipe(
108
- Effect.catch((platformError) =>
109
- Effect.succeed({
110
- stdout: "",
111
- stderr: String(platformError),
112
- exitCode: -1,
113
- }),
114
- ),
115
- );
116
-
117
- const runDirectCommand = (executable: string, args: readonly string[]) =>
118
- Effect.scoped(
119
- Effect.gen(function* () {
120
- const command = ChildProcess.make(executable, args, {
121
- stdout: "pipe",
122
- stderr: "pipe",
123
- });
124
- const process = yield* executor.spawn(command);
125
- return yield* collectProcessOutput(process);
126
- }),
127
- ).pipe(
128
- Effect.catch((platformError) =>
129
- Effect.succeed({ stdout: "", stderr: String(platformError), exitCode: -1 }),
130
- ),
131
- );
132
-
133
120
  const getLogsConfig = (profile?: string): LogsConfig | undefined =>
134
121
  getToolConfig<LogsConfig>(config, "logs", profile);
135
122
 
@@ -137,16 +124,16 @@ export class LogsService extends Context.Service<
137
124
  logsConfig: LogsConfig,
138
125
  ) {
139
126
  const localDir = logsConfig.localDir;
140
- const result = yield* runShellCommand(`ls -la ${localDir}`);
141
-
142
- if (result.exitCode !== 0) {
143
- return yield* new LogsReadError({
144
- message: result.stderr.trim() || "Failed to list local logs",
145
- source: localDir,
146
- });
147
- }
127
+ const files = yield* Effect.tryPromise(() => readLocalLogDirectory(localDir)).pipe(
128
+ Effect.mapError(
129
+ (error) =>
130
+ new LogsReadError({
131
+ message: errorText(error) || "Failed to list local logs",
132
+ source: localDir,
133
+ }),
134
+ ),
135
+ );
148
136
 
149
- const files = parseLogFiles(result.stdout);
150
137
  if (files.length === 0) {
151
138
  return yield* new LogsNotFoundError({
152
139
  message: "No log files found",
@@ -213,24 +200,25 @@ export class LogsService extends Context.Service<
213
200
  let logFile = options.file;
214
201
 
215
202
  if (!logFile) {
216
- const latest = yield* runShellCommand(`ls -t ${localDir}/*.log 2>/dev/null | head -1`);
217
-
218
- if (latest.exitCode !== 0) {
219
- return yield* new LogsReadError({
220
- message: latest.stderr.trim() || "Failed to find latest log",
221
- source: localDir,
222
- });
223
- }
203
+ const files = yield* Effect.tryPromise(() => readLocalLogDirectory(localDir)).pipe(
204
+ Effect.mapError(
205
+ (error) =>
206
+ new LogsReadError({
207
+ message: errorText(error) || "Failed to find latest log",
208
+ source: localDir,
209
+ }),
210
+ ),
211
+ );
224
212
 
225
- const latestPath = latest.stdout.trim();
226
- if (!latestPath) {
213
+ const latest = files[0];
214
+ if (!latest) {
227
215
  return yield* new LogsNotFoundError({
228
216
  message: "No log files found",
229
217
  path: localDir,
230
218
  });
231
219
  }
232
220
 
233
- logFile = latestPath.split("/").pop() ?? latestPath;
221
+ logFile = latest.name;
234
222
  }
235
223
 
236
224
  const lexicalPath = resolveLocalLogPath(localDir, logFile);
@@ -240,20 +228,22 @@ export class LogsService extends Context.Service<
240
228
  source: localDir,
241
229
  });
242
230
  }
243
- const realpathResult = yield* runDirectCommand("realpath", [localDir, lexicalPath]);
244
- if (realpathResult.exitCode !== 0) {
245
- return yield* new LogsReadError({
246
- message:
247
- realpathResult.stderr.trim() ||
248
- `realpath failed with exit code ${realpathResult.exitCode}`,
249
- source: lexicalPath,
250
- });
251
- }
252
- const [canonicalBase, canonicalPath] = realpathResult.stdout.trim().split("\n");
231
+ const canonical = yield* Effect.tryPromise(async () => ({
232
+ base: await realpath(localDir),
233
+ path: await realpath(lexicalPath),
234
+ })).pipe(
235
+ Effect.mapError(
236
+ (error) =>
237
+ new LogsReadError({
238
+ message: errorText(error) || "Failed to canonicalize the log path",
239
+ source: lexicalPath,
240
+ }),
241
+ ),
242
+ );
243
+
244
+ const canonicalPath = canonical.path;
253
245
  if (
254
- canonicalBase === undefined ||
255
- canonicalPath === undefined ||
256
- resolveLocalLogPath(canonicalBase, canonicalPath) !== canonicalPath ||
246
+ resolveLocalLogPath(canonical.base, canonicalPath) !== canonicalPath ||
257
247
  !canonicalPath.endsWith(".log")
258
248
  ) {
259
249
  return yield* new LogsReadError({
@@ -261,17 +251,18 @@ export class LogsService extends Context.Service<
261
251
  source: localDir,
262
252
  });
263
253
  }
264
- const command = `tail -${options.tail} ${sanitizeShellArg(canonicalPath)}`;
265
- const result = yield* runShellCommand(command);
266
254
 
267
- if (result.exitCode !== 0) {
268
- return yield* new LogsReadError({
269
- message: result.stderr.trim() || `Command failed with exit code ${result.exitCode}`,
270
- source: canonicalPath,
271
- });
272
- }
255
+ const contents = yield* Effect.tryPromise(() => readFile(canonicalPath, "utf8")).pipe(
256
+ Effect.mapError(
257
+ (error) =>
258
+ new LogsReadError({
259
+ message: errorText(error) || "Failed to read the log file",
260
+ source: canonicalPath,
261
+ }),
262
+ ),
263
+ );
273
264
 
274
- const output = filterLogLines(result.stdout, options.grep).trim();
265
+ const output = filterLogLines(takeLastLines(contents, options.tail), options.grep).trim();
275
266
  if (!output) {
276
267
  return "(no matching lines)";
277
268
  }
package/src/shared/bun.ts CHANGED
@@ -50,10 +50,3 @@ export async function runCommand(
50
50
  executionTimeMs: Date.now() - startTime,
51
51
  };
52
52
  }
53
-
54
- export function runShellCommand(
55
- command: string,
56
- options: CommandOptions = {},
57
- ): Promise<CommandResult> {
58
- return runCommand(["sh", "-c", command], options);
59
- }
@@ -23,18 +23,21 @@ export const collectProcessOutput = (process: ChildProcessSpawner.ChildProcessHa
23
23
  });
24
24
 
25
25
  export const execEffect = (
26
- commandStr: string,
26
+ executable: string,
27
+ args: readonly string[] = [],
27
28
  timeoutMs: number = DEFAULT_TIMEOUT_MS,
28
29
  ): Effect.Effect<
29
30
  { stdout: string; stderr: string; exitCode: number },
30
31
  ExecError,
31
32
  ChildProcessSpawner.ChildProcessSpawner
32
- > =>
33
- Effect.scoped(
33
+ > => {
34
+ const commandStr = renderCommandLine([executable, ...args]);
35
+
36
+ return Effect.scoped(
34
37
  Effect.gen(function* () {
35
38
  const executor = yield* ChildProcessSpawner.ChildProcessSpawner;
36
39
 
37
- const command = ChildProcess.make("sh", ["-c", commandStr], {
40
+ const command = ChildProcess.make(executable, args, {
38
41
  stdout: "pipe",
39
42
  stderr: "pipe",
40
43
  });
@@ -67,5 +70,56 @@ export const execEffect = (
67
70
  ),
68
71
  ),
69
72
  );
73
+ };
70
74
 
71
75
  export const quoteShellArg = (value: string) => `'${value.replaceAll("'", "'\\''")}'`;
76
+
77
+ /**
78
+ * Split a command line the way a POSIX shell would word-split it, without running one.
79
+ * Quotes group a value into a single argument and are removed; nothing else is interpreted,
80
+ * so a metacharacter reaches the child as literal text instead of shell syntax.
81
+ */
82
+ export const tokenizeCommandLine = (commandLine: string): string[] => {
83
+ const tokens: string[] = [];
84
+ let current = "";
85
+ let started = false;
86
+ let quote: '"' | "'" | undefined;
87
+
88
+ for (const character of commandLine) {
89
+ if (quote) {
90
+ if (character === quote) {
91
+ quote = undefined;
92
+ } else {
93
+ current += character;
94
+ }
95
+ continue;
96
+ }
97
+
98
+ if (character === '"' || character === "'") {
99
+ quote = character;
100
+ started = true;
101
+ continue;
102
+ }
103
+
104
+ if (/\s/.test(character)) {
105
+ if (started) {
106
+ tokens.push(current);
107
+ current = "";
108
+ started = false;
109
+ }
110
+ continue;
111
+ }
112
+
113
+ current += character;
114
+ started = true;
115
+ }
116
+
117
+ if (started) {
118
+ tokens.push(current);
119
+ }
120
+
121
+ return tokens;
122
+ };
123
+
124
+ export const renderCommandLine = (argv: readonly string[]): string =>
125
+ argv.map((arg) => (/^[A-Za-z0-9_./:=,@+-]+$/.test(arg) ? arg : quoteShellArg(arg))).join(" ");
@@ -9,7 +9,7 @@ export type {
9
9
 
10
10
  export { formatAny, formatOption, formatOutput, logFormatted } from "./format";
11
11
 
12
- export { expandPath, runCommand, runShellCommand } from "./bun";
12
+ export { expandPath, runCommand } from "./bun";
13
13
 
14
14
  export { commonArgOptions, parseCommonArgs } from "./cli";
15
15
 
@@ -21,7 +21,7 @@ export { dumpCommandSchema, makeSchemaCommand, type CommandSchema } from "./sche
21
21
  import pkg from "../../package.json" with { type: "json" };
22
22
  export const VERSION = pkg.version;
23
23
 
24
- export { execEffect, type ExecError } from "./exec";
24
+ export { execEffect, renderCommandLine, tokenizeCommandLine, type ExecError } from "./exec";
25
25
 
26
26
  export { createThrottle, type ThrottleError } from "./throttle";
27
27