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. > - Issue interactions give agents and people a structured decision record. > - Resolver routes used different authorization rules. > - Some routes blocked valid agents, including task watchdogs with normal issue access. > - The API did not show who could resolve a pending interaction. > - This pull request gives every interaction kind one resolver policy evaluator. > - The benefit is a clear decision path with consistent governance and company isolation. ## Linked Issues or Issue Description Fixes: #8087 Refs: #7403 Related PR: #11082 proposes board-only confirmation rules. This change keeps human-only review as an explicit policy. **What happened?** Agents could create issue interactions. Some resolver routes still required board access. This left valid agent confirmations pending. Task watchdogs could see the same problem without board identity. **Expected behavior** Every interaction kind must use one resolver policy contract. The contract must support `anyone`, `not_creator`, and `human_only`. It must also apply all normal governance controls. **Steps to reproduce** 1. Create a `request_confirmation` interaction as an agent. 2. Resolve it with another authorized agent. 3. Observe the board-only denial. **Paperclip version or commit** The problem exists on `master` before this change. **Deployment mode** Local development with `pnpm dev`. ## What Changed - Add canonical policies for `anyone`, `not_creator`, and `human_only`. - Use one server evaluator for every interaction kind. - Apply named addressees, company limits, review rules, and task watchdog scope. - Charge cross-issue resolutions to the existing per-run action limit. - Return the effective resolver audience in attention and interaction data. - Show the audience, governance choices, and denial reasons in the board UI. - Add telemetry, API documents, product documents, and regression fixtures. - Add migration provenance for safe legacy behavior. - Make migration `0218` safe for complete replays and partial prior runs. ## Product Rules - An interaction records a response. It does not grant authority for the next action. - `anyone` lets any authorized issue participant respond. - `not_creator` requires a responder other than the interaction creator. - `human_only` requires an authorized person. - A named addressee, company policy, or governed action can narrow the audience. - These controls cannot widen the audience. - A task watchdog uses the same rules as an ordinary agent. - A task watchdog does not receive board authority. - An agent resolution on another issue uses the shared cross-issue action limit. - Legacy pending interactions keep their earlier restrictions. - The UI shows the effective audience and a permanent denial reason. ## Verification - `pnpm --filter @paperclipai/db check:migrations` - `pnpm --filter @paperclipai/db typecheck` - `pnpm exec vitest run packages/db/src/issue-thread-interaction-resolver-policy-migration.test.ts` - The focused PostgreSQL test applies migration `0218` twice. - The test also completes a partial prior run and preserves existing provenance. - The latest GitHub head has 29 successful checks. - The opt-in Storybook visual check skipped as expected. - Greptile reports 5/5 with no open comments. ## Risks - New interaction writes use `anyone` by default. - Callers must select `not_creator` or `human_only` when they need stricter review. - Legacy pending interactions keep the old creator and human restrictions. - Migration `0218` fills only missing provenance fields during recovery. - Cross-issue resolutions can reach the existing action limit. - The shared evaluator affects every interaction kind. - Route, service, database, shared contract, and UI tests cover these rules. > This work matches the Agent Reviews and Approvals direction in `ROADMAP.md`. It does not duplicate a planned item. ## Model Used OpenAI Codex, GPT-5. The runtime does not expose the exact deployment ID or context window. The agent used reasoning, repository tools, shell commands, and test 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 linked public issues or described the issue with the required labels - [x] I have not referenced internal Paperclip issues or links - [x] My branch name describes the change and contains no internal ticket id - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation - [x] I have considered and documented the risks - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open comments - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
308 lines
12 KiB
TypeScript
308 lines
12 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import type { AttentionItem, AttentionResolverAudience } from "@paperclipai/shared";
|
|
import type { RequestConfirmationInteraction } from "./issue-thread-interactions";
|
|
import {
|
|
DEFAULT_RESOLVER_POLICY,
|
|
RESOLVER_POLICY_CHOICES,
|
|
describeAttentionResolverAudience,
|
|
describeInteractionAudience,
|
|
resolverPolicyEffect,
|
|
resolverPolicyLabel,
|
|
} from "./interaction-audience";
|
|
|
|
function confirmation(
|
|
overrides: Partial<RequestConfirmationInteraction> = {},
|
|
): RequestConfirmationInteraction {
|
|
return {
|
|
id: "interaction-1",
|
|
companyId: "company-1",
|
|
issueId: "issue-1",
|
|
kind: "request_confirmation",
|
|
status: "pending",
|
|
continuationPolicy: "wake_assignee",
|
|
createdByAgentId: "agent-creator",
|
|
createdByUserId: null,
|
|
createdAt: "2026-08-14T12:00:00.000Z",
|
|
updatedAt: "2026-08-14T12:00:00.000Z",
|
|
payload: { version: 1, prompt: "Ship it?" },
|
|
result: null,
|
|
// Open default with inherited provenance — what an omitted `resolverPolicy`
|
|
// produces under the PAP-17277 contract.
|
|
resolverPolicy: "anyone",
|
|
requestedResolverPolicy: "anyone",
|
|
effectiveResolverPolicy: "anyone",
|
|
resolverPolicyProvenance: "inherited",
|
|
effectiveResolverPolicySource: "requested",
|
|
legacyResolverPolicyAliases: { requested: "board_or_agents", effective: "board_or_agents" },
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("resolver policy vocabulary", () => {
|
|
it("defaults to the open audience", () => {
|
|
expect(DEFAULT_RESOLVER_POLICY).toBe("anyone");
|
|
expect(RESOLVER_POLICY_CHOICES[0]).toMatchObject({ value: "anyone", isDefault: true });
|
|
expect(RESOLVER_POLICY_CHOICES.map((choice) => choice.value)).toEqual([
|
|
"anyone",
|
|
"not_creator",
|
|
"human_only",
|
|
]);
|
|
expect(RESOLVER_POLICY_CHOICES.filter((choice) => choice.isDefault)).toHaveLength(1);
|
|
});
|
|
|
|
it("labels each canonical policy in plain language", () => {
|
|
expect(resolverPolicyLabel("anyone")).toBe("Anyone");
|
|
expect(resolverPolicyLabel("not_creator")).toBe("Anyone except creator");
|
|
expect(resolverPolicyLabel("human_only")).toBe("Human only");
|
|
});
|
|
|
|
it("maps deprecated board aliases onto canonical copy", () => {
|
|
expect(resolverPolicyLabel("board_or_agents")).toBe("Anyone");
|
|
expect(resolverPolicyLabel("board_only")).toBe("Human only");
|
|
expect(resolverPolicyEffect("board_only")).toBe(resolverPolicyEffect("human_only"));
|
|
});
|
|
|
|
it("previews an effect for every choice without naming a raw policy value", () => {
|
|
for (const choice of RESOLVER_POLICY_CHOICES) {
|
|
expect(choice.effect.length).toBeGreaterThan(0);
|
|
expect(choice.effect).not.toContain(choice.value);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("describeInteractionAudience", () => {
|
|
it("reads an omitted policy as open company attention", () => {
|
|
const audience = describeInteractionAudience({ interaction: confirmation() });
|
|
expect(audience.policy).toBe("anyone");
|
|
expect(audience.isOpen).toBe(true);
|
|
expect(audience.label).toBe("Anyone");
|
|
expect(audience.narrowedBy).toBeNull();
|
|
expect(audience.narrowedNote).toBeNull();
|
|
expect(audience.summary).toBe(
|
|
"Anyone in the company can respond — the board or any agent, including the one that asked.",
|
|
);
|
|
});
|
|
|
|
it("does not present an open card as board-required", () => {
|
|
const audience = describeInteractionAudience({ interaction: confirmation() });
|
|
expect(audience.summary).not.toMatch(/only .*board/i);
|
|
expect(audience.summary).toMatch(/anyone in the company/i);
|
|
});
|
|
|
|
it("names the excluded creator for an explicit not_creator restriction", () => {
|
|
const audience = describeInteractionAudience({
|
|
interaction: confirmation({
|
|
requestedResolverPolicy: "not_creator",
|
|
effectiveResolverPolicy: "not_creator",
|
|
resolverPolicyProvenance: "explicit",
|
|
legacyResolverPolicyAliases: { requested: null, effective: null },
|
|
}),
|
|
creatorLabel: "ClaudeCoder",
|
|
});
|
|
expect(audience.isOpen).toBe(false);
|
|
expect(audience.label).toBe("Anyone except creator");
|
|
expect(audience.narrowedBy).toBe("requested");
|
|
expect(audience.summary).toBe("Anyone in the company except ClaudeCoder can respond.");
|
|
// An explicitly requested restriction needs no extra explanation.
|
|
expect(audience.narrowedNote).toBeNull();
|
|
});
|
|
|
|
it("falls back to a generic creator phrase when the creator label is unknown", () => {
|
|
const audience = describeInteractionAudience({
|
|
interaction: confirmation({
|
|
requestedResolverPolicy: "not_creator",
|
|
effectiveResolverPolicy: "not_creator",
|
|
resolverPolicyProvenance: "explicit",
|
|
}),
|
|
});
|
|
expect(audience.summary).toBe(
|
|
"Anyone in the company except the agent that created it can respond.",
|
|
);
|
|
});
|
|
|
|
it("keeps human-only ownership copy explicit", () => {
|
|
const audience = describeInteractionAudience({
|
|
interaction: confirmation({
|
|
requestedResolverPolicy: "human_only",
|
|
effectiveResolverPolicy: "human_only",
|
|
resolverPolicyProvenance: "explicit",
|
|
legacyResolverPolicyAliases: { requested: "board_only", effective: "board_only" },
|
|
}),
|
|
});
|
|
expect(audience.label).toBe("Human only");
|
|
expect(audience.isOpen).toBe(false);
|
|
expect(audience.summary).toBe(
|
|
"Only a person on the board can respond — agents cannot resolve this card.",
|
|
);
|
|
});
|
|
|
|
it("keeps addressee ownership copy when a named agent owns the card", () => {
|
|
const audience = describeInteractionAudience({
|
|
interaction: confirmation({ addresseeAgentId: "agent-release" }),
|
|
addresseeLabel: "ReleaseBot",
|
|
});
|
|
expect(audience.isOpen).toBe(false);
|
|
expect(audience.narrowedBy).toBe("addressee");
|
|
expect(audience.summary).toBe("Only ReleaseBot or a person on the board can respond.");
|
|
// The label must not claim "Anyone" next to a sentence naming one agent.
|
|
expect(audience.label).toBe("Addressed");
|
|
});
|
|
|
|
it("lets human_only win over a named addressee", () => {
|
|
const audience = describeInteractionAudience({
|
|
interaction: confirmation({
|
|
addresseeAgentId: "agent-release",
|
|
requestedResolverPolicy: "human_only",
|
|
effectiveResolverPolicy: "human_only",
|
|
}),
|
|
addresseeLabel: "ReleaseBot",
|
|
});
|
|
expect(audience.summary).toBe(
|
|
"Only a person on the board can respond — agents cannot resolve this card.",
|
|
);
|
|
expect(audience.label).toBe("Human only");
|
|
});
|
|
|
|
it("explains a governed-action clamp", () => {
|
|
const audience = describeInteractionAudience({
|
|
interaction: confirmation({
|
|
requestedResolverPolicy: "anyone",
|
|
effectiveResolverPolicy: "human_only",
|
|
effectiveResolverPolicySource: "governed_action",
|
|
}),
|
|
});
|
|
expect(audience.policy).toBe("human_only");
|
|
expect(audience.requestedPolicy).toBe("anyone");
|
|
expect(audience.narrowedBy).toBe("governed_action");
|
|
expect(audience.narrowedNote).toBe(
|
|
"This card runs a governed action, so it stays human-only whatever audience was requested.",
|
|
);
|
|
});
|
|
|
|
it("explains a company cap using both audience labels", () => {
|
|
const audience = describeInteractionAudience({
|
|
interaction: confirmation({
|
|
requestedResolverPolicy: "anyone",
|
|
effectiveResolverPolicy: "human_only",
|
|
effectiveResolverPolicySource: "company_cap",
|
|
}),
|
|
});
|
|
expect(audience.narrowedBy).toBe("company_cap");
|
|
expect(audience.narrowedNote).toBe(
|
|
"Company interaction governance narrowed this from Anyone to Human only.",
|
|
);
|
|
});
|
|
|
|
it("explains a legacy restricted card that predates the open default", () => {
|
|
const audience = describeInteractionAudience({
|
|
interaction: confirmation({
|
|
requestedResolverPolicy: "not_creator",
|
|
effectiveResolverPolicy: "not_creator",
|
|
resolverPolicyProvenance: "legacy_inherited_restriction",
|
|
}),
|
|
creatorLabel: "ClaudeCoder",
|
|
});
|
|
expect(audience.narrowedBy).toBe("legacy_restriction");
|
|
expect(audience.narrowedNote).toBe(
|
|
"Created before Anyone became the default, so it stays restricted. A new card would be open.",
|
|
);
|
|
expect(audience.summary).toBe("Anyone in the company except ClaudeCoder can respond.");
|
|
});
|
|
});
|
|
|
|
/** The `resolverAudience` metadata the attention feed ships with an interaction row. */
|
|
function attentionAudience(
|
|
overrides: Partial<AttentionResolverAudience> = {},
|
|
): AttentionResolverAudience {
|
|
return {
|
|
requestedResolverPolicy: "anyone",
|
|
effectiveResolverPolicy: "anyone",
|
|
effectiveResolverPolicySource: "requested",
|
|
resolverPolicyProvenance: "inherited",
|
|
addresseeAgentId: null,
|
|
addresseeName: null,
|
|
createdByAgentId: "agent-creator",
|
|
createdByAgentName: "Watchdog",
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function attentionItem(
|
|
audience: AttentionResolverAudience | null,
|
|
sourceKind: AttentionItem["sourceKind"] = "issue_thread_interaction",
|
|
): Pick<AttentionItem, "sourceKind" | "resolverAudience"> {
|
|
return { sourceKind, resolverAudience: audience };
|
|
}
|
|
|
|
describe("glanceable audience copy", () => {
|
|
it("states the open default in one clause", () => {
|
|
expect(describeInteractionAudience({ interaction: confirmation() }).shortSummary)
|
|
.toBe("Anyone can respond");
|
|
});
|
|
|
|
it("names the excluded creator", () => {
|
|
expect(describeInteractionAudience({
|
|
interaction: confirmation({ requestedResolverPolicy: "not_creator", effectiveResolverPolicy: "not_creator" }),
|
|
creatorLabel: "Watchdog",
|
|
}).shortSummary).toBe("Anyone except Watchdog can respond");
|
|
});
|
|
|
|
it("names the addressed responder", () => {
|
|
expect(describeInteractionAudience({
|
|
interaction: confirmation({ addresseeAgentId: "agent-codex" }),
|
|
addresseeLabel: "CodexCoder",
|
|
}).shortSummary).toBe("Only CodexCoder or the board can respond");
|
|
});
|
|
|
|
it("keeps human-only ownership with the board", () => {
|
|
expect(describeInteractionAudience({
|
|
interaction: confirmation({ requestedResolverPolicy: "human_only", effectiveResolverPolicy: "human_only" }),
|
|
}).shortSummary).toBe("Only the board can respond");
|
|
});
|
|
});
|
|
|
|
describe("describeAttentionResolverAudience", () => {
|
|
it("describes an open interaction row from server metadata alone", () => {
|
|
const audience = describeAttentionResolverAudience(attentionItem(attentionAudience()));
|
|
expect(audience?.policy).toBe("anyone");
|
|
expect(audience?.isOpen).toBe(true);
|
|
expect(audience?.label).toBe("Anyone");
|
|
expect(audience?.shortSummary).toBe("Anyone can respond");
|
|
});
|
|
|
|
it("names the addressed agent the server recorded", () => {
|
|
const audience = describeAttentionResolverAudience(attentionItem(attentionAudience({
|
|
addresseeAgentId: "agent-codex",
|
|
addresseeName: "CodexCoder",
|
|
})));
|
|
expect(audience?.label).toBe("Addressed");
|
|
expect(audience?.shortSummary).toBe("Only CodexCoder or the board can respond");
|
|
});
|
|
|
|
it("names the excluded creator the server recorded", () => {
|
|
const audience = describeAttentionResolverAudience(attentionItem(attentionAudience({
|
|
requestedResolverPolicy: "not_creator",
|
|
effectiveResolverPolicy: "not_creator",
|
|
})));
|
|
expect(audience?.shortSummary).toBe("Anyone except Watchdog can respond");
|
|
});
|
|
|
|
it("carries the narrowing explanation for a company cap", () => {
|
|
const audience = describeAttentionResolverAudience(attentionItem(attentionAudience({
|
|
effectiveResolverPolicy: "human_only",
|
|
effectiveResolverPolicySource: "company_cap",
|
|
})));
|
|
expect(audience?.narrowedBy).toBe("company_cap");
|
|
expect(audience?.narrowedNote).toBe(
|
|
"Company interaction governance narrowed this from Anyone to Human only.",
|
|
);
|
|
});
|
|
|
|
it("stays silent rather than guessing a policy client-side", () => {
|
|
// No metadata (an older feed) and non-interaction rows must render nothing.
|
|
expect(describeAttentionResolverAudience(attentionItem(null))).toBeNull();
|
|
expect(describeAttentionResolverAudience({ sourceKind: "issue_thread_interaction" })).toBeNull();
|
|
expect(describeAttentionResolverAudience(attentionItem(attentionAudience(), "approval"))).toBeNull();
|
|
});
|
|
});
|