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,105 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { load } from "../shared/yaml.js";
|
|
4
|
+
import { sanitizeDashboardCell } from "./shared.js";
|
|
5
|
+
export const EXEC_RECORDS_FILE = "exec-records.md";
|
|
6
|
+
function readSpecdojoFrontmatter(filePath) {
|
|
7
|
+
try {
|
|
8
|
+
const content = readFileSync(filePath, "utf8");
|
|
9
|
+
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
10
|
+
if (!match)
|
|
11
|
+
return {};
|
|
12
|
+
const parsed = load(match[1]);
|
|
13
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
14
|
+
return {};
|
|
15
|
+
const specdojo = parsed.specdojo;
|
|
16
|
+
return typeof specdojo === "object" && specdojo !== null && !Array.isArray(specdojo)
|
|
17
|
+
? specdojo
|
|
18
|
+
: {};
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// 壊れた frontmatter の記録も一覧から辿れるよう、属性なしの行として残す。
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function frontmatterText(value) {
|
|
26
|
+
if (typeof value === "string" && value.trim())
|
|
27
|
+
return value.trim();
|
|
28
|
+
if (value instanceof Date)
|
|
29
|
+
return value.toISOString();
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
function listMarkdownFiles(dir, suffix) {
|
|
33
|
+
if (!existsSync(dir))
|
|
34
|
+
return [];
|
|
35
|
+
return readdirSync(dir)
|
|
36
|
+
.filter((name) => name.endsWith(suffix))
|
|
37
|
+
.sort();
|
|
38
|
+
}
|
|
39
|
+
// execution/exec/{plans,results} の記録を実行単位(ファイル名の stem)でまとめる。
|
|
40
|
+
// 並びは開始日時の新しい順、開始日時が無いものは後ろに stem 順で置く。
|
|
41
|
+
export function collectExecRecords(execPath) {
|
|
42
|
+
const rows = new Map();
|
|
43
|
+
const rowFor = (stem) => {
|
|
44
|
+
const existing = rows.get(stem);
|
|
45
|
+
if (existing)
|
|
46
|
+
return existing;
|
|
47
|
+
const created = { stem };
|
|
48
|
+
rows.set(stem, created);
|
|
49
|
+
return created;
|
|
50
|
+
};
|
|
51
|
+
for (const name of listMarkdownFiles(join(execPath, "plans"), "-plan.md")) {
|
|
52
|
+
const row = rowFor(name.slice(0, -"-plan.md".length));
|
|
53
|
+
const fm = readSpecdojoFrontmatter(join(execPath, "plans", name));
|
|
54
|
+
row.planFile = name;
|
|
55
|
+
row.taskId ??= frontmatterText(fm.task_id);
|
|
56
|
+
row.mode ??= frontmatterText(fm.mode);
|
|
57
|
+
}
|
|
58
|
+
for (const name of listMarkdownFiles(join(execPath, "results"), "-result.md")) {
|
|
59
|
+
const row = rowFor(name.slice(0, -"-result.md".length));
|
|
60
|
+
const fm = readSpecdojoFrontmatter(join(execPath, "results", name));
|
|
61
|
+
row.resultFile = name;
|
|
62
|
+
row.taskId = frontmatterText(fm.task_id) ?? row.taskId;
|
|
63
|
+
row.mode = frontmatterText(fm.mode) ?? row.mode;
|
|
64
|
+
row.status = frontmatterText(fm.status);
|
|
65
|
+
row.startedAt = frontmatterText(fm.started_at);
|
|
66
|
+
}
|
|
67
|
+
return [...rows.values()].sort((a, b) => {
|
|
68
|
+
if (a.startedAt && b.startedAt && a.startedAt !== b.startedAt) {
|
|
69
|
+
return a.startedAt < b.startedAt ? 1 : -1;
|
|
70
|
+
}
|
|
71
|
+
if (a.startedAt && !b.startedAt)
|
|
72
|
+
return -1;
|
|
73
|
+
if (!a.startedAt && b.startedAt)
|
|
74
|
+
return 1;
|
|
75
|
+
return a.stem.localeCompare(b.stem);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function execRecordLink(dir, file, label) {
|
|
79
|
+
return file ? `[${label}](../exec/${dir}/${file})` : "-";
|
|
80
|
+
}
|
|
81
|
+
export function buildExecRecordsMarkdown(projectId, rows) {
|
|
82
|
+
const lines = [
|
|
83
|
+
"# 実行記録一覧",
|
|
84
|
+
"",
|
|
85
|
+
`- project_id: \`${projectId}\``,
|
|
86
|
+
`- 再生成: \`specdojo dashboard build --project ${projectId}\``,
|
|
87
|
+
"",
|
|
88
|
+
"> このページは `specdojo dashboard build` が生成した派生ビューです。正本は `execution/exec/` 配下の plan / result であり、このページを手編集しても次回のビルドで失われます。実行記録はサイドバーに載せないため、このページから辿ります。",
|
|
89
|
+
"",
|
|
90
|
+
];
|
|
91
|
+
if (rows.length === 0) {
|
|
92
|
+
lines.push("- 実行記録はまだありません。");
|
|
93
|
+
return lines.join("\n");
|
|
94
|
+
}
|
|
95
|
+
lines.push(`- 件数: ${rows.length}`, "");
|
|
96
|
+
lines.push("| 開始日時 | task | mode | status | plan | result |");
|
|
97
|
+
lines.push("| --- | --- | --- | --- | --- | --- |");
|
|
98
|
+
for (const row of rows) {
|
|
99
|
+
const task = row.taskId ? `\`${sanitizeDashboardCell(row.taskId)}\`` : "-";
|
|
100
|
+
const mode = row.mode ? `\`${sanitizeDashboardCell(row.mode)}\`` : "-";
|
|
101
|
+
const status = row.status ? `\`${sanitizeDashboardCell(row.status)}\`` : "-";
|
|
102
|
+
lines.push(`| ${row.startedAt ? sanitizeDashboardCell(row.startedAt) : "-"} | ${task} | ${mode} | ${status} | ${execRecordLink("plans", row.planFile, "plan")} | ${execRecordLink("results", row.resultFile, "result")} |`);
|
|
103
|
+
}
|
|
104
|
+
return lines.join("\n");
|
|
105
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { load } from "../shared/yaml.js";
|
|
4
|
+
import { readJson } from "../shared/fs.js";
|
|
5
|
+
import { cronMatches, cronOccurrences, isRoutineDue, routineActionKindLabel, } from "../routine/routine.js";
|
|
6
|
+
// routine ファイル(rtn-*.yaml)を読み、状態ファイル generated/routine-state.json と突き合わせて
|
|
7
|
+
// 最終実行・実行結果・due 状況を得る。CLI 出力(routine list)の転記に依存しない。
|
|
8
|
+
export function aggregateRoutines(routinesPath) {
|
|
9
|
+
if (!routinesPath || !existsSync(routinesPath))
|
|
10
|
+
return { rows: [], docs: [], history: [] };
|
|
11
|
+
const result = {
|
|
12
|
+
rows: [],
|
|
13
|
+
docs: [],
|
|
14
|
+
history: readRoutineRunHistory(join(routinesPath, "generated", "routine-runs.jsonl")),
|
|
15
|
+
error: undefined,
|
|
16
|
+
};
|
|
17
|
+
const stateEntries = readRoutineStateEntries(join(routinesPath, "generated", "routine-state.json"));
|
|
18
|
+
const now = new Date();
|
|
19
|
+
const files = readdirSync(routinesPath)
|
|
20
|
+
.filter((name) => /^rtn-.*\.(ya?ml)$/.test(name))
|
|
21
|
+
.sort();
|
|
22
|
+
for (const file of files) {
|
|
23
|
+
try {
|
|
24
|
+
const doc = parseRoutineFileSafe(join(routinesPath, file));
|
|
25
|
+
if (!doc?.id || typeof doc.id !== "string")
|
|
26
|
+
continue;
|
|
27
|
+
result.docs.push(doc);
|
|
28
|
+
buildRoutineRow(result, doc, stateEntries, now);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
result.error = `routine file parse failed: ${file}`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
result.rows.sort((a, b) => a.id.localeCompare(b.id));
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
export function readRoutineRunHistory(historyPath) {
|
|
38
|
+
if (!existsSync(historyPath))
|
|
39
|
+
return [];
|
|
40
|
+
const entries = [];
|
|
41
|
+
for (const [index, line] of readFileSync(historyPath, "utf8").split(/\r?\n/).entries()) {
|
|
42
|
+
if (!line.trim())
|
|
43
|
+
continue;
|
|
44
|
+
try {
|
|
45
|
+
const value = JSON.parse(line);
|
|
46
|
+
if (value.version === 1 &&
|
|
47
|
+
typeof value.routine_id === "string" &&
|
|
48
|
+
typeof value.scheduled_for === "string" &&
|
|
49
|
+
typeof value.started_at === "string" &&
|
|
50
|
+
typeof value.completed_at === "string" &&
|
|
51
|
+
["success", "partial", "failure", "skipped"].includes(value.result) &&
|
|
52
|
+
Array.isArray(value.job_run_ids)) {
|
|
53
|
+
entries.push(value);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
throw new Error("invalid routine history entry");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
throw new Error(`routine history parse failed at line ${index + 1}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return entries;
|
|
64
|
+
}
|
|
65
|
+
// 毎時の dashboard 更新のように 1 日に何度も動く routine は、日ごとに 1 行へまとめる。
|
|
66
|
+
export const ROUTINE_ROW_COLLAPSE_THRESHOLD = 3;
|
|
67
|
+
export function formatZonedDateTime(iso, timeZone) {
|
|
68
|
+
const date = new Date(iso);
|
|
69
|
+
if (Number.isNaN(date.getTime()))
|
|
70
|
+
return iso;
|
|
71
|
+
const parts = new Intl.DateTimeFormat("en-CA", {
|
|
72
|
+
timeZone,
|
|
73
|
+
month: "2-digit",
|
|
74
|
+
day: "2-digit",
|
|
75
|
+
hour: "2-digit",
|
|
76
|
+
minute: "2-digit",
|
|
77
|
+
hour12: false,
|
|
78
|
+
}).formatToParts(date);
|
|
79
|
+
const get = (type) => parts.find((part) => part.type === type)?.value ?? "";
|
|
80
|
+
return `${get("month")}-${get("day")} ${get("hour")}:${get("minute")}`;
|
|
81
|
+
}
|
|
82
|
+
export function zonedDateKey(date, timeZone) {
|
|
83
|
+
return new Intl.DateTimeFormat("en-CA", {
|
|
84
|
+
timeZone,
|
|
85
|
+
year: "numeric",
|
|
86
|
+
month: "2-digit",
|
|
87
|
+
day: "2-digit",
|
|
88
|
+
}).format(date);
|
|
89
|
+
}
|
|
90
|
+
function previousDateKey(dateKey) {
|
|
91
|
+
const [year, month, day] = dateKey.split("-").map(Number);
|
|
92
|
+
const previous = new Date(Date.UTC(year, month - 1, day - 1));
|
|
93
|
+
return previous.toISOString().slice(0, 10);
|
|
94
|
+
}
|
|
95
|
+
function scheduledToday(doc, today, now, timeZone) {
|
|
96
|
+
if (!doc.trigger || doc.enabled === false)
|
|
97
|
+
return [];
|
|
98
|
+
const start = Math.floor((now.getTime() - 36 * 60 * 60 * 1000) / 60_000) * 60_000;
|
|
99
|
+
const end = Math.floor((now.getTime() + 36 * 60 * 60 * 1000) / 60_000) * 60_000;
|
|
100
|
+
const matches = [];
|
|
101
|
+
for (let cursor = start; cursor <= end; cursor += 60_000) {
|
|
102
|
+
const candidate = new Date(cursor);
|
|
103
|
+
if (zonedDateKey(candidate, timeZone) === today &&
|
|
104
|
+
cronMatches(doc.trigger.cron, doc.trigger.timezone, candidate)) {
|
|
105
|
+
matches.push(candidate);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return matches;
|
|
109
|
+
}
|
|
110
|
+
export function buildDailyRoutineRows(docs, history, now, timeZone = "Asia/Tokyo") {
|
|
111
|
+
const today = zonedDateKey(now, timeZone);
|
|
112
|
+
const yesterday = previousDateKey(today);
|
|
113
|
+
const rows = history
|
|
114
|
+
.filter((entry) => {
|
|
115
|
+
const key = zonedDateKey(new Date(entry.scheduled_for), timeZone);
|
|
116
|
+
return key === yesterday || key === today;
|
|
117
|
+
})
|
|
118
|
+
.map((entry) => ({
|
|
119
|
+
day: zonedDateKey(new Date(entry.scheduled_for), timeZone) === yesterday ? "昨日" : "本日",
|
|
120
|
+
routineId: entry.routine_id,
|
|
121
|
+
scheduledFor: entry.scheduled_for,
|
|
122
|
+
startedAt: entry.started_at,
|
|
123
|
+
completedAt: entry.completed_at,
|
|
124
|
+
result: entry.result,
|
|
125
|
+
jobRunIds: entry.job_run_ids,
|
|
126
|
+
runCount: 1,
|
|
127
|
+
}));
|
|
128
|
+
const completedKeys = new Set(history.map((entry) => `${entry.routine_id}:${new Date(entry.scheduled_for).toISOString().slice(0, 16)}`));
|
|
129
|
+
for (const doc of docs) {
|
|
130
|
+
for (const scheduledFor of scheduledToday(doc, today, now, timeZone)) {
|
|
131
|
+
const key = `${doc.id}:${scheduledFor.toISOString().slice(0, 16)}`;
|
|
132
|
+
if (completedKeys.has(key))
|
|
133
|
+
continue;
|
|
134
|
+
rows.push({
|
|
135
|
+
day: "本日",
|
|
136
|
+
routineId: doc.id,
|
|
137
|
+
scheduledFor: scheduledFor.toISOString(),
|
|
138
|
+
startedAt: "-",
|
|
139
|
+
completedAt: "-",
|
|
140
|
+
// 予定時刻を過ぎても履歴がなければ、skip や cron 停止で動かなかったことを示す。
|
|
141
|
+
result: scheduledFor.getTime() <= now.getTime() ? "未実行" : "予定",
|
|
142
|
+
jobRunIds: [],
|
|
143
|
+
runCount: 1,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return collapseFrequentRoutineRows(rows).sort((a, b) => a.scheduledFor.localeCompare(b.scheduledFor) || a.routineId.localeCompare(b.routineId));
|
|
148
|
+
}
|
|
149
|
+
// 同じ routine・同じ日の行が閾値以上あれば、最新の実行 1 行に件数をまとめる。
|
|
150
|
+
export function collapseFrequentRoutineRows(rows) {
|
|
151
|
+
const groups = new Map();
|
|
152
|
+
for (const row of rows) {
|
|
153
|
+
const key = `${row.day}:${row.routineId}`;
|
|
154
|
+
groups.set(key, [...(groups.get(key) ?? []), row]);
|
|
155
|
+
}
|
|
156
|
+
const collapsed = [];
|
|
157
|
+
for (const group of groups.values()) {
|
|
158
|
+
if (group.length < ROUTINE_ROW_COLLAPSE_THRESHOLD) {
|
|
159
|
+
collapsed.push(...group);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
const executed = group.filter((row) => row.result !== "予定" && row.result !== "未実行");
|
|
163
|
+
const latest = [...(executed.length > 0 ? executed : group)].sort((a, b) => b.scheduledFor.localeCompare(a.scheduledFor))[0];
|
|
164
|
+
const failures = executed.filter((row) => row.result === "failure").length;
|
|
165
|
+
const partials = executed.filter((row) => row.result === "partial").length;
|
|
166
|
+
collapsed.push({
|
|
167
|
+
...latest,
|
|
168
|
+
runCount: executed.length > 0 ? executed.length : group.length,
|
|
169
|
+
jobRunIds: [],
|
|
170
|
+
result: failures > 0 ? "failure" : partials > 0 ? "partial" : latest.result,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return collapsed;
|
|
174
|
+
}
|
|
175
|
+
// generated/routine-state.json の routines.<id> が状態の正本。破損時は空。
|
|
176
|
+
function readRoutineStateEntries(statePath) {
|
|
177
|
+
const entries = {};
|
|
178
|
+
if (!existsSync(statePath))
|
|
179
|
+
return entries;
|
|
180
|
+
try {
|
|
181
|
+
const parsed = readJson(statePath);
|
|
182
|
+
const routines = parsed?.routines;
|
|
183
|
+
if (routines && typeof routines === "object") {
|
|
184
|
+
for (const [id, value] of Object.entries(routines)) {
|
|
185
|
+
if (value && typeof value === "object") {
|
|
186
|
+
const entry = value;
|
|
187
|
+
entries[id] = {
|
|
188
|
+
last_run: typeof entry.last_run === "string" ? entry.last_run : undefined,
|
|
189
|
+
last_result: typeof entry.last_result === "string" ? entry.last_result : undefined,
|
|
190
|
+
last_scheduled_for: typeof entry.last_scheduled_for === "string" ? entry.last_scheduled_for : undefined,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
return {};
|
|
198
|
+
}
|
|
199
|
+
return entries;
|
|
200
|
+
}
|
|
201
|
+
function parseRoutineFileSafe(filePath) {
|
|
202
|
+
let parsed;
|
|
203
|
+
try {
|
|
204
|
+
parsed = load(readFileSync(filePath, "utf8"));
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
if (!parsed || typeof parsed !== "object")
|
|
210
|
+
return undefined;
|
|
211
|
+
return parsed;
|
|
212
|
+
}
|
|
213
|
+
// routine 1 行を機械可読な正本から集計し、due は now と状態から判定する。
|
|
214
|
+
function buildRoutineRow(result, doc, stateEntries, now) {
|
|
215
|
+
const id = String(doc.id);
|
|
216
|
+
const enabled = doc.enabled === undefined ? true : doc.enabled;
|
|
217
|
+
const kind = doc.action ? routineActionKindLabel(doc.action) : "-";
|
|
218
|
+
const stateEntry = stateEntries[id];
|
|
219
|
+
let lastRun = "-";
|
|
220
|
+
if (stateEntry?.last_run) {
|
|
221
|
+
lastRun = stateEntry.last_result
|
|
222
|
+
? `${stateEntry.last_run} (${stateEntry.last_result})`
|
|
223
|
+
: stateEntry.last_run;
|
|
224
|
+
}
|
|
225
|
+
result.rows.push({
|
|
226
|
+
id,
|
|
227
|
+
name: typeof doc.name === "string" ? doc.name : undefined,
|
|
228
|
+
enabled,
|
|
229
|
+
schedule: routineScheduleLabel(doc),
|
|
230
|
+
kind,
|
|
231
|
+
lastRun,
|
|
232
|
+
due: computeRoutineDue(doc, stateEntry, enabled, now),
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
// interval / trigger + 現在時刻 + 状態(last_run / last_scheduled_for)から due を機械的に判定する。
|
|
236
|
+
export function computeRoutineDue(doc, stateEntry, enabled, now) {
|
|
237
|
+
if (!enabled)
|
|
238
|
+
return "disabled";
|
|
239
|
+
if (doc.trigger) {
|
|
240
|
+
const occurrences = cronOccurrences(doc, stateEntry?.last_scheduled_for, now);
|
|
241
|
+
return occurrences.length > 0 ? "due" : "-";
|
|
242
|
+
}
|
|
243
|
+
if (doc.interval) {
|
|
244
|
+
return isRoutineDue(doc, stateEntry?.last_run, now) ? "due" : "-";
|
|
245
|
+
}
|
|
246
|
+
return "-";
|
|
247
|
+
}
|
|
248
|
+
// interval / trigger を表すラベル。interval 優先、なければ trigger.cron。
|
|
249
|
+
function routineScheduleLabel(doc) {
|
|
250
|
+
if (typeof doc.interval === "string")
|
|
251
|
+
return doc.interval;
|
|
252
|
+
const trigger = doc.trigger;
|
|
253
|
+
if (trigger && typeof trigger.cron === "string")
|
|
254
|
+
return `cron: ${trigger.cron}`;
|
|
255
|
+
return "-";
|
|
256
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { stripTerminalControlSequences } from "../shared/text.js";
|
|
2
|
+
const MAX_DASHBOARD_CELL_LENGTH = 200;
|
|
3
|
+
// dashboard の表へは event や subprocess 由来の文字列も入る。表へ埋める直前に
|
|
4
|
+
// ターミナル制御シーケンスと改行類を除き、列区切りをエスケープして長さを制限する。
|
|
5
|
+
export function sanitizeDashboardCell(text) {
|
|
6
|
+
const singleLine = stripTerminalControlSequences(text)
|
|
7
|
+
.replace(/[\t\r\n]+/g, " ")
|
|
8
|
+
.replace(/ +/g, " ")
|
|
9
|
+
.trim();
|
|
10
|
+
const truncated = singleLine.length <= MAX_DASHBOARD_CELL_LENGTH
|
|
11
|
+
? singleLine
|
|
12
|
+
: `${singleLine.slice(0, MAX_DASHBOARD_CELL_LENGTH)}…`;
|
|
13
|
+
return truncated.replace(/\|/g, "\\|");
|
|
14
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, readdirSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { readYaml } from "../shared/fs.js";
|
|
4
|
+
import { normalizeDateOnly } from "../shared/time.js";
|
|
4
5
|
const CATALOG_STATUSES = ["not_started", "draft", "primary"];
|
|
5
6
|
function isRecord(value) {
|
|
6
7
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join, resolve } from "node:path";
|
|
3
|
-
import { getProjectCatalogPath, getProjectTimelinePath, loadConfig, loadEnv, specdojoRootDir, } from "
|
|
3
|
+
import { getProjectCatalogPath, getProjectTimelinePath, loadConfig, loadEnv, specdojoRootDir, } from "../shared/specdojo-config.js";
|
|
4
4
|
import { buildTimeline, renderCatalogScaffoldMarkdown, renderTimelineOrderMarkdown, } from "./timeline-build.js";
|
|
5
5
|
function resolveTimelinePaths(opts) {
|
|
6
6
|
loadEnv();
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
-
import { addProjectOption, printCommandError, resolveCatalogPath } from "
|
|
3
|
-
import { runGenerate } from "
|
|
4
|
-
import { specdojoRootDir } from "
|
|
5
|
-
import { resolveSpecdojoPath } from "
|
|
6
|
-
import { applyTrash, planTrash } from "./
|
|
2
|
+
import { addProjectOption, printCommandError, resolveCatalogPath } from "../catalog/catalog.js";
|
|
3
|
+
import { runGenerate } from "../catalog/generate.js";
|
|
4
|
+
import { specdojoRootDir } from "../shared/specdojo-config.js";
|
|
5
|
+
import { resolveSpecdojoPath } from "../docs/template-resolution.js";
|
|
6
|
+
import { applyTrash, planTrash } from "./trash.js";
|
|
7
7
|
function collectCommaSeparated(value, previous) {
|
|
8
8
|
return [
|
|
9
9
|
...previous,
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
// unrelated nested `evidence_refs[].path` field.
|
|
11
11
|
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
12
12
|
import { basename, dirname, join, relative } from "node:path";
|
|
13
|
-
import
|
|
14
|
-
import { isDctCatalogFileName } from "
|
|
15
|
-
import { resolveBasePath, resolveDeliverablePath } from "
|
|
16
|
-
import { readSpecdojoNamespace } from "
|
|
17
|
-
import { gitOutput } from "
|
|
13
|
+
import { load } from "../shared/yaml.js";
|
|
14
|
+
import { isDctCatalogFileName } from "../catalog/types.js";
|
|
15
|
+
import { resolveBasePath, resolveDeliverablePath } from "../catalog/paths.js";
|
|
16
|
+
import { readSpecdojoNamespace } from "../docs/frontmatter-namespace.js";
|
|
17
|
+
import { gitOutput } from "../shared/git.js";
|
|
18
18
|
function findCatalogFiles(catalogDir) {
|
|
19
19
|
return readdirSync(catalogDir).filter(isDctCatalogFileName).sort();
|
|
20
20
|
}
|
|
@@ -38,7 +38,7 @@ function locateDeliverable(catalogDir, localId) {
|
|
|
38
38
|
const fullPath = join(catalogDir, file);
|
|
39
39
|
let doc;
|
|
40
40
|
try {
|
|
41
|
-
doc =
|
|
41
|
+
doc = load(readFileSync(fullPath, "utf8"));
|
|
42
42
|
}
|
|
43
43
|
catch {
|
|
44
44
|
continue;
|
|
@@ -133,7 +133,7 @@ export function applyTrash(repoRoot, plan) {
|
|
|
133
133
|
const rewritten = rewriteCatalogPath(rawYaml, plan.localId, plan.newDocPath);
|
|
134
134
|
// Verify the rewrite parses and resolves to the expected path before touching the
|
|
135
135
|
// filesystem, so a formatting assumption that doesn't hold aborts cleanly.
|
|
136
|
-
const reparsed =
|
|
136
|
+
const reparsed = load(rewritten);
|
|
137
137
|
const resolvedAfter = reparsed?.groups
|
|
138
138
|
? findDeliverablePath(reparsed.groups, resolveBasePath("", reparsed.base_path), plan.localId)
|
|
139
139
|
: null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { runDevcontainerScaffold } from "./
|
|
2
|
-
import { specdojoPackageRootDir } from "
|
|
3
|
-
import { specdojoRootDir } from "
|
|
1
|
+
import { runDevcontainerScaffold } from "./scaffold.js";
|
|
2
|
+
import { specdojoPackageRootDir } from "../shared/package-paths.js";
|
|
3
|
+
import { specdojoRootDir } from "../shared/specdojo-config.js";
|
|
4
4
|
export function registerDevcontainerCommands(program) {
|
|
5
5
|
const dc = program.command("devcontainer").description("Dev Container helpers");
|
|
6
6
|
dc.command("scaffold")
|
|
@@ -10,6 +10,7 @@ export function registerDevcontainerCommands(program) {
|
|
|
10
10
|
.option("--ollama", "Add Ollama connection settings", false)
|
|
11
11
|
.option("--cron", "Add cron support", false)
|
|
12
12
|
.option("--tmux", "Add tmux", false)
|
|
13
|
+
.option("--workspace-name <name>", "Override the workspace parent name used under /workspaces")
|
|
13
14
|
.option("--force", "Overwrite existing .devcontainer/", false)
|
|
14
15
|
.option("--dry-run", "Show planned files without writing", false)
|
|
15
16
|
.action(async (opts) => {
|
|
@@ -17,6 +18,7 @@ export function registerDevcontainerCommands(program) {
|
|
|
17
18
|
await runDevcontainerScaffold({
|
|
18
19
|
packageRoot: specdojoPackageRootDir(),
|
|
19
20
|
repoRoot: specdojoRootDir(),
|
|
21
|
+
workspaceName: opts.workspaceName === undefined ? undefined : String(opts.workspaceName),
|
|
20
22
|
providers: opts.provider
|
|
21
23
|
? String(opts.provider)
|
|
22
24
|
.split(",")
|
|
@@ -1,14 +1,90 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
+
function resolveWorkspaceName(repoRoot, override) {
|
|
5
|
+
const workspaceName = override ?? path.basename(path.dirname(path.resolve(repoRoot)));
|
|
6
|
+
if (workspaceName === "." || workspaceName === ".." || !/^[A-Za-z0-9._-]+$/.test(workspaceName)) {
|
|
7
|
+
throw new Error(`Invalid workspace name: ${JSON.stringify(workspaceName)}. Use only ASCII letters, numbers, dot, underscore, and hyphen.`);
|
|
8
|
+
}
|
|
9
|
+
return workspaceName;
|
|
10
|
+
}
|
|
4
11
|
function repositoryVolumePrefix(repoRoot) {
|
|
5
12
|
const repositoryName = path.basename(path.resolve(repoRoot)).toLowerCase();
|
|
6
13
|
const safeName = repositoryName.replace(/[^a-z0-9_.-]+/g, "-").replace(/^[._-]+|[._-]+$/g, "");
|
|
7
14
|
return safeName || "project";
|
|
8
15
|
}
|
|
16
|
+
function extractPortNumber(value) {
|
|
17
|
+
if (typeof value === "number") {
|
|
18
|
+
return Number.isInteger(value) && value > 0 && value <= 65535 ? value : undefined;
|
|
19
|
+
}
|
|
20
|
+
if (typeof value === "string") {
|
|
21
|
+
const trimmed = value.trim();
|
|
22
|
+
const withoutProto = trimmed.replace(/\/(tcp|udp)$/, "");
|
|
23
|
+
const parts = withoutProto.split(":");
|
|
24
|
+
const portStr = parts.length === 3 ? parts[1] : parts[0];
|
|
25
|
+
const parsed = parseInt(portStr, 10);
|
|
26
|
+
return !isNaN(parsed) && parsed > 0 && parsed <= 65535 ? parsed : undefined;
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
export function extractPublishedPorts(devcontainer) {
|
|
31
|
+
const ports = [];
|
|
32
|
+
const addPort = (val) => {
|
|
33
|
+
const port = extractPortNumber(val);
|
|
34
|
+
if (port !== undefined && !ports.includes(port)) {
|
|
35
|
+
ports.push(port);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const appPort = devcontainer.appPort;
|
|
39
|
+
if (Array.isArray(appPort)) {
|
|
40
|
+
for (const p of appPort)
|
|
41
|
+
addPort(p);
|
|
42
|
+
}
|
|
43
|
+
else if (appPort !== undefined) {
|
|
44
|
+
addPort(appPort);
|
|
45
|
+
}
|
|
46
|
+
const forwardPorts = devcontainer.forwardPorts;
|
|
47
|
+
if (Array.isArray(forwardPorts)) {
|
|
48
|
+
for (const p of forwardPorts)
|
|
49
|
+
addPort(p);
|
|
50
|
+
}
|
|
51
|
+
else if (forwardPorts !== undefined) {
|
|
52
|
+
addPort(forwardPorts);
|
|
53
|
+
}
|
|
54
|
+
return ports;
|
|
55
|
+
}
|
|
56
|
+
export function generateSshConfigSample(ports) {
|
|
57
|
+
const lines = [
|
|
58
|
+
"# 接続元端末の ~/.ssh/config 用設定サンプル",
|
|
59
|
+
"# <host> や <user> などのプレースホルダーは実際の接続先環境に合わせて変更してください。",
|
|
60
|
+
"",
|
|
61
|
+
"# 常時稼働ホストへの通常接続用",
|
|
62
|
+
"Host <host>",
|
|
63
|
+
" HostName <host>",
|
|
64
|
+
" User <user>",
|
|
65
|
+
"",
|
|
66
|
+
"# devcontainer 内の tmux セッションへ直接入る接続用",
|
|
67
|
+
"Host <host>-tmux",
|
|
68
|
+
" HostName <host>",
|
|
69
|
+
" User <user>",
|
|
70
|
+
" RequestTTY force",
|
|
71
|
+
" RemoteCommand ~/bin/specdojo-tmux.sh",
|
|
72
|
+
];
|
|
73
|
+
if (ports.length > 0) {
|
|
74
|
+
for (const port of ports) {
|
|
75
|
+
lines.push(` LocalForward ${port} 127.0.0.1:${port}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
lines.push(" # devcontainer.json の公開ポート(appPort / forwardPorts)に合わせて LocalForward を追加してください。", " # 例: LocalForward 5173 127.0.0.1:5173");
|
|
80
|
+
}
|
|
81
|
+
lines.push("");
|
|
82
|
+
return lines.join("\n");
|
|
83
|
+
}
|
|
9
84
|
export async function runDevcontainerScaffold(opts) {
|
|
10
|
-
const { packageRoot, repoRoot, providers, editors, ollama, cron, tmux, force, dryRun } = opts;
|
|
85
|
+
const { packageRoot, repoRoot, workspaceName: workspaceNameOverride, providers, editors, ollama, cron, tmux, force, dryRun, } = opts;
|
|
11
86
|
const devcontainerDir = path.join(repoRoot, ".devcontainer");
|
|
87
|
+
const workspaceName = resolveWorkspaceName(repoRoot, workspaceNameOverride);
|
|
12
88
|
if (existsSync(devcontainerDir) && !force) {
|
|
13
89
|
if (dryRun) {
|
|
14
90
|
process.stdout.write(`[dry-run] skipped: .devcontainer/ already exists\n`);
|
|
@@ -26,6 +102,9 @@ export async function runDevcontainerScaffold(opts) {
|
|
|
26
102
|
const devcontainerJsonPath = path.join(templateDir, "devcontainer.json");
|
|
27
103
|
const baseJsonStr = await readFile(devcontainerJsonPath, "utf8");
|
|
28
104
|
const devcontainer = JSON.parse(baseJsonStr);
|
|
105
|
+
const workspaceRoot = `/workspaces/${workspaceName}`;
|
|
106
|
+
devcontainer.workspaceMount = `source=\${localWorkspaceFolder}/..,target=${workspaceRoot},type=bind,consistency=cached`;
|
|
107
|
+
devcontainer.workspaceFolder = `${workspaceRoot}/\${localWorkspaceFolderBasename}`;
|
|
29
108
|
const volumePrefix = repositoryVolumePrefix(repoRoot);
|
|
30
109
|
const volumeName = (name) => `${volumePrefix}-specdojo-${name}`;
|
|
31
110
|
devcontainer.mounts = devcontainer.mounts.map((mount) => mount.replace(/^source=specdojo-/, `source=${volumePrefix}-specdojo-`));
|
|
@@ -139,12 +218,18 @@ fi`);
|
|
|
139
218
|
if (extraScripts.length > 0) {
|
|
140
219
|
postCreateScript = postCreateScript.replace("npm install", extraScripts.join("\n\n") + "\n\nnpm install");
|
|
141
220
|
}
|
|
221
|
+
const specdojoTmuxTemplatePath = path.join(templateDir, "remote-host", "specdojo-tmux.sh.sample");
|
|
222
|
+
const specdojoTmuxScript = await readFile(specdojoTmuxTemplatePath, "utf8");
|
|
223
|
+
const publishedPorts = extractPublishedPorts(devcontainer);
|
|
224
|
+
const sshConfigScript = generateSshConfigSample(publishedPorts);
|
|
142
225
|
if (dryRun) {
|
|
143
226
|
process.stdout.write(`[dry-run] would write: .devcontainer/devcontainer.json\n`);
|
|
144
227
|
process.stdout.write(`[dry-run] would write: .devcontainer/post-create.sh\n`);
|
|
145
228
|
if (emacsInitTemplate !== undefined) {
|
|
146
229
|
process.stdout.write(`[dry-run] would write: .devcontainer/emacs/init.el\n`);
|
|
147
230
|
}
|
|
231
|
+
process.stdout.write(`[dry-run] would write: .devcontainer/remote-host/specdojo-tmux.sh.sample\n`);
|
|
232
|
+
process.stdout.write(`[dry-run] would write: .devcontainer/remote-host/ssh-config.sample\n`);
|
|
148
233
|
return;
|
|
149
234
|
}
|
|
150
235
|
await mkdir(devcontainerDir, { recursive: true });
|
|
@@ -154,12 +239,19 @@ fi`);
|
|
|
154
239
|
await mkdir(path.join(devcontainerDir, "emacs"), { recursive: true });
|
|
155
240
|
await writeFile(path.join(devcontainerDir, "emacs", "init.el"), emacsInitTemplate, "utf8");
|
|
156
241
|
}
|
|
242
|
+
const remoteHostDir = path.join(devcontainerDir, "remote-host");
|
|
243
|
+
await mkdir(remoteHostDir, { recursive: true });
|
|
244
|
+
await writeFile(path.join(remoteHostDir, "specdojo-tmux.sh.sample"), specdojoTmuxScript, "utf8");
|
|
245
|
+
await writeFile(path.join(remoteHostDir, "ssh-config.sample"), sshConfigScript, "utf8");
|
|
157
246
|
process.stdout.write(`Written: .devcontainer/devcontainer.json\n`);
|
|
158
247
|
process.stdout.write(`Written: .devcontainer/post-create.sh\n`);
|
|
159
248
|
if (emacsInitTemplate !== undefined) {
|
|
160
249
|
process.stdout.write(`Written: .devcontainer/emacs/init.el\n`);
|
|
161
250
|
}
|
|
251
|
+
process.stdout.write(`Written: .devcontainer/remote-host/specdojo-tmux.sh.sample\n`);
|
|
252
|
+
process.stdout.write(`Written: .devcontainer/remote-host/ssh-config.sample\n`);
|
|
162
253
|
process.stdout.write("Next steps:\n" +
|
|
163
254
|
" 1. Commit the scaffolded files.\n" +
|
|
164
|
-
" 2. Open this directory in a Dev Container (VS Code or compatible editor).\n"
|
|
255
|
+
" 2. Open this directory in a Dev Container (VS Code or compatible editor).\n" +
|
|
256
|
+
" 3. Remote host: copy .devcontainer/remote-host/specdojo-tmux.sh.sample to the host (e.g. ~/bin/) and merge ssh-config.sample into ~/.ssh/config on your client.\n");
|
|
165
257
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname, join, relative, resolve } from "node:path";
|
|
3
|
-
import
|
|
3
|
+
import { load } from "../shared/yaml.js";
|
|
4
4
|
import { readSpecdojoNamespace } from "./frontmatter-namespace.js";
|
|
5
5
|
import { specdojoDirectoryPaths, specdojoReferencePath, } from "./template-resolution.js";
|
|
6
6
|
const SKIP_DIRS = new Set(["node_modules", "dist", ".vitepress", "out"]);
|
|
@@ -176,7 +176,7 @@ function scanFile(fullPath, rootDir, repoRoot, collector, nestedMap, locales, lo
|
|
|
176
176
|
try {
|
|
177
177
|
const content = readFileSync(fullPath, "utf8");
|
|
178
178
|
if (isYaml) {
|
|
179
|
-
const parsed =
|
|
179
|
+
const parsed = load(content);
|
|
180
180
|
const topId = extractTopLevelId(parsed);
|
|
181
181
|
if (topId)
|
|
182
182
|
addId(collector, topId, entryPath, locale);
|
|
@@ -290,7 +290,7 @@ function loadIndexConfig(repoRoot, configPath) {
|
|
|
290
290
|
if (!existsSync(p))
|
|
291
291
|
return {};
|
|
292
292
|
try {
|
|
293
|
-
const parsed =
|
|
293
|
+
const parsed = load(readFileSync(p, "utf8"));
|
|
294
294
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
295
295
|
return parsed;
|
|
296
296
|
}
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
//
|
|
5
5
|
// 対象は Markdown frontmatter のみ。独立 YAML データファイル(dct-*.yaml / pm-*.yaml /
|
|
6
6
|
// sch-*.yaml など)は名前空間化しないため、本モジュールは使わない。
|
|
7
|
-
import
|
|
7
|
+
import { load } from "../shared/yaml.js";
|
|
8
8
|
const FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;
|
|
9
9
|
function specdojoFromBlock(block) {
|
|
10
10
|
let parsed;
|
|
11
11
|
try {
|
|
12
|
-
parsed =
|
|
12
|
+
parsed = load(block);
|
|
13
13
|
}
|
|
14
14
|
catch {
|
|
15
15
|
return {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
-
import { loadEnv, specdojoRootDir } from "
|
|
3
|
+
import { loadEnv, specdojoRootDir } from "../shared/specdojo-config.js";
|
|
4
4
|
import { assertControlGeneratedIndexes, buildDocIndex, lookupDocIndex, replaceDocIndexRefs, } from "./doc-index.js";
|
|
5
5
|
function printCommandError(error) {
|
|
6
6
|
const message = error instanceof Error ? error.message : String(error);
|