Agents Builders

Extract shared agent API client

Archived
extract-shared-agent-api-client

Created

Jul 04, 01:33

Started

Jul 04, 02:20

Completed

Jul 04, 04:58

DevOps handoff

Type

Chore

Shape

library

Worktree Slug

extract-shared-agent-api-client

Repositories

mcritchie-studio

Release Slug

Branch

feat/extract-shared-agent-api-client

Local URL

QA URL

Production URL

devops

Acceptance Criteria

  • Extract token + HTTP boilerplate into bin/lib/agent_api
  • atomic-event, session-insights, atomic-capture-hook use the client
  • No behavior change; existing bin tests stay green

Expected Test Plan

  • [unit] agent_api_test covers token cache, secret fallback, base_url, http_json
  • [unit] atomic_event_cli_test stays green on shared client
  • [unit] session_insights_test stays green on shared client
  • [unit] atomic_capture_hook_test stays green on shared client
  • [integration] full bin test suite green (behavior-preserving refactor)

Checks Run

  • [unit] agent_api_test client tier green — 14 runs/37 asserts (cache, secret order, base_url, pinned timeout divergence)
  • [unit] atomic_event_cli_test green 37 runs (test file unchanged — behavior preserved)
  • [unit] session_insights_test green 8 runs (test file unchanged)
  • [unit] atomic_capture_hook_test green 37 runs (test file unchanged)
  • [integration] all four lib tests in ONE process: 96 runs/372 asserts, 0 failures (no load-order or constant-redefinition interactions)
  • [integration] stub-server round-trips: mint-once shared token cache, bearer/JSON request shape, dead-endpoint degrades to nil
  • [integration] rubocop clean on all 5 changed files
  • [full-suite@770502303cf23a6c4f12841e839bd74ef08c4bae] bin/rails test green
  • [rubocop@770502303cf23a6c4f12841e839bd74ef08c4bae] bin/rubocop clean

Agent Context

REFACTOR noticed during the insights audit (2026-07-03). bin/atomic-event, bin/session-insights, and bin/atomic-capture-hook each RE-IMPLEMENT the same agent-API boilerplate: ~4 token methods (mint via /api/v1/auth, read/write the shared token.json cache, agent_secret via ENV then 1Password op read then repo .env) and 3-5 HTTP methods (http_json, http_request, base_url from ATOMIC_CAPTURE_URL) plus present?/projects_dir. Extract a shared bin/lib/agent_api.rb (an AgentApi client: token + http_json/http_get + base_url) that the three collapse onto. The insights session already established the bin-lib pattern with bin/lib/repo_root.rb, so follow that shape. IMPORTANT SEQUENCING: WAIT for the in-flight insight-pipeline work (which edits session-insights + atomic-capture-hook, currently uncommitted in the primary / on feat/feed-banked-insights-forward) to LAND first — this refactor overlaps those files. Then extract. Tests: the existing atomic_event_cli_test, session_insights_test, atomic_capture_hook_test must stay green (behavior-preserving).

Stage Timeline

Who handled each stage, the time it took (measured), and the model / tokens / cost reported (best-effort) — plus who's on it right now. means the agent didn't report that metric.

Sizing Avi · PO SMALL Dev SMALL Actual XL ≠ forecast
  1. Created Designed
    C Caterpie
    Caterpie
    Model
    Duration
    Tokens
    Cost
    Completed Jul 04, 01:33 · 4 days ago
    api
  2. Designed Building
    F Fearow
    Fearow
    Model
    claude-fable-5
    Duration
    about 1 hour
    Tokens
    Cost
    Started Jul 04, 01:33
    Completed Jul 04, 02:20 · 4 days ago
    cli
  3. Building Submitted
    F Fearow
    Fearow
    Model
    claude-fable-5
    Duration
    26 minutes
    Tokens
    144,860
    Cost
    Started Jul 04, 02:20
    Completed Jul 04, 02:46 · 4 days ago
    cli
  4. Submitted Reviewed Review Activity
    C Carl
    Carl primary
    A Alex
    Alex light
    Model
    claude-fable-5
    Duration
    32 minutes
    Tokens
    5,873,077
    Cost
    ~$11.79
    Started Jul 04, 02:46
    Completed Jul 04, 03:18 · 4 days ago
    cli
  5. Reviewed Assembled
    S Steffon
    Steffon
    Model
    claude-fable-5
    Duration
    27 minutes
    Tokens
    8,428,960
    Cost
    ~$12.06
    Started Jul 04, 03:18
    Completed Jul 04, 03:45 · 4 days ago
  6. Assembled Shipped
    A Avi
    Avi
    Model
    claude-fable-5
    Duration
    about 1 hour
    Tokens
    19,210,785
    Cost
    ~$36.07
    Started Jul 04, 03:45
    Completed Jul 04, 04:58 · 4 days ago
  7. Shipped Archived
    Model
    Duration
    about 16 hours
    Tokens
    Cost
    Started Jul 04, 04:58
    Completed Jul 04, 20:46 · 4 days ago

Conversation

QA review feedback, agent handoffs, and follow-up notes for this task.

Handoff 4 days ago

PR #353 open into release. Three bin scripts collapsed onto shared bin/lib/agent_api.rb (repo_root bin-lib shape). Behavior-preserving: per-script timeouts (2/5, 2/4, 1/2) parameterized + pinned by unit test; 401 policy stays with callers. Drive-by: restored missing exec bit on bin/session-insights (was committed 644 — documented SessionStart wiring would permission-deny). Full suite certified at 770502303cf2, dor-check green. Task URL: https://mcritchie.studio/tasks/extract-shared-agent-api-client

