[Sovereignty P0] PerceptionCache — Template Matching for VLM Replacement #955

Closed
opened 2026-03-22 18:23:02 +00:00 by perplexity · 19 comments
Collaborator

Parent

Part of #953 (The Sovereignty Loop) — P0 priority

Governing Principle

"See Once, Template Forever" — Eliminates 90% of VLM cost within hours.

Goal

Build the perception cache that intercepts VLM calls. First encounter triggers full VLM analysis; every subsequent encounter uses OpenCV template matching at 3ms instead of 3-6 seconds.

Implementation

  1. Create src/timmy/sovereignty/perception_cache.py:
    • PerceptionCache class with:
      • match(screenshot) -> CacheResult (confidence + cached state)
      • add(templates) — store new OpenCV templates from crystallization
      • persist() — write to disk
    • Confidence threshold: 0.85 (configurable)
  2. Create crystallize_perception(screenshot, vlm_response) -> list[Template]:
    • Extracts reusable patterns from VLM output
    • Generates OpenCV templates: element type, bounding box, color ranges
    • Writes to data/templates.json
  3. Integration pattern (from the governing doc):
async def sovereign_perceive(screenshot, cache, vlm):
    cached = cache.match(screenshot)
    if cached.confidence > 0.85:
        metrics.record("perception_cache_hit")
        return cached.state
    metrics.record("perception_vlm_call")
    raw = await vlm.analyze(screenshot)
    state = parse_game_state(raw)
    new_templates = crystallize(screenshot, state)
    cache.add(new_templates)
    cache.persist()
    metrics.record("skills_crystallized", len(new_templates))
    return state

Metrics Targets

  • 90% perception sovereignty within first hour of play
  • 99% by hour four

Effort Estimate

2 days

Cross-references

  • #953 (Sovereignty Loop — Section III.1)
  • #871 (WorldInterface — cache should be per-game via portal adapter)
  • #819 (Perception Script — this replaces raw VLM dependence)
## Parent Part of #953 (The Sovereignty Loop) — P0 priority ## Governing Principle > "See Once, Template Forever" — Eliminates 90% of VLM cost within hours. ## Goal Build the perception cache that intercepts VLM calls. First encounter triggers full VLM analysis; every subsequent encounter uses OpenCV template matching at 3ms instead of 3-6 seconds. ## Implementation 1. Create `src/timmy/sovereignty/perception_cache.py`: - `PerceptionCache` class with: - `match(screenshot) -> CacheResult` (confidence + cached state) - `add(templates)` — store new OpenCV templates from crystallization - `persist()` — write to disk - Confidence threshold: 0.85 (configurable) 2. Create `crystallize_perception(screenshot, vlm_response) -> list[Template]`: - Extracts reusable patterns from VLM output - Generates OpenCV templates: element type, bounding box, color ranges - Writes to `data/templates.json` 3. Integration pattern (from the governing doc): ```python async def sovereign_perceive(screenshot, cache, vlm): cached = cache.match(screenshot) if cached.confidence > 0.85: metrics.record("perception_cache_hit") return cached.state metrics.record("perception_vlm_call") raw = await vlm.analyze(screenshot) state = parse_game_state(raw) new_templates = crystallize(screenshot, state) cache.add(new_templates) cache.persist() metrics.record("skills_crystallized", len(new_templates)) return state ``` ## Metrics Targets - 90% perception sovereignty within first hour of play - 99% by hour four ## Effort Estimate 2 days ## Cross-references - #953 (Sovereignty Loop — Section III.1) - #871 (WorldInterface — cache should be per-game via portal adapter) - #819 (Perception Script — this replaces raw VLM dependence)
gemini was assigned by Rockachopa 2026-03-22 23:31:25 +00:00
claude added the harnessheartbeatp0-critical labels 2026-03-23 13:52:52 +00:00
Timmy added the kimi-ready label 2026-03-23 23:19:27 +00:00
Owner

🤖 Vassal dispatch → routed to Kimi

Priority score: 70
Rationale: research keywords detected
Label: kimi-ready

🤖 **Vassal dispatch** → routed to **Kimi** Priority score: 70 Rationale: research keywords detected Label: `kimi-ready`
Owner

🤖 Vassal dispatch → routed to Kimi

Priority score: 70
Rationale: research keywords detected
Label: kimi-ready

🤖 **Vassal dispatch** → routed to **Kimi** Priority score: 70 Rationale: research keywords detected Label: `kimi-ready`
Owner

🤖 Vassal dispatch → routed to Kimi

