@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.
- package/README.md +50 -4
- package/cli.ts +53 -2
- package/index.ts +1 -0
- package/package.json +4 -1
- package/schemas/agency-graph-v1.schema.json +519 -0
- package/skills/agency/SKILL.md +6 -0
- package/src/cli-parser.test.ts +55 -0
- package/src/cli-parser.ts +73 -0
- package/src/cli.test.ts +84 -1
- package/src/commands/context.test.ts +379 -0
- package/src/commands/context.ts +29 -0
- package/src/commands/graph.ts +103 -0
- package/src/commands/read-only.test.ts +10 -0
- package/src/graph-schema.test.ts +61 -0
- package/src/graph-schema.ts +255 -0
- package/src/protocol.ts +11 -0
- package/src/services/ContextService.ts +898 -0
- package/src/services/GraphService.test.ts +277 -0
- package/src/services/GraphService.ts +886 -0
- package/src/test-utils.ts +4 -0
package/src/cli.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { afterEach, describe, expect, test } from "bun:test"
|
|
2
|
-
import { access, realpath } from "node:fs/promises"
|
|
2
|
+
import { access, mkdir, realpath } from "node:fs/promises"
|
|
3
3
|
import { join } from "node:path"
|
|
4
4
|
import { cleanupTempDir, createTempDir } from "./test-utils"
|
|
5
5
|
|
|
@@ -158,6 +158,8 @@ describe("CLI", () => {
|
|
|
158
158
|
["pr", "Usage: agency pr"],
|
|
159
159
|
["status", "Usage: agency status"],
|
|
160
160
|
["validate", "Usage: agency validate"],
|
|
161
|
+
["context", "Usage: agency context"],
|
|
162
|
+
["graph", "Usage: agency graph"],
|
|
161
163
|
] as const) {
|
|
162
164
|
const result = await runCli([command, "--help"])
|
|
163
165
|
expect(result.exitCode).toBe(0)
|
|
@@ -220,6 +222,69 @@ describe("CLI", () => {
|
|
|
220
222
|
).toEqual([await realpath(root)])
|
|
221
223
|
})
|
|
222
224
|
|
|
225
|
+
test("exports equivalent JSON and JSONL graph contracts", async () => {
|
|
226
|
+
const root = await createTempDir()
|
|
227
|
+
tempDirs.push(root)
|
|
228
|
+
expect((await runCli(["init", root])).exitCode).toBe(0)
|
|
229
|
+
await mkdir(join(root, "repos/agency"), { recursive: true })
|
|
230
|
+
await mkdir(join(root, "tasks/example"), { recursive: true })
|
|
231
|
+
await Bun.write(
|
|
232
|
+
join(root, "tasks/example/TASK.md"),
|
|
233
|
+
`---
|
|
234
|
+
ticketUrl: null
|
|
235
|
+
repo: agency
|
|
236
|
+
branch: feat/example
|
|
237
|
+
base: main
|
|
238
|
+
pr: null
|
|
239
|
+
status: open
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
# Example
|
|
243
|
+
`,
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
const json = parseJson(
|
|
247
|
+
await runCli(
|
|
248
|
+
["graph", "--json", "--include", "bodies", "--kind", "task"],
|
|
249
|
+
root,
|
|
250
|
+
),
|
|
251
|
+
)
|
|
252
|
+
expect(json).toMatchObject({
|
|
253
|
+
version: 1,
|
|
254
|
+
includes: ["bodies"],
|
|
255
|
+
nodes: [
|
|
256
|
+
{ id: "task:example", body: expect.stringContaining("# Example") },
|
|
257
|
+
],
|
|
258
|
+
edges: [],
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
const streamed = await runCli(
|
|
262
|
+
["graph", "--jsonl", "--include", "bodies", "--kind", "task"],
|
|
263
|
+
root,
|
|
264
|
+
)
|
|
265
|
+
expect(streamed.exitCode).toBe(0)
|
|
266
|
+
expect(streamed.stderr).toBe("")
|
|
267
|
+
const records = streamed.stdout
|
|
268
|
+
.trim()
|
|
269
|
+
.split("\n")
|
|
270
|
+
.map((line) => JSON.parse(line))
|
|
271
|
+
expect(records.map((record) => record.type)).toEqual([
|
|
272
|
+
"meta",
|
|
273
|
+
"node",
|
|
274
|
+
"end",
|
|
275
|
+
])
|
|
276
|
+
const reconstructed = {
|
|
277
|
+
...records[0].graph,
|
|
278
|
+
nodes: records
|
|
279
|
+
.filter((record) => record.type === "node")
|
|
280
|
+
.map((record) => record.node),
|
|
281
|
+
edges: records
|
|
282
|
+
.filter((record) => record.type === "edge")
|
|
283
|
+
.map((record) => record.edge),
|
|
284
|
+
}
|
|
285
|
+
expect(reconstructed).toEqual(json)
|
|
286
|
+
})
|
|
287
|
+
|
|
223
288
|
test("lets JSON override silent and disables interactive task input", async () => {
|
|
224
289
|
const root = await createTempDir()
|
|
225
290
|
tempDirs.push(root)
|
|
@@ -242,6 +307,24 @@ describe("CLI", () => {
|
|
|
242
307
|
|
|
243
308
|
const version = await runCli(["status", "--version", "--json"])
|
|
244
309
|
expect(parseJson(version)).toEqual({ version: "0.0.0-development" })
|
|
310
|
+
|
|
311
|
+
const jsonlHelp = await runCli(["graph", "--help", "--jsonl"])
|
|
312
|
+
expect(parseJson(jsonlHelp)).toContain("Usage: agency graph")
|
|
313
|
+
|
|
314
|
+
const invalidJsonl = await runCli([
|
|
315
|
+
"graph",
|
|
316
|
+
"--jsonl",
|
|
317
|
+
"--include",
|
|
318
|
+
"secrets",
|
|
319
|
+
])
|
|
320
|
+
expect(invalidJsonl.exitCode).toBe(1)
|
|
321
|
+
expect(invalidJsonl.stderr).toBe("")
|
|
322
|
+
expect(invalidJsonl.stdout.trim().split("\n")).toHaveLength(1)
|
|
323
|
+
expect(JSON.parse(invalidJsonl.stdout)).toMatchObject({
|
|
324
|
+
version: 1,
|
|
325
|
+
ok: false,
|
|
326
|
+
error: { code: "CLI_USAGE" },
|
|
327
|
+
})
|
|
245
328
|
})
|
|
246
329
|
|
|
247
330
|
test("runs a multi-phase domain workflow through subprocesses", async () => {
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test"
|
|
2
|
+
import { mkdir, rm } from "node:fs/promises"
|
|
3
|
+
import { dirname, join } from "node:path"
|
|
4
|
+
import {
|
|
5
|
+
captureLogs,
|
|
6
|
+
cleanupTempDir,
|
|
7
|
+
createTempDir,
|
|
8
|
+
runTestEffect,
|
|
9
|
+
} from "../test-utils"
|
|
10
|
+
import { context } from "./context"
|
|
11
|
+
|
|
12
|
+
const write = async (root: string, path: string, content: string) => {
|
|
13
|
+
const fullPath = join(root, path)
|
|
14
|
+
await mkdir(dirname(fullPath), { recursive: true })
|
|
15
|
+
await Bun.write(fullPath, content)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const run = async (cwd: string, args: string[]) => {
|
|
19
|
+
const process = Bun.spawn(args, { cwd, stdout: "pipe", stderr: "pipe" })
|
|
20
|
+
const [exitCode, stderr] = await Promise.all([
|
|
21
|
+
process.exited,
|
|
22
|
+
new Response(process.stderr).text(),
|
|
23
|
+
])
|
|
24
|
+
if (exitCode !== 0) throw new Error(`${args.join(" ")}: ${stderr}`)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const readContext = async (
|
|
28
|
+
root: string,
|
|
29
|
+
target: string | undefined,
|
|
30
|
+
compact = false,
|
|
31
|
+
) => {
|
|
32
|
+
const logs = await captureLogs(() =>
|
|
33
|
+
runTestEffect(context({ cwd: root, target, compact, json: true })),
|
|
34
|
+
)
|
|
35
|
+
expect(logs).toHaveLength(1)
|
|
36
|
+
return JSON.parse(logs[0]!)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe("context", () => {
|
|
40
|
+
let root: string
|
|
41
|
+
|
|
42
|
+
beforeEach(async () => {
|
|
43
|
+
root = await createTempDir()
|
|
44
|
+
await write(root, "agency.json", '{"version":2}\n')
|
|
45
|
+
for (const repo of ["agency", "docs"]) {
|
|
46
|
+
const path = join(root, "repos", repo)
|
|
47
|
+
await mkdir(path, { recursive: true })
|
|
48
|
+
await run(root, ["git", "init", "--initial-branch=main", path])
|
|
49
|
+
await run(path, ["git", "config", "user.email", "test@example.com"])
|
|
50
|
+
await run(path, ["git", "config", "user.name", "Test"])
|
|
51
|
+
await Bun.write(join(path, "README.md"), `${repo}\n`)
|
|
52
|
+
await run(path, ["git", "add", "README.md"])
|
|
53
|
+
await run(path, ["git", "commit", "-m", "initial"])
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
await write(
|
|
57
|
+
root,
|
|
58
|
+
"epics/contract/EPIC.md",
|
|
59
|
+
`---
|
|
60
|
+
ticketUrl: https://example.com/contract
|
|
61
|
+
repos:
|
|
62
|
+
- repo: agency
|
|
63
|
+
ref: main
|
|
64
|
+
tasks:
|
|
65
|
+
- id: foundations
|
|
66
|
+
- id: agent-contract
|
|
67
|
+
dependsOn: [foundations]
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
# Contract
|
|
71
|
+
`,
|
|
72
|
+
)
|
|
73
|
+
await write(
|
|
74
|
+
root,
|
|
75
|
+
"tasks/foundations/TASK.md",
|
|
76
|
+
`---
|
|
77
|
+
ticketUrl: null
|
|
78
|
+
epic: contract
|
|
79
|
+
repo: agency
|
|
80
|
+
branch: foundations
|
|
81
|
+
base: main
|
|
82
|
+
pr: https://github.com/example/agency/pull/1
|
|
83
|
+
status: done
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
# Foundations
|
|
87
|
+
`,
|
|
88
|
+
)
|
|
89
|
+
await write(
|
|
90
|
+
root,
|
|
91
|
+
"tasks/agent-contract/TASK.md",
|
|
92
|
+
`---
|
|
93
|
+
ticketUrl: null
|
|
94
|
+
epic: contract
|
|
95
|
+
phases:
|
|
96
|
+
- id: schema
|
|
97
|
+
- id: context-command
|
|
98
|
+
dependsOn: [schema]
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
# Agent contract
|
|
102
|
+
Task prose.
|
|
103
|
+
`,
|
|
104
|
+
)
|
|
105
|
+
await write(
|
|
106
|
+
root,
|
|
107
|
+
"tasks/agent-contract/phases/schema/PHASE.md",
|
|
108
|
+
`---
|
|
109
|
+
repo: agency
|
|
110
|
+
branch: schema
|
|
111
|
+
base: main
|
|
112
|
+
pr: https://github.com/example/agency/pull/2
|
|
113
|
+
status: done
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
# Schema
|
|
117
|
+
`,
|
|
118
|
+
)
|
|
119
|
+
await write(
|
|
120
|
+
root,
|
|
121
|
+
"tasks/agent-contract/phases/context-command/PHASE.md",
|
|
122
|
+
`---
|
|
123
|
+
repo: agency
|
|
124
|
+
repos:
|
|
125
|
+
- repo: docs
|
|
126
|
+
ref: main
|
|
127
|
+
branch: feat/context
|
|
128
|
+
base: main
|
|
129
|
+
pr: null
|
|
130
|
+
status: open
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
# Context command
|
|
134
|
+
Phase prose.
|
|
135
|
+
`,
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
const code = join(root, "tasks/agent-contract/phases/context-command/code")
|
|
139
|
+
await mkdir(code, { recursive: true })
|
|
140
|
+
await run(join(root, "repos/agency"), [
|
|
141
|
+
"git",
|
|
142
|
+
"worktree",
|
|
143
|
+
"add",
|
|
144
|
+
"-b",
|
|
145
|
+
"feat/context",
|
|
146
|
+
join(code, "agency"),
|
|
147
|
+
"main",
|
|
148
|
+
])
|
|
149
|
+
await run(join(root, "repos/docs"), [
|
|
150
|
+
"git",
|
|
151
|
+
"worktree",
|
|
152
|
+
"add",
|
|
153
|
+
"--detach",
|
|
154
|
+
join(code, "docs"),
|
|
155
|
+
"main",
|
|
156
|
+
])
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
afterEach(async () => {
|
|
160
|
+
await cleanupTempDir(root)
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
test("returns complete phase context with graph, authority, Git, and validation state", async () => {
|
|
164
|
+
const target = "tasks/agent-contract/phases/context-command"
|
|
165
|
+
const result = await readContext(root, target)
|
|
166
|
+
|
|
167
|
+
expect(result).toMatchObject({
|
|
168
|
+
projection: "complete",
|
|
169
|
+
workbase: { root, version: 2 },
|
|
170
|
+
target: {
|
|
171
|
+
kind: "phase",
|
|
172
|
+
taskId: "agent-contract",
|
|
173
|
+
phaseId: "context-command",
|
|
174
|
+
},
|
|
175
|
+
graph: {
|
|
176
|
+
parent: { kind: "task", id: "agent-contract" },
|
|
177
|
+
dependencies: ["schema"],
|
|
178
|
+
readiness: { ready: true, blocked: false, blockers: [] },
|
|
179
|
+
aggregate: { status: "open", total: 1, open: 1 },
|
|
180
|
+
},
|
|
181
|
+
authority: {
|
|
182
|
+
mode: "execution",
|
|
183
|
+
writable: { repo: "agency", branch: "feat/context", base: "main" },
|
|
184
|
+
references: [{ repo: "docs", ref: "main" }],
|
|
185
|
+
},
|
|
186
|
+
workspace: {
|
|
187
|
+
materialization: "complete",
|
|
188
|
+
writable: {
|
|
189
|
+
materialized: true,
|
|
190
|
+
registered: true,
|
|
191
|
+
checkoutBranch: "feat/context",
|
|
192
|
+
detached: false,
|
|
193
|
+
},
|
|
194
|
+
references: [
|
|
195
|
+
{
|
|
196
|
+
repo: "docs",
|
|
197
|
+
materialized: true,
|
|
198
|
+
registered: true,
|
|
199
|
+
detached: true,
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
},
|
|
203
|
+
pr: { url: null, state: "none" },
|
|
204
|
+
validation: { valid: true, warnings: [] },
|
|
205
|
+
})
|
|
206
|
+
expect(result.documents.epic.body).toContain("# Contract")
|
|
207
|
+
expect(result.documents.task.body).toContain("Task prose.")
|
|
208
|
+
expect(result.documents.phase.body).toContain("Phase prose.")
|
|
209
|
+
expect(result.documents.phase.sha256).toMatch(/^[a-f0-9]{64}$/)
|
|
210
|
+
expect(result.workspace.writable.branchCommit).toMatch(/^[a-f0-9]{40}$/)
|
|
211
|
+
expect(result.workspace.writable.baseCommit).toMatch(/^[a-f0-9]{40}$/)
|
|
212
|
+
expect(result.workspace.references[0].resolvedCommit).toMatch(
|
|
213
|
+
/^[a-f0-9]{40}$/,
|
|
214
|
+
)
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
test("makes compact projection explicit without omitting essential identity", async () => {
|
|
218
|
+
const result = await readContext(
|
|
219
|
+
root,
|
|
220
|
+
"tasks/agent-contract/phases/context-command/code/agency",
|
|
221
|
+
true,
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
expect(result.projection).toBe("compact")
|
|
225
|
+
expect(result.target.kind).toBe("phase")
|
|
226
|
+
expect(result.documents.phase.body).toBeUndefined()
|
|
227
|
+
expect(result.documents.phase.data.branch).toBe("feat/context")
|
|
228
|
+
expect(result.documents.phase.sha256).toMatch(/^[a-f0-9]{64}$/)
|
|
229
|
+
expect(result.workspace.writable).toEqual({
|
|
230
|
+
materialized: true,
|
|
231
|
+
registered: true,
|
|
232
|
+
})
|
|
233
|
+
expect(result.authority.writable.checkoutPath).toContain("code/agency")
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
test("reports dependency and validation blockers deterministically", async () => {
|
|
237
|
+
await write(
|
|
238
|
+
root,
|
|
239
|
+
"tasks/agent-contract/phases/schema/PHASE.md",
|
|
240
|
+
`---
|
|
241
|
+
repo: missing
|
|
242
|
+
branch: schema
|
|
243
|
+
base: main
|
|
244
|
+
pr: null
|
|
245
|
+
status: dropped
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
# Schema
|
|
249
|
+
`,
|
|
250
|
+
)
|
|
251
|
+
const result = await readContext(
|
|
252
|
+
root,
|
|
253
|
+
"tasks/agent-contract/phases/context-command",
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
expect(result.graph.readiness.ready).toBe(false)
|
|
257
|
+
expect(result.graph.readiness.blockers).toContainEqual({
|
|
258
|
+
kind: "dependency",
|
|
259
|
+
id: "schema",
|
|
260
|
+
status: "dropped",
|
|
261
|
+
reason: "Phase dependency is dropped",
|
|
262
|
+
})
|
|
263
|
+
expect(result.validation.valid).toBe(false)
|
|
264
|
+
expect(result.validation.warnings).toContainEqual({
|
|
265
|
+
path: "tasks/agent-contract/phases/schema/PHASE.md",
|
|
266
|
+
message: "Unknown repository alias 'missing'",
|
|
267
|
+
})
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
test("resolves a bare task ID and rejects a root target", async () => {
|
|
271
|
+
const task = await readContext(root, "agent-contract")
|
|
272
|
+
expect(task.target).toMatchObject({
|
|
273
|
+
kind: "task",
|
|
274
|
+
taskId: "agent-contract",
|
|
275
|
+
})
|
|
276
|
+
expect(task.graph.parent).toEqual({ kind: "epic", id: "contract" })
|
|
277
|
+
|
|
278
|
+
await expect(readContext(root, ".")).rejects.toThrow(
|
|
279
|
+
"Cannot infer an Agency target",
|
|
280
|
+
)
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
test("resolves bare task IDs from inside another target", async () => {
|
|
284
|
+
const cwd = join(
|
|
285
|
+
root,
|
|
286
|
+
"tasks/agent-contract/phases/context-command/code/agency",
|
|
287
|
+
)
|
|
288
|
+
const logs = await captureLogs(() =>
|
|
289
|
+
runTestEffect(context({ cwd, target: "foundations", json: true })),
|
|
290
|
+
)
|
|
291
|
+
const result = JSON.parse(logs[0]!)
|
|
292
|
+
expect(result.target).toMatchObject({ kind: "task", taskId: "foundations" })
|
|
293
|
+
expect(result.authority.writable.branch).toBe("foundations")
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
test("computes orchestration readiness from runnable descendants", async () => {
|
|
297
|
+
await write(
|
|
298
|
+
root,
|
|
299
|
+
"tasks/agent-contract/TASK.md",
|
|
300
|
+
`---
|
|
301
|
+
ticketUrl: null
|
|
302
|
+
epic: contract
|
|
303
|
+
phases:
|
|
304
|
+
- id: schema
|
|
305
|
+
- id: context-command
|
|
306
|
+
dependsOn: [schema]
|
|
307
|
+
- id: parallel
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
# Agent contract
|
|
311
|
+
`,
|
|
312
|
+
)
|
|
313
|
+
await write(
|
|
314
|
+
root,
|
|
315
|
+
"tasks/agent-contract/phases/schema/PHASE.md",
|
|
316
|
+
`---
|
|
317
|
+
repo: agency
|
|
318
|
+
branch: schema
|
|
319
|
+
base: main
|
|
320
|
+
pr: null
|
|
321
|
+
status: working
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
# Schema
|
|
325
|
+
`,
|
|
326
|
+
)
|
|
327
|
+
await write(
|
|
328
|
+
root,
|
|
329
|
+
"tasks/agent-contract/phases/parallel/PHASE.md",
|
|
330
|
+
`---
|
|
331
|
+
repo: docs
|
|
332
|
+
branch: parallel
|
|
333
|
+
base: main
|
|
334
|
+
pr: null
|
|
335
|
+
status: open
|
|
336
|
+
---
|
|
337
|
+
|
|
338
|
+
# Parallel
|
|
339
|
+
`,
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
const task = await readContext(root, "agent-contract")
|
|
343
|
+
expect(task.graph.readiness).toMatchObject({ ready: true, blocked: false })
|
|
344
|
+
expect(task.graph.aggregate).toMatchObject({
|
|
345
|
+
status: "working",
|
|
346
|
+
total: 3,
|
|
347
|
+
open: 2,
|
|
348
|
+
working: 1,
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
const epic = await readContext(root, "epics/contract")
|
|
352
|
+
expect(epic.graph.readiness).toMatchObject({ ready: true, blocked: false })
|
|
353
|
+
expect(epic.graph.aggregate).toMatchObject({
|
|
354
|
+
status: "working",
|
|
355
|
+
total: 4,
|
|
356
|
+
done: 1,
|
|
357
|
+
open: 2,
|
|
358
|
+
working: 1,
|
|
359
|
+
})
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
test("reports stale worktree registration independently of materialization", async () => {
|
|
363
|
+
const checkout = join(
|
|
364
|
+
root,
|
|
365
|
+
"tasks/agent-contract/phases/context-command/code/agency",
|
|
366
|
+
)
|
|
367
|
+
await rm(checkout, { recursive: true, force: true })
|
|
368
|
+
|
|
369
|
+
const result = await readContext(
|
|
370
|
+
root,
|
|
371
|
+
"tasks/agent-contract/phases/context-command",
|
|
372
|
+
)
|
|
373
|
+
expect(result.workspace.writable).toMatchObject({
|
|
374
|
+
materialized: false,
|
|
375
|
+
registered: true,
|
|
376
|
+
})
|
|
377
|
+
expect(result.workspace.materialization).toBe("partial")
|
|
378
|
+
})
|
|
379
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Effect } from "effect"
|
|
2
|
+
import type { BaseCommandOptions } from "../utils/command"
|
|
3
|
+
import { ContextService } from "../services/ContextService"
|
|
4
|
+
import { createLoggers } from "../utils/effect"
|
|
5
|
+
|
|
6
|
+
interface ContextOptions extends BaseCommandOptions {
|
|
7
|
+
readonly target?: string
|
|
8
|
+
readonly compact?: boolean
|
|
9
|
+
readonly json?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const context = (options: ContextOptions = {}) =>
|
|
13
|
+
Effect.gen(function* () {
|
|
14
|
+
const service = yield* ContextService
|
|
15
|
+
const { log } = createLoggers(options)
|
|
16
|
+
const result = yield* service.get(options)
|
|
17
|
+
log(JSON.stringify(result, null, 2))
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
export const help = `
|
|
21
|
+
Usage: agency context [target] [options]
|
|
22
|
+
|
|
23
|
+
Return the complete, read-only context for an epic, task, or phase. The target
|
|
24
|
+
defaults to the current directory and may be an entity path or task ID.
|
|
25
|
+
|
|
26
|
+
Options:
|
|
27
|
+
--json Output a versioned machine result
|
|
28
|
+
--compact Omit prose bodies and low-level Git details
|
|
29
|
+
`
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Effect } from "effect"
|
|
2
|
+
import {
|
|
3
|
+
graphJsonlRecords,
|
|
4
|
+
type GraphInclude,
|
|
5
|
+
type GraphNodeKind,
|
|
6
|
+
} from "../graph-schema"
|
|
7
|
+
import { GraphService } from "../services/GraphService"
|
|
8
|
+
import type { WorkStatus } from "../workbase/schemas"
|
|
9
|
+
import type { BaseCommandOptions } from "../utils/command"
|
|
10
|
+
import { createLoggers } from "../utils/effect"
|
|
11
|
+
|
|
12
|
+
interface GraphCommandOptions extends BaseCommandOptions {
|
|
13
|
+
readonly json?: boolean
|
|
14
|
+
readonly jsonl?: boolean
|
|
15
|
+
readonly ready?: boolean
|
|
16
|
+
readonly blocked?: boolean
|
|
17
|
+
readonly statuses?: readonly string[]
|
|
18
|
+
readonly repositories?: readonly string[]
|
|
19
|
+
readonly kinds?: readonly string[]
|
|
20
|
+
readonly include?: readonly string[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const allowedStatuses = new Set<WorkStatus>([
|
|
24
|
+
"open",
|
|
25
|
+
"working",
|
|
26
|
+
"delegated",
|
|
27
|
+
"done",
|
|
28
|
+
"dropped",
|
|
29
|
+
])
|
|
30
|
+
const allowedKinds = new Set<GraphNodeKind>([
|
|
31
|
+
"epic",
|
|
32
|
+
"task",
|
|
33
|
+
"phase",
|
|
34
|
+
"repository",
|
|
35
|
+
"execution-unit",
|
|
36
|
+
])
|
|
37
|
+
const allowedIncludes = new Set<GraphInclude>([
|
|
38
|
+
"bodies",
|
|
39
|
+
"workspace",
|
|
40
|
+
"git",
|
|
41
|
+
"pr",
|
|
42
|
+
])
|
|
43
|
+
|
|
44
|
+
const validated = <T extends string>(
|
|
45
|
+
label: string,
|
|
46
|
+
values: readonly string[] | undefined,
|
|
47
|
+
allowed: ReadonlySet<T>,
|
|
48
|
+
): T[] =>
|
|
49
|
+
(values ?? []).map((value) => {
|
|
50
|
+
if (!allowed.has(value as T)) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`Invalid --${label} value '${value}'. Expected one of: ${[...allowed].join(", ")}`,
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
return value as T
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
export const graph = (options: GraphCommandOptions = {}) =>
|
|
59
|
+
Effect.gen(function* () {
|
|
60
|
+
const service = yield* GraphService
|
|
61
|
+
const { log } = createLoggers(options)
|
|
62
|
+
const statuses = yield* Effect.sync(() =>
|
|
63
|
+
validated("status", options.statuses, allowedStatuses),
|
|
64
|
+
)
|
|
65
|
+
const kinds = yield* Effect.sync(() =>
|
|
66
|
+
validated("kind", options.kinds, allowedKinds),
|
|
67
|
+
)
|
|
68
|
+
const include = yield* Effect.sync(() =>
|
|
69
|
+
validated("include", options.include, allowedIncludes),
|
|
70
|
+
)
|
|
71
|
+
const result = yield* service.get({
|
|
72
|
+
cwd: options.cwd,
|
|
73
|
+
ready: options.ready,
|
|
74
|
+
blocked: options.blocked,
|
|
75
|
+
statuses,
|
|
76
|
+
repositories: options.repositories,
|
|
77
|
+
kinds,
|
|
78
|
+
include,
|
|
79
|
+
})
|
|
80
|
+
if (options.jsonl) {
|
|
81
|
+
for (const record of graphJsonlRecords(result)) {
|
|
82
|
+
process.stdout.write(`${JSON.stringify(record)}\n`)
|
|
83
|
+
}
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
log(JSON.stringify(result, null, 2))
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
export const help = `
|
|
90
|
+
Usage: agency graph [options]
|
|
91
|
+
|
|
92
|
+
Export the workbase as a deterministic, versioned graph.
|
|
93
|
+
|
|
94
|
+
Options:
|
|
95
|
+
--json Output one versioned machine result
|
|
96
|
+
--jsonl Stream versioned graph records
|
|
97
|
+
--ready Include only ready nodes
|
|
98
|
+
--blocked Include only blocked nodes
|
|
99
|
+
--status <status> Filter by status (repeatable)
|
|
100
|
+
--repository <alias> Filter by repository (repeatable)
|
|
101
|
+
--kind <kind> Filter by entity kind (repeatable)
|
|
102
|
+
--include <layer> Include bodies, workspace, git, or pr (repeatable)
|
|
103
|
+
`
|
|
@@ -11,6 +11,8 @@ import { repo } from "./repo"
|
|
|
11
11
|
import { status } from "./status"
|
|
12
12
|
import { task } from "./task"
|
|
13
13
|
import { validate } from "./validate"
|
|
14
|
+
import { context } from "./context"
|
|
15
|
+
import { graph } from "./graph"
|
|
14
16
|
|
|
15
17
|
const write = async (root: string, path: string, content: string) => {
|
|
16
18
|
const fullPath = join(root, path)
|
|
@@ -135,6 +137,14 @@ status: open
|
|
|
135
137
|
)
|
|
136
138
|
await runTestEffect(status({ cwd: root, silent: true }))
|
|
137
139
|
await runTestEffect(validate({ path: root, silent: true }))
|
|
140
|
+
await runTestEffect(
|
|
141
|
+
context({
|
|
142
|
+
target: "tasks/example-task/phases/implementation",
|
|
143
|
+
cwd: root,
|
|
144
|
+
silent: true,
|
|
145
|
+
}),
|
|
146
|
+
)
|
|
147
|
+
await runTestEffect(graph({ cwd: root, silent: true }))
|
|
138
148
|
|
|
139
149
|
expect(await Bun.file(join(root, "AGENTS.md")).exists()).toBe(false)
|
|
140
150
|
expect(
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import jsonSchema from "../schemas/agency-graph-v1.schema.json"
|
|
3
|
+
import { graphJsonlRecords, type AgencyGraph } from "./graph-schema"
|
|
4
|
+
|
|
5
|
+
describe("graph contract", () => {
|
|
6
|
+
test("publishes the v1 JSON Schema", () => {
|
|
7
|
+
expect(jsonSchema).toMatchObject({
|
|
8
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
9
|
+
title: "Agency workbase graph v1",
|
|
10
|
+
properties: { version: { const: 1 } },
|
|
11
|
+
})
|
|
12
|
+
expect(jsonSchema.properties.filters).toMatchObject({
|
|
13
|
+
additionalProperties: false,
|
|
14
|
+
required: ["ready", "blocked", "statuses", "repositories", "kinds"],
|
|
15
|
+
})
|
|
16
|
+
expect(jsonSchema.$defs.node.allOf).toHaveLength(5)
|
|
17
|
+
expect(jsonSchema.$defs.node.allOf[3]?.then?.properties).toMatchObject({
|
|
18
|
+
status: { type: "null" },
|
|
19
|
+
readiness: { type: "null" },
|
|
20
|
+
aggregate: { type: "null" },
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test("streams records that reconstruct graph semantics", () => {
|
|
25
|
+
const graph = {
|
|
26
|
+
version: 1,
|
|
27
|
+
workbase: { version: 2 },
|
|
28
|
+
filters: {
|
|
29
|
+
ready: null,
|
|
30
|
+
blocked: null,
|
|
31
|
+
statuses: [],
|
|
32
|
+
repositories: [],
|
|
33
|
+
kinds: [],
|
|
34
|
+
},
|
|
35
|
+
includes: [],
|
|
36
|
+
nodes: [],
|
|
37
|
+
edges: [],
|
|
38
|
+
summary: {
|
|
39
|
+
status: "open",
|
|
40
|
+
total: 0,
|
|
41
|
+
open: 0,
|
|
42
|
+
working: 0,
|
|
43
|
+
delegated: 0,
|
|
44
|
+
done: 0,
|
|
45
|
+
dropped: 0,
|
|
46
|
+
terminal: 0,
|
|
47
|
+
},
|
|
48
|
+
validation: { valid: true, issues: [] },
|
|
49
|
+
} satisfies AgencyGraph
|
|
50
|
+
const records = [...graphJsonlRecords(graph)]
|
|
51
|
+
const { nodes: _nodes, edges: _edges, ...metadata } = graph
|
|
52
|
+
expect(records).toEqual([
|
|
53
|
+
{
|
|
54
|
+
version: 1,
|
|
55
|
+
type: "meta",
|
|
56
|
+
graph: metadata,
|
|
57
|
+
},
|
|
58
|
+
{ version: 1, type: "end", nodeCount: 0, edgeCount: 0 },
|
|
59
|
+
])
|
|
60
|
+
})
|
|
61
|
+
})
|