coding-agent-harness 1.0.5 → 1.0.7

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.
Files changed (260) hide show
  1. package/CONTRIBUTING.md +2 -2
  2. package/README.md +63 -3
  3. package/README.zh-CN.md +52 -3
  4. package/SKILL.md +43 -43
  5. package/dist/build-dist.mjs +189 -0
  6. package/dist/check-dist-observation.mjs +428 -0
  7. package/dist/check-harness.mjs +489 -0
  8. package/dist/check-import-graph.mjs +511 -0
  9. package/dist/check-runtime-emit.mjs +304 -0
  10. package/dist/check-type-boundaries.mjs +139 -0
  11. package/dist/commands/dashboard-command.mjs +80 -0
  12. package/dist/commands/migration-command.mjs +152 -0
  13. package/dist/commands/preset-command.mjs +91 -0
  14. package/dist/commands/task-command.mjs +324 -0
  15. package/dist/harness.mjs +304 -0
  16. package/dist/lib/capability-registry.mjs +643 -0
  17. package/dist/lib/check-module-parallel.mjs +227 -0
  18. package/dist/lib/check-profiles.mjs +414 -0
  19. package/dist/lib/check-task-contracts.mjs +54 -0
  20. package/dist/lib/core-shared.mjs +254 -0
  21. package/dist/lib/dashboard-data.mjs +608 -0
  22. package/dist/lib/dashboard-workbench.mjs +334 -0
  23. package/dist/lib/dashboard-writer.mjs +200 -0
  24. package/dist/lib/git-status-summary.mjs +45 -0
  25. package/dist/lib/governance-index-generator.mjs +236 -0
  26. package/dist/lib/governance-sync.mjs +617 -0
  27. package/dist/lib/governance-table-boundary.mjs +161 -0
  28. package/{scripts → dist}/lib/harness-core.mjs +2 -0
  29. package/dist/lib/harness-paths.mjs +338 -0
  30. package/dist/lib/lesson-maintenance.mjs +139 -0
  31. package/dist/lib/markdown-utils.mjs +193 -0
  32. package/dist/lib/migration-planner.mjs +439 -0
  33. package/dist/lib/migration-support.mjs +317 -0
  34. package/dist/lib/phase-kind.mjs +46 -0
  35. package/dist/lib/preset-audit-contracts.mjs +40 -0
  36. package/dist/lib/preset-engine.mjs +516 -0
  37. package/dist/lib/preset-registry.mjs +831 -0
  38. package/dist/lib/preset-resource-contracts.mjs +83 -0
  39. package/dist/lib/review-confirm-git-gate.mjs +244 -0
  40. package/dist/lib/status-builder.mjs +87 -0
  41. package/{scripts → dist}/lib/status-dashboard-renderer.mjs +44 -46
  42. package/dist/lib/structure-migration.mjs +404 -0
  43. package/dist/lib/subagent-authorization-audit.mjs +198 -0
  44. package/dist/lib/task-audit-metadata.mjs +376 -0
  45. package/dist/lib/task-audit-migration.mjs +355 -0
  46. package/dist/lib/task-completion-consistency.mjs +29 -0
  47. package/dist/lib/task-index.mjs +133 -0
  48. package/dist/lib/task-lesson-candidates.mjs +239 -0
  49. package/dist/lib/task-lesson-sedimentation.mjs +300 -0
  50. package/dist/lib/task-lifecycle/create-task-helpers.mjs +84 -0
  51. package/dist/lib/task-lifecycle/phase-sync.mjs +82 -0
  52. package/dist/lib/task-lifecycle/review-confirm.mjs +93 -0
  53. package/dist/lib/task-lifecycle/review-gates.mjs +62 -0
  54. package/dist/lib/task-lifecycle/review-submission.mjs +52 -0
  55. package/dist/lib/task-lifecycle/scaffold-provenance.mjs +54 -0
  56. package/dist/lib/task-lifecycle/template-files.mjs +52 -0
  57. package/dist/lib/task-lifecycle/text-utils.mjs +26 -0
  58. package/dist/lib/task-lifecycle.mjs +611 -0
  59. package/dist/lib/task-metadata.mjs +116 -0
  60. package/dist/lib/task-review-model.mjs +474 -0
  61. package/dist/lib/task-scanner.mjs +439 -0
  62. package/dist/lib/task-tombstone-commands.mjs +125 -0
  63. package/dist/postinstall.mjs +14 -0
  64. package/dist/run-built-tests.mjs +84 -0
  65. package/docs-release/README.md +1 -0
  66. package/docs-release/architecture/overview.md +12 -12
  67. package/docs-release/architecture/overview.zh-CN.md +12 -12
  68. package/docs-release/architecture/system-explainer/01-system-overview.md +15 -14
  69. package/docs-release/architecture/system-explainer/02-module-dependency.md +8 -8
  70. package/docs-release/architecture/system-explainer/03-task-lifecycle.md +3 -3
  71. package/docs-release/architecture/system-explainer/04-check-and-governance.md +9 -7
  72. package/docs-release/architecture/system-explainer/05-data-flow.md +5 -5
  73. package/docs-release/architecture/system-explainer/06-preset-and-migration.md +1 -4
  74. package/docs-release/architecture/system-explainer/en-US/01-system-overview.md +15 -14
  75. package/docs-release/architecture/system-explainer/en-US/02-module-dependency.md +8 -8
  76. package/docs-release/architecture/system-explainer/en-US/03-task-lifecycle.md +3 -3
  77. package/docs-release/architecture/system-explainer/en-US/04-check-and-governance.md +10 -8
  78. package/docs-release/architecture/system-explainer/en-US/05-data-flow.md +5 -5
  79. package/docs-release/architecture/system-explainer/en-US/06-preset-and-migration.md +1 -4
  80. package/docs-release/guides/agent-installation.en-US.md +14 -8
  81. package/docs-release/guides/agent-installation.md +14 -8
  82. package/docs-release/guides/contributing.md +3 -3
  83. package/docs-release/guides/contributing.zh-CN.md +3 -3
  84. package/docs-release/guides/document-audience-and-surfaces.en-US.md +10 -10
  85. package/docs-release/guides/document-audience-and-surfaces.md +10 -10
  86. package/docs-release/guides/legacy-migration-agent-prompt.md +25 -2
  87. package/docs-release/guides/legacy-migration-agent-prompt.zh-CN.md +25 -2
  88. package/docs-release/guides/migration-playbook.en-US.md +63 -1
  89. package/docs-release/guides/migration-playbook.md +59 -1
  90. package/docs-release/guides/parent-control-repository-pattern.en-US.md +25 -25
  91. package/docs-release/guides/parent-control-repository-pattern.md +25 -25
  92. package/docs-release/guides/preset-development.md +2 -2
  93. package/docs-release/guides/repository-operating-models.en-US.md +21 -21
  94. package/docs-release/guides/repository-operating-models.md +21 -21
  95. package/docs-release/guides/task-state-machine.en-US.md +5 -5
  96. package/docs-release/guides/task-state-machine.md +5 -5
  97. package/docs-release/guides/typescript-runtime-migration-closeout.md +96 -0
  98. package/examples/minimal-project/AGENTS.md +2 -2
  99. package/examples/minimal-project/coding-agent-harness/harness.yaml +14 -0
  100. package/examples/minimal-project/coding-agent-harness/planning/tasks/demo-task/progress.md +11 -0
  101. package/examples/minimal-project/{docs/09-PLANNING/TASKS → coding-agent-harness/planning/tasks}/demo-task/review.md +1 -1
  102. package/package.json +20 -12
  103. package/presets/legacy-migration/preset.yaml +5 -5
  104. package/presets/legacy-migration/templates/execution_strategy.append.md +1 -1
  105. package/presets/lesson-sedimentation/preset.yaml +3 -3
  106. package/presets/module/preset.yaml +2 -2
  107. package/presets/module/templates/execution_strategy.append.md +1 -1
  108. package/presets/module/templates/task_plan.append.md +3 -3
  109. package/presets/standard-task/preset.yaml +2 -2
  110. package/references/adversarial-review-standard.md +2 -2
  111. package/references/agents-md-pattern.md +14 -14
  112. package/references/cadence-ledger.md +1 -1
  113. package/references/ci-cd-standard.md +1 -1
  114. package/references/delivery-operating-model-standard.md +4 -4
  115. package/references/docs-directory-standard.md +65 -159
  116. package/references/external-source-intake-standard.md +10 -10
  117. package/references/harness-ledger.md +5 -5
  118. package/references/legacy-12-phase-bootstrap.md +2 -2
  119. package/references/lessons-governance.md +15 -15
  120. package/references/long-running-task-standard.md +6 -6
  121. package/references/module-parallel-standard.md +34 -34
  122. package/references/planning-loop.md +6 -6
  123. package/references/project-onboarding-audit.md +4 -4
  124. package/references/regression-system.md +2 -2
  125. package/references/repo-governance-standard.md +4 -4
  126. package/references/review-routing-standard.md +1 -1
  127. package/references/ssot-governance.md +19 -19
  128. package/references/taskr-gap-analysis.md +5 -5
  129. package/references/walkthrough-closeout.md +14 -14
  130. package/references/worktree-parallel.md +3 -3
  131. package/skills/preset-creator/references/complex-task-skeleton/task_plan.md +1 -1
  132. package/skills/preset-creator/references/preset-package-skeleton.md +5 -5
  133. package/templates/AGENTS.md.template +26 -26
  134. package/templates/architecture/README.md +4 -4
  135. package/templates/architecture/service-catalog.md +2 -2
  136. package/templates/architecture/services/service-template.md +1 -1
  137. package/templates/dashboard/assets/app-src/20-overview.js +11 -5
  138. package/templates/dashboard/assets/app-src/40-modules.js +1 -1
  139. package/templates/dashboard/assets/app.js +12 -6
  140. package/templates/dashboard/assets/i18n.js +4 -2
  141. package/templates/development/README.md +10 -10
  142. package/templates/development/cross-repo-debugging.md +3 -3
  143. package/templates/development/external-context/service-template.md +2 -2
  144. package/templates/development/external-source-packs/README.md +4 -4
  145. package/templates/integrations/README.md +4 -4
  146. package/templates/integrations/api-contract.md +2 -2
  147. package/templates/integrations/event-contract.md +2 -2
  148. package/templates/integrations/third-party/vendor-template.md +2 -2
  149. package/templates/integrations/webhook-contract.md +2 -2
  150. package/templates/ledger/Harness-Ledger.md +1 -1
  151. package/templates/planning/INDEX.md +1 -0
  152. package/templates/planning/module_session_prompt.md +1 -1
  153. package/templates/planning/task_plan.md +1 -1
  154. package/templates/planning/walkthrough.md +47 -0
  155. package/templates/reference/docs-library-standard.md +8 -8
  156. package/templates/reference/external-source-intake-standard.md +15 -15
  157. package/templates/reference/repo-governance-standard.md +1 -1
  158. package/templates/ssot/Module-Registry.md +1 -1
  159. package/templates/walkthrough/walkthrough-template.md +2 -2
  160. package/templates-zh-CN/AGENTS.md.template +26 -26
  161. package/templates-zh-CN/CLAUDE.md.template +1 -1
  162. package/templates-zh-CN/architecture/README.md +4 -4
  163. package/templates-zh-CN/architecture/service-catalog.md +2 -2
  164. package/templates-zh-CN/architecture/services/service-template.md +1 -1
  165. package/templates-zh-CN/development/README.md +10 -10
  166. package/templates-zh-CN/development/cross-repo-debugging.md +3 -3
  167. package/templates-zh-CN/development/external-context/service-template.md +2 -2
  168. package/templates-zh-CN/development/external-source-packs/README.md +4 -4
  169. package/templates-zh-CN/integrations/README.md +4 -4
  170. package/templates-zh-CN/integrations/api-contract.md +2 -2
  171. package/templates-zh-CN/integrations/event-contract.md +2 -2
  172. package/templates-zh-CN/integrations/third-party/vendor-template.md +2 -2
  173. package/templates-zh-CN/integrations/webhook-contract.md +2 -2
  174. package/templates-zh-CN/ledger/Harness-Ledger.md +1 -1
  175. package/templates-zh-CN/lessons/lesson-arch-process-change.md +1 -1
  176. package/templates-zh-CN/lessons/lesson-new-doc.md +3 -3
  177. package/templates-zh-CN/lessons/lesson-ref-change.md +4 -4
  178. package/templates-zh-CN/planning/module_session_prompt.md +11 -11
  179. package/templates-zh-CN/planning/walkthrough.md +47 -0
  180. package/templates-zh-CN/reference/adversarial-review-standard.md +2 -2
  181. package/templates-zh-CN/reference/delivery-operating-model-standard.md +3 -3
  182. package/templates-zh-CN/reference/docs-library-standard.md +28 -28
  183. package/templates-zh-CN/reference/execution-workflow-standard.md +1 -1
  184. package/templates-zh-CN/reference/external-source-intake-standard.md +16 -16
  185. package/templates-zh-CN/reference/harness-ledger-standard.md +6 -6
  186. package/templates-zh-CN/reference/regression-ssot-governance.md +2 -2
  187. package/templates-zh-CN/reference/repo-governance-standard.md +1 -1
  188. package/templates-zh-CN/reference/review-routing-standard.md +1 -1
  189. package/templates-zh-CN/reference/walkthrough-standard.md +7 -7
  190. package/templates-zh-CN/reference/worktree-standard.md +1 -1
  191. package/templates-zh-CN/regression/Cadence-Ledger.md +2 -2
  192. package/templates-zh-CN/ssot/Delivery-SSoT.md +3 -3
  193. package/templates-zh-CN/ssot/Module-Registry.md +3 -3
  194. package/templates-zh-CN/ssot/Regression-SSoT.md +2 -2
  195. package/templates-zh-CN/walkthrough/walkthrough-template.md +5 -5
  196. package/tsconfig.dist.json +16 -0
  197. package/tsconfig.json +25 -0
  198. package/tsconfig.runtime.json +24 -0
  199. package/examples/minimal-project/.harness-capabilities.json +0 -8
  200. package/examples/minimal-project/docs/09-PLANNING/TASKS/demo-task/progress.md +0 -11
  201. package/scripts/check-harness.mjs +0 -508
  202. package/scripts/commands/dashboard-command.mjs +0 -67
  203. package/scripts/commands/migration-command.mjs +0 -126
  204. package/scripts/commands/preset-command.mjs +0 -73
  205. package/scripts/commands/task-command.mjs +0 -328
  206. package/scripts/harness.mjs +0 -291
  207. package/scripts/lib/capability-registry.mjs +0 -587
  208. package/scripts/lib/check-module-parallel.mjs +0 -230
  209. package/scripts/lib/check-profiles.mjs +0 -372
  210. package/scripts/lib/check-task-contracts.mjs +0 -55
  211. package/scripts/lib/core-shared.mjs +0 -249
  212. package/scripts/lib/dashboard-data.mjs +0 -520
  213. package/scripts/lib/dashboard-workbench.mjs +0 -336
  214. package/scripts/lib/dashboard-writer.mjs +0 -202
  215. package/scripts/lib/git-status-summary.mjs +0 -46
  216. package/scripts/lib/governance-index-generator.mjs +0 -174
  217. package/scripts/lib/governance-sync.mjs +0 -611
  218. package/scripts/lib/governance-table-boundary.mjs +0 -175
  219. package/scripts/lib/lesson-maintenance.mjs +0 -152
  220. package/scripts/lib/markdown-utils.mjs +0 -191
  221. package/scripts/lib/migration-planner.mjs +0 -476
  222. package/scripts/lib/migration-support.mjs +0 -312
  223. package/scripts/lib/phase-kind.mjs +0 -50
  224. package/scripts/lib/preset-audit-contracts.mjs +0 -37
  225. package/scripts/lib/preset-engine.mjs +0 -494
  226. package/scripts/lib/preset-registry.mjs +0 -776
  227. package/scripts/lib/preset-resource-contracts.mjs +0 -83
  228. package/scripts/lib/review-confirm-git-gate.mjs +0 -248
  229. package/scripts/lib/status-builder.mjs +0 -88
  230. package/scripts/lib/subagent-authorization-audit.mjs +0 -196
  231. package/scripts/lib/task-audit-metadata.mjs +0 -385
  232. package/scripts/lib/task-audit-migration.mjs +0 -350
  233. package/scripts/lib/task-completion-consistency.mjs +0 -26
  234. package/scripts/lib/task-index.mjs +0 -93
  235. package/scripts/lib/task-lesson-candidates.mjs +0 -242
  236. package/scripts/lib/task-lesson-sedimentation.mjs +0 -326
  237. package/scripts/lib/task-lifecycle/create-task-helpers.mjs +0 -67
  238. package/scripts/lib/task-lifecycle/phase-sync.mjs +0 -88
  239. package/scripts/lib/task-lifecycle/review-confirm.mjs +0 -112
  240. package/scripts/lib/task-lifecycle/review-gates.mjs +0 -73
  241. package/scripts/lib/task-lifecycle/review-submission.mjs +0 -63
  242. package/scripts/lib/task-lifecycle/scaffold-provenance.mjs +0 -49
  243. package/scripts/lib/task-lifecycle/template-files.mjs +0 -53
  244. package/scripts/lib/task-lifecycle/text-utils.mjs +0 -24
  245. package/scripts/lib/task-lifecycle.mjs +0 -616
  246. package/scripts/lib/task-metadata.mjs +0 -118
  247. package/scripts/lib/task-review-model.mjs +0 -455
  248. package/scripts/lib/task-scanner.mjs +0 -503
  249. package/scripts/lib/task-tombstone-commands.mjs +0 -140
  250. package/scripts/postinstall.mjs +0 -14
  251. package/templates/walkthrough/Closeout-SSoT.md +0 -43
  252. package/templates-zh-CN/walkthrough/Closeout-SSoT.md +0 -42
  253. /package/examples/minimal-project/{docs → coding-agent-harness/governance/generated}/Harness-Ledger.md +0 -0
  254. /package/examples/minimal-project/{docs/09-PLANNING/TASKS → coding-agent-harness/planning/tasks}/demo-task/INDEX.md +0 -0
  255. /package/examples/minimal-project/{docs/09-PLANNING/TASKS → coding-agent-harness/planning/tasks}/demo-task/brief.md +0 -0
  256. /package/examples/minimal-project/{docs/09-PLANNING/TASKS → coding-agent-harness/planning/tasks}/demo-task/execution_strategy.md +0 -0
  257. /package/examples/minimal-project/{docs/09-PLANNING/TASKS → coding-agent-harness/planning/tasks}/demo-task/findings.md +0 -0
  258. /package/examples/minimal-project/{docs/09-PLANNING/TASKS → coding-agent-harness/planning/tasks}/demo-task/lesson_candidates.md +0 -0
  259. /package/examples/minimal-project/{docs/09-PLANNING/TASKS → coding-agent-harness/planning/tasks}/demo-task/task_plan.md +0 -0
  260. /package/examples/minimal-project/{docs/09-PLANNING/TASKS → coding-agent-harness/planning/tasks}/demo-task/visual_map.md +0 -0
