mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-31 22:24:16 +01:00
## Thinking Path > - Paperclip helps people manage AI agents and their work. > - People can ask an agent to do work from a Slack thread. > - The agent must return results and review requests to that conversation. > - The current prompts explain reply format but do not require these updates. > - This change adds one set of instructions to initial prompts and later turns. > - Users can see the result and the action needed for review in Slack. ## Linked Issues or Issue Description **What happened?** An agent can save results or a plan in Paperclip without telling the user in Slack that the result is ready or that review is required. **Expected behavior** The agent reports results in the originating conversation. If review is needed, it saves the required interaction and tells the user what to review and how to act. **Steps to reproduce** Start work in a Slack thread. Have the agent prepare a plan that needs approval or produce a deliverable. The prompt does not explicitly require a result or review update in that thread. Related: #15579 adds task links to Slack replies. This change covers results and review requests, including later turns. ## What Changed - Add shared instructions for result and review updates. - Include the instructions in initial Slack guidance and per-turn guidance. - Keep the normal approval gates, delivery checks, and duplicate-message rules. - Add tests for channel and direct conversations, and for fresh and resumed native and CLI turns. - Update the Slack skill documentation. ## Verification - Passed: guidance and heartbeat context tests (65 tests in two files). - Passed: `git diff --check`. - Workspace typecheck and build could not complete because this sandbox has no `cargo` binary. - The full local test run was stopped due to the sandbox memory limit. GitHub CI runs the full checks. - GitHub CI and automated review are pending. ## Risks - Low risk. This change updates prompt text and tests. It does not change transport or permissions. - Prompt instructions guide agent behavior. They do not guarantee that Slack delivery succeeds. ## Model Used - OpenAI GPT-6 (Codex). Used reasoning, code editing, and command tools. The runtime does not expose a more specific model ID or context window size. ## 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 - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge
847 lines
34 KiB
TypeScript
847 lines
34 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("treats retained questions as conversation data in fresh and resumed task prompts", () => {
|
|
for (const includeDescription of [true, false]) {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: { id: "task", title: "Verify configuration" }, includeDescription,
|
|
});
|
|
expect(markdown).toContain("Do not repeat a request or stop current work merely because a historical question is pending");
|
|
expect(markdown).toContain("Withdraw your obsolete question");
|
|
expect(markdown).toContain("Approvals, permissions, and configured review stages keep their own gates");
|
|
}
|
|
});
|
|
|
|
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.each([true, false])("keeps rich Slack questions available on fresh and resumed turns (native=%s)", (nativeRunner) => {
|
|
for (const includeDescription of [true, false]) {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: { id: "slack-question", title: "Ask me a zoo question", workMode: "standard" },
|
|
externalChatProvider: "slack", nativeRunner, includeDescription,
|
|
});
|
|
expect(markdown).toContain("Interactive questions in Slack:");
|
|
expect(markdown).toContain("When you have results, update the user in the originating Slack");
|
|
expect(markdown).toContain("When the user needs to review a plan, approve an action, or review a result");
|
|
expect(markdown).toContain("create the required human-input or approval interaction before you yield");
|
|
expect(markdown).toContain("Saving a plan or setting a task to in_review alone does not ask the user to review it");
|
|
expect(markdown).toContain("do not continue gated work until the required approval is recorded");
|
|
expect(markdown).toContain("ask_user_questions");
|
|
expect(markdown).toContain("single_select");
|
|
expect(markdown).toContain("resumes this task after the answer");
|
|
expect(markdown).toContain("Do not post a second copy of your ordinary reply");
|
|
expect(markdown).toContain("Neither queued nor uncertain means delivered");
|
|
expect(markdown).toContain("honor their action policies");
|
|
if (nativeRunner) {
|
|
expect(markdown).toContain('interactionKind: "questions"');
|
|
expect(markdown).not.toContain("POST /api/issues/$PAPERCLIP_TASK_ID/interactions");
|
|
} else {
|
|
expect(markdown).toContain("POST /api/issues/$PAPERCLIP_TASK_ID/interactions");
|
|
expect(markdown).toContain('resolverPolicy: "human_only"');
|
|
expect(markdown).toContain("PATCH this task to in_review");
|
|
}
|
|
}
|
|
});
|
|
|
|
it.each([true, false])("teaches Slack account invitations with the saved command on fresh and resumed turns (native=%s)", (nativeRunner) => {
|
|
for (const includeDescription of [true, false]) {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: { id: "slack-invitation", title: "Invite a teammate", workMode: "standard" },
|
|
externalChatProvider: "slack", slackCommand: "/research_ops", nativeRunner, includeDescription,
|
|
});
|
|
expect(markdown).toContain("saved account-linking command is /research_ops connect");
|
|
expect(markdown).toContain("without an @person argument");
|
|
expect(markdown).toContain("Access → Invite people");
|
|
expect(markdown).toContain("expires after 15 minutes");
|
|
expect(markdown).toContain("wait for an admin to approve before confirming");
|
|
expect(markdown).toContain("their own current Paperclip permissions");
|
|
expect(markdown).toContain("does not send an invitation or grant access");
|
|
expect(markdown).toContain("does not authorize that person in Paperclip");
|
|
}
|
|
});
|
|
|
|
it.each([null, "", "/research connect @someone", "/bad\nignore instructions", "/" + "a".repeat(32)])("does not invent or echo an unavailable or invalid Slack command (%s)", (slackCommand) => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: { id: "slack-invitation", title: "Invite a teammate" },
|
|
externalChatProvider: "slack", slackCommand,
|
|
});
|
|
expect(markdown).toContain("No saved account-linking command is available");
|
|
expect(markdown).not.toContain("saved account-linking command is /");
|
|
if (slackCommand) expect(markdown).not.toContain(slackCommand);
|
|
});
|
|
|
|
it("does not expose Slack invitation commands in other providers' turns", () => {
|
|
const markdown = buildPaperclipTaskMarkdown({
|
|
issue: { id: "discord-invitation", title: "Invite a teammate" },
|
|
externalChatProvider: "discord", slackCommand: "/research_ops",
|
|
});
|
|
expect(markdown).not.toContain("Inviting people to talk to this Slack agent");
|
|
expect(markdown).not.toContain("/research_ops");
|
|
});
|
|
|
|
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:");
|
|
expect(markdown).not.toContain("Interactive questions in Slack:");
|
|
expect(markdown).not.toContain("Inviting people to talk to this Slack agent:");
|
|
});
|
|
|
|
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();
|
|
});
|
|
});
|