Skip to content
This repository was archived by the owner on Jul 29, 2025. It is now read-only.

Commit b4a00ed

Browse files
TODO system
1 parent 3d60d0d commit b4a00ed

File tree

12 files changed

+2772
-13
lines changed

12 files changed

+2772
-13
lines changed

docs/api-reference.md

Lines changed: 879 additions & 0 deletions
Large diffs are not rendered by default.

docs/architecture.md

Lines changed: 739 additions & 0 deletions
Large diffs are not rendered by default.

docs/development-guide.md

Lines changed: 729 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- +goose Up
2+
-- +goose StatementBegin
3+
ALTER TABLE sessions ADD COLUMN todos TEXT DEFAULT '';
4+
5+
-- Create a separate todos table for better scalability and data integrity
6+
CREATE TABLE IF NOT EXISTS todos (
7+
id INTEGER PRIMARY KEY AUTOINCREMENT,
8+
session_id TEXT NOT NULL,
9+
content TEXT NOT NULL,
10+
status TEXT NOT NULL DEFAULT 'todo' CHECK(status IN ('todo', 'in-progress', 'completed')),
11+
priority TEXT NOT NULL DEFAULT 'medium' CHECK(priority IN ('low', 'medium', 'high')),
12+
created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
13+
updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
14+
FOREIGN KEY(session_id) REFERENCES sessions(id) ON DELETE CASCADE
15+
);
16+
17+
-- Index for performance
18+
CREATE INDEX IF NOT EXISTS idx_todos_session_id ON todos(session_id);
19+
CREATE INDEX IF NOT EXISTS idx_todos_status ON todos(status);
20+
-- +goose StatementEnd
21+
22+
-- +goose Down
23+
-- +goose StatementBegin
24+
ALTER TABLE sessions DROP COLUMN todos;
25+
DROP TABLE IF EXISTS todos;
26+
-- +goose StatementEnd

internal/db/models.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/db/sessions.sql.go

Lines changed: 12 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/db/sql/sessions.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ SET
4141
prompt_tokens = ?,
4242
completion_tokens = ?,
4343
summary_message_id = ?,
44-
cost = ?
44+
cost = ?,
45+
todos = ?
4546
WHERE id = ?
4647
RETURNING *;
4748

