Add interactive tree editor island (Phase 4) + MCP server fixes
Phase 4: defisland ~sx-tools/tree-editor — interactive tree viewer embedded in the SX Tools page. Features: - Textarea with :bind for SX source input - Parse button to re-parse on demand - Tree view: annotated tree with path labels, clickable nodes - Context view: enclosing chain from root to selected node - Validate view: structural integrity checks (catches missing body etc.) MCP server fixes: added ident-start?, ident-char?, make-keyword, escape-string, sx-expr-source — needed by parser.sx when loaded into the MCP evaluator. Also: .mcp.json for Claude Code MCP server config, CLAUDE.md protocol for structural .sx file editing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
48
CLAUDE.md
48
CLAUDE.md
@@ -2,6 +2,54 @@
|
||||
|
||||
Cooperative web platform: federated content, commerce, events, and media processing. Each domain runs as an independent Quart microservice with its own database, communicating via HMAC-signed internal HTTP and ActivityPub events.
|
||||
|
||||
## S-expression files — reading and editing protocol
|
||||
|
||||
**Never use `str_replace` or `write_file` on `.sx` or `.sxc` files for structural edits.** These tools operate on text and have no understanding of tree structure. Bracket mismatches produced this way corrupt files silently — a single extra `)` caused the home page to go blank for an hour (25 March 2026).
|
||||
|
||||
Use the `sx-tree` MCP server tools instead. These operate on the parsed tree, not raw text. Bracket errors are impossible by construction.
|
||||
|
||||
### Before doing anything in an `.sx` file
|
||||
|
||||
1. Call `sx_summarise` to get a structural overview of the whole file
|
||||
2. Call `sx_read_subtree` on the region you intend to work in
|
||||
3. Call `sx_get_context` on specific nodes to understand their position
|
||||
4. Call `sx_find_all` to locate definitions or patterns by name
|
||||
|
||||
**Never proceed to an edit without first establishing where you are in the tree using the comprehension tools.**
|
||||
|
||||
### For every s-expression edit
|
||||
|
||||
1. Call `sx_read_subtree` on the target region to confirm the correct path
|
||||
2. Call `sx_replace_node` / `sx_insert_child` / `sx_delete_node` / `sx_wrap_node`
|
||||
3. Call `sx_validate` to confirm structural integrity
|
||||
4. Call `sx_read_subtree` again on the edited region to verify the result
|
||||
|
||||
### On failure
|
||||
|
||||
Read the error carefully. Fragment errors give the parse failure in the new source. Path errors tell you which segment was not found. Fix the specific problem and retry the tree edit. **Never fall back to raw file writes.**
|
||||
|
||||
### When raw file access is acceptable
|
||||
|
||||
- Searching for a string literal or reading prose content with `Read` is fine
|
||||
- Creating a **new** `.sx` file with `Write` is fine (there's no existing tree to corrupt)
|
||||
- Any question about structure, nesting, or tree position goes through the tree tools
|
||||
|
||||
### Available MCP tools (sx-tree server)
|
||||
|
||||
| Tool | Purpose |
|
||||
|------|---------|
|
||||
| `sx_read_tree` | Full annotated tree with path labels |
|
||||
| `sx_summarise` | Folded overview at configurable depth |
|
||||
| `sx_read_subtree` | Expand a specific subtree by path |
|
||||
| `sx_get_context` | Enclosing chain from root to target |
|
||||
| `sx_find_all` | Search by pattern, returns paths |
|
||||
| `sx_get_siblings` | Siblings of a node with target marked |
|
||||
| `sx_validate` | Structural integrity checks |
|
||||
| `sx_replace_node` | Replace node at path with new source |
|
||||
| `sx_insert_child` | Insert child at index in a list |
|
||||
| `sx_delete_node` | Remove node, siblings shift |
|
||||
| `sx_wrap_node` | Wrap in template with `_` placeholder |
|
||||
|
||||
## Deployment
|
||||
|
||||
- **Do NOT push** until explicitly told to. Pushes reload code to dev automatically.
|
||||
|
||||
Reference in New Issue
Block a user