@kaynooo/cli-code
v0.17.3
Published
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.
Maintainers
Readme
src
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.
bun install -g @kaynooo/cli-code
src peek src/a.ts:120-140 src/b.ts:1-40
src peek --def parseCommand
src peek --refs parseCommand packages/guard
src peek --outline src/cli.ts README.md
src peek --around 'TODO|FIXME' -C 2 src
errs -- bun check | src peek
src todo-scan
src todo-scan --stale
src hotspots --since '3 months ago' --limit 10src peek
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.--def <symbol>prints each declaration of the symbol, the comments and decorators right above it included: afunction,class,interface,type,enum,const/let/varornamespace(and Python'sdef/class, Go'sfunc, Rust'sfn/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.--refs <symbol>lists the lines naming the symbol as a whole word, grouped by file, one trimmed line each, at most 100 (--limit <n>,--fullfor all, the count of the rest after them).--defs-firstprints the symbol's declarations before them ({definitions, references}under--json).--defrepeats for several symbols in one call (src peek --def a --def b src); one with no declaration is named and exits 1.--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.--around <regex> -C <n>prints then(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).- Piped into with no file and no mode, it reads the
path:lineopening each line of the input (errs,rg -n,grep -n, a linter'spath:line:col, tsc'spath(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. --jsonprints the spans as[{path, from, to, lines}],--refsas[{path, line, text}]and--outlineas[{path, line, depth, text}], the lines never cut; a failure prints as{"error"}on stderr.--def,--refsand--aroundlook through the paths given, the files git keeps here by default (git ls-fileswith the untracked files.gitignorelets through), and outside a repository a walk leaving dot folders andnode_modules,dist,build,vendor,target,coverageand the names in theignorearray of~/.config/kaynooo-cli/config.jsonout; binary files and files over 2 MB are skipped.- 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.
- 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.
src todo-scan
src todo-scan [path...]prints<file>:<line>: <comment>for each comment holdingTODO,FIXMEor anowner/repo#Nreference, over the same files assrc 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.--stalelooks each referenced issue up withft issue <n>... -r <owner/repo> --json, one call per repository, or withgh apifor 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.ftis needed only for a reference it can look up.--older <duration>(30d,12w,6m) keeps the comments whose line last changed longer ago than that, dated bygit blame(a file git cannot blame is left out), and shows each one's age. At most 100 comments are listed, the count of the rest after them (--limit <n>,--fullfor all).--jsonprints[{path, line, kind, text, refs}], each ref with itsstateunder--stale, never cut unless--limitis given.
src hotspots
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 (.gitignorehonoured).- Churn is the commits touching the file since
--since(any date git reads,6 months agoby default), counted from onegit log. The score usesrecent, the commits weighted by age (half as much every--half-life,90dby default,0to count them alike), and leaves out the commits touching more than--bulkfiles (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. --limit <n>(-n) sets how many files are listed (20, the count of the rest after them),--fulllists all,--jsonis never cut unless--limitis given.--allkeeps test files and generated files (dist/,*.d.ts,*.min.js, snapshots, files whose first lines say generated),--jsonprints[{rank, path, score, churn, recent, changed, authors, solo, complexity, worst, lines}](changedthe lines added and deleted).--by-linesscores the lines changed instead of the commits, and each row also shows its author count (solowhen one author wrote every change). 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.- Exits 1 when no file has commits in the window, 2 on a usage error or outside a git repository.
~/.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).