Comment alex 4 days ago

Scout report: merge-ready - No blockers found. Shared AgentApi preserves the token/cache/base-url/HTTP behavior for the three bin clients, focused tests and CI are green, and merge safety is clean. Reporter: alex Outcome: merge-ready Findings: - Acceptance: bin/lib/agent_api.rb owns token mint/cache, secret env->1Password->.env fallback, base_url, and bearer JSON helpers; bin/atomic-event, bin/session-insights, and bin/atomic-capture-hook all delegate to it. - Behavior preserved: per-script timeout differences remain parameterized (2/5, 2/4, 1/2), atomic-event and capture-hook still invalidate cached tokens on 401, and session-insights still avoids invalidation and fails silent. - Merge safety: PR #353 targets release at head 57458640, GitHub mergeStateStatus is CLEAN, no open release PR touches these files, prior feed-banked-insights-forward work is already merged, and the local wire-bank same-file overlap merge-trees cleanly. Questions: - none Checks: - [local] bin/rails test test/lib/agent_api_test.rb test/lib/atomic_event_cli_test.rb test/lib/session_insights_test.rb test/lib/atomic_capture_hook_test.rb - 96 runs, 371 assertions, 0 failures. - [local] bin/rails test test/lib/agent_api_test.rb - 14 runs, 37 assertions, 0 failures. - [local] bin/rubocop bin/atomic-capture-hook bin/atomic-event bin/lib/agent_api.rb bin/session-insights test/lib/agent_api_test.rb - 5 files, no offenses. - [gate] bin/dor-check extract-shared-agent-api-client - DoR-to-Merge met for library shape; unit/integration tiers plus full-suite/rubocop certification present. - [ci] gh pr checks 353 - scan_ruby, scan_js, lint, and test all pass on current head 57458640.

Comment carl 4 days ago

Scout report: merge-ready - Primary review: acceptance met, focused tests/DoR/CI green, no blockers; recommend Avi proceed merge-ready. Reporter: carl Outcome: merge-ready Findings: - Blockers: none. Shared AgentApi preserves token cache, secret order, base URL, timeout divergence, and caller-owned 401 policy across atomic-event/session-insights/atomic-capture-hook. - Non-blocker: AgentApi#http_json(:unsupported) raises KeyError before nil-on-failure handling, but current callers only use :get/:post and caller wrappers rescue; optional hardening later. - Merge safety: no open release PR overlaps PR #353 files; two local unsubmitted branches touch related bin scripts but merge-tree auto-merges and should re-test if submitted later. Questions: - none Checks: - GitHub PR #353 targets release, head 57458640, mergeState CLEAN/MERGEABLE; scan_ruby, scan_js, lint, and test checks pass. - ruby -Itest combined agent_api/atomic_event/session_insights/atomic_capture_hook tests: 96 runs, 372 assertions, 0 failures. - bin/rubocop on the five changed files: 5 files inspected, no offenses. - bin/dor-check extract-shared-agent-api-client: DoR-to-Merge met for library shape; full suite + rubocop certified at 770502303cf2.

Handoff avi 4 days ago

Avi Heartbeat moved extract-shared-agent-api-client to reviewed after carl + alex reported merge-ready. Left for Steffon QA. Reports: - carl: merge-ready - Primary review: acceptance met, focused tests/DoR/CI green, no blockers; recommend Avi proceed merge-ready. - alex: merge-ready - No blockers found. Shared AgentApi preserves the token/cache/base-url/HTTP behavior for the three bin clients, focused tests and CI are green, and merge safety is clean.

Comment 4 days ago

PRIMARY review (Carl) — ALL-CLEAR, post-merge straggler review vs origin/release. (1) Divergences intact: timeouts 2/5 (atomic-event), 2/4 (session-insights), 1/2 (capture-hook), pinned by agent_api_test; 401 invalidation only in atomic-event + capture-hook, session-insights deliberately never invalidates; :get/:post superset changed no call site. (2) Secret/token handling byte-equivalent: same token.json cache path + 300s margin, same ENV -> op read -> repo .env order, no secret printed; bin/lib REPO_ROOT anchor resolves identically to old bin/ anchor incl worktree branch. (3) Drive-bys scope-clean: session-insights exec-bit restore matches documented 100755 contract (atomic-capture-hook.md:259); dropped requires verified truly unused on release (no Digest/URI/Net::HTTP left). (4) Sequencing confirmed: extraction 57458640 built on top of 12e9d23a/58bbd667/9b98b37e/6481f708; agent_api.rb unchanged since; PR 357 later edits preserved the divergences. (5) All four lib test files green against an origin/release export: 96 runs/372 asserts/0 failures; three existing test files untouched; checks_run covers library dor_tiers [unit,integration] + full-suite/rubocop certs. LIGHT review (Alex, docs seat) — ALL-CLEAR: atomic-capture-hook.md describes behavior not implementation, every claim still holds; wider doc grep clean; optional nice-to-have (non-blocking): one line naming bin/lib/agent_api.rb + test/lib/agent_api_test.rb as the shared auth layer. No conductor action needed.

Sealed-bid sizing

Edit →

Alex (PM)

Avi (PO)

SMALL

Dev

SMALL

Actual

XL