Skip to content

Inject OAuth access token into agent sessions + replace echo signals with curl + wire auto-advancement#77

Open
olsonjeffery wants to merge 3 commits into
mainfrom
task/15-task-api--live-session-access-
Open

Inject OAuth access token into agent sessions + replace echo signals with curl + wire auto-advancement#77
olsonjeffery wants to merge 3 commits into
mainfrom
task/15-task-api--live-session-access-

Conversation

@olsonjeffery

Copy link
Copy Markdown
Owner

Summary

This PR injects OAuth access tokens into agent LLM sessions, replaces echo-based signal stubs with actual curl commands to the OFM server's agent-flag endpoints, and wires up auto-advancement through the orchestration phases.

Key Changes

Phase 1: In-memory access_token cache

  • Added access_tokens: Arc<Mutex<HashMap<Uuid, String>>> to AppState
  • Populated on startup background refresh and in POST /api/auth/refresh handler

Phase 2: OFM env vars + curl instructions in context prompt

  • Extended build_context_prompt() to accept host/port/pid/access_token
  • New "OFM Environment" section with env vars (OFM_HOST, OFM_PORT, OFM_PID, OFM_TASK_ID) and curl instruction table

Phase 3-4: Shared agent-starting function + token wiring

  • Extracted start_next_agent() shared function in orchestration/mod.rs
  • Refactored post_create_agent_run() to use it
  • Access token looked up from cache (or refreshed on demand), written to .ofm_token file

Phase 5: Template updates

  • All 4 phase templates updated: planification.md, implementation.md, review.md, pr.md
  • Echo signal stubs replaced with curl commands targeting POST /api/tasks/{id}/agent-flags/{action}

Phase 6: Run status reset on resume

  • In send_message(), reset task_agent_runs from completed/failed to running before resuming turn

Phase 7: Auto-advancement wiring

  • Both agent_runs.rs and conversations.rs broadcast tasks now handle completion_handler's StartAgent response to call start_next_agent()

Phase 8: Token refresh broadcasting

  • After successful token refresh (API handler + background task), broadcast "agent token refreshed" UserText to active WS topics

Phase 10: Security hardening

  • Token written to .ofm_token file instead of embedding in prompt text (avoids leaking to LLM provider)
  • Token removed from GET /api/tasks/{id} response
  • .ofm_token added to .gitignore with instructions in context prompt
  • Templates read token via $(cat .ofm_token) instead of $OFM_ACCESS_TOKEN

Documentation

  • Updated spec/SPEC.md, spec/core/orchestration-loop.md, ARCHITECTURE.md

Testing

  • 442/442 unit tests pass, clippy clean
  • Manual Playwright scenarios deferred per user acceptance

…with curl

- Add in-memory access_token cache (Arc<Mutex<HashMap<Uuid,String>>>) to AppState
- Populate cache on startup refresh and POST /api/auth/refresh
- Broadcast "agent token refreshed" to active WS topics on refresh
- Extend build_context_prompt() with OFM_HOST/PORT/PID/ACCESS_TOKEN env vars
- Add "OFM Environment" section with curl instruction table to agent prompts
- Extract start_next_agent() shared function in orchestration/mod.rs
- Refactor post_create_agent_run() to use shared function
- Wire auto-advancement: completion_handler callers now invoke start_next_agent() on StartAgent
- Reset run status to running in send_message() to prevent short-circuit
- Update phase templates: replace echo signals with curl POST commands
- Update spec/SPEC.md, spec/core/orchestration-loop.md, ARCHITECTURE.md
- Fix all clippy warnings across the codebase
… prompt

- Security: OAuth access token is no longer embedded in prompt text
  sent to LLM providers (was HIGH severity vulnerability)
- Security: Token no longer persisted in conversation transcript
- Security: Token no longer returned in GET /api/tasks/{id} response
- Token is written to .ofm_token in the worktree root (0600 permissions)
- Templates updated to read token via $(cat .ofm_token)
- Simplified access_tokens init in test files (removed fully-qualified paths)
- Replaced writeln!().ok() with let _ = writeln!() in config.rs
…ext prompt

- ARCHITECTURE.md: reflect token written to .ofm_token, not embedded in prompt
- spec/SPEC.md: document .ofm_token file approach with curl examples
- spec/core/orchestration-loop.md: update agent flag endpoint invocation docs
- src/archive/mod.rs: add .gitignore reminder in OFM Environment section
- .gitignore: add .ofm_token to prevent accidental commits
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