karajan-code 2.7.3 → 2.8.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 (167) hide show
  1. package/README.md +4 -4
  2. package/package.json +24 -4
  3. package/scripts/diet-baseline.mjs +170 -0
  4. package/scripts/regen-arch-stats.sh +71 -0
  5. package/src/agents/availability.js +15 -9
  6. package/src/agents/claude-agent.js +143 -45
  7. package/src/agents/model-registry.js +1 -1
  8. package/src/audit/agent-readiness.js +240 -0
  9. package/src/bootstrap.js +26 -1
  10. package/src/brain/decision-tracker.js +3 -1
  11. package/src/brain/decisor.js +1 -1
  12. package/src/canvas/parse-md.js +238 -0
  13. package/src/canvas/schema.js +101 -0
  14. package/src/canvas/to-flat.js +85 -0
  15. package/src/canvas/validate.js +163 -0
  16. package/src/checks/binaries.js +1 -1
  17. package/src/checks/ports.js +97 -27
  18. package/src/checks/runner.js +26 -10
  19. package/src/checks/sonar.js +1 -1
  20. package/src/checks/system.js +1 -1
  21. package/src/checks/tokens.js +77 -24
  22. package/src/cli/_shared.js +30 -0
  23. package/src/cli/register-meta.js +204 -0
  24. package/src/cli/register-pipeline.js +212 -0
  25. package/src/cli/register-plan.js +152 -0
  26. package/src/cli/register-roles-skills.js +38 -0
  27. package/src/cli/register-sonar.js +28 -0
  28. package/src/cli.js +83 -468
  29. package/src/commands/agents.js +18 -6
  30. package/src/commands/architect.js +29 -2
  31. package/src/commands/audit.js +27 -3
  32. package/src/commands/board.js +160 -30
  33. package/src/commands/clean.js +83 -0
  34. package/src/commands/code.js +7 -2
  35. package/src/commands/discover.js +7 -2
  36. package/src/commands/init.js +2 -2
  37. package/src/commands/plan/_shared.js +40 -0
  38. package/src/commands/plan/add-hu.js +21 -0
  39. package/src/commands/plan/delete.js +9 -0
  40. package/src/commands/plan/generate.js +284 -0
  41. package/src/commands/plan/index.js +14 -0
  42. package/src/commands/plan/list.js +21 -0
  43. package/src/commands/plan/ready.js +46 -0
  44. package/src/commands/plan/remove-hu.js +17 -0
  45. package/src/commands/plan/show.js +81 -0
  46. package/src/commands/plan/validate.js +20 -0
  47. package/src/commands/plan.js +14 -291
  48. package/src/commands/researcher.js +7 -2
  49. package/src/commands/resume.js +24 -1
  50. package/src/commands/review.js +7 -2
  51. package/src/commands/run.js +52 -1
  52. package/src/commands/status.js +1 -1
  53. package/src/commands/sync.js +75 -0
  54. package/src/commands/triage.js +7 -2
  55. package/src/commands/undo.js +1 -1
  56. package/src/config/defaults.js +213 -0
  57. package/src/config/loader.js +137 -0
  58. package/src/config/overrides.js +199 -0
  59. package/src/config/role-resolver.js +159 -0
  60. package/src/config/test-harness.js +79 -0
  61. package/src/config.js +30 -609
  62. package/src/git/automation.js +2 -2
  63. package/src/guards/output-guard.js +0 -2
  64. package/src/hu/acceptance-runner.js +52 -10
  65. package/src/hu/store.js +11 -0
  66. package/src/mcp/handlers/direct-handlers.js +2 -5
  67. package/src/mcp/handlers/management-handlers.js +48 -4
  68. package/src/mcp/handlers/run-handler.js +9 -8
  69. package/src/mcp/preflight.js +32 -13
  70. package/src/mcp/server-handlers.js +4 -3
  71. package/src/mcp/suggest-handler.js +3 -2
  72. package/src/mcp/tools.js +15 -0
  73. package/src/orchestrator/agent-fallback.js +1 -1
  74. package/src/orchestrator/ci-integration.js +10 -10
  75. package/src/orchestrator/config-init.js +25 -7
  76. package/src/orchestrator/direct-actions.js +6 -2
  77. package/src/orchestrator/drivers/error-recovery.js +287 -0
  78. package/src/orchestrator/drivers/init-context.js +222 -0
  79. package/src/orchestrator/drivers/iteration-loop.js +311 -0
  80. package/src/orchestrator/drivers/iteration-phases/coder-and-refactorer.js +48 -0
  81. package/src/orchestrator/drivers/iteration-phases/guards.js +84 -0
  82. package/src/orchestrator/drivers/iteration-phases/handle-approved.js +29 -0
  83. package/src/orchestrator/drivers/iteration-phases/quality-gates.js +76 -0
  84. package/src/orchestrator/drivers/iteration-phases/reviewer-gate.js +60 -0
  85. package/src/orchestrator/drivers/post-loop.js +370 -0
  86. package/src/orchestrator/drivers/pre-loop-phases/auto-hu-batch.js +116 -0
  87. package/src/orchestrator/drivers/pre-loop-phases/config-deprecations.js +47 -0
  88. package/src/orchestrator/drivers/pre-loop-phases/ensure-addyosmani-skills.js +84 -0
  89. package/src/orchestrator/drivers/pre-loop-phases/inject-loaded-plan.js +268 -0
  90. package/src/orchestrator/drivers/pre-loop.js +434 -0
  91. package/src/orchestrator/drivers/run-hu-batch.js +367 -0
  92. package/src/orchestrator/flow-control.js +4 -3
  93. package/src/orchestrator/flow-runner.js +121 -2019
  94. package/src/orchestrator/fs-leak-detector.js +156 -0
  95. package/src/orchestrator/hu-sub-pipeline.js +197 -9
  96. package/src/orchestrator/integrations.js +88 -0
  97. package/src/orchestrator/post-loop-stages.js +35 -8
  98. package/src/orchestrator/preflight-checks.js +30 -3
  99. package/src/orchestrator/repair/repair-detector.js +117 -0
  100. package/src/orchestrator/repair/repair-runner.js +142 -0
  101. package/src/orchestrator/reviewer-fallback.js +1 -1
  102. package/src/orchestrator/solomon-escalation.js +3 -2
  103. package/src/orchestrator/solomon-rules.js +7 -3
  104. package/src/orchestrator/stages/architect-stage.js +12 -11
  105. package/src/orchestrator/stages/coder-stage.js +56 -7
  106. package/src/orchestrator/stages/hu-reviewer-phases/detect-and-apply-splits.js +127 -0
  107. package/src/orchestrator/stages/hu-reviewer-stage.js +6 -79
  108. package/src/orchestrator/stages/planner-stage.js +1 -1
  109. package/src/orchestrator/stages/research-stage.js +1 -1
  110. package/src/orchestrator/stages/reviewer-stage.js +7 -7
  111. package/src/orchestrator/stages/sonar-stage.js +94 -10
  112. package/src/orchestrator/stages/stage-classes.js +86 -0
  113. package/src/orchestrator/stages/stage-executor.js +1 -1
  114. package/src/orchestrator/stages/triage-stage.js +1 -1
  115. package/src/orchestrator/standby.js +3 -2
  116. package/src/orchestrator/verification-gate.js +20 -12
  117. package/src/plan/adr-generator.js +170 -0
  118. package/src/plan/adr-loader.js +60 -0
  119. package/src/plan/plan-executor.js +19 -1
  120. package/src/plan/plan-hu-ops.js +170 -1
  121. package/src/plan/plan-reviewer.js +199 -0
  122. package/src/plan/plan-schema.js +69 -1
  123. package/src/plan/plan-store.js +40 -3
  124. package/src/plan/spec-detector.js +61 -0
  125. package/src/plan/tests-synthesizer.js +116 -0
  126. package/src/planning-game/client.js +3 -14
  127. package/src/planning-game/decomposition.js +1 -1
  128. package/src/planning-game/pipeline-adapter.js +36 -5
  129. package/src/prompts/coder.js +172 -1
  130. package/src/prompts/hu-reviewer.js +0 -1
  131. package/src/prompts/planner.js +81 -4
  132. package/src/review/diff-generator.js +35 -22
  133. package/src/review/snapshot-diff.js +1 -1
  134. package/src/roles/coder-role.js +25 -3
  135. package/src/roles/planner-role.js +42 -1
  136. package/src/roles/repairer-role.js +181 -0
  137. package/src/roles/tester-role.js +70 -4
  138. package/src/session/mutators.js +304 -0
  139. package/src/session/runtime-overrides.js +59 -0
  140. package/src/{session-store.js → session/store.js} +8 -2
  141. package/src/skills/semantic-detector.js +10 -5
  142. package/src/skills/skill-detector.js +1 -1
  143. package/src/sonar/cloud-scanner.js +0 -1
  144. package/src/sonar/credentials.js +14 -6
  145. package/src/sonar/discovery.js +123 -0
  146. package/src/sonar/manager.js +18 -0
  147. package/src/sync/detect-drift.js +113 -0
  148. package/src/tracker-bootstrap.js +44 -0
  149. package/src/utils/agent-detect.js +15 -11
  150. package/src/utils/board-prompt-bridge.js +109 -0
  151. package/src/utils/cli-progress.js +161 -0
  152. package/src/utils/cwd-confirm.js +39 -0
  153. package/src/utils/derive-project-name-from-cwd.js +119 -0
  154. package/src/utils/garbage-collector.js +396 -0
  155. package/src/utils/git.js +16 -4
  156. package/src/utils/locale.js +1 -1
  157. package/src/utils/paths.js +21 -1
  158. package/src/utils/process.js +1 -1
  159. package/src/utils/prompt-project-name.js +35 -0
  160. package/src/utils/run-context.js +75 -0
  161. package/src/utils/run-log.js +12 -0
  162. package/src/utils/task-file.js +1 -1
  163. package/src/utils/telemetry.js +13 -1
  164. package/src/webperf/devtools-detect.js +1 -1
  165. package/templates/coder-rules.md +13 -0
  166. package/templates/roles/coder.md +34 -0
  167. package/templates/roles/repairer.md +94 -0
