@ekkos/cli 1.2.17 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cache/capture.js +0 -0
- package/dist/commands/dashboard.js +57 -49
- package/dist/commands/hooks.d.ts +25 -36
- package/dist/commands/hooks.js +43 -615
- package/dist/commands/init.js +7 -23
- package/dist/commands/run.js +97 -11
- package/dist/commands/setup.js +10 -352
- package/dist/deploy/hooks.d.ts +8 -5
- package/dist/deploy/hooks.js +12 -105
- package/dist/deploy/settings.d.ts +8 -2
- package/dist/deploy/settings.js +22 -51
- package/dist/index.js +17 -39
- package/dist/utils/state.js +7 -2
- package/package.json +1 -1
- package/templates/CLAUDE.md +82 -292
- package/templates/cursor-rules/ekkos-memory.md +48 -108
- package/templates/windsurf-rules/ekkos-memory.md +62 -64
- package/templates/cursor-hooks/after-agent-response.sh +0 -117
- package/templates/cursor-hooks/before-submit-prompt.sh +0 -419
- package/templates/cursor-hooks/hooks.json +0 -20
- package/templates/cursor-hooks/lib/contract.sh +0 -320
- package/templates/cursor-hooks/stop.sh +0 -75
- package/templates/hooks/assistant-response.ps1 +0 -256
- package/templates/hooks/assistant-response.sh +0 -160
- package/templates/hooks/hooks.json +0 -40
- package/templates/hooks/lib/contract.sh +0 -332
- package/templates/hooks/lib/count-tokens.cjs +0 -86
- package/templates/hooks/lib/ekkos-reminders.sh +0 -98
- package/templates/hooks/lib/state.sh +0 -210
- package/templates/hooks/session-start.ps1 +0 -146
- package/templates/hooks/session-start.sh +0 -353
- package/templates/hooks/stop.ps1 +0 -349
- package/templates/hooks/stop.sh +0 -382
- package/templates/hooks/user-prompt-submit.ps1 +0 -419
- package/templates/hooks/user-prompt-submit.sh +0 -516
- package/templates/project-stubs/session-start.ps1 +0 -63
- package/templates/project-stubs/session-start.sh +0 -55
- package/templates/project-stubs/stop.ps1 +0 -63
- package/templates/project-stubs/stop.sh +0 -55
- package/templates/project-stubs/user-prompt-submit.ps1 +0 -63
- package/templates/project-stubs/user-prompt-submit.sh +0 -55
- package/templates/windsurf-hooks/README.md +0 -212
- package/templates/windsurf-hooks/hooks.json +0 -17
- package/templates/windsurf-hooks/install.sh +0 -148
- package/templates/windsurf-hooks/lib/contract.sh +0 -322
- package/templates/windsurf-hooks/post-cascade-response.sh +0 -251
- package/templates/windsurf-hooks/pre-user-prompt.sh +0 -435
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
3
|
-
# ekkOS_ Turn Contract Library
|
|
4
|
-
#
|
|
5
|
-
# Shared functions for Golden Loop compliance enforcement.
|
|
6
|
-
# Used by BOTH Claude Code (.claude/) and Cursor (.cursor/) hooks.
|
|
7
|
-
#
|
|
8
|
-
# TURN CONTRACT: Evidence that retrieval occurred before answering.
|
|
9
|
-
# This is the SINGLE SOURCE OF TRUTH for compliance auditing.
|
|
10
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
11
|
-
|
|
12
|
-
# Get contract directory based on environment
|
|
13
|
-
get_contract_dir() {
|
|
14
|
-
local source="${1:-claude-code}"
|
|
15
|
-
local project_root="${2:-$PROJECT_ROOT}"
|
|
16
|
-
|
|
17
|
-
if [ "$source" = "cursor" ]; then
|
|
18
|
-
echo "$project_root/.cursor/state/ekkos"
|
|
19
|
-
else
|
|
20
|
-
echo "$project_root/.claude/state/ekkos"
|
|
21
|
-
fi
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
# Generate stable hash of user prompt (for deduplication)
|
|
25
|
-
generate_query_hash() {
|
|
26
|
-
local query="$1"
|
|
27
|
-
# Use md5 on macOS, md5sum on Linux
|
|
28
|
-
if command -v md5 >/dev/null 2>&1; then
|
|
29
|
-
echo -n "$query" | md5 | cut -c1-16
|
|
30
|
-
elif command -v md5sum >/dev/null 2>&1; then
|
|
31
|
-
echo -n "$query" | md5sum | cut -c1-16
|
|
32
|
-
else
|
|
33
|
-
# Fallback: simple hash using cksum
|
|
34
|
-
echo -n "$query" | cksum | cut -d' ' -f1
|
|
35
|
-
fi
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
# Write turn contract at RETRIEVAL time
|
|
39
|
-
# This is the EVIDENCE that retrieval happened before answering
|
|
40
|
-
write_turn_contract() {
|
|
41
|
-
local session_id="$1"
|
|
42
|
-
local retrieval_ok="$2"
|
|
43
|
-
local retrieval_source="$3"
|
|
44
|
-
local pattern_ids="$4" # Comma-separated list
|
|
45
|
-
local directive_ids="$5" # Comma-separated list
|
|
46
|
-
local query_hash="$6"
|
|
47
|
-
local project_root="${7:-$PROJECT_ROOT}"
|
|
48
|
-
|
|
49
|
-
local contract_dir
|
|
50
|
-
contract_dir=$(get_contract_dir "$retrieval_source" "$project_root")
|
|
51
|
-
mkdir -p "$contract_dir" 2>/dev/null || return 1
|
|
52
|
-
|
|
53
|
-
local contract_file="$contract_dir/turn-contract-${session_id}.json"
|
|
54
|
-
local timestamp
|
|
55
|
-
timestamp=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
|
56
|
-
|
|
57
|
-
# Convert comma-separated IDs to JSON array
|
|
58
|
-
local pattern_array
|
|
59
|
-
local directive_array
|
|
60
|
-
if [ -n "$pattern_ids" ]; then
|
|
61
|
-
pattern_array=$(echo "$pattern_ids" | tr ',' '\n' | grep -v '^$' | jq -R . | jq -s .)
|
|
62
|
-
else
|
|
63
|
-
pattern_array="[]"
|
|
64
|
-
fi
|
|
65
|
-
if [ -n "$directive_ids" ]; then
|
|
66
|
-
directive_array=$(echo "$directive_ids" | tr ',' '\n' | grep -v '^$' | jq -R . | jq -s .)
|
|
67
|
-
else
|
|
68
|
-
directive_array="[]"
|
|
69
|
-
fi
|
|
70
|
-
|
|
71
|
-
# Write contract
|
|
72
|
-
cat > "$contract_file" << EOF
|
|
73
|
-
{
|
|
74
|
-
"session_id": "$session_id",
|
|
75
|
-
"retrieval_ok": $retrieval_ok,
|
|
76
|
-
"retrieval_source": "$retrieval_source",
|
|
77
|
-
"retrieved_pattern_ids": $pattern_array,
|
|
78
|
-
"retrieved_directive_ids": $directive_array,
|
|
79
|
-
"timestamp": "$timestamp",
|
|
80
|
-
"query_hash": "$query_hash",
|
|
81
|
-
"ekkos_strict": ${EKKOS_STRICT:-0}
|
|
82
|
-
}
|
|
83
|
-
EOF
|
|
84
|
-
|
|
85
|
-
return 0
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
# Read turn contract
|
|
89
|
-
read_turn_contract() {
|
|
90
|
-
local session_id="$1"
|
|
91
|
-
local retrieval_source="$2"
|
|
92
|
-
local project_root="${3:-$PROJECT_ROOT}"
|
|
93
|
-
|
|
94
|
-
local contract_dir
|
|
95
|
-
contract_dir=$(get_contract_dir "$retrieval_source" "$project_root")
|
|
96
|
-
local contract_file="$contract_dir/turn-contract-${session_id}.json"
|
|
97
|
-
|
|
98
|
-
if [ -f "$contract_file" ]; then
|
|
99
|
-
cat "$contract_file"
|
|
100
|
-
return 0
|
|
101
|
-
else
|
|
102
|
-
return 1
|
|
103
|
-
fi
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
# Extract field from contract JSON
|
|
107
|
-
get_contract_field() {
|
|
108
|
-
local contract_json="$1"
|
|
109
|
-
local field="$2"
|
|
110
|
-
|
|
111
|
-
echo "$contract_json" | jq -r ".$field // \"\"" 2>/dev/null
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
# Get array field as comma-separated string
|
|
115
|
-
get_contract_array() {
|
|
116
|
-
local contract_json="$1"
|
|
117
|
-
local field="$2"
|
|
118
|
-
|
|
119
|
-
echo "$contract_json" | jq -r ".$field // [] | join(\",\")" 2>/dev/null
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
# Cleanup turn contract (only after successful capture)
|
|
123
|
-
cleanup_turn_contract() {
|
|
124
|
-
local session_id="$1"
|
|
125
|
-
local retrieval_source="$2"
|
|
126
|
-
local project_root="${3:-$PROJECT_ROOT}"
|
|
127
|
-
|
|
128
|
-
local contract_dir
|
|
129
|
-
contract_dir=$(get_contract_dir "$retrieval_source" "$project_root")
|
|
130
|
-
local contract_file="$contract_dir/turn-contract-${session_id}.json"
|
|
131
|
-
|
|
132
|
-
rm -f "$contract_file" 2>/dev/null
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
# Check if strict mode is enabled
|
|
136
|
-
is_strict_mode() {
|
|
137
|
-
[ "${EKKOS_STRICT:-0}" = "1" ]
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
# Generate strict mode blocker message for Claude Code
|
|
141
|
-
get_strict_blocker_message() {
|
|
142
|
-
cat << 'EOF'
|
|
143
|
-
════════════════════════════════════════════════════════════════════════════
|
|
144
|
-
⛔ EKKOS_STRICT MODE: RETRIEVAL FAILED — DO NOT ANSWER
|
|
145
|
-
|
|
146
|
-
ekkOS memory retrieval failed or was not authenticated.
|
|
147
|
-
In STRICT mode, you MUST NOT answer technical questions without memory context.
|
|
148
|
-
|
|
149
|
-
ACTION REQUIRED:
|
|
150
|
-
1. Check if ekkOS is connected: Run `ekkOS: Connect` in VS Code
|
|
151
|
-
2. Verify auth token exists: ~/.ekkos/config.json
|
|
152
|
-
3. Retry the request after connecting
|
|
153
|
-
|
|
154
|
-
DO NOT proceed with answering. The Golden Loop requires retrieval FIRST.
|
|
155
|
-
════════════════════════════════════════════════════════════════════════════
|
|
156
|
-
EOF
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
# Validate PatternGuard coverage (returns 0-100)
|
|
160
|
-
calculate_pattern_guard_coverage() {
|
|
161
|
-
local assistant_response="$1"
|
|
162
|
-
local pattern_ids="$2" # Comma-separated
|
|
163
|
-
|
|
164
|
-
# Count total patterns
|
|
165
|
-
local total_count
|
|
166
|
-
total_count=$(echo "$pattern_ids" | tr ',' '\n' | grep -c '.' || echo 0)
|
|
167
|
-
|
|
168
|
-
if [ "$total_count" -eq 0 ]; then
|
|
169
|
-
echo "100" # No patterns = 100% coverage by definition
|
|
170
|
-
return 0
|
|
171
|
-
fi
|
|
172
|
-
|
|
173
|
-
# Extract acknowledged IDs from [ekkOS_SELECT] and [ekkOS_SKIP] blocks
|
|
174
|
-
local acknowledged_count=0
|
|
175
|
-
|
|
176
|
-
# Check SELECT block
|
|
177
|
-
local select_block
|
|
178
|
-
select_block=$(echo "$assistant_response" | grep -ozP '\[ekkOS_SELECT\][\s\S]*?\[/ekkOS_SELECT\]' 2>/dev/null | tr '\0' '\n' || true)
|
|
179
|
-
if [ -n "$select_block" ]; then
|
|
180
|
-
local select_count
|
|
181
|
-
select_count=$(echo "$select_block" | grep -oE 'id:\s*[a-f0-9-]+' | wc -l | tr -d ' ')
|
|
182
|
-
acknowledged_count=$((acknowledged_count + select_count))
|
|
183
|
-
fi
|
|
184
|
-
|
|
185
|
-
# Check SKIP block
|
|
186
|
-
local skip_block
|
|
187
|
-
skip_block=$(echo "$assistant_response" | grep -ozP '\[ekkOS_SKIP\][\s\S]*?\[/ekkOS_SKIP\]' 2>/dev/null | tr '\0' '\n' || true)
|
|
188
|
-
if [ -n "$skip_block" ]; then
|
|
189
|
-
local skip_count
|
|
190
|
-
skip_count=$(echo "$skip_block" | grep -oE 'id:\s*[a-f0-9-]+' | wc -l | tr -d ' ')
|
|
191
|
-
acknowledged_count=$((acknowledged_count + skip_count))
|
|
192
|
-
fi
|
|
193
|
-
|
|
194
|
-
# Legacy: Check for [ekkOS_APPLY] markers (fallback)
|
|
195
|
-
if [ "$acknowledged_count" -eq 0 ]; then
|
|
196
|
-
local apply_count
|
|
197
|
-
apply_count=$(echo "$assistant_response" | grep -c '\[ekkOS_APPLY\]' || echo 0)
|
|
198
|
-
acknowledged_count=$apply_count
|
|
199
|
-
fi
|
|
200
|
-
|
|
201
|
-
# Calculate coverage percentage
|
|
202
|
-
local coverage
|
|
203
|
-
coverage=$((acknowledged_count * 100 / total_count))
|
|
204
|
-
|
|
205
|
-
# Cap at 100%
|
|
206
|
-
if [ "$coverage" -gt 100 ]; then
|
|
207
|
-
coverage=100
|
|
208
|
-
fi
|
|
209
|
-
|
|
210
|
-
echo "$coverage"
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
# Check for ekkOS footer presence
|
|
214
|
-
check_footer_present() {
|
|
215
|
-
local assistant_response="$1"
|
|
216
|
-
|
|
217
|
-
# Look for the mandatory footer format:
|
|
218
|
-
# 🧠 **ekkOS_™** · 📅 YYYY-MM-DD
|
|
219
|
-
# OR
|
|
220
|
-
# {IDE} ({Model}) · 🧠 **ekkOS_™** · 📅 {Timestamp}
|
|
221
|
-
|
|
222
|
-
if echo "$assistant_response" | grep -qE '🧠.*ekkOS.*📅.*[0-9]{4}-[0-9]{2}-[0-9]{2}'; then
|
|
223
|
-
echo "true"
|
|
224
|
-
return 0
|
|
225
|
-
else
|
|
226
|
-
echo "false"
|
|
227
|
-
return 1
|
|
228
|
-
fi
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
# Build compliance metadata for capture
|
|
232
|
-
build_compliance_metadata() {
|
|
233
|
-
local retrieval_ok="$1"
|
|
234
|
-
local pattern_guard_coverage="$2"
|
|
235
|
-
local footer_present="$3"
|
|
236
|
-
local ekkos_strict="$4"
|
|
237
|
-
local retrieved_count="$5"
|
|
238
|
-
|
|
239
|
-
local pattern_guard_required="false"
|
|
240
|
-
if [ "$retrieved_count" -gt 0 ]; then
|
|
241
|
-
pattern_guard_required="true"
|
|
242
|
-
fi
|
|
243
|
-
|
|
244
|
-
cat << EOF
|
|
245
|
-
{
|
|
246
|
-
"retrieval_ok": $retrieval_ok,
|
|
247
|
-
"pattern_guard_required": $pattern_guard_required,
|
|
248
|
-
"pattern_guard_coverage_pct": $pattern_guard_coverage,
|
|
249
|
-
"footer_present": $footer_present,
|
|
250
|
-
"ekkos_strict": $ekkos_strict,
|
|
251
|
-
"retrieved_count": $retrieved_count,
|
|
252
|
-
"compliance_version": "1.0"
|
|
253
|
-
}
|
|
254
|
-
EOF
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
# Determine if turn is compliant
|
|
258
|
-
is_turn_compliant() {
|
|
259
|
-
local retrieval_ok="$1"
|
|
260
|
-
local pattern_guard_coverage="$2"
|
|
261
|
-
local footer_present="$3"
|
|
262
|
-
local pattern_count="$4"
|
|
263
|
-
|
|
264
|
-
# Retrieval must have succeeded
|
|
265
|
-
if [ "$retrieval_ok" != "true" ]; then
|
|
266
|
-
echo "false"
|
|
267
|
-
return 1
|
|
268
|
-
fi
|
|
269
|
-
|
|
270
|
-
# If patterns were retrieved, PatternGuard must be 100%
|
|
271
|
-
if [ "$pattern_count" -gt 0 ] && [ "$pattern_guard_coverage" -lt 100 ]; then
|
|
272
|
-
echo "false"
|
|
273
|
-
return 1
|
|
274
|
-
fi
|
|
275
|
-
|
|
276
|
-
# Footer must be present
|
|
277
|
-
if [ "$footer_present" != "true" ]; then
|
|
278
|
-
echo "false"
|
|
279
|
-
return 1
|
|
280
|
-
fi
|
|
281
|
-
|
|
282
|
-
echo "true"
|
|
283
|
-
return 0
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
# Generate violation reason
|
|
287
|
-
get_violation_reason() {
|
|
288
|
-
local retrieval_ok="$1"
|
|
289
|
-
local pattern_guard_coverage="$2"
|
|
290
|
-
local footer_present="$3"
|
|
291
|
-
local pattern_count="$4"
|
|
292
|
-
|
|
293
|
-
local reasons=""
|
|
294
|
-
|
|
295
|
-
if [ "$retrieval_ok" != "true" ]; then
|
|
296
|
-
reasons="retrieval_failed"
|
|
297
|
-
fi
|
|
298
|
-
|
|
299
|
-
if [ "$pattern_count" -gt 0 ] && [ "$pattern_guard_coverage" -lt 100 ]; then
|
|
300
|
-
if [ -n "$reasons" ]; then
|
|
301
|
-
reasons="$reasons,pattern_guard_incomplete"
|
|
302
|
-
else
|
|
303
|
-
reasons="pattern_guard_incomplete"
|
|
304
|
-
fi
|
|
305
|
-
fi
|
|
306
|
-
|
|
307
|
-
if [ "$footer_present" != "true" ]; then
|
|
308
|
-
if [ -n "$reasons" ]; then
|
|
309
|
-
reasons="$reasons,footer_missing"
|
|
310
|
-
else
|
|
311
|
-
reasons="footer_missing"
|
|
312
|
-
fi
|
|
313
|
-
fi
|
|
314
|
-
|
|
315
|
-
if [ -z "$reasons" ]; then
|
|
316
|
-
reasons="none"
|
|
317
|
-
fi
|
|
318
|
-
|
|
319
|
-
echo "$reasons"
|
|
320
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
3
|
-
# ekkOS_ Hook: Stop (Cursor Agent Mode)
|
|
4
|
-
#
|
|
5
|
-
# Fires when agent iteration completes. Can:
|
|
6
|
-
# 1. Clear Time Machine consumed flag (allow new requests)
|
|
7
|
-
# 2. Capture session summary
|
|
8
|
-
# 3. Optionally submit follow-up message
|
|
9
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
10
|
-
|
|
11
|
-
set +e
|
|
12
|
-
|
|
13
|
-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
14
|
-
PROJECT_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")"
|
|
15
|
-
STATE_DIR="$PROJECT_ROOT/.cursor/state"
|
|
16
|
-
|
|
17
|
-
# Read JSON input
|
|
18
|
-
INPUT=$(cat)
|
|
19
|
-
|
|
20
|
-
# Extract status
|
|
21
|
-
STATUS=$(echo "$INPUT" | jq -r '.status // "unknown"' 2>/dev/null || echo "unknown")
|
|
22
|
-
LOOP_COUNT=$(echo "$INPUT" | jq -r '.loop_count // 0' 2>/dev/null || echo "0")
|
|
23
|
-
|
|
24
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
25
|
-
# Clear Time Machine flag on session end (allow new requests next session)
|
|
26
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
27
|
-
if [ "$STATUS" = "completed" ] || [ "$STATUS" = "aborted" ]; then
|
|
28
|
-
rm -f "$STATE_DIR/time-machine-consumed.flag" 2>/dev/null || true
|
|
29
|
-
fi
|
|
30
|
-
|
|
31
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
32
|
-
# Optional: Load auth for session summary
|
|
33
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
34
|
-
EKKOS_CONFIG="$HOME/.ekkos/config.json"
|
|
35
|
-
AUTH_TOKEN=""
|
|
36
|
-
USER_ID=""
|
|
37
|
-
|
|
38
|
-
if [ -f "$EKKOS_CONFIG" ]; then
|
|
39
|
-
AUTH_TOKEN=$(jq -r '.hookApiKey // .apiKey // ""' "$EKKOS_CONFIG" 2>/dev/null || echo "")
|
|
40
|
-
USER_ID=$(jq -r '.userId // ""' "$EKKOS_CONFIG" 2>/dev/null || echo "")
|
|
41
|
-
fi
|
|
42
|
-
|
|
43
|
-
if [ -z "$AUTH_TOKEN" ] && [ -f "$PROJECT_ROOT/.env.local" ]; then
|
|
44
|
-
AUTH_TOKEN=$(grep -E "^SUPABASE_SECRET_KEY=" "$PROJECT_ROOT/.env.local" | cut -d'=' -f2- | tr -d '"' | tr -d "'" | tr -d '\r')
|
|
45
|
-
fi
|
|
46
|
-
|
|
47
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
48
|
-
# Log session end (fire and forget)
|
|
49
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
50
|
-
if [ -n "$AUTH_TOKEN" ]; then
|
|
51
|
-
SESSION_ID=""
|
|
52
|
-
if [ -f "$STATE_DIR/current_session_id.txt" ]; then
|
|
53
|
-
SESSION_ID=$(cat "$STATE_DIR/current_session_id.txt" 2>/dev/null || echo "")
|
|
54
|
-
fi
|
|
55
|
-
|
|
56
|
-
TURN_COUNT=0
|
|
57
|
-
TURN_FILE="$STATE_DIR/turn_${SESSION_ID}.txt"
|
|
58
|
-
if [ -f "$TURN_FILE" ]; then
|
|
59
|
-
TURN_COUNT=$(cat "$TURN_FILE" 2>/dev/null || echo "0")
|
|
60
|
-
fi
|
|
61
|
-
|
|
62
|
-
# Could capture session end event here
|
|
63
|
-
# For now, just clean up
|
|
64
|
-
|
|
65
|
-
# Clean up turn counter for next session
|
|
66
|
-
# (commented out - might want to persist across agent runs)
|
|
67
|
-
# rm -f "$TURN_FILE" 2>/dev/null || true
|
|
68
|
-
fi
|
|
69
|
-
|
|
70
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
71
|
-
# Return empty response (no follow-up)
|
|
72
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
73
|
-
echo '{}'
|
|
74
|
-
|
|
75
|
-
exit 0
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
2
|
-
# ekkOS_ Hook: AssistantResponse - Process Claude's response (Windows)
|
|
3
|
-
# MANAGED BY ekkos-connect - DO NOT EDIT DIRECTLY
|
|
4
|
-
# EKKOS_MANAGED=1
|
|
5
|
-
# EKKOS_MANIFEST_SHA256=<computed-at-build>
|
|
6
|
-
# EKKOS_TEMPLATE_VERSION=1.0.0
|
|
7
|
-
#
|
|
8
|
-
# Per ekkOS Onboarding Spec v1.2 FINAL + ADDENDUM:
|
|
9
|
-
# - All persisted records MUST include: instanceId, sessionId, sessionName
|
|
10
|
-
# - Uses EKKOS_INSTANCE_ID env var for multi-session isolation
|
|
11
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
12
|
-
|
|
13
|
-
$ErrorActionPreference = "SilentlyContinue"
|
|
14
|
-
|
|
15
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
16
|
-
# CONFIG PATHS - No hardcoded word arrays per spec v1.2 Addendum
|
|
17
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
18
|
-
$EkkosConfigDir = if ($env:EKKOS_CONFIG_DIR) { $env:EKKOS_CONFIG_DIR } else { "$env:USERPROFILE\.ekkos" }
|
|
19
|
-
$HooksEnabledJson = "$EkkosConfigDir\hooks-enabled.json"
|
|
20
|
-
$HooksEnabledDefault = "$EkkosConfigDir\.defaults\hooks-enabled.json"
|
|
21
|
-
$SessionWordsJson = "$EkkosConfigDir\session-words.json"
|
|
22
|
-
$SessionWordsDefault = "$EkkosConfigDir\.defaults\session-words.json"
|
|
23
|
-
|
|
24
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
25
|
-
# INSTANCE ID - Multi-session isolation per v1.2 ADDENDUM
|
|
26
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
27
|
-
$EkkosInstanceId = if ($env:EKKOS_INSTANCE_ID) { $env:EKKOS_INSTANCE_ID } else { "default" }
|
|
28
|
-
|
|
29
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
30
|
-
# CHECK ENABLEMENT - Respect hooks-enabled.json
|
|
31
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
32
|
-
function Test-HookEnabled {
|
|
33
|
-
param([string]$HookName)
|
|
34
|
-
|
|
35
|
-
$enabledFile = $HooksEnabledJson
|
|
36
|
-
if (-not (Test-Path $enabledFile)) {
|
|
37
|
-
$enabledFile = $HooksEnabledDefault
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (-not (Test-Path $enabledFile)) {
|
|
41
|
-
# No enablement file = all enabled by default
|
|
42
|
-
return $true
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
$config = Get-Content $enabledFile -Raw | ConvertFrom-Json
|
|
47
|
-
|
|
48
|
-
# Check claude.enabled array
|
|
49
|
-
if ($config.claude -and $config.claude.enabled) {
|
|
50
|
-
$enabledHooks = $config.claude.enabled
|
|
51
|
-
if ($enabledHooks -contains $HookName -or $enabledHooks -contains "assistant-response") {
|
|
52
|
-
return $true
|
|
53
|
-
}
|
|
54
|
-
return $false
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return $true # Default to enabled if no config
|
|
58
|
-
} catch {
|
|
59
|
-
return $true # Default to enabled on error
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
# Check if this hook is enabled
|
|
64
|
-
if (-not (Test-HookEnabled "assistant-response")) {
|
|
65
|
-
exit 0
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
69
|
-
# Load session words from JSON file - NO HARDCODED ARRAYS
|
|
70
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
71
|
-
$script:SessionWords = $null
|
|
72
|
-
|
|
73
|
-
function Load-SessionWords {
|
|
74
|
-
$wordsFile = $SessionWordsJson
|
|
75
|
-
|
|
76
|
-
# Fallback to managed defaults if user file missing/invalid
|
|
77
|
-
if (-not (Test-Path $wordsFile)) {
|
|
78
|
-
$wordsFile = $SessionWordsDefault
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (-not (Test-Path $wordsFile)) {
|
|
82
|
-
return $null
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
$script:SessionWords = Get-Content $wordsFile -Raw | ConvertFrom-Json
|
|
87
|
-
} catch {
|
|
88
|
-
return $null
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
93
|
-
# SESSION NAME (UUID to words) - Uses external session-words.json
|
|
94
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
95
|
-
function Convert-UuidToWords {
|
|
96
|
-
param([string]$uuid)
|
|
97
|
-
|
|
98
|
-
# Load session words if not already loaded
|
|
99
|
-
if (-not $script:SessionWords) {
|
|
100
|
-
Load-SessionWords
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
# Handle missing session words gracefully
|
|
104
|
-
if (-not $script:SessionWords) {
|
|
105
|
-
return "unknown-session"
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
$adjectives = $script:SessionWords.adjectives
|
|
109
|
-
$nouns = $script:SessionWords.nouns
|
|
110
|
-
$verbs = $script:SessionWords.verbs
|
|
111
|
-
|
|
112
|
-
if (-not $adjectives -or -not $nouns -or -not $verbs) {
|
|
113
|
-
return "unknown-session"
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (-not $uuid -or $uuid -eq "unknown") { return "unknown-session" }
|
|
117
|
-
|
|
118
|
-
$clean = $uuid -replace "-", ""
|
|
119
|
-
if ($clean.Length -lt 12) { return "unknown-session" }
|
|
120
|
-
|
|
121
|
-
try {
|
|
122
|
-
$a = [Convert]::ToInt32($clean.Substring(0,4), 16) % $adjectives.Length
|
|
123
|
-
$n = [Convert]::ToInt32($clean.Substring(4,4), 16) % $nouns.Length
|
|
124
|
-
$an = [Convert]::ToInt32($clean.Substring(8,4), 16) % $verbs.Length
|
|
125
|
-
|
|
126
|
-
return "$($adjectives[$a])-$($nouns[$n])-$($verbs[$an])"
|
|
127
|
-
} catch {
|
|
128
|
-
return "unknown-session"
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
133
|
-
# READ INPUT
|
|
134
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
135
|
-
$inputJson = [Console]::In.ReadToEnd()
|
|
136
|
-
if (-not $inputJson) { exit 0 }
|
|
137
|
-
|
|
138
|
-
try {
|
|
139
|
-
$input = $inputJson | ConvertFrom-Json
|
|
140
|
-
} catch {
|
|
141
|
-
exit 0
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
# Extract response content
|
|
145
|
-
$assistantResponse = $input.response
|
|
146
|
-
if (-not $assistantResponse) { $assistantResponse = $input.message }
|
|
147
|
-
if (-not $assistantResponse) { $assistantResponse = $input.content }
|
|
148
|
-
if (-not $assistantResponse) { exit 0 }
|
|
149
|
-
|
|
150
|
-
# Get session ID
|
|
151
|
-
$rawSessionId = $input.session_id
|
|
152
|
-
if (-not $rawSessionId -or $rawSessionId -eq "null") { $rawSessionId = "unknown" }
|
|
153
|
-
|
|
154
|
-
# Fallback: read session_id from saved state
|
|
155
|
-
if ($rawSessionId -eq "unknown") {
|
|
156
|
-
$stateFile = Join-Path $env:USERPROFILE ".claude\state\current-session.json"
|
|
157
|
-
if (Test-Path $stateFile) {
|
|
158
|
-
try {
|
|
159
|
-
$state = Get-Content $stateFile -Raw | ConvertFrom-Json
|
|
160
|
-
$rawSessionId = $state.session_id
|
|
161
|
-
} catch {}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
$sessionName = Convert-UuidToWords $rawSessionId
|
|
166
|
-
|
|
167
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
168
|
-
# READ TURN STATE
|
|
169
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
170
|
-
$stateFile = Join-Path $env:USERPROFILE ".claude\state\hook-state.json"
|
|
171
|
-
$turn = 0
|
|
172
|
-
|
|
173
|
-
if (Test-Path $stateFile) {
|
|
174
|
-
try {
|
|
175
|
-
$hookState = Get-Content $stateFile -Raw | ConvertFrom-Json
|
|
176
|
-
$turn = [int]$hookState.turn
|
|
177
|
-
} catch {
|
|
178
|
-
$turn = 0
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
183
|
-
# PATTERN TRACKING (detect [ekkOS_SELECT] blocks)
|
|
184
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
185
|
-
$patternIds = @()
|
|
186
|
-
if ($assistantResponse -match '\[ekkOS_SELECT\]') {
|
|
187
|
-
# Extract pattern IDs from SELECT blocks
|
|
188
|
-
$selectMatches = [regex]::Matches($assistantResponse, 'id:\s*([a-zA-Z0-9\-_]+)')
|
|
189
|
-
foreach ($match in $selectMatches) {
|
|
190
|
-
$patternIds += $match.Groups[1].Value
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
195
|
-
# LOCAL CACHE: Tier 0 capture (async, non-blocking)
|
|
196
|
-
# Per v1.2 ADDENDUM: Pass instanceId for namespacing
|
|
197
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
198
|
-
$captureCmd = Get-Command "ekkos-capture" -ErrorAction SilentlyContinue
|
|
199
|
-
if ($captureCmd -and $rawSessionId -ne "unknown") {
|
|
200
|
-
try {
|
|
201
|
-
# NEW format: ekkos-capture response <instance_id> <session_id> <turn_id> <response> [tools] [files]
|
|
202
|
-
$responseBase64 = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($assistantResponse))
|
|
203
|
-
$toolsJson = "[]"
|
|
204
|
-
$filesJson = "[]"
|
|
205
|
-
|
|
206
|
-
# Extract tools used from response
|
|
207
|
-
$toolMatches = [regex]::Matches($assistantResponse, '\[TOOL:\s*([^\]]+)\]')
|
|
208
|
-
if ($toolMatches.Count -gt 0) {
|
|
209
|
-
$tools = $toolMatches | ForEach-Object { $_.Groups[1].Value } | Select-Object -Unique
|
|
210
|
-
$toolsJson = $tools | ConvertTo-Json -Depth 10 -Compress
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
Start-Job -ScriptBlock {
|
|
214
|
-
param($instanceId, $sessionId, $turnNum, $responseB64, $tools, $files)
|
|
215
|
-
try {
|
|
216
|
-
$decoded = [System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($responseB64))
|
|
217
|
-
& ekkos-capture response $instanceId $sessionId $turnNum $decoded $tools $files 2>&1 | Out-Null
|
|
218
|
-
} catch {}
|
|
219
|
-
} -ArgumentList $EkkosInstanceId, $rawSessionId, $turn, $responseBase64, $toolsJson, $filesJson | Out-Null
|
|
220
|
-
} catch {}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
224
|
-
# WORKING MEMORY: Fast capture to API (async, non-blocking)
|
|
225
|
-
# ═══════════════════════════════════════════════════════════════════════════
|
|
226
|
-
$configFile = Join-Path $EkkosConfigDir "config.json"
|
|
227
|
-
if (Test-Path $configFile) {
|
|
228
|
-
try {
|
|
229
|
-
$config = Get-Content $configFile -Raw | ConvertFrom-Json
|
|
230
|
-
$captureToken = $config.hookApiKey
|
|
231
|
-
if (-not $captureToken) { $captureToken = $config.apiKey }
|
|
232
|
-
|
|
233
|
-
if ($captureToken) {
|
|
234
|
-
Start-Job -ScriptBlock {
|
|
235
|
-
param($token, $instanceId, $sessionId, $sessionName, $turnNum, $response, $patterns)
|
|
236
|
-
$body = @{
|
|
237
|
-
session_id = $sessionId
|
|
238
|
-
session_name = $sessionName
|
|
239
|
-
instance_id = $instanceId
|
|
240
|
-
turn = $turnNum
|
|
241
|
-
response = $response.Substring(0, [Math]::Min(5000, $response.Length))
|
|
242
|
-
pattern_ids = $patterns
|
|
243
|
-
} | ConvertTo-Json -Depth 10
|
|
244
|
-
|
|
245
|
-
Invoke-RestMethod -Uri "https://mcp.ekkos.dev/api/v1/working/turn" `
|
|
246
|
-
-Method POST `
|
|
247
|
-
-Headers @{ Authorization = "Bearer $token" } `
|
|
248
|
-
-ContentType "application/json" `
|
|
249
|
-
-Body ([System.Text.Encoding]::UTF8.GetBytes($body)) -ErrorAction SilentlyContinue
|
|
250
|
-
} -ArgumentList $captureToken, $EkkosInstanceId, $rawSessionId, $sessionName, $turn, $assistantResponse, $patternIds | Out-Null
|
|
251
|
-
}
|
|
252
|
-
} catch {}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
# Silent exit - assistant-response hook should not produce output
|
|
256
|
-
exit 0
|