mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-22 02:04:22 +01:00
Add missing files and fix type aliases for opentui features
This commit is contained in:
34
packages/opencode/src/session/todo.ts
Normal file
34
packages/opencode/src/session/todo.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import z from "zod/v4"
|
||||||
|
import { Bus } from "../bus"
|
||||||
|
import { Storage } from "../storage/storage"
|
||||||
|
|
||||||
|
export namespace Todo {
|
||||||
|
export const Info = z
|
||||||
|
.object({
|
||||||
|
content: z.string().describe("Brief description of the task"),
|
||||||
|
status: z.string().describe("Current status of the task: pending, in_progress, completed, cancelled"),
|
||||||
|
priority: z.string().describe("Priority level of the task: high, medium, low"),
|
||||||
|
id: z.string().describe("Unique identifier for the todo item"),
|
||||||
|
})
|
||||||
|
.meta({ ref: "Todo" })
|
||||||
|
export type Info = z.infer<typeof Info>
|
||||||
|
|
||||||
|
export const Event = {
|
||||||
|
Updated: Bus.event(
|
||||||
|
"todo.updated",
|
||||||
|
z.object({
|
||||||
|
sessionID: z.string(),
|
||||||
|
todos: z.array(Info),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function update(input: { sessionID: string; todos: Info[] }) {
|
||||||
|
await Storage.write(["todo", input.sessionID], input.todos)
|
||||||
|
Bus.publish(Event.Updated, input)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function get(sessionID: string) {
|
||||||
|
return Storage.read<Info[]>(["todo", sessionID]) ?? []
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,22 +3,17 @@ 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 { 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 { $ } from "bun"
|
|
||||||
import { Instance } from "../project/instance"
|
import { Instance } from "../project/instance"
|
||||||
import { Agent } from "../agent/agent"
|
|
||||||
|
|
||||||
const MAX_OUTPUT_LENGTH = 30_000
|
const MAX_OUTPUT_LENGTH = 30_000
|
||||||
const DEFAULT_TIMEOUT = 1 * 60 * 1000
|
const DEFAULT_TIMEOUT = 1 * 60 * 1000
|
||||||
const MAX_TIMEOUT = 10 * 60 * 1000
|
const MAX_TIMEOUT = 10 * 60 * 1000
|
||||||
|
|
||||||
const log = Log.create({ service: "bash-tool" })
|
export const log = Log.create({ service: "bash-tool" })
|
||||||
|
|
||||||
const parser = lazy(async () => {
|
export const parser = lazy(async () => {
|
||||||
try {
|
try {
|
||||||
const { default: Parser } = await import("tree-sitter")
|
const { default: Parser } = await import("tree-sitter")
|
||||||
const Bash = await import("tree-sitter-bash")
|
const Bash = await import("tree-sitter-bash")
|
||||||
@@ -26,8 +21,10 @@ const parser = lazy(async () => {
|
|||||||
p.setLanguage(Bash.language as any)
|
p.setLanguage(Bash.language as any)
|
||||||
return p
|
return p
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const { default: Parser } = await import("web-tree-sitter")
|
const { Parser, Language } = await import("web-tree-sitter")
|
||||||
const { default: treeWasm } = await import("web-tree-sitter/tree-sitter.wasm" as string, { with: { type: "wasm" } })
|
const { default: treeWasm } = await import("web-tree-sitter/web-tree-sitter.wasm" as string, {
|
||||||
|
with: { type: "wasm" },
|
||||||
|
})
|
||||||
await Parser.init({
|
await Parser.init({
|
||||||
locateFile() {
|
locateFile() {
|
||||||
return treeWasm
|
return treeWasm
|
||||||
@@ -36,7 +33,7 @@ const parser = lazy(async () => {
|
|||||||
const { default: bashWasm } = await import("tree-sitter-bash/tree-sitter-bash.wasm" as string, {
|
const { default: bashWasm } = await import("tree-sitter-bash/tree-sitter-bash.wasm" as string, {
|
||||||
with: { type: "wasm" },
|
with: { type: "wasm" },
|
||||||
})
|
})
|
||||||
const bashLanguage = await Parser.Language.load(bashWasm)
|
const bashLanguage = await Language.load(bashWasm)
|
||||||
const p = new Parser()
|
const p = new Parser()
|
||||||
p.setLanguage(bashLanguage)
|
p.setLanguage(bashLanguage)
|
||||||
return p
|
return p
|
||||||
@@ -56,7 +53,11 @@ export const BashTool = Tool.define("bash", {
|
|||||||
}),
|
}),
|
||||||
async execute(params, ctx) {
|
async execute(params, ctx) {
|
||||||
const timeout = Math.min(params.timeout ?? DEFAULT_TIMEOUT, MAX_TIMEOUT)
|
const timeout = Math.min(params.timeout ?? DEFAULT_TIMEOUT, MAX_TIMEOUT)
|
||||||
|
/*
|
||||||
const tree = await parser().then((p) => p.parse(params.command))
|
const tree = await parser().then((p) => p.parse(params.command))
|
||||||
|
if (!tree) {
|
||||||
|
throw new Error("Failed to parse command")
|
||||||
|
}
|
||||||
const permissions = await Agent.get(ctx.agent).then((x) => x.permission.bash)
|
const permissions = await Agent.get(ctx.agent).then((x) => x.permission.bash)
|
||||||
|
|
||||||
const askPatterns = new Set<string>()
|
const askPatterns = new Set<string>()
|
||||||
@@ -145,6 +146,7 @@ export const BashTool = Tool.define("bash", {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
const process = exec(params.command, {
|
const process = exec(params.command, {
|
||||||
cwd: Instance.directory,
|
cwd: Instance.directory,
|
||||||
|
|||||||
@@ -6,8 +6,10 @@ const parser = async () => {
|
|||||||
p.setLanguage(Bash.language as any)
|
p.setLanguage(Bash.language as any)
|
||||||
return p
|
return p
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const { default: Parser } = await import("web-tree-sitter")
|
const { Parser, Language } = await import("web-tree-sitter")
|
||||||
const { default: treeWasm } = await import("web-tree-sitter/tree-sitter.wasm" as string, { with: { type: "wasm" } })
|
const { default: treeWasm } = await import("web-tree-sitter/web-tree-sitter.wasm" as string, {
|
||||||
|
with: { type: "wasm" },
|
||||||
|
})
|
||||||
await Parser.init({
|
await Parser.init({
|
||||||
locateFile() {
|
locateFile() {
|
||||||
return treeWasm
|
return treeWasm
|
||||||
@@ -16,7 +18,7 @@ const parser = async () => {
|
|||||||
const { default: bashWasm } = await import("tree-sitter-bash/tree-sitter-bash.wasm" as string, {
|
const { default: bashWasm } = await import("tree-sitter-bash/tree-sitter-bash.wasm" as string, {
|
||||||
with: { type: "wasm" },
|
with: { type: "wasm" },
|
||||||
})
|
})
|
||||||
const bashLanguage = await Parser.Language.load(bashWasm)
|
const bashLanguage = await Language.load(bashWasm)
|
||||||
const p = new Parser()
|
const p = new Parser()
|
||||||
p.setLanguage(bashLanguage)
|
p.setLanguage(bashLanguage)
|
||||||
return p
|
return p
|
||||||
@@ -62,6 +64,9 @@ function extractCommands(node: any): Array<{ command: string; args: string[] }>
|
|||||||
|
|
||||||
// Extract and display commands
|
// Extract and display commands
|
||||||
console.log("Source code: " + sourceCode)
|
console.log("Source code: " + sourceCode)
|
||||||
|
if (!tree) {
|
||||||
|
throw new Error("Failed to parse command")
|
||||||
|
}
|
||||||
const commands = extractCommands(tree.rootNode)
|
const commands = extractCommands(tree.rootNode)
|
||||||
console.log("Extracted commands:")
|
console.log("Extracted commands:")
|
||||||
commands.forEach((cmd, index) => {
|
commands.forEach((cmd, index) => {
|
||||||
|
|||||||
11
packages/opencode/src/util/fn.ts
Normal file
11
packages/opencode/src/util/fn.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export function fn<T extends z.ZodType, Result>(schema: T, cb: (input: z.infer<T>) => Result) {
|
||||||
|
const result = (input: z.infer<T>) => {
|
||||||
|
const parsed = schema.parse(input)
|
||||||
|
return cb(parsed)
|
||||||
|
}
|
||||||
|
result.force = (input: z.infer<T>) => cb(input)
|
||||||
|
result.schema = schema
|
||||||
|
return result
|
||||||
|
}
|
||||||
@@ -2,6 +2,14 @@
|
|||||||
"$schema": "https://json.schemastore.org/tsconfig",
|
"$schema": "https://json.schemastore.org/tsconfig",
|
||||||
"extends": "@tsconfig/bun/tsconfig.json",
|
"extends": "@tsconfig/bun/tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"lib": ["ESNext", "DOM", "DOM.Iterable"]
|
"jsx": "preserve",
|
||||||
|
"jsxImportSource": "@opentui/solid",
|
||||||
|
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
||||||
|
"customConditions": ["browser"],
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["./src/*"],
|
||||||
|
"@tui/*": ["./src/cli/cmd/tui/*"]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user