claude-cli-advanced-starter-pack 1.1.0 → 1.8.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.
Files changed (56) hide show
  1. package/OVERVIEW.md +5 -1
  2. package/README.md +241 -132
  3. package/bin/gtask.js +53 -0
  4. package/package.json +1 -1
  5. package/src/cli/menu.js +27 -0
  6. package/src/commands/explore-mcp/mcp-registry.js +99 -0
  7. package/src/commands/init.js +339 -351
  8. package/src/commands/install-panel-hook.js +108 -0
  9. package/src/commands/install-scripts.js +232 -0
  10. package/src/commands/install-skill.js +220 -0
  11. package/src/commands/panel.js +297 -0
  12. package/src/commands/setup-wizard.js +4 -3
  13. package/src/commands/test-setup.js +4 -5
  14. package/src/data/releases.json +164 -0
  15. package/src/panel/queue.js +188 -0
  16. package/templates/commands/ask-claude.template.md +118 -0
  17. package/templates/commands/ccasp-panel.template.md +72 -0
  18. package/templates/commands/ccasp-setup.template.md +470 -79
  19. package/templates/commands/create-smoke-test.template.md +186 -0
  20. package/templates/commands/project-impl.template.md +9 -113
  21. package/templates/commands/refactor-check.template.md +112 -0
  22. package/templates/commands/refactor-cleanup.template.md +144 -0
  23. package/templates/commands/refactor-prep.template.md +192 -0
  24. package/templates/docs/AI_ARCHITECTURE_CONSTITUTION.template.md +198 -0
  25. package/templates/docs/DETAILED_GOTCHAS.template.md +347 -0
  26. package/templates/docs/PHASE-DEV-CHECKLIST.template.md +241 -0
  27. package/templates/docs/PROGRESS_JSON_TEMPLATE.json +117 -0
  28. package/templates/docs/background-agent.template.md +264 -0
  29. package/templates/hooks/autonomous-decision-logger.template.js +207 -0
  30. package/templates/hooks/branch-merge-checker.template.js +272 -0
  31. package/templates/hooks/git-commit-tracker.template.js +267 -0
  32. package/templates/hooks/issue-completion-detector.template.js +205 -0
  33. package/templates/hooks/panel-queue-reader.template.js +83 -0
  34. package/templates/hooks/phase-validation-gates.template.js +307 -0
  35. package/templates/hooks/session-id-generator.template.js +236 -0
  36. package/templates/hooks/token-usage-monitor.template.js +193 -0
  37. package/templates/patterns/README.md +129 -0
  38. package/templates/patterns/l1-l2-orchestration.md +189 -0
  39. package/templates/patterns/multi-phase-orchestration.md +258 -0
  40. package/templates/patterns/two-tier-query-pipeline.md +192 -0
  41. package/templates/scripts/README.md +109 -0
  42. package/templates/scripts/analyze-delegation-log.js +299 -0
  43. package/templates/scripts/autonomous-decision-logger.js +277 -0
  44. package/templates/scripts/git-history-analyzer.py +269 -0
  45. package/templates/scripts/phase-validation-gates.js +307 -0
  46. package/templates/scripts/poll-deployment-status.js +260 -0
  47. package/templates/scripts/roadmap-scanner.js +263 -0
  48. package/templates/scripts/validate-deployment.js +293 -0
  49. package/templates/skills/agent-creator/skill.json +18 -0
  50. package/templates/skills/agent-creator/skill.md +335 -0
  51. package/templates/skills/hook-creator/skill.json +18 -0
  52. package/templates/skills/hook-creator/skill.md +318 -0
  53. package/templates/skills/panel/skill.json +18 -0
  54. package/templates/skills/panel/skill.md +90 -0
  55. package/templates/skills/rag-agent-creator/skill.json +18 -0
  56. package/templates/skills/rag-agent-creator/skill.md +307 -0
