Repository navigation
Description
Context
With the store (issues 2-3) and the trigger primitive (issue 4) in place, the API exposes Agents to the web UI and to external automation. The HTTP trigger endpoint is the v1 integration point for event-driven behavior: a GitHub Action, a webhook relay or the user's own cron calls POST /api/agent-definitions/:id/runs with an Idempotency-Key header.
Route prefix choice: /api/agents/* already belongs to coding-agent operations (agentRoutes.ts: health, chat, OpenCode models). To avoid colliding with or confusing that namespace, Agents use /api/agent-definitions and /api/agent-runs.
Requirements
New packages/api/routes/agentDefinitionRoutes.ts (createAgentDefinitionRoutes({ db, services? })) registered in packages/api/server.ts operational routes:
| Method | Path | Purpose |
|---|---|---|
| GET | /api/agent-definitions |
List the caller's definitions (offset, limit) |
| GET | /api/agent-definitions/contract |
AGENT_DEFINITION_CONTRACT for the UI form |
| POST | /api/agent-definitions |
Create |
| GET | /api/agent-definitions/:id |
Read |
| PATCH | /api/agent-definitions/:id |
Update (expectedRevision in body → 409 on conflict) |
| DELETE | /api/agent-definitions/:id |
Delete (refuses with 409 while a run is running/acting) |
| POST | /api/agent-definitions/:id/attachments |
Upload an input file (reuse goalAttachmentUpload multer + AttachmentService.processUpload) |
| DELETE | /api/agent-definitions/:id/attachments/:attachmentId |
Remove an input file |
| POST | /api/agent-definitions/:id/runs |
Trigger primitive. Body { trigger?: 'manual' | 'api' | 'cli', source?: string }; header Idempotency-Key |
| GET | /api/agent-definitions/:id/runs |
Run history (no report bodies) |
| GET | /api/agent-runs/:runId |
Run detail with report |
| POST | /api/agent-runs/:runId/cancel |
Cancel; stops the underlying task via stopTaskExecution when running |
Rules:
- Every route requires an authenticated user and is owner-scoped (404 for another user's resources — never 403, so existence is not leaked; same convention as goals).
- Demo mode rejects mutations (the global
demoModeReadOnlyMiddlewarealready covers non-GET routes; verify). - Repository grant: create, update (when repositories change) and trigger call
verifyGitHubRepositoryAccess(repo, token)for every repository usingresolveGitHubMetadataToken(req), exactly likeverifyPlannerRepositoryAccess. A user cannot create an agent over a repository they cannot read. - Body validation via
validateAgentDefinitionInput(issue 1) thenvalidateAgentDefinitionRuntime(issue 4). triggerdefaults tomanualwhen the request carries a browser session andapiotherwise (bearer / instance token); callers may passcli.mcpandscheduleare not accepted over REST.- Errors map
status/codefrom core errors to JSON{ error, code }. - Attachments stored under
storage/agent-definitions/<definitionId>/with the same allowed MIME types and 10 MB limit as goal attachments; metadata kept inagent_definitions.attachments. - Route tests
packages/api/test/agentDefinitionRoutes.test.ts.
Implementation Specification
- Keep handlers thin; core does the work. Inject
verifyAccess,resolveToken,trigger,stopTaskservices for tests. - The trigger endpoint returns
202with{ run, created }; a replayed key returns200with the original run. - The cost gate is attached in issue 11 by passing
gateintotriggerAgentRun; leave agateservice hook defaulting toundefined.
Acceptance Criteria
- CRUD round-trip works for the owner; another user gets 404 on every route.
- Creating an agent over a repository the user cannot access returns 404
REPOSITORY_NOT_ACCESSIBLE(viahandleGitHubRepositoryAccessError). -
POST .../runswith the sameIdempotency-Keytwice returns the same run id, status 202 then 200. - Deleting a definition with a running run returns 409.
- Cancel on a queued run moves it to
cancelled; on a running run it also callsstopTaskExecution(reportTaskId). - Routes registered without duplicates (
assertNoDuplicateRoutespasses).
Created by ProPR AI Planner
Activity
propr-dev commentedon Oct 6, 2026
Suggested Implementation:
Implementation Approach
A thin Express route factory over the core store and trigger primitive, following
taskSubmissionRoutes.tsandgoalRoutes.tsconventions: authenticated, owner-scoped, injected services for tests. Repository grant enforcement happens at the API boundary because only the API has the caller's GitHub credential; core re-checks instance-level enablement at every trigger. We reusegoalAttachmentUpload(multer config, MIME/extension validation) andAttachmentService.processUploadrather than writing a third upload pipeline.Alternatives: putting the trigger under
/api/agents/:id/run— rejected because/api/agentsis the coding-agent namespace and a definition id could collide with existing sub-paths like/api/agents/chat.File:
packages/api/routes/agentDefinitionRoutes.ts(new file)Why this file: The HTTP surface for the UI and for external automation. It translates requests into core calls and enforces the user's repository grant.
File:
packages/api/routes/index.tsFile:
packages/api/server.tsWhy this file: Registers the routes in the operational route table so
assertNoDuplicateRoutesand route timing apply.Register
/api/agent-definitions/contractbefore/api/agent-definitions/:id(Express matches in order).File:
packages/api/test/agentDefinitionRoutes.test.ts(new file)Why this file: Proves owner scoping, grant enforcement and idempotent triggering at the HTTP boundary with fake services.
propr-dev commentedon Oct 6, 2026
🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.
I'll analyze the problem and work on a solution. This may take a few minutes.
Processing Details:
claudeclaude-opus-5-52804/claude-opus-5-5-agents-v1-5-17-rest-api-f-20261006-1459-lfp2800-epic-agents-v1-y7tissue-2804-20261006-1459-claude-opus-5-5-lfp🔍 Track Task Execution