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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "opencode",
"description": "AI-powered development tool",
"name": "overaicoding",
"description": "AI-powered development tool (custom fork)",
"private": true,
"type": "module",
"packageManager": "bun@1.3.8",
Expand Down
84 changes: 84 additions & 0 deletions packages/opencode/bin/overaicoding
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env node

const childProcess = require("child_process")
const fs = require("fs")
const path = require("path")
const os = require("os")

function run(target) {
const result = childProcess.spawnSync(target, process.argv.slice(2), {
stdio: "inherit",
})
if (result.error) {
console.error(result.error.message)
process.exit(1)
}
const code = typeof result.status === "number" ? result.status : 0
process.exit(code)
}

const envPath = process.env.OVERAICODING_BIN_PATH || process.env.OPENCODE_BIN_PATH
if (envPath) {
run(envPath)
}

const scriptPath = fs.realpathSync(__filename)
const scriptDir = path.dirname(scriptPath)

const platformMap = {
darwin: "darwin",
linux: "linux",
win32: "windows",
}
const archMap = {
x64: "x64",
arm64: "arm64",
arm: "arm",
}

let platform = platformMap[os.platform()]
if (!platform) {
platform = os.platform()
}
let arch = archMap[os.arch()]
if (!arch) {
arch = os.arch()
}
const base = "overaicoding-" + platform + "-" + arch
const binary = platform === "windows" ? "overaicoding.exe" : "overaicoding"

function findBinary(startDir) {
let current = startDir
for (;;) {
const modules = path.join(current, "node_modules")
if (fs.existsSync(modules)) {
const entries = fs.readdirSync(modules)
for (const entry of entries) {
if (!entry.startsWith(base)) {
continue
}
const candidate = path.join(modules, entry, "bin", binary)
if (fs.existsSync(candidate)) {
return candidate
}
}
}
const parent = path.dirname(current)
if (parent === current) {
return
}
current = parent
}
}

const resolved = findBinary(scriptDir)
if (!resolved) {
console.error(
'It seems that your package manager failed to install the right version of the overaicoding CLI for your platform. You can try manually installing the "' +
base +
'" package',
)
process.exit(1)
}

run(resolved)
4 changes: 2 additions & 2 deletions packages/opencode/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
"version": "1.1.53",
"name": "opencode",
"name": "overaicoding",
"type": "module",
"license": "MIT",
"private": true,
Expand All @@ -18,7 +18,7 @@
"deploy": "echo 'Deploying application...' && bun run build && echo 'Deployment completed successfully'"
},
"bin": {
"opencode": "./bin/opencode"
"overaicoding": "./bin/overaicoding"
},
"randomField": "this-is-a-random-value-12345",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode/script/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ for (const item of targets) {
autoloadTsconfig: true,
autoloadPackageJson: true,
target: name.replace(pkg.name, "bun") as any,
outfile: `dist/${name}/bin/opencode`,
outfile: `dist/${name}/bin/overaicoding`,
execArgv: [`--user-agent=opencode/${Script.version}`, "--use-system-ca", "--"],
windows: {},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { useRoute } from "@tui/context/route"
import { useSync } from "@tui/context/sync"
import { useDialog } from "@tui/ui/dialog"
import { DialogSelect } from "@tui/ui/dialog-select"
import { useTheme } from "@tui/context/theme"
import { createMemo, onMount } from "solid-js"
import { buildChildSessionPickerOptions } from "../lib/child-session-picker"
import { sessionRunState } from "../lib/session-tree"
import "opentui-spinner/solid"

export function DialogChildSessionList(props: { sessionID: string }) {
const dialog = useDialog()
const sync = useSync()
const route = useRoute()
const { theme } = useTheme()

onMount(() => {
dialog.setSize("large")
})

const spinnerFrames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]

const options = createMemo(() => {
const sessions = sync.data.session.map((s) => ({
id: s.id,
title: s.title,
parentID: s.parentID,
time: { created: s.time.created, updated: s.time.updated },
}))

const baseOptions = buildChildSessionPickerOptions({
currentSessionID: props.sessionID,
sessions,
permissionsBySession: sync.data.permission,
}).options

// Enhance options with status indicators
return baseOptions.map((opt) => {
const pending = sync.data.permission[opt.value]?.length ?? 0
const status = sync.data.session_status?.[opt.value] as { type?: string } | undefined
const state = sessionRunState(status)

const session = sync.data.session.find((s) => s.id === opt.value)
const isSubagent = session?.parentID !== undefined

const gutter = (() => {
if (pending > 0) return <text fg={theme.warning}>!</text>
if (!isSubagent) return
if (state === "working") return <spinner frames={spinnerFrames} interval={80} color={theme.warning} />
if (state === "waiting") return <text fg={theme.accent}>◎</text>
return <text fg={theme.success}>●</text>
})()

return {
...opt,
gutter,
}
})
})

return (
<DialogSelect
title="Session Tree"
options={options()}
current={props.sessionID}
onSelect={(option) => {
route.navigate({
type: "session",
sessionID: option.value,
})
dialog.clear()
}}
/>
)
}
100 changes: 100 additions & 0 deletions packages/opencode/src/cli/cmd/tui/lib/child-session-picker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import type { DialogSelectOption } from "@tui/ui/dialog-select"
import { Locale } from "@/util/locale"
import { buildSessionTree } from "./session-tree"

export type ChildSessionPickerSession = {
id: string
title: string
parentID?: string
time: {
created: number
updated: number
}
}

type PermissionBySession = Record<string, Array<unknown> | undefined>

function isDefaultSessionTitle(title: string): boolean {
const prefix =
title.startsWith("New session - ") || title.startsWith("Child session - ") || title.startsWith("Subagent - ")
if (!prefix) return false
return /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(title)
}

function shortID(id: string): string {
if (!id) return ""
if (id.length <= 8) return id
return id.slice(-8)
}

function permissionCount(permissions: PermissionBySession, sessionID: string): number {
const list = permissions[sessionID]
if (!list) return 0
return Array.isArray(list) ? list.length : 0
}

export function buildChildSessionPickerOptions(input: {
currentSessionID: string
sessions: ChildSessionPickerSession[]
permissionsBySession: PermissionBySession
}): {
rootID: string
options: DialogSelectOption<string>[]
} {
const tree = buildSessionTree({
currentSessionID: input.currentSessionID,
sessions: input.sessions,
sort: "created",
})

const options = tree.list.map((item) => {
const sessionID = item.id
const session = tree.sessionByID.get(sessionID)
const sid = shortID(sessionID)

const indent = item.depth > 0 ? `${" ".repeat(item.depth - 1)}↳ ` : ""

const title = (() => {
if (sessionID === tree.rootID) {
const name = session?.title ?? "Root session"
return `Root · ${name} · ${sid}`
}

const name = (() => {
if (!session) return "Subagent session"
if (!isDefaultSessionTitle(session.title)) return session.title
return "Subagent session"
})()

return `${indent}${name} · ${sid}`
})()

const description = (() => {
const pending = permissionCount(input.permissionsBySession, sessionID)
if (pending > 0) return "Needs input"

if (!session) return
if (sessionID === tree.rootID) return
if (!isDefaultSessionTitle(session.title)) return
return session.title
})()

const footer = (() => {
const pending = permissionCount(input.permissionsBySession, sessionID)
if (pending > 0) return `${pending} pending`
if (session) return Locale.todayTimeOrDateTime(session.time.updated)
})()

return {
title,
value: sessionID,
description,
footer,
} satisfies DialogSelectOption<string>
})

return {
rootID: tree.rootID,
options,
}
}
Loading
Loading