karajan-code 4.70.4 → 5.0.1
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/README.md +2 -2
- package/package.json +6 -14
- package/packages/hu-board/package.json +1 -1
- package/packages/hu-board/public/app.js +4 -18
- package/packages/hu-board/public/index.html +5 -2
- package/packages/hu-board/public/styles.css +26 -0
- package/packages/hu-board/public/utils/api.js +0 -74
- package/packages/hu-board/public/utils/board-tour.js +62 -0
- package/packages/hu-board/public/utils/board-view.js +49 -144
- package/packages/hu-board/public/utils/command-launcher.js +8 -70
- package/packages/hu-board/public/utils/formatters.js +10 -0
- package/packages/hu-board/public/utils/governance-view.js +13 -1
- package/packages/hu-board/public/utils/hu-actions.js +17 -68
- package/packages/hu-board/public/utils/init-listeners.js +7 -8
- package/packages/hu-board/public/utils/log-panel.js +3 -16
- package/packages/hu-board/public/utils/maggle-mode.js +2 -12
- package/packages/hu-board/public/utils/modals.js +7 -0
- package/packages/hu-board/public/utils/project-picker-view.js +1 -1
- package/packages/hu-board/public/utils/server-push.js +3 -22
- package/packages/hu-board/public/utils/shared-board-notice.js +33 -0
- package/packages/hu-board/public/utils/story-detail-view.js +5 -19
- package/packages/hu-board/src/cleanup-zombies.js +0 -1
- package/packages/hu-board/src/command-runner.js +36 -25
- package/packages/hu-board/src/db-connection.js +282 -0
- package/packages/hu-board/src/db-paths.js +113 -0
- package/packages/hu-board/src/db-queries.js +188 -0
- package/packages/hu-board/src/db-tombstones.js +51 -0
- package/packages/hu-board/src/db.js +28 -619
- package/packages/hu-board/src/ephemeral-cleaner.js +2 -3
- package/packages/hu-board/src/hu-zombie-reaper.js +5 -1
- package/packages/hu-board/src/plan-mutations.js +3 -153
- package/packages/hu-board/src/plans-service.js +55 -0
- package/packages/hu-board/src/routes/api/commands.js +122 -0
- package/packages/hu-board/src/routes/api/plans.js +55 -0
- package/packages/hu-board/src/routes/api/projects.js +267 -0
- package/packages/hu-board/src/routes/api/prompts.js +135 -0
- package/packages/hu-board/src/routes/api/sessions.js +95 -0
- package/packages/hu-board/src/routes/api/stories.js +183 -0
- package/packages/hu-board/src/routes/api/system.js +241 -0
- package/packages/hu-board/src/routes/api/tombstones.js +38 -0
- package/packages/hu-board/src/routes/api.js +24 -1371
- package/packages/hu-board/src/routes/governance.js +23 -1
- package/packages/hu-board/src/routes/lanes.js +40 -0
- package/packages/hu-board/src/routes/rag.js +4 -3
- package/packages/hu-board/src/server.js +20 -34
- package/packages/hu-board/src/sync-files.js +318 -0
- package/packages/hu-board/src/sync-project.js +99 -0
- package/packages/hu-board/src/sync.js +22 -566
- package/packages/hu-board/src/zombie-reaper.js +1 -1
- package/scripts/dual-publish.mjs +19 -3
- package/scripts/postinstall.js +15 -2
- package/scripts/verify-pack-mcp.mjs +11 -7
- package/scripts/verify-pack.mjs +4 -4
- package/src/audit/audit-history.js +3 -2
- package/src/audit/dead-exports.js +68 -59
- package/src/audit/deterministic-summary.js +33 -13
- package/src/audit/npm-signatures.js +41 -0
- package/src/audit/sbom.js +35 -0
- package/src/checks/agent-token.js +112 -0
- package/src/checks/dir-setup.js +34 -1
- package/src/checks/native-build.js +21 -39
- package/src/checks/runner.js +128 -142
- package/src/cli/advanced-commands.js +6 -6
- package/src/cli/register-meta.js +42 -82
- package/src/cli/register-pipeline.js +8 -143
- package/src/cli/register-plan.js +9 -100
- package/src/cli/register-roles-skills.js +1 -1
- package/src/cli/retired-commands.js +49 -0
- package/src/cli.js +18 -5
- package/src/commands/agent-run.js +40 -26
- package/src/commands/audit.js +127 -124
- package/src/commands/board.js +5 -9
- package/src/commands/check.js +29 -16
- package/src/commands/doctor.js +2 -0
- package/src/commands/env.js +176 -150
- package/src/commands/go.js +71 -53
- package/src/commands/harden.js +90 -81
- package/src/commands/hu-start.js +52 -0
- package/src/commands/hu.js +288 -221
- package/src/commands/identity.js +111 -78
- package/src/commands/init-atril.js +47 -0
- package/src/commands/init.js +11 -40
- package/src/commands/install-tools.js +70 -85
- package/src/commands/main-guard.js +78 -0
- package/src/commands/policy.js +226 -184
- package/src/commands/qmd.js +27 -21
- package/src/commands/rag.js +121 -55
- package/src/commands/review-gate.js +421 -341
- package/src/commands/skills.js +4 -1
- package/src/commands/start.js +4 -5
- package/src/commands/steward.js +96 -47
- package/src/commands/tournament.js +46 -37
- package/src/commands/worktree.js +107 -26
- package/src/config/defaults.js +1 -0
- package/src/config/loader.js +34 -17
- package/src/config/role-resolver.js +1 -0
- package/src/config/schema.js +1 -0
- package/src/config/secrets.js +36 -0
- package/src/config.js +1 -0
- package/src/environment/adr.js +16 -2
- package/src/git/karajan-label.js +20 -8
- package/src/guards/main-guard.js +54 -0
- package/src/harden/hook-templates.js +16 -1
- package/src/harden/sentinel/posttooluse.mjs +18 -6
- package/src/harden/sentinel/pretooluse-sentinel.mjs +64 -36
- package/src/harden/sentinel/sentinel-lib.mjs +129 -26
- package/src/harden/sentinel/sentinel-shell.mjs +5 -16
- package/src/harden/sentinel/sessionstart.mjs +3 -2
- package/src/harden/sentinel/stop.mjs +5 -4
- package/src/harden/workflow-templates.js +1 -1
- package/src/hu/board-lookup.js +29 -0
- package/src/hu/gh-identity.js +23 -0
- package/src/hu/github-board.js +4 -2
- package/src/hu/lane-prune.js +83 -13
- package/src/hu/lane-setup.js +65 -0
- package/src/hu/lanes.js +66 -0
- package/src/hu/team-board-mirror.js +3 -2
- package/src/infrastructure/command-runner.js +1 -1
- package/src/infrastructure/file-system-service.js +1 -1
- package/src/mcp/handlers/direct-handlers.js +2 -292
- package/src/mcp/handlers/hu-handlers.js +1 -35
- package/src/mcp/handlers/management-handlers.js +2 -42
- package/src/mcp/handlers/rag-handler.js +9 -1
- package/src/mcp/server-handlers.js +16 -22
- package/src/mcp/tools.js +1 -196
- package/src/plan/lane-plans.js +54 -0
- package/src/plan/plan-store.js +7 -4
- package/src/policy/add.js +26 -12
- package/src/policy/adr-number-check.js +31 -0
- package/src/prompts/audit.js +299 -339
- package/src/prompts/card-context.js +10 -5
- package/src/prompts/reviewer.js +5 -2
- package/src/rag/auto-update.js +71 -44
- package/src/rag/bootstrap-index.js +46 -54
- package/src/rag/indexer.js +9 -4
- package/src/rag/migrate.js +1 -1
- package/src/rag/onnx-fallback.js +2 -2
- package/src/rag/pid-lease.js +181 -0
- package/src/rag/project-store.js +2 -12
- package/src/review/card-first.js +57 -46
- package/src/review/gate-gitignore.js +23 -4
- package/src/review/gate-hook.js +12 -4
- package/src/review/one-shot-review.js +45 -35
- package/src/review/publish-pr.js +14 -2
- package/src/review/repo-docs.js +73 -0
- package/src/review/repo-stack.js +59 -0
- package/src/review/reviewer-fallback.js +19 -4
- package/src/review/seal-commit.js +29 -0
- package/src/review/sonar-pregate.js +59 -44
- package/src/review/third-party-review.js +90 -16
- package/src/review/third-party-size.js +43 -0
- package/src/review/third-party-skills.js +54 -0
- package/src/review/verify-pr.js +1 -24
- package/src/roles/audit-role.js +106 -125
- package/src/skills/atril-cli.js +19 -1
- package/src/skills/atril-skills.js +5 -4
- package/src/skills/skills-search.js +72 -0
- package/src/skills/translate.js +62 -0
- package/src/sonar/scanner.js +116 -101
- package/src/steward/invariants.js +5 -4
- package/src/steward/phantom-sweep.js +66 -0
- package/src/tournament/judge.js +60 -53
- package/src/utils/gh-account.js +37 -0
- package/src/utils/git.js +0 -13
- package/src/utils/home-migration.js +7 -1
- package/src/utils/main-checkout.js +53 -0
- package/src/utils/qmd-collection.js +3 -1
- package/src/utils/welcome.js +3 -3
- package/templates/{skills → atril/commands}/kj-architect.md +5 -0
- package/templates/{skills → atril/commands}/kj-audit.md +5 -0
- package/templates/{skills → atril/commands}/kj-board.md +5 -0
- package/templates/{skills → atril/commands}/kj-code.md +5 -0
- package/templates/{skills → atril/commands}/kj-csv-transform.md +5 -0
- package/templates/{skills → atril/commands}/kj-data-report.md +5 -0
- package/templates/{skills → atril/commands}/kj-discover.md +5 -0
- package/templates/{skills → atril/commands}/kj-rag-query.md +5 -0
- package/templates/{skills → atril/commands}/kj-review.md +5 -0
- package/templates/{skills → atril/commands}/kj-security.md +5 -0
- package/templates/{skills → atril/commands}/kj-sonar.md +5 -0
- package/templates/{skills → atril/commands}/kj-sql-analysis.md +5 -0
- package/templates/{skills → atril/commands}/kj-test.md +5 -0
- package/packages/hu-board/public/utils/run-launcher.js +0 -169
- package/packages/hu-board/src/run-tracker.js +0 -121
- package/src/activity-log.js +0 -59
- package/src/agents/host-agent.js +0 -38
- package/src/agents/model-registry.js +0 -142
- package/src/audit/plan-adherence.js +0 -224
- package/src/autonomy/arbiter-role.js +0 -71
- package/src/autonomy/arbiter.js +0 -22
- package/src/autonomy/decider.js +0 -18
- package/src/autonomy/decision-resolver.js +0 -58
- package/src/autonomy/outcome-report.js +0 -55
- package/src/autonomy/stage-ask.js +0 -30
- package/src/brain/decision-tracker.js +0 -125
- package/src/brain/decisor.js +0 -243
- package/src/brain/solomon-consult.js +0 -171
- package/src/brain/standby-scheduler.js +0 -8
- package/src/budget/comparison.js +0 -96
- package/src/canvas/parse-md.js +0 -238
- package/src/canvas/schema.js +0 -101
- package/src/canvas/to-flat.js +0 -85
- package/src/canvas/validate.js +0 -163
- package/src/ci/dispatch.js +0 -99
- package/src/ci/index.js +0 -3
- package/src/ci/pr-diff.js +0 -26
- package/src/cli/register-standby.js +0 -26
- package/src/commands/architect.js +0 -111
- package/src/commands/autorun.js +0 -49
- package/src/commands/researcher.js +0 -54
- package/src/commands/resume.js +0 -72
- package/src/commands/review.js +0 -89
- package/src/commands/run.js +0 -185
- package/src/commands/standby.js +0 -117
- package/src/commands/status.js +0 -36
- package/src/commands/triage.js +0 -78
- package/src/commands/undo.js +0 -62
- package/src/domains/domain-loader.js +0 -245
- package/src/domains/domain-registry.js +0 -140
- package/src/domains/domain-synthesizer.js +0 -129
- package/src/git/automation.js +0 -433
- package/src/git/coder-commit-guard.js +0 -40
- package/src/git/hu-automation.js +0 -243
- package/src/git/hu-snapshot.js +0 -10
- package/src/git/symlink-targets.js +0 -57
- package/src/golden/asserter.js +0 -92
- package/src/golden/loader.js +0 -52
- package/src/golden/runner.js +0 -92
- package/src/golden/schema.js +0 -41
- package/src/guards/duplicate-members.js +0 -86
- package/src/guards/intent-guard.js +0 -161
- package/src/guards/perf-guard.js +0 -126
- package/src/guards/policy-guard.js +0 -90
- package/src/guards/policy-resolver.js +0 -85
- package/src/guards/secret-redactor.js +0 -71
- package/src/hu/acceptance-runner.js +0 -138
- package/src/hu/lazy-planner.js +0 -109
- package/src/hu/parallel-executor.js +0 -94
- package/src/hu/routing-metrics.js +0 -17
- package/src/hu/split-validator.js +0 -143
- package/src/hu/splitting-detector.js +0 -158
- package/src/hu/splitting-generator.js +0 -175
- package/src/hu/store.js +0 -394
- package/src/infrastructure/mocks.js +0 -182
- package/src/mcp/handlers/run-handler.js +0 -318
- package/src/mcp/sovereignty-guard.js +0 -113
- package/src/mcp/tool-arg-normalizers.js +0 -16
- package/src/mutate/reviewer-signal.js +0 -76
- package/src/orchestrator/agent-fallback.js +0 -81
- package/src/orchestrator/brain-coordinator.js +0 -186
- package/src/orchestrator/ci-integration.js +0 -139
- package/src/orchestrator/config-init.js +0 -426
- package/src/orchestrator/direct-actions.js +0 -217
- package/src/orchestrator/drivers/error-recovery.js +0 -287
- package/src/orchestrator/drivers/init-context.js +0 -238
- package/src/orchestrator/drivers/iteration-loop.js +0 -382
- package/src/orchestrator/drivers/iteration-phases/coder-and-refactorer.js +0 -69
- package/src/orchestrator/drivers/iteration-phases/guards.js +0 -91
- package/src/orchestrator/drivers/iteration-phases/handle-approved.js +0 -29
- package/src/orchestrator/drivers/iteration-phases/quality-gates.js +0 -125
- package/src/orchestrator/drivers/iteration-phases/reviewer-gate.js +0 -62
- package/src/orchestrator/drivers/post-loop.js +0 -404
- package/src/orchestrator/drivers/pre-loop-phases/auto-hu-batch.js +0 -137
- package/src/orchestrator/drivers/pre-loop-phases/config-deprecations.js +0 -47
- package/src/orchestrator/drivers/pre-loop-phases/ensure-addyosmani-skills.js +0 -84
- package/src/orchestrator/drivers/pre-loop-phases/inject-loaded-plan.js +0 -393
- package/src/orchestrator/drivers/pre-loop.js +0 -524
- package/src/orchestrator/drivers/run-hu-batch.js +0 -468
- package/src/orchestrator/feedback-enrichment.js +0 -140
- package/src/orchestrator/feedback-queue.js +0 -151
- package/src/orchestrator/flow-control.js +0 -170
- package/src/orchestrator/flow-runner.js +0 -365
- package/src/orchestrator/fs-leak-detector.js +0 -228
- package/src/orchestrator/hu-scheduler.js +0 -114
- package/src/orchestrator/hu-sub-pipeline.js +0 -642
- package/src/orchestrator/iteration-gate.js +0 -73
- package/src/orchestrator/iteration-stages.js +0 -9
- package/src/orchestrator/parallel-limiter.js +0 -74
- package/src/orchestrator/pipeline-context.js +0 -72
- package/src/orchestrator/post-loop-stages.js +0 -468
- package/src/orchestrator/pre-loop-stages.js +0 -11
- package/src/orchestrator/preflight-checks.js +0 -487
- package/src/orchestrator/repair/repair-detector.js +0 -117
- package/src/orchestrator/repair/repair-runner.js +0 -142
- package/src/orchestrator/reviewer-fallback.js +0 -45
- package/src/orchestrator/role-output-compressor.js +0 -189
- package/src/orchestrator/session-journal.js +0 -308
- package/src/orchestrator/solomon-escalation.js +0 -331
- package/src/orchestrator/solomon-rules.js +0 -212
- package/src/orchestrator/stages/acceptance-coverage-stage.js +0 -47
- package/src/orchestrator/stages/architect-stage.js +0 -172
- package/src/orchestrator/stages/coder-stage.js +0 -506
- package/src/orchestrator/stages/domain-curator-stage.js +0 -82
- package/src/orchestrator/stages/format-stage.js +0 -61
- package/src/orchestrator/stages/hu-reviewer-phases/detect-and-apply-splits.js +0 -127
- package/src/orchestrator/stages/hu-reviewer-stage.js +0 -419
- package/src/orchestrator/stages/perf-stage.js +0 -140
- package/src/orchestrator/stages/planner-stage.js +0 -85
- package/src/orchestrator/stages/rag-context-stage.js +0 -80
- package/src/orchestrator/stages/rag-preload-decisor.js +0 -58
- package/src/orchestrator/stages/research-stage.js +0 -69
- package/src/orchestrator/stages/reviewer-stage.js +0 -431
- package/src/orchestrator/stages/sonar-stage.js +0 -439
- package/src/orchestrator/stages/stage-classes.js +0 -84
- package/src/orchestrator/stages/stage-executor.js +0 -155
- package/src/orchestrator/stages/suite-green-stage.js +0 -62
- package/src/orchestrator/stages/tdd-discipline-stage.js +0 -56
- package/src/orchestrator/stages/tool-judge-stage.js +0 -53
- package/src/orchestrator/stages/triage-stage.js +0 -172
- package/src/orchestrator/standby.js +0 -71
- package/src/orchestrator/verification-gate.js +0 -183
- package/src/orchestrator.js +0 -22
- package/src/plan/adr-generator.js +0 -170
- package/src/plan/adr-loader.js +0 -60
- package/src/plan/plan-executor.js +0 -100
- package/src/plan/plan-validation.js +0 -4
- package/src/prompts/acceptance-coverage.js +0 -32
- package/src/prompts/arbiter.js +0 -38
- package/src/prompts/architect.js +0 -103
- package/src/prompts/hu-reviewer.js +0 -244
- package/src/prompts/tool-correctness-judge.js +0 -31
- package/src/prompts/triage.js +0 -57
- package/src/rag/embedder.js +0 -2
- package/src/rag/embedders/_cloud-base.js +0 -2
- package/src/rag/embedders/cohere.js +0 -2
- package/src/rag/embedders/mistral.js +0 -2
- package/src/rag/embedders/onnx.js +0 -2
- package/src/rag/embedders/openai.js +0 -2
- package/src/rag/embedders/voyage.js +0 -2
- package/src/rag/rerank.js +0 -4
- package/src/rag/where-parser.js +0 -4
- package/src/repeat-detector.js +0 -88
- package/src/review/diff-generator.js +0 -112
- package/src/review/git-stash-helper.js +0 -104
- package/src/review/schema.js +0 -31
- package/src/review/scope-filter.js +0 -152
- package/src/review/snapshot-diff.js +0 -122
- package/src/review/tdd-discipline.js +0 -90
- package/src/review/tdd-policy.js +0 -69
- package/src/roles/acceptance-coverage-role.js +0 -78
- package/src/roles/architect-role.js +0 -77
- package/src/roles/coder-role.js +0 -113
- package/src/roles/commiter-role.js +0 -113
- package/src/roles/domain-curator-role.js +0 -134
- package/src/roles/hu-reviewer-role.js +0 -64
- package/src/roles/impeccable-role.js +0 -85
- package/src/roles/index.js +0 -18
- package/src/roles/karajan-brain-role.js +0 -134
- package/src/roles/perf-role.js +0 -122
- package/src/roles/planner-role.js +0 -151
- package/src/roles/refactorer-role.js +0 -30
- package/src/roles/repairer-role.js +0 -181
- package/src/roles/researcher-role.js +0 -70
- package/src/roles/reviewer-role.js +0 -115
- package/src/roles/security-role.js +0 -73
- package/src/roles/solomon-role.js +0 -271
- package/src/roles/sonar-role.js +0 -72
- package/src/roles/tester-role.js +0 -235
- package/src/roles/tool-correctness-judge-role.js +0 -78
- package/src/roles/triage-role.js +0 -99
- package/src/session/journal/decisions-writer.js +0 -200
- package/src/session/journal/iteration-logger.js +0 -194
- package/src/session/journal/summary-writer.js +0 -320
- package/src/session/journal/tree-writer.js +0 -164
- package/src/session/journal/write-all.js +0 -89
- package/src/session-cleanup.js +0 -116
- package/src/skills/semantic-detector.js +0 -167
- package/src/skills/skill-detector.js +0 -385
- package/src/sonar/cloud-scanner.js +0 -78
- package/src/tracker-bootstrap.js +0 -44
- package/src/types/index.js +0 -38
- package/src/types/policy.js +0 -43
- package/src/types/solomon.js +0 -87
- package/src/utils/async-lock.js +0 -31
- package/src/utils/budget.js +0 -229
- package/src/utils/cwd-confirm.js +0 -39
- package/src/utils/display/event-handlers.js +0 -403
- package/src/utils/display/formatters.js +0 -132
- package/src/utils/display/header.js +0 -47
- package/src/utils/display/session-summary.js +0 -118
- package/src/utils/display/solomon.js +0 -42
- package/src/utils/pricing.js +0 -29
- package/src/utils/quota-simulator.js +0 -56
- package/src/utils/role-assigner.js +0 -137
- package/src/utils/rtk-wrapper.js +0 -87
- package/src/utils/run-registry.js +0 -9
- package/src/utils/status-dashboard.js +0 -254
- package/src/utils/tool-call-extractor.js +0 -56
- package/src/webperf/devtools-detect.js +0 -112
- package/src/webperf/webperf-role-integration.js +0 -66
- package/templates/skills/kj-run.md +0 -73
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Architect stage logic.
|
|
3
|
-
* Extracted from pre-loop-stages.js for maintainability.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { ArchitectRole } from "../../roles/architect-role.js";
|
|
7
|
-
import { createAgent } from "../../agents/index.js";
|
|
8
|
-
import { addCheckpoint } from "../../session/store.js";
|
|
9
|
-
import { emitProgress, makeEvent, emitAgentOutput } from "../../utils/events.js";
|
|
10
|
-
import { createStallDetector } from "../../utils/stall-detector.js";
|
|
11
|
-
import { getIntegration } from "../integrations.js";
|
|
12
|
-
|
|
13
|
-
async function handleArchitectClarification({ architectOutput, askQuestion, config, logger, emitter, eventBase, session, architectOnOutput, architectProvider, coderRole, researchContext, discoverResult, triageLevel, trackBudget }) {
|
|
14
|
-
if (!architectOutput.ok
|
|
15
|
-
|| architectOutput.result?.verdict !== "needs_clarification"
|
|
16
|
-
|| !architectOutput.result?.questions?.length) {
|
|
17
|
-
return architectOutput;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const questions = architectOutput.result.questions;
|
|
21
|
-
if (!askQuestion) {
|
|
22
|
-
logger.warn("Architect returned needs_clarification but no interactive input available — continuing with best-effort decisions");
|
|
23
|
-
return architectOutput;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const formatted = "The architect needs clarification before proceeding:\n\n"
|
|
27
|
-
+ questions.map((q, i) => `${i + 1}. ${q}`).join("\n")
|
|
28
|
-
+ "\n\nPlease provide your answers:";
|
|
29
|
-
|
|
30
|
-
emitProgress(
|
|
31
|
-
emitter,
|
|
32
|
-
makeEvent("architect:clarification", { ...eventBase, stage: "architect" }, {
|
|
33
|
-
message: "Architect needs clarification — pausing for human input",
|
|
34
|
-
detail: { questions }
|
|
35
|
-
})
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const answer = await askQuestion(formatted, { iteration: 0, stage: "architect" });
|
|
39
|
-
if (!answer) return architectOutput;
|
|
40
|
-
|
|
41
|
-
const architect2 = new ArchitectRole({ config, logger, emitter, createAgentFn: createAgent });
|
|
42
|
-
await architect2.init({ task: session.task, sessionId: session.id, iteration: 0 });
|
|
43
|
-
const rerunStart = Date.now();
|
|
44
|
-
const rerunStall = createStallDetector({
|
|
45
|
-
onOutput: architectOnOutput, emitter, eventBase, stage: "architect", provider: architectProvider
|
|
46
|
-
});
|
|
47
|
-
let result;
|
|
48
|
-
try {
|
|
49
|
-
result = await architect2.execute({
|
|
50
|
-
task: session.task,
|
|
51
|
-
onOutput: rerunStall.onOutput,
|
|
52
|
-
researchContext,
|
|
53
|
-
discoverResult,
|
|
54
|
-
triageLevel,
|
|
55
|
-
humanAnswers: answer
|
|
56
|
-
});
|
|
57
|
-
} finally {
|
|
58
|
-
rerunStall.stop();
|
|
59
|
-
}
|
|
60
|
-
trackBudget({
|
|
61
|
-
role: "architect",
|
|
62
|
-
provider: architectProvider,
|
|
63
|
-
model: config?.roles?.architect?.model || coderRole.model,
|
|
64
|
-
result,
|
|
65
|
-
duration_ms: Date.now() - rerunStart
|
|
66
|
-
});
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export async function runArchitectStage({ config, logger, emitter, eventBase, session, coderRole, trackBudget, researchContext = null, discoverResult = null, triageLevel = null, askQuestion = null }) {
|
|
71
|
-
logger.setContext({ iteration: 0, stage: "architect" });
|
|
72
|
-
const architectProvider = config?.roles?.architect?.provider || coderRole.provider;
|
|
73
|
-
emitProgress(
|
|
74
|
-
emitter,
|
|
75
|
-
makeEvent("architect:start", { ...eventBase, stage: "architect" }, {
|
|
76
|
-
message: "Architect designing solution architecture",
|
|
77
|
-
detail: { architect: architectProvider, provider: architectProvider, executorType: "agent" }
|
|
78
|
-
})
|
|
79
|
-
);
|
|
80
|
-
const architectOnOutput = (payload) => emitAgentOutput(emitter, eventBase, "architect", architectProvider, payload);
|
|
81
|
-
const architectStall = createStallDetector({
|
|
82
|
-
onOutput: architectOnOutput, emitter, eventBase, stage: "architect", provider: architectProvider
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const architect = new ArchitectRole({ config, logger, emitter, createAgentFn: createAgent });
|
|
86
|
-
await architect.init({ task: session.task, sessionId: session.id, iteration: 0 });
|
|
87
|
-
const architectStart = Date.now();
|
|
88
|
-
let architectOutput;
|
|
89
|
-
try {
|
|
90
|
-
architectOutput = await architect.execute({
|
|
91
|
-
task: session.task,
|
|
92
|
-
onOutput: architectStall.onOutput,
|
|
93
|
-
researchContext,
|
|
94
|
-
discoverResult,
|
|
95
|
-
triageLevel
|
|
96
|
-
});
|
|
97
|
-
} catch (err) {
|
|
98
|
-
logger.warn(`Architect threw: ${err.message}`);
|
|
99
|
-
architectOutput = { ok: false, summary: `Architect error: ${err.message}`, result: { error: err.message } };
|
|
100
|
-
} finally {
|
|
101
|
-
architectStall.stop();
|
|
102
|
-
}
|
|
103
|
-
trackBudget({
|
|
104
|
-
role: "architect",
|
|
105
|
-
provider: architectProvider,
|
|
106
|
-
model: config?.roles?.architect?.model || coderRole.model,
|
|
107
|
-
result: architectOutput,
|
|
108
|
-
duration_ms: Date.now() - architectStart
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
await addCheckpoint(session, {
|
|
112
|
-
stage: "architect",
|
|
113
|
-
iteration: 0,
|
|
114
|
-
ok: architectOutput.ok,
|
|
115
|
-
provider: architectProvider,
|
|
116
|
-
model: config?.roles?.architect?.model || coderRole.model || null
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
// --- Interactive clarification loop ---
|
|
120
|
-
architectOutput = await handleArchitectClarification({
|
|
121
|
-
architectOutput, askQuestion, config, logger, emitter, eventBase, session,
|
|
122
|
-
architectOnOutput, architectProvider, coderRole, researchContext, discoverResult, triageLevel, trackBudget
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
const stageResult = {
|
|
126
|
-
ok: architectOutput.ok,
|
|
127
|
-
verdict: architectOutput.result?.verdict || null,
|
|
128
|
-
architecture: architectOutput.result?.architecture || null,
|
|
129
|
-
questions: architectOutput.result?.questions || []
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
emitProgress(
|
|
133
|
-
emitter,
|
|
134
|
-
makeEvent("architect:end", { ...eventBase, stage: "architect" }, {
|
|
135
|
-
status: architectOutput.ok ? "ok" : "fail",
|
|
136
|
-
message: architectOutput.ok ? "Architecture completed" : `Architecture failed: ${architectOutput.summary}`,
|
|
137
|
-
detail: { ...stageResult, provider: architectProvider, executorType: "agent" }
|
|
138
|
-
})
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
const architectContext = architectOutput.ok ? architectOutput.result : null;
|
|
142
|
-
|
|
143
|
-
// TSK-0339: ADR creation is now a tracker hook. The orchestrator ships the
|
|
144
|
-
// tradeoffs; the registered adapter decides whether/how to persist them
|
|
145
|
-
// (PG creates ADR cards, another tracker might create Jira issues, an
|
|
146
|
-
// unregistered tracker is a no-op).
|
|
147
|
-
const tradeoffs = architectOutput.result?.architecture?.tradeoffs;
|
|
148
|
-
if (architectOutput.ok
|
|
149
|
-
&& architectOutput.result?.verdict === "ready"
|
|
150
|
-
&& tradeoffs?.length > 0
|
|
151
|
-
&& session.pg_task_id
|
|
152
|
-
&& session.pg_project_id) {
|
|
153
|
-
try {
|
|
154
|
-
const adrResult = await getIntegration("tracker")?.createAdrsFromTradeoffs?.({
|
|
155
|
-
tradeoffs,
|
|
156
|
-
pgTaskId: session.pg_task_id,
|
|
157
|
-
pgProject: session.pg_project_id,
|
|
158
|
-
taskTitle: session.task,
|
|
159
|
-
});
|
|
160
|
-
if (adrResult) {
|
|
161
|
-
stageResult.adrs = adrResult;
|
|
162
|
-
if (adrResult.created > 0) {
|
|
163
|
-
logger.info(`Architect: created ${adrResult.created} ADR(s) in tracker`);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
} catch (err) {
|
|
167
|
-
logger.warn(`Architect: failed to create ADRs: ${err.message}`);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return { architectContext, stageResult };
|
|
172
|
-
}
|
|
@@ -1,506 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coder stage logic.
|
|
3
|
-
* Extracted from iteration-stages.js for maintainability.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { createAgent } from "../../agents/index.js";
|
|
7
|
-
import { CoderRole } from "../../roles/coder-role.js";
|
|
8
|
-
import { RefactorerRole } from "../../roles/refactorer-role.js";
|
|
9
|
-
import { addCheckpoint, markSessionStatus, saveSession } from "../../session/store.js";
|
|
10
|
-
import {
|
|
11
|
-
setReviewerFeedback, setCoderTranscript, incrementRetryCount, resetRetryCount,
|
|
12
|
-
} from "../../session/mutators.js";
|
|
13
|
-
import { generateDiff, getUntrackedFiles } from "../../review/diff-generator.js";
|
|
14
|
-
import { evaluateTddPolicy } from "../../review/tdd-policy.js";
|
|
15
|
-
import { buildDeferredContext } from "../../review/scope-filter.js";
|
|
16
|
-
import { emitProgress, makeEvent, emitAgentOutput } from "../../utils/events.js";
|
|
17
|
-
import { runCoderWithFallback } from "../agent-fallback.js";
|
|
18
|
-
import { invokeSolomon } from "../solomon-escalation.js";
|
|
19
|
-
import { detectRateLimit } from "../../utils/rate-limit-detector.js";
|
|
20
|
-
import { headSha, undoCommitsSince } from "../../git/coder-commit-guard.js";
|
|
21
|
-
import { createStallDetector } from "../../utils/stall-detector.js";
|
|
22
|
-
import { buildStandbyState } from "../../brain/standby-store.js";
|
|
23
|
-
import { applyQuotaSimulation } from "../../utils/quota-simulator.js";
|
|
24
|
-
import { snapshotHomeTopLevel, detectNewHomeEntries, formatLeakMessage, splitLeakEvidence, detectTranscriptCdLeaks } from "../fs-leak-detector.js";
|
|
25
|
-
|
|
26
|
-
export async function runCoderStage({ coderRoleInstance, coderRole, config, logger, emitter, eventBase, session, plannedTask, trackBudget, iteration, brainCtx, acceptanceTests = null, adrs = null, specSection = null, reviewerFindings = null, huId = null }) {
|
|
27
|
-
logger.setContext({ iteration, stage: "coder" });
|
|
28
|
-
emitProgress(
|
|
29
|
-
emitter,
|
|
30
|
-
makeEvent("coder:start", { ...eventBase, stage: "coder" }, {
|
|
31
|
-
message: `Coder (${coderRole.provider}) running`,
|
|
32
|
-
detail: { coder: coderRole.provider, provider: coderRole.provider, executorType: "agent" }
|
|
33
|
-
})
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
// Brain: if enabled and queue has entries, use enriched feedback instead of flat string
|
|
37
|
-
let reviewerFeedback = session.last_reviewer_feedback;
|
|
38
|
-
if (brainCtx?.enabled) {
|
|
39
|
-
const { buildCoderFeedbackPrompt } = await import("../brain-coordinator.js");
|
|
40
|
-
const enriched = buildCoderFeedbackPrompt(brainCtx);
|
|
41
|
-
if (enriched) {
|
|
42
|
-
reviewerFeedback = enriched;
|
|
43
|
-
logger.info(`Brain: using enriched feedback (${brainCtx.feedbackQueue.entries.length} entries)`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const coderOnOutput = (payload) => emitAgentOutput(emitter, eventBase, "coder", coderRole.provider, payload);
|
|
48
|
-
const coderStall = createStallDetector({
|
|
49
|
-
onOutput: coderOnOutput, emitter, eventBase, stage: "coder", provider: coderRole.provider
|
|
50
|
-
});
|
|
51
|
-
const coderStart = Date.now();
|
|
52
|
-
// KJC-BUG-0032 (PR-I): snapshot $HOME's top-level entries BEFORE
|
|
53
|
-
// the coder runs so we can detect leaks afterwards. The bug: a HU
|
|
54
|
-
// titled "Initialize project skeleton: create assistant/…" had
|
|
55
|
-
// Claude run `cd /home/manu/assistant && pnpm init …` and 36 MB
|
|
56
|
-
// of code landed outside projectDir, outside any git repo.
|
|
57
|
-
const homeSnapshotBeforeCoder = snapshotHomeTopLevel();
|
|
58
|
-
// KJC-BUG-0285 (#1982): where HEAD stands before the coder runs. The coder
|
|
59
|
-
// commits nothing; the pipeline does, once the review approves.
|
|
60
|
-
const stageDir = config?.projectDir || process.cwd();
|
|
61
|
-
const headBefore = headSha(stageDir);
|
|
62
|
-
let coderExecResult;
|
|
63
|
-
try {
|
|
64
|
-
coderExecResult = await coderRoleInstance.execute({
|
|
65
|
-
task: plannedTask,
|
|
66
|
-
reviewerFeedback,
|
|
67
|
-
sonarSummary: session.last_sonar_summary,
|
|
68
|
-
deferredContext: buildDeferredContext(session.deferred_issues),
|
|
69
|
-
// Tests-first contract flows through to buildCoderPrompt which
|
|
70
|
-
// renders the "Acceptance Tests — MUST pass" section.
|
|
71
|
-
acceptanceTests,
|
|
72
|
-
// PR F (v2.7.5): plan-aware context. ADRs apply to every HU on
|
|
73
|
-
// the plan, the rest are scoped to this HU. All four pass through
|
|
74
|
-
// untouched when the caller omits them (legacy single-task runs).
|
|
75
|
-
adrs, specSection, reviewerFindings, huId,
|
|
76
|
-
// KJC-TSK-1183: a long ADR reaches the coder as its index, sections on demand.
|
|
77
|
-
indexFirstBytes: config?.docs?.indexFirstBytes ?? null,
|
|
78
|
-
// PAR-E2 (KJC-TSK-0629): the stage's config wins over the role's own —
|
|
79
|
-
// worktree lanes pass a laneConfig whose projectDir is the worktree.
|
|
80
|
-
projectDir: config?.projectDir || null,
|
|
81
|
-
// PAR-H (KJC-TSK-0631): lane env (KJ_LANE_SLOT / KJ_PORT_OFFSET)
|
|
82
|
-
// reaches the coder subprocess so services it starts don't collide.
|
|
83
|
-
env: config?.lane_env || null,
|
|
84
|
-
// KJC-TSK-1070 (MR-D2): the model and effort of this HU's coder.
|
|
85
|
-
route: config?.coder_route || null,
|
|
86
|
-
onOutput: coderStall.onOutput,
|
|
87
|
-
// Lets Brain Recovery persist a standby snapshot if the coder's
|
|
88
|
-
// provider hits a quota cap mid-run (KJC hibernation wiring).
|
|
89
|
-
sessionState: buildStandbyState({ session, config, huId }),
|
|
90
|
-
});
|
|
91
|
-
} finally {
|
|
92
|
-
coderStall.stop();
|
|
93
|
-
}
|
|
94
|
-
// KJC-TSK-1071 (MR-D3): the model the HU's route ran the coder on, so kj report measures the real one.
|
|
95
|
-
trackBudget({ role: "coder", provider: coderRole.provider, model: config?.coder_route?.model ?? coderRole.model, result: coderExecResult.result, duration_ms: Date.now() - coderStart });
|
|
96
|
-
applyQuotaSimulation(coderExecResult, { iteration, agent: coderRole.provider });
|
|
97
|
-
// KJC-BUG-0285 (#1982): a commit the coder made on its own carried the error the
|
|
98
|
-
// reviewer then rejected, and stayed on the branch. Undone softly: the changes
|
|
99
|
-
// stay in the tree for the review; the pipeline commits what it approves.
|
|
100
|
-
if (headBefore) {
|
|
101
|
-
const undone = undoCommitsSince(headBefore, stageDir);
|
|
102
|
-
if (undone.undone > 0) {
|
|
103
|
-
const message = `Coder committed on its own (${undone.undone} commit(s)); undone softly, the changes stay in the tree: the pipeline commits once the review approves`;
|
|
104
|
-
logger.warn(message);
|
|
105
|
-
emitProgress(emitter, makeEvent("coder:commit-undone", { ...eventBase, stage: "coder" }, { message, detail: { commits: undone.undone, headBefore } }));
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (!coderExecResult.ok) {
|
|
110
|
-
const details = coderExecResult.result?.error || coderExecResult.summary || "unknown error";
|
|
111
|
-
// Quota cap → Brain Recovery already hibernated the run and persisted
|
|
112
|
-
// the standby snapshot. Stop the stage cleanly: no fallback, no
|
|
113
|
-
// Solomon. The caller turns this into a clean run halt; the HU is NOT
|
|
114
|
-
// marked failed — it resumes via `kj standby resume`.
|
|
115
|
-
if (coderExecResult.result?.action === "hibernate") {
|
|
116
|
-
emitProgress(emitter, makeEvent("coder:hibernate", { ...eventBase, stage: "coder" }, {
|
|
117
|
-
message: "Coder hibernated — provider quota exhausted, run can be resumed",
|
|
118
|
-
detail: { standbyFile: coderExecResult.result?.standbyFile || null }
|
|
119
|
-
}));
|
|
120
|
-
return {
|
|
121
|
-
action: "hibernate",
|
|
122
|
-
standbyFile: coderExecResult.result?.standbyFile || null,
|
|
123
|
-
recovery: coderExecResult.result?.recovery || null,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
const rateLimitCheck = detectRateLimit({
|
|
127
|
-
stderr: coderExecResult.result?.error || "",
|
|
128
|
-
stdout: coderExecResult.result?.output || ""
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
if (rateLimitCheck.isRateLimit) {
|
|
132
|
-
// Try fallback agent if configured
|
|
133
|
-
const fallbackCoder = config.coder_options?.fallback_coder;
|
|
134
|
-
if (fallbackCoder && fallbackCoder !== coderRole.provider) {
|
|
135
|
-
logger.warn(`Coder ${coderRole.provider} hit rate limit, falling back to ${fallbackCoder}`);
|
|
136
|
-
emitProgress(
|
|
137
|
-
emitter,
|
|
138
|
-
makeEvent("coder:fallback", { ...eventBase, stage: "coder" }, {
|
|
139
|
-
message: `Coder ${coderRole.provider} rate-limited, switching to ${fallbackCoder}`,
|
|
140
|
-
detail: { primary: coderRole.provider, fallback: fallbackCoder }
|
|
141
|
-
})
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
const fallbackResult = await runCoderWithFallback({
|
|
145
|
-
coderName: fallbackCoder,
|
|
146
|
-
fallbackCoder: null,
|
|
147
|
-
config,
|
|
148
|
-
logger,
|
|
149
|
-
emitter,
|
|
150
|
-
RoleClass: CoderRole,
|
|
151
|
-
roleInput: { task: plannedTask, reviewerFeedback: session.last_reviewer_feedback, sonarSummary: session.last_sonar_summary, onOutput: coderOnOutput },
|
|
152
|
-
session,
|
|
153
|
-
iteration,
|
|
154
|
-
onAttemptResult: ({ coder, result }) => {
|
|
155
|
-
trackBudget({ role: "coder", provider: coder, model: coderRole.model, result, duration_ms: Date.now() - coderStart });
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
if (fallbackResult.execResult?.ok) {
|
|
160
|
-
await addCheckpoint(session, { stage: "coder", iteration, note: `Coder completed via fallback (${fallbackCoder})`, provider: fallbackCoder, model: null });
|
|
161
|
-
emitProgress(
|
|
162
|
-
emitter,
|
|
163
|
-
makeEvent("coder:end", { ...eventBase, stage: "coder" }, {
|
|
164
|
-
message: `Coder completed (fallback: ${fallbackCoder})`,
|
|
165
|
-
detail: { provider: fallbackCoder, executorType: "agent" }
|
|
166
|
-
})
|
|
167
|
-
);
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// No fallback or fallback also failed — enter standby
|
|
173
|
-
return {
|
|
174
|
-
action: "standby",
|
|
175
|
-
standbyInfo: {
|
|
176
|
-
agent: coderRole.provider,
|
|
177
|
-
cooldownMs: rateLimitCheck.cooldownMs || (rateLimitCheck.isProviderOutage ? 30000 : null),
|
|
178
|
-
cooldownUntil: rateLimitCheck.cooldownUntil,
|
|
179
|
-
message: rateLimitCheck.message,
|
|
180
|
-
isProviderOutage: rateLimitCheck.isProviderOutage || false
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
await markSessionStatus(session, "failed");
|
|
186
|
-
emitProgress(
|
|
187
|
-
emitter,
|
|
188
|
-
makeEvent("coder:end", { ...eventBase, stage: "coder" }, {
|
|
189
|
-
status: "fail",
|
|
190
|
-
message: `Coder failed: ${details}`,
|
|
191
|
-
detail: { provider: coderRole.provider, executorType: "agent" }
|
|
192
|
-
})
|
|
193
|
-
);
|
|
194
|
-
throw new Error(`Coder failed: ${details}`);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// KJC-BUG-0032 (PR-I): scan $HOME for new top-level entries the
|
|
198
|
-
// coder created OUTSIDE projectDir. Stop the HU loudly with a
|
|
199
|
-
// plain-Spanish message instead of letting the user discover by
|
|
200
|
-
// accident hours later that 36 MB of code is in the wrong place.
|
|
201
|
-
// Runs BEFORE the success-path verification so a leaked HU doesn't
|
|
202
|
-
// get marked as "Coder applied changes".
|
|
203
|
-
const projectDirAbs = config.projectDir || process.cwd();
|
|
204
|
-
const candidateLeaks = detectNewHomeEntries(homeSnapshotBeforeCoder, projectDirAbs);
|
|
205
|
-
// Issue #546: snapshot-diff alone produces false positives when other
|
|
206
|
-
// processes write to $HOME during the iteration window. Filter the
|
|
207
|
-
// detected entries against the coder's transcript: only flag those
|
|
208
|
-
// the coder demonstrably referenced.
|
|
209
|
-
const coderTranscript = coderExecResult.result?.output || "";
|
|
210
|
-
// KJC-BUG-0180: only what the transcript ATTRIBUTES to the coder fails the
|
|
211
|
-
// run. Without a transcript there is no evidence it wrote anything, so the
|
|
212
|
-
// finding is reported and the work goes on — a concurrent host-side write
|
|
213
|
-
// under $HOME used to kill the whole flow.
|
|
214
|
-
const { attributed: layer1Leaks, unattributed } = splitLeakEvidence(candidateLeaks, coderTranscript);
|
|
215
|
-
if (candidateLeaks.length > 0 && layer1Leaks.length === 0) {
|
|
216
|
-
const why = unattributed.length > 0 ? "no coder transcript to attribute them" : "none referenced in the coder transcript";
|
|
217
|
-
logger.warn(`fs-leak-detector: ${candidateLeaks.length} new $HOME entr(y/ies) detected but ${why} — likely a concurrent host-side write, not flagging (#546).`);
|
|
218
|
-
}
|
|
219
|
-
// Layer 2 (BUG-0032): scan the transcript for `cd <abs-out-of-project> && <write-cmd>`
|
|
220
|
-
// patterns the snapshot-diff misses (e.g. when target dir pre-existed).
|
|
221
|
-
const layer2Leaks = detectTranscriptCdLeaks(coderTranscript, projectDirAbs);
|
|
222
|
-
const fsLeaks = Array.from(new Set([...layer1Leaks, ...layer2Leaks]));
|
|
223
|
-
if (fsLeaks.length > 0) {
|
|
224
|
-
const msg = formatLeakMessage(fsLeaks, projectDirAbs);
|
|
225
|
-
logger.error(msg);
|
|
226
|
-
emitProgress(
|
|
227
|
-
emitter,
|
|
228
|
-
makeEvent("coder:fs-leak", { ...eventBase, stage: "coder" }, {
|
|
229
|
-
status: "fail",
|
|
230
|
-
message: `Coder escribió fuera del projectDir: ${fsLeaks.length} ruta(s) detectada(s)`,
|
|
231
|
-
detail: { provider: coderRole.provider, leaks: fsLeaks, projectDir: projectDirAbs }
|
|
232
|
-
})
|
|
233
|
-
);
|
|
234
|
-
await markSessionStatus(session, "failed");
|
|
235
|
-
throw new Error(msg);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Measure files changed so stale detection (solomon-rules) has accurate data
|
|
239
|
-
let filesChanged = 0;
|
|
240
|
-
try {
|
|
241
|
-
const { verifyCoderOutput } = await import("../verification-gate.js");
|
|
242
|
-
const verif = verifyCoderOutput({
|
|
243
|
-
baseRef: session.session_start_sha,
|
|
244
|
-
projectDir: config.projectDir || process.cwd()
|
|
245
|
-
});
|
|
246
|
-
if (verif.gitError) {
|
|
247
|
-
// Git failed (bad baseRef, corrupt repo, git missing). Don't
|
|
248
|
-
// feed filesChanged=0 into stale detection — it would blame the
|
|
249
|
-
// coder for an infrastructure problem.
|
|
250
|
-
logger?.warn?.(`[verification-gate] Git failed, change count is unreliable: ${verif.gitError}`);
|
|
251
|
-
} else {
|
|
252
|
-
filesChanged = verif.filesChanged || 0;
|
|
253
|
-
}
|
|
254
|
-
} catch (err) {
|
|
255
|
-
logger?.warn?.(`[verification-gate] Skipped: ${err?.message || err}`);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// KJC-TSK-0375 PR3: stash the coder's raw transcript on the session so
|
|
259
|
-
// the optional tool-judge stage can extract structured tool calls later
|
|
260
|
-
// without re-invoking the coder. Cleared between iterations by the coder
|
|
261
|
-
// overwriting it; ignored when the tool-judge flag is off.
|
|
262
|
-
setCoderTranscript(session, coderTranscript);
|
|
263
|
-
|
|
264
|
-
await addCheckpoint(session, { stage: "coder", iteration, note: "Coder applied changes", provider: coderRole.provider, model: coderRole.model || null, filesChanged });
|
|
265
|
-
emitProgress(
|
|
266
|
-
emitter,
|
|
267
|
-
makeEvent("coder:end", { ...eventBase, stage: "coder" }, {
|
|
268
|
-
message: "Coder completed",
|
|
269
|
-
detail: { provider: coderRole.provider, executorType: "agent", filesChanged }
|
|
270
|
-
})
|
|
271
|
-
);
|
|
272
|
-
|
|
273
|
-
// Brain: verify coder produced real changes + clear feedback queue (now addressed)
|
|
274
|
-
if (brainCtx?.enabled) {
|
|
275
|
-
const { verifyCoderRan, clearFeedback } = await import("../brain-coordinator.js");
|
|
276
|
-
const result = verifyCoderRan(brainCtx, {
|
|
277
|
-
baseRef: session.session_start_sha,
|
|
278
|
-
projectDir: config.projectDir || process.cwd()
|
|
279
|
-
});
|
|
280
|
-
const maxFailures = config.brain?.max_consecutive_verification_failures ?? 2;
|
|
281
|
-
if (!result.passed) {
|
|
282
|
-
logger.warn(`Brain verification: coder made 0 changes (consecutive failures: ${brainCtx.verificationTracker.consecutiveFailures}/${maxFailures})`);
|
|
283
|
-
emitProgress(emitter, makeEvent("brain:verification", { ...eventBase, stage: "coder" }, {
|
|
284
|
-
message: `Brain: coder produced no changes (${brainCtx.verificationTracker.consecutiveFailures}/${maxFailures} consecutive failures)`,
|
|
285
|
-
detail: { filesChanged: result.filesChanged, consecutiveFailures: brainCtx.verificationTracker.consecutiveFailures }
|
|
286
|
-
}));
|
|
287
|
-
if (brainCtx.verificationTracker.consecutiveFailures >= maxFailures) {
|
|
288
|
-
await markSessionStatus(session, "stalled");
|
|
289
|
-
throw new Error(`Brain: ${maxFailures} consecutive coder iterations with 0 file changes — pipeline stalled`);
|
|
290
|
-
}
|
|
291
|
-
} else {
|
|
292
|
-
clearFeedback(brainCtx);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
export async function runRefactorerStage({ refactorerRole, config, logger, emitter, eventBase, session, plannedTask, trackBudget, iteration }) {
|
|
298
|
-
logger.setContext({ iteration, stage: "refactorer" });
|
|
299
|
-
emitProgress(
|
|
300
|
-
emitter,
|
|
301
|
-
makeEvent("refactorer:start", { ...eventBase, stage: "refactorer" }, {
|
|
302
|
-
message: `Refactorer (${refactorerRole.provider}) running`,
|
|
303
|
-
detail: { refactorer: refactorerRole.provider, provider: refactorerRole.provider, executorType: "agent" }
|
|
304
|
-
})
|
|
305
|
-
);
|
|
306
|
-
const refactorerOnOutput = (payload) => emitAgentOutput(emitter, eventBase, "refactorer", refactorerRole.provider, payload);
|
|
307
|
-
const refactorerStall = createStallDetector({
|
|
308
|
-
onOutput: refactorerOnOutput, emitter, eventBase, stage: "refactorer", provider: refactorerRole.provider
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
const refRole = new RefactorerRole({ config, logger, emitter, createAgentFn: createAgent });
|
|
312
|
-
await refRole.init();
|
|
313
|
-
const refactorerStart = Date.now();
|
|
314
|
-
let refResult;
|
|
315
|
-
try {
|
|
316
|
-
refResult = await refRole.execute({
|
|
317
|
-
task: plannedTask, onOutput: refactorerStall.onOutput,
|
|
318
|
-
sessionState: buildStandbyState({ session, config }),
|
|
319
|
-
});
|
|
320
|
-
} finally {
|
|
321
|
-
refactorerStall.stop();
|
|
322
|
-
}
|
|
323
|
-
trackBudget({ role: "refactorer", provider: refactorerRole.provider, model: refactorerRole.model, result: refResult.result, duration_ms: Date.now() - refactorerStart });
|
|
324
|
-
applyQuotaSimulation(refResult, { iteration, agent: refactorerRole.provider });
|
|
325
|
-
if (!refResult.ok) {
|
|
326
|
-
const details = refResult.result?.error || refResult.summary || "unknown error";
|
|
327
|
-
// Quota cap → hibernate cleanly, same as the coder stage above.
|
|
328
|
-
if (refResult.result?.action === "hibernate") {
|
|
329
|
-
emitProgress(emitter, makeEvent("refactorer:hibernate", { ...eventBase, stage: "refactorer" }, {
|
|
330
|
-
message: "Refactorer hibernated — provider quota exhausted, run can be resumed",
|
|
331
|
-
detail: { standbyFile: refResult.result?.standbyFile || null }
|
|
332
|
-
}));
|
|
333
|
-
return {
|
|
334
|
-
action: "hibernate",
|
|
335
|
-
standbyFile: refResult.result?.standbyFile || null,
|
|
336
|
-
recovery: refResult.result?.recovery || null,
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
const rateLimitCheck = detectRateLimit({
|
|
340
|
-
stderr: refResult.result?.error || "",
|
|
341
|
-
stdout: refResult.result?.output || ""
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
if (rateLimitCheck.isRateLimit) {
|
|
345
|
-
// Enter standby instead of pausing
|
|
346
|
-
return {
|
|
347
|
-
action: "standby",
|
|
348
|
-
standbyInfo: {
|
|
349
|
-
agent: refactorerRole.provider,
|
|
350
|
-
cooldownMs: rateLimitCheck.cooldownMs || (rateLimitCheck.isProviderOutage ? 30000 : null),
|
|
351
|
-
cooldownUntil: rateLimitCheck.cooldownUntil,
|
|
352
|
-
message: rateLimitCheck.message,
|
|
353
|
-
isProviderOutage: rateLimitCheck.isProviderOutage || false
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
await markSessionStatus(session, "failed");
|
|
359
|
-
emitProgress(
|
|
360
|
-
emitter,
|
|
361
|
-
makeEvent("refactorer:end", { ...eventBase, stage: "refactorer" }, {
|
|
362
|
-
status: "fail",
|
|
363
|
-
message: `Refactorer failed: ${details}`,
|
|
364
|
-
detail: { provider: refactorerRole.provider, executorType: "agent" }
|
|
365
|
-
})
|
|
366
|
-
);
|
|
367
|
-
throw new Error(`Refactorer failed: ${details}`);
|
|
368
|
-
}
|
|
369
|
-
await addCheckpoint(session, { stage: "refactorer", iteration, note: "Refactorer applied cleanups", provider: refactorerRole.provider, model: refactorerRole.model || null });
|
|
370
|
-
emitProgress(
|
|
371
|
-
emitter,
|
|
372
|
-
makeEvent("refactorer:end", { ...eventBase, stage: "refactorer" }, {
|
|
373
|
-
message: "Refactorer completed",
|
|
374
|
-
detail: { provider: refactorerRole.provider, executorType: "agent" }
|
|
375
|
-
})
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
function handleSolomonAction(solomonResult, session, contextPrefix) {
|
|
380
|
-
if (solomonResult.action === "pause") {
|
|
381
|
-
return { action: "pause", result: { paused: true, sessionId: session.id, question: solomonResult.question, context: `${contextPrefix}_fail_fast` } };
|
|
382
|
-
}
|
|
383
|
-
if (solomonResult.action === "subtask") {
|
|
384
|
-
return { action: "pause", result: { paused: true, sessionId: session.id, subtask: solomonResult.subtask, context: `${contextPrefix}_subtask` } };
|
|
385
|
-
}
|
|
386
|
-
return null;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
async function handleSolomonContinue(solomonResult, session, counterField, brainCtx) {
|
|
390
|
-
if (solomonResult.action !== "continue") return false;
|
|
391
|
-
if (solomonResult.humanGuidance) {
|
|
392
|
-
setReviewerFeedback(session, `${session.last_reviewer_feedback ?? ""}\nUser guidance: ${solomonResult.humanGuidance}`);
|
|
393
|
-
// Brain: also push user guidance into feedback queue when enabled
|
|
394
|
-
if (brainCtx?.enabled) {
|
|
395
|
-
const { processRoleOutput } = await import("../brain-coordinator.js");
|
|
396
|
-
processRoleOutput(brainCtx, { roleName: "solomon", output: { verdict: "continue", summary: solomonResult.humanGuidance }, iteration: 0 });
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
session[counterField] = 0;
|
|
400
|
-
await saveSession(session);
|
|
401
|
-
return true;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
async function handleTddFailure({ tddEval, config, logger, emitter, eventBase, session, iteration, askQuestion, task, brainCtx }) {
|
|
405
|
-
setReviewerFeedback(session, tddEval.message);
|
|
406
|
-
// Brain: push TDD failure into feedback queue when enabled
|
|
407
|
-
if (brainCtx?.enabled) {
|
|
408
|
-
const { processRoleOutput } = await import("../brain-coordinator.js");
|
|
409
|
-
processRoleOutput(brainCtx, { roleName: "tdd", output: { verdict: "fail", summary: tddEval.message }, iteration });
|
|
410
|
-
}
|
|
411
|
-
incrementRetryCount(session, "repeated_issue");
|
|
412
|
-
await saveSession(session);
|
|
413
|
-
|
|
414
|
-
if (session.repeated_issue_count < config.session.fail_fast_repeats) {
|
|
415
|
-
return { action: "continue" };
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
// Brain: at the sub-loop limit the TDD gate must stop eating iterations.
|
|
419
|
-
// KJC-BUG-0115: returning "continue" here short-circuited runSingleIteration
|
|
420
|
-
// before the reviewer gate — 5/5 iterations ended without any review. The
|
|
421
|
-
// failure is already queued as feedback; "proceed" lets the reviewer run.
|
|
422
|
-
if (brainCtx?.enabled) {
|
|
423
|
-
logger.info("Brain: TDD sub-loop limit reached — proceeding to reviewer with TDD failure as pending feedback");
|
|
424
|
-
emitProgress(emitter, makeEvent("brain:tdd-retry-limit", { ...eventBase, stage: "tdd" }, {
|
|
425
|
-
message: `TDD sub-loop limit reached (${session.repeated_issue_count}/${config.session.fail_fast_repeats}) — proceeding to reviewer`,
|
|
426
|
-
detail: { subloop: "tdd", retryCount: session.repeated_issue_count, reason: tddEval.reason }
|
|
427
|
-
}));
|
|
428
|
-
resetRetryCount(session, "repeated_issue");
|
|
429
|
-
await saveSession(session);
|
|
430
|
-
return { action: "proceed" };
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
emitProgress(
|
|
434
|
-
emitter,
|
|
435
|
-
makeEvent("solomon:escalate", { ...eventBase, stage: "tdd" }, {
|
|
436
|
-
message: `TDD sub-loop limit reached (${session.repeated_issue_count}/${config.session.fail_fast_repeats})`,
|
|
437
|
-
detail: { subloop: "tdd", retryCount: session.repeated_issue_count, reason: tddEval.reason }
|
|
438
|
-
})
|
|
439
|
-
);
|
|
440
|
-
|
|
441
|
-
const solomonResult = await invokeSolomon({
|
|
442
|
-
config, logger, emitter, eventBase, stage: "tdd", askQuestion, session, iteration,
|
|
443
|
-
conflict: {
|
|
444
|
-
stage: "tdd",
|
|
445
|
-
task: task || session.task,
|
|
446
|
-
iterationCount: session.repeated_issue_count,
|
|
447
|
-
maxIterations: config.session.fail_fast_repeats,
|
|
448
|
-
reason: tddEval.reason,
|
|
449
|
-
sourceFiles: tddEval.sourceFiles,
|
|
450
|
-
testFiles: tddEval.testFiles,
|
|
451
|
-
history: [{ agent: "tdd-policy", feedback: tddEval.message }]
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
const actionResult = handleSolomonAction(solomonResult, session, "tdd");
|
|
456
|
-
if (actionResult) return actionResult;
|
|
457
|
-
const continued = await handleSolomonContinue(solomonResult, session, "repeated_issue_count", brainCtx);
|
|
458
|
-
if (continued) return { action: "continue" };
|
|
459
|
-
|
|
460
|
-
return { action: "continue" };
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
export async function runTddCheckStage({ config, logger, emitter, eventBase, session, trackBudget: _trackBudget, iteration, askQuestion, task, brainCtx }) {
|
|
464
|
-
logger.setContext({ iteration, stage: "tdd" });
|
|
465
|
-
let tddDiff, untrackedFiles;
|
|
466
|
-
try {
|
|
467
|
-
// PAR-E2 (KJC-TSK-0629): diff where the coder actually worked — a
|
|
468
|
-
// worktree lane's changes are invisible from the main tree.
|
|
469
|
-
tddDiff = await generateDiff({ baseRef: session.session_start_sha, projectDir: config?.projectDir || null });
|
|
470
|
-
untrackedFiles = await getUntrackedFiles(config?.projectDir || null);
|
|
471
|
-
} catch (err) {
|
|
472
|
-
logger.warn(`TDD diff generation failed: ${err.message}`);
|
|
473
|
-
return { action: "continue", stageResult: { ok: false, summary: `TDD check failed: ${err.message}` } };
|
|
474
|
-
}
|
|
475
|
-
const effectiveTaskType = session.resolved_policies?.taskType || null;
|
|
476
|
-
const tddEval = evaluateTddPolicy(tddDiff, config.development, untrackedFiles, effectiveTaskType);
|
|
477
|
-
await addCheckpoint(session, {
|
|
478
|
-
stage: "tdd-policy",
|
|
479
|
-
iteration,
|
|
480
|
-
ok: tddEval.ok,
|
|
481
|
-
reason: tddEval.reason,
|
|
482
|
-
source_files: tddEval.sourceFiles?.length || 0,
|
|
483
|
-
test_files: tddEval.testFiles?.length || 0
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
emitProgress(
|
|
487
|
-
emitter,
|
|
488
|
-
makeEvent("tdd:result", { ...eventBase, stage: "tdd" }, {
|
|
489
|
-
status: tddEval.ok ? "ok" : "fail",
|
|
490
|
-
message: tddEval.ok ? "TDD policy passed" : `TDD policy failed: ${tddEval.reason}`,
|
|
491
|
-
detail: {
|
|
492
|
-
ok: tddEval.ok,
|
|
493
|
-
reason: tddEval.reason,
|
|
494
|
-
sourceFiles: tddEval.sourceFiles?.length || 0,
|
|
495
|
-
testFiles: tddEval.testFiles?.length || 0,
|
|
496
|
-
executorType: "local"
|
|
497
|
-
}
|
|
498
|
-
})
|
|
499
|
-
);
|
|
500
|
-
|
|
501
|
-
if (!tddEval.ok) {
|
|
502
|
-
return handleTddFailure({ tddEval, config, logger, emitter, eventBase, session, iteration, askQuestion, task, brainCtx });
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
return { action: "ok", sourceFiles: tddEval.sourceFiles, testFiles: tddEval.testFiles };
|
|
506
|
-
}
|