diff --git a/README.md b/README.md index e9760ba6..0373f7f6 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,7 @@ curl -H "Authorization: Bearer $FACTORIZE_ACCESS_TOKEN" \ https://app.factorize.sh/api/v1/github-installations ``` -Job CRUD is available at `/jobs` and `/jobs/:id`; job metadata includes `currentRuns` and `maxConcurrency`. Run collections return `{ "items": [...], "nextCursor": "..." }`; pass `nextCursor` back as the `cursor` query parameter. Runs can be filtered by `jobId`, `state`, and `contextQuery`; context queries use case-insensitive literal substring matching and matching items contain a bounded `context_excerpt`, never the full context. `GET /runs/:runId` returns the complete structured trigger `context` and invocation metadata, including the firing `trigger_id`. The canonical Job prompt contract is documented in [docs/job-trigger-context.md](docs/job-trigger-context.md). Errors consistently use `{ "error": { "code": "...", "message": "..." } }`. +Job CRUD is available at `/jobs` and `/jobs/:id`; job metadata includes `currentRuns` and `maxConcurrency`. Run collections return `{ "items": [...], "nextCursor": "..." }`; pass `nextCursor` back as the `cursor` query parameter. Runs can be filtered by `jobId`, `state`, and `contextQuery`; context queries use case-insensitive literal substring matching and matching items contain a bounded `context_excerpt`, never the full context. `GET /runs/:runId` returns the rendered `prompt`, complete structured trigger `context`, and invocation metadata, including the firing `trigger_id`. The canonical Job prompt contract is documented in [docs/job-trigger-context.md](docs/job-trigger-context.md). Errors consistently use `{ "error": { "code": "...", "message": "..." } }`. ## MCP clients @@ -184,7 +184,7 @@ Factorize also supports the OAuth 2.0 Device Authorization Grant (RFC 8628) for - Linear webhooks require a valid HMAC-SHA256 signature and fresh timestamp before workspace routing. - Session cookies are signed, expire after seven days, and are checked against workspace membership. - OAuth access is tenant-bound, scope-checked, revocable, and revalidates current owner membership at the shared service boundary. -- Public REST and MCP responses omit connection tokens, credential records, prompts, and internal execution requests/responses. +- Public REST and MCP responses omit connection tokens, credential records, and internal execution requests/responses. Authorized run inspection includes the rendered prompt sent to the agent. - Agent output is not copied into Linear; completion comments point back to the Herdr session on your VM. - The dashboard uses a restrictive content-security policy and locally built Tailwind CSS. diff --git a/packages/app/src/protected-api.ts b/packages/app/src/protected-api.ts index 1d629a8d..28751563 100644 --- a/packages/app/src/protected-api.ts +++ b/packages/app/src/protected-api.ts @@ -75,7 +75,7 @@ async function mcp(request: Request, service: ApiService, env: Env, ctx: Executi tool("list_exe_connections", "List safe metadata for saved exe.dev connections. API tokens are never returned.", z.object({}), () => service.listExeConnections()); tool("list_github_installations", "List connected GitHub App installations, including the installation IDs needed by GitHub Job triggers. Credentials are never returned.", z.object({}), () => service.listGitHubInstallations()); tool("list_runs", "List authoritative job runs by job ID, state, and an optional case-insensitive literal substring of triggered context. Automatic webhook, schedule, and lifecycle signals coalesce, so query runs and the provider API for authoritative work. Context matches include only a bounded excerpt.", listRunsSchema, (input: any) => service.listRuns(queryOf(input))); - tool("get_run", "Get a run with its full triggered context, invocation metadata, execution metadata, output, and activity. For manual invocations, invocation.idempotency_key is the client-reusable value; invocation.claim_key is internal.", runIdSchema, ({ runId }: any) => service.getRun(runId)); + tool("get_run", "Get a run with its rendered prompt, full triggered context, invocation metadata, execution metadata, output, and activity. For manual invocations, invocation.idempotency_key is the client-reusable value; invocation.claim_key is internal.", runIdSchema, ({ runId }: any) => service.getRun(runId)); tool("stop_run", "Stop an active run", runIdSchema, ({ runId }: any) => service.stopRun(runId)); tool("list_jobs", "List jobs with their current run count and maximum concurrency", z.object({}), () => service.listJobs()); tool("get_job", "Get a job with its current run count and maximum concurrency", jobIdSchema, ({ jobId }: any) => service.getJob(jobId)); diff --git a/packages/app/src/tenant.ts b/packages/app/src/tenant.ts index 1fc902ed..59facc48 100644 --- a/packages/app/src/tenant.ts +++ b/packages/app/src/tenant.ts @@ -896,7 +896,7 @@ export class TenantV2 extends DurableObject { } private async getRun(runId: string): Promise { - const run = this.one(`SELECT r.id, r.pipe_id AS job_id, r.issue_id, r.issue_url, r.agent_name, r.workspace_name, r.agent_kind, r.state, r.provider, r.execution_backend_kind AS backend_kind, r.execution_handle, r.execution_capabilities AS capabilities, r.destination_url, r.result, r.exec_status, r.exec_exit_code, r.recovery_last_action, r.created_at, r.updated_at, + const run = this.one(`SELECT r.id, r.pipe_id AS job_id, r.issue_id, r.issue_url, r.agent_name, r.workspace_name, r.agent_kind, r.state, r.provider, r.execution_backend_kind AS backend_kind, r.execution_handle, r.execution_capabilities AS capabilities, r.destination_url, r.prompt AS encrypted_prompt, r.result, r.exec_status, r.exec_exit_code, r.recovery_last_action, r.created_at, r.updated_at, i.id AS invocation_id, i.job_id AS invocation_job_id, i.source AS invocation_source, i.claim_key AS invocation_claim_key, i.trigger_id AS invocation_trigger_id, i.context, i.occurrence AS invocation_occurrence, i.created_at AS invocation_created_at FROM runs r LEFT JOIN job_runs jr ON jr.id = r.id LEFT JOIN invocations i ON i.id = jr.invocation_id WHERE r.id = ?`, runId); if (!run) return new Response("Not found", { status: 404 }); @@ -914,6 +914,8 @@ export class TenantV2 extends DurableObject { run.invocation = null; } for (const key of ["invocation_id", "invocation_job_id", "invocation_source", "invocation_trigger_id", "invocation_claim_key", "invocation_occurrence", "invocation_created_at"]) delete run[key]; + if (typeof run.encrypted_prompt === "string" && run.encrypted_prompt) run.prompt = await decrypt(run.encrypted_prompt, this.env.CREDENTIAL_ENCRYPTION_KEY); + delete run.encrypted_prompt; if (run.state !== "ignored" && typeof run.result === "string" && run.result) run.result = await decrypt(run.result, this.env.CREDENTIAL_ENCRYPTION_KEY); run.activity = this.rows("SELECT action, detail, created_at FROM run_activity WHERE run_id = ? ORDER BY created_at, id", runId); this.presentExecution(run); diff --git a/packages/app/src/ui.ts b/packages/app/src/ui.ts index 93f53cd4..d260ba06 100644 --- a/packages/app/src/ui.ts +++ b/packages/app/src/ui.ts @@ -152,7 +152,7 @@ function elapsed(r){const start=new Date(r.created_at).getTime(),end=activeState function updateElapsed(r){const label=$('[data-run-elapsed]');if(label)label.textContent=elapsed(r);clearInterval(elapsedTimer);if(activeStates.includes(r.state))elapsedTimer=setInterval(()=>{const current=$('[data-run-elapsed]');if(current)current.textContent=elapsed(r)},1000)} function scheduleRefresh(r){clearTimeout(refreshTimer);if(activeStates.includes(r.state)&&(r.capabilities||[]).includes('output'))refreshTimer=setTimeout(refreshOutput,3000)} async function refreshOutput(){try{const r=await request('/api/v1/runs/'+encodeURIComponent(id)),output=$('[data-run-output]'),state=$('[data-run-state]');if(output){const follow=output.scrollHeight-output.scrollTop-output.clientHeight<24;output.innerHTML=ansiToHtml(outputText(r));if(follow)output.scrollTop=output.scrollHeight}if(state)state.innerHTML=stateBadge(r.state);updateElapsed(r);scheduleRefresh(r)}catch{refreshTimer=setTimeout(refreshOutput,5000)}} -request('/api/v1/runs/'+encodeURIComponent(id)).then(async r=>({r,j:await request('/api/v1/jobs/'+encodeURIComponent(r.job_id))})).then(({r,j})=>{const caps=r.capabilities||[],canOutput=caps.includes('output'),canStop=caps.includes('stop')&&['starting','running','blocked'].includes(r.state),context=r.context===null?'

