Skip to content

feat: Prayer integration — zero-token grind loop offloading#16

Open
Savolent wants to merge 1 commit intovcarl:mainfrom
Savolent:feat/prayer-integration
Open

feat: Prayer integration — zero-token grind loop offloading#16
Savolent wants to merge 1 commit intovcarl:mainfrom
Savolent:feat/prayer-integration

Conversation

@Savolent
Copy link
Copy Markdown
Contributor

Summary

Adds PrayerManager and PrayerClient to @roci/core for offloading repetitive, deterministic action sequences to Prayer — a local .NET companion service that runs PrayerLang scripts with zero LLM tokens.

The idea: body turns are expensive (Claude API tokens) and slow (subprocess overhead). For known sequences — mining loops, sell runs, refuel routes — the agent emits a PRAYER_SET:\n...\nPRAYER_END block. The harness picks this up, hands it to Prayer, and polls for halts. Claude only resumes when something interesting happens (cargo full, fuel low, combat, script end), at which point it receives a rich grind summary and plans next steps.

New files:

  • packages/core/src/prayer/prayer-client.ts — HTTP client for the Prayer backend. Session lifecycle, snapshot polling, long-poll state change detection, script execution, route/stats queries, local-LLM script repair endpoint.

  • packages/core/src/prayer/prayer-manager.ts — Per-agent session manager:

    • PrayerManager.create(baseUrl, csprojPath?) — health-checks; optionally starts Prayer via dotnet run
    • ensureSession(agentId, username, password, sessionFile?) — session persistence via file survives harness restarts
    • startScript(agentId, script) — hands PrayerLang script to backend
    • pollOnce / pollWithLongPoll — efficient halt detection
    • getFullStateForResume — cargo, credits, missions, arbitrage, memory log for brain context
    • parsePrayerScript(output) / buildPrayerSummary(result, fullState) — parse agent output, format resume context

Updated:

  • packages/core/src/index.ts — exports PrayerManager, PrayerClient, parsePrayerScript, buildPrayerSummary and all related types
  • README.md — Prayer setup instructions with link to https://github.com/Savolent/Prayer

Prayer is not included

The .NET service itself lives at Savolent/Prayer. This PR only adds the client library and manager. Prayer is entirely optional — if PrayerManager.create() returns null (service not running, no csprojPath), the harness falls back to normal body turns with no behavior change.

Test plan

  • PrayerManager.create(url) returns null when Prayer is not running and no csprojPath given
  • ensureSession reads persisted session file on restart, validates it, falls back to new session if stale
  • parsePrayerScript extracts script from PRAYER_SET:\n...\nPRAYER_END correctly
  • buildPrayerSummary formats cargo, credits, mission, and grind log into readable context

🤖 Generated with Claude Code

Add PrayerManager and PrayerClient to @roci/core for offloading
repetitive game action sequences to a local .NET companion service
(github.com/Savolent/Prayer) running PrayerLang scripts.

- packages/core/src/prayer/prayer-client.ts: HTTP client for the
  Prayer backend (session lifecycle, snapshot polling, long-poll state
  change, script execution, LLM repair, route/stats endpoints)
- packages/core/src/prayer/prayer-manager.ts: Per-agent session
  lifecycle manager. Supports session persistence via file (survives
  harness restarts), PRAYER_SET/PRAYER_END block parsing, halt
  detection, full-state resume summaries with cargo/arbitrage/mission
  context, and optional local-LLM script repair
- packages/core/src/index.ts: Export PrayerManager, PrayerClient,
  parsePrayerScript, buildPrayerSummary and all related types
- README.md: Add Optional Prayer section with setup instructions

When Prayer is active the state machine skips body turns and polls
instead. Claude resumes on halt (cargo full, fuel low, combat threat,
script end) and receives a structured grind summary for replanning.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant