forgedock 1.52.0 → 1.54.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.
Files changed (233) hide show
  1. package/.claude-plugin/marketplace.json +51 -0
  2. package/README.md +8 -2
  3. package/bin/auth/app-manifest.mjs +89 -0
  4. package/bin/auth/app-manifest.test.mjs +75 -0
  5. package/bin/auth/app-token.mjs +256 -0
  6. package/bin/auth/app-token.test.mjs +232 -0
  7. package/bin/brand.mjs +7 -0
  8. package/bin/config-history.mjs +151 -0
  9. package/bin/config-schema.mjs +115 -0
  10. package/bin/demo.mjs +65 -11
  11. package/bin/engine/outcome-codes.mjs +9 -3
  12. package/bin/engine/telemetry-seam.mjs +11 -3
  13. package/bin/engine/telemetry-seam.test.mjs +17 -0
  14. package/bin/engine-cli.mjs +110 -36
  15. package/bin/experiment.mjs +58 -6
  16. package/bin/first-run.mjs +122 -0
  17. package/bin/forge-utils.mjs +6 -2
  18. package/bin/forgedock.mjs +138 -142
  19. package/bin/help-text.mjs +144 -0
  20. package/bin/hooks/pre-tool-use.mjs +7 -0
  21. package/bin/journey.mjs +82 -83
  22. package/bin/lean/acceptance.mjs +313 -0
  23. package/bin/lean/acceptance.test.mjs +215 -0
  24. package/bin/lean/account-watch.mjs +28 -0
  25. package/bin/lean/account-watch.test.mjs +30 -0
  26. package/bin/lean/activation.mjs +38 -0
  27. package/bin/lean/activation.test.mjs +36 -1
  28. package/bin/lean/basered.mjs +115 -0
  29. package/bin/lean/basered.test.mjs +66 -0
  30. package/bin/lean/batch-health.mjs +114 -7
  31. package/bin/lean/batch-health.test.mjs +87 -1
  32. package/bin/lean/batch.mjs +41 -2
  33. package/bin/lean/batch.test.mjs +115 -11
  34. package/bin/lean/branchlock.mjs +54 -0
  35. package/bin/lean/branchlock.test.mjs +49 -0
  36. package/bin/lean/ceiling.mjs +72 -0
  37. package/bin/lean/ceiling.test.mjs +54 -0
  38. package/bin/lean/checkpoint-reconcile.mjs +43 -0
  39. package/bin/lean/checkpoint-reconcile.test.mjs +95 -0
  40. package/bin/lean/ci-budget.mjs +366 -0
  41. package/bin/lean/ci-budget.test.mjs +167 -0
  42. package/bin/lean/conformance.e2e.test.mjs +8 -1
  43. package/bin/lean/conformance.mjs +269 -38
  44. package/bin/lean/conformance.test.mjs +280 -7
  45. package/bin/lean/context.mjs +35 -6
  46. package/bin/lean/context.test.mjs +27 -1
  47. package/bin/lean/depcache.mjs +25 -1
  48. package/bin/lean/depcache.test.mjs +26 -0
  49. package/bin/lean/e2e.mjs +18 -2
  50. package/bin/lean/e2e.test.mjs +26 -1
  51. package/bin/lean/effects.mjs +47 -14
  52. package/bin/lean/execution.mjs +19 -3
  53. package/bin/lean/execution.test.mjs +63 -0
  54. package/bin/lean/facts.mjs +3 -3
  55. package/bin/lean/facts.test.mjs +5 -0
  56. package/bin/lean/findinglabel.mjs +16 -0
  57. package/bin/lean/findinglabel.test.mjs +39 -0
  58. package/bin/lean/fixround.mjs +14 -0
  59. package/bin/lean/fixround.test.mjs +25 -2
  60. package/bin/lean/gh-assoc.test.mjs +2 -1
  61. package/bin/lean/integration.mjs +100 -9
  62. package/bin/lean/integration.test.mjs +98 -0
  63. package/bin/lean/issuewatch-parity.mjs +64 -0
  64. package/bin/lean/issuewatch-parity.test.mjs +127 -0
  65. package/bin/lean/issuewatch-release.mjs +6 -2
  66. package/bin/lean/issuewatch-release.test.mjs +17 -1
  67. package/bin/lean/issuewatch.mjs +45 -6
  68. package/bin/lean/issuewatch.test.mjs +3 -2
  69. package/bin/lean/lanelock.mjs +14 -0
  70. package/bin/lean/lean.mjs +473 -100
  71. package/bin/lean/lean.test.mjs +686 -33
  72. package/bin/lean/light.mjs +48 -7
  73. package/bin/lean/light.test.mjs +37 -3
  74. package/bin/lean/limits.test.mjs +142 -9
  75. package/bin/lean/mechfix.mjs +124 -0
  76. package/bin/lean/mechfix.test.mjs +75 -0
  77. package/bin/lean/orchestrate-cancel.test.mjs +143 -0
  78. package/bin/lean/orchestrate.mjs +116 -28
  79. package/bin/lean/phaseledger.mjs +47 -5
  80. package/bin/lean/phaseledger.test.mjs +30 -1
  81. package/bin/lean/postdeploy-check.test.mjs +39 -0
  82. package/bin/lean/precheck.mjs +23 -4
  83. package/bin/lean/precheck.test.mjs +14 -1
  84. package/bin/lean/prereq.mjs +28 -0
  85. package/bin/lean/prereq.test.mjs +20 -0
  86. package/bin/lean/probe.mjs +4 -2
  87. package/bin/lean/prodparity.mjs +52 -0
  88. package/bin/lean/prodparity.test.mjs +67 -0
  89. package/bin/lean/prompts.mjs +77 -19
  90. package/bin/lean/quota.mjs +39 -0
  91. package/bin/lean/recovery.test.mjs +11 -1
  92. package/bin/lean/relaxation.mjs +73 -0
  93. package/bin/lean/relaxation.test.mjs +54 -0
  94. package/bin/lean/release-io.test.mjs +42 -0
  95. package/bin/lean/release-postmerge.mjs +125 -0
  96. package/bin/lean/release-preflight.mjs +58 -0
  97. package/bin/lean/release-preflight.test.mjs +114 -0
  98. package/bin/lean/release-rehearsal.mjs +64 -0
  99. package/bin/lean/release-rehearsal.test.mjs +93 -0
  100. package/bin/lean/release-review.e2e.test.mjs +77 -0
  101. package/bin/lean/release-review.mjs +254 -0
  102. package/bin/lean/release-review.test.mjs +307 -0
  103. package/bin/lean/release-snapshot.mjs +188 -0
  104. package/bin/lean/release-snapshot.test.mjs +190 -0
  105. package/bin/lean/release.mjs +296 -0
  106. package/bin/lean/release.test.mjs +387 -0
  107. package/bin/lean/render.mjs +1 -1
  108. package/bin/lean/replan.mjs +184 -0
  109. package/bin/lean/replan.test.mjs +110 -0
  110. package/bin/lean/resume.mjs +9 -7
  111. package/bin/lean/resume.test.mjs +16 -0
  112. package/bin/lean/rotator.mjs +150 -31
  113. package/bin/lean/rotator.test.mjs +105 -2
  114. package/bin/lean/sandbox-remote.mjs +9 -2
  115. package/bin/lean/schedd.mjs +83 -5
  116. package/bin/lean/schedd.test.mjs +108 -7
  117. package/bin/lean/selfreview.mjs +94 -0
  118. package/bin/lean/selfreview.test.mjs +58 -1
  119. package/bin/lean/selftest-gate.mjs +22 -0
  120. package/bin/lean/selftest-gate.test.mjs +18 -1
  121. package/bin/lean/selftest-journey.mjs +234 -0
  122. package/bin/lean/selftest-journey.test.mjs +130 -0
  123. package/bin/lean/selftest-live.mjs +2 -1
  124. package/bin/lean/seqlease.mjs +35 -1
  125. package/bin/lean/seqlease.test.mjs +15 -0
  126. package/bin/lean/seqreserve.e2e.test.mjs +135 -0
  127. package/bin/lean/seqreserve.mjs +73 -0
  128. package/bin/lean/seqreserve.test.mjs +134 -0
  129. package/bin/lean/sequence.mjs +35 -6
  130. package/bin/lean/seqversioned.mjs +147 -0
  131. package/bin/lean/stagestamp.mjs +28 -0
  132. package/bin/lean/stagestamp.test.mjs +32 -0
  133. package/bin/lean/surfaces.mjs +75 -0
  134. package/bin/lean/surfaces.test.mjs +59 -0
  135. package/bin/lean/toolplace.mjs +28 -0
  136. package/bin/lean/toolplace.test.mjs +24 -0
  137. package/bin/lean/toolstats.mjs +3 -1
  138. package/bin/lean/toolstats.test.mjs +11 -0
  139. package/bin/lean/validatebest.mjs +28 -0
  140. package/bin/lean/validatebest.test.mjs +27 -0
  141. package/bin/lean/verifier.mjs +3 -2
  142. package/bin/lean/verify.mjs +2 -1
  143. package/bin/lean/verify.test.mjs +6 -0
  144. package/bin/pool/agent.mjs +27 -4
  145. package/bin/pool/docker.mjs +5 -0
  146. package/bin/pool/router.mjs +74 -28
  147. package/bin/prereqs.mjs +111 -0
  148. package/bin/replay-timelapse.mjs +149 -0
  149. package/bin/review-staging.mjs +123 -16
  150. package/bin/review-staging.test.mjs +18 -0
  151. package/bin/runner.mjs +43 -6
  152. package/bin/splash-install.mjs +157 -0
  153. package/bin/stats/aggregate.mjs +8 -1
  154. package/bin/stats/conformance-outcomes.mjs +289 -0
  155. package/bin/stats/conformance-outcomes.test.mjs +274 -0
  156. package/bin/stats/depth.mjs +275 -0
  157. package/bin/stats/depth.test.mjs +158 -0
  158. package/bin/stats/efficiency.mjs +26 -5
  159. package/bin/stats/efficiency.test.mjs +45 -1
  160. package/bin/stats/experiment.mjs +7 -5
  161. package/bin/stats/first-review.mjs +77 -0
  162. package/bin/stats/first-review.test.mjs +36 -0
  163. package/bin/stats/firstmerge.mjs +40 -0
  164. package/bin/stats/firstmerge.test.mjs +41 -0
  165. package/bin/stats/github-source.mjs +53 -15
  166. package/bin/stats/index.mjs +147 -9
  167. package/bin/stats/local-source.mjs +12 -0
  168. package/bin/stats/origin.mjs +80 -0
  169. package/bin/stats/origin.test.mjs +58 -0
  170. package/bin/stats/query.mjs +69 -0
  171. package/bin/stats/render.mjs +3 -1
  172. package/bin/stats/scoreboard.mjs +137 -0
  173. package/bin/stats/scoreboard.test.mjs +87 -0
  174. package/bin/stats/selffiled.mjs +52 -0
  175. package/bin/stats/selffiled.test.mjs +71 -0
  176. package/bin/stats/stats.test.mjs +80 -0
  177. package/bin/tui.mjs +3 -2
  178. package/commands/bootstrap.md +15 -14
  179. package/commands/deploy-pr.md +18 -3
  180. package/commands/forge-stats.md +1 -1
  181. package/commands/forgedock-ci-setup.md +28 -0
  182. package/commands/forgedock-init.md +4 -5
  183. package/commands/issue.md +2 -0
  184. package/commands/milestone.md +9 -1
  185. package/commands/orchestrate.md +1 -1
  186. package/commands/replay.md +2 -0
  187. package/commands/review-pr-agents/security.md +4 -0
  188. package/commands/review-pr-staging.md +6 -1
  189. package/commands/work-on/build.md +4 -6
  190. package/commands/work-on/close.md +8 -0
  191. package/docs/CONFIG.md +170 -18
  192. package/docs/ISSUE-WATCH.md +25 -0
  193. package/docs/OUTCOME-CODES.md +4 -0
  194. package/docs/REPLAY.md +9 -0
  195. package/docs/SELFTEST.md +11 -0
  196. package/docs/STATS.md +61 -0
  197. package/docs/TELEMETRY.md +1 -1
  198. package/docs/eval/README.md +6 -0
  199. package/docs/eval/adversarial-bench.md +68 -0
  200. package/docs/eval/corpus/adversarial-v1.json +285 -0
  201. package/docs/eval/feature-bench.md +42 -0
  202. package/docs/eval/feature-specs/crud-auth/journeys/notes-crud-isolated.mjs +21 -0
  203. package/docs/eval/feature-specs/crud-auth/journeys/register-login.mjs +12 -0
  204. package/docs/eval/feature-specs/crud-auth/spec.md +15 -0
  205. package/docs/site/start-a-new-project.md +2 -1
  206. package/package.json +5 -2
  207. package/plugins/forgedock-splash/.claude-plugin/plugin.json +10 -0
  208. package/plugins/forgedock-splash/README.md +27 -0
  209. package/plugins/forgedock-splash/hooks/hooks.json +1 -0
  210. package/plugins/forgedock-splash/hooks/register.tsx +74 -0
  211. package/plugins/forgedock-splash/hooks/scene.ts +222 -0
  212. package/plugins/forgedock-splash/types/index.d.ts +10 -0
  213. package/pool/README.md +1 -1
  214. package/pool/image/cs-cred +14 -1
  215. package/scripts/backfill-finding-labels.mjs +50 -0
  216. package/scripts/backfill-finding-labels.test.mjs +36 -0
  217. package/scripts/bench-adversarial.mjs +216 -0
  218. package/scripts/bench-feature.mjs +170 -0
  219. package/scripts/bench-lightlane.mjs +2 -2
  220. package/scripts/bootstrap-create.mjs +2 -2
  221. package/scripts/bootstrap-validate.mjs +35 -2
  222. package/scripts/check-spec-size.sh +4 -3
  223. package/scripts/check-spec-size.test.sh +3 -0
  224. package/scripts/doctor-pipeline-state.sh +21 -6
  225. package/scripts/file-deferred-followups.sh +59 -251
  226. package/scripts/file-deferred-followups.test.sh +85 -206
  227. package/scripts/followup-route.mjs +12 -0
  228. package/scripts/owner-route-parity.test.sh +17 -1
  229. package/scripts/plan-validate-live.mjs +40 -6
  230. package/scripts/review-pr-side-effects.test.sh +40 -0
  231. package/scripts/review-pr-staging-scope.test.sh +1 -1
  232. package/scripts/review-staging-post.sh +23 -0
  233. package/scripts/review-staging-post.test.sh +8 -0
