aiwcli 0.10.2 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/run.js +1 -1
- package/dist/commands/clear.d.ts +11 -6
- package/dist/commands/clear.js +229 -381
- package/dist/commands/init/index.d.ts +1 -17
- package/dist/commands/init/index.js +22 -107
- package/dist/lib/gitignore-manager.d.ts +32 -0
- package/dist/lib/gitignore-manager.js +141 -2
- package/dist/lib/template-installer.d.ts +7 -12
- package/dist/lib/template-installer.js +69 -193
- package/dist/lib/template-settings-reconstructor.d.ts +35 -0
- package/dist/lib/template-settings-reconstructor.js +130 -0
- package/dist/templates/CLAUDE.md +8 -8
- package/dist/templates/_shared/.claude/commands/handoff-resume.md +64 -0
- package/dist/templates/_shared/.claude/commands/handoff.md +16 -10
- package/dist/templates/_shared/.claude/settings.json +7 -7
- package/dist/templates/_shared/hooks-ts/_utils/git-state.ts +2 -0
- package/dist/templates/_shared/hooks-ts/archive_plan.ts +159 -0
- package/dist/templates/_shared/hooks-ts/context_monitor.ts +147 -0
- package/dist/templates/_shared/hooks-ts/file-suggestion.ts +130 -0
- package/dist/templates/_shared/hooks-ts/pre_compact.ts +49 -0
- package/dist/templates/_shared/hooks-ts/session_end.ts +104 -0
- package/dist/templates/_shared/hooks-ts/session_start.ts +144 -0
- package/dist/templates/_shared/hooks-ts/task_create_capture.ts +48 -0
- package/dist/templates/_shared/hooks-ts/task_update_capture.ts +74 -0
- package/dist/templates/_shared/hooks-ts/user_prompt_submit.ts +83 -0
- package/dist/templates/_shared/lib-ts/CLAUDE.md +318 -0
- package/dist/templates/_shared/lib-ts/base/atomic-write.ts +138 -0
- package/dist/templates/_shared/lib-ts/base/constants.ts +306 -0
- package/dist/templates/_shared/lib-ts/base/git-state.ts +58 -0
- package/dist/templates/_shared/lib-ts/base/hook-utils.ts +439 -0
- package/dist/templates/_shared/lib-ts/base/inference.ts +252 -0
- package/dist/templates/_shared/lib-ts/base/logger.ts +250 -0
- package/dist/templates/_shared/lib-ts/base/state-io.ts +116 -0
- package/dist/templates/_shared/lib-ts/base/stop-words.ts +184 -0
- package/dist/templates/_shared/lib-ts/base/subprocess-utils.ts +162 -0
- package/dist/templates/_shared/lib-ts/base/utils.ts +184 -0
- package/dist/templates/_shared/lib-ts/context/context-formatter.ts +438 -0
- package/dist/templates/_shared/lib-ts/context/context-selector.ts +515 -0
- package/dist/templates/_shared/lib-ts/context/context-store.ts +707 -0
- package/dist/templates/_shared/lib-ts/context/plan-manager.ts +316 -0
- package/dist/templates/_shared/lib-ts/context/task-tracker.ts +185 -0
- package/dist/templates/_shared/lib-ts/handoff/document-generator.ts +216 -0
- package/dist/templates/_shared/lib-ts/handoff/handoff-reader.ts +159 -0
- package/dist/templates/_shared/lib-ts/package.json +21 -0
- package/dist/templates/_shared/lib-ts/templates/formatters.ts +104 -0
- package/dist/templates/_shared/{lib/templates/plan_context.py → lib-ts/templates/plan-context.ts} +14 -22
- package/dist/templates/_shared/lib-ts/tsconfig.json +13 -0
- package/dist/templates/_shared/lib-ts/types.ts +164 -0
- package/dist/templates/_shared/scripts/resolve_context.ts +24 -0
- package/dist/templates/_shared/scripts/resume_handoff.ts +321 -0
- package/dist/templates/_shared/scripts/save_handoff.ts +359 -0
- package/dist/templates/_shared/scripts/status_line.ts +733 -0
- package/dist/templates/cc-native/.claude/settings.json +175 -185
- package/dist/templates/cc-native/TEMPLATE-SCHEMA.md +15 -17
- package/dist/templates/cc-native/_cc-native/agents/ARCH-EVOLUTION.md +63 -0
- package/dist/templates/cc-native/_cc-native/agents/ARCH-PATTERNS.md +62 -0
- package/dist/templates/cc-native/_cc-native/agents/ARCH-STRUCTURE.md +63 -0
- package/dist/templates/cc-native/_cc-native/agents/{ASSUMPTION-CHAIN-TRACER.md → ASSUMPTION-TRACER.md} +6 -10
- package/dist/templates/cc-native/_cc-native/agents/CLARITY-AUDITOR.md +6 -10
- package/dist/templates/cc-native/_cc-native/agents/CLAUDE.md +74 -3
- package/dist/templates/cc-native/_cc-native/agents/COMPLETENESS-FEASIBILITY.md +67 -0
- package/dist/templates/cc-native/_cc-native/agents/COMPLETENESS-GAPS.md +71 -0
- package/dist/templates/cc-native/_cc-native/agents/COMPLETENESS-ORDERING.md +63 -0
- package/dist/templates/cc-native/_cc-native/agents/CONSTRAINT-VALIDATOR.md +73 -0
- package/dist/templates/cc-native/_cc-native/agents/DESIGN-ADR-VALIDATOR.md +62 -0
- package/dist/templates/cc-native/_cc-native/agents/DESIGN-SCALE-MATCHER.md +65 -0
- package/dist/templates/cc-native/_cc-native/agents/DEVILS-ADVOCATE.md +6 -9
- package/dist/templates/cc-native/_cc-native/agents/DOCUMENTATION-PHILOSOPHY.md +87 -0
- package/dist/templates/cc-native/_cc-native/agents/HANDOFF-READINESS.md +5 -9
- package/dist/templates/cc-native/_cc-native/agents/{HIDDEN-COMPLEXITY-DETECTOR.md → HIDDEN-COMPLEXITY.md} +6 -10
- package/dist/templates/cc-native/_cc-native/agents/INCREMENTAL-DELIVERY.md +67 -0
- package/dist/templates/cc-native/_cc-native/agents/PLAN-ORCHESTRATOR.md +91 -18
- package/dist/templates/cc-native/_cc-native/agents/RISK-DEPENDENCY.md +63 -0
- package/dist/templates/cc-native/_cc-native/agents/RISK-FMEA.md +67 -0
- package/dist/templates/cc-native/_cc-native/agents/RISK-PREMORTEM.md +72 -0
- package/dist/templates/cc-native/_cc-native/agents/RISK-REVERSIBILITY.md +75 -0
- package/dist/templates/cc-native/_cc-native/agents/SCOPE-BOUNDARY.md +78 -0
- package/dist/templates/cc-native/_cc-native/agents/SIMPLICITY-GUARDIAN.md +5 -9
- package/dist/templates/cc-native/_cc-native/agents/SKEPTIC.md +16 -12
- package/dist/templates/cc-native/_cc-native/agents/TESTDRIVEN-BEHAVIOR-AUDITOR.md +62 -0
- package/dist/templates/cc-native/_cc-native/agents/TESTDRIVEN-CHARACTERIZATION.md +72 -0
- package/dist/templates/cc-native/_cc-native/agents/TESTDRIVEN-FIRST-VALIDATOR.md +62 -0
- package/dist/templates/cc-native/_cc-native/agents/TESTDRIVEN-PYRAMID-ANALYZER.md +62 -0
- package/dist/templates/cc-native/_cc-native/agents/TRADEOFF-COSTS.md +68 -0
- package/dist/templates/cc-native/_cc-native/agents/TRADEOFF-STAKEHOLDERS.md +66 -0
- package/dist/templates/cc-native/_cc-native/agents/VERIFY-COVERAGE.md +75 -0
- package/dist/templates/cc-native/_cc-native/agents/VERIFY-STRENGTH.md +70 -0
- package/dist/templates/cc-native/_cc-native/hooks/CLAUDE.md +109 -135
- package/dist/templates/cc-native/_cc-native/hooks/add_plan_context.ts +119 -0
- package/dist/templates/cc-native/_cc-native/hooks/cc-native-plan-review.ts +921 -0
- package/dist/templates/cc-native/_cc-native/hooks/plan_questions_early.ts +61 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/aggregate-agents.ts +157 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/artifacts.ts +709 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/cc-native-state.ts +199 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/cli-output-parser.ts +124 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/config.ts +57 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/constants.ts +83 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/debug.ts +80 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/index.ts +119 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/json-parser.ts +162 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/nul +3 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/orchestrator.ts +249 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/agent.ts +155 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/codex.ts +130 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/gemini.ts +106 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/index.ts +10 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/types.ts +23 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/state.ts +243 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/tsconfig.json +18 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/types.ts +310 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/verdict.ts +72 -0
- package/dist/templates/cc-native/_cc-native/plan-review.config.json +12 -16
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/dist/lib/template-merger.d.ts +0 -47
- package/dist/lib/template-merger.js +0 -162
- package/dist/templates/_shared/hooks/__init__.py +0 -16
- package/dist/templates/_shared/hooks/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/archive_plan.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/context_enforcer.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/context_monitor.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/file-suggestion.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/pre_compact.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/session_end.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/session_start.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/task_create_atomicity.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/task_create_capture.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/task_update_capture.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/user_prompt_submit.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/archive_plan.py +0 -169
- package/dist/templates/_shared/hooks/context_monitor.py +0 -270
- package/dist/templates/_shared/hooks/file-suggestion.py +0 -215
- package/dist/templates/_shared/hooks/pre_compact.py +0 -104
- package/dist/templates/_shared/hooks/session_end.py +0 -173
- package/dist/templates/_shared/hooks/session_start.py +0 -206
- package/dist/templates/_shared/hooks/task_create_capture.py +0 -108
- package/dist/templates/_shared/hooks/task_update_capture.py +0 -145
- package/dist/templates/_shared/hooks/user_prompt_submit.py +0 -139
- package/dist/templates/_shared/lib/__init__.py +0 -1
- package/dist/templates/_shared/lib/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/__init__.py +0 -65
- package/dist/templates/_shared/lib/base/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/__pycache__/atomic_write.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/__pycache__/constants.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/__pycache__/hook_utils.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/__pycache__/inference.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/__pycache__/logger.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/__pycache__/stop_words.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/__pycache__/subprocess_utils.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/__pycache__/utils.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/atomic_write.py +0 -180
- package/dist/templates/_shared/lib/base/constants.py +0 -358
- package/dist/templates/_shared/lib/base/hook_utils.py +0 -341
- package/dist/templates/_shared/lib/base/inference.py +0 -318
- package/dist/templates/_shared/lib/base/logger.py +0 -291
- package/dist/templates/_shared/lib/base/stop_words.py +0 -213
- package/dist/templates/_shared/lib/base/subprocess_utils.py +0 -46
- package/dist/templates/_shared/lib/base/utils.py +0 -242
- package/dist/templates/_shared/lib/context/__init__.py +0 -102
- package/dist/templates/_shared/lib/context/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/cache.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/context_extractor.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/context_formatter.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/context_manager.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/context_selector.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/context_store.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/discovery.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/event_log.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/plan_archive.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/plan_manager.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/task_sync.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/task_tracker.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/context_formatter.py +0 -317
- package/dist/templates/_shared/lib/context/context_selector.py +0 -508
- package/dist/templates/_shared/lib/context/context_store.py +0 -653
- package/dist/templates/_shared/lib/context/plan_manager.py +0 -204
- package/dist/templates/_shared/lib/context/task_tracker.py +0 -188
- package/dist/templates/_shared/lib/handoff/__init__.py +0 -22
- package/dist/templates/_shared/lib/handoff/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/handoff/__pycache__/document_generator.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/handoff/document_generator.py +0 -278
- package/dist/templates/_shared/lib/templates/README.md +0 -206
- package/dist/templates/_shared/lib/templates/__init__.py +0 -36
- package/dist/templates/_shared/lib/templates/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/templates/__pycache__/formatters.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/templates/__pycache__/persona_questions.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/templates/__pycache__/plan_context.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/templates/formatters.py +0 -146
- package/dist/templates/_shared/scripts/__pycache__/save_handoff.cpython-313.pyc +0 -0
- package/dist/templates/_shared/scripts/__pycache__/status_line.cpython-313.pyc +0 -0
- package/dist/templates/_shared/scripts/save_handoff.py +0 -357
- package/dist/templates/_shared/scripts/status_line.py +0 -701
- package/dist/templates/cc-native/.claude/commands/cc-native/fresh-perspective.md +0 -8
- package/dist/templates/cc-native/.windsurf/workflows/cc-native/fresh-perspective.md +0 -8
- package/dist/templates/cc-native/MIGRATION.md +0 -86
- package/dist/templates/cc-native/_cc-native/agents/ACCESSIBILITY-TESTER.md +0 -79
- package/dist/templates/cc-native/_cc-native/agents/ARCHITECT-REVIEWER.md +0 -48
- package/dist/templates/cc-native/_cc-native/agents/CODE-REVIEWER.md +0 -70
- package/dist/templates/cc-native/_cc-native/agents/COMPLETENESS-CHECKER.md +0 -59
- package/dist/templates/cc-native/_cc-native/agents/CONTEXT-EXTRACTOR.md +0 -92
- package/dist/templates/cc-native/_cc-native/agents/DOCUMENTATION-REVIEWER.md +0 -51
- package/dist/templates/cc-native/_cc-native/agents/FEASIBILITY-ANALYST.md +0 -57
- package/dist/templates/cc-native/_cc-native/agents/FRESH-PERSPECTIVE.md +0 -54
- package/dist/templates/cc-native/_cc-native/agents/INCENTIVE-MAPPER.md +0 -61
- package/dist/templates/cc-native/_cc-native/agents/PENETRATION-TESTER.md +0 -79
- package/dist/templates/cc-native/_cc-native/agents/PERFORMANCE-ENGINEER.md +0 -75
- package/dist/templates/cc-native/_cc-native/agents/PRECEDENT-FINDER.md +0 -70
- package/dist/templates/cc-native/_cc-native/agents/REVERSIBILITY-ANALYST.md +0 -61
- package/dist/templates/cc-native/_cc-native/agents/RISK-ASSESSOR.md +0 -58
- package/dist/templates/cc-native/_cc-native/agents/SECOND-ORDER-ANALYST.md +0 -61
- package/dist/templates/cc-native/_cc-native/agents/STAKEHOLDER-ADVOCATE.md +0 -55
- package/dist/templates/cc-native/_cc-native/agents/TRADE-OFF-ILLUMINATOR.md +0 -204
- package/dist/templates/cc-native/_cc-native/hooks/__pycache__/add_plan_context.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/hooks/__pycache__/cc-native-plan-review.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/hooks/__pycache__/mark_questions_asked.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/hooks/__pycache__/plan_accepted.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/hooks/__pycache__/plan_questions_early.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/hooks/__pycache__/suggest-fresh-perspective.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/hooks/add_plan_context.py +0 -130
- package/dist/templates/cc-native/_cc-native/hooks/cc-native-plan-review.py +0 -869
- package/dist/templates/cc-native/_cc-native/hooks/plan_questions_early.py +0 -81
- package/dist/templates/cc-native/_cc-native/hooks/suggest-fresh-perspective.py +0 -340
- package/dist/templates/cc-native/_cc-native/lib/CLAUDE.md +0 -265
- package/dist/templates/cc-native/_cc-native/lib/__init__.py +0 -53
- package/dist/templates/cc-native/_cc-native/lib/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/__pycache__/atomic_write.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/__pycache__/constants.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/__pycache__/debug.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/__pycache__/orchestrator.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/__pycache__/state.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/__pycache__/utils.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/constants.py +0 -45
- package/dist/templates/cc-native/_cc-native/lib/debug.py +0 -139
- package/dist/templates/cc-native/_cc-native/lib/orchestrator.py +0 -362
- package/dist/templates/cc-native/_cc-native/lib/reviewers/__init__.py +0 -28
- package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/agent.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/base.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/codex.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/gemini.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/reviewers/agent.py +0 -215
- package/dist/templates/cc-native/_cc-native/lib/reviewers/base.py +0 -88
- package/dist/templates/cc-native/_cc-native/lib/reviewers/codex.py +0 -124
- package/dist/templates/cc-native/_cc-native/lib/reviewers/gemini.py +0 -108
- package/dist/templates/cc-native/_cc-native/lib/state.py +0 -268
- package/dist/templates/cc-native/_cc-native/lib/utils.py +0 -1027
- package/dist/templates/cc-native/_cc-native/scripts/__pycache__/aggregate_agents.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/scripts/aggregate_agents.py +0 -168
- package/dist/templates/cc-native/_cc-native/workflows/fresh-perspective.md +0 -134
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON parsing utilities for LLM responses.
|
|
3
|
+
* See cc-native-plan-review-spec.md §4.10-4.11
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ReviewData, Verdict } from "./types.js";
|
|
7
|
+
import { logDebug, logWarn } from "../../_shared/lib-ts/base/logger.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Try strict JSON parse. If that fails, attempt to extract the first {...} block.
|
|
11
|
+
*
|
|
12
|
+
* @param text - Raw text that may contain JSON
|
|
13
|
+
* @param requireFields - Optional list of field names to check for
|
|
14
|
+
* @returns Parsed dict or null if parsing failed entirely
|
|
15
|
+
*/
|
|
16
|
+
export function parseJsonMaybe(
|
|
17
|
+
text: string,
|
|
18
|
+
requireFields?: string[],
|
|
19
|
+
): null | Record<string, unknown> {
|
|
20
|
+
const trimmed = text.trim();
|
|
21
|
+
if (!trimmed) return null;
|
|
22
|
+
|
|
23
|
+
let obj: null | Record<string, unknown> = null;
|
|
24
|
+
let parseMethod: null | string = null;
|
|
25
|
+
|
|
26
|
+
// Strict parse
|
|
27
|
+
try {
|
|
28
|
+
const parsed: unknown = JSON.parse(trimmed);
|
|
29
|
+
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
30
|
+
obj = parsed as Record<string, unknown>;
|
|
31
|
+
parseMethod = "strict";
|
|
32
|
+
}
|
|
33
|
+
} catch {
|
|
34
|
+
// Fall through to heuristic
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Heuristic: try to extract a JSON object substring
|
|
38
|
+
if (obj === null) {
|
|
39
|
+
const start = trimmed.indexOf("{");
|
|
40
|
+
const end = trimmed.lastIndexOf("}");
|
|
41
|
+
if (start !== -1 && end !== -1 && end > start) {
|
|
42
|
+
const candidate = trimmed.slice(start, end + 1);
|
|
43
|
+
try {
|
|
44
|
+
const parsed: unknown = JSON.parse(candidate);
|
|
45
|
+
if (
|
|
46
|
+
parsed !== null &&
|
|
47
|
+
typeof parsed === "object" &&
|
|
48
|
+
!Array.isArray(parsed)
|
|
49
|
+
) {
|
|
50
|
+
obj = parsed as Record<string, unknown>;
|
|
51
|
+
parseMethod = "heuristic";
|
|
52
|
+
logDebug(
|
|
53
|
+
"parse",
|
|
54
|
+
`Used heuristic extraction (chars ${start}-${end})`,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
} catch {
|
|
58
|
+
logDebug(
|
|
59
|
+
"parse",
|
|
60
|
+
`Heuristic extraction failed for candidate at chars ${start}-${end}`,
|
|
61
|
+
);
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Validate required fields if parsed
|
|
68
|
+
if (obj && requireFields) {
|
|
69
|
+
const missing = requireFields.filter((f) => !(f in obj!) || !obj![f]);
|
|
70
|
+
if (missing.length > 0) {
|
|
71
|
+
logWarn(
|
|
72
|
+
"parse",
|
|
73
|
+
`Parsed JSON (${parseMethod}) missing/empty fields: ${JSON.stringify(missing)}`,
|
|
74
|
+
);
|
|
75
|
+
logDebug("parse", `Keys present: ${JSON.stringify(Object.keys(obj))}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return obj;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Validate/normalize parsed JSON to ReviewData shape with safe defaults.
|
|
84
|
+
*
|
|
85
|
+
* @param obj - Parsed JSON object (possibly null)
|
|
86
|
+
* @param defaultFixMsg - Default suggested_fix message for error case
|
|
87
|
+
* @returns Tuple of [ok, verdict, normalizedData]
|
|
88
|
+
*/
|
|
89
|
+
export function coerceToReview(
|
|
90
|
+
obj: null | Record<string, unknown>,
|
|
91
|
+
defaultFixMsg = "Retry or check configuration.",
|
|
92
|
+
): [boolean, Verdict, ReviewData] {
|
|
93
|
+
if (!obj) {
|
|
94
|
+
logWarn("coerce", "No object provided to coerceToReview");
|
|
95
|
+
return [
|
|
96
|
+
false,
|
|
97
|
+
"error",
|
|
98
|
+
{
|
|
99
|
+
verdict: "fail",
|
|
100
|
+
summary: "No structured output returned.",
|
|
101
|
+
summary_source: "default",
|
|
102
|
+
issues: [
|
|
103
|
+
{
|
|
104
|
+
severity: "high",
|
|
105
|
+
category: "tooling",
|
|
106
|
+
issue: "Reviewer returned no JSON.",
|
|
107
|
+
suggested_fix: defaultFixMsg,
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
missing_sections: [],
|
|
111
|
+
questions: [],
|
|
112
|
+
},
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const rawVerdict = obj.verdict;
|
|
117
|
+
let verdict: Verdict;
|
|
118
|
+
if (rawVerdict === "pass" || rawVerdict === "warn" || rawVerdict === "fail") {
|
|
119
|
+
verdict = rawVerdict;
|
|
120
|
+
} else {
|
|
121
|
+
logWarn(
|
|
122
|
+
"coerce",
|
|
123
|
+
`Invalid or missing verdict '${String(rawVerdict)}', defaulting to 'warn'`,
|
|
124
|
+
);
|
|
125
|
+
verdict = "warn";
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Log when fields are being defaulted
|
|
129
|
+
const summaryRaw = String(obj.summary ?? "").trim();
|
|
130
|
+
if (!summaryRaw) {
|
|
131
|
+
logWarn(
|
|
132
|
+
"coerce",
|
|
133
|
+
"summary missing or empty from parsed output, using default",
|
|
134
|
+
);
|
|
135
|
+
logDebug("coerce", `Raw object keys: ${JSON.stringify(Object.keys(obj))}`);
|
|
136
|
+
logDebug(
|
|
137
|
+
"coerce",
|
|
138
|
+
`verdict=${obj.verdict}, issues_count=${Array.isArray(obj.issues) ? (obj.issues as unknown[]).length : 0}`,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (!obj.issues) {
|
|
143
|
+
logDebug("coerce", "issues array empty or missing");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const norm: ReviewData = {
|
|
147
|
+
verdict,
|
|
148
|
+
summary: summaryRaw || "No summary provided.",
|
|
149
|
+
summary_source: summaryRaw ? "reviewer" : "default",
|
|
150
|
+
issues: Array.isArray(obj.issues)
|
|
151
|
+
? (obj.issues as ReviewData["issues"])
|
|
152
|
+
: [],
|
|
153
|
+
missing_sections: Array.isArray(obj.missing_sections)
|
|
154
|
+
? (obj.missing_sections as string[])
|
|
155
|
+
: [],
|
|
156
|
+
questions: Array.isArray(obj.questions)
|
|
157
|
+
? (obj.questions as string[])
|
|
158
|
+
: [],
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
return [true, verdict, norm];
|
|
162
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plan orchestrator — analyzes complexity and selects reviewer agents.
|
|
3
|
+
* See cc-native-plan-review-spec.md §4.8
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { parseCliOutput } from "./cli-output-parser.js";
|
|
7
|
+
import type { AgentConfig, ComplexityCategory, OrchestratorConfig, OrchestratorResult } from "./types.js";
|
|
8
|
+
import { ORCHESTRATOR_SCHEMA } from "./types.js";
|
|
9
|
+
import { logDebug, logError, logInfo, logWarn } from "../../_shared/lib-ts/base/logger.js";
|
|
10
|
+
import { execFileAsync, findExecutable, getInternalSubprocessEnv } from "../../_shared/lib-ts/base/subprocess-utils.js";
|
|
11
|
+
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Constants
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
const DEFAULT_AGENT_SELECTION: Record<string, unknown> = {
|
|
17
|
+
simple: { min: 3, max: 3 },
|
|
18
|
+
medium: { min: 8, max: 8 },
|
|
19
|
+
high: { min: 12, max: 12 },
|
|
20
|
+
fallbackCount: 3,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const DEFAULT_COMPLEXITY_CATEGORIES = [
|
|
24
|
+
"code",
|
|
25
|
+
"infrastructure",
|
|
26
|
+
"documentation",
|
|
27
|
+
"life",
|
|
28
|
+
"business",
|
|
29
|
+
"design",
|
|
30
|
+
"research",
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// Schema Builder
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Build orchestrator JSON schema with enum-constrained agent names.
|
|
39
|
+
*/
|
|
40
|
+
export function buildOrchestratorSchema(
|
|
41
|
+
validAgentNames: string[],
|
|
42
|
+
categories: string[],
|
|
43
|
+
): Record<string, unknown> {
|
|
44
|
+
const itemsSchema: Record<string, unknown> = { type: "string" };
|
|
45
|
+
if (validAgentNames.length > 0) {
|
|
46
|
+
itemsSchema.enum = validAgentNames;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
type: "object",
|
|
51
|
+
properties: {
|
|
52
|
+
complexity: { type: "string", enum: ["simple", "medium", "high"] },
|
|
53
|
+
category: { type: "string", enum: categories },
|
|
54
|
+
selectedAgents: {
|
|
55
|
+
type: "array",
|
|
56
|
+
items: itemsSchema,
|
|
57
|
+
},
|
|
58
|
+
reasoning: { type: "string" },
|
|
59
|
+
skipReason: { type: "string" },
|
|
60
|
+
},
|
|
61
|
+
required: ["complexity", "category", "selectedAgents", "reasoning"],
|
|
62
|
+
additionalProperties: false,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
// Orchestrator
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Run the orchestrator agent to analyze plan complexity and select reviewers.
|
|
72
|
+
* Never throws — returns fallback OrchestratorResult on failure.
|
|
73
|
+
*/
|
|
74
|
+
export async function runOrchestrator(
|
|
75
|
+
plan: string,
|
|
76
|
+
agentLibrary: AgentConfig[],
|
|
77
|
+
config: OrchestratorConfig,
|
|
78
|
+
settings: Record<string, unknown>,
|
|
79
|
+
mandatoryNames?: Set<string>,
|
|
80
|
+
): Promise<OrchestratorResult> {
|
|
81
|
+
logInfo("orchestrator", "Starting plan analysis...");
|
|
82
|
+
|
|
83
|
+
const mandatory = mandatoryNames ?? new Set<string>();
|
|
84
|
+
const selection = (settings.agentSelection as Record<string, unknown>) ?? DEFAULT_AGENT_SELECTION;
|
|
85
|
+
const categories = (settings.complexityCategories as string[]) ?? DEFAULT_COMPLEXITY_CATEGORIES;
|
|
86
|
+
const fallbackCount = (selection.fallbackCount as number) ?? 2;
|
|
87
|
+
|
|
88
|
+
// Filter out mandatory agents — they always run
|
|
89
|
+
const nonMandatory = agentLibrary.filter(
|
|
90
|
+
(a) => a.enabled && !mandatory.has(a.name),
|
|
91
|
+
);
|
|
92
|
+
const validNames = nonMandatory.map((a) => a.name);
|
|
93
|
+
|
|
94
|
+
logDebug("orchestrator", `Mandatory agents (always run): ${[...mandatory].sort().join(", ")}`);
|
|
95
|
+
logDebug("orchestrator", `Non-mandatory agents for selection: ${validNames.join(", ")}`);
|
|
96
|
+
|
|
97
|
+
const claudePath = findExecutable("claude");
|
|
98
|
+
if (!claudePath) {
|
|
99
|
+
logWarn(
|
|
100
|
+
"orchestrator",
|
|
101
|
+
"Claude CLI not found on PATH, falling back to medium complexity",
|
|
102
|
+
);
|
|
103
|
+
return makeFallback(nonMandatory, fallbackCount, "Orchestrator skipped - Claude CLI not found", "claude CLI not found on PATH");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
logDebug("orchestrator", `Found Claude CLI at: ${claudePath}`);
|
|
107
|
+
|
|
108
|
+
// Build agent list from non-mandatory agents
|
|
109
|
+
const agentList = nonMandatory
|
|
110
|
+
.map(
|
|
111
|
+
(a) =>
|
|
112
|
+
`- ${a.name} [${a.categories.join(", ")}]\n Focus: ${a.focus}\n Expertise: ${a.description}`,
|
|
113
|
+
)
|
|
114
|
+
.join("\n");
|
|
115
|
+
const categoryList = categories.join("/");
|
|
116
|
+
|
|
117
|
+
// Compute additional agent counts
|
|
118
|
+
const mandatoryCount = agentLibrary.filter((a) => mandatory.has(a.name)).length;
|
|
119
|
+
const simpleAdditional = Math.max(0, ((selection.simple as Record<string, number> | undefined)?.max ?? 3) - mandatoryCount);
|
|
120
|
+
const mediumAdditional = Math.max(0, ((selection.medium as Record<string, number> | undefined)?.max ?? 8) - mandatoryCount);
|
|
121
|
+
const highAdditional = Math.max(0, ((selection.high as Record<string, number> | undefined)?.max ?? 12) - mandatoryCount);
|
|
122
|
+
|
|
123
|
+
const systemPrompt = `You are a plan orchestrator for code review. Your job is to analyze plans and select appropriate reviewer agents.
|
|
124
|
+
|
|
125
|
+
You MUST call StructuredOutput immediately with your analysis. Do NOT ask questions or use any other tools.
|
|
126
|
+
|
|
127
|
+
When selecting agents:
|
|
128
|
+
- Match agent expertise to plan requirements
|
|
129
|
+
- Consider what each agent specializes in
|
|
130
|
+
- Only select agents whose categories match the plan category
|
|
131
|
+
- Fewer agents for simple plans, more for complex plans`;
|
|
132
|
+
|
|
133
|
+
const prompt = `Analyze this plan and select appropriate reviewer agents.
|
|
134
|
+
|
|
135
|
+
Available agents (select ONLY from this list):
|
|
136
|
+
${agentList}
|
|
137
|
+
|
|
138
|
+
Selection rules (number of ADDITIONAL agents to select from the list above):
|
|
139
|
+
- simple complexity = ${simpleAdditional} agents
|
|
140
|
+
- medium complexity = ${mediumAdditional} agents
|
|
141
|
+
- high complexity = ${highAdditional} agents
|
|
142
|
+
- Only select agents whose categories match the plan category (${categoryList})
|
|
143
|
+
- Non-technical plans (life, business) typically need 0 code-focused agents
|
|
144
|
+
- Note: mandatory agents run separately and are NOT listed above
|
|
145
|
+
|
|
146
|
+
PLAN:
|
|
147
|
+
<<<
|
|
148
|
+
${plan}
|
|
149
|
+
>>>
|
|
150
|
+
|
|
151
|
+
Call StructuredOutput now with: complexity, category, selectedAgents, reasoning`;
|
|
152
|
+
|
|
153
|
+
const schema =
|
|
154
|
+
validNames.length > 0
|
|
155
|
+
? buildOrchestratorSchema(validNames, categories)
|
|
156
|
+
: ORCHESTRATOR_SCHEMA;
|
|
157
|
+
const schemaJson = JSON.stringify(schema);
|
|
158
|
+
|
|
159
|
+
const cmdArgs = [
|
|
160
|
+
"--model", config.model,
|
|
161
|
+
"--output-format", "json",
|
|
162
|
+
"--json-schema", schemaJson,
|
|
163
|
+
"--max-turns", "3",
|
|
164
|
+
"--setting-sources", "",
|
|
165
|
+
"--system-prompt", systemPrompt,
|
|
166
|
+
"-p",
|
|
167
|
+
];
|
|
168
|
+
|
|
169
|
+
logInfo("orchestrator", `Running with model: ${config.model}, timeout: ${config.timeout}s`);
|
|
170
|
+
|
|
171
|
+
const env = getInternalSubprocessEnv();
|
|
172
|
+
|
|
173
|
+
const result = await execFileAsync(claudePath, cmdArgs, {
|
|
174
|
+
input: prompt,
|
|
175
|
+
timeout: config.timeout * 1000,
|
|
176
|
+
env: env as Record<string, string>,
|
|
177
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
if (result.killed || result.signal === "SIGTERM") {
|
|
181
|
+
logWarn("orchestrator", `TIMEOUT after ${config.timeout}s, falling back to medium complexity`);
|
|
182
|
+
return makeFallback(nonMandatory, fallbackCount, "Orchestrator timed out - defaulting to medium complexity", `Orchestrator timed out after ${config.timeout}s`);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const raw = result.stdout.trim();
|
|
186
|
+
if (result.stderr) logDebug("orchestrator", `stderr: ${result.stderr.slice(0, 300)}`);
|
|
187
|
+
|
|
188
|
+
if (!raw && !result.stderr && result.exitCode !== 0) {
|
|
189
|
+
logError("orchestrator", `Process exited with code ${result.exitCode}, falling back to medium complexity`);
|
|
190
|
+
return makeFallback(nonMandatory, fallbackCount, `Orchestrator failed (exit ${result.exitCode})`, `Exit code ${result.exitCode}`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const obj = parseCliOutput(raw);
|
|
194
|
+
|
|
195
|
+
logDebug("orchestrator", `Raw output length: ${raw.length} chars`);
|
|
196
|
+
if (raw) logDebug("orchestrator", `Raw output (first 500 chars): ${raw.slice(0, 500)}`);
|
|
197
|
+
logDebug("orchestrator", `Parsed obj: ${JSON.stringify(obj)}`);
|
|
198
|
+
|
|
199
|
+
if (!obj) {
|
|
200
|
+
logWarn("orchestrator", "Failed to parse output, falling back to medium complexity");
|
|
201
|
+
return makeFallback(nonMandatory, fallbackCount, "Orchestrator output could not be parsed", "Failed to parse orchestrator output");
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Extract and validate fields
|
|
205
|
+
const rawComplexity = String(obj.complexity ?? "medium");
|
|
206
|
+
const complexity: ComplexityCategory =
|
|
207
|
+
rawComplexity === "simple" || rawComplexity === "medium" || rawComplexity === "high"
|
|
208
|
+
? rawComplexity
|
|
209
|
+
: "medium";
|
|
210
|
+
|
|
211
|
+
let category = (obj.category as string) ?? "code";
|
|
212
|
+
if (!categories.includes(category)) category = "code";
|
|
213
|
+
|
|
214
|
+
let {selectedAgents} = obj;
|
|
215
|
+
if (!Array.isArray(selectedAgents)) selectedAgents = [];
|
|
216
|
+
|
|
217
|
+
const reasoning = String(obj.reasoning ?? "").trim() || "No reasoning provided";
|
|
218
|
+
const skipReason = obj.skipReason as string | undefined;
|
|
219
|
+
|
|
220
|
+
logInfo("orchestrator", `Result: complexity=${complexity}, category=${category}, agents=${JSON.stringify(selectedAgents)}`);
|
|
221
|
+
logDebug("orchestrator", `Reasoning: ${reasoning}`);
|
|
222
|
+
|
|
223
|
+
return {
|
|
224
|
+
complexity,
|
|
225
|
+
category,
|
|
226
|
+
selected_agents: selectedAgents as string[],
|
|
227
|
+
reasoning,
|
|
228
|
+
skip_reason: skipReason || undefined,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// ---------------------------------------------------------------------------
|
|
233
|
+
// Helpers
|
|
234
|
+
// ---------------------------------------------------------------------------
|
|
235
|
+
|
|
236
|
+
function makeFallback(
|
|
237
|
+
nonMandatory: AgentConfig[],
|
|
238
|
+
fallbackCount: number,
|
|
239
|
+
reasoning: string,
|
|
240
|
+
error: string,
|
|
241
|
+
): OrchestratorResult {
|
|
242
|
+
return {
|
|
243
|
+
complexity: "medium",
|
|
244
|
+
category: "code",
|
|
245
|
+
selected_agents: nonMandatory.slice(0, fallbackCount).map((a) => a.name),
|
|
246
|
+
reasoning,
|
|
247
|
+
error,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code agent-based plan reviewer.
|
|
3
|
+
* Uses --system-prompt with agent persona for specialized review.
|
|
4
|
+
* See cc-native-plan-review-spec.md §4.10
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as _path from "node:path";
|
|
8
|
+
|
|
9
|
+
import { logDebug, logError, logInfo, logWarn } from "../../../_shared/lib-ts/base/logger.js";
|
|
10
|
+
import { execFileAsync, findExecutable, getInternalSubprocessEnv } from "../../../_shared/lib-ts/base/subprocess-utils.js";
|
|
11
|
+
import { parseCliOutput } from "../cli-output-parser.js";
|
|
12
|
+
import { debugLog, debugRaw } from "../debug.js";
|
|
13
|
+
import { coerceToReview } from "../json-parser.js";
|
|
14
|
+
import type { AgentConfig, ReviewerResult, ReviewOptions } from "../types.js";
|
|
15
|
+
import { AGENT_REVIEW_PROMPT_PREFIX } from "../types.js";
|
|
16
|
+
import { makeResult } from "./types.js";
|
|
17
|
+
import type { Reviewer } from "./types.js";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Agent reviewer — runs a Claude Code instance with a custom persona.
|
|
21
|
+
*/
|
|
22
|
+
export class AgentReviewer implements Reviewer {
|
|
23
|
+
constructor(private agent: AgentConfig) {}
|
|
24
|
+
|
|
25
|
+
async review(
|
|
26
|
+
plan: string,
|
|
27
|
+
schema: Record<string, unknown>,
|
|
28
|
+
options: ReviewOptions,
|
|
29
|
+
): Promise<ReviewerResult> {
|
|
30
|
+
return runAgentReview(
|
|
31
|
+
plan,
|
|
32
|
+
this.agent,
|
|
33
|
+
schema,
|
|
34
|
+
options.timeout,
|
|
35
|
+
options.context_path,
|
|
36
|
+
options.session_name ?? "unknown",
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Run a single Claude Code agent to review the plan.
|
|
43
|
+
* Never throws — returns error ReviewerResult on failure.
|
|
44
|
+
*/
|
|
45
|
+
export async function runAgentReview(
|
|
46
|
+
plan: string,
|
|
47
|
+
agent: AgentConfig,
|
|
48
|
+
schema: Record<string, unknown>,
|
|
49
|
+
timeout: number,
|
|
50
|
+
contextPath?: string,
|
|
51
|
+
sessionName = "unknown",
|
|
52
|
+
): Promise<ReviewerResult> {
|
|
53
|
+
const claudePath = findExecutable("claude");
|
|
54
|
+
if (!claudePath) {
|
|
55
|
+
logWarn(agent.name, "Claude CLI not found on PATH");
|
|
56
|
+
return makeResult(agent.name, false, "skip", {}, "", "claude CLI not found on PATH");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
logDebug(agent.name, `Found Claude CLI at: ${claudePath}`);
|
|
60
|
+
|
|
61
|
+
const prompt = `IMMEDIATELY call StructuredOutput with your review of the plan below.
|
|
62
|
+
Do NOT output any text before calling StructuredOutput.
|
|
63
|
+
|
|
64
|
+
PLAN:
|
|
65
|
+
<<<
|
|
66
|
+
${plan}
|
|
67
|
+
>>>
|
|
68
|
+
`;
|
|
69
|
+
|
|
70
|
+
const schemaJson = JSON.stringify(schema);
|
|
71
|
+
const cmdArgs = [
|
|
72
|
+
"--model", agent.model,
|
|
73
|
+
"--output-format", "json",
|
|
74
|
+
"--json-schema", schemaJson,
|
|
75
|
+
"--max-turns", "3",
|
|
76
|
+
"--setting-sources", "",
|
|
77
|
+
"-p",
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
if (agent.system_prompt) {
|
|
81
|
+
const fullPrompt = AGENT_REVIEW_PROMPT_PREFIX + "\n\n---\n\n" + agent.system_prompt;
|
|
82
|
+
cmdArgs.push("--system-prompt", fullPrompt);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
logInfo(agent.name, `Running with model: ${agent.model}, timeout: ${timeout}s`);
|
|
86
|
+
|
|
87
|
+
const env = getInternalSubprocessEnv();
|
|
88
|
+
|
|
89
|
+
const result = await execFileAsync(claudePath, cmdArgs, {
|
|
90
|
+
input: prompt,
|
|
91
|
+
timeout: timeout * 1000,
|
|
92
|
+
env: env as Record<string, string>,
|
|
93
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (result.killed || result.signal === "SIGTERM") {
|
|
97
|
+
logWarn(agent.name, `TIMEOUT after ${timeout}s`);
|
|
98
|
+
return makeResult(agent.name, false, "error", {}, "", `${agent.name} timed out after ${timeout}s`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const raw = result.stdout.trim();
|
|
102
|
+
const err = result.stderr.trim();
|
|
103
|
+
|
|
104
|
+
if (!raw && !err && result.exitCode !== 0) {
|
|
105
|
+
logError(agent.name, `Process exited with code ${result.exitCode} and no output`);
|
|
106
|
+
return makeResult(agent.name, false, "error", {}, "", `${agent.name} failed to run (exit ${result.exitCode})`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
logDebug(agent.name, `Exit code: ${result.exitCode}`);
|
|
110
|
+
logDebug(agent.name, `stdout length: ${raw.length} chars`);
|
|
111
|
+
if (err) logDebug(agent.name, `stderr: ${err.slice(0, 500)}`);
|
|
112
|
+
|
|
113
|
+
// Debug logging
|
|
114
|
+
if (contextPath) {
|
|
115
|
+
debugRaw(contextPath, sessionName, `agent:${agent.name}`, "stdout", raw);
|
|
116
|
+
if (err) {
|
|
117
|
+
debugRaw(contextPath, sessionName, `agent:${agent.name}`, "stderr", err);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
debugLog(contextPath, sessionName, `agent:${agent.name}`, "subprocess_info", {
|
|
121
|
+
exit_code: result.exitCode,
|
|
122
|
+
stdout_len: raw.length,
|
|
123
|
+
stderr_len: err.length,
|
|
124
|
+
model: agent.model,
|
|
125
|
+
timeout,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (raw) logDebug(agent.name, `stdout preview: ${raw.slice(0, 500)}`);
|
|
130
|
+
|
|
131
|
+
const obj = parseCliOutput(raw, ["verdict", "summary"]);
|
|
132
|
+
|
|
133
|
+
if (contextPath) {
|
|
134
|
+
debugLog(contextPath, sessionName, `agent:${agent.name}`, "parsed_result", {
|
|
135
|
+
parsed_keys: obj ? Object.keys(obj) : null,
|
|
136
|
+
verdict: obj?.verdict ?? null,
|
|
137
|
+
has_summary: obj ? Boolean(obj.summary) : false,
|
|
138
|
+
issues_count: obj && Array.isArray(obj.issues) ? (obj.issues as unknown[]).length : 0,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (obj) {
|
|
143
|
+
logInfo(agent.name, `Parsed JSON successfully, verdict: ${obj.verdict ?? "N/A"}`);
|
|
144
|
+
} else {
|
|
145
|
+
logWarn(agent.name, "Failed to parse JSON from output");
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const [ok, verdict, norm] = coerceToReview(
|
|
149
|
+
obj as null | Record<string, unknown>,
|
|
150
|
+
"Retry or check agent configuration.",
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
return makeResult(agent.name, ok, verdict, norm, raw, err);
|
|
154
|
+
}
|
|
155
|
+
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex CLI plan reviewer.
|
|
3
|
+
* Runs Codex in non-interactive mode with read-only sandbox.
|
|
4
|
+
* See cc-native-plan-review-spec.md §4.11
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as fs from "node:fs";
|
|
8
|
+
import * as os from "node:os";
|
|
9
|
+
import * as path from "node:path";
|
|
10
|
+
|
|
11
|
+
import { logDebug, logError, logInfo as _logInfo, logWarn } from "../../../_shared/lib-ts/base/logger.js";
|
|
12
|
+
import { execFileAsync, findExecutable } from "../../../_shared/lib-ts/base/subprocess-utils.js";
|
|
13
|
+
import { coerceToReview, parseJsonMaybe } from "../json-parser.js";
|
|
14
|
+
import { REVIEW_PROMPT_PREFIX } from "../types.js";
|
|
15
|
+
import type { ReviewerResult, ReviewOptions } from "../types.js";
|
|
16
|
+
import { makeResult } from "./types.js";
|
|
17
|
+
import type { Reviewer } from "./types.js";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Codex reviewer — runs codex exec --sandbox read-only.
|
|
21
|
+
*/
|
|
22
|
+
export class CodexReviewer implements Reviewer {
|
|
23
|
+
private settings: Record<string, unknown>;
|
|
24
|
+
|
|
25
|
+
constructor(settings: Record<string, unknown>) {
|
|
26
|
+
this.settings = settings;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async review(
|
|
30
|
+
plan: string,
|
|
31
|
+
schema: Record<string, unknown>,
|
|
32
|
+
_options: ReviewOptions,
|
|
33
|
+
): Promise<ReviewerResult> {
|
|
34
|
+
return runCodexReview(plan, schema, this.settings);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Run Codex CLI to review the plan.
|
|
40
|
+
* Never throws — returns error ReviewerResult on failure.
|
|
41
|
+
*/
|
|
42
|
+
export async function runCodexReview(
|
|
43
|
+
plan: string,
|
|
44
|
+
schema: Record<string, unknown>,
|
|
45
|
+
settings: Record<string, unknown>,
|
|
46
|
+
): Promise<ReviewerResult> {
|
|
47
|
+
const codexSettings =
|
|
48
|
+
((settings.reviewers as Record<string, unknown> | undefined)?.codex as
|
|
49
|
+
| Record<string, unknown>
|
|
50
|
+
| undefined) ?? {};
|
|
51
|
+
const timeout = (codexSettings.timeout as number) ?? 120;
|
|
52
|
+
const model = (codexSettings.model as string) ?? "";
|
|
53
|
+
|
|
54
|
+
const codexPath = findExecutable("codex");
|
|
55
|
+
if (!codexPath) {
|
|
56
|
+
logWarn("codex", "CLI not found on PATH");
|
|
57
|
+
return makeResult("codex", false, "skip", {}, "", "codex CLI not found on PATH");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
logDebug("codex", `Found CLI at: ${codexPath}`);
|
|
61
|
+
|
|
62
|
+
const prompt = `${REVIEW_PROMPT_PREFIX}
|
|
63
|
+
Return ONLY a JSON object that matches this JSON Schema:
|
|
64
|
+
${JSON.stringify(schema)}
|
|
65
|
+
|
|
66
|
+
PLAN:
|
|
67
|
+
<<<
|
|
68
|
+
${plan}
|
|
69
|
+
>>>
|
|
70
|
+
`;
|
|
71
|
+
|
|
72
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "codex-review-"));
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const schemaPath = path.join(tmpDir, "schema.json");
|
|
76
|
+
const outPath = path.join(tmpDir, "codex_review.json");
|
|
77
|
+
|
|
78
|
+
fs.writeFileSync(schemaPath, JSON.stringify(schema, null, 2), "utf-8");
|
|
79
|
+
|
|
80
|
+
const cmdArgs = ["exec", "--sandbox", "read-only"];
|
|
81
|
+
|
|
82
|
+
if (model) {
|
|
83
|
+
cmdArgs.push("--model", model);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
cmdArgs.push("--output-schema", schemaPath, "-o", outPath, "-");
|
|
87
|
+
|
|
88
|
+
logDebug("codex", `Running command: codex ${cmdArgs.join(" ")}`);
|
|
89
|
+
|
|
90
|
+
const result = await execFileAsync(codexPath, cmdArgs, {
|
|
91
|
+
input: prompt,
|
|
92
|
+
timeout: timeout * 1000,
|
|
93
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (result.killed || result.signal === "SIGTERM") {
|
|
97
|
+
logWarn("codex", `TIMEOUT after ${timeout}s`);
|
|
98
|
+
return makeResult("codex", false, "error", {}, "", `codex timed out after ${timeout}s`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!result.stdout && !result.stderr && !fs.existsSync(outPath) && result.exitCode !== 0) {
|
|
102
|
+
logError("codex", `Process exited with code ${result.exitCode} and no output`);
|
|
103
|
+
return makeResult("codex", false, "error", {}, "", `codex failed to run (exit ${result.exitCode})`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
logDebug("codex", `Exit code: ${result.exitCode}`);
|
|
107
|
+
|
|
108
|
+
let raw = "";
|
|
109
|
+
if (fs.existsSync(outPath)) {
|
|
110
|
+
raw = fs.readFileSync(outPath, "utf8");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const obj = parseJsonMaybe(raw) ?? parseJsonMaybe(result.stdout);
|
|
114
|
+
const [ok, verdict, norm] = coerceToReview(
|
|
115
|
+
obj,
|
|
116
|
+
"Retry or check CLI auth/config.",
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const err = result.stderr.trim();
|
|
120
|
+
return makeResult("codex", ok, verdict, norm, raw || result.stdout, err);
|
|
121
|
+
} finally {
|
|
122
|
+
// Clean up temp directory
|
|
123
|
+
try {
|
|
124
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
125
|
+
} catch {
|
|
126
|
+
// Best effort cleanup
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|