@@ -28,6 +28,40 @@ Before reporting done, verify that ALL parts of the task are addressed:
28
28
  - If you write tests first (TDD), the implementation MUST make those tests pass.
29
29
  - Do NOT commit code that doesn't compile or doesn't pass tests.
30
30
 
31
+ ## Test file location (MANDATORY convention)
32
+
33
+ Tests live in a top-level `tests/` directory (or `test/` if the project already
34
+ established that convention). Mirror the source tree under it: a function in
35
+ `src/services/foo.js` is tested by `tests/services/foo.test.js`, NOT by a
36
+ sibling file inside `src/`. This is the default Karajan convention; the only
37
+ exception is when a `.karajan/coder-rules.md` in the project repo explicitly
38
+ overrides it.
39
+
40
+ Why this matters:
41
+ - Reviewers and humans look in `tests/`, not next to source. Buried tests get
42
+ treated as "no tests exist" even when they do.
43
+ - Sonar's default `sonar.tests=tests` (and equivalents in other scanners) only
44
+ finds tests there. Putting tests under `src/` produces empty coverage and
45
+ scanner errors.
46
+ - Bundlers (Vite, esbuild, Astro, etc.) skip a `tests/` tree by default;
47
+ in-source tests can leak into production bundles unless every config
48
+ explicitly excludes them.
49
+
50
+ When generating a project from scratch:
51
+ - Create the `tests/` directory.
52
+ - Configure the test runner to look there (`include: ['tests/**/*.test.{js,ts}']`
53
+ in vitest, `testMatch` in jest, etc.).
54
+ - Configure the build tool to ignore it (`vite.config` excludes, etc.).
55
+ - Configure Sonar (if `sonar-project.properties` is generated) with
56
+ `sonar.sources=src`, `sonar.tests=tests`, and verify both directories exist
57
+ before writing the file. NEVER write `sonar.tests=tests` without a `tests/`
58
+ folder — Sonar will refuse to scan and the run will burn iterations.
59
+
60
+ When modifying an existing project:
61
+ - Match whatever convention is already in place; do NOT introduce a second
62
+ one. If `tests/` exists, put new tests there. If only `src/**/*.test.js`
63
+ exists, follow that.
64
+
31
65
  ## Secrets and environment variables
