report/2026-03-13-08-46-token-optimization-implementation.md
Implemented the token-optimization plan across heartbeat orchestration, issue context APIs, adapter prompt construction, skill exposure, and agent configuration UX.
The main behavior changes are:
forceFreshSession wakes or new issue assignment wakes.GET /api/agents/me/inbox-lite, GET /api/issues/:id/heartbeat-context, and comment delta queries via GET /api/issues/:id/comments?after=...&order=asc.paperclip skill now teaches agents to use those compact/incremental APIs first, while keeping full-thread fetches as a cold-start fallback.bootstrapPromptTemplate correctly.paperclip, para-memory-files, and paperclip-create-agent. create-agent-adapter was moved to .agents/skills/create-agent-adapter.Important follow-up finding from real-run review:
codex_local currently injects Paperclip skills into the shared Codex skills home ($CODEX_HOME/skills or ~/.codex/skills) rather than mounting a worktree-local skill directory.skills/paperclip/SKILL.md guidance while Codex still follows an older checkout's skill content.codex_local skill isolation or symlink repair.Files with the most important implementation work:
server/src/services/heartbeat.tsserver/src/services/issues.tsserver/src/routes/issues.tsserver/src/routes/agents.tsserver/src/routes/access.tsskills/paperclip/SKILL.mdpackages/adapters/*/src/server/execute.tspackages/adapters/*/src/ui/build-config.tsui/src/components/AgentConfigForm.tsxVerification completed successfully:
pnpm -r typecheckpnpm test:runpnpm buildWhile verifying, I also fixed two existing embedded-postgres typing mismatches so repo-wide typecheck and build pass again:
packages/db/src/migration-runtime.tscli/src/commands/worktree.tsNext useful follow-up is measuring the before/after effect in real runs now that telemetry is less misleading and prompt/session reuse behavior is consistent across adapters.