oh-my-customcode 0.34.0 → 0.35.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oh-my-customcode",
3
- "version": "0.34.0",
3
+ "version": "0.35.1",
4
4
  "description": "Batteries-included agent harness for Claude Code",
5
5
  "type": "module",
6
6
  "bin": {
@@ -221,6 +221,16 @@
221
221
  }
222
222
  ],
223
223
  "description": "Detect repetitive failure loops and advise recovery strategies"
224
+ },
225
+ {
226
+ "matcher": "tool == \"Edit\" || tool == \"Write\" || tool == \"Bash\" || tool == \"Task\" || tool == \"Agent\"",
227
+ "hooks": [
228
+ {
229
+ "type": "command",
230
+ "command": "bash .claude/hooks/scripts/cost-cap-advisor.sh"
231
+ }
232
+ ],
233
+ "description": "Advisory cost cap monitoring — warn when session cost approaches configurable limit"
224
234
  }
225
235
  ],
226
236
  "Stop": [
@@ -0,0 +1,71 @@
1
+ #!/bin/bash
2
+ # cost-cap-advisor.sh — Advisory hook for session cost monitoring
3
+ # Trigger: PostToolUse (Agent/Task)
4
+ # Purpose: Warn when session cost approaches configurable cap
5
+ # Protocol: stdin JSON -> stdout pass-through, exit 0 always (advisory only, R010)
6
+
7
+ input=$(cat)
8
+
9
+ # Cost bridge file written by statusline.sh
10
+ COST_FILE="/tmp/.claude-cost-${PPID}"
11
+ ADVISORY_FILE="/tmp/.claude-cost-advisory-${PPID}"
12
+
13
+ # Configurable cap (default $5.00, override via CLAUDE_COST_CAP env var)
14
+ COST_CAP="${CLAUDE_COST_CAP:-5.00}"
15
+
16
+ # Check if cost data is available
17
+ if [ ! -f "$COST_FILE" ]; then
18
+ echo "$input"
19
+ exit 0
20
+ fi
21
+
22
+ # Read cost data (TSV: cost_usd, ctx_pct, timestamp)
23
+ IFS=$'\t' read -r cost_usd ctx_pct timestamp < "$COST_FILE" 2>/dev/null || {
24
+ echo "$input"
25
+ exit 0
26
+ }
27
+
28
+ # Validate cost_usd is a number
29
+ if ! printf '%f' "$cost_usd" >/dev/null 2>&1; then
30
+ echo "$input"
31
+ exit 0
32
+ fi
33
+
34
+ # Calculate percentage of cap used
35
+ # Use bc for float arithmetic
36
+ cost_pct=$(echo "scale=0; $cost_usd * 100 / $COST_CAP" | bc 2>/dev/null || echo "0")
37
+
38
+ # Staleness check — skip if data is older than 60 seconds
39
+ now=$(date +%s)
40
+ age=$((now - ${timestamp:-0}))
41
+ if [ "$age" -gt 60 ]; then
42
+ echo "$input"
43
+ exit 0
44
+ fi
45
+
46
+ # Read last advisory level to avoid repeating the same warning
47
+ last_level=""
48
+ if [ -f "$ADVISORY_FILE" ]; then
49
+ last_level=$(cat "$ADVISORY_FILE" 2>/dev/null || echo "")
50
+ fi
51
+
52
+ # Determine advisory level and emit warning (only once per level)
53
+ if [ "$cost_pct" -ge 100 ] && [ "$last_level" != "100" ]; then
54
+ echo "[Cost Cap] Session cost \$${cost_usd} has reached cap \$${COST_CAP} (${cost_pct}%)" >&2
55
+ echo "[Cost Cap] Consider wrapping up or increasing CLAUDE_COST_CAP" >&2
56
+ echo "100" > "$ADVISORY_FILE"
57
+ elif [ "$cost_pct" -ge 90 ] && [ "$last_level" != "90" ] && [ "$last_level" != "100" ]; then
58
+ echo "[Cost Cap] Session cost \$${cost_usd} at 90% of cap \$${COST_CAP}" >&2
59
+ echo "[Cost Cap] Ecomode recommended — consider /compact" >&2
60
+ echo "90" > "$ADVISORY_FILE"
61
+ elif [ "$cost_pct" -ge 75 ] && [ "$last_level" != "75" ] && [ "$last_level" != "90" ] && [ "$last_level" != "100" ]; then
62
+ echo "[Cost Cap] Session cost \$${cost_usd} at 75% of cap \$${COST_CAP}" >&2
63
+ echo "75" > "$ADVISORY_FILE"
64
+ elif [ "$cost_pct" -ge 50 ] && [ -z "$last_level" ]; then
65
+ echo "[Cost Cap] Session cost \$${cost_usd} at 50% of cap \$${COST_CAP}" >&2
66
+ echo "50" > "$ADVISORY_FILE"
67
+ fi
68
+
69
+ # Pass through — advisory only
70
+ echo "$input"
71
+ exit 0
@@ -31,7 +31,7 @@ if [ "$is_error" = "true" ]; then
31
31
  error_hash=$(echo "$output_preview" | head -c 50 | md5sum 2>/dev/null | cut -d' ' -f1 || echo "unknown")
32
32
  fi
33
33
 
34
- entry=$(jq -n \
34
+ entry=$(jq -cn \
35
35
  --arg ts "$timestamp" \
36
36
  --arg tool "$tool_name" \
37
37
  --arg path "$file_path" \
@@ -2,16 +2,16 @@
2
2
  set -euo pipefail
3
3
 
4
4
  # Task/Agent Outcome Recorder Hook
5
- # Trigger: PostToolUse, tool == "Task" || tool == "Agent"
5
+ # Trigger: PostToolUse (tool == "Task" || "Agent") and SubagentStop
6
6
  # Purpose: Record task outcomes for model escalation decisions
7
7
  # Protocol: stdin JSON -> process -> stdout pass-through, exit 0 always
8
8
 
9
9
  input=$(cat)
10
10
 
11
- # Extract task info
12
- agent_type=$(echo "$input" | jq -r '.tool_input.subagent_type // "unknown"')
13
- model=$(echo "$input" | jq -r '.tool_input.model // "inherit"')
14
- description=$(echo "$input" | jq -r '.tool_input.description // ""' | head -c 80)
11
+ # Extract task info — support both PostToolUse (tool_input.*) and SubagentStop (top-level) shapes
12
+ agent_type=$(echo "$input" | jq -r '.tool_input.subagent_type // .agent_type // "unknown"')
13
+ model=$(echo "$input" | jq -r '.tool_input.model // .model // "inherit"')
14
+ description=$(echo "$input" | jq -r '.tool_input.description // .description // ""' | head -c 80)
15
15
 
16
16
  # Determine outcome
17
17
  is_error=$(echo "$input" | jq -r '.tool_output.is_error // false')
@@ -24,8 +24,34 @@ else
24
24
  error_summary=""
25
25
  fi
26
26
 
27
- # Session-scoped outcome log
27
+ # Session-scoped outcome log and agent count tracker
28
28
  OUTCOME_FILE="/tmp/.claude-task-outcomes-${PPID}"
29
+ TASK_COUNT_FILE="/tmp/.claude-task-count-${PPID}"
30
+
31
+ # --- Pattern Detection ---
32
+ # Priority: skill-specific patterns > parallel > sequential (default)
33
+ pattern="sequential"
34
+
35
+ # Check description for skill-specific workflow patterns
36
+ desc_lower=$(echo "$description" | tr '[:upper:]' '[:lower:]')
37
+
38
+ if echo "$desc_lower" | grep -qE '(evaluator.optimizer|evaluator_optimizer)'; then
39
+ pattern="evaluator-optimizer"
40
+ elif echo "$desc_lower" | grep -qE '(worker.reviewer|worker_reviewer)'; then
41
+ pattern="worker-reviewer"
42
+ elif echo "$desc_lower" | grep -qE '(dag.orchestrat|dag_orchestrat|multi.phase|orchestrat)'; then
43
+ pattern="orchestrator"
44
+ elif echo "$desc_lower" | grep -qE '(parallel|\[1\]|\[2\]|\[3\]|\[4\])'; then
45
+ pattern="parallel"
46
+ else
47
+ # Infer parallel from agent count: if 2+ agents spawned this session, mark as parallel
48
+ if [ -f "$TASK_COUNT_FILE" ]; then
49
+ session_agent_count=$(cat "$TASK_COUNT_FILE" 2>/dev/null || echo "0")
50
+ if [ "$session_agent_count" -ge 2 ] 2>/dev/null; then
51
+ pattern="parallel"
52
+ fi
53
+ fi
54
+ fi
29
55
 
30
56
  # Append JSON line entry
31
57
  timestamp=$(date -u +%Y-%m-%dT%H:%M:%SZ)
@@ -34,7 +60,7 @@ entry=$(jq -n \
34
60
  --arg agent "$agent_type" \
35
61
  --arg model "$model" \
36
62
  --arg outcome "$outcome" \
37
- --arg pattern "unknown" \
63
+ --arg pattern "$pattern" \
38
64
  --arg desc "$description" \
39
65
  --arg err "$error_summary" \
40
66
  '{timestamp: $ts, agent_type: $agent, model: $model, outcome: $outcome, pattern_used: $pattern, description: $desc, error_summary: $err}')
@@ -20,6 +20,70 @@ Refactor code for better structure, naming, and patterns using language-specific
20
20
 
21
21
  **Pre-execution check**: Verify test coverage exists for the refactoring target. Refactoring without tests risks silent regressions.
22
22
 
23
+ ## Pre-flight Guards
24
+
25
+ Before executing the refactoring workflow, the agent MUST run these checks:
26
+
27
+ ### Guard 1: Test Coverage Check
28
+ **Level**: WARN
29
+ **Check**: Verify test files exist for the refactoring target
30
+ ```bash
31
+ # For target file src/module/foo.ts, check for:
32
+ # - src/module/foo.test.ts
33
+ # - src/module/foo.spec.ts
34
+ # - tests/module/foo.test.ts
35
+ # - test/module/foo.test.ts
36
+ # - __tests__/module/foo.test.ts
37
+ # For Go: foo_test.go in same package
38
+ # For Python: test_foo.py or foo_test.py
39
+ ```
40
+ **Action**: `[Pre-flight] WARN: No test file found for {target}. Refactoring without tests risks silent regressions. Consider writing tests first (/structured-dev-cycle).`
41
+
42
+ ### Guard 2: Rename-Only Detection
43
+ **Level**: INFO
44
+ **Check**: If the user request is purely about renaming (no structural change)
45
+ ```
46
+ # Keyword detection in user request
47
+ keywords: rename, 이름 변경, 이름 바꿔, rename variable, rename function
48
+ # AND no structural keywords
49
+ structural_keywords: extract, split, merge, restructure, reorganize, decompose
50
+ ```
51
+ **Action**: `[Pre-flight] INFO: For rename-only refactoring, IDE rename (F2) or sed is faster and safer (handles all references). Proceeding with full refactoring.`
52
+
53
+ ### Guard 3: Formatting-Only Request Detection
54
+ **Level**: INFO
55
+ **Check**: If the request is about formatting or style cleanup
56
+ ```
57
+ # Keyword detection
58
+ keywords: format, formatting, indent, indentation, 포맷, 스타일, whitespace, spacing
59
+ ```
60
+ **Action**: `[Pre-flight] INFO: For formatting cleanup, run the appropriate formatter (prettier, gofmt, black, rustfmt). Proceeding with full refactoring.`
61
+
62
+ ### Guard 4: File Move Detection
63
+ **Level**: INFO
64
+ **Check**: If the request is about moving files between directories
65
+ ```
66
+ # Keyword detection
67
+ keywords: move file, move to, 파일 이동, 옮겨, relocate, reorganize files
68
+ # AND no code-level changes mentioned
69
+ ```
70
+ **Action**: `[Pre-flight] INFO: For file moves without code changes, use git mv via mgr-gitnerd to preserve git history.`
71
+
72
+ ### Display Format
73
+
74
+ ```
75
+ [Pre-flight] dev-refactor
76
+ ├── Test coverage: WARN — no test file for src/utils.ts
77
+ ├── Rename-only: PASS
78
+ ├── Formatting-only: PASS
79
+ └── File move: PASS
80
+ Result: PROCEED WITH CAUTION (0 GATE, 1 WARN, 0 INFO)
81
+ ```
82
+
83
+ If any GATE: block and suggest prerequisite.
84
+ If any WARN: show warning, ask user to confirm.
85
+ If only PASS/INFO: proceed automatically.
86
+
23
87
  ## Parameters
24
88
 
25
89
  | Name | Type | Required | Description |
@@ -39,6 +103,7 @@ Refactor code for better structure, naming, and patterns using language-specific
39
103
  ## Workflow
40
104
 
41
105
  ```
106
+ 0. Run pre-flight guards (MUST complete before proceeding)
42
107
  1. Detect language (or use --lang)
43
108
  2. Select appropriate expert agent
44
109
  3. Load language-specific skill
@@ -20,6 +20,70 @@ Review code for best practices using language-specific expert agents.
20
20
 
21
21
  **Pre-execution check**: If the issue is purely formatting, run the appropriate formatter first.
22
22
 
23
+ ## Pre-flight Guards
24
+
25
+ Before executing the review workflow, the agent MUST run these checks:
26
+
27
+ ### Guard 1: Auto-generated Code Detection
28
+ **Level**: WARN
29
+ **Check**: Scan target files for auto-generation markers
30
+ ```bash
31
+ # Detection patterns (any match = WARN)
32
+ grep -rl "DO NOT EDIT" {target} 2>/dev/null
33
+ grep -rl "auto-generated" {target} 2>/dev/null
34
+ grep -rl "@generated" {target} 2>/dev/null
35
+ # File pattern detection
36
+ # *.gen.*, *.pb.go, */generated/*, */proto/*, *_generated.*, *.g.dart
37
+ ```
38
+ **Action**: `[Pre-flight] WARN: Auto-generated code detected in {file}. Generated code follows its own conventions — review may produce false positives. Continue? [Y/n]`
39
+
40
+ ### Guard 2: Formatting-Only Changes Detection
41
+ **Level**: INFO
42
+ **Check**: If reviewing changed files (not full codebase), check if changes are formatting-only
43
+ ```bash
44
+ # If git diff is available for the target
45
+ git diff --stat {target} | grep -E '^\s+\d+ files? changed'
46
+ # Compare with whitespace-ignored diff
47
+ git diff -w {target}
48
+ # If -w diff is empty but regular diff has changes → formatting only
49
+ ```
50
+ **Action**: `[Pre-flight] INFO: Changes in {file} appear to be formatting-only. Consider running the appropriate formatter instead (prettier, gofmt, black).`
51
+
52
+ ### Guard 3: Single Syntax Error Detection
53
+ **Level**: INFO
54
+ **Check**: If target is a single file and the request mentions "error", "syntax", or "broken"
55
+ ```
56
+ # Keyword detection in user request
57
+ keywords: error, syntax, broken, doesn't compile, won't build
58
+ # Single file check
59
+ target is exactly 1 file (not a directory)
60
+ ```
61
+ **Action**: `[Pre-flight] INFO: For single syntax errors, IDE/LSP diagnostics are faster. Proceeding with full review.`
62
+
63
+ ### Guard 4: Linter/Formatter Available Detection
64
+ **Level**: INFO
65
+ **Check**: Detect if a project-appropriate linter exists
66
+ ```bash
67
+ # Check for linter configs in project root
68
+ ls .eslintrc* .prettierrc* biome.json .golangci.yml pyproject.toml .rubocop.yml 2>/dev/null
69
+ ```
70
+ **Action**: `[Pre-flight] INFO: Linter config found ({config}). For style-only issues, run the linter directly.`
71
+
72
+ ### Display Format
73
+
74
+ ```
75
+ [Pre-flight] dev-review
76
+ ├── Auto-generated code: PASS
77
+ ├── Formatting-only changes: INFO — whitespace changes in src/util.ts
78
+ ├── Single syntax error: PASS
79
+ └── Linter available: INFO — .eslintrc.json found
80
+ Result: PROCEED (0 GATE, 0 WARN, 2 INFO)
81
+ ```
82
+
83
+ If any GATE: block and suggest alternative.
84
+ If any WARN: show warning, ask user to confirm.
85
+ If only PASS/INFO: proceed automatically.
86
+
23
87
  ## Parameters
24
88
 
25
89
  | Name | Type | Required | Description |
@@ -38,6 +102,7 @@ Review code for best practices using language-specific expert agents.
38
102
  ## Workflow
39
103
 
40
104
  ```
105
+ 0. Run pre-flight guards (see ## Pre-flight Guards)
41
106
  1. Detect language (or use --lang)
42
107
  2. Select appropriate expert agent
43
108
  3. Load language-specific skill
@@ -31,10 +31,113 @@ Orchestrates 10 parallel research teams for comprehensive deep analysis of any t
31
31
 
32
32
  **Pre-execution check**: If the query can be answered with < 3 sources, skip 10-team research.
33
33
 
34
+ ## Pre-flight Guards
35
+
36
+ Before executing the 10-team research workflow, the agent MUST run these checks. Research is a high-cost operation (~$8-15) — these guards prevent wasteful execution.
37
+
38
+ ### Guard Levels
39
+
40
+ | Level | Meaning | Action |
41
+ |-------|---------|--------|
42
+ | PASS | No issues detected | Proceed with research |
43
+ | INFO | Minor suggestion | Log note, proceed |
44
+ | WARN | Potentially wasteful | Show warning with cost estimate, ask confirmation |
45
+ | GATE | Wrong tool — use simpler alternative | Block execution, suggest alternative |
46
+
47
+ ### Guard 1: Query Complexity Assessment
48
+
49
+ **Level**: GATE or PASS
50
+
51
+ **Check**: Assess if the query requires multi-team research
52
+
53
+ ```
54
+ # Simple factual questions → GATE
55
+ indicators_simple:
56
+ - Query is < 10 words
57
+ - Query asks "what is", "how to", "when was" (factual)
58
+ - Query has a single definitive answer
59
+ - Can be answered from a single documentation source
60
+
61
+ # Complex research questions → PASS
62
+ indicators_complex:
63
+ - Query involves comparison of 3+ alternatives
64
+ - Query requires analysis across multiple dimensions
65
+ - Query mentions "compare", "evaluate", "analyze", "research"
66
+ - Query references a repository or ecosystem for deep analysis
67
+ ```
68
+
69
+ **Action (GATE)**: `[Pre-flight] GATE: Query appears to be a simple factual question. Use direct answer or single WebSearch instead. 10-team research (~$8-15) would be wasteful. Override with /research --force if intended.`
70
+
71
+ ### Guard 2: Single-File Review Detection
72
+
73
+ **Level**: GATE
74
+
75
+ **Check**: If the query references a single file for review
76
+
77
+ ```
78
+ # Detection
79
+ - Query mentions a specific file path (e.g., src/main.go)
80
+ - Query asks to "review" or "analyze" a single file
81
+ - No broader context requested
82
+ ```
83
+
84
+ **Action**: `[Pre-flight] GATE: For single-file review, use /dev-review {file} instead. Research is for multi-source analysis.`
85
+
86
+ ### Guard 3: Known Solution Detection
87
+
88
+ **Level**: INFO
89
+
90
+ **Check**: If the query is about implementing a known solution
91
+
92
+ ```
93
+ # Detection
94
+ keywords: implement, build, create, add feature, 구현, 만들어
95
+ # AND the solution approach is well-known (not requiring research)
96
+ ```
97
+
98
+ **Action**: `[Pre-flight] INFO: If the implementation approach is already known, consider /structured-dev-cycle instead of research. Proceeding with research.`
99
+
100
+ ### Guard 4: Context Budget Check
101
+
102
+ **Level**: WARN
103
+
104
+ **Check**: Estimate context impact of 10-team research
105
+
106
+ ```bash
107
+ # Check current context usage from statusline data
108
+ CONTEXT_FILE="/tmp/.claude-context-$PPID"
109
+ if [ -f "$CONTEXT_FILE" ]; then
110
+ context_pct=$(cat "$CONTEXT_FILE")
111
+ if [ "$context_pct" -gt 40 ]; then
112
+ # WARN — research will consume significant additional context
113
+ fi
114
+ fi
115
+ ```
116
+
117
+ **Action**: `[Pre-flight] WARN: Context usage at {pct}%. 10-team research typically adds 30-40% context. Consider /compact before proceeding, or results may be truncated.`
118
+
119
+ ### Display Format
120
+
121
+ ```
122
+ [Pre-flight] research
123
+ ├── Query complexity: PASS — multi-dimensional comparison detected
124
+ ├── Single-file review: PASS
125
+ ├── Known solution: PASS
126
+ └── Context budget: WARN — context at 45%, research adds ~35%
127
+ Result: PROCEED WITH CAUTION (0 GATE, 1 WARN, 0 INFO)
128
+ Cost estimate: ~$8-15 for 10-team parallel research
129
+ ```
130
+
131
+ If any GATE: block and suggest alternative. User can override with `--force`.
132
+ If any WARN: show warning with cost context, ask user to confirm.
133
+ If only PASS/INFO: proceed automatically.
134
+
34
135
  ## Architecture — 4 Phases
35
136
 
36
137
  ### Phase 1: Parallel Research (10 teams, batched per R009)
37
138
 
139
+ **Step 0**: Pre-flight guards pass (see Pre-flight Guards section)
140
+
38
141
  Teams operate in breadth/depth pairs across 5 domains:
39
142
 
40
143
  | Pair | Domain | Team | Role | Focus |
@@ -69,6 +69,12 @@ IFS=$'\t' read -r model_name project_dir ctx_pct ctx_size cost_usd <<< "$(
69
69
  ] | @tsv'
70
70
  )"
71
71
 
72
+ # ---------------------------------------------------------------------------
73
+ # 4b. Cost & context data bridge — write to temp file for hooks
74
+ # ---------------------------------------------------------------------------
75
+ COST_BRIDGE_FILE="/tmp/.claude-cost-${PPID}"
76
+ printf '%s\t%s\t%s\n' "$cost_usd" "$ctx_pct" "$(date +%s)" > "$COST_BRIDGE_FILE" 2>/dev/null || true
77
+
72
78
  # ---------------------------------------------------------------------------
73
79
  # 5. Model display name + color (bash 3.2 compatible case pattern matching)
74
80
  # Model detection (kept for internal reference, not displayed in statusline)
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.34.0",
2
+ "version": "0.35.1",
3
3
  "lastUpdated": "2026-03-14T00:00:00.000Z",
4
4
  "components": [
5
5
  {