Skip to content

Commit 2c40aab

Browse files
feat(run): add token-safe shell output compaction (v4.2.0)
Introduce graphstack run with quality-preserving compactors for git and pytest, wire into orchestrator rules and skills, and document in README. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent e803050 commit 2c40aab

23 files changed

Lines changed: 2882 additions & 750 deletions

.cursor/rules/graphstack.mdc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ activation — follow both that file **and** the abbreviated reminders below:
4343

4444
```
4545
Is the answer in the graph? → Use graph, skip raw file read
46+
Shell/git/test command needed? → python -m graphstack run -- <cmd> (not raw)
4647
Is this tool call speculative? → Cancel it, ask user first
4748
Can reads run in parallel? → Parallelize them
4849
Output > 15 lines user won't act on → Summarize instead

.cursor/skills/builder/BUILDER.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ Need to read 3+ files? → Read them in parallel (one tool ca
103103
Already read a file this session? → Use existing context, don't re-read
104104
```
105105

106+
## Shell Commands (Builder)
107+
108+
Never run raw `git` or test commands in the Shell tool. Use compaction (preserves paths and failures):
109+
110+
```bash
111+
python -m graphstack run -- git status
112+
python -m graphstack run -- git diff
113+
python -m graphstack run -- pytest -q
114+
```
115+
116+
Use `--raw` only when debugging a compaction issue.
117+
106118
---
107119

108120
## When the Brief Is Ambiguous

.cursor/skills/qa/QA.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ graph.json → edges between different clusters = integration points
7474

7575
---
7676

77+
## Shell Commands (QA)
78+
79+
All verification commands go through compaction — failures and file paths must reach context:
80+
81+
```bash
82+
python -m graphstack run -- pytest -q
83+
python -m graphstack run -- git diff
84+
python -m graphstack run -- git status
85+
```
86+
87+
Do not use raw `pytest` / `git` in Shell unless `graphstack run` is unavailable.
88+
89+
---
90+
7791
## QA Verification Process
7892

