Skip to content

Commit e5f0255

Browse files
authored
docs: update README and AGENTS.md (#228)
1 parent 82b351b commit e5f0255

2 files changed

Lines changed: 68 additions & 59 deletions

File tree

AGENTS.md

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,20 @@ Tree-sitter: `((a) (b))` — Plotnik: `{(a) (b)}`. The #1 syntax error.
145145
```
146146
crates/
147147
plotnik-cli/ # CLI tool
148-
src/commands/ # Subcommands (check, dump, infer, tree, langs)
148+
src/commands/ # Subcommands (check, dump, exec, infer, trace, tree, langs)
149149
plotnik-core/ # Common code (Interner, Symbol)
150150
plotnik-lib/ # Plotnik as library
151151
src/
152152
analyze/ # Semantic analysis (symbol_table, dependencies, type_check, validation)
153153
bytecode/ # Binary format definitions
154-
typegen/ # Type declaration extraction (bytecode → .d.ts)
155154
compile/ # Thompson NFA construction (AST → IR)
156155
diagnostics/ # User-friendly error reporting
157156
emit/ # Bytecode emission (IR → binary)
157+
engine/ # Runtime VM (execution, backtracking, effects)
158158
parser/ # Syntactic parsing (lexer, grammar, AST)
159159
query/ # Query facade (Query, QueryBuilder, SourceMap)
160160
type_system/ # Shared type primitives
161+
typegen/ # Type declaration extraction (bytecode → .d.ts)
161162
plotnik-langs/ # Tree-sitter language bindings
162163
plotnik-macros/ # Proc macros
163164
docs/
@@ -169,14 +170,15 @@ docs/
169170

170171
Run: `cargo run -p plotnik-cli -- <command>`
171172

172-
| Command | Purpose | Status |
173-
| ------- | -------------------------- | ------- |
174-
| `tree` | Explore tree-sitter AST | Working |
175-
| `check` | Validate query | Working |
176-
| `dump` | Show compiled bytecode | Working |
177-
| `infer` | Generate TypeScript types | Working |
178-
| `langs` | List supported languages | Working |
179-
| `exec` | Execute query, output JSON | Not yet |
173+
| Command | Purpose |
174+
| ------- | ----------------------------- |
175+
| `tree` | Explore tree-sitter AST |
176+
| `check` | Validate query |
177+
| `dump` | Show compiled bytecode |
178+
| `infer` | Generate TypeScript types |
179+
| `exec` | Execute query, output JSON |
180+
| `trace` | Trace execution for debugging |
181+
| `langs` | List supported languages |
180182

181183
## tree
182184

@@ -220,6 +222,30 @@ cargo run -p plotnik-cli -- infer -q '(identifier) @id' -l typescript
220222

221223
Options: `--verbose-nodes`, `--no-node-type`, `--no-export`, `-o <FILE>`
222224

225+
## exec
226+
227+
Execute a query against source code and output JSON.
228+
229+
```sh
230+
cargo run -p plotnik-cli -- exec query.ptk app.ts
231+
cargo run -p plotnik-cli -- exec -q '(identifier) @id' app.ts # -q shifts positional to source
232+
cargo run -p plotnik-cli -- exec -q '(identifier) @id' -s 'let x' -l javascript
233+
```
234+
235+
Options: `--compact`, `--verbose-nodes`, `--check`, `--entry <NAME>`
236+
237+
## trace
238+
239+
Trace query execution for debugging.
240+
241+
```sh
242+
cargo run -p plotnik-cli -- trace query.ptk app.ts
243+
cargo run -p plotnik-cli -- trace -q '(identifier) @id' app.ts # -q shifts positional to source
244+
cargo run -p plotnik-cli -- trace query.ptk app.ts --no-result -vv
245+
```
246+
247+
Options: `-v` (verbose), `-vv` (very verbose), `--no-result`, `--fuel <N>`
248+
223249
## langs
224250

225251
List supported tree-sitter languages.

README.md

Lines changed: 32 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
<br/>
1212

1313
<p align="center">
14-
Plotnik is a query language for source code.<br/>
15-
Queries extract relevant structured data.<br/>
16-
Transactions allow granular, atomic edits.
14+
A type-safe query language for source code.<br/>
15+
Query in, typed data out.
1716
</p>
1817

1918
<br/>
@@ -28,7 +27,7 @@
2827
<br/>
2928

3029
<p align="center">
31-
⚠️ <a href="#roadmap">ALPHA STAGE</a>: not for production use ⚠️<br/>
30+
⚠️ <a href="#status">ALPHA STAGE</a>: not for production use ⚠️<br/>
3231
</p>
3332

3433
<br/>
@@ -38,7 +37,7 @@
3837

3938
Tree-sitter solved parsing. It powers syntax highlighting and code navigation at GitHub, drives the editing experience in Zed, Helix, and Neovim. It gives you a fast, accurate, incremental syntax tree for virtually any language.
4039

41-
The hard problem now is what comes _after_ parsing: extraction of meaning from the tree, and safe transformation back to source:
40+
The hard problem now is what comes _after_ parsing: extracting structured data from the tree:
4241

4342
```typescript
4443
function extractFunction(node: SyntaxNode): FunctionInfo | null {
@@ -57,7 +56,7 @@ function extractFunction(node: SyntaxNode): FunctionInfo | null {
5756
}
5857
```
5958

60-
Every extraction requires a new function, each one a potential source of bugs that won't surface until production. And once you've extracted what you need, applying changes back to the source requires careful span tracking, validation, and error handling—another layer of brittle code.
59+
Every extraction requires a new function, each one a potential source of bugs that won't surface until production.
6160

6261
## The solution
6362

@@ -81,8 +80,6 @@ interface FunctionInfo {
8180

8281
This structure is guaranteed by the query engine. No defensive programming needed.
8382

84-
Once extraction is complete, Plotnik will support **transactions** to apply validated changes back to the source. The same typed nodes used for extraction become targets for transformation—completing the loop from source to structured data and back to source.
85-
8683
## But what about Tree-sitter queries?
8784

8885
Tree-sitter already has queries:
@@ -138,7 +135,22 @@ Plotnik extends Tree-sitter's query syntax with:
138135

139136
## Language design
140137

141-
Plotnik builds on Tree-sitter's query syntax, extending it with the features needed for typed extraction:
138+
Start simple—extract all function names from a file:
139+
140+
```clojure
141+
Functions = (program
142+
{(function_declaration name: (identifier) @name :: string)}* @functions)
143+
```
144+
145+
Plotnik infers the output type:
146+
147+
```typescript
148+
type Functions = {
149+
functions: { name: string }[];
150+
};
151+
```
152+
153+
Scale up to tagged unions for richer structure:
142154

143155
```clojure
144156
Statement = [
@@ -193,53 +205,24 @@ for (const stmt of result.statements) {
193205

194206
For the detailed specification, see the [Language Reference](docs/lang-reference.md).
195207

196-
## Supported Languages
197-
198-
Plotnik uses [arborium](https://github.com/bearcove/arborium), a batteries-included tree-sitter grammar collection with 60+ permissively-licensed languages out of the box.
199-
200-
## Roadmap
201-
202-
### Ignition: the parser ✓
208+
## Documentation
203209

204-
The foundation is complete: a resilient parser that recovers from errors and keeps going.
210+
- [CLI Guide](docs/cli.md) — Command-line tool usage
211+
- [Language Reference](docs/lang-reference.md) — Complete syntax and semantics
212+
- [Type System](docs/type-system.md) — How output types are inferred from queries
213+
- [Runtime Engine](docs/runtime-engine.md) — VM execution model (for contributors)
205214

206-
- [x] Resilient parser
207-
- [x] Rich diagnostics
208-
- [x] Name resolution
209-
- [x] Recursion validation
210-
- [x] Structural validation
211-
212-
### Liftoff: type inference
213-
214-
The schema infrastructure is built. Type inference is next.
215-
216-
- [x] `node-types.json` parsing and schema representation
217-
- [x] Proc macro for compile-time schema embedding
218-
- [x] Statically bundled languages with node type info
219-
- [x] Query validation against language schemas (unstable)
220-
- [x] Type inference
215+
## Supported Languages
221216

222-
### Acceleration: query engine
217+
Plotnik bundles 15 languages out of the box: Bash, C, C++, CSS, Go, HTML, Java, JavaScript, JSON, Python, Rust, TOML, TSX, TypeScript, and YAML. The underlying [arborium](https://github.com/bearcove/arborium) collection includes 60+ permissively-licensed grammars—additional languages can be enabled as needed.
223218

224-
- [x] Runtime execution with backtracking cursor walker
225-
- [x] Query IR
226-
- [ ] Advanced validation powered by `grammar.json` (production rules, precedence)
227-
- [ ] Match result API with typed accessors
219+
## Status
228220

229-
### Orbit: developer experience
221+
**Working now:** Parser with error recovery, type inference, query execution, CLI tools (`check`, `dump`, `infer`, `exec`, `trace`, `tree`, `langs`).
230222

231-
The CLI foundation exists. The full developer experience is ahead.
223+
**Next up:** CLI distribution (Homebrew, npm), language bindings (TypeScript/WASM, Python), LSP server, editor extensions.
232224

233-
- [x] CLI framework with `debug`, `docs`, `langs`, `exec`, `types` commands
234-
- [x] Query inspection: AST dump, symbol table, node arities, spans, transition graph, inferred types
235-
- [x] Source inspection: Tree-sitter parse tree visualization
236-
- [x] Execute queries against source code and output JSON (`exec`)
237-
- [x] Generate TypeScript types from queries (`types`)
238-
- [ ] CLI distribution: Homebrew, cargo-binstall, npm wrapper
239-
- [ ] Compiled queries via Rust proc macros (zero-cost: query → native code)
240-
- [ ] Language bindings: TypeScript (WASM), Python, Ruby
241-
- [ ] LSP server: diagnostics, completions, hover, go-to-definition
242-
- [ ] Editor extensions: VS Code, Zed, Neovim
225+
⚠️ Alpha stage—API may change. Not for production use.
243226

244227
## Acknowledgments
245228

0 commit comments

Comments
 (0)