Skip to content

Commit da670ca

Browse files
grypezclaude
andcommitted
fix(kernel-utils): recognize bare relative paths in isPathArg
Extends path detection to bare relative forms like `src/foo.ts` and `app/scripts/foo.ts` (word-char-prefixed segments containing a separator), not just absolute or `./`/`../`-prefixed paths. Provision routing was treating these as non-path args, which mis-matched commands that take relative project paths as the natural argument shape. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 04817fa commit da670ca

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

packages/kernel-utils/src/session/provision.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,19 @@ const provision = (
4343

4444
describe('isPathArg', () => {
4545
it.each([
46+
// absolute
4647
['/foo', true],
4748
['/a/b/c', true],
49+
// explicit relative
4850
['./foo', true],
4951
['../bar', true],
52+
// bare relative (word char + slash)
53+
['foo/bar', true],
54+
['app/scripts/foo.ts', true],
55+
['src/', true],
56+
// not paths
5057
['foo', false],
51-
['foo/bar', false],
58+
['--flag', false],
5259
['', false],
5360
])('isPathArg(%s) → %s', (input, expected) => {
5461
expect(isPathArg(input)).toBe(expected);

packages/kernel-utils/src/session/provision.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,22 @@ import type {
88
/**
99
* Returns true if the string looks like a file-system path (absolute or relative).
1010
*
11+
* Recognises:
12+
* - absolute paths (`/…`)
13+
* - explicit relative paths (`./…`, `../…`)
14+
* - bare relative paths (`src/foo.ts`, `app/scripts/…`) — start with a word
15+
* character and contain a path separator
16+
*
1117
* @param str - The string to test.
12-
* @returns True when the string starts with `/`, `./`, or `../`.
18+
* @returns True when the string looks like a filesystem path.
1319
*/
1420
export function isPathArg(str: string): boolean {
15-
return str.startsWith('/') || str.startsWith('./') || str.startsWith('../');
21+
return (
22+
str.startsWith('/') ||
23+
str.startsWith('./') ||
24+
str.startsWith('../') ||
25+
/^\w[\w.-]*\//u.test(str)
26+
);
1627
}
1728

1829
/**

0 commit comments

Comments
 (0)