Skip to content

The open-source app everyone uses to manage agents at work

Merge public-gh/master into paperclip-issue-documents

Dottaab41fdbaee5f
diff --cc server/src/routes/issues.ts
index 45cf3b5e7c,0213ded27a..1ee4294ad4
--- a/server/src/routes/issues.ts
+++ b/server/src/routes/issues.ts
@@@ -320,146 -316,79 +322,219 @@@ export function issueRoutes(db: Db, sto
});
});
+ router.get("/issues/:id/heartbeat-context", async (req, res) => {
+ const id = req.params.id as string;
+ const issue = await svc.getById(id);
+ if (!issue) {
+ res.status(404).json({ error: "Issue not found" });
+ return;
+ }
+ assertCompanyAccess(req, issue.companyId);
+
+ const wakeCommentId =
+ typeof req.query.wakeCommentId === "string" && req.query.wakeCommentId.trim().length > 0
+ ? req.query.wakeCommentId.trim()
+ : null;
+
+ const [ancestors, project, goal, commentCursor, wakeComment] = await Promise.all([
+ svc.getAncestors(issue.id),
+ issue.projectId ? projectsSvc.getById(issue.projectId) : null,
+ issue.goalId
+ ? goalsSvc.getById(issue.goalId)
+ : !issue.projectId
+ ? goalsSvc.getDefaultCompanyGoal(issue.companyId)
+ : null,
+ svc.getCommentCursor(issue.id),
+ wakeCommentId ? svc.getComment(wakeCommentId) : null,
+ ]);
+
+ res.json({
+ issue: {
+ id: issue.id,
+ identifier: issue.identifier,
+ title: issue.title,
+ description: issue.description,
+ status: issue.status,
+ priority: issue.priority,
+ projectId: issue.projectId,
+ goalId: goal?.id ?? issue.goalId,
+ parentId: issue.parentId,
+ assigneeAgentId: issue.assigneeAgentId,
+ assigneeUserId: issue.assigneeUserId,
+ updatedAt: issue.updatedAt,
+ },
+ ancestors: ancestors.map((ancestor) => ({
+ id: ancestor.id,
+ identifier: ancestor.identifier,
+ title: ancestor.title,
+ status: ancestor.status,
+ priority: ancestor.priority,
+ })),
+ project: project
+ ? {
+ id: project.id,
+ name: project.name,
+ status: project.status,
+ targetDate: project.targetDate,
+ }
+ : null,
+ goal: goal
+ ? {
+ id: goal.id,
+ title: goal.title,
+ status: goal.status,
+ level: goal.level,
+ parentId: goal.parentId,
+ }
+ : null,
+ commentCursor,
+ wakeComment:
+ wakeComment && wakeComment.issueId === issue.id
+ ? wakeComment
+ : null,
+ });
+ });
+
+ router.get("/issues/:id/documents", async (req, res) => {
+ const id = req.params.id as string;
+ const issue = await svc.getById(id);
+ if (!issue) {
+ res.status(404).json({ error: "Issue not found" });
+ return;
+ }
+ assertCompanyAccess(req, issue.companyId);
+ const docs = await documentsSvc.listIssueDocuments(issue.id);
+ res.json(docs);
+ });
+
+ router.get("/issues/:id/documents/:key", async (req, res) => {
+ const id = req.params.id as string;
+ const issue = await svc.getById(id);
+ if (!issue) {
+ res.status(404).json({ error: "Issue not found" });
+ return;
+ }
+ assertCompanyAccess(req, issue.companyId);
+ const keyParsed = issueDocumentKeySchema.safeParse(String(req.params.key ?? "").trim().toLowerCase());
+ if (!keyParsed.success) {
+ res.status(400).json({ error: "Invalid document key", details: keyParsed.error.issues });
+ return;
+ }
+ const doc = await documentsSvc.getIssueDocumentByKey(issue.id, keyParsed.data);
+ if (!doc) {
+ res.status(404).json({ error: "Document not found" });
+ return;
+ }
+ res.json(doc);
+ });
+
+ router.put("/issues/:id/documents/:key", validate(upsertIssueDocumentSchema), async (req, res) => {
+ const id = req.params.id as string;
+ const issue = await svc.getById(id);
+ if (!issue) {
+ res.status(404).json({ error: "Issue not found" });
+ return;
+ }
+ assertCompanyAccess(req, issue.companyId);
+ const keyParsed = issueDocumentKeySchema.safeParse(String(req.params.key ?? "").trim().toLowerCase());
+ if (!keyParsed.success) {
+ res.status(400).json({ error: "Invalid document key", details: keyParsed.error.issues });
+ return;
+ }
+
+ const actor = getActorInfo(req);
+ const before = await documentsSvc.getIssueDocumentByKey(issue.id, keyParsed.data);
+ const doc = await documentsSvc.upsertIssueDocument({
+ issueId: issue.id,
+ key: keyParsed.data,
+ title: req.body.title ?? null,
+ format: req.body.format,
+ body: req.body.body,
+ changeSummary: req.body.changeSummary ?? null,
+ baseRevisionId: req.body.baseRevisionId ?? null,
+ createdByAgentId: actor.agentId ?? null,
+ createdByUserId: actor.actorType === "user" ? actor.actorId : null,
+ });
+
+ await logActivity(db, {
+ companyId: issue.companyId,
+ actorType: actor.actorType,
+ actorId: actor.actorId,
+ agentId: actor.agentId,
+ runId: actor.runId,
+ action: before ? "issue.document_updated" : "issue.document_created",
+ entityType: "issue",
+ entityId: issue.id,
+ details: {
+ key: doc.key,
+ documentId: doc.id,
+ title: doc.title,
+ format: doc.format,
+ revisionNumber: doc.latestRevisionNumber,
+ },
+ });
+
+ res.status(before ? 200 : 201).json(doc);
+ });
+
+ router.get("/issues/:id/documents/:key/revisions", async (req, res) => {
+ const id = req.params.id as string;
+ const issue = await svc.getById(id);
+ if (!issue) {
+ res.status(404).json({ error: "Issue not found" });
+ return;
+ }
+ assertCompanyAccess(req, issue.companyId);
+ const keyParsed = issueDocumentKeySchema.safeParse(String(req.params.key ?? "").trim().toLowerCase());
+ if (!keyParsed.success) {
+ res.status(400).json({ error: "Invalid document key", details: keyParsed.error.issues });
+ return;
+ }
+ const revisions = await documentsSvc.listIssueDocumentRevisions(issue.id, keyParsed.data);
+ res.json(revisions);
+ });
+
+ router.delete("/issues/:id/documents/:key", async (req, res) => {
+ const id = req.params.id as string;
+ const issue = await svc.getById(id);
+ if (!issue) {
+ res.status(404).json({ error: "Issue not found" });
+ return;
+ }
+ assertCompanyAccess(req, issue.companyId);
+ if (req.actor.type !== "board") {
+ res.status(403).json({ error: "Board authentication required" });
+ return;
+ }
+ const keyParsed = issueDocumentKeySchema.safeParse(String(req.params.key ?? "").trim().toLowerCase());
+ if (!keyParsed.success) {
+ res.status(400).json({ error: "Invalid document key", details: keyParsed.error.issues });
+ return;
+ }
+ const removed = await documentsSvc.deleteIssueDocument(issue.id, keyParsed.data);
+ if (!removed) {
+ res.status(404).json({ error: "Document not found" });
+ return;
+ }
+ const actor = getActorInfo(req);
+ await logActivity(db, {
+ companyId: issue.companyId,
+ actorType: actor.actorType,
+ actorId: actor.actorId,
+ agentId: actor.agentId,
+ runId: actor.runId,
+ action: "issue.document_deleted",
+ entityType: "issue",
+ entityId: issue.id,
+ details: {
+ key: removed.key,
+ documentId: removed.id,
+ title: removed.title,
+ },
+ });
+ res.json({ ok: true });
+ });
+
router.post("/issues/:id/read", async (req, res) => {
const id = req.params.id as string;
const issue = await svc.getById(id);
diff --cc skills/paperclip/SKILL.md
index f992c87c52,928e3bc152..4a2a09517e
--- a/skills/paperclip/SKILL.md
+++ b/skills/paperclip/SKILL.md
@@@ -221,11 -237,9 +229,13 @@@ PATCH /api/agents/{agentId}/instruction
| My assignments | `GET /api/companies/:companyId/issues?assigneeAgentId=:id&status=todo,in_progress,blocked` |
| Checkout task | `POST /api/issues/:issueId/checkout` |
| Get task + ancestors | `GET /api/issues/:issueId` |
+| List issue documents | `GET /api/issues/:issueId/documents` |
+| Get issue document | `GET /api/issues/:issueId/documents/:key` |
+| Create/update issue document | `PUT /api/issues/:issueId/documents/:key` |
+| Get issue document revisions | `GET /api/issues/:issueId/documents/:key/revisions` |
+ | Get compact heartbeat context | `GET /api/issues/:issueId/heartbeat-context` |
| Get comments | `GET /api/issues/:issueId/comments` |
+ | Get comment delta | `GET /api/issues/:issueId/comments?after=:commentId&order=asc` |
| Get specific comment | `GET /api/issues/:issueId/comments/:commentId` |
| Update task | `PATCH /api/issues/:issueId` (optional `comment` field) |
| Add comment | `POST /api/issues/:issueId/comments` |