codigest 0.12.2__tar.gz → 0.14.0__tar.gz
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.
- {codigest-0.12.2 → codigest-0.14.0}/PKG-INFO +74 -16
- {codigest-0.12.2 → codigest-0.14.0}/README.md +73 -15
- {codigest-0.12.2 → codigest-0.14.0}/pyproject.toml +11 -1
- {codigest-0.12.2 → codigest-0.14.0}/pyproject.toml.orig +9 -1
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/__main__.py +1 -1
- codigest-0.14.0/src/codigest/commands/cap.py +183 -0
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/commands/clean.py +8 -3
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/commands/diff.py +4 -6
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/commands/digest.py +8 -2
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/commands/init.py +5 -4
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/commands/mcp.py +148 -18
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/commands/pack.py +70 -19
- codigest-0.14.0/src/codigest/commands/scan.py +425 -0
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/commands/semdiff.py +16 -11
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/commands/shell_help.py +2 -1
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/commands/status.py +24 -7
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/commands/term.py +214 -43
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/commands/tree.py +19 -14
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/cache.py +24 -8
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/callees.py +2 -1
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/common.py +35 -43
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/formats.py +32 -7
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/git_ops.py +8 -1
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/outline.py +5 -2
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/output.py +11 -7
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/presets.py +5 -2
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/processor.py +1 -5
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/prompts.py +41 -13
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/redact.py +28 -4
- codigest-0.14.0/src/codigest/core/remote.py +526 -0
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/resolver.py +26 -20
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/runner.py +35 -5
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/scanner.py +44 -31
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/semdiff.py +34 -12
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/shadow.py +91 -44
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/shellhist.py +2 -1
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/structure.py +6 -6
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/tags.py +20 -6
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/termstore.py +115 -35
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/core/tokenizer.py +2 -0
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/main.py +35 -7
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/options.py +7 -13
- codigest-0.14.0/src/codigest/shell/hook.ps1 +407 -0
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/shell/hook.sh +79 -2
- codigest-0.12.2/src/codigest/commands/cap.py +0 -78
- codigest-0.12.2/src/codigest/commands/scan.py +0 -239
- codigest-0.12.2/src/codigest/shell/hook.ps1 +0 -164
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/__init__.py +0 -0
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/commands/mark.py +0 -0
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/config.py +0 -0
- {codigest-0.12.2 → codigest-0.14.0}/src/codigest/shell/help.ps1 +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: codigest
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.14.0
|
|
4
4
|
Summary: Human-Centered Codebase Context Manager for LLMs
|
|
5
5
|
Author: Isaac Yong
|
|
6
6
|
Author-email: Isaac Yong <isaacyong@naver.com>
|
|
@@ -32,7 +32,7 @@ Description-Content-Type: text/markdown
|
|
|
32
32
|
|
|
33
33
|
**Share the code context you choose with an AI: your project, a few files, what changed, or the command that failed.**
|
|
34
34
|
|
|
35
|
-
[한국어](README.ko.md)
|
|
35
|
+
**Documentation: [nanisaac.github.io/codigest](https://nanisaac.github.io/codigest/)** (installation, guides, command reference). [한국어](README.ko.md)
|
|
36
36
|
|
|
37
37
|
<p align="center">
|
|
38
38
|
<a href="https://mcprush.com/to/codigest-mcp?ref=badge">
|
|
@@ -45,15 +45,15 @@ Description-Content-Type: text/markdown
|
|
|
45
45
|
<a href="https://mcprush.com/trust">How ratings work</a>.</sub>
|
|
46
46
|
</p>
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
Suppose a test fails and you want a coding assistant to help. Pasting the
|
|
49
|
+
error alone may omit the function under test; pasting the whole repository
|
|
50
|
+
buries the problem in unrelated files.
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
**Codigest lets you choose what context to send.** From the terminal, it can
|
|
53
|
+
collect selected files, their local imports, recent changes, or a failed
|
|
54
|
+
command and the files mentioned in its output. It packages the selection
|
|
55
|
+
as text for you to inspect and paste into ChatGPT, Claude, or another tool.
|
|
56
|
+
It does not choose a fix or call a model on its own.
|
|
57
57
|
|
|
58
58
|
## What it does
|
|
59
59
|
|
|
@@ -65,8 +65,9 @@ at.
|
|
|
65
65
|
together with the files its error points at.
|
|
66
66
|
- **Says what it included.** Every bundle reports its size, and `pack` gives the reason for each
|
|
67
67
|
file and names the ones it left out.
|
|
68
|
-
- **
|
|
69
|
-
|
|
68
|
+
- **Filters common secrets.** It excludes `.env` files and known key patterns and
|
|
69
|
+
attempts to mask tokens in code or output. Review a bundle before sharing
|
|
70
|
+
it; automated filtering cannot guarantee that every sensitive value is caught.
|
|
70
71
|
- **Works with agents.** Claude Code, Cursor and other MCP clients can request the same output.
|
|
71
72
|
|
|
72
73
|
Codigest does not call any AI model; it only prepares what you send to one. Everything runs on
|
|
@@ -80,14 +81,16 @@ your machine.
|
|
|
80
81
|
|
|
81
82
|
## Install
|
|
82
83
|
|
|
83
|
-
Prebuilt binary, no Python needed. Windows (PowerShell):
|
|
84
|
+
Prebuilt binary, no Python needed. Windows (cmd or PowerShell):
|
|
84
85
|
|
|
86
|
+
<!-- test windows -->
|
|
85
87
|
```powershell
|
|
86
|
-
irm https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex
|
|
88
|
+
powershell -ExecutionPolicy Bypass -c "irm -useb https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex"
|
|
87
89
|
```
|
|
88
90
|
|
|
89
91
|
Linux, macOS and Termux:
|
|
90
92
|
|
|
93
|
+
<!-- test unix -->
|
|
91
94
|
```bash
|
|
92
95
|
curl -fsSL https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.sh | sh
|
|
93
96
|
```
|
|
@@ -481,10 +484,13 @@ your machine, so `cap` and `term` work in any directory.
|
|
|
481
484
|
cdg cap "npm run build | tail -20" # quote pipelines
|
|
482
485
|
cdg term # last command and its output
|
|
483
486
|
cdg term -n 3 # last 3
|
|
487
|
+
cdg term -n 3-5 # commands 3 to 5 back, oldest first
|
|
484
488
|
cdg term -f # last failed one
|
|
485
489
|
cdg term --context # add the PC hostname and shell to the copied context (opt-in)
|
|
486
490
|
cdg term --here -n 3 # last 3 run in this project
|
|
487
491
|
cdg term -i 2 # only the command from 2 runs ago
|
|
492
|
+
cdg term -n 10 -l # list the last 10 commands, without their output
|
|
493
|
+
cdg term -l --format json # list as JSON (index, time, exit_code, cwd, command)
|
|
488
494
|
cdg term -n 3 --format json # the last 3 as JSON (markdown also works)
|
|
489
495
|
cdg term path # where captures are stored (override with CODIGEST_HOME)
|
|
490
496
|
cdg term clear # delete all captures
|
|
@@ -498,13 +504,63 @@ fish), without their output.
|
|
|
498
504
|
`cdg term install` edits your PowerShell profile, `~/.bashrc` and `~/.zshrc` for whichever of
|
|
499
505
|
these shells is installed; choose with `--shell powershell|bash|zsh|all`. On Windows, Git Bash
|
|
500
506
|
counts as bash. Commands still run in your current session (`cd`, variables and functions work
|
|
501
|
-
normally) and appear in your history as typed. Programs that need a real terminal are skipped: editors, pagers, `ssh`, full-screen tools (`tmux`, `zellij`, `herdr`, `k9s`, `yazi`, ...), `docker`/`podman`/`kubectl` with `-it`, `npm`/`pnpm`/`yarn`/`bun` `init` or `create`, `npx create-*`, `pip uninstall`, `gh auth login`, `az login`, `gcloud auth login` and `gcloud init`, `aws configure`, `ssh-keygen`, `sudo`, and database shells (`psql`, `mysql`, `sqlite3`, ...). A prompt that does not end its line stays invisible in the capture pipe until the next newline, so the command would look stuck.
|
|
507
|
+
normally) and appear in your history as typed. In PowerShell, `bat`, `batcat`, `delta`, `glow`, `man`, and `git diff`/`log`/`show`/`blame` or `git -p`/`--paginate` bypass capture to preserve colour and pagers; use `CODIGEST_CAP_SKIP` for other tools. Programs that need a real terminal are skipped: editors, pagers, `ssh`, full-screen tools (`tmux`, `zellij`, `herdr`, `k9s`, `yazi`, ...), `docker`/`podman`/`kubectl` with `-it`, `npm`/`pnpm`/`yarn`/`bun` `init` or `create`, `npx create-*`, `pip uninstall`, `gh auth login`, `az login`, `gcloud auth login` and `gcloud init`, `aws configure`, `ssh-keygen`, `sudo`, and database shells (`psql`, `mysql`, `sqlite3`, ...). A prompt that does not end its line stays invisible in the capture pipe until the next newline, so the command would look stuck.
|
|
502
508
|
|
|
503
509
|
- Skip one command: start the line with a space.
|
|
504
510
|
- Skip more programs: `$env:CODIGEST_CAP_SKIP = '^\s*(myrepl|mytui)\b'` (bash/zsh:
|
|
505
511
|
`export CODIGEST_CAP_SKIP='^(myrepl|mytui)( |$)'`, an extended regex).
|
|
506
512
|
- Disable for a session: `$env:CODIGEST_NOCAP = 1` (bash/zsh: `export CODIGEST_NOCAP=1`).
|
|
507
|
-
- Remove the hooks: `cdg term uninstall`.
|
|
513
|
+
- Remove the hooks: `cdg term uninstall`. Each startup file gets back the exact bytes it had
|
|
514
|
+
before install (line endings, BOM, final newline); one that install created is deleted with
|
|
515
|
+
any folder made for it, as are the hook copies in the data folder. Captured commands stay
|
|
516
|
+
until `cdg term clear`.
|
|
517
|
+
|
|
518
|
+
##### Programs that run other commands
|
|
519
|
+
|
|
520
|
+
A program that runs a command line for you, such as `hf` from
|
|
521
|
+
[hanfix](https://github.com/NaNIsaac/hanfix) (it re-runs the previous command typed with the Korean
|
|
522
|
+
layout on), would otherwise be captured as a whole, and the command it runs would get the capture
|
|
523
|
+
pipe instead of the terminal. Such a program can work with the hook in two steps:
|
|
524
|
+
|
|
525
|
+
1. Add its command names to `CODIGEST_RUNNERS` when it loads; the hook does not capture a line that
|
|
526
|
+
starts with one of them. Append, so the order in which the startup file loads it and codigest
|
|
527
|
+
does not matter:
|
|
528
|
+
- PowerShell: `$global:CODIGEST_RUNNERS += 'hf'`
|
|
529
|
+
- bash/zsh: `CODIGEST_RUNNERS="${CODIGEST_RUNNERS-} hf"` (a shell variable, space-separated)
|
|
530
|
+
2. Run each command line through `__cdg_run` when it is defined, looked up when the line runs. It
|
|
531
|
+
applies the hook's own rules to that line: a program that needs the terminal keeps it, anything
|
|
532
|
+
else is captured under that line.
|
|
533
|
+
- PowerShell: `if (Get-Command __cdg_run -CommandType Function -ErrorAction Ignore) { . __cdg_run $line } else { Invoke-Expression $line }`
|
|
534
|
+
- bash/zsh: `if typeset -f __cdg_run >/dev/null; then __cdg_run "$line"; else eval "$line"; fi`
|
|
535
|
+
|
|
536
|
+
A program that does not do step 2 can still be listed in `CODIGEST_RUNNERS`: what it runs then keeps
|
|
537
|
+
the terminal and is not captured. [thefuck](https://github.com/nvbn/thefuck) is one:
|
|
538
|
+
`$global:CODIGEST_RUNNERS += 'fuck'` (bash/zsh: `CODIGEST_RUNNERS="${CODIGEST_RUNNERS-} fuck"`).
|
|
539
|
+
|
|
540
|
+
A program can instead replace the typed line before it runs: when Enter is pressed, the hook calls
|
|
541
|
+
each function listed in `CODIGEST_REWRITERS` with the line, and the first one that claims it gives
|
|
542
|
+
the line to run. That line then goes on as if typed: it is the one in the shell history (PSReadLine's
|
|
543
|
+
and the engine's in PowerShell), the hook's rules decide whether it is captured, and `$?` is its own.
|
|
544
|
+
`hf` typed alone can work this way; `hf` inside a longer line still uses the steps above.
|
|
545
|
+
|
|
546
|
+
- PowerShell: `$global:CODIGEST_REWRITERS += 'name'`. The function gets the line and returns
|
|
547
|
+
`$null` (not its line), the new line, or `@{ Line = <new>; Confirm = $true }` to ask first.
|
|
548
|
+
- bash/zsh: `CODIGEST_REWRITERS="${CODIGEST_REWRITERS-} name"`. The function gets the line, sets
|
|
549
|
+
`REPLY` to the new line and returns 0, or 2 to ask first, or returns 1 when it is not its line.
|
|
550
|
+
- When asked, the hook shows the new line with `[Enter / Ctrl+C]`: Enter runs it, any other key
|
|
551
|
+
drops it (nothing runs, nothing is added to history).
|
|
552
|
+
- A function that fails, returns anything else, or gives a line that does not parse leaves the line
|
|
553
|
+
as typed, without a message. So does a result that comes after more than 200 ms: it is discarded.
|
|
554
|
+
This is not a timeout: the hook waits for the function to return, so one that hangs blocks Enter.
|
|
555
|
+
- The function should not add to history itself.
|
|
556
|
+
- A line typed with a leading space keeps it, so it stays out of the capture.
|
|
557
|
+
- Not in a PowerShell remote session, nested prompt or the debugger.
|
|
558
|
+
|
|
559
|
+
In PowerShell the hook works with another `PSConsoleHostReadLine` (VS Code's shell integration,
|
|
560
|
+
atuin): it calls that one for the line, so it sees the line as typed, and only wraps what it
|
|
561
|
+
returns. When one is loaded after the hook, the hook puts itself back on top while the shell
|
|
562
|
+
waits for input, also when that one reads the line itself (atuin does); the first line after it
|
|
563
|
+
is not captured.
|
|
508
564
|
|
|
509
565
|
The profile loads a copy of the hook that `cdg term install` puts in the data folder (`shell/` next to the captures), not the file inside the package. After updating codigest, run `cdg term install` again to refresh it.
|
|
510
566
|
|
|
@@ -516,6 +572,8 @@ Limitations:
|
|
|
516
572
|
normally. In bash, neither are lines that start with a subshell `( ... )`.
|
|
517
573
|
- In bash the hook uses the DEBUG trap and keeps one set before the first prompt (starship,
|
|
518
574
|
bash-preexec); a DEBUG trap set later replaces it.
|
|
575
|
+
- In bash, VS Code's shell integration loaded after the hook stops the capture
|
|
576
|
+
([#52](https://github.com/NaNIsaac/codigest/issues/52)).
|
|
519
577
|
- Long output is bounded: the PowerShell hook keeps the first and last 2,000 lines, and a bash or
|
|
520
578
|
zsh capture file over 4 MB is read 1 MB from each end. The store then keeps 64 KB.
|
|
521
579
|
- In PowerShell, a command counts as failed when its exit code is non-zero or an error reached
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
**Share the code context you choose with an AI: your project, a few files, what changed, or the command that failed.**
|
|
8
8
|
|
|
9
|
-
[한국어](README.ko.md)
|
|
9
|
+
**Documentation: [nanisaac.github.io/codigest](https://nanisaac.github.io/codigest/)** (installation, guides, command reference). [한국어](README.ko.md)
|
|
10
10
|
|
|
11
11
|
<p align="center">
|
|
12
12
|
<a href="https://mcprush.com/to/codigest-mcp?ref=badge">
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
<a href="https://mcprush.com/trust">How ratings work</a>.</sub>
|
|
20
20
|
</p>
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
Suppose a test fails and you want a coding assistant to help. Pasting the
|
|
23
|
+
error alone may omit the function under test; pasting the whole repository
|
|
24
|
+
buries the problem in unrelated files.
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
**Codigest lets you choose what context to send.** From the terminal, it can
|
|
27
|
+
collect selected files, their local imports, recent changes, or a failed
|
|
28
|
+
command and the files mentioned in its output. It packages the selection
|
|
29
|
+
as text for you to inspect and paste into ChatGPT, Claude, or another tool.
|
|
30
|
+
It does not choose a fix or call a model on its own.
|
|
31
31
|
|
|
32
32
|
## What it does
|
|
33
33
|
|
|
@@ -39,8 +39,9 @@ at.
|
|
|
39
39
|
together with the files its error points at.
|
|
40
40
|
- **Says what it included.** Every bundle reports its size, and `pack` gives the reason for each
|
|
41
41
|
file and names the ones it left out.
|
|
42
|
-
- **
|
|
43
|
-
|
|
42
|
+
- **Filters common secrets.** It excludes `.env` files and known key patterns and
|
|
43
|
+
attempts to mask tokens in code or output. Review a bundle before sharing
|
|
44
|
+
it; automated filtering cannot guarantee that every sensitive value is caught.
|
|
44
45
|
- **Works with agents.** Claude Code, Cursor and other MCP clients can request the same output.
|
|
45
46
|
|
|
46
47
|
Codigest does not call any AI model; it only prepares what you send to one. Everything runs on
|
|
@@ -54,14 +55,16 @@ your machine.
|
|
|
54
55
|
|
|
55
56
|
## Install
|
|
56
57
|
|
|
57
|
-
Prebuilt binary, no Python needed. Windows (PowerShell):
|
|
58
|
+
Prebuilt binary, no Python needed. Windows (cmd or PowerShell):
|
|
58
59
|
|
|
60
|
+
<!-- test windows -->
|
|
59
61
|
```powershell
|
|
60
|
-
irm https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex
|
|
62
|
+
powershell -ExecutionPolicy Bypass -c "irm -useb https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex"
|
|
61
63
|
```
|
|
62
64
|
|
|
63
65
|
Linux, macOS and Termux:
|
|
64
66
|
|
|
67
|
+
<!-- test unix -->
|
|
65
68
|
```bash
|
|
66
69
|
curl -fsSL https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.sh | sh
|
|
67
70
|
```
|
|
@@ -455,10 +458,13 @@ your machine, so `cap` and `term` work in any directory.
|
|
|
455
458
|
cdg cap "npm run build | tail -20" # quote pipelines
|
|
456
459
|
cdg term # last command and its output
|
|
457
460
|
cdg term -n 3 # last 3
|
|
461
|
+
cdg term -n 3-5 # commands 3 to 5 back, oldest first
|
|
458
462
|
cdg term -f # last failed one
|
|
459
463
|
cdg term --context # add the PC hostname and shell to the copied context (opt-in)
|
|
460
464
|
cdg term --here -n 3 # last 3 run in this project
|
|
461
465
|
cdg term -i 2 # only the command from 2 runs ago
|
|
466
|
+
cdg term -n 10 -l # list the last 10 commands, without their output
|
|
467
|
+
cdg term -l --format json # list as JSON (index, time, exit_code, cwd, command)
|
|
462
468
|
cdg term -n 3 --format json # the last 3 as JSON (markdown also works)
|
|
463
469
|
cdg term path # where captures are stored (override with CODIGEST_HOME)
|
|
464
470
|
cdg term clear # delete all captures
|
|
@@ -472,13 +478,63 @@ fish), without their output.
|
|
|
472
478
|
`cdg term install` edits your PowerShell profile, `~/.bashrc` and `~/.zshrc` for whichever of
|
|
473
479
|
these shells is installed; choose with `--shell powershell|bash|zsh|all`. On Windows, Git Bash
|
|
474
480
|
counts as bash. Commands still run in your current session (`cd`, variables and functions work
|
|
475
|
-
normally) and appear in your history as typed. Programs that need a real terminal are skipped: editors, pagers, `ssh`, full-screen tools (`tmux`, `zellij`, `herdr`, `k9s`, `yazi`, ...), `docker`/`podman`/`kubectl` with `-it`, `npm`/`pnpm`/`yarn`/`bun` `init` or `create`, `npx create-*`, `pip uninstall`, `gh auth login`, `az login`, `gcloud auth login` and `gcloud init`, `aws configure`, `ssh-keygen`, `sudo`, and database shells (`psql`, `mysql`, `sqlite3`, ...). A prompt that does not end its line stays invisible in the capture pipe until the next newline, so the command would look stuck.
|
|
481
|
+
normally) and appear in your history as typed. In PowerShell, `bat`, `batcat`, `delta`, `glow`, `man`, and `git diff`/`log`/`show`/`blame` or `git -p`/`--paginate` bypass capture to preserve colour and pagers; use `CODIGEST_CAP_SKIP` for other tools. Programs that need a real terminal are skipped: editors, pagers, `ssh`, full-screen tools (`tmux`, `zellij`, `herdr`, `k9s`, `yazi`, ...), `docker`/`podman`/`kubectl` with `-it`, `npm`/`pnpm`/`yarn`/`bun` `init` or `create`, `npx create-*`, `pip uninstall`, `gh auth login`, `az login`, `gcloud auth login` and `gcloud init`, `aws configure`, `ssh-keygen`, `sudo`, and database shells (`psql`, `mysql`, `sqlite3`, ...). A prompt that does not end its line stays invisible in the capture pipe until the next newline, so the command would look stuck.
|
|
476
482
|
|
|
477
483
|
- Skip one command: start the line with a space.
|
|
478
484
|
- Skip more programs: `$env:CODIGEST_CAP_SKIP = '^\s*(myrepl|mytui)\b'` (bash/zsh:
|
|
479
485
|
`export CODIGEST_CAP_SKIP='^(myrepl|mytui)( |$)'`, an extended regex).
|
|
480
486
|
- Disable for a session: `$env:CODIGEST_NOCAP = 1` (bash/zsh: `export CODIGEST_NOCAP=1`).
|
|
481
|
-
- Remove the hooks: `cdg term uninstall`.
|
|
487
|
+
- Remove the hooks: `cdg term uninstall`. Each startup file gets back the exact bytes it had
|
|
488
|
+
before install (line endings, BOM, final newline); one that install created is deleted with
|
|
489
|
+
any folder made for it, as are the hook copies in the data folder. Captured commands stay
|
|
490
|
+
until `cdg term clear`.
|
|
491
|
+
|
|
492
|
+
##### Programs that run other commands
|
|
493
|
+
|
|
494
|
+
A program that runs a command line for you, such as `hf` from
|
|
495
|
+
[hanfix](https://github.com/NaNIsaac/hanfix) (it re-runs the previous command typed with the Korean
|
|
496
|
+
layout on), would otherwise be captured as a whole, and the command it runs would get the capture
|
|
497
|
+
pipe instead of the terminal. Such a program can work with the hook in two steps:
|
|
498
|
+
|
|
499
|
+
1. Add its command names to `CODIGEST_RUNNERS` when it loads; the hook does not capture a line that
|
|
500
|
+
starts with one of them. Append, so the order in which the startup file loads it and codigest
|
|
501
|
+
does not matter:
|
|
502
|
+
- PowerShell: `$global:CODIGEST_RUNNERS += 'hf'`
|
|
503
|
+
- bash/zsh: `CODIGEST_RUNNERS="${CODIGEST_RUNNERS-} hf"` (a shell variable, space-separated)
|
|
504
|
+
2. Run each command line through `__cdg_run` when it is defined, looked up when the line runs. It
|
|
505
|
+
applies the hook's own rules to that line: a program that needs the terminal keeps it, anything
|
|
506
|
+
else is captured under that line.
|
|
507
|
+
- PowerShell: `if (Get-Command __cdg_run -CommandType Function -ErrorAction Ignore) { . __cdg_run $line } else { Invoke-Expression $line }`
|
|
508
|
+
- bash/zsh: `if typeset -f __cdg_run >/dev/null; then __cdg_run "$line"; else eval "$line"; fi`
|
|
509
|
+
|
|
510
|
+
A program that does not do step 2 can still be listed in `CODIGEST_RUNNERS`: what it runs then keeps
|
|
511
|
+
the terminal and is not captured. [thefuck](https://github.com/nvbn/thefuck) is one:
|
|
512
|
+
`$global:CODIGEST_RUNNERS += 'fuck'` (bash/zsh: `CODIGEST_RUNNERS="${CODIGEST_RUNNERS-} fuck"`).
|
|
513
|
+
|
|
514
|
+
A program can instead replace the typed line before it runs: when Enter is pressed, the hook calls
|
|
515
|
+
each function listed in `CODIGEST_REWRITERS` with the line, and the first one that claims it gives
|
|
516
|
+
the line to run. That line then goes on as if typed: it is the one in the shell history (PSReadLine's
|
|
517
|
+
and the engine's in PowerShell), the hook's rules decide whether it is captured, and `$?` is its own.
|
|
518
|
+
`hf` typed alone can work this way; `hf` inside a longer line still uses the steps above.
|
|
519
|
+
|
|
520
|
+
- PowerShell: `$global:CODIGEST_REWRITERS += 'name'`. The function gets the line and returns
|
|
521
|
+
`$null` (not its line), the new line, or `@{ Line = <new>; Confirm = $true }` to ask first.
|
|
522
|
+
- bash/zsh: `CODIGEST_REWRITERS="${CODIGEST_REWRITERS-} name"`. The function gets the line, sets
|
|
523
|
+
`REPLY` to the new line and returns 0, or 2 to ask first, or returns 1 when it is not its line.
|
|
524
|
+
- When asked, the hook shows the new line with `[Enter / Ctrl+C]`: Enter runs it, any other key
|
|
525
|
+
drops it (nothing runs, nothing is added to history).
|
|
526
|
+
- A function that fails, returns anything else, or gives a line that does not parse leaves the line
|
|
527
|
+
as typed, without a message. So does a result that comes after more than 200 ms: it is discarded.
|
|
528
|
+
This is not a timeout: the hook waits for the function to return, so one that hangs blocks Enter.
|
|
529
|
+
- The function should not add to history itself.
|
|
530
|
+
- A line typed with a leading space keeps it, so it stays out of the capture.
|
|
531
|
+
- Not in a PowerShell remote session, nested prompt or the debugger.
|
|
532
|
+
|
|
533
|
+
In PowerShell the hook works with another `PSConsoleHostReadLine` (VS Code's shell integration,
|
|
534
|
+
atuin): it calls that one for the line, so it sees the line as typed, and only wraps what it
|
|
535
|
+
returns. When one is loaded after the hook, the hook puts itself back on top while the shell
|
|
536
|
+
waits for input, also when that one reads the line itself (atuin does); the first line after it
|
|
537
|
+
is not captured.
|
|
482
538
|
|
|
483
539
|
The profile loads a copy of the hook that `cdg term install` puts in the data folder (`shell/` next to the captures), not the file inside the package. After updating codigest, run `cdg term install` again to refresh it.
|
|
484
540
|
|
|
@@ -490,6 +546,8 @@ Limitations:
|
|
|
490
546
|
normally. In bash, neither are lines that start with a subshell `( ... )`.
|
|
491
547
|
- In bash the hook uses the DEBUG trap and keeps one set before the first prompt (starship,
|
|
492
548
|
bash-preexec); a DEBUG trap set later replaces it.
|
|
549
|
+
- In bash, VS Code's shell integration loaded after the hook stops the capture
|
|
550
|
+
([#52](https://github.com/NaNIsaac/codigest/issues/52)).
|
|
493
551
|
- Long output is bounded: the PowerShell hook keeps the first and last 2,000 lines, and a bash or
|
|
494
552
|
zsh capture file over 4 MB is read 1 MB from each end. The store then keeps 64 KB.
|
|
495
553
|
- In PowerShell, a command counts as failed when its exit code is non-zero or an error reached
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "codigest"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.14.0"
|
|
4
4
|
description = "Human-Centered Codebase Context Manager for LLMs"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.15.0b1"
|
|
@@ -45,6 +45,13 @@ build-backend = "uv_build"
|
|
|
45
45
|
[tool.ruff]
|
|
46
46
|
line-length = 100
|
|
47
47
|
|
|
48
|
+
[tool.ruff.lint]
|
|
49
|
+
extend-select = [
|
|
50
|
+
"B",
|
|
51
|
+
"I",
|
|
52
|
+
"UP",
|
|
53
|
+
]
|
|
54
|
+
|
|
48
55
|
[tool.ruff.lint.extend-per-file-ignores]
|
|
49
56
|
"src/codigest/commands/cap.py" = ["I001"]
|
|
50
57
|
"src/codigest/commands/clean.py" = ["B008"]
|
|
@@ -158,3 +165,6 @@ line-length = 100
|
|
|
158
165
|
"PIE807",
|
|
159
166
|
"UP012",
|
|
160
167
|
]
|
|
168
|
+
|
|
169
|
+
[tool.pr-land]
|
|
170
|
+
test-command = "uv run --with pytest --with pywinpty pytest -q -p no:cacheprovider --basetemp {basetemp}"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "codigest"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.14.0"
|
|
4
4
|
description = "Human-Centered Codebase Context Manager for LLMs"
|
|
5
5
|
authors = [{ name = "Isaac Yong", email = "isaacyong@naver.com" }]
|
|
6
6
|
readme = "README.md"
|
|
@@ -41,6 +41,9 @@ build-backend = "uv_build"
|
|
|
41
41
|
[tool.ruff]
|
|
42
42
|
line-length = 100
|
|
43
43
|
|
|
44
|
+
[tool.ruff.lint]
|
|
45
|
+
extend-select = ["B", "I", "UP"]
|
|
46
|
+
|
|
44
47
|
# violations present when ruff became mandatory in CI; remove entries as they are fixed
|
|
45
48
|
[tool.ruff.lint.extend-per-file-ignores]
|
|
46
49
|
"src/codigest/commands/cap.py" = ["I001"]
|
|
@@ -75,3 +78,8 @@ line-length = 100
|
|
|
75
78
|
"src/codigest/main.py" = ["BLE001", "I001"]
|
|
76
79
|
"src/codigest/options.py" = ["I001"]
|
|
77
80
|
"tests/test_term_install.py" = ["PIE807", "UP012"]
|
|
81
|
+
|
|
82
|
+
# Test command for merge tooling that runs the suite before landing a PR (pytest and
|
|
83
|
+
# pywinpty are not project dependencies; the suite drives a real terminal on Windows).
|
|
84
|
+
[tool.pr-land]
|
|
85
|
+
test-command = "uv run --with pytest --with pywinpty pytest -q -p no:cacheprovider --basetemp {basetemp}"
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"""
|
|
2
|
+
`cdg cap` -- run a command transparently and record it for later recall.
|
|
3
|
+
|
|
4
|
+
Registered on the root app as a single command (not a Typer group), so the
|
|
5
|
+
first word after `cap` is treated as the wrapped program rather than a
|
|
6
|
+
subcommand. Everything after `cap` belongs to the wrapped command, so flags
|
|
7
|
+
like `-n` are never stolen from it. Only output options written before the
|
|
8
|
+
command (`cdg cap -c -- pytest`) are read, by hand, and they make `cap` hand
|
|
9
|
+
over the result like `cdg term` would.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import base64
|
|
13
|
+
import shutil
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Annotated
|
|
17
|
+
|
|
18
|
+
import typer
|
|
19
|
+
from rich.console import Console
|
|
20
|
+
|
|
21
|
+
from ..core.formats import Format
|
|
22
|
+
lazy from ..core import runner, termstore, shellhist
|
|
23
|
+
lazy from ..core.output import OutputHandler
|
|
24
|
+
|
|
25
|
+
err_console = Console(stderr=True)
|
|
26
|
+
|
|
27
|
+
CONTEXT_SETTINGS = {
|
|
28
|
+
"allow_extra_args": True,
|
|
29
|
+
"ignore_unknown_options": True,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
CommandArgument = Annotated[
|
|
33
|
+
list[str] | None,
|
|
34
|
+
typer.Argument(
|
|
35
|
+
metavar="COMMAND...",
|
|
36
|
+
help=(
|
|
37
|
+
"Command to run. Prefix with `--` so its flags are passed through. Output options "
|
|
38
|
+
"before it (-c, -s, -o FILE, --format) also hand over the result like `cdg term`."
|
|
39
|
+
),
|
|
40
|
+
),
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass(slots=True)
|
|
45
|
+
class Delivery:
|
|
46
|
+
"""What `cap` does with the result once the command has run."""
|
|
47
|
+
|
|
48
|
+
copy: bool | None = None
|
|
49
|
+
stdout: bool = False
|
|
50
|
+
output: Path | None = None
|
|
51
|
+
format: Format = Format.XML
|
|
52
|
+
requested: bool = False
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def split_options(args: list[str]) -> tuple[Delivery, list[str]]:
|
|
56
|
+
"""Reads the output options in front of the command. Parsed by hand because the
|
|
57
|
+
option parser would also pick them out of the wrapped command's own arguments."""
|
|
58
|
+
delivery = Delivery()
|
|
59
|
+
i = 0
|
|
60
|
+
while i < len(args):
|
|
61
|
+
name, eq, inline = args[i].partition("=")
|
|
62
|
+
if not (eq and name.startswith("--")):
|
|
63
|
+
name, inline = args[i], None
|
|
64
|
+
takes_value = name in ("-o", "--output", "--format")
|
|
65
|
+
if inline is not None and not takes_value:
|
|
66
|
+
break
|
|
67
|
+
match name:
|
|
68
|
+
case "-c" | "--copy":
|
|
69
|
+
delivery.copy = True
|
|
70
|
+
case "--no-copy":
|
|
71
|
+
delivery.copy = False
|
|
72
|
+
case "-s" | "--stdout":
|
|
73
|
+
delivery.stdout = True
|
|
74
|
+
case "--":
|
|
75
|
+
return delivery, args[i + 1 :]
|
|
76
|
+
case "-o" | "--output" | "--format":
|
|
77
|
+
if inline is None:
|
|
78
|
+
i += 1
|
|
79
|
+
if i == len(args):
|
|
80
|
+
raise ValueError(f"{name} needs a value")
|
|
81
|
+
inline = args[i]
|
|
82
|
+
if name == "--format":
|
|
83
|
+
try:
|
|
84
|
+
delivery.format = Format(inline.lower())
|
|
85
|
+
except ValueError:
|
|
86
|
+
raise ValueError(
|
|
87
|
+
f"unknown format '{inline}' (xml, markdown or json)"
|
|
88
|
+
) from None
|
|
89
|
+
else:
|
|
90
|
+
delivery.output = Path(inline)
|
|
91
|
+
case _:
|
|
92
|
+
break
|
|
93
|
+
delivery.requested = True
|
|
94
|
+
i += 1
|
|
95
|
+
return delivery, args[i:]
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def script_block(args: list[str]) -> str | None:
|
|
99
|
+
"""PowerShell hands a `{ ... }` argument to a program as `-encodedCommand <base64 of
|
|
100
|
+
UTF-16LE>` followed by `-inputFormat xml -outputFormat text`, the form `pwsh { ... }`
|
|
101
|
+
receives. Returns the script text."""
|
|
102
|
+
if len(args) < 2 or args[0].lower() != "-encodedcommand":
|
|
103
|
+
return None
|
|
104
|
+
try:
|
|
105
|
+
return base64.b64decode(args[1], validate=True).decode("utf-16-le")
|
|
106
|
+
except ValueError:
|
|
107
|
+
return None
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def handle(ctx: typer.Context, command: CommandArgument = None) -> None:
|
|
111
|
+
"""
|
|
112
|
+
Run a command as usual and keep its output for `pack` and `term`.
|
|
113
|
+
|
|
114
|
+
Examples:
|
|
115
|
+
|
|
116
|
+
cdg cap -- pytest -q
|
|
117
|
+
|
|
118
|
+
cdg cap "npm run build | tail -20"
|
|
119
|
+
|
|
120
|
+
cdg cap --copy { Get-ChildItem | Sort-Object Length }
|
|
121
|
+
"""
|
|
122
|
+
try:
|
|
123
|
+
delivery, args = split_options([*(command or []), *ctx.args])
|
|
124
|
+
except ValueError as e:
|
|
125
|
+
err_console.print(f"[red][Error][/red] {e}")
|
|
126
|
+
raise typer.Exit(code=2) from e
|
|
127
|
+
|
|
128
|
+
if not args:
|
|
129
|
+
err_console.print(
|
|
130
|
+
"[yellow]Usage:[/yellow] cdg cap -- <command>\n[dim]Example: cdg cap -- pytest -q[/dim]"
|
|
131
|
+
)
|
|
132
|
+
raise typer.Exit(code=2)
|
|
133
|
+
|
|
134
|
+
try:
|
|
135
|
+
if (script := script_block(args)) is not None:
|
|
136
|
+
shell = shutil.which("pwsh") or shutil.which("powershell")
|
|
137
|
+
if not shell:
|
|
138
|
+
err_console.print("[red][Error][/red] PowerShell is needed to run a { } block")
|
|
139
|
+
raise typer.Exit(code=127)
|
|
140
|
+
command_text = script.strip()
|
|
141
|
+
exit_code, output, duration_ms = runner.run_argv(
|
|
142
|
+
[shell, "-NoProfile", "-EncodedCommand", args[1]]
|
|
143
|
+
)
|
|
144
|
+
else:
|
|
145
|
+
command_text = runner.join_command(args)
|
|
146
|
+
exit_code, output, duration_ms = runner.run(args)
|
|
147
|
+
except FileNotFoundError as e:
|
|
148
|
+
err_console.print(f"[red][Error][/red] Command not found: {args[0]}")
|
|
149
|
+
raise typer.Exit(code=127) from e
|
|
150
|
+
except RuntimeError as e:
|
|
151
|
+
err_console.print(f"[red][Error][/red] {e}")
|
|
152
|
+
raise typer.Exit(code=1) from e
|
|
153
|
+
|
|
154
|
+
entry = termstore.Entry(
|
|
155
|
+
command=command_text,
|
|
156
|
+
output=output,
|
|
157
|
+
exit_code=exit_code,
|
|
158
|
+
cwd=str(Path.cwd()),
|
|
159
|
+
shell=shellhist.detect_shell(),
|
|
160
|
+
started_at=termstore.now_iso(),
|
|
161
|
+
duration_ms=duration_ms,
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
try:
|
|
165
|
+
# Normalizes, redacts and truncates `entry` in place: what is delivered is what is stored.
|
|
166
|
+
termstore.append_entry(entry)
|
|
167
|
+
except OSError as e:
|
|
168
|
+
err_console.print(f"[dim]Capture not stored: {e}[/dim]")
|
|
169
|
+
else:
|
|
170
|
+
if delivery.requested:
|
|
171
|
+
render = {
|
|
172
|
+
Format.XML: termstore.render,
|
|
173
|
+
Format.MARKDOWN: termstore.render_markdown,
|
|
174
|
+
Format.JSON: termstore.render_json,
|
|
175
|
+
}[delivery.format]
|
|
176
|
+
handler = OutputHandler(
|
|
177
|
+
stdout=delivery.stdout, copy=delivery.copy, output=delivery.output
|
|
178
|
+
)
|
|
179
|
+
handler.handle_output(
|
|
180
|
+
render([entry], include_context=False), item_name="1 terminal entry"
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
raise typer.Exit(code=exit_code)
|
|
@@ -8,6 +8,7 @@ lazy from ..core import common
|
|
|
8
8
|
app = typer.Typer()
|
|
9
9
|
console = Console()
|
|
10
10
|
|
|
11
|
+
|
|
11
12
|
@app.callback(invoke_without_command=True)
|
|
12
13
|
def handle(
|
|
13
14
|
target: Path = typer.Argument(
|
|
@@ -16,9 +17,11 @@ def handle(
|
|
|
16
17
|
exists=True,
|
|
17
18
|
file_okay=False,
|
|
18
19
|
dir_okay=True,
|
|
19
|
-
resolve_path=True
|
|
20
|
+
resolve_path=True,
|
|
21
|
+
),
|
|
22
|
+
yes: bool = typer.Option(
|
|
23
|
+
False, "-y", "--yes", "-f", "--force", help="Skip confirmation prompt"
|
|
20
24
|
),
|
|
21
|
-
yes: bool = typer.Option(False, "-y", "--yes", "-f", "--force", help="Skip confirmation prompt"),
|
|
22
25
|
) -> None:
|
|
23
26
|
"""
|
|
24
27
|
Delete .codigest/: the config, the baseline and the cache.
|
|
@@ -32,7 +35,9 @@ def handle(
|
|
|
32
35
|
return
|
|
33
36
|
|
|
34
37
|
if not yes:
|
|
35
|
-
console.print(
|
|
38
|
+
console.print(
|
|
39
|
+
f"[yellow]Warning: This will remove [bold]{codigest_dir}[/bold] and all stored context/anchors.[/yellow]"
|
|
40
|
+
)
|
|
36
41
|
if not typer.confirm("Are you sure you want to remove .codigest?"):
|
|
37
42
|
console.print("[red]Aborted.[/red]")
|
|
38
43
|
raise typer.Exit()
|
|
@@ -10,6 +10,7 @@ lazy from ..core.output import OutputHandler, spinner
|
|
|
10
10
|
|
|
11
11
|
app = typer.Typer()
|
|
12
12
|
|
|
13
|
+
|
|
13
14
|
@app.callback(invoke_without_command=True)
|
|
14
15
|
def handle(
|
|
15
16
|
target: Path = typer.Argument(
|
|
@@ -18,7 +19,7 @@ def handle(
|
|
|
18
19
|
exists=True,
|
|
19
20
|
file_okay=False,
|
|
20
21
|
dir_okay=True,
|
|
21
|
-
resolve_path=True
|
|
22
|
+
resolve_path=True,
|
|
22
23
|
),
|
|
23
24
|
copy: CopyOption = None,
|
|
24
25
|
output: OutputOption = None,
|
|
@@ -49,14 +50,11 @@ def handle(
|
|
|
49
50
|
|
|
50
51
|
# [2] Calculate Diff via Context
|
|
51
52
|
with spinner(log_console, "[bold blue]Analyzing changes...[/bold blue]"):
|
|
52
|
-
|
|
53
|
-
|
|
54
53
|
current_files = ctx.get_target_files(resolve_deps=resolve)
|
|
55
54
|
|
|
56
55
|
# Compare Working Tree vs Anchor
|
|
57
56
|
diff_content = redact_diff(anchor.get_changes(current_files))
|
|
58
57
|
|
|
59
|
-
|
|
60
58
|
if not diff_content.strip():
|
|
61
59
|
log_console.print("[green]No changes since the last mark.[/green]")
|
|
62
60
|
return
|
|
@@ -69,7 +67,7 @@ def handle(
|
|
|
69
67
|
project_name=root_path.name,
|
|
70
68
|
context_message=f"since cdg mark ({last_update})",
|
|
71
69
|
diff_content=diff_content,
|
|
72
|
-
instruction=message
|
|
70
|
+
instruction=message,
|
|
73
71
|
)
|
|
74
72
|
except Exception:
|
|
75
73
|
# Fallback if template fails (using safe escaping via tags)
|
|
@@ -79,4 +77,4 @@ def handle(
|
|
|
79
77
|
# [4] Output
|
|
80
78
|
log_console.print(f"[bold green]Changes Detected![/bold green] ({len(formatted_diff)} chars)")
|
|
81
79
|
|
|
82
|
-
handler.handle_output(formatted_diff, item_name="diff")
|
|
80
|
+
handler.handle_output(formatted_diff, item_name="diff")
|