- Strip write_file/str_replace/bash from the model binding in the
first-report run: after_model rewrites only fire after a full model
response, so any bound write tool let weak models draft the whole
essay into tool args (write_file content or bash cat>/python
heredocs) for tens of invisible seconds before interception
- Hallucinated hand-writes are still handled: after_model rewrites
bash cat >/python open('w')/tee and leftover write calls to
deep_research_report; wrap_tool_call rejects whatever reaches the
tool layer; post-success writes are dropped, nudged to a 2-3
sentence summary, and patched with a fallback closing message so
the turn never ends silently
- The rewritten pipeline call carries topic = original request
(clarification answers skipped) plus focus = clarification answers,
so the pipeline writes the clarified subject instead of the raw
prompt text; prompts updated to match (tools unavailable, call the
tool directly, do not draft first)
- Frontend write-step interception and streaming preview scoping now
applies only in writing mode; normal mode shows/previews writes
exactly as before
136 lines
3.6 KiB
TypeScript
136 lines
3.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
isInterceptedWritingReportWrite,
|
|
isWritingFirstReportTurn,
|
|
shouldAutoOpenWritingArtifact,
|
|
} from "./writing-mode";
|
|
|
|
test("custom outputs markdown is always intercepted except the research stub", () => {
|
|
assert.equal(
|
|
isInterceptedWritingReportWrite("/mnt/user-data/outputs/paper.md", undefined, undefined, true),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
isInterceptedWritingReportWrite(
|
|
"/mnt/user-data/outputs/report.md",
|
|
"research-report-j1",
|
|
undefined,
|
|
true,
|
|
),
|
|
false,
|
|
);
|
|
});
|
|
|
|
test("normal mode never intercepts outputs markdown writes", () => {
|
|
assert.equal(
|
|
isInterceptedWritingReportWrite("/mnt/user-data/outputs/paper.md"),
|
|
false,
|
|
);
|
|
assert.equal(
|
|
isInterceptedWritingReportWrite("/mnt/user-data/outputs/report.md", "m0", [
|
|
{ type: "human", content: "写一篇论文" },
|
|
]),
|
|
false,
|
|
);
|
|
});
|
|
|
|
test("report.md is intercepted for the whole first-report turn", () => {
|
|
const beforePipeline = [{ type: "human", content: "写一篇论文" }];
|
|
assert.equal(isWritingFirstReportTurn(beforePipeline), true);
|
|
assert.equal(
|
|
isInterceptedWritingReportWrite(
|
|
"/mnt/user-data/outputs/report.md",
|
|
"m1",
|
|
beforePipeline,
|
|
true,
|
|
),
|
|
true,
|
|
);
|
|
|
|
const inFlight = [
|
|
{ type: "human", content: "写一篇论文" },
|
|
{
|
|
type: "ai",
|
|
tool_calls: [{ name: "deep_research_report" }],
|
|
},
|
|
];
|
|
assert.equal(isWritingFirstReportTurn(inFlight), true);
|
|
assert.equal(
|
|
isInterceptedWritingReportWrite("/mnt/user-data/outputs/report.md", "m2", inFlight, true),
|
|
true,
|
|
);
|
|
|
|
const succeeded = [
|
|
...inFlight,
|
|
{
|
|
type: "tool",
|
|
name: "deep_research_report",
|
|
content: "研究报告已完成:已写入 report.md。",
|
|
},
|
|
];
|
|
assert.equal(isWritingFirstReportTurn(succeeded), true);
|
|
assert.equal(
|
|
isInterceptedWritingReportWrite("/mnt/user-data/outputs/report.md", "m3", succeeded, true),
|
|
true,
|
|
);
|
|
});
|
|
|
|
test("sandbox auto-open waits for report.md on the first-report turn", () => {
|
|
const firstTurn = [
|
|
{ type: "human", content: "写一篇论文" },
|
|
{
|
|
type: "ai",
|
|
tool_calls: [{ name: "deep_research_report" }],
|
|
},
|
|
];
|
|
assert.equal(
|
|
shouldAutoOpenWritingArtifact("/mnt/user-data/outputs/research-notes.md", firstTurn, true),
|
|
false,
|
|
);
|
|
assert.equal(
|
|
shouldAutoOpenWritingArtifact("/mnt/user-data/outputs/report.md", firstTurn, true),
|
|
true,
|
|
);
|
|
});
|
|
|
|
test("normal mode auto-opens every new artifact like before writing mode existed", () => {
|
|
const firstTurn = [
|
|
{ type: "human", content: "写一篇论文" },
|
|
{
|
|
type: "ai",
|
|
tool_calls: [{ name: "deep_research_report" }],
|
|
},
|
|
];
|
|
assert.equal(
|
|
shouldAutoOpenWritingArtifact("/mnt/user-data/outputs/research-notes.md", firstTurn),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
shouldAutoOpenWritingArtifact("/mnt/user-data/outputs/report.md", firstTurn),
|
|
true,
|
|
);
|
|
});
|
|
|
|
test("a later user turn releases report.md live edits", () => {
|
|
const followUp = [
|
|
{ type: "human", content: "写一篇论文" },
|
|
{
|
|
type: "ai",
|
|
tool_calls: [{ name: "deep_research_report" }],
|
|
},
|
|
{
|
|
type: "tool",
|
|
name: "deep_research_report",
|
|
content: "研究报告已完成:已写入 report.md。",
|
|
},
|
|
{ type: "human", content: "把第二节改短一点" },
|
|
];
|
|
assert.equal(isWritingFirstReportTurn(followUp), false);
|
|
assert.equal(
|
|
isInterceptedWritingReportWrite("/mnt/user-data/outputs/report.md", "m4", followUp, true),
|
|
false,
|
|
);
|
|
});
|