xonecas.io
64875
Mc

mini-coder / commit d744b78

feat: typebox validation at boundaries and post-implementation fixes

xonecas2026-09-22 d744b78b669d4e99061abf441fb9fba22e911870 parent 56a638c

8 files changed

package-lock.json+2−1
@@ -10,7 +10,8 @@
1010 "license": "MIT",
1111 "dependencies": {
1212 "@earendil-works/pi-ai": "0.87.0",
13- "diff": "^8.0.2"
13+ "diff": "^8.0.2",
14+ "typebox": "1.3.27"
1415 },
1516 "bin": {
1617 "mini-coder": "bin/mini-coder.ts"
package.json+2−1
@@ -13,7 +13,8 @@
1313 },
1414 "dependencies": {
1515 "@earendil-works/pi-ai": "0.87.0",
16- "diff": "^8.0.2"
16+ "diff": "^8.0.2",
17+ "typebox": "1.3.27"
1718 },
1819 "devDependencies": {
1920 "@types/node": "^22.19.19",
src/agent.ts+6−6
@@ -1,5 +1,4 @@
11 import {
2- validateToolCall,
32 type Api,
43 type AssistantMessage,
54 type Message,
@@ -12,7 +11,7 @@ import {
1211 type UserMessage,
1312 } from "@earendil-works/pi-ai";
1413 import type { Session } from "./session.ts";
15-import { executeTool, type ToolResult } from "./tools.ts";
14+import { executeTool, type ToolDetails, type ToolResult } from "./tools.ts";
1615 import type { ToolName } from "./config.ts";
1716
1817 export type Phase = "preparing" | "waitingModel" | "streaming" | "runningTool" | "pausing" | "idle";
@@ -152,13 +151,13 @@ export async function runAgentTurn(run: AgentRun): Promise<void> {
152151 }
153152 onEvent({ type: "phase", phase: "runningTool", detail: call.name });
154153
154+ const tool = run.toolNames.find((name) => name === call.name);
155155 let result: ToolResult;
156- if (!run.toolNames.includes(call.name as ToolName)) {
156+ if (tool === undefined) {
157157 result = { text: `unknown tool: ${call.name}`, isError: true };
158158 } else {
159159 try {
160- const args = validateToolCall(run.tools, call);
161- result = await executeTool(call.name as ToolName, args, {
160+ result = await executeTool(tool, call, {
162161 signal,
163162 onOutput: (chunk) => onEvent({ type: "toolOutput", name: call.name, callId: call.id, chunk }),
164163 });
@@ -167,11 +166,12 @@ export async function runAgentTurn(run: AgentRun): Promise<void> {
167166 }
168167 }
169168
170- const toolMessage: ToolResultMessage = {
169+ const toolMessage: ToolResultMessage<ToolDetails> = {
171170 role: "toolResult",
172171 toolCallId: call.id,
173172 toolName: call.name,
174173 content: [{ type: "text", text: result.text }],
174+ details: result.details,
175175 isError: result.isError,
176176 timestamp: Date.now(),
177177 };
src/cli.ts+4−6
@@ -56,7 +56,6 @@ async function runPrint(prompt: string, ctx: RunContext): Promise<number> {
5656 process.on("SIGINT", onSignal);
5757 process.on("SIGTERM", onSignal);
5858
59- let last: AssistantMessage | null = null;
6059 let failed = false;
6160 let cancelled = false;
6261 try {
@@ -66,8 +65,7 @@ async function runPrint(prompt: string, ctx: RunContext): Promise<number> {
6665 signal: controller.signal,
6766 interaction: NO_INTERACTION,
6867 onEvent: (event) => {
69- if (event.type === "message") last = event.message;
70- else if (event.type === "toolCall") process.stderr.write(`[tool] ${event.name}\n`);
68+ if (event.type === "toolCall") process.stderr.write(`[tool] ${event.name}\n`);
7169 else if (event.type === "toolOutput") process.stderr.write(event.chunk);
7270 else if (event.type === "error") {
7371 failed = true;
@@ -87,9 +85,9 @@ async function runPrint(prompt: string, ctx: RunContext): Promise<number> {
8785 ctx.session.close();
8886 }
8987
90- if (!failed && !cancelled && last !== null) {
91- const answer = last as AssistantMessage;
92- const text = answer.content
88+ const last = messages.filter((message): message is AssistantMessage => message.role === "assistant").at(-1);
89+ if (!failed && !cancelled && last !== undefined) {
90+ const text = last.content
9391 .filter((block) => block.type === "text")
9492 .map((block) => block.text)
9593 .join("");
src/config.ts+72−138
@@ -2,166 +2,100 @@ import { readFileSync } from "node:fs";
22 import { homedir } from "node:os";
33 import { join } from "node:path";
44 import {
5- createModels,
65 createProvider,
76 envApiKeyAuth,
7+ Type,
88 type Api,
99 type Model,
1010 type MutableModels,
11- type ThinkingLevel,
11+ type Static,
1212 } from "@earendil-works/pi-ai";
13+import { Value } from "typebox/value";
1314 import { builtinModels } from "@earendil-works/pi-ai/providers/all";
1415 import { anthropicMessagesApi } from "@earendil-works/pi-ai/api/anthropic-messages.lazy";
1516 import { googleGenerativeAIApi } from "@earendil-works/pi-ai/api/google-generative-ai.lazy";
1617 import { openAICompletionsApi } from "@earendil-works/pi-ai/api/openai-completions.lazy";
1718 import { openAIResponsesApi } from "@earendil-works/pi-ai/api/openai-responses.lazy";
1819
19-export const CUSTOM_APIS = [
20- "openai-completions",
21- "openai-responses",
22- "anthropic-messages",
23- "google-generative-ai",
24-] as const;
25-export type CustomApi = (typeof CUSTOM_APIS)[number];
26-
27-export const TOOL_NAMES = ["edit", "bash"] as const;
28-export type ToolName = (typeof TOOL_NAMES)[number];
29-
30-export interface CustomProviderConfig {
31- id: string;
32- name?: string;
33- baseUrl: string;
34- api: CustomApi;
35- models: string[];
36- envKeys?: string[];
37- headers?: Record<string, string>;
38-}
39-
40-export interface Config {
41- sessionsDir: string;
42- systemPrompt: string;
43- discoverAgentFiles: boolean;
44- skillsDirs: string[];
45- tools: ToolName[];
46- provider: string;
47- model: string;
48- thinkingEffort: ThinkingLevel;
49- customProviders: CustomProviderConfig[];
50-}
51-
52-const THINKING_LEVELS: ThinkingLevel[] = [
53- "minimal",
54- "low",
55- "medium",
56- "high",
57- "xhigh",
58- "max",
59-];
60-
61-export function configPath(): string {
20+const ToolNameSchema = Type.Union([Type.Literal("edit"), Type.Literal("bash")]);
21+export type ToolName = Static<typeof ToolNameSchema>;
22+
23+const CustomApiSchema = Type.Union([
24+ Type.Literal("openai-completions"),
25+ Type.Literal("openai-responses"),
26+ Type.Literal("anthropic-messages"),
27+ Type.Literal("google-generative-ai"),
28+]);
29+type CustomApi = Static<typeof CustomApiSchema>;
30+
31+const CustomProviderSchema = Type.Object(
32+ {
33+ id: Type.String({ minLength: 1 }),
34+ name: Type.Optional(Type.String()),
35+ baseUrl: Type.String({ minLength: 1 }),
36+ api: CustomApiSchema,
37+ models: Type.Array(Type.String(), { minItems: 1 }),
38+ envKeys: Type.Optional(Type.Array(Type.String())),
39+ headers: Type.Optional(Type.Record(Type.String(), Type.String())),
40+ },
41+ { additionalProperties: false },
42+);
43+
44+const ConfigSchema = Type.Object(
45+ {
46+ sessionsDir: Type.String({ default: join(process.cwd(), "sessions") }),
47+ systemPrompt: Type.String({ default: "" }),
48+ discoverAgentFiles: Type.Boolean({ default: true }),
49+ skillsDirs: Type.Array(Type.String(), { default: [] }),
50+ tools: Type.Array(ToolNameSchema, { default: ["edit", "bash"] }),
51+ provider: Type.String({ default: "anthropic" }),
52+ model: Type.String({ default: "claude-sonnet-4-5" }),
53+ thinkingEffort: Type.Union(
54+ [
55+ Type.Literal("minimal"),
56+ Type.Literal("low"),
57+ Type.Literal("medium"),
58+ Type.Literal("high"),
59+ Type.Literal("xhigh"),
60+ Type.Literal("max"),
61+ ],
62+ { default: "medium" },
63+ ),
64+ customProviders: Type.Array(CustomProviderSchema, { default: [] }),
65+ },
66+ { additionalProperties: false },
67+);
68+export type Config = Static<typeof ConfigSchema>;
69+
70+function configPath(): string {
6271 const base = process.env.XDG_CONFIG_HOME || join(homedir(), ".config");
6372 return join(base, "mini-coder", "config.json");
6473 }
6574
66-export function loadConfig(): Config {
67- let raw: Record<string, unknown> = {};
68- const path = configPath();
75+function readJson(path: string): unknown {
76+ let text: string;
6977 try {
70- raw = JSON.parse(readFileSync(path, "utf8")) as Record<string, unknown>;
78+ text = readFileSync(path, "utf8");
7179 } catch (error) {
72- if ((error as NodeJS.ErrnoException).code !== "ENOENT") {
73- throw new Error(`config ${path}: ${(error as Error).message}`);
74- }
75- }
76-
77- const tools = raw.tools === undefined ? ["edit", "bash"] : raw.tools;
78- if (!Array.isArray(tools) || tools.some((t) => !TOOL_NAMES.includes(t as ToolName))) {
79- throw new Error(`config tools: expected a subset of ${TOOL_NAMES.join(", ")}`);
80+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return {};
81+ throw new Error(`config ${path}: ${(error as Error).message}`);
8082 }
81-
82- const thinkingEffort = raw.thinkingEffort ?? "medium";
83- if (typeof thinkingEffort !== "string" || !THINKING_LEVELS.includes(thinkingEffort as ThinkingLevel)) {
84- throw new Error(`config thinkingEffort: expected one of ${THINKING_LEVELS.join(", ")}`);
85- }
86-
87- return {
88- sessionsDir: str(raw, "sessionsDir", join(process.cwd(), "sessions")),
89- systemPrompt: str(raw, "systemPrompt", ""),
90- discoverAgentFiles: bool(raw, "discoverAgentFiles", true),
91- skillsDirs: strArray(raw, "skillsDirs", []),
92- tools: tools as ToolName[],
93- provider: str(raw, "provider", "anthropic"),
94- model: str(raw, "model", "claude-sonnet-4-5"),
95- thinkingEffort: thinkingEffort as ThinkingLevel,
96- customProviders: customProviders(raw.customProviders),
97- };
98-}
99-
100-function str(raw: Record<string, unknown>, field: string, fallback: string): string {
101- const value = raw[field];
102- if (value === undefined) return fallback;
103- if (typeof value !== "string") throw new Error(`config ${field}: expected a string`);
104- return value;
105-}
106-
107-function bool(raw: Record<string, unknown>, field: string, fallback: boolean): boolean {
108- const value = raw[field];
109- if (value === undefined) return fallback;
110- if (typeof value !== "boolean") throw new Error(`config ${field}: expected a boolean`);
111- return value;
112-}
113-
114-function strArray(raw: Record<string, unknown>, field: string, fallback: string[]): string[] {
115- const value = raw[field];
116- if (value === undefined) return fallback;
117- if (!Array.isArray(value) || value.some((v) => typeof v !== "string")) {
118- throw new Error(`config ${field}: expected an array of strings`);
83+ try {
84+ return JSON.parse(text);
85+ } catch (error) {
86+ throw new Error(`config ${path}: ${(error as Error).message}`);
11987 }
120- return value as string[];
121-}
122-
123-function customProviders(value: unknown): CustomProviderConfig[] {
124- if (value === undefined) return [];
125- if (!Array.isArray(value)) throw new Error("config customProviders: expected an array");
126- return value.map((entry, index) => {
127- if (typeof entry !== "object" || entry === null) {
128- throw new Error(`config customProviders[${index}]: expected an object`);
129- }
130- const provider = entry as Record<string, unknown>;
131- const where = `config customProviders[${index}]`;
132- const id = provider.id;
133- if (typeof id !== "string" || id.length === 0) throw new Error(`${where}.id: expected a non-empty string`);
134- const baseUrl = provider.baseUrl;
135- if (typeof baseUrl !== "string" || baseUrl.length === 0) throw new Error(`${where}.baseUrl: expected a non-empty string`);
136- const api = provider.api;
137- if (typeof api !== "string" || !CUSTOM_APIS.includes(api as CustomApi)) {
138- throw new Error(`${where}.api: expected one of ${CUSTOM_APIS.join(", ")}`);
139- }
140- const models = provider.models;
141- if (!Array.isArray(models) || models.length === 0 || models.some((m) => typeof m !== "string")) {
142- throw new Error(`${where}.models: expected a non-empty array of strings`);
143- }
144- return {
145- id,
146- name: typeof provider.name === "string" ? provider.name : undefined,
147- baseUrl,
148- api: api as CustomApi,
149- models: models as string[],
150- envKeys: strArray(provider, "envKeys", []),
151- headers: headers(provider.headers, `${where}.headers`),
152- };
153- });
15488 }
15589
156-function headers(value: unknown, where: string): Record<string, string> | undefined {
157- if (value === undefined) return undefined;
158- if (typeof value !== "object" || value === null) throw new Error(`${where}: expected an object`);
159- const out: Record<string, string> = {};
160- for (const [key, val] of Object.entries(value)) {
161- if (typeof val !== "string") throw new Error(`${where}.${key}: expected a string`);
162- out[key] = val;
90+export function loadConfig(): Config {
91+ const path = configPath();
92+ const filled = Value.Default(ConfigSchema, readJson(path));
93+ try {
94+ return Value.Parse(ConfigSchema, filled);
95+ } catch {
96+ const first = [...Value.Errors(ConfigSchema, filled)][0];
97+ throw new Error(`config ${path}: ${first ? `${first.instancePath || "/"} ${first.message}` : "invalid"}`);
16398 }
164- return out;
16599 }
166100
167101 const API_FACTORY: Record<CustomApi, () => ReturnType<typeof openAICompletionsApi>> = {
@@ -198,7 +132,7 @@ export function resolveModel(config: Config): ResolvedModel {
198132 provider: provider.id,
199133 baseUrl: provider.baseUrl,
200134 reasoning: false,
201- input: ["text"] as ("text" | "image")[],
135+ input: ["text"] satisfies ("text" | "image")[],
202136 cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
203137 contextWindow: 200_000,
204138 maxTokens: 32_768,
src/prompt.ts+2−2
@@ -1,6 +1,6 @@
11 import { existsSync, readdirSync, readFileSync } from "node:fs";
22 import { homedir } from "node:os";
3-import { join } from "node:path";
3+import { join, resolve } from "node:path";
44 import type { Config } from "./config.ts";
55
66 interface Skill {
@@ -34,7 +34,7 @@ function discoverSkills(dirs: string[]): Skill[] {
3434 continue;
3535 }
3636 for (const entry of entries) {
37- const path = join(root, entry, "SKILL.md");
37+ const path = resolve(root, entry, "SKILL.md");
3838 if (!existsSync(path)) continue;
3939 const meta = frontmatter(readFileSync(path, "utf8"));
4040 if (!meta.name) continue;
src/session.ts+1−30
@@ -1,11 +1,8 @@
11 import {
2- appendFileSync,
32 closeSync,
4- existsSync,
53 fsyncSync,
64 mkdirSync,
75 openSync,
8- readFileSync,
96 writeSync,
107 } from "node:fs";
118 import { randomBytes } from "node:crypto";
@@ -40,7 +37,7 @@ export interface MessageRecord {
4037
4138 export type SessionRecord = SessionHeader | RequestRecord | MessageRecord;
4239
43-export function slugify(text: string): string {
40+function slugify(text: string): string {
4441 const slug = text
4542 .toLowerCase()
4643 .replace(/[^a-z0-9]+/g, "-")
@@ -137,7 +134,6 @@ export class Session {
137134 title,
138135 };
139136 this.write(header);
140- this.ignoreDefaultDir();
141137 return;
142138 }
143139 throw new Error(`session: could not create a unique directory in ${this.sessionsDir}`);
@@ -148,29 +144,4 @@ export class Session {
148144 writeSync(this.fd, JSON.stringify(record) + "\n");
149145 fsyncSync(this.fd);
150146 }
151-
152- private ignoreDefaultDir(): void {
153- if (this.sessionsDir !== join(this.cwd, "sessions")) return;
154- const path = join(this.cwd, ".gitignore");
155- const entry = "sessions/";
156- if (existsSync(path) && readFileSync(path, "utf8").split("\n").includes(entry)) return;
157- appendFileSync(path, entry + "\n");
158- }
159-}
160-
161-export function readSession(logPath: string): SessionRecord[] {
162- const lines = readFileSync(logPath, "utf8").split("\n");
163- let last = lines.length - 1;
164- while (last >= 0 && lines[last] === "") last--;
165- const records: SessionRecord[] = [];
166- for (let i = 0; i <= last; i++) {
167- if (lines[i] === "") continue;
168- try {
169- records.push(JSON.parse(lines[i]) as SessionRecord);
170- } catch (error) {
171- if (i === last) return records;
172- throw new Error(`session corruption at line ${i + 1}: ${(error as Error).message}`);
173- }
174- }
175- return records;
176147 }
src/tools.ts+82−41
@@ -1,6 +1,7 @@
11 import { spawn } from "node:child_process";
22 import { existsSync, readFileSync, writeFileSync } from "node:fs";
3-import { Type, type Tool } from "@earendil-works/pi-ai";
3+import { Type, type Static, type TSchema, type Tool, type ToolCall } from "@earendil-works/pi-ai";
4+import { Value } from "typebox/value";
45 import { createTwoFilesPatch } from "diff";
56 import type { ToolName } from "./config.ts";
67
@@ -9,49 +10,69 @@ export interface ToolContext {
910 onOutput?: (chunk: string) => void;
1011 }
1112
13+export interface ToolDetails {
14+ truncated: boolean;
15+ omittedChars: number;
16+ totalChars: number;
17+}
18+
1219 export interface ToolResult {
1320 text: string;
1421 isError: boolean;
22+ details?: ToolDetails;
1523 }
1624
17-export const EDIT_TOOL: Tool = {
18- name: "edit",
19- description:
20- "Edit a file by exact text replacement. oldText must occur exactly once. " +
21- "With empty oldText, create a new file (fails if it exists).",
22- parameters: Type.Object(
23- {
24- path: Type.String({ description: "File path" }),
25- oldText: Type.String({ description: "Exact text to replace; empty to create a file" }),
26- newText: Type.String({ description: "Replacement text" }),
27- },
28- { additionalProperties: false },
29- ),
30-};
31-
32-export const BASH_TOOL: Tool = {
33- name: "bash",
34- description: "Run a bash command in the current working directory.",
35- parameters: Type.Object(
36- { command: Type.String({ description: "Command to run" }) },
37- { additionalProperties: false },
38- ),
25+const EDIT_PARAMS = Type.Object(
26+ {
27+ path: Type.String({ description: "File path" }),
28+ oldText: Type.String({ description: "Exact text to replace; empty to create a file" }),
29+ newText: Type.String({ description: "Replacement text" }),
30+ },
31+ { additionalProperties: false },
32+);
33+type EditArgs = Static<typeof EDIT_PARAMS>;
34+
35+const BASH_PARAMS = Type.Object(
36+ { command: Type.String({ description: "Command to run" }) },
37+ { additionalProperties: false },
38+);
39+type BashArgs = Static<typeof BASH_PARAMS>;
40+
41+const TOOL_SCHEMAS: Record<ToolName, Tool> = {
42+ edit: {
43+ name: "edit",
44+ description:
45+ "Edit a file by exact text replacement. oldText must occur exactly once. " +
46+ "With empty oldText, create a new file (fails if it exists).",
47+ parameters: EDIT_PARAMS,
48+ },
49+ bash: {
50+ name: "bash",
51+ description: "Run a bash command in the current working directory.",
52+ parameters: BASH_PARAMS,
53+ },
3954 };
4055
4156 export function toolSchemas(names: ToolName[]): Tool[] {
42- const available: Record<ToolName, Tool> = { edit: EDIT_TOOL, bash: BASH_TOOL };
43- return names.map((name) => available[name]);
57+ return names.map((name) => TOOL_SCHEMAS[name]);
4458 }
4559
46-export function executeTool(name: ToolName, args: unknown, ctx: ToolContext): Promise<ToolResult> {
47- if (name === "edit") return Promise.resolve(edit(args as EditArgs, ctx.signal));
48- return bash(args as BashArgs, ctx);
60+export function executeTool(name: ToolName, call: ToolCall, ctx: ToolContext): Promise<ToolResult> {
61+ try {
62+ if (name === "edit") return Promise.resolve(edit(parseArgs(EDIT_PARAMS, call.arguments), ctx.signal));
63+ return bash(parseArgs(BASH_PARAMS, call.arguments), ctx);
64+ } catch (error) {
65+ return Promise.resolve({ text: (error as Error).message, isError: true });
66+ }
4967 }
5068
51-interface EditArgs {
52- path: string;
53- oldText: string;
54- newText: string;
69+function parseArgs<T extends TSchema>(schema: T, value: unknown): Static<T> {
70+ try {
71+ return Value.Parse(schema, value);
72+ } catch {
73+ const first = [...Value.Errors(schema, value)][0];
74+ throw new Error(first ? `${first.instancePath || "/"} ${first.message}` : "invalid arguments");
75+ }
5576 }
5677
5778 function edit(args: EditArgs, signal: AbortSignal): ToolResult {
@@ -81,9 +102,9 @@ function unified(path: string, before: string, after: string): string {
81102 return createTwoFilesPatch(path, path, before, after, "", "", { context: 3 });
82103 }
83104
84-interface BashArgs {
85- command: string;
86-}
105+const MAX_HEAD = 10_000;
106+const MAX_TAIL = 6_000;
107+const TRUNCATED = "\n\n... output truncated ...\n\n";
87108
88109 function bash(args: BashArgs, ctx: ToolContext): Promise<ToolResult> {
89110 return new Promise((resolve) => {
@@ -93,11 +114,23 @@ function bash(args: BashArgs, ctx: ToolContext): Promise<ToolResult> {
93114 stdio: ["ignore", "pipe", "pipe"],
94115 });
95116
96- let output = "";
117+ let head = "";
118+ let tail = "";
119+ let omitted = 0;
97120 const append = (chunk: Buffer) => {
98- const text = chunk.toString();
99- output += text;
121+ let text = chunk.toString();
100122 ctx.onOutput?.(text);
123+ if (head.length < MAX_HEAD) {
124+ const take = Math.min(MAX_HEAD - head.length, text.length);
125+ head += text.slice(0, take);
126+ text = text.slice(take);
127+ }
128+ if (text === "") return;
129+ tail += text;
130+ if (tail.length > MAX_TAIL) {
131+ omitted += tail.length - MAX_TAIL;
132+ tail = tail.slice(tail.length - MAX_TAIL);
133+ }
101134 };
102135 child.stdout?.on("data", append);
103136 child.stderr?.on("data", append);
@@ -109,8 +142,16 @@ function bash(args: BashArgs, ctx: ToolContext): Promise<ToolResult> {
109142 ctx.signal.removeEventListener("abort", onAbort);
110143 clearTimeout(killTimer);
111144 const exit = code ?? (ctx.signal.aborted ? "aborted" : "unknown");
112- const text = output + (output.endsWith("\n") || output === "" ? "" : "\n") + `exit code: ${exit}`;
113- resolve({ text, isError: code !== 0 });
145+ const truncated = omitted > 0;
146+ const body = truncated ? head + TRUNCATED + tail : head + tail;
147+ const text = body + (body.endsWith("\n") || body === "" ? "" : "\n") + `exit code: ${exit}`;
148+ resolve({
149+ text,
150+ isError: code !== 0,
151+ details: truncated
152+ ? { truncated: true, omittedChars: omitted, totalChars: head.length + tail.length + omitted }
153+ : undefined,
154+ });
114155 };
115156
116157 let killTimer: NodeJS.Timeout | undefined;
@@ -134,7 +175,7 @@ function bash(args: BashArgs, ctx: ToolContext): Promise<ToolResult> {
134175 else ctx.signal.addEventListener("abort", onAbort, { once: true });
135176
136177 child.on("error", (error) => {
137- output += `${output ? "\n" : ""}bash failed: ${error.message}\n`;
178+ append(Buffer.from(`${head || tail ? "\n" : ""}bash failed: ${error.message}\n`));
138179 finish(null);
139180 });
140181 child.on("close", (code) => finish(code));