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,352 @@
|
|
|
1
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { inlineCodeAnglePlaceholders } from "../shared/text.js";
|
|
4
|
+
import { APPROACHES } from "../shared/agent-types.js";
|
|
5
|
+
import { appendRegisterEvent, buildRegisterEvent, registerEventFilePath } from "./events.js";
|
|
6
|
+
import { nowUtcTimestamp } from "./date.js";
|
|
7
|
+
import { CELL_NONE, CELL_TODO, REMOVE_REGISTER_ITEM_FIELD, VALID_PRIORITIES, VALID_STATUSES, VALID_TYPES, } from "./item.js";
|
|
8
|
+
import { resolveSpecdojoTemplatePath } from "../docs/template-resolution.js";
|
|
9
|
+
import { validateRegisterApproachTargetsForProject } from "./approach.js";
|
|
10
|
+
import { normalizeDerivedFrom, validateDerivedFrom } from "./derivation.js";
|
|
11
|
+
function collectTarget(value, previous = []) {
|
|
12
|
+
return [...previous, value];
|
|
13
|
+
}
|
|
14
|
+
function normalizedTargets(values) {
|
|
15
|
+
if (values === undefined)
|
|
16
|
+
return undefined;
|
|
17
|
+
const targets = [...new Set(values.map((value) => value.trim()).filter(Boolean))];
|
|
18
|
+
if (targets.includes("-")) {
|
|
19
|
+
if (targets.length !== 1)
|
|
20
|
+
throw new Error("--target - cannot be combined with other targets");
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
if (targets.length === 0)
|
|
24
|
+
throw new Error("--target must contain a document id");
|
|
25
|
+
return targets;
|
|
26
|
+
}
|
|
27
|
+
export function registerCreateCommands(reg, dependencies) {
|
|
28
|
+
const { addProjectOption, addRegisterCommitOptions, atomicWriteFile, buildRegisterItemContent, derivedTopicNeedsWarning, generateDerivedViewFiles, loadRegisterItems, parseRegisterTimestampOption, planRegisterItem, printCommandError, printDerivedTopicWarning, registerEventActor, registerTopicPattern, resolveRegisterPaths, runRegisterMutation, slugify, writeDerivedViews, } = dependencies;
|
|
29
|
+
// --- scaffold ---
|
|
30
|
+
const scaffoldCmd = reg
|
|
31
|
+
.command("scaffold")
|
|
32
|
+
.description("Initialize the register directory and generate its views");
|
|
33
|
+
addProjectOption(scaffoldCmd);
|
|
34
|
+
scaffoldCmd.option("--dry-run", "Print generated content to stdout without writing", false);
|
|
35
|
+
scaffoldCmd.action((opts) => {
|
|
36
|
+
try {
|
|
37
|
+
const paths = resolveRegisterPaths(opts);
|
|
38
|
+
if (opts.dryRun) {
|
|
39
|
+
for (const view of generateDerivedViewFiles(paths, "all")) {
|
|
40
|
+
process.stdout.write(`=== ${view.path} ===\n${view.content}\n\n`);
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
mkdirSync(paths.projectRegisterPath, { recursive: true });
|
|
45
|
+
process.stdout.write(`Created: ${paths.projectRegisterPath}/\n`);
|
|
46
|
+
for (const view of writeDerivedViews(paths, "all")) {
|
|
47
|
+
process.stdout.write(`Generated: ${view.path}\n`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
printCommandError(error);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
// --- add ---
|
|
55
|
+
const addCmd = reg.command("add").description("Add a new item to pjr-index.md");
|
|
56
|
+
addProjectOption(addCmd);
|
|
57
|
+
addCmd.requiredOption("--type <type>", `Item type: ${VALID_TYPES.join(" | ")}`);
|
|
58
|
+
addCmd.requiredOption("--title <title>", "Short title for the item");
|
|
59
|
+
addCmd.option("--description <text>", "Description shown in the list", "_TODO_");
|
|
60
|
+
addCmd.option("--priority <priority>", `Priority: ${VALID_PRIORITIES.join(" | ")}`, "medium");
|
|
61
|
+
addCmd.option("--status <status>", `Status: ${VALID_STATUSES.join(" | ")}`, "open");
|
|
62
|
+
addCmd.option("--owner <owner>", "Owner or role", "_TODO_");
|
|
63
|
+
addCmd.option("--registered <datetime>", "Registration date-time (RFC 3339 with time zone, or _TODO_; defaults to now in UTC)");
|
|
64
|
+
addCmd.option("--due <date>", "Due date (YYYY-MM-DD, -, or _TODO_)", "_TODO_");
|
|
65
|
+
addCmd.option("--completed <datetime>", "Completion date-time (RFC 3339 with time zone, or -)", "-");
|
|
66
|
+
addCmd.option("--conclusion <text>", "Conclusion or resolution summary", "-");
|
|
67
|
+
addCmd.option("--approach <approach>", `Execution approach: ${APPROACHES.join(" | ")}`);
|
|
68
|
+
addCmd.option("--target <doc-id>", "Target document id (repeatable; approach requires exactly one)", collectTarget);
|
|
69
|
+
addCmd.option("--from <item-id>", "Register item this item derives from (repeatable)", collectTarget);
|
|
70
|
+
addCmd.option("--id <id>", "Display ID (e.g., PJR-0061); auto-incremented if omitted");
|
|
71
|
+
addCmd.option("--topic <topic>", "Topic slug for ticket filename; derived from --title if omitted");
|
|
72
|
+
addCmd.option("--by <actor>", "Actor recorded in the append-only register event");
|
|
73
|
+
addCmd.option("--reason <text>", "Reason recorded in the append-only register event");
|
|
74
|
+
addCmd.option("--force", "Overwrite existing ticket file", false);
|
|
75
|
+
addCmd.option("--dry-run", "Print the generated item file without writing", false);
|
|
76
|
+
addRegisterCommitOptions(addCmd);
|
|
77
|
+
addCmd.action(async (opts) => {
|
|
78
|
+
await runRegisterMutation("add", opts, ({ paths, assertCommitTargetsClean }) => {
|
|
79
|
+
const explicitTopic = opts.topic?.trim();
|
|
80
|
+
const topic = explicitTopic || slugify(opts.title);
|
|
81
|
+
const warnAboutDerivedTopic = explicitTopic === undefined && derivedTopicNeedsWarning(opts.title, topic);
|
|
82
|
+
if (!registerTopicPattern.test(topic)) {
|
|
83
|
+
throw new Error(`Invalid topic: "${topic}". Must use lowercase letters, numbers, and single hyphens`);
|
|
84
|
+
}
|
|
85
|
+
const registeredAt = parseRegisterTimestampOption(opts.registered, "registered", CELL_TODO);
|
|
86
|
+
const completedAt = parseRegisterTimestampOption(opts.completed, "completed", CELL_NONE);
|
|
87
|
+
if (opts.target?.some((target) => target.trim() === "-")) {
|
|
88
|
+
throw new Error("--target - is only valid with register update");
|
|
89
|
+
}
|
|
90
|
+
const targets = normalizedTargets(opts.target);
|
|
91
|
+
validateRegisterApproachTargetsForProject({
|
|
92
|
+
projectId: paths.projectId,
|
|
93
|
+
...(opts.approach !== undefined ? { approach: opts.approach } : {}),
|
|
94
|
+
...(targets !== undefined ? { targets } : {}),
|
|
95
|
+
validateTargetsWithoutApproach: opts.target !== undefined,
|
|
96
|
+
});
|
|
97
|
+
const fields = {
|
|
98
|
+
type: opts.type,
|
|
99
|
+
title: opts.title,
|
|
100
|
+
description: opts.description,
|
|
101
|
+
priority: opts.priority,
|
|
102
|
+
status: opts.status,
|
|
103
|
+
owner: opts.owner,
|
|
104
|
+
registeredAt: registeredAt ?? nowUtcTimestamp(),
|
|
105
|
+
due: opts.due,
|
|
106
|
+
completedAt: completedAt ?? CELL_NONE,
|
|
107
|
+
conclusion: opts.conclusion,
|
|
108
|
+
...(opts.approach !== undefined ? { approach: opts.approach } : {}),
|
|
109
|
+
...(targets !== undefined ? { targets } : {}),
|
|
110
|
+
};
|
|
111
|
+
const templatePath = resolveSpecdojoTemplatePath(`pjr-${opts.type}-template.md`);
|
|
112
|
+
const { assignedId: displayId, ticketFilename } = planRegisterItem({
|
|
113
|
+
existingIds: loadRegisterItems(paths).map((view) => view.id),
|
|
114
|
+
explicitId: opts.id?.trim() || undefined,
|
|
115
|
+
fields,
|
|
116
|
+
topic,
|
|
117
|
+
});
|
|
118
|
+
const derivedFrom = normalizeDerivedFrom(opts.from, { allowRemove: false });
|
|
119
|
+
validateDerivedFrom({
|
|
120
|
+
projectId: paths.projectId,
|
|
121
|
+
itemId: displayId,
|
|
122
|
+
derivedFrom,
|
|
123
|
+
});
|
|
124
|
+
if (derivedFrom !== undefined)
|
|
125
|
+
fields.derivedFrom = derivedFrom;
|
|
126
|
+
const ticketPath = join(paths.projectRegisterPath, ticketFilename);
|
|
127
|
+
const content = buildRegisterItemContent({
|
|
128
|
+
projectId: paths.projectId,
|
|
129
|
+
displayId,
|
|
130
|
+
topic,
|
|
131
|
+
fields,
|
|
132
|
+
templatePath,
|
|
133
|
+
});
|
|
134
|
+
const addEvent = buildRegisterEvent({
|
|
135
|
+
afterContent: content,
|
|
136
|
+
filename: ticketFilename,
|
|
137
|
+
timeZone: paths.registerDateTimeZone,
|
|
138
|
+
action: "add",
|
|
139
|
+
actor: registerEventActor(opts),
|
|
140
|
+
reason: opts.reason?.trim() || "item added",
|
|
141
|
+
});
|
|
142
|
+
if (!addEvent)
|
|
143
|
+
throw new Error(`Failed to build add event for ${displayId}`);
|
|
144
|
+
if (opts.dryRun) {
|
|
145
|
+
process.stdout.write(`Would create ${ticketPath}:\n${content}\n`);
|
|
146
|
+
process.stdout.write(`Would create ${registerEventFilePath(paths.projectRegisterPath, displayId)}:\n` +
|
|
147
|
+
`${appendRegisterEvent(undefined, addEvent)}\n`);
|
|
148
|
+
if (warnAboutDerivedTopic)
|
|
149
|
+
printDerivedTopicWarning(topic);
|
|
150
|
+
return { id: displayId, title: opts.title };
|
|
151
|
+
}
|
|
152
|
+
if (!opts.force && existsSync(ticketPath)) {
|
|
153
|
+
throw new Error(`Item file already exists (use --force to overwrite): ${ticketPath}`);
|
|
154
|
+
}
|
|
155
|
+
const eventPath = registerEventFilePath(paths.projectRegisterPath, displayId);
|
|
156
|
+
assertCommitTargetsClean([ticketPath, eventPath]);
|
|
157
|
+
if (!opts.force && existsSync(eventPath)) {
|
|
158
|
+
throw new Error(`Register event file already exists (use --force to overwrite): ${eventPath}`);
|
|
159
|
+
}
|
|
160
|
+
mkdirSync(paths.projectRegisterPath, { recursive: true });
|
|
161
|
+
atomicWriteFile(ticketPath, content);
|
|
162
|
+
atomicWriteFile(eventPath, appendRegisterEvent(undefined, addEvent));
|
|
163
|
+
process.stdout.write(`Created: ${ticketPath} (added ${displayId})\n`);
|
|
164
|
+
process.stdout.write(`Created: ${eventPath}\n`);
|
|
165
|
+
if (existsSync(paths.pjrIndexPath)) {
|
|
166
|
+
for (const view of writeDerivedViews(paths, "all")) {
|
|
167
|
+
process.stdout.write(`Generated: ${view.path}\n`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (warnAboutDerivedTopic)
|
|
171
|
+
printDerivedTopicWarning(topic);
|
|
172
|
+
return { id: displayId, title: opts.title };
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
export function registerUpdateCommand(reg, dependencies) {
|
|
177
|
+
const { addProjectOption, addRegisterCommitOptions, applyItemUpdate, assertRegisterItemCommitTargetsClean, loadItemForUpdate, planRetopic, registerEventActor, registerTopicPattern, retopicPjrItem, runRegisterMutation, ticketTopicFromFilename, } = dependencies;
|
|
178
|
+
// --- update ---
|
|
179
|
+
const updateCmd = reg.command("update").description("Update fields of a register item");
|
|
180
|
+
addProjectOption(updateCmd);
|
|
181
|
+
updateCmd.requiredOption("--id <id>", "Item ID (PJR-XXXX)");
|
|
182
|
+
updateCmd.option("--title <title>", "Update title");
|
|
183
|
+
updateCmd.option("--description <text>", "Update description");
|
|
184
|
+
updateCmd.option("--priority <priority>", `Update priority: ${VALID_PRIORITIES.join(" | ")}`);
|
|
185
|
+
updateCmd.option("--owner <owner>", "Update owner or role");
|
|
186
|
+
updateCmd.option("--due <date>", "Update due date (YYYY-MM-DD, -, or _TODO_)");
|
|
187
|
+
updateCmd.option("--conclusion <text>", "Update conclusion or use - to remove it");
|
|
188
|
+
updateCmd.option("--block-reason <text>", "Update the waiting reason or use - to remove it");
|
|
189
|
+
updateCmd.option("--approach <approach>", `Update execution approach (${APPROACHES.join(" | ")}; use - to remove)`);
|
|
190
|
+
updateCmd.option("--target <doc-id>", "Replace target document ids (repeatable; use - to remove)", collectTarget);
|
|
191
|
+
updateCmd.option("--from <item-id>", "Replace source register item IDs (repeatable; use - to remove)", collectTarget);
|
|
192
|
+
updateCmd.option("--topic <topic>", "Update the topic slug in the ticket filename and document ID");
|
|
193
|
+
updateCmd.option("--by <actor>", "Actor recorded in the append-only register event");
|
|
194
|
+
updateCmd.option("--reason <text>", "Reason recorded in the append-only register event");
|
|
195
|
+
updateCmd.option("--dry-run", "Print change without writing", false);
|
|
196
|
+
addRegisterCommitOptions(updateCmd);
|
|
197
|
+
updateCmd.action(async (opts) => {
|
|
198
|
+
await runRegisterMutation("update", opts, (context) => {
|
|
199
|
+
const { paths } = context;
|
|
200
|
+
const view = loadItemForUpdate(paths, opts.id);
|
|
201
|
+
const item = view.item;
|
|
202
|
+
const hasUpdates = [
|
|
203
|
+
"title",
|
|
204
|
+
"description",
|
|
205
|
+
"priority",
|
|
206
|
+
"owner",
|
|
207
|
+
"due",
|
|
208
|
+
"conclusion",
|
|
209
|
+
"blockReason",
|
|
210
|
+
"approach",
|
|
211
|
+
"target",
|
|
212
|
+
"from",
|
|
213
|
+
"topic",
|
|
214
|
+
].some((key) => opts[key] !== undefined);
|
|
215
|
+
if (!hasUpdates) {
|
|
216
|
+
throw new Error("At least one field option must be specified (--title, --description, --priority, --owner, --due, --conclusion, --block-reason, --approach, --target, --from, --topic)");
|
|
217
|
+
}
|
|
218
|
+
if (opts.priority !== undefined &&
|
|
219
|
+
!VALID_PRIORITIES.includes(opts.priority)) {
|
|
220
|
+
throw new Error(`Invalid priority: "${opts.priority}". Must be one of: ${VALID_PRIORITIES.join(", ")}`);
|
|
221
|
+
}
|
|
222
|
+
if (opts.due !== undefined && !/^(\d{4}-\d{2}-\d{2}|-|_TODO_)$/.test(opts.due)) {
|
|
223
|
+
throw new Error(`Invalid due: "${opts.due}". Must be YYYY-MM-DD, -, or _TODO_`);
|
|
224
|
+
}
|
|
225
|
+
const topic = opts.topic?.trim();
|
|
226
|
+
if (topic !== undefined && !registerTopicPattern.test(topic)) {
|
|
227
|
+
throw new Error(`Invalid topic: "${topic}". Must use lowercase letters, numbers, and single hyphens`);
|
|
228
|
+
}
|
|
229
|
+
const blockReason = opts.blockReason?.trim();
|
|
230
|
+
if (blockReason !== undefined && blockReason === "") {
|
|
231
|
+
throw new Error("Block reason must not be empty; use - to remove it");
|
|
232
|
+
}
|
|
233
|
+
if (blockReason !== undefined && blockReason !== "-" && item.status !== "waiting") {
|
|
234
|
+
throw new Error(`Cannot set block reason for ${item.id}: status is "${item.status}" (expected "waiting"). Use - to remove it.`);
|
|
235
|
+
}
|
|
236
|
+
const blockReasonUpdates = blockReason === undefined
|
|
237
|
+
? undefined
|
|
238
|
+
: {
|
|
239
|
+
block_reason: blockReason === "-"
|
|
240
|
+
? REMOVE_REGISTER_ITEM_FIELD
|
|
241
|
+
: inlineCodeAnglePlaceholders(blockReason),
|
|
242
|
+
};
|
|
243
|
+
const nextApproach = opts.approach === undefined
|
|
244
|
+
? item.approach
|
|
245
|
+
: opts.approach.trim() === "-"
|
|
246
|
+
? undefined
|
|
247
|
+
: opts.approach.trim();
|
|
248
|
+
const nextTargets = opts.target === undefined ? item.targets : normalizedTargets(opts.target);
|
|
249
|
+
const nextDerivedFrom = opts.from === undefined
|
|
250
|
+
? item.derivedFrom
|
|
251
|
+
: normalizeDerivedFrom(opts.from, { allowRemove: true });
|
|
252
|
+
validateDerivedFrom({
|
|
253
|
+
projectId: paths.projectId,
|
|
254
|
+
itemId: item.id,
|
|
255
|
+
derivedFrom: nextDerivedFrom,
|
|
256
|
+
});
|
|
257
|
+
validateRegisterApproachTargetsForProject({
|
|
258
|
+
projectId: paths.projectId,
|
|
259
|
+
...(nextApproach !== undefined ? { approach: nextApproach } : {}),
|
|
260
|
+
...(nextTargets !== undefined ? { targets: nextTargets } : {}),
|
|
261
|
+
validateTargetsWithoutApproach: opts.target !== undefined,
|
|
262
|
+
});
|
|
263
|
+
const approachTargetUpdates = {
|
|
264
|
+
...(opts.approach !== undefined
|
|
265
|
+
? {
|
|
266
|
+
approach: nextApproach === undefined ? REMOVE_REGISTER_ITEM_FIELD : nextApproach,
|
|
267
|
+
}
|
|
268
|
+
: {}),
|
|
269
|
+
...(opts.target !== undefined
|
|
270
|
+
? {
|
|
271
|
+
targets: nextTargets ?? REMOVE_REGISTER_ITEM_FIELD,
|
|
272
|
+
}
|
|
273
|
+
: {}),
|
|
274
|
+
...(opts.from !== undefined
|
|
275
|
+
? {
|
|
276
|
+
derived_from: nextDerivedFrom ?? REMOVE_REGISTER_ITEM_FIELD,
|
|
277
|
+
}
|
|
278
|
+
: {}),
|
|
279
|
+
};
|
|
280
|
+
const updated = {
|
|
281
|
+
...item,
|
|
282
|
+
...(opts.title !== undefined ? { title: opts.title } : {}),
|
|
283
|
+
...(opts.description !== undefined ? { description: opts.description } : {}),
|
|
284
|
+
...(opts.priority !== undefined ? { priority: opts.priority } : {}),
|
|
285
|
+
...(opts.owner !== undefined ? { owner: opts.owner } : {}),
|
|
286
|
+
...(opts.due !== undefined ? { due: opts.due } : {}),
|
|
287
|
+
...(opts.conclusion !== undefined ? { conclusion: opts.conclusion } : {}),
|
|
288
|
+
};
|
|
289
|
+
if (opts.approach !== undefined) {
|
|
290
|
+
if (nextApproach === undefined)
|
|
291
|
+
delete updated.approach;
|
|
292
|
+
else
|
|
293
|
+
updated.approach = nextApproach;
|
|
294
|
+
}
|
|
295
|
+
if (opts.target !== undefined) {
|
|
296
|
+
if (nextTargets === undefined)
|
|
297
|
+
delete updated.targets;
|
|
298
|
+
else
|
|
299
|
+
updated.targets = nextTargets;
|
|
300
|
+
}
|
|
301
|
+
if (opts.from !== undefined) {
|
|
302
|
+
if (nextDerivedFrom === undefined)
|
|
303
|
+
delete updated.derivedFrom;
|
|
304
|
+
else
|
|
305
|
+
updated.derivedFrom = nextDerivedFrom;
|
|
306
|
+
}
|
|
307
|
+
const currentTopic = view.ticketFilename
|
|
308
|
+
? ticketTopicFromFilename(opts.id, view.ticketFilename)
|
|
309
|
+
: undefined;
|
|
310
|
+
if (topic !== undefined && topic !== currentTopic) {
|
|
311
|
+
const retopicPlan = planRetopic(paths, opts.id, topic);
|
|
312
|
+
context.assertCommitTargetsClean([
|
|
313
|
+
retopicPlan.ticketRename.from,
|
|
314
|
+
...retopicPlan.writes.map((write) => write.path),
|
|
315
|
+
registerEventFilePath(paths.projectRegisterPath, item.id),
|
|
316
|
+
]);
|
|
317
|
+
retopicPjrItem({
|
|
318
|
+
paths,
|
|
319
|
+
id: opts.id,
|
|
320
|
+
topic,
|
|
321
|
+
updated,
|
|
322
|
+
dryRun: opts.dryRun,
|
|
323
|
+
...(blockReasonUpdates || Object.keys(approachTargetUpdates).length > 0
|
|
324
|
+
? { fieldUpdates: { ...blockReasonUpdates, ...approachTargetUpdates } }
|
|
325
|
+
: {}),
|
|
326
|
+
...(opts.title !== undefined ? { title: opts.title } : {}),
|
|
327
|
+
...(opts.description !== undefined ? { description: opts.description } : {}),
|
|
328
|
+
actor: registerEventActor(opts),
|
|
329
|
+
reason: opts.reason?.trim() || "",
|
|
330
|
+
});
|
|
331
|
+
return { id: item.id, title: updated.title };
|
|
332
|
+
}
|
|
333
|
+
assertRegisterItemCommitTargetsClean(context, view);
|
|
334
|
+
applyItemUpdate({
|
|
335
|
+
paths,
|
|
336
|
+
view,
|
|
337
|
+
updated,
|
|
338
|
+
dryRun: opts.dryRun,
|
|
339
|
+
action: "fields updated",
|
|
340
|
+
...(opts.title !== undefined ? { title: opts.title } : {}),
|
|
341
|
+
...(opts.description !== undefined ? { description: opts.description } : {}),
|
|
342
|
+
...(blockReasonUpdates || Object.keys(approachTargetUpdates).length > 0
|
|
343
|
+
? { fieldUpdates: { ...blockReasonUpdates, ...approachTargetUpdates } }
|
|
344
|
+
: {}),
|
|
345
|
+
eventAction: "update",
|
|
346
|
+
eventActor: registerEventActor(opts),
|
|
347
|
+
eventReason: opts.reason?.trim() || "fields updated",
|
|
348
|
+
});
|
|
349
|
+
return { id: item.id, title: updated.title };
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_REGISTER_DATE_TIMEZONE } from "
|
|
1
|
+
import { DEFAULT_REGISTER_DATE_TIMEZONE } from "../shared/specdojo-config.js";
|
|
2
2
|
// 登録項目の日時(registered_at / completed_at)と、そこから導出する表示日の共通ヘルパー。
|
|
3
3
|
//
|
|
4
4
|
// 保存形式は UTC・RFC 3339・秒精度(`YYYY-MM-DDTHH:MM:SSZ`)に固定する。瞬間そのものを
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { getProjectRegisterPath, loadConfig, specdojoRootDir, } from "../shared/specdojo-config.js";
|
|
4
|
+
import { loadRegisterItemDocs, PJR_ID_RE } from "./item.js";
|
|
5
|
+
const QUALIFIED_REGISTER_ITEM_REF_RE = /^([a-z][a-z0-9-]*):(PJR-[0-9ABCDEFGHJKMNPQRSTVWXYZ]{4})$/;
|
|
6
|
+
export function parseRegisterItemRef(value, currentProjectId) {
|
|
7
|
+
if (PJR_ID_RE.test(value))
|
|
8
|
+
return { projectId: currentProjectId, itemId: value };
|
|
9
|
+
const match = QUALIFIED_REGISTER_ITEM_REF_RE.exec(value);
|
|
10
|
+
return match ? { projectId: match[1], itemId: match[2] } : undefined;
|
|
11
|
+
}
|
|
12
|
+
export function normalizeDerivedFrom(values, options) {
|
|
13
|
+
if (values === undefined)
|
|
14
|
+
return undefined;
|
|
15
|
+
const refs = [...new Set(values.map((value) => value.trim()).filter(Boolean))];
|
|
16
|
+
if (refs.includes("-")) {
|
|
17
|
+
if (!options.allowRemove)
|
|
18
|
+
throw new Error("--from - is only valid with register update");
|
|
19
|
+
if (refs.length !== 1)
|
|
20
|
+
throw new Error("--from - cannot be combined with other item IDs");
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
if (refs.length === 0)
|
|
24
|
+
throw new Error("--from must contain a register item ID");
|
|
25
|
+
return refs;
|
|
26
|
+
}
|
|
27
|
+
function configuredItemIds(config, projectId) {
|
|
28
|
+
const project = config.projects[projectId];
|
|
29
|
+
if (!project)
|
|
30
|
+
return undefined;
|
|
31
|
+
const registerPath = getProjectRegisterPath(project);
|
|
32
|
+
if (!registerPath) {
|
|
33
|
+
throw new Error(`Cannot verify derived_from item in configured project ${projectId}: project_register_path is not set`);
|
|
34
|
+
}
|
|
35
|
+
const absolutePath = resolve(specdojoRootDir(), registerPath);
|
|
36
|
+
return new Set(loadRegisterItemDocs(absolutePath).map((doc) => doc.id));
|
|
37
|
+
}
|
|
38
|
+
function validateDerivedFromWithConfig(opts, config, idsByProject) {
|
|
39
|
+
for (const ref of opts.derivedFrom) {
|
|
40
|
+
const parsed = parseRegisterItemRef(ref, opts.projectId);
|
|
41
|
+
if (!parsed) {
|
|
42
|
+
throw new Error(`Invalid --from item ID: "${ref}". Use PJR-XXXX or <project-id>:PJR-XXXX`);
|
|
43
|
+
}
|
|
44
|
+
if (parsed.projectId === opts.projectId && parsed.itemId === opts.itemId) {
|
|
45
|
+
throw new Error(`Item ${opts.itemId} cannot derive from itself`);
|
|
46
|
+
}
|
|
47
|
+
if (!config.projects[parsed.projectId])
|
|
48
|
+
continue;
|
|
49
|
+
let ids = idsByProject.get(parsed.projectId);
|
|
50
|
+
if (!idsByProject.has(parsed.projectId)) {
|
|
51
|
+
ids = configuredItemIds(config, parsed.projectId);
|
|
52
|
+
idsByProject.set(parsed.projectId, ids);
|
|
53
|
+
}
|
|
54
|
+
if (!ids?.has(parsed.itemId)) {
|
|
55
|
+
throw new Error(`Derived-from item not found: ${ref} (searched configured project ${parsed.projectId})`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export function validateDerivedFrom(opts) {
|
|
60
|
+
if (!opts.derivedFrom)
|
|
61
|
+
return;
|
|
62
|
+
const { config } = loadConfig();
|
|
63
|
+
if (!config)
|
|
64
|
+
throw new Error("register commands require specdojo.config.json");
|
|
65
|
+
validateDerivedFromWithConfig({ ...opts, derivedFrom: opts.derivedFrom }, config, new Map());
|
|
66
|
+
}
|
|
67
|
+
export function validateDerivedFromDocs(paths) {
|
|
68
|
+
const docs = loadRegisterItemDocs(paths.projectRegisterPath);
|
|
69
|
+
const derivedDocs = docs.filter((doc) => doc.item.derivedFrom !== undefined);
|
|
70
|
+
if (derivedDocs.length === 0)
|
|
71
|
+
return [];
|
|
72
|
+
let config;
|
|
73
|
+
try {
|
|
74
|
+
({ config } = loadConfig());
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
return [`derived_from: ${error instanceof Error ? error.message : String(error)}`];
|
|
78
|
+
}
|
|
79
|
+
if (!config)
|
|
80
|
+
return ["derived_from: register commands require specdojo.config.json"];
|
|
81
|
+
const errors = [];
|
|
82
|
+
const idsByProject = new Map([
|
|
83
|
+
[paths.projectId, new Set(docs.map((doc) => doc.id))],
|
|
84
|
+
]);
|
|
85
|
+
for (const doc of derivedDocs) {
|
|
86
|
+
try {
|
|
87
|
+
validateDerivedFromWithConfig({
|
|
88
|
+
projectId: paths.projectId,
|
|
89
|
+
itemId: doc.id,
|
|
90
|
+
derivedFrom: doc.item.derivedFrom,
|
|
91
|
+
}, config, idsByProject);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
errors.push(`${doc.filename}: ${error instanceof Error ? error.message : String(error)}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return errors;
|
|
98
|
+
}
|
|
99
|
+
function configuredExternalRegisterDirectories(paths) {
|
|
100
|
+
let config;
|
|
101
|
+
try {
|
|
102
|
+
({ config } = loadConfig());
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
// `init --dry-run` may intentionally preserve an existing, non-SpecDojo config file.
|
|
106
|
+
// The current project can still produce an empty/local derivation view in that case.
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
if (!config)
|
|
110
|
+
return [];
|
|
111
|
+
const configuredCurrent = config.projects[paths.projectId];
|
|
112
|
+
const configuredCurrentPath = configuredCurrent
|
|
113
|
+
? getProjectRegisterPath(configuredCurrent)
|
|
114
|
+
: undefined;
|
|
115
|
+
if (!configuredCurrentPath ||
|
|
116
|
+
resolve(specdojoRootDir(), configuredCurrentPath) !== resolve(paths.projectRegisterPath)) {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
return Object.entries(config.projects).flatMap(([projectId, project]) => {
|
|
120
|
+
if (projectId === paths.projectId)
|
|
121
|
+
return [];
|
|
122
|
+
const registerPath = getProjectRegisterPath(project);
|
|
123
|
+
if (!registerPath)
|
|
124
|
+
return [];
|
|
125
|
+
const absolutePath = resolve(specdojoRootDir(), registerPath);
|
|
126
|
+
return existsSync(absolutePath) ? [{ projectId, registerPath: absolutePath }] : [];
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
export function collectDerivedRegisterRelations(paths, currentItems) {
|
|
130
|
+
const relations = [];
|
|
131
|
+
const collect = (projectId, items) => {
|
|
132
|
+
for (const item of items) {
|
|
133
|
+
for (const ref of item.item.derivedFrom ?? []) {
|
|
134
|
+
const source = parseRegisterItemRef(ref, projectId);
|
|
135
|
+
if (!source || source.projectId !== paths.projectId)
|
|
136
|
+
continue;
|
|
137
|
+
relations.push({
|
|
138
|
+
sourceId: source.itemId,
|
|
139
|
+
derivedProjectId: projectId,
|
|
140
|
+
derivedItem: item.item,
|
|
141
|
+
derivedTicketPath: item.ticketPath,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
collect(paths.projectId, currentItems.flatMap((view) => view.ticketPath ? [{ item: view.item, ticketPath: view.ticketPath }] : []));
|
|
147
|
+
for (const project of configuredExternalRegisterDirectories(paths)) {
|
|
148
|
+
collect(project.projectId, loadRegisterItemDocs(project.registerPath).map((doc) => ({
|
|
149
|
+
item: doc.item,
|
|
150
|
+
ticketPath: doc.path,
|
|
151
|
+
})));
|
|
152
|
+
}
|
|
153
|
+
return relations.sort((left, right) => {
|
|
154
|
+
if (left.sourceId !== right.sourceId)
|
|
155
|
+
return left.sourceId < right.sourceId ? -1 : 1;
|
|
156
|
+
if (left.derivedProjectId !== right.derivedProjectId) {
|
|
157
|
+
return left.derivedProjectId < right.derivedProjectId ? -1 : 1;
|
|
158
|
+
}
|
|
159
|
+
if (left.derivedItem.id === right.derivedItem.id)
|
|
160
|
+
return 0;
|
|
161
|
+
return left.derivedItem.id < right.derivedItem.id ? -1 : 1;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// 統合 merge で登録簿の記帳ファイルが競合したときの解決処理。イベントファイルは追記型の記録なので、
|
|
2
2
|
// 両側のイベントの和集合(同一 id は 1 件)を時刻順に並べ、`previous_event_id` の連鎖を張り直す。
|
|
3
3
|
// 個票は exec branch 側を基準にし、統合先だけにあるイベントが変えたフィールドのうち、frontmatter の
|
|
4
|
-
// 単純な値へ写せるもの(type / priority / owner / due
|
|
5
|
-
|
|
6
|
-
import {
|
|
4
|
+
// 単純な値へ写せるもの(type / priority / owner / due / approach / targets /
|
|
5
|
+
// derived_from)だけを再構築する。
|
|
6
|
+
import { readRegisterEventsFromContent, serializeRegisterEvents, } from "./events.js";
|
|
7
|
+
import { applyRegisterItemFields, CELL_NONE, CELL_TODO, REMOVE_REGISTER_ITEM_FIELD, } from "./item.js";
|
|
7
8
|
function hasStatusChange(event) {
|
|
8
9
|
return event.changes.some((change) => change.field === "status");
|
|
9
10
|
}
|
|
@@ -136,6 +137,34 @@ function fieldUpdateFromChange(change) {
|
|
|
136
137
|
? null
|
|
137
138
|
: value,
|
|
138
139
|
};
|
|
140
|
+
case "approach":
|
|
141
|
+
return { approach: isUnset ? REMOVE_REGISTER_ITEM_FIELD : value };
|
|
142
|
+
case "targets": {
|
|
143
|
+
if (isUnset)
|
|
144
|
+
return { targets: REMOVE_REGISTER_ITEM_FIELD };
|
|
145
|
+
try {
|
|
146
|
+
const parsed = JSON.parse(value);
|
|
147
|
+
return Array.isArray(parsed) && parsed.every((target) => typeof target === "string")
|
|
148
|
+
? { targets: parsed }
|
|
149
|
+
: undefined;
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
case "derived_from": {
|
|
156
|
+
if (isUnset)
|
|
157
|
+
return { derived_from: REMOVE_REGISTER_ITEM_FIELD };
|
|
158
|
+
try {
|
|
159
|
+
const parsed = JSON.parse(value);
|
|
160
|
+
return Array.isArray(parsed) && parsed.every((ref) => typeof ref === "string")
|
|
161
|
+
? { derived_from: parsed }
|
|
162
|
+
: undefined;
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
139
168
|
default:
|
|
140
169
|
return undefined;
|
|
141
170
|
}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
4
|
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
5
5
|
import { join } from "node:path";
|
|
6
|
-
import
|
|
7
|
-
import { CELL_NONE, displayIdFromTicketFilename, readRegisterItemContent, readSpecdojoFields, toDisplayItem, updateSpecdojoFields, VALID_STATUSES, } from "./
|
|
8
|
-
import { isUtcIsoSeconds, nowUtcIsoSeconds } from "
|
|
6
|
+
import { dump, load } from "../shared/yaml.js";
|
|
7
|
+
import { CELL_NONE, displayIdFromTicketFilename, readRegisterItemContent, readSpecdojoFields, toDisplayItem, updateSpecdojoFields, VALID_STATUSES, } from "./item.js";
|
|
8
|
+
import { isUtcIsoSeconds, nowUtcIsoSeconds } from "../shared/time.js";
|
|
9
9
|
export const REGISTER_EVENTS_DIRNAME = "events";
|
|
10
10
|
export const REGISTER_EVENTS_SCHEMA_MODELINE = "# yaml-language-server: $schema=../../../../../../specdojo/schemas/v1/register-events.schema.yaml";
|
|
11
11
|
export const REGISTER_EVENT_FIELDS = [
|
|
@@ -20,6 +20,9 @@ export const REGISTER_EVENT_FIELDS = [
|
|
|
20
20
|
"completed",
|
|
21
21
|
"conclusion",
|
|
22
22
|
"block_reason",
|
|
23
|
+
"approach",
|
|
24
|
+
"targets",
|
|
25
|
+
"derived_from",
|
|
23
26
|
];
|
|
24
27
|
export const REGISTER_EVENT_ACTIONS = [
|
|
25
28
|
"add",
|
|
@@ -68,6 +71,9 @@ export function registerEventFieldValues(content, filename, timeZone) {
|
|
|
68
71
|
completed: item.completed,
|
|
69
72
|
conclusion: item.conclusion,
|
|
70
73
|
block_reason: parsed.blockReason,
|
|
74
|
+
approach: item.approach ?? CELL_NONE,
|
|
75
|
+
targets: item.targets ? JSON.stringify(item.targets) : CELL_NONE,
|
|
76
|
+
derived_from: item.derivedFrom ? JSON.stringify(item.derivedFrom) : CELL_NONE,
|
|
71
77
|
};
|
|
72
78
|
}
|
|
73
79
|
function isUnsetFieldValue(value) {
|
|
@@ -188,7 +194,7 @@ export function validateRegisterEventShape(value, source) {
|
|
|
188
194
|
export function readRegisterEventsFromContent(content, source) {
|
|
189
195
|
let parsed;
|
|
190
196
|
try {
|
|
191
|
-
parsed =
|
|
197
|
+
parsed = load(content);
|
|
192
198
|
}
|
|
193
199
|
catch (error) {
|
|
194
200
|
const detail = error instanceof Error ? error.message : String(error);
|
|
@@ -206,10 +212,10 @@ export function readRegisterEventsFromContent(content, source) {
|
|
|
206
212
|
return events;
|
|
207
213
|
}
|
|
208
214
|
export function serializeRegisterEvents(events) {
|
|
209
|
-
return `${REGISTER_EVENTS_SCHEMA_MODELINE}\n${
|
|
215
|
+
return `${REGISTER_EVENTS_SCHEMA_MODELINE}\n${dump([...events], {
|
|
210
216
|
lineWidth: -1,
|
|
211
217
|
noRefs: true,
|
|
212
|
-
|
|
218
|
+
quoteStyle: "double",
|
|
213
219
|
})}`;
|
|
214
220
|
}
|
|
215
221
|
export function appendRegisterEvent(content, event) {
|
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
// 未移行の期間だけ Git 差分を読み、event の開始時刻より前の legacy 履歴として統合する。
|
|
3
3
|
//
|
|
4
4
|
// 比較対象は生成される登録項目一覧の列(ステータス・タイトル・説明・分類・優先度・担当・
|
|
5
|
-
//
|
|
6
|
-
//
|
|
5
|
+
// 登録日・期限・完了日・結論)に、待機時のブロック理由と approach / targets /
|
|
6
|
+
// derived_from を加える。
|
|
7
|
+
// 一覧に表示しない構造化フィールドも、個票の更新履歴として監査できるよう比較対象にする。
|
|
7
8
|
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
8
9
|
import { basename, join } from "node:path";
|
|
9
|
-
import { displayIdFromTicketFilename, isPlaceholderCell } from "./
|
|
10
|
-
import { gitOutput, gitResult } from "
|
|
11
|
-
import { DEFAULT_REGISTER_DATE_TIMEZONE } from "
|
|
12
|
-
import { REGISTER_EVENT_FIELDS, REGISTER_EVENTS_DIRNAME, displayIdFromRegisterEventFilename, readRegisterEventsFromContent, registerEventFieldValues, } from "./
|
|
10
|
+
import { displayIdFromTicketFilename, isPlaceholderCell } from "./item.js";
|
|
11
|
+
import { gitOutput, gitResult } from "../shared/git.js";
|
|
12
|
+
import { DEFAULT_REGISTER_DATE_TIMEZONE } from "../shared/specdojo-config.js";
|
|
13
|
+
import { REGISTER_EVENT_FIELDS, REGISTER_EVENTS_DIRNAME, displayIdFromRegisterEventFilename, readRegisterEventsFromContent, registerEventFieldValues, } from "./events.js";
|
|
13
14
|
// 比較する項目と出力順。登録項目一覧の列順(ID と個票リンクを除く)に合わせる。
|
|
14
15
|
export const REGISTER_HISTORY_FIELDS = REGISTER_EVENT_FIELDS;
|
|
15
16
|
// git log の1コミット分の区切り(レコード分離子)とヘッダー項目の区切り(単位分離子)。
|