@alvarolorentedev/opencode-taskfeed 0.0.0-stage → 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +431 -2
- package/docs/architecture.md +123 -0
- package/docs/configuration.md +123 -0
- package/docs/development.md +312 -0
- package/docs/integrations.md +84 -0
- package/docs/operations.md +136 -0
- package/docs/releases/v0.1.0-alpha.1.md +164 -0
- package/docs/security.md +120 -0
- package/examples/README.md +7 -0
- package/examples/approvals/README.md +27 -0
- package/examples/flowgraph/config.yaml +28 -0
- package/examples/flowgraph/opencode.jsonc +14 -0
- package/examples/headless/README.md +25 -0
- package/examples/headless/config.yaml +21 -0
- package/examples/native-agent/config.yaml +31 -0
- package/examples/native-agent/opencode.jsonc +10 -0
- package/examples/playground/README.md +61 -0
- package/examples/playground/config.yaml +40 -0
- package/examples/playground/opencode.jsonc +5 -0
- package/package.json +89 -4
- package/src/config/load.ts +122 -0
- package/src/config/repository.ts +72 -0
- package/src/config/schema.ts +215 -0
- package/src/core/approval.ts +190 -0
- package/src/core/comments.ts +175 -0
- package/src/core/index.ts +5 -0
- package/src/core/ports.ts +185 -0
- package/src/core/state.ts +186 -0
- package/src/core/types.ts +430 -0
- package/src/executors/flowgraph/client.ts +27 -0
- package/src/executors/flowgraph/executor.ts +593 -0
- package/src/executors/flowgraph/lazy.ts +77 -0
- package/src/executors/flowgraph/rpc.ts +145 -0
- package/src/executors/flowgraph/worker.ts +538 -0
- package/src/executors/native/bridge.ts +421 -0
- package/src/executors/native/executor.ts +295 -0
- package/src/executors/native/prompt.ts +57 -0
- package/src/executors/native/trust.ts +105 -0
- package/src/index.ts +116 -0
- package/src/rpc.ts +75 -0
- package/src/runtime/backends.ts +27 -0
- package/src/runtime/engine.ts +2345 -0
- package/src/runtime/server-backends.ts +136 -0
- package/src/runtime/service.ts +276 -0
- package/src/sources/github/client.ts +98 -0
- package/src/sources/github/source.ts +490 -0
- package/src/storage/capacity.ts +223 -0
- package/src/storage/jobs.ts +249 -0
- package/src/storage/locks.ts +342 -0
- package/src/tui.tsx +399 -0
- package/src/util/ids.ts +18 -0
- package/src/util/logger.ts +52 -0
- package/src/util/process.ts +119 -0
- package/src/util/redact.ts +28 -0
- package/src/version.ts +2 -0
- package/src/workspaces/native.ts +162 -0
- package/src/workspaces/publication.ts +477 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import type { DecisionComment, Gate, Job, PullRequestInfo } from "./types.js"
|
|
2
|
+
|
|
3
|
+
export type DecisionErrorCode =
|
|
4
|
+
| "malformed"
|
|
5
|
+
| "unauthorized"
|
|
6
|
+
| "stale"
|
|
7
|
+
| "edited"
|
|
8
|
+
| "artifact_changed"
|
|
9
|
+
| "duplicate"
|
|
10
|
+
| "invalid_state"
|
|
11
|
+
| "forbidden"
|
|
12
|
+
| "missing_remote_artifact"
|
|
13
|
+
|
|
14
|
+
/** GitHub REST timestamps have second precision; any difference is treated as an edit. */
|
|
15
|
+
const EDIT_TOLERANCE_MS = 0
|
|
16
|
+
|
|
17
|
+
export class DecisionError extends Error {
|
|
18
|
+
constructor(
|
|
19
|
+
readonly code: DecisionErrorCode,
|
|
20
|
+
message: string,
|
|
21
|
+
) {
|
|
22
|
+
super(message)
|
|
23
|
+
this.name = "DecisionError"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type ParsedCommand =
|
|
28
|
+
| { kind: "approve"; gateID: string; revision: number; feedback: string }
|
|
29
|
+
| { kind: "request_changes"; gateID: string; revision: number; feedback: string }
|
|
30
|
+
| { kind: "outcome"; gateID: string; revision: number; outcome: string; feedback: string }
|
|
31
|
+
|
|
32
|
+
const COMMAND = /^\/taskfeed\s+(approve|request-changes|outcome)\s+(\S+)\s+(\d+)(?:\s+(\S+))?\s*$/iu
|
|
33
|
+
const OUTCOME = /^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$/u
|
|
34
|
+
|
|
35
|
+
export interface DecisionContext {
|
|
36
|
+
readonly job: Job
|
|
37
|
+
readonly gate: Gate
|
|
38
|
+
readonly comment: DecisionComment
|
|
39
|
+
readonly authorizedUsers: readonly string[]
|
|
40
|
+
readonly currentHeadSHA: string | undefined
|
|
41
|
+
readonly currentPullRequest: PullRequestInfo | undefined
|
|
42
|
+
readonly currentContentHash?: string
|
|
43
|
+
readonly processedCommentIDs?: readonly number[]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function parseApprovalComment(
|
|
47
|
+
input: Pick<DecisionComment, "body" | "author" | "createdAt">,
|
|
48
|
+
): ParsedCommand | undefined {
|
|
49
|
+
const normalized = input.body.replace(/\r\n/gu, "\n").trim()
|
|
50
|
+
if (normalized.length === 0 || normalized.length > 16_384) return undefined
|
|
51
|
+
const lines = normalized.split("\n")
|
|
52
|
+
const first = lines[0]?.trim() ?? ""
|
|
53
|
+
const match = COMMAND.exec(first)
|
|
54
|
+
if (!match) return undefined
|
|
55
|
+
const verb = match[1]!.toLowerCase()
|
|
56
|
+
const gateID = match[2]!
|
|
57
|
+
const revision = Number(match[3])
|
|
58
|
+
if (!Number.isSafeInteger(revision) || revision < 0) return undefined
|
|
59
|
+
const feedback = lines.slice(1).join("\n").trim().slice(0, 8_000)
|
|
60
|
+
if (verb === "approve") return { kind: "approve", gateID, revision, feedback }
|
|
61
|
+
if (verb === "request-changes") {
|
|
62
|
+
if (!feedback) return undefined
|
|
63
|
+
return { kind: "request_changes", gateID, revision, feedback }
|
|
64
|
+
}
|
|
65
|
+
const outcome = match[4]
|
|
66
|
+
if (!outcome || !OUTCOME.test(outcome)) return undefined
|
|
67
|
+
return { kind: "outcome", gateID, revision, outcome, feedback }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function decisionFromCommand(
|
|
71
|
+
command: ParsedCommand,
|
|
72
|
+
gate: Gate,
|
|
73
|
+
): { kind: "approved" | "changes_requested" | "outcome"; outcome?: string; feedback: string } | undefined {
|
|
74
|
+
if (command.kind === "approve") {
|
|
75
|
+
if (gate.kind === "native_review") return { kind: "approved", feedback: command.feedback }
|
|
76
|
+
if (gate.outcomes?.includes("approved")) return { kind: "approved", outcome: "approved", feedback: command.feedback }
|
|
77
|
+
return undefined
|
|
78
|
+
}
|
|
79
|
+
if (command.kind === "request_changes") {
|
|
80
|
+
if (gate.kind === "native_review") return { kind: "changes_requested", feedback: command.feedback }
|
|
81
|
+
if (gate.outcomes?.includes("changes_requested")) {
|
|
82
|
+
return { kind: "changes_requested", outcome: "changes_requested", feedback: command.feedback }
|
|
83
|
+
}
|
|
84
|
+
return undefined
|
|
85
|
+
}
|
|
86
|
+
if (!gate.outcomes?.includes(command.outcome)) return undefined
|
|
87
|
+
return { kind: "outcome", outcome: command.outcome, feedback: command.feedback }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function validateDecision(context: DecisionContext): {
|
|
91
|
+
command: ParsedCommand
|
|
92
|
+
decision: {
|
|
93
|
+
kind: "approved" | "changes_requested" | "outcome"
|
|
94
|
+
outcome?: string
|
|
95
|
+
feedback: string
|
|
96
|
+
}
|
|
97
|
+
} {
|
|
98
|
+
const { job, gate, comment } = context
|
|
99
|
+
const command = parseApprovalComment(comment)
|
|
100
|
+
if (!command) throw new DecisionError("malformed", "The command is not a valid Taskfeed approval command.")
|
|
101
|
+
const created = Date.parse(comment.createdAt)
|
|
102
|
+
const updated = Date.parse(comment.updatedAt)
|
|
103
|
+
if (!Number.isFinite(created) || !Number.isFinite(updated)) {
|
|
104
|
+
throw new DecisionError("edited", "The comment timestamps are invalid, so Taskfeed cannot prove it is unedited.")
|
|
105
|
+
}
|
|
106
|
+
if (updated < created || updated - created > EDIT_TOLERANCE_MS) {
|
|
107
|
+
throw new DecisionError("edited", "The approval comment was edited; edited comments are never accepted.")
|
|
108
|
+
}
|
|
109
|
+
if (!context.authorizedUsers.map((value) => value.toLowerCase()).includes(comment.author.toLowerCase())) {
|
|
110
|
+
throw new DecisionError("unauthorized", "The commenter is not authorized to decide this gate.")
|
|
111
|
+
}
|
|
112
|
+
if (context.processedCommentIDs?.includes(comment.id)) {
|
|
113
|
+
throw new DecisionError("duplicate", "This comment has already been processed.")
|
|
114
|
+
}
|
|
115
|
+
if (job.status !== "awaiting_approval" || !job.gate || job.gate.id !== gate.id) {
|
|
116
|
+
throw new DecisionError("invalid_state", "The job is not waiting on this approval gate.")
|
|
117
|
+
}
|
|
118
|
+
if (gate.status !== "open") throw new DecisionError("duplicate", "This gate has already been decided.")
|
|
119
|
+
if (gate.id !== command.gateID) throw new DecisionError("stale", "The gate ID does not match the pending gate.")
|
|
120
|
+
if (command.revision !== gate.revision) throw new DecisionError("stale", "The approval revision is stale.")
|
|
121
|
+
if (created < gate.createdAt - 1_000) {
|
|
122
|
+
throw new DecisionError("stale", "The approval comment predates the gate.")
|
|
123
|
+
}
|
|
124
|
+
if (gate.decisionCommentID !== undefined) {
|
|
125
|
+
throw new DecisionError("duplicate", "A decision has already been recorded for this gate.")
|
|
126
|
+
}
|
|
127
|
+
if (gate.artifact?.type === "content") {
|
|
128
|
+
if (!gate.artifact.commentID || !gate.artifact.url || !gate.artifact.contentHash) {
|
|
129
|
+
throw new DecisionError("missing_remote_artifact", "The content review artifact has no GitHub representation.")
|
|
130
|
+
}
|
|
131
|
+
if (!context.currentContentHash || context.currentContentHash !== gate.artifact.contentHash) {
|
|
132
|
+
throw new DecisionError("artifact_changed", "The published review content no longer matches the approved artifact.")
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
if (!gate.pullRequestNumber || !gate.pullRequestURL || !gate.remoteHeadSHA || !gate.commitSHA) {
|
|
136
|
+
throw new DecisionError(
|
|
137
|
+
"missing_remote_artifact",
|
|
138
|
+
"This gate has no remotely accessible pull request and reviewed commit, so it cannot be approved externally.",
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
const pull = context.currentPullRequest
|
|
142
|
+
if (!pull) {
|
|
143
|
+
throw new DecisionError(
|
|
144
|
+
"artifact_changed",
|
|
145
|
+
"Taskfeed could not verify the current GitHub pull request, so the decision is not accepted.",
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
if (pull.number !== gate.pullRequestNumber || pull.url !== gate.pullRequestURL) {
|
|
149
|
+
throw new DecisionError("artifact_changed", "The review gate no longer points at the current pull request.")
|
|
150
|
+
}
|
|
151
|
+
if (pull.state !== "open") {
|
|
152
|
+
throw new DecisionError("artifact_changed", "The reviewed pull request is no longer open.")
|
|
153
|
+
}
|
|
154
|
+
if (pull.draft !== true) {
|
|
155
|
+
throw new DecisionError("artifact_changed", "The reviewed pull request is not a draft; Taskfeed will not continue.")
|
|
156
|
+
}
|
|
157
|
+
if (gate.commitSHA !== gate.remoteHeadSHA) {
|
|
158
|
+
throw new DecisionError("artifact_changed", "The recorded local and remote reviewed commits disagree.")
|
|
159
|
+
}
|
|
160
|
+
if (!context.currentHeadSHA || context.currentHeadSHA !== gate.commitSHA) {
|
|
161
|
+
throw new DecisionError("artifact_changed", "The worktree HEAD no longer matches the reviewed commit.")
|
|
162
|
+
}
|
|
163
|
+
if (pull.headSHA !== gate.remoteHeadSHA) {
|
|
164
|
+
throw new DecisionError("artifact_changed", "The GitHub pull request head no longer matches the reviewed commit.")
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const decision = decisionFromCommand(command, gate)
|
|
168
|
+
if (!decision) {
|
|
169
|
+
const available = gate.outcomes?.length ? ` Declared outcomes: ${gate.outcomes.join(", ")}.` : ""
|
|
170
|
+
throw new DecisionError(
|
|
171
|
+
"forbidden",
|
|
172
|
+
command.kind === "outcome"
|
|
173
|
+
? `The declared workflow outcome "${command.outcome}" is not available.${available}`
|
|
174
|
+
: `This workflow gate does not declare the requested outcome.${available}`,
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
return { command, decision }
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function approvalCommand(gateID: string, revision: number): string {
|
|
181
|
+
return `/taskfeed approve ${gateID} ${revision}`
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function changesCommand(gateID: string, revision: number): string {
|
|
185
|
+
return `/taskfeed request-changes ${gateID} ${revision}\n\nFeedback explaining the required changes.`
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function outcomeCommand(gateID: string, revision: number, outcome: string): string {
|
|
189
|
+
return `/taskfeed outcome ${gateID} ${revision} ${outcome}`
|
|
190
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import type { ExecutionEvidence, Gate, Job } from "./types.js"
|
|
2
|
+
import { approvalCommand, changesCommand, outcomeCommand } from "./approval.js"
|
|
3
|
+
|
|
4
|
+
function quote(value: string, max = 6_000): string {
|
|
5
|
+
return value.trim().slice(0, max) || "No summary was supplied."
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function evidenceLines(evidence: readonly ExecutionEvidence[]): string {
|
|
9
|
+
if (evidence.length === 0) return "- No structured evidence supplied."
|
|
10
|
+
return evidence
|
|
11
|
+
.slice(0, 20)
|
|
12
|
+
.map((item) => `- **${item.kind}**: ${item.value.slice(0, 1_000)}`)
|
|
13
|
+
.join("\n")
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function gateMarker(gateID: string): string {
|
|
17
|
+
return `<!-- taskfeed:gate:${gateID} -->`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function resultMarker(jobID: string): string {
|
|
21
|
+
return `<!-- taskfeed:result:${jobID} -->`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function artifactMarker(gateID: string): string {
|
|
25
|
+
return `<!-- taskfeed:artifact:${gateID} -->`
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function contentArtifactBody(input: {
|
|
29
|
+
job: Job
|
|
30
|
+
gate: Gate
|
|
31
|
+
content: string
|
|
32
|
+
}): string {
|
|
33
|
+
const { job, gate } = input
|
|
34
|
+
return [
|
|
35
|
+
`## Taskfeed content review for #${job.task.issueNumber}`,
|
|
36
|
+
"",
|
|
37
|
+
`**${job.task.title}**`,
|
|
38
|
+
"",
|
|
39
|
+
`- Gate: \`${gate.id}\``,
|
|
40
|
+
`- Revision: \`${gate.revision}\``,
|
|
41
|
+
...(gate.runID ? [`- Run: \`${gate.runID}\``] : []),
|
|
42
|
+
"",
|
|
43
|
+
"<taskfeed-artifact>",
|
|
44
|
+
input.content,
|
|
45
|
+
"</taskfeed-artifact>",
|
|
46
|
+
].join("\n")
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function extractContentArtifact(body: string): string | undefined {
|
|
50
|
+
const match = /<taskfeed-artifact>\n([\s\S]*?)\n<\/taskfeed-artifact>/u.exec(body)
|
|
51
|
+
return match?.[1]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function gateComment(input: {
|
|
55
|
+
job: Job
|
|
56
|
+
gate: Gate
|
|
57
|
+
summary: string
|
|
58
|
+
evidence: readonly ExecutionEvidence[]
|
|
59
|
+
}): string {
|
|
60
|
+
const { job, gate } = input
|
|
61
|
+
const commands =
|
|
62
|
+
gate.kind === "native_review"
|
|
63
|
+
? [
|
|
64
|
+
"```text",
|
|
65
|
+
approvalCommand(gate.id, gate.revision),
|
|
66
|
+
"```",
|
|
67
|
+
"",
|
|
68
|
+
"Request a rework:",
|
|
69
|
+
"```text",
|
|
70
|
+
changesCommand(gate.id, gate.revision),
|
|
71
|
+
"```",
|
|
72
|
+
]
|
|
73
|
+
: workflowCommands(gate)
|
|
74
|
+
return [
|
|
75
|
+
`## Taskfeed review requested for #${job.task.issueNumber}`,
|
|
76
|
+
"",
|
|
77
|
+
`**${job.task.title}**`,
|
|
78
|
+
"",
|
|
79
|
+
`- Execution: ${job.execution.type} \`${job.execution.name}\``,
|
|
80
|
+
...(job.workspace ? [`- Branch: \`${job.workspace.branch}\``] : []),
|
|
81
|
+
...(gate.artifact?.type === "content"
|
|
82
|
+
? [
|
|
83
|
+
`- Content review artifact: ${gate.artifact.url ?? "publishing"}`,
|
|
84
|
+
`- Content digest: \`${gate.artifact.contentHash}\``,
|
|
85
|
+
]
|
|
86
|
+
: gate.pullRequestURL
|
|
87
|
+
? [`- Draft pull request: ${gate.pullRequestURL}`]
|
|
88
|
+
: ["- Remote review artifact: **unavailable**"]),
|
|
89
|
+
...(gate.remoteHeadSHA
|
|
90
|
+
? [`- Reviewed commit: \`${gate.remoteHeadSHA}\``]
|
|
91
|
+
: gate.commitSHA
|
|
92
|
+
? [`- Worktree commit: \`${gate.commitSHA}\``]
|
|
93
|
+
: []),
|
|
94
|
+
"",
|
|
95
|
+
"### Summary",
|
|
96
|
+
"",
|
|
97
|
+
quote(input.summary),
|
|
98
|
+
"",
|
|
99
|
+
"### Evidence",
|
|
100
|
+
"",
|
|
101
|
+
evidenceLines(input.evidence),
|
|
102
|
+
"",
|
|
103
|
+
"### Decision",
|
|
104
|
+
"",
|
|
105
|
+
...commands,
|
|
106
|
+
"",
|
|
107
|
+
"Only configured Taskfeed approvers can decide this gate. Stale revisions, edited/replayed commands and unauthorized users are rejected.",
|
|
108
|
+
"Taskfeed does not merge or deploy.",
|
|
109
|
+
].join("\n")
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function workflowCommands(gate: Gate): string[] {
|
|
113
|
+
const outcomes = gate.outcomes ?? []
|
|
114
|
+
const lines: string[] = []
|
|
115
|
+
if (outcomes.includes("approved")) {
|
|
116
|
+
lines.push("```text", approvalCommand(gate.id, gate.revision), "```", "")
|
|
117
|
+
}
|
|
118
|
+
if (outcomes.includes("changes_requested")) {
|
|
119
|
+
lines.push("Request changes:", "```text", changesCommand(gate.id, gate.revision), "```", "")
|
|
120
|
+
}
|
|
121
|
+
if (lines.length === 0) {
|
|
122
|
+
lines.push(
|
|
123
|
+
"This Flowgraph gate has no standard approved/changes_requested outcome. Use one of its declared outcomes:",
|
|
124
|
+
"```text",
|
|
125
|
+
outcomes.map((outcome) => outcomeCommand(gate.id, gate.revision, outcome)).join("\n") || "(none declared)",
|
|
126
|
+
"```",
|
|
127
|
+
"",
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
return lines
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function resultComment(input: {
|
|
134
|
+
job: Job
|
|
135
|
+
summary: string
|
|
136
|
+
evidence: readonly ExecutionEvidence[]
|
|
137
|
+
}): string {
|
|
138
|
+
const { job } = input
|
|
139
|
+
return [
|
|
140
|
+
`## Taskfeed completed #${job.task.issueNumber}`,
|
|
141
|
+
"",
|
|
142
|
+
`**${job.task.title}**`,
|
|
143
|
+
"",
|
|
144
|
+
...(job.gate?.pullRequestURL ? [`- Draft pull request: ${job.gate.pullRequestURL}`] : []),
|
|
145
|
+
...(job.gate?.remoteHeadSHA
|
|
146
|
+
? [`- Reviewed commit: \`${job.gate.remoteHeadSHA}\``]
|
|
147
|
+
: job.gate?.commitSHA
|
|
148
|
+
? [`- Worktree commit: \`${job.gate.commitSHA}\``]
|
|
149
|
+
: []),
|
|
150
|
+
...(job.workspace ? [`- Branch: \`${job.workspace.branch}\``] : []),
|
|
151
|
+
"",
|
|
152
|
+
"### Result",
|
|
153
|
+
"",
|
|
154
|
+
quote(input.summary),
|
|
155
|
+
"",
|
|
156
|
+
"### Evidence",
|
|
157
|
+
"",
|
|
158
|
+
evidenceLines(input.evidence),
|
|
159
|
+
"",
|
|
160
|
+
"Taskfeed does not merge or deploy. Any merge remains a human decision.",
|
|
161
|
+
].join("\n")
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function blockerComment(job: Job): string {
|
|
165
|
+
return [
|
|
166
|
+
`## Taskfeed blocked #${job.task.issueNumber}`,
|
|
167
|
+
"",
|
|
168
|
+
`**${job.task.title}**`,
|
|
169
|
+
"",
|
|
170
|
+
`\`${job.blocker?.code ?? "blocked"}\`: ${quote(job.blocker?.message ?? "Execution needs attention.", 2_000)}`,
|
|
171
|
+
...(job.blocker?.action ? ["", `Required action: ${job.blocker.action}`] : []),
|
|
172
|
+
"",
|
|
173
|
+
"The workspace and session state were retained. Taskfeed will not guess whether it is safe to replay this execution.",
|
|
174
|
+
].join("\n")
|
|
175
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AdmissionAuthorization,
|
|
3
|
+
DecisionComment,
|
|
4
|
+
ExecutionEvidence,
|
|
5
|
+
ExecutionMode,
|
|
6
|
+
ExecutionObservation,
|
|
7
|
+
Gate,
|
|
8
|
+
IssueSummary,
|
|
9
|
+
IssueContext,
|
|
10
|
+
IssueTask,
|
|
11
|
+
LinkedPullRequest,
|
|
12
|
+
PublicationResult,
|
|
13
|
+
PublishedComment,
|
|
14
|
+
PullRequestInfo,
|
|
15
|
+
Workspace,
|
|
16
|
+
} from "./types.js"
|
|
17
|
+
|
|
18
|
+
export interface SourceValidation {
|
|
19
|
+
readonly defaultBranch: string
|
|
20
|
+
readonly repository: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ReadyListing {
|
|
24
|
+
readonly issues: readonly IssueSummary[]
|
|
25
|
+
readonly skipped: readonly { number: number; reason: string }[]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface WorkSource {
|
|
29
|
+
readonly repository: string
|
|
30
|
+
validate(signal?: AbortSignal): Promise<SourceValidation>
|
|
31
|
+
ensureLabels(labels: readonly string[], signal?: AbortSignal): Promise<void>
|
|
32
|
+
listReady(input: { triggerLabels: readonly string[]; enqueueUsers: readonly string[]; signal?: AbortSignal }): Promise<ReadyListing>
|
|
33
|
+
authorizeAdmission(
|
|
34
|
+
summary: IssueSummary,
|
|
35
|
+
policy: { triggerLabels: readonly string[]; enqueueUsers: readonly string[] },
|
|
36
|
+
signal?: AbortSignal,
|
|
37
|
+
): Promise<AdmissionAuthorization>
|
|
38
|
+
loadContext(summary: IssueSummary, signal?: AbortSignal): Promise<IssueContext>
|
|
39
|
+
readDecisions(job: { task: { repository: string; issueNumber: number } }, signal?: AbortSignal): Promise<readonly DecisionComment[]>
|
|
40
|
+
getComment(repository: string, issueNumber: number, commentID: number, signal?: AbortSignal): Promise<DecisionComment | undefined>
|
|
41
|
+
applyLabels(
|
|
42
|
+
input: { repository: string; issueNumber: number; add: readonly string[]; remove: readonly string[] },
|
|
43
|
+
signal?: AbortSignal,
|
|
44
|
+
): Promise<void>
|
|
45
|
+
upsertComment(
|
|
46
|
+
input: {
|
|
47
|
+
repository: string
|
|
48
|
+
issueNumber: number
|
|
49
|
+
marker: string
|
|
50
|
+
body: string
|
|
51
|
+
commentID?: number
|
|
52
|
+
signal?: AbortSignal
|
|
53
|
+
},
|
|
54
|
+
): Promise<PublishedComment>
|
|
55
|
+
listLinkedPullRequests(repository: string, issueNumber: number, signal?: AbortSignal): Promise<readonly LinkedPullRequest[]>
|
|
56
|
+
getPullRequest(repository: string, pullRequestNumber: number, signal?: AbortSignal): Promise<PullRequestInfo | undefined>
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface WorkspaceState {
|
|
60
|
+
readonly exists: boolean
|
|
61
|
+
readonly clean: boolean
|
|
62
|
+
readonly headSHA?: string
|
|
63
|
+
readonly dirtyFiles: readonly string[]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface WorkspaceProvider {
|
|
67
|
+
prepare(input: { jobID: string; issueNumber: number; title: string; baseBranch?: string }): Promise<Workspace>
|
|
68
|
+
state(workspace: Workspace): Promise<WorkspaceState>
|
|
69
|
+
cleanup(workspace: Workspace): Promise<void>
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface ExecutionStart {
|
|
73
|
+
readonly sessionID?: string
|
|
74
|
+
readonly runID?: string
|
|
75
|
+
readonly runRevision?: number
|
|
76
|
+
readonly promptMessageID?: string
|
|
77
|
+
readonly rootSessionID?: string
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface ExecutionInspectionInput {
|
|
81
|
+
readonly jobID: string
|
|
82
|
+
readonly sessionID?: string
|
|
83
|
+
readonly runID?: string
|
|
84
|
+
readonly workspaceDirectory?: string
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface Executor {
|
|
88
|
+
readonly mode: ExecutionMode["type"]
|
|
89
|
+
validate(input: { name: string; canonicalDirectory: string }): Promise<void>
|
|
90
|
+
start(input: {
|
|
91
|
+
jobID: string
|
|
92
|
+
task: IssueTask
|
|
93
|
+
workspace: Workspace
|
|
94
|
+
prompt: string
|
|
95
|
+
idempotencyKey: string
|
|
96
|
+
execution: ExecutionMode
|
|
97
|
+
attempt: number
|
|
98
|
+
}): Promise<ExecutionStart>
|
|
99
|
+
/** Native execution creates a session first, then admits its prompt. */
|
|
100
|
+
submit?(input: {
|
|
101
|
+
jobID: string
|
|
102
|
+
task: IssueTask
|
|
103
|
+
workspace: Workspace
|
|
104
|
+
sessionID?: string
|
|
105
|
+
prompt: string
|
|
106
|
+
requestID: string
|
|
107
|
+
attempt: number
|
|
108
|
+
}): Promise<{ promptMessageID?: string }>
|
|
109
|
+
inspect(input: ExecutionInspectionInput & { promptMessageID?: string }): Promise<ExecutionObservation>
|
|
110
|
+
respond(input: {
|
|
111
|
+
jobID: string
|
|
112
|
+
task: IssueTask
|
|
113
|
+
sessionID?: string
|
|
114
|
+
runID?: string
|
|
115
|
+
workspaceDirectory: string
|
|
116
|
+
gate: Gate
|
|
117
|
+
decision: { kind: "approved" | "changes_requested" | "outcome"; outcome?: string; feedback: string }
|
|
118
|
+
requestID: string
|
|
119
|
+
attempt: number
|
|
120
|
+
}): Promise<ExecutionStart>
|
|
121
|
+
cancel(input: ExecutionInspectionInput): Promise<{ confirmed: boolean; observation?: ExecutionObservation }>
|
|
122
|
+
recover?(input: {
|
|
123
|
+
jobID: string
|
|
124
|
+
workspace: Workspace
|
|
125
|
+
attempt: number
|
|
126
|
+
}): Promise<ExecutionStart | undefined>
|
|
127
|
+
pause?(input: ExecutionInspectionInput): Promise<void>
|
|
128
|
+
resume?(input: ExecutionInspectionInput): Promise<void>
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface PublicationInput {
|
|
132
|
+
readonly jobID: string
|
|
133
|
+
readonly repository: string
|
|
134
|
+
readonly issueNumber: number
|
|
135
|
+
readonly title: string
|
|
136
|
+
readonly issueURL: string
|
|
137
|
+
readonly branch: string
|
|
138
|
+
readonly baseSHA: string
|
|
139
|
+
readonly headSHA: string
|
|
140
|
+
readonly workspace: Workspace
|
|
141
|
+
readonly summary: string
|
|
142
|
+
readonly evidence: readonly ExecutionEvidence[]
|
|
143
|
+
readonly existingPullRequest?: { number: number; url: string; headSHA: string }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface Publisher {
|
|
147
|
+
readonly enabled: boolean
|
|
148
|
+
publish(input: PublicationInput): Promise<PublicationResult>
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface CapacityPort {
|
|
152
|
+
acquire(input: {
|
|
153
|
+
projectKey: string
|
|
154
|
+
jobID: string
|
|
155
|
+
state?: "active" | "ambiguous"
|
|
156
|
+
recover?: boolean
|
|
157
|
+
}): Promise<{
|
|
158
|
+
token: string
|
|
159
|
+
generation: number
|
|
160
|
+
state: "active" | "ambiguous"
|
|
161
|
+
projectKey: string
|
|
162
|
+
jobID: string
|
|
163
|
+
} | undefined>
|
|
164
|
+
heartbeat(slot: { projectKey: string; jobID: string; token: string; generation?: number }): Promise<boolean>
|
|
165
|
+
markAmbiguous(slot: { projectKey: string; jobID: string; token: string; generation?: number }): Promise<unknown>
|
|
166
|
+
release(slot: { projectKey: string; jobID: string; token: string; generation?: number }): Promise<boolean>
|
|
167
|
+
snapshot(): Promise<{
|
|
168
|
+
limit: number
|
|
169
|
+
used: number
|
|
170
|
+
ambiguous: number
|
|
171
|
+
slots: readonly {
|
|
172
|
+
projectKey: string
|
|
173
|
+
jobID: string
|
|
174
|
+
token: string
|
|
175
|
+
generation: number
|
|
176
|
+
state: "active" | "ambiguous"
|
|
177
|
+
heartbeatAt: number
|
|
178
|
+
}[]
|
|
179
|
+
}>
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface LeaderPort {
|
|
183
|
+
isLeader(): Promise<boolean>
|
|
184
|
+
heartbeat(): Promise<boolean>
|
|
185
|
+
}
|