@getpaseo/cli 0.11.0-beta.4 → 0.11.0-beta.5

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,6 +4,7 @@ export function addAttachOptions(cmd) {
4
4
  .argument("<id>", "Agent ID (or prefix)");
5
5
  }
6
6
  import { connectToDaemon } from "../../utils/client.js";
7
+ import { waitForStop } from "../../utils/wait-for-stop.js";
7
8
  import { fetchProjectedTimelineItems, LIVE_HISTORY_FETCH_TIMEOUT_MS, } from "../../utils/timeline.js";
8
9
  /**
9
10
  * Format and print a timeline item to the terminal
@@ -123,29 +124,10 @@ export async function runAttachCommand(id, options, _command) {
123
124
  });
124
125
  await unsubscribe.ready;
125
126
  console.log(`Attached to agent ${resolvedId.substring(0, 7)}.`);
126
- // Handle Ctrl+C to detach gracefully
127
- let detached = false;
128
- const detach = () => {
129
- if (detached)
130
- return;
131
- detached = true;
132
- console.log("\n\nDetaching from agent...");
133
- unsubscribe();
134
- client
135
- .close()
136
- .then(() => {
137
- process.exit(0);
138
- })
139
- .catch(() => {
140
- process.exit(1);
141
- });
142
- };
143
- process.on("SIGINT", detach);
144
- process.on("SIGTERM", detach);
145
- // Keep the process alive
146
- await new Promise(() => {
147
- // Wait indefinitely until interrupted
148
- });
127
+ await waitForStop();
128
+ console.log("\n\nDetaching from agent...");
129
+ unsubscribe();
130
+ await client.close();
149
131
  }
150
132
  catch (err) {
151
133
  await client.close().catch(() => { });
@@ -1,4 +1,5 @@
1
1
  import { connectToDaemon } from "../../utils/client.js";
2
+ import { waitForStop } from "../../utils/wait-for-stop.js";
2
3
  import { fetchProjectedTimelineItems, LIVE_HISTORY_FETCH_TIMEOUT_MS, } from "../../utils/timeline.js";
3
4
  import { curateAgentActivity } from "@getpaseo/server/agent-activity";
4
5
  export function addLogsOptions(cmd) {
@@ -166,15 +167,8 @@ async function runFollowMode(client, agentId, options) {
166
167
  });
167
168
  await unsubscribe.ready;
168
169
  console.log(`\n--- Following logs (${tailLabel}; Ctrl+C to stop) ---\n`);
169
- // Wait for interrupt
170
- await new Promise((resolve) => {
171
- const cleanup = () => {
172
- unsubscribe();
173
- resolve();
174
- };
175
- process.on("SIGINT", cleanup);
176
- process.on("SIGTERM", cleanup);
177
- });
170
+ await waitForStop();
171
+ unsubscribe();
178
172
  await client.close();
179
173
  }
180
174
  //# sourceMappingURL=logs.js.map
package/dist/run.js CHANGED
@@ -24,7 +24,19 @@ export function createCliParseArgv(input) {
24
24
  }
25
25
  return [...nodeArgv, ...cliArgv];
26
26
  }
27
+ // The program that started the CLI can close its end of stdout before the output
28
+ // is written, as `paseo ls | head -1` or a launcher that discards output does.
29
+ // Drop the output nobody reads and let the command finish, instead of surfacing
30
+ // the failed write as an uncaught error.
31
+ function ignoreClosedStdout(error) {
32
+ if (error.code !== "EPIPE") {
33
+ throw error;
34
+ }
35
+ }
27
36
  export async function runCli(argv, options = {}) {
37
+ if (!process.stdout.listeners("error").includes(ignoreClosedStdout)) {
38
+ process.stdout.on("error", ignoreClosedStdout);
39
+ }
28
40
  const parseArgv = createCliParseArgv({
29
41
  argv,
30
42
  cwd: options.cwd ?? process.cwd(),
@@ -0,0 +1,2 @@
1
+ export declare function waitForStop(): Promise<void>;
2
+ //# sourceMappingURL=wait-for-stop.d.ts.map
@@ -0,0 +1,24 @@
1
+ // Commands that stream until stopped (`paseo agent logs --follow`, `paseo agent
2
+ // attach`) stop on Ctrl+C, a termination signal, or when the program reading
3
+ // their output closes its end, as `| head` does. A closed reader shows up as
4
+ // EPIPE on the next write to stdout, so the command stops at its next line of
5
+ // output.
6
+ export function waitForStop() {
7
+ return new Promise((resolve) => {
8
+ const stop = () => {
9
+ process.off("SIGINT", stop);
10
+ process.off("SIGTERM", stop);
11
+ process.stdout.off("error", stopOnClosedStdout);
12
+ resolve();
13
+ };
14
+ const stopOnClosedStdout = (error) => {
15
+ if (error.code === "EPIPE") {
16
+ stop();
17
+ }
18
+ };
19
+ process.on("SIGINT", stop);
20
+ process.on("SIGTERM", stop);
21
+ process.stdout.on("error", stopOnClosedStdout);
22
+ });
23
+ }
24
+ //# sourceMappingURL=wait-for-stop.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getpaseo/cli",
3
- "version": "0.11.0-beta.4",
3
+ "version": "0.11.0-beta.5",
4
4
  "description": "Paseo CLI - control your AI coding agents from the command line",
5
5
  "bin": {
6
6
  "paseo": "bin/paseo"
@@ -28,9 +28,9 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@clack/prompts": "^1.0.0",
31
- "@getpaseo/client": "0.11.0-beta.4",
32
- "@getpaseo/protocol": "0.11.0-beta.4",
33
- "@getpaseo/server": "0.11.0-beta.4",
31
+ "@getpaseo/client": "0.11.0-beta.5",
32
+ "@getpaseo/protocol": "0.11.0-beta.5",
33
+ "@getpaseo/server": "0.11.0-beta.5",
34
34
  "chalk": "^5.3.0",
35
35
  "commander": "^12.0.0",
36
36
  "mime-types": "^2.1.35",