mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 23:56:43 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Agents need to inspect configuration and instructions when they set up teammates. > - Configuration reads currently depend on configure or suggestion grants. > - Legacy standard agents did not receive those newer grants. Some self-read routes also lose the target agent identity. > - This pull request adds an independent read grant and applies only that grant to eligible existing agents. > - The benefit is that agents can inspect and verify configuration without new write authority. ## Linked Issues or Issue Description Refs #15283. Related earlier proposals: #8064 and #12050. Those proposals target older authorization code; this change uses the current configure/suggest model and adds a read-only rollout for existing agents. Related bounded peer metadata proposal: #14160. **What existing behavior does this improve?** Agent configuration, configured skill, instruction, and revision reads through the existing APIs and native instruction tools. **Current behavior** An agent needs `agents:configure` or `agents:suggest-changes` to inspect a peer. Older standard agents can hire a teammate but cannot verify the saved instructions. Configuration and revision routes also reject self-reads because they authorize a company resource instead of the target agent. **Proposed behavior** Add `agents:read` for redacted configuration and instruction reads. Keep `agents:configure` as read/write and preserve suggestion-grant compatibility. Standard new agents receive the read grant. A one-time migration grants only reads to eligible existing standard agents. Individual routes authorize the target agent and grant scope. **Reason and benefit** Read access can be granted without configuration changes, rollback, or environment probes. Legacy agents can verify teammates without receiving new write permissions. ## What Changed - Add `agents:read` to the shared permission contract and standard-agent defaults. - Accept read, configure, or suggestion grants for configuration reads, with target scope and the responsible-user ceiling. - Fix target-aware self and scoped configuration, skill, and revision reads. - Add an audited data migration. Skip low-trust, built-in, inactive, pending, terminated, setup, and scoped configuration/suggestion cases. Preserve existing read scopes and later revocation. - Update the specifications, default-permission documentation, and agent access map. ## Verification - Focused acceptance: 276 tests passed across seven suites on commit `a37314df88`: authorization, real-key HTTP access, route authorization, canonical instructions, default grants, migration replay, and lifecycle configuration. - The HTTP journey uses a real hashed agent API key and a disposable PostgreSQL database. It verifies redaction, scoped reads, denied edits and rollback, cross-company isolation, and both agent and responsible-user revocation. - New read-grant regressions failed before the authorization change. A realistic paused/pausing/resuming migration fixture also failed before the lifecycle filter correction and passed afterward. Setup-held paused agents stay excluded. - `pnpm -r typecheck` and `pnpm build` passed on the rebased branch; the final lifecycle migration correction also passed the database package typecheck and build. The latest commit changes only a test assertion. - `pnpm --filter @paperclipai/db check:migrations`, `node scripts/check-maps.mjs`, and `git diff --check` passed. - Full current-head [CI run](https://github.com/paperclipai/paperclip/actions/runs/41641531426) passed: typecheck, build, all general and serialized test lanes, Runner checks, all eight browser shards, canary dry run, policy, and aggregate gates. The local full-suite attempt was stopped after exposing the outdated cross-company 403 assertion; interrupted local full-suite attempts are not counted as passes. ## Risks The migration deliberately expands redacted configuration and instruction visibility for eligible existing standard agents in the same company. An absent older write grant does not deny the new read capability. It adds no write grant. Scoped configure/suggestion grants and all existing read-grant scopes stay intact. Administrators can remove the independent read grant after the one-time rollout; ordinary updates and startup do not restore it. Configure and suggestion grants still imply reads within their own scopes. Cross-company configuration/history reads now return 404 through the common target-aware helper. No schema change or credential-value disclosure is added. ## Model Used OpenAI GPT-6 through Codex, with reasoning, repository tools, and code execution. The host does not expose a more specific runtime 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 - [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>
95 lines
6.6 KiB
TypeScript
95 lines
6.6 KiB
TypeScript
import { createHash, randomUUID } from "node:crypto";
|
|
import { readFile } from "node:fs/promises";
|
|
import postgres from "postgres";
|
|
import { describe, expect, it } from "vitest";
|
|
import { applyPendingMigrations } from "./client.js";
|
|
import { getEmbeddedPostgresTestSupport, startEmbeddedPostgresTestDatabase } from "./test-embedded-postgres.js";
|
|
|
|
const support = await getEmbeddedPostgresTestSupport();
|
|
const migrationFile = "0423_agent_config_read_defaults.sql";
|
|
|
|
(support.supported ? describe : describe.skip)("agent configuration read default migration", () => {
|
|
it("adds only read access to existing standard agents and preserves restrictions and later revocation", async () => {
|
|
const database = await startEmbeddedPostgresTestDatabase("agent-config-read-defaults-");
|
|
const sql = postgres(database.connectionString, { max: 1, onnotice: () => {} });
|
|
try {
|
|
const [company] = await sql`INSERT INTO companies (name, issue_prefix) VALUES ('Read defaults', 'RD1') RETURNING id`;
|
|
const [otherCompany] = await sql`INSERT INTO companies (name, issue_prefix) VALUES ('Other company', 'RD2') RETURNING id`;
|
|
const candidates = [
|
|
{ name: "Legacy" },
|
|
{ name: "Paused", status: "paused", lifecycleState: "paused", lifecycleHolds: ["manual"], pauseReason: "manual" },
|
|
{ name: "Pausing", status: "paused", lifecycleState: "pausing", lifecycleHolds: ["manual"], pauseReason: "manual" },
|
|
{ name: "Resuming", status: "paused", lifecycleState: "resuming" },
|
|
{ name: "Configured" },
|
|
{ name: "Scoped configure" },
|
|
{ name: "Scoped suggest" },
|
|
{ name: "Scoped read" },
|
|
{ name: "Low trust", permissions: { trustPreset: "low_trust_review" } },
|
|
{ name: "Nested low trust", permissions: { authorizationPolicy: { trustPreset: "low_trust_review" } } },
|
|
{ name: "Review preset", permissions: { reviewPreset: { id: "low_trust_review" } } },
|
|
{ name: "Nested review preset", permissions: { authorizationPolicy: { reviewPreset: { id: "low_trust_review" } } } },
|
|
{ name: "Boundary", permissions: { authorizationPolicy: { trustBoundary: { mode: "low_trust_review" } } } },
|
|
{ name: "Unknown preset", permissions: { trustPreset: "unknown" } },
|
|
{ name: "Built in", metadata: { paperclipBuiltInAgent: { key: "summarizer", featureKeys: [] } } },
|
|
{ name: "Pending", status: "pending_approval" },
|
|
{ name: "Terminated", status: "terminated" },
|
|
{ name: "Setup", status: "paused", lifecycleState: "paused", lifecycleHolds: ["setup"], pauseReason: "setup" },
|
|
{ name: "Legacy setup", status: "paused", lifecycleState: "paused", pauseReason: "setup" },
|
|
{ name: "Inactive membership", membershipStatus: "inactive" },
|
|
{ name: "No membership", membershipStatus: "absent" },
|
|
{ name: "Wrong company membership", membershipStatus: "other_company" },
|
|
];
|
|
const ids = new Map<string, string>();
|
|
for (const candidate of candidates) {
|
|
const id = randomUUID();
|
|
ids.set(candidate.name, id);
|
|
await sql`INSERT INTO agents (id, company_id, name, status, lifecycle_state, lifecycle_holds, pause_reason, permissions, metadata)
|
|
VALUES (${id}, ${company!.id}, ${candidate.name}, ${candidate.status ?? "idle"},
|
|
${candidate.lifecycleState ?? "ready"}, ${sql.json(candidate.lifecycleHolds ?? [])}, ${candidate.pauseReason ?? null},
|
|
${sql.json(candidate.permissions ?? {})}, ${sql.json(candidate.metadata ?? {})})`;
|
|
if (candidate.membershipStatus === "absent") continue;
|
|
await sql`INSERT INTO company_memberships (company_id, principal_type, principal_id, status, membership_role)
|
|
VALUES (${candidate.membershipStatus === "other_company" ? otherCompany!.id : company!.id}, 'agent', ${id},
|
|
${candidate.membershipStatus === "inactive" ? "inactive" : "active"}, 'member')`;
|
|
}
|
|
const scope = { agentIds: [ids.get("Legacy")!] };
|
|
for (const [name, permissionKey, grantScope] of [
|
|
["Configured", "agents:configure", null],
|
|
["Scoped configure", "agents:configure", scope],
|
|
["Scoped suggest", "agents:suggest-changes", scope],
|
|
["Scoped read", "agents:read", scope],
|
|
] as const) {
|
|
await sql`INSERT INTO principal_permission_grants (company_id, principal_type, principal_id, permission_key, scope)
|
|
VALUES (${company!.id}, 'agent', ${ids.get(name)!}, ${permissionKey}, ${grantScope ? sql.json(grantScope) : null})`;
|
|
}
|
|
const before = await sql`SELECT principal_id, permission_key, scope FROM principal_permission_grants ORDER BY principal_id, permission_key`;
|
|
const content = await readFile(new URL(`./migrations/${migrationFile}`, import.meta.url), "utf8");
|
|
const hash = createHash("sha256").update(content).digest("hex");
|
|
await sql`DELETE FROM drizzle.__drizzle_migrations WHERE hash = ${hash}`;
|
|
await applyPendingMigrations(database.connectionString);
|
|
|
|
const after = await sql`SELECT principal_id, permission_key, scope FROM principal_permission_grants ORDER BY principal_id, permission_key`;
|
|
const added = after.filter(row => !before.some(previous => previous.principal_id === row.principal_id && previous.permission_key === row.permission_key));
|
|
expect(added).toEqual(expect.arrayContaining(["Legacy", "Paused", "Pausing", "Resuming", "Configured"].map(name => ({
|
|
principal_id: ids.get(name), permission_key: "agents:read", scope: null,
|
|
}))));
|
|
expect(added).toHaveLength(5);
|
|
expect(after.filter(row => row.permission_key !== "agents:read")).toEqual(before.filter(row => row.permission_key !== "agents:read"));
|
|
expect(after.find(row => row.principal_id === ids.get("Scoped read"))).toMatchObject({ scope });
|
|
const audit = await sql`SELECT entity_id, details FROM activity_log WHERE actor_id = 'migration:agent-config-read-defaults'`;
|
|
expect(audit).toHaveLength(5);
|
|
expect(audit.every(row => row.details.added.length === 1 && row.details.added[0] === "agents:read")).toBe(true);
|
|
await sql.unsafe(content);
|
|
expect(await sql`SELECT id FROM activity_log WHERE actor_id = 'migration:agent-config-read-defaults'`).toHaveLength(5);
|
|
|
|
await sql`DELETE FROM principal_permission_grants WHERE principal_id = ${ids.get("Legacy")!} AND permission_key = 'agents:read'`;
|
|
await applyPendingMigrations(database.connectionString);
|
|
expect(await sql`SELECT id FROM principal_permission_grants WHERE principal_id = ${ids.get("Legacy")!}`).toHaveLength(0);
|
|
expect(await sql`SELECT id FROM drizzle.__drizzle_migrations WHERE hash = ${hash}`).toHaveLength(1);
|
|
} finally {
|
|
await sql.end();
|
|
await database.cleanup();
|
|
}
|
|
}, 120_000);
|
|
});
|