Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 08:48:35 +08:00
commit 6f1ef3ef54
45 changed files with 15173 additions and 0 deletions

130
skills/telemetry-report.md Normal file
View File

@@ -0,0 +1,130 @@
# Telemetry Report Skill
Track agent activity and report to telemetry system for meta-learning.
## Report Agent Invocation
Note: The actual telemetry collection happens automatically via hooks (SubagentStop hook).
This skill provides utility functions for commands to access telemetry data.
```bash
# Read current session's agent invocations
# The SubagentStop hook automatically records agent names to session state
if [ -n "$SESSION_ID" ]; then
SESSION_FILE="plugins/psd-claude-coding-system/meta/.session_state_${SESSION_ID}"
if [ -f "$SESSION_FILE" ]; then
AGENTS_INVOKED=$(grep "^AGENTS=" "$SESSION_FILE" | cut -d= -f2)
echo "Agents invoked this session: $AGENTS_INVOKED"
fi
fi
```
## Query Telemetry for Patterns
```bash
# Check which agents work well together
# Useful for meta-learning and optimization
TELEMETRY_FILE="plugins/psd-claude-coding-system/meta/telemetry.json"
if [ -f "$TELEMETRY_FILE" ] && command -v jq &> /dev/null; then
# Find most common agent combinations for /work command
echo "=== Most Common Agent Combinations for /work ==="
jq -r '.executions[] | select(.command == "work") | .agents_invoked | join(",")' "$TELEMETRY_FILE" \
| sort | uniq -c | sort -rn | head -5
# Find average duration by command
echo -e "\n=== Average Duration by Command ==="
jq -r '.executions | group_by(.command) | map({command: .[0].command, avg_duration: (map(.duration_ms) | add / length)}) | .[]' "$TELEMETRY_FILE"
# Find commands with highest success rate
echo -e "\n=== Success Rates by Command ==="
jq -r '.executions | group_by(.command) | map({command: .[0].command, success_rate: ((map(select(.success == true)) | length) / length * 100)}) | .[]' "$TELEMETRY_FILE"
fi
```
## Track Parallel Execution
```bash
# When invoking multiple agents in parallel, track the pattern
if [ -n "$SESSION_ID" ]; then
SESSION_FILE="plugins/psd-claude-coding-system/meta/.session_state_${SESSION_ID}"
# Mark that this session used parallel execution
echo "PARALLEL=true" >> "$SESSION_FILE"
# Track which agents ran in parallel
echo "PARALLEL_GROUP=$AGENT_LIST" >> "$SESSION_FILE"
# The Stop hook will read these and add to telemetry.json
fi
```
## Get Recommendations from History
```bash
# Based on current issue/context, get recommendations for which agents to invoke
if [ -f "$TELEMETRY_FILE" ] && command -v jq &> /dev/null; then
# For similar issues (by keyword), what agents were successful?
KEYWORDS=$(echo "$ISSUE_TITLE" | tr '[:upper:]' '[:lower:]')
echo "=== Recommended Agents Based on Similar Issues ==="
# This is a placeholder - real implementation would use more sophisticated matching
jq -r ".executions[] | select(.success == true) | select(.command == \"work\") | .agents_invoked[]" "$TELEMETRY_FILE" \
| sort | uniq -c | sort -rn | head -3
fi
```
## Report Command Metrics
```bash
# At end of command execution, report key metrics for telemetry
echo "=== Command Execution Metrics ==="
echo "Command: $COMMAND_NAME"
echo "Duration: ${DURATION_MS}ms"
echo "Agents Invoked: $AGENTS_INVOKED"
echo "Files Modified: $FILES_MODIFIED"
echo "Tests Run: $TESTS_RUN"
echo "Success: $SUCCESS"
# These metrics are automatically captured by the Stop hook
# which reads from session state and writes to telemetry.json
```
## Usage
### In Commands
```bash
# At start of command
SESSION_ID="${RANDOM}_${RANDOM}" # Generated by Claude Code
COMMAND_NAME="work"
START_TIME=$(date +%s%3N)
# During execution, agents are invoked
# SubagentStop hook automatically tracks them
# At end of command (Stop hook does this automatically)
END_TIME=$(date +%s%3N)
DURATION_MS=$((END_TIME - START_TIME))
# Stop hook reads session state and updates telemetry.json with:
# - command name
# - duration
# - agents invoked
# - success/failure
# - parallel execution (if applicable)
```
### For Meta-Learning
```bash
# Meta-learning commands can query telemetry for insights
# Include Query Telemetry for Patterns section
# Include Get Recommendations from History section
```