feat: roolbac

This commit is contained in:
Gab 2026-03-24 15:06:34 +11:00
parent 7c015708cb
commit ff2d13015d
23 changed files with 1847 additions and 203 deletions

706
bun.lock

File diff suppressed because it is too large Load Diff

230
docs/build-release.md Normal file
View File

@ -0,0 +1,230 @@
# tfcode Build & Release Guide
This document explains how to build and release tfcode to match opencode's distribution model.
## Distribution Channels
tfcode can be installed via:
1. **curl** - `curl -fsSL https://toothfairyai.com/install/tfcode | bash`
2. **npm** - `npm install -g @toothfairyai/tfcode`
3. **bun** - `bun install -g @toothfairyai/tfcode`
4. **brew** - `brew install toothfairyai/tap/tfcode`
## How It Works
### Architecture
```
┌──────────────────────────────────────────────────────────────┐
│ Gitea Releases │
│ (gitea.toothfairyai.com/ToothFairyAI/tfcode/releases) │
│ │
│ - tfcode-darwin-arm64.zip │
│ - tfcode-darwin-x64.zip │
│ - tfcode-linux-arm64.tar.gz │
│ - tfcode-linux-x64.tar.gz │
│ - tfcode-windows-x64.zip │
│ - ... │
└──────────────────────────────────────────────────────────────┘
┌─────────────────┼─────────────────┐
│ │ │
┌────┴────┐ ┌─────┴─────┐ ┌────┴────┐
│ npm │ │ curl │ │ brew │
│ │ │ │ │ │
│Downloads│ │ Downloads │ │Downloads│
│ binary │ │ binary │ │ binary │
└─────────┘ └───────────┘ └─────────┘
```
### npm Package Structure
```
@toothfairyai/tfcode (main package)
├── bin/tfcode (wrapper script)
├── postinstall.mjs (downloads correct binary)
└── optionalDependencies:
├── @toothfairyai/tfcode-darwin-arm64
├── @toothfairyai/tfcode-darwin-x64
├── @toothfairyai/tfcode-linux-arm64
├── @toothfairyai/tfcode-linux-x64
├── @toothfairyai/tfcode-windows-arm64
└── @toothfairyai/tfcode-windows-x64
```
## Build Process
### Prerequisites
1. **bun** installed
2. **Gitea token** with release permissions
3. **npm token** for publishing
### Step 1: Build Binaries
```bash
# Build all platform binaries
cd packages/tfcode
bun run build
# Or build just for current platform (faster for testing)
bun run build:single
```
This creates:
- `dist/tfcode-darwin-arm64/bin/tfcode`
- `dist/tfcode-darwin-x64/bin/tfcode`
- `dist/tfcode-linux-arm64/bin/tfcode`
- etc.
### Step 2: Package for Release
```bash
# Set environment
export GITEA_TOKEN="your-token"
export GITEA_HOST="gitea.toothfairyai.com"
export GITEA_REPO="ToothFairyAI/tfcode"
# Upload to Gitea release
bun run publish:upload
# Publish to npm
bun run publish:npm
# Create Homebrew formula
bun run publish:brew
# Or do all at once
bun run publish:all
```
## Release Checklist
### Before Release
1. Update version in `packages/tfcode/package.json`
2. Update `CHANGELOG.md` with changes
3. Test build locally: `bun run build:single`
4. Test the binary: `./dist/tfcode-darwin-arm64/bin/tfcode --version`
### During Release
```bash
# 1. Build all binaries
bun run build
# 2. Upload to Gitea
bun run publish:upload
# 3. Publish to npm
npm login --scope=@toothfairyai
bun run publish:npm
# 4. Update Homebrew tap
# (Manual: copy dist/tfcode.rb to homebrew-tap repo)
```
### After Release
1. Verify curl install works:
```bash
curl -fsSL https://toothfairyai.com/install/tfcode | bash
tfcode --version
```
2. Verify npm install works:
```bash
npm install -g @toothfairyai/tfcode
tfcode --version
```
3. Verify brew install works:
```bash
brew install toothfairyai/tap/tfcode
tfcode --version
```
## Environment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| `GITEA_HOST` | Gitea server | `gitea.toothfairyai.com` |
| `GITEA_REPO` | Gitea repository | `ToothFairyAI/tfcode` |
| `GITEA_TOKEN` | Gitea API token | (required for upload) |
| `TFCODE_VERSION` | Override version | (from package.json) |
## Platform Support
| Platform | Arch | Variants |
|----------|------|----------|
| macOS | arm64 | - |
| macOS | x64 | baseline |
| Linux | arm64 | musl |
| Linux | x64 | baseline, musl |
| Windows | arm64 | - |
| Windows | x64 | baseline |
### Binary Variants
- **baseline**: For older CPUs without AVX2 support
- **musl**: For Alpine Linux and other musl-based distros
## Troubleshooting
### Build Fails
```bash
# Try installing dependencies first
bun install
# Then rebuild
bun run build:single
```
### Upload Fails
```bash
# Check token permissions
curl -H "Authorization: token $GITEA_TOKEN" \
https://$GITEA_HOST/api/v1/user/repos
```
### npm Publish Fails
```bash
# Login to npm
npm login --scope=@toothfairyai
# Check you're logged in
npm whoami
```
## Files Reference
| File | Purpose |
|------|---------|
| `script/build-tfcode.ts` | Build all platform binaries |
| `script/publish-tfcode.ts` | Upload to Gitea, publish npm, create brew formula |
| `script/postinstall-tfcode.mjs` | npm postinstall - downloads binary |
| `scripts/install-tfcode.sh` | curl install script |
| `bin/tfcode` | Wrapper script (source repo) |
| `bin/tfcode.js` | Minimal CLI (npm package) |
## Comparison with OpenCode
| Aspect | OpenCode | tfcode |
|--------|----------|--------|
| Release hosting | GitHub Releases | Gitea Releases |
| npm package | `opencode-ai/opencode` | `@toothfairyai/tfcode` |
| Binary packages | `opencode-*` | `tfcode-*` |
| Install script | `opencode.ai/install` | `toothfairyai.com/install/tfcode` |
| Brew tap | `anomalyco/homebrew-tap` | `toothfairyai/homebrew-tap` |
## Next Steps
1. **Set up CI/CD** - Automate builds on tag push
2. **Create Homebrew tap repo** - `github.com/toothfairyai/homebrew-tap`
3. **Set up install website** - `toothfairyai.com/install/tfcode`
4. **Add auto-update** - Check for updates on launch

View File