@@ -1,336 +0,0 @@
1
- import crypto from "node:crypto";
2
- import { spawn } from "node:child_process";
3
- import fs from "node:fs";
4
- import http from "node:http";
5
- import path from "node:path";
6
- import { URL } from "node:url";
7
- import { confirmTaskReview } from "./task-lifecycle.mjs";
8
- import { createLessonSedimentationTask } from "./task-lesson-sedimentation.mjs";
9
- import { normalizeTarget } from "./core-shared.mjs";
10
- import { collectTasks } from "./task-scanner.mjs";
11
- import { writeDashboardFolder } from "./dashboard-data.mjs";
12
- import {
13
- checkPresetPackage,
14
- installPresetPackage,
15
- listPresetPackages,
16
- seedBundledPresets,
17
- uninstallPresetPackage,
18
- } from "./preset-registry.mjs";
19
-
20
- const jsonHeaders = { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" };
21
-
22
- export async function serveDashboardWorkbench(outDir, targetInput, { host = "127.0.0.1", port = 0, localeOverride = "", autoRefresh = false, open = false, label = "dashboard workbench", recoverGeneratedDashboard = false } = {}) {
23
- if (host !== "127.0.0.1") throw new Error("dashboard workbench only supports --host 127.0.0.1");
24
- const target = normalizeTarget(targetInput);
25
- const outputDir = path.resolve(outDir);
26
- const csrfToken = crypto.randomBytes(24).toString("hex");
27
- const options = localeOverride ? { localeOverride } : {};
28
- let snapshotVersion = Date.now();
29
- const regenerate = () => {
30
- writeDashboardFolder(outputDir, targetInput, { ...options, workbenchRuntime: true, recoverGeneratedDashboard });
31
- snapshotVersion = Date.now();
32
- };
33
- regenerate();
34
-
35
- const server = http.createServer(async (request, response) => {
36
- try {
37
- const address = server.address();
38
- const actualPort = typeof address === "object" && address ? address.port : port;
39
- const origin = `http://${host}:${actualPort}`;
40
- const requestUrl = new URL(request.url || "/", origin);
41
-
42
- if (requestUrl.pathname === "/api/runtime" && request.method === "GET") {
43
- writeJson(response, 200, {
44
- mode: "workbench",
45
- csrfToken,
46
- writableActions: ["review-complete", "lesson-sedimentation-task", "preset-check", "preset-install", "preset-seed", "preset-uninstall"],
47
- target: target.projectRoot,
48
- autoRefresh: autoRefresh === true,
49
- snapshotVersion,
50
- });
51
- return;
52
- }
53
-
54
- if (requestUrl.pathname === "/api/tasks/review-complete" && request.method === "POST") {
55
- assertTrustedWorkbenchRequest(request, { origin, csrfToken });
56
- const body = await readJsonBody(request);
57
- const taskId = String(body.taskId || "");
58
- const task = collectTasks(target).find((item) => item.id === taskId);
59
- if (!task) {
60
- writeJson(response, 404, { error: "Task not found" });
61
- return;
62
- }
63
- if (!isTaskInReviewQueue(task)) {
64
- writeJson(response, 409, reviewQueueRejectionPayload(task));
65
- return;
66
- }
67
- if (task.reviewStatus === "confirmed") {
68
- writeJson(response, 409, { error: "Review is already confirmed." });
69
- return;
70
- }
71
- const result = confirmTaskReview(target.projectRoot, taskId, {
72
- reviewer: body.reviewer || "Human Reviewer",
73
- message: body.message || "confirmed from dashboard workbench",
74
- evidence: body.evidence || "",
75
- confirmText: body.confirmText || "",
76
- });
77
- regenerate();
78
- writeJson(response, 200, result);
79
- return;
80
- }
81
-
82
- if (requestUrl.pathname === "/api/tasks/lesson-sedimentation" && request.method === "POST") {
83
- assertTrustedWorkbenchRequest(request, { origin, csrfToken });
84
- const body = await readJsonBody(request);
85
- const taskId = String(body.taskId || "");
86
- const candidateId = String(body.candidateId || "");
87
- const task = collectTasks(target).find((item) => item.id === taskId);
88
- if (!task) {
89
- writeJson(response, 404, { error: "Task not found" });
90
- return;
91
- }
92
- if (!candidateId) {
93
- writeJson(response, 400, { error: "Missing lesson candidate id" });
94
- return;
95
- }
96
- const result = createLessonSedimentationTask(target.projectRoot, taskId, candidateId, {
97
- title: body.title || "",
98
- });
99
- regenerate();
100
- writeJson(response, 200, result);
101
- return;
102
- }
103
-
104
- if (requestUrl.pathname === "/api/presets/check" && request.method === "POST") {
105
- assertTrustedWorkbenchRequest(request, { origin, csrfToken });
106
- const body = await readJsonBody(request);
107
- const id = String(body.id || "");
108
- if (!id) {
109
- writeJson(response, 400, { error: "Missing preset id" });
110
- return;
111
- }
112
- const result = checkPresetPackage(id, { targetInput: target.projectRoot });
113
- writeJson(response, 200, result);
114
- return;
115
- }
116
-
117
- if (requestUrl.pathname === "/api/presets/install" && request.method === "POST") {
118
- assertTrustedWorkbenchRequest(request, { origin, csrfToken });
119
- const body = await readJsonBody(request);
120
- const source = String(body.source || "");
121
- if (!source) {
122
- writeJson(response, 400, { error: "Missing preset source" });
123
- return;
124
- }
125
- if (/^https?:\/\//i.test(source)) {
126
- writeJson(response, 400, { error: "Network preset sources are not supported by the dashboard workbench." });
127
- return;
128
- }
129
- const scope = normalizePresetScope(body.scope);
130
- const result = installPresetPackage(source, { force: body.force === true, scope, targetInput: target.projectRoot });
131
- regenerate();
132
- writeJson(response, 200, { ...result, scope });
133
- return;
134
- }
135
-
136
- if (requestUrl.pathname === "/api/presets/seed" && request.method === "POST") {
137
- assertTrustedWorkbenchRequest(request, { origin, csrfToken });
138
- const body = await readJsonBody(request);
139
- const scope = normalizePresetScope(body.scope);
140
- const result = seedBundledPresets({ force: body.force === true, dryRun: body.dryRun === true, scope, targetInput: target.projectRoot });
141
- if (body.dryRun !== true) regenerate();
142
- writeJson(response, 200, result);
143
- return;
144
- }
145
-
146
- if (requestUrl.pathname === "/api/presets/uninstall" && request.method === "POST") {
147
- assertTrustedWorkbenchRequest(request, { origin, csrfToken });
148
- const body = await readJsonBody(request);
149
- const id = String(body.id || "");
150
- if (!id) {
151
- writeJson(response, 400, { error: "Missing preset id" });
152
- return;
153
- }
154
- if (String(body.confirmText || "").trim() !== id) {
155
- writeJson(response, 400, { error: "Preset uninstall requires typing the preset id." });
156
- return;
157
- }
158
- const scope = normalizePresetScope(body.scope);
159
- const discovered = listPresetPackages({ targetInput: target.projectRoot }).find((preset) => preset.id === id);
160
- if (discovered?.source === "builtin") {
161
- writeJson(response, 409, { error: "Builtin preset cannot be uninstalled from the dashboard workbench.", id, source: "builtin" });
162
- return;
163
- }
164
- const result = uninstallPresetPackage(id, { scope, targetInput: target.projectRoot });
165
- regenerate();
166
- writeJson(response, 200, { ...result, scope });
167
- return;
168
- }
169
-
170
- if (request.method !== "GET" && request.method !== "HEAD") {
171
- writeJson(response, 405, { error: "Method not allowed" });
172
- return;
173
- }
174
- serveStaticFile(response, outputDir, requestUrl.pathname, request.method === "HEAD");
175
- } catch (error) {
176
- const status = error.status || (/CSRF|Origin|Host/.test(error.message) ? 403 : 400);
177
- writeJson(response, status, errorPayload(error));
178
- }
179
- });
180
-
181
- await new Promise((resolve, reject) => {
182
- server.once("error", reject);
183
- server.listen(Number(port), host, resolve);
184
- });
185
- const address = server.address();
186
- const actualPort = typeof address === "object" && address ? address.port : port;
187
- const url = `http://${host}:${actualPort}/`;
188
- let watcher = null;
189
- if (autoRefresh) watcher = startPollingWatch(target.docsRoot, regenerate);
190
- console.log(`${label}: ${url} csrf=${csrfToken} outDir=${outputDir}`);
191
- if (open) openBrowser(url);
192
-
193
- const close = () => {
194
- if (watcher) clearInterval(watcher);
195
- server.close(() => process.exit(0));
196
- };
197
- process.once("SIGINT", close);
198
- process.once("SIGTERM", close);
199
- await new Promise(() => {});
200
- }
201
-
202
- function normalizePresetScope(value) {
203
- const scope = String(value || "project");
204
- if (scope !== "project" && scope !== "user") throw new Error(`Invalid preset scope: ${scope}`);
205
- return scope;
206
- }
207
-
208
- function isTaskInReviewQueue(task) {
209
- return task?.reviewQueueState === "ready-to-confirm" && Array.isArray(task?.taskQueues) && task.taskQueues.includes("review");
210
- }
211
-
212
- function reviewQueueRejectionPayload(task) {
213
- return {
214
- error: "Review completion is only available for tasks in the review queue.",
215
- reviewQueueState: task?.reviewQueueState || "unknown",
216
- taskQueues: Array.isArray(task?.taskQueues) ? task.taskQueues : [],
217
- queueReasons: Array.isArray(task?.queueReasons) ? task.queueReasons : [],
218
- repairPrompt: task?.repairPrompt || "",
219
- reviewStatus: task?.reviewStatus || "unknown",
220
- taskId: task?.id || "",
221
- };
222
- }
223
-
224
- function startPollingWatch(root, regenerate) {
225
- let lastMtime = latestTreeMtime(root);
226
- let timer = null;
227
- return setInterval(() => {
228
- const nextMtime = latestTreeMtime(root);
229
- if (nextMtime <= lastMtime) return;
230
- lastMtime = nextMtime;
231
- clearTimeout(timer);
232
- timer = setTimeout(() => {
233
- try {
234
- regenerate();
235
- } catch (error) {
236
- console.error(`dashboard regeneration failed: ${error.message}`);
237
- }
238
- }, 250);
239
- }, 1000);
240
- }
241
-
242
- function latestTreeMtime(root) {
243
- let latest = 0;
244
- if (!fs.existsSync(root)) return latest;
245
- const visit = (dir) => {
246
- for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
247
- if ([".git", "node_modules", "tmp"].includes(entry.name)) continue;
248
- const fullPath = path.join(dir, entry.name);
249
- const stat = fs.statSync(fullPath);
250
- latest = Math.max(latest, stat.mtimeMs);
251
- if (entry.isDirectory()) visit(fullPath);
252
- }
253
- };
254
- visit(root);
255
- return latest;
256
- }
257
-
258
- function openBrowser(url) {
259
- const command =
260
- process.platform === "darwin" ? "open" :
261
- process.platform === "win32" ? "cmd" :
262
- "xdg-open";
263
- const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
264
- const child = spawn(command, args, { stdio: "ignore", detached: true });
265
- child.on("error", () => {});
266
- child.unref();
267
- }
268
-
269
- function assertTrustedWorkbenchRequest(request, { origin, csrfToken }) {
270
- const host = request.headers.host || "";
271
- if (host !== origin.replace(/^http:\/\//, "")) throw new Error("Host mismatch");
272
- if (request.headers.origin !== origin) throw new Error("Origin mismatch");
273
- if (request.headers["x-harness-csrf"] !== csrfToken) throw new Error("CSRF token mismatch");
274
- }
275
-
276
- function readJsonBody(request) {
277
- return new Promise((resolve, reject) => {
278
- let raw = "";
279
- request.setEncoding("utf8");
280
- request.on("data", (chunk) => {
281
- raw += chunk;
282
- if (raw.length > 32_768) {
283
- reject(new Error("Request body too large"));
284
- request.destroy();
285
- }
286
- });
287
- request.on("end", () => {
288
- try {
289
- resolve(raw ? JSON.parse(raw) : {});
290
- } catch {
291
- reject(new Error("Invalid JSON body"));
292
- }
293
- });
294
- request.on("error", reject);
295
- });
296
- }
297
-
298
- function serveStaticFile(response, outputDir, urlPath, headOnly) {
299
- const decoded = decodeURIComponent(urlPath);
300
- const relative = decoded === "/" ? "index.html" : decoded.replace(/^\/+/, "");
301
- const filePath = path.resolve(outputDir, relative);
302
- if (!isPathInside(filePath, outputDir) || !fs.existsSync(filePath) || fs.statSync(filePath).isDirectory()) {
303
- writeJson(response, 404, { error: "Not found" });
304
- return;
305
- }
306
- response.writeHead(200, { "content-type": mimeType(filePath), "cache-control": "no-store" });
307
- if (!headOnly) response.end(fs.readFileSync(filePath));
308
- else response.end();
309
- }
310
-
311
- function writeJson(response, status, payload) {
312
- response.writeHead(status, jsonHeaders);
313
- response.end(`${JSON.stringify(payload)}\n`);
314
- }
315
-
316
- function errorPayload(error) {
317
- const payload = { error: error.message };
318
- if (error.code) payload.code = error.code;
319
- if (Array.isArray(error.recovery) && error.recovery.length > 0) payload.recovery = error.recovery;
320
- if (error.details) payload.details = error.details;
321
- return payload;
322
- }
323
-
324
- function mimeType(filePath) {
325
- if (filePath.endsWith(".html")) return "text/html; charset=utf-8";
326
- if (filePath.endsWith(".js")) return "text/javascript; charset=utf-8";
327
- if (filePath.endsWith(".css")) return "text/css; charset=utf-8";
328
- if (filePath.endsWith(".json")) return "application/json; charset=utf-8";
329
- if (filePath.endsWith(".md")) return "text/markdown; charset=utf-8";
330
- return "application/octet-stream";
331
- }
332
-
333
- function isPathInside(candidate, parent) {
334
- const relative = path.relative(path.resolve(parent), path.resolve(candidate));
335
- return !relative.startsWith("..") && !path.isAbsolute(relative);
336
- }
@@ -1,202 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- import { readJsonSafe } from "./core-shared.mjs";
5
-
6
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
- const repoRoot = path.resolve(__dirname, "../..");
8
- const dashboardTemplateRoot = path.join(repoRoot, "templates/dashboard");
9
- const dashboardMarker = ".harness-dashboard";
10
-
11
- export function writeJsonFile(filePath, value) {
12
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
13
- fs.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`);
14
- }
15
-
16
- export function copyDashboardAssets(outDir, options = {}) {
17
- copyDirectory(dashboardTemplateRootForLocale(options.locale), outDir);
18
- }
19
-
20
- export function writeDashboardDirectory(outDir, bundle, options = {}) {
21
- const target = path.resolve(outDir);
22
- assertSafeDashboardTarget(target, options);
23
- if (fs.existsSync(target)) fs.rmSync(target, { recursive: true, force: true });
24
- fs.mkdirSync(target, { recursive: true });
25
- fs.writeFileSync(path.join(target, dashboardMarker), "generated dashboard directory\n");
26
- copyDashboardAssets(target, options);
27
- fs.writeFileSync(path.join(target, "assets/app.js"), readDashboardApp(dashboardTemplateRootForLocale(options.locale)));
28
- fs.writeFileSync(path.join(target, "index.html"), renderDashboardIndex(options.locale, options));
29
- writeJsonFile(path.join(target, "data/status.json"), bundle.status);
30
- writeJsonFile(path.join(target, "data/tables.json"), bundle.tables);
31
- writeJsonFile(path.join(target, "data/documents.json"), bundle.documents);
32
- writeJsonFile(path.join(target, "data/graph.json"), bundle.graph);
33
- writeJsonFile(path.join(target, "data/adoption.json"), bundle.adoption);
34
- writeJsonFile(path.join(target, "data/presetCatalog.json"), bundle.presetCatalog);
35
- fs.writeFileSync(
36
- path.join(target, "assets/dashboard-data.js"),
37
- `window.__HARNESS_DASHBOARD__ = ${JSON.stringify(bundle, null, 2)};\n`,
38
- );
39
- fs.writeFileSync(
40
- path.join(target, "README.md"),
41
- [
42
- "# Harness Dashboard",
43
- "",
44
- "This is a read-only static snapshot generated by `harness dashboard --out-dir`.",
45
- "Open `index.html` directly in a browser. No target project files are read at browser runtime.",
46
- "",
47
- ].join("\n"),
48
- );
49
- return target;
50
- }
51
-
52
- export function writeDashboardFile(outFile, bundle, options = {}) {
53
- const target = path.resolve(outFile);
54
- fs.mkdirSync(path.dirname(target), { recursive: true });
55
- fs.writeFileSync(target, renderDashboardFile(bundle, options));
56
- return target;
57
- }
58
-
59
- export function renderDashboardFile(bundle, options = {}) {
60
- const templateRoot = dashboardTemplateRootForLocale(options.locale);
61
- const readAsset = (relativePath) => fs.readFileSync(path.join(templateRoot, relativePath), "utf8");
62
- const css = readAsset("assets/app.css");
63
- const i18n = readAsset("assets/i18n.js");
64
- const markdown = readAsset("assets/markdown-reader.js");
65
- const mermaid = readAsset("assets/mermaid-renderer.js");
66
- const app = readDashboardApp(templateRoot);
67
- const title = options.locale === "zh-CN" ? "Harness 控制台" : "Harness Dashboard";
68
- const payload = JSON.stringify(bundle).replace(/</g, "\\u003c");
69
- const runtimeLocale = options.locale === "zh-CN" ? "zh" : "en";
70
- return `<!doctype html>
71
- <html lang="${options.locale === "zh-CN" ? "zh-CN" : "en"}">
72
- <head>
73
- <meta charset="utf-8">
74
- <meta name="viewport" content="width=device-width, initial-scale=1">
75
- <title>${title}</title>
76
- <link rel="icon" href="data:,">
77
- <style>${css}</style>
78
- </head>
79
- <body>
80
- <div id="app" class="app-shell" aria-live="polite"></div>
81
- <script>window.__HARNESS_DASHBOARD__ = ${payload};</script>
82
- <script>window.__HARNESS_LOCALE__ = ${JSON.stringify(runtimeLocale)};</script>
83
- <script>${i18n}</script>
84
- <script>${markdown}</script>
85
- <script>${mermaid}</script>
86
- <script>${app}</script>
87
- </body>
88
- </html>`;
89
- }
90
-
91
- function renderDashboardIndex(locale = "en-US", options = {}) {
92
- const normalizedLocale = locale === "zh-CN" ? "zh-CN" : "en";
93
- const runtimeLocale = locale === "zh-CN" ? "zh" : "en";
94
- const title = locale === "zh-CN" ? "Harness 控制台" : "Harness Dashboard";
95
- const assetVersion = Date.now();
96
- return `<!doctype html>
97
- <html lang="${normalizedLocale}">
98
- <head>
99
- <meta charset="utf-8">
100
- <meta name="viewport" content="width=device-width, initial-scale=1">
101
- <title>${title}</title>
102
- <link rel="icon" href="data:,">
103
- <link rel="stylesheet" href="./assets/app.css?v=${assetVersion}">
104
- </head>
105
- <body>
106
- <div id="app" class="app-shell" aria-live="polite"></div>
107
- <script src="./assets/dashboard-data.js?v=${assetVersion}"></script>
108
- <script>window.__HARNESS_LOCALE__ = ${JSON.stringify(runtimeLocale)};</script>
109
- <script>window.__HARNESS_WORKBENCH__ = ${options.workbenchRuntime === true ? "true" : "false"};</script>
110
- <script src="./assets/i18n.js?v=${assetVersion}"></script>
111
- <script src="./assets/markdown-reader.js?v=${assetVersion}"></script>
112
- <script src="./assets/mermaid-renderer.js?v=${assetVersion}"></script>
113
- <script src="./assets/app.js?v=${assetVersion}"></script>
114
- </body>
115
- </html>`;
116
- }
117
-
118
- function readDashboardApp(templateRoot) {
119
- const manifestPath = path.join(templateRoot, "assets/app.manifest.json");
120
- if (!fs.existsSync(manifestPath)) return fs.readFileSync(path.join(templateRoot, "assets/app.js"), "utf8");
121
- const manifest = readJsonSafe(manifestPath, null);
122
- if (!Array.isArray(manifest) || manifest.length === 0) throw new Error(`Invalid dashboard app manifest: ${manifestPath}`);
123
- return `${manifest.map((relativePath) => {
124
- const source = path.join(templateRoot, "assets", relativePath);
125
- if (!fs.existsSync(source)) throw new Error(`Dashboard app source missing: ${relativePath}`);
126
- return fs.readFileSync(source, "utf8").trimEnd();
127
- }).join("\n\n")}\n`;
128
- }
129
-
130
- function assertSafeDashboardTarget(target, options) {
131
- const localizedDashboardTemplateRoot = dashboardTemplateRootForLocale(options.locale);
132
- const sourceRepoRoot = options.repoRoot ? path.resolve(options.repoRoot) : "";
133
- const projectRoot = options.projectRoot ? path.resolve(options.projectRoot) : "";
134
- if (
135
- sourceRepoRoot &&
136
- projectRoot &&
137
- isPathInside(projectRoot, sourceRepoRoot) &&
138
- path.basename(projectRoot) === ".harness-private" &&
139
- isPathInside(target, sourceRepoRoot) &&
140
- !isPathInside(target, projectRoot)
141
- ) {
142
- throw new Error(`Refusing private dashboard output inside publishable source package: ${target}`);
143
- }
144
- const protectedRoots = [
145
- path.parse(target).root,
146
- process.env.HOME,
147
- options.repoRoot,
148
- options.projectRoot,
149
- options.docsRoot,
150
- dashboardTemplateRoot,
151
- localizedDashboardTemplateRoot,
152
- ].filter(Boolean).map((item) => path.resolve(item));
153
- if (protectedRoots.includes(target)) {
154
- throw new Error(`Refusing unsafe dashboard output directory: ${target}`);
155
- }
156
- for (const root of [options.docsRoot, dashboardTemplateRoot, localizedDashboardTemplateRoot].filter(Boolean).map((item) => path.resolve(item))) {
157
- if (isPathInside(target, root)) {
158
- throw new Error(`Refusing dashboard output inside protected directory: ${target}`);
159
- }
160
- }
161
- if (fs.existsSync(target)) {
162
- const entries = fs.readdirSync(target);
163
- const hasMarker = fs.existsSync(path.join(target, dashboardMarker));
164
- const canRecoverGeneratedDashboard = options.recoverGeneratedDashboard === true && looksLikeGeneratedDashboardDirectory(target);
165
- if (entries.length > 0 && !hasMarker && !canRecoverGeneratedDashboard) {
166
- throw new Error(`Refusing to overwrite non-dashboard directory: ${target}`);
167
- }
168
- }
169
- }
170
-
171
- function looksLikeGeneratedDashboardDirectory(target) {
172
- return [
173
- "index.html",
174
- "README.md",
175
- "assets/app.js",
176
- "assets/dashboard-data.js",
177
- "data/status.json",
178
- ].every((relativePath) => fs.existsSync(path.join(target, relativePath)));
179
- }
180
-
181
- function dashboardTemplateRootForLocale(locale = "en-US") {
182
- return dashboardTemplateRoot;
183
- }
184
-
185
- function isPathInside(candidate, parent) {
186
- const relative = path.relative(parent, candidate);
187
- return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
188
- }
189
-
190
- function copyDirectory(from, to) {
191
- if (!fs.existsSync(from)) throw new Error(`Missing dashboard template directory: ${from}`);
192
- fs.mkdirSync(to, { recursive: true });
193
- for (const entry of fs.readdirSync(from, { withFileTypes: true })) {
194
- const source = path.join(from, entry.name);
195
- const destination = path.join(to, entry.name);
196
- if (entry.isDirectory()) {
197
- copyDirectory(source, destination);
198
- } else {
199
- fs.copyFileSync(source, destination);
200
- }
201
- }
202
- }
@@ -1,46 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { inspectGit } from "./governance-sync.mjs";
4
-
5
- export function summarizeGitState(target) {
6
- const state = inspectGit(target.projectRoot);
7
- if (!state.inGit) {
8
- return {
9
- summary: {
10
- inGit: false,
11
- root: "",
12
- dirty: false,
13
- entries: [],
14
- blocksCliAutoCommit: false,
15
- },
16
- warnings: [],
17
- };
18
- }
19
- const targetRoot = real(target.projectRoot);
20
- const gitRoot = real(state.gitRoot);
21
- const rootMatches = gitRoot === targetRoot;
22
- const entries = rootMatches ? state.entries.map((entry) => ({
23
- path: entry.path,
24
- index: entry.index,
25
- worktree: entry.worktree,
26
- })) : [];
27
- const dirty = entries.length > 0;
28
- const warnings = [];
29
- if (dirty) {
30
- warnings.push(`dirty-state: ${entries.length} uncommitted Git path(s) may block CLI-owned auto-commit when they overlap a command write scope or are staged; commit them or record owner/no-commit reason before lifecycle commands.`);
31
- }
32
- return {
33
- summary: {
34
- inGit: true,
35
- root: rootMatches ? "TARGET:." : "outside-target",
36
- dirty,
37
- entries,
38
- blocksCliAutoCommit: !rootMatches || dirty,
39
- },
40
- warnings,
41
- };
42
- }
43
-
44
- function real(filePath) {
45
- return fs.realpathSync(filePath);
46
- }