@markjaquith/agency 2.9.0 → 2.11.0

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.
@@ -0,0 +1,255 @@
1
+ import { Schema } from "@effect/schema"
2
+ import {
3
+ EpicFrontmatter,
4
+ PhaseFrontmatter,
5
+ TaskFrontmatter,
6
+ WorkStatus,
7
+ } from "./workbase/schemas"
8
+
9
+ export const GRAPH_VERSION = 1 as const
10
+
11
+ export const GraphNodeKind = Schema.Literal(
12
+ "epic",
13
+ "task",
14
+ "phase",
15
+ "repository",
16
+ "execution-unit",
17
+ )
18
+
19
+ export const GraphEdgeKind = Schema.Literal(
20
+ "owns",
21
+ "depends_on",
22
+ "writes",
23
+ "references",
24
+ )
25
+
26
+ export const GraphInclude = Schema.Literal("bodies", "workspace", "git", "pr")
27
+
28
+ export const GraphBlocker = Schema.Struct({
29
+ kind: Schema.Literal("dependency", "validation", "status"),
30
+ id: Schema.String,
31
+ status: Schema.optional(WorkStatus),
32
+ reason: Schema.String,
33
+ })
34
+
35
+ export const GraphProgress = Schema.Struct({
36
+ status: WorkStatus,
37
+ total: Schema.Number,
38
+ open: Schema.Number,
39
+ working: Schema.Number,
40
+ delegated: Schema.Number,
41
+ done: Schema.Number,
42
+ dropped: Schema.Number,
43
+ terminal: Schema.Number,
44
+ })
45
+
46
+ export const GraphReadiness = Schema.Struct({
47
+ ready: Schema.Boolean,
48
+ blocked: Schema.Boolean,
49
+ blockers: Schema.Array(GraphBlocker),
50
+ })
51
+
52
+ export const GraphWorkbase = Schema.Struct({
53
+ version: Schema.Literal(2),
54
+ root: Schema.optional(Schema.String),
55
+ })
56
+
57
+ export const GraphFilters = Schema.Struct({
58
+ ready: Schema.NullOr(Schema.Boolean),
59
+ blocked: Schema.NullOr(Schema.Boolean),
60
+ statuses: Schema.Array(WorkStatus),
61
+ repositories: Schema.Array(Schema.String),
62
+ kinds: Schema.Array(GraphNodeKind),
63
+ })
64
+
65
+ const DocumentHash = Schema.Struct({ sha256: Schema.String })
66
+ export const GraphEpicData = Schema.extend(EpicFrontmatter, DocumentHash)
67
+ export const GraphTaskData = Schema.extend(TaskFrontmatter, DocumentHash)
68
+ export const GraphPhaseData = Schema.extend(PhaseFrontmatter, DocumentHash)
69
+ export const GraphExecutionData = Schema.extend(
70
+ PhaseFrontmatter,
71
+ Schema.Struct({
72
+ taskId: Schema.String,
73
+ phaseId: Schema.optional(Schema.String),
74
+ ticketUrl: Schema.optional(Schema.NullOr(Schema.String)),
75
+ epic: Schema.optional(Schema.String),
76
+ }),
77
+ )
78
+
79
+ export const GraphDocumentWorkspace = Schema.Struct({
80
+ documentPath: Schema.String,
81
+ directory: Schema.String,
82
+ })
83
+ export const GraphRepositoryWorkspace = Schema.Struct({
84
+ path: Schema.String,
85
+ target: Schema.NullOr(Schema.String),
86
+ })
87
+ export const GraphExecutionWorkspace = Schema.Struct({
88
+ codePath: Schema.String,
89
+ checkoutPath: Schema.String,
90
+ materialized: Schema.Boolean,
91
+ })
92
+ export const GraphRepositoryGit = Schema.Struct({
93
+ kind: Schema.NullOr(Schema.Literal("bare", "repository")),
94
+ remote: Schema.NullOr(Schema.String),
95
+ head: Schema.NullOr(Schema.String),
96
+ branch: Schema.NullOr(Schema.String),
97
+ })
98
+ export const GraphExecutionGit = Schema.Struct({
99
+ branch: Schema.String,
100
+ base: Schema.String,
101
+ branchCommit: Schema.NullOr(Schema.String),
102
+ baseCommit: Schema.NullOr(Schema.String),
103
+ checkoutCommit: Schema.NullOr(Schema.String),
104
+ checkoutBranch: Schema.NullOr(Schema.String),
105
+ dirty: Schema.NullOr(Schema.Boolean),
106
+ })
107
+ export const GraphPr = Schema.Union(
108
+ Schema.Struct({ url: Schema.Null, state: Schema.Literal("none") }),
109
+ Schema.Struct({ url: Schema.String, state: Schema.Literal("unavailable") }),
110
+ Schema.Struct({
111
+ recordedUrl: Schema.String,
112
+ number: Schema.Number,
113
+ state: Schema.String,
114
+ title: Schema.String,
115
+ isDraft: Schema.Boolean,
116
+ headRefName: Schema.String,
117
+ baseRefName: Schema.String,
118
+ url: Schema.String,
119
+ }),
120
+ )
121
+
122
+ const NodeIdentity = {
123
+ id: Schema.String,
124
+ key: Schema.String,
125
+ dependents: Schema.Array(Schema.String),
126
+ repositories: Schema.Array(Schema.String),
127
+ }
128
+ const StatefulNode = {
129
+ ...NodeIdentity,
130
+ status: WorkStatus,
131
+ readiness: GraphReadiness,
132
+ aggregate: GraphProgress,
133
+ }
134
+ const DocumentNode = {
135
+ ...StatefulNode,
136
+ body: Schema.optional(Schema.String),
137
+ workspace: Schema.optional(GraphDocumentWorkspace),
138
+ }
139
+
140
+ export const GraphNode = Schema.Union(
141
+ Schema.Struct({
142
+ ...DocumentNode,
143
+ kind: Schema.Literal("epic"),
144
+ data: GraphEpicData,
145
+ }),
146
+ Schema.Struct({
147
+ ...DocumentNode,
148
+ kind: Schema.Literal("task"),
149
+ data: GraphTaskData,
150
+ }),
151
+ Schema.Struct({
152
+ ...DocumentNode,
153
+ kind: Schema.Literal("phase"),
154
+ data: GraphPhaseData,
155
+ }),
156
+ Schema.Struct({
157
+ ...NodeIdentity,
158
+ kind: Schema.Literal("repository"),
159
+ status: Schema.Null,
160
+ readiness: Schema.Null,
161
+ aggregate: Schema.Null,
162
+ data: Schema.Struct({ alias: Schema.String }),
163
+ workspace: Schema.optional(GraphRepositoryWorkspace),
164
+ git: Schema.optional(GraphRepositoryGit),
165
+ }),
166
+ Schema.Struct({
167
+ ...StatefulNode,
168
+ kind: Schema.Literal("execution-unit"),
169
+ data: GraphExecutionData,
170
+ workspace: Schema.optional(GraphExecutionWorkspace),
171
+ git: Schema.optional(GraphExecutionGit),
172
+ pr: Schema.optional(GraphPr),
173
+ }),
174
+ )
175
+
176
+ export const GraphEdge = Schema.Struct({
177
+ id: Schema.String,
178
+ kind: GraphEdgeKind,
179
+ from: Schema.String,
180
+ to: Schema.String,
181
+ })
182
+
183
+ export const AgencyGraph = Schema.Struct({
184
+ version: Schema.Literal(GRAPH_VERSION),
185
+ workbase: GraphWorkbase,
186
+ filters: GraphFilters,
187
+ includes: Schema.Array(GraphInclude),
188
+ nodes: Schema.Array(GraphNode),
189
+ edges: Schema.Array(GraphEdge),
190
+ summary: GraphProgress,
191
+ validation: Schema.Struct({
192
+ valid: Schema.Boolean,
193
+ issues: Schema.Array(
194
+ Schema.Struct({ path: Schema.String, message: Schema.String }),
195
+ ),
196
+ }),
197
+ })
198
+
199
+ export type GraphNodeKind = Schema.Schema.Type<typeof GraphNodeKind>
200
+ export type GraphEdgeKind = Schema.Schema.Type<typeof GraphEdgeKind>
201
+ export type GraphInclude = Schema.Schema.Type<typeof GraphInclude>
202
+ export type GraphBlocker = Schema.Schema.Type<typeof GraphBlocker>
203
+ export type GraphProgress = Schema.Schema.Type<typeof GraphProgress>
204
+ export type GraphReadiness = Schema.Schema.Type<typeof GraphReadiness>
205
+ export type GraphExecutionWorkspace = Schema.Schema.Type<
206
+ typeof GraphExecutionWorkspace
207
+ >
208
+ export type GraphExecutionGit = Schema.Schema.Type<typeof GraphExecutionGit>
209
+ export type GraphRepositoryGit = Schema.Schema.Type<typeof GraphRepositoryGit>
210
+ export type GraphPr = Schema.Schema.Type<typeof GraphPr>
211
+ export type GraphNode = Schema.Schema.Type<typeof GraphNode>
212
+ export type GraphEdge = Schema.Schema.Type<typeof GraphEdge>
213
+ export type AgencyGraph = Schema.Schema.Type<typeof AgencyGraph>
214
+
215
+ export type GraphJsonlRecord =
216
+ | {
217
+ readonly version: typeof GRAPH_VERSION
218
+ readonly type: "meta"
219
+ readonly graph: Omit<AgencyGraph, "nodes" | "edges">
220
+ }
221
+ | {
222
+ readonly version: typeof GRAPH_VERSION
223
+ readonly type: "node"
224
+ readonly node: GraphNode
225
+ }
226
+ | {
227
+ readonly version: typeof GRAPH_VERSION
228
+ readonly type: "edge"
229
+ readonly edge: GraphEdge
230
+ }
231
+ | {
232
+ readonly version: typeof GRAPH_VERSION
233
+ readonly type: "end"
234
+ readonly nodeCount: number
235
+ readonly edgeCount: number
236
+ }
237
+
238
+ export function* graphJsonlRecords(
239
+ graph: AgencyGraph,
240
+ ): Generator<GraphJsonlRecord> {
241
+ const { nodes, edges, ...metadata } = graph
242
+ yield { version: GRAPH_VERSION, type: "meta", graph: metadata }
243
+ for (const node of nodes) {
244
+ yield { version: GRAPH_VERSION, type: "node", node }
245
+ }
246
+ for (const edge of edges) {
247
+ yield { version: GRAPH_VERSION, type: "edge", edge }
248
+ }
249
+ yield {
250
+ version: GRAPH_VERSION,
251
+ type: "end",
252
+ nodeCount: nodes.length,
253
+ edgeCount: edges.length,
254
+ }
255
+ }
package/src/protocol.ts CHANGED
@@ -84,6 +84,17 @@ const errorMetadata: Readonly<Record<string, ErrorMetadata>> = {
84
84
  ArchiveError: { code: "ARCHIVE_ERROR", retryable: false },
85
85
  WorktreeError: { code: "WORKTREE_ERROR", retryable: false },
86
86
  PullRequestError: { code: "PULL_REQUEST_ERROR", retryable: false },
87
+ ContextError: {
88
+ code: "CONTEXT_ERROR",
89
+ retryable: false,
90
+ remediation:
91
+ "Run the command from an Agency entity or provide a valid target.",
92
+ },
93
+ GraphError: {
94
+ code: "GRAPH_ERROR",
95
+ retryable: false,
96
+ remediation: "Correct the workbase graph data or filters and retry.",
97
+ },
87
98
  ProcessError: { code: "PROCESS_ERROR", retryable: true },
88
99
  ProtocolOutputError: {
89
100
  code: "PROTOCOL_OUTPUT_ERROR",