specdojo 0.3.0 → 0.4.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/CHANGELOG.md +65 -0
- package/README.md +77 -18
- package/dist/catalog/build-references.js +144 -0
- package/dist/catalog/build-render.js +32 -0
- package/dist/{catalog-build.js → catalog/build.js} +18 -295
- package/dist/{catalog.js → catalog/catalog.js} +11 -11
- package/dist/{catalog-generate.js → catalog/generate.js} +13 -16
- package/dist/catalog/paths.js +1 -0
- package/dist/{catalog-plan-generate.js → catalog/plan-generate.js} +5 -5
- package/dist/{catalog-plan.js → catalog/plan.js} +9 -9
- package/dist/{catalog-scaffold.js → catalog/scaffold.js} +6 -6
- package/dist/{agent.js → commands/agent.js} +11 -11
- package/dist/{build-command.js → commands/build.js} +2 -2
- package/dist/{init-command.js → commands/init.js} +103 -37
- package/dist/{orchestrator.js → commands/orchestrator.js} +2 -2
- package/dist/{watch.js → commands/watch.js} +3 -3
- package/dist/dashboard/dashboard-timeline.js +175 -0
- package/dist/{dashboard.js → dashboard/dashboard.js} +16 -549
- package/dist/dashboard/exec-records.js +105 -0
- package/dist/dashboard/routines.js +256 -0
- package/dist/dashboard/shared.js +14 -0
- package/dist/{timeline-build.js → dashboard/timeline-build.js} +2 -1
- package/dist/{timeline.js → dashboard/timeline.js} +1 -1
- package/dist/{deliverable.js → deliverable/deliverable.js} +5 -5
- package/dist/{deliverable-trash.js → deliverable/trash.js} +7 -7
- package/dist/{devcontainer-command.js → devcontainer/command.js} +5 -3
- package/dist/{devcontainer-scaffold.js → devcontainer/scaffold.js} +94 -2
- package/dist/{doc-index.js → docs/doc-index.js} +3 -3
- package/dist/{frontmatter-namespace.js → docs/frontmatter-namespace.js} +2 -2
- package/dist/{index-command.js → docs/index-command.js} +1 -1
- package/dist/docs/template-resolution.js +1 -0
- package/dist/{viewpoint-document-kinds-check.js → docs/viewpoint-document-kinds-check.js} +3 -3
- package/dist/{yaml-pages-command.js → docs/yaml-pages-command.js} +1 -1
- package/dist/{yaml-pages.js → docs/yaml-pages.js} +5 -5
- package/dist/{exec-agent-config.js → exec/agent-config.js} +33 -4
- package/dist/{exec-agent-git-state.js → exec/agent-git-state.js} +1 -1
- package/dist/{exec-agent-protected-config.js → exec/agent-protected-config.js} +1 -1
- package/dist/{exec.js → exec/commands.js} +22 -467
- package/dist/exec/core.js +457 -0
- package/dist/{exec-events.js → exec/events.js} +2 -2
- package/dist/{exec-evidence.js → exec/evidence.js} +11 -6
- package/dist/exec/exec.js +2 -0
- package/dist/exec/format.js +1 -0
- package/dist/{exec-handoff.js → exec/handoff.js} +13 -12
- package/dist/{exec-limit.js → exec/limit.js} +93 -12
- package/dist/{exec-parent-validation.js → exec/parent-validation.js} +4 -4
- package/dist/{exec-pipeline-state.js → exec/pipeline-state.js} +16 -2
- package/dist/{exec-plans.js → exec/plans-core.js} +97 -468
- package/dist/exec/plans-generation.js +249 -0
- package/dist/exec/plans-storage.js +131 -0
- package/dist/exec/plans.js +3 -0
- package/dist/{exec-project.js → exec/project.js} +1 -1
- package/dist/{exec-protection-handoff.js → exec/protection-handoff.js} +3 -3
- package/dist/{exec-register-resume.js → exec/register-resume.js} +2 -2
- package/dist/{exec-register.js → exec/register.js} +92 -9
- package/dist/exec/repo-integration-git.js +23 -0
- package/dist/exec/repo-integration-sync.js +264 -0
- package/dist/{exec-repo-integration.js → exec/repo-integration.js} +13 -287
- package/dist/{exec-repo-trace.js → exec/repo-trace.js} +3 -3
- package/dist/exec/reporter-output.js +206 -0
- package/dist/{exec-reporter.js → exec/reporter.js} +29 -216
- package/dist/{exec-results.js → exec/results.js} +277 -36
- package/dist/exec/run/agent-pipeline.js +276 -0
- package/dist/exec/run/agent.js +583 -0
- package/dist/exec/run/in-place.js +570 -0
- package/dist/exec/run/job.js +746 -0
- package/dist/exec/run/lifecycle-commands.js +530 -0
- package/dist/{exec-run-lock.js → exec/run/lock.js} +4 -3
- package/dist/exec/run/mode-shared.js +140 -0
- package/dist/exec/run/register-command.js +252 -0
- package/dist/exec/run/register-core.js +411 -0
- package/dist/exec/run/register-mode.js +210 -0
- package/dist/exec/run/register-resume.js +398 -0
- package/dist/exec/run/register-state.js +325 -0
- package/dist/exec/run/register-worktree.js +540 -0
- package/dist/exec/run/run.js +11 -0
- package/dist/exec/run/schedule-mode.js +294 -0
- package/dist/exec/run/schedule-prepare.js +366 -0
- package/dist/exec/run/schedule-task.js +599 -0
- package/dist/exec/run/shared.js +449 -0
- package/dist/{exec-schedule-calendar.js → exec/schedule/calendar.js} +1 -1
- package/dist/{exec-schedule-cpm.js → exec/schedule/cpm.js} +2 -2
- package/dist/{exec-schedule-gantt-chart-render.js → exec/schedule/gantt-chart-render.js} +2 -2
- package/dist/exec/schedule/gantt-chart.js +2 -0
- package/dist/{exec-schedule-hash.js → exec/schedule/hash.js} +2 -2
- package/dist/exec/schedule/index.js +1 -0
- package/dist/{exec-schedule-initial.js → exec/schedule/initial.js} +2 -2
- package/dist/{exec-schedule-progress.js → exec/schedule/progress.js} +2 -2
- package/dist/{exec-schedule-ready.js → exec/schedule/ready.js} +2 -2
- package/dist/{exec-schedule.js → exec/schedule/schedule.js} +11 -11
- package/dist/exec/shared.js +63 -0
- package/dist/exec/slot-lock.js +1 -0
- package/dist/{exec-strategy.js → exec/strategy.js} +2 -2
- package/dist/{exec-task-repos.js → exec/task-repos.js} +2 -2
- package/dist/{exec-task-view.js → exec/task-view.js} +4 -4
- package/dist/{exec-trial.js → exec/trial-commands.js} +23 -388
- package/dist/exec/trial-core.js +371 -0
- package/dist/exec/trial.js +2 -0
- package/dist/{exec-worktree-command.js → exec/worktree-command.js} +25 -23
- package/dist/exec/worktree-ops-commit.js +672 -0
- package/dist/exec/worktree-ops-lifecycle.js +297 -0
- package/dist/exec/worktree-ops-merge.js +344 -0
- package/dist/exec/worktree-ops.js +3 -0
- package/dist/exec/worktree.js +305 -0
- 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/grade.js +19 -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 → grade/result.js} +7 -96
- package/dist/grade/target-discovery.js +265 -0
- package/dist/grade/targets.js +435 -0
- package/dist/{job.js → job/definition.js} +32 -574
- package/dist/job/job.js +568 -0
- package/dist/{kata-command.js → kata/command.js} +4 -4
- package/dist/{kata.js → kata/kata.js} +5 -5
- package/dist/register/approach.js +134 -0
- package/dist/register/command-types.js +1 -0
- package/dist/register/core.js +369 -0
- package/dist/register/create-commands.js +352 -0
- package/dist/{register-date.js → register/date.js} +1 -1
- package/dist/register/derivation.js +163 -0
- package/dist/{register-event-merge.js → register/event-merge.js} +32 -3
- package/dist/{register-events.js → register/events.js} +12 -6
- package/dist/{register-history.js → register/history.js} +7 -6
- package/dist/{register-item.js → register/item.js} +28 -10
- package/dist/register/lifecycle-lock.js +5 -0
- package/dist/register/maintenance-commands.js +193 -0
- package/dist/{register-migrate-timestamps.js → register/migrate-timestamps.js} +3 -3
- package/dist/register/migration.js +268 -0
- package/dist/register/register.js +404 -0
- package/dist/register/renumber.js +341 -0
- package/dist/register/transition-commands.js +248 -0
- package/dist/register/update.js +230 -0
- package/dist/register/views.js +296 -0
- package/dist/{review-grade.js → review/grade.js} +2 -2
- package/dist/{review-plan.js → review/plan.js} +5 -5
- package/dist/routine/definition.js +401 -0
- package/dist/{routine.js → routine/routine.js} +50 -419
- package/dist/{schedule-approach.js → schedule/approach.js} +9 -9
- package/dist/{schedule-build.js → schedule/build.js} +7 -4
- package/dist/{schedule.js → schedule/schedule.js} +9 -9
- package/dist/schedule/strategy-generate-document.js +273 -0
- package/dist/schedule/strategy-generate-scope.js +199 -0
- package/dist/schedule/strategy-generate.js +348 -0
- package/dist/shared/agent-types.js +23 -0
- package/dist/shared/artifact-path.js +9 -0
- package/dist/{build-if-stale.js → shared/build-if-stale.js} +1 -1
- package/dist/shared/catalog-render.js +115 -0
- package/dist/{exec-slot-lock.js → shared/cross-process-lock.js} +3 -1
- package/dist/shared/fs.js +30 -0
- package/dist/shared/git.js +316 -0
- package/dist/shared/grade-result.js +94 -0
- package/dist/{package-paths.js → shared/package-paths.js} +3 -3
- package/dist/shared/plan-templates.js +114 -0
- package/dist/{exec-provider-scaffold.js → shared/provider-scaffold.js} +3 -1
- package/dist/shared/random.js +4 -0
- package/dist/{exec-schedule-index.js → shared/schedule-index.js} +3 -1
- package/dist/shared/schedule-paths.js +9 -0
- package/dist/{specdojo-config.js → shared/specdojo-config.js} +96 -9
- package/dist/{exec-shared.js → shared/text.js} +0 -134
- package/dist/shared/time.js +28 -0
- package/dist/shared/yaml.js +28 -0
- package/dist/specdojo.js +22 -22
- package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +29 -17
- package/docs/ja/specdojo/exec-templates/xep-register-investigate-template.md +1 -2
- package/docs/ja/specdojo/exec-templates/xep-register-template.md +1 -2
- package/docs/ja/specdojo/exec-templates/xer-template.md +1 -3
- package/docs/ja/specdojo/exec-templates/xrp-job-template.md +6 -4
- package/docs/ja/specdojo/guides/exec-config-guide.md +97 -22
- package/docs/ja/specdojo/guides/exec-operation-guide.md +145 -12
- package/docs/ja/specdojo/guides/exec-worktree-guide.md +2 -0
- package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +51 -18
- package/docs/ja/specdojo/guides/quick-start-guide.md +81 -16
- package/docs/ja/specdojo/guides/register-operation-guide.md +2 -1
- package/docs/ja/specdojo/guides/remote-host-development-guide.md +10 -1
- package/docs/ja/specdojo/guides/review-guide.md +1 -1
- package/docs/ja/specdojo/guides/routine-operation-guide.md +6 -6
- package/docs/ja/specdojo/guides/use-case-guide.md +1 -1
- package/docs/ja/specdojo/references/command-reference.md +52 -28
- package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +17 -11
- package/docs/ja/specdojo/standards/job-definition-standard.md +20 -18
- package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +2 -2
- package/docs/ja/specdojo/templates/pjr-derived-items-template.md +22 -0
- package/docs/ja/specdojo/templates/pjr-index-template.md +1 -0
- package/docs/specdojo/schemas/v1/agent-members.schema.yaml +29 -2
- package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +20 -0
- package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +23 -0
- package/docs/specdojo/schemas/v1/job-run.schema.yaml +2 -2
- package/docs/specdojo/schemas/v1/job.schema.yaml +7 -0
- package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +26 -0
- package/docs/specdojo/schemas/v1/register-events.schema.yaml +3 -0
- package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +70 -7
- package/docs/specdojo/schemas/v1/routine-run.schema.yaml +1 -1
- package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +1 -1
- package/package.json +4 -5
- package/templates/antigravity/README.md +7 -3
- package/templates/antigravity/agent-members-snippet.yaml +108 -12
- package/templates/antigravity/exec-defaults-snippet.yaml +10 -13
- package/templates/claude/README.md +27 -3
- package/templates/claude/agents/claude-executor.md +0 -1
- package/templates/claude/agents/claude-reporter.md +2 -1
- package/templates/claude/agents/claude-review-executor.md +0 -1
- package/templates/codex/README.md +23 -4
- package/templates/devcontainer/devcontainer.json +2 -2
- package/templates/devcontainer/remote-host/specdojo-tmux.sh.sample +69 -0
- package/templates/devcontainer/remote-host/ssh-config.sample +16 -0
- package/templates/init-agent-members.yaml +75 -25
- package/templates/init-exec-defaults.yaml +26 -8
- package/templates/opencode/README.md +17 -3
- package/templates/opencode/agents/opencode-executor.md +0 -1
- package/templates/opencode/agents/opencode-reporter.md +2 -1
- package/templates/opencode/agents/opencode-review-executor.md +0 -1
- package/dist/exec-run.js +0 -6182
- package/dist/exec-schedule-gantt-chart.js +0 -2
- package/dist/exec-worktree-ops.js +0 -1292
- package/dist/exec-worktree.js +0 -446
- package/dist/grade.js +0 -3193
- package/dist/register.js +0 -2407
- package/dist/schedule-strategy-generate.js +0 -812
- package/templates/claude/agents/claude-expert-review-executor.md +0 -14
- /package/dist/{catalog-plan-prompt.js → catalog/plan-prompt.js} +0 -0
- /package/dist/{catalog-types.js → catalog/types.js} +0 -0
- /package/dist/{template-frontmatter.js → docs/template-frontmatter.js} +0 -0
- /package/dist/{role-types.js → exec/role-types.js} +0 -0
- /package/dist/{exec-schedule-gantt-chart-scope.js → exec/schedule/gantt-chart-scope.js} +0 -0
- /package/dist/{exec-types.js → exec/types.js} +0 -0
- /package/dist/{review-types.js → review/types.js} +0 -0
- /package/dist/{schedule-phase-sets.js → schedule/phase-sets.js} +0 -0
- /package/dist/{schedule-strategy-profiles.js → schedule/strategy-profiles.js} +0 -0
- /package/dist/{agent-response.js → shared/agent-response.js} +0 -0
- /package/dist/{catalog-paths.js → shared/catalog-paths.js} +0 -0
- /package/dist/{dist-freshness.js → shared/dist-freshness.js} +0 -0
- /package/dist/{git-environment.js → shared/git-environment.js} +0 -0
- /package/dist/{exec-format.js → shared/markdown-format.js} +0 -0
- /package/dist/{practice-id.js → shared/practice-id.js} +0 -0
- /package/dist/{spawn-self.js → shared/spawn-self.js} +0 -0
- /package/dist/{specdojo-gitignore.js → shared/specdojo-gitignore.js} +0 -0
- /package/dist/{template-resolution.js → shared/template-resolution.js} +0 -0
- /package/dist/{yaml-schema-modeline.js → shared/yaml-schema-modeline.js} +0 -0
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { relative, sep } from "node:path";
|
|
3
|
+
import { CrossProcessMutex } from "../shared/cross-process-lock.js";
|
|
4
|
+
import { gitOutput, gitResult, repoRelative, stageCommitTargets, worktreeStatusPaths, } from "../shared/git.js";
|
|
5
|
+
import { inlineCodeAnglePlaceholders } from "../shared/text.js";
|
|
6
|
+
import { atomicWriteFile, buildRegisterItemContent, derivedTopicNeedsWarning, generatePjrId, printDerivedTopicWarning, registerEventActor, REGISTER_TOPIC_RE, resolveRegisterPaths, slugify, validateFields, } from "./core.js";
|
|
7
|
+
import { registerCreateCommands, registerUpdateCommand } from "./create-commands.js";
|
|
8
|
+
import { normalizeRegisterTimestamp } from "./date.js";
|
|
9
|
+
import { validateDerivedFromDocs } from "./derivation.js";
|
|
10
|
+
import { appendRegisterEvent, deterministicRegisterEventId, readEmbeddedRegisterEvents, readRegisterEventsFromContent, registerEventFilePath, removeEmbeddedRegisterEvents, serializeRegisterEvents, validateRegisterEventDocs, } from "./events.js";
|
|
11
|
+
import { collectRegisterHistoryEvents } from "./history.js";
|
|
12
|
+
import { loadRegisterItemDocs, PJR_ID_ALPHABET, PJR_ID_RE, TERMINAL_STATUSES_SET, toCell, validateRegisterItemDocs, VALID_PRIORITIES, VALID_STATUSES, VALID_TYPES, } from "./item.js";
|
|
13
|
+
import { registerMaintenanceCommands } from "./maintenance-commands.js";
|
|
14
|
+
import { applyRegisterMigrationPlan, planRegisterMigration } from "./migration.js";
|
|
15
|
+
import { planRenumber, planRetopic, renumberPjrItem, retopicPjrItem, ticketTopicFromFilename, } from "./renumber.js";
|
|
16
|
+
import { registerTransitionCommands } from "./transition-commands.js";
|
|
17
|
+
import { applyItemUpdate, assertTerminalOperationAllowed, loadItemForUpdate, updateTicketStatusForItem, } from "./update.js";
|
|
18
|
+
import { generateDerivedViewFiles, loadRegisterItems, VALID_BUILD_SCOPES, writeDerivedViews, } from "./views.js";
|
|
19
|
+
import { specdojoRootDir } from "../shared/specdojo-config.js";
|
|
20
|
+
import { registerLifecyclePoolPath } from "./lifecycle-lock.js";
|
|
21
|
+
export { PJR_ID_ALPHABET, PJR_ID_RE, TERMINAL_STATUSES_SET, toCell, VALID_PRIORITIES, VALID_STATUSES, VALID_TYPES, };
|
|
22
|
+
export { REGISTER_TOPIC_RE, VALID_TICKET_STATUSES, buildRegisterItemContent, extractTableHeading, findMarkdownReferenceFiles, generatePjrId, injectRegisterRows, parsePjrIndex, resolveRegisterPaths, } from "./core.js";
|
|
23
|
+
export { applyRegisterMigrationPlan, planRegisterMigration, } from "./migration.js";
|
|
24
|
+
export { findItemById, findRegisterItem, generateDerivedViewFiles, injectViewSlots, loadRegisterItems, sortByRegisteredDesc, } from "./views.js";
|
|
25
|
+
export { parseTicketFilename, updateTicketFrontmatterStatus, updateTicketStatusForItem, } from "./update.js";
|
|
26
|
+
export { planRenumber, planRetopic, renumberPjrItem, renumberReferences, renumberTicketContent, retopicPjrItem, ticketTopicFromFilename, } from "./renumber.js";
|
|
27
|
+
// 作成する個票ファイル名と割り当て ID を算出する純粋関数。I/O を持たず、
|
|
28
|
+
// フィールド検証と ID 衝突検知だけを行う。ID を省略するとランダムに採番する。
|
|
29
|
+
export function planRegisterItem(opts) {
|
|
30
|
+
const existing = [...opts.existingIds];
|
|
31
|
+
const assignedId = opts.explicitId?.trim() || generatePjrId(existing);
|
|
32
|
+
validateFields({
|
|
33
|
+
status: opts.fields.status,
|
|
34
|
+
type: opts.fields.type,
|
|
35
|
+
priority: opts.fields.priority,
|
|
36
|
+
registeredAt: opts.fields.registeredAt,
|
|
37
|
+
due: opts.fields.due,
|
|
38
|
+
completedAt: opts.fields.completedAt,
|
|
39
|
+
id: assignedId,
|
|
40
|
+
});
|
|
41
|
+
if (existing.includes(assignedId)) {
|
|
42
|
+
throw new Error(`ID already exists in the project register: ${assignedId}`);
|
|
43
|
+
}
|
|
44
|
+
return { assignedId, ticketFilename: `${assignedId.toLowerCase()}-${opts.topic}.md` };
|
|
45
|
+
}
|
|
46
|
+
// ================================
|
|
47
|
+
// Error Handling & Shared Helpers
|
|
48
|
+
// ================================
|
|
49
|
+
// register 系コマンドのエラーは Unix/CLI の慣習に合わせて stderr へ書く。
|
|
50
|
+
// 正常出力(更新内容・生成パス・警告など)は stdout のまま残し、エラーだけを分離する。
|
|
51
|
+
export function printCommandError(error) {
|
|
52
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
53
|
+
process.stderr.write(message + "\n");
|
|
54
|
+
process.exitCode = 1;
|
|
55
|
+
}
|
|
56
|
+
function addProjectOption(cmd) {
|
|
57
|
+
return cmd.option("--project <projectId>", "Project id in specdojo.config.json");
|
|
58
|
+
}
|
|
59
|
+
function assertRegisterItemCommitTargetsClean(context, view) {
|
|
60
|
+
if (!view.ticketPath)
|
|
61
|
+
return;
|
|
62
|
+
context.assertCommitTargetsClean([
|
|
63
|
+
view.ticketPath,
|
|
64
|
+
registerEventFilePath(context.paths.projectRegisterPath, view.id),
|
|
65
|
+
]);
|
|
66
|
+
}
|
|
67
|
+
function addRegisterCommitOptions(cmd) {
|
|
68
|
+
return cmd
|
|
69
|
+
.option("--commit", "Take the register lifecycle lock, rebuild views, and commit only this command's changes", false)
|
|
70
|
+
.option("-m, --message <message>", "Override the register commit message");
|
|
71
|
+
}
|
|
72
|
+
const REGISTER_COMMIT_SUBJECT_MAX_LENGTH = 100;
|
|
73
|
+
const REGISTER_COMMIT_STABILIZATION_ATTEMPTS = 3;
|
|
74
|
+
function defaultRegisterCommitMessage(command, result) {
|
|
75
|
+
const prefix = `docs(register ${result.id}): ${command} `;
|
|
76
|
+
const flatTitle = result.title.replace(/\s+/g, " ").trim();
|
|
77
|
+
const subject = `${prefix}${flatTitle}`;
|
|
78
|
+
if (subject.length <= REGISTER_COMMIT_SUBJECT_MAX_LENGTH)
|
|
79
|
+
return subject;
|
|
80
|
+
return `${subject.slice(0, REGISTER_COMMIT_SUBJECT_MAX_LENGTH - 1)}…`;
|
|
81
|
+
}
|
|
82
|
+
function rebuildRegisterViews(paths) {
|
|
83
|
+
const validation = validateRegisterItemDocs(paths.projectRegisterPath);
|
|
84
|
+
const derivationErrors = validateDerivedFromDocs(paths);
|
|
85
|
+
const eventErrors = validateRegisterEventDocs(paths.projectRegisterPath, paths.registerDateTimeZone);
|
|
86
|
+
if (validation.errors.length > 0 || derivationErrors.length > 0 || eventErrors.length > 0) {
|
|
87
|
+
throw new Error(`Invalid register item files:\n${[
|
|
88
|
+
...validation.errors,
|
|
89
|
+
...derivationErrors,
|
|
90
|
+
...eventErrors,
|
|
91
|
+
].join("\n")}`);
|
|
92
|
+
}
|
|
93
|
+
writeDerivedViews(paths, "all");
|
|
94
|
+
}
|
|
95
|
+
function isGeneratedRegisterPath(repoRoot, paths, path) {
|
|
96
|
+
const normalized = path.replaceAll("\\", "/");
|
|
97
|
+
const generatedPrefixes = [paths.generatedPath, paths.controlsGeneratedPath].map((target) => `${repoRelative(repoRoot, target)}/`);
|
|
98
|
+
return (normalized === ".specdojo/doc-index.json" ||
|
|
99
|
+
generatedPrefixes.some((prefix) => normalized.startsWith(prefix)));
|
|
100
|
+
}
|
|
101
|
+
function commitRegisterMutation(repoRoot, paths, command, result, preexisting, message) {
|
|
102
|
+
const changed = worktreeStatusPaths(repoRoot).filter((path) => !preexisting.has(path) && !isGeneratedRegisterPath(repoRoot, paths, path));
|
|
103
|
+
if (changed.length === 0) {
|
|
104
|
+
process.stdout.write(`No register changes to commit for ${result.id}.\n`);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
stageCommitTargets(repoRoot, changed);
|
|
108
|
+
const staged = gitResult(repoRoot, ["diff", "--cached", "--quiet", "--", ...changed]);
|
|
109
|
+
if (staged.status === 0) {
|
|
110
|
+
process.stdout.write(`No register changes to commit for ${result.id}.\n`);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (staged.status !== 1)
|
|
114
|
+
throw new Error("Failed to inspect staged register changes.");
|
|
115
|
+
const commitMessage = message?.trim() || defaultRegisterCommitMessage(command, result);
|
|
116
|
+
if (commitMessage === "")
|
|
117
|
+
throw new Error("Register commit message must not be empty");
|
|
118
|
+
gitOutput(repoRoot, ["commit", "-m", commitMessage, "--", ...changed]);
|
|
119
|
+
for (let attempt = 0; attempt < REGISTER_COMMIT_STABILIZATION_ATTEMPTS; attempt++) {
|
|
120
|
+
const remaining = worktreeStatusPaths(repoRoot).filter((path) => changed.includes(path));
|
|
121
|
+
if (remaining.length === 0) {
|
|
122
|
+
const sha = gitOutput(repoRoot, ["rev-parse", "--short", "HEAD"]).trim();
|
|
123
|
+
process.stdout.write(`Committed: ${sha} (${result.id})\n`);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
stageCommitTargets(repoRoot, remaining);
|
|
127
|
+
gitOutput(repoRoot, ["commit", "--amend", "--no-edit", "--", ...remaining]);
|
|
128
|
+
}
|
|
129
|
+
const remaining = worktreeStatusPaths(repoRoot).filter((path) => changed.includes(path));
|
|
130
|
+
if (remaining.length === 0) {
|
|
131
|
+
const sha = gitOutput(repoRoot, ["rev-parse", "--short", "HEAD"]).trim();
|
|
132
|
+
process.stdout.write(`Committed: ${sha} (${result.id})\n`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
throw new Error(`Register commit incomplete: target paths remained dirty after hook stabilization:\n` +
|
|
136
|
+
remaining.map((path) => ` ${path}`).join("\n"));
|
|
137
|
+
}
|
|
138
|
+
async function runRegisterMutation(command, opts, mutate) {
|
|
139
|
+
try {
|
|
140
|
+
const paths = resolveRegisterPaths(opts);
|
|
141
|
+
if (!opts.commit || opts.dryRun) {
|
|
142
|
+
mutate({ paths, assertCommitTargetsClean: () => undefined });
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const repoRoot = specdojoRootDir();
|
|
146
|
+
if (!paths.executionPath) {
|
|
147
|
+
throw new Error(`Execution path is not configured for project ${paths.projectId}`);
|
|
148
|
+
}
|
|
149
|
+
const mutex = new CrossProcessMutex(registerLifecyclePoolPath(paths.executionPath), {
|
|
150
|
+
actor: registerEventActor(opts),
|
|
151
|
+
label: `register ${command}`,
|
|
152
|
+
}, {
|
|
153
|
+
onWait: () => process.stdout.write("Waiting for the register lifecycle lock held by another operation\n"),
|
|
154
|
+
});
|
|
155
|
+
await mutex.runExclusive(() => {
|
|
156
|
+
const preexisting = new Set(worktreeStatusPaths(repoRoot));
|
|
157
|
+
const assertCommitTargetsClean = (targets) => {
|
|
158
|
+
const overlapping = targets
|
|
159
|
+
.map((target) => repoRelative(repoRoot, target))
|
|
160
|
+
.filter((target) => preexisting.has(target));
|
|
161
|
+
if (overlapping.length === 0)
|
|
162
|
+
return;
|
|
163
|
+
throw new Error(`Cannot use --commit because register targets already have uncommitted changes:\n` +
|
|
164
|
+
overlapping.map((path) => ` ${path}`).join("\n"));
|
|
165
|
+
};
|
|
166
|
+
const result = mutate({ paths, assertCommitTargetsClean });
|
|
167
|
+
rebuildRegisterViews(paths);
|
|
168
|
+
commitRegisterMutation(repoRoot, paths, command, result, preexisting, opts.message);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
printCommandError(error);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// CLI で明示された日時オプションを UTC の秒精度へ正規化する。未指定は undefined を返し、
|
|
176
|
+
// 呼び出し側の既定値(実行時刻・プレースホルダ)へ委ねる。
|
|
177
|
+
function parseRegisterTimestampOption(value, label, placeholder) {
|
|
178
|
+
const text = value?.trim();
|
|
179
|
+
if (!text)
|
|
180
|
+
return undefined;
|
|
181
|
+
if (text === placeholder)
|
|
182
|
+
return placeholder;
|
|
183
|
+
return normalizeRegisterTimestamp(text, label);
|
|
184
|
+
}
|
|
185
|
+
// git のパス限定(pathspec)はリポジトリルート起点の POSIX 表記で渡す。
|
|
186
|
+
function repoRelativePathspec(repoRoot, target) {
|
|
187
|
+
const value = relative(repoRoot, target);
|
|
188
|
+
if (!value || value === ".." || value.startsWith(`..${sep}`)) {
|
|
189
|
+
throw new Error(`Register directory is outside the repository root: ${target}`);
|
|
190
|
+
}
|
|
191
|
+
return value.split(sep).join("/");
|
|
192
|
+
}
|
|
193
|
+
// `--id PJR-AAAA PJR-BBBB` と `--id PJR-AAAA,PJR-BBBB` の両方を受け付ける。
|
|
194
|
+
function parseHistoryIds(values) {
|
|
195
|
+
if (!values || values.length === 0)
|
|
196
|
+
return undefined;
|
|
197
|
+
const ids = [];
|
|
198
|
+
for (const value of values.flatMap((entry) => entry.split(/[\s,]+/))) {
|
|
199
|
+
const id = value.trim().toUpperCase();
|
|
200
|
+
if (id === "")
|
|
201
|
+
continue;
|
|
202
|
+
if (!PJR_ID_RE.test(id)) {
|
|
203
|
+
throw new Error(`Invalid item ID: "${value}". Must match PJR-XXXX`);
|
|
204
|
+
}
|
|
205
|
+
if (!ids.includes(id))
|
|
206
|
+
ids.push(id);
|
|
207
|
+
}
|
|
208
|
+
return ids.length > 0 ? ids : undefined;
|
|
209
|
+
}
|
|
210
|
+
function actionFromLegacyHistory(kind, changes) {
|
|
211
|
+
if (kind === "added")
|
|
212
|
+
return "add";
|
|
213
|
+
const statusChange = changes.find((change) => change.field === "status");
|
|
214
|
+
const status = statusChange?.to;
|
|
215
|
+
if (statusChange &&
|
|
216
|
+
TERMINAL_STATUSES_SET.has(statusChange.from) &&
|
|
217
|
+
!TERMINAL_STATUSES_SET.has(statusChange.to)) {
|
|
218
|
+
return "reopen";
|
|
219
|
+
}
|
|
220
|
+
if (status === "in-progress")
|
|
221
|
+
return "start";
|
|
222
|
+
if (status === "waiting")
|
|
223
|
+
return "wait";
|
|
224
|
+
if (status === "review")
|
|
225
|
+
return "review";
|
|
226
|
+
if (status === "done" || status === "decided")
|
|
227
|
+
return "close";
|
|
228
|
+
if (status === "rejected")
|
|
229
|
+
return "reject";
|
|
230
|
+
if (status === "deferred")
|
|
231
|
+
return "defer";
|
|
232
|
+
const idChange = changes.some((change) => change.field === "id");
|
|
233
|
+
if (idChange)
|
|
234
|
+
return "renumber";
|
|
235
|
+
return "update";
|
|
236
|
+
}
|
|
237
|
+
// Git 履歴から復元した1件の変更を Register event へ変換する。状態連鎖を成立させるための
|
|
238
|
+
// 接続処理を含むため、移行本体から切り離して単体で検証できるようにしている。
|
|
239
|
+
export function legacyHistoryEventToRegisterEvent(historyEvent, context) {
|
|
240
|
+
// 過去の revision には、山括弧のエスケープ規約(PJR-B1SJ / PJR-ZWMH)より前に書かれた
|
|
241
|
+
// `<domain>` のようなプレースホルダが素のまま残っている。event へ写すと個票 frontmatter の
|
|
242
|
+
// 検証に落ちるため、現行の規約に合わせてインラインコードで囲んでから記録する。
|
|
243
|
+
const escape = (text) => inlineCodeAnglePlaceholders(text);
|
|
244
|
+
const statusChange = historyEvent.changes.find((change) => change.field === "status");
|
|
245
|
+
// 同じ個票が Git 履歴上で複数回 `added` として現れることがある。worktree のブランチで
|
|
246
|
+
// 作成した個票が統合ブランチへ再度追加された場合などで、走査は両方の commit を見る。
|
|
247
|
+
// 起票は状態連鎖の起点であり1件しか置けないため、2件目以降は追加ではなく更新として扱う。
|
|
248
|
+
const kind = historyEvent.kind === "added" && !context.isFirst ? "updated" : historyEvent.kind;
|
|
249
|
+
// 再追加の差分は「無」との比較になるため status の from が空になる。空のときは直前の
|
|
250
|
+
// event の到達状態へ接続し、状態連鎖が途切れないようにする。
|
|
251
|
+
const fromStatus = kind === "added" ? null : statusChange?.from || context.currentStatus || context.fallbackStatus;
|
|
252
|
+
const toStatus = statusChange?.to ?? fromStatus ?? context.fallbackStatus;
|
|
253
|
+
return {
|
|
254
|
+
v: 1,
|
|
255
|
+
id: deterministicRegisterEventId(`${historyEvent.commit}\0${historyEvent.id}\0${JSON.stringify(historyEvent.changes)}`),
|
|
256
|
+
ts: normalizeRegisterTimestamp(historyEvent.date, "legacy event date"),
|
|
257
|
+
action: actionFromLegacyHistory(kind, historyEvent.changes),
|
|
258
|
+
actor: historyEvent.author.trim() || "git-author-unknown",
|
|
259
|
+
from_status: fromStatus,
|
|
260
|
+
to_status: toStatus,
|
|
261
|
+
reason: escape(historyEvent.subject.trim()) || `migrated from ${historyEvent.commit.slice(0, 7)}`,
|
|
262
|
+
// 再追加を更新として扱う場合、status の差分は「無 -> open」のまま残ると from_status /
|
|
263
|
+
// to_status と食い違う。接続先の状態に合わせ、実際に変化していなければ差分から落とす。
|
|
264
|
+
changes: historyEvent.changes.flatMap((change) => {
|
|
265
|
+
const from = change.field === "status" ? (fromStatus ?? change.from) : change.from;
|
|
266
|
+
if (change.field === "status" && from === change.to)
|
|
267
|
+
return [];
|
|
268
|
+
return [
|
|
269
|
+
{
|
|
270
|
+
field: change.field,
|
|
271
|
+
from: escape(from),
|
|
272
|
+
to: escape(change.to),
|
|
273
|
+
},
|
|
274
|
+
];
|
|
275
|
+
}),
|
|
276
|
+
legacy_commit: historyEvent.commit,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
function migrateEmbeddedRegisterEvents(paths, dryRun) {
|
|
280
|
+
let itemCount = 0;
|
|
281
|
+
let eventCount = 0;
|
|
282
|
+
for (const doc of loadRegisterItemDocs(paths.projectRegisterPath)) {
|
|
283
|
+
const ticketContent = readFileSync(doc.path, "utf8");
|
|
284
|
+
const embedded = readEmbeddedRegisterEvents(ticketContent, doc.filename);
|
|
285
|
+
if (embedded.length === 0)
|
|
286
|
+
continue;
|
|
287
|
+
const eventPath = registerEventFilePath(paths.projectRegisterPath, doc.id);
|
|
288
|
+
if (existsSync(eventPath)) {
|
|
289
|
+
const existing = readRegisterEventsFromContent(readFileSync(eventPath, "utf8"), eventPath);
|
|
290
|
+
if (JSON.stringify(existing) !== JSON.stringify(embedded)) {
|
|
291
|
+
throw new Error(`${doc.filename}: embedded and external register events differ`);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (!dryRun) {
|
|
295
|
+
atomicWriteFile(eventPath, serializeRegisterEvents(embedded));
|
|
296
|
+
atomicWriteFile(doc.path, removeEmbeddedRegisterEvents(ticketContent));
|
|
297
|
+
}
|
|
298
|
+
itemCount++;
|
|
299
|
+
eventCount += embedded.length;
|
|
300
|
+
}
|
|
301
|
+
return { items: itemCount, events: eventCount };
|
|
302
|
+
}
|
|
303
|
+
function migrateRegisterEventsFromGit(paths, dryRun) {
|
|
304
|
+
let history;
|
|
305
|
+
try {
|
|
306
|
+
history = collectRegisterHistoryEvents({
|
|
307
|
+
repoRoot: specdojoRootDir(),
|
|
308
|
+
registerPathspec: repoRelativePathspec(specdojoRootDir(), paths.projectRegisterPath),
|
|
309
|
+
timeZone: paths.registerDateTimeZone,
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
catch {
|
|
313
|
+
return { items: 0, events: 0, skipped: 0, available: false };
|
|
314
|
+
}
|
|
315
|
+
const byId = new Map();
|
|
316
|
+
for (const event of history) {
|
|
317
|
+
if (event.source === "event" || event.kind === "removed")
|
|
318
|
+
continue;
|
|
319
|
+
const entries = byId.get(event.id) ?? [];
|
|
320
|
+
entries.push(event);
|
|
321
|
+
byId.set(event.id, entries);
|
|
322
|
+
}
|
|
323
|
+
let itemCount = 0;
|
|
324
|
+
let eventCount = 0;
|
|
325
|
+
let skipped = 0;
|
|
326
|
+
for (const doc of loadRegisterItemDocs(paths.projectRegisterPath)) {
|
|
327
|
+
const eventPath = registerEventFilePath(paths.projectRegisterPath, doc.id);
|
|
328
|
+
const ticketContent = readFileSync(doc.path, "utf8");
|
|
329
|
+
if (existsSync(eventPath) ||
|
|
330
|
+
(dryRun && readEmbeddedRegisterEvents(ticketContent, doc.filename).length > 0)) {
|
|
331
|
+
skipped++;
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
const legacyEvents = byId.get(doc.id) ?? [];
|
|
335
|
+
if (legacyEvents.length === 0)
|
|
336
|
+
continue;
|
|
337
|
+
let currentStatus = null;
|
|
338
|
+
let appended = 0;
|
|
339
|
+
let eventContent;
|
|
340
|
+
for (const historyEvent of legacyEvents) {
|
|
341
|
+
const event = legacyHistoryEventToRegisterEvent(historyEvent, {
|
|
342
|
+
isFirst: appended === 0,
|
|
343
|
+
currentStatus,
|
|
344
|
+
fallbackStatus: doc.item.status,
|
|
345
|
+
});
|
|
346
|
+
eventContent = appendRegisterEvent(eventContent, event);
|
|
347
|
+
currentStatus = event.to_status;
|
|
348
|
+
appended++;
|
|
349
|
+
}
|
|
350
|
+
if (appended === 0)
|
|
351
|
+
continue;
|
|
352
|
+
if (!dryRun && eventContent)
|
|
353
|
+
atomicWriteFile(eventPath, eventContent);
|
|
354
|
+
itemCount++;
|
|
355
|
+
eventCount += appended;
|
|
356
|
+
}
|
|
357
|
+
return { items: itemCount, events: eventCount, skipped, available: true };
|
|
358
|
+
}
|
|
359
|
+
// ================================
|
|
360
|
+
// Command Registration
|
|
361
|
+
// ================================
|
|
362
|
+
const REGISTER_COMMAND_DEPENDENCIES = {
|
|
363
|
+
registerTopicPattern: REGISTER_TOPIC_RE,
|
|
364
|
+
validBuildScopes: VALID_BUILD_SCOPES,
|
|
365
|
+
addProjectOption,
|
|
366
|
+
addRegisterCommitOptions,
|
|
367
|
+
applyItemUpdate,
|
|
368
|
+
applyRegisterMigrationPlan,
|
|
369
|
+
assertRegisterItemCommitTargetsClean,
|
|
370
|
+
assertTerminalOperationAllowed,
|
|
371
|
+
atomicWriteFile,
|
|
372
|
+
buildRegisterItemContent,
|
|
373
|
+
derivedTopicNeedsWarning,
|
|
374
|
+
generateDerivedViewFiles,
|
|
375
|
+
loadItemForUpdate,
|
|
376
|
+
loadRegisterItems,
|
|
377
|
+
migrateEmbeddedRegisterEvents,
|
|
378
|
+
migrateRegisterEventsFromGit,
|
|
379
|
+
parseHistoryIds,
|
|
380
|
+
parseRegisterTimestampOption,
|
|
381
|
+
planRegisterItem,
|
|
382
|
+
planRegisterMigration,
|
|
383
|
+
planRenumber,
|
|
384
|
+
planRetopic,
|
|
385
|
+
printCommandError,
|
|
386
|
+
printDerivedTopicWarning,
|
|
387
|
+
registerEventActor,
|
|
388
|
+
renumberPjrItem,
|
|
389
|
+
repoRelativePathspec,
|
|
390
|
+
resolveRegisterPaths,
|
|
391
|
+
retopicPjrItem,
|
|
392
|
+
runRegisterMutation,
|
|
393
|
+
slugify,
|
|
394
|
+
ticketTopicFromFilename,
|
|
395
|
+
updateTicketStatusForItem,
|
|
396
|
+
writeDerivedViews,
|
|
397
|
+
};
|
|
398
|
+
export function registerRegisterCommands(program) {
|
|
399
|
+
const reg = program.command("register").description("Project register (pjr-index.md) commands");
|
|
400
|
+
registerCreateCommands(reg, REGISTER_COMMAND_DEPENDENCIES);
|
|
401
|
+
registerTransitionCommands(reg, REGISTER_COMMAND_DEPENDENCIES);
|
|
402
|
+
registerUpdateCommand(reg, REGISTER_COMMAND_DEPENDENCIES);
|
|
403
|
+
registerMaintenanceCommands(reg, REGISTER_COMMAND_DEPENDENCIES);
|
|
404
|
+
}
|