Compare commits

..

2 Commits

Author SHA1 Message Date
071568b37b docs(todo): improve formatting in make.md
- Shorten title for conciseness.
- Align tables for better readability.
- Minor formatting adjustments for consistency.
2026-03-31 23:12:09 +01:00
a7c7ec5aad Start working on make 2026-03-31 23:05:11 +01:00
2 changed files with 115 additions and 73 deletions

115
todo/doing/make.md Normal file
View File

@ -0,0 +1,115 @@
# `grokkit agent make`
**Description**: Wrappers for Makefile targets (test/lint/build/cover). Enables Grok to run/verify builds mid-agent workflow (e.g., "edit, test, fix loops").
## Problem It Solves
Agent edits code but can't auto-verify compilation/tests—manual `make test` context-switch.
## Benefits
- **Automated verification**: Post-edit `make test` + analyze failures.
- **Dry-runs**: Preview `make build` output.
- **Safe**: Whitelisted targets, timeout, project-dir.
- **Parse results**: Extract pass/fail, coverage, errors for next agent step.
- **Workflow**: "Refactor → test → fix → commit".
## Agent Tool Examples
```
grokkit agent "Fix lint errors in cmd/, run make lint to verify, then test"
# Grok: edits → make lint → "All green!" → make test → fixes failures
```
```
grokkit agent "Benchmark changes before commit"
# Grok: make test-cover → "Coverage drop 2%" → optimizations
```
## High-Level Implementation
1. **Detect**: `test -f Makefile` or `make --version`.
2. **Tool schemas**:
- `run_target(target: string) → {output: string, success: bool}`
- `dry_run(target: string) → simulated_output`
3. **Wrappers** in `internal/tools/make.go`:
```go
func RunTarget(ctx context.Context, args map[string]any) (string, error)
```
4. **Agent integration**: Tool call → parse stdout → feed to Grok ("Tests failed: fix?").
5. **Safety**:
- Whitelist: test, lint, build, test-cover, install.
- 300s timeout.
- No sudo/privileged.
- Config: `[tools.make.enabled]`.
6. **Parsing**: Grep for "PASS/FAIL", coverage %.
## Flags / Config
| Key | Description |
|----------------------|------------------------|
| `tools.make.enabled` | Enable make tools |
| `tools.make.timeout` | Per-target timeout (s) |
## Implementation Notes
- **Commands**: `make TARGET` (no args).
- **Extend agent**: Loop includes make calls post-edit.
- **Errors**: MakeError with output.
- **Tests**: Mock exec, table-driven (success/fail outputs).
- **Effort**: Low (~120 LOC). Std exec + parsing.
- **Prereq**: Makefile present.
## ROI
**High**. Agent verification loop:
| Stage | Covered |
|----------|----------------|
| Edit | `agent` ✓ |
| Verify | **make** ← new |
| Repo/log | tea/cnotes |
Instant feedback elevates agent reliability.## Work Plan
1. **Setup structure**: Create `internal/tools/make.go` and `internal/tools/make_test.go`. Add config flags in `internal/config/config.go` for `tools.make.enabled` (bool, default false) and `tools.make.timeout` (int, default 300).
2. **Implement whitelist**: Define `validTargets = []string{"test", "lint", "build", "test-cover", "install"}`. Add `isValidTarget(target string) bool` func.
3. **Implement `RunTarget`**:
- Check `tools.make.enabled`, Makefile exists (`os.Stat("Makefile")`), validate target.
- Use `exec.CommandContext` with timeout: `cd $PROJECT_DIR && make TARGET`.
- Capture stdout/stderr, return `{output: string, success: bool, exitCode: int}` as JSON.
- Error wrapping: `MakeError{target, output, exitCode}`.
4. **Add `DryRun` tool**: Simulate `make -n TARGET` (no-execute mode), same safety checks.
5. **Implement parsing helpers**:
- `ParseTestResult(output string) (pass bool, failures int)`: grep "PASS", "FAIL".
- `ParseCoverage(output string) (float64, error)`: regex for "%" coverage.
- `ParseErrors(output string) []string`: extract compiler/lint errors.
6. **Register tools**: In `internal/agent/tools.go`, add `makeRun` and `makeDryRun` tool schemas calling `RunTarget`/`DryRun`.
7. **Agent loop integration**: Update `internal/agent/run.go` post-edit: auto-call `make test` if Makefile exists, parse results, feed to next prompt ("Tests failed: ...").
8. **Safety hardening**:
- Set `exec.Dir = projectDir`, `Env` without `PATH` mods.
- Timeout enforcement, kill on ctx cancel.
- Log full output to `cnotes`.
9. **Tests** (table-driven in `make_test.go`):
- Mock `exec.Command` returns (success/fail outputs).
- Invalid target → error.
- Timeout simulation.
- Parsing: PASS/FAIL, coverage "92.3%", lint errors.
- Run `go test ./internal/tools -v`.
10. **Docs/Config**: Update README with tool examples. Add `[tools.make]` sample config.
11. **Commit**: `git commit -m "feat: grokkit agent make integration
- Add make tool wrappers (run_target, dry_run)
- Safety: whitelist, timeout, parsing for tests/cover
- Agent auto-verification loop
Closes #<todo-id>"`

View File

@ -1,73 +0,0 @@
# `grokkit agent` make integration
**Description**: Wrappers for Makefile targets (test/lint/build/cover). Enables Grok to run/verify builds mid-agent workflow (e.g., "edit, test, fix loops").
## Problem It Solves
Agent edits code but can't auto-verify compilation/tests—manual `make test` context-switch.
## Benefits
- **Automated verification**: Post-edit `make test` + analyze failures.
- **Dry-runs**: Preview `make build` output.
- **Safe**: Whitelisted targets, timeout, project-dir.
- **Parse results**: Extract pass/fail, coverage, errors for next agent step.
- **Workflow**: "Refactor → test → fix → commit".
## Agent Tool Examples
```
grokkit agent "Fix lint errors in cmd/, run make lint to verify, then test"
# Grok: edits → make lint → "All green!" → make test → fixes failures
```
```
grokkit agent "Benchmark changes before commit"
# Grok: make test-cover → "Coverage drop 2%" → optimizations
```
## High-Level Implementation
1. **Detect**: `test -f Makefile` or `make --version`.
2. **Tool schemas**:
- `run_target(target: string) → {output: string, success: bool}`
- `dry_run(target: string) → simulated_output`
3. **Wrappers** in `internal/tools/make.go`:
```go
func RunTarget(ctx context.Context, args map[string]any) (string, error)
```
4. **Agent integration**: Tool call → parse stdout → feed to Grok ("Tests failed: fix?").
5. **Safety**:
- Whitelist: test, lint, build, test-cover, install.
- 300s timeout.
- No sudo/privileged.
- Config: `[tools.make.enabled]`.
6. **Parsing**: Grep for "PASS/FAIL", coverage %.
## Flags / Config
| Key | Description |
|-----|-------------|
| `tools.make.enabled` | Enable make tools |
| `tools.make.timeout` | Per-target timeout (s) |
## Implementation Notes
- **Commands**: `make TARGET` (no args).
- **Extend agent**: Loop includes make calls post-edit.
- **Errors**: MakeError with output.
- **Tests**: Mock exec, table-driven (success/fail outputs).
- **Effort**: Low (~120 LOC). Std exec + parsing.
- **Prereq**: Makefile present.
## ROI
**High**. Agent verification loop:
| Stage | Covered |
|-------|---------|
| Edit | `agent` ✓ |
| Verify | **make** ← new |
| Repo/log | tea/cnotes |
Instant feedback elevates agent reliability.