chad-code 1.3.7 → 1.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/chad-code CHANGED
@@ -1,12 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const childProcess = require("child_process")
4
- const fs = require("fs")
5
- const path = require("path")
6
- const os = require("os")
3
+ import { spawnSync } from "child_process"
4
+ import { existsSync, readdirSync, realpathSync } from "fs"
5
+ import { dirname, join } from "path"
6
+ import { platform as osPlatform, arch as osArch } from "os"
7
+ import { fileURLToPath } from "url"
7
8
 
8
9
  function run(target) {
9
- const result = childProcess.spawnSync(target, process.argv.slice(2), {
10
+ const result = spawnSync(target, process.argv.slice(2), {
10
11
  stdio: "inherit",
11
12
  })
12
13
  if (result.error) {
@@ -22,8 +23,9 @@ if (envPath) {
22
23
  run(envPath)
23
24
  }
24
25
 
25
- const scriptPath = fs.realpathSync(__filename)
26
- const scriptDir = path.dirname(scriptPath)
26
+ const __filename = fileURLToPath(import.meta.url)
27
+ const scriptPath = realpathSync(__filename)
28
+ const scriptDir = dirname(scriptPath)
27
29
 
28
30
  const platformMap = {
29
31
  darwin: "darwin",
@@ -36,13 +38,13 @@ const archMap = {
36
38
  arm: "arm",
37
39
  }
38
40
 
39
- let platform = platformMap[os.platform()]
41
+ let platform = platformMap[osPlatform()]
40
42
  if (!platform) {
41
- platform = os.platform()
43
+ platform = osPlatform()
42
44
  }
43
- let arch = archMap[os.arch()]
45
+ let arch = archMap[osArch()]
44
46
  if (!arch) {
45
- arch = os.arch()
47
+ arch = osArch()
46
48
  }
47
49
  const base = "chad-code-" + platform + "-" + arch
48
50
  const binary = platform === "windows" ? "chad-code.exe" : "chad-code"
@@ -50,20 +52,20 @@ const binary = platform === "windows" ? "chad-code.exe" : "chad-code"
50
52
  function findBinary(startDir) {
51
53
  let current = startDir
52
54
  for (;;) {
53
- const modules = path.join(current, "node_modules")
54
- if (fs.existsSync(modules)) {
55
- const entries = fs.readdirSync(modules)
55
+ const modules = join(current, "node_modules")
56
+ if (existsSync(modules)) {
57
+ const entries = readdirSync(modules)
56
58
  for (const entry of entries) {
57
59
  if (!entry.startsWith(base)) {
58
60
  continue
59
61
  }
60
- const candidate = path.join(modules, entry, "bin", binary)
61
- if (fs.existsSync(candidate)) {
62
+ const candidate = join(modules, entry, "bin", binary)
63
+ if (existsSync(candidate)) {
62
64
  return candidate
63
65
  }
64
66
  }
65
67
  }
66
- const parent = path.dirname(current)
68
+ const parent = dirname(current)
67
69
  if (parent === current) {
68
70
  return
69
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
4
4
  "name": "chad-code",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -25,7 +25,6 @@
25
25
  "devDependencies": {
26
26
  "@babel/core": "7.28.4",
27
27
  "@octokit/webhooks-types": "7.6.1",
28
- "@opencode-ai/script": "workspace:*",
29
28
  "@parcel/watcher-darwin-arm64": "2.5.1",
30
29
  "@parcel/watcher-darwin-x64": "2.5.1",
31
30
  "@parcel/watcher-linux-arm64-glibc": "2.5.1",
@@ -63,10 +62,8 @@
63
62
  "@octokit/graphql": "9.0.2",
64
63
  "@octokit/rest": "22.0.0",
65
64
  "@openauthjs/openauth": "0.0.0-20250322224806",
66
- "@opencode-ai/plugin": "workspace:*",
67
- "@opencode-ai/script": "workspace:*",
68
- "@opencode-ai/sdk": "workspace:*",
69
- "@opencode-ai/util": "workspace:*",
65
+ "@opencode-ai/plugin": "1.1.13",
66
+ "@opencode-ai/sdk": "1.1.13",
70
67
  "@opentui/core": "0.1.68",
71
68
  "@opentui/solid": "0.1.68",
72
69
  "@parcel/watcher": "2.5.1",
package/src/bun/index.ts CHANGED
@@ -2,7 +2,7 @@ import z from "zod"
2
2
  import { Global } from "../global"
3
3
  import { Log } from "../util/log"
4
4
  import path from "path"
5
- import { NamedError } from "@opencode-ai/util/error"
5
+ import { NamedError } from "@/util/error"
6
6
  import { readableStreamToText } from "bun"
7
7
  import { createRequire } from "module"
8
8
  import { Lock } from "../util/lock"
@@ -19,7 +19,7 @@ import type {
19
19
  } from "@opencode-ai/sdk/v2"
20
20
  import { createStore, produce, reconcile } from "solid-js/store"
21
21
  import { useSDK } from "@tui/context/sdk"
22
- import { Binary } from "@opencode-ai/util/binary"
22
+ import { Binary } from "@/util/binary"
23
23
  import { createSimpleContext } from "./helper"
24
24
  import type { Snapshot } from "@/snapshot"
25
25
  import { useExit } from "./exit"
package/src/cli/ui.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import z from "zod"
2
2
  import { EOL } from "os"
3
- import { NamedError } from "@opencode-ai/util/error"
3
+ import { NamedError } from "@/util/error"
4
4
 
5
5
  export namespace UI {
6
6
  const LOGO = [
@@ -9,7 +9,7 @@ import { mergeDeep, pipe, unique } from "remeda"
9
9
  import { Global } from "../global"
10
10
  import fs from "fs/promises"
11
11
  import { lazy } from "../util/lazy"
12
- import { NamedError } from "@opencode-ai/util/error"
12
+ import { NamedError } from "@/util/error"
13
13
  import { Flag } from "../flag/flag"
14
14
  import { Auth } from "../auth"
15
15
  import { type ParseError as JsoncParseError, parse as parseJsonc, printParseErrorCode } from "jsonc-parser"
@@ -1,4 +1,4 @@
1
- import { NamedError } from "@opencode-ai/util/error"
1
+ import { NamedError } from "@/util/error"
2
2
  import matter from "gray-matter"
3
3
  import { z } from "zod"
4
4
 
@@ -3,7 +3,7 @@ import path from "path"
3
3
  import { Global } from "../global"
4
4
  import fs from "fs/promises"
5
5
  import z from "zod"
6
- import { NamedError } from "@opencode-ai/util/error"
6
+ import { NamedError } from "@/util/error"
7
7
  import { lazy } from "../util/lazy"
8
8
  import { $ } from "bun"
9
9
 
package/src/ide/index.ts CHANGED
@@ -2,7 +2,7 @@ import { BusEvent } from "@/bus/bus-event"
2
2
  import { Bus } from "@/bus"
3
3
  import { spawn } from "bun"
4
4
  import z from "zod"
5
- import { NamedError } from "@opencode-ai/util/error"
5
+ import { NamedError } from "@/util/error"
6
6
  import { Log } from "../util/log"
7
7
 
8
8
  const SUPPORTED_IDES = [
package/src/index.ts CHANGED
@@ -10,7 +10,7 @@ import { UninstallCommand } from "./cli/cmd/uninstall"
10
10
  import { ModelsCommand } from "./cli/cmd/models"
11
11
  import { UI } from "./cli/ui"
12
12
  import { Installation } from "./installation"
13
- import { NamedError } from "@opencode-ai/util/error"
13
+ import { NamedError } from "@/util/error"
14
14
  import { FormatError } from "./cli/error"
15
15
  import { ServeCommand } from "./cli/cmd/serve"
16
16
  import { DebugCommand } from "./cli/cmd/debug"
@@ -2,7 +2,7 @@ import { BusEvent } from "@/bus/bus-event"
2
2
  import path from "path"
3
3
  import { $ } from "bun"
4
4
  import z from "zod"
5
- import { NamedError } from "@opencode-ai/util/error"
5
+ import { NamedError } from "@/util/error"
6
6
  import { Log } from "../util/log"
7
7
  import { iife } from "@/util/iife"
8
8
  import { Flag } from "../flag/flag"
package/src/lsp/client.ts CHANGED
@@ -8,7 +8,7 @@ import { Log } from "../util/log"
8
8
  import { LANGUAGE_EXTENSIONS } from "./language"
9
9
  import z from "zod"
10
10
  import type { LSPServer } from "./server"
11
- import { NamedError } from "@opencode-ai/util/error"
11
+ import { NamedError } from "@/util/error"
12
12
  import { withTimeout } from "../util/timeout"
13
13
  import { Instance } from "../project/instance"
14
14
  import { Filesystem } from "../util/filesystem"
package/src/mcp/index.ts CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  } from "@modelcontextprotocol/sdk/types.js"
12
12
  import { Config } from "../config/config"
13
13
  import { Log } from "../util/log"
14
- import { NamedError } from "@opencode-ai/util/error"
14
+ import { NamedError } from "@/util/error"
15
15
  import z from "zod/v4"
16
16
  import { Instance } from "../project/instance"
17
17
  import { Installation } from "../installation"
@@ -8,7 +8,7 @@ import { Log } from "../util/log"
8
8
  import { Flag } from "@/flag/flag"
9
9
  import { Session } from "../session"
10
10
  import { work } from "../util/queue"
11
- import { fn } from "@opencode-ai/util/fn"
11
+ import { fn } from "@/util/fn"
12
12
  import { BusEvent } from "@/bus/bus-event"
13
13
  import { iife } from "@/util/iife"
14
14
  import { GlobalBus } from "@/bus/global"
@@ -4,7 +4,7 @@ import { map, filter, pipe, fromEntries, mapValues } from "remeda"
4
4
  import z from "zod"
5
5
  import { fn } from "@/util/fn"
6
6
  import type { AuthOuathResult, Hooks } from "@opencode-ai/plugin"
7
- import { NamedError } from "@opencode-ai/util/error"
7
+ import { NamedError } from "@/util/error"
8
8
  import { Auth } from "@/auth"
9
9
 
10
10
  export namespace ProviderAuth {
@@ -3,7 +3,7 @@ import { Config } from "../config/config"
3
3
  import { mapValues, mergeDeep } from "remeda"
4
4
  import { NoSuchModelError, type Provider as SDK } from "ai"
5
5
  import { Log } from "../util/log"
6
- import { NamedError } from "@opencode-ai/util/error"
6
+ import { NamedError } from "@/util/error"
7
7
  import { Env } from "../env"
8
8
  import { Instance } from "../project/instance"
9
9
  import { createOpenAICompatible } from "@ai-sdk/openai-compatible"
package/src/pty/index.ts CHANGED
@@ -6,7 +6,7 @@ import { Identifier } from "../id/id"
6
6
  import { Log } from "../util/log"
7
7
  import type { WSContext } from "hono/ws"
8
8
  import { Instance } from "../project/instance"
9
- import { lazy } from "@opencode-ai/util/lazy"
9
+ import { lazy } from "@/util/lazy"
10
10
  import { Shell } from "@/shell/shell"
11
11
 
12
12
  export namespace Pty {
@@ -11,7 +11,7 @@ import { Session } from "../session"
11
11
  import z from "zod"
12
12
  import { Provider } from "../provider/provider"
13
13
  import { filter, mapValues, sortBy, pipe } from "remeda"
14
- import { NamedError } from "@opencode-ai/util/error"
14
+ import { NamedError } from "@/util/error"
15
15
  import { ModelsDev } from "../provider/models"
16
16
  import { Ripgrep } from "../file/ripgrep"
17
17
  import { Config } from "../config/config"
@@ -1,6 +1,6 @@
1
1
  import { BusEvent } from "@/bus/bus-event"
2
2
  import z from "zod"
3
- import { NamedError } from "@opencode-ai/util/error"
3
+ import { NamedError } from "@/util/error"
4
4
  import { APICallError, convertToModelMessages, LoadAPIKeyError, type ModelMessage, type UIMessage } from "ai"
5
5
  import { Identifier } from "../id/id"
6
6
  import { LSP } from "../lsp"
@@ -1,5 +1,5 @@
1
1
  import z from "zod"
2
- import { NamedError } from "@opencode-ai/util/error"
2
+ import { NamedError } from "@/util/error"
3
3
 
4
4
  export namespace Message {
5
5
  export const OutputLengthError = NamedError.create("MessageOutputLengthError", z.object({}))
@@ -34,7 +34,7 @@ import { Command } from "../command"
34
34
  import { $, fileURLToPath } from "bun"
35
35
  import { ConfigMarkdown } from "../config/markdown"
36
36
  import { SessionSummary } from "./summary"
37
- import { NamedError } from "@opencode-ai/util/error"
37
+ import { NamedError } from "@/util/error"
38
38
  import { fn } from "@/util/fn"
39
39
  import { SessionProcessor } from "./processor"
40
40
  import { TaskTool } from "@/tool/task"
@@ -1,4 +1,4 @@
1
- import type { NamedError } from "@opencode-ai/util/error"
1
+ import type { NamedError } from "@/util/error"
2
2
  import { MessageV2 } from "./message-v2"
3
3
 
4
4
  export namespace SessionRetry {
@@ -1,7 +1,7 @@
1
1
  import z from "zod"
2
2
  import { Config } from "../config/config"
3
3
  import { Instance } from "../project/instance"
4
- import { NamedError } from "@opencode-ai/util/error"
4
+ import { NamedError } from "@/util/error"
5
5
  import { ConfigMarkdown } from "../config/markdown"
6
6
  import { Log } from "../util/log"
7
7
  import { Global } from "@/global"
@@ -5,7 +5,7 @@ import { Global } from "../global"
5
5
  import { lazy } from "../util/lazy"
6
6
  import { Lock } from "../util/lock"
7
7
  import { $ } from "bun"
8
- import { NamedError } from "@opencode-ai/util/error"
8
+ import { NamedError } from "@/util/error"
9
9
  import z from "zod"
10
10
 
11
11
  export namespace Storage {
@@ -0,0 +1,41 @@
1
+ export namespace Binary {
2
+ export function search<T>(array: T[], id: string, compare: (item: T) => string): { found: boolean; index: number } {
3
+ let left = 0
4
+ let right = array.length - 1
5
+
6
+ while (left <= right) {
7
+ const mid = Math.floor((left + right) / 2)
8
+ const midId = compare(array[mid])
9
+
10
+ if (midId === id) {
11
+ return { found: true, index: mid }
12
+ } else if (midId < id) {
13
+ left = mid + 1
14
+ } else {
15
+ right = mid - 1
16
+ }
17
+ }
18
+
19
+ return { found: false, index: left }
20
+ }
21
+
22
+ export function insert<T>(array: T[], item: T, compare: (item: T) => string): T[] {
23
+ const id = compare(item)
24
+ let left = 0
25
+ let right = array.length
26
+
27
+ while (left < right) {
28
+ const mid = Math.floor((left + right) / 2)
29
+ const midId = compare(array[mid])
30
+
31
+ if (midId < id) {
32
+ left = mid + 1
33
+ } else {
34
+ right = mid
35
+ }
36
+ }
37
+
38
+ array.splice(left, 0, item)
39
+ return array
40
+ }
41
+ }
@@ -0,0 +1,54 @@
1
+ import z from "zod"
2
+
3
+ export abstract class NamedError extends Error {
4
+ abstract schema(): z.core.$ZodType
5
+ abstract toObject(): { name: string; data: any }
6
+
7
+ static create<Name extends string, Data extends z.core.$ZodType>(name: Name, data: Data) {
8
+ const schema = z
9
+ .object({
10
+ name: z.literal(name),
11
+ data,
12
+ })
13
+ .meta({
14
+ ref: name,
15
+ })
16
+ const result = class extends NamedError {
17
+ public static readonly Schema = schema
18
+
19
+ public override readonly name = name as Name
20
+
21
+ constructor(
22
+ public readonly data: z.input<Data>,
23
+ options?: ErrorOptions,
24
+ ) {
25
+ super(name, options)
26
+ this.name = name
27
+ }
28
+
29
+ static isInstance(input: any): input is InstanceType<typeof result> {
30
+ return typeof input === "object" && "name" in input && input.name === name
31
+ }
32
+
33
+ schema() {
34
+ return schema
35
+ }
36
+
37
+ toObject() {
38
+ return {
39
+ name: name,
40
+ data: this.data,
41
+ }
42
+ }
43
+ }
44
+ Object.defineProperty(result, "name", { value: name })
45
+ return result
46
+ }
47
+
48
+ public static readonly Unknown = NamedError.create(
49
+ "UnknownError",
50
+ z.object({
51
+ message: z.string(),
52
+ }),
53
+ )
54
+ }
@@ -2,7 +2,7 @@ import { $ } from "bun"
2
2
  import fs from "fs/promises"
3
3
  import path from "path"
4
4
  import z from "zod"
5
- import { NamedError } from "@opencode-ai/util/error"
5
+ import { NamedError } from "@/util/error"
6
6
  import { Global } from "../global"
7
7
  import { Instance } from "../project/instance"
8
8
  import { Project } from "../project/project"