aiwcli 0.12.7 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/dist/commands/clean.d.ts +7 -0
  2. package/dist/commands/clean.js +17 -8
  3. package/dist/commands/clear.d.ts +85 -0
  4. package/dist/commands/clear.js +455 -347
  5. package/dist/commands/init/index.d.ts +15 -0
  6. package/dist/commands/init/index.js +79 -38
  7. package/dist/lib/gitignore-manager.js +12 -13
  8. package/dist/lib/settings-hierarchy.d.ts +13 -1
  9. package/dist/lib/settings-hierarchy.js +1 -1
  10. package/dist/lib/template-linter.d.ts +4 -0
  11. package/dist/lib/template-linter.js +1 -1
  12. package/dist/lib/tty-detection.d.ts +1 -0
  13. package/dist/lib/tty-detection.js +1 -0
  14. package/dist/templates/CLAUDE.md +27 -0
  15. package/dist/templates/_shared/.claude/settings.json +7 -7
  16. package/dist/templates/_shared/.claude/{commands/handoff.md → skills/handoff/SKILL.md} +4 -3
  17. package/dist/templates/_shared/.claude/{commands/handoff-resume.md → skills/handoff-resume/SKILL.md} +3 -2
  18. package/dist/templates/_shared/.claude/skills/meta-plan/SKILL.md +43 -0
  19. package/dist/templates/_shared/.codex/workflows/handoff.md +1 -1
  20. package/dist/templates/_shared/.codex/workflows/meta-plan.md +347 -0
  21. package/dist/templates/_shared/.windsurf/workflows/handoff.md +1 -1
  22. package/dist/templates/_shared/.windsurf/workflows/meta-plan.md +347 -0
  23. package/dist/templates/_shared/hooks-ts/lint_after_edit.ts +59 -0
  24. package/dist/templates/_shared/hooks-ts/session_end.ts +11 -10
  25. package/dist/templates/_shared/hooks-ts/session_start.ts +15 -12
  26. package/dist/templates/_shared/hooks-ts/user_prompt_submit.ts +12 -12
  27. package/dist/templates/_shared/lib-ts/CLAUDE.md +3 -3
  28. package/dist/templates/_shared/lib-ts/base/constants.ts +324 -306
  29. package/dist/templates/_shared/lib-ts/base/hook-utils.ts +26 -7
  30. package/dist/templates/_shared/lib-ts/base/inference.ts +19 -19
  31. package/dist/templates/_shared/lib-ts/base/lint-dispatch.ts +287 -0
  32. package/dist/templates/_shared/lib-ts/base/state-io.ts +4 -3
  33. package/dist/templates/_shared/lib-ts/base/subprocess-utils.ts +3 -3
  34. package/dist/templates/_shared/lib-ts/context/CLAUDE.md +134 -0
  35. package/dist/templates/_shared/lib-ts/context/context-formatter.ts +16 -15
  36. package/dist/templates/_shared/lib-ts/context/context-selector.ts +16 -16
  37. package/dist/templates/_shared/lib-ts/context/context-store.ts +15 -14
  38. package/dist/templates/_shared/lib-ts/context/plan-manager.ts +2 -2
  39. package/dist/templates/_shared/scripts/resolve-run.ts +61 -0
  40. package/dist/templates/_shared/scripts/resolve_context.ts +1 -1
  41. package/dist/templates/_shared/scripts/status_line.ts +100 -94
  42. package/dist/templates/_shared/{handoff-system → skills/handoff-system}/CLAUDE.md +433 -421
  43. package/dist/templates/_shared/{handoff-system → skills/handoff-system}/lib/document-generator.ts +5 -4
  44. package/dist/templates/_shared/{handoff-system → skills/handoff-system}/lib/handoff-reader.ts +2 -1
  45. package/dist/templates/_shared/{handoff-system → skills/handoff-system}/scripts/resume_handoff.ts +6 -6
  46. package/dist/templates/_shared/{handoff-system → skills/handoff-system}/scripts/save_handoff.ts +16 -17
  47. package/dist/templates/_shared/{handoff-system → skills/handoff-system}/workflows/handoff-resume.md +2 -2
  48. package/dist/templates/_shared/{handoff-system → skills/handoff-system}/workflows/handoff.md +3 -3
  49. package/dist/templates/_shared/skills/meta-plan/CLAUDE.md +44 -0
  50. package/dist/templates/_shared/skills/meta-plan/workflows/meta-plan.md +347 -0
  51. package/dist/templates/cc-native/.claude/commands/cc-native/specdev.md +1 -1
  52. package/dist/templates/cc-native/.claude/settings.json +86 -57
  53. package/dist/templates/cc-native/_cc-native/artifacts/CLAUDE.md +64 -0
  54. package/dist/templates/cc-native/_cc-native/{lib-ts/artifacts → artifacts/lib}/format.ts +599 -597
  55. package/dist/templates/cc-native/_cc-native/{lib-ts/artifacts → artifacts/lib}/index.ts +26 -26
  56. package/dist/templates/cc-native/_cc-native/{lib-ts/artifacts → artifacts/lib}/tracker.ts +107 -106
  57. package/dist/templates/cc-native/_cc-native/{lib-ts/artifacts → artifacts/lib}/write.ts +119 -118
  58. package/dist/templates/cc-native/_cc-native/hooks/CLAUDE.md +237 -247
  59. package/dist/templates/cc-native/_cc-native/hooks/cc-native-plan-review.ts +76 -74
  60. package/dist/templates/cc-native/_cc-native/hooks/validate_task_prompt.ts +76 -0
  61. package/dist/templates/cc-native/_cc-native/lib-ts/aggregate-agents.ts +163 -156
  62. package/dist/templates/cc-native/_cc-native/lib-ts/cc-native-state.ts +15 -16
  63. package/dist/templates/cc-native/_cc-native/lib-ts/index.ts +116 -116
  64. package/dist/templates/cc-native/_cc-native/lib-ts/plan-discovery.ts +3 -3
  65. package/dist/templates/cc-native/_cc-native/lib-ts/rlm/embedding-indexer.ts +16 -12
  66. package/dist/templates/cc-native/_cc-native/lib-ts/rlm/hyde.ts +2 -3
  67. package/dist/templates/cc-native/_cc-native/lib-ts/rlm/index.ts +31 -31
  68. package/dist/templates/cc-native/_cc-native/lib-ts/rlm/logger.ts +7 -6
  69. package/dist/templates/cc-native/_cc-native/lib-ts/rlm/ollama-client.ts +9 -7
  70. package/dist/templates/cc-native/_cc-native/lib-ts/rlm/retrieval-pipeline.ts +17 -14
  71. package/dist/templates/cc-native/_cc-native/lib-ts/rlm/transcript-indexer.ts +41 -37
  72. package/dist/templates/cc-native/_cc-native/lib-ts/rlm/transcript-loader.ts +43 -33
  73. package/dist/templates/cc-native/_cc-native/lib-ts/rlm/transcript-searcher.ts +20 -20
  74. package/dist/templates/cc-native/_cc-native/lib-ts/rlm/types.ts +9 -8
  75. package/dist/templates/cc-native/_cc-native/lib-ts/rlm/vector-store.ts +4 -3
  76. package/dist/templates/cc-native/_cc-native/lib-ts/settings.ts +9 -10
  77. package/dist/templates/cc-native/_cc-native/lib-ts/state.ts +20 -19
  78. package/dist/templates/cc-native/_cc-native/lib-ts/types.ts +329 -329
  79. package/dist/templates/cc-native/_cc-native/plan-review/CLAUDE.md +149 -0
  80. package/dist/templates/cc-native/_cc-native/plan-review/agents/CLAUDE.md +143 -0
  81. package/dist/templates/cc-native/_cc-native/plan-review/agents/PLAN-ORCHESTRATOR.md +213 -0
  82. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-questions/PLAN-QUESTIONER.md +70 -0
  83. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/ARCH-EVOLUTION.md +62 -0
  84. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/ARCH-PATTERNS.md +61 -0
  85. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/ARCH-STRUCTURE.md +62 -0
  86. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/ASSUMPTION-TRACER.md +56 -0
  87. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/CLARITY-AUDITOR.md +53 -0
  88. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/COMPLETENESS-FEASIBILITY.md +66 -0
  89. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/COMPLETENESS-GAPS.md +70 -0
  90. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/COMPLETENESS-ORDERING.md +62 -0
  91. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/CONSTRAINT-VALIDATOR.md +72 -0
  92. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/DESIGN-ADR-VALIDATOR.md +61 -0
  93. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/DESIGN-SCALE-MATCHER.md +64 -0
  94. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/DEVILS-ADVOCATE.md +56 -0
  95. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/DOCUMENTATION-PHILOSOPHY.md +86 -0
  96. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/HANDOFF-READINESS.md +59 -0
  97. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/HIDDEN-COMPLEXITY.md +58 -0
  98. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/INCREMENTAL-DELIVERY.md +66 -0
  99. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/RISK-DEPENDENCY.md +62 -0
  100. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/RISK-FMEA.md +66 -0
  101. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/RISK-PREMORTEM.md +71 -0
  102. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/RISK-REVERSIBILITY.md +74 -0
  103. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/SCOPE-BOUNDARY.md +77 -0
  104. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/SIMPLICITY-GUARDIAN.md +62 -0
  105. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/SKEPTIC.md +68 -0
  106. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/TESTDRIVEN-BEHAVIOR-AUDITOR.md +61 -0
  107. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/TESTDRIVEN-CHARACTERIZATION.md +71 -0
  108. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/TESTDRIVEN-FIRST-VALIDATOR.md +61 -0
  109. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/TESTDRIVEN-PYRAMID-ANALYZER.md +61 -0
  110. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/TRADEOFF-COSTS.md +67 -0
  111. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/TRADEOFF-STAKEHOLDERS.md +65 -0
  112. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/VERIFY-COVERAGE.md +74 -0
  113. package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/VERIFY-STRENGTH.md +69 -0
  114. package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/agent-selection.ts +162 -163
  115. package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/corroboration.ts +119 -119
  116. package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/graduation.ts +132 -132
  117. package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/orchestrator.ts +70 -70
  118. package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/output-builder.ts +121 -130
  119. package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/plan-questions.ts +101 -102
  120. package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/review-pipeline.ts +507 -511
  121. package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/reviewers/agent.ts +73 -74
  122. package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/reviewers/base/base-agent.ts +217 -217
  123. package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/reviewers/index.ts +12 -12
  124. package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/reviewers/providers/claude-agent.ts +66 -66
  125. package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/reviewers/providers/codex-agent.ts +185 -185
  126. package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/reviewers/providers/gemini-agent.ts +39 -39
  127. package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/reviewers/providers/orchestrator-claude-agent.ts +196 -196
  128. package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/reviewers/schemas.ts +201 -201
  129. package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/reviewers/types.ts +23 -23
  130. package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/verdict.ts +72 -72
  131. package/dist/templates/cc-native/_cc-native/{workflows → plan-review/workflows}/specdev.md +9 -9
  132. package/oclif.manifest.json +1 -1
  133. package/package.json +6 -5
  134. package/dist/templates/cc-native/_cc-native/lib-ts/artifacts.ts +0 -21