32
66
 
33
67
  - NEVER hardcode API keys, tokens, passwords, secrets, or credentials in source code. No exceptions, not even for public keys or test keys.
@@ -0,0 +1,94 @@
1
+ # Repairer Role
2
+
3
+ You are the **Repairer** in a multi-role AI pipeline. Your single job is
4
+ to look at a **failing acceptance test** that the coder has tried and
5
+ failed to satisfy across multiple iterations, decide whether the test
6
+ **itself** is broken (vs. the code), and — if it is — return a corrected
7
+ test that preserves the original intent.
8
+
9
+ ## When you are invoked
10
+
11
+ The Brain calls you when an HU's acceptance test has failed N
12
+ consecutive iterations with the same error signature, and the coder
13
+ cannot make it pass. The Brain has classified the failure as
14
+ *possibly infeasible* (the test may itself be the problem, not the
15
+ implementation under test).
16
+
17
+ ## Your task
18
+
19
+ You receive:
20
+
21
+ - The failing acceptance test (string or `{ type, content }`).
22
+ - The most recent error output from running it.
23
+ - The HU's title and scope so you understand intent.
24
+ - A list of all of the HU's other acceptance tests (so any rewrite
25
+ stays consistent with them).
26
+
27
+ Decide:
28
+
29
+ 1. **fixable**: the test has a syntactic / structural bug you can
30
+ correct (e.g. invalid `jq` query, wrong shell quoting, unreachable
31
+ path assumed to exist, command name typo). Return the corrected
32
+ test content.
33
+ 2. **unfixable**: the test is fundamentally impossible (asks for a
34
+ contradiction, depends on an external service that's unreachable,
35
+ the HU's intent itself is wrong). Escalate.
36
+
37
+ ## Diagnostic checklist (apply in order)
38
+
39
+ For shell tests:
40
+ - Does `bash -n -c '<cmd>'` parse? If not → syntax fix.
41
+ - Does the test invoke `jq`? Run `echo '{}' | jq <query>` to check
42
+ the jq query parses. If "Cannot index array with string", the test
43
+ likely uses `as $n | .field` after a transform — restructure with
44
+ `as $r` binding the root.
45
+ - Does the test reference a file path that the HU explicitly creates?
46
+ If the path doesn't match what the HU actually produces, fix the
47
+ path.
48
+ - Does the test depend on a tool not in the project's runtime
49
+ (`pnpm` vs `npm` vs `yarn`, `python3` vs `python`)? Match what's
50
+ actually used.
51
+
52
+ For Gherkin tests:
53
+ - Are Given/When/Then well-formed? If a step is ambiguous, narrow it.
54
+ - Does the test rely on state set up by another scenario? Inline the
55
+ setup or mark the scenario as needing the upstream HU.
56
+
57
+ ## When NOT to "fix"
58
+
59
+ - The test is correct and the code is wrong → return `unfixable` with
60
+ reason `"test is correct; coder must fix the implementation"`. The
61
+ Brain will treat this as a normal failure, not as a repair.
62
+ - The HU's intent contradicts the test (the HU asks to do A, the test
63
+ checks B) → return `unfixable` with reason `"intent mismatch"`.
64
+ This is an FDE problem, not a Repairer problem.
65
+
66
+ ## Output format
67
+
68
+ Return ONLY a single valid JSON object:
69
+
70
+ ```json
71
+ {
72
+ "verdict": "fixable" | "unfixable",
73
+ "fixed_test": { "type": "shell" | "gherkin", "content": "..." } | null,
74
+ "reason": "one-sentence explanation of what was wrong (or why unfixable)",
75
+ "diagnostics": ["any tool-output snippets you used to diagnose"]
76
+ }
77
+ ```
78
+
79
+ - When `verdict: "fixable"`, `fixed_test` is REQUIRED and `reason`
80
+ describes the bug class (e.g. `"jq query had 'as $n | .field' on
81
+ the array tail"`).
82
+ - When `verdict: "unfixable"`, `fixed_test` is `null` and `reason`
83
+ explains why (`"test depends on Sonar 9000 reachable, network
84
+ isolated"`, `"intent mismatch — HU asks X, test checks Y"`).
85
+
86
+ ## Constraints
87
+
88
+ - NEVER soften an assertion just to make it pass. If the test was
89
+ asking the right question, your job is to make it ask it correctly,
90
+ not weakly.
91
+ - NEVER rewrite a test to pass against the CURRENT code. The test
92
+ defines the contract; the code is what's measured against it.
93
+ - Keep changes minimal. One bug at a time. If the test has multiple
94
+ problems, fix the most blocking one first.