@routinecrew/routinecode 2.31.55 → 2.31.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/prompt-vault.js +1 -1
- package/bin/rc-credit-turn.js +30 -10
- package/bin/rc-login.js +19 -1
- package/bin/setup.js +1 -1
- package/hooks/hooks-config.json +31 -4
- package/hooks/lib/anchors.json +523 -126
- package/hooks/lib/attest_reader.py +695 -0
- package/hooks/lib/cc-surface.json +71 -0
- package/hooks/lib/cc_compat_scan.py +321 -0
- package/hooks/lib/completion_log.py +130 -0
- package/hooks/lib/evidence.py +12 -0
- package/hooks/lib/secret_filter.py +17 -1
- package/hooks/post-edit-track.sh +35 -5
- package/hooks/post-tool-universal.sh +6 -0
- package/hooks/pre-account-guard.sh +8 -0
- package/hooks/pre-agent-spawn.mjs +1 -1
- package/hooks/pre-credit-guard.sh +12 -1
- package/hooks/pre-edit-snapshot.sh +29 -0
- package/hooks/pre-mark-complete.sh +170 -72
- package/hooks/session-start.sh +109 -5
- package/hooks/stop-claim-check.v3.sh +81 -0
- package/hooks/tests/gate-integration.test.sh +183 -2
- package/hooks/tests/mcp-name-wiring.test.sh +64 -0
- package/hooks/tests/stop-autoproceed.test.sh +60 -0
- package/mcp-db-manager/dist/analyzers/duplicate-detector.js +1 -1
- package/mcp-db-manager/dist/core/model-parser.js +1 -1
- package/mcp-db-manager/dist/core/schema-reader.js +1 -1
- package/mcp-db-manager/dist/executors/migration-executor.js +1 -1
- package/mcp-db-manager/dist/generators/migration-generator.js +1 -1
- package/mcp-db-manager/dist/index.js +1 -1
- package/mcp-db-manager/dist/validators/schema-validator.js +1 -1
- package/mcp-dev-tester/dist/analyzers/auth-diagnoser.js +1 -1
- package/mcp-dev-tester/dist/analyzers/backend-analyzer.js +1 -1
- package/mcp-dev-tester/dist/analyzers/endpoint-diagnoser.js +1 -1
- package/mcp-dev-tester/dist/analyzers/frontend-analyzer.js +1 -1
- package/mcp-dev-tester/dist/analyzers/runtime-diagnoser.js +1 -1
- package/mcp-dev-tester/dist/analyzers/type-comparator.js +1 -1
- package/mcp-dev-tester/dist/analyzers/validation-diagnoser.js +1 -1
- package/mcp-dev-tester/dist/attestation.d.ts +36 -0
- package/mcp-dev-tester/dist/attestation.d.ts.map +1 -0
- package/mcp-dev-tester/dist/attestation.js +1 -0
- package/mcp-dev-tester/dist/browser/playwright-manager.js +1 -1
- package/mcp-dev-tester/dist/browser/ui-tester.js +1 -1
- package/mcp-dev-tester/dist/config/project-config.js +1 -1
- package/mcp-dev-tester/dist/index.js +1 -1
- package/mcp-dev-tester/dist/testers/api-tester.js +1 -1
- package/mcp-doc-fetcher/dist/index.js +1 -1
- package/mcp-html-renderer/dist/index.js +1 -1
- package/mcp-html-renderer/dist/preview.js +1 -1
- package/mcp-html-renderer/dist/template-engine.js +1 -1
- package/mcp-intelligence/dist/concept-catalog.js +1 -1
- package/mcp-intelligence/dist/concept-server-proxy.js +1 -1
- package/mcp-intelligence/dist/config-auth.js +1 -1
- package/mcp-intelligence/dist/contracts.generated.js +1 -1
- package/mcp-intelligence/dist/domain-templates.js +1 -1
- package/mcp-intelligence/dist/grounding.js +1 -1
- package/mcp-intelligence/dist/handlers.js +1 -1
- package/mcp-intelligence/dist/index.js +1 -1
- package/mcp-intelligence/dist/intelligence-file.js +1 -1
- package/mcp-intelligence/dist/knowledge-critic.js +1 -1
- package/mcp-intelligence/dist/knowledge-handlers.js +1 -1
- package/mcp-intelligence/dist/mention-extractor.js +1 -1
- package/mcp-intelligence/dist/provenance.js +1 -1
- package/mcp-intelligence/dist/semantic-embedder.js +1 -1
- package/mcp-log-watcher/dist/config-auth.js +1 -1
- package/mcp-log-watcher/dist/file-watcher.js +1 -1
- package/mcp-log-watcher/dist/index.js +1 -1
- package/mcp-log-watcher/dist/known-solutions.js +1 -1
- package/mcp-log-watcher/dist/log-store.js +1 -1
- package/mcp-log-watcher/dist/websocket-server.js +1 -1
- package/mcp-plan-manager/dist/__tests__/plan-parser.test.js +1 -1
- package/mcp-plan-manager/dist/file-ops.js +1 -1
- package/mcp-plan-manager/dist/index.js +1 -1
- package/mcp-plan-manager/dist/plan-parser.js +1 -1
- package/mcp-project-context/dist/git-ops.js +1 -1
- package/mcp-project-context/dist/index.js +1 -1
- package/mcp-project-context/dist/project-analysis.js +1 -1
- package/mcp-routinecode/dist/agent-tracker.js +1 -1
- package/mcp-routinecode/dist/attestation.d.ts +37 -0
- package/mcp-routinecode/dist/attestation.js +1 -0
- package/mcp-routinecode/dist/blast-radius.js +1 -1
- package/mcp-routinecode/dist/changeset.d.ts +86 -0
- package/mcp-routinecode/dist/changeset.js +1 -0
- package/mcp-routinecode/dist/config-auth.js +1 -1
- package/mcp-routinecode/dist/contracts.generated.js +1 -1
- package/mcp-routinecode/dist/coverage.d.ts +49 -0
- package/mcp-routinecode/dist/coverage.js +1 -0
- package/mcp-routinecode/dist/explorer-advisor.js +1 -1
- package/mcp-routinecode/dist/failure-tracker.js +1 -1
- package/mcp-routinecode/dist/file-lock-registry.js +1 -1
- package/mcp-routinecode/dist/file-risk-scorer.js +1 -1
- package/mcp-routinecode/dist/index.js +1 -1
- package/mcp-routinecode/dist/known-solutions.js +1 -1
- package/mcp-routinecode/dist/ledger-miner.js +1 -1
- package/mcp-routinecode/dist/observed-draft.js +1 -1
- package/mcp-routinecode/dist/pattern-matcher.js +1 -1
- package/mcp-routinecode/dist/route-match.d.ts +24 -0
- package/mcp-routinecode/dist/route-match.js +1 -0
- package/mcp-routinecode/dist/routines.d.ts +1 -0
- package/mcp-routinecode/dist/routines.js +1 -1
- package/mcp-routinecode/dist/rule-engine.js +1 -1
- package/mcp-routinecode/dist/rule-promoter.js +1 -1
- package/mcp-routinecode/dist/telemetry-analyzer.js +1 -1
- package/mcp-routinecode/dist/test-runner.d.ts +66 -0
- package/mcp-routinecode/dist/test-runner.js +1 -0
- package/mcp-routinecode/dist/verification.d.ts +65 -0
- package/mcp-routinecode/dist/verification.js +0 -0
- package/mcp-routinecode/dist/viral-loop.js +1 -1
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
|
+
# 차단 메시지는 python 이 직접 출력한다 (macOS bash 3.2 는 echo "$(python3 -c "...{...}...")" 의 중첩 따옴표를 잘못 파싱 →
|
|
3
|
+
# 중괄호 확장 → python SyntaxError → fallback 이 두 번 출력되어 JSON 파싱 불가 = 차단 무효).
|
|
4
|
+
# 메시지 생성 python 에 넘길 lib 경로 — 큰따옴표 문자열 안에 $(cd "$(dirname "$0")..) 를 중첩하면
|
|
5
|
+
# 따옴표가 깨져 python 이 죽고 fallback JSON 이 두 번 출력된다(파싱 불가 → 차단 무효). 한 번만 계산해 참조.
|
|
6
|
+
_RC_HOOK_LIB="$(cd "$(dirname "$0")/lib" 2>/dev/null && pwd)"
|
|
2
7
|
# PreToolUse hook: mcp__plan_manager__mark_task_complete
|
|
3
8
|
# 태스크 완료 마킹 전에 빌드 검증 상태를 확인하고, 실패 시 차단.
|
|
4
9
|
# PostToolUse가 아닌 PreToolUse이므로 실행 자체를 block할 수 있다.
|
|
5
10
|
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
# 채점 MCP(ROUTINECODE_KNOWLEDGE_DIR)와 같은 디렉터리를 본다
|
|
12
|
+
KNOW_DIR="${ROUTINECODE_KNOWLEDGE_DIR:-$HOME/.routinecode/knowledge}"
|
|
13
|
+
BUILD_STATE="$KNOW_DIR/build-state.json"
|
|
14
|
+
EDIT_TRACKER="$KNOW_DIR/edit-tracker.json"
|
|
8
15
|
|
|
9
16
|
# stdin에서 hook input 읽기
|
|
10
17
|
INPUT=$(cat)
|
|
@@ -37,13 +44,13 @@ else
|
|
|
37
44
|
done
|
|
38
45
|
fi
|
|
39
46
|
if [ "$MCP_ALIVE" != "true" ]; then
|
|
40
|
-
|
|
41
|
-
import sys,json;sys.path.insert(0,'$
|
|
47
|
+
python3 -c "
|
|
48
|
+
import sys,json;sys.path.insert(0,'$_RC_HOOK_LIB')
|
|
42
49
|
try:
|
|
43
50
|
from i18n import t;msg=t('gate.mcp_degraded_mark')
|
|
44
51
|
except:msg='[mark-gate] MCP disconnected - all gates skipped (enforced normally in connected sessions). Verify completion manually before marking.'
|
|
45
52
|
print(json.dumps({'systemMessage':msg}))
|
|
46
|
-
" 2>/dev/null || echo '{"systemMessage":"[mark-gate] MCP disconnected - gates skipped. Verify completion manually."}'
|
|
53
|
+
" 2>/dev/null || echo '{"systemMessage":"[mark-gate] MCP disconnected - gates skipped. Verify completion manually."}'
|
|
47
54
|
exit 0
|
|
48
55
|
fi
|
|
49
56
|
|
|
@@ -58,7 +65,7 @@ import json, re
|
|
|
58
65
|
try:
|
|
59
66
|
t = json.load(open('$EDIT_TRACKER'))
|
|
60
67
|
files = t.get('files', [])
|
|
61
|
-
route_pattern = re.compile(r'\.(
|
|
68
|
+
route_pattern = re.compile(r'\.(routes?|controller|router)\.[cm]?[jt]s$|(^|/)router\.[cm]?[jt]s$|(^|/)routes?/[^/]+\.(py|[cm]?[jt]s)$')
|
|
62
69
|
found = any(route_pattern.search(f) for f in files)
|
|
63
70
|
print('true' if found else 'false')
|
|
64
71
|
except:
|
|
@@ -67,77 +74,86 @@ except:
|
|
|
67
74
|
fi
|
|
68
75
|
|
|
69
76
|
if [ "$ROUTE_MODIFIED" = "true" ]; then
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
# 증거 = test_endpoint 가 직접 기록한 서명 attestation (마지막 route 파일 편집 이후).
|
|
78
|
+
# (구: mark_task_complete 입력 문자열에 'test_endpoint' 포함 여부 — 호출 증거 아님)
|
|
79
|
+
TEST_ENDPOINT_CALLED=$(RC_LIB="$(cd "$(dirname "$0")/lib" 2>/dev/null && pwd)" RC_TRACKER="$EDIT_TRACKER" python3 -c "
|
|
80
|
+
import json, os, re, sys
|
|
81
|
+
sys.path.insert(0, os.environ.get('RC_LIB', ''))
|
|
72
82
|
try:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
from attest_reader import read_attestations
|
|
84
|
+
t = json.load(open(os.environ['RC_TRACKER']))
|
|
85
|
+
rp = re.compile(r'\.(routes?|controller|router)\.[cm]?[jt]s$|(^|/)router\.[cm]?[jt]s$|(^|/)routes?/[^/]+\.(py|[cm]?[jt]s)$')
|
|
86
|
+
mt = 0
|
|
87
|
+
for f in t.get('files', []):
|
|
88
|
+
if rp.search(f):
|
|
89
|
+
try: mt = max(mt, os.path.getmtime(f))
|
|
90
|
+
except OSError: pass
|
|
91
|
+
from attest_reader import is_local_host
|
|
92
|
+
# 로컬/사설망 호출 + 라우트가 존재함을 보인 응답(0·404 아님)만 인정
|
|
93
|
+
rows = [r for r in read_attestations(since_ms=int(mt * 1000), kinds=['endpoint'])
|
|
94
|
+
if is_local_host((r.get('detail') or {}).get('host'))
|
|
95
|
+
and (r.get('detail') or {}).get('status') not in (0, 404, None)
|
|
96
|
+
and int((r.get('detail') or {}).get('status') or 0) < 500
|
|
97
|
+
and (r.get('detail') or {}).get('status') not in (401, 403, 405)] # 채점기 provesRoute 와 동일
|
|
98
|
+
print('true' if rows else 'false')
|
|
99
|
+
except Exception:
|
|
80
100
|
print('false')
|
|
81
101
|
" 2>/dev/null)
|
|
82
102
|
|
|
83
103
|
if [ "$TEST_ENDPOINT_CALLED" != "true" ]; then
|
|
84
|
-
|
|
85
|
-
import sys,json;sys.path.insert(0,'$
|
|
104
|
+
python3 -c "
|
|
105
|
+
import sys,json;sys.path.insert(0,'$_RC_HOOK_LIB')
|
|
86
106
|
try:
|
|
87
107
|
from i18n import t;msg=t('mark.route_test_missing')
|
|
88
108
|
except:msg='[HOOK] Cannot mark task complete: route/controller files modified but test_endpoint never called.'
|
|
89
109
|
print(json.dumps({'decision':'block','reason':msg}))
|
|
90
|
-
" 2>/dev/null || echo '{"decision":"block","reason":"[HOOK] Route modified but test_endpoint not called."}'
|
|
110
|
+
" 2>/dev/null || echo '{"decision":"block","reason":"[HOOK] Route modified but test_endpoint not called."}'
|
|
91
111
|
exit 0
|
|
92
112
|
fi
|
|
93
113
|
fi
|
|
94
114
|
|
|
95
115
|
# ─── 빌드 상태 확인 ───
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
116
|
+
# 증거 = build_check 가 서명한 build attestation 중 마지막 편집 이후 시작된 실빌드 (build-state.json 은 무서명)
|
|
117
|
+
BUILD_OK=$(RC_LIB="$(cd "$(dirname "$0")/lib" 2>/dev/null && pwd)" RC_TRACKER="$EDIT_TRACKER" python3 -c "
|
|
118
|
+
import os, sys
|
|
119
|
+
sys.path.insert(0, os.environ.get('RC_LIB', ''))
|
|
100
120
|
try:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
else:
|
|
105
|
-
all_ok = all(v.get('success', True) for v in bs.values() if isinstance(v, dict))
|
|
106
|
-
print('true' if all_ok else 'false')
|
|
107
|
-
except:
|
|
121
|
+
from attest_reader import build_status
|
|
122
|
+
print(build_status(os.environ['RC_TRACKER']))
|
|
123
|
+
except Exception:
|
|
108
124
|
print('unknown')
|
|
109
125
|
" 2>/dev/null)
|
|
110
|
-
|
|
126
|
+
BUILD_OK=${BUILD_OK:-unknown}
|
|
111
127
|
|
|
112
128
|
# (W1a MCP-liveness 는 파일 최상단으로 이동됨 — 전 게이트를 degraded-aware 로 커버)
|
|
113
129
|
|
|
114
130
|
# 빌드 실패 상태 — block
|
|
115
131
|
if [ "$BUILD_OK" = "false" ]; then
|
|
116
|
-
|
|
117
|
-
import sys,json;sys.path.insert(0,'$
|
|
132
|
+
python3 -c "
|
|
133
|
+
import sys,json;sys.path.insert(0,'$_RC_HOOK_LIB')
|
|
118
134
|
try:
|
|
119
135
|
from i18n import t;msg=t('mark.build_failing')
|
|
120
136
|
except:msg='[HOOK] Cannot mark task complete: BUILD IS FAILING. Run mcp__routinecode__build_check first.'
|
|
121
137
|
print(json.dumps({'decision':'block','reason':msg}))
|
|
122
|
-
" 2>/dev/null || echo '{"decision":"block","reason":"[HOOK] BUILD IS FAILING."}'
|
|
138
|
+
" 2>/dev/null || echo '{"decision":"block","reason":"[HOOK] BUILD IS FAILING."}'
|
|
123
139
|
exit 0
|
|
124
140
|
fi
|
|
125
141
|
|
|
126
142
|
# 빌드 상태를 모르거나 비어있음 — block (fail-closed)
|
|
127
143
|
if [ "$BUILD_OK" = "unknown" ] || [ "$BUILD_OK" = "empty" ]; then
|
|
128
|
-
|
|
129
|
-
import sys,json;sys.path.insert(0,'$
|
|
144
|
+
python3 -c "
|
|
145
|
+
import sys,json;sys.path.insert(0,'$_RC_HOOK_LIB')
|
|
130
146
|
try:
|
|
131
147
|
from i18n import t;msg=t('mark.build_unknown')
|
|
132
148
|
except:msg='[HOOK] Cannot mark task complete: no build verification found. Run mcp__routinecode__build_check first.'
|
|
133
149
|
print(json.dumps({'decision':'block','reason':msg}))
|
|
134
|
-
" 2>/dev/null || echo '{"decision":"block","reason":"[HOOK] No build verification found."}'
|
|
150
|
+
" 2>/dev/null || echo '{"decision":"block","reason":"[HOOK] No build verification found."}'
|
|
135
151
|
exit 0
|
|
136
152
|
fi
|
|
137
153
|
|
|
138
154
|
# --- 3. Development verification score check ---
|
|
139
|
-
VERIFY_DIR="$
|
|
140
|
-
mkdir -p "$VERIFY_DIR" "$
|
|
155
|
+
VERIFY_DIR="$KNOW_DIR/verification"
|
|
156
|
+
mkdir -p "$VERIFY_DIR" "$KNOW_DIR/classifications"
|
|
141
157
|
|
|
142
158
|
# Extract task_id from hook input (tool_input.task_id)
|
|
143
159
|
TASK_ID=$(echo "$INPUT" | python3 -c "
|
|
@@ -155,13 +171,13 @@ except:
|
|
|
155
171
|
HOOK_LIB_DIR="$(cd "$(dirname "$0")/lib" 2>/dev/null && pwd)"
|
|
156
172
|
|
|
157
173
|
if [ -z "$TASK_ID" ]; then
|
|
158
|
-
|
|
174
|
+
python3 -c "
|
|
159
175
|
import sys,json;sys.path.insert(0,'$HOOK_LIB_DIR')
|
|
160
176
|
try:
|
|
161
177
|
from i18n import t;msg=t('mark.no_task_id')
|
|
162
178
|
except:msg='[HOOK] mark_task_complete called without task_id. Cannot verify.'
|
|
163
179
|
print(json.dumps({'decision':'block','reason':msg}))
|
|
164
|
-
" 2>/dev/null || echo '{"decision":"block","reason":"[HOOK] mark_task_complete called without task_id."}'
|
|
180
|
+
" 2>/dev/null || echo '{"decision":"block","reason":"[HOOK] mark_task_complete called without task_id."}'
|
|
165
181
|
exit 0
|
|
166
182
|
fi
|
|
167
183
|
|
|
@@ -175,27 +191,34 @@ esac
|
|
|
175
191
|
|
|
176
192
|
if true; then
|
|
177
193
|
# Tier 조회 (없으면 standard 취급 → fail-closed)
|
|
178
|
-
CLASSIFY_FILE="$
|
|
194
|
+
CLASSIFY_FILE="$KNOW_DIR/classifications/${TASK_ID}.json"
|
|
179
195
|
TIER="standard"
|
|
180
196
|
if [ -f "$CLASSIFY_FILE" ]; then
|
|
181
|
-
TIER=$(python3 -c "
|
|
182
|
-
import json
|
|
197
|
+
TIER=$(RC_LIB="$HOOK_LIB_DIR" RC_CF="$CLASSIFY_FILE" RC_TRACKER="$EDIT_TRACKER" python3 -c "
|
|
198
|
+
import json, os, sys
|
|
199
|
+
sys.path.insert(0, os.environ.get('RC_LIB', ''))
|
|
183
200
|
try:
|
|
184
|
-
|
|
185
|
-
|
|
201
|
+
from attest_reader import verify_classification, tracker_state
|
|
202
|
+
c = json.load(open(os.environ['RC_CF']))
|
|
203
|
+
# 무서명/위조 tier 파일 = standard (light 로 점수 게이트 우회 차단)
|
|
204
|
+
tier = c.get('tier', 'standard') if verify_classification(c) else 'standard'
|
|
205
|
+
files, _ = tracker_state(os.environ['RC_TRACKER'])
|
|
206
|
+
if tier == 'light' and len(files) > 2:
|
|
207
|
+
tier = 'standard' # light = 2파일 이하 — 실제 변경 집합이 더 크면 무효
|
|
208
|
+
print(tier)
|
|
209
|
+
except Exception:
|
|
186
210
|
print('standard')
|
|
187
211
|
" 2>/dev/null)
|
|
188
212
|
TIER=${TIER:-standard}
|
|
189
213
|
fi
|
|
190
214
|
|
|
191
|
-
# light tier:
|
|
192
|
-
|
|
193
|
-
echo '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow"}}'
|
|
194
|
-
exit 0
|
|
195
|
-
fi
|
|
215
|
+
# light tier: 설계 점수·blast-radius 요구만 면제. 개발 점수(auto_score)는 모든 tier 필수 —
|
|
216
|
+
# tier 는 classify_task 의 LLM 신고 입력(fileCount 등)으로 정해지므로 점수 게이트 생략 근거가 될 수 없다.
|
|
196
217
|
|
|
197
|
-
DEV_SCORE=$(RC_VERIFY_DIR="$VERIFY_DIR" RC_TASK_ID="$TASK_ID" python3 -c "
|
|
198
|
-
import json, glob, os
|
|
218
|
+
DEV_SCORE=$(RC_VERIFY_DIR="$VERIFY_DIR" RC_TASK_ID="$TASK_ID" RC_LIB="$HOOK_LIB_DIR" RC_TRACKER="$EDIT_TRACKER" python3 -c "
|
|
219
|
+
import json, glob, os, sys
|
|
220
|
+
sys.path.insert(0, os.environ.get('RC_LIB', ''))
|
|
221
|
+
from attest_reader import verify_state
|
|
199
222
|
verify_dir = os.environ['RC_VERIFY_DIR']
|
|
200
223
|
task_id = os.environ['RC_TASK_ID']
|
|
201
224
|
# verification.ts saves as development-{targetId}.json
|
|
@@ -205,38 +228,93 @@ if not files:
|
|
|
205
228
|
else:
|
|
206
229
|
latest = sorted(files)[-1]
|
|
207
230
|
v = json.load(open(latest))
|
|
231
|
+
# 서명 없는/위조된 점수 파일 = 점수 없음 (auto_score 재실행으로만 회복)
|
|
232
|
+
if not verify_state(v):
|
|
233
|
+
print(-1)
|
|
234
|
+
sys.exit(0)
|
|
235
|
+
from attest_reader import tracker_state, change_fingerprint
|
|
236
|
+
files, last_edit = tracker_state(os.environ.get('RC_TRACKER', ''))
|
|
237
|
+
if not isinstance(v.get('scoredAt'), (int, float)) or v['scoredAt'] < last_edit:
|
|
238
|
+
print(-4) # 채점 이후 코드가 바뀜 — 재채점 필요
|
|
239
|
+
sys.exit(0)
|
|
240
|
+
# 변경 지문: tracker 에 안 남는 Bash 편집·커밋까지 포함한 레포 상태(HEAD+dirty 내용) 해시가 채점 시점과 같아야 함
|
|
241
|
+
fp = change_fingerprint(files)
|
|
242
|
+
if getattr(change_fingerprint, 'oversize', []):
|
|
243
|
+
print(-5) # git status 과대 — 변경 검증 불가
|
|
244
|
+
sys.exit(0)
|
|
245
|
+
if getattr(change_fingerprint, 'redirect', []):
|
|
246
|
+
print(-6) # core.worktree 가 변경 파일 밖을 가리킴 — git 이 실제 파일을 보지 않음
|
|
247
|
+
sys.exit(0)
|
|
248
|
+
if not v.get('changeFingerprint') or v['changeFingerprint'] != fp:
|
|
249
|
+
print(-4)
|
|
250
|
+
sys.exit(0)
|
|
208
251
|
score = v.get('currentScore', -1)
|
|
209
252
|
adjusted = v.get('adjustedScore')
|
|
210
|
-
|
|
253
|
+
s = adjusted if adjusted is not None else score
|
|
254
|
+
# forcedPass: 반복 상한 도달 후 70+ (bounded-retry 탈출구) — 부채로 허용
|
|
255
|
+
print(str(int(s)) + ' ' + ('1' if v.get('forcedPass') else '0'))
|
|
211
256
|
" 2>/dev/null)
|
|
212
257
|
|
|
258
|
+
DEV_FORCED=$(echo "$DEV_SCORE" | awk '{print $2}')
|
|
259
|
+
DEV_SCORE=$(echo "$DEV_SCORE" | awk '{print $1}')
|
|
213
260
|
DEV_SCORE=${DEV_SCORE:--1}
|
|
261
|
+
DEBT_MSG=""
|
|
262
|
+
if [ "$DEV_FORCED" = "1" ] && [ "$DEV_SCORE" -ge 70 ] && [ "$DEV_SCORE" -lt 90 ]; then
|
|
263
|
+
DEBT_MSG="[mark-gate] task ${TASK_ID} passed WITH DEBT: auto_score ${DEV_SCORE}/100 after max iterations (forced pass). Report the unmet dimensions to the user."
|
|
264
|
+
DEV_SCORE=90
|
|
265
|
+
fi
|
|
266
|
+
|
|
267
|
+
if [ "$DEV_SCORE" -eq -5 ]; then
|
|
268
|
+
python3 -c "
|
|
269
|
+
import json
|
|
270
|
+
print(json.dumps({'decision':'block','reason':'[HOOK] Too much to verify in a repository you changed (git status > 32MB, or > 20000 files inside a nested repo / linked directory) — add the bulk (venv, build output, data, vendored deps) to .gitignore so changes can be verified, then re-run auto_score.'}))
|
|
271
|
+
"
|
|
272
|
+
exit 0
|
|
273
|
+
fi
|
|
274
|
+
|
|
275
|
+
if [ "$DEV_SCORE" -eq -6 ]; then
|
|
276
|
+
python3 -c "
|
|
277
|
+
import json
|
|
278
|
+
print(json.dumps({'decision':'block','reason':'[HOOK] core.worktree points git at a different directory than the files you changed — git cannot verify them. Unset core.worktree (git config --unset core.worktree), then re-run auto_score.'}))
|
|
279
|
+
"
|
|
280
|
+
exit 0
|
|
281
|
+
fi
|
|
282
|
+
|
|
283
|
+
if [ "$DEV_SCORE" -eq -4 ]; then
|
|
284
|
+
RC_T="$TASK_ID" python3 -c "
|
|
285
|
+
import json, os
|
|
286
|
+
print(json.dumps({'decision':'block','reason':'[HOOK] Files were edited after task '+os.environ['RC_T']+' was scored — the score is stale. Re-run build_check / run_tests, then auto_score.'}))
|
|
287
|
+
"
|
|
288
|
+
exit 0
|
|
289
|
+
fi
|
|
214
290
|
|
|
215
291
|
if [ "$DEV_SCORE" -eq -1 ]; then
|
|
216
|
-
|
|
292
|
+
python3 -c "
|
|
217
293
|
import sys,json;sys.path.insert(0,'$HOOK_LIB_DIR')
|
|
218
294
|
try:
|
|
219
295
|
from i18n import t;msg=t('mark.no_score',task_id='${TASK_ID}',tier='${TIER}')
|
|
220
296
|
except:msg='[HOOK] No verification score for task ${TASK_ID} (tier=${TIER}). Run: classify_task -> save_evidence -> auto_score. Score must reach 90+ before mark_task_complete.'
|
|
221
297
|
print(json.dumps({'decision':'block','reason':msg}))
|
|
222
|
-
" 2>/dev/null || echo "{\"decision\":\"block\",\"reason\":\"[HOOK] No verification score for task ${TASK_ID}.\"}"
|
|
298
|
+
" 2>/dev/null || echo "{\"decision\":\"block\",\"reason\":\"[HOOK] No verification score for task ${TASK_ID}.\"}"
|
|
223
299
|
exit 0
|
|
224
300
|
fi
|
|
225
301
|
|
|
226
302
|
if [ "$DEV_SCORE" -lt 90 ]; then
|
|
227
|
-
|
|
303
|
+
python3 -c "
|
|
228
304
|
import sys,json;sys.path.insert(0,'$HOOK_LIB_DIR')
|
|
229
305
|
try:
|
|
230
306
|
from i18n import t;msg=t('mark.low_score',score='${DEV_SCORE}',tier='${TIER}')
|
|
231
307
|
except:msg='[HOOK] Verification score ${DEV_SCORE}/100 < 90 (tier=${TIER}). Analyze failing dimensions -> fix -> save_evidence -> auto_score -> repeat until 90+.'
|
|
232
308
|
print(json.dumps({'decision':'block','reason':msg}))
|
|
233
|
-
" 2>/dev/null || echo "{\"decision\":\"block\",\"reason\":\"[HOOK] Verification score ${DEV_SCORE}/100 < 90.\"}"
|
|
309
|
+
" 2>/dev/null || echo "{\"decision\":\"block\",\"reason\":\"[HOOK] Verification score ${DEV_SCORE}/100 < 90.\"}"
|
|
234
310
|
exit 0
|
|
235
311
|
fi
|
|
236
312
|
|
|
237
313
|
# --- 4. Design phase score check (retroactive deductions may lower it) ---
|
|
238
|
-
DESIGN_SCORE=$(python3 -c "
|
|
239
|
-
import json, glob, os
|
|
314
|
+
DESIGN_SCORE=$(RC_LIB="$HOOK_LIB_DIR" python3 -c "
|
|
315
|
+
import json, glob, os, sys
|
|
316
|
+
sys.path.insert(0, os.environ.get('RC_LIB', ''))
|
|
317
|
+
from attest_reader import verify_state
|
|
240
318
|
verify_dir = '$VERIFY_DIR'
|
|
241
319
|
task_id = '$TASK_ID'
|
|
242
320
|
files = glob.glob(os.path.join(verify_dir, f'design-{task_id}.json'))
|
|
@@ -245,6 +323,9 @@ if not files:
|
|
|
245
323
|
else:
|
|
246
324
|
latest = sorted(files)[-1]
|
|
247
325
|
v = json.load(open(latest))
|
|
326
|
+
if not verify_state(v):
|
|
327
|
+
print(-2)
|
|
328
|
+
sys.exit(0)
|
|
248
329
|
adjusted = v.get('adjustedScore')
|
|
249
330
|
score = v.get('currentScore', -1)
|
|
250
331
|
print(adjusted if adjusted is not None else score)
|
|
@@ -254,24 +335,24 @@ else:
|
|
|
254
335
|
|
|
255
336
|
# B-2 fix: design file not found for standard/full tier = block
|
|
256
337
|
if [ "$DESIGN_SCORE" -eq -2 ] && [ "$TIER" != "light" ]; then
|
|
257
|
-
|
|
338
|
+
python3 -c "
|
|
258
339
|
import sys,json;sys.path.insert(0,'$HOOK_LIB_DIR')
|
|
259
340
|
try:
|
|
260
341
|
from i18n import t;msg=t('mark.no_design_score',task_id='${TASK_ID}',tier='${TIER}')
|
|
261
342
|
except:msg='[HOOK] No design verification found for task ${TASK_ID} (tier=${TIER}). Complete design phase scoring (>= 90) before marking complete.'
|
|
262
343
|
print(json.dumps({'decision':'block','reason':msg}))
|
|
263
|
-
" 2>/dev/null || echo "{\"decision\":\"block\",\"reason\":\"[HOOK] No design verification for task ${TASK_ID}.\"}"
|
|
344
|
+
" 2>/dev/null || echo "{\"decision\":\"block\",\"reason\":\"[HOOK] No design verification for task ${TASK_ID}.\"}"
|
|
264
345
|
exit 0
|
|
265
346
|
fi
|
|
266
347
|
|
|
267
348
|
if [ "$DESIGN_SCORE" -ne -2 ] && [ "$DESIGN_SCORE" -lt 90 ]; then
|
|
268
|
-
|
|
349
|
+
python3 -c "
|
|
269
350
|
import sys,json;sys.path.insert(0,'$HOOK_LIB_DIR')
|
|
270
351
|
try:
|
|
271
352
|
from i18n import t;msg=t('mark.low_design_score',score='${DESIGN_SCORE}')
|
|
272
353
|
except:msg='[HOOK] Design phase score ${DESIGN_SCORE}/100 < 90 (retroactive deductions applied). Fix design flaws and re-score design phase before marking complete.'
|
|
273
354
|
print(json.dumps({'decision':'block','reason':msg}))
|
|
274
|
-
" 2>/dev/null || echo "{\"decision\":\"block\",\"reason\":\"[HOOK] Design score ${DESIGN_SCORE}/100 < 90.\"}"
|
|
355
|
+
" 2>/dev/null || echo "{\"decision\":\"block\",\"reason\":\"[HOOK] Design score ${DESIGN_SCORE}/100 < 90.\"}"
|
|
275
356
|
exit 0
|
|
276
357
|
fi
|
|
277
358
|
|
|
@@ -289,7 +370,7 @@ except:
|
|
|
289
370
|
MODIFIED_COUNT=${MODIFIED_COUNT:-0}
|
|
290
371
|
else
|
|
291
372
|
# edit-tracker missing — fall back to classification's fileCount
|
|
292
|
-
CLASSIFY_FILE="$
|
|
373
|
+
CLASSIFY_FILE="$KNOW_DIR/classifications/${TASK_ID}.json"
|
|
293
374
|
if [ -f "$CLASSIFY_FILE" ]; then
|
|
294
375
|
MODIFIED_COUNT=$(python3 -c "
|
|
295
376
|
import json, re
|
|
@@ -306,15 +387,15 @@ except:
|
|
|
306
387
|
fi
|
|
307
388
|
|
|
308
389
|
if [ "$MODIFIED_COUNT" -ge 3 ] && [ "$TIER" != "light" ]; then
|
|
309
|
-
BLAST_FILE="$
|
|
390
|
+
BLAST_FILE="$KNOW_DIR/blast-radius/${TASK_ID}.json"
|
|
310
391
|
if [ ! -f "$BLAST_FILE" ]; then
|
|
311
|
-
|
|
392
|
+
python3 -c "
|
|
312
393
|
import sys,json;sys.path.insert(0,'$HOOK_LIB_DIR')
|
|
313
394
|
try:
|
|
314
395
|
from i18n import t;msg=t('mark.no_blast_radius',count='${MODIFIED_COUNT}',tier='${TIER}')
|
|
315
396
|
except:msg='[HOOK] ${MODIFIED_COUNT} files modified (tier=${TIER}) but no blast-radius trace found. Run mcp__routinecode__trace_blast_radius before marking complete.'
|
|
316
397
|
print(json.dumps({'decision':'block','reason':msg}))
|
|
317
|
-
" 2>/dev/null || echo "{\"decision\":\"block\",\"reason\":\"[HOOK] ${MODIFIED_COUNT} files modified but no blast-radius trace.\"}"
|
|
398
|
+
" 2>/dev/null || echo "{\"decision\":\"block\",\"reason\":\"[HOOK] ${MODIFIED_COUNT} files modified but no blast-radius trace.\"}"
|
|
318
399
|
exit 0
|
|
319
400
|
fi
|
|
320
401
|
|
|
@@ -331,7 +412,7 @@ except:
|
|
|
331
412
|
CHECKLIST_COUNT=${CHECKLIST_COUNT:-0}
|
|
332
413
|
|
|
333
414
|
if [ "$CHECKLIST_COUNT" -gt 0 ]; then
|
|
334
|
-
EVIDENCE_BASE="$HOME/.routinecode/evidence"
|
|
415
|
+
EVIDENCE_BASE="${ROUTINECODE_EVIDENCE_DIR:-$HOME/.routinecode/evidence}"
|
|
335
416
|
CHAIN_FOUND=false
|
|
336
417
|
for dir in "$EVIDENCE_BASE"/*/task-"$TASK_ID"; do
|
|
337
418
|
if [ -f "$dir/chain-checks.json" ]; then
|
|
@@ -340,22 +421,39 @@ except:
|
|
|
340
421
|
fi
|
|
341
422
|
done
|
|
342
423
|
if [ "$CHAIN_FOUND" = "false" ]; then
|
|
343
|
-
|
|
424
|
+
python3 -c "
|
|
344
425
|
import sys,json;sys.path.insert(0,'$HOOK_LIB_DIR')
|
|
345
426
|
try:
|
|
346
427
|
from i18n import t;msg=t('mark.no_chain_checks',count='${CHECKLIST_COUNT}')
|
|
347
428
|
except:msg='[HOOK] Blast-radius has ${CHECKLIST_COUNT} checklist items but no chain-checks evidence found. Verify each chain item and save_evidence with chainChecks.'
|
|
348
429
|
print(json.dumps({'decision':'block','reason':msg}))
|
|
349
|
-
" 2>/dev/null || echo "{\"decision\":\"block\",\"reason\":\"[HOOK] Blast-radius has ${CHECKLIST_COUNT} checklist items but no chain-checks.\"}"
|
|
430
|
+
" 2>/dev/null || echo "{\"decision\":\"block\",\"reason\":\"[HOOK] Blast-radius has ${CHECKLIST_COUNT} checklist items but no chain-checks.\"}"
|
|
350
431
|
exit 0
|
|
351
432
|
fi
|
|
352
433
|
fi
|
|
353
434
|
fi
|
|
354
435
|
fi
|
|
355
436
|
|
|
437
|
+
# 결함 유출률 실측 원천 기록 (fail-open) — tracker 리셋 전에 변경 파일 스냅샷
|
|
438
|
+
python3 "$(dirname "$0")/lib/completion_log.py" "$TASK_ID" "${TIER:-standard}" "$EDIT_TRACKER" 2>/dev/null
|
|
439
|
+
# 다음 태스크의 기준 HEAD = 이 완료 시점의 HEAD (첫 Edit 시점이 아님 — 그 사이 Bash 커밋 세탁 차단)
|
|
440
|
+
RC_LIB="$_RC_HOOK_LIB" RC_TRACKER="$EDIT_TRACKER" python3 -c "
|
|
441
|
+
import os, sys
|
|
442
|
+
sys.path.insert(0, os.environ.get('RC_LIB', ''))
|
|
443
|
+
from attest_reader import record_task_heads, tracker_state
|
|
444
|
+
record_task_heads([os.path.dirname(f) for f in tracker_state(os.environ['RC_TRACKER'])[0]], overwrite=True)
|
|
445
|
+
" 2>/dev/null
|
|
446
|
+
|
|
356
447
|
# Task complete — reset edit-tracker for next task
|
|
357
|
-
EDIT_TRACKER_RESET="$
|
|
448
|
+
EDIT_TRACKER_RESET="$KNOW_DIR/edit-tracker.json"
|
|
358
449
|
rm -f "$EDIT_TRACKER_RESET"
|
|
359
450
|
|
|
360
|
-
# 빌드 성공 — 통과
|
|
451
|
+
# 빌드 성공 — 통과 (forcedPass 면 부채 고지 동반)
|
|
452
|
+
if [ -n "$DEBT_MSG" ]; then
|
|
453
|
+
RC_DEBT="$DEBT_MSG" python3 -c "
|
|
454
|
+
import json, os
|
|
455
|
+
print(json.dumps({'hookSpecificOutput':{'hookEventName':'PreToolUse','permissionDecision':'allow'},'systemMessage':os.environ['RC_DEBT']}))
|
|
456
|
+
"
|
|
457
|
+
exit 0
|
|
458
|
+
fi
|
|
361
459
|
echo '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow"}}'
|
package/hooks/session-start.sh
CHANGED
|
@@ -1,4 +1,32 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
|
+
# 메시지 생성 python 에 넘길 lib 경로 — 큰따옴표 문자열 안에 $(cd "$(dirname "$0")..) 를 중첩하면
|
|
3
|
+
# 따옴표가 깨져 python 이 죽고 fallback JSON 이 두 번 출력된다(파싱 불가 → 차단 무효). 한 번만 계산해 참조.
|
|
4
|
+
_RC_HOOK_LIB="$(cd "$(dirname "$0")/lib" 2>/dev/null && pwd)"
|
|
5
|
+
# 기준 HEAD 기록 — 진행 중인 태스크 창(tracker 비어있지 않음)이 없을 때만 이 세션의 시작 HEAD 를 갱신.
|
|
6
|
+
# (태스크 첫 Edit 이전의 Bash 커밋이 기준선으로 세탁되지 않게 — 채점기 baseline:true 검증 기준)
|
|
7
|
+
# compact/resume/clear 로 SessionStart 가 재발생할 때는 갱신하지 않는다 (작업 도중 Bash 커밋이 기준이 되는 것 차단)
|
|
8
|
+
_RC_SS_INPUT=""
|
|
9
|
+
if [ ! -t 0 ]; then _RC_SS_INPUT=$(cat); fi
|
|
10
|
+
RC_SS_INPUT="$_RC_SS_INPUT" RC_LIB="$_RC_HOOK_LIB" python3 -c "
|
|
11
|
+
import json, os, sys
|
|
12
|
+
sys.path.insert(0, os.environ.get('RC_LIB', ''))
|
|
13
|
+
try:
|
|
14
|
+
src = json.loads(os.environ.get('RC_SS_INPUT') or '{}').get('source', 'startup')
|
|
15
|
+
except Exception:
|
|
16
|
+
src = 'startup'
|
|
17
|
+
if src != 'startup':
|
|
18
|
+
sys.exit(0)
|
|
19
|
+
from attest_reader import record_task_heads
|
|
20
|
+
k = os.environ.get('ROUTINECODE_KNOWLEDGE_DIR') or os.path.expanduser('~/.routinecode/knowledge')
|
|
21
|
+
try:
|
|
22
|
+
active = bool(json.load(open(os.path.join(k, 'edit-tracker.json'))).get('files'))
|
|
23
|
+
except Exception:
|
|
24
|
+
active = False
|
|
25
|
+
if not active:
|
|
26
|
+
# cwd 가 레포가 아닌 워크스페이스(여러 레포 묶음)여도 하위 2단계 레포를 모두 기록
|
|
27
|
+
from attest_reader import git_repos_under
|
|
28
|
+
record_task_heads(git_repos_under(os.getcwd(), 3), overwrite=True, keep_if_dirty=True)
|
|
29
|
+
" >/dev/null 2>&1 || true
|
|
2
30
|
# SECURITY(R10): 예측/공유 /tmp 대신 per-user 0700 런타임 디렉터리(훅 간 좌표 유지, symlink race 차단)
|
|
3
31
|
RC_RUNDIR="${XDG_RUNTIME_DIR:-$HOME/.routinecode/run}"
|
|
4
32
|
if ! mkdir -p "$RC_RUNDIR" 2>/dev/null; then RC_RUNDIR="/tmp"; else chmod 700 "$RC_RUNDIR" 2>/dev/null; fi
|
|
@@ -45,7 +73,7 @@ for _hook in $CRITICAL_HOOKS; do
|
|
|
45
73
|
REPAIRED="${REPAIRED:+$REPAIRED, }$_hook"
|
|
46
74
|
else
|
|
47
75
|
_HOOK_MSG=$(python3 -c "
|
|
48
|
-
import sys;sys.path.insert(0,'$
|
|
76
|
+
import sys;sys.path.insert(0,'$_RC_HOOK_LIB')
|
|
49
77
|
try:
|
|
50
78
|
from i18n import t;print(t('session.hook_broken',hook='$_hook'))
|
|
51
79
|
except:print('CRITICAL: $_hook broken, manual fix needed (routinecode doctor)')
|
|
@@ -58,7 +86,7 @@ done
|
|
|
58
86
|
|
|
59
87
|
if [ -n "$REPAIRED" ]; then
|
|
60
88
|
_REPAIR_MSG=$(python3 -c "
|
|
61
|
-
import sys;sys.path.insert(0,'$
|
|
89
|
+
import sys;sys.path.insert(0,'$_RC_HOOK_LIB')
|
|
62
90
|
try:
|
|
63
91
|
from i18n import t;print(t('session.hook_repaired',hooks='$REPAIRED'))
|
|
64
92
|
except:print('Hook auto-repaired: $REPAIRED')
|
|
@@ -292,7 +320,7 @@ except: print('')
|
|
|
292
320
|
|
|
293
321
|
if $UPDATE_OK; then
|
|
294
322
|
UPDATE_MSG=$(python3 -c "
|
|
295
|
-
import sys;sys.path.insert(0,'$
|
|
323
|
+
import sys;sys.path.insert(0,'$_RC_HOOK_LIB')
|
|
296
324
|
try:
|
|
297
325
|
from i18n import t;print(t('session.updated',old='${INSTALLED_VERSION}',new='${LATEST_VERSION}'))
|
|
298
326
|
except:print('RoutineCode updated: ${INSTALLED_VERSION} -> ${LATEST_VERSION}')
|
|
@@ -309,7 +337,7 @@ except:
|
|
|
309
337
|
" 2>/dev/null
|
|
310
338
|
else
|
|
311
339
|
UPDATE_MSG=$(python3 -c "
|
|
312
|
-
import sys;sys.path.insert(0,'$
|
|
340
|
+
import sys;sys.path.insert(0,'$_RC_HOOK_LIB')
|
|
313
341
|
try:
|
|
314
342
|
from i18n import t;print(t('session.update_failed',old='${INSTALLED_VERSION}',new='${LATEST_VERSION}'))
|
|
315
343
|
except:print('RoutineCode update failed (${INSTALLED_VERSION} -> ${LATEST_VERSION}). If the log shows EACCES, npm cache has root-owned files. Run: npm install -g @routinecrew/routinecode@latest --@routinecrew:registry=https://registry.npmjs.org --cache \"\$(mktemp -d)\"')
|
|
@@ -378,6 +406,26 @@ try:
|
|
|
378
406
|
cmd = h.get('command', '')
|
|
379
407
|
existing_cmds.add(cmd.split('/')[-1] if '/' in cmd else cmd)
|
|
380
408
|
|
|
409
|
+
# MCP matcher 마이그레이션: 이미 등록된 훅도 matcher를 hooks-config 값으로 갱신한다.
|
|
410
|
+
# (구 matcher 'mcp__routinecode__x'는 대화형 세션 실제 도구명 'mcp__mcp-routinecode__x'에
|
|
411
|
+
# 매칭되지 않아 훅이 발화하지 않았다. 추가만 하던 동기화로는 기존 설치가 영구 미발화.)
|
|
412
|
+
desired_mcp = {}
|
|
413
|
+
for entry in entries:
|
|
414
|
+
m = entry.get('matcher', '')
|
|
415
|
+
if m.startswith('mcp__'):
|
|
416
|
+
for h in entry.get('hooks', []):
|
|
417
|
+
desired_mcp[h['command'].split('/')[-1]] = m
|
|
418
|
+
for entry in current_hooks[event_type]:
|
|
419
|
+
m = entry.get('matcher', '')
|
|
420
|
+
if not m.startswith('mcp__'):
|
|
421
|
+
continue
|
|
422
|
+
for h in entry.get('hooks', []):
|
|
423
|
+
want = desired_mcp.get(h.get('command', '').split('/')[-1])
|
|
424
|
+
if want and want != m:
|
|
425
|
+
entry['matcher'] = want
|
|
426
|
+
added += 1
|
|
427
|
+
break
|
|
428
|
+
|
|
381
429
|
for entry in entries:
|
|
382
430
|
resolved_hooks = []
|
|
383
431
|
for h in entry.get('hooks', []):
|
|
@@ -900,6 +948,60 @@ if [ -n "$CREDIT_MSG" ]; then
|
|
|
900
948
|
MESSAGES="${MESSAGES:+$MESSAGES | }${CREDIT_MSG}"
|
|
901
949
|
fi
|
|
902
950
|
|
|
951
|
+
# --- 2.8. Claude Code Compatibility Watch (CCW) — L0 탐지(동기 저비용·non-blocking) + CC 갱신 보조 ---
|
|
952
|
+
# 호스트(Claude Code) 버전 변화를 인지해 MCP/훅/에이전트/권한 표면 깨짐을 선제 탐지한다.
|
|
953
|
+
# 설계: docs2/CC-Compatibility-Watch.md. detect-only 는 네트워크 0·token 0, full 은 백그라운드.
|
|
954
|
+
CCW_SCAN="$HOOKS_DIR/lib/cc_compat_scan.py"
|
|
955
|
+
CCW_STATE="$HOME/.routinecode/cc-compat.json"
|
|
956
|
+
CCW_LOCK="$RC_RUNDIR/ccw-scan.lock" # 24h 디바운스
|
|
957
|
+
if [ -f "$CCW_SCAN" ] && command -v python3 >/dev/null 2>&1; then
|
|
958
|
+
CC_VER=""
|
|
959
|
+
if command -v claude >/dev/null 2>&1; then
|
|
960
|
+
CC_VER=$(claude --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
|
|
961
|
+
fi
|
|
962
|
+
# fallback: CLAUDE_CODE_EXECPATH 의 package.json
|
|
963
|
+
if [ -z "$CC_VER" ] && [ -n "$CLAUDE_CODE_EXECPATH" ]; then
|
|
964
|
+
_ccpkg="$(dirname "$CLAUDE_CODE_EXECPATH")/../package.json"
|
|
965
|
+
[ -f "$_ccpkg" ] && CC_VER=$(node -e "console.log(require('$_ccpkg').version)" 2>/dev/null)
|
|
966
|
+
fi
|
|
967
|
+
|
|
968
|
+
if [ -n "$CC_VER" ]; then
|
|
969
|
+
# L0: 네트워크 0 탐지 — 변화/behind 있으면 1줄 방출
|
|
970
|
+
CCW_MSG=$(CC_VER="$CC_VER" python3 "$CCW_SCAN" --detect-only 2>/dev/null)
|
|
971
|
+
if [ -n "$CCW_MSG" ]; then
|
|
972
|
+
MESSAGES="${MESSAGES:+$MESSAGES | }$CCW_MSG"
|
|
973
|
+
fi
|
|
974
|
+
|
|
975
|
+
# L1: running 버전이 아직 verified 가 아니면 백그라운드 풀스캔(24h lock 디바운스)
|
|
976
|
+
_ccw_state=$(python3 -c "import json;print(json.load(open('$CCW_STATE')).get('state',''))" 2>/dev/null)
|
|
977
|
+
if [ "$_ccw_state" != "verified" ] || [ ! -f "$CCW_STATE" ]; then
|
|
978
|
+
if [ ! -f "$CCW_LOCK" ] || find "$CCW_LOCK" -mmin +1440 2>/dev/null | grep -q .; then
|
|
979
|
+
touch "$CCW_LOCK"
|
|
980
|
+
( CC_VER="$CC_VER" python3 "$CCW_SCAN" --full >/dev/null 2>&1 ) &
|
|
981
|
+
disown
|
|
982
|
+
fi
|
|
983
|
+
fi
|
|
984
|
+
|
|
985
|
+
# CC 자동 갱신 보조: running < latestCC(캐시) 일 때만. 기본 넛지, opt-in 시 백그라운드 claude update.
|
|
986
|
+
_cc_behind=$(python3 -c "import json;print('1' if json.load(open('$CCW_STATE')).get('ccBehind') else '')" 2>/dev/null)
|
|
987
|
+
if [ -n "$_cc_behind" ]; then
|
|
988
|
+
# npm bin 쓰기권한 선점검 — root 소유 심링크면 갱신 불가, 복구 한 줄 넛지
|
|
989
|
+
_npm_bin="$(npm bin -g 2>/dev/null || echo "$(npm prefix -g 2>/dev/null)/bin")"
|
|
990
|
+
_cc_opt="${ROUTINECODE_CC_AUTOUPDATE:-}"
|
|
991
|
+
if [ -z "$_cc_opt" ] && [ -f "$RC_CONFIG" ]; then
|
|
992
|
+
_cc_opt=$(python3 -c "import json;print('on' if json.load(open('$RC_CONFIG')).get('ccAutoUpdate') else '')" 2>/dev/null)
|
|
993
|
+
fi
|
|
994
|
+
if [ -n "$_npm_bin" ] && [ ! -w "$_npm_bin" ]; then
|
|
995
|
+
MESSAGES="${MESSAGES:+$MESSAGES | }CC auto-update blocked: $_npm_bin not writable — run: sudo chown -h \"\$(whoami)\":admin $_npm_bin/claude"
|
|
996
|
+
elif [ "$_cc_opt" = "on" ]; then
|
|
997
|
+
# 호스트는 re-exec 불가 → 다음 CC 세션부터 반영. fail-silent.
|
|
998
|
+
( claude update >/dev/null 2>&1 ) &
|
|
999
|
+
disown
|
|
1000
|
+
fi
|
|
1001
|
+
fi
|
|
1002
|
+
fi
|
|
1003
|
+
fi
|
|
1004
|
+
|
|
903
1005
|
# --- 3. Quota check (Auth seeding 완료 후 활성화) ---
|
|
904
1006
|
if [ -f "$RC_CONFIG" ]; then
|
|
905
1007
|
QUOTA_MSG=$(python3 -c "
|
|
@@ -1001,7 +1103,9 @@ scores = []
|
|
|
1001
1103
|
for f in sorted(files)[-20:]:
|
|
1002
1104
|
try:
|
|
1003
1105
|
v = json.load(open(f))
|
|
1004
|
-
|
|
1106
|
+
s = v.get('currentScore', 0)
|
|
1107
|
+
if isinstance(s, (int, float)) and s >= 0: # -1 = advisory-only(게이트 점수 없음)
|
|
1108
|
+
scores.append(s)
|
|
1005
1109
|
except:
|
|
1006
1110
|
pass
|
|
1007
1111
|
if scores:
|