Skip to content

Commit 533cfe8

Browse files
sahrizviclaude
andcommitted
fix: tidy the run signal-exit notice and the stdin source assertion
- Load `unsent-memory` alongside the 2s mirror drain on SIGINT/SIGTERM, so only the local count runs after it. - Assert the stdin guard and the `readRunStdin(` call separately instead of pinning the newline and indent between them. - Test `workspace list --json` through the yargs command, not only `runList`. - Docs: a slow pipe reaching `run` through a socket (for example over `ssh`) is subject to the same 3s wait. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011chv9Rmu7jQXokum1WNcs7
1 parent c973733 commit 533cfe8

4 files changed

Lines changed: 39 additions & 8 deletions

File tree

‎docs/docs/usage/cli.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ altimate --print-logs --log-level DEBUG run "test query"
190190
altimate run --no-trace "quick question"
191191
```
192192

193-
`run` reads piped input to the end, however long the command before the pipe takes. One exception: when `run` already has a message or `--command` and its stdin is a socket, which is what an agent's shell tool or a Node `spawn` hands a child, it waits only 3 seconds for the first byte and then continues without stdin. Set `ALTIMATE_RUN_STDIN_WAIT_MS` to change that wait, or to `0` to always wait. A caller that never writes to or closes stdin, and whose stdin is not a socket (for example a pipe on Windows), should redirect it from an empty source: `< /dev/null`, or `< NUL` in `cmd.exe`.
193+
`run` reads piped input to the end, however long the command before the pipe takes. One exception: when `run` already has a message or `--command` and its stdin is a socket, which is what an agent's shell tool or a Node `spawn` hands a child, it waits only 3 seconds for the first byte and then continues without stdin. That can also catch a slow pipe that reaches `run` through a socket, such as `slow-cmd | ssh host altimate-code run "summarize"`. Set `ALTIMATE_RUN_STDIN_WAIT_MS` to change that wait, or to `0` to always wait. A caller that never writes to or closes stdin, and whose stdin is not a socket (for example a pipe on Windows), should redirect it from an empty source: `< /dev/null`, or `< NUL` in `cmd.exe`.
194194

195195
For CI pipelines and headless automation, see [CI & Automation](ci-headless.md).
196196

‎packages/opencode/src/cli/cmd/run.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,10 @@ You are speaking to a non-technical business executive. Follow these rules stric
15401540
// flush takes; what is already on the wire is what gets the 2s.
15411541
eventAbort.abort()
15421542
const drains: Promise<unknown>[] = []
1543+
// Loaded during the drain, so only the count itself runs after it.
1544+
const unsent = CoreFlag.ALTIMATE_DISABLE_WORKSPACE
1545+
? undefined
1546+
: import("../../altimate/cli/unsent-memory").catch(() => undefined)
15431547
if (!CoreFlag.ALTIMATE_DISABLE_WORKSPACE)
15441548
drains.push(import("../../altimate/workspace/memory-sync").then((m) => m.flushPendingMirrors(2_000)))
15451549
if (captureEnabled)
@@ -1554,12 +1558,10 @@ You are speaking to a non-technical business executive. Follow these rules stric
15541558
clearTimeout(timer)
15551559
// An interrupted upload is the likeliest to stay on this machine, so say so here too. The count
15561560
// is local; a second signal still exits at once.
1557-
if (!CoreFlag.ALTIMATE_DISABLE_WORKSPACE) {
1558-
const notice = await import("../../altimate/cli/unsent-memory")
1559-
.then((m) => m.unsentMemoryNoticeAfterRun(process.cwd(), 1_000))
1560-
.catch(() => null)
1561-
if (notice) process.stderr.write(notice + EOL)
1562-
}
1561+
const notice = await unsent
1562+
?.then((m) => m?.unsentMemoryNoticeAfterRun(process.cwd(), 1_000))
1563+
.catch(() => null)
1564+
if (notice) process.stderr.write(notice + EOL)
15631565
process.exit(code)
15641566
})
15651567
}

‎packages/opencode/test/cli/workspace-command.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ import {
1111
runStatus,
1212
runSync,
1313
runUnlink,
14+
WorkspaceCommand,
1415
type WorkspaceDeps,
1516
} from "../../src/cli/cmd/workspace"
1617
import { SIGN_IN_COMMAND, linkHeadless, matchWorkspace, type LinkHeadlessDeps } from "../../src/cli/cmd/link"
1718
import { AltimateAuthPlugin } from "../../src/altimate/plugin/altimate"
19+
import { AltimateApi } from "../../src/altimate/api/client"
20+
import { WorkspaceApi } from "../../src/altimate/workspace/api-client"
21+
import yargs from "yargs"
1822

1923
const binding = {
2024
datamateId: 35,
@@ -450,3 +454,27 @@ describe("link --workspace / --create without prompting", () => {
450454
expect(f.calls).toEqual(["create:Marketing"])
451455
})
452456
})
457+
458+
describe("workspace list through the command parser", () => {
459+
const original = { isConfigured: AltimateApi.isConfigured, listDatamates: WorkspaceApi.listDatamates, write: process.stdout.write }
460+
afterEach(() => {
461+
;(AltimateApi as any).isConfigured = original.isConfigured
462+
;(WorkspaceApi as any).listDatamates = original.listDatamates
463+
process.stdout.write = original.write
464+
process.exitCode = 0
465+
})
466+
467+
test("`workspace list --json` is registered and prints the account's workspaces", async () => {
468+
;(AltimateApi as any).isConfigured = async () => true
469+
;(WorkspaceApi as any).listDatamates = async () => [{ id: 35, name: "Growth", memory_enabled: true }]
470+
let written = ""
471+
process.stdout.write = ((chunk: string) => {
472+
written += chunk
473+
return true
474+
}) as typeof process.stdout.write
475+
await yargs(["workspace", "list", "--json"]).command(WorkspaceCommand).strict().fail(false).parseAsync()
476+
process.stdout.write = original.write
477+
expect(JSON.parse(written)).toEqual({ ok: true, workspaces: [{ id: 35, name: "Growth" }] })
478+
expect(process.exitCode).toBe(0)
479+
})
480+
})

‎packages/opencode/test/release-validation/question-937-codex.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ describe("release validation PR #937 source-level env plumbing", () => {
348348
test("run command guards the stdin read behind an existing non-TTY stdin", async () => {
349349
const source = await Bun.file(new URL("../../src/cli/cmd/run.ts", import.meta.url)).text()
350350

351-
expect(source).toContain("if (process.stdin && !process.stdin.isTTY) {\n const { readRunStdin, stdinWaitMs }")
351+
expect(source).toContain("if (process.stdin && !process.stdin.isTTY) {")
352+
expect(source).toContain("readRunStdin(")
352353
expect(source).not.toContain("if (!process.stdin?.isTTY)")
353354
})
354355

0 commit comments

Comments
 (0)