@verbodhpteltd/devops-agent 0.1.0 → 0.1.2
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/README.md +7 -3
- package/bin/devops-agent.js +3 -2
- package/lib/platform.js +9 -0
- package/package.json +1 -1
- package/scripts/install.js +43 -12
package/README.md
CHANGED
|
@@ -47,9 +47,13 @@ your Linux uses musl instead of glibc (Alpine).
|
|
|
47
47
|
| This package's version | the installer's own version, which is what `npm i` pins |
|
|
48
48
|
| The agent's version, from `devops-agent version` | the build the website's release pointer names on the day you install |
|
|
49
49
|
|
|
50
|
-
So pinning a version of this package does not pin a version of the agent.
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
So pinning a version of this package does not pin a version of the agent.
|
|
51
|
+
|
|
52
|
+
Once the agent is on your machine, the command runs it and does not look for a newer one. Measured
|
|
53
|
+
with `npx`: the first run downloads the agent, a second run just runs it, and a run after the agent
|
|
54
|
+
is gone from the app folder downloads it again. To move to a newer build, run `/update` inside the
|
|
55
|
+
chat, or `rm -rf ~/.local/share/devops-agent/versions` and run the command again. `npm i -g` of a
|
|
56
|
+
newer package version refreshes this installer, not the agent.
|
|
53
57
|
|
|
54
58
|
## What this package cannot do
|
|
55
59
|
|
package/bin/devops-agent.js
CHANGED
|
@@ -20,8 +20,9 @@ const { spawn } = require('node:child_process');
|
|
|
20
20
|
const P = require('../lib/platform.js');
|
|
21
21
|
const { ensure, Refused } = require('../scripts/install.js');
|
|
22
22
|
|
|
23
|
-
// The shell's own convention, so a caller can tell a kill from an exit code.
|
|
24
|
-
|
|
23
|
+
// The shell's own convention, so a caller can tell a kill from an exit code. Node's own table, so
|
|
24
|
+
// SIGABRT, SIGSEGV and SIGPIPE get their real numbers too instead of falling to a bare 128.
|
|
25
|
+
const NUMBERS = require('node:os').constants.signals;
|
|
25
26
|
|
|
26
27
|
async function agentFile() {
|
|
27
28
|
const found = P.newestInstalled();
|
package/lib/platform.js
CHANGED
|
@@ -86,6 +86,15 @@ function chooseTriple(env = process.env, platform = process.platform, arch = pro
|
|
|
86
86
|
function releasesUrl(env = process.env) {
|
|
87
87
|
const named = (env.DEVOPS_AGENT_RELEASES_URL || '').trim();
|
|
88
88
|
if (!named) return { url: RELEASES };
|
|
89
|
+
// Two things must be set, not one. A CI variable, a project .npmrc or another package's script
|
|
90
|
+
// can set one variable by accident or on purpose; both together are a deliberate test setup.
|
|
91
|
+
if ((env.DEVOPS_AGENT_TEST || '').trim() !== '1') {
|
|
92
|
+
return {
|
|
93
|
+
error:
|
|
94
|
+
`this package downloads only from ${SITE}. DEVOPS_AGENT_RELEASES_URL is for our own tests ` +
|
|
95
|
+
`and needs DEVOPS_AGENT_TEST=1 beside it. ${NOTHING}`,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
89
98
|
let parsed;
|
|
90
99
|
try {
|
|
91
100
|
parsed = new URL(named);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verbodhpteltd/devops-agent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "The AgenticDevOps DevOps agent in your terminal: asks your AWS estate questions, runs checks, reports findings, and makes an approved change behind an approval.",
|
|
5
5
|
"bin": { "devops-agent": "bin/devops-agent.js" },
|
|
6
6
|
"files": ["bin", "lib", "scripts", "README.md", "LICENSE.md"],
|
package/scripts/install.js
CHANGED
|
@@ -32,7 +32,11 @@ const { URL } = require('node:url');
|
|
|
32
32
|
const P = require('../lib/platform.js');
|
|
33
33
|
|
|
34
34
|
const TIMEOUT_MS = 120000;
|
|
35
|
-
|
|
35
|
+
// A published agent is about 55 MB; this refuses a surprise. The tests lower it rather than
|
|
36
|
+
// download 200 MB to see the cap fire; a number that is not a number leaves the default standing.
|
|
37
|
+
const MAX_BYTES = Number(process.env.DEVOPS_AGENT_MAX_BYTES) > 0
|
|
38
|
+
? Number(process.env.DEVOPS_AGENT_MAX_BYTES)
|
|
39
|
+
: 200 * 1024 * 1024;
|
|
36
40
|
|
|
37
41
|
// A refusal a person reads. `ensure` throws it; the command and the direct run both print it and
|
|
38
42
|
// stop, so one sentence covers both doors.
|
|
@@ -122,11 +126,17 @@ function sha256OfFile(file) {
|
|
|
122
126
|
return crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
|
123
127
|
}
|
|
124
128
|
|
|
125
|
-
/**
|
|
126
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Keep the one just installed and the one before it, newest by version number, not by file time.
|
|
131
|
+
* Only a folder that actually holds the agent counts as a version: an empty one left behind by a
|
|
132
|
+
* refusal must not take the place of a build a person can roll back to.
|
|
133
|
+
*/
|
|
134
|
+
function prune(versionsDir, keep, placed) {
|
|
127
135
|
let names;
|
|
128
136
|
try {
|
|
129
|
-
names = fs
|
|
137
|
+
names = fs
|
|
138
|
+
.readdirSync(versionsDir)
|
|
139
|
+
.filter((n) => P.VERSION.test(n) && fs.existsSync(path.join(versionsDir, n, placed)));
|
|
130
140
|
} catch {
|
|
131
141
|
return;
|
|
132
142
|
}
|
|
@@ -172,10 +182,10 @@ async function ensure({ quiet = false } = {}) {
|
|
|
172
182
|
|
|
173
183
|
const dir = path.join(app, 'versions', version);
|
|
174
184
|
const target = path.join(dir, P.placedName(triple));
|
|
175
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
176
|
-
fs.mkdirSync(path.join(app, 'database'), { recursive: true });
|
|
177
|
-
fs.mkdirSync(path.join(app, 'run'), { recursive: true });
|
|
178
185
|
|
|
186
|
+
// Nothing is created on disk until the checksum is in hand. An empty version folder left by a
|
|
187
|
+
// refusal used to count as an installed version, and the next good install then pruned both real
|
|
188
|
+
// builds away, so a bad release could not be rolled back without a download.
|
|
179
189
|
let want;
|
|
180
190
|
try {
|
|
181
191
|
want = (await fetchText(`${base}/${version}/${triple}/${P.downloadName(triple)}.sha256`)).toLowerCase();
|
|
@@ -190,22 +200,43 @@ async function ensure({ quiet = false } = {}) {
|
|
|
190
200
|
// .exe (install.ps1:54-58), and re-installing while the agent is open must still work.
|
|
191
201
|
if (fs.existsSync(target) && sha256OfFile(target) === want) {
|
|
192
202
|
say(`devops-agent ${version} is already installed: ${target}`);
|
|
193
|
-
prune(path.join(app, 'versions'), version);
|
|
203
|
+
prune(path.join(app, 'versions'), version, P.placedName(triple));
|
|
194
204
|
return target;
|
|
195
205
|
}
|
|
196
206
|
|
|
207
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
208
|
+
fs.mkdirSync(path.join(app, 'database'), { recursive: true });
|
|
209
|
+
fs.mkdirSync(path.join(app, 'run'), { recursive: true });
|
|
210
|
+
|
|
197
211
|
// The temporary file lives beside the target, so the move below is a rename on one filesystem.
|
|
198
212
|
const tmp = path.join(dir, `.download-${process.pid}-${Date.now()}`);
|
|
213
|
+
// A refusal, or a Ctrl-C mid-download, must leave nothing behind: not the part-file, and not an
|
|
214
|
+
// empty version folder, which the pruner would otherwise count as an installed build.
|
|
215
|
+
const sweep = () => {
|
|
216
|
+
fs.rmSync(tmp, { force: true });
|
|
217
|
+
try {
|
|
218
|
+
if (fs.readdirSync(dir).length === 0) fs.rmdirSync(dir);
|
|
219
|
+
} catch {
|
|
220
|
+
// another install is working in the same folder, or it is already gone
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
process.on('exit', sweep);
|
|
224
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
|
225
|
+
process.on(signal, () => {
|
|
226
|
+
sweep();
|
|
227
|
+
process.exit(1);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
199
230
|
say(`Installing devops-agent ${version} for ${triple} from ${new URL(base).host}...`);
|
|
200
231
|
let got;
|
|
201
232
|
try {
|
|
202
233
|
got = await fetchBinary(`${base}/${version}/${triple}/${P.downloadName(triple)}`, tmp);
|
|
203
234
|
} catch (e) {
|
|
204
|
-
|
|
235
|
+
sweep();
|
|
205
236
|
fail(`could not download ${version} for ${triple} (${e.message}). ${P.NOTHING}`);
|
|
206
237
|
}
|
|
207
238
|
if (got.digest !== want) {
|
|
208
|
-
|
|
239
|
+
sweep();
|
|
209
240
|
fail(
|
|
210
241
|
`checksum mismatch for ${version}/${triple}: the download is not what was published. ${P.NOTHING}`,
|
|
211
242
|
);
|
|
@@ -217,11 +248,11 @@ async function ensure({ quiet = false } = {}) {
|
|
|
217
248
|
// overwritten in place (install.sh:99-100).
|
|
218
249
|
fs.renameSync(tmp, target);
|
|
219
250
|
} catch (e) {
|
|
220
|
-
|
|
251
|
+
sweep();
|
|
221
252
|
fail(`could not put the agent at ${target} (${e.message}). Close devops-agent and try again.`);
|
|
222
253
|
}
|
|
223
254
|
|
|
224
|
-
prune(path.join(app, 'versions'), version);
|
|
255
|
+
prune(path.join(app, 'versions'), version, P.placedName(triple));
|
|
225
256
|
say(`devops-agent ${version} installed: ${target}`);
|
|
226
257
|
say('Run `devops-agent login` to sign in, then `devops-agent` for the chat.');
|
|
227
258
|
return target;
|