@@ -1,130 +1,121 @@
1
- /**
2
- * Output construction: issue truncation, verdict override, message building.
3
- * Extracted from cc-native-plan-review.ts.
4
- */
5
-
6
- import { logInfo } from "../../_shared/lib-ts/base/logger.js";
7
-
8
- import type {
9
- ReviewerResult,
10
- CombinedReviewResult,
11
- CorroborationResult,
12
- IterationState,
13
- } from "./types.js";
14
- import {
15
- buildInlineReviewSummary,
16
- extractTopIssuesText,
17
- } from "./artifacts/format.js";
18
- import { extractTopIssuesForTracker } from "./graduation.js";
19
-
20
- const HOOK = "output-builder";
21
-
22
- const REVIEWER_CAVEAT = "Reviewers have limited context compared to your full session — use your judgment to adopt valid points and dismiss genuine false positives. However, treat false positives as a clarity signal: if a reviewer misunderstood your plan, an agent executing it will likely hit the same confusion. Revise those sections to be unambiguous so no future reader — human or AI — makes the same mistake.";
23
- const RESUBMIT_INSTRUCTION = "IMPORTANT: After revising the plan file, you MUST call ExitPlanMode again to trigger re-review. Do not end your turn or ask the user without calling ExitPlanMode.";
24
-
25
- // ---------------------------------------------------------------------------
26
- // Issue Truncation
27
- // ---------------------------------------------------------------------------
28
-
29
- /**
30
- * Truncate per-agent issues to top N by severity.
31
- * @mutates agentResults[name].data.issues in place.
32
- */
33
- export function truncateAgentIssues(
34
- agentResults: Record<string, ReviewerResult>,
35
- maxPerAgent: number,
36
- ): void {
37
- for (const r of Object.values(agentResults)) {
38
- if (!Array.isArray(r.data?.issues)) continue;
39
- const issues = r.data.issues as Array<{ severity?: string }>;
40
- if (issues.length <= maxPerAgent) continue;
41
- const severityOrder: Record<string, number> = { high: 0, medium: 1, low: 2 };
42
- issues.sort((a, b) => (severityOrder[a.severity ?? "low"] ?? 2) - (severityOrder[b.severity ?? "low"] ?? 2));
43
- const originalCount = issues.length;
44
- r.data.issues = issues.slice(0, maxPerAgent);
45
- logInfo(HOOK, `${r.name}: truncated issues ${originalCount} → ${maxPerAgent}`);
46
- }
47
- }
48
-
49
- // ---------------------------------------------------------------------------
50
- // Verdict Override
51
- // ---------------------------------------------------------------------------
52
-
53
- /**
54
- * Override verdict to "fail" for agents exceeding high-issue threshold.
55
- * @mutates agentResults[name].verdict in place.
56
- */
57
- export function overrideVerdictsByThreshold(
58
- agentResults: Record<string, ReviewerResult>,
59
- threshold: number,
60
- ): void {
61
- for (const r of Object.values(agentResults)) {
62
- if (!r.verdict || r.verdict === "skip" || r.verdict === "error") continue;
63
- const issues = Array.isArray(r.data?.issues) ? r.data.issues as Array<{ severity?: string }> : [];
64
- const agentHigh = issues.filter(i => i.severity === "high").length;
65
- if (agentHigh >= threshold) {
66
- logInfo(HOOK, `${r.name}: verdict overridden to 'fail' (${agentHigh} high issues >= ${threshold})`);
67
- r.verdict = "fail";
68
- }
69
- }
70
- }
71
-
72
- // ---------------------------------------------------------------------------
73
- // Output Building
74
- // ---------------------------------------------------------------------------
75
-
76
- export interface ReviewOutputParams {
77
- combinedResult: CombinedReviewResult;
78
- corroborationResult: CorroborationResult;
79
- iterationState: IterationState;
80
- reviewFile: string;
81
- highIssuesPath: string;
82
- }
83
-
84
- export interface ReviewOutput {
85
- contextText: string;
86
- blockReason: string;
87
- shouldDeny: boolean;
88
- }
89
-
90
- /**
91
- * Build the final review output: context text and block reason.
92
- */
93
- export function buildReviewOutput(params: ReviewOutputParams): ReviewOutput {
94
- const { combinedResult, corroborationResult, iterationState } = params;
95
-
96
- const shouldDeny = corroborationResult.blocking.length > 0;
97
- const reviewScore = shouldDeny ? 1.0 : 0.0;
98
- const overall = corroborationResult.verdict;
99
-
100
- // Build inline summary
101
- const inlineSummary = buildInlineReviewSummary(combinedResult, 5, 800, corroborationResult);
102
- const contextParts = [inlineSummary];
103
-
104
- // Top issues
105
- const topIssuesList = extractTopIssuesForTracker(combinedResult, 5);
106
- if (topIssuesList.length > 0) {
107
- contextParts.push(`\nTop high-severity issues:\n${topIssuesList.map(i => `- ${i}`).join("\n")}`);
108
- }
109
- contextParts.push(`\nFull review: \`${params.reviewFile}\`\n`);
110
-
111
- const contextText = contextParts.join("");
112
- const iterInfo = ` (iteration ${iterationState.current}/${iterationState.max}, score=${reviewScore.toFixed(2)})`;
113
-
114
- let blockReason: string;
115
- if (shouldDeny) {
116
- const topIssuesText = extractTopIssuesText(combinedResult, 3, "high");
117
- blockReason = `Plan review FAILED${iterInfo}. ` +
118
- `Critical issues: ${topIssuesText}. ` +
119
- `IMPORTANT: Read \`${params.highIssuesPath}\` for ALL high-severity issues — ` +
120
- `this file contains only the most critical findings, no noise. ` +
121
- `${REVIEWER_CAVEAT} ` +
122
- `Revise the plan to address these issues, then call ExitPlanMode again. ` +
123
- RESUBMIT_INSTRUCTION;
124
- } else {
125
- blockReason = `Plan review ${overall.toUpperCase()}${iterInfo}. Review complete. ${REVIEWER_CAVEAT}`;
126
- }
127
-
128
- return { contextText, blockReason, shouldDeny };
129
- }
130
-
1
+ /**
2
+ * Output construction: issue truncation, verdict override, message building.
3
+ * Extracted from cc-native-plan-review.ts.
4
+ */
5
+
6
+ import { logInfo } from "../../../_shared/lib-ts/base/logger.js";
7
+ import {
8
+ buildInlineReviewSummary,
9
+ extractTopIssuesText,
10
+ } from "../../artifacts/lib/format.js";
11
+ import type {
12
+ ReviewerResult,
13
+ CombinedReviewResult,
14
+ CorroborationResult,
15
+ IterationState,
16
+ } from "../../lib-ts/types.js";
17
+
18
+ const HOOK = "output-builder";
19
+
20
+ const REVIEWER_CAVEAT = "Reviewers have limited context compared to your full session — use your judgment to adopt valid points and dismiss genuine false positives. However, treat false positives as a clarity signal: if a reviewer misunderstood your plan, an agent executing it will likely hit the same confusion. Revise those sections to be unambiguous so no future reader — human or AI — makes the same mistake.";
21
+ const RESUBMIT_INSTRUCTION = "IMPORTANT: After revising the plan file, you MUST call ExitPlanMode again to trigger re-review. Do not end your turn or ask the user without calling ExitPlanMode.";
22
+
23
+ // ---------------------------------------------------------------------------
24
+ // Issue Truncation
25
+ // ---------------------------------------------------------------------------
26
+
27
+ /**
28
+ * Truncate per-agent issues to top N by severity.
29
+ * Mutates agentResults[name].data.issues in place.
30
+ */
31
+ export function truncateAgentIssues(
32
+ agentResults: Record<string, ReviewerResult>,
33
+ maxPerAgent: number,
34
+ ): void {
35
+ for (const r of Object.values(agentResults)) {
36
+ if (!Array.isArray(r.data?.issues)) continue;
37
+ const issues = r.data.issues as Array<{ severity?: string }>;
38
+ if (issues.length <= maxPerAgent) continue;
39
+ const severityOrder: Record<string, number> = { high: 0, medium: 1, low: 2 };
40
+ issues.sort((a, b) => (severityOrder[a.severity ?? "low"] ?? 2) - (severityOrder[b.severity ?? "low"] ?? 2));
41
+ const originalCount = issues.length;
42
+ r.data.issues = issues.slice(0, maxPerAgent);
43
+ logInfo(HOOK, `${r.name}: truncated issues ${originalCount} ${maxPerAgent}`);
44
+ }
45
+ }
46
+
47
+ // ---------------------------------------------------------------------------
48
+ // Verdict Override
49
+ // ---------------------------------------------------------------------------
50
+
51
+ /**
52
+ * Override verdict to "fail" for agents exceeding high-issue threshold.
53
+ * Mutates agentResults[name].verdict in place.
54
+ */
55
+ export function overrideVerdictsByThreshold(
56
+ agentResults: Record<string, ReviewerResult>,
57
+ threshold: number,
58
+ ): void {
59
+ for (const r of Object.values(agentResults)) {
60
+ if (!r.verdict || r.verdict === "skip" || r.verdict === "error") continue;
61
+ const issues = Array.isArray(r.data?.issues) ? r.data.issues as Array<{ severity?: string }> : [];
62
+ const agentHigh = issues.filter(i => i.severity === "high").length;
63
+ if (agentHigh >= threshold) {
64
+ logInfo(HOOK, `${r.name}: verdict overridden to 'fail' (${agentHigh} high issues >= ${threshold})`);
65
+ r.verdict = "fail";
66
+ }
67
+ }
68
+ }
69
+
70
+ // ---------------------------------------------------------------------------
71
+ // Output Building
72
+ // ---------------------------------------------------------------------------
73
+
74
+ export interface ReviewOutputParams {
75
+ combinedResult: CombinedReviewResult;
76
+ corroborationResult: CorroborationResult;
77
+ iterationState: IterationState;
78
+ reviewFile: string;
79
+ highIssuesPath: string;
80
+ }
81
+
82
+ export interface ReviewOutput {
83
+ contextText: string;
84
+ blockReason: string;
85
+ shouldDeny: boolean;
86
+ }
87
+
88
+ /**
89
+ * Build the final review output: context text and block reason.
90
+ */
91
+ export function buildReviewOutput(params: ReviewOutputParams): ReviewOutput {
92
+ const { combinedResult, corroborationResult, iterationState } = params;
93
+
94
+ const shouldDeny = corroborationResult.blocking.length > 0;
95
+ const reviewScore = shouldDeny ? 1 : 0;
96
+ const overall = corroborationResult.verdict;
97
+
98
+ // Build inline summary (no individual issues — those go in blockReason)
99
+ const inlineSummary = buildInlineReviewSummary(combinedResult, 0, 800, corroborationResult);
100
+ const contextParts = [inlineSummary];
101
+ contextParts.push(`\nFull review: \`${params.reviewFile}\`\n`);
102
+
103
+ const contextText = contextParts.join("");
104
+ const iterInfo = ` (iteration ${iterationState.current}/${iterationState.max}, score=${reviewScore.toFixed(2)})`;
105
+
106
+ let blockReason: string;
107
+ if (shouldDeny) {
108
+ const topIssuesText = extractTopIssuesText(combinedResult, 15, "high");
109
+ blockReason = `Plan review FAILED${iterInfo}. ` +
110
+ `High-severity issues:\n${topIssuesText}\n\n` +
111
+ `Full details: \`${params.highIssuesPath}\`\n` +
112
+ `${REVIEWER_CAVEAT} ` +
113
+ `Revise the plan to address these issues, then call ExitPlanMode again. ` +
114
+ RESUBMIT_INSTRUCTION;
115
+ } else {
116
+ blockReason = `Plan review ${overall.toUpperCase()}${iterInfo}. Review complete. ${REVIEWER_CAVEAT}`;
117
+ }
118
+
119
+ return { contextText, blockReason, shouldDeny };
120
+ }
121
+
@@ -1,102 +1,101 @@
1
- /**
2
- * Plan question generation — runs a fresh-context agent to identify
3
- * questions, assumptions, and ambiguities in a plan before review.
4
- * See cc-native-plan-review.ts for integration point (questions gate).
5
- */
6
-
7
- import * as path from "node:path";
8
-
9
- import { aggregateAgents } from "./aggregate-agents.js";
10
- import { runAgentReview } from "./reviewers/index.js";
11
- import { QUESTIONS_SCHEMA } from "./reviewers/schemas.js";
12
- import type { AgentConfig, ModelsConfig } from "./types.js";
13
- import { logInfo, logWarn, logError } from "../../_shared/lib-ts/base/logger.js";
14
-
15
- // ---------------------------------------------------------------------------
16
- // Types
17
- // ---------------------------------------------------------------------------
18
-
19
- export interface PlanQuestionsResult {
20
- questions: string[];
21
- assumptions: string[];
22
- ambiguities: string[];
23
- }
24
-
25
- // ---------------------------------------------------------------------------
26
- // Provider assignment (local copy — avoids circular import from hook)
27
- // ---------------------------------------------------------------------------
28
-
29
- import { findExecutable } from "../../_shared/lib-ts/base/subprocess-utils.js";
30
-
31
- function assignProvider(agent: AgentConfig): AgentConfig {
32
- // Default to claude provider with the agent's configured model
33
- const found = findExecutable("claude");
34
- if (found) {
35
- return { ...agent, provider: "claude" };
36
- }
37
- logWarn("plan-questions", "Claude CLI not found, using agent defaults");
38
- return agent;
39
- }
40
-
41
- // ---------------------------------------------------------------------------
42
- // Main
43
- // ---------------------------------------------------------------------------
44
-
45
- const HOOK = "plan-questions";
46
-
47
- /**
48
- * Run the plan-questions agent to generate questions about a plan.
49
- * Returns structured questions/assumptions/ambiguities, or null on failure.
50
- *
51
- * The agent runs in a fresh context (no codebase, no session history)
52
- * and uses QUESTIONS_SCHEMA instead of REVIEW_SCHEMA — the agent runner
53
- * is schema-agnostic.
54
- */
55
- export async function runPlanQuestions(
56
- plan: string,
57
- aiwcliDir: string,
58
- timeout: number,
59
- contextPath?: string,
60
- sessionName?: string,
61
- ): Promise<PlanQuestionsResult | null> {
62
- // Load the plan-questions agent from agents/plan-questions/
63
- const questionsAgentDir = path.join(aiwcliDir, "_cc-native", "agents", "plan-questions");
64
- const agents = aggregateAgents(questionsAgentDir);
65
-
66
- if (agents.length === 0) {
67
- logWarn(HOOK, `No agents found in ${questionsAgentDir}`);
68
- return null;
69
- }
70
-
71
- // Use the first agent (PLAN-QUESTIONER)
72
- let agent = agents[0]!;
73
- logInfo(HOOK, `Using plan-questions agent: ${agent.name}`);
74
-
75
- // Assign provider
76
- agent = assignProvider(agent);
77
-
78
- // Run the agent with QUESTIONS_SCHEMA
79
- const result = await runAgentReview(
80
- plan,
81
- agent,
82
- QUESTIONS_SCHEMA,
83
- timeout,
84
- contextPath,
85
- sessionName ?? "unknown",
86
- );
87
-
88
- if (!result.ok) {
89
- logError(HOOK, `Plan-questions agent failed: ${result.err}`);
90
- return null;
91
- }
92
-
93
- // Extract structured data
94
- const data = result.data ?? {};
95
- const questions = Array.isArray(data.questions) ? (data.questions as string[]) : [];
96
- const assumptions = Array.isArray(data.assumptions) ? (data.assumptions as string[]) : [];
97
- const ambiguities = Array.isArray(data.ambiguities) ? (data.ambiguities as string[]) : [];
98
-
99
- logInfo(HOOK, `Plan-questions result: ${questions.length} questions, ${assumptions.length} assumptions, ${ambiguities.length} ambiguities`);
100
-
101
- return { questions, assumptions, ambiguities };
102
- }
1
+ /**
2
+ * Plan question generation — runs a fresh-context agent to identify
3
+ * questions, assumptions, and ambiguities in a plan before review.
4
+ * See cc-native-plan-review.ts for integration point (questions gate).
5
+ */
6
+
7
+ import * as path from "node:path";
8
+
9
+ import { runAgentReview } from "./reviewers/index.js";
10
+ import { QUESTIONS_SCHEMA } from "./reviewers/schemas.js";
11
+ import { logInfo, logWarn, logError } from "../../../_shared/lib-ts/base/logger.js";
12
+ import { findExecutable } from "../../../_shared/lib-ts/base/subprocess-utils.js";
13
+ import { aggregateAgents } from "../../lib-ts/aggregate-agents.js";
14
+ import type { AgentConfig } from "../../lib-ts/types.js";
15
+
16
+ // ---------------------------------------------------------------------------
17
+ // Types
18
+ // ---------------------------------------------------------------------------
19
+
20
+ export interface PlanQuestionsResult {
21
+ questions: string[];
22
+ assumptions: string[];
23
+ ambiguities: string[];
24
+ }
25
+
26
+ // ---------------------------------------------------------------------------
27
+ // Provider assignment (local copy — avoids circular import from hook)
28
+ // ---------------------------------------------------------------------------
29
+
30
+ function assignProvider(agent: AgentConfig): AgentConfig {
31
+ // Default to claude provider with the agent's configured model
32
+ const found = findExecutable("claude");
33
+ if (found) {
34
+ return { ...agent, provider: "claude" };
35
+ }
36
+ logWarn("plan-questions", "Claude CLI not found, using agent defaults");
37
+ return agent;
38
+ }
39
+
40
+ // ---------------------------------------------------------------------------
41
+ // Main
42
+ // ---------------------------------------------------------------------------
43
+
44
+ const HOOK = "plan-questions";
45
+
46
+ /**
47
+ * Run the plan-questions agent to generate questions about a plan.
48
+ * Returns structured questions/assumptions/ambiguities, or null on failure.
49
+ *
50
+ * The agent runs in a fresh context (no codebase, no session history)
51
+ * and uses QUESTIONS_SCHEMA instead of REVIEW_SCHEMA the agent runner
52
+ * is schema-agnostic.
53
+ */
54
+ export async function runPlanQuestions(
55
+ plan: string,
56
+ aiwcliDir: string,
57
+ timeout: number,
58
+ contextPath?: string,
59
+ sessionName?: string,
60
+ ): Promise<PlanQuestionsResult | null> {
61
+ // Load the plan-questions agent from agents/plan-questions/
62
+ const questionsAgentDir = path.join(aiwcliDir, "_cc-native", "plan-review", "agents", "plan-questions");
63
+ const agents = aggregateAgents(questionsAgentDir);
64
+
65
+ if (agents.length === 0) {
66
+ logWarn(HOOK, `No agents found in ${questionsAgentDir}`);
67
+ return null;
68
+ }
69
+
70
+ // Use the first agent (PLAN-QUESTIONER)
71
+ let agent = agents[0]!;
72
+ logInfo(HOOK, `Using plan-questions agent: ${agent.name}`);
73
+
74
+ // Assign provider
75
+ agent = assignProvider(agent);
76
+
77
+ // Run the agent with QUESTIONS_SCHEMA
78
+ const result = await runAgentReview(
79
+ plan,
80
+ agent,
81
+ QUESTIONS_SCHEMA,
82
+ timeout,
83
+ contextPath,
84
+ sessionName ?? "unknown",
85
+ );
86
+
87
+ if (!result.ok) {
88
+ logError(HOOK, `Plan-questions agent failed: ${result.err}`);
89
+ return null;
90
+ }
91
+
92
+ // Extract structured data
93
+ const data = result.data ?? {};
94
+ const questions = Array.isArray(data.questions) ? (data.questions as string[]) : [];
95
+ const assumptions = Array.isArray(data.assumptions) ? (data.assumptions as string[]) : [];
96
+ const ambiguities = Array.isArray(data.ambiguities) ? (data.ambiguities as string[]) : [];
97
+
98
+ logInfo(HOOK, `Plan-questions result: ${questions.length} questions, ${assumptions.length} assumptions, ${ambiguities.length} ambiguities`);
99
+
100
+ return { questions, assumptions, ambiguities };
101
+ }