@@ -6,6 +6,8 @@
6
6
  * metrics: usd_median,wall_p50_ms,first_pass_rate,needs_human_rate (default all)
7
7
  * targets: light.usd_median<=1.2xfull,light.first_pass_rate>=0.8 min_n: 10
8
8
  * The arm is a hash of (id, issue), so a re-run or resume keeps its arm. Pure; the stats report is bin/stats/experiment.mjs.
9
+ * forge#5206: `<arm>.<key>: <value>` overrides a lane-shaping key for that arm only (ARM_OVERRIDE_KEYS); any other dotted
10
+ * key or an invalid value makes the whole declaration invalid (null, reason warned), never a partial apply.
9
11
  */
10
12
  import { createHash } from "node:crypto";
11
13
  import { readFileSync } from "node:fs";
@@ -16,10 +18,23 @@ export const EXPERIMENT_METRICS = ["usd_median", "wall_p50_ms", "first_pass_rate
16
18
  export const BENCH_SCHEMA = "forge.bench.v1";
17
19
  const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
18
20
  const TARGET = /^([A-Za-z0-9][A-Za-z0-9._-]*)\.([a-z_0-9]+)(<=|>=)(\d+(?:\.\d+)?)(?:x([A-Za-z0-9][A-Za-z0-9._-]*))?$/;
21
+ const MODEL = /^[A-Za-z0-9._:[\]-]+$/;
22
+ const oneOf = (...vals) => (v) => vals.includes(v);
23
+ /** forge#5206: the keys an arm may override, each with its value check. `context_pack` excludes `ab` (its own arm hash). */
24
+ export const ARM_OVERRIDE_KEYS = Object.freeze({
25
+ "lean.explore": oneOf("on", "off"),
26
+ "lean.explore_model": (v) => MODEL.test(v),
27
+ "lean.light_mode": oneOf("off", "shadow", "on"),
28
+ "context_pack": oneOf("shadow", "on", "off"),
29
+ "review.verifier": oneOf("off", "shadow", "enforce"),
30
+ });
19
31
  const list = (v) => String(v ?? "").split(",").map((s) => s.trim()).filter(Boolean);
20
32
 
21
- /** Parsed declaration {id, arms, ratio, metrics, targets, minN}, or null when absent or invalid. */
22
- export function parseExperiment(sec, { defaultMinN = 10 } = {}) {
33
+ /**
34
+ * Parsed declaration {id, arms, ratio, metrics, targets, minN, overrides: {arm: {key: value}}}, or null when absent or
35
+ * invalid. An invalid arm override calls `warn(reason)`.
36
+ */
37
+ export function parseExperiment(sec, { defaultMinN = 10, warn = () => {} } = {}) {
23
38
  if (!sec || typeof sec !== "object") return null;
24
39
  const id = String(sec.id ?? "").trim(), arms = list(sec.arms);
25
40
  if (!NAME.test(id) || arms.length < 2 || new Set(arms).size !== arms.length || !arms.every((a) => NAME.test(a))) return null;
@@ -35,12 +50,49 @@ export function parseExperiment(sec, { defaultMinN = 10 } = {}) {
35
50
  }
36
51
  const mn = String(sec.min_n ?? "").trim();
37
52
  if (mn && !/^\d+$/.test(mn)) return null;
38
- return { id, arms, ratio, metrics, targets, minN: mn ? Number(mn) : defaultMinN };
53
+ const overrides = Object.fromEntries(arms.map((a) => [a, {}]));
54
+ for (const [k, raw] of Object.entries(sec)) {
55
+ if (!k.includes(".")) continue;
56
+ const arm = arms.filter((a) => k.startsWith(`${a}.`) && Object.hasOwn(ARM_OVERRIDE_KEYS, k.slice(a.length + 1))).sort((a, b) => b.length - a.length)[0];
57
+ if (!arm) { warn(`${k}: not <arm>.<key> with a declared arm and an allowed key (${Object.keys(ARM_OVERRIDE_KEYS).join(", ")})`); return null; }
58
+ const key = k.slice(arm.length + 1), v = String(raw ?? "").trim();
59
+ if (!ARM_OVERRIDE_KEYS[key](v)) { warn(`${k}: invalid value "${v}"`); return null; }
60
+ overrides[arm][key] = v;
61
+ }
62
+ return { id, arms, ratio, metrics, targets, minN: mn ? Number(mn) : defaultMinN, overrides };
63
+ }
64
+
65
+ /** forge#5206: the {key: value} overrides of one arm ({} for none, an unknown arm or no experiment). */
66
+ export const armOverrides = (exp, arm) => ({ ...(exp?.overrides?.[arm] ?? {}) });
67
+
68
+ /** forge#5206: the recorded form of an arm's overrides, sorted `k=v` joined by `,` ("" when none). */
69
+ export const overridesText = (ov) => Object.keys(ov ?? {}).sort().map((k) => `${k}=${ov[k]}`).join(",");
70
+
71
+ /**
72
+ * forge#5206: the lane options of `issue` with its arm's overrides applied, and the run tag {experiment, arm, arm_overrides}.
73
+ * Without `opts.experiment` the very same options object and an empty tag (no change to today's lane).
74
+ */
75
+ export function applyArmOverrides(opts, issue) {
76
+ const exp = opts?.experiment;
77
+ if (!exp) return { options: opts, tag: {} };
78
+ const arm = assignArm(exp, issue), ov = armOverrides(exp, arm), has = (k) => Object.hasOwn(ov, k);
79
+ const options = { ...opts };
80
+ if (has("lean.explore") || has("lean.explore_model")) {
81
+ options.explore = { ...(opts.explore ?? {}), ...(has("lean.explore") ? { mode: ov["lean.explore"] } : {}), ...(has("lean.explore_model") ? { model: ov["lean.explore_model"] } : {}) };
82
+ }
83
+ if (has("lean.light_mode")) options.light = { ...(opts.light ?? {}), mode: ov["lean.light_mode"] };
84
+ if (has("context_pack")) options.contextPack = { ...(opts.contextPack ?? {}), mode: ov.context_pack };
85
+ if (has("review.verifier")) options.verifier = { ...(opts.verifier ?? {}), mode: ov["review.verifier"] };
86
+ return { options, tag: { experiment: exp.id, arm, arm_overrides: overridesText(ov) } };
39
87
  }
40
88
 
41
- /** forge.yaml `experiment:` of `cwd`, or null. */
42
- export function readExperiment(cwd = process.cwd()) {
43
- try { return parseExperiment(parseForgeYaml(readFileSync(join(cwd, "forge.yaml"), "utf8"))?.experiment); } catch { return null; }
89
+ const warned = new Set();
90
+ const stderrWarn = (m) => { if (!warned.has(m)) { warned.add(m); process.stderr.write(`forge.yaml experiment: ${m}; experiment ignored\n`); } };
91
+ /** forge.yaml `experiment:` of `cwd`, or null; an invalid arm override is warned (#5206). */
92
+ export function readExperiment(cwd = process.cwd(), warn = stderrWarn) {
93
+ let raw;
94
+ try { raw = readFileSync(join(cwd, "forge.yaml"), "utf8"); } catch { return null; }
95
+ try { return parseExperiment(parseForgeYaml(raw, { dottedSections: ["experiment"] })?.experiment, { warn }); } catch { return null; }
44
96
  }
45
97
 
46
98
  /** Deterministic arm of an issue: sha1(id:issue) mod the ratio total, walked over the arms in declared order. */
@@ -0,0 +1,122 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ /**
4
+ * forgedock first-run (#5290): on the user's own repo, propose up to 3 small, verifiable issues found by
5
+ * deterministic scans (no model), file them on approval and run one to a PR. Each filed issue carries a
6
+ * FORGE:FIRST_RUN marker with the setup start time, so `forgedock stats --first-merge` can measure setup start to
7
+ * first merge from GitHub alone. Every failure ends with a plain-language next step (nextStep).
8
+ */
9
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
10
+ import { dirname, join, relative, resolve } from "node:path";
11
+
12
+ export const MAX_PROPOSALS = 3;
13
+ export const FIRST_RUN_MARKER = "FORGE:FIRST_RUN";
14
+ const MARKER_RE = /<!--\s*FORGE:FIRST_RUN\s+(\{.*?\})\s*-->/;
15
+
16
+ /** The FORGE:FIRST_RUN marker for an issue body: {started: iso} or null. */
17
+ export function parseFirstRunMarker(body) {
18
+ const m = MARKER_RE.exec(String(body ?? ""));
19
+ if (!m) return null;
20
+ try {
21
+ const j = JSON.parse(m[1]);
22
+ return Number.isFinite(Date.parse(j?.started)) ? j : null;
23
+ } catch { return null; }
24
+ }
25
+ export const markerLine = (startedMs) => `<!-- ${FIRST_RUN_MARKER} ${JSON.stringify({ started: new Date(startedMs).toISOString() })} -->`;
26
+
27
+ const readJson = (p) => { try { return JSON.parse(readFileSync(p, "utf8")); } catch { return null; } };
28
+ const mdFiles = (cwd) => {
29
+ const out = ["README.md"].filter((f) => existsSync(join(cwd, f)));
30
+ try { for (const f of readdirSync(join(cwd, "docs"))) if (f.endsWith(".md")) out.push(`docs/${f}`); } catch { /* no docs dir */ }
31
+ return out;
32
+ };
33
+
34
+ /** Relative markdown links whose target is missing: [{file, target}]. */
35
+ export function findDeadLinks(cwd) {
36
+ const dead = [];
37
+ for (const file of mdFiles(cwd)) {
38
+ const text = readFileSync(join(cwd, file), "utf8").replace(/```[\s\S]*?```/g, "");
39
+ for (const m of text.matchAll(/\[[^\]]*\]\(([^)\s]+)\)/g)) {
40
+ const target = m[1].split("#")[0];
41
+ if (!target || /^[a-z][a-z0-9+.-]*:/i.test(target) || target.startsWith("/")) continue;
42
+ const abs = resolve(cwd, dirname(file), target);
43
+ if (relative(cwd, abs).startsWith("..")) continue;
44
+ if (!existsSync(abs)) dead.push({ file, target });
45
+ }
46
+ }
47
+ return dead;
48
+ }
49
+
50
+ /** Up to 3 small, verifiable candidates: [{kind, title, body}], most useful first. */
51
+ export function proposeIssues(cwd) {
52
+ const pkg = readJson(join(cwd, "package.json"));
53
+ const out = [];
54
+ const dead = findDeadLinks(cwd);
55
+ if (dead.length) {
56
+ const list = dead.slice(0, 10).map((d) => `- \`${d.file}\` links to \`${d.target}\`, which does not exist`).join("\n");
57
+ out.push({ kind: "dead-link", title: "docs: fix broken relative links", body: `Dead relative links found:\n\n${list}\n\nVerify: every relative link in the listed files resolves to an existing file.` });
58
+ }
59
+ if (!existsSync(join(cwd, "CONTRIBUTING.md"))) {
60
+ out.push({ kind: "doc-gap", title: "docs: add CONTRIBUTING.md", body: "The repo has no CONTRIBUTING.md. Add a short one: how to set up, run the tests and open a PR.\n\nVerify: CONTRIBUTING.md exists and is linked from the README." });
61
+ }
62
+ if (pkg?.scripts?.lint) {
63
+ out.push({ kind: "lint-debt", title: "chore: make `npm run lint` pass cleanly", body: "Run `npm run lint` and fix the reported findings without changing behaviour.\n\nVerify: `npm run lint` exits 0." });
64
+ }
65
+ if (pkg && !pkg.scripts?.test) {
66
+ out.push({ kind: "failing-test", title: "test: add a `test` script and one passing test", body: "package.json has no `test` script. Add one with a single smoke test for an existing module.\n\nVerify: `npm test` exits 0." });
67
+ }
68
+ return out.slice(0, MAX_PROPOSALS);
69
+ }
70
+
71
+ /** Plain-language next step for a failure message or error. Always returns a non-empty string. */
72
+ export function nextStep(err) {
73
+ const m = String(err?.stderr || err?.message || err || "");
74
+ if (/gh auth|not logged in|authentication|GH_TOKEN|HTTP 401|bad credentials/i.test(m)) return "GitHub CLI is not signed in. Run `gh auth login`, then re-run `npx forgedock first-run`.";
75
+ if (/gh: command not found|ENOENT.*gh|spawn gh/i.test(m)) return "The GitHub CLI (gh) is not installed. Install it from https://cli.github.com, run `gh auth login`, then re-run `npx forgedock first-run`.";
76
+ if (/protected branch|GH006|required status check|branch protection/i.test(m)) return "The base branch is protected, so ForgeDock cannot merge directly. That is fine: it opens a PR for you to review and merge. Check the PR with `gh pr list`.";
77
+ if (/no ci|no workflows|no checks/i.test(m)) return "This repo has no CI workflow, so nothing verifies the PR. Add a workflow under .github/workflows (or review the PR yourself) before merging.";
78
+ if (/remote|not a git repository|no github|could not resolve/i.test(m)) return "No GitHub remote found. Run this inside a clone of a GitHub repo, or add one with `git remote add origin <url>`.";
79
+ return "Something went wrong. Re-run `npx forgedock first-run`, or run `npx forgedock doctor` to check your setup.";
80
+ }
81
+
82
+ const issueNumber = (out) => { const m = /\/issues\/(\d+)/.exec(String(out ?? "")); return m ? Number(m[1]) : null; };
83
+
84
+ /** File each proposal with the start marker; returns [{number, title}]. exec(cmd, args) -> stdout. */
85
+ export function fileIssues({ exec, repo, proposals, startedMs }) {
86
+ const filed = [];
87
+ for (const p of proposals) {
88
+ const body = `${p.body}\n\n${markerLine(startedMs)}`;
89
+ const number = issueNumber(exec("gh", ["issue", "create", "-R", repo, "--title", p.title, "--body", body]));
90
+ if (!number) throw new Error(`could not read the issue number for "${p.title}" from gh output`);
91
+ filed.push({ number, title: p.title });
92
+ }
93
+ return filed;
94
+ }
95
+
96
+ /**
97
+ * Guided first run. Never throws: returns {status: "done"|"declined"|"nothing"|"error", issues, step?}.
98
+ * deps: exec(cmd,args), confirmFn(q, default), write(text), runIssueFn(n), startedMs.
99
+ */
100
+ export async function runFirstRun({ cwd = process.cwd(), exec, confirmFn, write = (t) => process.stdout.write(t), runIssueFn, startedMs = Date.now() } = {}) {
101
+ const fail = (err, issues = []) => { const step = nextStep(err); write(`\n ${String(err?.message ?? err).split("\n")[0]}\n Next step: ${step}\n`); return { status: "error", issues, step }; };
102
+ let repo;
103
+ try {
104
+ exec("gh", ["auth", "status"]);
105
+ } catch (err) { return fail(/not found|ENOENT/i.test(String(err?.message)) ? err : `gh auth: ${err?.stderr || err?.message}`); }
106
+ try {
107
+ repo = String(exec("gh", ["repo", "view", "--json", "nameWithOwner", "-q", ".nameWithOwner"])).trim();
108
+ if (!repo) throw new Error("could not resolve the GitHub repo");
109
+ } catch (err) { return fail(err); }
110
+ if (!existsSync(join(cwd, ".github", "workflows"))) write(` Note: ${nextStep("no CI")}\n`);
111
+ const proposals = proposeIssues(cwd);
112
+ if (!proposals.length) { write(" Nothing small and obvious to propose here. File an issue yourself, then run: npx forgedock run-issue <n>\n"); return { status: "nothing", issues: [] }; }
113
+ write(`\n ForgeDock proposes ${proposals.length} small issue${proposals.length === 1 ? "" : "s"} on ${repo}:\n`);
114
+ proposals.forEach((p, i) => write(` ${i + 1}. ${p.title}\n`));
115
+ if (!(await confirmFn(`File these issue${proposals.length === 1 ? "" : "s"} on ${repo}?`, false))) { write(" Nothing filed. Re-run anytime: npx forgedock first-run\n"); return { status: "declined", issues: [] }; }
116
+ let issues;
117
+ try { issues = fileIssues({ exec, repo, proposals, startedMs }); } catch (err) { return fail(err); }
118
+ write(` Filed ${issues.map((i) => `#${i.number}`).join(", ")}. Running #${issues[0].number} now.\n`);
119
+ try { await runIssueFn(issues[0].number); } catch (err) { return fail(err, issues); }
120
+ write(` Done. Review the PR with: gh pr list -R ${repo}\n`);
121
+ return { status: "done", issues };
122
+ }
@@ -43,9 +43,11 @@
43
43
  * YAML features. Intended only for the flat key-value structure of forge.yaml.
44
44
  *
45
45
  * @param {string} raw - Raw string content of a forge.yaml file.
46
+ * @param {{dottedSections?: string[]}} [opts] - forge#5206: sections whose nested keys may also contain `.` and `-`
47
+ * after the first character (e.g. `experiment:` arm overrides `on.lean.explore: on`); other sections are unchanged.
46
48
  * @returns {Record<string, string | Record<string, string>>}
47
49
  */
48
- export function parseForgeYaml(raw) {
50
+ export function parseForgeYaml(raw, { dottedSections = [] } = {}) {
49
51
  const result = {};
50
52
  let currentSection = null;
51
53
 
@@ -78,7 +80,9 @@ export function parseForgeYaml(raw) {
78
80
  // Nested scalar under current section: ` key: value`
79
81
  if (currentSection && /^\s+/.test(line)) {
80
82
  const nestedMatch = line.match(
81
- /^\s+([a-zA-Z_][a-zA-Z0-9_]*):\s+"([^"]*)"(?:\s*#.*)?$|^\s+([a-zA-Z_][a-zA-Z0-9_]*):\s+([^#\n]+?)(?:\s*#.*)?$/,
83
+ dottedSections.includes(currentSection)
84
+ ? /^\s+([a-zA-Z_][a-zA-Z0-9_.-]*):\s+"([^"]*)"(?:\s*#.*)?$|^\s+([a-zA-Z_][a-zA-Z0-9_.-]*):\s+([^#\n]+?)(?:\s*#.*)?$/
85
+ : /^\s+([a-zA-Z_][a-zA-Z0-9_]*):\s+"([^"]*)"(?:\s*#.*)?$|^\s+([a-zA-Z_][a-zA-Z0-9_]*):\s+([^#\n]+?)(?:\s*#.*)?$/,
82
86
  );
83
87
  if (nestedMatch) {
84
88
  const key = nestedMatch[1] ?? nestedMatch[3];