agentswarm-cli 0.0.0-next-202603190040
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/LICENSE +21 -0
- package/README.md +161 -0
- package/bin/agency +180 -0
- package/bin/bin/agency +180 -0
- package/package.json +32 -0
- package/postinstall.mjs +131 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 opencode
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://opencode.ai">
|
|
3
|
+
<picture>
|
|
4
|
+
<source srcset="packages/console/app/src/asset/logo-ornate-dark.svg" media="(prefers-color-scheme: dark)">
|
|
5
|
+
<source srcset="packages/console/app/src/asset/logo-ornate-light.svg" media="(prefers-color-scheme: light)">
|
|
6
|
+
<img src="packages/console/app/src/asset/logo-ornate-light.svg" alt="OpenCode logo">
|
|
7
|
+
</picture>
|
|
8
|
+
</a>
|
|
9
|
+
</p>
|
|
10
|
+
<p align="center">The open source AI coding agent.</p>
|
|
11
|
+
|
|
12
|
+
> [!NOTE]
|
|
13
|
+
> This repository is the private `agent-swarm-cli` fork used to ship Agency Swarm integration on top of the OpenCode TUI.
|
|
14
|
+
> Keep OpenCode client/server contracts intact while extending the runtime under `packages/opencode/src/agency-swarm/`.
|
|
15
|
+
|
|
16
|
+
## Agency Swarm Integration Notes
|
|
17
|
+
|
|
18
|
+
- Agency Swarm runtime integration is limited to the existing FastAPI endpoints:
|
|
19
|
+
- `get_metadata`
|
|
20
|
+
- `get_response_stream`
|
|
21
|
+
- `cancel_response_stream`
|
|
22
|
+
- `get_response`
|
|
23
|
+
- OpenCode session/message/event contracts remain the UI source of truth. Agency frames are translated into standard processor stream parts (`text-*`, `reasoning-*`, `tool-*`, `finish-step`, `finish`) before persistence.
|
|
24
|
+
- Provider-specific logic should not bypass `SessionProcessor` with direct message writes.
|
|
25
|
+
- `chat_history` is required by the current Agency API contract, so a transport sidecar is maintained in `packages/opencode/src/agency-swarm/history.ts`. This is request continuity state, not a replacement for OpenCode session storage.
|
|
26
|
+
- Recipient-agent routing is validated against live `get_metadata` on each turn before `recipient_agent` is sent. Stale saved recipients are ignored instead of causing 422 failures.
|
|
27
|
+
|
|
28
|
+
<p align="center">
|
|
29
|
+
<a href="https://opencode.ai/discord"><img alt="Discord" src="https://img.shields.io/discord/1391832426048651334?style=flat-square&label=discord" /></a>
|
|
30
|
+
<a href="https://www.npmjs.com/package/agent-swarm-cli"><img alt="npm" src="https://img.shields.io/npm/v/agent-swarm-cli?style=flat-square" /></a>
|
|
31
|
+
<a href="https://github.com/anomalyco/opencode/actions/workflows/publish.yml"><img alt="Build status" src="https://img.shields.io/github/actions/workflow/status/anomalyco/opencode/publish.yml?style=flat-square&branch=dev" /></a>
|
|
32
|
+
</p>
|
|
33
|
+
|
|
34
|
+
<p align="center">
|
|
35
|
+
<a href="README.md">English</a> |
|
|
36
|
+
<a href="README.zh.md">简体中文</a> |
|
|
37
|
+
<a href="README.zht.md">繁體中文</a> |
|
|
38
|
+
<a href="README.ko.md">한국어</a> |
|
|
39
|
+
<a href="README.de.md">Deutsch</a> |
|
|
40
|
+
<a href="README.es.md">Español</a> |
|
|
41
|
+
<a href="README.fr.md">Français</a> |
|
|
42
|
+
<a href="README.it.md">Italiano</a> |
|
|
43
|
+
<a href="README.da.md">Dansk</a> |
|
|
44
|
+
<a href="README.ja.md">日本語</a> |
|
|
45
|
+
<a href="README.pl.md">Polski</a> |
|
|
46
|
+
<a href="README.ru.md">Русский</a> |
|
|
47
|
+
<a href="README.bs.md">Bosanski</a> |
|
|
48
|
+
<a href="README.ar.md">العربية</a> |
|
|
49
|
+
<a href="README.no.md">Norsk</a> |
|
|
50
|
+
<a href="README.br.md">Português (Brasil)</a> |
|
|
51
|
+
<a href="README.th.md">ไทย</a> |
|
|
52
|
+
<a href="README.tr.md">Türkçe</a> |
|
|
53
|
+
<a href="README.uk.md">Українська</a> |
|
|
54
|
+
<a href="README.bn.md">বাংলা</a> |
|
|
55
|
+
<a href="README.gr.md">Ελληνικά</a> |
|
|
56
|
+
<a href="README.vi.md">Tiếng Việt</a>
|
|
57
|
+
</p>
|
|
58
|
+
|
|
59
|
+
[](https://opencode.ai)
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
### Installation
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# YOLO
|
|
67
|
+
curl -fsSL https://opencode.ai/install | bash
|
|
68
|
+
|
|
69
|
+
# Package managers
|
|
70
|
+
npm i -g agent-swarm-cli # or agentswarm-cli
|
|
71
|
+
|
|
72
|
+
# Commands
|
|
73
|
+
agentswarm
|
|
74
|
+
scoop install opencode # Windows
|
|
75
|
+
choco install opencode # Windows
|
|
76
|
+
brew install anomalyco/tap/opencode # macOS and Linux (recommended, always up to date)
|
|
77
|
+
brew install opencode # macOS and Linux (official brew formula, updated less)
|
|
78
|
+
sudo pacman -S opencode # Arch Linux (Stable)
|
|
79
|
+
paru -S opencode-bin # Arch Linux (Latest from AUR)
|
|
80
|
+
mise use -g opencode # Any OS
|
|
81
|
+
nix run nixpkgs#opencode # or github:anomalyco/opencode for latest dev branch
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
> [!TIP]
|
|
85
|
+
> Remove versions older than 0.1.x before installing.
|
|
86
|
+
|
|
87
|
+
### Desktop App (BETA)
|
|
88
|
+
|
|
89
|
+
OpenCode is also available as a desktop application. Download directly from the [releases page](https://github.com/anomalyco/opencode/releases) or [opencode.ai/download](https://opencode.ai/download).
|
|
90
|
+
|
|
91
|
+
| Platform | Download |
|
|
92
|
+
| --------------------- | ------------------------------------- |
|
|
93
|
+
| macOS (Apple Silicon) | `opencode-desktop-darwin-aarch64.dmg` |
|
|
94
|
+
| macOS (Intel) | `opencode-desktop-darwin-x64.dmg` |
|
|
95
|
+
| Windows | `opencode-desktop-windows-x64.exe` |
|
|
96
|
+
| Linux | `.deb`, `.rpm`, or AppImage |
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# macOS (Homebrew)
|
|
100
|
+
brew install --cask opencode-desktop
|
|
101
|
+
# Windows (Scoop)
|
|
102
|
+
scoop bucket add extras; scoop install extras/opencode-desktop
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### Installation Directory
|
|
106
|
+
|
|
107
|
+
The install script respects the following priority order for the installation path:
|
|
108
|
+
|
|
109
|
+
1. `$OPENCODE_INSTALL_DIR` - Custom installation directory
|
|
110
|
+
2. `$XDG_BIN_DIR` - XDG Base Directory Specification compliant path
|
|
111
|
+
3. `$HOME/bin` - Standard user binary directory (if it exists or can be created)
|
|
112
|
+
4. `$HOME/.opencode/bin` - Default fallback
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# Examples
|
|
116
|
+
OPENCODE_INSTALL_DIR=/usr/local/bin curl -fsSL https://opencode.ai/install | bash
|
|
117
|
+
XDG_BIN_DIR=$HOME/.local/bin curl -fsSL https://opencode.ai/install | bash
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Agents
|
|
121
|
+
|
|
122
|
+
OpenCode includes two built-in agents you can switch between with the `Tab` key.
|
|
123
|
+
|
|
124
|
+
- **build** - Default, full-access agent for development work
|
|
125
|
+
- **plan** - Read-only agent for analysis and code exploration
|
|
126
|
+
- Denies file edits by default
|
|
127
|
+
- Asks permission before running bash commands
|
|
128
|
+
- Ideal for exploring unfamiliar codebases or planning changes
|
|
129
|
+
|
|
130
|
+
Also included is a **general** subagent for complex searches and multistep tasks.
|
|
131
|
+
This is used internally and can be invoked using `@general` in messages.
|
|
132
|
+
|
|
133
|
+
Learn more about [agents](https://opencode.ai/docs/agents).
|
|
134
|
+
|
|
135
|
+
### Documentation
|
|
136
|
+
|
|
137
|
+
For more info on how to configure OpenCode, [**head over to our docs**](https://opencode.ai/docs).
|
|
138
|
+
|
|
139
|
+
### Contributing
|
|
140
|
+
|
|
141
|
+
If you're interested in contributing to OpenCode, please read our [contributing docs](./CONTRIBUTING.md) before submitting a pull request.
|
|
142
|
+
|
|
143
|
+
### Building on OpenCode
|
|
144
|
+
|
|
145
|
+
If you are working on a project that's related to OpenCode and is using "opencode" as part of its name, for example "opencode-dashboard" or "opencode-mobile", please add a note to your README to clarify that it is not built by the OpenCode team and is not affiliated with us in any way.
|
|
146
|
+
|
|
147
|
+
### FAQ
|
|
148
|
+
|
|
149
|
+
#### How is this different from Claude Code?
|
|
150
|
+
|
|
151
|
+
It's very similar to Claude Code in terms of capability. Here are the key differences:
|
|
152
|
+
|
|
153
|
+
- 100% open source
|
|
154
|
+
- Not coupled to any provider. Although we recommend the models we provide through [OpenCode Zen](https://opencode.ai/zen), OpenCode can be used with Claude, OpenAI, Google, or even local models. As models evolve, the gaps between them will close and pricing will drop, so being provider-agnostic is important.
|
|
155
|
+
- Out-of-the-box LSP support
|
|
156
|
+
- A focus on TUI. OpenCode is built by neovim users and the creators of [terminal.shop](https://terminal.shop); we are going to push the limits of what's possible in the terminal.
|
|
157
|
+
- A client/server architecture. This, for example, can allow OpenCode to run on your computer while you drive it remotely from a mobile app, meaning that the TUI frontend is just one of the possible clients.
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
**Join our community** [Discord](https://discord.gg/opencode) | [X.com](https://x.com/opencode)
|
package/bin/agency
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import * as childProcess from "node:child_process"
|
|
4
|
+
import * as fs from "node:fs"
|
|
5
|
+
import os from "node:os"
|
|
6
|
+
import path from "node:path"
|
|
7
|
+
import { fileURLToPath } from "node:url"
|
|
8
|
+
|
|
9
|
+
function run(target) {
|
|
10
|
+
const result = childProcess.spawnSync(target, process.argv.slice(2), {
|
|
11
|
+
stdio: "inherit",
|
|
12
|
+
})
|
|
13
|
+
if (result.error) {
|
|
14
|
+
console.error(result.error.message)
|
|
15
|
+
process.exit(1)
|
|
16
|
+
}
|
|
17
|
+
const code = typeof result.status === "number" ? result.status : 0
|
|
18
|
+
process.exit(code)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const envPath = process.env.AGENCY_BIN_PATH || process.env.OPENCODE_BIN_PATH
|
|
22
|
+
if (envPath) {
|
|
23
|
+
run(envPath)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const scriptPath = fs.realpathSync(fileURLToPath(import.meta.url))
|
|
27
|
+
const scriptDir = path.dirname(scriptPath)
|
|
28
|
+
|
|
29
|
+
//
|
|
30
|
+
const cached = path.join(scriptDir, ".opencode")
|
|
31
|
+
if (fs.existsSync(cached)) {
|
|
32
|
+
run(cached)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const platformMap = {
|
|
36
|
+
darwin: "darwin",
|
|
37
|
+
linux: "linux",
|
|
38
|
+
win32: "windows",
|
|
39
|
+
}
|
|
40
|
+
const archMap = {
|
|
41
|
+
x64: "x64",
|
|
42
|
+
arm64: "arm64",
|
|
43
|
+
arm: "arm",
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let platform = platformMap[os.platform()]
|
|
47
|
+
if (!platform) {
|
|
48
|
+
platform = os.platform()
|
|
49
|
+
}
|
|
50
|
+
let arch = archMap[os.arch()]
|
|
51
|
+
if (!arch) {
|
|
52
|
+
arch = os.arch()
|
|
53
|
+
}
|
|
54
|
+
const base = "agent-swarm-cli-" + platform + "-" + arch
|
|
55
|
+
const binary = platform === "windows" ? "agency.exe" : "agency"
|
|
56
|
+
|
|
57
|
+
function supportsAvx2() {
|
|
58
|
+
if (arch !== "x64") return false
|
|
59
|
+
|
|
60
|
+
if (platform === "linux") {
|
|
61
|
+
try {
|
|
62
|
+
return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
|
|
63
|
+
} catch {
|
|
64
|
+
return false
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (platform === "darwin") {
|
|
69
|
+
try {
|
|
70
|
+
const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
|
|
71
|
+
encoding: "utf8",
|
|
72
|
+
timeout: 1500,
|
|
73
|
+
})
|
|
74
|
+
if (result.status !== 0) return false
|
|
75
|
+
return (result.stdout || "").trim() === "1"
|
|
76
|
+
} catch {
|
|
77
|
+
return false
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (platform === "windows") {
|
|
82
|
+
const cmd =
|
|
83
|
+
'(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
|
|
84
|
+
|
|
85
|
+
for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
|
|
86
|
+
try {
|
|
87
|
+
const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
|
|
88
|
+
encoding: "utf8",
|
|
89
|
+
timeout: 3000,
|
|
90
|
+
windowsHide: true,
|
|
91
|
+
})
|
|
92
|
+
if (result.status !== 0) continue
|
|
93
|
+
const out = (result.stdout || "").trim().toLowerCase()
|
|
94
|
+
if (out === "true" || out === "1") return true
|
|
95
|
+
if (out === "false" || out === "0") return false
|
|
96
|
+
} catch {
|
|
97
|
+
continue
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return false
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return false
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const names = (() => {
|
|
108
|
+
const avx2 = supportsAvx2()
|
|
109
|
+
const baseline = arch === "x64" && !avx2
|
|
110
|
+
|
|
111
|
+
if (platform === "linux") {
|
|
112
|
+
const musl = (() => {
|
|
113
|
+
try {
|
|
114
|
+
if (fs.existsSync("/etc/alpine-release")) return true
|
|
115
|
+
} catch {
|
|
116
|
+
// ignore
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
|
|
121
|
+
const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
|
|
122
|
+
if (text.includes("musl")) return true
|
|
123
|
+
} catch {
|
|
124
|
+
// ignore
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return false
|
|
128
|
+
})()
|
|
129
|
+
|
|
130
|
+
if (musl) {
|
|
131
|
+
if (arch === "x64") {
|
|
132
|
+
if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
|
|
133
|
+
return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
|
|
134
|
+
}
|
|
135
|
+
return [`${base}-musl`, base]
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (arch === "x64") {
|
|
139
|
+
if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
|
|
140
|
+
return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
|
|
141
|
+
}
|
|
142
|
+
return [base, `${base}-musl`]
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (arch === "x64") {
|
|
146
|
+
if (baseline) return [`${base}-baseline`, base]
|
|
147
|
+
return [base, `${base}-baseline`]
|
|
148
|
+
}
|
|
149
|
+
return [base]
|
|
150
|
+
})()
|
|
151
|
+
|
|
152
|
+
function findBinary(startDir) {
|
|
153
|
+
let current = startDir
|
|
154
|
+
for (;;) {
|
|
155
|
+
const modules = path.join(current, "node_modules")
|
|
156
|
+
if (fs.existsSync(modules)) {
|
|
157
|
+
for (const name of names) {
|
|
158
|
+
const candidate = path.join(modules, name, "bin", binary)
|
|
159
|
+
if (fs.existsSync(candidate)) return candidate
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const parent = path.dirname(current)
|
|
163
|
+
if (parent === current) {
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
current = parent
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const resolved = findBinary(scriptDir)
|
|
171
|
+
if (!resolved) {
|
|
172
|
+
console.error(
|
|
173
|
+
"It seems that your package manager failed to install the right version of the agent-swarm-cli or agentswarm-cli package for your platform. You can try manually installing " +
|
|
174
|
+
names.map((n) => `\"${n}\"`).join(" or ") +
|
|
175
|
+
" package",
|
|
176
|
+
)
|
|
177
|
+
process.exit(1)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
run(resolved)
|
package/bin/bin/agency
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import * as childProcess from "node:child_process"
|
|
4
|
+
import * as fs from "node:fs"
|
|
5
|
+
import os from "node:os"
|
|
6
|
+
import path from "node:path"
|
|
7
|
+
import { fileURLToPath } from "node:url"
|
|
8
|
+
|
|
9
|
+
function run(target) {
|
|
10
|
+
const result = childProcess.spawnSync(target, process.argv.slice(2), {
|
|
11
|
+
stdio: "inherit",
|
|
12
|
+
})
|
|
13
|
+
if (result.error) {
|
|
14
|
+
console.error(result.error.message)
|
|
15
|
+
process.exit(1)
|
|
16
|
+
}
|
|
17
|
+
const code = typeof result.status === "number" ? result.status : 0
|
|
18
|
+
process.exit(code)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const envPath = process.env.AGENCY_BIN_PATH || process.env.OPENCODE_BIN_PATH
|
|
22
|
+
if (envPath) {
|
|
23
|
+
run(envPath)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const scriptPath = fs.realpathSync(fileURLToPath(import.meta.url))
|
|
27
|
+
const scriptDir = path.dirname(scriptPath)
|
|
28
|
+
|
|
29
|
+
//
|
|
30
|
+
const cached = path.join(scriptDir, ".opencode")
|
|
31
|
+
if (fs.existsSync(cached)) {
|
|
32
|
+
run(cached)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const platformMap = {
|
|
36
|
+
darwin: "darwin",
|
|
37
|
+
linux: "linux",
|
|
38
|
+
win32: "windows",
|
|
39
|
+
}
|
|
40
|
+
const archMap = {
|
|
41
|
+
x64: "x64",
|
|
42
|
+
arm64: "arm64",
|
|
43
|
+
arm: "arm",
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let platform = platformMap[os.platform()]
|
|
47
|
+
if (!platform) {
|
|
48
|
+
platform = os.platform()
|
|
49
|
+
}
|
|
50
|
+
let arch = archMap[os.arch()]
|
|
51
|
+
if (!arch) {
|
|
52
|
+
arch = os.arch()
|
|
53
|
+
}
|
|
54
|
+
const base = "agent-swarm-cli-" + platform + "-" + arch
|
|
55
|
+
const binary = platform === "windows" ? "agency.exe" : "agency"
|
|
56
|
+
|
|
57
|
+
function supportsAvx2() {
|
|
58
|
+
if (arch !== "x64") return false
|
|
59
|
+
|
|
60
|
+
if (platform === "linux") {
|
|
61
|
+
try {
|
|
62
|
+
return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
|
|
63
|
+
} catch {
|
|
64
|
+
return false
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (platform === "darwin") {
|
|
69
|
+
try {
|
|
70
|
+
const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
|
|
71
|
+
encoding: "utf8",
|
|
72
|
+
timeout: 1500,
|
|
73
|
+
})
|
|
74
|
+
if (result.status !== 0) return false
|
|
75
|
+
return (result.stdout || "").trim() === "1"
|
|
76
|
+
} catch {
|
|
77
|
+
return false
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (platform === "windows") {
|
|
82
|
+
const cmd =
|
|
83
|
+
'(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
|
|
84
|
+
|
|
85
|
+
for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
|
|
86
|
+
try {
|
|
87
|
+
const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
|
|
88
|
+
encoding: "utf8",
|
|
89
|
+
timeout: 3000,
|
|
90
|
+
windowsHide: true,
|
|
91
|
+
})
|
|
92
|
+
if (result.status !== 0) continue
|
|
93
|
+
const out = (result.stdout || "").trim().toLowerCase()
|
|
94
|
+
if (out === "true" || out === "1") return true
|
|
95
|
+
if (out === "false" || out === "0") return false
|
|
96
|
+
} catch {
|
|
97
|
+
continue
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return false
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return false
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const names = (() => {
|
|
108
|
+
const avx2 = supportsAvx2()
|
|
109
|
+
const baseline = arch === "x64" && !avx2
|
|
110
|
+
|
|
111
|
+
if (platform === "linux") {
|
|
112
|
+
const musl = (() => {
|
|
113
|
+
try {
|
|
114
|
+
if (fs.existsSync("/etc/alpine-release")) return true
|
|
115
|
+
} catch {
|
|
116
|
+
// ignore
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
|
|
121
|
+
const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
|
|
122
|
+
if (text.includes("musl")) return true
|
|
123
|
+
} catch {
|
|
124
|
+
// ignore
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return false
|
|
128
|
+
})()
|
|
129
|
+
|
|
130
|
+
if (musl) {
|
|
131
|
+
if (arch === "x64") {
|
|
132
|
+
if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
|
|
133
|
+
return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
|
|
134
|
+
}
|
|
135
|
+
return [`${base}-musl`, base]
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (arch === "x64") {
|
|
139
|
+
if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
|
|
140
|
+
return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
|
|
141
|
+
}
|
|
142
|
+
return [base, `${base}-musl`]
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (arch === "x64") {
|
|
146
|
+
if (baseline) return [`${base}-baseline`, base]
|
|
147
|
+
return [base, `${base}-baseline`]
|
|
148
|
+
}
|
|
149
|
+
return [base]
|
|
150
|
+
})()
|
|
151
|
+
|
|
152
|
+
function findBinary(startDir) {
|
|
153
|
+
let current = startDir
|
|
154
|
+
for (;;) {
|
|
155
|
+
const modules = path.join(current, "node_modules")
|
|
156
|
+
if (fs.existsSync(modules)) {
|
|
157
|
+
for (const name of names) {
|
|
158
|
+
const candidate = path.join(modules, name, "bin", binary)
|
|
159
|
+
if (fs.existsSync(candidate)) return candidate
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const parent = path.dirname(current)
|
|
163
|
+
if (parent === current) {
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
current = parent
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const resolved = findBinary(scriptDir)
|
|
171
|
+
if (!resolved) {
|
|
172
|
+
console.error(
|
|
173
|
+
"It seems that your package manager failed to install the right version of the agent-swarm-cli or agentswarm-cli package for your platform. You can try manually installing " +
|
|
174
|
+
names.map((n) => `\"${n}\"`).join(" or ") +
|
|
175
|
+
" package",
|
|
176
|
+
)
|
|
177
|
+
process.exit(1)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
run(resolved)
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "agentswarm-cli",
|
|
3
|
+
"version": "0.0.0-next-202603190040",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "Agent Swarm CLI for the terminal.",
|
|
7
|
+
"bin": {
|
|
8
|
+
"agentswarm": "./bin/agency"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
|
|
12
|
+
},
|
|
13
|
+
"optionalDependencies": {
|
|
14
|
+
"agent-swarm-cli-windows-x64": "0.0.0-next-202603190040",
|
|
15
|
+
"agent-swarm-cli-linux-arm64": "0.0.0-next-202603190040",
|
|
16
|
+
"agent-swarm-cli-linux-x64-baseline": "0.0.0-next-202603190040",
|
|
17
|
+
"agent-swarm-cli-linux-x64": "0.0.0-next-202603190040",
|
|
18
|
+
"agent-swarm-cli-darwin-arm64": "0.0.0-next-202603190040",
|
|
19
|
+
"agent-swarm-cli-windows-arm64": "0.0.0-next-202603190040",
|
|
20
|
+
"agentswarm-cli": "0.0.0-next-202603190040",
|
|
21
|
+
"agent-swarm-cli-windows-x64-baseline": "0.0.0-next-202603190040",
|
|
22
|
+
"agent-swarm-cli-linux-x64-musl": "0.0.0-next-202603190040",
|
|
23
|
+
"agent-swarm-cli-linux-arm64-musl": "0.0.0-next-202603190040",
|
|
24
|
+
"agent-swarm-cli": "0.0.0-next-202603190040",
|
|
25
|
+
"agent-swarm-cli-linux-x64-baseline-musl": "0.0.0-next-202603190040",
|
|
26
|
+
"agent-swarm-cli-darwin-x64": "0.0.0-next-202603190040",
|
|
27
|
+
"agent-swarm-cli-darwin-x64-baseline": "0.0.0-next-202603190040"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/postinstall.mjs
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "fs"
|
|
4
|
+
import path from "path"
|
|
5
|
+
import os from "os"
|
|
6
|
+
import { fileURLToPath } from "url"
|
|
7
|
+
import { createRequire } from "module"
|
|
8
|
+
|
|
9
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
10
|
+
const require = createRequire(import.meta.url)
|
|
11
|
+
|
|
12
|
+
function detectPlatformAndArch() {
|
|
13
|
+
// Map platform names
|
|
14
|
+
let platform
|
|
15
|
+
switch (os.platform()) {
|
|
16
|
+
case "darwin":
|
|
17
|
+
platform = "darwin"
|
|
18
|
+
break
|
|
19
|
+
case "linux":
|
|
20
|
+
platform = "linux"
|
|
21
|
+
break
|
|
22
|
+
case "win32":
|
|
23
|
+
platform = "windows"
|
|
24
|
+
break
|
|
25
|
+
default:
|
|
26
|
+
platform = os.platform()
|
|
27
|
+
break
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Map architecture names
|
|
31
|
+
let arch
|
|
32
|
+
switch (os.arch()) {
|
|
33
|
+
case "x64":
|
|
34
|
+
arch = "x64"
|
|
35
|
+
break
|
|
36
|
+
case "arm64":
|
|
37
|
+
arch = "arm64"
|
|
38
|
+
break
|
|
39
|
+
case "arm":
|
|
40
|
+
arch = "arm"
|
|
41
|
+
break
|
|
42
|
+
default:
|
|
43
|
+
arch = os.arch()
|
|
44
|
+
break
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return { platform, arch }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function findBinary() {
|
|
51
|
+
const { platform, arch } = detectPlatformAndArch()
|
|
52
|
+
const packageName = `agent-swarm-cli-${platform}-${arch}`
|
|
53
|
+
const binaryName = platform === "windows" ? "agency.exe" : "agency"
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
// Use require.resolve to find the package
|
|
57
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`)
|
|
58
|
+
const packageDir = path.dirname(packageJsonPath)
|
|
59
|
+
const binaryPath = path.join(packageDir, "bin", binaryName)
|
|
60
|
+
|
|
61
|
+
if (!fs.existsSync(binaryPath)) {
|
|
62
|
+
throw new Error(`Binary not found at ${binaryPath}`)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return { binaryPath, binaryName }
|
|
66
|
+
} catch (error) {
|
|
67
|
+
throw new Error(`Could not find package ${packageName}: ${error.message}`)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function prepareBinDirectory(binaryName) {
|
|
72
|
+
const binDir = path.join(__dirname, "bin")
|
|
73
|
+
const targetPath = path.join(binDir, binaryName)
|
|
74
|
+
|
|
75
|
+
// Ensure bin directory exists
|
|
76
|
+
if (!fs.existsSync(binDir)) {
|
|
77
|
+
fs.mkdirSync(binDir, { recursive: true })
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Remove existing binary/symlink if it exists
|
|
81
|
+
if (fs.existsSync(targetPath)) {
|
|
82
|
+
fs.unlinkSync(targetPath)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return { binDir, targetPath }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function symlinkBinary(sourcePath, binaryName) {
|
|
89
|
+
const { targetPath } = prepareBinDirectory(binaryName)
|
|
90
|
+
|
|
91
|
+
fs.symlinkSync(sourcePath, targetPath)
|
|
92
|
+
console.log(`agentswarm binary symlinked: ${targetPath} -> ${sourcePath}`)
|
|
93
|
+
|
|
94
|
+
// Verify the file exists after operation
|
|
95
|
+
if (!fs.existsSync(targetPath)) {
|
|
96
|
+
throw new Error(`Failed to symlink binary to ${targetPath}`)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function main() {
|
|
101
|
+
try {
|
|
102
|
+
if (os.platform() === "win32") {
|
|
103
|
+
// On Windows, the .exe is already included in the package and bin field points to it
|
|
104
|
+
// No postinstall setup needed
|
|
105
|
+
console.log("Windows detected: binary setup not needed (using packaged .exe)")
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// On non-Windows platforms, just verify the binary package exists
|
|
110
|
+
// Don't replace the wrapper script - it handles binary execution
|
|
111
|
+
const { binaryPath } = findBinary()
|
|
112
|
+
const target = path.join(__dirname, "bin", ".opencode")
|
|
113
|
+
if (fs.existsSync(target)) fs.unlinkSync(target)
|
|
114
|
+
try {
|
|
115
|
+
fs.linkSync(binaryPath, target)
|
|
116
|
+
} catch {
|
|
117
|
+
fs.copyFileSync(binaryPath, target)
|
|
118
|
+
}
|
|
119
|
+
fs.chmodSync(target, 0o755)
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error("Failed to setup agentswarm binary:", error.message)
|
|
122
|
+
process.exit(1)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
main()
|
|
128
|
+
} catch (error) {
|
|
129
|
+
console.error("Postinstall script error:", error.message)
|
|
130
|
+
process.exit(0)
|
|
131
|
+
}
|