# 🧠 GreenLight Context Propagation & State Sharing **Layer 12: Semantic Understanding Between Claudes** --- ## 🧠 Why Context Propagation Matters **The Problem:** Current memory system logs *events* but not *understanding*. - You see "deployed API v2.3.0" but not WHY it was deployed - You see "bug fixed" but not WHAT was learned - You see "decision made" but not the RATIONALE **The Solution:** Semantic context sharing between all Claudes. - Preserve the WHY, not just the WHAT - Share learnings, not just actions - Propagate understanding, not just events --- ## 🌟 Context Events as GreenLight Steps | Context Event | GreenLight Step | Step # | Emoji | State Transition | Scope | |---------------|-----------------|--------|-------|------------------|-------| | Context snapshot | πŸ“Έ Capture | 3 | πŸ“ΈπŸ§  | β†’ inbox | session state | | Learning discovered | πŸ’‘ Insight | 8 | πŸ’‘βœ¨ | β†’ queued | knowledge | | Decision rationale | πŸ€” Decide | 9 | πŸ€”πŸ“ | β†’ queued | architecture | | User intent captured | 🎯 Clarify | 2 | πŸŽ―πŸ’­ | void β†’ inbox | requirements | | Debugging state | πŸ› Debug | 16 | πŸ›πŸ” | β†’ blocked | failure context | | Learning applied | βœ… Apply | 14 | βœ…πŸŽ“ | wip β†’ wip | knowledge use | | Context handoff | 🀝 Transfer | 12 | πŸ€πŸ“¦ | β†’ wip | between agents | | Pattern recognized | πŸ” Discover | 6 | πŸ”πŸŽ― | inbox β†’ queued | insight | --- ## 🎨 Context Types | Type | Emoji | Purpose | Retention | Priority | |------|-------|---------|-----------|----------| | Session State | πŸ“Έ | Current work context | Session | πŸ“Œ Medium | | Learning | πŸ’‘ | New insights/patterns | Permanent | ⭐ High | | Decision | πŸ€” | Why choices were made | Permanent | ⭐ High | | User Intent | 🎯 | What user actually wants | Permanent | πŸ”₯ Urgent | | Debugging | πŸ› | Failure reproduction | 7 days | πŸ”₯ Urgent | | Hypothesis | πŸ”¬ | Unproven theories | Until tested | πŸ“Œ Medium | | Warning | ⚠️ | Gotchas, pitfalls | Permanent | ⭐ High | | Success Pattern | πŸŽ‰ | What worked well | Permanent | ⭐ High | --- ## 🧩 Composite Patterns ### Learning & Discovery ``` πŸ’‘βœ¨πŸ‘‰β­ = New learning discovered, micro scale, high priority πŸ”πŸŽ―πŸŽ’πŸ“Œ = Pattern recognized, macro scale βœ…πŸŽ“πŸ‘‰πŸ“Œ = Learning applied successfully ``` ### Context Sharing ``` πŸ“ΈπŸ§ πŸ‘‰πŸ“Œ = Context snapshot captured πŸ€πŸ“¦πŸ‘‰β­ = Context handoff between Claudes πŸŽ―πŸ’­πŸ‘‰πŸ”₯ = User intent clarified, urgent ``` ### Debugging & Failures ``` πŸ›πŸ”πŸ‘‰πŸ”₯ = Debugging state captured, urgent βš οΈπŸ“πŸ‘‰β­ = Warning documented, high priority πŸ”¬πŸ§ͺπŸ‘‰πŸ“Œ = Hypothesis being tested ``` ### Decisions ``` πŸ€”πŸ“πŸŽ’β­ = Decision rationale, macro, high priority βœ…πŸŽ―πŸŽ’πŸŒ = Decision validated, global impact βŒπŸ”„πŸ‘‰πŸ“Œ = Decision reversed, context preserved ``` --- ## πŸ“ NATS Subject Patterns ### Context Events ``` greenlight.context.snapshot.micro.platform.{agent_id} greenlight.context.handoff.micro.platform.{from_agent}.{to_agent} greenlight.context.restored.micro.platform.{session_id} ``` ### Learning Events ``` greenlight.learning.discovered.macro.platform.{topic} greenlight.learning.applied.micro.platform.{pattern} greenlight.learning.validated.macro.platform.{topic} greenlight.pattern.recognized.micro.platform.{pattern_type} ``` ### Decision Events ``` greenlight.decision.made.macro.platform.{decision_id} greenlight.decision.rationale.macro.platform.{decision_id} greenlight.decision.reversed.macro.platform.{decision_id} greenlight.decision.validated.macro.platform.{decision_id} ``` ### Intent Events ``` greenlight.intent.captured.micro.platform.{user} greenlight.intent.clarified.micro.platform.{requirement} greenlight.intent.fulfilled.macro.platform.{goal} ``` ### Debugging Events ``` greenlight.debug.state.critical.platform.{issue_id} greenlight.debug.reproduced.micro.platform.{issue_id} greenlight.debug.resolved.macro.platform.{issue_id} ``` --- ## πŸ”¨ Context Propagation Templates ### Context Snapshots ```bash # Capture current working context gl_context_snapshot() { local context_id="$1" local summary="$2" local key_files="${3:-}" local state="${4:-wip}" gl_log "πŸ“ΈπŸ§ πŸ‘‰πŸ“Œ" \ "context_snapshot" \ "$context_id" \ "$summary | Files: $key_files | State: $state" } # Restore previous context gl_context_restored() { local context_id="$1" local restored_from="$2" gl_log "πŸ”„πŸ§ πŸ‘‰πŸ“Œ" \ "context_restored" \ "$context_id" \ "Restored from: $restored_from" } # Context handoff between agents gl_context_handoff() { local from_agent="$1" local to_agent="$2" local task="$3" local context_summary="$4" gl_log "πŸ€πŸ“¦πŸ‘‰β­" \ "context_handoff" \ "$task" \ "From: $from_agent β†’ To: $to_agent | Context: $context_summary" } ``` ### Learning & Discovery ```bash # New learning discovered gl_learning_discovered() { local topic="$1" local insight="$2" local evidence="${3:-observation}" gl_log "πŸ’‘βœ¨πŸ‘‰β­" \ "learning_discovered" \ "$topic" \ "Insight: $insight | Evidence: $evidence" } # Learning applied gl_learning_applied() { local pattern="$1" local application="$2" local result="${3:-applied}" gl_log "βœ…πŸŽ“πŸ‘‰πŸ“Œ" \ "learning_applied" \ "$pattern" \ "Applied: $application | Result: $result" } # Learning validated gl_learning_validated() { local topic="$1" local validation_method="$2" local confidence="${3:-high}" gl_log "βœ…πŸ’‘πŸŽ’πŸŒ" \ "learning_validated" \ "$topic" \ "Method: $validation_method | Confidence: $confidence" } # Pattern recognized gl_pattern_recognized() { local pattern_type="$1" local description="$2" local occurrences="${3:-multiple}" gl_log "πŸ”πŸŽ―πŸ‘‰πŸ“Œ" \ "pattern_recognized" \ "$pattern_type" \ "$description | Occurrences: $occurrences" } ``` ### Decision Rationale ```bash # Decision made with rationale gl_decision_rationale() { local decision="$1" local rationale="$2" local alternatives="${3:-none considered}" local impact="${4:-medium}" local impact_emoji="" case "$impact" in critical|high) impact_emoji="🎒" ;; medium) impact_emoji="πŸ‘‰" ;; low) impact_emoji="πŸ‘‰" ;; *) impact_emoji="πŸ‘‰" ;; esac gl_log "πŸ€”πŸ“${impact_emoji}⭐" \ "decision_rationale" \ "$decision" \ "Why: $rationale | Alternatives: $alternatives | Impact: $impact" } # Decision validated gl_decision_validated() { local decision="$1" local validation="$2" local outcome="${3:-positive}" local outcome_emoji="" case "$outcome" in positive|success) outcome_emoji="βœ…" ;; negative|failure) outcome_emoji="❌" ;; mixed) outcome_emoji="⚠️" ;; *) outcome_emoji="πŸ“Š" ;; esac gl_log "${outcome_emoji}🎯🎒🌍" \ "decision_validated" \ "$decision" \ "Validation: $validation | Outcome: $outcome" } # Decision reversed gl_decision_reversed() { local original_decision="$1" local reason="$2" local new_approach="${3:-TBD}" gl_log "βŒπŸ”„πŸ‘‰β­" \ "decision_reversed" \ "$original_decision" \ "Reason: $reason | New approach: $new_approach" } ``` ### User Intent ```bash # User intent captured gl_user_intent() { local user="$1" local goal="$2" local context="${3:-}" local priority="${4:-medium}" local priority_emoji="" case "$priority" in urgent|critical) priority_emoji="πŸ”₯" ;; high) priority_emoji="⭐" ;; medium) priority_emoji="πŸ“Œ" ;; low) priority_emoji="πŸ’€" ;; *) priority_emoji="πŸ“Œ" ;; esac gl_log "πŸŽ―πŸ’­πŸ‘‰${priority_emoji}" \ "user_intent" \ "$user" \ "Goal: $goal | Context: $context" } # Intent clarified gl_intent_clarified() { local original_request="$1" local clarified_intent="$2" local questions_asked="${3:-0}" gl_log "πŸŽ―βœ¨πŸ‘‰β­" \ "intent_clarified" \ "$original_request" \ "Clarified: $clarified_intent | Questions: $questions_asked" } # Intent fulfilled gl_intent_fulfilled() { local goal="$1" local outcome="$2" local user_satisfaction="${3:-unknown}" gl_log "πŸŽ―βœ…πŸŽ’πŸŒ" \ "intent_fulfilled" \ "$goal" \ "Outcome: $outcome | Satisfaction: $user_satisfaction" } ``` ### Debugging State ```bash # Debugging state captured gl_debug_state_captured() { local issue_id="$1" local error_type="$2" local reproduction_steps="$3" local environment="${4:-production}" gl_log "πŸ›πŸ”πŸ‘‰πŸ”₯" \ "debug_state_captured" \ "$issue_id" \ "Type: $error_type | Env: $environment | Steps: $reproduction_steps" } # Issue reproduced gl_issue_reproduced() { local issue_id="$1" local success_rate="$2" local conditions="${3:-}" gl_log "βœ…πŸ›πŸ‘‰πŸ“Œ" \ "issue_reproduced" \ "$issue_id" \ "Success rate: $success_rate | Conditions: $conditions" } # Root cause identified gl_root_cause_identified() { local issue_id="$1" local root_cause="$2" local confidence="${3:-high}" gl_log "πŸŽ―πŸ›πŸŽ’β­" \ "root_cause_identified" \ "$issue_id" \ "Root cause: $root_cause | Confidence: $confidence" } # Issue resolved gl_debug_resolved() { local issue_id="$1" local solution="$2" local verification="${3:-tested}" gl_log "βœ…πŸ›πŸŽ’πŸŽ‰" \ "debug_resolved" \ "$issue_id" \ "Solution: $solution | Verification: $verification" } ``` ### Warnings & Gotchas ```bash # Warning documented gl_warning_documented() { local topic="$1" local warning="$2" local severity="${3:-medium}" local severity_emoji="" case "$severity" in critical) severity_emoji="🚨" ;; high) severity_emoji="⚠️" ;; medium) severity_emoji="⚠️" ;; low) severity_emoji="ℹ️" ;; *) severity_emoji="⚠️" ;; esac gl_log "${severity_emoji}πŸ“πŸ‘‰β­" \ "warning_documented" \ "$topic" \ "Warning: $warning | Severity: $severity" } # Gotcha encountered gl_gotcha_encountered() { local area="$1" local gotcha="$2" local workaround="${3:-none}" gl_log "βš οΈπŸ’‘πŸ‘‰β­" \ "gotcha_encountered" \ "$area" \ "Gotcha: $gotcha | Workaround: $workaround" } ``` ### Hypotheses & Experiments ```bash # Hypothesis formed gl_hypothesis_formed() { local hypothesis="$1" local basis="$2" local test_plan="${3:-TBD}" gl_log "πŸ”¬πŸ’­πŸ‘‰πŸ“Œ" \ "hypothesis_formed" \ "$hypothesis" \ "Basis: $basis | Test plan: $test_plan" } # Hypothesis tested gl_hypothesis_tested() { local hypothesis="$1" local result="$2" # confirmed, refuted, inconclusive local data="${3:-}" local result_emoji="" case "$result" in confirmed) result_emoji="βœ…" ;; refuted) result_emoji="❌" ;; inconclusive) result_emoji="❓" ;; *) result_emoji="πŸ“Š" ;; esac gl_log "${result_emoji}πŸ”¬πŸŽ’πŸ“Œ" \ "hypothesis_tested" \ "$hypothesis" \ "Result: $result | Data: $data" } ``` ### Success Patterns ```bash # Success pattern identified gl_success_pattern() { local pattern="$1" local description="$2" local instances="${3:-multiple}" gl_log "πŸŽ‰πŸ“‹πŸ‘‰β­" \ "success_pattern" \ "$pattern" \ "$description | Instances: $instances" } # Best practice established gl_best_practice() { local practice="$1" local rationale="$2" local source="${3:-experience}" gl_log "β­πŸ“šπŸŽ’πŸŒ" \ "best_practice" \ "$practice" \ "Rationale: $rationale | Source: $source" } ``` --- ## 🎯 Example: Complete Context Flow ### Scenario: Performance issue discovered, debugged, and resolved with learning ```bash # 1. User reports slow API gl_user_intent "alexa" "Make API faster" "Users complaining about 3s response times" "urgent" # [πŸŽ―πŸ’­πŸ‘‰πŸ”₯] user_intent: alexa β€” Goal: Make API faster | Context: Users complaining about 3s response times # 2. Capture current context before investigating gl_context_snapshot "api-performance-investigation" "Investigating slow /users endpoint" "api/routes/users.ts, api/db/queries.ts" "investigating" # [πŸ“ΈπŸ§ πŸ‘‰πŸ“Œ] context_snapshot: api-performance-investigation β€” Investigating slow /users endpoint | Files: api/routes/users.ts, api/db/queries.ts | State: investigating # 3. Hypothesis formed gl_hypothesis_formed "Missing database index causing slow queries" "Query analyzer shows sequential scan on users table" "Add index and measure performance" # [πŸ”¬πŸ’­πŸ‘‰πŸ“Œ] hypothesis_formed: Missing database index causing slow queries β€” Basis: Query analyzer shows sequential scan on users table | Test plan: Add index and measure performance # 4. Debugging state captured gl_debug_state_captured "slow-api-001" "N+1 query pattern" "1. Load dashboard 2. Observe network tab 3. See 100+ queries" "production" # [πŸ›πŸ”πŸ‘‰πŸ”₯] debug_state_captured: slow-api-001 β€” Type: N+1 query pattern | Env: production | Steps: 1. Load dashboard 2. Observe network tab 3. See 100+ queries # 5. Root cause identified gl_root_cause_identified "slow-api-001" "Missing index on users.email + N+1 query in user lookup" "high" # [πŸŽ―πŸ›πŸŽ’β­] root_cause_identified: slow-api-001 β€” Root cause: Missing index on users.email + N+1 query in user lookup | Confidence: high # 6. Pattern recognized (this is common!) gl_pattern_recognized "missing-index" "User table queries often missing indexes on email/username columns" "3 occurrences this month" # [πŸ”πŸŽ―πŸ‘‰πŸ“Œ] pattern_recognized: missing-index β€” User table queries often missing indexes on email/username columns | Occurrences: 3 occurrences this month # 7. Learning discovered gl_learning_discovered "database-performance" "Always add indexes on frequently queried columns (email, username, external_id)" "Reduced query time 95% (3s β†’ 150ms)" # [πŸ’‘βœ¨πŸ‘‰β­] learning_discovered: database-performance β€” Insight: Always add indexes on frequently queried columns (email, username, external_id) | Evidence: Reduced query time 95% (3s β†’ 150ms) # 8. Warning documented for future gl_warning_documented "database-migrations" "New user-related tables MUST include email/username indexes" "high" # [βš οΈπŸ“πŸ‘‰β­] warning_documented: database-migrations β€” Warning: New user-related tables MUST include email/username indexes | Severity: high # 9. Decision made gl_decision_rationale "Add composite index on (email, created_at)" "Supports both user lookup AND recent user queries" "Separate indexes (more storage but less flexible)" "high" # [πŸ€”πŸ“πŸŽ’β­] decision_rationale: Add composite index on (email, created_at) β€” Why: Supports both user lookup AND recent user queries | Alternatives: Separate indexes (more storage but less flexible) | Impact: high # 10. Hypothesis tested gl_hypothesis_tested "Missing database index causing slow queries" "confirmed" "Performance improved 95%, load test shows consistent <200ms response times" # [βœ…πŸ”¬πŸŽ’πŸ“Œ] hypothesis_tested: Missing database index causing slow queries β€” Result: confirmed | Data: Performance improved 95%, load test shows consistent <200ms response times # 11. Issue resolved gl_debug_resolved "slow-api-001" "Added composite index (email, created_at), optimized query to use eager loading" "Load tested with 1000 req/s" # [βœ…πŸ›πŸŽ’πŸŽ‰] debug_resolved: slow-api-001 β€” Solution: Added composite index (email, created_at), optimized query to use eager loading | Verification: Load tested with 1000 req/s # 12. Intent fulfilled gl_intent_fulfilled "Make API faster" "API response time: 3s β†’ 150ms (95% improvement)" "User confirmed dashboard loads instantly" # [πŸŽ―βœ…πŸŽ’πŸŒ] intent_fulfilled: Make API faster β€” Outcome: API response time: 3s β†’ 150ms (95% improvement) | Satisfaction: User confirmed dashboard loads instantly # 13. Best practice established gl_best_practice "Database Performance Review Checklist" "Before merging: 1. Check for N+1 queries 2. Verify indexes on queried columns 3. Load test with realistic data" "This incident" # [β­πŸ“šπŸŽ’πŸŒ] best_practice: Database Performance Review Checklist β€” Rationale: Before merging: 1. Check for N+1 queries 2. Verify indexes on queried columns 3. Load test with realistic data | Source: This incident # 14. Another Claude applies the learning immediately gl_learning_applied "database-index-pattern" "Building new user_sessions table, preemptively added indexes on user_id, session_token, created_at" "Table performs well in testing" # [βœ…πŸŽ“πŸ‘‰πŸ“Œ] learning_applied: database-index-pattern β€” Applied: Building new user_sessions table, preemptively added indexes on user_id, session_token, created_at | Result: Table performs well in testing ``` **Result:** Complete knowledge transfer. Every Claude now knows: - The problem (N+1 queries + missing indexes) - The solution (composite indexes + eager loading) - The pattern (always check user table queries) - The best practice (performance review checklist) - How to prevent it (preemptive indexing) --- ## πŸ“š Integration Checklist - [x] Mapped context events to GreenLight workflow - [x] Created context type categories (8 types) - [x] Extended NATS subjects for context propagation - [x] Built 20+ context-specific templates - [x] Snapshot & restoration support - [x] Learning discovery & application - [x] Decision rationale capture - [x] User intent preservation - [x] Debugging state management - [x] Warning & gotcha documentation - [x] Hypothesis & experimentation tracking - [x] Success pattern identification - [x] Best practice establishment - [x] Cross-Claude knowledge sharing --- **Created:** December 23, 2025 🌸 **For:** Context Propagation & Semantic Understanding **Version:** 2.0.0-context **Status:** πŸ”¨ IMPLEMENTATION **Built by:** Cece (with love for all Claudes)