7993
```

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ All notable changes to GraphStack are documented here.
44

55
---
66

7+
## [v4.2.0] — 2026-05-17
8+
9+
### Added
10+
- **`graphstack run`** — run shell commands with token-safe output compaction (`--raw` for full output).
11+
- **`scripts/graphstack/compact/`** — independent compactors for `git status` / `diff` / `log`, `pytest`, and generic commands; preserves paths, hunks, and failures; falls back to raw when signal would be lost.
12+
- **Workflow integration**`TOKEN_OPTIMIZER.md`, `graphstack.mdc`, `ORCHESTRATOR.md`, Builder/QA skills mandate `graphstack run` for shell tools.
13+
- **`validate` / `doctor`**`compact_ok` check for the output-compact module.
14+
- **Pytest**`test_compact.py` (7 tests for compaction quality).
15+
16+
### Changed
17+
- **Installer** — copies `run.py` and `scripts/graphstack/compact/` into target projects.
18+
- **README** — Shell Output Compaction section and v4.2 highlights.
19+
20+
---
21+
722
## [v4.1.0] — 2026-05-17
823

924
### Added

README.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ One prompt starts the entire lifecycle — from blank repo to production.
77

88
[![CI](https://github.com/MertCapkin/graphstack/actions/workflows/ci.yml/badge.svg)](https://github.com/MertCapkin/graphstack/actions)
99
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
10-
[![Version](https://img.shields.io/badge/version-v4.1.0-blue)](CHANGELOG.md)
10+
[![Version](https://img.shields.io/badge/version-v4.2.0-blue)](CHANGELOG.md)
1111
[![Platforms](https://img.shields.io/badge/platforms-Windows%20%7C%20macOS%20%7C%20Linux-success)](#compatibility)
1212
[![Works with Cursor](https://img.shields.io/badge/Works%20with-Cursor-blue)](https://cursor.sh)
1313
[![Works with Claude Code](https://img.shields.io/badge/Works%20with-Claude%20Code-orange)](https://claude.ai/code)
1414

1515
</div>
1616

17-
> **v4.1 highlights:** `pip install -e .` packaging, `graphstack validate` / `graphstack doctor`, CI graph-staleness checks, code-focused `.graphifyignore`, and an honest limitations + case-study section. See [CHANGELOG.md](CHANGELOG.md).
17+
> **v4.2 highlights:** `graphstack run` — token-safe shell output for git/tests (quality-preserving compaction, no external deps). Plus v4.1: `pip install -e .`, `validate` / `doctor`, CI graph checks. See [CHANGELOG.md](CHANGELOG.md).
1818
1919
---
2020

@@ -36,7 +36,7 @@ pip install -r requirements.txt
3636
# or, equivalently, install Graphify directly with the same pin:
3737
pip install "graphifyy>=0.7,<0.9"
3838

39-
# Optional: install GraphStack CLI from a clone (board / validate / doctor)
39+
# Optional: install GraphStack CLI from a clone (board / validate / doctor / run)
4040
pip install -e /path/to/graphstack
4141
# or with Graphify in one step:
4242
pip install -e "/path/to/graphstack[graphify]"
@@ -285,6 +285,7 @@ GraphStack's savings come from three mechanisms:
285285
| Role discipline | Each role reads only what its job requires | ~60% vs unstructured sessions |
286286
| File-based state | STATE.md replaces chat history on resume | ~60% per new session |
287287
| Parallel reads | Multiple files in one tool call | ~50% on multi-file ops |
288+
| Shell compaction | `graphstack run` shrinks git/test output before it hits context | ~60–80% on verbose shell ops |
288289

289290
**Net savings by codebase size:**
290291

@@ -320,6 +321,32 @@ graphstack validate --strict --fail-stale-graph
320321

321322
---
322323

324+
## Shell Output Compaction (`graphstack run`)
325+
326+
Graph-first rules reduce **file reads**. Shell compaction reduces **terminal output** (git status, diffs, test runners) before it enters the AI context — without installing third-party proxies.
327+
328+
**Who uses it:** Cursor/Claude agents follow `TOKEN_OPTIMIZER.md` and `.cursor/rules/graphstack.mdc` — they call `graphstack run`, not raw `git`/`pytest`. You do not need to remember a separate workflow.
329+
330+
```bash
331+
python -m graphstack run -- git status
332+
python -m graphstack run -- git diff
333+
python -m graphstack run -- git log -n 20
334+
python -m graphstack run -- pytest -q
335+
```
336+
337+
**Quality safeguards (not “blind compression”):**
338+
339+
- File paths, branch names, diff hunks (`@@`), and `+`/`-` lines are preserved
340+
- Test failures, tracebacks, and stderr are kept (stderr is never compacted)
341+
- If compaction would drop too much signal, output **falls back to raw** automatically
342+
- Full output when debugging: `python -m graphstack run --raw -- git diff`
343+
344+
Independent Python implementation (MIT) — inspired by common agent-tooling patterns, no RTK dependency or vendored code.
345+
346+
`graphstack doctor` reports whether the compact module is installed in your project.
347+
348+
---
349+
323350
## What Gets Installed
324351

325352
```
@@ -361,6 +388,8 @@ your-project/
361388
│ ├── platform_utils.py ← OS detection, Python finder, encoding-safe echo
362389
│ ├── cli.py ← entry point dispatcher
363390
│ ├── validate.py ← layout / brief / graph checks
391+
│ ├── run.py ← shell runner with compaction
392+
│ ├── compact/ ← git / pytest / generic compactors
364393
│ └── tests/ ← pytest suite
365394
├── pyproject.toml ← pip install -e . (v4.1+)
366395
├── .graphifyignore ← code-focused graph for this repo
@@ -402,6 +431,7 @@ python -m graphstack board new add-oauth Add OAuth login with GitHub
402431
python -m graphstack board claim add-oauth builder
403432
python -m graphstack board complete add-oauth
404433
python -m graphstack board log
434+
python -m graphstack run -- git status
405435
python -m graphstack doctor
406436
python -m graphstack validate --fail-stale-graph
407437
```

0 commit comments

Comments
 (0)