@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,186 @@
|
|
|
1
|
+
import type { AdmissionAuthorization, IssueTask } from "./types.js"
|
|
2
|
+
import { JobSchema, type ExecutionMode, type Job, type JobStatus, type JobView, type StatusLabels } from "./types.js"
|
|
3
|
+
|
|
4
|
+
const ALLOWED: Readonly<Record<JobStatus, readonly JobStatus[]>> = {
|
|
5
|
+
discovered: ["queued", "blocked", "cancelled"],
|
|
6
|
+
queued: ["starting", "blocked", "cancelled"],
|
|
7
|
+
starting: ["running", "awaiting_approval", "paused", "blocked", "failed", "cancelled"],
|
|
8
|
+
running: ["awaiting_approval", "paused", "blocked", "failed", "completed", "cancelled"],
|
|
9
|
+
awaiting_approval: ["running", "blocked", "failed", "completed", "cancelled"],
|
|
10
|
+
paused: ["running", "queued", "blocked", "failed", "completed", "cancelled"],
|
|
11
|
+
blocked: ["starting", "queued", "running", "awaiting_approval", "failed", "cancelled", "completed"],
|
|
12
|
+
completed: [],
|
|
13
|
+
failed: ["starting", "queued", "blocked", "cancelled"],
|
|
14
|
+
cancelled: [],
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class InvalidTransition extends Error {
|
|
18
|
+
constructor(
|
|
19
|
+
readonly from: JobStatus,
|
|
20
|
+
readonly to: JobStatus,
|
|
21
|
+
) {
|
|
22
|
+
super(`invalid Taskfeed job transition: ${from} -> ${to}`)
|
|
23
|
+
this.name = "InvalidTransition"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function canTransition(from: JobStatus, to: JobStatus): boolean {
|
|
28
|
+
return ALLOWED[from].includes(to)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function transition(
|
|
32
|
+
job: Job,
|
|
33
|
+
to: JobStatus,
|
|
34
|
+
message: string,
|
|
35
|
+
at: number,
|
|
36
|
+
patch: Partial<Job> = {},
|
|
37
|
+
): Job {
|
|
38
|
+
if (!canTransition(job.status, to)) throw new InvalidTransition(job.status, to)
|
|
39
|
+
const event = { at, status: to, message: message.slice(0, 500) }
|
|
40
|
+
return JobSchema.parse({
|
|
41
|
+
...job,
|
|
42
|
+
...patch,
|
|
43
|
+
status: to,
|
|
44
|
+
revision: job.revision + 1,
|
|
45
|
+
updatedAt: at,
|
|
46
|
+
...(to === "completed" || to === "cancelled" ? { completedAt: at } : {}),
|
|
47
|
+
events: [...job.events, event].slice(-50),
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function isTerminal(status: JobStatus): boolean {
|
|
52
|
+
return status === "completed" || status === "cancelled"
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function taskKeyFor(repository: string, issueNumber: number): string {
|
|
56
|
+
return `github:${repository.toLowerCase()}#${issueNumber}`
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function createJob(input: {
|
|
60
|
+
projectKey: string
|
|
61
|
+
issue: IssueTask
|
|
62
|
+
execution: ExecutionMode
|
|
63
|
+
idempotencyKey: string
|
|
64
|
+
admission?: AdmissionAuthorization
|
|
65
|
+
statusLabels: StatusLabels
|
|
66
|
+
now: number
|
|
67
|
+
jobID: string
|
|
68
|
+
}): Job {
|
|
69
|
+
const taskKey = taskKeyFor(input.issue.repository, input.issue.number)
|
|
70
|
+
return JobSchema.parse({
|
|
71
|
+
schemaVersion: 1,
|
|
72
|
+
jobID: input.jobID,
|
|
73
|
+
projectKey: input.projectKey,
|
|
74
|
+
taskKey,
|
|
75
|
+
task: {
|
|
76
|
+
source: "github",
|
|
77
|
+
repository: input.issue.repository,
|
|
78
|
+
issueNumber: input.issue.number,
|
|
79
|
+
issueURL: input.issue.url,
|
|
80
|
+
title: input.issue.title,
|
|
81
|
+
bodyHash: input.issue.bodyHash,
|
|
82
|
+
enqueuedBy: input.issue.enqueuedBy,
|
|
83
|
+
enqueuedAt: input.issue.enqueuedAt,
|
|
84
|
+
updatedAt: input.issue.updatedAt,
|
|
85
|
+
},
|
|
86
|
+
status: "queued",
|
|
87
|
+
revision: 1,
|
|
88
|
+
attempts: 0,
|
|
89
|
+
feedbackIterations: 0,
|
|
90
|
+
idempotencyKey: input.idempotencyKey,
|
|
91
|
+
execution: input.execution,
|
|
92
|
+
...(input.admission === undefined ? {} : { admission: input.admission }),
|
|
93
|
+
workspace: null,
|
|
94
|
+
executionRef: null,
|
|
95
|
+
gate: null,
|
|
96
|
+
pendingDecision: null,
|
|
97
|
+
publication: null,
|
|
98
|
+
capacity: null,
|
|
99
|
+
blocker: null,
|
|
100
|
+
labels: { ready: [...input.issue.labels], applied: [] },
|
|
101
|
+
createdAt: input.now,
|
|
102
|
+
updatedAt: input.now,
|
|
103
|
+
events: [{ at: input.now, status: "queued", message: "Issue discovered and queued" }],
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function desiredStatusLabel(status: JobStatus, labels: StatusLabels): string | undefined {
|
|
108
|
+
switch (status) {
|
|
109
|
+
case "discovered":
|
|
110
|
+
case "queued":
|
|
111
|
+
case "cancelled":
|
|
112
|
+
return undefined
|
|
113
|
+
case "starting":
|
|
114
|
+
case "running":
|
|
115
|
+
case "paused":
|
|
116
|
+
return labels.running
|
|
117
|
+
case "awaiting_approval":
|
|
118
|
+
return labels.review
|
|
119
|
+
case "blocked":
|
|
120
|
+
case "failed":
|
|
121
|
+
return labels.blocked
|
|
122
|
+
case "completed":
|
|
123
|
+
return labels.completed
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface LabelPlan {
|
|
128
|
+
readonly add: readonly string[]
|
|
129
|
+
readonly remove: readonly string[]
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function labelPlan(input: {
|
|
133
|
+
status: JobStatus
|
|
134
|
+
ready: readonly string[]
|
|
135
|
+
applied: readonly string[]
|
|
136
|
+
labels: StatusLabels
|
|
137
|
+
triggerLabels: readonly string[]
|
|
138
|
+
}): LabelPlan {
|
|
139
|
+
const statuses = Object.values(input.labels)
|
|
140
|
+
const desired = desiredStatusLabel(input.status, input.labels)
|
|
141
|
+
const add = desired && !input.applied.includes(desired) ? [desired] : []
|
|
142
|
+
const remove = new Set<string>()
|
|
143
|
+
for (const label of input.applied) if (label !== desired && statuses.includes(label)) remove.add(label)
|
|
144
|
+
const triggers = input.ready.filter((label) => input.triggerLabels.includes(label))
|
|
145
|
+
if (input.status !== "discovered" && input.status !== "queued") {
|
|
146
|
+
for (const label of triggers) remove.add(label)
|
|
147
|
+
}
|
|
148
|
+
if (input.status === "cancelled") {
|
|
149
|
+
for (const label of statuses) if (input.applied.includes(label)) remove.add(label)
|
|
150
|
+
for (const label of triggers) remove.add(label)
|
|
151
|
+
}
|
|
152
|
+
for (const label of add) remove.delete(label)
|
|
153
|
+
return { add, remove: [...remove].filter((label) => !add.includes(label)) }
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function toJobView(job: Job): JobView {
|
|
157
|
+
return {
|
|
158
|
+
jobID: job.jobID,
|
|
159
|
+
task: job.task,
|
|
160
|
+
status: job.status,
|
|
161
|
+
revision: job.revision,
|
|
162
|
+
attempts: job.attempts,
|
|
163
|
+
feedbackIterations: job.feedbackIterations,
|
|
164
|
+
execution: job.execution,
|
|
165
|
+
branch: job.workspace?.branch ?? null,
|
|
166
|
+
commitSHA: job.gate?.remoteHeadSHA ?? job.gate?.commitSHA ?? null,
|
|
167
|
+
pullRequestURL: job.gate?.pullRequestURL ?? job.publication?.pullRequestURL ?? null,
|
|
168
|
+
pullRequestNumber: job.gate?.pullRequestNumber ?? job.publication?.pullRequestNumber ?? null,
|
|
169
|
+
publication: job.publication,
|
|
170
|
+
sessionID: job.executionRef?.sessionID ?? job.executionRef?.rootSessionID ?? null,
|
|
171
|
+
runID: job.executionRef?.runID ?? null,
|
|
172
|
+
gate: job.gate,
|
|
173
|
+
pendingDecision: job.pendingDecision,
|
|
174
|
+
blocker: job.blocker,
|
|
175
|
+
labels: [job.task.repository, ...job.labels.applied],
|
|
176
|
+
createdAt: job.createdAt,
|
|
177
|
+
updatedAt: job.updatedAt,
|
|
178
|
+
startedAt: job.startedAt ?? null,
|
|
179
|
+
completedAt: job.completedAt ?? null,
|
|
180
|
+
lastError: job.lastError ?? null,
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function parseJob(value: unknown): Job {
|
|
185
|
+
return JobSchema.parse(value)
|
|
186
|
+
}
|
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
import { z } from "zod"
|
|
2
|
+
|
|
3
|
+
export interface StatusLabels {
|
|
4
|
+
readonly running: string
|
|
5
|
+
readonly review: string
|
|
6
|
+
readonly blocked: string
|
|
7
|
+
readonly completed: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const JobStatusSchema = z.enum([
|
|
11
|
+
"discovered",
|
|
12
|
+
"queued",
|
|
13
|
+
"starting",
|
|
14
|
+
"running",
|
|
15
|
+
"awaiting_approval",
|
|
16
|
+
"paused",
|
|
17
|
+
"blocked",
|
|
18
|
+
"completed",
|
|
19
|
+
"failed",
|
|
20
|
+
"cancelled",
|
|
21
|
+
])
|
|
22
|
+
export type JobStatus = z.infer<typeof JobStatusSchema>
|
|
23
|
+
|
|
24
|
+
export const ExecutionModeSchema = z.object({
|
|
25
|
+
type: z.enum(["agent", "workflow"]),
|
|
26
|
+
name: z.string().min(1),
|
|
27
|
+
})
|
|
28
|
+
export type ExecutionMode = z.infer<typeof ExecutionModeSchema>
|
|
29
|
+
|
|
30
|
+
export const WorkspaceSchema = z.object({
|
|
31
|
+
directory: z.string().min(1),
|
|
32
|
+
branch: z.string().min(1),
|
|
33
|
+
baseSHA: z.string().min(1),
|
|
34
|
+
strategy: z.string().min(1),
|
|
35
|
+
createdAt: z.number().int().nonnegative(),
|
|
36
|
+
})
|
|
37
|
+
export type Workspace = z.infer<typeof WorkspaceSchema>
|
|
38
|
+
|
|
39
|
+
export const AdmissionAuthorizationSchema = z.object({
|
|
40
|
+
repository: z.string(),
|
|
41
|
+
issueNumber: z.number().int().positive(),
|
|
42
|
+
issueURL: z.string().url(),
|
|
43
|
+
actor: z.string(),
|
|
44
|
+
admittedAt: z.number().int().nonnegative(),
|
|
45
|
+
labels: z.array(
|
|
46
|
+
z.object({
|
|
47
|
+
name: z.string(),
|
|
48
|
+
actor: z.string(),
|
|
49
|
+
at: z.string(),
|
|
50
|
+
eventID: z.union([z.string(), z.number()]).optional(),
|
|
51
|
+
}),
|
|
52
|
+
),
|
|
53
|
+
})
|
|
54
|
+
export type AdmissionAuthorization = z.infer<typeof AdmissionAuthorizationSchema>
|
|
55
|
+
|
|
56
|
+
export const ContentReviewArtifactSchema = z.object({
|
|
57
|
+
type: z.literal("content"),
|
|
58
|
+
content: z.string(),
|
|
59
|
+
contentHash: z.string(),
|
|
60
|
+
commentID: z.number().int().positive().optional(),
|
|
61
|
+
url: z.string().url().optional(),
|
|
62
|
+
executionID: z.string().optional(),
|
|
63
|
+
})
|
|
64
|
+
export type ContentReviewArtifact = z.infer<typeof ContentReviewArtifactSchema>
|
|
65
|
+
|
|
66
|
+
export const CommitReviewArtifactSchema = z.object({
|
|
67
|
+
type: z.literal("commit"),
|
|
68
|
+
repository: z.string(),
|
|
69
|
+
pullRequestNumber: z.number().int().positive(),
|
|
70
|
+
url: z.string().url(),
|
|
71
|
+
headSHA: z.string(),
|
|
72
|
+
executionID: z.string().optional(),
|
|
73
|
+
})
|
|
74
|
+
export type CommitReviewArtifact = z.infer<typeof CommitReviewArtifactSchema>
|
|
75
|
+
|
|
76
|
+
export const ReviewArtifactSchema = z.discriminatedUnion("type", [
|
|
77
|
+
ContentReviewArtifactSchema,
|
|
78
|
+
CommitReviewArtifactSchema,
|
|
79
|
+
])
|
|
80
|
+
export type ReviewArtifact = z.infer<typeof ReviewArtifactSchema>
|
|
81
|
+
|
|
82
|
+
export const GateSchema = z.object({
|
|
83
|
+
id: z.string().min(1),
|
|
84
|
+
kind: z.enum(["native_review", "workflow_human"]),
|
|
85
|
+
createdAt: z.number().int().nonnegative(),
|
|
86
|
+
revision: z.number().int().nonnegative(),
|
|
87
|
+
providerRevision: z.number().int().nonnegative().optional(),
|
|
88
|
+
nodeID: z.string().optional(),
|
|
89
|
+
outcomes: z.array(z.string()).optional(),
|
|
90
|
+
commitSHA: z.string().optional(),
|
|
91
|
+
summary: z.string().optional(),
|
|
92
|
+
evidence: z
|
|
93
|
+
.array(
|
|
94
|
+
z.object({
|
|
95
|
+
kind: z.enum(["file", "command", "url", "note", "commit"]),
|
|
96
|
+
value: z.string(),
|
|
97
|
+
}),
|
|
98
|
+
)
|
|
99
|
+
.optional(),
|
|
100
|
+
pullRequestNumber: z.number().int().positive().optional(),
|
|
101
|
+
pullRequestURL: z.string().url().optional(),
|
|
102
|
+
remoteHeadSHA: z.string().optional(),
|
|
103
|
+
artifact: ReviewArtifactSchema.optional(),
|
|
104
|
+
runID: z.string().optional(),
|
|
105
|
+
sessionID: z.string().optional(),
|
|
106
|
+
commentID: z.number().int().positive().optional(),
|
|
107
|
+
status: z.enum(["open", "approved", "changes_requested", "cancelled", "stale"]).default("open"),
|
|
108
|
+
decidedBy: z.string().optional(),
|
|
109
|
+
decidedAt: z.number().int().nonnegative().optional(),
|
|
110
|
+
decisionCommentID: z.number().int().positive().optional(),
|
|
111
|
+
decisionCommentUpdatedAt: z.string().optional(),
|
|
112
|
+
})
|
|
113
|
+
export type Gate = z.infer<typeof GateSchema>
|
|
114
|
+
|
|
115
|
+
export const DecisionAdmissionSchema = z.object({
|
|
116
|
+
requestID: z.string().min(1),
|
|
117
|
+
startedAt: z.number().int().nonnegative(),
|
|
118
|
+
sessionID: z.string().optional(),
|
|
119
|
+
runID: z.string().optional(),
|
|
120
|
+
})
|
|
121
|
+
export type DecisionAdmission = z.infer<typeof DecisionAdmissionSchema>
|
|
122
|
+
|
|
123
|
+
export const PendingDecisionSchema = z.object({
|
|
124
|
+
kind: z.enum(["approved", "changes_requested", "outcome"]),
|
|
125
|
+
outcome: z.string().optional(),
|
|
126
|
+
feedback: z.string().default(""),
|
|
127
|
+
gateID: z.string(),
|
|
128
|
+
gateRevision: z.number().int().nonnegative(),
|
|
129
|
+
commentID: z.number().int().positive(),
|
|
130
|
+
receivedAt: z.number().int().nonnegative(),
|
|
131
|
+
commentAuthor: z.string().optional(),
|
|
132
|
+
commentBodyHash: z.string().optional(),
|
|
133
|
+
reviewedSHA: z.string().optional(),
|
|
134
|
+
reviewedContentHash: z.string().optional(),
|
|
135
|
+
admission: DecisionAdmissionSchema.optional(),
|
|
136
|
+
})
|
|
137
|
+
export type PendingDecision = z.infer<typeof PendingDecisionSchema>
|
|
138
|
+
|
|
139
|
+
export const PublicationSchema = z.object({
|
|
140
|
+
status: z.enum(["disabled", "pending", "published", "failed", "local_only"]),
|
|
141
|
+
branch: z.string().optional(),
|
|
142
|
+
remote: z.string().optional(),
|
|
143
|
+
pullRequestNumber: z.number().int().positive().optional(),
|
|
144
|
+
pullRequestURL: z.string().url().optional(),
|
|
145
|
+
headSHA: z.string().optional(),
|
|
146
|
+
error: z.string().optional(),
|
|
147
|
+
})
|
|
148
|
+
export type Publication = z.infer<typeof PublicationSchema>
|
|
149
|
+
|
|
150
|
+
export const ExecutionRefSchema = z.object({
|
|
151
|
+
mode: z.enum(["agent", "workflow"]),
|
|
152
|
+
sessionID: z.string().optional(),
|
|
153
|
+
runID: z.string().optional(),
|
|
154
|
+
runRevision: z.number().int().nonnegative().optional(),
|
|
155
|
+
promptMessageID: z.string().optional(),
|
|
156
|
+
promptRequestID: z.string().optional(),
|
|
157
|
+
rootSessionID: z.string().optional(),
|
|
158
|
+
startedAt: z.number().int().nonnegative(),
|
|
159
|
+
lastObservedAt: z.number().int().nonnegative().optional(),
|
|
160
|
+
})
|
|
161
|
+
export type ExecutionRef = z.infer<typeof ExecutionRefSchema>
|
|
162
|
+
|
|
163
|
+
export const CapacityRefSchema = z.object({
|
|
164
|
+
token: z.string(),
|
|
165
|
+
generation: z.number().int().nonnegative().default(1),
|
|
166
|
+
state: z.enum(["active", "ambiguous"]),
|
|
167
|
+
})
|
|
168
|
+
export type CapacityRef = z.infer<typeof CapacityRefSchema>
|
|
169
|
+
|
|
170
|
+
export const BlockerSchema = z.object({
|
|
171
|
+
code: z.string().min(1),
|
|
172
|
+
message: z.string().min(1),
|
|
173
|
+
at: z.number().int().nonnegative(),
|
|
174
|
+
action: z.string().optional(),
|
|
175
|
+
})
|
|
176
|
+
export type Blocker = z.infer<typeof BlockerSchema>
|
|
177
|
+
|
|
178
|
+
export const JobEventSchema = z.object({
|
|
179
|
+
at: z.number().int().nonnegative(),
|
|
180
|
+
status: JobStatusSchema,
|
|
181
|
+
message: z.string(),
|
|
182
|
+
})
|
|
183
|
+
export type JobEvent = z.infer<typeof JobEventSchema>
|
|
184
|
+
|
|
185
|
+
export const JobTaskSchema = z.object({
|
|
186
|
+
source: z.literal("github"),
|
|
187
|
+
repository: z.string(),
|
|
188
|
+
issueNumber: z.number().int().positive(),
|
|
189
|
+
issueURL: z.string().url(),
|
|
190
|
+
title: z.string(),
|
|
191
|
+
bodyHash: z.string(),
|
|
192
|
+
enqueuedBy: z.string(),
|
|
193
|
+
enqueuedAt: z.number().int().nonnegative(),
|
|
194
|
+
updatedAt: z.string(),
|
|
195
|
+
})
|
|
196
|
+
export type JobTask = z.infer<typeof JobTaskSchema>
|
|
197
|
+
|
|
198
|
+
export const JobSchema = z.object({
|
|
199
|
+
schemaVersion: z.literal(1),
|
|
200
|
+
jobID: z.string().min(1),
|
|
201
|
+
projectKey: z.string().min(1),
|
|
202
|
+
taskKey: z.string().min(1),
|
|
203
|
+
task: JobTaskSchema,
|
|
204
|
+
admission: AdmissionAuthorizationSchema.optional(),
|
|
205
|
+
status: JobStatusSchema,
|
|
206
|
+
revision: z.number().int().nonnegative(),
|
|
207
|
+
attempts: z.number().int().nonnegative(),
|
|
208
|
+
feedbackIterations: z.number().int().nonnegative(),
|
|
209
|
+
idempotencyKey: z.string().min(1),
|
|
210
|
+
execution: ExecutionModeSchema,
|
|
211
|
+
workspace: WorkspaceSchema.nullable(),
|
|
212
|
+
executionRef: ExecutionRefSchema.nullable(),
|
|
213
|
+
gate: GateSchema.nullable(),
|
|
214
|
+
pendingDecision: PendingDecisionSchema.nullable(),
|
|
215
|
+
publication: PublicationSchema.nullable(),
|
|
216
|
+
capacity: CapacityRefSchema.nullable(),
|
|
217
|
+
blocker: BlockerSchema.nullable(),
|
|
218
|
+
labels: z.object({
|
|
219
|
+
ready: z.array(z.string()),
|
|
220
|
+
applied: z.array(z.string()),
|
|
221
|
+
}),
|
|
222
|
+
createdAt: z.number().int().nonnegative(),
|
|
223
|
+
updatedAt: z.number().int().nonnegative(),
|
|
224
|
+
startedAt: z.number().int().nonnegative().optional(),
|
|
225
|
+
completedAt: z.number().int().nonnegative().optional(),
|
|
226
|
+
retryAt: z.number().int().nonnegative().optional(),
|
|
227
|
+
lastError: z.string().optional(),
|
|
228
|
+
resultCommentID: z.number().int().positive().optional(),
|
|
229
|
+
events: z.array(JobEventSchema).max(50).default([]),
|
|
230
|
+
})
|
|
231
|
+
export type Job = z.infer<typeof JobSchema>
|
|
232
|
+
|
|
233
|
+
export const SettingsSchema = z.object({
|
|
234
|
+
enabledOverride: z.boolean().optional(),
|
|
235
|
+
paused: z.boolean().default(false),
|
|
236
|
+
updatedAt: z.number().int().nonnegative(),
|
|
237
|
+
updatedBy: z.string(),
|
|
238
|
+
})
|
|
239
|
+
export type Settings = z.infer<typeof SettingsSchema>
|
|
240
|
+
|
|
241
|
+
export const ControlRequestSchema = z.object({
|
|
242
|
+
id: z.string().min(1),
|
|
243
|
+
action: z.enum([
|
|
244
|
+
"dispatch",
|
|
245
|
+
"cancel",
|
|
246
|
+
"retry",
|
|
247
|
+
"cleanup_workspace",
|
|
248
|
+
"pause_workflow",
|
|
249
|
+
"resume_workflow",
|
|
250
|
+
]),
|
|
251
|
+
jobID: z.string().optional(),
|
|
252
|
+
at: z.number().int().nonnegative(),
|
|
253
|
+
requestedBy: z.string(),
|
|
254
|
+
})
|
|
255
|
+
export type ControlRequest = z.infer<typeof ControlRequestSchema>
|
|
256
|
+
|
|
257
|
+
export const JobViewSchema = z.object({
|
|
258
|
+
jobID: z.string(),
|
|
259
|
+
task: JobTaskSchema,
|
|
260
|
+
status: JobStatusSchema,
|
|
261
|
+
revision: z.number().int().nonnegative(),
|
|
262
|
+
attempts: z.number().int().nonnegative(),
|
|
263
|
+
feedbackIterations: z.number().int().nonnegative(),
|
|
264
|
+
execution: ExecutionModeSchema,
|
|
265
|
+
branch: z.string().nullable(),
|
|
266
|
+
commitSHA: z.string().nullable(),
|
|
267
|
+
pullRequestURL: z.string().nullable(),
|
|
268
|
+
pullRequestNumber: z.number().int().positive().nullable(),
|
|
269
|
+
publication: PublicationSchema.nullable(),
|
|
270
|
+
sessionID: z.string().nullable(),
|
|
271
|
+
runID: z.string().nullable(),
|
|
272
|
+
gate: GateSchema.nullable(),
|
|
273
|
+
pendingDecision: PendingDecisionSchema.nullable(),
|
|
274
|
+
blocker: BlockerSchema.nullable(),
|
|
275
|
+
labels: z.array(z.string()),
|
|
276
|
+
createdAt: z.number().int().nonnegative(),
|
|
277
|
+
updatedAt: z.number().int().nonnegative(),
|
|
278
|
+
startedAt: z.number().int().nonnegative().nullable(),
|
|
279
|
+
completedAt: z.number().int().nonnegative().nullable(),
|
|
280
|
+
lastError: z.string().nullable(),
|
|
281
|
+
})
|
|
282
|
+
export type JobView = z.infer<typeof JobViewSchema>
|
|
283
|
+
|
|
284
|
+
export const SchedulerViewSchema = z.object({
|
|
285
|
+
enabled: z.boolean(),
|
|
286
|
+
paused: z.boolean(),
|
|
287
|
+
leader: z.boolean(),
|
|
288
|
+
concurrency: z.number().int().positive(),
|
|
289
|
+
running: z.number().int().nonnegative(),
|
|
290
|
+
globalUsed: z.number().int().nonnegative(),
|
|
291
|
+
globalLimit: z.number().int().positive(),
|
|
292
|
+
globalAmbiguous: z.number().int().nonnegative(),
|
|
293
|
+
pollIntervalSeconds: z.number().int().positive(),
|
|
294
|
+
lastPollAt: z.number().int().nonnegative().nullable(),
|
|
295
|
+
lastError: z.string().nullable(),
|
|
296
|
+
})
|
|
297
|
+
export type SchedulerView = z.infer<typeof SchedulerViewSchema>
|
|
298
|
+
|
|
299
|
+
export const TaskfeedSnapshotSchema = z.object({
|
|
300
|
+
plugin: z.object({ name: z.string(), version: z.string() }),
|
|
301
|
+
project: z.object({ id: z.string(), canonical: z.string(), directory: z.string() }),
|
|
302
|
+
config: z.object({
|
|
303
|
+
status: z.enum(["valid", "missing", "invalid"]),
|
|
304
|
+
path: z.string(),
|
|
305
|
+
repository: z.string().nullable(),
|
|
306
|
+
execution: ExecutionModeSchema.nullable(),
|
|
307
|
+
error: z.string().nullable(),
|
|
308
|
+
}),
|
|
309
|
+
scheduler: SchedulerViewSchema,
|
|
310
|
+
jobs: z.array(JobViewSchema),
|
|
311
|
+
warnings: z.array(z.string()),
|
|
312
|
+
})
|
|
313
|
+
export type TaskfeedSnapshot = z.infer<typeof TaskfeedSnapshotSchema>
|
|
314
|
+
|
|
315
|
+
export interface IssueComment {
|
|
316
|
+
readonly id: number
|
|
317
|
+
readonly author: string
|
|
318
|
+
readonly body: string
|
|
319
|
+
readonly createdAt: string
|
|
320
|
+
readonly updatedAt: string
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export interface LinkedPullRequest {
|
|
324
|
+
readonly number: number
|
|
325
|
+
readonly url: string
|
|
326
|
+
readonly state: "open" | "closed" | "merged"
|
|
327
|
+
readonly headSHA?: string
|
|
328
|
+
readonly draft?: boolean
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export interface PullRequestInfo extends LinkedPullRequest {
|
|
332
|
+
readonly headSHA: string
|
|
333
|
+
readonly draft: boolean
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export interface IssueContext {
|
|
337
|
+
readonly repository: string
|
|
338
|
+
readonly number: number
|
|
339
|
+
readonly title: string
|
|
340
|
+
readonly url: string
|
|
341
|
+
readonly body: string
|
|
342
|
+
readonly labels: readonly string[]
|
|
343
|
+
readonly updatedAt: string
|
|
344
|
+
readonly comments: readonly IssueComment[]
|
|
345
|
+
readonly linkedPullRequests: readonly LinkedPullRequest[]
|
|
346
|
+
readonly bodyHash: string
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export interface IssueTask extends IssueContext {
|
|
350
|
+
readonly enqueuedBy: string
|
|
351
|
+
readonly enqueuedAt: number
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export interface IssueSummary {
|
|
355
|
+
readonly repository: string
|
|
356
|
+
readonly number: number
|
|
357
|
+
readonly title: string
|
|
358
|
+
readonly url: string
|
|
359
|
+
readonly updatedAt: string
|
|
360
|
+
readonly labels: readonly string[]
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export interface DecisionComment {
|
|
364
|
+
readonly id: number
|
|
365
|
+
readonly author: string
|
|
366
|
+
readonly body: string
|
|
367
|
+
readonly createdAt: string
|
|
368
|
+
readonly updatedAt: string
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export interface PublishedComment {
|
|
372
|
+
readonly commentID: number
|
|
373
|
+
readonly url?: string
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export interface ExternalGate {
|
|
377
|
+
readonly kind: "native_review" | "workflow_human"
|
|
378
|
+
readonly artifact?: ReviewArtifact
|
|
379
|
+
readonly providerRevision?: number
|
|
380
|
+
readonly nodeID?: string
|
|
381
|
+
readonly outcomes?: readonly string[]
|
|
382
|
+
readonly commitSHA?: string
|
|
383
|
+
readonly summary: string
|
|
384
|
+
readonly evidence: readonly ExecutionEvidence[]
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export interface ExecutionEvidence {
|
|
388
|
+
readonly kind: "file" | "command" | "url" | "note" | "commit"
|
|
389
|
+
readonly value: string
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export interface ExecutionObservation {
|
|
393
|
+
readonly state:
|
|
394
|
+
| "starting"
|
|
395
|
+
| "running"
|
|
396
|
+
| "paused"
|
|
397
|
+
| "awaiting_approval"
|
|
398
|
+
| "completed"
|
|
399
|
+
| "failed"
|
|
400
|
+
| "interrupted"
|
|
401
|
+
| "blocked"
|
|
402
|
+
| "cancelled"
|
|
403
|
+
| "unknown"
|
|
404
|
+
readonly sessionID?: string
|
|
405
|
+
readonly rootSessionID?: string
|
|
406
|
+
readonly runID?: string
|
|
407
|
+
readonly runRevision?: number
|
|
408
|
+
readonly gate?: ExternalGate
|
|
409
|
+
readonly summary?: string
|
|
410
|
+
readonly evidence?: readonly ExecutionEvidence[]
|
|
411
|
+
readonly error?: { code: string; message: string; action?: string }
|
|
412
|
+
readonly pendingPermission?: { requestID: string; action: string; resources: readonly string[] }
|
|
413
|
+
readonly usage?: {
|
|
414
|
+
input?: number
|
|
415
|
+
output?: number
|
|
416
|
+
costUSD?: number
|
|
417
|
+
source?: string
|
|
418
|
+
enforced?: boolean
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
export interface PublicationResult {
|
|
423
|
+
readonly status: "published" | "disabled" | "failed" | "local_only"
|
|
424
|
+
readonly branch?: string
|
|
425
|
+
readonly remote?: string
|
|
426
|
+
readonly pullRequestNumber?: number
|
|
427
|
+
readonly pullRequestURL?: string
|
|
428
|
+
readonly headSHA?: string
|
|
429
|
+
readonly error?: string
|
|
430
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { OpenCode } from "@opencode/client"
|
|
2
|
+
import { Service } from "@opencode/client/service"
|
|
3
|
+
import type { RpcClient } from "@opencode/client/promise"
|
|
4
|
+
import { FlowgraphRpc, type FlowgraphRpcDefinition } from "./rpc.js"
|
|
5
|
+
|
|
6
|
+
export type FlowgraphClient = RpcClient<FlowgraphRpcDefinition>
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The plugin context RPC is pinned to its own location. Flowgraph must be
|
|
10
|
+
* invoked at the worktree location, so use the public client and the local
|
|
11
|
+
* OpenCode service registration. This never starts a new service.
|
|
12
|
+
*/
|
|
13
|
+
export async function createFlowgraphClient(openCodeVersion: string): Promise<FlowgraphClient> {
|
|
14
|
+
const endpoint = await Service.discover({
|
|
15
|
+
version: (value) => value === openCodeVersion || value.startsWith(`${openCodeVersion.split(".")[0]}.`),
|
|
16
|
+
})
|
|
17
|
+
if (!endpoint) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
"Flowgraph location routing requires a discoverable OpenCode service registration; the embedded/standalone server has no public location-preserving RPC endpoint",
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
const client = OpenCode.make({
|
|
23
|
+
baseUrl: endpoint.url,
|
|
24
|
+
headers: Service.headers(endpoint),
|
|
25
|
+
})
|
|
26
|
+
return client.rpc(FlowgraphRpc)
|
|
27
|
+
}
|