@jondeodat/claude-setup-cli 0.2.1 → 0.2.3
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 +16 -5
- package/dist/claude-setup-cli.js +106 -28
- package/dist/claude-setup.js +5 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -37,12 +37,14 @@ overrides it); without one, updates apply at once.
|
|
|
37
37
|
A marketplace clone is shallow, so the commit that introduced a version is out of reach. The release date
|
|
38
38
|
is estimated as the earlier of the day `claude-setup` first saw the version and the date of the last
|
|
39
39
|
commit of the clone: both come after the release, so the delay is never shortened, at worst lengthened.
|
|
40
|
-
A held-back version is reported
|
|
41
|
-
`node_modules/.cache/claude-setup/state.json`.
|
|
40
|
+
A held-back version is reported at each refresh until it applies, with the day it will; the first
|
|
41
|
+
sightings are recorded in `node_modules/.cache/claude-setup/state.json`. When npm cannot tell the delay
|
|
42
|
+
(npm missing or failing), these updates are held back and the failure is reported.
|
|
42
43
|
|
|
43
44
|
It never fails, so that it cannot break an `npm install` or a session start: a failure (network down,
|
|
44
|
-
unknown plugin…) is reported, and the run goes on. It does nothing
|
|
45
|
-
set
|
|
45
|
+
unknown plugin…) is reported, and the run goes on. It does nothing in CI (`CI` set), with
|
|
46
|
+
`CLAUDE_SETUP_SKIP` set, or without the `claude` CLI: run by npm, silently, since the machine may not
|
|
47
|
+
have Claude Code; as a hook, it reports that none was found and why each candidate was turned down.
|
|
46
48
|
|
|
47
49
|
The `claude` CLI it runs is the one `CLAUDE_CODE_EXECPATH` names, or else the `claude` on the `PATH`,
|
|
48
50
|
whichever first answers `--version` as Claude Code. Claude Code sets `CLAUDE_CODE_EXECPATH` in the
|
|
@@ -68,7 +70,9 @@ claude-setup [--hook] [--max-age <hours>]
|
|
|
68
70
|
|
|
69
71
|
- `--hook` prints its report as the JSON output of a `SessionStart` hook, and nothing when there is nothing
|
|
70
72
|
to report. The terminal shows its `systemMessage`, in yellow; the IDE extensions do not show it, so an
|
|
71
|
-
`additionalContext` asks Claude to pass the news on at the start of its first reply
|
|
73
|
+
`additionalContext` asks Claude to pass the news on at the start of its first reply, failures
|
|
74
|
+
included. Even a wrong option or an unexpected error is reported this way, with a zero exit code:
|
|
75
|
+
Claude Code ignores the output of a hook that fails.
|
|
72
76
|
- `--max-age <hours>` refreshes the marketplaces only when the last refresh, recorded in
|
|
73
77
|
`node_modules/.cache/claude-setup/state.json`, is older. Without it, every run refreshes.
|
|
74
78
|
|
|
@@ -153,6 +157,13 @@ npm run push
|
|
|
153
157
|
- `npm run push` runs `npm publish`, whose `prepublishOnly` script first runs `npm run typecheck`,
|
|
154
158
|
`npm test`, `npm run format:check` and `npm run build`, and stops if one fails; then it publishes the
|
|
155
159
|
package, publicly, on registry.npmjs.org.
|
|
160
|
+
- With `ignore-scripts` set, `npm publish` skips `prepublishOnly` and ships whatever `dist/` holds, stale
|
|
161
|
+
or missing: `npm run push` passes `--ignore-scripts=false`, so publish with it rather than with
|
|
162
|
+
`npm publish`. A publish installs nothing, so this only lets the scripts of this `package.json` run, no
|
|
163
|
+
dependency's.
|
|
164
|
+
- `npm run push` logs in to npm first and logs out afterwards, even when the publish fails: `npm logout`
|
|
165
|
+
revokes the token that `npm login` wrote in the user `.npmrc`, so no valid token stays on disk between
|
|
166
|
+
publishes. The script needs a POSIX shell (`sh`, the default for npm scripts on macOS and Linux).
|
|
156
167
|
|
|
157
168
|
## License
|
|
158
169
|
|
package/dist/claude-setup-cli.js
CHANGED
|
@@ -13,12 +13,50 @@ than the min-release-age npm reads for the project (.npmrc).
|
|
|
13
13
|
|
|
14
14
|
The claude CLI rewrites .claude/settings.json in its own format: this tool puts the file back as it was.
|
|
15
15
|
It does nothing in CI (CI set), with CLAUDE_SETUP_SKIP set, or without the claude CLI, and never fails.
|
|
16
|
+
The claude CLI is the one CLAUDE_CODE_EXECPATH names, set by Claude Code in a hook, or else the one on
|
|
17
|
+
the PATH, whichever first answers --version as Claude Code.
|
|
16
18
|
|
|
17
19
|
Options:
|
|
18
20
|
--hook prints its report as the JSON output of a SessionStart hook, and nothing when there
|
|
19
21
|
is nothing to report
|
|
20
22
|
--max-age <hours> refreshes the marketplaces only when the last refresh is older (default: every run)
|
|
21
23
|
-h, --help prints this help`;
|
|
24
|
+
/**
|
|
25
|
+
* Finds the claude CLI to run: the one of the Claude Code session that started this tool, as a hook,
|
|
26
|
+
* which Claude Code names in CLAUDE_CODE_EXECPATH even when it is only installed as an IDE extension and
|
|
27
|
+
* puts no claude on the PATH; or else the claude on the PATH. CLAUDE_CODE_EXECPATH is not documented: it
|
|
28
|
+
* can name a binary removed by an update since, or one that is not the claude CLI, so each candidate must
|
|
29
|
+
* answer `--version` as Claude Code does. Without one, tells why each candidate was turned down.
|
|
30
|
+
*/
|
|
31
|
+
function findClaude() {
|
|
32
|
+
const candidates = [
|
|
33
|
+
{ path: process.env.CLAUDE_CODE_EXECPATH, label: `CLAUDE_CODE_EXECPATH (${process.env.CLAUDE_CODE_EXECPATH})` },
|
|
34
|
+
{ path: 'claude', label: 'claude on the PATH' },
|
|
35
|
+
];
|
|
36
|
+
const rejections = [];
|
|
37
|
+
for (const { path, label } of candidates) {
|
|
38
|
+
if (!path) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const probe = spawnSync(path, ['--version'], { encoding: 'utf8' });
|
|
42
|
+
if (!probe.error && probe.status === 0 && probe.stdout.includes('Claude Code')) {
|
|
43
|
+
return { path };
|
|
44
|
+
}
|
|
45
|
+
const reason = probe.error
|
|
46
|
+
? probe.error.code === 'ENOENT'
|
|
47
|
+
? 'not found'
|
|
48
|
+
: probe.error.message
|
|
49
|
+
: probe.status !== 0
|
|
50
|
+
? `--version exits with code ${probe.status}`
|
|
51
|
+
: `--version answers "${probe.stdout.trim().split('\n')[0]}", not Claude Code`;
|
|
52
|
+
rejections.push(`${label}: ${reason}`);
|
|
53
|
+
}
|
|
54
|
+
return { rejections };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The claude CLI to run, that main() finds before anything runs it
|
|
58
|
+
*/
|
|
59
|
+
let claude = 'claude';
|
|
22
60
|
/**
|
|
23
61
|
* A `claude plugin` command can clone a marketplace
|
|
24
62
|
*/
|
|
@@ -27,7 +65,7 @@ const CLAUDE_TIMEOUT_MS = 180_000;
|
|
|
27
65
|
* Runs `claude <args> --json` from the project root
|
|
28
66
|
*/
|
|
29
67
|
function runClaude(root, args) {
|
|
30
|
-
const child = spawnSync(
|
|
68
|
+
const child = spawnSync(claude, [...args, '--json'], { cwd: root, encoding: 'utf8', timeout: CLAUDE_TIMEOUT_MS });
|
|
31
69
|
if (child.error) {
|
|
32
70
|
return { error: `claude ${args.join(' ')}: ${child.error.message}` };
|
|
33
71
|
}
|
|
@@ -120,11 +158,18 @@ function installPlugins(root, settings, known, report) {
|
|
|
120
158
|
return installedAfter;
|
|
121
159
|
}
|
|
122
160
|
/**
|
|
123
|
-
* The project's minimum release age, in days, as npm resolves it from its .npmrc files and environment
|
|
161
|
+
* The project's minimum release age, in days, as npm resolves it from its .npmrc files and environment,
|
|
162
|
+
* or the reason npm could not tell
|
|
124
163
|
*/
|
|
125
164
|
function readReleaseAgeDays(root) {
|
|
126
165
|
const child = spawnSync('npm', ['config', 'get', 'min-release-age'], { cwd: root, encoding: 'utf8' });
|
|
127
|
-
|
|
166
|
+
if (child.error) {
|
|
167
|
+
return { error: child.error.code === 'ENOENT' ? 'npm not found' : child.error.message };
|
|
168
|
+
}
|
|
169
|
+
if (child.status !== 0) {
|
|
170
|
+
return { error: child.stderr.trim() || `exit code ${child.status}` };
|
|
171
|
+
}
|
|
172
|
+
return { days: parseReleaseAgeDays(child.stdout) };
|
|
128
173
|
}
|
|
129
174
|
/**
|
|
130
175
|
* When the last commit of a marketplace clone was made, or undefined if git cannot tell
|
|
@@ -161,10 +206,19 @@ function refresh(root, settings, known, installedBefore, state, now, report) {
|
|
|
161
206
|
report.failures.push(update.error);
|
|
162
207
|
}
|
|
163
208
|
}
|
|
164
|
-
const
|
|
209
|
+
const listing = runClaude(root, ['plugin', 'marketplace', 'list']);
|
|
210
|
+
if (listing.error) {
|
|
211
|
+
report.failures.push(listing.error);
|
|
212
|
+
}
|
|
213
|
+
const locations = new Map(asArray(listing.output).map(({ name, installLocation }) => [name, installLocation]));
|
|
165
214
|
const installed = listInstalledPlugins(root, report);
|
|
166
215
|
const justInstalled = new Set(report.installed.map(({ id }) => id));
|
|
167
|
-
const
|
|
216
|
+
const releaseAge = readReleaseAgeDays(root);
|
|
217
|
+
// Without the delay, the updates it covers wait rather than apply at once
|
|
218
|
+
const minAgeDays = 'days' in releaseAge ? releaseAge.days : undefined;
|
|
219
|
+
if ('error' in releaseAge) {
|
|
220
|
+
report.failures.push(`npm config get min-release-age: ${releaseAge.error}; the updates of the marketplaces without autoUpdate are held back`);
|
|
221
|
+
}
|
|
168
222
|
const firstSeen = {};
|
|
169
223
|
const enabledIds = getEnabledPlugins(settings);
|
|
170
224
|
let hasRunUpdate = false;
|
|
@@ -191,16 +245,16 @@ function refresh(root, settings, known, installedBefore, state, now, report) {
|
|
|
191
245
|
}
|
|
192
246
|
const key = `${id} ${offered}`;
|
|
193
247
|
const firstSeenAt = state.firstSeen?.[key] ?? now;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
if (state.firstSeen?.[key] === undefined) {
|
|
248
|
+
if (minAgeDays !== undefined) {
|
|
249
|
+
const appliesAt = getAppliesAt(estimateReleasedAt(firstSeenAt, readLastCommittedAt(location)), minAgeDays);
|
|
250
|
+
if (now >= appliesAt) {
|
|
251
|
+
update(root, id, installation.scope, report);
|
|
252
|
+
hasRunUpdate = true;
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
202
255
|
report.pending.push({ id, from: installation.version, to: offered, appliesOn: new Date(appliesAt).toISOString().slice(0, 10) });
|
|
203
256
|
}
|
|
257
|
+
firstSeen[key] = firstSeenAt;
|
|
204
258
|
}
|
|
205
259
|
const installedAfter = hasRunUpdate ? listInstalledPlugins(root, report) : installed;
|
|
206
260
|
report.updated.push(...findUpdates(installedBefore, installedAfter, enabledIds, root));
|
|
@@ -244,7 +298,27 @@ function print(report, isHook) {
|
|
|
244
298
|
(line.startsWith('failed:') ? console.error : console.log)(`claude-setup: ${line}`);
|
|
245
299
|
}
|
|
246
300
|
}
|
|
247
|
-
|
|
301
|
+
/**
|
|
302
|
+
* Reports a failure that stops the run. As a hook, it goes to the session and the exit code stays 0:
|
|
303
|
+
* Claude Code reads the output of a hook that succeeds only.
|
|
304
|
+
*/
|
|
305
|
+
function printFailure(message, isHook) {
|
|
306
|
+
const report = createReport();
|
|
307
|
+
report.failures.push(message);
|
|
308
|
+
print(report, isHook);
|
|
309
|
+
}
|
|
310
|
+
function printUsageError(message, isHook) {
|
|
311
|
+
if (isHook) {
|
|
312
|
+
printFailure(message, true);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
console.error(`claude-setup: ${message}\n\n${USAGE}`);
|
|
316
|
+
process.exitCode = 1;
|
|
317
|
+
}
|
|
318
|
+
function getMessage(error) {
|
|
319
|
+
return error instanceof Error ? error.message : String(error);
|
|
320
|
+
}
|
|
321
|
+
function parseOptions(isHook) {
|
|
248
322
|
try {
|
|
249
323
|
return parseArgs({
|
|
250
324
|
options: {
|
|
@@ -255,13 +329,12 @@ function parseOptions() {
|
|
|
255
329
|
}).values;
|
|
256
330
|
}
|
|
257
331
|
catch (error) {
|
|
258
|
-
|
|
259
|
-
process.exitCode = 1;
|
|
332
|
+
printUsageError(getMessage(error), isHook);
|
|
260
333
|
return undefined;
|
|
261
334
|
}
|
|
262
335
|
}
|
|
263
|
-
function main() {
|
|
264
|
-
const values = parseOptions();
|
|
336
|
+
function main(isHook) {
|
|
337
|
+
const values = parseOptions(isHook);
|
|
265
338
|
if (!values) {
|
|
266
339
|
return;
|
|
267
340
|
}
|
|
@@ -271,8 +344,7 @@ function main() {
|
|
|
271
344
|
}
|
|
272
345
|
const maxAgeHours = values['max-age'] === undefined ? undefined : Number(values['max-age']);
|
|
273
346
|
if (maxAgeHours !== undefined && !(maxAgeHours >= 0)) {
|
|
274
|
-
|
|
275
|
-
process.exitCode = 1;
|
|
347
|
+
printUsageError('--max-age expects a number of hours', isHook);
|
|
276
348
|
return;
|
|
277
349
|
}
|
|
278
350
|
if (process.env.CI || process.env.CLAUDE_SETUP_SKIP) {
|
|
@@ -283,18 +355,22 @@ function main() {
|
|
|
283
355
|
if (!existsSync(settingsPath)) {
|
|
284
356
|
return;
|
|
285
357
|
}
|
|
286
|
-
const isHook = values.hook === true;
|
|
287
358
|
const report = createReport();
|
|
288
359
|
const original = readFileSync(settingsPath, 'utf8');
|
|
289
360
|
try {
|
|
290
|
-
const
|
|
291
|
-
if (
|
|
292
|
-
|
|
361
|
+
const found = findClaude();
|
|
362
|
+
if ('path' in found) {
|
|
363
|
+
claude = found.path;
|
|
364
|
+
setUp(root, JSON.parse(original), maxAgeHours, report);
|
|
365
|
+
}
|
|
366
|
+
else if (isHook) {
|
|
367
|
+
// Run by npm, on a machine without Claude Code, there is nothing to set up. A hook runs in a
|
|
368
|
+
// Claude Code session: its claude CLI must be there.
|
|
369
|
+
report.failures.push(`no claude CLI found (${found.rejections.join('; ')})`);
|
|
293
370
|
}
|
|
294
|
-
setUp(root, JSON.parse(original), maxAgeHours, report);
|
|
295
371
|
}
|
|
296
372
|
catch (error) {
|
|
297
|
-
report.failures.push(
|
|
373
|
+
report.failures.push(getMessage(error));
|
|
298
374
|
}
|
|
299
375
|
finally {
|
|
300
376
|
if (readFileSync(settingsPath, 'utf8') !== original) {
|
|
@@ -303,10 +379,12 @@ function main() {
|
|
|
303
379
|
}
|
|
304
380
|
print(report, isHook);
|
|
305
381
|
}
|
|
382
|
+
// Known before the options are parsed, so that even an error parsing them reaches the session
|
|
383
|
+
const isHook = process.argv.slice(2).includes('--hook');
|
|
306
384
|
try {
|
|
307
|
-
main();
|
|
385
|
+
main(isHook);
|
|
308
386
|
}
|
|
309
387
|
catch (error) {
|
|
310
388
|
// Never fail the npm install or the session start that runs this tool
|
|
311
|
-
|
|
389
|
+
printFailure(getMessage(error), isHook);
|
|
312
390
|
}
|
package/dist/claude-setup.js
CHANGED
|
@@ -164,7 +164,8 @@ const RESET = '\u001b[0m';
|
|
|
164
164
|
/**
|
|
165
165
|
* The JSON a SessionStart hook prints to report a run, or undefined when there is nothing to report.
|
|
166
166
|
* The terminal shows `systemMessage`, the IDE extensions do not: there, `additionalContext` asks
|
|
167
|
-
* Claude to pass the news on in its first reply
|
|
167
|
+
* Claude to pass the news on in its first reply, failures included, so that a hook that stopped working
|
|
168
|
+
* does not go unnoticed.
|
|
168
169
|
*/
|
|
169
170
|
export function formatHookOutput(report) {
|
|
170
171
|
const lines = formatLines(report);
|
|
@@ -185,6 +186,9 @@ export function formatHookOutput(report) {
|
|
|
185
186
|
report.pending.map((change) => `${describeChange(change)} from ${change.appliesOn}`).join(', ') +
|
|
186
187
|
'.');
|
|
187
188
|
}
|
|
189
|
+
if (report.failures.length > 0) {
|
|
190
|
+
news.push(`The claude-setup hook, which sets up the Claude Code plugins of this project, failed: ${report.failures.join('; ')}.`);
|
|
191
|
+
}
|
|
188
192
|
if (news.length > 0) {
|
|
189
193
|
output.hookSpecificOutput = {
|
|
190
194
|
hookEventName: 'SessionStart',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jondeodat/claude-setup-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Registers the Claude Code marketplaces and installs the plugins that a project declares in .claude/settings.json, at project scope.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"format": "prettier --write .",
|
|
48
48
|
"format:check": "prettier --check .",
|
|
49
49
|
"prepublishOnly": "npm run typecheck && npm test && npm run format:check && npm run build",
|
|
50
|
-
"push": "npm publish"
|
|
50
|
+
"push": "npm login || exit 1; npm publish --ignore-scripts=false; status=$?; npm logout; exit $status"
|
|
51
51
|
},
|
|
52
52
|
"keywords": [
|
|
53
53
|
"claude",
|