mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-02 10:44:52 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - The Runner sends authorized tool calls to the control plane. > - Agents use these calls to save plans and instruction files. > - The Runner used diagnostic secret detection to reject execution arguments. > - Ordinary credential-related prose could reject a document save before persistence. > - This pull request forwards the original arguments and leaves credential policy to the provider harness. > - The benefit is reliable saves with useful diagnostic records. ## Linked Issues or Issue Description Related foundation: Refs #12415 and #14430. No duplicate save-policy fix was found. **What happened?** A `write_document` call failed before the server saved its plan. The Runner reported `semantic tool input contains credential material; refusing to execute altered arguments`. The detector also masked ordinary phrases such as `secret manager` and `credential handling` in diagnostics. Both TypeScript dispatchers had equivalent execution gates. One dispatcher also rewrote structured approval and question payloads before execution. **Expected behavior** Paperclip forwards authorized arguments unchanged. The provider harness decides credential-content policy. Log and audit redaction does not reject or rewrite save input. **Steps to reproduce** 1. Send an authorized `write_document` call with a plan that discusses credential handling. 2. Include an intentional credential value in the body to exercise harness-owned policy. 3. The old Runner rejects the call. With this change, the document service stores the exact body. 4. Diagnostic records still mask explicit credential values. Qualified credential fields, short bearer values, opaque diagnostic pairs, and valid encoded JSON token headers have regression coverage. **Paperclip version or commit** Reproduced at `c46e41e81c03cd3c8b64cf993615b604d7fe8c62`. The branch is based on current `master`. **Deployment mode** Server deployment with the native Paperclip Runner. Local regression tests use the real document service and an embedded test database. ## What Changed - Remove credential-content vetoes from Rust admission and both TypeScript semantic dispatchers. - Preserve original structured approval and question arguments during execution. - Keep transport bounds, schema checks, authorization, idempotency, and audit masking. - Require explicit credential syntax or recognized formats for diagnostic masking. Preserve ordinary prose, metadata, and dotted identifiers. - Test exact document persistence, replay, nested argument identities, and masked audit copies. - Remove obsolete retry guidance and document harness-owned credential policy. ## Verification - `cargo test --manifest-path packages/paperclip-runner/runner/Cargo.toml --locked -p paperclip-runner-core --lib --test acpx_event_payload --test acpx_provider_state --test acpx_provider_turns`: 355 tests passed. - Focused server and adapter tests: 189 tests passed after rebase. These include the real document save and the complete tool-gateway suite. - Semantic dispatcher and conformance tests: 34 tests passed. - Diagnostic redaction and MCP tests: 46 tests passed, including all six review examples. - `pnpm -r typecheck` and `pnpm build` passed on the repaired branch. - The broad local root suite was interrupted after database fixture setup failures. The focused database suites passed. CI runs the complete configured test lanes. ## Risks - Authorized tool arguments can intentionally contain credentials. The harness must enforce its content policy. - Diagnostic detection is narrower. Explicit assignments, credential fields, and recognized credential formats remain masked. - The change does not add a database migration or change company authorization. ## Model Used - OpenAI GPT-6 through Codex. The session exposes the GPT-6 model family; its exact runtime model identifier and context window size are not exposed. Used reasoning, tool use, and code execution. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
769 lines
30 KiB
TypeScript
769 lines
30 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
buildPaperclipTaskMarkdown,
|
|
mergeCoalescedContextSnapshot,
|
|
summarizeHeartbeatRunContextSnapshot,
|
|
summarizeHeartbeatRunListResultJson,
|
|
} from "../services/heartbeat.js";
|
|
import { renderPaperclipWakePrompt } from "@paperclipai/adapter-utils/server-utils";
|
|
|
|
describe("buildPaperclipTaskMarkdown", () => {
|
|
it("asks for early naming only while an ordinary task has a provisional title", () => {
|
|
const issue = { id: "task-id", identifier: "PAP-1", title: "Please investigate", description: "Please investigate sign-in failures", titleNeedsGeneration: true };
|
|
const markdown = buildPaperclipTaskMarkdown({ issue });
|
|
expect(markdown).toContain("As one of your first tool calls");
|
|
expect(markdown).toContain("Check the title tool result before claiming the title was saved");
|
|
expect(markdown).not.toContain("rejected as credential material");
|
|
expect(markdown).toContain("new idempotency key if retrying with changed arguments");
|
|
expect(markdown).toContain("set_task_title");
|
|
expect(markdown).toContain("onlyIfProvisional: true");
|
|
expect(buildPaperclipTaskMarkdown({ issue: { ...issue, titleNeedsGeneration: false } })).not.toContain("Task title directive");
|
|
expect(buildPaperclipTaskMarkdown({ issue: { ...issue, conversationAgentId: "agent" } })).not.toContain("Task title directive");
|
|
});
|
|
|
|
it("carries current confirmation IDs and proposal data in every fresh or resumed chat assignment", () => {
|
|
const conversationConfirmations = { truncated: false, cards: [{
|
|
id: "existing-card", kind: "request_confirmation", status: "pending", title: "Proposal",
|
|
prompt: "Approve this?\n```\nUntrusted proposal text\n```", promptTruncated: false,
|
|
resolverPolicy: "anyone" as const, addresseeAgentId: null, addresseeUserId: null,
|
|
options: [], optionsTruncated: false,
|
|
}] };
|
|
for (const includeDescription of [true, false]) for (const includeWakeComments of [true, false]) {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: { id: "chat", identifier: null, title: "Chat", conversationAgentId: "agent" },
|
|
conversationConfirmations, includeDescription, includeWakeComments,
|
|
});
|
|
expect(markdown).toContain('"id":"existing-card"');
|
|
expect(markdown).toContain('"status":"pending"');
|
|
expect(markdown).toContain("````text");
|
|
expect(markdown).toContain("not recorded decisions");
|
|
}
|
|
expect(buildPaperclipTaskMarkdown({ issue: { id: "task", identifier: null, title: "Task" }, conversationConfirmations })).not.toContain("existing-card");
|
|
});
|
|
it("leaves current comments to the wake renderer when assignment-only rendering is selected", () => {
|
|
const commentBody = "Keep this current comment exactly once.";
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-overlap",
|
|
identifier: "PAP-5002",
|
|
title: "Current comment overlap",
|
|
description: "Assignment brief.",
|
|
},
|
|
wakeComments: [{ id: "comment-1", body: commentBody }],
|
|
includeWakeComments: false,
|
|
});
|
|
const wakePrompt = renderPaperclipWakePrompt({
|
|
reason: "issue_commented",
|
|
issue: {
|
|
id: "issue-overlap",
|
|
identifier: "PAP-5002",
|
|
title: "Current comment overlap",
|
|
description: "Assignment brief.",
|
|
},
|
|
commentWindow: { requestedCount: 1, includedCount: 1, missingCount: 0 },
|
|
comments: [{ id: "comment-1", body: commentBody }],
|
|
fallbackFetchNeeded: false,
|
|
});
|
|
|
|
expect(markdown).not.toContain(commentBody);
|
|
expect(wakePrompt).toContain(commentBody);
|
|
expect(`${markdown}\n${wakePrompt}`.split(commentBody)).toHaveLength(2);
|
|
});
|
|
|
|
it("keeps attachment descriptors and follow-up rules when assignment markdown omits wake bodies", () => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: { id: "issue-files", identifier: "PAP-5003", title: "Files", description: "Brief" },
|
|
wakeComments: [{
|
|
id: "comment-files",
|
|
body: "Inspect the file.",
|
|
attachments: [{
|
|
id: "attachment-1",
|
|
filename: "evidence.png",
|
|
contentType: "image/png",
|
|
byteSize: 42,
|
|
contentPath: "/api/attachments/attachment-1/content",
|
|
}],
|
|
}],
|
|
includeWakeComments: false,
|
|
});
|
|
|
|
expect(markdown).not.toContain("Inspect the file.");
|
|
expect(markdown).toContain("Follow-up directive:");
|
|
expect(markdown).toContain('Attachments on wake comment "comment-files":');
|
|
expect(markdown).toContain('"id":"attachment-1"');
|
|
});
|
|
|
|
it("preserves repeated same-body wake events as distinct ordered comments", () => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: { id: "issue-order", identifier: "PAP-5004", title: "Order", description: null },
|
|
wakeComments: [
|
|
{ id: "comment-a", body: "Repeat me." },
|
|
{ id: "comment-b", body: "Repeat me." },
|
|
],
|
|
});
|
|
expect(markdown!.indexOf('"comment-a"')).toBeLessThan(markdown!.indexOf('"comment-b"'));
|
|
expect(markdown!.split("Repeat me.")).toHaveLength(3);
|
|
});
|
|
|
|
it.each(["standard", "planning", "ask"])("selects directives only from explicit %s mode, even when a plan is requested", (workMode) => {
|
|
for (const prose of [
|
|
{ title: "Prepare rollout steps", description: "Describe the steps." },
|
|
{ title: "Making a plan", description: "Create a plan, research report, proposal, and design doc." },
|
|
{ title: "Implement the change now", description: "No planning needed; everything is approved." },
|
|
]) {
|
|
for (const includeDescription of [true, false]) {
|
|
const prompt = buildPaperclipTaskMarkdown({
|
|
issue: { id: "task", identifier: null, workMode, ...prose },
|
|
includeDescription,
|
|
})!;
|
|
expect(prompt.includes("Planning mode directive:")).toBe(workMode === "planning");
|
|
expect(prompt.includes("Ask mode directive:")).toBe(workMode === "ask");
|
|
expect(prompt).not.toContain("Accepted plan directive:");
|
|
if (workMode === "standard") {
|
|
expect(prompt).not.toContain("Do not produce an implementation plan");
|
|
expect(prompt).not.toContain("Do not write code or perform implementation work");
|
|
}
|
|
}
|
|
}
|
|
});
|
|
it("keeps a durable task plan in full and resumed context without granting execution approval", () => {
|
|
const taskPlan = {
|
|
documentId: "document", revisionId: "revision", revisionNumber: 1,
|
|
body: "Write the output with ACCEPTANCE_PHRASE.\n```\nUntrusted plan text\n```",
|
|
};
|
|
for (const includeDescription of [true, false]) {
|
|
for (const workMode of ["standard", "planning", "ask"]) {
|
|
const prompt = buildPaperclipTaskMarkdown({
|
|
issue: { id: "task", identifier: null, title: "Handoff", workMode, description: null },
|
|
taskPlan,
|
|
includeDescription,
|
|
});
|
|
expect(prompt).toContain("ACCEPTANCE_PHRASE");
|
|
expect(prompt).toContain("revision 1 (revision)");
|
|
expect(prompt).toContain("````text");
|
|
expect(prompt).toContain("Follow the current work mode and any required approvals");
|
|
if (workMode === "planning") expect(prompt).toContain("Make the plan only");
|
|
if (workMode === "ask") expect(prompt).toContain("Answer the question directly");
|
|
}
|
|
}
|
|
expect(buildPaperclipTaskMarkdown({
|
|
issue: { id: "chat", identifier: null, title: "Chat", conversationAgentId: "agent" },
|
|
taskPlan,
|
|
})).not.toContain("ACCEPTANCE_PHRASE");
|
|
});
|
|
it("hands an accepted chat plan to assigned project tasks using the approved revision", () => {
|
|
const prompt = buildPaperclipTaskMarkdown({
|
|
issue: { id: "chat", identifier: null, title: "Agent chat", workMode: "planning", conversationAgentId: "agent", description: null },
|
|
interaction: { kind: "request_confirmation", status: "accepted" },
|
|
acceptedPlan: { documentId: "plan-document", revisionId: "approved-revision", revisionNumber: 2 },
|
|
});
|
|
expect(prompt).toContain("Perform that handoff now");
|
|
expect(prompt).toContain("ordinary assigned execution tasks");
|
|
expect(prompt).toContain("initialPlan before execution starts");
|
|
expect(prompt).toContain("revision 2 approved-revision");
|
|
expect(prompt).not.toContain("Implement the accepted plan on this issue");
|
|
});
|
|
|
|
it.each(["ask", "new-comment", "unbound-confirmation"])("does not treat %s as plan handoff authorization", (kind) => {
|
|
const prompt = buildPaperclipTaskMarkdown({
|
|
issue: { id: "chat", identifier: null, title: "Agent chat", workMode: kind === "ask" ? "ask" : "planning", conversationAgentId: "agent", description: null },
|
|
interaction: { kind: "request_confirmation", status: "accepted" },
|
|
...(kind === "unbound-confirmation" ? {} : { acceptedPlan: { documentId: "plan-document", revisionId: "approved-revision", revisionNumber: 2 } }),
|
|
...(kind === "new-comment" ? { wakeComment: { id: "later-comment", body: "Please revise it again first." } } : {}),
|
|
});
|
|
expect(prompt).not.toContain("Perform that handoff now");
|
|
});
|
|
|
|
it("surfaces every coalesced wake comment in provider order", () => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-burst",
|
|
identifier: "PAP-5000",
|
|
title: "Handle a chat burst",
|
|
workMode: "standard",
|
|
description: "Original request",
|
|
},
|
|
wakeComment: {
|
|
id: "comment-3",
|
|
body: "burst-four",
|
|
},
|
|
wakeComments: [
|
|
{ id: "comment-1", body: "burst-two" },
|
|
{ id: "comment-2", body: "burst-three" },
|
|
{ id: "comment-3", body: "burst-four" },
|
|
],
|
|
});
|
|
|
|
expect(markdown).toContain(
|
|
"Address every comment without repeating completed work.",
|
|
);
|
|
expect(markdown).toContain("Pending wake comments (oldest to newest):");
|
|
expect(markdown).not.toContain("Latest wake comment:");
|
|
expect(markdown!.indexOf("burst-two")).toBeLessThan(
|
|
markdown!.indexOf("burst-three"),
|
|
);
|
|
expect(markdown!.indexOf("burst-three")).toBeLessThan(
|
|
markdown!.indexOf("burst-four"),
|
|
);
|
|
});
|
|
|
|
it("surfaces exact wake-comment attachment descriptors and inspection guidance", () => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-attachments",
|
|
identifier: "PAP-5001",
|
|
title: "Inspect provider files",
|
|
workMode: "standard",
|
|
description: null,
|
|
},
|
|
wakeComments: [
|
|
{
|
|
id: "comment-files",
|
|
body: "Identify the image and quote the text file.",
|
|
attachments: [
|
|
{
|
|
id: "attachment-image",
|
|
filename: "evidence.png",
|
|
contentType: "image/png",
|
|
byteSize: 2048,
|
|
contentPath: "/api/attachments/attachment-image/content",
|
|
},
|
|
{
|
|
id: "attachment-text",
|
|
filename: "phrase.txt",
|
|
contentType: "text/plain",
|
|
byteSize: 128,
|
|
contentPath: "/api/attachments/attachment-text/content",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(markdown).toContain(
|
|
'Attachments on wake comment "comment-files":',
|
|
);
|
|
expect(markdown).toContain('"id":"attachment-image"');
|
|
expect(markdown).toContain('"filename":"phrase.txt"');
|
|
expect(markdown).toContain(
|
|
'"contentPath":"/api/attachments/attachment-text/content"',
|
|
);
|
|
expect(markdown).toContain("PAPERCLIP_API_URL");
|
|
expect(markdown).toContain("PAPERCLIP_API_KEY");
|
|
expect(markdown).toContain("never invoke `npx`");
|
|
expect(markdown).toContain(
|
|
"Do not infer file contents from filenames or metadata",
|
|
);
|
|
});
|
|
|
|
it.each(["slack", "discord", "telegram", "microsoft-teams", "github"])(
|
|
"directs %s file replies through the bundled artifact handoff",
|
|
(externalChatProvider) => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-file-reply",
|
|
title: "Send the requested image and file",
|
|
workMode: "standard",
|
|
description: null,
|
|
},
|
|
externalChatProvider,
|
|
});
|
|
expect(markdown).toContain("External chat file delivery:");
|
|
expect(markdown).toContain("paperclip-upload-artifact.sh --chat-comment");
|
|
expect(markdown).toContain("installed skill location, not the task workspace");
|
|
expect(markdown).toContain("Do not search for a separate provider tool connection");
|
|
expect(markdown).toContain("do not claim provider delivery merely because binding succeeded");
|
|
expect(markdown).toContain(
|
|
"one helper command per file into as few tool calls as practical",
|
|
);
|
|
expect(markdown).toContain("do not manually bind the same file again");
|
|
expect(markdown).toContain(
|
|
"Retry or investigate only a failed or ambiguous step",
|
|
);
|
|
},
|
|
);
|
|
|
|
it("omits external file handoff instructions from non-chat tasks", () => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-internal",
|
|
title: "An internal task",
|
|
workMode: "standard",
|
|
description: null,
|
|
},
|
|
});
|
|
expect(markdown).not.toContain("External chat file delivery:");
|
|
expect(markdown).not.toContain("External chat turn efficiency:");
|
|
});
|
|
|
|
it.each(["slack", "discord", "telegram", "microsoft-teams", "github"])(
|
|
"directs native %s files through scoped tools without legacy credentials",
|
|
(externalChatProvider) => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "native-files",
|
|
title: "Inspect and share requested files",
|
|
workMode: "standard",
|
|
description: null,
|
|
},
|
|
externalChatProvider,
|
|
nativeRunner: true,
|
|
wakeComments: [{
|
|
id: "native-file-comment",
|
|
body: "Inspect this image, then send the requested file.",
|
|
attachments: [{
|
|
id: "native-attachment",
|
|
filename: "image.png",
|
|
contentType: "image/png",
|
|
byteSize: 2048,
|
|
contentPath: "/api/attachments/native-attachment/content",
|
|
}],
|
|
}],
|
|
});
|
|
expect(markdown).toContain("`register_deliverable`");
|
|
expect(markdown).toContain("workspace-relative `contentRef`");
|
|
expect(markdown).toContain("do not confirm provider delivery");
|
|
expect(markdown).toContain("Register or reuse only the requested files");
|
|
expect(markdown).toContain("`list_chat_attachments`");
|
|
expect(markdown).toContain("`reuse_chat_attachment`");
|
|
expect(markdown).toContain(
|
|
"never substitute an earlier file for unavailable current-turn input",
|
|
);
|
|
expect(markdown).toContain("workspace-relative staged attachment descriptors");
|
|
expect(markdown).toContain("clearly state that you could not inspect it");
|
|
expect(markdown).toContain("batch independent reads/inspection with the appropriate available tools");
|
|
expect(markdown).toContain("Compute exact sizes and SHA-256 hashes in the same preparation step");
|
|
expect(markdown).toContain("batch independent per-file registrations into as few tool calls as practical");
|
|
expect(markdown).toContain("one registration and a distinct stable idempotencyKey per file");
|
|
expect(markdown).toContain("wait for each receipt before the final-response protocol");
|
|
expect(markdown).toContain("retry only a failed or ambiguous step with its original key");
|
|
expect(markdown).toContain("current source/generation authorization, exact-byte reuse, or approval gates");
|
|
expect(markdown).toContain("skip a separate preamble and narration before each step");
|
|
expect(markdown).toContain("Keep useful wait, blocker, permission, and failure updates");
|
|
expect(markdown).toContain("do not suppress transport-managed progress");
|
|
expect(markdown).toContain('"id":"native-attachment"');
|
|
expect(markdown).not.toContain("paperclip-upload-artifact.sh");
|
|
expect(markdown).not.toContain("PAPERCLIP_API_KEY");
|
|
expect(markdown).not.toContain("/api/attachments/");
|
|
},
|
|
);
|
|
|
|
it.each([
|
|
{ nativeRunner: false, externalChatProvider: "slack" },
|
|
{ nativeRunner: true, externalChatProvider: null },
|
|
])("keeps native media batching out of unrelated instruction paths: %j", (mode) => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: { id: "other-workflow", identifier: null, title: "Other work" },
|
|
...mode,
|
|
});
|
|
expect(markdown).not.toContain("batch independent per-file registrations");
|
|
expect(markdown).not.toContain("skip a separate preamble and narration before each step");
|
|
});
|
|
|
|
it("does not imply that GitHub chat grants attachment or repository-tool access", () => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-github-chat",
|
|
identifier: "PAP-5002",
|
|
title: "Inspect a GitHub comment",
|
|
workMode: "standard",
|
|
description: null,
|
|
},
|
|
wakeComments: [
|
|
{
|
|
id: "comment-github",
|
|
body: "Inspect https://user-images.githubusercontent.com/example/file.png",
|
|
},
|
|
],
|
|
externalChatProvider: "github",
|
|
});
|
|
|
|
expect(markdown).toContain("GitHub chat attachment note:");
|
|
expect(markdown).toContain(
|
|
"does not grant repository-tool or attachment-download authority",
|
|
);
|
|
expect(markdown).toContain(
|
|
"do not ask for another chat connection",
|
|
);
|
|
expect(markdown).toContain(
|
|
"attach the file directly to this Paperclip task or paste the needed text",
|
|
);
|
|
expect(markdown).toContain(
|
|
"Never borrow browser cookies or forward credentials to an attachment URL",
|
|
);
|
|
});
|
|
|
|
it("adds planning directives for assignment and comment task context", () => {
|
|
const assignment = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-1",
|
|
identifier: "PAP-3404",
|
|
title: "Plan first",
|
|
workMode: "planning",
|
|
description: null,
|
|
},
|
|
});
|
|
|
|
expect(assignment).toContain("- Work mode: \"planning\"");
|
|
expect(assignment).toContain("Make the plan only. Do not write code or perform implementation work.");
|
|
|
|
const commentWake = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-1",
|
|
identifier: "PAP-3404",
|
|
title: "Plan first",
|
|
workMode: "planning",
|
|
description: null,
|
|
},
|
|
wakeComment: {
|
|
id: "comment-1",
|
|
body: "Please revise the plan.",
|
|
},
|
|
});
|
|
|
|
expect(commentWake).toContain("Update the plan only. Do not write code or perform implementation work.");
|
|
|
|
const acceptedConfirmation = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-1",
|
|
identifier: "PAP-3404",
|
|
title: "Plan first",
|
|
workMode: "planning",
|
|
description: null,
|
|
},
|
|
interaction: {
|
|
kind: "request_confirmation",
|
|
status: "accepted",
|
|
},
|
|
});
|
|
|
|
expect(acceptedConfirmation).toContain(
|
|
"Implement the accepted plan on this issue when the work is small and cohesive.",
|
|
);
|
|
expect(acceptedConfirmation).not.toContain("Make the plan only.");
|
|
});
|
|
|
|
it("adds accepted-plan continuation guidance for standard-work issues when the wake is flagged as a plan continuation", () => {
|
|
const acceptedConfirmation = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-2",
|
|
identifier: "PAP-415",
|
|
title: "Implement the fix",
|
|
workMode: "standard",
|
|
description: null,
|
|
},
|
|
acceptedPlanContinuation: true,
|
|
});
|
|
|
|
expect(acceptedConfirmation).toContain("Accepted plan directive:");
|
|
expect(acceptedConfirmation).toContain(
|
|
"Implement the accepted plan on this issue when the work is small and cohesive.",
|
|
);
|
|
expect(acceptedConfirmation).not.toContain("- Work mode: \"planning\"");
|
|
});
|
|
|
|
it("adds answer-only guidance for ask-mode issues", () => {
|
|
const assignment = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-ask",
|
|
identifier: "PAP-416",
|
|
title: "Explain the tradeoff",
|
|
workMode: "ask",
|
|
description: null,
|
|
},
|
|
});
|
|
|
|
expect(assignment).toContain("- Work mode: \"ask\"");
|
|
expect(assignment).toContain("Ask mode directive:");
|
|
expect(assignment).toContain("Answer the question directly in the issue thread.");
|
|
expect(assignment).toContain("Do not write implementation code");
|
|
expect(assignment).toContain("do not produce an implementation plan");
|
|
});
|
|
|
|
it("adds dry-run containment guidance for skill-test issues", () => {
|
|
const assignment = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-skill-test",
|
|
identifier: "PAP-417",
|
|
title: "Test skill draft",
|
|
workMode: "skill_test",
|
|
description: null,
|
|
},
|
|
});
|
|
|
|
expect(assignment).toContain("- Work mode: \"skill_test\"");
|
|
expect(assignment).toContain("Skill test mode directive:");
|
|
expect(assignment).toContain("Make no durable changes outside this issue.");
|
|
expect(assignment).toContain("Write your final output as issue document `output`");
|
|
});
|
|
|
|
it("strips the description for the compact resume variant but keeps directives and the wake comment", () => {
|
|
const input = {
|
|
issue: {
|
|
id: "issue-1",
|
|
identifier: "PAP-3404",
|
|
title: "Ship the fix",
|
|
workMode: "standard",
|
|
description: "Full multi-paragraph brief that the session already received.",
|
|
},
|
|
wakeComment: {
|
|
id: "comment-1",
|
|
body: "Please also update the changelog.",
|
|
},
|
|
};
|
|
|
|
const full = buildPaperclipTaskMarkdown(input);
|
|
expect(full).toContain("Issue description:");
|
|
expect(full).toContain("Full multi-paragraph brief that the session already received.");
|
|
|
|
const compact = buildPaperclipTaskMarkdown({ ...input, includeDescription: false });
|
|
expect(compact).not.toContain("Issue description:");
|
|
expect(compact).not.toContain("Full multi-paragraph brief");
|
|
expect(compact).toContain("- Issue: \"PAP-3404\"");
|
|
expect(compact).toContain("Please also update the changelog.");
|
|
});
|
|
|
|
it("makes the latest wake comment the immediate follow-up request", () => {
|
|
const commentWake = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-follow-up",
|
|
identifier: "PAP-418",
|
|
title: "Original task",
|
|
workMode: "standard",
|
|
description: "Reply with the original answer.",
|
|
},
|
|
wakeComment: {
|
|
id: "comment-follow-up",
|
|
body: "Reply with the new answer instead.",
|
|
},
|
|
});
|
|
|
|
expect(commentWake).toContain("Apply the latest wake comment to the current task.");
|
|
expect(commentWake).toContain("Later direction replaces conflicting scope");
|
|
expect(commentWake).toContain("preserve other requirements and approval gates");
|
|
expect(commentWake).not.toContain("unless the latest comment asks you to");
|
|
expect(commentWake).toContain("Reply with the new answer instead.");
|
|
});
|
|
|
|
it("prefers ordinary comment planning guidance over stale accepted confirmation state", () => {
|
|
const commentWake = buildPaperclipTaskMarkdown({
|
|
issue: {
|
|
id: "issue-1",
|
|
identifier: "PAP-3404",
|
|
title: "Plan first",
|
|
workMode: "planning",
|
|
description: null,
|
|
},
|
|
wakeComment: {
|
|
id: "comment-1",
|
|
body: "Please revise the plan.",
|
|
},
|
|
interaction: {
|
|
kind: "request_confirmation",
|
|
status: "accepted",
|
|
},
|
|
});
|
|
|
|
expect(commentWake).toContain("Update the plan only. Do not write code or perform implementation work.");
|
|
expect(commentWake).not.toContain("Create child issues from the approved plan only");
|
|
});
|
|
});
|
|
|
|
describe("mergeCoalescedContextSnapshot", () => {
|
|
it("clears stale accepted-plan interaction state when merging a later ordinary comment wake", () => {
|
|
const merged = mergeCoalescedContextSnapshot(
|
|
{
|
|
issueId: "issue-1",
|
|
interactionId: "interaction-1",
|
|
interactionKind: "request_confirmation",
|
|
interactionStatus: "accepted",
|
|
continuationPolicy: "wake_assignee_on_accept",
|
|
checkboxSelection: {
|
|
prompt: "Delete selected files?",
|
|
selectedOptionIds: ["file-b"],
|
|
selectedOptions: [{ id: "file-b", label: "b.txt", description: "Generated build output" }],
|
|
},
|
|
wakeReason: "issue_commented",
|
|
},
|
|
{
|
|
issueId: "issue-1",
|
|
commentId: "comment-1",
|
|
wakeCommentId: "comment-1",
|
|
wakeReason: "issue_commented",
|
|
},
|
|
);
|
|
|
|
expect(merged.interactionId).toBeUndefined();
|
|
expect(merged.interactionKind).toBeUndefined();
|
|
expect(merged.interactionStatus).toBeUndefined();
|
|
expect(merged.continuationPolicy).toBeUndefined();
|
|
expect(merged.checkboxSelection).toBeUndefined();
|
|
expect(merged.commentId).toBe("comment-1");
|
|
expect(merged.wakeCommentId).toBe("comment-1");
|
|
});
|
|
|
|
it("preserves resolved interaction state for the interaction wake itself", () => {
|
|
const merged = mergeCoalescedContextSnapshot(
|
|
{
|
|
issueId: "issue-1",
|
|
},
|
|
{
|
|
issueId: "issue-1",
|
|
interactionId: "interaction-1",
|
|
interactionKind: "request_confirmation",
|
|
interactionStatus: "accepted",
|
|
continuationPolicy: "wake_assignee_on_accept",
|
|
checkboxSelection: {
|
|
prompt: "Delete selected files?",
|
|
selectedOptionIds: ["file-b"],
|
|
selectedOptions: [{ id: "file-b", label: "b.txt", description: "Generated build output" }],
|
|
},
|
|
wakeReason: "issue_commented",
|
|
},
|
|
);
|
|
|
|
expect(merged.interactionId).toBe("interaction-1");
|
|
expect(merged.interactionKind).toBe("request_confirmation");
|
|
expect(merged.interactionStatus).toBe("accepted");
|
|
expect(merged.continuationPolicy).toBe("wake_assignee_on_accept");
|
|
expect(merged.checkboxSelection).toEqual({
|
|
prompt: "Delete selected files?",
|
|
selectedOptionIds: ["file-b"],
|
|
selectedOptions: [{ id: "file-b", label: "b.txt", description: "Generated build output" }],
|
|
});
|
|
});
|
|
|
|
it("preserves a deferred interaction when a later comment joins its successor wake", () => {
|
|
const merged = mergeCoalescedContextSnapshot(
|
|
{
|
|
issueId: "issue-1",
|
|
interactionId: "interaction-1",
|
|
interactionKind: "request_confirmation",
|
|
interactionStatus: "accepted",
|
|
continuationPolicy: "wake_assignee_on_accept",
|
|
wakeReason: "issue_commented",
|
|
},
|
|
{
|
|
issueId: "issue-1",
|
|
commentId: "comment-1",
|
|
wakeCommentId: "comment-1",
|
|
wakeReason: "issue_commented",
|
|
},
|
|
{ preserveExistingInteractionContinuation: true },
|
|
);
|
|
|
|
expect(merged.interactionId).toBe("interaction-1");
|
|
expect(merged.interactionKind).toBe("request_confirmation");
|
|
expect(merged.interactionStatus).toBe("accepted");
|
|
expect(merged.continuationPolicy).toBe("wake_assignee_on_accept");
|
|
expect(merged.commentId).toBe("comment-1");
|
|
expect(merged.wakeCommentId).toBe("comment-1");
|
|
});
|
|
|
|
it("keeps a queued comment when an interaction joins its successor wake", () => {
|
|
const merged = mergeCoalescedContextSnapshot(
|
|
{
|
|
issueId: "issue-1",
|
|
commentId: "comment-1",
|
|
wakeCommentId: "comment-1",
|
|
wakeCommentIds: ["comment-1"],
|
|
wakeReason: "issue_commented",
|
|
},
|
|
{
|
|
issueId: "issue-1",
|
|
interactionId: "interaction-1",
|
|
interactionKind: "ask_user_questions",
|
|
interactionStatus: "answered",
|
|
continuationPolicy: "wake_assignee_on_accept",
|
|
wakeReason: "issue_commented",
|
|
},
|
|
{ preserveExistingInteractionContinuation: true },
|
|
);
|
|
|
|
expect(merged.interactionId).toBe("interaction-1");
|
|
expect(merged.interactionKind).toBe("ask_user_questions");
|
|
expect(merged.interactionStatus).toBe("answered");
|
|
expect(merged.commentId).toBe("comment-1");
|
|
expect(merged.wakeCommentId).toBe("comment-1");
|
|
expect(merged.wakeCommentIds).toEqual(["comment-1"]);
|
|
});
|
|
});
|
|
|
|
describe("summarizeHeartbeatRunContextSnapshot", () => {
|
|
it("keeps only the small retry/linking fields needed by the client", () => {
|
|
const summarized = summarizeHeartbeatRunContextSnapshot({
|
|
issueId: "issue-1",
|
|
taskId: "task-1",
|
|
taskKey: "PAP-1",
|
|
commentId: "comment-1",
|
|
wakeCommentId: "comment-2",
|
|
wakeReason: "retry_failed_run",
|
|
wakeSource: "on_demand",
|
|
wakeTriggerDetail: "manual",
|
|
paperclipWake: {
|
|
comments: [
|
|
{
|
|
body: "x".repeat(50_000),
|
|
},
|
|
],
|
|
},
|
|
executionStage: {
|
|
summary: "large nested object that should not be sent back in run lists",
|
|
},
|
|
});
|
|
|
|
expect(summarized).toEqual({
|
|
issueId: "issue-1",
|
|
taskId: "task-1",
|
|
taskKey: "PAP-1",
|
|
commentId: "comment-1",
|
|
wakeCommentId: "comment-2",
|
|
wakeReason: "retry_failed_run",
|
|
wakeSource: "on_demand",
|
|
wakeTriggerDetail: "manual",
|
|
});
|
|
});
|
|
|
|
it("returns null when no allowed fields are present", () => {
|
|
expect(
|
|
summarizeHeartbeatRunContextSnapshot({
|
|
paperclipWake: { comments: [{ body: "hello" }] },
|
|
}),
|
|
).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("summarizeHeartbeatRunListResultJson", () => {
|
|
it("keeps only summary fields and parses numeric cost aliases", () => {
|
|
expect(
|
|
summarizeHeartbeatRunListResultJson({
|
|
summary: "Completed the task",
|
|
result: "Updated three files",
|
|
message: "",
|
|
error: null,
|
|
totalCostUsd: "1.25",
|
|
costUsd: "0.75",
|
|
costUsdCamel: "0.5",
|
|
}),
|
|
).toEqual({
|
|
summary: "Completed the task",
|
|
result: "Updated three files",
|
|
total_cost_usd: 1.25,
|
|
cost_usd: 0.75,
|
|
costUsd: 0.5,
|
|
});
|
|
});
|
|
|
|
it("returns null when projected fields are empty", () => {
|
|
expect(
|
|
summarizeHeartbeatRunListResultJson({
|
|
summary: "",
|
|
result: null,
|
|
message: undefined,
|
|
error: " ",
|
|
totalCostUsd: "abc",
|
|
}),
|
|
).toBeNull();
|
|
});
|
|
});
|