feat(opencode): add enforced learn mode - #19
vmiloserdov wants to merge 6 commits into
Conversation
yswcyswc
left a comment
There was a problem hiding this comment.
The read-only protections look solid overall. I left one integration question about allowing read-only learning commands within Learn mode.
| } | ||
| const agentName = cmd.agent ?? input.agent | ||
|
|
||
| if (input.agent === "learn" || agentName === "learn") { |
There was a problem hiding this comment.
Should Learn mode block every slash command here, or only commands that can modify the repository? As written, this appears to prevent read-only learning commands such as /group and /newcomer from running while Learn mode is active. Since these features are intended to integrate with Learn mode, it may be useful to allow explicitly read-only commands while continuing to block shell expansions and mutation-capable commands.
There was a problem hiding this comment.
Great note. Yes, Learn mode will allow a specific list of commands, and I think this part should be reserved for another PR, when we move onto the next stage of the project, which is the integration of the Learn Mode.
Issue for this PR
Closes #15
Type of change
What does this PR do?
User story
As a student completing a coding assignment, I want to use AI to understand the codebase while writing the assignment myself, so that I can strengthen my software engineering skills.
The existing Plan mode relies on a system prompt. That is useful guidance, but it cannot guarantee that a tool call will not modify the working tree. This PR adds Learn mode as an enforced read-only alternative for students who want explanations, code navigation, and research without allowing OpenCode to make changes for them.
Changes
read,glob,grep,webfetch, andwebsearch. Write tools, task delegation, custom tools, plugin tools, and MCP tools are omitted before the model can call them..devcontainersetup out of version control via.gitignore; it is only for my local container workflow and is not part of this feature.I did not use a "revert after the fact" strategy such as
git reset --hard. A reset could discard the student's own uncommitted work. Learn instead prevents mutation-capable paths from being exposed or started.How did you verify your code works?
Automated verification:
bun typecheckfrompackages/opencodebun test test/agent/agent.test.ts test/tool/registry.test.ts test/session/prompt.test.tsfrompackages/opencodeThe tests cover:
Manual verification:
!and attempted a command that writes a file. Learn rejected the command before execution.git diff --exit-codeandgit status --short.Screenshots / recordings
The Learn option uses the existing mode selector and agent styling. I will attach a short terminal recording of the read-only prompt and shell checks before this draft is marked ready for review.
How it looks:

Rejecting edit prompt:

Rejects the shell commands that are run in Shell mode (! in the front of the prompt):

Accepting the allowed prompt:

Link to GDrive recording:
https://drive.google.com/file/d/1gg9rFkDplu-3DVvuWCNoM--lAjMTzpln/view?usp=drive_link
Checklist