Compare commits

...

3 Commits

Author SHA1 Message Date
c72effda28 Added opencode.json template with current working config
Some checks failed
Format / format (push) Has been cancelled
2025-09-11 21:57:17 +02:00
d78bbff439 Remove path-based restrictions 2025-09-11 21:01:09 +02:00
6835f9084c Add script for simplified local build 2025-09-11 20:49:03 +02:00
6 changed files with 118 additions and 18 deletions

43
build_local.sh Executable file
View File

@@ -0,0 +1,43 @@
#!/bin/bash
set -e
echo "Building opencode locally..."
# Get the absolute paths
REPO_ROOT="$(cd "$(dirname "$0")" && pwd)"
TUI_DIR="$REPO_ROOT/packages/tui"
SERVER_DIR="$REPO_ROOT/packages/opencode"
TUI_BINARY_PATH="$TUI_DIR/cmd/opencode/dist/tui"
echo "Repository root: $REPO_ROOT"
# Build the TUI binary
echo "Building TUI binary..."
cd "$TUI_DIR"
go build -o cmd/opencode/dist/tui cmd/opencode/main.go
echo "✓ TUI built: $TUI_BINARY_PATH"
# Build the server CLI with embedded TUI path
echo "Building server CLI..."
cd "$SERVER_DIR"
bun build \
--define OPENCODE_TUI_PATH="'$TUI_BINARY_PATH'" \
--define OPENCODE_VERSION="'0.7.2'" \
--compile \
--target=bun-linux-x64 \
--outfile=opencode-cli \
./src/index.ts
echo "✓ Server CLI built: $SERVER_DIR/opencode-cli"
echo ""
echo "Build complete!"
echo ""
echo "To run opencode from anywhere:"
echo " $SERVER_DIR/opencode-cli"
echo ""
echo "To run from a specific directory:"
echo " $SERVER_DIR/opencode-cli /path/to/your/project"
echo ""
echo "To run headless server only:"
echo " $SERVER_DIR/opencode-cli serve"

57
opencode.template.jsonc Normal file
View File

@@ -0,0 +1,57 @@
{
// Template opencode configuration with restrictive permissions
// Copy this file to ~/.config/opencode.json (or opencode.json inside a repo)
// and modify as needed
"$schema": "https://opencode.ai/config.json",
"mcp": {
"weather": {
"type": "local",
"command": ["opencode", "x", "@h1deya/mcp-server-weather"]
}
},
"permission": {
"bash": {
"git branch -d": "ask",
"git branch -D": "ask",
"git status": "allow",
"git diff": "allow",
"git log": "allow",
"git show": "allow",
"git branch": "allow",
"git remote": "allow",
"git fetch": "allow",
"git pull": "allow",
"git merge": "ask",
"git rebase": "ask",
"git commit": "ask",
"git push": "ask",
"git checkout": "ask",
"git switch": "ask",
"git reset": "ask",
"git revert": "ask",
"git rm": "ask",
"git mv": "ask",
"git worktree": "ask",
"cat": "allow",
"tail": "allow",
"head": "allow",
"less": "allow",
"more": "allow",
"grep": "allow",
"find": "allow",
"ls": "allow",
"pwd": "allow",
"cd": "allow",
"mkdir": "ask",
"rm": "ask",
"rmdir": "ask",
"mv": "ask",
"cp": "ask",
"touch": "ask",
"chmod": "ask",
"chown": "ask",
"su": "deny",
"sudo": "deny"
}
}
}

View File

@@ -4,7 +4,7 @@ import { exec } from "child_process"
import { Tool } from "./tool"
import DESCRIPTION from "./bash.txt"
import { Permission } from "../permission"
import { Filesystem } from "../util/filesystem"
// import { Filesystem } from "../util/filesystem"
import { lazy } from "../util/lazy"
import { Log } from "../util/log"
import { Wildcard } from "../util/wildcard"
@@ -87,11 +87,11 @@ export const BashTool = Tool.define("bash", {
.text()
.then((x) => x.trim())
log.info("resolved path", { arg, resolved })
if (resolved && !Filesystem.contains(Instance.directory, resolved)) {
throw new Error(
`This command references paths outside of ${Instance.directory} so it is not allowed to be executed.`,
)
}
// if (resolved && !Filesystem.contains(Instance.directory, resolved)) {
// throw new Error(
// `This command references paths outside of ${Instance.directory} so it is not allowed to be executed.`,
// )
// }
}
}

View File

@@ -13,7 +13,7 @@ import DESCRIPTION from "./edit.txt"
import { File } from "../file"
import { Bus } from "../bus"
import { FileTime } from "../file/time"
import { Filesystem } from "../util/filesystem"
// import { Filesystem } from "../util/filesystem"
import { Instance } from "../project/instance"
import { Agent } from "../agent/agent"
@@ -35,9 +35,9 @@ export const EditTool = Tool.define("edit", {
}
const filePath = path.isAbsolute(params.filePath) ? params.filePath : path.join(Instance.directory, params.filePath)
if (!Filesystem.contains(Instance.directory, filePath)) {
throw new Error(`File ${filePath} is not in the current working directory`)
}
// if (!Filesystem.contains(Instance.directory, filePath)) {
// throw new Error(`File ${filePath} is not in the current working directory`)
// }
const agent = await Agent.get(ctx.agent)
let diff = ""

View File

@@ -5,7 +5,7 @@ import { Tool } from "./tool"
import { LSP } from "../lsp"
import { FileTime } from "../file/time"
import DESCRIPTION from "./read.txt"
import { Filesystem } from "../util/filesystem"
// import { Filesystem } from "../util/filesystem"
import { Instance } from "../project/instance"
const DEFAULT_READ_LIMIT = 2000
@@ -23,9 +23,9 @@ export const ReadTool = Tool.define("read", {
if (!path.isAbsolute(filepath)) {
filepath = path.join(process.cwd(), filepath)
}
if (!ctx.extra?.["bypassCwdCheck"] && !Filesystem.contains(Instance.directory, filepath)) {
throw new Error(`File ${filepath} is not in the current working directory`)
}
// if (!ctx.extra?.["bypassCwdCheck"] && !Filesystem.contains(Instance.directory, filepath)) {
// throw new Error(`File ${filepath} is not in the current working directory`)
// }
const file = Bun.file(filepath)
if (!(await file.exists())) {

View File

@@ -7,7 +7,7 @@ import DESCRIPTION from "./write.txt"
import { Bus } from "../bus"
import { File } from "../file"
import { FileTime } from "../file/time"
import { Filesystem } from "../util/filesystem"
// import { Filesystem } from "../util/filesystem"
import { Instance } from "../project/instance"
import { Agent } from "../agent/agent"
@@ -19,9 +19,9 @@ export const WriteTool = Tool.define("write", {
}),
async execute(params, ctx) {
const filepath = path.isAbsolute(params.filePath) ? params.filePath : path.join(Instance.directory, params.filePath)
if (!Filesystem.contains(Instance.directory, filepath)) {
throw new Error(`File ${filepath} is not in the current working directory`)
}
// if (!Filesystem.contains(Instance.directory, filepath)) {
// throw new Error(`File ${filepath} is not in the current working directory`)
// }
const file = Bun.file(filepath)
const exists = await file.exists()