mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-17 03:10:38 +09:00
## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies. > - Operators supervise that work through issues, comments, approvals, and the board UI. > - Some agent proposals need structured board/user decisions, not hidden markdown conventions or heavyweight governed approvals. > - Issue-thread interactions already provide a natural thread-native surface for proposed tasks and questions. > - This pull request extends that surface with request confirmations, richer interaction cards, and agent/plugin/MCP helpers. > - The benefit is that plan approvals and yes/no decisions become explicit, auditable, and resumable without losing the single-issue workflow. ## What Changed - Added persisted issue-thread interactions for suggested tasks, structured questions, and request confirmations. - Added board UI cards for interaction review, selection, question answers, and accept/reject confirmation flows. - Added MCP and plugin SDK helpers for creating interaction cards from agents/plugins. - Updated agent wake instructions, onboarding assets, Paperclip skill docs, and public docs to prefer structured confirmations for issue-scoped decisions. - Rebased the branch onto `public-gh/master` and renumbered branch migrations to `0063` and `0064`; the idempotency migration uses `ADD COLUMN IF NOT EXISTS` for old branch users. ## Verification - `git diff --check public-gh/master..HEAD` - `pnpm exec vitest run packages/adapter-utils/src/server-utils.test.ts packages/mcp-server/src/tools.test.ts packages/shared/src/issue-thread-interactions.test.ts ui/src/lib/issue-thread-interactions.test.ts ui/src/lib/issue-chat-messages.test.ts ui/src/components/IssueThreadInteractionCard.test.tsx ui/src/components/IssueChatThread.test.tsx server/src/__tests__/issue-thread-interaction-routes.test.ts server/src/__tests__/issue-thread-interactions-service.test.ts server/src/services/issue-thread-interactions.test.ts` -> 9 files / 79 tests passed - `pnpm -r typecheck` -> passed, including `packages/db` migration numbering check ## Risks - Medium: this adds a new issue-thread interaction model across db/shared/server/ui/plugin surfaces. - Migration risk is reduced by placing this branch after current master migrations (`0063`, `0064`) and making the idempotency column add idempotent for users who applied the old branch numbering. - UI interaction behavior is covered by component tests, but this PR does not include browser screenshots. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used - OpenAI Codex, GPT-5-class coding agent runtime. Exact model ID and context window are not exposed in this Paperclip run; tool use and local shell/code execution were enabled. ## 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 run tests locally and they pass - [x] I have added or updated tests where applicable - [ ] If this change affects the UI, I have included before/after screenshots - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
313 lines
8.8 KiB
TypeScript
313 lines
8.8 KiB
TypeScript
import express from "express";
|
|
import request from "supertest";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const companyId = "22222222-2222-4222-8222-222222222222";
|
|
const agentId = "11111111-1111-4111-8111-111111111111";
|
|
const routineId = "33333333-3333-4333-8333-333333333333";
|
|
const projectId = "44444444-4444-4444-8444-444444444444";
|
|
const otherAgentId = "55555555-5555-4555-8555-555555555555";
|
|
|
|
const routine = {
|
|
id: routineId,
|
|
companyId,
|
|
projectId,
|
|
goalId: null,
|
|
parentIssueId: null,
|
|
title: "Daily routine",
|
|
description: null,
|
|
assigneeAgentId: agentId,
|
|
priority: "medium",
|
|
status: "active",
|
|
concurrencyPolicy: "coalesce_if_active",
|
|
catchUpPolicy: "skip_missed",
|
|
createdByAgentId: null,
|
|
createdByUserId: null,
|
|
updatedByAgentId: null,
|
|
updatedByUserId: null,
|
|
lastTriggeredAt: null,
|
|
lastEnqueuedAt: null,
|
|
createdAt: new Date("2026-03-20T00:00:00.000Z"),
|
|
updatedAt: new Date("2026-03-20T00:00:00.000Z"),
|
|
};
|
|
const pausedRoutine = {
|
|
...routine,
|
|
status: "paused",
|
|
};
|
|
const trigger = {
|
|
id: "66666666-6666-4666-8666-666666666666",
|
|
companyId,
|
|
routineId,
|
|
kind: "schedule",
|
|
label: "weekday",
|
|
enabled: false,
|
|
cronExpression: "0 10 * * 1-5",
|
|
timezone: "UTC",
|
|
nextRunAt: null,
|
|
lastFiredAt: null,
|
|
publicId: null,
|
|
secretId: null,
|
|
signingMode: null,
|
|
replayWindowSec: null,
|
|
lastRotatedAt: null,
|
|
lastResult: null,
|
|
createdByAgentId: null,
|
|
createdByUserId: null,
|
|
updatedByAgentId: null,
|
|
updatedByUserId: null,
|
|
createdAt: new Date("2026-03-20T00:00:00.000Z"),
|
|
updatedAt: new Date("2026-03-20T00:00:00.000Z"),
|
|
};
|
|
|
|
const mockRoutineService = vi.hoisted(() => ({
|
|
list: vi.fn(),
|
|
get: vi.fn(),
|
|
getDetail: vi.fn(),
|
|
update: vi.fn(),
|
|
create: vi.fn(),
|
|
listRuns: vi.fn(),
|
|
createTrigger: vi.fn(),
|
|
getTrigger: vi.fn(),
|
|
updateTrigger: vi.fn(),
|
|
deleteTrigger: vi.fn(),
|
|
rotateTriggerSecret: vi.fn(),
|
|
runRoutine: vi.fn(),
|
|
firePublicTrigger: vi.fn(),
|
|
}));
|
|
|
|
const mockAccessService = vi.hoisted(() => ({
|
|
canUser: vi.fn(),
|
|
}));
|
|
|
|
const mockLogActivity = vi.hoisted(() => vi.fn());
|
|
const mockTrackRoutineCreated = vi.hoisted(() => vi.fn());
|
|
const mockGetTelemetryClient = vi.hoisted(() => vi.fn());
|
|
|
|
function registerModuleMocks() {
|
|
vi.doMock("../routes/authz.js", async () => vi.importActual("../routes/authz.js"));
|
|
|
|
vi.doMock("@paperclipai/shared/telemetry", () => ({
|
|
trackRoutineCreated: mockTrackRoutineCreated,
|
|
trackErrorHandlerCrash: vi.fn(),
|
|
}));
|
|
|
|
vi.doMock("../telemetry.js", () => ({
|
|
getTelemetryClient: mockGetTelemetryClient,
|
|
}));
|
|
|
|
vi.doMock("../services/access.js", () => ({
|
|
accessService: () => mockAccessService,
|
|
}));
|
|
|
|
vi.doMock("../services/routines.js", () => ({
|
|
routineService: () => mockRoutineService,
|
|
}));
|
|
|
|
vi.doMock("../services/activity-log.js", () => ({
|
|
logActivity: mockLogActivity,
|
|
}));
|
|
|
|
vi.doMock("../services/index.js", () => ({
|
|
accessService: () => mockAccessService,
|
|
logActivity: mockLogActivity,
|
|
routineService: () => mockRoutineService,
|
|
}));
|
|
}
|
|
|
|
async function createApp(actor: Record<string, unknown>) {
|
|
const [{ errorHandler }, { routineRoutes }] = await Promise.all([
|
|
vi.importActual<typeof import("../middleware/index.js")>("../middleware/index.js"),
|
|
vi.importActual<typeof import("../routes/routines.js")>("../routes/routines.js"),
|
|
]);
|
|
const app = express();
|
|
app.use(express.json());
|
|
app.use((req, _res, next) => {
|
|
(req as any).actor = actor;
|
|
next();
|
|
});
|
|
app.use("/api", routineRoutes({} as any));
|
|
app.use(errorHandler);
|
|
return app;
|
|
}
|
|
|
|
describe("routine routes", () => {
|
|
beforeEach(() => {
|
|
vi.resetModules();
|
|
vi.doUnmock("@paperclipai/shared/telemetry");
|
|
vi.doUnmock("../telemetry.js");
|
|
vi.doUnmock("../services/access.js");
|
|
vi.doUnmock("../services/index.js");
|
|
vi.doUnmock("../services/activity-log.js");
|
|
vi.doUnmock("../services/routines.js");
|
|
vi.doUnmock("../routes/routines.js");
|
|
vi.doUnmock("../routes/authz.js");
|
|
vi.doUnmock("../middleware/index.js");
|
|
registerModuleMocks();
|
|
vi.resetAllMocks();
|
|
mockGetTelemetryClient.mockReturnValue({ track: vi.fn() });
|
|
mockRoutineService.create.mockResolvedValue(routine);
|
|
mockRoutineService.get.mockResolvedValue(routine);
|
|
mockRoutineService.getTrigger.mockResolvedValue(trigger);
|
|
mockRoutineService.update.mockResolvedValue({ ...routine, assigneeAgentId: otherAgentId });
|
|
mockRoutineService.runRoutine.mockResolvedValue({
|
|
id: "run-1",
|
|
source: "manual",
|
|
status: "issue_created",
|
|
});
|
|
mockAccessService.canUser.mockResolvedValue(false);
|
|
mockLogActivity.mockResolvedValue(undefined);
|
|
});
|
|
|
|
it("requires tasks:assign permission for non-admin board routine creation", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "board-user",
|
|
source: "session",
|
|
isInstanceAdmin: false,
|
|
companyIds: [companyId],
|
|
});
|
|
|
|
const res = await request(app)
|
|
.post(`/api/companies/${companyId}/routines`)
|
|
.send({
|
|
projectId,
|
|
title: "Daily routine",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
|
|
expect(res.status).toBe(403);
|
|
expect(res.body.error).toContain("tasks:assign");
|
|
expect(mockRoutineService.create).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("requires tasks:assign permission to retarget a routine assignee", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "board-user",
|
|
source: "session",
|
|
isInstanceAdmin: false,
|
|
companyIds: [companyId],
|
|
});
|
|
|
|
const res = await request(app)
|
|
.patch(`/api/routines/${routineId}`)
|
|
.send({
|
|
assigneeAgentId: otherAgentId,
|
|
});
|
|
|
|
expect(res.status).toBe(403);
|
|
expect(res.body.error).toContain("tasks:assign");
|
|
expect(mockRoutineService.update).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("requires tasks:assign permission to reactivate a routine", async () => {
|
|
mockRoutineService.get.mockResolvedValue(pausedRoutine);
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "board-user",
|
|
source: "session",
|
|
isInstanceAdmin: false,
|
|
companyIds: [companyId],
|
|
});
|
|
|
|
const res = await request(app)
|
|
.patch(`/api/routines/${routineId}`)
|
|
.send({
|
|
status: "active",
|
|
});
|
|
|
|
expect(res.status).toBe(403);
|
|
expect(res.body.error).toContain("tasks:assign");
|
|
expect(mockRoutineService.update).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("requires tasks:assign permission to create a trigger", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "board-user",
|
|
source: "session",
|
|
isInstanceAdmin: false,
|
|
companyIds: [companyId],
|
|
});
|
|
|
|
const res = await request(app)
|
|
.post(`/api/routines/${routineId}/triggers`)
|
|
.send({
|
|
kind: "schedule",
|
|
cronExpression: "0 10 * * *",
|
|
timezone: "UTC",
|
|
});
|
|
|
|
expect(res.status).toBe(403);
|
|
expect(res.body.error).toContain("tasks:assign");
|
|
expect(mockRoutineService.createTrigger).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("requires tasks:assign permission to update a trigger", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "board-user",
|
|
source: "session",
|
|
isInstanceAdmin: false,
|
|
companyIds: [companyId],
|
|
});
|
|
|
|
const res = await request(app)
|
|
.patch(`/api/routine-triggers/${trigger.id}`)
|
|
.send({
|
|
enabled: true,
|
|
});
|
|
|
|
expect(res.status).toBe(403);
|
|
expect(res.body.error).toContain("tasks:assign");
|
|
expect(mockRoutineService.updateTrigger).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("requires tasks:assign permission to manually run a routine", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "board-user",
|
|
source: "session",
|
|
isInstanceAdmin: false,
|
|
companyIds: [companyId],
|
|
});
|
|
|
|
const res = await request(app)
|
|
.post(`/api/routines/${routineId}/run`)
|
|
.send({});
|
|
|
|
expect(res.status).toBe(403);
|
|
expect(res.body.error).toContain("tasks:assign");
|
|
expect(mockRoutineService.runRoutine).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("allows routine creation when the board user has tasks:assign", async () => {
|
|
mockAccessService.canUser.mockResolvedValue(true);
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "board-user",
|
|
source: "session",
|
|
isInstanceAdmin: false,
|
|
companyIds: [companyId],
|
|
});
|
|
|
|
const res = await request(app)
|
|
.post(`/api/companies/${companyId}/routines`)
|
|
.send({
|
|
projectId,
|
|
title: "Daily routine",
|
|
assigneeAgentId: agentId,
|
|
});
|
|
|
|
expect(res.status).toBe(201);
|
|
expect(mockRoutineService.create).toHaveBeenCalledWith(companyId, expect.objectContaining({
|
|
projectId,
|
|
title: "Daily routine",
|
|
assigneeAgentId: agentId,
|
|
}), {
|
|
agentId: null,
|
|
userId: "board-user",
|
|
});
|
|
expect(mockTrackRoutineCreated).toHaveBeenCalledWith(expect.anything());
|
|
});
|
|
});
|