codigest 0.12.2__tar.gz → 0.13.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.
Files changed (51) hide show
  1. {codigest-0.12.2 → codigest-0.13.0}/PKG-INFO +57 -3
  2. {codigest-0.12.2 → codigest-0.13.0}/README.md +56 -2
  3. {codigest-0.12.2 → codigest-0.13.0}/pyproject.toml +8 -1
  4. {codigest-0.12.2 → codigest-0.13.0}/pyproject.toml.orig +4 -1
  5. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/__main__.py +1 -1
  6. codigest-0.13.0/src/codigest/commands/cap.py +183 -0
  7. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/commands/clean.py +8 -3
  8. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/commands/diff.py +4 -6
  9. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/commands/digest.py +8 -2
  10. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/commands/init.py +5 -4
  11. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/commands/mcp.py +55 -12
  12. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/commands/pack.py +70 -19
  13. codigest-0.13.0/src/codigest/commands/scan.py +425 -0
  14. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/commands/semdiff.py +16 -11
  15. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/commands/shell_help.py +2 -1
  16. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/commands/status.py +24 -7
  17. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/commands/term.py +128 -32
  18. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/commands/tree.py +19 -14
  19. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/cache.py +24 -8
  20. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/callees.py +2 -1
  21. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/common.py +35 -43
  22. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/formats.py +32 -7
  23. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/git_ops.py +8 -1
  24. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/outline.py +5 -2
  25. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/output.py +11 -7
  26. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/presets.py +5 -2
  27. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/processor.py +1 -5
  28. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/prompts.py +41 -13
  29. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/redact.py +28 -4
  30. codigest-0.13.0/src/codigest/core/remote.py +526 -0
  31. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/resolver.py +26 -20
  32. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/runner.py +35 -5
  33. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/scanner.py +44 -31
  34. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/semdiff.py +34 -12
  35. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/shadow.py +91 -44
  36. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/shellhist.py +2 -1
  37. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/structure.py +6 -6
  38. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/tags.py +20 -6
  39. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/termstore.py +5 -28
  40. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/core/tokenizer.py +2 -0
  41. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/main.py +35 -7
  42. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/options.py +7 -13
  43. codigest-0.13.0/src/codigest/shell/hook.ps1 +340 -0
  44. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/shell/hook.sh +79 -2
  45. codigest-0.12.2/src/codigest/commands/cap.py +0 -78
  46. codigest-0.12.2/src/codigest/commands/scan.py +0 -239
  47. codigest-0.12.2/src/codigest/shell/hook.ps1 +0 -164
  48. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/__init__.py +0 -0
  49. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/commands/mark.py +0 -0
  50. {codigest-0.12.2 → codigest-0.13.0}/src/codigest/config.py +0 -0
  51. {codigest-0.12.2 → codigest-0.13.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.12.2
3
+ Version: 0.13.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">
@@ -82,12 +82,14 @@ your machine.
82
82
 
83
83
  Prebuilt binary, no Python needed. Windows (PowerShell):
84
84
 
85
+ <!-- test windows -->
85
86
  ```powershell
86
87
  irm https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex
87
88
  ```
88
89
 
89
90
  Linux, macOS and Termux:
90
91
 
92
+ <!-- test unix -->
91
93
  ```bash
92
94
  curl -fsSL https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.sh | sh
93
95
  ```
@@ -504,7 +506,57 @@ normally) and appear in your history as typed. Programs that need a real termina
504
506
  - Skip more programs: `$env:CODIGEST_CAP_SKIP = '^\s*(myrepl|mytui)\b'` (bash/zsh:
505
507
  `export CODIGEST_CAP_SKIP='^(myrepl|mytui)( |$)'`, an extended regex).
506
508
  - Disable for a session: `$env:CODIGEST_NOCAP = 1` (bash/zsh: `export CODIGEST_NOCAP=1`).
