Compare commits
3 Commits
dev
...
feature/un
| Author | SHA1 | Date | |
|---|---|---|---|
| c72effda28 | |||
| d78bbff439 | |||
| 6835f9084c |
43
build_local.sh
Executable file
43
build_local.sh
Executable 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
57
opencode.template.jsonc
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ import { exec } from "child_process"
|
|||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
import DESCRIPTION from "./bash.txt"
|
import DESCRIPTION from "./bash.txt"
|
||||||
import { Permission } from "../permission"
|
import { Permission } from "../permission"
|
||||||
import { Filesystem } from "../util/filesystem"
|
// import { Filesystem } from "../util/filesystem"
|
||||||
import { lazy } from "../util/lazy"
|
import { lazy } from "../util/lazy"
|
||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
import { Wildcard } from "../util/wildcard"
|
import { Wildcard } from "../util/wildcard"
|
||||||
@@ -87,11 +87,11 @@ export const BashTool = Tool.define("bash", {
|
|||||||
.text()
|
.text()
|
||||||
.then((x) => x.trim())
|
.then((x) => x.trim())
|
||||||
log.info("resolved path", { arg, resolved })
|
log.info("resolved path", { arg, resolved })
|
||||||
if (resolved && !Filesystem.contains(Instance.directory, resolved)) {
|
// if (resolved && !Filesystem.contains(Instance.directory, resolved)) {
|
||||||
throw new Error(
|
// throw new Error(
|
||||||
`This command references paths outside of ${Instance.directory} so it is not allowed to be executed.`,
|
// `This command references paths outside of ${Instance.directory} so it is not allowed to be executed.`,
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import DESCRIPTION from "./edit.txt"
|
|||||||
import { File } from "../file"
|
import { File } from "../file"
|
||||||
import { Bus } from "../bus"
|
import { Bus } from "../bus"
|
||||||
import { FileTime } from "../file/time"
|
import { FileTime } from "../file/time"
|
||||||
import { Filesystem } from "../util/filesystem"
|
// import { Filesystem } from "../util/filesystem"
|
||||||
import { Instance } from "../project/instance"
|
import { Instance } from "../project/instance"
|
||||||
import { Agent } from "../agent/agent"
|
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)
|
const filePath = path.isAbsolute(params.filePath) ? params.filePath : path.join(Instance.directory, params.filePath)
|
||||||
if (!Filesystem.contains(Instance.directory, filePath)) {
|
// if (!Filesystem.contains(Instance.directory, filePath)) {
|
||||||
throw new Error(`File ${filePath} is not in the current working directory`)
|
// throw new Error(`File ${filePath} is not in the current working directory`)
|
||||||
}
|
// }
|
||||||
|
|
||||||
const agent = await Agent.get(ctx.agent)
|
const agent = await Agent.get(ctx.agent)
|
||||||
let diff = ""
|
let diff = ""
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { Tool } from "./tool"
|
|||||||
import { LSP } from "../lsp"
|
import { LSP } from "../lsp"
|
||||||
import { FileTime } from "../file/time"
|
import { FileTime } from "../file/time"
|
||||||
import DESCRIPTION from "./read.txt"
|
import DESCRIPTION from "./read.txt"
|
||||||
import { Filesystem } from "../util/filesystem"
|
// import { Filesystem } from "../util/filesystem"
|
||||||
import { Instance } from "../project/instance"
|
import { Instance } from "../project/instance"
|
||||||
|
|
||||||
const DEFAULT_READ_LIMIT = 2000
|
const DEFAULT_READ_LIMIT = 2000
|
||||||
@@ -23,9 +23,9 @@ export const ReadTool = Tool.define("read", {
|
|||||||
if (!path.isAbsolute(filepath)) {
|
if (!path.isAbsolute(filepath)) {
|
||||||
filepath = path.join(process.cwd(), filepath)
|
filepath = path.join(process.cwd(), filepath)
|
||||||
}
|
}
|
||||||
if (!ctx.extra?.["bypassCwdCheck"] && !Filesystem.contains(Instance.directory, filepath)) {
|
// if (!ctx.extra?.["bypassCwdCheck"] && !Filesystem.contains(Instance.directory, filepath)) {
|
||||||
throw new Error(`File ${filepath} is not in the current working directory`)
|
// throw new Error(`File ${filepath} is not in the current working directory`)
|
||||||
}
|
// }
|
||||||
|
|
||||||
const file = Bun.file(filepath)
|
const file = Bun.file(filepath)
|
||||||
if (!(await file.exists())) {
|
if (!(await file.exists())) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import DESCRIPTION from "./write.txt"
|
|||||||
import { Bus } from "../bus"
|
import { Bus } from "../bus"
|
||||||
import { File } from "../file"
|
import { File } from "../file"
|
||||||
import { FileTime } from "../file/time"
|
import { FileTime } from "../file/time"
|
||||||
import { Filesystem } from "../util/filesystem"
|
// import { Filesystem } from "../util/filesystem"
|
||||||
import { Instance } from "../project/instance"
|
import { Instance } from "../project/instance"
|
||||||
import { Agent } from "../agent/agent"
|
import { Agent } from "../agent/agent"
|
||||||
|
|
||||||
@@ -19,9 +19,9 @@ export const WriteTool = Tool.define("write", {
|
|||||||
}),
|
}),
|
||||||
async execute(params, ctx) {
|
async execute(params, ctx) {
|
||||||
const filepath = path.isAbsolute(params.filePath) ? params.filePath : path.join(Instance.directory, params.filePath)
|
const filepath = path.isAbsolute(params.filePath) ? params.filePath : path.join(Instance.directory, params.filePath)
|
||||||
if (!Filesystem.contains(Instance.directory, filepath)) {
|
// if (!Filesystem.contains(Instance.directory, filepath)) {
|
||||||
throw new Error(`File ${filepath} is not in the current working directory`)
|
// throw new Error(`File ${filepath} is not in the current working directory`)
|
||||||
}
|
// }
|
||||||
|
|
||||||
const file = Bun.file(filepath)
|
const file = Bun.file(filepath)
|
||||||
const exists = await file.exists()
|
const exists = await file.exists()
|
||||||
|
|||||||
Reference in New Issue
Block a user