@ -1,30 +1,155 @@
{
"name": "@toothfairyai/tfcode",
"version": "1.0.0-beta.9",
"description": "ToothFairyAI's official AI coding agent",
"keywords": ["toothfairyai", "ai", "coding", "cli"],
"author": "ToothFairyAI",
"license": "MIT",
"$schema": "https://json.schemastore.org/package.json",
"version": "1.0.0",
"name": "tfcode",
"type": "module",
"bin": {
"tfcode": "./bin/tfcode.js"
},
"files": [
"bin/",
"scripts/"
],
"license": "MIT",
"private": true,
"scripts": {
"postinstall": "node scripts/postinstall.cjs"
"prepare": "effect-language-service patch || true",
"postinstall": "node scripts/postinstall.cjs",
"typecheck": "tsgo --noEmit",
"test": "bun test --timeout 30000",
"build": "bun run script/build-tfcode.ts",
"build:single": "bun run script/build-tfcode.ts --single",
"publish:upload": "bun run script/publish-tfcode.ts --upload",
"publish:npm": "bun run script/publish-tfcode.ts --npm",
"publish:brew": "bun run script/publish-tfcode.ts --brew",
"publish:all": "bun run script/publish-tfcode.ts --all",
"dev": "bun run --conditions=browser ./src/index.ts",
"db": "bun drizzle-kit"
},
"bin": {
"tfcode": "./bin/tfcode"
},
"exports": {
"./*": "./src/*.ts"
},
"imports": {
"#db": {
"bun": "./src/storage/db.bun.ts",
"node": "./src/storage/db.node.ts",
"default": "./src/storage/db.bun.ts"
}
},
"devDependencies": {
"@babel/core": "7.28.4",
"@effect/language-service": "0.79.0",
"@octokit/webhooks-types": "7.6.1",
"@opencode-ai/script": "workspace:*",
"@parcel/watcher-darwin-arm64": "2.5.1",
"@parcel/watcher-darwin-x64": "2.5.1",
"@parcel/watcher-linux-arm64-glibc": "2.5.1",
"@parcel/watcher-linux-arm64-musl": "2.5.1",
"@parcel/watcher-linux-x64-glibc": "2.5.1",
"@parcel/watcher-linux-x64-musl": "2.5.1",
"@parcel/watcher-win32-arm64": "2.5.1",
"@parcel/watcher-win32-x64": "2.5.1",
"@standard-schema/spec": "1.0.0",
"@tsconfig/bun": "catalog:",
"@types/babel__core": "7.20.5",
"@types/bun": "catalog:",
"@types/cross-spawn": "6.0.6",
"@types/mime-types": "3.0.1",
"@types/semver": "^7.5.8",
"@types/turndown": "5.0.5",
"@types/which": "3.0.4",
"@types/yargs": "17.0.33",
"@typescript/native-preview": "catalog:",
"drizzle-kit": "catalog:",
"drizzle-orm": "catalog:",
"typescript": "catalog:",
"vscode-languageserver-types": "3.17.5",
"why-is-node-running": "3.2.2",
"zod-to-json-schema": "3.24.5"
},
"dependencies": {
"yargs": "^17.7.2"
"@actions/core": "1.11.1",
"@actions/github": "6.0.1",
"@agentclientprotocol/sdk": "0.14.1",
"@ai-sdk/amazon-bedrock": "3.0.82",
"@ai-sdk/anthropic": "2.0.65",
"@ai-sdk/azure": "2.0.91",
"@ai-sdk/cerebras": "1.0.36",
"@ai-sdk/cohere": "2.0.22",
"@ai-sdk/deepinfra": "1.0.36",
"@ai-sdk/gateway": "2.0.30",
"@ai-sdk/google": "2.0.54",
"@ai-sdk/google-vertex": "3.0.106",
"@ai-sdk/groq": "2.0.34",
"@ai-sdk/mistral": "2.0.27",
"@ai-sdk/openai": "2.0.89",
"@ai-sdk/openai-compatible": "1.0.32",
"@ai-sdk/perplexity": "2.0.23",
"@ai-sdk/provider": "2.0.1",
"@ai-sdk/provider-utils": "3.0.21",
"@ai-sdk/togetherai": "1.0.34",
"@ai-sdk/vercel": "1.0.33",
"@ai-sdk/xai": "2.0.51",
"@aws-sdk/credential-providers": "3.993.0",
"@clack/prompts": "1.0.0-alpha.1",
"@effect/platform-node": "catalog:",
"@hono/standard-validator": "0.1.5",
"@hono/zod-validator": "catalog:",
"@modelcontextprotocol/sdk": "1.25.2",
"@octokit/graphql": "9.0.2",
"@octokit/rest": "catalog:",
"@openauthjs/openauth": "catalog:",
"@opencode-ai/plugin": "workspace:*",
"@opencode-ai/script": "workspace:*",
"@opencode-ai/sdk": "workspace:*",
"@opencode-ai/util": "workspace:*",
"@openrouter/ai-sdk-provider": "1.5.4",
"@opentui/core": "0.1.90",
"@opentui/solid": "0.1.90",
"@parcel/watcher": "2.5.1",
"@pierre/diffs": "catalog:",
"@solid-primitives/event-bus": "1.1.2",
"@solid-primitives/scheduled": "1.5.2",
"@standard-schema/spec": "1.0.0",
"@zip.js/zip.js": "2.7.62",
"ai": "catalog:",
"ai-gateway-provider": "2.3.1",
"bonjour-service": "1.3.0",
"bun-pty": "0.4.8",
"chokidar": "4.0.3",
"clipboardy": "4.0.0",
"cross-spawn": "^7.0.6",
"decimal.js": "10.5.0",
"diff": "catalog:",
"drizzle-orm": "catalog:",
"effect": "catalog:",
"fuzzysort": "3.1.0",
"gitlab-ai-provider": "5.2.2",
"glob": "13.0.5",
"google-auth-library": "10.5.0",
"gray-matter": "4.0.3",
"hono": "catalog:",
"hono-openapi": "catalog:",
"ignore": "7.0.5",
"jsonc-parser": "3.3.1",
"mime-types": "3.0.2",
"minimatch": "10.0.3",
"open": "10.1.2",
"opencode-gitlab-auth": "2.0.0",
"opentui-spinner": "0.0.6",
"partial-json": "0.1.7",
"remeda": "catalog:",
"semver": "^7.6.3",
"solid-js": "catalog:",
"strip-ansi": "7.1.2",
"tree-sitter-bash": "0.25.0",
"turndown": "7.2.0",
"ulid": "catalog:",
"vscode-jsonrpc": "8.2.1",
"web-tree-sitter": "0.25.10",
"which": "6.0.1",
"xdg-basedir": "5.1.0",
"yargs": "18.0.0",
"zod": "catalog:",
"zod-to-json-schema": "3.24.5"
},
"engines": {
"node": ">=18"
},
"homepage": "https://toothfairyai.com/developers/tfcode",
"repository": {
"type": "git",
"url": "https://github.com/ToothFairyAI/tfcode.git"
"overrides": {
"drizzle-orm": "catalog:"
}
}

View File

@ -0,0 +1,194 @@
#!/usr/bin/env bun
import { $ } from "bun"
import fs from "fs"
import path from "path"
import { fileURLToPath } from "url"
import solidPlugin from "@opentui/solid/bun-plugin"
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const dir = path.resolve(__dirname, "..")
process.chdir(dir)
import { Script } from "@opencode-ai/script"
import pkg from "../package.json"
// tfcode version
const TFCODE_VERSION = pkg.version
const TFCODE_NAME = "tfcode"
// Fetch models snapshot
const modelsUrl = process.env.TFCODE_MODELS_URL || "https://models.dev"
const modelsData = process.env.MODELS_DEV_API_JSON
? await Bun.file(process.env.MODELS_DEV_API_JSON).text()
: await fetch(`${modelsUrl}/api.json`).then((x) => x.text())
await Bun.write(
path.join(dir, "src/provider/models-snapshot.ts"),
`// Auto-generated by build.ts - do not edit\nexport const snapshot = ${modelsData} as const\n`,
)
console.log("Generated models-snapshot.ts")
// Load migrations
const migrationDirs = (
await fs.promises.readdir(path.join(dir, "migration"), {
withFileTypes: true,
})
)
.filter((entry) => entry.isDirectory() && /^\d{4}\d{2}\d{2}\d{2}\d{2}\d{2}/.test(entry.name))
.map((entry) => entry.name)
.sort()
const migrations = await Promise.all(
migrationDirs.map(async (name) => {
const file = path.join(dir, "migration", name, "migration.sql")
const sql = await Bun.file(file).text()
const match = /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/.exec(name)
const timestamp = match
? Date.UTC(
Number(match[1]),
Number(match[2]) - 1,
Number(match[3]),
Number(match[4]),
Number(match[5]),
Number(match[6]),
)
: 0
return { sql, timestamp, name }
}),
)
console.log(`Loaded ${migrations.length} migrations`)
const singleFlag = process.argv.includes("--single")
const baselineFlag = process.argv.includes("--baseline")
const skipInstall = process.argv.includes("--skip-install")
const allTargets: {
os: string
arch: "arm64" | "x64"
abi?: "musl"
avx2?: false
}[] = [
{ os: "linux", arch: "arm64" },
{ os: "linux", arch: "x64" },
{ os: "linux", arch: "x64", avx2: false },
{ os: "linux", arch: "arm64", abi: "musl" },
{ os: "linux", arch: "x64", abi: "musl" },
{ os: "linux", arch: "x64", abi: "musl", avx2: false },
{ os: "darwin", arch: "arm64" },
{ os: "darwin", arch: "x64" },
{ os: "darwin", arch: "x64", avx2: false },
{ os: "win32", arch: "arm64" },
{ os: "win32", arch: "x64" },
{ os: "win32", arch: "x64", avx2: false },
]
const targets = singleFlag
? allTargets.filter((item) => {
if (item.os !== process.platform || item.arch !== process.arch) return false
if (item.avx2 === false) return baselineFlag
if (item.abi !== undefined) return false
return true
})
: allTargets
await $`rm -rf dist`
const binaries: Record<string, string> = {}
if (!skipInstall) {
await $`bun install --os="*" --cpu="*" @opentui/core@${pkg.dependencies["@opentui/core"]}`
await $`bun install --os="*" --cpu="*" @parcel/watcher@${pkg.dependencies["@parcel/watcher"]}`
}
for (const item of targets) {
const name = [
TFCODE_NAME,
item.os === "win32" ? "windows" : item.os,
item.arch,
item.avx2 === false ? "baseline" : undefined,
item.abi === undefined ? undefined : item.abi,
]
.filter(Boolean)
.join("-")
console.log(`Building ${name}`)
await $`mkdir -p dist/${name}/bin`
const localPath = path.resolve(dir, "node_modules/@opentui/core/parser.worker.js")
const rootPath = path.resolve(dir, "../../node_modules/@opentui/core/parser.worker.js")
const parserWorker = fs.realpathSync(fs.existsSync(localPath) ? localPath : rootPath)
const workerPath = "./src/cli/cmd/tui/worker.ts"
const bunfsRoot = item.os === "win32" ? "B:/~BUN/root/" : "/$bunfs/root/"
const workerRelativePath = path.relative(dir, parserWorker).replaceAll("\\", "/")
await Bun.build({
conditions: ["browser"],
tsconfig: "./tsconfig.json",
plugins: [solidPlugin],
compile: {
autoloadBunfig: false,
autoloadDotenv: false,
autoloadTsconfig: true,
autoloadPackageJson: true,
target: name.replace(TFCODE_NAME, "bun") as any,
outfile: `dist/${name}/bin/tfcode`,
execArgv: [`--user-agent=tfcode/${TFCODE_VERSION}`, "--use-system-ca", "--"],
windows: {},
},
entrypoints: ["./src/index.ts", parserWorker, workerPath],
define: {
OPENCODE_VERSION: `'${TFCODE_VERSION}'`,
OPENCODE_MIGRATIONS: JSON.stringify(migrations),
OTUI_TREE_SITTER_WORKER_PATH: bunfsRoot + workerRelativePath,
OPENCODE_WORKER_PATH: workerPath,
OPENCODE_CHANNEL: `'${Script.channel}'`,
OPENCODE_LIBC: item.os === "linux" ? `'${item.abi ?? "glibc"}'` : "",
},
})
// Smoke test
if (item.os === process.platform && item.arch === process.arch && !item.abi) {
const binaryPath = `dist/${name}/bin/tfcode`
console.log(`Running smoke test: ${binaryPath} --version`)
try {
const versionOutput = await $`${binaryPath} --version`.text()
console.log(`Smoke test passed: ${versionOutput.trim()}`)
} catch (e) {
console.error(`Smoke test failed for ${name}:`, e)
process.exit(1)
}
}
await $`rm -rf ./dist/${name}/bin/tui`
await Bun.file(`dist/${name}/package.json`).write(
JSON.stringify(
{
name: `@toothfairyai/${name}`,
version: TFCODE_VERSION,
os: [item.os],
cpu: [item.arch],
},
null,
2,
),
)
binaries[name] = TFCODE_VERSION
}
// Package for release
if (Script.release || process.env.TFCODE_RELEASE) {
console.log("Packaging for release...")
for (const key of Object.keys(binaries)) {
if (key.includes("linux")) {
await $`tar -czf ../../${key}.tar.gz *`.cwd(`dist/${key}/bin`)
} else {
await $`zip -r ../../${key}.zip *`.cwd(`dist/${key}/bin`)
}
}
console.log("Binaries packaged. Upload to Gitea releases manually or use publish.ts")
}
export { binaries, TFCODE_VERSION }

View File

@ -0,0 +1,216 @@
#!/usr/bin/env node
import fs from "fs"
import path from "path"
import os from "os"
import { spawnSync } from "child_process"
const GITEA_HOST = process.env.TFCODE_GITEA_HOST || "gitea.toothfairyai.com"
const GITEA_REPO = process.env.TFCODE_GITEA_REPO || "ToothFairyAI/tfcode"
function detectPlatform() {
let platform
switch (os.platform()) {
case "darwin": platform = "darwin"; break
case "linux": platform = "linux"; break
case "win32": platform = "windows"; break
default: platform = os.platform()
}
let arch
switch (os.arch()) {
case "x64": arch = "x64"; break
case "arm64": arch = "arm64"; break
default: arch = os.arch()
}
// Check for AVX2 on x64
let needsBaseline = false
if (arch === "x64" && (platform === "linux" || platform === "darwin")) {
try {
if (platform === "linux") {
const cpuinfo = fs.readFileSync("/proc/cpuinfo", "utf8")
needsBaseline = !cpuinfo.toLowerCase().includes("avx2")
} else if (platform === "darwin") {
const result = spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], { encoding: "utf8" })
needsBaseline = result.stdout.trim() !== "1"
}
} catch {}
}
// Check for musl on Linux
let abi = ""
if (platform === "linux") {
try {
if (fs.existsSync("/etc/alpine-release")) {
abi = "musl"
} else {
const result = spawnSync("ldd", ["--version"], { encoding: "utf8" })
if ((result.stdout + result.stderr).toLowerCase().includes("musl")) {
abi = "musl"
}
}
} catch {}
}
return { platform, arch, needsBaseline, abi }
}
async function getVersion() {
try {
const res = await fetch(`https://${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/latest`)
const data = await res.json()
return data.tag_name?.replace(/^v/, "") || "1.0.0"
} catch {
return "1.0.0"
}
}
async function downloadBinary() {
const { platform, arch, needsBaseline, abi } = detectPlatform()
const version = await getVersion()
// Build filename
let target = `tfcode-${platform}-${arch}`
if (needsBaseline) target += "-baseline"
if (abi) target += `-${abi}`
const ext = platform === "linux" ? ".tar.gz" : ".zip"
const filename = `${target}${ext}`
const url = `https://${GITEA_HOST}/${GITEA_REPO}/releases/download/v${version}/${filename}`
console.log(`Downloading tfcode v${version} for ${target}...`)
// Download
const binDir = path.join(__dirname, "bin")
if (!fs.existsSync(binDir)) fs.mkdirSync(binDir, { recursive: true })
const tmpDir = path.join(os.tmpdir(), `tfcode-install-${process.pid}`)
fs.mkdirSync(tmpDir, { recursive: true })
const archivePath = path.join(tmpDir, filename)
// Use curl to download
const curlResult = spawnSync("curl", ["-fsSL", "-o", archivePath, url], { stdio: "inherit" })
if (curlResult.status !== 0) {
console.error(`Failed to download from ${url}`)
console.error("Trying npm package fallback...")
// Fallback to npm optionalDependencies
try {
const pkgName = `@toothfairyai/${target}`
const pkgPath = require.resolve(`${pkgName}/package.json`)
const pkgDir = path.dirname(pkgPath)
const binaryName = platform === "windows" ? "tfcode.exe" : "tfcode"
const binaryPath = path.join(pkgDir, "bin", binaryName)
if (fs.existsSync(binaryPath)) {
setupBinary(binaryPath, platform)
return
}
} catch {}
process.exit(1)
}
// Extract
console.log("Extracting...")
if (platform === "linux") {
spawnSync("tar", ["-xzf", archivePath, "-C", tmpDir], { stdio: "inherit" })
} else {
spawnSync("unzip", ["-q", archivePath, "-d", tmpDir], { stdio: "inherit" })
}
// Move binary
const binaryName = platform === "windows" ? "tfcode.exe" : "tfcode"
const extractedBinary = path.join(tmpDir, "tfcode")
const targetBinary = path.join(binDir, binaryName)
if (fs.existsSync(extractedBinary)) {
if (fs.existsSync(targetBinary)) fs.unlinkSync(targetBinary)
fs.copyFileSync(extractedBinary, targetBinary)
fs.chmodSync(targetBinary, 0o755)
console.log(`Installed tfcode to ${targetBinary}`)
}
// Cleanup
fs.rmSync(tmpDir, { recursive: true, force: true })
}
function setupBinary(sourcePath, platform) {
const binDir = path.join(__dirname, "bin")
const binaryName = platform === "windows" ? "tfcode.exe" : "tfcode"
const targetBinary = path.join(binDir, binaryName)
if (!fs.existsSync(binDir)) fs.mkdirSync(binDir, { recursive: true })
if (fs.existsSync(targetBinary)) fs.unlinkSync(targetBinary)
// Try hardlink, fall back to copy
try {
fs.linkSync(sourcePath, targetBinary)
} catch {
fs.copyFileSync(sourcePath, targetBinary)
}
fs.chmodSync(targetBinary, 0o755)
console.log(`tfcode installed to ${targetBinary}`)
}
async function main() {
console.log("")
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
console.log(" tfcode - ToothFairyAI's official coding agent")
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
console.log("")
// Check for Python (needed for TF integration)
try {
const result = spawnSync("python3", ["--version"], { encoding: "utf8" })
if (result.status === 0) {
console.log(`✓ Found ${result.stdout.trim()}`)
// Install Python SDK
console.log("Installing ToothFairyAI Python SDK...")
const pipResult = spawnSync("python3", ["-m", "pip", "install", "--user", "--break-system-packages", "toothfairyai", "pydantic", "httpx", "rich"], {
stdio: "inherit"
})
if (pipResult.status === 0) {
console.log("✓ Python SDK installed")
} else {
console.log("! Python SDK install failed, run manually:")
console.log(" pip install toothfairyai pydantic httpx rich")
}
}
} catch {
console.log("! Python 3.10+ not found. Install with:")
console.log(" macOS: brew install python@3.12")
console.log(" Ubuntu: sudo apt install python3.12")
console.log(" Windows: Download from python.org/downloads")
console.log("")
}
console.log("")
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
console.log("✓ tfcode installed successfully!")
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
console.log("")
console.log("Quick Start:")
console.log("")
console.log(" 1. Set credentials:")
console.log(" export TF_WORKSPACE_ID=\"your-workspace-id\"")
console.log(" export TF_API_KEY=\"your-api-key\"")
console.log("")
console.log(" 2. Validate:")
console.log(" tfcode validate")
console.log("")
console.log(" 3. Sync tools:")
console.log(" tfcode sync")
console.log("")
console.log(" 4. Start coding:")
console.log(" tfcode")
console.log("")
console.log("Documentation: https://toothfairyai.com/developers/tfcode")
console.log("")
}
main().catch(console.error)