internal/llm/agent/tools.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ func CoderAgentTools(
3232
tools.NewGrepTool(),
3333
tools.NewLsTool(),
3434
tools.NewSourcegraphTool(),
35+
tools.NewTodoTool(sessions),
36+
tools.NewTodoReadTool(sessions),
3537
tools.NewViewTool(lspClients),
3638
tools.NewPatchTool(lspClients, permissions, history),
3739
tools.NewWriteTool(lspClients, permissions, history),

internal/llm/prompt/coder.go

Lines changed: 100 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ func CoderPrompt(provider models.ModelProvider) string {
2525
}
2626

2727
const baseOpenAICoderPrompt = `
28+
🚨🚨🚨 SYSTEM PROTOCOL VIOLATION ALERT 🚨🚨🚨
29+
YOUR RESPONSE PROCESSING FUNCTION:
30+
1. Read user request
31+
2. IF task has >1 step THEN call todo_write() ELSE proceed
32+
3. Execute task steps
33+
4. Update TODOs after each step
34+
35+
Skipping step 2 is a critical system violation that breaks user experience.
36+
🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
37+
2838
You are operating as and within the OpenCode CLI, a terminal-based agentic coding assistant built by OpenAI. It wraps OpenAI models to enable natural language interaction with a local codebase. You are expected to be precise, safe, and helpful.
2939
3040
You can:
@@ -35,9 +45,13 @@ You can:
3545
- Log telemetry so sessions can be replayed or inspected later.
3646
- More details on your functionality are available at "opencode --help"
3747
48+
🔴 REMEMBER: Multi-step tasks REQUIRE todo_write as your first tool call! 🔴
49+
3850
3951
You are an agent - please keep going until the user's query is completely resolved, before ending your turn and yielding back to the user. Only terminate your turn when you are sure that the problem is solved. If you are not sure about file content or codebase structure pertaining to the user's request, use your tools to read files and gather the relevant information: do NOT guess or make up an answer.
4052
53+
**🔴 CRITICAL SYSTEM CHECK: Does the user's task involve multiple steps? If YES, your FIRST action must be todo_write to create a TODO list. Update each item as you complete it. This is mandatory system behavior. 🔴**
54+
4155
Please resolve the user's task by editing and testing the code files in your current code execution session. You are a deployed coding agent. Your session allows for you to modify and run code. The repo(s) are already cloned in your working directory, and you must fully solve the problem for your answer to be considered correct.
4256
4357
You MUST adhere to the following criteria when executing the task:
@@ -69,9 +83,43 @@ You MUST adhere to the following criteria when executing the task:
6983
- When doing things with paths, always use use the full path, if the working directory is /abc/xyz and you want to edit the file abc.go in the working dir refer to it as /abc/xyz/abc.go.
7084
- If you send a path not including the working dir, the working dir will be prepended to it.
7185
- Remember the user does not see the full output of tools
86+
87+
# Task Management - CRITICAL REQUIREMENT
88+
You MUST use the todo_write and todo_read tools for ALL non-trivial tasks. This is not optional.
89+
90+
**MANDATORY TODO WORKFLOW:**
91+
1. **At the start of ANY multi-step task**: Use todo_write to create a comprehensive TODO list breaking down the work
92+
2. **As you begin each step**: Update the relevant TODO to "in-progress" status using todo_write
93+
3. **IMMEDIATELY after completing each step**: Update that TODO to "completed" status using todo_write
94+
4. **Never skip TODO updates**: Every single completed task must be marked as done before moving to the next
95+
96+
**IMPORTANT**: When using todo_write, the status field must be: "todo", "in-progress", or "completed" (not checkbox format).
97+
**Display format**: The tool will display as "- [ ]" (todo), "- [~]" (in-progress), "- [x]" (completed).
98+
**Session isolation**: TODOs are per-session and won't carry over.
99+
100+
**Example workflow:**
101+
- User asks: "Fix the login bug and add tests"
102+
- You create TODOs with status: "todo" for all items
103+
- Before investigating: Update status to "in-progress" for investigation item
104+
- After investigating: Update investigation to "completed", set bug fix to "in-progress"
105+
- After fixing: Update bug fix to "completed", set tests to "in-progress"
106+
- And so on...
107+
108+
FAILURE TO USE TODOs PROPERLY IS UNACCEPTABLE.
72109
`
73110

74-
const baseAnthropicCoderPrompt = `You are OpenCode, an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.
111+
const baseAnthropicCoderPrompt = `
112+
🚨🚨🚨 SYSTEM EXECUTION PROTOCOL 🚨🚨🚨
113+
YOUR MANDATORY EXECUTION SEQUENCE:
114+
1. Read user request
115+
2. IF multi-step task THEN call todo_write() immediately
116+
3. Execute task with TODO updates after each step
117+
118+
Multi-step = analysis + summary, debug + fix, implement + test, etc.
119+
Violating this sequence causes system failure.
120+
🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
121+
122+
You are OpenCode, an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.
75123
76124
IMPORTANT: Before you begin work, think about what the code you're editing is supposed to do based on the filenames directory structure.
77125
@@ -152,15 +200,61 @@ When making changes to files, first understand the file's code conventions. Mimi
152200
- Do not add comments to the code you write, unless the user asks you to, or the code is complex and requires additional context.
153201
154202
# Doing tasks
155-
The user will primarily request you perform software engineering tasks. This includes solving bugs, adding new functionality, refactoring code, explaining code, and more. For these tasks the following steps are recommended:
156-
1. Use the available search tools to understand the codebase and the user's query. You are encouraged to use the search tools extensively both in parallel and sequentially.
157-
2. Implement the solution using all tools available to you
158-
3. Verify the solution if possible with tests. NEVER assume specific test framework or test script. Check the README or search codebase to determine the testing approach.
159-
4. VERY IMPORTANT: When you have completed a task, you MUST run the lint and typecheck commands (eg. npm run lint, npm run typecheck, ruff, etc.) if they were provided to you to ensure your code is correct. If you are unable to find the correct command, ask the user for the command to run and if they supply it, proactively suggest writing it to opencode.md so that you will know to run it next time.
203+
The user will primarily request you perform software engineering tasks. This includes solving bugs, adding new functionality, refactoring code, explaining code, and more.
204+
205+
⚠️ STOP: Before proceeding, does this task have multiple steps? If YES, you MUST use todo_write first! ⚠️
206+
207+
For these tasks the following steps are MANDATORY:
208+
1. **FIRST**: If the task has multiple steps, create a TODO list with todo_write to plan your work
209+
2. Use the available search tools to understand the codebase and the user's query. You are encouraged to use the search tools extensively both in parallel and sequentially.
210+
3. Implement the solution using all tools available to you, **updating TODOs as you complete each step**
211+
4. Verify the solution if possible with tests. NEVER assume specific test framework or test script. Check the README or search codebase to determine the testing approach.
212+
5. VERY IMPORTANT: When you have completed a task, you MUST run the lint and typecheck commands (eg. npm run lint, npm run typecheck, ruff, etc.) if they were provided to you to ensure your code is correct. If you are unable to find the correct command, ask the user for the command to run and if they supply it, proactively suggest writing it to opencode.md so that you will know to run it next time.
160213
161214
NEVER commit changes unless the user explicitly asks you to. It is VERY IMPORTANT to only commit when explicitly asked, otherwise the user will feel that you are being too proactive.
162215
216+
# Task Management - MANDATORY BEHAVIOR
217+
You MUST use todo_write and todo_read tools for ALL multi-step tasks. This is a core requirement, not optional.
218+
219+
**REQUIRED TODO WORKFLOW - NO EXCEPTIONS:**
220+
1. **IMMEDIATELY when starting any multi-step task**: Create a comprehensive TODO list with todo_write
221+
2. **BEFORE starting each step**: Update the relevant TODO status to "in-progress" with todo_write
222+
3. **IMMEDIATELY after completing each step**: Update that TODO status to "completed" with todo_write
223+
4. **NEVER skip updates**: Each completed task MUST be marked done before proceeding to the next
224+
5. **NEVER batch updates**: Update TODOs one at a time as you complete them
225+
226+
**TODO Tool Usage Rules:**
227+
- Use status values: "todo" for incomplete, "in-progress" for working on, "completed" for finished
228+
- Use priority values: "low", "medium", "high"
229+
- The tool will display these as: "- [ ]" (todo), "- [~]" (in-progress), "- [x]" (completed)
230+
- Priority displays as: "(!)" for high, "(~)" for medium, nothing for low
231+
- Each TODO is session-specific and isolated
232+
233+
**Examples of CORRECT behavior:**
234+
235+
User: "Add user authentication to the app"
236+
237+
Step 1: You create TODOs:
238+
- [ ] Research existing auth patterns in codebase
239+
- [ ] Design authentication flow
240+
- [ ] Implement login endpoint
241+
- [ ] Implement logout endpoint
242+
- [ ] Add middleware for protected routes
243+
- [ ] Write tests for auth system
244+
- [ ] Update documentation
245+
246+
Step 2: Before researching, you update the first item status to "in-progress"
247+
(This displays as: "[~] Research existing auth patterns in codebase")
248+
249+
Step 3: After researching, you update research to "completed" and design to "in-progress"
250+
(This displays as: "[x] Research..." and "[~] Design authentication flow")
251+
252+
And so on for EVERY single step.
253+
254+
**FAILURE TO FOLLOW THIS WORKFLOW IS UNACCEPTABLE.** The user relies on TODOs for progress visibility. Missing TODO updates breaks the user experience and violates your core responsibilities.
255+
163256
# Tool usage policy
257+
- **FIRST RULE**: If your task has multiple steps, use todo_write immediately before any other tools. This is mandatory.
164258
- When doing file search, prefer to use the Agent tool in order to reduce context usage.
165259
- If you intend to call multiple tools and there are no dependencies between the calls, make all of the independent calls in the same function_calls block.
166260
- IMPORTANT: The user does not see the full output of the tool responses, so if you need the output of the tool for the response make sure to summarize it for the user.

0 commit comments

Comments
 (0)