Compare commits

...

2 Commits

Author SHA1 Message Date
Aiden Cline 5fc91fdadc ignore: git slop 2026-02-02 21:32:35 -06:00
Aiden Cline 5eb4080947 tweak: adjust skill tool output to make it more clear which base directory the skill lives in 2026-02-02 00:08:28 -06:00
6 changed files with 45 additions and 48 deletions
+2 -6
View File
@@ -11,7 +11,7 @@ import { createWrapper } from "@parcel/watcher/wrapper"
import { lazy } from "@/util/lazy" import { lazy } from "@/util/lazy"
import { withTimeout } from "@/util/timeout" import { withTimeout } from "@/util/timeout"
import type ParcelWatcher from "@parcel/watcher" import type ParcelWatcher from "@parcel/watcher"
import { $ } from "bun" import { gitText } from "../util/git"
import { Flag } from "@/flag/flag" import { Flag } from "@/flag/flag"
import { readdir } from "fs/promises" import { readdir } from "fs/promises"
@@ -88,11 +88,7 @@ export namespace FileWatcher {
if (sub) subs.push(sub) if (sub) subs.push(sub)
} }
const vcsDir = await $`git rev-parse --git-dir` const vcsDir = await gitText(["rev-parse", "--git-dir"], Instance.worktree)
.quiet()
.nothrow()
.cwd(Instance.worktree)
.text()
.then((x) => path.resolve(Instance.worktree, x.trim())) .then((x) => path.resolve(Instance.worktree, x.trim()))
.catch(() => undefined) .catch(() => undefined)
if (vcsDir && !cfgIgnores.includes(".git") && !cfgIgnores.includes(vcsDir)) { if (vcsDir && !cfgIgnores.includes(".git") && !cfgIgnores.includes(vcsDir)) {
+9 -21
View File
@@ -2,7 +2,7 @@ import z from "zod"
import fs from "fs/promises" import fs from "fs/promises"
import { Filesystem } from "../util/filesystem" import { Filesystem } from "../util/filesystem"
import path from "path" import path from "path"
import { $ } from "bun" import { gitText } from "../util/git"
import { Storage } from "../storage/storage" import { Storage } from "../storage/storage"
import { Log } from "../util/log" import { Log } from "../util/log"
import { Flag } from "@/flag/flag" import { Flag } from "@/flag/flag"
@@ -55,15 +55,15 @@ export namespace Project {
const { id, sandbox, worktree, vcs } = await iife(async () => { const { id, sandbox, worktree, vcs } = await iife(async () => {
const matches = Filesystem.up({ targets: [".git"], start: directory }) const matches = Filesystem.up({ targets: [".git"], start: directory })
const git = await matches.next().then((x) => x.value) const gitdir = await matches.next().then((x) => x.value)
await matches.return() await matches.return()
if (git) { if (gitdir) {
let sandbox = path.dirname(git) let sandbox = path.dirname(gitdir)
const gitBinary = Bun.which("git") const gitBinary = Bun.which("git")
// cached id calculation // cached id calculation
let id = await Bun.file(path.join(git, "opencode")) let id = await Bun.file(path.join(gitdir, "opencode"))
.text() .text()
.then((x) => x.trim()) .then((x) => x.trim())
.catch(() => undefined) .catch(() => undefined)
@@ -79,11 +79,7 @@ export namespace Project {
// generate id from root commit // generate id from root commit
if (!id) { if (!id) {
const roots = await $`git rev-list --max-parents=0 --all` const roots = await gitText(["rev-list", "--max-parents=0", "--all"], sandbox)
.quiet()
.nothrow()
.cwd(sandbox)
.text()
.then((x) => .then((x) =>
x x
.split("\n") .split("\n")
@@ -104,7 +100,7 @@ export namespace Project {
id = roots[0] id = roots[0]
if (id) { if (id) {
void Bun.file(path.join(git, "opencode")) void Bun.file(path.join(gitdir, "opencode"))
.write(id) .write(id)
.catch(() => undefined) .catch(() => undefined)
} }
@@ -119,11 +115,7 @@ export namespace Project {
} }
} }
const top = await $`git rev-parse --show-toplevel` const top = await gitText(["rev-parse", "--show-toplevel"], sandbox)
.quiet()
.nothrow()
.cwd(sandbox)
.text()
.then((x) => path.resolve(sandbox, x.trim())) .then((x) => path.resolve(sandbox, x.trim()))
.catch(() => undefined) .catch(() => undefined)
@@ -138,11 +130,7 @@ export namespace Project {
sandbox = top sandbox = top
const worktree = await $`git rev-parse --git-common-dir` const worktree = await gitText(["rev-parse", "--git-common-dir"], sandbox)
.quiet()
.nothrow()
.cwd(sandbox)
.text()
.then((x) => { .then((x) => {
const dirname = path.dirname(x.trim()) const dirname = path.dirname(x.trim())
if (dirname === ".") return sandbox if (dirname === ".") return sandbox
+2 -7
View File
@@ -1,7 +1,6 @@
import { BusEvent } from "@/bus/bus-event" import { BusEvent } from "@/bus/bus-event"
import { Bus } from "@/bus" import { Bus } from "@/bus"
import { $ } from "bun" import { gitText } from "../util/git"
import path from "path"
import z from "zod" import z from "zod"
import { Log } from "@/util/log" import { Log } from "@/util/log"
import { Instance } from "./instance" import { Instance } from "./instance"
@@ -29,11 +28,7 @@ export namespace Vcs {
export type Info = z.infer<typeof Info> export type Info = z.infer<typeof Info>
async function currentBranch() { async function currentBranch() {
return $`git rev-parse --abbrev-ref HEAD` return gitText(["rev-parse", "--abbrev-ref", "HEAD"], Instance.worktree)
.quiet()
.nothrow()
.cwd(Instance.worktree)
.text()
.then((x) => x.trim()) .then((x) => x.trim())
.catch(() => undefined) .catch(() => undefined)
} }
+10 -10
View File
@@ -5,7 +5,7 @@ import { Global } from "../global"
import { Filesystem } from "../util/filesystem" import { Filesystem } from "../util/filesystem"
import { lazy } from "../util/lazy" import { lazy } from "../util/lazy"
import { Lock } from "../util/lock" import { Lock } from "../util/lock"
import { $ } from "bun" import { gitText } from "../util/git"
import { NamedError } from "@opencode-ai/util/error" import { NamedError } from "@opencode-ai/util/error"
import z from "zod" import z from "zod"
@@ -45,18 +45,18 @@ export namespace Storage {
} }
if (!worktree) continue if (!worktree) continue
if (!(await Filesystem.isDir(worktree))) continue if (!(await Filesystem.isDir(worktree))) continue
const [id] = await $`git rev-list --max-parents=0 --all` const roots = await gitText(["rev-list", "--max-parents=0", "--all"], worktree)
.quiet()
.nothrow()
.cwd(worktree)
.text()
.then((x) => .then((x) =>
x x
.split("\n") ? x
.filter(Boolean) .split("\n")
.map((x) => x.trim()) .filter(Boolean)
.toSorted(), .map((x) => x.trim())
.toSorted()
: undefined,
) )
.catch(() => undefined)
const id = roots?.[0]
if (!id) continue if (!id) continue
projectID = id projectID = id
+6 -4
View File
@@ -64,12 +64,14 @@ export const SkillTool = Tool.define("skill", async (ctx) => {
const content = skill.content const content = skill.content
const dir = path.dirname(skill.location) const dir = path.dirname(skill.location)
// Format output similar to plugin pattern
const output = [`## Skill: ${skill.name}`, "", `**Base directory**: ${dir}`, "", content.trim()].join("\n")
return { return {
title: `Loaded skill: ${skill.name}`, title: `Loaded skill: ${skill.name}`,
output, output: [
`Successfully loaded skill: ${skill.name}`,
`Base directory for this skill: ${dir}`,
"",
content.trim(),
].join("\n"),
metadata: { metadata: {
name: skill.name, name: skill.name,
dir, dir,
+16
View File
@@ -0,0 +1,16 @@
import { $ } from "bun"
function env() {
return {
...process.env,
GIT_TERMINAL_PROMPT: "0",
GIT_ASKPASS: "echo",
GIT_PAGER: "cat",
PAGER: "",
}
}
export async function gitText(args: string[], cwd: string): Promise<string> {
const input = new Response("")
return $`git ${args} < ${input}`.env(env()).cwd(cwd).quiet().nothrow().text()
}