palmier 1.1.6 → 1.1.7

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.
@@ -4,7 +4,7 @@ import * as path from "path";
4
4
  import { listTasks, parseTaskFile, writeTaskFile, getTaskDir, readTaskStatus, writeTaskStatus, readHistory, deleteHistoryEntry, appendTaskList, removeFromTaskList, isTaskInList, appendHistory, createRunDir, appendRunMessage, getRunDir, writeFollowupStatus, readFollowupStatus, deleteFollowupStatus, isRunStarred, setRunStarred } from "./task.js";
5
5
  import { resolvePending, getPending, listPending } from "./pending-requests.js";
6
6
  import { getPlatform } from "./platform/index.js";
7
- import { resolveCommand, spawnCommand } from "./spawn-command.js";
7
+ import { onChildDone, resolveCommand, spawnCommand } from "./spawn-command.js";
8
8
  import crossSpawn from "cross-spawn";
9
9
  import { getAgent, getPromptCommandLine, getNpmInstalledVersion } from "./agents/agent.js";
10
10
  import { validateClient, revokeClient } from "./client-store.js";
@@ -419,7 +419,7 @@ export function createRpcHandler(config, nc) {
419
419
  const chunks = [];
420
420
  child.stdout?.on("data", (d) => chunks.push(d));
421
421
  child.stderr?.on("data", (d) => process.stderr.write(d));
422
- child.on("close", async (code) => {
422
+ onChildDone(child, async (code) => {
423
423
  activeFollowups.delete(followupKey);
424
424
  deleteFollowupStatus(followupRunDir);
425
425
  // stop_followup already wrote the stopped status.
@@ -8,6 +8,12 @@ export declare function resolveCommand(command: string, args: string[]): {
8
8
  command: string;
9
9
  args: string[];
10
10
  };
11
+ /**
12
+ * Like the "close" event, but doesn't wait for grandchildren: a background process
13
+ * the child started (e.g. a browser daemon) can inherit its stdio pipes on Windows
14
+ * and hold them open long after the child itself exits.
15
+ */
16
+ export declare function onChildDone(child: ChildProcess, callback: (code: number | null) => void): void;
11
17
  export interface SpawnStreamingOptions {
12
18
  cwd: string;
13
19
  env?: Record<string, string>;
@@ -50,6 +50,32 @@ function treeKill(child) {
50
50
  }
51
51
  child.kill();
52
52
  }
53
+ const STDIO_DRAIN_GRACE_MS = 1000;
54
+ /**
55
+ * Like the "close" event, but doesn't wait for grandchildren: a background process
56
+ * the child started (e.g. a browser daemon) can inherit its stdio pipes on Windows
57
+ * and hold them open long after the child itself exits.
58
+ */
59
+ export function onChildDone(child, callback) {
60
+ let done = false;
61
+ let grace;
62
+ const finish = (code) => {
63
+ if (done)
64
+ return;
65
+ done = true;
66
+ if (grace)
67
+ clearTimeout(grace);
68
+ callback(code);
69
+ };
70
+ child.on("exit", (code) => {
71
+ grace = setTimeout(() => {
72
+ child.stdout?.destroy();
73
+ child.stderr?.destroy();
74
+ finish(code);
75
+ }, STDIO_DRAIN_GRACE_MS);
76
+ });
77
+ child.on("close", finish);
78
+ }
53
79
  /**
54
80
  * Spawn with shell interpretation for piped commands like "tail -f log | grep".
55
81
  * Returns the ChildProcess with stdout piped so the caller can read it directly
@@ -104,7 +130,7 @@ export function spawnCommand(command, args, opts) {
104
130
  reject(new Error("command timed out"));
105
131
  }, opts.timeout);
106
132
  }
107
- child.on("close", (code) => {
133
+ onChildDone(child, (code) => {
108
134
  if (timer)
109
135
  clearTimeout(timer);
110
136
  const output = Buffer.concat(chunks).toString("utf-8");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "palmier",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "Palmier host CLI - provisions, executes tasks, and serves NATS RPC",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Hongxu Cai",