aiwcli 0.10.3 → 0.11.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/bin/run.js +1 -1
- package/dist/commands/clear.js +28 -131
- package/dist/commands/init/index.js +3 -3
- package/dist/lib/gitignore-manager.d.ts +32 -0
- package/dist/lib/gitignore-manager.js +141 -2
- 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 +107 -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 +12 -12
- package/dist/templates/_shared/lib-ts/base/constants.ts +22 -15
- package/dist/templates/_shared/lib-ts/base/git-state.ts +1 -1
- package/dist/templates/_shared/lib-ts/base/hook-utils.ts +129 -50
- package/dist/templates/_shared/lib-ts/base/inference.ts +28 -21
- package/dist/templates/_shared/lib-ts/base/logger.ts +15 -2
- package/dist/templates/_shared/lib-ts/base/state-io.ts +9 -7
- package/dist/templates/_shared/lib-ts/base/stop-words.ts +131 -131
- package/dist/templates/_shared/lib-ts/base/subprocess-utils.ts +142 -0
- package/dist/templates/_shared/lib-ts/base/utils.ts +69 -69
- package/dist/templates/_shared/lib-ts/context/context-formatter.ts +30 -24
- package/dist/templates/_shared/lib-ts/context/context-selector.ts +50 -32
- package/dist/templates/_shared/lib-ts/context/context-store.ts +76 -48
- package/dist/templates/_shared/lib-ts/context/plan-manager.ts +43 -23
- package/dist/templates/_shared/lib-ts/context/task-tracker.ts +10 -6
- package/dist/templates/_shared/lib-ts/handoff/document-generator.ts +11 -10
- package/dist/templates/_shared/lib-ts/handoff/handoff-reader.ts +158 -0
- package/dist/templates/_shared/lib-ts/templates/formatters.ts +6 -4
- package/dist/templates/_shared/lib-ts/types.ts +68 -55
- package/dist/templates/_shared/scripts/resolve_context.ts +24 -0
- package/dist/templates/_shared/scripts/resume_handoff.ts +345 -0
- package/dist/templates/_shared/scripts/save_handoff.ts +3 -3
- package/dist/templates/_shared/scripts/status_line.ts +687 -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/CLAUDE.md +0 -2
- 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 +1027 -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 +156 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/artifacts.ts +792 -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 +144 -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/corroboration.ts +115 -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 +120 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/json-parser.ts +168 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/nul +3 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/orchestrator.ts +250 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/agent.ts +275 -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 +107 -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 +240 -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 +385 -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 +14 -1
- package/oclif.manifest.json +1 -1
- package/package.json +2 -2
- 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 -177
- 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 -339
- package/dist/templates/_shared/lib/base/inference.py +0 -307
- package/dist/templates/_shared/lib/base/logger.py +0 -305
- package/dist/templates/_shared/lib/base/stop_words.py +0 -221
- package/dist/templates/_shared/lib/base/subprocess_utils.py +0 -46
- package/dist/templates/_shared/lib/base/utils.py +0 -263
- 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 -303
- 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/lib/templates/plan_context.py +0 -73
- 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 -716
- 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/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 -954
- 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 -1071
- 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,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CC-Native plan review library — package entry point.
|
|
3
|
+
* Re-exports the public API from all modules.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Agent aggregation
|
|
7
|
+
export {
|
|
8
|
+
aggregateAgents,
|
|
9
|
+
extractBody,
|
|
10
|
+
extractFrontmatter,
|
|
11
|
+
} from "./aggregate-agents.js";
|
|
12
|
+
|
|
13
|
+
// Artifacts
|
|
14
|
+
export {
|
|
15
|
+
buildCombinedJson,
|
|
16
|
+
buildHighIssuesDocument,
|
|
17
|
+
buildInlineReviewSummary,
|
|
18
|
+
extractTopIssuesText,
|
|
19
|
+
formatCombinedMarkdown,
|
|
20
|
+
formatReviewMarkdown,
|
|
21
|
+
generateReviewIndex,
|
|
22
|
+
writeCombinedArtifacts,
|
|
23
|
+
} from "./artifacts.js";
|
|
24
|
+
|
|
25
|
+
// CC-native state
|
|
26
|
+
export {
|
|
27
|
+
getCcNativeState,
|
|
28
|
+
isPlanAlreadyReviewed,
|
|
29
|
+
markPlanReviewed,
|
|
30
|
+
markQuestionsAsked,
|
|
31
|
+
saveCcNativeState,
|
|
32
|
+
wasPlanPreviouslyDenied,
|
|
33
|
+
wasQuestionsAsked,
|
|
34
|
+
} from "./cc-native-state.js";
|
|
35
|
+
|
|
36
|
+
// CLI output parsing
|
|
37
|
+
export { parseCliOutput } from "./cli-output-parser.js";
|
|
38
|
+
|
|
39
|
+
// Configuration
|
|
40
|
+
export { getDisplaySettings, loadConfig } from "./config.js";
|
|
41
|
+
|
|
42
|
+
// Constants & security
|
|
43
|
+
export {
|
|
44
|
+
ENABLE_PLAN_NOTIFICATIONS,
|
|
45
|
+
ENABLE_ROBUST_PLAN_WRITES,
|
|
46
|
+
MAX_ERROR_FILE_SIZE,
|
|
47
|
+
MAX_PLAN_PATH_LENGTH,
|
|
48
|
+
MAX_RETRY_ATTEMPTS,
|
|
49
|
+
MAX_TOTAL_RETRY_TIME_MS,
|
|
50
|
+
PLANS_DIR,
|
|
51
|
+
RETRY_BACKOFF_MS,
|
|
52
|
+
validatePlanPath,
|
|
53
|
+
} from "./constants.js";
|
|
54
|
+
|
|
55
|
+
// Debug logging
|
|
56
|
+
export { cleanupDebugFolder, debugLog, debugRaw, getDebugDir } from "./debug.js";
|
|
57
|
+
|
|
58
|
+
// JSON parsing
|
|
59
|
+
export { coerceToReview, parseJsonMaybe } from "./json-parser.js";
|
|
60
|
+
|
|
61
|
+
// Orchestrator
|
|
62
|
+
export { buildOrchestratorSchema, runOrchestrator } from "./orchestrator.js";
|
|
63
|
+
|
|
64
|
+
// Reviewers
|
|
65
|
+
export {
|
|
66
|
+
AgentReviewer,
|
|
67
|
+
CodexReviewer,
|
|
68
|
+
GeminiReviewer,
|
|
69
|
+
runAgentReview,
|
|
70
|
+
runCodexReview,
|
|
71
|
+
runGeminiReview,
|
|
72
|
+
} from "./reviewers/index.js";
|
|
73
|
+
|
|
74
|
+
// Iteration state
|
|
75
|
+
export {
|
|
76
|
+
DEFAULT_REVIEW_ITERATIONS,
|
|
77
|
+
deleteState,
|
|
78
|
+
getIterationState,
|
|
79
|
+
getStateFilePath,
|
|
80
|
+
loadState,
|
|
81
|
+
saveStateToPlan,
|
|
82
|
+
shouldContinueIterating,
|
|
83
|
+
updateIterationState,
|
|
84
|
+
} from "./state.js";
|
|
85
|
+
|
|
86
|
+
// Types & schemas
|
|
87
|
+
export type {
|
|
88
|
+
AgentConfig,
|
|
89
|
+
CcNativeState,
|
|
90
|
+
CombinedReviewResult,
|
|
91
|
+
ComplexityCategory,
|
|
92
|
+
DisplaySettings,
|
|
93
|
+
IterationEntry,
|
|
94
|
+
IterationState,
|
|
95
|
+
OrchestratorConfig,
|
|
96
|
+
OrchestratorResult,
|
|
97
|
+
PlanReviewConfig,
|
|
98
|
+
PlanReviewState,
|
|
99
|
+
QuestionsAskedState,
|
|
100
|
+
ReviewData,
|
|
101
|
+
ReviewDecision,
|
|
102
|
+
ReviewDecisionResult,
|
|
103
|
+
Reviewer,
|
|
104
|
+
ReviewerResult,
|
|
105
|
+
ReviewIssue,
|
|
106
|
+
ReviewOptions,
|
|
107
|
+
Verdict,
|
|
108
|
+
} from "./types.js";
|
|
109
|
+
|
|
110
|
+
export {
|
|
111
|
+
AGENT_REVIEW_PROMPT_PREFIX,
|
|
112
|
+
DEFAULT_DISPLAY,
|
|
113
|
+
DEFAULT_SANITIZATION,
|
|
114
|
+
ORCHESTRATOR_SCHEMA,
|
|
115
|
+
REVIEW_PROMPT_PREFIX,
|
|
116
|
+
REVIEW_SCHEMA,
|
|
117
|
+
} from "./types.js";
|
|
118
|
+
|
|
119
|
+
// Verdict aggregation
|
|
120
|
+
export { computeReviewDecision, worstVerdict } from "./verdict.js";
|
|
@@ -0,0 +1,168 @@
|
|
|
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
|
+
// Heuristic extraction grabbed the wrong object — reject it.
|
|
77
|
+
// Strict parse still returns partial objects (caller handles defaults).
|
|
78
|
+
if (parseMethod === "heuristic") {
|
|
79
|
+
logWarn("parse", "Rejecting heuristic result due to missing required fields");
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return obj;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Validate/normalize parsed JSON to ReviewData shape with safe defaults.
|
|
90
|
+
*
|
|
91
|
+
* @param obj - Parsed JSON object (possibly null)
|
|
92
|
+
* @param defaultFixMsg - Default suggested_fix message for error case
|
|
93
|
+
* @returns Tuple of [ok, verdict, normalizedData]
|
|
94
|
+
*/
|
|
95
|
+
export function coerceToReview(
|
|
96
|
+
obj: null | Record<string, unknown>,
|
|
97
|
+
defaultFixMsg = "Retry or check configuration.",
|
|
98
|
+
): [boolean, Verdict, ReviewData] {
|
|
99
|
+
if (!obj) {
|
|
100
|
+
logWarn("coerce", "No object provided to coerceToReview");
|
|
101
|
+
return [
|
|
102
|
+
false,
|
|
103
|
+
"error",
|
|
104
|
+
{
|
|
105
|
+
verdict: "fail",
|
|
106
|
+
summary: "No structured output returned.",
|
|
107
|
+
summary_source: "default",
|
|
108
|
+
issues: [
|
|
109
|
+
{
|
|
110
|
+
severity: "high",
|
|
111
|
+
category: "tooling",
|
|
112
|
+
issue: "Reviewer returned no JSON.",
|
|
113
|
+
suggested_fix: defaultFixMsg,
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
missing_sections: [],
|
|
117
|
+
questions: [],
|
|
118
|
+
},
|
|
119
|
+
];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const rawVerdict = obj.verdict;
|
|
123
|
+
let verdict: Verdict;
|
|
124
|
+
if (rawVerdict === "pass" || rawVerdict === "warn" || rawVerdict === "fail") {
|
|
125
|
+
verdict = rawVerdict;
|
|
126
|
+
} else {
|
|
127
|
+
logWarn(
|
|
128
|
+
"coerce",
|
|
129
|
+
`Invalid or missing verdict '${String(rawVerdict)}', defaulting to 'warn'`,
|
|
130
|
+
);
|
|
131
|
+
verdict = "warn";
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Log when fields are being defaulted
|
|
135
|
+
const summaryRaw = String(obj.summary ?? "").trim();
|
|
136
|
+
if (!summaryRaw) {
|
|
137
|
+
logWarn(
|
|
138
|
+
"coerce",
|
|
139
|
+
"summary missing or empty from parsed output, using default",
|
|
140
|
+
);
|
|
141
|
+
logDebug("coerce", `Raw object keys: ${JSON.stringify(Object.keys(obj))}`);
|
|
142
|
+
logDebug(
|
|
143
|
+
"coerce",
|
|
144
|
+
`verdict=${obj.verdict}, issues_count=${Array.isArray(obj.issues) ? (obj.issues as unknown[]).length : 0}`,
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (!obj.issues) {
|
|
149
|
+
logDebug("coerce", "issues array empty or missing");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const norm: ReviewData = {
|
|
153
|
+
verdict,
|
|
154
|
+
summary: summaryRaw || "No summary provided.",
|
|
155
|
+
summary_source: summaryRaw ? "reviewer" : "default",
|
|
156
|
+
issues: Array.isArray(obj.issues)
|
|
157
|
+
? (obj.issues as ReviewData["issues"])
|
|
158
|
+
: [],
|
|
159
|
+
missing_sections: Array.isArray(obj.missing_sections)
|
|
160
|
+
? (obj.missing_sections as string[])
|
|
161
|
+
: [],
|
|
162
|
+
questions: Array.isArray(obj.questions)
|
|
163
|
+
? (obj.questions as string[])
|
|
164
|
+
: [],
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
return [true, verdict, norm];
|
|
168
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plan orchestrator — analyzes complexity and selects reviewer agents.
|
|
3
|
+
* See cc-native-plan-review-spec.md §4.8
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { logDebug, logInfo, logWarn, logError } from "../../_shared/lib-ts/base/logger.js";
|
|
7
|
+
import { getInternalSubprocessEnv, findExecutable, execFileAsync } from "../../_shared/lib-ts/base/subprocess-utils.js";
|
|
8
|
+
import { parseCliOutput } from "./cli-output-parser.js";
|
|
9
|
+
import type { AgentConfig, OrchestratorConfig, OrchestratorResult, ComplexityCategory } from "./types.js";
|
|
10
|
+
import { ORCHESTRATOR_SCHEMA } from "./types.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
|
+
shell: process.platform === "win32",
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
if (result.killed || result.signal === "SIGTERM") {
|
|
182
|
+
logWarn("orchestrator", `TIMEOUT after ${config.timeout}s, falling back to medium complexity`);
|
|
183
|
+
return makeFallback(nonMandatory, fallbackCount, "Orchestrator timed out - defaulting to medium complexity", `Orchestrator timed out after ${config.timeout}s`);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const raw = result.stdout.trim();
|
|
187
|
+
if (result.stderr) logDebug("orchestrator", `stderr: ${result.stderr.slice(0, 300)}`);
|
|
188
|
+
|
|
189
|
+
if (!raw && !result.stderr && result.exitCode !== 0) {
|
|
190
|
+
logError("orchestrator", `Process exited with code ${result.exitCode}, falling back to medium complexity`);
|
|
191
|
+
return makeFallback(nonMandatory, fallbackCount, `Orchestrator failed (exit ${result.exitCode})`, `Exit code ${result.exitCode}`);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const obj = parseCliOutput(raw);
|
|
195
|
+
|
|
196
|
+
logDebug("orchestrator", `Raw output length: ${raw.length} chars`);
|
|
197
|
+
if (raw) logDebug("orchestrator", `Raw output (first 500 chars): ${raw.slice(0, 500)}`);
|
|
198
|
+
logDebug("orchestrator", `Parsed obj: ${JSON.stringify(obj)}`);
|
|
199
|
+
|
|
200
|
+
if (!obj) {
|
|
201
|
+
logWarn("orchestrator", "Failed to parse output, falling back to medium complexity");
|
|
202
|
+
return makeFallback(nonMandatory, fallbackCount, "Orchestrator output could not be parsed", "Failed to parse orchestrator output");
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Extract and validate fields
|
|
206
|
+
const rawComplexity = String(obj.complexity ?? "medium");
|
|
207
|
+
const complexity: ComplexityCategory =
|
|
208
|
+
rawComplexity === "simple" || rawComplexity === "medium" || rawComplexity === "high"
|
|
209
|
+
? rawComplexity
|
|
210
|
+
: "medium";
|
|
211
|
+
|
|
212
|
+
let category = (obj.category as string) ?? "code";
|
|
213
|
+
if (!categories.includes(category)) category = "code";
|
|
214
|
+
|
|
215
|
+
let selectedAgents = obj.selectedAgents;
|
|
216
|
+
if (!Array.isArray(selectedAgents)) selectedAgents = [];
|
|
217
|
+
|
|
218
|
+
const reasoning = String(obj.reasoning ?? "").trim() || "No reasoning provided";
|
|
219
|
+
const skipReason = obj.skipReason as string | undefined;
|
|
220
|
+
|
|
221
|
+
logInfo("orchestrator", `Result: complexity=${complexity}, category=${category}, agents=${JSON.stringify(selectedAgents)}`);
|
|
222
|
+
logDebug("orchestrator", `Reasoning: ${reasoning}`);
|
|
223
|
+
|
|
224
|
+
return {
|
|
225
|
+
complexity,
|
|
226
|
+
category,
|
|
227
|
+
selected_agents: selectedAgents as string[],
|
|
228
|
+
reasoning,
|
|
229
|
+
skip_reason: skipReason || undefined,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// ---------------------------------------------------------------------------
|
|
234
|
+
// Helpers
|
|
235
|
+
// ---------------------------------------------------------------------------
|
|
236
|
+
|
|
237
|
+
function makeFallback(
|
|
238
|
+
nonMandatory: AgentConfig[],
|
|
239
|
+
fallbackCount: number,
|
|
240
|
+
reasoning: string,
|
|
241
|
+
error: string,
|
|
242
|
+
): OrchestratorResult {
|
|
243
|
+
return {
|
|
244
|
+
complexity: "medium",
|
|
245
|
+
category: "code",
|
|
246
|
+
selected_agents: nonMandatory.slice(0, fallbackCount).map((a) => a.name),
|
|
247
|
+
reasoning,
|
|
248
|
+
error,
|
|
249
|
+
};
|
|
250
|
+
}
|