mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-27 20:09:10 +01:00
fix(runner): retain unlabeled prefixes and complete tool JSON
Retain the published message identity when a provider begins labeling deltas. Preserve the original full-prefix oracle, separate subsequent message boundaries, and keep unknown JSON result fields inspectable. Record native, server and browser proof and the pending release gates. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
2d9e483cb9
commit
334db53750
10 files changed
+239
-32
No files matched your search
@@ -403,6 +403,28 @@ describe("transcriptToTaskChatItems tool_call updates", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ content: "hello", count: 3 },
|
||||
{ output: "hello", count: 3, exit_code: 0 },
|
||||
{ stdout: "hello", error: { code: "missing_input" }, exit_code: 2 },
|
||||
])("preserves every field in arbitrary JSON tool output: %j", (output) => {
|
||||
const content = JSON.stringify(output);
|
||||
const items = transcriptToTaskChatItems([
|
||||
toolCall("terminal", { command: "print JSON" }),
|
||||
{ kind: "tool_result", ts: TS, toolUseId: "tool-terminal", content, isError: false },
|
||||
], opts);
|
||||
expect(items).toMatchObject([{ kind: "tool", detail: content }]);
|
||||
});
|
||||
|
||||
it("retains distinct output streams in a known command result", () => {
|
||||
const items = transcriptToTaskChatItems([
|
||||
toolCall("terminal", { command: "run checks" }),
|
||||
{ kind: "tool_result", ts: TS, toolUseId: "tool-terminal", isError: true,
|
||||
content: JSON.stringify({ output: "Progress", stdout: "Checks failed", stderr: "Missing input", exit_code: 2 }) },
|
||||
], opts);
|
||||
expect(items).toMatchObject([{ kind: "tool", detail: "Progress\nChecks failed\nMissing input\nExit code: 2" }]);
|
||||
});
|
||||
|
||||
function update(toolUseId: string, status: string): TranscriptEntry {
|
||||
// Mirrors what a persisted acpx tool_call_update line parses to: the
|
||||
// literal placeholder name plus a synthesized { text, status } input.
|
||||
|
||||
@@ -566,9 +566,17 @@ function formatToolResultDetail(content: unknown): string | undefined {
|
||||
try {
|
||||
const result: unknown = typeof content === "string" ? JSON.parse(content) : content;
|
||||
const output = objectRecord(result);
|
||||
const parts = [output.output ?? output.stdout ?? output.content, output.stderr, output.error]
|
||||
const commandFields = ["output", "stdout", "stderr", "error"];
|
||||
const isCommandResult = typeof output.exit_code === "number"
|
||||
&& Number.isFinite(output.exit_code)
|
||||
&& Object.entries(output).every(([key, value]) =>
|
||||
key === "exit_code" || (commandFields.includes(key)
|
||||
&& (value == null || typeof value === "string")));
|
||||
const parts = commandFields.map((key) => output[key])
|
||||
.filter((value): value is string => typeof value === "string" && value.trim().length > 0);
|
||||
if (parts.length > 0) {
|
||||
// Only unwrap the complete command-result shape. Arbitrary JSON printed by
|
||||
// a command (including objects with a "content" field) remains inspectable.
|
||||
if (isCommandResult && parts.length > 0) {
|
||||
text = [...new Set(parts)].join("\n");
|
||||
if (typeof output.exit_code === "number" && output.exit_code !== 0) {
|
||||
text += `\nExit code: ${output.exit_code}`;
|
||||
|
||||
@@ -2,6 +2,7 @@ import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { HeartbeatRunEvent } from "@paperclipai/shared";
|
||||
import { nativeRunEventsToTranscript } from "./native-run-events";
|
||||
import { transcriptToTaskChatItems } from "../task-chat/transcript-adapter";
|
||||
|
||||
const RUN_ID = "10000000-0000-4000-8000-000000000001";
|
||||
|
||||
@@ -118,6 +119,23 @@ describe("provider notice presentation", () => {
|
||||
});
|
||||
|
||||
describe("nativeRunEventsToTranscript", () => {
|
||||
it("keeps JSON printed through native command output intact in the expanded tool", () => {
|
||||
const output = JSON.stringify({ content: "hello", count: 3 });
|
||||
const entries = nativeRunEventsToTranscript([
|
||||
event(1, "tool.execution.started", {
|
||||
schema: "paperclip.tool.execution.v1", executionId: "json-command",
|
||||
transport: "process", operation: "execute", name: "terminal", status: "running",
|
||||
input: { cmd: "print JSON" },
|
||||
}),
|
||||
event(2, "tool.execution.completed", {
|
||||
schema: "paperclip.tool.execution.v1", executionId: "json-command",
|
||||
transport: "process", operation: "execute", name: "terminal", status: "completed", output,
|
||||
}),
|
||||
]);
|
||||
const items = transcriptToTaskChatItems(entries, { runId: RUN_ID, running: false });
|
||||
expect(items).toContainEqual(expect.objectContaining({ kind: "tool", detail: output }));
|
||||
});
|
||||
|
||||
it.each(["command", "cmd"])("uses native %s arguments for process previews and preserves plain results", (key) => {
|
||||
const input = { [key]: "printf 'native output'", cwd: "/workspace" };
|
||||
const transcript = nativeRunEventsToTranscript([
|
||||
|
||||
Reference in new issue
Block a user