Skip to content

Commit 7644398

Browse files
NagyViktNagyViktOmX
authored
Prefer RTK guidance for noisy gx agent commands (#515)
Agents need concrete compact-command examples in the gx prompt and managed AGENTS snippet. This adds an RTK prompt slice and matching skill guidance while keeping Guardex internals on raw command output for parsed contracts. Constraint: rtk may be absent from PATH, so guidance must fall back cleanly without making it a hard dependency Rejected: Routing internal git helpers through rtk | RTK output filtering would break --porcelain, --json, and other parsed stdout contracts Confidence: high Scope-risk: narrow Directive: Do not wrap machine-readable Guardex command calls with RTK unless the parser contract is changed and tested Tested: /home/deadpool/.local/bin/rtk test node --test test/prompt.test.js test/metadata.test.js Tested: /home/deadpool/.local/bin/rtk test openspec validate agent-codex-optimize-gx-to-use-rtk-2026-05-04-06-03 --strict Tested: git diff --check Not-tested: Full repo test suite Co-authored-by: NagyVikt <nagy.viktordp@gmail.com> Co-authored-by: OmX <omx@oh-my-codex.dev>
1 parent 5364734 commit 7644398

8 files changed

Lines changed: 115 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Optimize gx guidance for RTK command wrappers
2+
3+
## Why
4+
5+
Guardex already pushes agents toward compact, phase-based execution, but `gx prompt`
6+
and managed AGENTS snippets do not name the concrete RTK command surface. Agents
7+
therefore fall back to raw `git`, `rg`, test, and build commands even when RTK is
8+
available, increasing terminal output and context load.
9+
10+
## What
11+
12+
- Add RTK command-compression guidance to the `gx prompt` checklist.
13+
- Add the same rule to the managed multi-agent AGENTS snippet so `gx setup`/`gx doctor`
14+
can propagate it to guarded repos.
15+
- Keep internal `gx` machine-readable git/process calls raw so RTK filtering cannot
16+
break parsed stdout contracts.
17+
18+
## Impact
19+
20+
Agents get concrete RTK examples for file discovery, git/GitHub, tests, builds,
21+
logs, and savings analytics while existing scripted Guardex behavior remains
22+
compatible when RTK is not installed.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## ADDED Requirements
2+
3+
### Requirement: GX Prompt Surfaces SHOULD Prefer RTK For Noisy Agent Commands
4+
5+
`gx prompt` managed guidance SHALL tell agents to prefer RTK wrappers for noisy
6+
file discovery, git/GitHub inspection, test/build output, logs, and savings
7+
analytics when `rtk` is available.
8+
9+
#### Scenario: default prompt includes RTK command examples
10+
11+
- **WHEN** a user runs `gx prompt`
12+
- **THEN** the checklist includes RTK examples for file, git/GitHub, test/build,
13+
passthrough, and savings commands
14+
15+
#### Scenario: managed snippet includes RTK command discipline
16+
17+
- **WHEN** a user runs `gx prompt --snippet`
18+
- **THEN** the managed AGENTS snippet includes RTK command-compression rules
19+
20+
### Requirement: GX Internal Parsers MUST Keep Machine Output Raw
21+
22+
Guardex SHALL NOT require internal machine-readable commands to be routed through
23+
RTK when code parses stdout.
24+
25+
#### Scenario: parsed command output stays unfiltered
26+
27+
- **WHEN** Guardex code needs exact stdout from commands such as `git status --porcelain`,
28+
JSON output, NUL-delimited output, or other parsed command contracts
29+
- **THEN** the guidance tells agents not to wrap those commands with RTK
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Tasks
2+
3+
## 1. Spec
4+
5+
- [x] Record RTK prompt/guidance behavior and the machine-readable output boundary.
6+
7+
## 2. Tests
8+
9+
- [x] Cover `gx prompt` and `gx prompt --snippet` RTK guidance.
10+
11+
## 3. Implementation
12+
13+
- [x] Add an RTK command-compression slice to the AI setup prompt.
14+
- [x] Add RTK command discipline to the managed AGENTS snippet.
15+
- [x] Keep Codex skill guidance aligned with the managed template.
16+
17+
## 4. Verification
18+
19+
- [x] Run focused prompt/OpenSpec verification.
20+
21+
## 5. Cleanup
22+
23+
- [ ] Commit, push, PR, merge, and sandbox cleanup through `gx branch finish --branch "agent/codex/optimize-gx-to-use-rtk-2026-05-04-06-03" --base main --via-pr --wait-for-merge --cleanup`.
24+
- [ ] Record final PR URL, `MERGED` state, and cleanup evidence.

skills/gitguardex/SKILL.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ Use when repo safety may be broken.
99

1010
Bootstrap: `gx setup`
1111
Ops: `gx branch start "<task>" "<agent>"`, `gx locks claim --branch "<agent-branch>" <file...>`, `gx branch finish --branch "<agent-branch>" --base <base> --via-pr --wait-for-merge --cleanup`, `gx finish --all`, `gx cleanup`
12+
13+
When inspecting or verifying, prefer `rtk` compact wrappers if available (`rtk git status`, `rtk grep`, `rtk test <cmd>`). Do not wrap commands whose stdout is parsed by scripts.

src/context.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,9 @@ const DOCTOR_AUTO_FINISH_MESSAGE_MAX = 160;
452452
const AI_SETUP_PART_ALIASES = new Map([
453453
['task', 'task-loop'],
454454
['loop', 'task-loop'],
455+
['compact-commands', 'rtk'],
456+
['command-compression', 'rtk'],
457+
['token-commands', 'rtk'],
455458
['reviewbot', 'review-bot'],
456459
['forksync', 'fork-sync'],
457460
]);
@@ -503,6 +506,18 @@ const AI_SETUP_PARTS = [
503506
'gx locks claim --branch "<agent-branch>" <file...>',
504507
],
505508
},
509+
{
510+
name: 'rtk',
511+
label: 'RTK command compression',
512+
promptLines: [
513+
'Prefer RTK wrappers for noisy shell discovery and verification when `rtk` is available; fall back to raw commands when missing.',
514+
'Files: `rtk ls .`, `rtk read <file>`, `rtk read <file> -l aggressive`, `rtk smart <file>`, `rtk find "<glob>" .`, `rtk grep "<pattern>" .`, `rtk diff <a> <b>`.',
515+
'Git/GitHub: `rtk git status`, `rtk git diff`, `rtk git log -n 10`, `rtk gh pr list`, `rtk gh pr view <id>`.',
516+
'Tests/build: `rtk test <cmd>`, `rtk err <cmd>`, `rtk jest`, `rtk vitest`, `rtk playwright test`, `rtk pytest`, `rtk cargo test`, `rtk tsc`, `rtk lint`.',
517+
'Use `rtk gain`, `rtk discover`, and `rtk session` to audit savings; use `rtk proxy <command>` only when raw passthrough is required.',
518+
'Do not wrap machine-readable commands with RTK when code parses stdout (`--porcelain`, `--json`, NUL-delimited output, or exact stdout contracts).',
519+
],
520+
},
506521
{
507522
name: 'integrate',
508523
label: 'Integrate',

templates/AGENTS.multiagent-safety.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@ Default: less word, same proof.
134134
- Treat local edit/commit, remote publish/PR, CI diagnosis, and cleanup as bounded phases.
135135
- Do not spend fresh narration or approval turns on obvious safe follow-ons inside an already authorized phase unless the risk changes.
136136

137+
### RTK command compression
138+
139+
When `rtk` is available, prefer it for noisy shell discovery and verification.
140+
141+
- Files: `rtk ls .`, `rtk read <file>`, `rtk read <file> -l aggressive`, `rtk smart <file>`, `rtk find "<glob>" .`, `rtk grep "<pattern>" .`, `rtk diff <a> <b>`.
142+
- Git and GitHub: `rtk git status`, `rtk git diff`, `rtk git log -n 10`, `rtk gh pr list`, `rtk gh pr view <id>`.
143+
- Tests and builds: `rtk test <cmd>`, `rtk err <cmd>`, `rtk jest`, `rtk vitest`, `rtk playwright test`, `rtk pytest`, `rtk cargo test`, `rtk tsc`, `rtk lint`.
144+
- Runtime and data probes: `rtk docker ps`, `rtk docker logs <container>`, `rtk kubectl pods`, `rtk json <file>`, `rtk log <file>`, `rtk curl <url>`.
145+
- Savings checks: `rtk gain`, `rtk discover`, and `rtk session`.
146+
- Use `rtk proxy <command>` only when raw passthrough is required.
147+
- Do not wrap machine-readable commands with RTK when code parses stdout (`--porcelain`, `--json`, NUL-delimited output, or exact stdout contracts).
148+
- If `rtk` is missing, use raw commands and summarize only meaningful lines.
149+
137150
### Caveman style
138151

139152
Commentary and progress updates use smart-caveman `ultra` by default:

templates/codex/skills/gitguardex/SKILL.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ Use when repo safety may be broken.
99

1010
Bootstrap: `gx setup`
1111
Ops: `gx branch start "<task>" "<agent>"`, `gx locks claim --branch "<agent-branch>" <file...>`, `gx branch finish --branch "<agent-branch>" --base <base> --via-pr --wait-for-merge --cleanup`, `gx finish --all`, `gx cleanup`
12+
13+
When inspecting or verifying, prefer `rtk` compact wrappers if available (`rtk git status`, `rtk grep`, `rtk test <cmd>`). Do not wrap commands whose stdout is parsed by scripts.

test/prompt.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ test('prompt outputs AI setup instructions', () => {
7777
assert.match(result.stdout, /avoid repeated peeks or stdin loops/);
7878
assert.match(result.stdout, /checkpoint after each milestone: Task -> Done -> Current status -> Next/);
7979
assert.match(result.stdout, /keep execution log separate from reasoning context/);
80+
assert.match(result.stdout, /RTK command compression/);
81+
assert.match(result.stdout, /rtk git status/);
82+
assert.match(result.stdout, /rtk test <cmd>/);
83+
assert.match(result.stdout, /Do not wrap machine-readable commands with RTK/);
8084
assert.match(result.stdout, /gx finish --all/);
8185
assert.match(result.stdout, /\/opsx:propose/);
8286
assert.match(result.stdout, /https:\/\/github\.com\/apps\/pull/);
@@ -133,6 +137,7 @@ test('prompt --list-parts prints the available prompt slices', () => {
133137
assert.equal(result.status, 0, result.stderr || result.stdout);
134138
assert.match(result.stdout, /^install$/m);
135139
assert.match(result.stdout, /^task-loop$/m);
140+
assert.match(result.stdout, /^rtk$/m);
136141
assert.match(result.stdout, /^openspec$/m);
137142
assert.match(result.stdout, /^review-bot$/m);
138143
});
@@ -156,6 +161,9 @@ test('prompt --snippet prints the managed AGENTS template with token budget and
156161
assert.match(result.stdout, /Default: less word, same proof\./);
157162
assert.match(result.stdout, /Keep raw terminal interaction out of long-lived context/);
158163
assert.match(result.stdout, /Keep execution log separate from reasoning context/);
164+
assert.match(result.stdout, /### RTK command compression/);
165+
assert.match(result.stdout, /rtk git status/);
166+
assert.match(result.stdout, /Do not wrap machine-readable commands with RTK/);
159167
assert.match(result.stdout, /### Caveman style/);
160168
assert.match(result.stdout, /Answer order stays fixed: answer first, cause next, fix or next step last\./);
161169
});

0 commit comments

Comments
 (0)