Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ dsh --json -C /repo --mode plan --disallowed-tools bash --timeout 900 -p "$PROMP
dsh models --json [--refresh]
```

Exit codes: `0` completed, `1` failed or waiting_for_user, `130` interrupted (SIGINT/SIGTERM).
Exit codes: `0` completed, `1` failed or waiting_for_user, `130` interrupted (SIGINT/SIGTERM). The result is written in full before exit, so output over 64 KiB read through a pipe stays valid JSON (fixed in 0.1.4; 0.1.2 and earlier cut it at 65,536 bytes).
`--timeout <s>` stops the run, kills its child processes and reports `failed` with `failReason: "timeout ..."`.
`-p <text>` takes the next argument verbatim, also when it starts with `-`. `-e disabled` = `--no-thinking`.

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coderbuzz/dsh",
"version": "0.1.3",
"version": "0.1.4",
"description": "DeepSeek harness for orchestrators: structured JSON SDK and CLI on top of the deepcode-cli engine",
"license": "MIT",
"repository": {
Expand Down
5 changes: 3 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ async function readStdin(): Promise<string> {
}

main().then(
(code) => process.exit(code),
// exitCode, not process.exit(): exit() drops stdout still queued on a pipe (cut at 64 KiB for large results).
(code) => void (process.exitCode = code),
(err) => {
process.stderr.write(`dsh: ${err instanceof Error ? err.message : String(err)}\n`);
process.exit(1);
process.exitCode = 1;
}
);
39 changes: 37 additions & 2 deletions test/e2e.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import http from "node:http";
import { execFile } from "node:child_process";
import { execFile, spawn } from "node:child_process";
import { promisify } from "node:util";
import fs from "node:fs";
import os from "node:os";
Expand Down Expand Up @@ -35,7 +35,10 @@ const server = http.createServer(async (req, res) => {
if (last.role === "user" && JSON.stringify(last.content).includes("again")) return sse(res, { role: "assistant", reasoning_content: "thought-3", content: "again-done" }, true);
const user = JSON.stringify(json.messages.filter((m) => m.role === "user").at(-1)?.content);
if (user.includes("PARALLEL")) return sse(res, { role: "assistant", content: "parallel-done" }, true);
const command = user.includes("SLEEP")
if (user.includes("BIGREPLY")) return sse(res, { role: "assistant", content: "x".repeat(200000) }, true);
const command = user.includes("BIGFAIL")
? "head -c 200000 /dev/zero | tr '\\0' y; sleep 37.25"
: user.includes("SLEEP")
? "sleep 37.25"
: user.includes("ENVCHECK")
? "env | grep -E '^(DEEPCODE_)?(PLUS_)?API_KEY=' | wc -l; echo MARK=$MARK USERVAR=${OTHER_API_KEY:-unset}"
Expand Down Expand Up @@ -170,3 +173,35 @@ test("agent bash does not see the provider API key, but keeps other env", async
// the user's own variables (even ones ending in API_KEY) are untouched.
assert.equal(r.toolExecutions[0].process_stdout, "0\nMARK=kept USERVAR=mine\n");
});

// Regression: stdout read through a slow pipe was cut at 64 KiB because the CLI called process.exit
// before the pipe drained. The reader here waits before consuming, so the pipe buffer fills.
const viaSlowPipe = (args) => new Promise((resolve) => {
const child = spawn("node", [cli, ...args], { cwd, env, stdio: ["ignore", "pipe", "ignore"] });
const chunks = [];
child.stdout.pause();
setTimeout(() => { child.stdout.on("data", (c) => chunks.push(c)); child.stdout.resume(); }, 1500);
child.on("close", (code) => resolve({ code, out: Buffer.concat(chunks).toString() }));
});

test("--json output over 64 KiB survives a slow pipe", async () => {
const { code, out } = await viaSlowPipe(["--json", "BIGREPLY"]);
assert.equal(code, 0);
assert.equal(JSON.parse(out).reply.length, 200000);
});

test("--stream-json output over 64 KiB survives a slow pipe", async () => {
const { code, out } = await viaSlowPipe(["--stream-json", "BIGREPLY"]);
assert.equal(code, 0);
const lines = out.trimEnd().split("\n");
assert.ok(out.length > 65536);
for (const l of lines) JSON.parse(l);
});

test("failed run (exit 1) with output over 64 KiB stays intact", async () => {
const { code, out } = await viaSlowPipe(["--json", "--timeout", "2", "BIGFAIL"]);
assert.equal(code, 1);
const r = JSON.parse(out);
assert.match(r.failReason, /timeout/);
assert.ok(out.length > 65536);
});
Loading