@kaynooo/cli-code 0.15.1 → 0.16.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 +19 -19
- package/dist/cli.js +12 -36
- package/package.json +8 -14
- package/dist/hotspots-cli.js +0 -1661
- package/dist/peek-cli.js +0 -1885
- package/dist/todo-scan-cli.js +0 -1654
package/README.md
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
#
|
|
1
|
+
# src
|
|
2
2
|
|
|
3
|
-
Reads source for Claude Code in fewer calls and fewer tokens: `peek` prints the spans, declarations, usages and outlines a session would otherwise get from `sed -n N,Mp`, `grep -n` chains and whole-file reads, and `todo-scan` lists the TODO and issue-reference comments of a repository, flagging the ones whose issue is closed.
|
|
3
|
+
Reads source for Claude Code in fewer calls and fewer tokens: `src peek` prints the spans, declarations, usages and outlines a session would otherwise get from `sed -n N,Mp`, `grep -n` chains and whole-file reads, and `src todo-scan` lists the TODO and issue-reference comments of a repository, flagging the ones whose issue is closed.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
bun install -g @kaynooo/cli-code
|
|
7
|
-
peek src/a.ts:120-140 src/b.ts:1-40
|
|
8
|
-
peek --def parseCommand
|
|
9
|
-
peek --refs parseCommand packages/guard
|
|
10
|
-
peek --outline src/cli.ts README.md
|
|
11
|
-
peek --around 'TODO|FIXME' -C 2 src
|
|
12
|
-
errs -- bun check | peek
|
|
13
|
-
todo-scan
|
|
14
|
-
todo-scan --stale
|
|
15
|
-
hotspots --since '3 months ago' --limit 10
|
|
7
|
+
src peek src/a.ts:120-140 src/b.ts:1-40
|
|
8
|
+
src peek --def parseCommand
|
|
9
|
+
src peek --refs parseCommand packages/guard
|
|
10
|
+
src peek --outline src/cli.ts README.md
|
|
11
|
+
src peek --around 'TODO|FIXME' -C 2 src
|
|
12
|
+
errs -- bun check | src peek
|
|
13
|
+
src todo-scan
|
|
14
|
+
src todo-scan --stale
|
|
15
|
+
src hotspots --since '3 months ago' --limit 10
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
## peek
|
|
18
|
+
## src peek
|
|
19
19
|
|
|
20
|
-
- `peek <file[:from-to]>...` prints each span under a `<file>:<from>-<to>` header, each line with its number, so an edit can target it; `<file>:<n>` is one line, a bare `<file>` the whole file. A line past 300 characters is cut.
|
|
20
|
+
- `src peek <file[:from-to]>...` prints each span under a `<file>:<from>-<to>` header, each line with its number, so an edit can target it; `<file>:<n>` is one line, a bare `<file>` the whole file. A line past 300 characters is cut.
|
|
21
21
|
- `--def <symbol>` prints each declaration of the symbol, the comments and decorators right above it included: a `function`, `class`, `interface`, `type`, `enum`, `const`/`let`/`var` or `namespace` (and Python's `def`/`class`, Go's `func`, Rust's `fn`/`struct`/`trait`), or a class member whose parameters follow its name. Its end is where its braces close, strings and line comments left out of the count, or for Python and YAML where its indentation ends.
|
|
22
22
|
- `--refs <symbol>` lists the lines naming the symbol as a whole word, grouped by file, one trimmed line each, at most 100 (`--limit <n>`, `--full` for all, the count of the rest after them). `--defs-first` prints the symbol's declarations before them (`{definitions, references}` under `--json`).
|
|
23
|
-
- `--def` repeats for several symbols in one call (`peek --def a --def b src`); one with no declaration is named and exits 1.
|
|
23
|
+
- `--def` repeats for several symbols in one call (`src peek --def a --def b src`); one with no declaration is named and exits 1.
|
|
24
24
|
- `--outline <file>...` lists the declarations at the top of each file and the members one level inside its classes, with their line numbers; a Markdown file lists its headings.
|
|
25
25
|
- `--around <regex> -C <n>` prints the `n` (3) lines on each side of each matching line, spans that touch merged, at most 20 spans (`--limit`, `--full`, the count of the rest after them).
|
|
26
26
|
- Piped into with no file and no mode, it reads the `path:line` opening each line of the input (`errs`, `rg -n`, `grep -n`, a linter's `path:line:col`, tsc's `path(line,col)`) and prints the `-C` (3) lines around each, spans that touch merged and files in the order first named; a path outside the repository or not readable is skipped, and nothing readable exits 1.
|
|
@@ -29,17 +29,17 @@ hotspots --since '3 months ago' --limit 10
|
|
|
29
29
|
- The symbols are found by pattern, not by a type checker: a name declared twice in a file shows twice, and a symbol re-exported under another name is not followed.
|
|
30
30
|
- A path must lie inside the repository (a symlink out of it counts as outside), absolute or relative. Exits 1 when nothing is found, a file cannot be read or a span starts past the end, 2 on a usage error or a path outside the repository.
|
|
31
31
|
|
|
32
|
-
## todo-scan
|
|
32
|
+
## src todo-scan
|
|
33
33
|
|
|
34
|
-
- `todo-scan [path...]` prints `<file>:<line>: <comment>` for each comment holding `TODO`, `FIXME` or an `owner/repo#N` reference, over the same files as `peek`. A comment opens with `//` (not a URL's), `/*`, `<!--`, a `#` or `--` standing alone, or the `*` of a block comment's line; in Markdown and HTML only `<!--` does.
|
|
34
|
+
- `src todo-scan [path...]` prints `<file>:<line>: <comment>` for each comment holding `TODO`, `FIXME` or an `owner/repo#N` reference, over the same files as `src peek`. A comment opens with `//` (not a URL's), `/*`, `<!--`, a `#` or `--` standing alone, or the `*` of a block comment's line; in Markdown and HTML only `<!--` does.
|
|
35
35
|
- `--stale` looks each referenced issue up with `ft issue <n>... -r <owner/repo> --json`, one call per repository, or with `gh api` for a repository Forgejo does not have (a GitHub one), keeps the comments naming a closed issue (`src/a.ts:3: kaynooo/kayjs#823 closed: ...`) and exits 1 when it finds one; a repository neither can reach is named on stderr and makes the run exit 2 when no stale comment was found, so a clean exit never hides an unchecked issue. `ft` is needed only for a reference it can look up.
|
|
36
36
|
- `--json` prints `[{path, line, kind, text, refs}]`, each ref with its `state` under `--stale`.
|
|
37
37
|
|
|
38
|
-
## hotspots
|
|
38
|
+
## src hotspots
|
|
39
39
|
|
|
40
|
-
- `hotspots [dir]` ranks the source files by complexity times churn, so the files both hard to read and often edited come first: rank, score, churn, recent, complexity, lines, file and the file's most complex declaration. The files are the ones git keeps (`.gitignore` honoured).
|
|
40
|
+
- `src hotspots [dir]` ranks the source files by complexity times churn, so the files both hard to read and often edited come first: rank, score, churn, recent, complexity, lines, file and the file's most complex declaration. The files are the ones git keeps (`.gitignore` honoured).
|
|
41
41
|
- Churn is the commits touching the file since `--since` (any date git reads, `6 months ago` by default), counted from one `git log`. The score uses `recent`, the commits weighted by age (half as much every `--half-life`, `90d` by default, `0` to count them alike), and leaves out the commits touching more than `--bulk` files (25), the format and rename sweeps. Complexity is the decision points of the file (`if`, loops, `case`, `catch`, `&&`, `||`, `??`, ternaries, `and`/`or`) plus one, counted with comments and strings blanked; it is computed in-house (js, ts, vue, svelte, astro, kay, php, py, go, rs, rb, java, kt, swift, cs, c, cpp, scala, dart, lua and shell files are ranked) so the bin needs no dependency and reads any language the same way.
|
|
42
42
|
- `--limit <n>` (`-n`) sets how many files are listed (20, the count of the rest after them), `--full` lists all, `--json` is never cut unless `--limit` is given. `--all` keeps test files and generated files (`dist/`, `*.d.ts`, `*.min.js`, snapshots, files whose first lines say generated), `--json` prints `[{rank, path, score, churn, recent, complexity, worst, lines}]`. The most complex declaration is found from the indentation alone (a class is opened into its methods), so it reads any language the same way.
|
|
43
43
|
- Exits 1 when no file has commits in the window, 2 on a usage error or outside a git repository.
|
|
44
44
|
|
|
45
|
-
`~/.config/kaynooo-cli/hotspots.json` (`$XDG_CONFIG_HOME/kaynooo-cli/` when set) changes the defaults of `hotspots`: `since` (a date as git reads it, `6 months ago`), `bulk` (25) and `limit` (20, the files listed).
|
|
45
|
+
`~/.config/kaynooo-cli/hotspots.json` (`$XDG_CONFIG_HOME/kaynooo-cli/` when set) changes the defaults of `src hotspots`: `since` (a date as git reads it, `6 months ago`), `bulk` (25) and `limit` (20, the files listed).
|
package/dist/cli.js
CHANGED
|
@@ -1383,30 +1383,6 @@ function commandPath(scope, argv) {
|
|
|
1383
1383
|
}
|
|
1384
1384
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1385
1385
|
}
|
|
1386
|
-
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1387
|
-
if (argv[0] === COMPLETE)
|
|
1388
|
-
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1389
|
-
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1390
|
-
return printCompletionScript(name, flagValue(argv));
|
|
1391
|
-
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
1392
|
-
console.log(version ?? packageVersion());
|
|
1393
|
-
return 0;
|
|
1394
|
-
}
|
|
1395
|
-
let code;
|
|
1396
|
-
const started = performance.now();
|
|
1397
|
-
try {
|
|
1398
|
-
code = await run(argv);
|
|
1399
|
-
} catch (error) {
|
|
1400
|
-
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1401
|
-
}
|
|
1402
|
-
notifyEnd(name, code, performance.now() - started);
|
|
1403
|
-
if (usage !== false) {
|
|
1404
|
-
try {
|
|
1405
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1406
|
-
} catch {}
|
|
1407
|
-
}
|
|
1408
|
-
return code;
|
|
1409
|
-
}
|
|
1410
1386
|
// ../kit/src/folders.ts
|
|
1411
1387
|
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1412
1388
|
function ignoredFolders(extra = [], where = {}) {
|
|
@@ -1589,7 +1565,7 @@ var DEFAULT_BULK = configuredNumber("hotspots", "bulk", 25);
|
|
|
1589
1565
|
var DAY_MS2 = 86400000;
|
|
1590
1566
|
var DEFAULT_HALF_LIFE = "90d";
|
|
1591
1567
|
var DEFAULT_COUNT = configuredNumber("hotspots", "limit", 20);
|
|
1592
|
-
var USAGE = `hotspots [options] [dir]: ranks the source files under dir (here by default) by complexity times churn, the ones both hard to read and often edited first, honouring .gitignore
|
|
1568
|
+
var USAGE = `src hotspots [options] [dir]: ranks the source files under dir (here by default) by complexity times churn, the ones both hard to read and often edited first, honouring .gitignore
|
|
1593
1569
|
|
|
1594
1570
|
Complexity is the count of decision points in the file (branches, loops, cases, catches, boolean operators, ternaries) plus one, churn the commits touching it since --since (${DEFAULT_SINCE}), score their product. A commit counts for less the older it is (half as much every --half-life, 0 for all alike) and a commit touching more than --bulk files, a format or rename sweep, is left out. --by-lines scores the lines changed instead of the commits. Each file also shows how many lines changed, its author count ("solo" when one author wrote every change) and its most complex declaration, found by indentation. Test files and generated or built files are left out unless --all.
|
|
1595
1571
|
|
|
@@ -1607,7 +1583,7 @@ var OPTIONS = {
|
|
|
1607
1583
|
var HOT = 0.66;
|
|
1608
1584
|
var WARM = 0.33;
|
|
1609
1585
|
async function hotspots(args) {
|
|
1610
|
-
const { values, positionals } = parse(args, USAGE, OPTIONS, { exits: EXITS, positionals: ["[dir]"], replaces: "guessing which files are worth splitting first", examples: ["hotspots", 'hotspots src --since "3 months ago" --limit 10'] });
|
|
1586
|
+
const { values, positionals } = parse(args, USAGE, OPTIONS, { exits: EXITS, positionals: ["[dir]"], replaces: "guessing which files are worth splitting first", examples: ["hotspots", 'src hotspots src --since "3 months ago" --limit 10'] });
|
|
1611
1587
|
if (positionals.length > 1)
|
|
1612
1588
|
badUsage("give one folder");
|
|
1613
1589
|
const count = limitOf(values, DEFAULT_COUNT);
|
|
@@ -1837,14 +1813,14 @@ function locations(text) {
|
|
|
1837
1813
|
}
|
|
1838
1814
|
|
|
1839
1815
|
// src/peek.ts
|
|
1840
|
-
var USAGE2 = `peek [options] <file[:from-to]>...: prints files or line spans with their line numbers, several in one call
|
|
1816
|
+
var USAGE2 = `src peek [options] <file[:from-to]>...: prints files or line spans with their line numbers, several in one call
|
|
1841
1817
|
|
|
1842
|
-
peek src/a.ts:120-140 src/b.ts:1-40 the spans, src/a.ts:120 the one line, src/a.ts the whole file
|
|
1843
|
-
peek --def <symbol> [path...] the whole declaration of the symbol, its comments included, --def again for more symbols
|
|
1844
|
-
peek --refs <symbol> [path...] the lines naming the symbol, grouped by file, --defs-first printing its declarations before
|
|
1845
|
-
peek --outline <file>... the declarations and class members, a Markdown file's headings
|
|
1846
|
-
peek --around <regex> [-C 3] [path...] the lines around each match, overlapping ones merged
|
|
1847
|
-
<output> | peek [-C 3] the lines around each path:line the output opens a line with (errs, rg -n, grep -n, tsc, linters)
|
|
1818
|
+
src peek src/a.ts:120-140 src/b.ts:1-40 the spans, src/a.ts:120 the one line, src/a.ts the whole file
|
|
1819
|
+
src peek --def <symbol> [path...] the whole declaration of the symbol, its comments included, --def again for more symbols
|
|
1820
|
+
src peek --refs <symbol> [path...] the lines naming the symbol, grouped by file, --defs-first printing its declarations before
|
|
1821
|
+
src peek --outline <file>... the declarations and class members, a Markdown file's headings
|
|
1822
|
+
src peek --around <regex> [-C 3] [path...] the lines around each match, overlapping ones merged
|
|
1823
|
+
<output> | src peek [-C 3] the lines around each path:line the output opens a line with (errs, rg -n, grep -n, tsc, linters)
|
|
1848
1824
|
The paths default to the files git keeps here (.gitignore holds).
|
|
1849
1825
|
--refs lists at most 100 lines and --around prints at most 20 spans, the count of the rest after them (--limit <n>, --full for all).
|
|
1850
1826
|
--json prints spans as [{path, from, to, lines}], --refs as [{path, line, text}] ({definitions, references} with --defs-first), --outline as [{path, line, depth, text}], the lines never cut and the rows never counted off unless --limit is given.`;
|
|
@@ -1981,7 +1957,7 @@ async function definitionsOf(symbols, paths) {
|
|
|
1981
1957
|
return [...found.values()].flat();
|
|
1982
1958
|
}
|
|
1983
1959
|
async function peek(args) {
|
|
1984
|
-
const { values, positionals } = parse(args, USAGE2, OPTIONS2, { exits: EXITS2, positionals: ["[target...]"], replaces: "sed -n N,Mp, grep -n chains and whole-file reads", examples: [["peek src/a.ts:120-140 src/b.ts:1-40", "two spans in one call"], ["peek --def parseArgs src", "a whole declaration"]] });
|
|
1960
|
+
const { values, positionals } = parse(args, USAGE2, OPTIONS2, { exits: EXITS2, positionals: ["[target...]"], replaces: "sed -n N,Mp, grep -n chains and whole-file reads", examples: [["src peek src/a.ts:120-140 src/b.ts:1-40", "two spans in one call"], ["src peek --def parseArgs src", "a whole declaration"]] });
|
|
1985
1961
|
const modes = [values.def?.length === 0 ? undefined : values.def, values.refs, values.outline, values.around].filter((mode) => mode !== undefined && mode !== false);
|
|
1986
1962
|
const json = values.json === true;
|
|
1987
1963
|
if (values["defs-first"] === true && values.refs === undefined)
|
|
@@ -2163,7 +2139,7 @@ async function lookUp(refs, cwd) {
|
|
|
2163
2139
|
}
|
|
2164
2140
|
|
|
2165
2141
|
// src/todo-scan.ts
|
|
2166
|
-
var USAGE3 = `todo-scan [options] [path...]: lists the TODO, FIXME, HACK, XXX and owner/repo#N comments under the paths (here by default), each as <file>:<line>: <comment>, honouring .gitignore
|
|
2142
|
+
var USAGE3 = `src todo-scan [options] [path...]: lists the TODO, FIXME, HACK, XXX and owner/repo#N comments under the paths (here by default), each as <file>:<line>: <comment>, honouring .gitignore
|
|
2167
2143
|
|
|
2168
2144
|
--older <duration> keeps only the comments whose line last changed longer ago than that (30d, 12w, 6m: git blame dates each one, a file git cannot blame is left out) and shows each one's age.
|
|
2169
2145
|
|
|
@@ -2186,7 +2162,7 @@ function printLines(lines, footer) {
|
|
|
2186
2162
|
`));
|
|
2187
2163
|
}
|
|
2188
2164
|
async function todoScan(args) {
|
|
2189
|
-
const { values, positionals } = parse(args, USAGE3, OPTIONS3, { exits: EXITS3, positionals: ["[path...]"], replaces: "grep -rn TODO, then opening each issue it names", examples: ["todo-scan src", ["todo-scan --stale", "only the comments naming a closed issue"]] });
|
|
2165
|
+
const { values, positionals } = parse(args, USAGE3, OPTIONS3, { exits: EXITS3, positionals: ["[path...]"], replaces: "grep -rn TODO, then opening each issue it names", examples: ["src todo-scan src", ["src todo-scan --stale", "only the comments naming a closed issue"]] });
|
|
2190
2166
|
const cwd = process18.cwd();
|
|
2191
2167
|
const limit = limitOf(values, LIST_LIMIT);
|
|
2192
2168
|
const found = [];
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-code",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "0.16.0",
|
|
5
|
+
"description": "src: source read by spans, symbols and outlines in one call, the TODO and issue-reference comments of a repository with stale ones flagged, and the files ranked by complexity times git churn.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"homepage": "https://
|
|
8
|
+
"homepage": "https://github.com/Kayno0o/cli/tree/main/packages/code#readme",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://
|
|
11
|
+
"url": "git+https://github.com/Kayno0o/cli.git",
|
|
12
12
|
"directory": "packages/code"
|
|
13
13
|
},
|
|
14
|
-
"bugs": "https://
|
|
14
|
+
"bugs": "https://github.com/Kayno0o/cli/issues",
|
|
15
15
|
"keywords": [
|
|
16
16
|
"claude-code",
|
|
17
17
|
"cli",
|
|
@@ -21,10 +21,7 @@
|
|
|
21
21
|
"hotspots"
|
|
22
22
|
],
|
|
23
23
|
"bin": {
|
|
24
|
-
"src": "./dist/cli.js"
|
|
25
|
-
"peek": "./dist/peek-cli.js",
|
|
26
|
-
"todo-scan": "./dist/todo-scan-cli.js",
|
|
27
|
-
"hotspots": "./dist/hotspots-cli.js"
|
|
24
|
+
"src": "./dist/cli.js"
|
|
28
25
|
},
|
|
29
26
|
"files": [
|
|
30
27
|
"dist"
|
|
@@ -36,11 +33,8 @@
|
|
|
36
33
|
"registry": "https://git.kaynooo.fr/api/packages/kaynooo/npm/"
|
|
37
34
|
},
|
|
38
35
|
"scripts": {
|
|
39
|
-
"build": "$npm_execpath build src/cli.ts
|
|
40
|
-
"src": "$npm_execpath src/cli.ts"
|
|
41
|
-
"peek": "$npm_execpath src/peek-cli.ts",
|
|
42
|
-
"todo-scan": "$npm_execpath src/todo-scan-cli.ts",
|
|
43
|
-
"hotspots": "$npm_execpath src/hotspots-cli.ts"
|
|
36
|
+
"build": "$npm_execpath build src/cli.ts --target bun --outdir dist",
|
|
37
|
+
"src": "$npm_execpath src/cli.ts"
|
|
44
38
|
},
|
|
45
39
|
"dependencies": {
|
|
46
40
|
"@kaynooo/utils": "3.0.0"
|