@markjaquith/agency 3.4.2 → 3.5.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/package.json +1 -1
- package/src/cli-parser.ts +2 -2
- package/src/commands/sync.ts +4 -3
- package/src/services/SyncService.ts +57 -13
package/package.json
CHANGED
package/src/cli-parser.ts
CHANGED
|
@@ -665,14 +665,14 @@ const commands = {
|
|
|
665
665
|
},
|
|
666
666
|
},
|
|
667
667
|
sync: {
|
|
668
|
-
usage: "agency sync [<task-id> [phase-id]] [--dry-run] [--json]",
|
|
668
|
+
usage: "agency sync [<task-id|path> [phase-id]] [--dry-run] [--json]",
|
|
669
669
|
options: {
|
|
670
670
|
...outputOptions,
|
|
671
671
|
...entitySelectorOptions,
|
|
672
672
|
"dry-run": { type: "boolean" },
|
|
673
673
|
},
|
|
674
674
|
command: {
|
|
675
|
-
usage: "agency sync [<task-id> [phase-id]] [--dry-run] [--json]",
|
|
675
|
+
usage: "agency sync [<task-id|path> [phase-id]] [--dry-run] [--json]",
|
|
676
676
|
minArgs: 0,
|
|
677
677
|
maxArgs: 2,
|
|
678
678
|
options: ["dry-run", "json", "task", "phase"],
|
package/src/commands/sync.ts
CHANGED
|
@@ -122,13 +122,14 @@ export const sync = (
|
|
|
122
122
|
})
|
|
123
123
|
|
|
124
124
|
export const help = `
|
|
125
|
-
Usage: agency sync [<task-id> [phase-id]] [--dry-run] [--json]
|
|
125
|
+
Usage: agency sync [<task-id|path> [phase-id]] [--dry-run] [--json]
|
|
126
126
|
|
|
127
127
|
Compare portable repository declarations and execution state with local Git
|
|
128
128
|
repositories, worktrees, branches, references, and pull requests.
|
|
129
129
|
Safe reconciliation transitions are applied by default.
|
|
130
|
-
When a task or
|
|
131
|
-
queried or reconciled. Task
|
|
130
|
+
When a task, phase, or item path is provided, only that target and its
|
|
131
|
+
repositories are queried or reconciled. Task and epic scopes include their
|
|
132
|
+
child execution units.
|
|
132
133
|
|
|
133
134
|
Options:
|
|
134
135
|
--dry-run Report planned safe transitions without changing state
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Data, Effect, Either } from "effect"
|
|
2
|
-
import { dirname, join, resolve } from "node:path"
|
|
2
|
+
import { dirname, join, relative, resolve, sep } from "node:path"
|
|
3
3
|
import type {
|
|
4
4
|
PhaseFrontmatter,
|
|
5
5
|
RepositoryReference,
|
|
@@ -228,7 +228,17 @@ export class SyncService extends Effect.Service<SyncService>()("SyncService", {
|
|
|
228
228
|
const worktrees = yield* WorktreeService
|
|
229
229
|
const repositories = yield* RepositoryService
|
|
230
230
|
const versionControl = yield* VersionControlService
|
|
231
|
-
const
|
|
231
|
+
const cwd = resolve(options.cwd ?? process.cwd())
|
|
232
|
+
const candidate = options.taskId
|
|
233
|
+
? resolve(cwd, options.taskId)
|
|
234
|
+
: undefined
|
|
235
|
+
const candidateExists =
|
|
236
|
+
candidate !== undefined && !options.phaseId
|
|
237
|
+
? yield* fs.exists(candidate)
|
|
238
|
+
: false
|
|
239
|
+
const { root, config } = yield* workbase.loadConfig(
|
|
240
|
+
candidateExists ? candidate : cwd,
|
|
241
|
+
)
|
|
232
242
|
const backend = yield* versionControl.forWorkbase(root)
|
|
233
243
|
const validation = yield* workbase.validate(root, {
|
|
234
244
|
includeDocuments: true,
|
|
@@ -246,20 +256,49 @@ export class SyncService extends Effect.Service<SyncService>()("SyncService", {
|
|
|
246
256
|
})
|
|
247
257
|
}
|
|
248
258
|
const documents = validation.documents!
|
|
259
|
+
let taskId = options.taskId
|
|
260
|
+
let phaseId = options.phaseId
|
|
261
|
+
let epicId: string | undefined
|
|
262
|
+
const existingTaskSelector =
|
|
263
|
+
options.taskId !== undefined &&
|
|
264
|
+
documents.tasks.some((task) => task.id === options.taskId)
|
|
265
|
+
if (candidateExists && candidate && !existingTaskSelector) {
|
|
266
|
+
const canonicalPath = yield* fs.realPath(candidate)
|
|
267
|
+
const canonicalRoot = yield* fs.realPath(root)
|
|
268
|
+
const parts = relative(canonicalRoot, canonicalPath).split(sep)
|
|
269
|
+
if (parts[0] === "epics" && parts[1]) {
|
|
270
|
+
epicId = parts[1]
|
|
271
|
+
taskId = undefined
|
|
272
|
+
} else if (parts[0] === "tasks" && parts[1]) {
|
|
273
|
+
taskId = parts[1]
|
|
274
|
+
phaseId = parts[2] === "phases" && parts[3] ? parts[3] : undefined
|
|
275
|
+
} else {
|
|
276
|
+
return yield* new SyncError({
|
|
277
|
+
message: `Sync path does not identify an active task, phase, or epic: ${canonicalPath}`,
|
|
278
|
+
})
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (epicId && !documents.epics.some((epic) => epic.id === epicId)) {
|
|
282
|
+
return yield* new SyncError({
|
|
283
|
+
message: `Epic '${epicId}' does not exist`,
|
|
284
|
+
})
|
|
285
|
+
}
|
|
249
286
|
const allTaskRecords = documents.tasks
|
|
250
|
-
const taskRecords =
|
|
251
|
-
? allTaskRecords.filter((task) => task.id ===
|
|
252
|
-
:
|
|
253
|
-
|
|
287
|
+
const taskRecords = taskId
|
|
288
|
+
? allTaskRecords.filter((task) => task.id === taskId)
|
|
289
|
+
: epicId
|
|
290
|
+
? allTaskRecords.filter((task) => task.data.epic === epicId)
|
|
291
|
+
: allTaskRecords
|
|
292
|
+
if (taskId && taskRecords.length === 0) {
|
|
254
293
|
return yield* new SyncError({
|
|
255
|
-
message: `Task '${
|
|
294
|
+
message: `Task '${taskId}' does not exist`,
|
|
256
295
|
})
|
|
257
296
|
}
|
|
258
297
|
const records: ExecutionRecord[] = []
|
|
259
298
|
for (const task of taskRecords) {
|
|
260
299
|
if ("phases" in task.data) {
|
|
261
300
|
for (const phase of documents.phasesByTask.get(task.id) ?? []) {
|
|
262
|
-
if (
|
|
301
|
+
if (phaseId && phase.id !== phaseId) continue
|
|
263
302
|
records.push({
|
|
264
303
|
key: `phase:${task.id}/${phase.id}`,
|
|
265
304
|
taskId: task.id,
|
|
@@ -270,7 +309,7 @@ export class SyncService extends Effect.Service<SyncService>()("SyncService", {
|
|
|
270
309
|
data: phase.data,
|
|
271
310
|
})
|
|
272
311
|
}
|
|
273
|
-
} else if (!
|
|
312
|
+
} else if (!phaseId && !("review" in task.data)) {
|
|
274
313
|
records.push({
|
|
275
314
|
key: `task:${task.id}`,
|
|
276
315
|
taskId: task.id,
|
|
@@ -281,12 +320,12 @@ export class SyncService extends Effect.Service<SyncService>()("SyncService", {
|
|
|
281
320
|
})
|
|
282
321
|
}
|
|
283
322
|
}
|
|
284
|
-
const reviewRecords =
|
|
323
|
+
const reviewRecords = phaseId
|
|
285
324
|
? []
|
|
286
325
|
: taskRecords.filter((task) => "review" in task.data)
|
|
287
|
-
if (
|
|
326
|
+
if (phaseId && records.length === 0) {
|
|
288
327
|
return yield* new SyncError({
|
|
289
|
-
message: `Phase '${
|
|
328
|
+
message: `Phase '${taskId}/${phaseId}' does not exist`,
|
|
290
329
|
})
|
|
291
330
|
}
|
|
292
331
|
const repositoryAliases = new Set<string>()
|
|
@@ -299,10 +338,15 @@ export class SyncService extends Effect.Service<SyncService>()("SyncService", {
|
|
|
299
338
|
if ("review" in task.data)
|
|
300
339
|
repositoryAliases.add(task.data.review.repo)
|
|
301
340
|
}
|
|
341
|
+
if (epicId) {
|
|
342
|
+
const epic = documents.epics.find((record) => record.id === epicId)!
|
|
343
|
+
for (const reference of epic.data.repos)
|
|
344
|
+
repositoryAliases.add(reference.repo)
|
|
345
|
+
}
|
|
302
346
|
const repositorySetup = yield* repositories.setup({
|
|
303
347
|
cwd: root,
|
|
304
348
|
apply: options.apply === true,
|
|
305
|
-
...(
|
|
349
|
+
...(taskId || epicId ? { aliases: [...repositoryAliases] } : {}),
|
|
306
350
|
})
|
|
307
351
|
options.onProgress?.({
|
|
308
352
|
stage: "repositories",
|