@useavalon/caelence-agent 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +201 -0
- package/bin/harness.ts +10 -0
- package/package.json +75 -0
- package/skills/copy-editor/SKILL.md +74 -0
- package/skills/copy-editor/references/anti-slop.md +62 -0
- package/skills/copy-editor/references/ui-states.md +46 -0
- package/skills/copy-editor/scripts/lint-copy.py +78 -0
- package/skills/copy-harry-dry/SKILL.md +120 -0
- package/skills/copy-rmbc/SKILL.md +97 -0
- package/skills/copywriting/SKILL.md +73 -0
- package/skills/impeccable/SKILL.md +133 -0
- package/skills/impeccable/references/visual-slop.md +36 -0
- package/src/cli/main.test.ts +36 -0
- package/src/cli/main.ts +384 -0
- package/src/cli/media-models.ts +82 -0
- package/src/cli/models.ts +43 -0
- package/src/cli/openrouter-live.test.ts +35 -0
- package/src/cli/openrouter-live.ts +72 -0
- package/src/cli/openrouter-modality.test.ts +25 -0
- package/src/cli/openrouter-modality.ts +83 -0
- package/src/cli/picker.test.ts +53 -0
- package/src/cli/picker.ts +48 -0
- package/src/cli/plain-text.ts +15 -0
- package/src/cli/slash-dispatch.test.ts +213 -0
- package/src/cli/slash-dispatch.ts +298 -0
- package/src/cli/slash.test.ts +113 -0
- package/src/cli/slash.ts +119 -0
- package/src/cli/theme.test.ts +10 -0
- package/src/cli/theme.ts +44 -0
- package/src/cli/tui-layout.test.ts +33 -0
- package/src/cli/tui-layout.ts +33 -0
- package/src/cli/tui-screen.test.ts +33 -0
- package/src/cli/tui-screen.ts +13 -0
- package/src/cli/tui.tsx +735 -0
- package/src/config.ts +86 -0
- package/src/core/approval.test.ts +60 -0
- package/src/core/approval.ts +83 -0
- package/src/core/auto-router.test.ts +31 -0
- package/src/core/auto-router.ts +66 -0
- package/src/core/errors.ts +67 -0
- package/src/core/events.ts +85 -0
- package/src/core/hooks.test.ts +66 -0
- package/src/core/hooks.ts +94 -0
- package/src/core/ids.ts +6 -0
- package/src/core/instructions.test.ts +49 -0
- package/src/core/instructions.ts +44 -0
- package/src/core/logger.ts +45 -0
- package/src/core/mcp.ts +191 -0
- package/src/core/mode.test.ts +63 -0
- package/src/core/mode.ts +60 -0
- package/src/core/run-turn.test.ts +339 -0
- package/src/core/run-turn.ts +487 -0
- package/src/core/session.test.ts +203 -0
- package/src/core/session.ts +349 -0
- package/src/core/stdio-mcp.ts +143 -0
- package/src/core/strands.ts +262 -0
- package/src/core/usage.test.ts +69 -0
- package/src/core/usage.ts +171 -0
- package/src/desktop/bridge.test.ts +331 -0
- package/src/desktop/bridge.ts +729 -0
- package/src/desktop/open-local.test.ts +40 -0
- package/src/desktop/open-local.ts +52 -0
- package/src/desktop/preview-cache.test.ts +36 -0
- package/src/desktop/preview-cache.ts +63 -0
- package/src/desktop/secrets.test.ts +44 -0
- package/src/desktop/secrets.ts +60 -0
- package/src/evals/runner.test.ts +43 -0
- package/src/evals/runner.ts +225 -0
- package/src/index.ts +132 -0
- package/src/init.test.ts +54 -0
- package/src/init.ts +117 -0
- package/src/integrations/catalog-data.json +424 -0
- package/src/integrations/catalog.ts +81 -0
- package/src/integrations/connect.ts +231 -0
- package/src/integrations/integrations.test.ts +329 -0
- package/src/integrations/marks/airtable.svg +1 -0
- package/src/integrations/marks/algolia-mcp.svg +1 -0
- package/src/integrations/marks/canva.jpg +0 -0
- package/src/integrations/marks/cloudflare-mcp.svg +1 -0
- package/src/integrations/marks/contentful-mcp.svg +1 -0
- package/src/integrations/marks/craft.png +0 -0
- package/src/integrations/marks/dinero.png +0 -0
- package/src/integrations/marks/figma.svg +1 -0
- package/src/integrations/marks/gitlab.svg +1 -0
- package/src/integrations/marks/google-calendar.svg +1 -0
- package/src/integrations/marks/google-docs.svg +1 -0
- package/src/integrations/marks/google-drive.svg +1 -0
- package/src/integrations/marks/google-gmail.svg +1 -0
- package/src/integrations/marks/google-sheets.svg +1 -0
- package/src/integrations/marks/google-slides.svg +1 -0
- package/src/integrations/marks/granola.png +0 -0
- package/src/integrations/marks/jira.svg +1 -0
- package/src/integrations/marks/linear.svg +1 -0
- package/src/integrations/marks/microsoft-365.svg +7 -0
- package/src/integrations/marks/miro.svg +1 -0
- package/src/integrations/marks/mixpanel-mcp.svg +1 -0
- package/src/integrations/marks/monday.png +0 -0
- package/src/integrations/marks/mux-mcp.png +0 -0
- package/src/integrations/marks/neon-mcp.svg +1 -0
- package/src/integrations/marks/notion.svg +1 -0
- package/src/integrations/marks/paddle-mcp.svg +1 -0
- package/src/integrations/marks/posthog-mcp.svg +1 -0
- package/src/integrations/marks/prismic-mcp.svg +1 -0
- package/src/integrations/marks/replicate-mcp.svg +1 -0
- package/src/integrations/marks/resend-mcp.svg +1 -0
- package/src/integrations/marks/sanity-mcp.svg +1 -0
- package/src/integrations/marks/sceneplane.png +0 -0
- package/src/integrations/marks/sentry-mcp.svg +1 -0
- package/src/integrations/marks/stripe-mcp.svg +1 -0
- package/src/integrations/marks/supabase-mcp.svg +1 -0
- package/src/integrations/marks/upstash-mcp.svg +1 -0
- package/src/integrations/marks/vercel.svg +1 -0
- package/src/integrations/marks/webflow.svg +1 -0
- package/src/integrations/mcp-oauth.test.ts +39 -0
- package/src/integrations/mcp-oauth.ts +330 -0
- package/src/integrations/oauth-clients.test.ts +77 -0
- package/src/integrations/oauth-clients.ts +127 -0
- package/src/integrations/oauth.ts +145 -0
- package/src/integrations/remote-mcp.ts +307 -0
- package/src/integrations/store.ts +149 -0
- package/src/media/openrouter-generate.test.ts +80 -0
- package/src/media/openrouter-generate.ts +178 -0
- package/src/media/prefs.ts +54 -0
- package/src/observability/categories.ts +41 -0
- package/src/observability/create.test.ts +56 -0
- package/src/observability/create.ts +45 -0
- package/src/observability/experiments.ts +113 -0
- package/src/observability/fake.ts +191 -0
- package/src/observability/index.ts +57 -0
- package/src/observability/judges.ts +91 -0
- package/src/observability/langfuse.ts +275 -0
- package/src/observability/noop.ts +33 -0
- package/src/observability/observability.test.ts +113 -0
- package/src/observability/prompts.ts +98 -0
- package/src/observability/regression-items.ts +158 -0
- package/src/observability/sanitize.test.ts +26 -0
- package/src/observability/sanitize.ts +57 -0
- package/src/observability/types.ts +122 -0
- package/src/observability/version.ts +41 -0
- package/src/product.ts +2 -0
- package/src/runtime.test.ts +98 -0
- package/src/runtime.ts +438 -0
- package/src/skills/author-skill.ts +49 -0
- package/src/skills/create-skill.test.ts +108 -0
- package/src/skills/create-skill.ts +70 -0
- package/src/skills/loader.test.ts +122 -0
- package/src/skills/loader.ts +162 -0
- package/src/skills/registry.test.ts +190 -0
- package/src/skills/registry.ts +402 -0
- package/src/skills/skill-command.ts +53 -0
- package/src/skills/user-dir.ts +8 -0
- package/src/tools/git.test.ts +71 -0
- package/src/tools/git.ts +126 -0
- package/src/tools/local.ts +258 -0
- package/src/tools/paths.test.ts +24 -0
- package/src/tools/paths.ts +39 -0
- package/src/tools/read-skill.ts +43 -0
- package/src/tools/subagent.test.ts +77 -0
- package/src/tools/subagent.ts +74 -0
- package/src/tools/todo.test.ts +25 -0
- package/src/tools/todo.ts +70 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { createRecordingObservability } from "../observability/fake.ts";
|
|
6
|
+
import { createLocalTools } from "../tools/local.ts";
|
|
7
|
+
import { createMemoryTodoStore, createTodoTool } from "../tools/todo.ts";
|
|
8
|
+
import { createExecApprovalGate } from "./approval.ts";
|
|
9
|
+
import type { AgentEvent, MainModelProvider } from "./events.ts";
|
|
10
|
+
import type { HookRunner } from "./hooks.ts";
|
|
11
|
+
import { buildSystemPrompt, type RunTurnDeps, runTurn } from "./run-turn.ts";
|
|
12
|
+
import { createFileSessionStore, sessionToProviderMessages } from "./session.ts";
|
|
13
|
+
import type { ConstructAgent } from "./strands.ts";
|
|
14
|
+
|
|
15
|
+
const fakeProvider: MainModelProvider = {
|
|
16
|
+
kind: "fake",
|
|
17
|
+
modelId: "fake",
|
|
18
|
+
async *stream() {
|
|
19
|
+
yield { type: "done" };
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe("runTurn", () => {
|
|
24
|
+
test("fake agent writes a file and emits agent events", async () => {
|
|
25
|
+
const cwd = await mkdtemp(join(tmpdir(), "harness-turn-"));
|
|
26
|
+
try {
|
|
27
|
+
const constructAgent: ConstructAgent = (input) => ({
|
|
28
|
+
async run(_message, emit) {
|
|
29
|
+
emit({ kind: "text_delta", text: "editing…" });
|
|
30
|
+
const write = input.tools.find((t) => t.name === "write_file");
|
|
31
|
+
if (!write) throw new Error("write_file missing");
|
|
32
|
+
await write.invoke({ path: "hello.txt", content: "hi" });
|
|
33
|
+
emit({ kind: "text_delta", text: " done" });
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
const events: AgentEvent["kind"][] = [];
|
|
37
|
+
const deps: RunTurnDeps = {
|
|
38
|
+
cwd,
|
|
39
|
+
name: "test",
|
|
40
|
+
systemPrompt: "test",
|
|
41
|
+
tools: createLocalTools({ cwd }).listTools(),
|
|
42
|
+
approval: createExecApprovalGate({ policy: "deny" }),
|
|
43
|
+
store: createFileSessionStore(cwd),
|
|
44
|
+
provider: fakeProvider,
|
|
45
|
+
constructAgent,
|
|
46
|
+
};
|
|
47
|
+
const session = await runTurn(deps, { message: "write hello" }, (event) => {
|
|
48
|
+
events.push(event.kind);
|
|
49
|
+
});
|
|
50
|
+
expect(events[0]).toBe("session_meta");
|
|
51
|
+
expect(events).toContain("text_delta");
|
|
52
|
+
expect(events).toContain("tool_call_start");
|
|
53
|
+
expect(events).toContain("tool_call_end");
|
|
54
|
+
expect(events[events.length - 1]).toBe("completion");
|
|
55
|
+
expect(await readFile(join(cwd, "hello.txt"), "utf8")).toBe("hi");
|
|
56
|
+
const stored = session ? await deps.store.get(session.id) : undefined;
|
|
57
|
+
expect(
|
|
58
|
+
stored?.messages.some(
|
|
59
|
+
(message) => message.kind === "tool" && message.name === "write_file",
|
|
60
|
+
),
|
|
61
|
+
).toBe(true);
|
|
62
|
+
} finally {
|
|
63
|
+
await rm(cwd, { recursive: true, force: true });
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("records nested tool spans on the observer", async () => {
|
|
68
|
+
const cwd = await mkdtemp(join(tmpdir(), "harness-obs-"));
|
|
69
|
+
try {
|
|
70
|
+
const obs = createRecordingObservability();
|
|
71
|
+
const constructAgent: ConstructAgent = (input) => ({
|
|
72
|
+
async run(_message, emit) {
|
|
73
|
+
const write = input.tools.find((t) => t.name === "write_file");
|
|
74
|
+
if (!write) throw new Error("write_file missing");
|
|
75
|
+
await write.invoke({ path: "a.txt", content: "x" });
|
|
76
|
+
emit({ kind: "text_delta", text: "ok" });
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
await runTurn(
|
|
80
|
+
{
|
|
81
|
+
cwd,
|
|
82
|
+
name: "test",
|
|
83
|
+
systemPrompt: "test",
|
|
84
|
+
tools: createLocalTools({ cwd }).listTools(),
|
|
85
|
+
approval: createExecApprovalGate({ policy: "deny" }),
|
|
86
|
+
store: createFileSessionStore(cwd),
|
|
87
|
+
provider: fakeProvider,
|
|
88
|
+
constructAgent,
|
|
89
|
+
observability: obs,
|
|
90
|
+
},
|
|
91
|
+
{ message: "write" },
|
|
92
|
+
() => undefined,
|
|
93
|
+
);
|
|
94
|
+
expect(obs.turns[0]?.name).toBe("agent_turn");
|
|
95
|
+
expect(obs.turns[0]?.children.some((c) => c.kind === "tool" && c.name === "write_file")).toBe(
|
|
96
|
+
true,
|
|
97
|
+
);
|
|
98
|
+
expect(obs.turns[0]?.children.some((c) => c.kind === "generation")).toBe(true);
|
|
99
|
+
} finally {
|
|
100
|
+
await rm(cwd, { recursive: true, force: true });
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("emits usage when the provider reports it", async () => {
|
|
105
|
+
const cwd = await mkdtemp(join(tmpdir(), "harness-usage-"));
|
|
106
|
+
try {
|
|
107
|
+
let taken = false;
|
|
108
|
+
const provider: MainModelProvider = {
|
|
109
|
+
kind: "fake",
|
|
110
|
+
modelId: "fake",
|
|
111
|
+
async *stream() {
|
|
112
|
+
yield { type: "done" };
|
|
113
|
+
},
|
|
114
|
+
takeUsage() {
|
|
115
|
+
if (taken) return undefined;
|
|
116
|
+
taken = true;
|
|
117
|
+
return { promptTokens: 8, completionTokens: 2, totalTokens: 10 };
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
const events: AgentEvent[] = [];
|
|
121
|
+
await runTurn(
|
|
122
|
+
{
|
|
123
|
+
cwd,
|
|
124
|
+
name: "test",
|
|
125
|
+
systemPrompt: "test",
|
|
126
|
+
tools: [],
|
|
127
|
+
approval: createExecApprovalGate({ policy: "deny" }),
|
|
128
|
+
store: createFileSessionStore(cwd),
|
|
129
|
+
provider,
|
|
130
|
+
constructAgent: () => ({
|
|
131
|
+
async run(_message, emit) {
|
|
132
|
+
emit({ kind: "text_delta", text: "ok" });
|
|
133
|
+
},
|
|
134
|
+
}),
|
|
135
|
+
},
|
|
136
|
+
{ message: "hi" },
|
|
137
|
+
(event) => events.push(event),
|
|
138
|
+
);
|
|
139
|
+
expect(events.some((event) => event.kind === "usage" && event.promptTokens === 8)).toBe(true);
|
|
140
|
+
expect(events.some((event) => event.kind === "usage" && "costUsd" in event)).toBe(false);
|
|
141
|
+
} finally {
|
|
142
|
+
await rm(cwd, { recursive: true, force: true });
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("emits todos after todo_write and honors a denying pre_tool hook", async () => {
|
|
147
|
+
const cwd = await mkdtemp(join(tmpdir(), "harness-todos-"));
|
|
148
|
+
try {
|
|
149
|
+
const hooks: HookRunner = {
|
|
150
|
+
sessionStart: async () => undefined,
|
|
151
|
+
preTool: async (name) =>
|
|
152
|
+
name === "write_file" ? { allow: false, reason: "blocked" } : { allow: true },
|
|
153
|
+
postTool: async () => undefined,
|
|
154
|
+
};
|
|
155
|
+
const events: AgentEvent[] = [];
|
|
156
|
+
const constructAgent: ConstructAgent = (input) => ({
|
|
157
|
+
async run() {
|
|
158
|
+
const todo = input.tools.find((t) => t.name === "todo_write");
|
|
159
|
+
const write = input.tools.find((t) => t.name === "write_file");
|
|
160
|
+
if (!todo || !write) throw new Error("tools missing");
|
|
161
|
+
await todo.invoke({
|
|
162
|
+
items: [{ id: "1", content: "inspect", status: "pending" }],
|
|
163
|
+
});
|
|
164
|
+
const denied = await write.invoke({ path: "nope.txt", content: "x" });
|
|
165
|
+
expect(denied.isError).toBe(true);
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
await runTurn(
|
|
169
|
+
{
|
|
170
|
+
cwd,
|
|
171
|
+
name: "test",
|
|
172
|
+
systemPrompt: "test",
|
|
173
|
+
tools: [
|
|
174
|
+
...createLocalTools({ cwd }).listTools(),
|
|
175
|
+
createTodoTool(createMemoryTodoStore()),
|
|
176
|
+
],
|
|
177
|
+
approval: createExecApprovalGate({ policy: "deny" }),
|
|
178
|
+
store: createFileSessionStore(cwd),
|
|
179
|
+
provider: fakeProvider,
|
|
180
|
+
constructAgent,
|
|
181
|
+
hooks,
|
|
182
|
+
},
|
|
183
|
+
{ message: "plan" },
|
|
184
|
+
(event) => events.push(event),
|
|
185
|
+
);
|
|
186
|
+
const todos = events.find((event) => event.kind === "todos");
|
|
187
|
+
expect(todos?.kind === "todos" && todos.items[0]?.content).toBe("inspect");
|
|
188
|
+
expect(
|
|
189
|
+
events.some(
|
|
190
|
+
(event) =>
|
|
191
|
+
event.kind === "tool_call_end" && event.toolName === "write_file" && !event.success,
|
|
192
|
+
),
|
|
193
|
+
).toBe(true);
|
|
194
|
+
} finally {
|
|
195
|
+
await rm(cwd, { recursive: true, force: true });
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test("buildSystemPrompt stacks layers and mode", () => {
|
|
200
|
+
const prompt = buildSystemPrompt({
|
|
201
|
+
name: "harness",
|
|
202
|
+
cwd: "/tmp/proj",
|
|
203
|
+
userInstructions: "prefer bun",
|
|
204
|
+
projectInstructions: "no secrets",
|
|
205
|
+
mode: "ask",
|
|
206
|
+
});
|
|
207
|
+
expect(prompt).toContain("## User instructions");
|
|
208
|
+
expect(prompt).toContain("prefer bun");
|
|
209
|
+
expect(prompt).toContain("## Project instructions");
|
|
210
|
+
expect(prompt).toContain("no secrets");
|
|
211
|
+
expect(prompt).toContain("## Mode: ask");
|
|
212
|
+
expect(prompt).toContain("You are a coding agent in this project.");
|
|
213
|
+
expect(prompt).not.toContain("You are harness, a coding agent working in /tmp/proj");
|
|
214
|
+
expect(prompt).toContain("plain text");
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test("abort keeps the partial assistant reply", async () => {
|
|
218
|
+
const cwd = await mkdtemp(join(tmpdir(), "harness-abort-"));
|
|
219
|
+
try {
|
|
220
|
+
const controller = new AbortController();
|
|
221
|
+
const store = createFileSessionStore(cwd);
|
|
222
|
+
const pending = runTurn(
|
|
223
|
+
{
|
|
224
|
+
cwd,
|
|
225
|
+
name: "test",
|
|
226
|
+
systemPrompt: "test",
|
|
227
|
+
tools: [],
|
|
228
|
+
approval: createExecApprovalGate({ policy: "deny" }),
|
|
229
|
+
store,
|
|
230
|
+
provider: fakeProvider,
|
|
231
|
+
constructAgent: () => ({
|
|
232
|
+
async run(_message, emit, options) {
|
|
233
|
+
emit({ kind: "text_delta", text: "partial" });
|
|
234
|
+
await new Promise<void>((_, reject) => {
|
|
235
|
+
const fail = (): void => {
|
|
236
|
+
reject(Object.assign(new Error("aborted"), { name: "AbortError" }));
|
|
237
|
+
};
|
|
238
|
+
if (options?.signal?.aborted) fail();
|
|
239
|
+
else options?.signal?.addEventListener("abort", fail, { once: true });
|
|
240
|
+
});
|
|
241
|
+
},
|
|
242
|
+
}),
|
|
243
|
+
},
|
|
244
|
+
{ message: "go" },
|
|
245
|
+
() => undefined,
|
|
246
|
+
{ signal: controller.signal },
|
|
247
|
+
);
|
|
248
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
249
|
+
controller.abort();
|
|
250
|
+
const session = await pending;
|
|
251
|
+
expect(
|
|
252
|
+
session?.messages.some(
|
|
253
|
+
(m) => m.kind === "turn" && m.role === "assistant" && m.content === "partial",
|
|
254
|
+
),
|
|
255
|
+
).toBe(true);
|
|
256
|
+
} finally {
|
|
257
|
+
await rm(cwd, { recursive: true, force: true });
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test("editUserTurn replaces the user message instead of appending", async () => {
|
|
262
|
+
const cwd = await mkdtemp(join(tmpdir(), "harness-edit-turn-"));
|
|
263
|
+
try {
|
|
264
|
+
const store = createFileSessionStore(cwd);
|
|
265
|
+
let session = await store.create("system");
|
|
266
|
+
session = await store.append(session, { kind: "turn", role: "user", content: "old" });
|
|
267
|
+
session = await store.append(session, {
|
|
268
|
+
kind: "turn",
|
|
269
|
+
role: "assistant",
|
|
270
|
+
content: "old reply",
|
|
271
|
+
});
|
|
272
|
+
await runTurn(
|
|
273
|
+
{
|
|
274
|
+
cwd,
|
|
275
|
+
name: "test",
|
|
276
|
+
systemPrompt: "test",
|
|
277
|
+
tools: [],
|
|
278
|
+
approval: createExecApprovalGate({ policy: "deny" }),
|
|
279
|
+
store,
|
|
280
|
+
provider: fakeProvider,
|
|
281
|
+
constructAgent: () => ({
|
|
282
|
+
async run(_message, emit) {
|
|
283
|
+
emit({ kind: "text_delta", text: "new reply" });
|
|
284
|
+
},
|
|
285
|
+
}),
|
|
286
|
+
},
|
|
287
|
+
{ message: "edited", sessionId: session.id, editUserTurn: 0 },
|
|
288
|
+
() => undefined,
|
|
289
|
+
);
|
|
290
|
+
const loaded = await store.get(session.id);
|
|
291
|
+
expect(sessionToProviderMessages(loaded!)).toEqual([
|
|
292
|
+
{ role: "user", content: "edited" },
|
|
293
|
+
{ role: "assistant", content: "new reply" },
|
|
294
|
+
]);
|
|
295
|
+
} finally {
|
|
296
|
+
await rm(cwd, { recursive: true, force: true });
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test("persists reasoning as a thought line before the assistant reply", async () => {
|
|
301
|
+
const cwd = await mkdtemp(join(tmpdir(), "harness-thought-"));
|
|
302
|
+
try {
|
|
303
|
+
const store = createFileSessionStore(cwd);
|
|
304
|
+
await runTurn(
|
|
305
|
+
{
|
|
306
|
+
cwd,
|
|
307
|
+
name: "test",
|
|
308
|
+
systemPrompt: "test",
|
|
309
|
+
tools: [],
|
|
310
|
+
approval: createExecApprovalGate({ policy: "deny" }),
|
|
311
|
+
store,
|
|
312
|
+
provider: fakeProvider,
|
|
313
|
+
constructAgent: () => ({
|
|
314
|
+
async run(_message, emit) {
|
|
315
|
+
emit({ kind: "reasoning_delta", text: "I should answer directly." });
|
|
316
|
+
emit({ kind: "text_delta", text: "ok" });
|
|
317
|
+
},
|
|
318
|
+
}),
|
|
319
|
+
},
|
|
320
|
+
{ message: "hi" },
|
|
321
|
+
() => undefined,
|
|
322
|
+
);
|
|
323
|
+
const listed = await store.list();
|
|
324
|
+
const session = listed[0];
|
|
325
|
+
expect(session?.messages.map((message) => message.kind)).toEqual([
|
|
326
|
+
"system",
|
|
327
|
+
"turn",
|
|
328
|
+
"thought",
|
|
329
|
+
"turn",
|
|
330
|
+
]);
|
|
331
|
+
const thought = session?.messages.find((message) => message.kind === "thought");
|
|
332
|
+
expect(thought && thought.kind === "thought" ? thought.text : "").toBe(
|
|
333
|
+
"I should answer directly.",
|
|
334
|
+
);
|
|
335
|
+
} finally {
|
|
336
|
+
await rm(cwd, { recursive: true, force: true });
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
});
|