aiwcli 0.12.7 → 0.12.8
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/dist/templates/CLAUDE.md +27 -0
- package/dist/templates/_shared/.claude/{commands/handoff.md → skills/handoff/SKILL.md} +3 -2
- package/dist/templates/_shared/.claude/{commands/handoff-resume.md → skills/handoff-resume/SKILL.md} +2 -1
- package/dist/templates/_shared/handoff-system/CLAUDE.md +433 -421
- package/dist/templates/_shared/lib-ts/CLAUDE.md +3 -3
- package/dist/templates/_shared/lib-ts/base/constants.ts +324 -306
- package/dist/templates/_shared/lib-ts/base/inference.ts +3 -3
- package/dist/templates/_shared/lib-ts/context/CLAUDE.md +134 -0
- package/dist/templates/_shared/scripts/status_line.ts +26 -29
- package/dist/templates/cc-native/.claude/commands/cc-native/specdev.md +1 -1
- package/dist/templates/cc-native/.claude/settings.json +3 -2
- package/dist/templates/cc-native/_cc-native/artifacts/CLAUDE.md +64 -0
- package/dist/templates/cc-native/_cc-native/{lib-ts/artifacts → artifacts/lib}/format.ts +597 -597
- package/dist/templates/cc-native/_cc-native/{lib-ts/artifacts → artifacts/lib}/index.ts +26 -26
- package/dist/templates/cc-native/_cc-native/{lib-ts/artifacts → artifacts/lib}/tracker.ts +107 -107
- package/dist/templates/cc-native/_cc-native/{lib-ts/artifacts → artifacts/lib}/write.ts +119 -119
- package/dist/templates/cc-native/_cc-native/hooks/CLAUDE.md +237 -247
- package/dist/templates/cc-native/_cc-native/hooks/cc-native-plan-review.ts +76 -76
- package/dist/templates/cc-native/_cc-native/hooks/validate_task_prompt.ts +76 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/aggregate-agents.ts +163 -156
- package/dist/templates/cc-native/_cc-native/lib-ts/index.ts +116 -116
- package/dist/templates/cc-native/_cc-native/lib-ts/settings.ts +1 -1
- package/dist/templates/cc-native/_cc-native/lib-ts/types.ts +329 -329
- package/dist/templates/cc-native/_cc-native/plan-review/CLAUDE.md +149 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/CLAUDE.md +143 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/PLAN-ORCHESTRATOR.md +213 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-questions/PLAN-QUESTIONER.md +70 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/ARCH-EVOLUTION.md +62 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/ARCH-PATTERNS.md +61 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/ARCH-STRUCTURE.md +62 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/ASSUMPTION-TRACER.md +56 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/CLARITY-AUDITOR.md +53 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/COMPLETENESS-FEASIBILITY.md +66 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/COMPLETENESS-GAPS.md +70 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/COMPLETENESS-ORDERING.md +62 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/CONSTRAINT-VALIDATOR.md +72 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/DESIGN-ADR-VALIDATOR.md +61 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/DESIGN-SCALE-MATCHER.md +64 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/DEVILS-ADVOCATE.md +56 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/DOCUMENTATION-PHILOSOPHY.md +86 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/HANDOFF-READINESS.md +59 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/HIDDEN-COMPLEXITY.md +58 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/INCREMENTAL-DELIVERY.md +66 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/RISK-DEPENDENCY.md +62 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/RISK-FMEA.md +66 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/RISK-PREMORTEM.md +71 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/RISK-REVERSIBILITY.md +74 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/SCOPE-BOUNDARY.md +77 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/SIMPLICITY-GUARDIAN.md +62 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/SKEPTIC.md +68 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/TESTDRIVEN-BEHAVIOR-AUDITOR.md +61 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/TESTDRIVEN-CHARACTERIZATION.md +71 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/TESTDRIVEN-FIRST-VALIDATOR.md +61 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/TESTDRIVEN-PYRAMID-ANALYZER.md +61 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/TRADEOFF-COSTS.md +67 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/TRADEOFF-STAKEHOLDERS.md +65 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/VERIFY-COVERAGE.md +74 -0
- package/dist/templates/cc-native/_cc-native/plan-review/agents/plan-review/VERIFY-STRENGTH.md +69 -0
- package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/agent-selection.ts +163 -163
- package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/corroboration.ts +119 -119
- package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/graduation.ts +132 -132
- package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/orchestrator.ts +70 -70
- package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/output-builder.ts +130 -130
- package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/plan-questions.ts +102 -102
- package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/review-pipeline.ts +511 -511
- package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/reviewers/agent.ts +74 -74
- package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/reviewers/base/base-agent.ts +217 -217
- package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/reviewers/index.ts +12 -12
- package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/reviewers/providers/claude-agent.ts +66 -66
- package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/reviewers/providers/codex-agent.ts +185 -185
- package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/reviewers/providers/gemini-agent.ts +39 -39
- package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/reviewers/providers/orchestrator-claude-agent.ts +196 -196
- package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/reviewers/schemas.ts +201 -201
- package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/reviewers/types.ts +23 -23
- package/dist/templates/cc-native/_cc-native/{lib-ts → plan-review/lib}/verdict.ts +72 -72
- package/dist/templates/cc-native/_cc-native/{workflows → plan-review/workflows}/specdev.md +9 -9
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/dist/templates/cc-native/_cc-native/lib-ts/artifacts.ts +0 -21
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: verify-coverage
|
|
3
|
+
description: Test coverage mapper who ensures every implementation step has a corresponding verification step. Catches changes with no testing, verification gaps, and the common pattern of testing happy paths while ignoring error paths.
|
|
4
|
+
model: sonnet
|
|
5
|
+
focus: verification coverage mapping
|
|
6
|
+
categories:
|
|
7
|
+
- code
|
|
8
|
+
- infrastructure
|
|
9
|
+
- documentation
|
|
10
|
+
- design
|
|
11
|
+
- research
|
|
12
|
+
- life
|
|
13
|
+
- business
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# Verify Coverage - Plan Review Agent
|
|
17
|
+
|
|
18
|
+
You map implementation steps to verification steps. Your question: "Is every change covered by a verification step?"
|
|
19
|
+
|
|
20
|
+
## Your Core Principle
|
|
21
|
+
|
|
22
|
+
A plan without adequate verification is a plan that assumes success. The most dangerous gap is not a missing feature — it is a missing test. Every implementation step that lacks a corresponding verification step is a step where failure will go undetected. Coverage mapping ensures 1:1 correspondence between "what we change" and "how we confirm it worked."
|
|
23
|
+
|
|
24
|
+
## Your Expertise
|
|
25
|
+
|
|
26
|
+
- **Coverage gap detection**: Implementation steps with no corresponding verification
|
|
27
|
+
- **Happy path bias**: Verification that only tests the success case, ignoring error and edge cases
|
|
28
|
+
- **Verification specificity**: Are verification steps concrete enough to execute without interpretation?
|
|
29
|
+
- **Regression awareness**: Do verification steps confirm existing functionality still works after the change?
|
|
30
|
+
- **Coverage completeness**: Does the verification plan cover all dimensions of the change (functionality, performance, security)?
|
|
31
|
+
|
|
32
|
+
## Review Approach
|
|
33
|
+
|
|
34
|
+
Build a coverage map between implementation and verification:
|
|
35
|
+
|
|
36
|
+
1. **List all implementation steps**: Every change the plan makes
|
|
37
|
+
2. **List all verification steps**: Every check the plan includes
|
|
38
|
+
3. **Map 1:1**: For each implementation step, identify its verification step(s)
|
|
39
|
+
4. **Find gaps**: Implementation steps with no verification
|
|
40
|
+
5. **Assess coverage quality**: Do verification steps test the right things?
|
|
41
|
+
|
|
42
|
+
## Verification Coverage Levels
|
|
43
|
+
|
|
44
|
+
| Level | Description | Example |
|
|
45
|
+
|-------|-------------|---------|
|
|
46
|
+
| **Full** | Every change verified with specific criteria | "Run `pytest test_auth.py -k test_token_expiry` — 3 tests pass" |
|
|
47
|
+
| **Partial** | Some changes verified, others assumed | "Run the auth tests" (misses schema change verification) |
|
|
48
|
+
| **Minimal** | Only overall functionality checked | "Verify it works" |
|
|
49
|
+
| **None** | Implementation step has no verification | Change with no corresponding check |
|
|
50
|
+
|
|
51
|
+
## Key Distinction
|
|
52
|
+
|
|
53
|
+
| Agent | Asks |
|
|
54
|
+
|-------|------|
|
|
55
|
+
| verify-strength | "Would these tests catch a subtle bug?" |
|
|
56
|
+
| **verify-coverage** | **"Is every change covered by a verification step?"** |
|
|
57
|
+
|
|
58
|
+
## CRITICAL: Single-Turn Review
|
|
59
|
+
|
|
60
|
+
When reviewing a plan:
|
|
61
|
+
1. Analyze the plan content provided directly (do not use Read, Glob, Grep, or any file tools)
|
|
62
|
+
2. Call StructuredOutput immediately with your assessment
|
|
63
|
+
3. Complete your entire review in one response
|
|
64
|
+
|
|
65
|
+
Avoid querying external systems, reading codebase files, requesting additional information, or asking follow-up questions.
|
|
66
|
+
|
|
67
|
+
## Required Output
|
|
68
|
+
|
|
69
|
+
Call StructuredOutput with exactly these fields:
|
|
70
|
+
- **verdict**: "pass" (verification covers all changes), "warn" (some gaps in verification coverage), or "fail" (critical changes without verification)
|
|
71
|
+
- **summary**: 2-3 sentences explaining verification coverage assessment (minimum 20 characters)
|
|
72
|
+
- **issues**: Array of coverage concerns, each with: severity (high/medium/low), category (e.g., "missing-verification", "happy-path-only", "weak-verification", "no-regression-check"), issue description, suggested_fix (specific verification step to add)
|
|
73
|
+
- **missing_sections**: Verification gaps the plan should address (untested changes, missing edge cases, absent regression checks)
|
|
74
|
+
- **questions**: Verification aspects that need clarification
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: verify-strength
|
|
3
|
+
description: Test quality analyst who evaluates whether verification steps would catch subtle bugs, not just total failures. Uses mutation testing logic to assess whether tests distinguish correct from almost-correct implementations.
|
|
4
|
+
model: sonnet
|
|
5
|
+
focus: test quality and mutation analysis
|
|
6
|
+
categories:
|
|
7
|
+
- code
|
|
8
|
+
- infrastructure
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Verify Strength - Plan Review Agent
|
|
12
|
+
|
|
13
|
+
You evaluate the quality of verification steps. Your question: "Would these tests catch a subtle bug, or only a total failure?"
|
|
14
|
+
|
|
15
|
+
## Your Core Principle
|
|
16
|
+
|
|
17
|
+
Mutation testing (DeMillo et al. 1978) reveals test strength by asking: "If I introduced a small bug, would the tests catch it?" Weak tests pass on both correct and incorrect implementations. Strong tests fail when the implementation is wrong in any way. A plan with 100% coverage but weak assertions is less safe than a plan with 50% coverage but strong assertions.
|
|
18
|
+
|
|
19
|
+
## Your Expertise
|
|
20
|
+
|
|
21
|
+
- **Assertion strength evaluation**: Do verification steps check specific expected values, or just "no error"?
|
|
22
|
+
- **Mutation sensitivity**: Would a small change to the implementation (off-by-one, wrong variable, swapped condition) be caught?
|
|
23
|
+
- **Boundary testing**: Do tests exercise boundary conditions where bugs cluster?
|
|
24
|
+
- **Negative testing**: Do tests verify that invalid inputs are rejected, not just that valid inputs succeed?
|
|
25
|
+
- **State verification**: Do tests check the full resulting state, or just the return value?
|
|
26
|
+
|
|
27
|
+
## Review Approach
|
|
28
|
+
|
|
29
|
+
For each verification step in the plan, apply mutation logic:
|
|
30
|
+
|
|
31
|
+
1. **Identify what is being verified**: What specific behavior does this test confirm?
|
|
32
|
+
2. **Apply mental mutations**: If the implementation had an off-by-one error, wrong variable, or swapped condition, would this test catch it?
|
|
33
|
+
3. **Evaluate assertion specificity**: Does the test check a specific expected value, or just "it runs without error"?
|
|
34
|
+
4. **Check boundary coverage**: Are edge cases and boundary values tested?
|
|
35
|
+
5. **Assess negative testing**: Are failure cases and invalid inputs covered?
|
|
36
|
+
|
|
37
|
+
## Test Strength Levels
|
|
38
|
+
|
|
39
|
+
| Level | Test Behavior | Example |
|
|
40
|
+
|-------|---------------|---------|
|
|
41
|
+
| **Strong** | Fails on any mutation to the implementation | Checks specific values, boundaries, and error cases |
|
|
42
|
+
| **Moderate** | Catches major bugs but misses subtle ones | Checks return type and approximate value |
|
|
43
|
+
| **Weak** | Only catches total failure | "Assert no error" or "assert result is not null" |
|
|
44
|
+
| **Absent** | No verification at all | Implementation change with no test |
|
|
45
|
+
|
|
46
|
+
## Key Distinction
|
|
47
|
+
|
|
48
|
+
| Agent | Asks |
|
|
49
|
+
|-------|------|
|
|
50
|
+
| verify-coverage | "Is every change covered by a verification step?" |
|
|
51
|
+
| **verify-strength** | **"Would these tests catch a subtle bug?"** |
|
|
52
|
+
|
|
53
|
+
## CRITICAL: Single-Turn Review
|
|
54
|
+
|
|
55
|
+
When reviewing a plan:
|
|
56
|
+
1. Analyze the plan content provided directly (do not use Read, Glob, Grep, or any file tools)
|
|
57
|
+
2. Call StructuredOutput immediately with your assessment
|
|
58
|
+
3. Complete your entire review in one response
|
|
59
|
+
|
|
60
|
+
Avoid querying external systems, reading codebase files, requesting additional information, or asking follow-up questions.
|
|
61
|
+
|
|
62
|
+
## Required Output
|
|
63
|
+
|
|
64
|
+
Call StructuredOutput with exactly these fields:
|
|
65
|
+
- **verdict**: "pass" (tests would catch subtle bugs), "warn" (some weak assertions), or "fail" (tests would miss common bug patterns)
|
|
66
|
+
- **summary**: 2-3 sentences explaining test strength assessment (minimum 20 characters)
|
|
67
|
+
- **issues**: Array of strength concerns, each with: severity (high/medium/low), category (e.g., "weak-assertion", "no-boundary-test", "missing-negative-test", "mutation-survivor", "state-unchecked"), issue description, suggested_fix (strengthen specific assertion or add test case)
|
|
68
|
+
- **missing_sections**: Test strength improvements the plan should address (boundary tests, negative tests, specific assertions)
|
|
69
|
+
- **questions**: Test quality aspects that need clarification
|
|
@@ -1,163 +1,163 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent selection: mandatory resolution, orchestrator-based selection, model assignment.
|
|
3
|
-
* Extracted from cc-native-plan-review.ts.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { logDebug, logInfo, logWarn } from "
|
|
7
|
-
import { findExecutable } from "
|
|
8
|
-
|
|
9
|
-
import type {
|
|
10
|
-
AgentConfig,
|
|
11
|
-
ModelsConfig,
|
|
12
|
-
OrchestratorResult,
|
|
13
|
-
AgentSelectionResult,
|
|
14
|
-
} from "
|
|
15
|
-
|
|
16
|
-
const HOOK = "agent-selection";
|
|
17
|
-
|
|
18
|
-
// ---------------------------------------------------------------------------
|
|
19
|
-
// Mandatory Agent Resolution
|
|
20
|
-
// ---------------------------------------------------------------------------
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Resolve mandatory agent names from config. Supports flat arrays or
|
|
24
|
-
* complexity-tiered objects with `always`, `medium+`, and `high` keys.
|
|
25
|
-
*/
|
|
26
|
-
export function resolveMandatoryAgents(
|
|
27
|
-
configValue: unknown,
|
|
28
|
-
complexity: string,
|
|
29
|
-
): Set<string> {
|
|
30
|
-
if (Array.isArray(configValue)) {
|
|
31
|
-
return new Set(configValue as string[]);
|
|
32
|
-
}
|
|
33
|
-
if (!configValue || typeof configValue !== "object") {
|
|
34
|
-
return new Set(["handoff-readiness", "clarity-auditor", "skeptic"]);
|
|
35
|
-
}
|
|
36
|
-
const cfg = configValue as Record<string, string[]>;
|
|
37
|
-
const names = new Set(cfg.always ?? []);
|
|
38
|
-
if (complexity === "medium" || complexity === "high") {
|
|
39
|
-
for (const n of cfg["medium+"] ?? []) names.add(n);
|
|
40
|
-
}
|
|
41
|
-
if (complexity === "high") {
|
|
42
|
-
for (const n of cfg.high ?? []) names.add(n);
|
|
43
|
-
}
|
|
44
|
-
return names;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// ---------------------------------------------------------------------------
|
|
48
|
-
// Model Assignment
|
|
49
|
-
// ---------------------------------------------------------------------------
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Randomly assign enabled providers and models to agents.
|
|
53
|
-
* Filters to providers whose CLI is available on PATH.
|
|
54
|
-
*/
|
|
55
|
-
export function assignModelsToAgents(
|
|
56
|
-
agents: AgentConfig[],
|
|
57
|
-
modelsConfig: ModelsConfig,
|
|
58
|
-
): AgentConfig[] {
|
|
59
|
-
const enabledProviders = Object.entries(modelsConfig.providers)
|
|
60
|
-
.filter(([name, config]) => {
|
|
61
|
-
if (!config.enabled || config.models.length === 0) return false;
|
|
62
|
-
const cliName = name === "claude" ? "claude" : name;
|
|
63
|
-
const found = findExecutable(cliName);
|
|
64
|
-
if (!found) {
|
|
65
|
-
logWarn(HOOK, `Provider '${name}' enabled but CLI '${cliName}' not found on PATH — skipping`);
|
|
66
|
-
}
|
|
67
|
-
return !!found;
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
if (enabledProviders.length === 0) {
|
|
71
|
-
logWarn(HOOK, "No providers with available CLI found, falling back to Claude with agent defaults");
|
|
72
|
-
return agents.map(a => ({ ...a, provider: "claude" }));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return agents.map(agent => {
|
|
76
|
-
const idx = Math.floor(Math.random() * enabledProviders.length);
|
|
77
|
-
const entry = enabledProviders[idx];
|
|
78
|
-
if (!entry) return { ...agent, provider: "claude" };
|
|
79
|
-
const [providerName, providerConfig] = entry;
|
|
80
|
-
const modelIdx = Math.floor(Math.random() * providerConfig.models.length);
|
|
81
|
-
const model = providerConfig.models[modelIdx] ?? providerConfig.models[0] ?? agent.model;
|
|
82
|
-
return { ...agent, provider: providerName, model };
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// ---------------------------------------------------------------------------
|
|
87
|
-
// Agent Selection
|
|
88
|
-
// ---------------------------------------------------------------------------
|
|
89
|
-
|
|
90
|
-
export interface AgentSelectionInput {
|
|
91
|
-
enabledAgents: AgentConfig[];
|
|
92
|
-
orchResult: OrchestratorResult | null;
|
|
93
|
-
mandatoryConfig: unknown;
|
|
94
|
-
agentSettings: Record<string, unknown>;
|
|
95
|
-
legacyMode: boolean;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Select agents based on orchestrator result and mandatory config.
|
|
100
|
-
*/
|
|
101
|
-
export function selectAgents(input: AgentSelectionInput): AgentSelectionResult {
|
|
102
|
-
const { enabledAgents, orchResult, mandatoryConfig, agentSettings, legacyMode } = input;
|
|
103
|
-
|
|
104
|
-
let detectedComplexity = "medium";
|
|
105
|
-
let mandatoryNames = resolveMandatoryAgents(mandatoryConfig, "simple");
|
|
106
|
-
|
|
107
|
-
if (enabledAgents.length === 0) {
|
|
108
|
-
return { selectedAgents: [], mandatoryNames, detectedComplexity };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
let mandatoryAgents = enabledAgents.filter(a => mandatoryNames.has(a.name));
|
|
112
|
-
let nonMandatory = enabledAgents.filter(a => !mandatoryNames.has(a.name));
|
|
113
|
-
|
|
114
|
-
logDebug(HOOK, `Mandatory agents: ${mandatoryAgents.map(a => a.name)}`);
|
|
115
|
-
logDebug(HOOK, `Non-mandatory pool: ${nonMandatory.length} agents`);
|
|
116
|
-
|
|
117
|
-
if (orchResult && !legacyMode) {
|
|
118
|
-
detectedComplexity = orchResult.complexity;
|
|
119
|
-
|
|
120
|
-
// Recompute mandatory with actual complexity
|
|
121
|
-
mandatoryNames = resolveMandatoryAgents(mandatoryConfig, detectedComplexity);
|
|
122
|
-
mandatoryAgents = enabledAgents.filter(a => mandatoryNames.has(a.name));
|
|
123
|
-
nonMandatory = enabledAgents.filter(a => !mandatoryNames.has(a.name));
|
|
124
|
-
|
|
125
|
-
const orchSelectedNames = new Set(
|
|
126
|
-
orchResult.selected_agents.filter(n => !mandatoryNames.has(n)),
|
|
127
|
-
);
|
|
128
|
-
let orchSelected = nonMandatory.filter(a => orchSelectedNames.has(a.name));
|
|
129
|
-
|
|
130
|
-
logDebug(HOOK, `Orchestrator selected (non-mandatory): ${orchSelected.map(a => a.name)}`);
|
|
131
|
-
|
|
132
|
-
// Warn if orchestrator returned unknown names
|
|
133
|
-
const knownNames = new Set(nonMandatory.map(a => a.name));
|
|
134
|
-
const unmatched = [...orchSelectedNames].filter(n => !knownNames.has(n));
|
|
135
|
-
if (unmatched.length > 0) {
|
|
136
|
-
logWarn(HOOK, `Orchestrator selected unknown agents: ${unmatched}`);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Enforce minimum agent count
|
|
140
|
-
const fallbackByComplexity = agentSettings.fallbackByComplexity ?? { simple: 0, medium: 2, high: 4 };
|
|
141
|
-
const minAdditional = fallbackByComplexity[detectedComplexity] ?? 5;
|
|
142
|
-
if (orchSelected.length < minAdditional && nonMandatory.length > 0) {
|
|
143
|
-
const remaining = nonMandatory.filter(a => !orchSelected.includes(a));
|
|
144
|
-
const topUpCount = Math.min(minAdditional - orchSelected.length, remaining.length);
|
|
145
|
-
if (topUpCount > 0) {
|
|
146
|
-
const shuffled = [...remaining].sort(() => Math.random() - 0.5);
|
|
147
|
-
const topUp = shuffled.slice(0, topUpCount);
|
|
148
|
-
orchSelected = [...orchSelected, ...topUp];
|
|
149
|
-
logDebug(HOOK, `Topped up ${topUpCount} agents to meet ${detectedComplexity} minimum: ${topUp.map(a => a.name)}`);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const selectedAgents = [...mandatoryAgents, ...orchSelected];
|
|
154
|
-
logInfo(HOOK, `Final selection: ${selectedAgents.length} agents (${mandatoryAgents.length} mandatory + ${orchSelected.length} additional)`);
|
|
155
|
-
return { selectedAgents, mandatoryNames, detectedComplexity };
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Legacy mode: all enabled agents
|
|
159
|
-
logInfo(HOOK, "Running in legacy mode (all enabled agents)");
|
|
160
|
-
detectedComplexity = "medium";
|
|
161
|
-
mandatoryNames = resolveMandatoryAgents(mandatoryConfig, detectedComplexity);
|
|
162
|
-
return { selectedAgents: enabledAgents, mandatoryNames, detectedComplexity };
|
|
163
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Agent selection: mandatory resolution, orchestrator-based selection, model assignment.
|
|
3
|
+
* Extracted from cc-native-plan-review.ts.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { logDebug, logInfo, logWarn } from "../../../_shared/lib-ts/base/logger.js";
|
|
7
|
+
import { findExecutable } from "../../../_shared/lib-ts/base/subprocess-utils.js";
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
AgentConfig,
|
|
11
|
+
ModelsConfig,
|
|
12
|
+
OrchestratorResult,
|
|
13
|
+
AgentSelectionResult,
|
|
14
|
+
} from "../../lib-ts/types.js";
|
|
15
|
+
|
|
16
|
+
const HOOK = "agent-selection";
|
|
17
|
+
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
// Mandatory Agent Resolution
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Resolve mandatory agent names from config. Supports flat arrays or
|
|
24
|
+
* complexity-tiered objects with `always`, `medium+`, and `high` keys.
|
|
25
|
+
*/
|
|
26
|
+
export function resolveMandatoryAgents(
|
|
27
|
+
configValue: unknown,
|
|
28
|
+
complexity: string,
|
|
29
|
+
): Set<string> {
|
|
30
|
+
if (Array.isArray(configValue)) {
|
|
31
|
+
return new Set(configValue as string[]);
|
|
32
|
+
}
|
|
33
|
+
if (!configValue || typeof configValue !== "object") {
|
|
34
|
+
return new Set(["handoff-readiness", "clarity-auditor", "skeptic"]);
|
|
35
|
+
}
|
|
36
|
+
const cfg = configValue as Record<string, string[]>;
|
|
37
|
+
const names = new Set(cfg.always ?? []);
|
|
38
|
+
if (complexity === "medium" || complexity === "high") {
|
|
39
|
+
for (const n of cfg["medium+"] ?? []) names.add(n);
|
|
40
|
+
}
|
|
41
|
+
if (complexity === "high") {
|
|
42
|
+
for (const n of cfg.high ?? []) names.add(n);
|
|
43
|
+
}
|
|
44
|
+
return names;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// Model Assignment
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Randomly assign enabled providers and models to agents.
|
|
53
|
+
* Filters to providers whose CLI is available on PATH.
|
|
54
|
+
*/
|
|
55
|
+
export function assignModelsToAgents(
|
|
56
|
+
agents: AgentConfig[],
|
|
57
|
+
modelsConfig: ModelsConfig,
|
|
58
|
+
): AgentConfig[] {
|
|
59
|
+
const enabledProviders = Object.entries(modelsConfig.providers)
|
|
60
|
+
.filter(([name, config]) => {
|
|
61
|
+
if (!config.enabled || config.models.length === 0) return false;
|
|
62
|
+
const cliName = name === "claude" ? "claude" : name;
|
|
63
|
+
const found = findExecutable(cliName);
|
|
64
|
+
if (!found) {
|
|
65
|
+
logWarn(HOOK, `Provider '${name}' enabled but CLI '${cliName}' not found on PATH — skipping`);
|
|
66
|
+
}
|
|
67
|
+
return !!found;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (enabledProviders.length === 0) {
|
|
71
|
+
logWarn(HOOK, "No providers with available CLI found, falling back to Claude with agent defaults");
|
|
72
|
+
return agents.map(a => ({ ...a, provider: "claude" }));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return agents.map(agent => {
|
|
76
|
+
const idx = Math.floor(Math.random() * enabledProviders.length);
|
|
77
|
+
const entry = enabledProviders[idx];
|
|
78
|
+
if (!entry) return { ...agent, provider: "claude" };
|
|
79
|
+
const [providerName, providerConfig] = entry;
|
|
80
|
+
const modelIdx = Math.floor(Math.random() * providerConfig.models.length);
|
|
81
|
+
const model = providerConfig.models[modelIdx] ?? providerConfig.models[0] ?? agent.model;
|
|
82
|
+
return { ...agent, provider: providerName, model };
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
// Agent Selection
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
|
|
90
|
+
export interface AgentSelectionInput {
|
|
91
|
+
enabledAgents: AgentConfig[];
|
|
92
|
+
orchResult: OrchestratorResult | null;
|
|
93
|
+
mandatoryConfig: unknown;
|
|
94
|
+
agentSettings: Record<string, unknown>;
|
|
95
|
+
legacyMode: boolean;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Select agents based on orchestrator result and mandatory config.
|
|
100
|
+
*/
|
|
101
|
+
export function selectAgents(input: AgentSelectionInput): AgentSelectionResult {
|
|
102
|
+
const { enabledAgents, orchResult, mandatoryConfig, agentSettings, legacyMode } = input;
|
|
103
|
+
|
|
104
|
+
let detectedComplexity = "medium";
|
|
105
|
+
let mandatoryNames = resolveMandatoryAgents(mandatoryConfig, "simple");
|
|
106
|
+
|
|
107
|
+
if (enabledAgents.length === 0) {
|
|
108
|
+
return { selectedAgents: [], mandatoryNames, detectedComplexity };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let mandatoryAgents = enabledAgents.filter(a => mandatoryNames.has(a.name));
|
|
112
|
+
let nonMandatory = enabledAgents.filter(a => !mandatoryNames.has(a.name));
|
|
113
|
+
|
|
114
|
+
logDebug(HOOK, `Mandatory agents: ${mandatoryAgents.map(a => a.name)}`);
|
|
115
|
+
logDebug(HOOK, `Non-mandatory pool: ${nonMandatory.length} agents`);
|
|
116
|
+
|
|
117
|
+
if (orchResult && !legacyMode) {
|
|
118
|
+
detectedComplexity = orchResult.complexity;
|
|
119
|
+
|
|
120
|
+
// Recompute mandatory with actual complexity
|
|
121
|
+
mandatoryNames = resolveMandatoryAgents(mandatoryConfig, detectedComplexity);
|
|
122
|
+
mandatoryAgents = enabledAgents.filter(a => mandatoryNames.has(a.name));
|
|
123
|
+
nonMandatory = enabledAgents.filter(a => !mandatoryNames.has(a.name));
|
|
124
|
+
|
|
125
|
+
const orchSelectedNames = new Set(
|
|
126
|
+
orchResult.selected_agents.filter(n => !mandatoryNames.has(n)),
|
|
127
|
+
);
|
|
128
|
+
let orchSelected = nonMandatory.filter(a => orchSelectedNames.has(a.name));
|
|
129
|
+
|
|
130
|
+
logDebug(HOOK, `Orchestrator selected (non-mandatory): ${orchSelected.map(a => a.name)}`);
|
|
131
|
+
|
|
132
|
+
// Warn if orchestrator returned unknown names
|
|
133
|
+
const knownNames = new Set(nonMandatory.map(a => a.name));
|
|
134
|
+
const unmatched = [...orchSelectedNames].filter(n => !knownNames.has(n));
|
|
135
|
+
if (unmatched.length > 0) {
|
|
136
|
+
logWarn(HOOK, `Orchestrator selected unknown agents: ${unmatched}`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Enforce minimum agent count
|
|
140
|
+
const fallbackByComplexity = agentSettings.fallbackByComplexity ?? { simple: 0, medium: 2, high: 4 };
|
|
141
|
+
const minAdditional = fallbackByComplexity[detectedComplexity] ?? 5;
|
|
142
|
+
if (orchSelected.length < minAdditional && nonMandatory.length > 0) {
|
|
143
|
+
const remaining = nonMandatory.filter(a => !orchSelected.includes(a));
|
|
144
|
+
const topUpCount = Math.min(minAdditional - orchSelected.length, remaining.length);
|
|
145
|
+
if (topUpCount > 0) {
|
|
146
|
+
const shuffled = [...remaining].sort(() => Math.random() - 0.5);
|
|
147
|
+
const topUp = shuffled.slice(0, topUpCount);
|
|
148
|
+
orchSelected = [...orchSelected, ...topUp];
|
|
149
|
+
logDebug(HOOK, `Topped up ${topUpCount} agents to meet ${detectedComplexity} minimum: ${topUp.map(a => a.name)}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const selectedAgents = [...mandatoryAgents, ...orchSelected];
|
|
154
|
+
logInfo(HOOK, `Final selection: ${selectedAgents.length} agents (${mandatoryAgents.length} mandatory + ${orchSelected.length} additional)`);
|
|
155
|
+
return { selectedAgents, mandatoryNames, detectedComplexity };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Legacy mode: all enabled agents
|
|
159
|
+
logInfo(HOOK, "Running in legacy mode (all enabled agents)");
|
|
160
|
+
detectedComplexity = "medium";
|
|
161
|
+
mandatoryNames = resolveMandatoryAgents(mandatoryConfig, detectedComplexity);
|
|
162
|
+
return { selectedAgents: enabledAgents, mandatoryNames, detectedComplexity };
|
|
163
|
+
}
|