@yasaswy.nagavolu/agents 0.25.0 → 0.26.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.
- package/README.md +9 -0
- package/bin/cli.js +47 -0
- package/content/manifest.json +21 -0
- package/content/mods/handoff/.claude-plugin/plugin.json +1 -1
- package/content/mods/handoff/README.md +1 -1
- package/content/mods/handoff/hooks/register.js +2 -0
- package/content/mods/handoff/tests/register.test.mjs +41 -1
- package/content/skills/ci-runner/SKILL.md +35 -0
- package/lib/claudeVersion.js +82 -0
- package/lib/doctor.js +19 -2
- package/lib/runner/args.js +154 -0
- package/lib/runner/detect.js +84 -0
- package/lib/runner/exec.js +72 -0
- package/lib/runner/gitlab.js +126 -0
- package/lib/runner/index.js +290 -0
- package/lib/runner/profiles/linuxDocker.js +353 -0
- package/lib/runner/profiles/macosShell.js +416 -0
- package/lib/runner/project.js +172 -0
- package/lib/runner/result.js +12 -0
- package/lib/runner/secrets.js +68 -0
- package/lib/semver.js +12 -1
- package/package.json +1 -1
- package/templates/ci/README.md +25 -0
- package/templates/ci/base.yml +34 -0
- package/templates/ci/docker.yml +7 -0
- package/templates/ci/image/Dockerfile +33 -0
- package/templates/ci/macos.yml +16 -0
- package/templates/ci/node.yml +34 -0
- package/templates/ci/python.yml +34 -0
package/README.md
CHANGED
|
@@ -73,6 +73,15 @@ agents-cli install
|
|
|
73
73
|
secrets --list` — see [Secrets](#secrets) below.
|
|
74
74
|
- `agents-cli update --yes` / `agents-cli update --bundle <key> --yes` — see
|
|
75
75
|
[Updating](#updating) below.
|
|
76
|
+
- `agents-cli runner install --group-id <id> | --project-id <id>` — install a
|
|
77
|
+
ready GitLab CI runner on this machine (`linux-docker`, or `macos-shell` on
|
|
78
|
+
a Mac). `runner status` / `runner doctor` / `runner uninstall` check,
|
|
79
|
+
diagnose or remove it; `runner attach|detach --project-id <id>` enable the
|
|
80
|
+
saved runners on a project (`--no-cloud` also turns off cloud runners);
|
|
81
|
+
`runner init-project [--write] [--attach --project-id <id>]` writes a
|
|
82
|
+
`.gitlab-ci.yml`. Needs `GITLAB_RUNNER_PAT` (set it with `agents-cli
|
|
83
|
+
secrets`). Add `--json` for a machine-readable result that never contains a
|
|
84
|
+
token. Exit codes: 0 ok, 1 a step failed, 2 usage error.
|
|
76
85
|
- `agents-cli --help` — show usage
|
|
77
86
|
|
|
78
87
|
### The interactive menu
|
package/bin/cli.js
CHANGED
|
@@ -32,6 +32,7 @@ const { collectBundleSecrets, collectComponentSecrets, isResolved, promptForMiss
|
|
|
32
32
|
const { envPath, readSecrets, removeSecret } = require('../lib/secretsStore');
|
|
33
33
|
const { runSelfProfilePostInstall } = require('../lib/selfProfile');
|
|
34
34
|
const { checkHealth, DoctorError } = require('../lib/doctor');
|
|
35
|
+
const { checkModVersions } = require('../lib/claudeVersion');
|
|
35
36
|
|
|
36
37
|
const PACKAGE_ROOT = path.join(__dirname, '..');
|
|
37
38
|
// One styler for the whole process: colors on only for a real TTY stdout
|
|
@@ -63,6 +64,7 @@ Usage:
|
|
|
63
64
|
agents-cli secrets --bundle <key> Prompt for missing secrets for one bundle
|
|
64
65
|
agents-cli secrets --list Show which secrets are set/missing (names only — never values)
|
|
65
66
|
agents-cli doctor Report orphaned/missing/drifted files under the install target
|
|
67
|
+
agents-cli runner <sub> [flags] Install and manage a self-hosted GitLab CI runner (see "Flags for runner")
|
|
66
68
|
agents-cli --help Show this help
|
|
67
69
|
|
|
68
70
|
Flags for install:
|
|
@@ -133,6 +135,19 @@ Python is installed to wire it. Duplicate hook registrations that predate this C
|
|
|
133
135
|
(or otherwise accumulate outside its per-block dedupe) are collapsed automatically on
|
|
134
136
|
every install/update — see "doctor" below to inspect settings.json wiring separately.
|
|
135
137
|
|
|
138
|
+
Flags for runner:
|
|
139
|
+
runner install --group-id <id> | --project-id <id> Install a ready runner on this machine (idempotent)
|
|
140
|
+
runner status | doctor | uninstall Check, diagnose (docker, PAT scopes, online) or remove it
|
|
141
|
+
runner attach | detach --project-id <id> Enable/disable the saved runners on a project (--no-cloud on
|
|
142
|
+
attach also turns off cloud runners for it)
|
|
143
|
+
runner init-project [--profile node|python|docker|macos|blank] [--write] [--attach --project-id <id>]
|
|
144
|
+
Write a .gitlab-ci.yml that uses the shared templates (dry run unless --write)
|
|
145
|
+
--profile <auto|linux|macos> Install profile (default auto); --name, --tags, --concurrent, --url, --image,
|
|
146
|
+
--cache-volume, --protected, --run-untagged/--no-run-untagged, --dry-run
|
|
147
|
+
--json Print a machine-readable result (never contains a token or PAT)
|
|
148
|
+
Needs a GitLab PAT in GITLAB_RUNNER_PAT (or GITLAB_TOKEN): set it with "agents-cli secrets".
|
|
149
|
+
Exit codes: 0 ok, 1 a step failed, 2 usage error.
|
|
150
|
+
|
|
136
151
|
Flags for doctor:
|
|
137
152
|
--target-dir <path> Install target base, default ~/.claude (use for testing)
|
|
138
153
|
--json Print a machine-readable report instead of prose
|
|
@@ -143,6 +158,8 @@ by a renamed/retired item), missing (a ledger-tracked file no longer on disk), a
|
|
|
143
158
|
drifted (a ledger-tracked file whose on-disk hash no longer matches what was installed).
|
|
144
159
|
It never scans anywhere the manifest doesn't declare a file/directory item into, so the
|
|
145
160
|
rest of <target> (Claude Code's own state, caches, logs, your own files) is left alone.
|
|
161
|
+
It also compares the local "claude --version" with each installed mod's minClaudeCodeVersion:
|
|
162
|
+
a too-old Claude Code is a finding (exit 1); a missing claude binary only warns.
|
|
146
163
|
Exit code is 0 when clean, 1 otherwise — safe to use as a CI/scripted gate. It never
|
|
147
164
|
deletes or modifies anything; deciding what to do about a finding is a separate step.
|
|
148
165
|
`);
|
|
@@ -378,12 +395,28 @@ function printFinalSummary({ installed, skipped, targetBase }) {
|
|
|
378
395
|
console.log(` ${mark('skip')} ${label}`);
|
|
379
396
|
}
|
|
380
397
|
printPythonSyncIssues(installed.map(({ result }) => result));
|
|
398
|
+
printModVersionWarnings(installed.map(({ bundle }) => bundle.key), targetBase);
|
|
381
399
|
console.log(
|
|
382
400
|
`\nInstalled to ${ansi.bold(targetBase)}. Next: ${ansi.dim('agents-cli secrets')} to fill in any skipped ` +
|
|
383
401
|
`secrets, ${ansi.dim('agents-cli update --yes')} to refresh later.`
|
|
384
402
|
);
|
|
385
403
|
}
|
|
386
404
|
|
|
405
|
+
/** Print one warning line per just-installed mod whose minClaudeCodeVersion the local Claude Code does not meet; never fails the run. */
|
|
406
|
+
function printModVersionWarnings(bundleKeys, targetBase) {
|
|
407
|
+
try {
|
|
408
|
+
const { manifest } = loadManifest(PACKAGE_ROOT);
|
|
409
|
+
const items = [...new Set(bundleKeys)].flatMap((key) => {
|
|
410
|
+
const bundle = findBundle(manifest, key);
|
|
411
|
+
return bundle ? bundle.items.filter((item) => item.kind === 'mod') : [];
|
|
412
|
+
});
|
|
413
|
+
const checks = checkModVersions({ items, targetBase: targetBase || defaultTargetBase() });
|
|
414
|
+
for (const c of checks) {
|
|
415
|
+
if (c.status === 'too-old') console.log(` ${mark('skip')} ${c.line}`);
|
|
416
|
+
}
|
|
417
|
+
} catch { /* advisory only — never fail an install or update */ }
|
|
418
|
+
}
|
|
419
|
+
|
|
387
420
|
/**
|
|
388
421
|
* A python item's missing-uv/failed status is easy to miss among per-bundle
|
|
389
422
|
* component/hook bullets — surface it again as the last thing printed before
|
|
@@ -588,6 +621,7 @@ async function runInstall(argv) {
|
|
|
588
621
|
});
|
|
589
622
|
runSelfProfileStepsIfNeeded({ profile: args.profile, targetDir: args.targetDir });
|
|
590
623
|
printPythonSyncIssues([result]);
|
|
624
|
+
printModVersionWarnings([args.bundle], result.targetBase);
|
|
591
625
|
return 0;
|
|
592
626
|
} catch (err) {
|
|
593
627
|
if (err instanceof InstallError || err instanceof ManifestError || err instanceof LedgerError || err instanceof WiringError) {
|
|
@@ -1001,6 +1035,7 @@ async function runUpdate(argv) {
|
|
|
1001
1035
|
}
|
|
1002
1036
|
|
|
1003
1037
|
printPythonSyncIssues(result.bundles);
|
|
1038
|
+
printModVersionWarnings(result.bundles.map((b) => b.bundle), result.targetBase);
|
|
1004
1039
|
|
|
1005
1040
|
if (result.exitCode !== 0) {
|
|
1006
1041
|
console.error(
|
|
@@ -1060,8 +1095,15 @@ function runDoctor(argv) {
|
|
|
1060
1095
|
return result.healthy ? 0 : 1;
|
|
1061
1096
|
}
|
|
1062
1097
|
|
|
1098
|
+
const printModVersions = () => {
|
|
1099
|
+
if (result.modVersions.length === 0) return;
|
|
1100
|
+
console.log('\nClaude Code version vs. installed mods:');
|
|
1101
|
+
for (const c of result.modVersions) console.log(` ${c.line}`);
|
|
1102
|
+
};
|
|
1103
|
+
|
|
1063
1104
|
if (result.healthy) {
|
|
1064
1105
|
console.log(`${result.targetBase}: healthy — no orphans, no missing files, no drift.`);
|
|
1106
|
+
printModVersions();
|
|
1065
1107
|
return 0;
|
|
1066
1108
|
}
|
|
1067
1109
|
|
|
@@ -1078,6 +1120,7 @@ function runDoctor(argv) {
|
|
|
1078
1120
|
console.log(`\nDrifted (on-disk hash no longer matches the ledger, ${result.drifted.length}):`);
|
|
1079
1121
|
for (const d of result.drifted) console.log(` ${d.relTarget} (bundle: ${d.bundle})`);
|
|
1080
1122
|
}
|
|
1123
|
+
printModVersions();
|
|
1081
1124
|
return 1;
|
|
1082
1125
|
} catch (err) {
|
|
1083
1126
|
if (err instanceof DoctorError || err instanceof ManifestError || err instanceof LedgerError) {
|
|
@@ -1121,6 +1164,10 @@ async function main(argv) {
|
|
|
1121
1164
|
return runDoctor(rest);
|
|
1122
1165
|
}
|
|
1123
1166
|
|
|
1167
|
+
if (command === 'runner') {
|
|
1168
|
+
return require('../lib/runner').runRunnerCommand(rest);
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1124
1171
|
console.error(`Unknown command: ${command}`);
|
|
1125
1172
|
printHelp();
|
|
1126
1173
|
return 1;
|
package/content/manifest.json
CHANGED
|
@@ -1356,6 +1356,27 @@
|
|
|
1356
1356
|
],
|
|
1357
1357
|
"deps": [],
|
|
1358
1358
|
"secrets": []
|
|
1359
|
+
},
|
|
1360
|
+
{
|
|
1361
|
+
"key": "runner",
|
|
1362
|
+
"title": "CI runner",
|
|
1363
|
+
"summary": "Thin ci-runner skill: set up GitLab CI on a self-hosted runner (linux-docker or macos-shell) with `npx @yasaswy.nagavolu/agents runner install`, write a .gitlab-ci.yml with `runner init-project`, and attach projects with `runner attach` so pipelines avoid cloud minutes",
|
|
1364
|
+
"profile": "public",
|
|
1365
|
+
"advanced": false,
|
|
1366
|
+
"items": [
|
|
1367
|
+
{
|
|
1368
|
+
"path": "skills/ci-runner",
|
|
1369
|
+
"kind": "skill"
|
|
1370
|
+
}
|
|
1371
|
+
],
|
|
1372
|
+
"deps": [],
|
|
1373
|
+
"secrets": [
|
|
1374
|
+
{
|
|
1375
|
+
"name": "GITLAB_RUNNER_PAT",
|
|
1376
|
+
"prompt": "GitLab personal access token for installing runners (api scope, or create_runner + manage_runner) - optional, falls back to GITLAB_TOKEN",
|
|
1377
|
+
"validationHint": "starts with glpat-; optional, skip if you do not install runners"
|
|
1378
|
+
}
|
|
1379
|
+
]
|
|
1359
1380
|
}
|
|
1360
1381
|
],
|
|
1361
1382
|
"internal": [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "handoff",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "One-click session handoff: prepares the work, writes a lean handoff file, verifies it, clears the session and submits the handoff as the first message",
|
|
5
5
|
"author": { "name": "Yasaswy Nagavolu" },
|
|
6
6
|
"metadata": { "minClaudeCodeVersion": "2.1.287" }
|
|
@@ -60,7 +60,7 @@ an unattended session's prompt cache warm. Needs Claude Code 2.1.287 or later (m
|
|
|
60
60
|
|
|
61
61
|
- On by default each session. `/keepwarm on|off|status`. No status-bar marker.
|
|
62
62
|
- When the main chat is idle, no handoff runs, and the cache has 1 to 75 s left, the mod submits
|
|
63
|
-
`prompts/keepwarm-nudge.md`. Max 6 in a row; a real user prompt resets the count.
|
|
63
|
+
`prompts/keepwarm-nudge.md`. Max 6 in a row; a real user prompt resets the count. Each submitted nudge toasts `Keep-warm nudge sent (N of 6)`.
|
|
64
64
|
- A nudge is never sent while a user prompt waits for its turn to start, within 3 s of any turn end,
|
|
65
65
|
or while the prompt box holds text (checked again right before the submit).
|
|
66
66
|
- The nudge reply is the turn whose start text carries the nudge marker; its turn id is the only turn
|
|
@@ -210,6 +210,7 @@ const nudgeToolCount = ($) => tryOr($, 'nudge tool count', async () => toolUseCo
|
|
|
210
210
|
|
|
211
211
|
async function sendNudge($, now) {
|
|
212
212
|
state = onNudgeSent(state, now)
|
|
213
|
+
const sent = state.count
|
|
213
214
|
try {
|
|
214
215
|
const text = normalize(await $.fs.read($.plugin.root.replace(/\\/g, '/') + '/prompts/keepwarm-nudge.md')).trim()
|
|
215
216
|
if (String((await $.prompt.read()).text || '').trim() !== '') {
|
|
@@ -218,6 +219,7 @@ async function sendNudge($, now) {
|
|
|
218
219
|
}
|
|
219
220
|
if (state.nudgeSentAt !== now) return
|
|
220
221
|
await $.prompt.submit({ text })
|
|
222
|
+
$.ui.toast('Keep-warm nudge sent (' + sent + ' of ' + state.max + ')', { timeoutMs: TOAST_MS })
|
|
221
223
|
} catch (err) {
|
|
222
224
|
state = onNudgeFailed(state)
|
|
223
225
|
$.ui.log('keepwarm nudge failed: ' + err, { to: 'debug' })
|
|
@@ -184,6 +184,46 @@ test('count rises per nudge and the cap pauses at six with a toast', async () =>
|
|
|
184
184
|
assert.ok(h.toasts.some((t) => /nudge limit/.test(t)))
|
|
185
185
|
})
|
|
186
186
|
|
|
187
|
+
test('each nudge toasts its count of the maximum once', async () => {
|
|
188
|
+
const h = await harness({ cache: FIVE_MIN })
|
|
189
|
+
await h.start()
|
|
190
|
+
await h.reply()
|
|
191
|
+
for (let i = 0; i < 3; i += 1) {
|
|
192
|
+
advance(h, 240 * 1000)
|
|
193
|
+
await h.tick()
|
|
194
|
+
await h.nudgeReply('Working.\nKEEPWARM_STATUS: working')
|
|
195
|
+
}
|
|
196
|
+
assert.deepEqual(h.toasts, ['Keep-warm nudge sent (1 of 6)', 'Keep-warm nudge sent (2 of 6)', 'Keep-warm nudge sent (3 of 6)'])
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
test('a failed nudge submit shows no sent toast', async () => {
|
|
200
|
+
const h = await harness({ cache: FIVE_MIN })
|
|
201
|
+
await h.start()
|
|
202
|
+
await h.reply()
|
|
203
|
+
h.$.prompt.submit = async () => {
|
|
204
|
+
throw new Error('submit refused')
|
|
205
|
+
}
|
|
206
|
+
advance(h, 240 * 1000)
|
|
207
|
+
await h.tick()
|
|
208
|
+
assert.deepEqual(h.toasts, [])
|
|
209
|
+
const status = await h.fire('command.run', { args: 'status' }, 'keepwarm')
|
|
210
|
+
assert.match(status.text, /nudges 0\/6/)
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
test('a nudge skipped for a draft shows no sent toast', async () => {
|
|
214
|
+
const h = await harness({ cache: FIVE_MIN })
|
|
215
|
+
await h.start()
|
|
216
|
+
await h.reply()
|
|
217
|
+
advance(h, 240 * 1000)
|
|
218
|
+
let reads = 0
|
|
219
|
+
h.$.prompt.read = async () => {
|
|
220
|
+
reads += 1
|
|
221
|
+
return { text: reads === 1 ? '' : 'started typing' }
|
|
222
|
+
}
|
|
223
|
+
await h.tick()
|
|
224
|
+
assert.deepEqual(h.toasts, [])
|
|
225
|
+
})
|
|
226
|
+
|
|
187
227
|
async function nudgeOnce(h, reply, over = {}) {
|
|
188
228
|
await h.start()
|
|
189
229
|
await h.reply()
|
|
@@ -204,7 +244,7 @@ async function nudgeOnce(h, reply, over = {}) {
|
|
|
204
244
|
test('idle reply with no tools and nothing running pauses silently', async () => {
|
|
205
245
|
const h = await harness({ cache: FIVE_MIN })
|
|
206
246
|
assert.equal(await nudgeOnce(h, 'Nothing left.\nKEEPWARM_STATUS: idle'), 1)
|
|
207
|
-
assert.deepEqual(h.toasts, [])
|
|
247
|
+
assert.deepEqual(h.toasts, ['Keep-warm nudge sent (1 of 6)'])
|
|
208
248
|
})
|
|
209
249
|
|
|
210
250
|
test('blocked reply pauses with a toast', async () => {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ci-runner
|
|
3
|
+
description: Set up GitLab CI on a self-hosted runner so pipelines avoid cloud minutes. Use when the user says "set up CI", "add a pipeline", "GitLab runner", "avoid cloud minutes", "new project pipeline", or "install a runner on this machine". Thin wrapper over the agents CLI `runner` command; all mechanics live in code.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# ci-runner
|
|
7
|
+
|
|
8
|
+
Goal: a project has a working `.gitlab-ci.yml` and a self-hosted runner that runs it.
|
|
9
|
+
This skill only calls the CLI and reports its result. The CLI owns detection, tokens and retries.
|
|
10
|
+
|
|
11
|
+
## Rules
|
|
12
|
+
|
|
13
|
+
- Never read, print or ask for a token or PAT. A missing PAT is fixed by the user with `agents-cli secrets` (key `GITLAB_RUNNER_PAT`).
|
|
14
|
+
- Run every command headless; never open a window.
|
|
15
|
+
- Report each CLI result once.
|
|
16
|
+
|
|
17
|
+
## Flow
|
|
18
|
+
|
|
19
|
+
CLI = `npx @yasaswy.nagavolu/agents`. Always start with `CLI runner status`.
|
|
20
|
+
|
|
21
|
+
| Situation | Command |
|
|
22
|
+
|---|---|
|
|
23
|
+
| No runner on this machine | `CLI runner install --project-id <id>` |
|
|
24
|
+
| Repo has no `.gitlab-ci.yml` | `CLI runner init-project --write --attach --project-id <id>` |
|
|
25
|
+
| Repo has a pipeline, project does not use the runner | `CLI runner attach --project-id <id> [--no-cloud]` |
|
|
26
|
+
| Any command exits 1 | `CLI runner doctor`, then follow its fix hints |
|
|
27
|
+
|
|
28
|
+
Exit codes: 0 ok, 1 a step failed (read the failed step), 2 usage error (fix the flags).
|
|
29
|
+
|
|
30
|
+
## Notes
|
|
31
|
+
|
|
32
|
+
- `--no-cloud` stops the project from using cloud runners. Pipelines then wait while the host is off. Use it only when the user asks to avoid cloud minutes.
|
|
33
|
+
- `init-project` is a dry run without `--write` and never overwrites an existing `.gitlab-ci.yml`.
|
|
34
|
+
- The project id comes from the GitLab remote of the repo; ask the user only if it cannot be found.
|
|
35
|
+
- Add `--json` when you need to parse the result.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const { execFileSync } = require('node:child_process');
|
|
6
|
+
const { parseLeading, compare } = require('./semver');
|
|
7
|
+
|
|
8
|
+
function defaultProbe() {
|
|
9
|
+
try {
|
|
10
|
+
return execFileSync('claude', ['--version'], {
|
|
11
|
+
encoding: 'utf8',
|
|
12
|
+
timeout: 15000,
|
|
13
|
+
windowsHide: true,
|
|
14
|
+
shell: process.platform === 'win32',
|
|
15
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
16
|
+
});
|
|
17
|
+
} catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function readModPlugin(targetBase, item) {
|
|
23
|
+
const rel = item.targetPath || item.path;
|
|
24
|
+
const file = path.join(targetBase, ...rel.split('/'), '.claude-plugin', 'plugin.json');
|
|
25
|
+
try {
|
|
26
|
+
const plugin = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
27
|
+
const required = plugin && plugin.metadata && plugin.metadata.minClaudeCodeVersion;
|
|
28
|
+
const min = required ? parseLeading(required) : null;
|
|
29
|
+
if (!min) return null;
|
|
30
|
+
return { name: plugin.name || path.posix.basename(rel), required: min };
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function formatCheck(check) {
|
|
37
|
+
if (check.status === 'ok') return `claude ${check.installed} >= ${check.required} (${check.mod})`;
|
|
38
|
+
if (check.status === 'too-old') {
|
|
39
|
+
return (
|
|
40
|
+
`WARNING claude ${check.installed} < ${check.required} required by ${check.mod}: update Claude Code, ` +
|
|
41
|
+
'then restart every chat started before the update (a running chat keeps the version it started with)'
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return `WARNING cannot read the Claude Code version (\`claude --version\` failed); ${check.mod} requires >= ${check.required}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* One check per deployed mod item that declares metadata.minClaudeCodeVersion.
|
|
49
|
+
* `probe` returns the text of `claude --version` (or null); it is called at
|
|
50
|
+
* most once, and not at all when there is nothing to check.
|
|
51
|
+
*/
|
|
52
|
+
function checkModVersions({ items, targetBase, probe = defaultProbe }) {
|
|
53
|
+
const mods = [];
|
|
54
|
+
for (const item of items) {
|
|
55
|
+
if (item.kind !== 'mod') continue;
|
|
56
|
+
const plugin = readModPlugin(targetBase, item);
|
|
57
|
+
if (plugin) mods.push(plugin);
|
|
58
|
+
}
|
|
59
|
+
if (mods.length === 0) return [];
|
|
60
|
+
|
|
61
|
+
let raw = null;
|
|
62
|
+
try {
|
|
63
|
+
raw = probe();
|
|
64
|
+
} catch {
|
|
65
|
+
raw = null;
|
|
66
|
+
}
|
|
67
|
+
const installed = raw == null ? null : parseLeading(raw);
|
|
68
|
+
|
|
69
|
+
return mods.map(({ name, required }) => {
|
|
70
|
+
let status = 'unknown';
|
|
71
|
+
if (installed) status = compare(installed, required) >= 0 ? 'ok' : 'too-old';
|
|
72
|
+
const check = {
|
|
73
|
+
mod: name,
|
|
74
|
+
required: required.text,
|
|
75
|
+
installed: installed ? installed.text : null,
|
|
76
|
+
status,
|
|
77
|
+
};
|
|
78
|
+
return { ...check, line: formatCheck(check) };
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
module.exports = { checkModVersions, defaultProbe };
|
package/lib/doctor.js
CHANGED
|
@@ -6,6 +6,7 @@ const { loadManifest } = require('./manifest');
|
|
|
6
6
|
const { loadLedger } = require('./ledger');
|
|
7
7
|
const { sha256File, matchesStoredHash } = require('./fsutil');
|
|
8
8
|
const { defaultTargetBase } = require('./install');
|
|
9
|
+
const { checkModVersions } = require('./claudeVersion');
|
|
9
10
|
|
|
10
11
|
class DoctorError extends Error {}
|
|
11
12
|
|
|
@@ -109,7 +110,7 @@ function* walkDeployed(dir, relBase = '') {
|
|
|
109
110
|
* neither this CLI nor its manifest has ever heard of), so no orphan scan
|
|
110
111
|
* is safe to run there.
|
|
111
112
|
*/
|
|
112
|
-
function checkHealth({ packageRoot, targetBase, cliVersion }) {
|
|
113
|
+
function checkHealth({ packageRoot, targetBase, cliVersion, claudeVersionProbe }) {
|
|
113
114
|
const { manifest, manifestPath } = loadManifest(packageRoot);
|
|
114
115
|
const repoRoot = path.dirname(manifestPath);
|
|
115
116
|
const resolvedTargetBase = targetBase || defaultTargetBase();
|
|
@@ -209,6 +210,17 @@ function checkHealth({ packageRoot, targetBase, cliVersion }) {
|
|
|
209
210
|
missing.sort((a, b) => a.relTarget.localeCompare(b.relTarget));
|
|
210
211
|
drifted.sort((a, b) => a.relTarget.localeCompare(b.relTarget));
|
|
211
212
|
|
|
213
|
+
const installedMods = allFileItems(manifest).filter((item) => {
|
|
214
|
+
if (item.kind !== 'mod') return false;
|
|
215
|
+
const prefix = `${item.targetPath || item.path}/`;
|
|
216
|
+
return [...claimed].some((k) => k.startsWith(prefix));
|
|
217
|
+
});
|
|
218
|
+
const modVersions = checkModVersions({
|
|
219
|
+
items: installedMods,
|
|
220
|
+
targetBase: resolvedTargetBase,
|
|
221
|
+
probe: claudeVersionProbe,
|
|
222
|
+
});
|
|
223
|
+
|
|
212
224
|
return {
|
|
213
225
|
targetBase: resolvedTargetBase,
|
|
214
226
|
scannedDirs: [...flatDirs].sort(),
|
|
@@ -216,7 +228,12 @@ function checkHealth({ packageRoot, targetBase, cliVersion }) {
|
|
|
216
228
|
orphans,
|
|
217
229
|
missing,
|
|
218
230
|
drifted,
|
|
219
|
-
|
|
231
|
+
modVersions,
|
|
232
|
+
healthy:
|
|
233
|
+
orphans.length === 0 &&
|
|
234
|
+
missing.length === 0 &&
|
|
235
|
+
drifted.length === 0 &&
|
|
236
|
+
modVersions.every((c) => c.status !== 'too-old'),
|
|
220
237
|
};
|
|
221
238
|
}
|
|
222
239
|
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const SUBCOMMANDS = Object.freeze(['install', 'status', 'doctor', 'uninstall', 'attach', 'detach', 'init-project']);
|
|
4
|
+
const INSTALL_PROFILES = Object.freeze(['auto', 'linux', 'macos', 'linux-docker', 'macos-shell']);
|
|
5
|
+
const PROJECT_PROFILES = Object.freeze(['node', 'python', 'docker', 'macos', 'blank']);
|
|
6
|
+
const NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
|
|
7
|
+
|
|
8
|
+
const VALUE_FLAGS = new Set([
|
|
9
|
+
'profile', 'name', 'tags', 'concurrent', 'group-id', 'project-id', 'url', 'image', 'cache-volume', 'runner',
|
|
10
|
+
]);
|
|
11
|
+
const BOOL_FLAGS = new Set([
|
|
12
|
+
'protected', 'run-untagged', 'no-run-untagged', 'dry-run', 'json', 'no-cloud', 'write', 'attach', 'yes',
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
const OS_LABELS = Object.freeze({ win32: 'windows', darwin: 'macos', linux: 'linux' });
|
|
16
|
+
|
|
17
|
+
function sanitizeHostname(hostname) {
|
|
18
|
+
const cleaned = String(hostname || '')
|
|
19
|
+
.toLowerCase()
|
|
20
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
21
|
+
.replace(/^-+|-+$/g, '');
|
|
22
|
+
return cleaned || 'host';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function defaultName({ hostname, platform } = {}) {
|
|
26
|
+
const os = OS_LABELS[platform] || sanitizeHostname(platform || '');
|
|
27
|
+
return `agents-${os}-${sanitizeHostname(hostname)}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function positiveInt(raw, label, errors) {
|
|
31
|
+
if (!/^\d+$/.test(String(raw)) || Number(raw) < 1) {
|
|
32
|
+
errors.push(`${label} must be a positive integer`);
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return Number(raw);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function tokenize(argv, errors) {
|
|
39
|
+
const flags = {};
|
|
40
|
+
const positionals = [];
|
|
41
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
42
|
+
const arg = String(argv[i]);
|
|
43
|
+
if (!arg.startsWith('--')) {
|
|
44
|
+
positionals.push(arg);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const eq = arg.indexOf('=');
|
|
48
|
+
const key = eq === -1 ? arg.slice(2) : arg.slice(2, eq);
|
|
49
|
+
const inline = eq === -1 ? undefined : arg.slice(eq + 1);
|
|
50
|
+
if (BOOL_FLAGS.has(key)) {
|
|
51
|
+
flags[key] = true;
|
|
52
|
+
} else if (VALUE_FLAGS.has(key)) {
|
|
53
|
+
let value = inline;
|
|
54
|
+
if (value === undefined) {
|
|
55
|
+
const next = argv[i + 1];
|
|
56
|
+
if (next === undefined || String(next).startsWith('--')) {
|
|
57
|
+
errors.push(`--${key} requires a value`);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
value = String(next);
|
|
61
|
+
i += 1;
|
|
62
|
+
}
|
|
63
|
+
if (key === 'cache-volume') {
|
|
64
|
+
(flags[key] = flags[key] || []).push(value);
|
|
65
|
+
} else {
|
|
66
|
+
flags[key] = value;
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
errors.push(`unknown flag: --${key}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return { flags, positionals };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function parseRunnerArgs(argv = [], { hostname, platform } = {}) {
|
|
76
|
+
const errors = [];
|
|
77
|
+
const { flags, positionals } = tokenize(argv, errors);
|
|
78
|
+
|
|
79
|
+
let sub = positionals[0] || null;
|
|
80
|
+
if (!sub) {
|
|
81
|
+
errors.push(`missing subcommand (${SUBCOMMANDS.join('|')})`);
|
|
82
|
+
} else if (!SUBCOMMANDS.includes(sub)) {
|
|
83
|
+
errors.push(`unknown subcommand: ${sub}`);
|
|
84
|
+
sub = null;
|
|
85
|
+
}
|
|
86
|
+
if (positionals.length > 1) errors.push(`unexpected argument: ${positionals[1]}`);
|
|
87
|
+
|
|
88
|
+
if (flags['run-untagged'] && flags['no-run-untagged']) {
|
|
89
|
+
errors.push('--run-untagged and --no-run-untagged conflict');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const groupId = flags['group-id'] !== undefined ? positiveInt(flags['group-id'], '--group-id', errors) : null;
|
|
93
|
+
const projectId = flags['project-id'] !== undefined ? positiveInt(flags['project-id'], '--project-id', errors) : null;
|
|
94
|
+
if (groupId !== null && projectId !== null) errors.push('--group-id and --project-id are mutually exclusive');
|
|
95
|
+
const scope = groupId !== null ? 'group' : (projectId !== null ? 'project' : null);
|
|
96
|
+
|
|
97
|
+
const concurrent = flags.concurrent !== undefined ? positiveInt(flags.concurrent, '--concurrent', errors) : 1;
|
|
98
|
+
|
|
99
|
+
const name = flags.name !== undefined ? flags.name : defaultName({ hostname, platform });
|
|
100
|
+
if (!NAME_PATTERN.test(name)) errors.push('--name may contain only letters, digits, ".", "_" and "-"');
|
|
101
|
+
|
|
102
|
+
const tags = flags.tags !== undefined
|
|
103
|
+
? flags.tags.split(',').map((t) => t.trim()).filter(Boolean)
|
|
104
|
+
: [];
|
|
105
|
+
|
|
106
|
+
let profile = flags.profile;
|
|
107
|
+
if (sub === 'init-project') {
|
|
108
|
+
if (profile !== undefined && !PROJECT_PROFILES.includes(profile)) {
|
|
109
|
+
errors.push(`--profile for init-project must be one of ${PROJECT_PROFILES.join('|')}`);
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
if (profile === undefined) profile = 'auto';
|
|
113
|
+
if (!INSTALL_PROFILES.includes(profile)) {
|
|
114
|
+
errors.push(`--profile must be one of ${INSTALL_PROFILES.join('|')}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
let runUntagged = null;
|
|
119
|
+
if (flags['run-untagged']) runUntagged = true;
|
|
120
|
+
if (flags['no-run-untagged']) runUntagged = false;
|
|
121
|
+
|
|
122
|
+
if (sub === 'install' && scope === null) {
|
|
123
|
+
errors.push('install requires --group-id or --project-id');
|
|
124
|
+
}
|
|
125
|
+
if ((sub === 'attach' || sub === 'detach') && projectId === null) {
|
|
126
|
+
errors.push(`${sub} requires --project-id`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const opts = {
|
|
130
|
+
name,
|
|
131
|
+
profile,
|
|
132
|
+
tags,
|
|
133
|
+
concurrent,
|
|
134
|
+
scope,
|
|
135
|
+
groupId,
|
|
136
|
+
projectId,
|
|
137
|
+
url: String(flags.url || 'https://gitlab.com').replace(/\/+$/, ''),
|
|
138
|
+
protected: Boolean(flags.protected),
|
|
139
|
+
runUntagged,
|
|
140
|
+
image: flags.image || 'alpine:3.20',
|
|
141
|
+
cacheVolumes: flags['cache-volume'] || [],
|
|
142
|
+
dryRun: Boolean(flags['dry-run']),
|
|
143
|
+
json: Boolean(flags.json),
|
|
144
|
+
runner: flags.runner || null,
|
|
145
|
+
noCloud: Boolean(flags['no-cloud']),
|
|
146
|
+
write: Boolean(flags.write),
|
|
147
|
+
attach: Boolean(flags.attach),
|
|
148
|
+
yes: Boolean(flags.yes),
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
return { sub, opts, errors };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
module.exports = { SUBCOMMANDS, INSTALL_PROFILES, PROJECT_PROFILES, parseRunnerArgs, defaultName, sanitizeHostname };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const PROFILE_ALIASES = Object.freeze({
|
|
4
|
+
linux: 'linux-docker',
|
|
5
|
+
'linux-docker': 'linux-docker',
|
|
6
|
+
macos: 'macos-shell',
|
|
7
|
+
'macos-shell': 'macos-shell',
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const PROFILE_DEFAULTS = Object.freeze({
|
|
11
|
+
'linux-docker': { tags: ['self-hosted', 'linux', 'docker'], runUntagged: true },
|
|
12
|
+
'macos-shell': { tags: ['self-hosted', 'macos'], runUntagged: false },
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const ARCH_TAGS = Object.freeze({ x64: 'amd64', amd64: 'amd64', arm64: 'arm64', aarch64: 'arm64' });
|
|
16
|
+
|
|
17
|
+
async function probe(exec, cmd, args) {
|
|
18
|
+
try {
|
|
19
|
+
const res = await exec(cmd, args, { timeoutMs: 15000 });
|
|
20
|
+
return res && typeof res.code === 'number' ? res : { code: 127, stdout: '', stderr: '' };
|
|
21
|
+
} catch {
|
|
22
|
+
return { code: 127, stdout: '', stderr: '' };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function detectDocker(exec) {
|
|
27
|
+
const ver = await probe(exec, 'docker', ['version', '--format', '{{.Server.Version}}']);
|
|
28
|
+
const version = ver.stdout.trim();
|
|
29
|
+
if (ver.code === 0 && version) return { present: true, running: true, version };
|
|
30
|
+
const info = await probe(exec, 'docker', ['info']);
|
|
31
|
+
if (info.code === 0) return { present: true, running: true, version: null };
|
|
32
|
+
return { present: ver.code !== 127 || info.code !== 127, running: false, version: null };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function detectHost({ platform, arch, exec }) {
|
|
36
|
+
const os = platform;
|
|
37
|
+
const [docker, brew, runner, xcode] = await Promise.all([
|
|
38
|
+
detectDocker(exec),
|
|
39
|
+
probe(exec, 'brew', ['--version']),
|
|
40
|
+
probe(exec, 'gitlab-runner', ['--version']),
|
|
41
|
+
os === 'darwin' ? probe(exec, 'xcode-select', ['-p']) : Promise.resolve({ code: 1 }),
|
|
42
|
+
]);
|
|
43
|
+
return {
|
|
44
|
+
os,
|
|
45
|
+
arch,
|
|
46
|
+
docker,
|
|
47
|
+
brew: brew.code === 0,
|
|
48
|
+
runnerBin: runner.code === 0,
|
|
49
|
+
xcodeClt: xcode.code === 0,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function chooseProfiles(host, opts = {}) {
|
|
54
|
+
const requested = opts.profile;
|
|
55
|
+
if (requested && requested !== 'auto') {
|
|
56
|
+
const key = PROFILE_ALIASES[requested];
|
|
57
|
+
return key ? [key] : [];
|
|
58
|
+
}
|
|
59
|
+
if (host.os === 'darwin') {
|
|
60
|
+
const keys = [];
|
|
61
|
+
if (host.xcodeClt) keys.push('macos-shell');
|
|
62
|
+
if (host.docker && host.docker.running) keys.push('linux-docker');
|
|
63
|
+
return keys;
|
|
64
|
+
}
|
|
65
|
+
return ['linux-docker'];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function resolveDefaults(opts, profileKey, host = {}) {
|
|
69
|
+
const defaults = PROFILE_DEFAULTS[profileKey] || { tags: [], runUntagged: false };
|
|
70
|
+
const archTag = ARCH_TAGS[host.arch];
|
|
71
|
+
const tags = opts.tags && opts.tags.length
|
|
72
|
+
? opts.tags
|
|
73
|
+
: [...defaults.tags, ...(archTag ? [archTag] : [])];
|
|
74
|
+
const runUntagged = typeof opts.runUntagged === 'boolean' ? opts.runUntagged : defaults.runUntagged;
|
|
75
|
+
return { ...opts, tags, runUntagged };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
module.exports = {
|
|
79
|
+
PROFILE_ALIASES,
|
|
80
|
+
PROFILE_DEFAULTS,
|
|
81
|
+
detectHost,
|
|
82
|
+
chooseProfiles,
|
|
83
|
+
resolveDefaults,
|
|
84
|
+
};
|