Compare commits

..
Author SHA1 Message Date
Julius Marmingeandcodex bf58a964cd Fix raw command output handling for PR #4083
Co-authored-by: codex <[email protected]>
2026-07-20 16:59:43 +02:00
LikoKiko Tech 86dc15c3d5 fix(web): show command output in work log 2026-07-20 16:39:37 +02:00
4 changed files with 191 additions and 96 deletions

No files matched your search

@@ -0,0 +1,85 @@
import { EventId, TurnId, type OrchestrationThreadActivity } from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";
import { deriveWorkLogEntries } from "./session-logic";
function makeCommandActivity(
id: string,
payload: Record<string, unknown>,
): OrchestrationThreadActivity {
return {
id: EventId.make(id),
createdAt: "2026-07-17T10:00:00.000Z",
kind: "tool.completed",
summary: "Ran command",
tone: "tool",
payload,
turnId: TurnId.make("turn-1"),
};
}
describe("deriveWorkLogEntries command output", () => {
it("uses Codex aggregated output instead of repeating the command", () => {
const [entry] = deriveWorkLogEntries([
makeCommandActivity("codex-command", {
itemType: "command_execution",
title: "Ran command",
detail: "/bin/zsh -lc \"printf 'hello\\n'\"",
data: {
item: {
type: "commandExecution",
command: "/bin/zsh -lc \"printf 'hello\\n'\"",
commandActions: [{ command: "printf 'hello\\n'", type: "unknown" }],
aggregatedOutput: "hello\n<exited with exit code 0>",
status: "completed",
},
},
}),
]);
expect(entry).toMatchObject({
command: "printf 'hello\\n'",
rawCommand: "/bin/zsh -lc \"printf 'hello\\n'\"",
detail: "hello",
});
});
it("uses Claude ACP stdout instead of repeating the command", () => {
const [entry] = deriveWorkLogEntries([
makeCommandActivity("claude-command", {
itemType: "command_execution",
title: "Ran command",
detail: "printf hello",
data: {
kind: "execute",
command: "printf hello",
rawOutput: {
stdout: "hello from claude\n",
},
},
}),
]);
expect(entry).toMatchObject({
command: "printf hello",
detail: "hello from claude",
});
});
it("drops duplicated command detail when the command has no output", () => {
const [entry] = deriveWorkLogEntries([
makeCommandActivity("empty-command", {
itemType: "command_execution",
title: "Ran command",
detail: "true",
data: {
kind: "execute",
command: "true",
},
}),
]);
expect(entry?.command).toBe("true");
expect(entry?.detail).toBeUndefined();
});
});
+91 -2
View File
@@ -1149,6 +1149,70 @@ function summarizeToolRawOutput(payload: Record<string, unknown> | null): string
return null;
}
function extractAcpTextContent(value: unknown): string | null {
if (!Array.isArray(value)) {
return null;
}
const chunks: string[] = [];
for (const entryValue of value) {
const entry = asRecord(entryValue);
if (entry?.type !== "content") {
continue;
}
const content = asRecord(entry.content);
if (content?.type !== "text") {
continue;
}
const text = asTrimmedString(content.text);
if (text) {
chunks.push(text);
}
}
return chunks.length > 0 ? chunks.join("\n") : null;
}
function extractToolOutput(payload: Record<string, unknown> | null): string | null {
const data = asRecord(payload?.data);
const item = asRecord(data?.item);
const itemResult = asRecord(item?.result);
const rawOutput = asRecord(data?.rawOutput);
const outputStreams: string[] = [];
const stdout = asTrimmedString(rawOutput?.stdout);
const stderr = asTrimmedString(rawOutput?.stderr);
if (stdout) {
outputStreams.push(stdout);
}
if (stderr) {
outputStreams.push(stderr);
}
const candidates: unknown[] = [
item?.aggregatedOutput,
itemResult?.content,
data?.rawOutput,
rawOutput?.content,
outputStreams.length > 0 ? outputStreams.join("\n") : null,
rawOutput?.output,
extractAcpTextContent(data?.content),
];
for (const candidate of candidates) {
const text = asTrimmedString(candidate);
if (!text) {
continue;
}
const output = stripTrailingExitCode(text).output;
if (output) {
return output;
}
}
return null;
}
function isCommandToolDetail(payload: Record<string, unknown> | null, heading: string): boolean {
const data = asRecord(payload?.data);
const kind = asTrimmedString(data?.kind)?.toLowerCase();
@@ -1169,12 +1233,37 @@ function extractToolDetail(
const detail = rawDetail ? stripTrailingExitCode(rawDetail).output : null;
const normalizedHeading = normalizePreviewForComparison(heading);
const normalizedDetail = normalizePreviewForComparison(detail);
const commandTool = isCommandToolDetail(payload, heading);
const commandPreview = commandTool
? extractToolCommand(payload)
: { command: null, rawCommand: null };
const command = commandPreview.command;
const normalizedCommand = normalizePreviewForComparison(command);
const normalizedRawCommand = normalizePreviewForComparison(commandPreview.rawCommand);
if (detail && normalizedHeading !== normalizedDetail) {
if (
detail &&
normalizedHeading !== normalizedDetail &&
(!commandTool ||
(normalizedCommand !== normalizedDetail && normalizedRawCommand !== normalizedDetail))
) {
return detail;
}
if (isCommandToolDetail(payload, heading)) {
if (commandTool) {
if (!command) {
return null;
}
const output = extractToolOutput(payload);
const normalizedOutput = normalizePreviewForComparison(output);
if (
output &&
normalizedOutput !== normalizedHeading &&
normalizedOutput !== normalizedCommand
) {
return output;
}
return null;
}
-56
View File
@@ -14,7 +14,6 @@ import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
import { SshPasswordPrompt } from "./auth.ts";
import {
buildSupervisedSshTunnelArgs,
buildRemoteLaunchScript,
buildRemotePairingScript,
buildRemoteStopScript,
@@ -90,50 +89,6 @@ function commandArgs(command: ChildProcess.Command): ReadonlyArray<string> {
}
describe("ssh tunnel scripts", () => {
it("disables connection multiplexing for the supervised port-forward command", () => {
const target = {
alias: "devbox",
hostname: "devbox.example.com",
username: "julius",
port: 2222,
} as const;
assert.deepEqual(
buildSupervisedSshTunnelArgs({
target,
batchMode: "no",
localPort: 41_773,
remotePort: 3_773,
hostSpec: "julius@devbox",
}),
[
"-o",
"BatchMode=no",
"-o",
"ConnectTimeout=10",
"-p",
"2222",
"-o",
"ControlMaster=no",
"-o",
"ControlPath=none",
"-o",
"ControlPersist=no",
"-o",
"ExitOnForwardFailure=yes",
"-o",
"ServerAliveInterval=15",
"-o",
"ServerAliveCountMax=3",
"-n",
"-N",
"-L",
"41773:127.0.0.1:3773",
"julius@devbox",
],
);
});
it("builds the remote t3 runner with npx and npm fallbacks", () => {
const script = buildRemoteT3RunnerScript({ nodeEngineRange: TEST_NODE_ENGINE_RANGE });
@@ -427,17 +382,6 @@ describe("ssh tunnel scripts", () => {
const first = yield* manager.ensureEnvironment(target);
assert.equal(first.httpBaseUrl, "http://127.0.0.1:41773/");
const firstTunnelArgs = spawnedCommands.find((args) => args.includes("-N"));
assert.isDefined(firstTunnelArgs);
assert.include(firstTunnelArgs, "ControlMaster=no");
assert.include(firstTunnelArgs, "ControlPath=none");
assert.include(firstTunnelArgs, "ControlPersist=no");
for (const args of spawnedCommands.filter((entry) => !entry.includes("-N"))) {
assert.notInclude(args, "ControlMaster=no");
assert.notInclude(args, "ControlPath=none");
assert.notInclude(args, "ControlPersist=no");
}
yield* manager.disconnectEnvironment(target);
assert.equal(tunnelKillCount, 1);
assert.equal(stopCommandCount, 1);
+15 -38
View File
@@ -917,38 +917,6 @@ const reserveLocalTunnelPort = Effect.fn("ssh/tunnel.reserveLocalTunnelPort")(fu
return yield* net.reserveLoopbackPort();
});
export function buildSupervisedSshTunnelArgs(input: {
readonly target: DesktopSshEnvironmentTarget;
readonly batchMode: "yes" | "no";
readonly localPort: number;
readonly remotePort: number;
readonly hostSpec: string;
}): ReadonlyArray<string> {
return [
...baseSshArgs(input.target, { batchMode: input.batchMode }),
// This process owns the tunnel lifecycle. Inherited ControlMaster settings
// can otherwise hand the forward to an existing master and let `ssh -N`
// exit while the manager believes it still supervises the connection.
"-o",
"ControlMaster=no",
"-o",
"ControlPath=none",
"-o",
"ControlPersist=no",
"-o",
"ExitOnForwardFailure=yes",
"-o",
"ServerAliveInterval=15",
"-o",
"ServerAliveCountMax=3",
"-n",
"-N",
"-L",
`${input.localPort}:127.0.0.1:${input.remotePort}`,
input.hostSpec,
];
}
const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input: {
readonly key: string;
readonly resolvedTarget: DesktopSshEnvironmentTarget;
@@ -988,13 +956,22 @@ const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input:
}),
),
);
const args = buildSupervisedSshTunnelArgs({
target: input.resolvedTarget,
batchMode: input.authOptions.batchMode ?? "no",
localPort: input.localPort,
remotePort: input.remotePort,
const args = [
...baseSshArgs(input.resolvedTarget, {
batchMode: input.authOptions.batchMode ?? "no",
}),
"-o",
"ExitOnForwardFailure=yes",
"-o",
"ServerAliveInterval=15",
"-o",
"ServerAliveCountMax=3",
"-n",
"-N",
"-L",
`${input.localPort}:127.0.0.1:${input.remotePort}`,
hostSpec,
});
];
const sshCommand = yield* resolveSshCommand;
const tunnelCommand = [sshCommand, ...args];
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;