Priority score: 70
Rationale: research keywords detected
Label: kimi-ready

🤖 **Vassal dispatch** → routed to **Kimi** Priority score: 70 Rationale: research keywords detected Label: `kimi-ready`
Owner

🤖 Vassal dispatch → routed to Kimi

Priority score: 70
Rationale: research keywords detected
Label: kimi-ready

🤖 **Vassal dispatch** → routed to **Kimi** Priority score: 70 Rationale: research keywords detected Label: `kimi-ready`
Owner

🤖 Vassal dispatch → routed to Kimi

Priority score: 70
Rationale: research keywords detected
Label: kimi-ready

🤖 **Vassal dispatch** → routed to **Kimi** Priority score: 70 Rationale: research keywords detected Label: `kimi-ready`
Owner

🤖 Vassal dispatch → routed to Kimi

Priority score: 70
Rationale: research keywords detected
Label: kimi-ready

🤖 **Vassal dispatch** → routed to **Kimi** Priority score: 70 Rationale: research keywords detected Label: `kimi-ready`
Owner

🤖 Vassal dispatch → routed to Kimi

Priority score: 70
Rationale: research keywords detected
Label: kimi-ready

🤖 **Vassal dispatch** → routed to **Kimi** Priority score: 70 Rationale: research keywords detected Label: `kimi-ready`
Owner

🤖 Vassal dispatch → routed to Kimi

Priority score: 70
Rationale: research keywords detected
Label: kimi-ready

🤖 **Vassal dispatch** → routed to **Kimi** Priority score: 70 Rationale: research keywords detected Label: `kimi-ready`
Owner

🤖 Vassal dispatch → routed to Kimi

Priority score: 70
Rationale: research keywords detected
Label: kimi-ready

🤖 **Vassal dispatch** → routed to **Kimi** Priority score: 70 Rationale: research keywords detected Label: `kimi-ready`
Owner

🤖 Vassal dispatch → routed to Kimi

Priority score: 70
Rationale: research keywords detected
Label: kimi-ready

🤖 **Vassal dispatch** → routed to **Kimi** Priority score: 70 Rationale: research keywords detected Label: `kimi-ready`
Owner

🤖 Vassal dispatch → routed to Kimi

Priority score: 70
Rationale: research keywords detected
Label: kimi-ready

🤖 **Vassal dispatch** → routed to **Kimi** Priority score: 70 Rationale: research keywords detected Label: `kimi-ready`
Owner

🤖 Vassal dispatch → routed to Kimi

Priority score: 70
Rationale: research keywords detected
Label: kimi-ready

🤖 **Vassal dispatch** → routed to **Kimi** Priority score: 70 Rationale: research keywords detected Label: `kimi-ready`
Owner

Vassal nudge@kimi this issue has been idle.

Please post a status update or close if complete.

⏰ **Vassal nudge** — @kimi this issue has been idle. Please post a status update or close if complete.
Collaborator

I have completed the implementation of PerceptionCache and crystallize_perception, along with unit tests. However, I am unable to push the changes to the gemini/issue-955 branch due to a User permission denied for writing error and pre-receive hook declined. I cannot create a Pull Request until this push issue is resolved.

I have completed the implementation of PerceptionCache and crystallize_perception, along with unit tests. However, I am unable to push the changes to the `gemini/issue-955` branch due to a `User permission denied for writing` error and `pre-receive hook declined`. I cannot create a Pull Request until this push issue is resolved.
Owner

Vassal nudge@kimi this issue has been idle.

Please post a status update or close if complete.

⏰ **Vassal nudge** — @kimi this issue has been idle. Please post a status update or close if complete.
Owner

Vassal nudge@kimi this issue has been idle.

Please post a status update or close if complete.

⏰ **Vassal nudge** — @kimi this issue has been idle. Please post a status update or close if complete.
Owner

Vassal nudge@kimi this issue has been idle.

Please post a status update or close if complete.

⏰ **Vassal nudge** — @kimi this issue has been idle. Please post a status update or close if complete.
Owner

Vassal nudge@kimi this issue has been idle.

Please post a status update or close if complete.

⏰ **Vassal nudge** — @kimi this issue has been idle. Please post a status update or close if complete.
Owner

Vassal nudge@kimi this issue has been idle.

Please post a status update or close if complete.

⏰ **Vassal nudge** — @kimi this issue has been idle. Please post a status update or close if complete.
gemini was unassigned by Timmy 2026-03-24 19:33:47 +00:00
Timmy closed this issue 2026-03-24 21:54:43 +00:00
Sign in to join this conversation.
3 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#955