@markjaquith/agency 2.63.0 → 2.64.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 +7 -6
- package/cli-main.ts +2 -1
- package/package.json +1 -1
- package/src/cli-parser.test.ts +4 -1
- package/src/cli-parser.ts +4 -4
- package/src/commands/act.test.ts +95 -0
- package/src/commands/act.ts +89 -8
- package/src/services/IntegrationService.test.ts +70 -21
- package/src/workbase/opencode-plugin-file.ts +6 -1
package/README.md
CHANGED
|
@@ -517,12 +517,13 @@ pull request, dropping, reopening, or archiving. Cancelling either chooser makes
|
|
|
517
517
|
no changes, and the command refreshes the graph before dispatch so a stale
|
|
518
518
|
selection cannot act on changed work.
|
|
519
519
|
|
|
520
|
-
Use `--epic <id>`, `--task <id>`,
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
520
|
+
Use an existing directory, a positional task ID, `--epic <id>`, `--task <id>`,
|
|
521
|
+
or `--task <id> --phase <id>` to skip work-item selection. For example,
|
|
522
|
+
`agency act .` selects the current task or phase. `--dry-run` still prompts for
|
|
523
|
+
an action but prints the exact Agency command instead of executing it. `--json`
|
|
524
|
+
never prompts or executes; it returns matching targets, status and readiness
|
|
525
|
+
details, document revisions, and each available action's command argv. With no
|
|
526
|
+
selector, JSON includes every active work item.
|
|
526
527
|
|
|
527
528
|
`--auto` is included in generated or executed work commands, and `--draft` is
|
|
528
529
|
included in generated or executed pull request commands.
|
package/cli-main.ts
CHANGED
|
@@ -177,10 +177,11 @@ const VERSION = packageJson.version
|
|
|
177
177
|
// Define commands
|
|
178
178
|
const commands: Record<string, Command> = {
|
|
179
179
|
act: {
|
|
180
|
-
run: async (
|
|
180
|
+
run: async (args: string[], options: Record<string, any>) => {
|
|
181
181
|
if (options.help) return console.log(actHelp)
|
|
182
182
|
await runCommand(
|
|
183
183
|
act({
|
|
184
|
+
directory: args[0],
|
|
184
185
|
auto: options.auto,
|
|
185
186
|
draft: options.draft,
|
|
186
187
|
dryRun: options["dry-run"],
|
package/package.json
CHANGED
package/src/cli-parser.test.ts
CHANGED
|
@@ -31,7 +31,10 @@ describe("strict CLI parsing", () => {
|
|
|
31
31
|
},
|
|
32
32
|
})
|
|
33
33
|
expect(parseCli(["act", "--json"]).values.json).toBe(true)
|
|
34
|
-
|
|
34
|
+
expect(parseCli(["act", "task-id"]).args).toEqual(["task-id"])
|
|
35
|
+
expect(parseCli(["act", "."]).args).toEqual(["."])
|
|
36
|
+
expectUsageError(["act", "one", "two"], "agency act")
|
|
37
|
+
expectUsageError(["act", ".", "--task", "example"], "agency act")
|
|
35
38
|
expectUsageError(["act", "--phase", "build"], "agency act")
|
|
36
39
|
expectUsageError(
|
|
37
40
|
["act", "--epic", "roadmap", "--task", "example"],
|
package/src/cli-parser.ts
CHANGED
|
@@ -148,7 +148,7 @@ const commands = {
|
|
|
148
148
|
},
|
|
149
149
|
act: {
|
|
150
150
|
usage:
|
|
151
|
-
"agency act [--epic <id> | --task <id> [--phase <id>]] [--dry-run | --json] [--auto] [--draft]",
|
|
151
|
+
"agency act [<directory-or-task-id> | --epic <id> | --task <id> [--phase <id>]] [--dry-run | --json] [--auto] [--draft]",
|
|
152
152
|
options: {
|
|
153
153
|
...outputOptions,
|
|
154
154
|
...entitySelectorOptions,
|
|
@@ -158,9 +158,9 @@ const commands = {
|
|
|
158
158
|
},
|
|
159
159
|
command: {
|
|
160
160
|
usage:
|
|
161
|
-
"agency act [--epic <id> | --task <id> [--phase <id>]] [--dry-run | --json] [--auto] [--draft]",
|
|
161
|
+
"agency act [<directory-or-task-id> | --epic <id> | --task <id> [--phase <id>]] [--dry-run | --json] [--auto] [--draft]",
|
|
162
162
|
minArgs: 0,
|
|
163
|
-
maxArgs:
|
|
163
|
+
maxArgs: 1,
|
|
164
164
|
options: ["epic", "task", "phase", "dry-run", "json", "auto", "draft"],
|
|
165
165
|
conflicts: [
|
|
166
166
|
["dry-run", "json"],
|
|
@@ -1198,7 +1198,7 @@ function applyEntitySelectors(
|
|
|
1198
1198
|
spec.usage,
|
|
1199
1199
|
)
|
|
1200
1200
|
}
|
|
1201
|
-
if (
|
|
1201
|
+
if (["act", "work", "context"].includes(commandName)) {
|
|
1202
1202
|
if (
|
|
1203
1203
|
positionals.length >
|
|
1204
1204
|
(commandName === "work" && positionals[0] === "prepare" ? 1 : 0)
|
package/src/commands/act.test.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, test } from "bun:test"
|
|
2
2
|
import { Effect } from "effect"
|
|
3
|
+
import { mkdir } from "node:fs/promises"
|
|
3
4
|
import { join } from "node:path"
|
|
4
5
|
import {
|
|
5
6
|
captureLogs,
|
|
@@ -118,6 +119,100 @@ describe("act command", () => {
|
|
|
118
119
|
expect(await readTaskStatus("example")).toBe("open")
|
|
119
120
|
})
|
|
120
121
|
|
|
122
|
+
test("resolves a positional path and task ID without prompting for an item", async () => {
|
|
123
|
+
await createTask("example")
|
|
124
|
+
await mkdir(join(root, "tasks/example/code/agency"), { recursive: true })
|
|
125
|
+
for (const options of [
|
|
126
|
+
{ cwd: join(root, "tasks/example"), directory: "." },
|
|
127
|
+
{ cwd: join(root, "tasks/example"), directory: "code/agency" },
|
|
128
|
+
{ cwd: root, directory: "example" },
|
|
129
|
+
]) {
|
|
130
|
+
const prompts: string[] = []
|
|
131
|
+
await runTestEffect(
|
|
132
|
+
act(
|
|
133
|
+
{ ...options, inputAllowed: true, dryRun: true, silent: true },
|
|
134
|
+
scriptedInteraction(["drop"], (prompt) => prompts.push(prompt)),
|
|
135
|
+
),
|
|
136
|
+
)
|
|
137
|
+
expect(prompts).toEqual(["Act on task example"])
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test("resolves a positional phase path without prompting for an item", async () => {
|
|
142
|
+
await runTestEffect(
|
|
143
|
+
task({
|
|
144
|
+
subcommand: "create",
|
|
145
|
+
args: ["multi"],
|
|
146
|
+
multiPhase: true,
|
|
147
|
+
cwd: root,
|
|
148
|
+
silent: true,
|
|
149
|
+
}),
|
|
150
|
+
)
|
|
151
|
+
await runTestEffect(
|
|
152
|
+
phase({
|
|
153
|
+
subcommand: "create",
|
|
154
|
+
args: ["multi", "build"],
|
|
155
|
+
repo: "agency",
|
|
156
|
+
branch: "task/multi-build",
|
|
157
|
+
base: "main",
|
|
158
|
+
cwd: root,
|
|
159
|
+
silent: true,
|
|
160
|
+
}),
|
|
161
|
+
)
|
|
162
|
+
const prompts: string[] = []
|
|
163
|
+
await runTestEffect(
|
|
164
|
+
act(
|
|
165
|
+
{
|
|
166
|
+
cwd: join(root, "tasks/multi/phases/build"),
|
|
167
|
+
directory: ".",
|
|
168
|
+
inputAllowed: true,
|
|
169
|
+
dryRun: true,
|
|
170
|
+
silent: true,
|
|
171
|
+
},
|
|
172
|
+
scriptedInteraction(["drop"], (prompt) => prompts.push(prompt)),
|
|
173
|
+
),
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
expect(prompts).toEqual(["Act on phase multi/build"])
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
test("orders owned items hierarchically and omits items without actions", async () => {
|
|
180
|
+
await runTestEffect(
|
|
181
|
+
task({
|
|
182
|
+
subcommand: "create",
|
|
183
|
+
args: ["multi"],
|
|
184
|
+
multiPhase: true,
|
|
185
|
+
cwd: root,
|
|
186
|
+
silent: true,
|
|
187
|
+
}),
|
|
188
|
+
)
|
|
189
|
+
await runTestEffect(
|
|
190
|
+
phase({
|
|
191
|
+
subcommand: "create",
|
|
192
|
+
args: ["multi", "build"],
|
|
193
|
+
repo: "agency",
|
|
194
|
+
branch: "task/multi-build",
|
|
195
|
+
base: "main",
|
|
196
|
+
cwd: root,
|
|
197
|
+
silent: true,
|
|
198
|
+
}),
|
|
199
|
+
)
|
|
200
|
+
let choices: readonly Choice<unknown>[] = []
|
|
201
|
+
await runTestEffect(
|
|
202
|
+
act(
|
|
203
|
+
{ cwd: root, inputAllowed: true },
|
|
204
|
+
scriptedInteraction([null], (_prompt, offered) => {
|
|
205
|
+
choices = offered
|
|
206
|
+
}),
|
|
207
|
+
),
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
expect(choices.map((choice) => [choice.value, choice.depth])).toEqual([
|
|
211
|
+
["task:multi", 0],
|
|
212
|
+
["phase:multi/build", 1],
|
|
213
|
+
])
|
|
214
|
+
})
|
|
215
|
+
|
|
121
216
|
test("returns structured actions and argv for agents", async () => {
|
|
122
217
|
await createTask("example")
|
|
123
218
|
const logs = await captureLogs(() =>
|
package/src/commands/act.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Effect } from "effect"
|
|
2
|
+
import { isAbsolute, relative, resolve, sep } from "node:path"
|
|
2
3
|
import type { GraphNode } from "../graph-schema"
|
|
3
4
|
import { isTerminalStatus } from "../readiness"
|
|
5
|
+
import { FileSystemService } from "../services/FileSystemService"
|
|
4
6
|
import { GraphService } from "../services/GraphService"
|
|
5
7
|
import { WorkbaseService } from "../services/WorkbaseService"
|
|
6
8
|
import type { BaseCommandOptions } from "../utils/command"
|
|
@@ -29,6 +31,7 @@ export interface ActInteraction {
|
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
interface ActOptions extends BaseCommandOptions {
|
|
34
|
+
readonly directory?: string
|
|
32
35
|
readonly auto?: boolean
|
|
33
36
|
readonly draft?: boolean
|
|
34
37
|
readonly dryRun?: boolean
|
|
@@ -49,13 +52,49 @@ const entityDescription = (node: EntityNode) =>
|
|
|
49
52
|
? ` - ${node.data.description}`
|
|
50
53
|
: ""
|
|
51
54
|
|
|
55
|
+
const orderedEntities = (
|
|
56
|
+
nodes: readonly EntityNode[],
|
|
57
|
+
edges: readonly {
|
|
58
|
+
readonly kind: string
|
|
59
|
+
readonly from: string
|
|
60
|
+
readonly to: string
|
|
61
|
+
}[],
|
|
62
|
+
) => {
|
|
63
|
+
const byId = new Map(nodes.map((node) => [node.id, node]))
|
|
64
|
+
const children = new Map<string, EntityNode[]>()
|
|
65
|
+
const owned = new Set<string>()
|
|
66
|
+
for (const edge of edges) {
|
|
67
|
+
if (edge.kind !== "owns") continue
|
|
68
|
+
const parent = byId.get(edge.from)
|
|
69
|
+
const child = byId.get(edge.to)
|
|
70
|
+
if (!parent || !child) continue
|
|
71
|
+
children.set(edge.from, [...(children.get(edge.from) ?? []), child])
|
|
72
|
+
owned.add(child.id)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const ordered: { readonly node: EntityNode; readonly depth: number }[] = []
|
|
76
|
+
const append = (node: EntityNode, depth: number) => {
|
|
77
|
+
ordered.push({ node, depth })
|
|
78
|
+
for (const child of children.get(node.id) ?? []) append(child, depth + 1)
|
|
79
|
+
}
|
|
80
|
+
for (const node of nodes) {
|
|
81
|
+
if (!owned.has(node.id)) append(node, 0)
|
|
82
|
+
}
|
|
83
|
+
return ordered
|
|
84
|
+
}
|
|
85
|
+
|
|
52
86
|
const entityChoices = (
|
|
53
87
|
nodes: readonly EntityNode[],
|
|
88
|
+
edges: readonly {
|
|
89
|
+
readonly kind: string
|
|
90
|
+
readonly from: string
|
|
91
|
+
readonly to: string
|
|
92
|
+
}[],
|
|
54
93
|
): readonly Choice<string>[] =>
|
|
55
|
-
nodes.map((node, index) => ({
|
|
94
|
+
orderedEntities(nodes, edges).map(({ node, depth }, index) => ({
|
|
56
95
|
key: String(index),
|
|
57
96
|
label: `[${node.status}] ${node.kind} ${node.key}${entityDescription(node)}`,
|
|
58
|
-
depth
|
|
97
|
+
depth,
|
|
59
98
|
segments: [
|
|
60
99
|
{ text: `[${node.status}] `, color: macchiato.overlay1 },
|
|
61
100
|
{ text: `${node.kind} `, color: macchiato.sapphire },
|
|
@@ -229,6 +268,26 @@ const selectedEntityKey = (options: ActOptions) =>
|
|
|
229
268
|
? `task:${options.taskId}`
|
|
230
269
|
: undefined
|
|
231
270
|
|
|
271
|
+
const pathEntityKey = (
|
|
272
|
+
directory: string | undefined,
|
|
273
|
+
isDirectory: boolean,
|
|
274
|
+
root: string,
|
|
275
|
+
startPath: string,
|
|
276
|
+
) => {
|
|
277
|
+
if (!directory) return undefined
|
|
278
|
+
if (!isDirectory) return `task:${directory}`
|
|
279
|
+
const path = relative(root, startPath)
|
|
280
|
+
const parts =
|
|
281
|
+
!path || isAbsolute(path) || path.startsWith(`..${sep}`)
|
|
282
|
+
? []
|
|
283
|
+
: path.split(sep)
|
|
284
|
+
if (parts[0] === "epics" && parts[1]) return `epic:${parts[1]}`
|
|
285
|
+
if (parts[0] !== "tasks" || !parts[1]) return undefined
|
|
286
|
+
return parts[2] === "phases" && parts[3]
|
|
287
|
+
? `phase:${parts[1]}/${parts[3]}`
|
|
288
|
+
: `task:${parts[1]}`
|
|
289
|
+
}
|
|
290
|
+
|
|
232
291
|
const sameActions = (
|
|
233
292
|
left: readonly Choice<ActAction>[],
|
|
234
293
|
right: readonly Choice<ActAction>[],
|
|
@@ -250,11 +309,19 @@ export const act = (
|
|
|
250
309
|
)
|
|
251
310
|
}
|
|
252
311
|
const cwd = options.cwd ?? process.cwd()
|
|
312
|
+
const fs = yield* FileSystemService
|
|
253
313
|
const workbase = yield* WorkbaseService
|
|
254
314
|
const graphs = yield* GraphService
|
|
255
315
|
const { log } = createLoggers(options)
|
|
256
|
-
const
|
|
257
|
-
|
|
316
|
+
const directoryPath = options.directory
|
|
317
|
+
? resolve(cwd, options.directory)
|
|
318
|
+
: undefined
|
|
319
|
+
const isDirectory = directoryPath
|
|
320
|
+
? yield* fs.isDirectory(directoryPath)
|
|
321
|
+
: false
|
|
322
|
+
const startPath = isDirectory && directoryPath ? directoryPath : cwd
|
|
323
|
+
const { root, config } = yield* workbase.loadConfig(startPath)
|
|
324
|
+
const graph = yield* graphs.get({ cwd: root })
|
|
258
325
|
const nodes = graph.nodes.filter(
|
|
259
326
|
(node): node is EntityNode =>
|
|
260
327
|
node.kind === "epic" || node.kind === "task" || node.kind === "phase",
|
|
@@ -269,7 +336,9 @@ export const act = (
|
|
|
269
336
|
)
|
|
270
337
|
}
|
|
271
338
|
|
|
272
|
-
const requestedKey =
|
|
339
|
+
const requestedKey =
|
|
340
|
+
selectedEntityKey(options) ??
|
|
341
|
+
pathEntityKey(options.directory, isDirectory, root, startPath)
|
|
273
342
|
const matchingNodes = requestedKey
|
|
274
343
|
? nodes.filter((node) => entityKey(node) === requestedKey)
|
|
275
344
|
: nodes
|
|
@@ -293,11 +362,21 @@ export const act = (
|
|
|
293
362
|
return
|
|
294
363
|
}
|
|
295
364
|
|
|
365
|
+
const selectableNodes = nodes.filter(
|
|
366
|
+
(node) => actionChoices(node, graph.nodes).length > 0,
|
|
367
|
+
)
|
|
368
|
+
if (!requestedKey && selectableNodes.length === 0) {
|
|
369
|
+
return yield* Effect.fail(
|
|
370
|
+
new Error(
|
|
371
|
+
"No work items with available actions found in this workbase",
|
|
372
|
+
),
|
|
373
|
+
)
|
|
374
|
+
}
|
|
296
375
|
const selectedKey =
|
|
297
376
|
requestedKey ??
|
|
298
377
|
(yield* interaction.select(
|
|
299
378
|
"Act on",
|
|
300
|
-
entityChoices(
|
|
379
|
+
entityChoices(selectableNodes, graph.edges),
|
|
301
380
|
config.chooserCommand,
|
|
302
381
|
))
|
|
303
382
|
if (selectedKey === null) return
|
|
@@ -424,10 +503,12 @@ export const act = (
|
|
|
424
503
|
})
|
|
425
504
|
|
|
426
505
|
export const help = `
|
|
427
|
-
Usage: agency act [--epic <id> | --task <id> [--phase <id>]] [--dry-run | --json] [--auto] [--draft]
|
|
506
|
+
Usage: agency act [<directory-or-task-id> | --epic <id> | --task <id> [--phase <id>]] [--dry-run | --json] [--auto] [--draft]
|
|
428
507
|
|
|
429
508
|
Interactively choose an active work item and a state-aware lifecycle action.
|
|
430
|
-
|
|
509
|
+
An existing positional directory selects its containing epic, task, or phase;
|
|
510
|
+
otherwise the positional value is a task ID. Selectors skip work-item selection.
|
|
511
|
+
--dry-run prints the selected action's exact
|
|
431
512
|
Agency command without executing it. --json lists targets, available actions,
|
|
432
513
|
and command argv without prompting or executing.
|
|
433
514
|
|
|
@@ -174,6 +174,18 @@ describe("IntegrationService", () => {
|
|
|
174
174
|
expect(managedWorkbaseOpencodePlugin).toContain(
|
|
175
175
|
"Do not invoke agency work for this target",
|
|
176
176
|
)
|
|
177
|
+
expect(managedWorkbaseOpencodePlugin).toContain(
|
|
178
|
+
"as the default implementation directory",
|
|
179
|
+
)
|
|
180
|
+
expect(managedWorkbaseOpencodePlugin).toContain(
|
|
181
|
+
"Set each tool's working directory to that checkout when supported",
|
|
182
|
+
)
|
|
183
|
+
expect(managedWorkbaseOpencodePlugin).toContain(
|
|
184
|
+
"Run Agency lifecycle and context commands from the task or phase directory",
|
|
185
|
+
)
|
|
186
|
+
expect(managedWorkbaseOpencodePlugin).toContain(
|
|
187
|
+
"reference checkouts reported by Agency context are read-only",
|
|
188
|
+
)
|
|
177
189
|
expect(managedWorkbaseOpencodePlugin).toContain(
|
|
178
190
|
".map((path) => `${path}${sep}.`)",
|
|
179
191
|
)
|
|
@@ -187,23 +199,39 @@ describe("IntegrationService", () => {
|
|
|
187
199
|
).toBe(false)
|
|
188
200
|
})
|
|
189
201
|
|
|
190
|
-
|
|
202
|
+
const testWorkerIdentity = async ({
|
|
203
|
+
target,
|
|
204
|
+
launchTarget,
|
|
205
|
+
phase,
|
|
206
|
+
}: {
|
|
207
|
+
readonly target:
|
|
208
|
+
| { readonly kind: "task"; readonly taskId: string }
|
|
209
|
+
| {
|
|
210
|
+
readonly kind: "phase"
|
|
211
|
+
readonly taskId: string
|
|
212
|
+
readonly phaseId: string
|
|
213
|
+
}
|
|
214
|
+
readonly launchTarget: string
|
|
215
|
+
readonly phase?: string
|
|
216
|
+
}) => {
|
|
191
217
|
const path = join(root, "agency-repository-skills.ts")
|
|
218
|
+
const checkoutPath = join(root, "code/agency")
|
|
192
219
|
const contextResponse = JSON.stringify({
|
|
193
220
|
version: 1,
|
|
194
221
|
ok: true,
|
|
195
222
|
result: {
|
|
196
223
|
workbase: { root },
|
|
197
224
|
target: {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
path: join(root, "TASK.md"),
|
|
225
|
+
...target,
|
|
226
|
+
path: join(root, phase ? "PHASE.md" : "TASK.md"),
|
|
201
227
|
},
|
|
202
228
|
authority: {
|
|
203
229
|
mode: "execution",
|
|
204
|
-
writable: { checkoutPath
|
|
230
|
+
writable: { checkoutPath },
|
|
205
231
|
},
|
|
206
|
-
documents:
|
|
232
|
+
documents: phase
|
|
233
|
+
? { phase: { data: { status: "working" } } }
|
|
234
|
+
: { task: { data: { status: "working" } } },
|
|
207
235
|
validation: { valid: true, warnings: [] },
|
|
208
236
|
},
|
|
209
237
|
})
|
|
@@ -225,27 +253,28 @@ describe("IntegrationService", () => {
|
|
|
225
253
|
}) as ReturnType<typeof Bun.spawn>) as typeof Bun.spawn
|
|
226
254
|
try {
|
|
227
255
|
const generated = await import(
|
|
228
|
-
`${pathToFileURL(path).href}?worker-identity`
|
|
256
|
+
`${pathToFileURL(path).href}?worker-identity=${encodeURIComponent(launchTarget)}`
|
|
229
257
|
)
|
|
230
258
|
expect(
|
|
231
259
|
generated.workerLaunchTarget([
|
|
232
260
|
{
|
|
233
261
|
type: "text",
|
|
234
|
-
text:
|
|
262
|
+
text: `Agency worker launch target: ${launchTarget}. Start the task.`,
|
|
235
263
|
},
|
|
236
264
|
]),
|
|
237
|
-
).toBe(
|
|
265
|
+
).toBe(launchTarget)
|
|
238
266
|
expect(generated.workerLaunchTarget(undefined)).toBeUndefined()
|
|
239
267
|
expect(
|
|
240
268
|
generated.contextTarget({
|
|
241
|
-
target
|
|
269
|
+
target,
|
|
242
270
|
authority: { mode: "execution" },
|
|
243
271
|
}),
|
|
244
|
-
).toBe(
|
|
272
|
+
).toBe(launchTarget)
|
|
245
273
|
expect(await generated.agencyContext(root)).toMatchObject({
|
|
246
274
|
root,
|
|
247
|
-
target:
|
|
275
|
+
target: launchTarget,
|
|
248
276
|
task: "example",
|
|
277
|
+
phase,
|
|
249
278
|
})
|
|
250
279
|
const hooks = await generated.default({ directory: root } as never)
|
|
251
280
|
await hooks["chat.message"]!(
|
|
@@ -254,7 +283,7 @@ describe("IntegrationService", () => {
|
|
|
254
283
|
parts: [
|
|
255
284
|
{
|
|
256
285
|
type: "text",
|
|
257
|
-
text:
|
|
286
|
+
text: `Agency worker launch target: ${launchTarget}. Start the task.`,
|
|
258
287
|
},
|
|
259
288
|
],
|
|
260
289
|
} as never,
|
|
@@ -276,11 +305,17 @@ describe("IntegrationService", () => {
|
|
|
276
305
|
{ sessionID: "worker-session" } as never,
|
|
277
306
|
system,
|
|
278
307
|
)
|
|
279
|
-
expect(system.system).
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
308
|
+
expect(system.system).toHaveLength(1)
|
|
309
|
+
expect(system.system[0]).toContain(`active worker for ${launchTarget}`)
|
|
310
|
+
expect(system.system[0]).toContain(
|
|
311
|
+
`${checkoutPath} as the default implementation directory`,
|
|
312
|
+
)
|
|
313
|
+
expect(system.system[0]).toContain(
|
|
314
|
+
"Run Agency lifecycle and context commands from the task or phase directory",
|
|
315
|
+
)
|
|
316
|
+
expect(system.system[0]).toContain(
|
|
317
|
+
"reference checkouts reported by Agency context are read-only",
|
|
318
|
+
)
|
|
284
319
|
const mismatchedSystem = { system: [] as string[] }
|
|
285
320
|
await hooks["experimental.chat.system.transform"]!(
|
|
286
321
|
{ sessionID: "mismatched-session" } as never,
|
|
@@ -292,15 +327,29 @@ describe("IntegrationService", () => {
|
|
|
292
327
|
await hooks["shell.env"]!({ sessionID: "worker-session" } as never, shell)
|
|
293
328
|
expect(shell.env).toMatchObject({
|
|
294
329
|
AGENCY_SESSION_ID: "worker-session",
|
|
295
|
-
AGENCY_TARGET:
|
|
330
|
+
AGENCY_TARGET: launchTarget,
|
|
296
331
|
AGENCY_WORKBASE: root,
|
|
297
332
|
AGENCY_TASK_ID: "example",
|
|
298
|
-
AGENCY_WRITABLE_CHECKOUT:
|
|
333
|
+
AGENCY_WRITABLE_CHECKOUT: checkoutPath,
|
|
299
334
|
})
|
|
335
|
+
if (phase) expect(shell.env.AGENCY_PHASE_ID).toBe(phase)
|
|
300
336
|
} finally {
|
|
301
337
|
Bun.spawn = originalSpawn
|
|
302
338
|
}
|
|
303
|
-
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
test("binds validated task worker identity to an OpenCode session", () =>
|
|
342
|
+
testWorkerIdentity({
|
|
343
|
+
target: { kind: "task", taskId: "example" },
|
|
344
|
+
launchTarget: "execution-unit:task/example",
|
|
345
|
+
}))
|
|
346
|
+
|
|
347
|
+
test("binds validated phase worker identity to an OpenCode session", () =>
|
|
348
|
+
testWorkerIdentity({
|
|
349
|
+
target: { kind: "phase", taskId: "example", phaseId: "build" },
|
|
350
|
+
launchTarget: "execution-unit:phase/example/build",
|
|
351
|
+
phase: "build",
|
|
352
|
+
}))
|
|
304
353
|
|
|
305
354
|
test("registers a TUI-only /agency-debug diagnostic", async () => {
|
|
306
355
|
const config = JSON.parse(managedBody(managedWorkbaseOpencodeTui))
|
|
@@ -164,7 +164,12 @@ const plugin: Plugin = async ({ directory }) => {
|
|
|
164
164
|
const context = workerSessions.get(sessionID)
|
|
165
165
|
if (!context?.target) return
|
|
166
166
|
output.system.push(
|
|
167
|
-
|
|
167
|
+
[
|
|
168
|
+
\`Agency verified this OpenCode session as the active worker for \${context.target}. Perform the assigned work directly. Do not invoke agency work for this target or launch a replacement worker.\`,
|
|
169
|
+
context.checkout
|
|
170
|
+
? \`OpenCode remains rooted in the task or phase directory for Agency instructions and context. Treat \${context.checkout} as the default implementation directory: use it for source reads, edits, repository status, builds, tests, formatting, and other repository-local commands. Set each tool's working directory to that checkout when supported; otherwise use absolute paths. Run Agency lifecycle and context commands from the task or phase directory. Any reference checkouts reported by Agency context are read-only.\`
|
|
171
|
+
: undefined,
|
|
172
|
+
].filter(Boolean).join(" "),
|
|
168
173
|
)
|
|
169
174
|
},
|
|
170
175
|
"shell.env": async ({ sessionID }, output) => {
|