Repository navigation
feat(session): native per-session goals with /goal and autonomous pursuit - #32743
dfredriksen wants to merge 10 commits into
Conversation
Add a persisted, per-session "goal": a single objective with a status lifecycle (active / paused / completed), optional token budget, and running token/time usage. Closes anomalyco#27167. Closes anomalyco#29445. - Goal service + Drizzle schema + migration (core and opencode), exposed over the HTTP API as GET/POST/PATCH/DELETE /session/{sessionID}/goal and in the generated SDK as `client.session.goal.*`. - Inject the active goal as a <session-goal> block at the head of the system prompt every turn, and carry it into the compaction summary so it survives context overflow. No goal -> no block. - A model-callable `goal` tool (update / pause / resume / complete) lets the agent steer and terminate its own work; completing requires verification. - Setting or resuming a goal starts autonomous pursuit: SessionPrompt.pursue takes turns toward the goal and auto-continues after each natural stop until the model completes it, it is paused, the token budget is reached, or a hard step cap is hit. A default budget bounds runaway cost; pausing/completing cancels the in-flight turn so it stops promptly. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add `/goal` to the interactive TUI (slash autocomplete + Session command palette) and to `opencode run`. `/goal set "..."`, `/goal pause|resume| complete|clear|show` dispatch to the typed session goal client. Argument parsing is a single dependency-free helper, @opencode-ai/core/session/ goal-command, shared by both frontends. The prompt status row shows the active goal (◆ pursuing goal / ⏸ goal paused / ✓ goal done), seeded from session.goal.get on session open, updated optimistically on /goal commands, and kept live via goal.updated events in the sync store. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Exercise GET/POST/PATCH/DELETE /session/{sessionID}/goal in the HttpApi
coverage harness, including the complete-with-verification transition, and
provide the Goal layer to the prompt test so the system-prompt path runs with
goals enabled.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
The following comment was made by an LLM, it may be inaccurate: I found one potentially related PR: feat: add native session goals (PR #27163) This PR appears to be related as it also implements native session goals functionality. The current PR (#32743) may have been a refresh or iteration on this earlier work, since the description mentions it "supersedes the earlier exploratory attempts (#29721, #31762, both closed)" and addresses the same underlying issues (#27167, #29445). You should verify if PR #27163 is still open or if it was closed in favor of the current PR #32743. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Cover set/get, update, pause/resume, complete (status + verification), recordUsage accumulation (active only), and clear directly against the Goal service, alongside the existing HttpApi route coverage. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Quick status: rebased onto current |
|
Additional local crash fix pushed to Quantyra/session-goals: commit 41fb8f1 fixes the submit-time TUI crash [Reconciler] Unknown component type: spinner\ by removing direct lowercase <spinner>\ custom-element usage from the prompt/status/footer render paths and falling back to normal <text>... \ indicators. Verified locally on Windows with \�un run build\ (Windows x64 smoke test passed at \ |
|
Related draft opened at #32924. It explores a workspace-local .opencode/goals foundation with richer planning/evidence/checkpoint abstractions.\n\nI am tracking it for possible consolidation. The main open design question is session-scoped DB persistence vs workspace-local file persistence, or a layered model where session runtime state remains DB-backed and workspace goal planning/evidence can build on top. |
|
Design summary for review:\n\nProblem:\nUsers want native /goal behavior similar to Codex/Claude: a way to keep the agent oriented on a task across turns and continue autonomously until explicitly paused or completed.\n\nProposed scope:\nThis PR implements one active goal per session as runtime state. It is intentionally not a full workspace/project planning system.\n\nDesign choices:\n- Persist goal state in the existing session DB because it affects session runtime behavior, prompt injection, compaction, API/SDK routes, and continuation.\n- Inject the active goal into the system prompt only when present, and preserve it through compaction.\n- Use a model-facing goal tool as the clean termination/control signal for autonomous pursuit.\n- Keep /goal UX small: set/show/pause/resume/complete/clear.\n- Add token/time/step accounting so autonomous continuation has hard bounds.\n\nAlternatives considered:\n- Plugin-only: lower core impact, but weaker integration with prompt lifecycle, compaction, API/SDK, and tool-based completion.\n- Workspace-local file store: useful for richer planning/evidence, but seems better as a higher-level layer than the first runtime persistence boundary.\n- No autonomous loop: simpler, but does not solve the main long-task continuation use case.\n\nOpen design questions:\n1. Should the first merged implementation be session-scoped, workspace-scoped, or layered?\n2. Should /goal be core runtime behavior or a plugin?\n3. Should richer evidence/checkpoint/history features land later as separate PRs?\n\nHappy to adjust or split this PR based on maintainer preference. |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #27167
Closes #29445
Type of change
What does this PR do?
Adds a persisted per-session goal with a
/goalcommand. A goal has a status (active / paused / completed), an optional token budget, and accumulated token/time usage.goaltable + migration), exposed over the HTTP API and SDK assession.goal.*.<session-goal>block each turn, and folded into the compaction summary so it is not lost on context overflow. No goal -> no block.SessionPrompt.pursue) that re-prompts after each turn until the model calls thegoaltool to mark it complete, the user pauses it, or the token budget / step cap is hit. Pausing or completing cancels the in-flight turn so work stops immediately./goal set|pause|resume|complete|clear|showworks in the interactive TUI andopencode run; the prompt footer shows the goal state.The loop deliberately wraps the existing
prompt()path rather than editing the core run loop, to keep the change contained. The model-facinggoaltool is what lets the model end its own loop cleanly - without it the loop has no terminate signal.Hardening added after local crash testing
20260618064913_cultured_red_wolf) idempotent withCREATE TABLE IF NOT EXISTSandCREATE INDEX IF NOT EXISTS. This fixes an existing-profile upgrade state where thegoaltable already exists but the migration marker is missing; before this fix, startup could fail withtable goal already exists.git add --sparsefails withunknown option 'sparse', opencode retries the same pathspec add without--sparse. This was reproduced locally with Git 2.27.0.windows.1.How did you verify your code works?
bun typecheckpasses forpackages/core.bun typecheckpasses forpackages/opencode./session/{id}/goalroutes, including the complete-with-verification transition.test/session/goal.test.tscovers the service lifecycle (set/get, update, pause/resume, complete, recordUsage accumulation, clear).bun test test/database-migration.test.tsfrompackages/core: 15 pass / 0 fail, including the new idempotent-goal-migration regression.database-migrationandsession-runnercompaction tests pass;bun run migration --checkpasses (regenerated on Linux - see below).debug snapshot track --print-logs --log-level DEBUGcompleted and produced hash29bc5c5c39b37c929d1fd0c8aad68130f1827157, with nogit add --sparsewarning.Note: a full root pre-push
bun turbo typecheckcurrently fails in@opencode-ai/apponsrc/custom-elements.d.tsin this checkout; that file is unchanged by this PR update. The focused changed-package checks above pass.Screenshots / recordings
The prompt footer shows
pursuing goal/goal paused/goal done, left of the context/usage hints. Happy to attach a recording.Checklist
Migration codegen: the Drizzle snapshot (
packages/core/schema.json) andschema.gen.tsbaseline are regenerated and consistent -bun run migration --checkpasses (authored on Windows where drizzle-kit cannot run, so the regen was done on a Linux runner; no outstanding codegen steps).Also aware of #27163 (also "native session goals") - glad to consolidate behind whichever the maintainers prefer.