Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .devcontainer/devcontainer-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"features": {
"ghcr.io/devcontainers-contrib/features/bun:1": {
"version": "1.1.0",
"resolved": "ghcr.io/devcontainers-extra/features/bun@sha256:0624284ecaead9dd4c6654616a7f939cfa4ebcbc60593700a74e35b1767befa5",
"integrity": "sha256:0624284ecaead9dd4c6654616a7f939cfa4ebcbc60593700a74e35b1767befa5"
}
}
}
8 changes: 8 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "opencode-dev",
"image": "mcr.microsoft.com/devcontainers/typescript-node:latest",
"features": {
"ghcr.io/devcontainers-contrib/features/bun:1": {}
},
"postCreateCommand": "bun --version"
}
36 changes: 0 additions & 36 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/app/src/utils/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const defaults: Record<string, string> = {
ask: "var(--icon-agent-ask-base)",
build: "var(--icon-agent-build-base)",
docs: "var(--icon-agent-docs-base)",
learn: "var(--icon-agent-docs-base)",
plan: "var(--icon-agent-plan-base)",
}

Expand Down
20 changes: 20 additions & 0 deletions packages/opencode/src/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ProviderTransform } from "@/provider/transform"
import PROMPT_GENERATE from "./generate.txt"
import PROMPT_COMPACTION from "./prompt/compaction.txt"
import PROMPT_EXPLORE from "./prompt/explore.txt"
import PROMPT_LEARN from "./prompt/learn.txt"
import PROMPT_SUMMARY from "./prompt/summary.txt"
import PROMPT_TITLE from "./prompt/title.txt"
import { Permission } from "@/permission"
Expand Down Expand Up @@ -179,6 +180,25 @@ const layer = Layer.effect(
mode: "primary",
native: true,
},
learn: {
name: "learn",
description: "Learn mode. Explores the codebase without making changes.",
options: {},
permission: Permission.merge(
defaults,
Permission.fromConfig({
"*": "deny",
read: "allow",
glob: "allow",
grep: "allow",
webfetch: "allow",
websearch: "allow",
}),
),
mode: "primary",
native: true,
prompt: PROMPT_LEARN,
},
general: {
name: "general",
description: `General-purpose agent for researching complex questions and executing multi-step tasks. Use this agent to execute multiple units of work in parallel.`,
Expand Down
3 changes: 3 additions & 0 deletions packages/opencode/src/agent/prompt/learn.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Learn mode is active. Help the user understand the codebase, answer questions, and explain possible changes.

Do not attempt to edit files, run shell commands, invoke subagents, or make any other changes. If the user asks for an implementation, explain the change that would be needed and ask them to switch to Build mode when they want it applied.
11 changes: 11 additions & 0 deletions packages/opencode/src/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,11 @@ const layer = Layer.effect(
const shell: (input: ShellInput) => Effect.Effect<SessionV1.WithParts, Session.BusyError> = Effect.fn(
"SessionPrompt.shell",
)(function* (input: ShellInput) {
if (input.agent === "learn") {
const error = new NamedError.Unknown({ message: "Learn mode does not allow shell commands." })
yield* events.publish(Session.Event.Error, { sessionID: input.sessionID, error: error.toObject() })
throw error
}
const ready = yield* Latch.make()
return yield* state.startShell(input.sessionID, lastAssistant(input.sessionID), shellImpl(input, ready), ready)
})
Expand All @@ -1369,6 +1374,12 @@ const layer = Layer.effect(
}
const agentName = cmd.agent ?? input.agent

if (input.agent === "learn" || agentName === "learn") {
const error = new NamedError.Unknown({ message: "Learn mode does not allow commands." })
yield* events.publish(Session.Event.Error, { sessionID: input.sessionID, error: error.toObject() })
throw error
}

const raw = input.arguments.match(argsRegex) ?? []
const args = raw.map((arg) => arg.replace(quoteTrimRegex, ""))
const templateCommand = yield* Effect.promise(async () => cmd.template)
Expand Down
12 changes: 12 additions & 0 deletions packages/opencode/src/session/reminders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Session } from "./session"
import PROMPT_PLAN from "./prompt/plan.txt"
import BUILD_SWITCH from "./prompt/build-switch.txt"
import PLAN_MODE from "./prompt/plan-mode.txt"
import PROMPT_LEARN from "../agent/prompt/learn.txt"

export const apply = Effect.fn("SessionReminders.apply")(function* (input: {
messages: SessionV1.WithParts[]
Expand All @@ -23,6 +24,17 @@ export const apply = Effect.fn("SessionReminders.apply")(function* (input: {
const userMessage = input.messages.findLast((msg) => msg.info.role === "user")
if (!userMessage) return input.messages

if (input.agent.name === "learn") {
userMessage.parts.push({
id: PartID.ascending(),
messageID: userMessage.info.id,
sessionID: userMessage.info.sessionID,
type: "text",
text: PROMPT_LEARN,
synthetic: true,
})
}

if (!flags.experimentalPlanMode) {
if (input.agent.name === "plan") {
userMessage.parts.push({
Expand Down
3 changes: 3 additions & 0 deletions packages/opencode/src/session/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const resolve = Effect.fn("SessionTools.resolve")(function* (input: {
providerID: input.model.providerID,
agent: input.agent,
permission: input.session.permission,
readOnly: input.agent.name === "learn",
})) {
const schema = ProviderTransform.schema(input.model, ToolJsonSchema.fromTool(item))
tools[item.id] = tool({
Expand Down Expand Up @@ -133,6 +134,8 @@ export const resolve = Effect.fn("SessionTools.resolve")(function* (input: {
})
}

if (input.agent.name === "learn") return tools

const hasMcpResourceServer = Object.values(yield* mcp.clients()).some(
(client) => !!client.getServerCapabilities()?.resources,
)
Expand Down
Loading
Loading