Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Ethos

- `AGENTS.md` is our constitution. Propose useful amendments.
- `AGENTS.md` is our constitution. When you notice systematic gaps (repeated retries, patterns discovered through trial-and-error), propose amendments at the end of the session.
- Resilient parser with user-friendly error messages called "diagnostics" (see `diagnostics/`)
- Stability via invariants: `panic!`/`assert!`/`.expect()` for simple cases, `invariants.rs` otherwise

Expand Down Expand Up @@ -227,6 +227,7 @@ Options: `--verbose-nodes`, `--no-node-type`, `--no-export`, `-o <FILE>`
Execute a query against source code and output JSON.

**Usage variants:**

```
exec <QUERY> <SOURCE> # two positional files
exec -q <TEXT> <SOURCE> # inline query + source file
Expand All @@ -246,6 +247,7 @@ Options: `--compact`, `--verbose-nodes`, `--check`, `--entry <NAME>`
Trace query execution for debugging.

**Usage variants:**

```
trace <QUERY> <SOURCE> # two positional files
trace -q <TEXT> <SOURCE> # inline query + source file
Expand Down Expand Up @@ -276,13 +278,13 @@ cargo run -p plotnik-cli -- langs

## Lifetime Conventions

| Lifetime | Meaning |
| -------- | ------------------------------------------------ |
| `'q` | Query source string (`.ptk` file content) |
| `'d` | Diagnostics reference |
| `'s` | Source code string (tree-sitter input) |
| `'t` | Parsed tree-sitter tree |
| `'a` | Any other (generic borrows, bytecode views) |
| Lifetime | Meaning |
| -------- | ------------------------------------------- |
| `'q` | Query source string (`.ptk` file content) |
| `'d` | Diagnostics reference |
| `'s` | Source code string (tree-sitter input) |
| `'t` | Parsed tree-sitter tree |
| `'a` | Any other (generic borrows, bytecode views) |

# Testing Rules

Expand Down Expand Up @@ -318,3 +320,22 @@ fn valid_query() {
Coverage: `make coverage-lines | grep recursion`

`invariants.rs`: `ensure_*()` functions for unreachable code exclusion from coverage.

# PR Body Format

```
## Summary
<1-3 bullets: what this PR does>

## Why
<1-2 sentences: motivation, problem solved, or link to relevant docs>

## Notes (optional)
<Tradeoffs, alternatives considered, gotchas for future reference>
```

- **Summary**: Quick scan; becomes squash-merge commit body
- **Why**: Captures context that code/diff doesn't convey
- **Notes**: Escape hatch for edge cases

**Omit**: How (diff shows this), Testing (CI covers it).
39 changes: 20 additions & 19 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ plotnik exec query.ptk app.js --entry FunctionDef

**Flags:**

| Flag | Purpose |
| ----------------- | ------------------------------------- |
| `-q, --query` | Inline query text |
| `-s, --source` | Inline source text |
| `-l, --lang` | Language (inferred from file ext) |
| `--compact` | Output compact JSON |
| `--verbose-nodes` | Include line/column in nodes |
| `--check` | Validate output against inferred types|
| `--entry NAME` | Start from specific definition |
| Flag | Purpose |
| ----------------- | -------------------------------------- |
| `-q, --query` | Inline query text |
| `-s, --source` | Inline source text |
| `-l, --lang` | Language (inferred from file ext) |
| `--compact` | Output compact JSON |
| `--verbose-nodes` | Include line/column in nodes |
| `--check` | Validate output against inferred types |
| `--entry NAME` | Start from specific definition |

---

Expand Down Expand Up @@ -221,28 +221,29 @@ plotnik trace query.ptk app.js -vv # very verbose
### Query-Only Commands (tree, check, dump, infer)

These commands take a single input. Use either:

- **Positional**: `plotnik tree app.ts` or `plotnik dump query.ptk`
- **Flag**: `plotnik tree -s 'let x' -l js` or `plotnik dump -q 'Q = ...'`

### Query+Source Commands (exec, trace)

These commands take two inputs. Use any combination:

| Pattern | Query from | Source from |
| ------------------------------- | ------------- | -------------- |
| `exec QUERY SOURCE` | 1st positional| 2nd positional |
| `exec -q '...' SOURCE` | `-q` flag | positional |
| `exec -s '...' QUERY -l lang` | positional | `-s` flag |
| `exec -q '...' -s '...' -l lang`| `-q` flag | `-s` flag |
| Pattern | Query from | Source from |
| -------------------------------- | -------------- | -------------- |
| `exec QUERY SOURCE` | 1st positional | 2nd positional |
| `exec -q '...' SOURCE` | `-q` flag | positional |
| `exec -s '...' QUERY -l lang` | positional | `-s` flag |
| `exec -q '...' -s '...' -l lang` | `-q` flag | `-s` flag |

**Key rule**: When `-q` is provided with one positional, it becomes SOURCE.

### Language Detection

| Input type | Language |
| ------------ | -------------------- |
| File | Inferred from `.ext` |
| Inline (`-s`)| Requires `-l` |
| Input type | Language |
| ------------- | -------------------- |
| File | Inferred from `.ext` |
| Inline (`-s`) | Requires `-l` |

---

Expand Down