@markjaquith/agency 2.52.0 → 2.52.2

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.
@@ -6,10 +6,37 @@ const managedHeaderPattern =
6
6
  const checksum = (content: string) =>
7
7
  createHash("sha256").update(content).digest("hex")
8
8
 
9
- const body = `import { existsSync } from "node:fs"
10
- import { join, sep } from "node:path"
9
+ const body = `import { existsSync, readFileSync } from "node:fs"
10
+ import { dirname, join, sep } from "node:path"
11
11
  import type { Plugin } from "@opencode-ai/plugin"
12
12
 
13
+ const discoverWorkbase = (directory: string) => {
14
+ let current = directory
15
+ while (true) {
16
+ if (existsSync(join(current, "agency.json"))) return current
17
+ const parent = dirname(current)
18
+ if (parent === current) return
19
+ current = parent
20
+ }
21
+ }
22
+
23
+ const discoverCheckout = (directory: string, root: string | undefined) => {
24
+ if (!root) return
25
+ let current = directory
26
+ while (current.startsWith(root)) {
27
+ for (const name of ["PHASE.md", "TASK.md"]) {
28
+ const document = join(current, name)
29
+ if (!existsSync(document)) continue
30
+ const repo = readFileSync(document, "utf8").match(/^repo:\\s*([^\\s]+)\\s*$/m)?.[1]
31
+ if (!repo) return
32
+ const checkout = join(current, "code", repo.replace(/^['\"]|['\"]$/g, ""))
33
+ return existsSync(checkout) ? checkout : undefined
34
+ }
35
+ if (current === root) return
36
+ current = dirname(current)
37
+ }
38
+ }
39
+
13
40
  const agencyContext = async (directory: string) => {
14
41
  const task = process.env.AGENCY_TASK_ID
15
42
  const phase = process.env.AGENCY_PHASE_ID
@@ -30,8 +57,8 @@ const agencyContext = async (directory: string) => {
30
57
  const plugin: Plugin = async ({ directory }) => ({
31
58
  config: async (config) => {
32
59
  const context = await agencyContext(directory).catch(() => undefined)
33
- const root = process.env.AGENCY_WORKBASE ?? context?.root
34
- const checkout = process.env.AGENCY_WRITABLE_CHECKOUT ?? context?.checkout
60
+ const root = process.env.AGENCY_WORKBASE ?? context?.root ?? discoverWorkbase(directory)
61
+ const checkout = process.env.AGENCY_WRITABLE_CHECKOUT ?? context?.checkout ?? discoverCheckout(directory, root)
35
62
 
36
63
  const reference = config.references?.workbase
37
64
  if (