Context is not available for this legacy run.

':'
'+esc(JSON.stringify(r.context,null,2))+'
',runLabel='Run '+r.id.slice(0,8);root.innerHTML='

'+esc(runLabel)+'

'+elapsed(r)+'

'+stateBadge(r.state)+''+(canStop?'':'')+'
Context sent to agent'+context+'
'+(canOutput?'

Output

'+(activeStates.includes(r.state)?'Live · refreshes automatically':'')+'
'+ansiToHtml(outputText(r))+'
':'
Output is not available for this run.
');const output=$('[data-run-output]');if(output)output.scrollTop=output.scrollHeight;if(canStop)$('#stop-run').onclick=async()=>{await request('/api/v1/runs/'+encodeURIComponent(id)+'/stop',{method:'POST'});location.reload()};updateElapsed(r);scheduleRefresh(r)}).catch(e=>root.innerHTML='

'+esc(e.message)+'

');`); +request('/api/v1/runs/'+encodeURIComponent(id)).then(async r=>({r,j:await request('/api/v1/jobs/'+encodeURIComponent(r.job_id))})).then(({r,j})=>{const caps=r.capabilities||[],canOutput=caps.includes('output'),canStop=caps.includes('stop')&&['starting','running','blocked'].includes(r.state),runLabel='Run '+r.id.slice(0,8);root.innerHTML='

'+esc(runLabel)+'

'+elapsed(r)+'

'+stateBadge(r.state)+''+(canStop?'':'')+'

Prompt

'+esc(r.prompt||'Prompt is not available for this run.')+'
'+(canOutput?'

Output

'+(activeStates.includes(r.state)?'Live · refreshes automatically':'')+'
'+ansiToHtml(outputText(r))+'
':'
Output is not available for this run.
');const output=$('[data-run-output]');if(output)output.scrollTop=output.scrollHeight;if(canStop)$('#stop-run').onclick=async()=>{await request('/api/v1/runs/'+encodeURIComponent(id)+'/stop',{method:'POST'});location.reload()};updateElapsed(r);scheduleRefresh(r)}).catch(e=>root.innerHTML='

'+esc(e.message)+'

');`); const settingsLayout = (active: "integrations" | "api-keys", content: string) => `