The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import type { OrchestrationV2TurnItem } from "@t3tools/contracts"; |
| 2 | import * as DateTime from "effect/DateTime"; |
| 3 | import * as Option from "effect/Option"; |
| 4 | import * as Schema from "effect/Schema"; |
| 5 | |
| 6 | type CommandExecutionItem = Extract<OrchestrationV2TurnItem, { type: "command_execution" }>; |
| 7 | |
| 8 | // Only nightlies 20261003.2610 to 20261004.2644 stored raw Claude Bash envelopes; rows carry no |
| 9 | // build stamp, so start time is the only discriminator. The cutoff leaves nightly laggards four days. |
| 10 | const CLAUDE_RAW_BASH_RESULT_CUTOFF = DateTime.makeUnsafe("2026-10-08T00:00:00Z"); |
| 11 | |
| 12 | const decodeClaudeBashResult = Schema.decodeUnknownOption( |
| 13 | Schema.fromJsonString( |
| 14 | Schema.Struct({ stdout: Schema.String, stderr: Schema.String, interrupted: Schema.Boolean }), |
| 15 | ), |
| 16 | ); |
| 17 | |
| 18 | function storesRawClaudeBashResult(item: CommandExecutionItem): boolean { |
| 19 | return ( |
| 20 | item.nativeItemRef?.driver === "claudeAgent" && |
| 21 | DateTime.isLessThan(item.startedAt ?? item.updatedAt, CLAUDE_RAW_BASH_RESULT_CUTOFF) |
| 22 | ); |
| 23 | } |
| 24 | |
| 25 | /** The output a command row shows: the stored bytes, except early Claude rows' raw Bash envelopes. */ |
| 26 | export function commandItemOutput(item: CommandExecutionItem): string | undefined { |
| 27 | const output = item.output; |
| 28 | if (output === undefined || !storesRawClaudeBashResult(item)) return output; |
| 29 | if (!output.trimStart().startsWith('{"stdout"')) return output; |
| 30 | const parsed = decodeClaudeBashResult(output); |
| 31 | if (Option.isNone(parsed)) return output; |
| 32 | const out = parsed.value.stdout.trim().length > 0 ? parsed.value.stdout : ""; |
| 33 | const err = parsed.value.stderr.trim().length > 0 ? parsed.value.stderr : ""; |
| 34 | return out.length > 0 && err.length > 0 && !out.endsWith("\n") ? `${out}\n${err}` : out + err; |
| 35 | } |