@haposoft/cafekit 0.14.0 → 0.14.1
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.
- package/README.md +21 -1
- package/bin/phases/root-config.js +24 -5
- package/package.json +1 -1
- package/src/claude/gitignore +11 -4
- package/src/claude/migration-manifest.json +1 -0
- package/src/claude/rules/skill-workflow-routing.md +8 -0
- package/src/claude/skills/delegate/SKILL.md +124 -0
- package/src/claude/skills/delegate/references/codex-delegation.md +71 -0
- package/src/claude/skills/delegate/references/grok-delegation.md +84 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> Claude Code-first spec-driven workflow and runtime bundle for AI coding assistants.
|
|
4
4
|
|
|
5
|
-
[](https://github.com/haposoft/cafekit)
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
[](https://claude.ai/code)
|
|
8
8
|
|
|
@@ -46,6 +46,26 @@ Requirements:
|
|
|
46
46
|
- Node.js 18+
|
|
47
47
|
- Claude Code project with `.claude/`, OpenCode project with `.opencode/` or `opencode.json`, or choose a runtime when prompted
|
|
48
48
|
|
|
49
|
+
## Git ignore policy
|
|
50
|
+
|
|
51
|
+
On install, CafeKit updates the **project-root** `.gitignore` with:
|
|
52
|
+
|
|
53
|
+
```text
|
|
54
|
+
# CafeKit / Ecosystem
|
|
55
|
+
specs/_shared/
|
|
56
|
+
plans/
|
|
57
|
+
!plans/templates/
|
|
58
|
+
.cafekit-backup/
|
|
59
|
+
.cafekit.lock
|
|
60
|
+
.claude/
|
|
61
|
+
.opencode/
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Runtime folders are local — reinstall with `npx @haposoft/cafekit` rather than
|
|
65
|
+
committing them. Inside the runtime, CafeKit also installs `.claude/.gitignore`
|
|
66
|
+
(or `.opencode/.gitignore`) so secrets, skill dependencies, session state, and
|
|
67
|
+
hook logs stay out of git even if someone force-adds the folder.
|
|
68
|
+
|
|
49
69
|
## What Gets Installed
|
|
50
70
|
|
|
51
71
|
Claude Code targets:
|
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Phase: root project configuration (.gitignore).
|
|
3
3
|
*
|
|
4
|
-
* Ensures the root .gitignore carries CafeKit-managed patterns
|
|
5
|
-
*
|
|
4
|
+
* Ensures the root .gitignore carries CafeKit-managed patterns:
|
|
5
|
+
* - workflow dirs (plans, shared research)
|
|
6
|
+
* - install safety artifacts (backup, lock)
|
|
7
|
+
* - runtime folders (.claude/, .opencode/) — reinstall via
|
|
8
|
+
* `npx @haposoft/cafekit`; do not commit the local payload
|
|
9
|
+
*
|
|
10
|
+
* Layered with the in-folder `.claude/.gitignore` /
|
|
11
|
+
* `.opencode/.gitignore` templates (secrets, skill deps, session
|
|
12
|
+
* state) so force-adds and partial un-ignores stay safe.
|
|
13
|
+
*
|
|
14
|
+
* Honors dry-run.
|
|
6
15
|
*/
|
|
7
16
|
|
|
8
17
|
const fs = require('fs');
|
|
9
18
|
const path = require('path');
|
|
10
19
|
|
|
20
|
+
/** True if `lines` already carries `pattern` with or without a trailing slash. */
|
|
21
|
+
function hasPattern(lines, pattern) {
|
|
22
|
+
const bare = pattern.replace(/\/$/, '');
|
|
23
|
+
const withSlash = bare + '/';
|
|
24
|
+
return lines.includes(pattern) || lines.includes(bare) || lines.includes(withSlash);
|
|
25
|
+
}
|
|
26
|
+
|
|
11
27
|
function ensureGitignore(ctx) {
|
|
12
28
|
const gitignorePath = path.join(process.cwd(), '.gitignore');
|
|
13
29
|
const header = '# CafeKit / Ecosystem';
|
|
@@ -16,7 +32,10 @@ function ensureGitignore(ctx) {
|
|
|
16
32
|
'plans/',
|
|
17
33
|
'!plans/templates/',
|
|
18
34
|
'.cafekit-backup/',
|
|
19
|
-
'.cafekit.lock'
|
|
35
|
+
'.cafekit.lock',
|
|
36
|
+
// Local runtime payload — reinstall with npx; keep out of git
|
|
37
|
+
'.claude/',
|
|
38
|
+
'.opencode/'
|
|
20
39
|
];
|
|
21
40
|
const prefix = ctx.dryRun ? '[dry-run] ' : '';
|
|
22
41
|
|
|
@@ -30,7 +49,7 @@ function ensureGitignore(ctx) {
|
|
|
30
49
|
|
|
31
50
|
const content = fs.readFileSync(gitignorePath, 'utf8');
|
|
32
51
|
const lines = content.split('\n').map((l) => l.trim());
|
|
33
|
-
const missing = patterns.filter((p) => !lines
|
|
52
|
+
const missing = patterns.filter((p) => !hasPattern(lines, p));
|
|
34
53
|
|
|
35
54
|
if (missing.length > 0) {
|
|
36
55
|
let newContent = content;
|
|
@@ -46,4 +65,4 @@ function ensureGitignore(ctx) {
|
|
|
46
65
|
}
|
|
47
66
|
}
|
|
48
67
|
|
|
49
|
-
module.exports = { ensureGitignore };
|
|
68
|
+
module.exports = { ensureGitignore, hasPattern };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haposoft/cafekit",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "Claude Code-first spec-driven workflow for AI coding assistants. Bundles CafeKit hapo: skills, runtime hooks, agents, and installer scaffolding.",
|
|
5
5
|
"author": "Haposoft <nghialt@haposoft.com>",
|
|
6
6
|
"license": "MIT",
|
package/src/claude/gitignore
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
#
|
|
1
|
+
# CafeKit local runtime (.claude/ or .opencode/)
|
|
2
|
+
# Also ignored at project root by the installer. This file protects
|
|
3
|
+
# force-adds (`git add -f`) and partial un-ignores of the runtime folder.
|
|
4
|
+
|
|
5
|
+
# Secrets and local credentials
|
|
2
6
|
.env
|
|
3
7
|
.env.*
|
|
4
8
|
!.env.example
|
|
5
9
|
|
|
6
|
-
#
|
|
10
|
+
# Skill dependency installs (Python venv + npm)
|
|
7
11
|
skills/.venv/
|
|
12
|
+
skills/**/.venv/
|
|
13
|
+
skills/**/node_modules/
|
|
8
14
|
.venv/
|
|
9
15
|
venv/
|
|
10
|
-
skills/**/node_modules/
|
|
11
16
|
__pycache__/
|
|
17
|
+
**/__pycache__/
|
|
12
18
|
*.pyc
|
|
13
19
|
|
|
14
|
-
#
|
|
20
|
+
# Generated session state, caches, and logs
|
|
15
21
|
session-state/
|
|
16
22
|
hooks/.logs/
|
|
23
|
+
plugins/.logs/
|
|
17
24
|
agent-memory/
|
|
18
25
|
settings.bak.json
|
|
19
26
|
.mcp.json
|
|
@@ -66,6 +66,14 @@ Do not turn reconstructed docs directly into implementation. Human review must a
|
|
|
66
66
|
|
|
67
67
|
Use `/hapo:research` for external knowledge. Use `/hapo:inspect` for local source truth.
|
|
68
68
|
|
|
69
|
+
## Delegation Workflow
|
|
70
|
+
|
|
71
|
+
| User intent | Suggested skill |
|
|
72
|
+
|---|---|
|
|
73
|
+
| assign/offload an implementation task to an external agent CLI (codex, grok) | `/hapo:delegate` |
|
|
74
|
+
|
|
75
|
+
Claude Code remains the orchestrator: it writes the task brief, dispatches, monitors, and independently verifies the returned work.
|
|
76
|
+
|
|
69
77
|
## Output Artifact Workflow
|
|
70
78
|
|
|
71
79
|
| User intent | Suggested skill |
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: hapo:delegate
|
|
3
|
+
description: "Delegate implementation tasks from Claude Code to external CLI agents (Codex or Grok). Covers task-brief authoring, non-interactive dispatch, permission setup, background monitoring, resume, and independent verification of the returned work."
|
|
4
|
+
user-invocable: true
|
|
5
|
+
when_to_use: "Invoke when the user asks to assign/offload a coding task to codex or grok, or to run work on an external agent CLI."
|
|
6
|
+
category: orchestration
|
|
7
|
+
keywords: [delegate, codex, grok, external-agent, offload, assign]
|
|
8
|
+
argument-hint: "<codex|grok> <task-description | path/to/task-brief.md>"
|
|
9
|
+
metadata:
|
|
10
|
+
author: haposoft
|
|
11
|
+
version: "1.0.0"
|
|
12
|
+
---
|
|
13
|
+
# Delegate to External Agents (Codex / Grok)
|
|
14
|
+
|
|
15
|
+
Dispatch a well-scoped implementation task to an external agentic CLI — **Codex** (OpenAI) or **Grok** (xAI Grok Build) — from a Claude Code session acting as orchestrator. Claude Code stays responsible for: writing the task brief, choosing safe permissions, monitoring, and **independently verifying** the result before reporting completion.
|
|
16
|
+
|
|
17
|
+
**Mantra:** Brief precisely, sandbox tightly, verify independently.
|
|
18
|
+
|
|
19
|
+
## When to Use
|
|
20
|
+
|
|
21
|
+
- User explicitly asks to hand a task to codex/grok ("giao cho codex", "assign to grok").
|
|
22
|
+
- Parallel workstreams: Claude Code keeps orchestrating while an external agent implements a scoped task.
|
|
23
|
+
- Cross-checking: a second model implements or reviews independently.
|
|
24
|
+
|
|
25
|
+
Do NOT delegate: tasks touching secrets/`.env`, deploys to shared environments, destructive migrations on live data, or tasks whose scope is still unclear (clarify first — a vague brief wastes an entire agent run).
|
|
26
|
+
|
|
27
|
+
## Workflow
|
|
28
|
+
|
|
29
|
+
### 1. Write the task brief (mandatory, file-based)
|
|
30
|
+
|
|
31
|
+
External agents run **fresh-context** — they see none of your conversation. Write the brief to a file (convention: `plans/<slug>-task.md` in the target repo), never inline-only. Follow the orchestrator prompt rules (`.claude/rules/orchestrator.md`): the brief must be self-contained.
|
|
32
|
+
|
|
33
|
+
Required sections:
|
|
34
|
+
|
|
35
|
+
```markdown
|
|
36
|
+
# Task: <title>
|
|
37
|
+
|
|
38
|
+
> Self-contained brief for a fresh-context agent. Date: <YYYY-MM-DD>.
|
|
39
|
+
> FOUNDATION: <state of the working tree the agent builds on — branch,
|
|
40
|
+
> uncommitted changes it must NOT revert, verified test/build status>
|
|
41
|
+
|
|
42
|
+
## Context — project, architecture, why this task exists
|
|
43
|
+
## Scope — numbered work items with exact file paths
|
|
44
|
+
## Constraints — what must NOT be touched (staging data, .env, deploys,
|
|
45
|
+
unrelated refactors); repo rules to obey (CLAUDE.md)
|
|
46
|
+
## Completion Criteria — verifiable, numbered
|
|
47
|
+
## Evidence required — exact commands whose output proves completion
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Rules of thumb:
|
|
51
|
+
- Name exact files and line-level anchors where known; agents burn tokens rediscovering what you already know.
|
|
52
|
+
- State dependency order explicitly if this task builds on another agent's uncommitted work ("do NOT revert/stash existing changes").
|
|
53
|
+
- Put user-pending decisions in Constraints as forbidden actions (e.g. "do NOT touch staging rows until user confirms").
|
|
54
|
+
|
|
55
|
+
### 2. Protect the working tree
|
|
56
|
+
|
|
57
|
+
Before dispatch, snapshot state you cannot afford to lose:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
git stash push -u -m "backup: <reason>" && git stash apply -q # snapshot, keep tree intact
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Prefer isolation when the task is risky or parallel to other edits:
|
|
64
|
+
- Grok: `--worktree=<name>` (built-in).
|
|
65
|
+
- Codex: run with `-C <worktree-dir>` after creating a git worktree yourself.
|
|
66
|
+
|
|
67
|
+
If the agent must build on uncommitted changes, isolation is not possible — use the stash-backup pattern above and say so in the brief.
|
|
68
|
+
|
|
69
|
+
### 3. Dispatch
|
|
70
|
+
|
|
71
|
+
Load the matching reference for exact flags, permission model, and pitfalls:
|
|
72
|
+
- **Codex:** `./references/codex-delegation.md`
|
|
73
|
+
- **Grok:** `./references/grok-delegation.md`
|
|
74
|
+
|
|
75
|
+
Common principles:
|
|
76
|
+
- Run non-interactive/headless mode in a **background** shell; both CLIs stream progress to stdout.
|
|
77
|
+
- Grant the **minimum** permission set that lets the agent write code and run its Evidence commands (npm/node). Never grant full-access/bypass modes for routine tasks.
|
|
78
|
+
- Model/effort overrides: pass explicitly rather than relying on user config, so the run is reproducible.
|
|
79
|
+
- Capture the output file path; check progress after ~20–30s to confirm the agent actually started (auth errors, bad flags, and permission blocks surface early).
|
|
80
|
+
|
|
81
|
+
### 4. Monitor
|
|
82
|
+
|
|
83
|
+
- Poll the background output periodically; look for permission-block messages — both CLIs degrade to "design-only" output instead of failing loudly when a write tool is blocked.
|
|
84
|
+
- If blocked on permissions: **resume the same session** with corrected flags (both CLIs support resume; see references) — context is preserved, work continues instead of restarting.
|
|
85
|
+
- Apply the 3-strike rule from `.claude/rules/orchestrator.md`: same failure 3+ times → stop, escalate to user with evidence.
|
|
86
|
+
|
|
87
|
+
### 5. Verify independently (non-negotiable)
|
|
88
|
+
|
|
89
|
+
External-agent claims are **not** evidence (CLAUDE.md: no completion claim without fresh proof from the current run). After the agent reports done:
|
|
90
|
+
|
|
91
|
+
1. `git status` / `git diff` — confirm the changed file set matches the brief's Scope; flag out-of-scope edits.
|
|
92
|
+
2. Run the brief's Evidence commands yourself (tests, build). The agent's transcript of a test run does not count.
|
|
93
|
+
3. Check Completion Criteria one by one.
|
|
94
|
+
4. Report to user: what was delegated, what came back, verification results, and any deviations.
|
|
95
|
+
|
|
96
|
+
### 6. Sync
|
|
97
|
+
|
|
98
|
+
- Keep the brief file updated (checklist ticks / blockers) so it doubles as task state.
|
|
99
|
+
- If a spec (`specs/<slug>/`) governs the work, follow the Tollgate Protocol (`.claude/rules/state-sync.md`): update `spec.json` + task files only after verification passes.
|
|
100
|
+
- The user decides commit/merge/deploy — delegation ends at verified working-tree changes unless told otherwise.
|
|
101
|
+
|
|
102
|
+
## Choosing Codex vs Grok
|
|
103
|
+
|
|
104
|
+
Both are capable general coding agents; prefer the one the user names. If unspecified:
|
|
105
|
+
|
|
106
|
+
| Factor | Codex | Grok |
|
|
107
|
+
|---|---|---|
|
|
108
|
+
| Isolation | manual git worktree + `-C` | built-in `--worktree=<name>` |
|
|
109
|
+
| Structured output | `--output-schema` (JSON Schema) | `--json-schema` |
|
|
110
|
+
| Self-verification | ask in the brief | `--check` flag appends a verify loop |
|
|
111
|
+
| Resume | `codex exec resume <id>` | `grok --resume <id>` |
|
|
112
|
+
|
|
113
|
+
## Rules
|
|
114
|
+
|
|
115
|
+
- Never grant `--dangerously-bypass-approvals-and-sandbox` (codex) or `bypassPermissions` (grok) for routine delegation.
|
|
116
|
+
- Never let an external agent touch `.env`, secrets, staging/production data, or run deploys.
|
|
117
|
+
- Never report the agent's own success claim as completion — verify first.
|
|
118
|
+
- Never re-dispatch a blocked task unchanged (BLOCKED ≠ retry; fix the cause: permissions, context, or scope).
|
|
119
|
+
- One writer per file set: don't run two agents (or an agent + yourself) editing the same files concurrently.
|
|
120
|
+
|
|
121
|
+
## References
|
|
122
|
+
|
|
123
|
+
- `./references/codex-delegation.md` — Codex CLI: exec mode, sandbox/approval model, resume, pitfalls
|
|
124
|
+
- `./references/grok-delegation.md` — Grok CLI: headless mode, worktree, permission rules, resume, pitfalls
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Delegating to Codex CLI
|
|
2
|
+
|
|
3
|
+
Verified against codex-cli 0.144.4 (2026-07). Re-check `codex exec --help` if flags fail — the CLI evolves quickly.
|
|
4
|
+
|
|
5
|
+
## Preflight
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
which codex && codex --version # installed?
|
|
9
|
+
codex doctor # auth + runtime health (slow; run only when suspicious)
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
User-level defaults live in `~/.codex/config.toml` (`model`, `model_reasoning_effort`, agents, MCP servers). Overrides via `-m` and `-c key=value` beat config — pass them explicitly for reproducible runs.
|
|
13
|
+
|
|
14
|
+
## Non-interactive dispatch: `codex exec`
|
|
15
|
+
|
|
16
|
+
Reads the prompt from an argument, or from **stdin** when the argument is `-`. Prefer stdin + brief file:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
codex exec \
|
|
20
|
+
-m gpt-5.6-terra \
|
|
21
|
+
-c model_reasoning_effort='"max"' \
|
|
22
|
+
--sandbox workspace-write \
|
|
23
|
+
-o /tmp/codex-last-message.txt \
|
|
24
|
+
- < plans/<slug>-task.md
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Run it in a background shell and poll the output.
|
|
28
|
+
|
|
29
|
+
### Key flags
|
|
30
|
+
|
|
31
|
+
| Flag | Notes |
|
|
32
|
+
|---|---|
|
|
33
|
+
| `-m <model>` | model ID, e.g. `gpt-5.6-terra` (note spelling: *terra*) |
|
|
34
|
+
| `-c model_reasoning_effort='"max"'` | TOML-parsed value — keep the inner quotes |
|
|
35
|
+
| `--sandbox <mode>` | `read-only` \| `workspace-write` \| `danger-full-access` |
|
|
36
|
+
| `-o <file>` | write the agent's final message to a file — easiest completion check |
|
|
37
|
+
| `-C <dir>` | working root (use for delegating into a git worktree) |
|
|
38
|
+
| `--add-dir <dir>` | extra writable dirs alongside the workspace |
|
|
39
|
+
| `--output-schema <file>` | JSON Schema constraining the final response |
|
|
40
|
+
| `--json` | JSONL event stream on stdout (machine parsing) |
|
|
41
|
+
| `--ephemeral` | don't persist session files |
|
|
42
|
+
|
|
43
|
+
### Pitfalls
|
|
44
|
+
|
|
45
|
+
- **`-a` / `--ask-for-approval` is TUI-only.** `codex exec` rejects it (`error: unexpected argument '-a' found`). Exec mode is implicitly `approval: never` — sandbox mode is your only control there.
|
|
46
|
+
- **`workspace-write` limits writes, not reads**, to: workdir, `/tmp`, `$TMPDIR`. Network is available. Commands needing writes outside (global installs) will fail — keep Evidence commands repo-local.
|
|
47
|
+
- **Effort value is TOML**: `-c model_reasoning_effort='"max"'` (double-quoted inside single quotes). Bare `max` may parse as a literal string too, but the quoted form is unambiguous.
|
|
48
|
+
- Startup banner echoes `model:`, `reasoning effort:`, `sandbox:` — **verify these lines** ~20s after dispatch instead of assuming flags took effect.
|
|
49
|
+
- User config may define agents/hooks/MCP servers that activate automatically; `--ignore-user-config` gives a clean run if they interfere.
|
|
50
|
+
|
|
51
|
+
## Monitor & verify liveness
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# ~20-30s after dispatch: banner shows model/sandbox; then agent narration follows
|
|
55
|
+
head -c 1200 <output-file>
|
|
56
|
+
tail -c 1500 <output-file> # progress
|
|
57
|
+
cat /tmp/codex-last-message.txt # exists → run finished; content = final report
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Resume
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
codex exec resume --last "<follow-up>" # most recent session
|
|
64
|
+
codex exec resume <SESSION_ID> "<follow-up>" # by id (session id printed in banner)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Use resume (not a fresh dispatch) when: permission-blocked mid-run, follow-up fixes after your verification failed, or continuing a design into implementation.
|
|
68
|
+
|
|
69
|
+
## Review mode
|
|
70
|
+
|
|
71
|
+
`codex review` (or `codex exec review`) runs a non-interactive code review of the current repo — useful as an independent second-opinion pass on another agent's diff.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Delegating to Grok CLI (Grok Build)
|
|
2
|
+
|
|
3
|
+
Verified against grok 0.2.101 (2026-07). Re-check `grok --help` if flags fail.
|
|
4
|
+
|
|
5
|
+
## Preflight
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
which grok && grok --version
|
|
9
|
+
grok models # available model IDs
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Non-interactive dispatch
|
|
13
|
+
|
|
14
|
+
Two forms:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# single-turn from a brief file (preferred for delegation)
|
|
18
|
+
grok --prompt-file plans/<slug>-task.md \
|
|
19
|
+
--worktree=<slug> \
|
|
20
|
+
--check \
|
|
21
|
+
--permission-mode acceptEdits \
|
|
22
|
+
--allow "Bash(npm:*)" --allow "Bash(node:*)" \
|
|
23
|
+
--output-format plain
|
|
24
|
+
|
|
25
|
+
# short single-turn prompt
|
|
26
|
+
grok -p "<prompt>"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Run in a background shell and poll the output.
|
|
30
|
+
|
|
31
|
+
### Key flags
|
|
32
|
+
|
|
33
|
+
| Flag | Notes |
|
|
34
|
+
|---|---|
|
|
35
|
+
| `--prompt-file <path>` | single-turn prompt from file |
|
|
36
|
+
| `-p, --single <prompt>` | single-turn inline prompt |
|
|
37
|
+
| `--worktree=<name>` | built-in git worktree isolation (grok-managed; see pitfalls) |
|
|
38
|
+
| `--check` | appends a self-verification loop (headless only) — use it |
|
|
39
|
+
| `--permission-mode <mode>` | `default` \| `acceptEdits` \| `auto` \| `dontAsk` \| `bypassPermissions` \| `plan` |
|
|
40
|
+
| `--allow "<RULE>"` / `--deny "<RULE>"` | permission rules, Claude Code syntax: `Bash(npm:*)`, `Write`, `Edit` |
|
|
41
|
+
| `-m <model>` / `--reasoning-effort` | model + effort overrides |
|
|
42
|
+
| `--max-turns <N>` | hard cap on agent turns |
|
|
43
|
+
| `--json-schema '<schema>'` | structured final output |
|
|
44
|
+
| `--output-format plain\|json\|streaming-json` | headless output format |
|
|
45
|
+
| `--resume <SESSION_ID>` | continue a session (context preserved) |
|
|
46
|
+
| `--best-of-n <N>` | run task N ways in parallel, pick best (headless) |
|
|
47
|
+
|
|
48
|
+
## Permission model — the #1 pitfall
|
|
49
|
+
|
|
50
|
+
`--permission-mode acceptEdits` **does not reliably unblock file writes in headless runs**; grok may report "Write tool blocked" and quietly degrade to a **design-only** response that reads like progress. It still exits 0.
|
|
51
|
+
|
|
52
|
+
Mitigations:
|
|
53
|
+
- Add explicit allow rules for write tools on the first dispatch: `--allow "Write" --allow "Edit" --allow "StrReplace"` alongside `--allow "Bash(npm:*)" --allow "Bash(node:*)"`.
|
|
54
|
+
- After ~30s, grep the output for `blocked`/`chặn` — catch degradation early.
|
|
55
|
+
- If the run finished design-only: **resume the same session** with widened allows and an explicit apply instruction; grok picks up its own design and implements without re-exploring:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
grok --resume <SESSION_ID> --no-plan \
|
|
59
|
+
--permission-mode acceptEdits \
|
|
60
|
+
--allow "Write" --allow "Edit" --allow "StrReplace" \
|
|
61
|
+
--allow "Bash(npm:*)" --allow "Bash(node:*)" \
|
|
62
|
+
--check -p "Continue: apply the designed changes, run tests, report results."
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Even with allows granted, shell may still be policy-restricted (runs finish with "npm test BLOCKED — shell not pre-approved"). That's fine: **you run the Evidence commands yourself during verification** — do not loosen to `bypassPermissions` just to make the agent self-verify.
|
|
66
|
+
|
|
67
|
+
## Worktree pitfalls
|
|
68
|
+
|
|
69
|
+
- `--worktree=<name>` worktrees are **grok-managed**: they may not appear in the target repo's `git worktree list` and `grok worktree list` may still say "No worktrees found". **Do not trust either listing** — after the run, check `git status` in the main repo to find where changes actually landed. In practice (0.2.101, resumed sessions) grok can write **directly into the main working tree** despite the flag.
|
|
70
|
+
- Consequence: always take a stash-backup snapshot before dispatch (`git stash push -u -m "backup: ..." && git stash apply -q`), and treat the main tree as potentially modified.
|
|
71
|
+
|
|
72
|
+
## Session management
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
grok sessions list # ids + summaries
|
|
76
|
+
grok --resume <SESSION_ID> [flags] -p "..." # continue with same context
|
|
77
|
+
grok export <SESSION_ID> # transcript as Markdown
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Quirks
|
|
81
|
+
|
|
82
|
+
- Grok reads the target repo's `CLAUDE.md` and obeys it (including tone rules) — repo constraints apply automatically, but so do repo-wide bans; account for that in the brief.
|
|
83
|
+
- `--check` produces a self-verification section in the final report — useful signal, **not** a substitute for your independent verification.
|
|
84
|
+
- Exit code 0 means the CLI ran, not that the task succeeded. Judge by diff + your own Evidence runs.
|