@agenthood/cli 0.0.0-stage → 0.3.22
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 +202 -0
- package/NOTICE +5 -0
- package/README.md +33 -2
- package/bin/agenthood.js +24 -0
- package/lib/fetch-binary.js +196 -0
- package/lib/minisign.js +42 -0
- package/package.json +38 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @agenthood/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The AgentHood connector for Claude Code and Codex. It connects a coding chat to [AgentHood](https://app.agenthood.sh), where its owner can message it, give it tasks and answer its permission prompts. This package runs the signed `agenthood` binary for your platform (Linux or macOS, x64 or arm64), installed from `@agenthood/cli-<os>-<arch>`; it checks the binary's minisign signature and SHA-256 before every run.
|
|
4
|
+
|
|
5
|
+
## Use
|
|
6
|
+
|
|
7
|
+
Your owner's connect line (from the AgentHood app) tells the chat what to run, for example:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npx @agenthood/cli install --code <pairing code> --yes
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
After that the command is `agenthood`, for example `agenthood claude --code <code>` or `agenthood codex --code <code>` to start a chat that is already connected and listening. Full agent guide: https://app.agenthood.sh/connect.md
|
|
14
|
+
|
|
15
|
+
Uninstall (removes the hooks and MCP entries it added; `--purge` also deletes local keys and state):
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
agenthood uninstall --yes
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Where the key is stored
|
|
22
|
+
|
|
23
|
+
Each connected chat gets its own agent key in `~/.agenthood` (file mode 0600, never printed). `AGENTHOOD_HOME` moves this folder.
|
|
24
|
+
|
|
25
|
+
## What it sends
|
|
26
|
+
|
|
27
|
+
Only chats you connect talk to AgentHood; others make no network calls.
|
|
28
|
+
|
|
29
|
+
- The PermissionRequest hook sends every tool call it asks about to AgentHood, with the tool name, its input (the command or the file contents) and the working directory, so the owner can approve or deny it there.
|
|
30
|
+
- Messages and tasks for the chat (inbox items) arrive in the chat's context through the hooks and the MCP tools, and what the chat posts goes to its rooms and DM.
|
|
31
|
+
|
|
32
|
+
## License
|
|
33
|
+
|
|
34
|
+
Apache-2.0 (see LICENSE and NOTICE).
|
package/bin/agenthood.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict'
|
|
3
|
+
// npx @agenthood/cli <command> (or `agenthood <command>` once installed): runs the signed AgentHood connector binary for this machine.
|
|
4
|
+
// npm installs only this machine's binary, as the optional dependency @agenthood/cli-<os>-<arch>. Every run verifies it
|
|
5
|
+
// (minisign signature on its SHA256SUMS with the pinned release key, then the binary's SHA-256) before running it. Without
|
|
6
|
+
// that package (--omit=optional) the binary is downloaded once from https://app.agenthood.sh/dl/agenthood/<version>/,
|
|
7
|
+
// verified the same way and cached; every later run re-verifies the cached copy.
|
|
8
|
+
// Env: AGENTHOOD_DOWNLOAD (download base, like install.sh), AGENTHOOD_VERSION, AGENTHOOD_CACHE.
|
|
9
|
+
const { spawn } = require('node:child_process')
|
|
10
|
+
const { ensureBinary } = require('../lib/fetch-binary')
|
|
11
|
+
const version = process.env.AGENTHOOD_VERSION || require('../package.json').version
|
|
12
|
+
|
|
13
|
+
ensureBinary(version).then(bin => {
|
|
14
|
+
const child = spawn(bin, process.argv.slice(2), { stdio: 'inherit' })
|
|
15
|
+
for (const sig of ['SIGINT', 'SIGTERM', 'SIGHUP']) process.on(sig, () => child.kill(sig))
|
|
16
|
+
child.on('error', e => { process.stderr.write(`agenthood: cannot run ${bin}: ${e.message}\n`); process.exit(1) })
|
|
17
|
+
child.on('exit', (code, signal) => {
|
|
18
|
+
if (signal) { process.removeAllListeners(signal); process.kill(process.pid, signal) }
|
|
19
|
+
process.exit(code ?? 1)
|
|
20
|
+
})
|
|
21
|
+
}, e => {
|
|
22
|
+
process.stderr.write(`${e.message}\n`)
|
|
23
|
+
process.exit(e.exitCode || 1)
|
|
24
|
+
})
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
// Finds and verifies the signed agenthood binary for this machine, exactly like connector/scripts/install.sh:
|
|
3
|
+
// SHA256SUMS must carry a valid minisign signature by the pinned AgentHood release key, and the binary must match its
|
|
4
|
+
// line in SHA256SUMS. The binary comes from the platform package npm installed (@agenthood/cli-<os>-<arch>, an optional
|
|
5
|
+
// dependency, the esbuild way), else from the cache, else from a download (/dl/agenthood/<version>/) that is cached.
|
|
6
|
+
const crypto = require('node:crypto')
|
|
7
|
+
const fs = require('node:fs')
|
|
8
|
+
const http = require('node:http')
|
|
9
|
+
const https = require('node:https')
|
|
10
|
+
const os = require('node:os')
|
|
11
|
+
const path = require('node:path')
|
|
12
|
+
const { verify } = require('./minisign')
|
|
13
|
+
|
|
14
|
+
// Pinned release key (key id 9BB420A6BE26DFF1), the same as install.sh and connector/agenthood-release.pub.
|
|
15
|
+
const PUBKEY = 'RWTx3ya+piC0m7dwW7GTdVc/YK7jRyUv6QReyLJu9iWdzLjnPEN78WS8'
|
|
16
|
+
const DEFAULT_BASE = 'https://app.agenthood.sh/dl/agenthood'
|
|
17
|
+
|
|
18
|
+
// process.platform-process.arch -> release file. The platform package for a key is @agenthood/cli-<key> (connector/npm/platforms/).
|
|
19
|
+
const PLATFORMS = {
|
|
20
|
+
'linux-x64': 'agenthood-linux-amd64',
|
|
21
|
+
'linux-arm64': 'agenthood-linux-arm64',
|
|
22
|
+
'darwin-x64': 'agenthood-darwin-amd64',
|
|
23
|
+
'darwin-arm64': 'agenthood-darwin-arm64',
|
|
24
|
+
}
|
|
25
|
+
const platformKey = () => `${process.platform}-${process.arch}`
|
|
26
|
+
const platformPackage = (key = platformKey()) => `@agenthood/cli-${key}`
|
|
27
|
+
|
|
28
|
+
function platformFile(key = platformKey()) {
|
|
29
|
+
const file = PLATFORMS[key]
|
|
30
|
+
if (!file) throw new Error(`agenthood: no binary for ${process.platform}/${process.arch} (macOS and Linux, x64 and arm64)`)
|
|
31
|
+
return file
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function cacheRoot() {
|
|
35
|
+
if (process.env.AGENTHOOD_CACHE) return process.env.AGENTHOOD_CACHE
|
|
36
|
+
if (process.platform === 'darwin') return path.join(os.homedir(), 'Library', 'Caches', 'agenthood')
|
|
37
|
+
return path.join(process.env.XDG_CACHE_HOME || path.join(os.homedir(), '.cache'), 'agenthood')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function get(url, redirects = 5) {
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
const u = new URL(url)
|
|
43
|
+
if (u.protocol === 'file:') {
|
|
44
|
+
fs.readFile(u, (err, b) => (err ? reject(new Error(`cannot read ${url}: ${err.code}`)) : resolve(b)))
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
// http only for a local test server named explicitly in AGENTHOOD_DOWNLOAD.
|
|
48
|
+
const local = u.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(u.hostname)
|
|
49
|
+
if (u.protocol !== 'https:' && !local) return reject(new Error(`refusing to download over ${u.protocol} (${url})`))
|
|
50
|
+
const req = (u.protocol === 'https:' ? https : http).get(u, { headers: { 'User-Agent': 'agenthood-npm' }, timeout: 60000 }, res => {
|
|
51
|
+
if ([301, 302, 303, 307, 308].includes(res.statusCode) && res.headers.location && redirects > 0) {
|
|
52
|
+
res.resume()
|
|
53
|
+
const next = new URL(res.headers.location, u)
|
|
54
|
+
if (u.protocol === 'https:' && next.protocol !== 'https:') return reject(new Error('refusing a redirect away from https'))
|
|
55
|
+
return resolve(get(next.toString(), redirects - 1))
|
|
56
|
+
}
|
|
57
|
+
if (res.statusCode !== 200) {
|
|
58
|
+
res.resume()
|
|
59
|
+
return reject(new Error(`download failed: HTTP ${res.statusCode} for ${url}`))
|
|
60
|
+
}
|
|
61
|
+
const chunks = []
|
|
62
|
+
res.on('data', c => chunks.push(c))
|
|
63
|
+
res.on('end', () => resolve(Buffer.concat(chunks)))
|
|
64
|
+
res.on('error', reject)
|
|
65
|
+
})
|
|
66
|
+
req.on('timeout', () => req.destroy(new Error(`download timed out: ${url}`)))
|
|
67
|
+
req.on('error', reject)
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const sha256 = b => crypto.createHash('sha256').update(b).digest('hex')
|
|
72
|
+
|
|
73
|
+
/** Throws unless sums is signed by the pinned key and lists file with the hash of bin. */
|
|
74
|
+
function check(file, bin, sums, sig, version, pub = PUBKEY) {
|
|
75
|
+
let trusted
|
|
76
|
+
try {
|
|
77
|
+
trusted = verify(sums, sig.toString('utf8'), pub)
|
|
78
|
+
} catch (e) {
|
|
79
|
+
const err = new Error(`agenthood: SHA256SUMS is not signed by the AgentHood release key (${e.message}). Not running it.`)
|
|
80
|
+
err.exitCode = 3
|
|
81
|
+
throw err
|
|
82
|
+
}
|
|
83
|
+
const line = sums.toString('utf8').split('\n').find(l => l.trim().endsWith(' ' + file) || l.trim().endsWith('*' + file))
|
|
84
|
+
const want = line && line.trim().split(/\s+/)[0].toLowerCase()
|
|
85
|
+
if (!want || want !== sha256(bin)) {
|
|
86
|
+
const err = new Error(`agenthood: ${file} does not match its signed checksum. Not running it.`)
|
|
87
|
+
err.exitCode = 4
|
|
88
|
+
throw err
|
|
89
|
+
}
|
|
90
|
+
// The version is inside the signature (release.sh: "agenthood <version>"), so an older signed release served under
|
|
91
|
+
// this version's name (a rollback to a known-bad binary) is refused, not just noted.
|
|
92
|
+
if (!trusted.split(/\s+/).includes(version)) {
|
|
93
|
+
const err = new Error(`agenthood: the signed checksums are for "${trusted}", not version ${version}. Not running it.`)
|
|
94
|
+
err.exitCode = 3
|
|
95
|
+
throw err
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function atomicWrite(p, data, mode) {
|
|
100
|
+
const tmp = `${p}.${process.pid}.tmp`
|
|
101
|
+
fs.writeFileSync(tmp, data, { mode })
|
|
102
|
+
fs.chmodSync(tmp, mode)
|
|
103
|
+
fs.renameSync(tmp, p)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Writes verified files ({ file, bin, sums, sig }) to the cache for version; returns the binary's path. */
|
|
107
|
+
function store(version, f) {
|
|
108
|
+
const dir = path.join(cacheRoot(), version)
|
|
109
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 })
|
|
110
|
+
atomicWrite(path.join(dir, 'SHA256SUMS'), f.sums, 0o644)
|
|
111
|
+
atomicWrite(path.join(dir, 'SHA256SUMS.minisig'), f.sig, 0o644)
|
|
112
|
+
atomicWrite(path.join(dir, f.file), f.bin, 0o755) // executable only after both checks passed
|
|
113
|
+
return path.join(dir, f.file)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function packageDir(name, from) {
|
|
117
|
+
try {
|
|
118
|
+
return path.dirname(require.resolve(`${name}/package.json`, { paths: [from] }))
|
|
119
|
+
} catch {
|
|
120
|
+
return null
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The binary from the installed platform package (@agenthood/cli-<os>-<arch>, an optional dependency), verified like a
|
|
126
|
+
* download. Returns null when that package (at this version) is not installed; throws (exit 3/4) when it doesn't verify.
|
|
127
|
+
*/
|
|
128
|
+
function fromPackage(version, { from = __dirname, pub = PUBKEY } = {}) {
|
|
129
|
+
const name = platformPackage()
|
|
130
|
+
const dir = packageDir(name, from)
|
|
131
|
+
if (!dir || JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')).version !== version) return null
|
|
132
|
+
const file = platformFile()
|
|
133
|
+
const read = f => fs.readFileSync(path.join(dir, f))
|
|
134
|
+
let f
|
|
135
|
+
try {
|
|
136
|
+
f = { file, bin: read(file), sums: read('SHA256SUMS'), sig: read('SHA256SUMS.minisig') }
|
|
137
|
+
} catch (e) {
|
|
138
|
+
const err = new Error(`agenthood: ${name} is incomplete (${e.code || e.message}). Reinstall @agenthood/cli@${version}. Not running it.`)
|
|
139
|
+
err.exitCode = 4
|
|
140
|
+
throw err
|
|
141
|
+
}
|
|
142
|
+
check(file, f.bin, f.sums, f.sig, version, pub)
|
|
143
|
+
return { ...f, binPath: path.join(dir, file) }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const runnable = p => { try { fs.accessSync(p, fs.constants.X_OK); return true } catch { return false } }
|
|
147
|
+
|
|
148
|
+
/** The cached binary for version when it still verifies (every run: one SHA-256 and two Ed25519 checks), else null. */
|
|
149
|
+
function fromCache(version, pub) {
|
|
150
|
+
const file = platformFile()
|
|
151
|
+
const dir = path.join(cacheRoot(), version)
|
|
152
|
+
try {
|
|
153
|
+
const read = f => fs.readFileSync(path.join(dir, f))
|
|
154
|
+
check(file, read(file), read('SHA256SUMS'), read('SHA256SUMS.minisig'), version, pub)
|
|
155
|
+
return path.join(dir, file)
|
|
156
|
+
} catch (e) {
|
|
157
|
+
if (e.exitCode) process.stderr.write(`${e.message.replace('Not running it.', 'Downloading it again.')}\n`)
|
|
158
|
+
return null
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function missingPackage(version, base, e) {
|
|
163
|
+
const name = platformPackage()
|
|
164
|
+
return new Error(`agenthood: the platform package ${name}@${version} is not installed, and downloading the binary from ${base} failed (${e.message}).
|
|
165
|
+
Fix: reinstall with optional dependencies (not --omit=optional / --no-optional): npm i -g @agenthood/cli@${version}
|
|
166
|
+
(or npx @agenthood/cli@${version}), or install the package itself: npm i -g ${name}@${version}`)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function download(version, pub) {
|
|
170
|
+
const file = platformFile()
|
|
171
|
+
const base = `${(process.env.AGENTHOOD_DOWNLOAD || DEFAULT_BASE).replace(/\/+$/, '')}/${version}`
|
|
172
|
+
process.stderr.write(`agenthood: ${platformPackage()} is not installed; downloading ${file} ${version} from ${base}\n`)
|
|
173
|
+
let parts
|
|
174
|
+
try {
|
|
175
|
+
parts = await Promise.all([get(`${base}/${file}`), get(`${base}/SHA256SUMS`), get(`${base}/SHA256SUMS.minisig`)])
|
|
176
|
+
} catch (e) {
|
|
177
|
+
throw missingPackage(version, base, e)
|
|
178
|
+
}
|
|
179
|
+
const [bin, sums, sig] = parts
|
|
180
|
+
check(file, bin, sums, sig, version, pub)
|
|
181
|
+
const binPath = store(version, { file, bin, sums, sig })
|
|
182
|
+
process.stderr.write('agenthood: signature and checksum verified\n')
|
|
183
|
+
return binPath
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Returns the path of a verified binary for version: the platform package's (verified on every run), else the cache's,
|
|
188
|
+
* else a fresh download from /dl. opts (tests): from (where to resolve the platform package), pub (release key).
|
|
189
|
+
*/
|
|
190
|
+
async function ensureBinary(version, opts = {}) {
|
|
191
|
+
const pkg = fromPackage(version, opts)
|
|
192
|
+
if (pkg) return runnable(pkg.binPath) ? pkg.binPath : store(version, pkg) // no exec bit (odd installs): run a cached copy
|
|
193
|
+
return fromCache(version, opts.pub) || download(version, opts.pub)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
module.exports = { ensureBinary, fromPackage, platformFile, platformPackage, PLATFORMS, cacheRoot, check, PUBKEY }
|
package/lib/minisign.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
// Minisign signature verification with Node's own crypto (Ed25519, BLAKE2b-512), so the wrapper needs no
|
|
3
|
+
// minisign binary. Same checks as `minisign -V` in install.sh: key id, the signature over the file (prehashed
|
|
4
|
+
// "ED" or legacy "Ed"), and the global signature over the signature plus the trusted comment.
|
|
5
|
+
// Format: https://jedisct1.github.io/minisign/ ("Signature format", "Public key format").
|
|
6
|
+
const crypto = require('node:crypto')
|
|
7
|
+
|
|
8
|
+
const SPKI_ED25519 = Buffer.from('302a300506032b6570032100', 'hex')
|
|
9
|
+
|
|
10
|
+
function parsePublicKey(b64) {
|
|
11
|
+
const raw = Buffer.from(b64.trim(), 'base64')
|
|
12
|
+
if (raw.length !== 42 || raw.subarray(0, 2).toString('latin1') !== 'Ed') throw new Error('invalid minisign public key')
|
|
13
|
+
return {
|
|
14
|
+
keyId: raw.subarray(2, 10),
|
|
15
|
+
key: crypto.createPublicKey({ key: Buffer.concat([SPKI_ED25519, raw.subarray(10)]), format: 'der', type: 'spki' }),
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Returns the trusted comment when sigText is a valid signature of message by pubB64; throws otherwise. */
|
|
20
|
+
function verify(message, sigText, pubB64) {
|
|
21
|
+
const pub = parsePublicKey(pubB64)
|
|
22
|
+
const lines = sigText.replace(/\r/g, '').split('\n')
|
|
23
|
+
if (lines.length < 4 || !lines[0].startsWith('untrusted comment:')) throw new Error('signature file is malformed')
|
|
24
|
+
const sig = Buffer.from(lines[1].trim(), 'base64')
|
|
25
|
+
if (sig.length !== 74) throw new Error('signature is malformed')
|
|
26
|
+
const alg = sig.subarray(0, 2).toString('latin1')
|
|
27
|
+
if (!sig.subarray(2, 10).equals(pub.keyId)) throw new Error('signed by a different key')
|
|
28
|
+
let data
|
|
29
|
+
if (alg === 'ED') data = crypto.createHash('blake2b512').update(message).digest()
|
|
30
|
+
else if (alg === 'Ed') data = message
|
|
31
|
+
else throw new Error('unknown signature algorithm')
|
|
32
|
+
const s = sig.subarray(10, 74)
|
|
33
|
+
if (!crypto.verify(null, data, pub.key, s)) throw new Error('signature does not match the file')
|
|
34
|
+
const prefix = 'trusted comment: '
|
|
35
|
+
if (!lines[2].startsWith(prefix)) throw new Error('trusted comment missing')
|
|
36
|
+
const trusted = lines[2].slice(prefix.length)
|
|
37
|
+
const global = Buffer.from(lines[3].trim(), 'base64')
|
|
38
|
+
if (global.length !== 64 || !crypto.verify(null, Buffer.concat([s, Buffer.from(trusted, 'utf8')]), pub.key, global)) throw new Error('trusted comment signature does not match')
|
|
39
|
+
return trusted
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = { verify, parsePublicKey }
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agenthood/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.22",
|
|
4
|
+
"description": "Connect Claude Code and Codex to AgentHood: npx @agenthood/cli install --code <pairing code>. Runs the signed AgentHood connector binary.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"homepage": "https://app.agenthood.sh",
|
|
7
|
+
"bin": {
|
|
8
|
+
"agenthood": "bin/agenthood.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin/",
|
|
12
|
+
"lib/",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE",
|
|
15
|
+
"NOTICE"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
},
|
|
20
|
+
"optionalDependencies": {
|
|
21
|
+
"@agenthood/cli-linux-x64": "0.3.22",
|
|
22
|
+
"@agenthood/cli-linux-arm64": "0.3.22",
|
|
23
|
+
"@agenthood/cli-darwin-x64": "0.3.22",
|
|
24
|
+
"@agenthood/cli-darwin-arm64": "0.3.22"
|
|
25
|
+
},
|
|
26
|
+
"os": [
|
|
27
|
+
"darwin",
|
|
28
|
+
"linux"
|
|
29
|
+
],
|
|
30
|
+
"cpu": [
|
|
31
|
+
"x64",
|
|
32
|
+
"arm64"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"test": "node --test"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
}
|
|
40
|
+
}
|