thoth-agents 0.1.19 → 0.2.0

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.
@@ -1,182 +0,0 @@
1
- // src/utils/subprocess.ts
2
- import {
3
- spawn as nodeSpawn,
4
- spawnSync as nodeSpawnSync
5
- } from "child_process";
6
- import { Readable } from "stream";
7
- function emptyReadableStream() {
8
- return new ReadableStream({
9
- start(controller) {
10
- controller.close();
11
- }
12
- });
13
- }
14
- function toWebReadable(stream) {
15
- if (!stream) {
16
- return emptyReadableStream();
17
- }
18
- return Readable.toWeb(
19
- stream
20
- );
21
- }
22
- function fallbackStdin() {
23
- return {
24
- write: () => void 0,
25
- end: () => void 0
26
- };
27
- }
28
- function spawn(command, options = {}) {
29
- const child = nodeSpawn(command[0], command.slice(1), {
30
- cwd: options.cwd,
31
- env: options.env,
32
- stdio: [
33
- options.stdin ?? "pipe",
34
- options.stdout ?? "pipe",
35
- options.stderr ?? "pipe"
36
- ]
37
- });
38
- const managed = {
39
- stdin: child.stdin ?? fallbackStdin(),
40
- stdout: toWebReadable(child.stdout),
41
- stderr: toWebReadable(child.stderr),
42
- exited: new Promise((resolve) => {
43
- child.on("exit", (code) => {
44
- managed.exitCode = code;
45
- resolve(code ?? 1);
46
- });
47
- child.on("error", () => {
48
- managed.exitCode = 1;
49
- resolve(1);
50
- });
51
- }),
52
- exitCode: child.exitCode,
53
- kill: () => {
54
- child.kill();
55
- }
56
- };
57
- return managed;
58
- }
59
- function spawnSync(command, options = {}) {
60
- const result = nodeSpawnSync(command[0], command.slice(1), {
61
- cwd: options.cwd,
62
- env: options.env,
63
- stdio: [
64
- options.stdin ?? "ignore",
65
- options.stdout ?? "pipe",
66
- options.stderr ?? "pipe"
67
- ]
68
- });
69
- return { exitCode: result.status };
70
- }
71
-
72
- // src/cli/system.ts
73
- import { statSync } from "fs";
74
- var cachedOpenCodePath = null;
75
- function getOpenCodePaths() {
76
- const home = process.env.HOME || process.env.USERPROFILE || "";
77
- return [
78
- // PATH (try this first)
79
- "opencode",
80
- // User local installations (Linux & macOS)
81
- `${home}/.local/bin/opencode`,
82
- `${home}/.opencode/bin/opencode`,
83
- `${home}/bin/opencode`,
84
- // System-wide installations
85
- "/usr/local/bin/opencode",
86
- "/opt/opencode/bin/opencode",
87
- "/usr/bin/opencode",
88
- "/bin/opencode",
89
- // macOS specific
90
- "/Applications/OpenCode.app/Contents/MacOS/opencode",
91
- `${home}/Applications/OpenCode.app/Contents/MacOS/opencode`,
92
- // Homebrew (macOS & Linux)
93
- "/opt/homebrew/bin/opencode",
94
- "/home/linuxbrew/.linuxbrew/bin/opencode",
95
- `${home}/homebrew/bin/opencode`,
96
- // macOS user Library
97
- `${home}/Library/Application Support/opencode/bin/opencode`,
98
- // Snap (Linux)
99
- "/snap/bin/opencode",
100
- "/var/snap/opencode/current/bin/opencode",
101
- // Flatpak (Linux)
102
- "/var/lib/flatpak/exports/bin/ai.opencode.OpenCode",
103
- `${home}/.local/share/flatpak/exports/bin/ai.opencode.OpenCode`,
104
- // Nix (Linux/macOS)
105
- "/nix/store/opencode/bin/opencode",
106
- `${home}/.nix-profile/bin/opencode`,
107
- "/run/current-system/sw/bin/opencode",
108
- // Cargo (Rust toolchain)
109
- `${home}/.cargo/bin/opencode`,
110
- // npm/npx global
111
- `${home}/.npm-global/bin/opencode`,
112
- "/usr/local/lib/node_modules/opencode/bin/opencode",
113
- // Yarn global
114
- `${home}/.yarn/bin/opencode`,
115
- // PNPM
116
- `${home}/.pnpm-global/bin/opencode`
117
- ];
118
- }
119
- function resolveOpenCodePath() {
120
- if (cachedOpenCodePath) {
121
- return cachedOpenCodePath;
122
- }
123
- const paths = getOpenCodePaths();
124
- for (const opencodePath of paths) {
125
- if (opencodePath === "opencode") continue;
126
- try {
127
- const stat = statSync(opencodePath);
128
- if (stat.isFile()) {
129
- cachedOpenCodePath = opencodePath;
130
- return opencodePath;
131
- }
132
- } catch {
133
- }
134
- }
135
- return "opencode";
136
- }
137
- async function isOpenCodeInstalled() {
138
- const paths = getOpenCodePaths();
139
- for (const opencodePath of paths) {
140
- try {
141
- const proc = spawn([opencodePath, "--version"], {
142
- stdout: "pipe",
143
- stderr: "pipe"
144
- });
145
- await proc.exited;
146
- if (proc.exitCode === 0) {
147
- cachedOpenCodePath = opencodePath;
148
- return true;
149
- }
150
- } catch {
151
- }
152
- }
153
- return false;
154
- }
155
- async function getOpenCodeVersion() {
156
- const opencodePath = resolveOpenCodePath();
157
- try {
158
- const proc = spawn([opencodePath, "--version"], {
159
- stdout: "pipe",
160
- stderr: "pipe"
161
- });
162
- const output = await new Response(proc.stdout).text();
163
- await proc.exited;
164
- if (proc.exitCode === 0) {
165
- return output.trim();
166
- }
167
- } catch {
168
- }
169
- return null;
170
- }
171
- function getOpenCodePath() {
172
- const path = resolveOpenCodePath();
173
- return path === "opencode" ? null : path;
174
- }
175
-
176
- export {
177
- spawn,
178
- spawnSync,
179
- isOpenCodeInstalled,
180
- getOpenCodeVersion,
181
- getOpenCodePath
182
- };