507
- - Remove the hooks: `cdg term uninstall`.
509
+ - Remove the hooks: `cdg term uninstall`. Each startup file gets back the exact bytes it had
510
+ before install (line endings, BOM, final newline); one that install created is deleted with
511
+ any folder made for it, as are the hook copies in the data folder. Captured commands stay
512
+ until `cdg term clear`.
513
+
514
+ ##### Programs that run other commands
515
+
516
+ A program that runs a command line for you, such as `hf` from
517
+ [hanfix](https://github.com/NaNIsaac/hanfix) (it re-runs the previous command typed with the Korean
518
+ layout on), would otherwise be captured as a whole, and the command it runs would get the capture
519
+ pipe instead of the terminal. Such a program can work with the hook in two steps:
520
+
521
+ 1. Add its command names to `CODIGEST_RUNNERS` when it loads; the hook does not capture a line that
522
+ starts with one of them. Append, so the order in which the startup file loads it and codigest
523
+ does not matter:
524
+ - PowerShell: `$global:CODIGEST_RUNNERS += 'hf'`
525
+ - bash/zsh: `CODIGEST_RUNNERS="${CODIGEST_RUNNERS-} hf"` (a shell variable, space-separated)
526
+ 2. Run each command line through `__cdg_run` when it is defined, looked up when the line runs. It
527
+ applies the hook's own rules to that line: a program that needs the terminal keeps it, anything
528
+ else is captured under that line.
529
+ - PowerShell: `if (Get-Command __cdg_run -CommandType Function -ErrorAction Ignore) { . __cdg_run $line } else { Invoke-Expression $line }`
530
+ - bash/zsh: `if typeset -f __cdg_run >/dev/null; then __cdg_run "$line"; else eval "$line"; fi`
531
+
532
+ A program that does not do step 2 can still be listed in `CODIGEST_RUNNERS`: what it runs then keeps
533
+ the terminal and is not captured. [thefuck](https://github.com/nvbn/thefuck) is one:
534
+ `$global:CODIGEST_RUNNERS += 'fuck'` (bash/zsh: `CODIGEST_RUNNERS="${CODIGEST_RUNNERS-} fuck"`).
535
+
536
+ A program can instead replace the typed line before it runs: when Enter is pressed, the hook calls
537
+ each function listed in `CODIGEST_REWRITERS` with the line, and the first one that claims it gives
538
+ the line to run. That line then goes on as if typed: it is the one in the shell history (PSReadLine's
539
+ and the engine's in PowerShell), the hook's rules decide whether it is captured, and `$?` is its own.
540
+ `hf` typed alone can work this way; `hf` inside a longer line still uses the steps above.
541
+
542
+ - PowerShell: `$global:CODIGEST_REWRITERS += 'name'`. The function gets the line and returns
543
+ `$null` (not its line), the new line, or `@{ Line = <new>; Confirm = $true }` to ask first.
544
+ - bash/zsh: `CODIGEST_REWRITERS="${CODIGEST_REWRITERS-} name"`. The function gets the line, sets
545
+ `REPLY` to the new line and returns 0, or 2 to ask first, or returns 1 when it is not its line.
546
+ - When asked, the hook shows the new line with `[Enter / Ctrl+C]`: Enter runs it, any other key
547
+ drops it (nothing runs, nothing is added to history).
548
+ - A function that fails, returns anything else, or gives a line that does not parse leaves the line
549
+ as typed, without a message. So does a result that comes after more than 200 ms: it is discarded.
550
+ This is not a timeout: the hook waits for the function to return, so one that hangs blocks Enter.
551
+ - The function should not add to history itself.
552
+ - A line typed with a leading space keeps it, so it stays out of the capture.
553
+ - Not in a PowerShell remote session, nested prompt or the debugger.
554
+
555
+ In PowerShell the hook works with another `PSConsoleHostReadLine` (VS Code's shell integration,
556
+ atuin): it calls that one for the line, so it sees the line as typed, and only wraps what it
557
+ returns. When one is loaded after the hook, the hook puts itself back on top while the shell
558
+ waits for input, also when that one reads the line itself (atuin does); the first line after it
559
+ is not captured.
508
560
 
509
561
  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
562
 
@@ -516,6 +568,8 @@ Limitations:
516
568
  normally. In bash, neither are lines that start with a subshell `( ... )`.
517
569
  - In bash the hook uses the DEBUG trap and keeps one set before the first prompt (starship,
518
570
  bash-preexec); a DEBUG trap set later replaces it.
571
+ - In bash, VS Code's shell integration loaded after the hook stops the capture
572
+ ([#52](https://github.com/NaNIsaac/codigest/issues/52)).
519
573
  - Long output is bounded: the PowerShell hook keeps the first and last 2,000 lines, and a bash or
520
574
  zsh capture file over 4 MB is read 1 MB from each end. The store then keeps 64 KB.
521
575
  - 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">
@@ -56,12 +56,14 @@ your machine.
56
56
 
57
57
  Prebuilt binary, no Python needed. Windows (PowerShell):
58
58
 
59
+ <!-- test windows -->
59
60
  ```powershell
60
61
  irm https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex
61
62
  ```
62
63
 
63
64
  Linux, macOS and Termux:
64
65
 
66
+ <!-- test unix -->
65
67
  ```bash
66
68
  curl -fsSL https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.sh | sh
67
69
  ```
@@ -478,7 +480,57 @@ normally) and appear in your history as typed. Programs that need a real termina
478
480
  - Skip more programs: `$env:CODIGEST_CAP_SKIP = '^\s*(myrepl|mytui)\b'` (bash/zsh:
479
481
  `export CODIGEST_CAP_SKIP='^(myrepl|mytui)( |$)'`, an extended regex).
480
482
  - Disable for a session: `$env:CODIGEST_NOCAP = 1` (bash/zsh: `export CODIGEST_NOCAP=1`).
481
- - Remove the hooks: `cdg term uninstall`.
483
+ - Remove the hooks: `cdg term uninstall`. Each startup file gets back the exact bytes it had
484
+ before install (line endings, BOM, final newline); one that install created is deleted with
485
+ any folder made for it, as are the hook copies in the data folder. Captured commands stay
486
+ until `cdg term clear`.
487
+
488
+ ##### Programs that run other commands
489
+
490
+ A program that runs a command line for you, such as `hf` from
491
+ [hanfix](https://github.com/NaNIsaac/hanfix) (it re-runs the previous command typed with the Korean
492
+ layout on), would otherwise be captured as a whole, and the command it runs would get the capture
493
+ pipe instead of the terminal. Such a program can work with the hook in two steps:
494
+
495
+ 1. Add its command names to `CODIGEST_RUNNERS` when it loads; the hook does not capture a line that
496
+ starts with one of them. Append, so the order in which the startup file loads it and codigest
497
+ does not matter:
498
+ - PowerShell: `$global:CODIGEST_RUNNERS += 'hf'`
499
+ - bash/zsh: `CODIGEST_RUNNERS="${CODIGEST_RUNNERS-} hf"` (a shell variable, space-separated)
500
+ 2. Run each command line through `__cdg_run` when it is defined, looked up when the line runs. It
501
+ applies the hook's own rules to that line: a program that needs the terminal keeps it, anything
502
+ else is captured under that line.
503
+ - PowerShell: `if (Get-Command __cdg_run -CommandType Function -ErrorAction Ignore) { . __cdg_run $line } else { Invoke-Expression $line }`
504
+ - bash/zsh: `if typeset -f __cdg_run >/dev/null; then __cdg_run "$line"; else eval "$line"; fi`
505
+
506
+ A program that does not do step 2 can still be listed in `CODIGEST_RUNNERS`: what it runs then keeps
507
+ the terminal and is not captured. [thefuck](https://github.com/nvbn/thefuck) is one:
508
+ `$global:CODIGEST_RUNNERS += 'fuck'` (bash/zsh: `CODIGEST_RUNNERS="${CODIGEST_RUNNERS-} fuck"`).
509
+
510
+ A program can instead replace the typed line before it runs: when Enter is pressed, the hook calls
511
+ each function listed in `CODIGEST_REWRITERS` with the line, and the first one that claims it gives
512
+ the line to run. That line then goes on as if typed: it is the one in the shell history (PSReadLine's
513
+ and the engine's in PowerShell), the hook's rules decide whether it is captured, and `$?` is its own.
514
+ `hf` typed alone can work this way; `hf` inside a longer line still uses the steps above.
515
+
516
+ - PowerShell: `$global:CODIGEST_REWRITERS += 'name'`. The function gets the line and returns
517
+ `$null` (not its line), the new line, or `@{ Line = <new>; Confirm = $true }` to ask first.
518
+ - bash/zsh: `CODIGEST_REWRITERS="${CODIGEST_REWRITERS-} name"`. The function gets the line, sets
519
+ `REPLY` to the new line and returns 0, or 2 to ask first, or returns 1 when it is not its line.
520
+ - When asked, the hook shows the new line with `[Enter / Ctrl+C]`: Enter runs it, any other key
521
+ drops it (nothing runs, nothing is added to history).
522
+ - A function that fails, returns anything else, or gives a line that does not parse leaves the line
523
+ as typed, without a message. So does a result that comes after more than 200 ms: it is discarded.
524
+ This is not a timeout: the hook waits for the function to return, so one that hangs blocks Enter.
525
+ - The function should not add to history itself.
526
+ - A line typed with a leading space keeps it, so it stays out of the capture.
527
+ - Not in a PowerShell remote session, nested prompt or the debugger.
528
+
529
+ In PowerShell the hook works with another `PSConsoleHostReadLine` (VS Code's shell integration,
530
+ atuin): it calls that one for the line, so it sees the line as typed, and only wraps what it
531
+ returns. When one is loaded after the hook, the hook puts itself back on top while the shell
532
+ waits for input, also when that one reads the line itself (atuin does); the first line after it
533
+ is not captured.
482
534
 
483
535
  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
536
 
@@ -490,6 +542,8 @@ Limitations:
490
542
  normally. In bash, neither are lines that start with a subshell `( ... )`.
491
543
  - In bash the hook uses the DEBUG trap and keeps one set before the first prompt (starship,
492
544
  bash-preexec); a DEBUG trap set later replaces it.
545
+ - In bash, VS Code's shell integration loaded after the hook stops the capture
546
+ ([#52](https://github.com/NaNIsaac/codigest/issues/52)).
493
547
  - Long output is bounded: the PowerShell hook keeps the first and last 2,000 lines, and a bash or
494
548
  zsh capture file over 4 MB is read 1 MB from each end. The store then keeps 64 KB.
495
549
  - 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.12.2"
3
+ version = "0.13.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"]
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "codigest"
3
- version = "0.12.2"
3
+ version = "0.13.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"]
@@ -1,4 +1,4 @@
1
1
  from .main import main
2
2
 
3
3
  if __name__ == "__main__":
4
- main()
4
+ main()
@@ -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(f"[yellow]Warning: This will remove [bold]{codigest_dir}[/bold] and all stored context/anchors.[/yellow]")
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")
@@ -9,10 +9,14 @@ lazy from ..core.output import OutputHandler, spinner
9
9
 
10
10
  app = typer.Typer()
11
11
 
12
+
12
13
  @app.callback(invoke_without_command=True)
13
14
  def handle(
14
15
  targets: list[Path] = typer.Argument(
15
- None, help="Files or directories to outline (default: the project)", exists=True, resolve_path=True
16
+ None,
17
+ help="Files or directories to outline (default: the project)",
18
+ exists=True,
19
+ resolve_path=True,
16
20
  ),
17
21
  copy: CopyOption = None,
18
22
  output: OutputOption = None,
@@ -72,7 +76,9 @@ def handle(
72
76
  )
73
77
 
74
78
  if unreadable:
75
- log_console.print(f"[yellow]Could not read:[/yellow] {', '.join(unreadable)}", highlight=False)
79
+ log_console.print(
80
+ f"[yellow]Could not read:[/yellow] {', '.join(unreadable)}", highlight=False
81
+ )
76
82
  token_count = tokenizer.estimate_tokens(digest_content)
77
83
  log_console.print(f"[bold]Digest[/bold] {len(summary_blocks)} files, ~{token_count:,} tokens")
78
84
 
@@ -33,23 +33,23 @@ format = "xml"
33
33
  structure = "toon"
34
34
  """
35
35
 
36
+
36
37
  @app.callback(invoke_without_command=True)
37
38
  def handle(
38
- # target 인자 추가 (기본값: 현재 위치)
39
39
  target: Path = typer.Argument(
40
40
  Path("."),
41
41
  help="Target directory to initialize",
42
42
  exists=True,
43
43
  file_okay=False,
44
44
  dir_okay=True,
45
- resolve_path=True
45
+ resolve_path=True,
46
46
  ),
47
47
  force: bool = typer.Option(False, "--force", "-f", help="Overwrite existing config"),
48
48
  ) -> None:
49
49
  """
50
50
  Create .codigest/config.toml (file filters). `cdg mark` sets a baseline.
51
51
  """
52
- root_path = target # Typer가 이미 resolve_path=True로 절대경로 변환해줌
52
+ root_path = target # Typer already resolved it (resolve_path=True)
53
53
 
54
54
  config_dir = root_path / ".codigest"
55
55
  config_file = config_dir / "config.toml"
@@ -69,6 +69,7 @@ def handle(
69
69
  console.print("\nEdit .codigest/config.toml to choose which files are included.")
70
70
  console.print("[dim]To compare against this point later, run cdg mark.[/dim]")
71
71
 
72
+
72
73
  def _update_gitignore(path: Path) -> None:
73
74
  entry = ".codigest/"
74
75
  if not path.exists():
@@ -78,4 +79,4 @@ def _update_gitignore(path: Path) -> None:
78
79
  if entry not in path.read_text(encoding="utf-8"):
79
80
  with path.open("a", encoding="utf-8") as f:
80
81
  f.write(f"\n{entry}\n")
81
- console.print(" [green]Added[/green] .codigest/ to .gitignore")
82
+ console.print(" [green]Added[/green] .codigest/ to .gitignore")