Skip to content

Commit 9cfd2d1

Browse files
committed
Add agent-formulated goal tool
1 parent ce93eec commit 9cfd2d1

6 files changed

Lines changed: 630 additions & 4 deletions

File tree

AGENTS.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Agent Notes
2+
3+
## Project Shape
4+
5+
This package is an OpenCode plugin with separate server and TUI entrypoints:
6+
7+
- `src/server.ts` is the server plugin. It registers the `/goal` command, goal tools, chat/session hooks, usage accounting, compaction context, and idle auto-continuation.
8+
- `src/state.ts` owns goal persistence and lifecycle state. It stores JSON at `OPENCODE_GOAL_STATE_PATH` when set, otherwise under the user's OpenCode data location.
9+
- `src/tui.tsx` is the Solid/OpenTUI sidebar and command-palette UI. It is exported as source, so avoid adding heavy runtime dependencies here unless there is a strong reason.
10+
- `src/prompts.ts` contains the goal-mode continuation/system/compaction prompts.
11+
- `test/` covers state, server hooks/tools, and TUI behavior with Bun tests.
12+
13+
## Change Guidelines
14+
15+
- Preserve the public Promise-based state API (`getGoal`, `createGoal`, `completeGoal`, etc.) because OpenCode hooks and tests call it directly.
16+
- Keep `zod` for OpenCode tool argument schemas unless the OpenCode plugin API explicitly supports another schema format.
17+
- Effect is intentionally used in the state/persistence boundary. Do not spread Effect into the TUI unless the benefit clearly outweighs the extra runtime footprint.
18+
- If server code imports a runtime dependency that should be resolved from `dependencies`, externalize it in the Bun build script so the package does not silently bundle it.
19+
- State writes should remain atomic: write to a temp file, then `rename` into place.
20+
- Use `OPENCODE_GOAL_STATE_PATH` for tests and smoke runs so you do not touch a real user's goal state.
21+
22+
## Local Validation
23+
24+
Before treating a code change as complete, run the relevant checks. For release-level changes, run the full local gate:
25+
26+
```bash
27+
bun run lint
28+
bun run typecheck
29+
bun test
30+
bun run build
31+
bun run pack:dry-run
32+
```
33+
34+
`bun run build` writes `dist/server.js`. The package only publishes `dist`, `src/tui.tsx`, `LICENSE`, and `README.md`, so confirm `npm pack --dry-run` includes what runtime installation needs.
35+
36+
## Publishing Flow
37+
38+
This repo publishes from GitHub Actions on pushes to `main`. The workflow computes the next patch version from npm, builds, publishes, and creates a GitHub release.
39+
40+
After pushing a release change, monitor the workflow with `gh run list --branch main` and `gh run watch <run-id> --exit-status`. Verify the release and package metadata after success:
41+
42+
```bash
43+
npm view @prevalentware/opencode-goal-plugin version dependencies
44+
gh release view v<version>
45+
```
46+
47+
## End-To-End Plugin Test
48+
49+
To test this plugin end to end, do not stop at unit tests. Run the local gates first: `bun run lint`, `bun run typecheck`, `bun test`, `bun run build`, and `bun run pack:dry-run`.
50+
51+
After publishing, verify the exact npm version with `npm view @prevalentware/opencode-goal-plugin version dependencies`. Install that version in an isolated temp OpenCode project with `opencode plugin @prevalentware/opencode-goal-plugin@<version>`, run `opencode debug config` to confirm the package is loaded and the `goal` command is registered, then run a smoke test with an isolated state file, for example:
52+
53+
```bash
54+
OPENCODE_GOAL_STATE_PATH="/tmp/opencode-goal-plugin-smoke/goals.json" opencode run "/goal create a smoke-test goal and then report the current goal state"
55+
```
56+
57+
The smoke test should show `create_goal` and `get_goal` tool calls and report an active goal. Inspect the state file afterward if you need to confirm JSON persistence.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This plugin adds:
66

77
- `/goal <objective>` as an OpenCode command for TUI, desktop, and web.
88
- A sidebar goal indicator with status, elapsed time, and objective.
9-
- Agent tools: `get_goal`, `create_goal`, `update_goal`, and `clear_goal`.
9+
- Agent tools: `get_goal`, `create_goal`, `set_goal`, `update_goal`, and `clear_goal`.
1010
- Goal close evidence: `complete` requires verified evidence, and `unmet` requires a concrete blocker.
1111
- Persistent per-session goal state.
1212
- Optional automatic continuation on `session.idle`.
@@ -85,6 +85,8 @@ Use `/goal <objective>` in a fresh OpenCode chat to create a long-running goal:
8585

8686
Bare `/goal` reports the current goal state. `/goal clear` clears the goal. The TUI also includes a `Goal` command-palette entry for viewing, refreshing, or clearing the current goal state without creating a new goal.
8787

88+
You can also ask the agent to formulate the objective and call `set_goal` itself, for example: "set your own goal to finish this refactor safely." The tool uses the agent-written objective but still only creates a goal when explicitly requested.
89+
8890
When writing the objective, include the scope, non-goals, and verification path when they matter. The agent is reminded to audit real files, command output, tests, or PR state before closing the goal.
8991

9092
The `update_goal` tool can close a goal in two ways:

0 commit comments

Comments
 (0)