View File

@ -0,0 +1,236 @@
#!/usr/bin/env bun
import { $ } from "bun"
import fs from "fs"
import path from "path"
import { fileURLToPath } from "url"
import pkg from "../package.json"
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const dir = path.resolve(__dirname, "..")
process.chdir(dir)
const TFCODE_VERSION = pkg.version
const GITEA_HOST = process.env.GITEA_HOST || "gitea.toothfairyai.com"
const GITEA_TOKEN = process.env.GITEA_TOKEN
const GITEA_REPO = process.env.GITEA_REPO || "ToothFairyAI/tfcode"
// Collect binaries
const binaries: Record<string, string> = {}
for (const filepath of new Bun.Glob("*/package.json").scanSync({ cwd: "./dist" })) {
const pkg = await Bun.file(`./dist/${filepath}`).json()
if (pkg.name.startsWith("@toothfairyai/tfcode-")) {
binaries[pkg.name] = pkg.version
}
}
console.log("Binaries:", binaries)
// Upload to Gitea release
async function uploadToGitea() {
if (!GITEA_TOKEN) {
console.error("GITEA_TOKEN is required")
process.exit(1)
}
// Check if release exists
const releaseUrl = `https://${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/tags/v${TFCODE_VERSION}`
let releaseId: string
try {
const res = await fetch(releaseUrl, {
headers: { Authorization: `token ${GITEA_TOKEN}` }
})
if (res.ok) {
const release = await res.json()
releaseId = release.id
console.log(`Release v${TFCODE_VERSION} exists, updating...`)
} else {
throw new Error("Not found")
}
} catch {
// Create new release
const createUrl = `https://${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases`
const res = await fetch(createUrl, {
method: "POST",
headers: {
Authorization: `token ${GITEA_TOKEN}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
tag_name: `v${TFCODE_VERSION}`,
name: `v${TFCODE_VERSION}`,
body: `tfcode v${TFCODE_VERSION}\n\nSee CHANGELOG.md for details.`,
draft: false,
prerelease: TFCODE_VERSION.includes("-")
})
})
if (!res.ok) {
console.error("Failed to create release:", await res.text())
process.exit(1)
}
const release = await res.json()
releaseId = release.id
console.log(`Created release v${TFCODE_VERSION}`)
}
// Upload assets
const assets = await fs.promises.readdir("./dist")
for (const asset of assets) {
if (asset.endsWith(".tar.gz") || asset.endsWith(".zip")) {
const assetPath = `./dist/${asset}`
const file = Bun.file(assetPath)
const uploadUrl = `https://${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/${releaseId}/assets?name=${asset}`
console.log(`Uploading ${asset}...`)
const res = await fetch(uploadUrl, {
method: "POST",
headers: {
Authorization: `token ${GITEA_TOKEN}`,
"Content-Type": "application/octet-stream"
},
body: file
})
if (!res.ok) {
console.error(`Failed to upload ${asset}:`, await res.text())
} else {
console.log(`Uploaded ${asset}`)
}
}
}
}
// Create main npm package
async function createMainPackage() {
await $`mkdir -p ./dist/tfcode`
await $`cp -r ./bin ./dist/tfcode/bin`
await Bun.file(`./dist/tfcode/postinstall.mjs`).write(await Bun.file("./script/postinstall-tfcode.mjs").text())
await Bun.file(`./dist/tfcode/LICENSE`).write(await Bun.file("../../LICENSE").text())
await Bun.file(`./dist/tfcode/package.json`).write(
JSON.stringify(
{
name: "@toothfairyai/tfcode",
version: TFCODE_VERSION,
bin: { tfcode: "./bin/tfcode" },
scripts: { postinstall: "node ./postinstall.mjs" },
license: pkg.license,
optionalDependencies: binaries,
homepage: "https://toothfairyai.com/developers/tfcode",
repository: {
type: "git",
url: `https://${GITEA_HOST}/${GITEA_REPO}.git`
}
},
null,
2
)
)
// Pack and publish
if (process.platform !== "win32") {
await $`chmod -R 755 ./dist/tfcode`
}
for (const [name, version] of Object.entries(binaries)) {
console.log(`Publishing ${name}...`)
await $`cd ./dist/${name.replace('@toothfairyai/', '')} && bun pm pack && npm publish *.tgz --access public --tag beta`
}
console.log("Publishing main package...")
await $`cd ./dist/tfcode && bun pm pack && npm publish *.tgz --access public --tag beta`
}
// Create Homebrew formula
async function createHomebrewFormula() {
const arm64Sha = await $`sha256sum ./dist/tfcode-linux-arm64.tar.gz | cut -d' ' -f1`.text().then((x) => x.trim())
const x64Sha = await $`sha256sum ./dist/tfcode-linux-x64.tar.gz | cut -d' ' -f1`.text().then((x) => x.trim())
const macX64Sha = await $`sha256sum ./dist/tfcode-darwin-x64.zip | cut -d' ' -f1`.text().then((x) => x.trim())
const macArm64Sha = await $`sha256sum ./dist/tfcode-darwin-arm64.zip | cut -d' ' -f1`.text().then((x) => x.trim())
const formula = [
"# typed: false",
"# frozen_string_literal: true",
"",
"class Tfcode < Formula",
` desc "ToothFairyAI's official AI coding agent"`,
` homepage "https://toothfairyai.com/developers/tfcode"`,
` version "${TFCODE_VERSION.split("-")[0]}"`,
"",
` depends_on "ripgrep"`,
"",
" on_macos do",
" if Hardware::CPU.intel?",
` url "https://${GITEA_HOST}/${GITEA_REPO}/releases/download/v${TFCODE_VERSION}/tfcode-darwin-x64.zip"`,
` sha256 "${macX64Sha}"`,
"",
" def install",
' bin.install "tfcode"',
" end",
" end",
" if Hardware::CPU.arm?",
` url "https://${GITEA_HOST}/${GITEA_REPO}/releases/download/v${TFCODE_VERSION}/tfcode-darwin-arm64.zip"`,
` sha256 "${macArm64Sha}"`,
"",
" def install",
' bin.install "tfcode"',
" end",
" end",
" end",
"",
" on_linux do",
" if Hardware::CPU.intel? and Hardware::CPU.is_64_bit?",
` url "https://${GITEA_HOST}/${GITEA_REPO}/releases/download/v${TFCODE_VERSION}/tfcode-linux-x64.tar.gz"`,
` sha256 "${x64Sha}"`,
" def install",
' bin.install "tfcode"',
" end",
" end",
" if Hardware::CPU.arm? and Hardware::CPU.is_64_bit?",
` url "https://${GITEA_HOST}/${GITEA_REPO}/releases/download/v${TFCODE_VERSION}/tfcode-linux-arm64.tar.gz"`,
` sha256 "${arm64Sha}"`,
" def install",
' bin.install "tfcode"',
" end",
" end",
" end",
"end",
""
].join("\n")
await Bun.file("./dist/tfcode.rb").write(formula)
console.log("Created Homebrew formula: ./dist/tfcode.rb")
console.log("To publish: Create a tap repo and push this formula")
}
// Run
if (process.argv.includes("--upload")) {
await uploadToGitea()
}
if (process.argv.includes("--npm")) {
await createMainPackage()
}
if (process.argv.includes("--brew")) {
await createHomebrewFormula()
}
if (!process.argv.includes("--upload") && !process.argv.includes("--npm") && !process.argv.includes("--brew")) {
console.log(`
Usage:
bun run publish.ts --upload Upload binaries to Gitea release
bun run publish.ts --npm Publish to npm
bun run publish.ts --brew Create Homebrew formula
bun run publish.ts --all Do all of the above
`)
}
if (process.argv.includes("--all")) {
await uploadToGitea()
await createMainPackage()
await createHomebrewFormula()
}

View File

@ -85,7 +85,7 @@ export const McpListCommand = cmd({
if (servers.length === 0) {
prompts.log.warn("No MCP servers configured")
prompts.outro("Add servers with: opencode mcp add")
prompts.outro("Add servers with: tfcode mcp add")
return
}

View File

@ -6,7 +6,7 @@ import { git } from "@/util/git"
export const PrCommand = cmd({
command: "pr <number>",
describe: "fetch and checkout a GitHub PR branch, then run opencode",
describe: "fetch and checkout a GitHub PR branch, then run tfcode",
builder: (yargs) =>
yargs.positional("number", {
type: "number",
@ -82,15 +82,15 @@ export const PrCommand = cmd({
})
}
// Check for opencode session link in PR body
// Check for tfcode session link in PR body
if (prInfo && prInfo.body) {
const sessionMatch = prInfo.body.match(/https:\/\/opncd\.ai\/s\/([a-zA-Z0-9_-]+)/)
if (sessionMatch) {
const sessionUrl = sessionMatch[0]
UI.println(`Found opencode session: ${sessionUrl}`)
UI.println(`Found tfcode session: ${sessionUrl}`)
UI.println(`Importing session...`)
const importResult = await Process.text(["opencode", "import", sessionUrl], {
const importResult = await Process.text(["tfcode", "import", sessionUrl], {
nothrow: true,
})
if (importResult.code === 0) {
@ -109,18 +109,18 @@ export const PrCommand = cmd({
UI.println(`Successfully checked out PR #${prNumber} as branch '${localBranchName}'`)
UI.println()
UI.println("Starting opencode...")
UI.println("Starting tfcode...")
UI.println()
const opencodeArgs = sessionId ? ["-s", sessionId] : []
const opencodeProcess = Process.spawn(["opencode", ...opencodeArgs], {
const tfcodeArgs = sessionId ? ["-s", sessionId] : []
const tfcodeProcess = Process.spawn(["tfcode", ...tfcodeArgs], {
stdin: "inherit",
stdout: "inherit",
stderr: "inherit",
cwd: process.cwd(),
})
const code = await opencodeProcess.exited
if (code !== 0) throw new Error(`opencode exited with code ${code}`)
const code = await tfcodeProcess.exited
if (code !== 0) throw new Error(`tfcode exited with code ${code}`)
},
})
},

View File

@ -220,7 +220,7 @@ function normalizePath(input?: string) {
export const RunCommand = cmd({
command: "run [message..]",
describe: "run opencode with a message",
describe: "run tfcode with a message",
builder: (yargs: Argv) => {
return yargs
.positional("message", {
@ -278,7 +278,7 @@ export const RunCommand = cmd({
})
.option("attach", {
type: "string",
describe: "attach to a running opencode server (e.g., http://localhost:4096)",
describe: "attach to a running tfcode server (e.g., http://localhost:4096)",
})
.option("password", {
alias: ["p"],

View File

@ -9,14 +9,14 @@ import { Installation } from "../../installation"
export const ServeCommand = cmd({
command: "serve",
builder: (yargs) => withNetworkOptions(yargs),
describe: "starts a headless opencode server",
describe: "starts a headless tfcode server",
handler: async (args) => {
if (!Flag.OPENCODE_SERVER_PASSWORD) {
console.log("Warning: OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")
}
const opts = await resolveNetworkOptions(args)
const server = Server.listen(opts)
console.log(`opencode server listening on http://${server.hostname}:${server.port}`)
console.log(`tfcode server listening on http://${server.hostname}:${server.port}`)
await new Promise(() => {})
await server.stop()

View File

@ -8,7 +8,7 @@ import { existsSync } from "fs"
export const AttachCommand = cmd({
command: "attach <url>",
describe: "attach to a running opencode server",
describe: "attach to a running tfcode server",
builder: (yargs) =>
yargs
.positional("url", {

View File

@ -64,12 +64,12 @@ async function input(value?: string) {
export const TuiThreadCommand = cmd({
command: "$0 [project]",
describe: "start opencode tui",
describe: "start tfcode tui",
builder: (yargs) =>
withNetworkOptions(yargs)
.positional("project", {
type: "string",
describe: "path to start opencode in",
describe: "path to start tfcode in",
})
.option("model", {
type: "string",

View File

@ -24,7 +24,7 @@ interface RemovalTargets {
export const UninstallCommand = {
command: "uninstall",
describe: "uninstall opencode and remove all related files",
describe: "uninstall tfcode and remove all related files",
builder: (yargs: Argv) =>
yargs
.option("keep-config", {

View File

@ -5,7 +5,7 @@ import { Installation } from "../../installation"
export const UpgradeCommand = {
command: "upgrade [target]",
describe: "upgrade opencode to the latest or a specific version",
describe: "upgrade tfcode to the latest or a specific version",
builder: (yargs: Argv) => {
return yargs
.positional("target", {
@ -27,7 +27,7 @@ export const UpgradeCommand = {
const detectedMethod = await Installation.method()
const method = (args.method as Installation.Method) ?? detectedMethod
if (method === "unknown") {
prompts.log.error(`opencode is installed to ${process.execPath} and may be managed by a package manager`)
prompts.log.error(`tfcode is installed to ${process.execPath} and may be managed by a package manager`)
const install = await prompts.select({
message: "Install anyways?",
options: [
@ -45,7 +45,7 @@ export const UpgradeCommand = {
const target = args.target ? args.target.replace(/^v/, "") : await Installation.latest()
if (Installation.VERSION === target) {
prompts.log.warn(`opencode upgrade skipped: ${target} is already installed`)
prompts.log.warn(`tfcode upgrade skipped: ${target} is already installed`)
prompts.outro("Done")
return
}

View File

@ -31,7 +31,7 @@ function getNetworkIPs() {
export const WebCommand = cmd({
command: "web",
builder: (yargs) => withNetworkOptions(yargs),
describe: "start opencode server and open web interface",
describe: "start tfcode server and open web interface",
handler: async (args) => {
if (!Flag.OPENCODE_SERVER_PASSWORD) {
UI.println(UI.Style.TEXT_WARNING_BOLD + "! " + "OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")

View File

@ -6,14 +6,14 @@ import { UI } from "./ui"
export function FormatError(input: unknown) {
if (MCP.Failed.isInstance(input))
return `MCP server "${input.data.name}" failed. Note, opencode does not support MCP authentication yet.`
return `MCP server "${input.data.name}" failed. Note, tfcode does not support MCP authentication yet.`
if (Provider.ModelNotFoundError.isInstance(input)) {
const { providerID, modelID, suggestions } = input.data
return [
`Model not found: ${providerID}/${modelID}`,
...(Array.isArray(suggestions) && suggestions.length ? ["Did you mean: " + suggestions.join(", ")] : []),
`Try: \`opencode models\` to list available models`,
`Or check your config (opencode.json) provider/model names`,
`Try: \`tfcode models\` to list available models`,
`Or check your config (tfcode.json) provider/model names`,
].join("\n")
}
if (Provider.InitError.isInstance(input)) {

View File

@ -25,12 +25,12 @@ export namespace UI {
export function println(...message: string[]) {
print(...message)
process.stderr.write(EOL)
Bun.stderr.write(EOL)
}
export function print(...message: string[]) {
blank = false
process.stderr.write(message.join(" "))
Bun.stderr.write(message.join(" "))
}
let blank = false
@ -44,7 +44,7 @@ export namespace UI {
const result: string[] = []
const reset = "\x1b[0m"
const left = {
fg: "\x1b[90m",
fg: Bun.color("gray", "ansi") ?? "",
shadow: "\x1b[38;5;235m",
bg: "\x1b[48;5;235m",
}
@ -104,9 +104,6 @@ export namespace UI {
}
export function error(message: string) {
if (message.startsWith("Error: ")) {
message = message.slice("Error: ".length)
}
println(Style.TEXT_DANGER_BOLD + "Error: " + Style.TEXT_NORMAL + message)
}

View File

@ -35,7 +35,7 @@
"vscode-languageserver-types": "3.17.5"
},
"devDependencies": {
"opencode": "workspace:*",
"tfcode": "workspace:*",
"@types/node": "catalog:",
"@astrojs/check": "0.9.6",
"typescript": "catalog:"

View File

@ -5,9 +5,9 @@ import { IconArrowDown } from "./icons"
import { IconOpencode } from "./icons/custom"
import { ShareI18nProvider, formatCurrency, formatNumber, normalizeLocale } from "./share/common"
import styles from "./share.module.css"
import type { MessageV2 } from "opencode/session/message-v2"
import type { Message } from "opencode/session/message"
import type { Session } from "opencode/session/index"
import type { MessageV2 } from "tfcode/session/message-v2"
import type { Message } from "tfcode/session/message"
import type { Session } from "tfcode/session/index"
import { Part, ProviderIcon } from "./share/part"
type MessageWithParts = MessageV2.Info & { parts: MessageV2.Part[] }

View File

@ -27,7 +27,7 @@ import { ContentBash } from "./content-bash"
import { ContentError } from "./content-error"
import { formatCount, formatDuration, formatNumber, normalizeLocale, useShareMessages } from "../share/common"
import { ContentMarkdown } from "./content-markdown"
import type { MessageV2 } from "opencode/session/message-v2"
import type { MessageV2 } from "tfcode/session/message-v2"
import type { Diagnostic } from "vscode-languageserver-types"
import styles from "./part.module.css"

View File

@ -1,7 +1,7 @@
---
import { Base64 } from "js-base64"
import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro"
import type { Session } from "opencode/session/index"
import type { Session } from "tfcode/session/index"
import config from "../../../config.mjs"
import Share from "../../components/Share.tsx"

222
scripts/install-tfcode.sh Normal file
View File

@ -0,0 +1,222 @@
#!/usr/bin/env bash
set -euo pipefail
APP=tfcode
GITEA_HOST="${TFCODE_GITEA_HOST:-gitea.toothfairyai.com}"
GITEA_REPO="${TFCODE_GITEA_REPO:-ToothFairyAI/tfcode}"
MUTED='\033[0;2m'
RED='\033[0;31m'
ORANGE='\033[38;5;214m'
GREEN='\033[0;32m'
NC='\033[0m'
usage() {
cat <<EOF
tfcode Installer - ToothFairyAI's official coding agent
Usage: install.sh [options]
Options:
-h, --help Display this help message
-v, --version <version> Install a specific version (e.g., 1.0.0)
--no-modify-path Don't modify shell config files
Examples:
curl -fsSL https://toothfairyai.com/install/tfcode | bash
curl -fsSL https://toothfairyai.com/install/tfcode | bash -s -- --version 1.0.0
EOF
}
requested_version=${VERSION:-}
no_modify_path=false
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
-v|--version)
if [[ -n "${2:-}" ]]; then
requested_version="$2"
shift 2
else
echo -e "${RED}Error: --version requires a version argument${NC}"
exit 1
fi
;;
--no-modify-path)
no_modify_path=true
shift
;;
*)
echo -e "${ORANGE}Warning: Unknown option '$1'${NC}" >&2
shift
;;
esac
done
INSTALL_DIR=$HOME/.tfcode/bin
mkdir -p "$INSTALL_DIR"
# Detect platform
raw_os=$(uname -s)
os=$(echo "$raw_os" | tr '[:upper:]' '[:lower:]')
case "$raw_os" in
Darwin*) os="darwin" ;;
Linux*) os="linux" ;;
MINGW*|MSYS*|CYGWIN*) os="windows" ;;
esac
arch=$(uname -m)
if [[ "$arch" == "aarch64" ]]; then arch="arm64"; fi
if [[ "$arch" == "x86_64" ]]; then arch="x64"; fi
# Check Rosetta on macOS
if [ "$os" = "darwin" ] && [ "$arch" = "x64" ]; then
rosetta_flag=$(sysctl -n sysctl.proc_translated 2>/dev/null || echo 0)
if [ "$rosetta_flag" = "1" ]; then arch="arm64"; fi
fi
# Check AVX2 on x64
needs_baseline=false
if [ "$arch" = "x64" ]; then
if [ "$os" = "linux" ]; then
if ! grep -qwi avx2 /proc/cpuinfo 2>/dev/null; then
needs_baseline=true
fi
fi
if [ "$os" = "darwin" ]; then
avx2=$(sysctl -n hw.optional.avx2_0 2>/dev/null || echo 0)
if [ "$avx2" != "1" ]; then needs_baseline=true; fi
fi
fi
# Check musl on Linux
is_musl=false
if [ "$os" = "linux" ]; then
if [ -f /etc/alpine-release ]; then is_musl=true; fi
if command -v ldd >/dev/null 2>&1; then
if ldd --version 2>&1 | grep -qi musl; then is_musl=true; fi
fi
fi
# Build target
target="$os-$arch"
if [ "$needs_baseline" = "true" ]; then target="$target-baseline"; fi
if [ "$is_musl" = "true" ]; then target="$target-musl"; fi
archive_ext=".zip"
if [ "$os" = "linux" ]; then archive_ext=".tar.gz"; fi
filename="$APP-$target$archive_ext"
# Check tools
if [ "$os" = "linux" ]; then
if ! command -v tar >/dev/null 2>&1; then
echo -e "${RED}Error: 'tar' is required but not installed.${NC}"
exit 1
fi
else
if ! command -v unzip >/dev/null 2>&1; then
echo -e "${RED}Error: 'unzip' is required but not installed.${NC}"
exit 1
fi
fi
# Get version
if [ -z "$requested_version" ]; then
# Get latest version from Gitea API
api_url="https://$GITEA_HOST/api/v1/repos/$GITEA_REPO/releases/latest"
specific_version=$(curl -s "$api_url" | sed -n 's/.*"tag_name": *"v\([^"]*\)".*/\1/p')
if [[ $? -ne 0 || -z "$specific_version" ]]; then
echo -e "${RED}Failed to fetch version information${NC}"
exit 1
fi
url="https://$GITEA_HOST/$GITEA_REPO/releases/download/v${specific_version}/$filename"
else
requested_version="${requested_version#v}"
url="https://$GITEA_HOST/$GITEA_REPO/releases/download/v${requested_version}/$filename"
specific_version=$requested_version
fi
# Download
echo -e "${MUTED}Installing ${NC}tfcode ${MUTED}version: ${NC}$specific_version"
tmp_dir="${TMPDIR:-/tmp}/tfcode_install_$$"
mkdir -p "$tmp_dir"
echo -e "${MUTED}Downloading ${NC}$filename"
curl -# -L -o "$tmp_dir/$filename" "$url"
# Extract
echo -e "${MUTED}Extracting...${NC}"
if [ "$os" = "linux" ]; then
tar -xzf "$tmp_dir/$filename" -C "$tmp_dir"
else
unzip -q "$tmp_dir/$filename" -d "$tmp_dir"
fi
# Install
mv "$tmp_dir/tfcode" "$INSTALL_DIR"
chmod 755 "${INSTALL_DIR}/tfcode"
rm -rf "$tmp_dir"
# Add to PATH
add_to_path() {
local config_file=$1
local command=$2
if grep -Fxq "$command" "$config_file" 2>/dev/null; then
return
elif [[ -w $config_file ]]; then
echo -e "\n# tfcode" >> "$config_file"
echo "$command" >> "$config_file"
echo -e "${MUTED}Added tfcode to \$PATH in ${NC}$config_file"
fi
}
if [[ "$no_modify_path" != "true" ]]; then
current_shell=$(basename "$SHELL")
case $current_shell in
fish) config_files="$HOME/.config/fish/config.fish" ;;
zsh) config_files="$HOME/.zshrc $HOME/.zshenv" ;;
bash) config_files="$HOME/.bashrc $HOME/.bash_profile $HOME/.profile" ;;
*) config_files="$HOME/.profile" ;;
esac
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
for file in $config_files; do
if [[ -f $file ]]; then
add_to_path "$file" "export PATH=$INSTALL_DIR:\$PATH"
break
fi
done
fi
fi
# Install Python SDK
echo ""
if command -v python3 >/dev/null 2>&1; then
echo -e "${MUTED}Installing ToothFairyAI Python SDK...${NC}"
python3 -m pip install --user --break-system-packages toothfairyai pydantic httpx rich 2>/dev/null || \
python3 -m pip install --user toothfairyai pydantic httpx rich 2>/dev/null || \
echo -e "${ORANGE}Could not install Python SDK. Run manually:${NC}"
echo -e " ${MUTED}pip install toothfairyai pydantic httpx rich${NC}"
fi
echo ""
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${GREEN}✓ tfcode installed successfully!${NC}"
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo -e "${MUTED}Quick Start:${NC}"
echo ""
echo -e " ${ORANGE}tfcode setup${NC} ${MUTED}Interactive credential setup${NC}"
echo -e " ${ORANGE}tfcode validate${NC} ${MUTED}Test your credentials${NC}"
echo -e " ${ORANGE}tfcode sync${NC} ${MUTED}Sync tools from workspace${NC}"
echo -e " ${ORANGE}tfcode${NC} ${MUTED}Start coding assistant${NC}"
echo ""
echo -e "${MUTED}Documentation: https://toothfairyai.com/developers/tfcode${NC}"
echo ""