Skip to content

Commit d091bf7

Browse files
committed
fix: skills add CTA command name
1 parent 72edc87 commit d091bf7

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

.changeset/calm-peaches-talk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
incur: patch
3+
---
4+
5+
Fixed stale `skills add` CTA commands to use the invoked CLI name when running installed binaries directly, instead of falling back to `npx`.

src/Cli.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,6 +2646,31 @@ describe('skills staleness', () => {
26462646
expect(output).toContain('skills add')
26472647
})
26482648

2649+
test('uses displayName for stale skills CTA when invoked directly', async () => {
2650+
const savedArgv1 = process.argv[1]
2651+
const savedAgent = process.env.npm_config_user_agent
2652+
const savedExec = process.env.npm_execpath
2653+
try {
2654+
process.argv[1] = '/usr/local/bin/mc'
2655+
delete process.env.npm_config_user_agent
2656+
delete process.env.npm_execpath
2657+
2658+
__mockSkillsHash = '0000000000000000'
2659+
const cli = Cli.create({ name: 'my-cli', aliases: ['mc'] })
2660+
cli.command('ping', { description: 'Health check', run: () => ({ pong: true }) })
2661+
2662+
const { output } = await serve(cli, ['ping'])
2663+
2664+
expect(output).toContain('mc skills add')
2665+
expect(output).not.toContain('npx my-cli skills add')
2666+
} finally {
2667+
if (savedArgv1 === undefined) process.argv[1] = undefined as any
2668+
else process.argv[1] = savedArgv1
2669+
process.env.npm_config_user_agent = savedAgent
2670+
process.env.npm_execpath = savedExec
2671+
}
2672+
})
2673+
26492674
test('merges skills CTA with command CTA', async () => {
26502675
__mockSkillsHash = '0000000000000000'
26512676
;(process.stdout as any).isTTY = true

src/Cli.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -555,13 +555,13 @@ async function serveImpl(
555555
const groups = new Map<string, string>()
556556
const entries = collectSkillCommands(commands, [], groups, options.rootCommand)
557557
if (Skill.hash(entries) !== stored) {
558-
const runner = detectRunner()
559-
const spec = SyncMcp.detectPackageSpecifier(name)
558+
const command =
559+
process.env.npm_config_user_agent || process.env.npm_execpath
560+
? `${detectRunner()} ${SyncMcp.detectPackageSpecifier(name)} skills add`
561+
: `${displayName} skills add`
560562
skillsCta = {
561563
description: 'Skills are out of date:',
562-
commands: [
563-
{ command: `${runner} ${spec} skills add`, description: 'sync outdated skills' },
564-
],
564+
commands: [{ command, description: 'sync outdated skills' }],
565565
}
566566
}
567567
}

src/Completions.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { Cli, Completions, z } from 'incur'
12
import { execFile, spawnSync } from 'node:child_process'
23
import { chmod, mkdtemp, rm, writeFile } from 'node:fs/promises'
34
import { tmpdir } from 'node:os'
45
import { join } from 'node:path'
5-
import { Cli, Completions, z } from 'incur'
66

77
const originalIsTTY = process.stdout.isTTY
88
const originalEnv = { ...process.env }
@@ -338,8 +338,11 @@ _incur_complete_fake_cli`,
338338
await withFakeCli(async (dir) => {
339339
const output = await exec(
340340
'fish',
341-
['-c', `${Completions.register('fish', 'fake-cli')}
342-
complete --do-complete 'fake-cli '`],
341+
[
342+
'-c',
343+
`${Completions.register('fish', 'fake-cli')}
344+
complete --do-complete 'fake-cli '`,
345+
],
343346
{ ...process.env, PATH: `${dir}:${process.env.PATH ?? ''}` },
344347
)
345348

0 commit comments

Comments
 (0)