specdojo 0.2.1 → 0.3.1
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/.github/agents/specdojo-orchestrator.md +165 -0
- package/CHANGELOG.md +298 -0
- package/README.md +92 -42
- package/dist/agent-response.js +20 -0
- package/dist/agent.js +4 -4
- package/dist/build-command.js +28 -8
- package/dist/catalog-build-references.js +144 -0
- package/dist/catalog-build-render.js +144 -0
- package/dist/catalog-build.js +13 -290
- package/dist/catalog-generate.js +6 -9
- package/dist/catalog-plan-generate.js +2 -2
- package/dist/catalog-plan.js +6 -6
- package/dist/catalog-scaffold.js +4 -4
- package/dist/catalog.js +2 -2
- package/dist/dashboard-exec-records.js +105 -0
- package/dist/dashboard-routines.js +255 -0
- package/dist/dashboard-shared.js +14 -0
- package/dist/dashboard-timeline.js +175 -0
- package/dist/dashboard.js +31 -444
- package/dist/deliverable-trash.js +3 -3
- package/dist/devcontainer-command.js +43 -0
- package/dist/devcontainer-scaffold.js +165 -0
- package/dist/doc-index.js +3 -3
- package/dist/exec-agent-config.js +107 -9
- package/dist/exec-agent-git-state.js +18 -0
- package/dist/exec-agent-protected-config.js +46 -8
- package/dist/exec-commands.js +557 -0
- package/dist/exec-core.js +457 -0
- package/dist/exec-evidence.js +254 -11
- package/dist/exec-handoff.js +336 -0
- package/dist/exec-parent-validation.js +317 -43
- package/dist/exec-pipeline-state.js +74 -9
- package/dist/exec-plans-core.js +693 -0
- package/dist/exec-plans-generation.js +206 -0
- package/dist/exec-plans-storage.js +131 -0
- package/dist/exec-plans.js +3 -1016
- package/dist/exec-protection-handoff.js +43 -2
- package/dist/exec-provider-scaffold.js +247 -15
- package/dist/exec-register-resume.js +65 -19
- package/dist/exec-register.js +9 -3
- package/dist/exec-repo-integration-git.js +23 -0
- package/dist/exec-repo-integration-sync.js +264 -0
- package/dist/exec-repo-integration.js +534 -0
- package/dist/exec-repo-trace.js +182 -0
- package/dist/exec-reporter-output.js +206 -0
- package/dist/exec-reporter.js +525 -248
- package/dist/exec-results.js +103 -71
- package/dist/exec-run-agent-pipeline.js +256 -0
- package/dist/exec-run-agent.js +531 -0
- package/dist/exec-run-in-place.js +541 -0
- package/dist/exec-run-job.js +717 -0
- package/dist/exec-run-lifecycle-commands.js +522 -0
- package/dist/exec-run-lock.js +110 -107
- package/dist/exec-run-mode-shared.js +140 -0
- package/dist/exec-run-register-command.js +244 -0
- package/dist/exec-run-register-core.js +386 -0
- package/dist/exec-run-register-mode.js +206 -0
- package/dist/exec-run-register-resume.js +393 -0
- package/dist/exec-run-register-state.js +322 -0
- package/dist/exec-run-register-worktree.js +509 -0
- package/dist/exec-run-schedule-mode.js +294 -0
- package/dist/exec-run-schedule-prepare.js +353 -0
- package/dist/exec-run-schedule-task.js +572 -0
- package/dist/exec-run-shared.js +399 -0
- package/dist/exec-run.js +11 -4953
- package/dist/exec-shared.js +9 -2
- package/dist/exec-slot-lock.js +242 -0
- package/dist/exec-task-repos.js +415 -0
- package/dist/exec-trial-commands.js +558 -0
- package/dist/exec-trial-core.js +371 -0
- package/dist/exec-trial.js +2 -895
- package/dist/exec-worktree-command.js +87 -43
- package/dist/exec-worktree-ops-commit.js +707 -0
- package/dist/exec-worktree-ops-lifecycle.js +292 -0
- package/dist/exec-worktree-ops-merge.js +303 -0
- package/dist/exec-worktree-ops.js +3 -847
- package/dist/exec-worktree.js +146 -31
- package/dist/exec.js +2 -999
- package/dist/frontmatter-namespace.js +2 -2
- package/dist/grade-apply.js +734 -0
- package/dist/grade-command-apply.js +250 -0
- package/dist/grade-command-inspect.js +138 -0
- package/dist/grade-command-plan.js +101 -0
- package/dist/grade-command-shared.js +68 -0
- package/dist/grade-core.js +307 -0
- package/dist/grade-markdown.js +274 -0
- package/dist/grade-pipeline-state.js +184 -0
- package/dist/grade-plan.js +507 -0
- package/dist/grade-result.js +133 -5
- package/dist/grade-target-discovery.js +265 -0
- package/dist/grade-targets.js +432 -0
- package/dist/grade.js +14 -2451
- package/dist/init-command.js +443 -0
- package/dist/job-definition.js +670 -0
- package/dist/job.js +64 -578
- package/dist/kata-command.js +2 -2
- package/dist/orchestrator.js +213 -0
- package/dist/register-command-types.js +1 -0
- package/dist/register-core.js +363 -0
- package/dist/register-create-commands.js +245 -0
- package/dist/register-event-merge.js +169 -0
- package/dist/register-events.js +4 -4
- package/dist/register-item.js +13 -7
- package/dist/register-maintenance-commands.js +187 -0
- package/dist/register-migration.js +268 -0
- package/dist/register-renumber.js +314 -0
- package/dist/register-transition-commands.js +248 -0
- package/dist/register-update.js +230 -0
- package/dist/register-views.js +256 -0
- package/dist/register.js +175 -1975
- package/dist/review-grade.js +252 -0
- package/dist/review-plan.js +114 -4
- package/dist/review-types.js +40 -1
- package/dist/routine-definition.js +401 -0
- package/dist/routine.js +73 -402
- package/dist/schedule-approach.js +2 -2
- package/dist/schedule-build.js +2 -2
- package/dist/schedule-strategy-generate-document.js +273 -0
- package/dist/schedule-strategy-generate-scope.js +199 -0
- package/dist/schedule-strategy-generate.js +9 -473
- package/dist/schedule.js +19 -6
- package/dist/specdojo-config.js +465 -20
- package/dist/specdojo-gitignore.js +135 -0
- package/dist/specdojo.js +6 -0
- package/dist/viewpoint-document-kinds-check.js +128 -0
- package/dist/yaml-pages.js +4 -4
- package/dist/yaml.js +28 -0
- package/docs/ja/specdojo/defaults/pm-review-viewpoints.yaml +348 -90
- package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +51 -17
- package/docs/ja/specdojo/exec-templates/xep-fully-guided-template.md +7 -5
- package/docs/ja/specdojo/exec-templates/xrp-freeform-template.md +29 -31
- package/docs/ja/specdojo/exec-templates/xrp-fully-guided-template.md +34 -55
- package/docs/ja/specdojo/exec-templates/xrp-job-template.md +54 -0
- package/docs/ja/specdojo/exec-templates/xrp-recipe-guided-template.md +28 -37
- package/docs/ja/specdojo/exec-templates/xrp-recipe-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-retrofit-template.md +30 -30
- package/docs/ja/specdojo/exec-templates/xrp-rulebook-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-sample-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-template-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-template.md +29 -28
- package/docs/ja/specdojo/exec-templates/xrr-template.md +11 -9
- package/docs/ja/specdojo/guides/docs-editing-guide.md +20 -0
- package/docs/ja/specdojo/guides/docs-structure-guide.md +103 -70
- package/docs/ja/specdojo/guides/exec-config-guide.md +93 -49
- package/docs/ja/specdojo/guides/exec-operation-guide.md +124 -27
- package/docs/ja/specdojo/guides/exec-worktree-guide.md +40 -11
- package/docs/ja/specdojo/guides/kata-guide.md +4 -4
- package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +45 -22
- package/docs/ja/specdojo/guides/plan-result-lifecycle-guide.md +1 -1
- package/docs/ja/specdojo/guides/practice-system-composition-guide.md +13 -13
- package/docs/ja/specdojo/guides/quick-start-guide.md +260 -30
- package/docs/ja/specdojo/guides/register-operation-guide.md +31 -14
- package/docs/ja/specdojo/guides/release-v0-3-0-migration-guide.md +264 -0
- package/docs/ja/specdojo/guides/remote-host-development-guide.md +22 -1
- package/docs/ja/specdojo/guides/review-guide.md +195 -158
- package/docs/ja/specdojo/guides/routine-operation-guide.md +75 -10
- package/docs/ja/specdojo/guides/ryu-guide.md +32 -30
- package/docs/ja/specdojo/guides/schedule-design-guide.md +10 -10
- package/docs/ja/specdojo/guides/schedule-operation-guide.md +1 -1
- package/docs/ja/specdojo/guides/specdojo-overview-guide.md +58 -33
- package/docs/ja/specdojo/guides/use-case-guide.md +3 -3
- package/docs/ja/specdojo/guides/waza-guide.md +15 -2
- package/docs/ja/specdojo/index.md +2 -2
- package/docs/ja/specdojo/philosophy/specdojo-philosophy.md +5 -5
- package/docs/ja/specdojo/recipes/bps-recipe.md +213 -0
- package/docs/ja/specdojo/recipes/pm-members-recipe.md +52 -117
- package/docs/ja/specdojo/references/command-reference.md +335 -92
- package/docs/ja/specdojo/references/deliverables-reference.md +1 -1
- package/docs/ja/specdojo/references/directory-layout-reference.md +13 -9
- package/docs/ja/specdojo/references/specdojo-config-reference.md +107 -24
- package/docs/ja/specdojo/rulebooks/bps-rulebook.md +132 -220
- package/docs/ja/specdojo/rulebooks/br-rulebook.md +6 -44
- package/docs/ja/specdojo/rulebooks/cdfd-rulebook.md +2 -0
- package/docs/ja/specdojo/rulebooks/dmd-rulebook.md +0 -87
- package/docs/ja/specdojo/rulebooks/gl-rulebook.md +61 -39
- package/docs/ja/specdojo/rulebooks/ifx-cmd-rulebook.md +0 -87
- package/docs/ja/specdojo/rulebooks/ifx-index-rulebook.md +1 -33
- package/docs/ja/specdojo/rulebooks/opd-rulebook.md +0 -137
- package/docs/ja/specdojo/rulebooks/opr-rulebook.md +0 -247
- package/docs/ja/specdojo/rulebooks/otp-rulebook.md +0 -83
- package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +4 -2
- package/docs/ja/specdojo/rulebooks/pm-members-rulebook.md +78 -150
- package/docs/ja/specdojo/rulebooks/pm-roles-rulebook.md +5 -4
- package/docs/ja/specdojo/rulebooks/sch-rulebook.md +1 -1
- package/docs/ja/specdojo/rulebooks/stsd-mermaid-rulebook.md +0 -11
- package/docs/ja/specdojo/rulebooks/stsd-rulebook.md +0 -61
- package/docs/ja/specdojo/rulebooks/tml-rulebook.md +2 -47
- package/docs/ja/specdojo/samples/bps-sample.md +74 -21
- package/docs/ja/specdojo/samples/gl-sample.yaml +17 -1
- package/docs/ja/specdojo/samples/ifx-index-sample.yaml +28 -0
- package/docs/ja/specdojo/samples/pm-members-sample.yaml +2 -67
- package/docs/ja/specdojo/samples/pm-organization-sample.md +8 -7
- package/docs/ja/specdojo/samples/pm-raci-sample.md +1 -1
- package/docs/ja/specdojo/samples/tml-sample.yaml +40 -0
- package/docs/ja/specdojo/standards/document-metadata-standard.md +21 -16
- package/docs/ja/specdojo/standards/id-and-file-naming-standard.md +14 -14
- package/docs/ja/specdojo/standards/job-definition-standard.md +37 -17
- package/docs/ja/specdojo/standards/people-and-organization-definition-standard.md +37 -32
- package/docs/ja/specdojo/standards/philosophy-authoring-standard.md +1 -1
- package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +21 -11
- package/docs/ja/specdojo/templates/agent-members-template.yaml +25 -0
- package/docs/ja/specdojo/templates/bps-template.md +91 -0
- package/docs/ja/specdojo/templates/pm-members-template.yaml +2 -59
- package/docs/specdojo/schemas/v1/agent-members.schema.yaml +76 -0
- package/docs/specdojo/schemas/v1/exec-common.schema.yaml +4 -2
- package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +55 -2
- package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +93 -6
- package/docs/specdojo/schemas/v1/exec-reporter-output.schema.yaml +27 -78
- package/docs/specdojo/schemas/v1/gl.schema.yaml +87 -0
- package/docs/specdojo/schemas/v1/grade-result.schema.yaml +33 -0
- package/docs/specdojo/schemas/v1/job-run.schema.yaml +27 -0
- package/docs/specdojo/schemas/v1/job.schema.yaml +25 -0
- package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +49 -1
- package/docs/specdojo/schemas/v1/pm-members.schema.yaml +9 -169
- package/docs/specdojo/schemas/v1/pm-review-viewpoints.schema.yaml +100 -10
- package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +13 -0
- package/docs/specdojo/schemas/v1/routine-run.schema.yaml +3 -0
- package/docs/specdojo/schemas/v1/routine.schema.yaml +7 -0
- package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +110 -0
- package/package.json +17 -12
- package/templates/antigravity/README.md +29 -4
- package/templates/antigravity/{pm-members-snippet.yaml → agent-members-snippet.yaml} +8 -2
- package/templates/antigravity/exec-defaults-snippet.yaml +10 -7
- package/templates/antigravity/orchestrator.md +18 -7
- package/templates/antigravity/settings.global.json +55 -0
- package/templates/claude/agents/claude-executor.md +14 -0
- package/templates/claude/agents/claude-reporter.md +16 -0
- package/templates/claude/agents/specdojo-orchestrator.md +18 -7
- package/templates/claude/settings.edit.json +27 -1
- package/templates/codex/README.md +5 -4
- package/templates/codex/agents/specdojo-orchestrator.toml +18 -7
- package/templates/codex/orchestrator.md +18 -7
- package/templates/copilot/README.md +7 -5
- package/templates/copilot/{pm-members-snippet.yaml → agent-members-snippet.yaml} +4 -2
- package/templates/devcontainer/devcontainer.json +27 -0
- package/templates/devcontainer/emacs/init.el +88 -0
- package/templates/devcontainer/post-create.sh +62 -0
- package/templates/init-agent-members.yaml +200 -0
- package/templates/init-exec-defaults.yaml +74 -0
- package/templates/opencode/agents/specdojo-orchestrator.md +18 -7
- package/docs/ja/specdojo/exec-templates/xrp-viewpoint-detail-template.md +0 -7
- package/docs/ja/specdojo/exec-templates/xrr-viewpoint-detail-template.md +0 -7
package/dist/exec.js
CHANGED
|
@@ -1,999 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { validateCatalogLocalIds, validateRulebookKata } from "./catalog-build.js";
|
|
4
|
-
import { acquireSchedulerLock, buildEvent, canBlockTask, canCancelTask, canClaimTask, canCompleteTask, canReopenTask, canReleaseTask, canUnblockTask, collectRepeatable, computeReadyIds, findDoingTasksForActor, foldEventsToState, readAllEventFiles, releaseSchedulerLock, schedulerLockPath, writeEventFile, } from "./exec-events.js";
|
|
5
|
-
import { activateResolvedProjectPaths, eventsDirForProject, generatedDirForProject, resolveProjectPaths, } from "./exec-project.js";
|
|
6
|
-
import { assertValidActor, getProjectViewpointsPath, loadConfig, loadMemberRoster, specdojoRootDir, } from "./specdojo-config.js";
|
|
7
|
-
import { buildScheduleIndex, computeCpm, exitWithCode, printValidateResult, selectNextTask, validateAll, writeCpmFiles, writeGeneratedCore, writeScheduleHashAndDiff, } from "./exec-schedule.js";
|
|
8
|
-
import { readReadySnapshot } from "./exec-schedule-ready.js";
|
|
9
|
-
import { displayWidth, nowUtcIsoSeconds, padEndDisplay, qualifyTaskId, requireNonEmpty, } from "./exec-shared.js";
|
|
10
|
-
import { archivePlan, buildInPlaceStem, generateDeliverablePlan, generateSinglePlan, resolveDeliverableTarget, finalizeResultSectionsForDeliverable, reviewResultSectionsForDeliverable, targetDocIdsForScheduledTask, stemFromPlanPath, } from "./exec-plans.js";
|
|
11
|
-
import { resetResultForClaim, scaffoldResult } from "./exec-results.js";
|
|
12
|
-
import { runProviderScaffold, specdojoPackageRootDir } from "./exec-provider-scaffold.js";
|
|
13
|
-
import { generateRegisterPlan, normalizePjrId, resolveRegisterRunTarget } from "./exec-register.js";
|
|
14
|
-
import { scaffoldViewpoints } from "./review-plan.js";
|
|
15
|
-
import { registerCycleCommand, registerResumeCommand, registerRunCommand } from "./exec-run.js";
|
|
16
|
-
import { buildTaskView } from "./exec-task-view.js";
|
|
17
|
-
import { registerExecWorktreeCommands } from "./exec-worktree-command.js";
|
|
18
|
-
import { registerExecTrialCommands } from "./exec-trial.js";
|
|
19
|
-
import { discardStaleExecWorktree } from "./exec-worktree-ops.js";
|
|
20
|
-
import { buildInitialStateFromStrategy } from "./exec-schedule-initial.js";
|
|
21
|
-
import { buildPhaseModeIndex, resolveApproach, resolveOwnerForLocalId, resolveTaskExecution, resolveTaskMode, } from "./exec-strategy.js";
|
|
22
|
-
const KNOWN_OWNER_LABELS = ["PO", "PM", "BA", "ARC", "DEV", "QE", "UX", "OPS"];
|
|
23
|
-
const KNOWN_OWNER_LABELS_TEXT = KNOWN_OWNER_LABELS.join("|");
|
|
24
|
-
const KNOWN_APPROACHES = [
|
|
25
|
-
"fully-guided",
|
|
26
|
-
"recipe-guided",
|
|
27
|
-
"freeform",
|
|
28
|
-
"bootstrap",
|
|
29
|
-
"retrofit",
|
|
30
|
-
"cross-deliverable-dedup",
|
|
31
|
-
"rulebook-maintenance",
|
|
32
|
-
"recipe-maintenance",
|
|
33
|
-
"sample-maintenance",
|
|
34
|
-
"template-maintenance",
|
|
35
|
-
"finalize",
|
|
36
|
-
"bootstrap-finalize",
|
|
37
|
-
];
|
|
38
|
-
function parseTaskMode(value) {
|
|
39
|
-
const mode = typeof value === "string" ? value.trim().toLowerCase() : "edit";
|
|
40
|
-
if (mode !== "edit" && mode !== "review") {
|
|
41
|
-
throw new Error(`Invalid --mode value: ${mode}. Use one of: edit|review.`);
|
|
42
|
-
}
|
|
43
|
-
return mode;
|
|
44
|
-
}
|
|
45
|
-
function parseApproach(value) {
|
|
46
|
-
const approach = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
47
|
-
if (!KNOWN_APPROACHES.includes(approach)) {
|
|
48
|
-
throw new Error(`Invalid --approach value: ${approach}. Use one of: ${KNOWN_APPROACHES.join("|")}.`);
|
|
49
|
-
}
|
|
50
|
-
return approach;
|
|
51
|
-
}
|
|
52
|
-
function addProjectOptions(cmd) {
|
|
53
|
-
return cmd.option("--project <projectId>", "Project id in specdojo.config.json (e.g. shj-0001)");
|
|
54
|
-
}
|
|
55
|
-
function addLockOptions(cmd) {
|
|
56
|
-
return cmd
|
|
57
|
-
.option("--allow-multiple-doing", "Allow this actor to hold multiple doing tasks", false)
|
|
58
|
-
.option("--lock-timeout-ms <ms>", "Lock acquisition timeout in ms", "10000")
|
|
59
|
-
.option("--lock-stale-ms <ms>", "Lock stale threshold in ms", "300000");
|
|
60
|
-
}
|
|
61
|
-
function addForceOption(cmd) {
|
|
62
|
-
return cmd.option("--force", "Human actor only: override the guard on a task held by another actor", false);
|
|
63
|
-
}
|
|
64
|
-
function addOwnerOptions(cmd) {
|
|
65
|
-
return cmd
|
|
66
|
-
.option("--owner <owner>", `Planned owner label for assignment checks (${KNOWN_OWNER_LABELS_TEXT}; defaults to SPECDOJO_OWNER, roster owner, or actor)`)
|
|
67
|
-
.option("--allow-owner-mismatch", "Allow claiming a task assigned to a different owner", false);
|
|
68
|
-
}
|
|
69
|
-
// Fixed default messages for routine state transitions. Events whose message carries the
|
|
70
|
-
// reason itself (note / block / unblock / reopen / cancel) have no default and keep --msg required.
|
|
71
|
-
const DEFAULT_EVENT_MESSAGES = {
|
|
72
|
-
claim: "claim task",
|
|
73
|
-
complete: "complete task",
|
|
74
|
-
release: "release task",
|
|
75
|
-
link: "link refs",
|
|
76
|
-
estimate: "update estimate",
|
|
77
|
-
};
|
|
78
|
-
function addCommonAddOptions(cmd, options) {
|
|
79
|
-
addProjectOptions(cmd);
|
|
80
|
-
// `release --all-blocked` operates on every blocked task instead of a single --task, so the task
|
|
81
|
-
// option must be optional for that command. The single-task path still validates it via
|
|
82
|
-
// requireNonEmpty before building the event.
|
|
83
|
-
if (options?.requireTask === false) {
|
|
84
|
-
cmd.option("--task <taskId>", "Task/Milestone ID");
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
cmd.requiredOption("--task <taskId>", "Task/Milestone ID");
|
|
88
|
-
}
|
|
89
|
-
cmd.requiredOption("--by <actor>", "Actor (human/agent)");
|
|
90
|
-
if (options?.msgDefault !== undefined) {
|
|
91
|
-
cmd.option("--msg <message>", "Short message", options.msgDefault);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
cmd.requiredOption("--msg <message>", "Short message");
|
|
95
|
-
}
|
|
96
|
-
return cmd
|
|
97
|
-
.option("--run-id <id>", "Correlation id")
|
|
98
|
-
.option("--ref <k=v...>", "refs key=value (repeatable)", collectRepeatable, [])
|
|
99
|
-
.option("--meta <k=v...>", "meta key=value (repeatable)", collectRepeatable, [])
|
|
100
|
-
.option("--dry-run", "Print event JSON without writing to disk", false);
|
|
101
|
-
}
|
|
102
|
-
function resolveProjectContext(opts) {
|
|
103
|
-
const resolvedPaths = resolveProjectPaths({ project: opts.project });
|
|
104
|
-
activateResolvedProjectPaths(resolvedPaths);
|
|
105
|
-
return resolvedPaths;
|
|
106
|
-
}
|
|
107
|
-
function loadRosterForOpts(opts) {
|
|
108
|
-
const { config } = loadConfig();
|
|
109
|
-
if (!config)
|
|
110
|
-
return null;
|
|
111
|
-
const projectId = resolveProjectId(opts);
|
|
112
|
-
const project = config.projects[projectId];
|
|
113
|
-
if (!project)
|
|
114
|
-
return null;
|
|
115
|
-
return loadMemberRoster(specdojoRootDir(), project);
|
|
116
|
-
}
|
|
117
|
-
function resolveProjectId(opts) {
|
|
118
|
-
const { config } = loadConfig();
|
|
119
|
-
return (opts.project?.trim() ||
|
|
120
|
-
process.env.SPECDOJO_PROJECT?.trim() ||
|
|
121
|
-
config?.current_project?.trim() ||
|
|
122
|
-
Object.keys(config?.projects ?? {})[0] ||
|
|
123
|
-
"");
|
|
124
|
-
}
|
|
125
|
-
function findRosterMember(roster, actor) {
|
|
126
|
-
return roster?.members.find((member) => member.nickname === actor) ?? null;
|
|
127
|
-
}
|
|
128
|
-
// The --force override is honored only for actors registered as humans in the
|
|
129
|
-
// roster, so agents cannot steal a task another actor is working on.
|
|
130
|
-
function resolveForceOverride(opts, actor) {
|
|
131
|
-
const isHuman = findRosterMember(loadRosterForOpts(opts), actor)?.type === "human";
|
|
132
|
-
return { isHuman, force: !!opts.force };
|
|
133
|
-
}
|
|
134
|
-
export function resolveClaimOwner(opts, actor, roster = null, taskOwner) {
|
|
135
|
-
const cliOwner = typeof opts.owner === "string" ? opts.owner.trim().toUpperCase() : "";
|
|
136
|
-
const envOwner = typeof process.env.SPECDOJO_OWNER === "string"
|
|
137
|
-
? process.env.SPECDOJO_OWNER.trim().toUpperCase()
|
|
138
|
-
: "";
|
|
139
|
-
const rosterMemberRoles = findRosterMember(roster, actor)?.roles ?? [];
|
|
140
|
-
// For multi-role actors, prefer the role matching the task's planned owner.
|
|
141
|
-
const matchedRole = taskOwner && rosterMemberRoles.length > 1
|
|
142
|
-
? (rosterMemberRoles
|
|
143
|
-
.find((r) => r.trim().toUpperCase() === taskOwner.toUpperCase() &&
|
|
144
|
-
KNOWN_OWNER_LABELS.includes(r.trim().toUpperCase()))
|
|
145
|
-
?.trim()
|
|
146
|
-
.toUpperCase() ?? "")
|
|
147
|
-
: "";
|
|
148
|
-
const rosterOwner = Array.isArray(rosterMemberRoles) && rosterMemberRoles.length > 0
|
|
149
|
-
? rosterMemberRoles[0].trim().toUpperCase()
|
|
150
|
-
: "";
|
|
151
|
-
if (cliOwner && !KNOWN_OWNER_LABELS.includes(cliOwner)) {
|
|
152
|
-
throw new Error(`Invalid --owner value: ${cliOwner}. Use one of: ${KNOWN_OWNER_LABELS_TEXT}.`);
|
|
153
|
-
}
|
|
154
|
-
if (envOwner && !KNOWN_OWNER_LABELS.includes(envOwner)) {
|
|
155
|
-
throw new Error(`Invalid SPECDOJO_OWNER value: ${envOwner}. Use one of: ${KNOWN_OWNER_LABELS_TEXT}.`);
|
|
156
|
-
}
|
|
157
|
-
if (rosterOwner &&
|
|
158
|
-
!KNOWN_OWNER_LABELS.includes(rosterOwner)) {
|
|
159
|
-
throw new Error(`Invalid roster owner for actor ${actor}: ${rosterOwner}. Use one of: ${KNOWN_OWNER_LABELS_TEXT}.`);
|
|
160
|
-
}
|
|
161
|
-
return cliOwner || envOwner || matchedRole || rosterOwner || "";
|
|
162
|
-
}
|
|
163
|
-
function resolveSchedulerStrategy(opts, actor, roster = null) {
|
|
164
|
-
const cliStrategy = typeof opts.strategy === "string" ? opts.strategy.trim().toLowerCase() : "";
|
|
165
|
-
const rosterStrategy = findRosterMember(roster, actor)?.scheduler_strategy ?? "";
|
|
166
|
-
const strategy = (cliStrategy || rosterStrategy || "critical-first");
|
|
167
|
-
if (strategy !== "critical-first" && strategy !== "fifo") {
|
|
168
|
-
throw new Error(`Invalid --strategy value: ${strategy}. Use one of: critical-first|fifo.`);
|
|
169
|
-
}
|
|
170
|
-
return strategy;
|
|
171
|
-
}
|
|
172
|
-
function printCommandError(error, fail = true) {
|
|
173
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
174
|
-
process.stdout.write(message + "\n");
|
|
175
|
-
if (fail)
|
|
176
|
-
exitWithCode(false);
|
|
177
|
-
else
|
|
178
|
-
process.exitCode = 1;
|
|
179
|
-
}
|
|
180
|
-
function loadValidatedExecState(projectPath) {
|
|
181
|
-
const res = validateAll(projectPath);
|
|
182
|
-
if (!res.ok) {
|
|
183
|
-
printValidateResult(res);
|
|
184
|
-
exitWithCode(false);
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
|
-
const schedule = buildScheduleIndex(projectPath);
|
|
188
|
-
const events = readAllEventFiles(projectPath);
|
|
189
|
-
const initialTasks = buildInitialStateFromStrategy(projectPath, schedule);
|
|
190
|
-
const snapshot = foldEventsToState(events, schedule, projectPath, initialTasks);
|
|
191
|
-
return { schedule, events, snapshot };
|
|
192
|
-
}
|
|
193
|
-
function ensureActorCanClaimNext(snapshot, actor, allowMultipleDoing) {
|
|
194
|
-
const doingTasks = findDoingTasksForActor(snapshot, actor);
|
|
195
|
-
if (allowMultipleDoing || doingTasks.length === 0)
|
|
196
|
-
return true;
|
|
197
|
-
process.stdout.write(`Actor ${actor} already has doing task(s): ${doingTasks.join(", ")}\n` +
|
|
198
|
-
`Use --allow-multiple-doing to override.\n`);
|
|
199
|
-
exitWithCode(false);
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
async function scaffoldClaimResult(opts) {
|
|
203
|
-
const scheduleNode = opts.state.schedule.nodes.get(opts.taskId);
|
|
204
|
-
const localId = scheduleNode?.local_id;
|
|
205
|
-
const phaseModeIndex = buildPhaseModeIndex(opts.schedulePath);
|
|
206
|
-
const mode = resolveTaskMode(localId, opts.taskId, phaseModeIndex, scheduleNode?.phase_suffix, scheduleNode?.phase_set);
|
|
207
|
-
const approach = resolveApproach(localId, opts.taskId, phaseModeIndex, scheduleNode?.phase_suffix, scheduleNode?.phase_set);
|
|
208
|
-
const execution = resolveTaskExecution(localId, opts.taskId, phaseModeIndex, scheduleNode?.phase_suffix, scheduleNode?.phase_set);
|
|
209
|
-
const reviewSections = mode === "review"
|
|
210
|
-
? reviewResultSectionsForDeliverable(opts.catalogPath ?? "", localId)
|
|
211
|
-
: undefined;
|
|
212
|
-
const finalizeSections = approach === "finalize" || approach === "bootstrap-finalize"
|
|
213
|
-
? finalizeResultSectionsForDeliverable(opts.catalogPath ?? "", localId, approach)
|
|
214
|
-
: undefined;
|
|
215
|
-
const targets = targetDocIdsForScheduledTask(opts.catalogPath ?? "", {
|
|
216
|
-
local_id: localId,
|
|
217
|
-
target_local_ids: scheduleNode?.target_local_ids,
|
|
218
|
-
approach,
|
|
219
|
-
}, opts.projectId);
|
|
220
|
-
const result = await scaffoldResult({
|
|
221
|
-
executionPath: opts.executionPath,
|
|
222
|
-
taskId: opts.taskId,
|
|
223
|
-
mode,
|
|
224
|
-
projectId: opts.projectId,
|
|
225
|
-
...(execution === "agent" ? { planRef: `exec/plans/${opts.taskId}-plan.md` } : {}),
|
|
226
|
-
agent: opts.actor,
|
|
227
|
-
startedAt: opts.startedAt,
|
|
228
|
-
execution,
|
|
229
|
-
...(approach ? { approach } : {}),
|
|
230
|
-
...(targets ? { targets } : {}),
|
|
231
|
-
...(reviewSections ? { reviewSections } : {}),
|
|
232
|
-
...(finalizeSections ? { finalizeSections } : {}),
|
|
233
|
-
});
|
|
234
|
-
if (!result.created) {
|
|
235
|
-
await resetResultForClaim(result.resultPath, opts.actor, opts.startedAt, execution);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
function runSimpleEventCommand(opts, type) {
|
|
239
|
-
try {
|
|
240
|
-
const { schedulePath } = resolveProjectContext(opts);
|
|
241
|
-
const actor = requireNonEmpty("by", opts.by);
|
|
242
|
-
const roster = loadRosterForOpts(opts);
|
|
243
|
-
assertValidActor(actor, roster);
|
|
244
|
-
const event = buildEvent(type, opts);
|
|
245
|
-
if (opts.dryRun) {
|
|
246
|
-
process.stdout.write(`[dry-run] ${JSON.stringify(event, null, 2)}\n`);
|
|
247
|
-
exitWithCode(true);
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
const out = writeEventFile(schedulePath, event);
|
|
251
|
-
process.stdout.write(out + "\n");
|
|
252
|
-
exitWithCode(true);
|
|
253
|
-
}
|
|
254
|
-
catch (error) {
|
|
255
|
-
printCommandError(error, false);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
async function runLockedEventCommand(opts, action) {
|
|
259
|
-
let lockDir = "";
|
|
260
|
-
try {
|
|
261
|
-
const { schedulePath, executionPath, catalogPath } = resolveProjectContext(opts);
|
|
262
|
-
const actor = requireNonEmpty("by", opts.by);
|
|
263
|
-
const roster = loadRosterForOpts(opts);
|
|
264
|
-
assertValidActor(actor, roster);
|
|
265
|
-
let taskId = typeof opts.task === "string" ? opts.task.trim() : "";
|
|
266
|
-
const allowMultipleDoing = !!opts.allowMultipleDoing;
|
|
267
|
-
const lockTimeoutMs = Number(opts.lockTimeoutMs);
|
|
268
|
-
const lockStaleMs = Number(opts.lockStaleMs);
|
|
269
|
-
lockDir = acquireSchedulerLock(schedulePath, { actor, lockTimeoutMs, lockStaleMs });
|
|
270
|
-
const state = loadValidatedExecState(schedulePath);
|
|
271
|
-
if (!state)
|
|
272
|
-
return;
|
|
273
|
-
if (!taskId && action.type === "complete") {
|
|
274
|
-
const doingTasks = findDoingTasksForActor(state.snapshot, actor);
|
|
275
|
-
if (doingTasks.length === 0) {
|
|
276
|
-
throw new Error(`Actor ${actor} has no doing task to complete.`);
|
|
277
|
-
}
|
|
278
|
-
if (doingTasks.length > 1) {
|
|
279
|
-
throw new Error(`Actor ${actor} has multiple doing tasks: ${doingTasks.join(", ")}. Specify --task.`);
|
|
280
|
-
}
|
|
281
|
-
taskId = doingTasks[0];
|
|
282
|
-
}
|
|
283
|
-
if (!taskId)
|
|
284
|
-
taskId = requireNonEmpty("task", opts.task);
|
|
285
|
-
const resolvedOpts = { ...opts, task: taskId };
|
|
286
|
-
if (action.requireSingleDoing &&
|
|
287
|
-
!ensureActorCanClaimNext(state.snapshot, actor, allowMultipleDoing)) {
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
const check = action.check(state, taskId, actor, resolvedOpts);
|
|
291
|
-
if (!check.ok) {
|
|
292
|
-
process.stdout.write(`Cannot ${action.type} ${taskId}: ${check.reason}\n`);
|
|
293
|
-
exitWithCode(false);
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
const event = buildEvent(action.type, resolvedOpts);
|
|
297
|
-
if (action.type === "claim") {
|
|
298
|
-
const plannedOwner = state.schedule.nodes.get(taskId)?.owner;
|
|
299
|
-
const claimOwner = resolveClaimOwner(resolvedOpts, actor, roster, plannedOwner);
|
|
300
|
-
const cpm = computeCpm(state.schedule, schedulePath);
|
|
301
|
-
writeGeneratedCore(schedulePath, state.events, state.schedule, cpm);
|
|
302
|
-
writeScheduleHashAndDiff(schedulePath, state.schedule);
|
|
303
|
-
writeCpmFiles(schedulePath, cpm, state.snapshot);
|
|
304
|
-
event.meta = {
|
|
305
|
-
...(event.meta ?? {}),
|
|
306
|
-
claim_owner: claimOwner,
|
|
307
|
-
};
|
|
308
|
-
if (plannedOwner)
|
|
309
|
-
event.meta.planned_owner = plannedOwner;
|
|
310
|
-
if (plannedOwner && claimOwner !== plannedOwner && resolvedOpts.allowOwnerMismatch) {
|
|
311
|
-
event.meta.owner_override = true;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
if (opts.dryRun) {
|
|
315
|
-
process.stdout.write(`[dry-run] ${JSON.stringify(event, null, 2)}\n`);
|
|
316
|
-
if (action.type === "release" && opts.resetWorktree) {
|
|
317
|
-
resetExecWorktreeForTask({
|
|
318
|
-
projectId: resolveProjectId(opts),
|
|
319
|
-
taskId,
|
|
320
|
-
schedulePath,
|
|
321
|
-
executionPath,
|
|
322
|
-
dryRun: true,
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
exitWithCode(true);
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
const out = writeEventFile(schedulePath, event);
|
|
329
|
-
if (action.type === "claim") {
|
|
330
|
-
await scaffoldClaimResult({
|
|
331
|
-
schedulePath,
|
|
332
|
-
executionPath,
|
|
333
|
-
catalogPath,
|
|
334
|
-
taskId,
|
|
335
|
-
state,
|
|
336
|
-
projectId: resolveProjectId(opts),
|
|
337
|
-
actor,
|
|
338
|
-
startedAt: new Date().toISOString(),
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
// The release event has been persisted (the task is now todo), so a retained exec worktree is
|
|
342
|
-
// stale residue. --reset-worktree discards it eagerly instead of waiting for the next claim to
|
|
343
|
-
// clean it up via discardStaleExecWorktree.
|
|
344
|
-
if (action.type === "release" && opts.resetWorktree) {
|
|
345
|
-
resetExecWorktreeForTask({
|
|
346
|
-
projectId: resolveProjectId(opts),
|
|
347
|
-
taskId,
|
|
348
|
-
schedulePath,
|
|
349
|
-
executionPath,
|
|
350
|
-
dryRun: false,
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
process.stdout.write(out + "\n");
|
|
354
|
-
exitWithCode(true);
|
|
355
|
-
}
|
|
356
|
-
catch (error) {
|
|
357
|
-
printCommandError(error);
|
|
358
|
-
}
|
|
359
|
-
finally {
|
|
360
|
-
if (lockDir) {
|
|
361
|
-
try {
|
|
362
|
-
releaseSchedulerLock(lockDir);
|
|
363
|
-
}
|
|
364
|
-
catch { }
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
// Discards the exec worktree and branch left behind by a now-released task. A released task is back
|
|
369
|
-
// in todo, so any retained worktree is stale residue. `dryRun` only prints what would be discarded.
|
|
370
|
-
function resetExecWorktreeForTask(args) {
|
|
371
|
-
const worktreeTaskId = qualifyTaskId(args.projectId, args.taskId);
|
|
372
|
-
if (args.dryRun) {
|
|
373
|
-
process.stdout.write(`[dry-run] reset worktree: discard exec/${worktreeTaskId}\n`);
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
const discarded = discardStaleExecWorktree({
|
|
377
|
-
context: {
|
|
378
|
-
repoRoot: specdojoRootDir(),
|
|
379
|
-
schedulePath: args.schedulePath,
|
|
380
|
-
executionPath: args.executionPath,
|
|
381
|
-
},
|
|
382
|
-
worktreeTaskId,
|
|
383
|
-
});
|
|
384
|
-
process.stdout.write(discarded
|
|
385
|
-
? `reset worktree: discarded ${discarded}\n`
|
|
386
|
-
: `reset worktree: no worktree or branch for ${worktreeTaskId}\n`);
|
|
387
|
-
}
|
|
388
|
-
// `release --all-blocked`: return every blocked task in the project to todo under a single scheduler
|
|
389
|
-
// lock. Tasks blocked by a different actor are skipped unless --force is given (humans only); each
|
|
390
|
-
// skip is reported with its reason. --reset-worktree discards each released task's stale worktree.
|
|
391
|
-
async function runReleaseAllBlocked(opts) {
|
|
392
|
-
let lockDir = "";
|
|
393
|
-
try {
|
|
394
|
-
const { schedulePath, executionPath } = resolveProjectContext(opts);
|
|
395
|
-
const actor = requireNonEmpty("by", opts.by);
|
|
396
|
-
const roster = loadRosterForOpts(opts);
|
|
397
|
-
assertValidActor(actor, roster);
|
|
398
|
-
requireNonEmpty("msg", opts.msg);
|
|
399
|
-
if (opts.task) {
|
|
400
|
-
process.stdout.write("Note: --all-blocked ignores --task.\n");
|
|
401
|
-
}
|
|
402
|
-
const lockTimeoutMs = Number(opts.lockTimeoutMs);
|
|
403
|
-
const lockStaleMs = Number(opts.lockStaleMs);
|
|
404
|
-
lockDir = acquireSchedulerLock(schedulePath, { actor, lockTimeoutMs, lockStaleMs });
|
|
405
|
-
const state = loadValidatedExecState(schedulePath);
|
|
406
|
-
if (!state)
|
|
407
|
-
return;
|
|
408
|
-
const projectId = resolveProjectId(opts);
|
|
409
|
-
const blockedTaskIds = Object.entries(state.snapshot.tasks)
|
|
410
|
-
.filter(([, cs]) => cs.state === "blocked")
|
|
411
|
-
.map(([taskId]) => taskId)
|
|
412
|
-
.sort((a, b) => a.localeCompare(b));
|
|
413
|
-
if (blockedTaskIds.length === 0) {
|
|
414
|
-
process.stdout.write("No blocked tasks to release.\n");
|
|
415
|
-
exitWithCode(true);
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
const released = [];
|
|
419
|
-
const skipped = [];
|
|
420
|
-
const override = resolveForceOverride(opts, actor);
|
|
421
|
-
// Releasing one task does not change another task's releasability, so a single snapshot read is
|
|
422
|
-
// sufficient even though the in-memory snapshot is not re-folded after each write.
|
|
423
|
-
for (const taskId of blockedTaskIds) {
|
|
424
|
-
const check = canReleaseTask(state.schedule, state.snapshot, taskId, actor, override);
|
|
425
|
-
if (!check.ok) {
|
|
426
|
-
skipped.push({ taskId, reason: check.reason ?? "not releasable" });
|
|
427
|
-
continue;
|
|
428
|
-
}
|
|
429
|
-
const event = buildEvent("release", { ...opts, task: taskId });
|
|
430
|
-
if (opts.dryRun) {
|
|
431
|
-
process.stdout.write(`[dry-run] ${JSON.stringify(event, null, 2)}\n`);
|
|
432
|
-
if (opts.resetWorktree) {
|
|
433
|
-
resetExecWorktreeForTask({
|
|
434
|
-
projectId,
|
|
435
|
-
taskId,
|
|
436
|
-
schedulePath,
|
|
437
|
-
executionPath,
|
|
438
|
-
dryRun: true,
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
released.push(taskId);
|
|
442
|
-
continue;
|
|
443
|
-
}
|
|
444
|
-
const out = writeEventFile(schedulePath, event);
|
|
445
|
-
if (opts.resetWorktree) {
|
|
446
|
-
resetExecWorktreeForTask({ projectId, taskId, schedulePath, executionPath, dryRun: false });
|
|
447
|
-
}
|
|
448
|
-
process.stdout.write(out + "\n");
|
|
449
|
-
released.push(taskId);
|
|
450
|
-
}
|
|
451
|
-
const dryRunSuffix = opts.dryRun ? " (dry-run)" : "";
|
|
452
|
-
process.stdout.write(`\nReleased ${released.length} blocked task(s)${dryRunSuffix}; skipped ${skipped.length}.\n`);
|
|
453
|
-
for (const s of skipped) {
|
|
454
|
-
process.stdout.write(` skip ${s.taskId}: ${s.reason}\n`);
|
|
455
|
-
}
|
|
456
|
-
exitWithCode(true);
|
|
457
|
-
}
|
|
458
|
-
catch (error) {
|
|
459
|
-
printCommandError(error);
|
|
460
|
-
}
|
|
461
|
-
finally {
|
|
462
|
-
if (lockDir) {
|
|
463
|
-
try {
|
|
464
|
-
releaseSchedulerLock(lockDir);
|
|
465
|
-
}
|
|
466
|
-
catch { }
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
export function registerExecCommands(program) {
|
|
471
|
-
const exec = program.command("exec").description("Execution helpers");
|
|
472
|
-
const lockedActions = {
|
|
473
|
-
claim: {
|
|
474
|
-
type: "claim",
|
|
475
|
-
requireSingleDoing: true,
|
|
476
|
-
check: ({ schedule, snapshot }, taskId, actor, opts) => {
|
|
477
|
-
const taskOwner = schedule.nodes.get(taskId)?.owner;
|
|
478
|
-
return canClaimTask(schedule, snapshot, taskId, resolveClaimOwner(opts, actor, loadRosterForOpts(opts), taskOwner), !!opts.allowOwnerMismatch);
|
|
479
|
-
},
|
|
480
|
-
},
|
|
481
|
-
complete: {
|
|
482
|
-
type: "complete",
|
|
483
|
-
check: ({ schedule, snapshot }, taskId, actor, opts) => canCompleteTask(schedule, snapshot, taskId, actor, resolveForceOverride(opts, actor)),
|
|
484
|
-
},
|
|
485
|
-
reopen: {
|
|
486
|
-
type: "reopen",
|
|
487
|
-
check: ({ schedule, snapshot }, taskId, actor, opts) => canReopenTask(schedule, snapshot, taskId, findRosterMember(loadRosterForOpts(opts), actor)?.type === "human"),
|
|
488
|
-
},
|
|
489
|
-
block: {
|
|
490
|
-
type: "block",
|
|
491
|
-
check: ({ schedule, snapshot }, taskId, actor, opts) => canBlockTask(schedule, snapshot, taskId, actor, resolveForceOverride(opts, actor)),
|
|
492
|
-
},
|
|
493
|
-
unblock: {
|
|
494
|
-
type: "unblock",
|
|
495
|
-
check: ({ schedule, snapshot }, taskId) => canUnblockTask(schedule, snapshot, taskId),
|
|
496
|
-
},
|
|
497
|
-
release: {
|
|
498
|
-
type: "release",
|
|
499
|
-
check: ({ schedule, snapshot }, taskId, actor, opts) => canReleaseTask(schedule, snapshot, taskId, actor, resolveForceOverride(opts, actor)),
|
|
500
|
-
},
|
|
501
|
-
cancel: {
|
|
502
|
-
type: "cancel",
|
|
503
|
-
check: ({ schedule, snapshot }, taskId) => canCancelTask(schedule, snapshot, taskId),
|
|
504
|
-
},
|
|
505
|
-
};
|
|
506
|
-
const types = [
|
|
507
|
-
"claim",
|
|
508
|
-
"note",
|
|
509
|
-
"block",
|
|
510
|
-
"unblock",
|
|
511
|
-
"complete",
|
|
512
|
-
"reopen",
|
|
513
|
-
"release",
|
|
514
|
-
"cancel",
|
|
515
|
-
"link",
|
|
516
|
-
"estimate",
|
|
517
|
-
];
|
|
518
|
-
for (const t of types) {
|
|
519
|
-
const cmd = exec.command(t).description(`Write ${t} event JSON into exec/events/ (UTC)`);
|
|
520
|
-
addCommonAddOptions(cmd, {
|
|
521
|
-
requireTask: t !== "release" && t !== "complete",
|
|
522
|
-
msgDefault: DEFAULT_EVENT_MESSAGES[t],
|
|
523
|
-
});
|
|
524
|
-
if (t in lockedActions)
|
|
525
|
-
addLockOptions(cmd);
|
|
526
|
-
if (t === "claim")
|
|
527
|
-
addOwnerOptions(cmd);
|
|
528
|
-
if (t === "complete" || t === "block" || t === "release")
|
|
529
|
-
addForceOption(cmd);
|
|
530
|
-
if (t === "release") {
|
|
531
|
-
cmd.option("--reset-worktree", "Discard the task's exec worktree and branch after releasing (force removal)", false);
|
|
532
|
-
cmd.option("--all-blocked", "Release every blocked task in the project back to todo (ignores --task)", false);
|
|
533
|
-
}
|
|
534
|
-
if (t in lockedActions) {
|
|
535
|
-
const action = lockedActions[t];
|
|
536
|
-
cmd.action(async (opts) => {
|
|
537
|
-
if (action.type === "release" && opts.allBlocked) {
|
|
538
|
-
await runReleaseAllBlocked(opts);
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
await runLockedEventCommand(opts, action);
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
else {
|
|
545
|
-
cmd.action((opts) => runSimpleEventCommand(opts, t));
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
const vcmd = exec.command("validate").description("Validate schedule + events");
|
|
549
|
-
addProjectOptions(vcmd);
|
|
550
|
-
vcmd.action((opts) => {
|
|
551
|
-
try {
|
|
552
|
-
const { schedulePath, catalogPath } = resolveProjectContext(opts);
|
|
553
|
-
const res = validateAll(schedulePath);
|
|
554
|
-
printValidateResult(res);
|
|
555
|
-
// Scheduled tasks resolve their deliverable by bare local_id, so warn when a
|
|
556
|
-
// local_id is not unique project-wide across the catalogs.
|
|
557
|
-
if (catalogPath && existsSync(catalogPath)) {
|
|
558
|
-
for (const warn of validateCatalogLocalIds(catalogPath).warnings) {
|
|
559
|
-
process.stdout.write(`WARN: ${warn}\n`);
|
|
560
|
-
}
|
|
561
|
-
// Warn when a rulebook declares recipe/sample/template or includes rulebooks
|
|
562
|
-
// that do not exist (or self-reference / non-rulebook includes).
|
|
563
|
-
for (const warn of validateRulebookKata(catalogPath).warnings) {
|
|
564
|
-
process.stdout.write(`WARN: ${warn}\n`);
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
exitWithCode(res.ok);
|
|
568
|
-
}
|
|
569
|
-
catch (error) {
|
|
570
|
-
printCommandError(error, false);
|
|
571
|
-
}
|
|
572
|
-
});
|
|
573
|
-
const refreshCmd = exec
|
|
574
|
-
.command("refresh")
|
|
575
|
-
.description("Refresh derived execution state under generated/");
|
|
576
|
-
addProjectOptions(refreshCmd);
|
|
577
|
-
refreshCmd.action(async (opts) => {
|
|
578
|
-
try {
|
|
579
|
-
const { schedulePath } = resolveProjectContext(opts);
|
|
580
|
-
const res = validateAll(schedulePath);
|
|
581
|
-
printValidateResult(res);
|
|
582
|
-
if (!res.ok) {
|
|
583
|
-
exitWithCode(false);
|
|
584
|
-
return;
|
|
585
|
-
}
|
|
586
|
-
const schedule = buildScheduleIndex(schedulePath);
|
|
587
|
-
const events = readAllEventFiles(schedulePath);
|
|
588
|
-
const cpm = computeCpm(schedule, schedulePath);
|
|
589
|
-
const snapshot = writeGeneratedCore(schedulePath, events, schedule, cpm);
|
|
590
|
-
writeScheduleHashAndDiff(schedulePath, schedule);
|
|
591
|
-
writeCpmFiles(schedulePath, cpm, snapshot);
|
|
592
|
-
process.stdout.write(`\nGenerated: ${generatedDirForProject(schedulePath)}\n`);
|
|
593
|
-
exitWithCode(true);
|
|
594
|
-
}
|
|
595
|
-
catch (error) {
|
|
596
|
-
printCommandError(error, false);
|
|
597
|
-
}
|
|
598
|
-
});
|
|
599
|
-
const planCmd = exec
|
|
600
|
-
.command("plan")
|
|
601
|
-
.description("Generate a plan for an agent task or catalog deliverable (schedule-independent; does not change state or events)");
|
|
602
|
-
addProjectOptions(planCmd);
|
|
603
|
-
planCmd.option("--task <taskId>", "Scheduled task ID to generate the plan for");
|
|
604
|
-
planCmd.option("--deliverable <localId>", "Catalog deliverable local_id (unique project-wide)");
|
|
605
|
-
planCmd.option("--register <pjrId>", "Project register item ID (PJR-XXXX)");
|
|
606
|
-
planCmd.option("--mode <mode>", "edit|review (deliverable target)", "edit");
|
|
607
|
-
planCmd.option("--approach <approach>", "Approach template (deliverable target)");
|
|
608
|
-
planCmd.option("--track <track>", "Track to resolve the owner role from sch-strategy owner_rules (deliverable target)");
|
|
609
|
-
planCmd.option("--out <path>", "Override output path");
|
|
610
|
-
planCmd.action(async (opts) => {
|
|
611
|
-
try {
|
|
612
|
-
const { schedulePath, executionPath, catalogPath, rolesPath, viewpointsPath, projectContext, } = resolveProjectContext(opts);
|
|
613
|
-
const hasTask = typeof opts.task === "string" && opts.task.trim() !== "";
|
|
614
|
-
const hasDeliverable = typeof opts.deliverable === "string" && opts.deliverable.trim() !== "";
|
|
615
|
-
const hasRegister = typeof opts.register === "string" && opts.register.trim() !== "";
|
|
616
|
-
if ([hasTask, hasDeliverable, hasRegister].filter(Boolean).length !== 1) {
|
|
617
|
-
throw new Error("Specify exactly one of --task, --deliverable, or --register.");
|
|
618
|
-
}
|
|
619
|
-
const projectId = resolveProjectId(opts);
|
|
620
|
-
const outOverride = typeof opts.out === "string" && opts.out.trim() ? opts.out.trim() : undefined;
|
|
621
|
-
// Stem priority: --out → derive from the given filename (overwrite it); else --task → the
|
|
622
|
-
// fixed task id, so the plan/result share one canonical name with claim / run --track-state
|
|
623
|
-
// and an in-place run can be adopted without renaming; else --deliverable / --register → a
|
|
624
|
-
// new unique stem per generation (no task identity; avoids doc-index id collisions).
|
|
625
|
-
let outPath;
|
|
626
|
-
if (hasRegister) {
|
|
627
|
-
const pjrId = normalizePjrId(opts.register);
|
|
628
|
-
const { registerPaths, item } = resolveRegisterRunTarget(projectId, pjrId);
|
|
629
|
-
const stem = outOverride
|
|
630
|
-
? stemFromPlanPath(outOverride)
|
|
631
|
-
: buildInPlaceStem(pjrId.toLowerCase());
|
|
632
|
-
const generated = await generateRegisterPlan({
|
|
633
|
-
executionPath,
|
|
634
|
-
projectId,
|
|
635
|
-
registerPaths,
|
|
636
|
-
item,
|
|
637
|
-
stem,
|
|
638
|
-
...(outOverride ? { outPath: outOverride } : {}),
|
|
639
|
-
});
|
|
640
|
-
outPath = generated.planPath;
|
|
641
|
-
}
|
|
642
|
-
else if (hasTask) {
|
|
643
|
-
const task = buildTaskView(schedulePath, executionPath, opts.task.trim());
|
|
644
|
-
const stem = outOverride ? stemFromPlanPath(outOverride) : opts.task.trim();
|
|
645
|
-
outPath = await generateSinglePlan({
|
|
646
|
-
executionPath,
|
|
647
|
-
projectId,
|
|
648
|
-
catalogPath: catalogPath ?? "",
|
|
649
|
-
rolesPath,
|
|
650
|
-
viewpointsPath,
|
|
651
|
-
projectContext,
|
|
652
|
-
task,
|
|
653
|
-
stem,
|
|
654
|
-
...(outOverride ? { outPath: outOverride } : {}),
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
|
-
else {
|
|
658
|
-
const target = resolveDeliverableTarget(catalogPath ?? "", opts.deliverable.trim());
|
|
659
|
-
const track = typeof opts.track === "string" && opts.track.trim() ? opts.track.trim() : undefined;
|
|
660
|
-
const owner = resolveOwnerForLocalId(schedulePath, target.localId, track);
|
|
661
|
-
const stem = outOverride ? stemFromPlanPath(outOverride) : buildInPlaceStem(target.slug);
|
|
662
|
-
outPath = await generateDeliverablePlan({
|
|
663
|
-
executionPath,
|
|
664
|
-
projectId,
|
|
665
|
-
catalogPath: catalogPath ?? "",
|
|
666
|
-
rolesPath,
|
|
667
|
-
viewpointsPath,
|
|
668
|
-
projectContext,
|
|
669
|
-
target,
|
|
670
|
-
mode: parseTaskMode(opts.mode),
|
|
671
|
-
...(opts.approach ? { approach: parseApproach(opts.approach) } : {}),
|
|
672
|
-
...(owner ? { owner } : {}),
|
|
673
|
-
stem,
|
|
674
|
-
...(outOverride ? { outPath: outOverride } : {}),
|
|
675
|
-
});
|
|
676
|
-
}
|
|
677
|
-
process.stdout.write(`Generated: ${outPath}\n`);
|
|
678
|
-
exitWithCode(true);
|
|
679
|
-
}
|
|
680
|
-
catch (error) {
|
|
681
|
-
printCommandError(error, false);
|
|
682
|
-
}
|
|
683
|
-
});
|
|
684
|
-
const archiveCmd = exec
|
|
685
|
-
.command("archive")
|
|
686
|
-
.description("Archive a completed plan to exec/plans/done/ (or delete it)");
|
|
687
|
-
addProjectOptions(archiveCmd);
|
|
688
|
-
archiveCmd.option("--task <taskId>", "Scheduled task ID whose plan to archive");
|
|
689
|
-
archiveCmd.option("--deliverable <localId>", "Catalog deliverable local_id (unique project-wide)");
|
|
690
|
-
archiveCmd.option("--plan <path>", "Plan file to archive (for unique-named in-place plans)");
|
|
691
|
-
archiveCmd.option("--delete", "Delete the plan instead of moving it to done/", false);
|
|
692
|
-
archiveCmd.action((opts) => {
|
|
693
|
-
try {
|
|
694
|
-
const { executionPath, catalogPath } = resolveProjectContext(opts);
|
|
695
|
-
const hasTask = typeof opts.task === "string" && opts.task.trim() !== "";
|
|
696
|
-
const hasDeliverable = typeof opts.deliverable === "string" && opts.deliverable.trim() !== "";
|
|
697
|
-
const hasPlan = typeof opts.plan === "string" && opts.plan.trim() !== "";
|
|
698
|
-
if ([hasTask, hasDeliverable, hasPlan].filter(Boolean).length !== 1) {
|
|
699
|
-
throw new Error("Specify exactly one of --task, --deliverable, or --plan.");
|
|
700
|
-
}
|
|
701
|
-
// `archivePlan` rebuilds `<slug>-plan.md`; for --plan the stem recovered from the filename
|
|
702
|
-
// is that slug, so a unique-named in-place plan archives to done/ like a fixed-name one.
|
|
703
|
-
const slug = hasPlan
|
|
704
|
-
? stemFromPlanPath(opts.plan.trim())
|
|
705
|
-
: hasTask
|
|
706
|
-
? opts.task.trim()
|
|
707
|
-
: resolveDeliverableTarget(catalogPath ?? "", opts.deliverable.trim()).slug;
|
|
708
|
-
const result = archivePlan({ executionPath, slug, delete: !!opts.delete });
|
|
709
|
-
process.stdout.write(result.deleted ? `Deleted: ${result.from}\n` : `Archived: ${result.from} -> ${result.to}\n`);
|
|
710
|
-
exitWithCode(true);
|
|
711
|
-
}
|
|
712
|
-
catch (error) {
|
|
713
|
-
printCommandError(error, false);
|
|
714
|
-
}
|
|
715
|
-
});
|
|
716
|
-
const scmd = exec
|
|
717
|
-
.command("scheduler")
|
|
718
|
-
.description("Auto-claim next task safely (with project-level lock).");
|
|
719
|
-
addProjectOptions(scmd);
|
|
720
|
-
scmd.requiredOption("--by <actor>", "Actor (agent name)");
|
|
721
|
-
addOwnerOptions(scmd);
|
|
722
|
-
scmd.option("--strategy <strategy>", "critical-first|fifo (defaults to member profile or critical-first)");
|
|
723
|
-
scmd.option("--dry-run", "Do not write; print selected task only", false);
|
|
724
|
-
scmd.option("--msg <message>", "Claim message", "auto-claim");
|
|
725
|
-
addLockOptions(scmd);
|
|
726
|
-
scmd.action(async (opts) => {
|
|
727
|
-
let lockDir = "";
|
|
728
|
-
try {
|
|
729
|
-
const { schedulePath, executionPath, catalogPath } = resolveProjectContext(opts);
|
|
730
|
-
const actor = requireNonEmpty("by", opts.by);
|
|
731
|
-
const roster = loadRosterForOpts(opts);
|
|
732
|
-
assertValidActor(actor, roster);
|
|
733
|
-
const strategy = resolveSchedulerStrategy(opts, actor, roster);
|
|
734
|
-
const dryRun = !!opts.dryRun;
|
|
735
|
-
const msg = String(opts.msg ?? "auto-claim");
|
|
736
|
-
const claimOwner = resolveClaimOwner(opts, actor, roster);
|
|
737
|
-
const allowOwnerMismatch = !!opts.allowOwnerMismatch;
|
|
738
|
-
const allowMultipleDoing = !!opts.allowMultipleDoing;
|
|
739
|
-
const lockTimeoutMs = Number(opts.lockTimeoutMs);
|
|
740
|
-
const lockStaleMs = Number(opts.lockStaleMs);
|
|
741
|
-
lockDir = acquireSchedulerLock(schedulePath, { actor, lockTimeoutMs, lockStaleMs });
|
|
742
|
-
const state = loadValidatedExecState(schedulePath);
|
|
743
|
-
if (!state)
|
|
744
|
-
return;
|
|
745
|
-
if (!ensureActorCanClaimNext(state.snapshot, actor, allowMultipleDoing))
|
|
746
|
-
return;
|
|
747
|
-
const ready = computeReadyIds(state.schedule, state.snapshot);
|
|
748
|
-
let cpm = null;
|
|
749
|
-
try {
|
|
750
|
-
cpm = computeCpm(state.schedule, schedulePath);
|
|
751
|
-
}
|
|
752
|
-
catch {
|
|
753
|
-
cpm = null;
|
|
754
|
-
}
|
|
755
|
-
// Collect all valid owner labels for this actor.
|
|
756
|
-
// Single-role actors use claimOwner; multi-role actors (e.g. indie) check every role.
|
|
757
|
-
const actorAllRoles = findRosterMember(roster, actor)
|
|
758
|
-
?.roles?.map((r) => r.trim().toUpperCase())
|
|
759
|
-
.filter((r) => KNOWN_OWNER_LABELS.includes(r)) ??
|
|
760
|
-
[];
|
|
761
|
-
const ownerCandidates = actorAllRoles.length > 1 ? actorAllRoles : claimOwner ? [claimOwner] : [];
|
|
762
|
-
const readyForOwner = ready.filter((taskId) => {
|
|
763
|
-
if (ownerCandidates.length === 0) {
|
|
764
|
-
return canClaimTask(state.schedule, state.snapshot, taskId, claimOwner, allowOwnerMismatch).ok;
|
|
765
|
-
}
|
|
766
|
-
// Pass if any of the actor's roles can claim the task
|
|
767
|
-
return ownerCandidates.some((role) => canClaimTask(state.schedule, state.snapshot, taskId, role, allowOwnerMismatch).ok);
|
|
768
|
-
});
|
|
769
|
-
// Filter by actor mode and execution type from ready.json.
|
|
770
|
-
// Agent actors (with mode set) skip tasks with wrong mode or execution: human.
|
|
771
|
-
const actorMember = findRosterMember(roster, actor);
|
|
772
|
-
const actorMode = actorMember?.mode;
|
|
773
|
-
const isAgent = actorMember?.type === "agent";
|
|
774
|
-
let readyForMode = readyForOwner;
|
|
775
|
-
if (actorMode || isAgent) {
|
|
776
|
-
const readyJsonPath = join(generatedDirForProject(schedulePath), "ready.json");
|
|
777
|
-
if (existsSync(readyJsonPath)) {
|
|
778
|
-
const readySnapshot = readReadySnapshot(readyJsonPath);
|
|
779
|
-
const taskInfoMap = new Map(readySnapshot.tasks.map((t) => [t.id, t]));
|
|
780
|
-
readyForMode = readyForOwner.filter((taskId) => {
|
|
781
|
-
const taskInfo = taskInfoMap.get(taskId);
|
|
782
|
-
if (!taskInfo)
|
|
783
|
-
return true;
|
|
784
|
-
// Agents skip manual tasks
|
|
785
|
-
if (isAgent && (taskInfo.execution ?? "agent") === "human")
|
|
786
|
-
return false;
|
|
787
|
-
// Mode filter: skip tasks with different mode
|
|
788
|
-
if (actorMode && (taskInfo.mode ?? "edit") !== actorMode)
|
|
789
|
-
return false;
|
|
790
|
-
return true;
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
const next = selectNextTask(readyForMode, cpm, strategy);
|
|
795
|
-
if (!next) {
|
|
796
|
-
if (readyForOwner.length > 0 && (actorMode || isAgent)) {
|
|
797
|
-
process.stdout.write(`No ready ${actorMode ?? "agent"} task for ${actor}. ` +
|
|
798
|
-
`${readyForOwner.length} task(s) ready but require different mode or are human-only.\n`);
|
|
799
|
-
}
|
|
800
|
-
else if (ready.length > 0 && !allowOwnerMismatch) {
|
|
801
|
-
process.stdout.write(`No ready task assigned to owner ${claimOwner}. Use --owner <${KNOWN_OWNER_LABELS_TEXT}>, SPECDOJO_OWNER, or --allow-owner-mismatch.\n`);
|
|
802
|
-
}
|
|
803
|
-
else {
|
|
804
|
-
process.stdout.write("No ready task to claim.\n");
|
|
805
|
-
}
|
|
806
|
-
exitWithCode(true);
|
|
807
|
-
return;
|
|
808
|
-
}
|
|
809
|
-
if (dryRun) {
|
|
810
|
-
process.stdout.write(next + "\n");
|
|
811
|
-
exitWithCode(true);
|
|
812
|
-
return;
|
|
813
|
-
}
|
|
814
|
-
// For multi-role actors, use the role that matches the selected task's owner.
|
|
815
|
-
const plannedOwner = state.schedule.nodes.get(next)?.owner ?? "";
|
|
816
|
-
const effectiveClaimOwner = ownerCandidates.length > 1 && ownerCandidates.includes(plannedOwner)
|
|
817
|
-
? plannedOwner
|
|
818
|
-
: claimOwner;
|
|
819
|
-
const ev = {
|
|
820
|
-
v: 1,
|
|
821
|
-
ts: nowUtcIsoSeconds(),
|
|
822
|
-
type: "claim",
|
|
823
|
-
task_id: next,
|
|
824
|
-
by: actor,
|
|
825
|
-
msg,
|
|
826
|
-
meta: {
|
|
827
|
-
claim_owner: effectiveClaimOwner,
|
|
828
|
-
planned_owner: plannedOwner || undefined,
|
|
829
|
-
scheduler_strategy: strategy,
|
|
830
|
-
claimed_via: "dojo-exec-scheduler",
|
|
831
|
-
},
|
|
832
|
-
};
|
|
833
|
-
if (ev.meta?.planned_owner &&
|
|
834
|
-
ev.meta.claim_owner !== ev.meta.planned_owner &&
|
|
835
|
-
allowOwnerMismatch) {
|
|
836
|
-
ev.meta.owner_override = true;
|
|
837
|
-
}
|
|
838
|
-
const out = writeEventFile(schedulePath, ev);
|
|
839
|
-
// Await the scaffold (it formats the result with Prettier asynchronously). Firing it without
|
|
840
|
-
// awaiting leaks a promise that can read/write the result after the caller tears down its
|
|
841
|
-
// working directory, surfacing as an ENOENT unhandled rejection.
|
|
842
|
-
await scaffoldClaimResult({
|
|
843
|
-
schedulePath,
|
|
844
|
-
executionPath,
|
|
845
|
-
catalogPath,
|
|
846
|
-
state,
|
|
847
|
-
taskId: next,
|
|
848
|
-
projectId: resolveProjectId(opts),
|
|
849
|
-
actor,
|
|
850
|
-
startedAt: ev.ts,
|
|
851
|
-
});
|
|
852
|
-
process.stdout.write(out + "\n");
|
|
853
|
-
exitWithCode(true);
|
|
854
|
-
}
|
|
855
|
-
catch (error) {
|
|
856
|
-
printCommandError(error);
|
|
857
|
-
}
|
|
858
|
-
finally {
|
|
859
|
-
if (lockDir) {
|
|
860
|
-
try {
|
|
861
|
-
releaseSchedulerLock(lockDir);
|
|
862
|
-
}
|
|
863
|
-
catch {
|
|
864
|
-
// ignore
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
});
|
|
869
|
-
registerRunCommand(exec);
|
|
870
|
-
registerResumeCommand(exec);
|
|
871
|
-
registerCycleCommand(exec);
|
|
872
|
-
registerExecWorktreeCommands(exec);
|
|
873
|
-
registerExecTrialCommands(exec);
|
|
874
|
-
// exec scaffold: creates project setup files (viewpoints etc.) or provider templates
|
|
875
|
-
const scaffoldCmd = exec
|
|
876
|
-
.command("scaffold")
|
|
877
|
-
.description("Scaffold project setup files (pm-review-viewpoints.yaml) or provider templates (--provider)");
|
|
878
|
-
addProjectOptions(scaffoldCmd);
|
|
879
|
-
scaffoldCmd.option("--force", "Overwrite existing files", false);
|
|
880
|
-
scaffoldCmd.option("--provider <name>", "Copy the provider's agent/settings templates (templates/<name>) into the repository");
|
|
881
|
-
scaffoldCmd.option("--dry-run", "Show planned files without writing", false);
|
|
882
|
-
scaffoldCmd.action(async (opts) => {
|
|
883
|
-
try {
|
|
884
|
-
if (opts.provider) {
|
|
885
|
-
await runProviderScaffold(String(opts.provider), {
|
|
886
|
-
packageRoot: specdojoPackageRootDir(),
|
|
887
|
-
repoRoot: specdojoRootDir(),
|
|
888
|
-
force: !!opts.force,
|
|
889
|
-
dryRun: !!opts.dryRun,
|
|
890
|
-
});
|
|
891
|
-
return;
|
|
892
|
-
}
|
|
893
|
-
const { config } = loadConfig();
|
|
894
|
-
if (!config)
|
|
895
|
-
throw new Error("specdojo.config.json not found. Run: specdojo config init");
|
|
896
|
-
const projectId = opts.project?.trim() ||
|
|
897
|
-
process.env.SPECDOJO_PROJECT?.trim() ||
|
|
898
|
-
config.current_project?.trim() ||
|
|
899
|
-
Object.keys(config.projects)[0] ||
|
|
900
|
-
"";
|
|
901
|
-
if (!projectId)
|
|
902
|
-
throw new Error("No project specified. Use --project <id>.");
|
|
903
|
-
const project = config.projects[projectId];
|
|
904
|
-
if (!project)
|
|
905
|
-
throw new Error(`Unknown project: ${projectId}`);
|
|
906
|
-
const baseDir = specdojoRootDir();
|
|
907
|
-
const commonPath = join(baseDir, "docs", "ja", "specdojo", "standards", "pm-review-viewpoints.yaml");
|
|
908
|
-
const viewpointsRel = getProjectViewpointsPath(project);
|
|
909
|
-
if (viewpointsRel) {
|
|
910
|
-
const outputPath = pathResolve(baseDir, viewpointsRel);
|
|
911
|
-
const result = scaffoldViewpoints({
|
|
912
|
-
commonPath,
|
|
913
|
-
projectId,
|
|
914
|
-
outputPath,
|
|
915
|
-
force: !!opts.force,
|
|
916
|
-
});
|
|
917
|
-
if (result.written) {
|
|
918
|
-
process.stdout.write(`Written: ${outputPath}\n`);
|
|
919
|
-
}
|
|
920
|
-
else {
|
|
921
|
-
process.stdout.write(`Skipped (already exists): ${outputPath}\n`);
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
else {
|
|
925
|
-
process.stdout.write(`viewpoints_path not set for project '${projectId}'. Add it to specdojo.config.json.\n`);
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
catch (error) {
|
|
929
|
-
printCommandError(error, false);
|
|
930
|
-
}
|
|
931
|
-
});
|
|
932
|
-
const statusCmd = exec.command("status").description("Show tasks filtered by state and actor");
|
|
933
|
-
addProjectOptions(statusCmd);
|
|
934
|
-
statusCmd.option("--by <actor>", "Filter by actor nickname");
|
|
935
|
-
statusCmd.option("--state <state>", "Filter by state: todo|doing|blocked|done|cancelled (default: doing)", "doing");
|
|
936
|
-
statusCmd.action((opts) => {
|
|
937
|
-
try {
|
|
938
|
-
const { schedulePath } = resolveProjectContext(opts);
|
|
939
|
-
// Compute state directly from events (not from cached state.json)
|
|
940
|
-
const state = loadValidatedExecState(schedulePath);
|
|
941
|
-
if (!state)
|
|
942
|
-
return;
|
|
943
|
-
const snapshot = state.snapshot;
|
|
944
|
-
const schedule = state.schedule;
|
|
945
|
-
const filterState = String(opts.state ?? "doing");
|
|
946
|
-
const filterBy = typeof opts.by === "string" ? opts.by.trim() : undefined;
|
|
947
|
-
const entries = Object.entries(snapshot.tasks)
|
|
948
|
-
.filter(([, cs]) => cs.state === filterState)
|
|
949
|
-
.filter(([, cs]) => !filterBy || cs.last_by === filterBy)
|
|
950
|
-
.sort(([a], [b]) => a.localeCompare(b));
|
|
951
|
-
if (entries.length === 0) {
|
|
952
|
-
const byMsg = filterBy ? ` for ${filterBy}` : "";
|
|
953
|
-
process.stdout.write(`No ${filterState} tasks${byMsg}.\n`);
|
|
954
|
-
exitWithCode(true);
|
|
955
|
-
return;
|
|
956
|
-
}
|
|
957
|
-
const byMsg = filterBy ? ` for ${filterBy}` : "";
|
|
958
|
-
process.stdout.write(`${filterState} tasks${byMsg}:\n\n`);
|
|
959
|
-
const rows = entries.map(([taskId, cs]) => ({
|
|
960
|
-
taskId,
|
|
961
|
-
name: schedule.nodes.get(taskId)?.name ?? "-",
|
|
962
|
-
by: cs.last_by ?? "-",
|
|
963
|
-
ts: cs.last_ts ?? "-",
|
|
964
|
-
}));
|
|
965
|
-
// Size every column to its longest value (including the header) so nothing is truncated.
|
|
966
|
-
// displayWidth counts full-width (CJK) characters as 2 columns so the table stays aligned.
|
|
967
|
-
const taskWidth = Math.max("task_id".length, ...rows.map((r) => displayWidth(r.taskId)));
|
|
968
|
-
const nameWidth = Math.max("name".length, ...rows.map((r) => displayWidth(r.name)));
|
|
969
|
-
const byWidth = Math.max("by".length, ...rows.map((r) => displayWidth(r.by)));
|
|
970
|
-
const tsWidth = Math.max("claimed_at".length, ...rows.map((r) => displayWidth(r.ts)));
|
|
971
|
-
process.stdout.write(` ${padEndDisplay("task_id", taskWidth)} ${padEndDisplay("name", nameWidth)} ${padEndDisplay("by", byWidth)} claimed_at\n`);
|
|
972
|
-
process.stdout.write(` ${"-".repeat(taskWidth)} ${"-".repeat(nameWidth)} ${"-".repeat(byWidth)} ${"-".repeat(tsWidth)}\n`);
|
|
973
|
-
for (const r of rows) {
|
|
974
|
-
// The trailing claimed_at column is left unpadded to avoid stray trailing whitespace.
|
|
975
|
-
process.stdout.write(` ${padEndDisplay(r.taskId, taskWidth)} ${padEndDisplay(r.name, nameWidth)} ${padEndDisplay(r.by, byWidth)} ${r.ts}\n`);
|
|
976
|
-
}
|
|
977
|
-
exitWithCode(true);
|
|
978
|
-
}
|
|
979
|
-
catch (error) {
|
|
980
|
-
printCommandError(error, false);
|
|
981
|
-
}
|
|
982
|
-
});
|
|
983
|
-
const wcmd = exec.command("where").description("Print resolved paths");
|
|
984
|
-
addProjectOptions(wcmd);
|
|
985
|
-
wcmd.action((opts) => {
|
|
986
|
-
try {
|
|
987
|
-
const resolvedPaths = resolveProjectContext(opts);
|
|
988
|
-
process.stdout.write(`schedule-path: ${resolvedPaths.schedulePath}\n`);
|
|
989
|
-
process.stdout.write(`execution-path: ${resolvedPaths.executionPath}\n`);
|
|
990
|
-
const projectPath = resolvedPaths.schedulePath;
|
|
991
|
-
process.stdout.write(`exec/events : ${eventsDirForProject(projectPath)}\n`);
|
|
992
|
-
process.stdout.write(`generated : ${generatedDirForProject(projectPath)}\n`);
|
|
993
|
-
process.stdout.write(`scheduler-lock: ${schedulerLockPath(projectPath)}\n`);
|
|
994
|
-
}
|
|
995
|
-
catch (error) {
|
|
996
|
-
printCommandError(error, false);
|
|
997
|
-
}
|
|
998
|
-
});
|
|
999
|
-
}
|
|
1
|
+
export { resolveClaimOwner } from "./exec-core.js";
|
|
2
|
+
export { registerExecCommands } from "./exec-commands.js";
|