@jondeodat/claude-setup-cli 0.2.2 → 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 +12 -5
- package/dist/claude-setup-cli.js +90 -33
- 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
|
|
|
@@ -157,6 +161,9 @@ npm run push
|
|
|
157
161
|
or missing: `npm run push` passes `--ignore-scripts=false`, so publish with it rather than with
|
|
158
162
|
`npm publish`. A publish installs nothing, so this only lets the scripts of this `package.json` run, no
|
|
159
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).
|
|
160
167
|
|
|
161
168
|
## License
|
|
162
169
|
|
package/dist/claude-setup-cli.js
CHANGED
|
@@ -26,14 +26,32 @@ Options:
|
|
|
26
26
|
* which Claude Code names in CLAUDE_CODE_EXECPATH even when it is only installed as an IDE extension and
|
|
27
27
|
* puts no claude on the PATH; or else the claude on the PATH. CLAUDE_CODE_EXECPATH is not documented: it
|
|
28
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
|
|
29
|
+
* answer `--version` as Claude Code does. Without one, tells why each candidate was turned down.
|
|
30
30
|
*/
|
|
31
31
|
function findClaude() {
|
|
32
|
-
const candidates = [
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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 };
|
|
37
55
|
}
|
|
38
56
|
/**
|
|
39
57
|
* The claude CLI to run, that main() finds before anything runs it
|
|
@@ -140,11 +158,18 @@ function installPlugins(root, settings, known, report) {
|
|
|
140
158
|
return installedAfter;
|
|
141
159
|
}
|
|
142
160
|
/**
|
|
143
|
-
* 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
|
|
144
163
|
*/
|
|
145
164
|
function readReleaseAgeDays(root) {
|
|
146
165
|
const child = spawnSync('npm', ['config', 'get', 'min-release-age'], { cwd: root, encoding: 'utf8' });
|
|
147
|
-
|
|
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) };
|
|
148
173
|
}
|
|
149
174
|
/**
|
|
150
175
|
* When the last commit of a marketplace clone was made, or undefined if git cannot tell
|
|
@@ -181,10 +206,19 @@ function refresh(root, settings, known, installedBefore, state, now, report) {
|
|
|
181
206
|
report.failures.push(update.error);
|
|
182
207
|
}
|
|
183
208
|
}
|
|
184
|
-
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]));
|
|
185
214
|
const installed = listInstalledPlugins(root, report);
|
|
186
215
|
const justInstalled = new Set(report.installed.map(({ id }) => id));
|
|
187
|
-
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
|
+
}
|
|
188
222
|
const firstSeen = {};
|
|
189
223
|
const enabledIds = getEnabledPlugins(settings);
|
|
190
224
|
let hasRunUpdate = false;
|
|
@@ -211,16 +245,16 @@ function refresh(root, settings, known, installedBefore, state, now, report) {
|
|
|
211
245
|
}
|
|
212
246
|
const key = `${id} ${offered}`;
|
|
213
247
|
const firstSeenAt = state.firstSeen?.[key] ?? now;
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
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
|
+
}
|
|
222
255
|
report.pending.push({ id, from: installation.version, to: offered, appliesOn: new Date(appliesAt).toISOString().slice(0, 10) });
|
|
223
256
|
}
|
|
257
|
+
firstSeen[key] = firstSeenAt;
|
|
224
258
|
}
|
|
225
259
|
const installedAfter = hasRunUpdate ? listInstalledPlugins(root, report) : installed;
|
|
226
260
|
report.updated.push(...findUpdates(installedBefore, installedAfter, enabledIds, root));
|
|
@@ -264,7 +298,27 @@ function print(report, isHook) {
|
|
|
264
298
|
(line.startsWith('failed:') ? console.error : console.log)(`claude-setup: ${line}`);
|
|
265
299
|
}
|
|
266
300
|
}
|
|
267
|
-
|
|
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) {
|
|
268
322
|
try {
|
|
269
323
|
return parseArgs({
|
|
270
324
|
options: {
|
|
@@ -275,13 +329,12 @@ function parseOptions() {
|
|
|
275
329
|
}).values;
|
|
276
330
|
}
|
|
277
331
|
catch (error) {
|
|
278
|
-
|
|
279
|
-
process.exitCode = 1;
|
|
332
|
+
printUsageError(getMessage(error), isHook);
|
|
280
333
|
return undefined;
|
|
281
334
|
}
|
|
282
335
|
}
|
|
283
|
-
function main() {
|
|
284
|
-
const values = parseOptions();
|
|
336
|
+
function main(isHook) {
|
|
337
|
+
const values = parseOptions(isHook);
|
|
285
338
|
if (!values) {
|
|
286
339
|
return;
|
|
287
340
|
}
|
|
@@ -291,8 +344,7 @@ function main() {
|
|
|
291
344
|
}
|
|
292
345
|
const maxAgeHours = values['max-age'] === undefined ? undefined : Number(values['max-age']);
|
|
293
346
|
if (maxAgeHours !== undefined && !(maxAgeHours >= 0)) {
|
|
294
|
-
|
|
295
|
-
process.exitCode = 1;
|
|
347
|
+
printUsageError('--max-age expects a number of hours', isHook);
|
|
296
348
|
return;
|
|
297
349
|
}
|
|
298
350
|
if (process.env.CI || process.env.CLAUDE_SETUP_SKIP) {
|
|
@@ -303,19 +355,22 @@ function main() {
|
|
|
303
355
|
if (!existsSync(settingsPath)) {
|
|
304
356
|
return;
|
|
305
357
|
}
|
|
306
|
-
const isHook = values.hook === true;
|
|
307
358
|
const report = createReport();
|
|
308
359
|
const original = readFileSync(settingsPath, 'utf8');
|
|
309
360
|
try {
|
|
310
361
|
const found = findClaude();
|
|
311
|
-
if (
|
|
312
|
-
|
|
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('; ')})`);
|
|
313
370
|
}
|
|
314
|
-
claude = found;
|
|
315
|
-
setUp(root, JSON.parse(original), maxAgeHours, report);
|
|
316
371
|
}
|
|
317
372
|
catch (error) {
|
|
318
|
-
report.failures.push(
|
|
373
|
+
report.failures.push(getMessage(error));
|
|
319
374
|
}
|
|
320
375
|
finally {
|
|
321
376
|
if (readFileSync(settingsPath, 'utf8') !== original) {
|
|
@@ -324,10 +379,12 @@ function main() {
|
|
|
324
379
|
}
|
|
325
380
|
print(report, isHook);
|
|
326
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');
|
|
327
384
|
try {
|
|
328
|
-
main();
|
|
385
|
+
main(isHook);
|
|
329
386
|
}
|
|
330
387
|
catch (error) {
|
|
331
388
|
// Never fail the npm install or the session start that runs this tool
|
|
332
|
-
|
|
389
|
+
printFailure(getMessage(error), isHook);
|
|
333
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 --ignore-scripts=false"
|
|
50
|
+
"push": "npm login || exit 1; npm publish --ignore-scripts=false; status=$?; npm logout; exit $status"
|
|
51
51
|
},
|
|
52
52
|
"keywords": [
|
|
53
53
|
"claude",
|