@@ -0,0 +1,193 @@
1
+ /**
2
+ * Token Usage Monitor Hook
3
+ *
4
+ * Tracks cumulative token usage across the session.
5
+ * Auto-respawn warning at 90% of context window.
6
+ * Provides real-time token consumption feedback.
7
+ *
8
+ * Event: PostToolUse
9
+ *
10
+ * Configuration: Reads from .claude/config/hooks-config.json
11
+ */
12
+
13
+ const fs = require('fs');
14
+ const path = require('path');
15
+
16
+ // Default configuration
17
+ const DEFAULT_CONFIG = {
18
+ context_limit: 200000, // Estimated context window
19
+ warning_threshold: 0.75, // Warn at 75%
20
+ critical_threshold: 0.90, // Critical at 90%
21
+ auto_compact_suggestion: true, // Suggest compaction at critical
22
+ session_timeout_ms: 300000, // 5 minutes
23
+ };
24
+
25
+ // Paths
26
+ const CONFIG_PATH = path.join(process.cwd(), '.claude', 'config', 'hooks-config.json');
27
+ const STATE_PATH = path.join(process.cwd(), '.claude', 'config', 'token-usage-state.json');
28
+
29
+ /**
30
+ * Load configuration
31
+ */
32
+ function loadConfig() {
33
+ try {
34
+ if (fs.existsSync(CONFIG_PATH)) {
35
+ const config = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8'));
36
+ return { ...DEFAULT_CONFIG, ...(config.token_usage || {}) };
37
+ }
38
+ } catch (e) {
39
+ // Use defaults
40
+ }
41
+ return DEFAULT_CONFIG;
42
+ }
43
+
44
+ /**
45
+ * Load state
46
+ */
47
+ function loadState() {
48
+ try {
49
+ if (fs.existsSync(STATE_PATH)) {
50
+ return JSON.parse(fs.readFileSync(STATE_PATH, 'utf8'));
51
+ }
52
+ } catch (e) {
53
+ // Fresh state
54
+ }
55
+ return {
56
+ session_id: null,
57
+ session_start: null,
58
+ total_input_chars: 0,
59
+ total_output_chars: 0,
60
+ estimated_tokens: 0,
61
+ tool_calls: 0,
62
+ last_activity: null,
63
+ warnings_shown: 0,
64
+ };
65
+ }
66
+
67
+ /**
68
+ * Save state
69
+ */
70
+ function saveState(state) {
71
+ try {
72
+ const dir = path.dirname(STATE_PATH);
73
+ if (!fs.existsSync(dir)) {
74
+ fs.mkdirSync(dir, { recursive: true });
75
+ }
76
+ fs.writeFileSync(STATE_PATH, JSON.stringify(state, null, 2), 'utf8');
77
+ } catch (e) {
78
+ // Silent
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Estimate tokens from text (rough approximation)
84
+ */
85
+ function estimateTokens(text) {
86
+ if (!text) return 0;
87
+ // Average ~4 characters per token for English text
88
+ return Math.ceil(text.length / 4);
89
+ }
90
+
91
+ /**
92
+ * Generate session ID
93
+ */
94
+ function generateSessionId() {
95
+ return Date.now().toString(36) + Math.random().toString(36).substr(2, 5);
96
+ }
97
+
98
+ /**
99
+ * Format number with commas
100
+ */
101
+ function formatNumber(num) {
102
+ return num.toLocaleString();
103
+ }
104
+
105
+ /**
106
+ * Main hook handler
107
+ */
108
+ module.exports = async function tokenUsageMonitor(context) {
109
+ const approve = () => ({ continue: true });
110
+
111
+ try {
112
+ const config = loadConfig();
113
+ let state = loadState();
114
+ const now = Date.now();
115
+
116
+ // Check for new session
117
+ if (!state.session_start || (now - state.last_activity) > config.session_timeout_ms) {
118
+ state = {
119
+ session_id: generateSessionId(),
120
+ session_start: now,
121
+ total_input_chars: 0,
122
+ total_output_chars: 0,
123
+ estimated_tokens: 0,
124
+ tool_calls: 0,
125
+ last_activity: now,
126
+ warnings_shown: 0,
127
+ };
128
+ }
129
+
130
+ // Parse hook input
131
+ let inputChars = 0;
132
+ let outputChars = 0;
133
+
134
+ try {
135
+ const input = JSON.parse(process.env.CLAUDE_HOOK_INPUT || '{}');
136
+
137
+ // Count input characters
138
+ if (input.tool_input) {
139
+ const inputStr = typeof input.tool_input === 'string'
140
+ ? input.tool_input
141
+ : JSON.stringify(input.tool_input);
142
+ inputChars = inputStr.length;
143
+ }
144
+
145
+ // Count output characters
146
+ if (input.tool_output) {
147
+ const outputStr = typeof input.tool_output === 'string'
148
+ ? input.tool_output
149
+ : JSON.stringify(input.tool_output);
150
+ outputChars = outputStr.length;
151
+ }
152
+ } catch (e) {
153
+ // Skip counting on error
154
+ }
155
+
156
+ // Update totals
157
+ state.total_input_chars += inputChars;
158
+ state.total_output_chars += outputChars;
159
+ state.tool_calls++;
160
+ state.last_activity = now;
161
+
162
+ // Estimate tokens
163
+ const totalChars = state.total_input_chars + state.total_output_chars;
164
+ state.estimated_tokens = estimateTokens(totalChars);
165
+
166
+ // Calculate usage percentage
167
+ const usagePercent = state.estimated_tokens / config.context_limit;
168
+
169
+ // Check thresholds
170
+ if (usagePercent >= config.critical_threshold) {
171
+ if (state.warnings_shown < 3) { // Don't spam
172
+ console.log(`[token-usage-monitor] CRITICAL: ${(usagePercent * 100).toFixed(1)}% of context used`);
173
+ console.log(`[token-usage-monitor] Estimated tokens: ${formatNumber(state.estimated_tokens)}`);
174
+ if (config.auto_compact_suggestion) {
175
+ console.log('[token-usage-monitor] Consider using /context-audit or starting a new session');
176
+ }
177
+ state.warnings_shown++;
178
+ }
179
+ } else if (usagePercent >= config.warning_threshold) {
180
+ if (state.warnings_shown < 2) {
181
+ console.log(`[token-usage-monitor] WARNING: ${(usagePercent * 100).toFixed(1)}% of context used`);
182
+ state.warnings_shown++;
183
+ }
184
+ }
185
+
186
+ saveState(state);
187
+
188
+ return approve();
189
+ } catch (error) {
190
+ console.error(`[token-usage-monitor] Error: ${error.message}`);
191
+ return approve();
192
+ }
193
+ };
@@ -0,0 +1,129 @@
1
+ # Agent Patterns Library
2
+
3
+ Reusable patterns for Claude Code agent orchestration.
4
+
5
+ ## Quick Reference
6
+
7
+ | Pattern | Use Case | Complexity |
8
+ |---------|----------|------------|
9
+ | [Two-Tier Query Pipeline](two-tier-query-pipeline.md) | Intent classification + execution | Medium |
10
+ | [L1→L2 Orchestration](l1-l2-orchestration.md) | Master-worker parallel tasks | Medium |
11
+ | [Multi-Phase Orchestration](multi-phase-orchestration.md) | Sequential phases with parallel tasks | High |
12
+
13
+ ## Choosing a Pattern
14
+
15
+ ### Simple Task Routing
16
+ **Use: Two-Tier Query Pipeline**
17
+ - User requests vary in type
18
+ - Different handlers for different intents
19
+ - Need confidence-based routing
20
+
21
+ ### Parallel Subtask Execution
22
+ **Use: L1→L2 Orchestration**
23
+ - Task decomposes into independent parts
24
+ - Parallel execution improves speed
25
+ - Need result aggregation
26
+
27
+ ### Complex Multi-Step Projects
28
+ **Use: Multi-Phase Orchestration**
29
+ - Work has natural phase boundaries
30
+ - Validation needed between phases
31
+ - Phases may have parallel subtasks
32
+
33
+ ## Pattern Combinations
34
+
35
+ ### Query → Orchestration
36
+
37
+ ```
38
+ User Request
39
+
40
+ ┌─────────────────┐
41
+ │ Query Pipeline │ Classify intent
42
+ └─────────────────┘
43
+
44
+ ┌─────────────────┐
45
+ │ L1→L2 Pattern │ Execute with specialists
46
+ └─────────────────┘
47
+ ```
48
+
49
+ ### Phase → Orchestration
50
+
51
+ ```
52
+ ┌─────────────────────────────┐
53
+ │ Phase 1: Discovery │
54
+ │ ┌───────────────────────┐ │
55
+ │ │ L1→L2 Orchestration │ │ Parallel exploration
56
+ │ └───────────────────────┘ │
57
+ └─────────────────────────────┘
58
+
59
+ ┌─────────────────────────────┐
60
+ │ Phase 2: Implementation │
61
+ │ ┌───────────────────────┐ │
62
+ │ │ L1→L2 Orchestration │ │ Parallel coding
63
+ │ └───────────────────────┘ │
64
+ └─────────────────────────────┘
65
+ ```
66
+
67
+ ## Implementation Tips
68
+
69
+ ### 1. Start Simple
70
+ Begin with the simplest pattern that solves your problem. Add complexity only when needed.
71
+
72
+ ### 2. Use Appropriate Models
73
+ - L1 Orchestrators: Sonnet (needs reasoning)
74
+ - L2 Search/Explore: Haiku (fast, cheap)
75
+ - L2 Analysis/Generate: Sonnet (quality needed)
76
+
77
+ ### 3. Handle Failures Gracefully
78
+ Always have fallback behavior when agents fail.
79
+
80
+ ### 4. Log Extensively
81
+ Track agent launches, completions, and aggregations for debugging.
82
+
83
+ ### 5. Use Background Agents
84
+ For long-running tasks, use `run_in_background: true` to avoid blocking.
85
+
86
+ ## Creating New Patterns
87
+
88
+ When documenting a new pattern:
89
+
90
+ 1. **Overview**: What problem does it solve?
91
+ 2. **When to Use**: Clear use cases
92
+ 3. **Architecture**: Visual diagram
93
+ 4. **Implementation**: Code examples
94
+ 5. **Examples**: Real-world usage
95
+ 6. **Related Patterns**: Connections to other patterns
96
+
97
+ ## Pattern Template
98
+
99
+ ```markdown
100
+ # Pattern Name
101
+
102
+ Brief description.
103
+
104
+ ## Overview
105
+
106
+ What this pattern does.
107
+
108
+ ## When to Use
109
+
110
+ - Use case 1
111
+ - Use case 2
112
+
113
+ ## Architecture
114
+
115
+ [Diagram]
116
+
117
+ ## Implementation
118
+
119
+ [Code]
120
+
121
+ ## Example
122
+
123
+ [Complete example]
124
+
125
+ ## Related Patterns
126
+
127
+ - Pattern A
128
+ - Pattern B
129
+ ```
@@ -0,0 +1,189 @@
1
+ # L1→L2 Orchestration Pattern
2
+
3
+ Hierarchical agent coordination with parallel L2 spawning.
4
+
5
+ ## Overview
6
+
7
+ A master-worker pattern where:
8
+ - **L1 (Orchestrator)**: Decomposes task, coordinates workers, aggregates results
9
+ - **L2 (Specialists)**: Execute specific subtasks in parallel
10
+
11
+ ## When to Use
12
+
13
+ - Complex tasks that can be broken into independent subtasks
14
+ - Parallel execution would improve speed
15
+ - Subtasks require different specializations
16
+
17
+ ## Architecture
18
+
19
+ ```
20
+ ┌─────────────────────┐
21
+ │ L1 Orchestrator │
22
+ │ - Decompose task │
23
+ │ - Dispatch L2s │
24
+ │ - Aggregate │
25
+ └─────────────────────┘
26
+
27
+ ┌────────────────────┼────────────────────┐
28
+ ↓ ↓ ↓
29
+ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐
30
+ │ L2 Specialist │ │ L2 Specialist │ │ L2 Specialist │
31
+ │ (Search) │ │ (Analyze) │ │ (Document) │
32
+ └───────────────┘ └───────────────┘ └───────────────┘
33
+ ```
34
+
35
+ ## Implementation
36
+
37
+ ### L1 Orchestrator
38
+
39
+ ```typescript
40
+ async function orchestrate(task: string) {
41
+ // Step 1: Decompose task into subtasks
42
+ const subtasks = await decomposeTask(task);
43
+
44
+ // Step 2: Identify dependencies
45
+ const { independent, dependent } = categorizeSubtasks(subtasks);
46
+
47
+ // Step 3: Launch independent L2 agents in parallel
48
+ const parallelResults = await launchParallelL2s(independent);
49
+
50
+ // Step 4: Launch dependent L2 agents sequentially
51
+ const sequentialResults = await launchSequentialL2s(dependent, parallelResults);
52
+
53
+ // Step 5: Aggregate results
54
+ return aggregateResults([...parallelResults, ...sequentialResults]);
55
+ }
56
+ ```
57
+
58
+ ### L2 Launcher
59
+
60
+ ```typescript
61
+ async function launchParallelL2s(subtasks: Subtask[]) {
62
+ // Launch all in single message for true parallelism
63
+ const agents = subtasks.map(subtask => ({
64
+ description: subtask.title,
65
+ prompt: subtask.prompt,
66
+ subagent_type: subtask.type,
67
+ run_in_background: true
68
+ }));
69
+
70
+ // All agents start simultaneously
71
+ const handles = await Promise.all(agents.map(a => Task(a)));
72
+
73
+ // Wait for all to complete
74
+ return Promise.all(handles.map(h => waitForAgent(h)));
75
+ }
76
+ ```
77
+
78
+ ### Task Decomposition
79
+
80
+ ```typescript
81
+ function decomposeTask(task: string): Subtask[] {
82
+ // Example: "Analyze and document the authentication system"
83
+
84
+ return [
85
+ {
86
+ id: 'search',
87
+ title: 'Find auth files',
88
+ prompt: 'Search for all authentication-related files',
89
+ type: 'Explore',
90
+ dependencies: []
91
+ },
92
+ {
93
+ id: 'analyze',
94
+ title: 'Analyze auth flow',
95
+ prompt: 'Analyze the authentication flow and security',
96
+ type: 'Plan',
97
+ dependencies: ['search']
98
+ },
99
+ {
100
+ id: 'document',
101
+ title: 'Generate docs',
102
+ prompt: 'Document the authentication system',
103
+ type: 'general-purpose',
104
+ dependencies: ['analyze']
105
+ }
106
+ ];
107
+ }
108
+ ```
109
+
110
+ ### Result Aggregation
111
+
112
+ ```typescript
113
+ function aggregateResults(results: AgentResult[]): FinalResult {
114
+ return {
115
+ summary: results.map(r => r.summary).join('\n\n'),
116
+ files: results.flatMap(r => r.files || []),
117
+ insights: results.flatMap(r => r.insights || []),
118
+ recommendations: prioritizeRecommendations(results)
119
+ };
120
+ }
121
+ ```
122
+
123
+ ## Complete Example
124
+
125
+ ```typescript
126
+ // Task: "Analyze the codebase for performance issues"
127
+
128
+ // L1 Orchestrator breaks into:
129
+ const subtasks = [
130
+ // Independent (run in parallel)
131
+ { id: 'bundle', type: 'Explore', prompt: 'Find bundle size issues' },
132
+ { id: 'queries', type: 'Explore', prompt: 'Find slow database queries' },
133
+ { id: 'renders', type: 'Explore', prompt: 'Find excessive re-renders' },
134
+
135
+ // Dependent (run after above complete)
136
+ { id: 'report', type: 'general-purpose', prompt: 'Generate performance report',
137
+ dependencies: ['bundle', 'queries', 'renders'] }
138
+ ];
139
+
140
+ // Execution:
141
+ // 1. L1 launches 3 Explore agents in parallel
142
+ // 2. All 3 complete with findings
143
+ // 3. L1 launches report agent with aggregated findings
144
+ // 4. L1 returns final report
145
+ ```
146
+
147
+ ## Model Selection by Level
148
+
149
+ | Level | Model | Reasoning |
150
+ |-------|-------|-----------|
151
+ | L1 | Sonnet | Needs to coordinate, decompose, aggregate |
152
+ | L2 Search | Haiku | Simple file discovery |
153
+ | L2 Analysis | Sonnet | Complex reasoning required |
154
+ | L2 Generate | Sonnet | Quality output needed |
155
+
156
+ ## Error Handling
157
+
158
+ ```typescript
159
+ async function orchestrateWithRecovery(task) {
160
+ const subtasks = await decomposeTask(task);
161
+ const results = [];
162
+
163
+ for (const subtask of subtasks) {
164
+ try {
165
+ const result = await executeSubtask(subtask);
166
+ results.push({ subtask, result, success: true });
167
+ } catch (error) {
168
+ // Log failure but continue with other subtasks
169
+ results.push({ subtask, error, success: false });
170
+ }
171
+ }
172
+
173
+ // Report partial success if some failed
174
+ const successful = results.filter(r => r.success);
175
+ const failed = results.filter(r => !r.success);
176
+
177
+ return {
178
+ results: aggregateResults(successful.map(r => r.result)),
179
+ failures: failed.map(f => ({ task: f.subtask.id, error: f.error })),
180
+ partial: failed.length > 0
181
+ };
182
+ }
183
+ ```
184
+
185
+ ## Related Patterns
186
+
187
+ - Two-Tier Query Pipeline
188
+ - Multi-Phase Orchestration
189
+ - Dependency Ordering