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
4 changes: 2 additions & 2 deletions .claude/skills/add-language/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ lose time, because missing one fails silently in a different layer.

Read [`specs/`](../../../specs/) for the language you are adding **before**
writing the lexer — it is the authority on what the language accepts, and it
must be updated in the same change if you alter behaviour.
must be updated in the same change if you alter behavior.
[`docs/ADDING_A_LANGUAGE.md`](../../../docs/ADDING_A_LANGUAGE.md) has longer
code examples; this skill is the integration path.

Expand Down Expand Up @@ -58,7 +58,7 @@ lexer/parser/emitter and bypasses the emitter dispatch entirely.
- Recursive descent, lowest precedence at the top of the call tree:
`assignment → logicalOr → logicalAnd → equality → comparison → term → factor
→ unary → postfix → primary`.
- Normalise operators to Universal AST spelling: logical operators become
- Normalize operators to Universal AST spelling: logical operators become
`'and'`/`'or'`/`'not'`; not-equal becomes `'!='`. Emitters translate back out.
- Use `synchronize()` to skip to the next statement after a parse error.

Expand Down
16 changes: 8 additions & 8 deletions .claude/skills/add-tests/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ After any parser, interpreter, or emitter change, run the browser suite too —
| `tests/<lang>.test.ts` | Everything specific to one language: lexer, parser, interpreter, and that language's emitter output. One per language (`python`, `java`, `javascript`, `csp`, `praxis`). |
| `tests/round-trip.test.ts` | Cross-language fidelity: translates each `examples/demo.*` to every target, re-parses, re-runs, and compares output. |
| `tests/examples.test.ts` | Guards that every `examples/demo.*` still parses, runs without error, and translates to all targets without throwing. |
| `tests/control-flow.test.ts`, `blank-lines.test.ts`, `comments.test.ts`, `blocks.test.ts`, `debugger.test.ts`, `placeholder.test.ts` | Cross-cutting behaviour that isn't owned by one language. |
| `tests/control-flow.test.ts`, `blank-lines.test.ts`, `comments.test.ts`, `blocks.test.ts`, `debugger.test.ts`, `placeholder.test.ts` | Cross-cutting behavior that isn't owned by one language. |
| `tests/bugfixes.test.ts` | Regression cases for specific fixed bugs. Add a comment naming the original failure. |
| `tests/chatStore.test.ts` | Non-compiler modules (zustand stores, plain utils). |

A new _language feature_ goes in `tests/<lang>.test.ts`. A new _AST node_ or
interpreter behaviour usually needs a case in the relevant language file **and**
interpreter behavior usually needs a case in the relevant language file **and**
a demo update so `round-trip.test.ts` covers it in every target.

## The four APIs you will assert against
Expand Down Expand Up @@ -105,7 +105,7 @@ it('runs REPEAT n TIMES', () => {
```

Write the source in the syntax the language actually has — check `specs/<lang>.md`
first. A construct the parser doesn't recognise usually yields an **empty
first. A construct the parser doesn't recognize usually yields an **empty
program**, so the test "passes" against `[]` while proving nothing. If an
interpreter assertion comes back empty, suspect the syntax before the
interpreter.
Expand All @@ -128,7 +128,7 @@ on the same interpreter: translate, re-parse, re-run, compare output. Prefer
this over eyeballing emitted text when you change an emitter.

```typescript
it('CSP → Python preserves behaviour', () => {
it('CSP → Python preserves behavior', () => {
const source = 'x <- 5\nDISPLAY(x)';
const program = new CSPParser(new CSPLexer(source).tokenize()).parse();
const python = new Translator().translate(program, 'python');
Expand All @@ -145,7 +145,7 @@ helper at the top of `tests/debugger.test.ts` for the established shape.

**Hooks and components** — there is no DOM environment configured, so test the
extracted logic rather than rendering. The refactor deliberately put page
behaviour in hooks and pure helpers for this reason; the pure ones are directly
behavior in hooks and pure helpers for this reason; the pure ones are directly
testable with no setup:

- `src/utils/panelLayout.ts` — `toggleStack`, `reorderPanel`, `swapStacked`, `inSameColumn`
Expand All @@ -165,11 +165,11 @@ first — neither is currently a dependency.
(including the loop/branch boundary); each emitter's output; then add it to the
language's `examples/demo.*` so round-trip covers all five targets.

**New expression type** — tokenisation; expression-tree shape including
**New expression type** — tokenization; expression-tree shape including
precedence against neighbouring operators; evaluated value; one emitter's
output, with parenthesisation checked.
output, with parenthesization checked.

**New built-in** — parser recognises it as a `CallExpression`; interpreter
**New built-in** — parser recognizes it as a `CallExpression`; interpreter
returns the right value (and mutates in place where the spec says so); each
emitter maps it to the target's equivalent. Cross-language differences belong in
`specs/stdlib.md`.
Expand Down
14 changes: 7 additions & 7 deletions .claude/skills/add-ui-feature/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
name: add-ui-feature
description: Add or change UI in the Praxly2 editor, embed player, or account page — panes, toolbar controls, side panels, dialogs, keyboard shortcuts, layout and resize behaviour, and example programs. Use when deciding which hook or component owns a piece of state, or where a new control belongs.
description: Add or change UI in the Praxly2 editor, embed player, or account page — panes, toolbar controls, side panels, dialogs, keyboard shortcuts, layout and resize behavior, and example programs. Use when deciding which hook or component owns a piece of state, or where a new control belongs.
---

# Adding a UI feature to Praxly2

The three pages are **composition only**. Behaviour lives in hooks; layout lives
The three pages are **composition only**. Behavior lives in hooks; layout lives
in components. Before adding state to a page, find the hook that already owns
that concern — nearly always there is one.

Expand All @@ -17,7 +17,7 @@ src/pages/
EmbedPage.tsx ~165 lines — layout switch (?to= present or not)
AccountPage.tsx ~ 70 lines — nav + section switch

src/hooks/ ← behaviour
src/hooks/ ← behavior
useCodeParsing source text → AST, AST → translation (+ source map)
useCodeDebugger step-through state machine
useProgramRunner plain (non-debug) run that can pause on input() and resume
Expand Down Expand Up @@ -65,7 +65,7 @@ Despite its name, `LanguageSelector.tsx` exports **no component** — only the
- **No global store for editor state.** Zustand (`src/store/appStore.ts`) is used
only for chat sessions, AI prefs, BYOK settings, and the editor bridge — not
for the program, panels, or layout.
- **Behaviour goes in a hook, not the page.** If you are about to add a
- **Behavior goes in a hook, not the page.** If you are about to add a
`useState` to `EditorPage.tsx`, first check whether an existing hook owns that
concern. The page holds only `code`, `sourceLang`, the two panel toggles, the
pending-dialog flags, and `embedCopied`.
Expand All @@ -78,7 +78,7 @@ Despite its name, `LanguageSelector.tsx` exports **no component** — only the
| You want to… | Touch |
| ------------------------------------------------------ | -------------------------------------------------------------------- |
| change how code runs or what the console shows | `useEditorExecution` / `useEmbedExecution` |
| change run-with-`input()` behaviour in **both** pages | `useProgramRunner` |
| change run-with-`input()` behavior in **both** pages | `useProgramRunner` |
| change pane sizing, resize limits, or the width budget | `useEditorLayout` + `components/editor/layoutConstants.ts` |
| add/remove/rearrange translation panels | `useTranslationPanels` (+ `utils/panelLayout.ts` for the pure rules) |
| change what survives a reload | `useEditorSession` |
Expand Down Expand Up @@ -133,7 +133,7 @@ expose bare background.
Per-language _demos_ are different: they come from `examples/demo.*` via
`src/utils/demoPrograms.ts` and are covered by the round-trip tests.

**CodeMirror behaviour** — add a `StateField`/`Extension` in
**CodeMirror behavior** — add a `StateField`/`Extension` in
`src/utils/codemirrorConfig.ts`, then include it where the pane builds its
extensions (`sourceExtensions` in `EditorPage`, `HighlightableCodeMirror` for
read-only panes). Debug highlighting already works via `highlightedLinesField` +
Expand Down Expand Up @@ -180,7 +180,7 @@ asserting into `src/utils/` so it can be unit-tested without rendering.

## Checklist

- [ ] Behaviour landed in a hook (or an existing one), not inline in the page
- [ ] Behavior landed in a hook (or an existing one), not inline in the page
- [ ] Pure logic extracted to `src/utils/` where it could be unit-tested
- [ ] No new global store for editor state
- [ ] Tailwind only; matches the dark theme and neighbouring focus rings
Expand Down
12 changes: 8 additions & 4 deletions .claude/skills/verify/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ without a login the AI panel shows a sign-in prompt — that's expected.

## Drive it (selenium)

`selenium-webdriver` + `chromedriver` are devDependencies. **chromedriver's
major version must match the installed Chrome major** (`"/Applications/
Google Chrome.app/Contents/MacOS/Google Chrome" --version`). Run scripts
from the repo root so `require('selenium-webdriver')` resolves.
`selenium-webdriver` is a devDependency; there is deliberately **no
`chromedriver` package**. Selenium Manager (built into selenium-webdriver)
downloads a chromedriver matching whatever Chrome is installed and caches it
under `~/.cache/selenium`, so nothing needs re-pinning when Chrome updates.
Don't reintroduce the `chromedriver` npm package — `npm run` puts
`node_modules/.bin` on `PATH`, so a pinned driver shadows Selenium Manager and
breaks on the next Chrome release. Run scripts from the repo root so
`require('selenium-webdriver')` resolves.

Gotchas learned the hard way:

Expand Down
4 changes: 2 additions & 2 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Three routes, each a thin composition layer over hooks:

All other paths redirect to `/v2/editor`; there is no separate landing route.

**Behaviour lives in `src/hooks/`, not in the pages.** The important ones:
**Behavior lives in `src/hooks/`, not in the pages.** The important ones:
`useCodeParsing` (text → AST → translation), `useCodeDebugger` (step-through),
`useProgramRunner` (plain run that pauses on `input()` and resumes — shared by
the editor and the embed player), `useEditorExecution` / `useEmbedExecution`
Expand Down Expand Up @@ -98,7 +98,7 @@ npx tsc --noEmit # Type-check only
## Testing

- **Unit tests** (`tests/`): One file per language, plus `round-trip.test.ts`, `examples.test.ts`, and cross-cutting files (`control-flow`, `comments`, `blank-lines`, `blocks`, `debugger`, `bugfixes`, `placeholder`, `chatStore`). There is **no DOM environment** — test the compiler pipeline and pure modules directly.
- **API shapes worth memorising**: `tokenize(): Token[]`, `parse(): Program`, `interpret(program, source): string[]` (an array of lines, not a string), `translate(program, target): string`.
- **API shapes worth memorizing**: `tokenize(): Token[]`, `parse(): Program`, `interpret(program, source): string[]` (an array of lines, not a string), `translate(program, target): string`.
- **CSV test matrix** (`csv/praxly.test.csv`): Columns are `Test Name | Program Code | User Input | Expected Output | Expected Error`. Selenium runs each row in a headless browser. **Do not edit this file** — those snippets are the original regression suite.
- Details and patterns: the [`add-tests` skill](../.claude/skills/add-tests/SKILL.md).

Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The **Visitor pattern** (`src/language/visitor.ts`) is the spine. Every emitter
1. **One Universal AST** — parsers produce only nodes defined in `ast.ts`. Never add language-specific node types.
2. **All AST nodes require `id: generateId()`** — the debugger and source maps depend on unique IDs.
3. **TypeScript strict mode** — `noUnusedLocals` and `noUnusedParameters` are on. Every new `visit*` method must be listed as `abstract` in `ASTVisitor`.
4. **No global store for editor state** — pages are composition only; behaviour lives in hooks under `src/hooks/`, pure transforms in `src/utils/`. Zustand (`src/store/appStore.ts`) covers only chat, AI prefs, BYOK, and the editor bridge.
4. **No global store for editor state** — pages are composition only; behavior lives in hooks under `src/hooks/`, pure transforms in `src/utils/`. Zustand (`src/store/appStore.ts`) covers only chat, AI prefs, BYOK, and the editor bridge.
5. **When adding a new `Statement` node type**: update `ast.ts`, `visitor.ts` (abstract method + dispatch case), all 4+ emitters, `interpreter.ts`, and `translator.ts` (recurse into body in `analyzeBlock`).

## Key files to read first
Expand Down
18 changes: 9 additions & 9 deletions csv/selenium.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ const INPUT_WAIT_MS = OPTIONS.inputWaitMs; // wait for stdin prompt per line
const STARTUP_SETTLE_MS = OPTIONS.startupSettleMs;
const EDITOR_ACTION_DELAY_MS = Math.min(80, Math.max(20, Math.floor(INPUT_DELAY_MS / 2) || 40));

// ─── ANSI colour helpers ─────────────────────────────────────────────────────
// ─── ANSI color helpers ──────────────────────────────────────────────────────

const C = {
reset: '\x1b[0m',
Expand Down Expand Up @@ -275,9 +275,9 @@ function renderProgressBar(passed: number, failed: number, total: number, curren
process.stdout.write(`\r [${bar}] ${stats} `);
}

// ─── Normalise output for comparison ─────────────────────────────────────────
// ─── Normalize output for comparison ─────────────────────────────────────────

function normalise(s: string = ''): string {
function normalize(s: string = ''): string {
return s
.replace(/\r\n/g, '\n')
.split('\n')
Expand Down Expand Up @@ -328,10 +328,10 @@ async function setEditorCode(driver: WebDriver, code: string): Promise<void> {
}

/**
* Click the "Run Code" button in the header toolbar.
* Click the "Run" button in the header toolbar.
*/
async function clickRun(driver: WebDriver): Promise<void> {
const runBtn = await driver.findElement(By.xpath("//button[contains(., 'Run Code')]"));
const runBtn = await driver.findElement(By.css('button[aria-label="Run code (F5)"]'));
await runBtn.click();
}

Expand Down Expand Up @@ -612,12 +612,12 @@ async function runTests(): Promise<void> {
await driver.sleep(RUN_SETTLE_MS);

// Read results
actualOut = normalise(await readOutputPanel(driver));
actualErr = normalise(await readErrorText(driver));
actualOut = normalize(await readOutputPanel(driver));
actualErr = normalize(await readErrorText(driver));

// Compare
const normExpOut = normalise(expectedOut);
const normExpErr = normalise(expectedErr);
const normExpOut = normalize(expectedOut);
const normExpErr = normalize(expectedErr);

if (normExpErr) {
// This test expects a runtime/compile error
Expand Down
2 changes: 1 addition & 1 deletion docs/COMPONENT_REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ emitters — `tsc` will list the ones you miss.

**Precedence constants** (`Member: 18` down to `Sequence: 1`) live in the same
file; pass them as `parentPrecedence` so `generateExpression` knows when to
parenthesise.
parenthesize.

### Example: Python Emitter

Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ src/
│ ├── layoutConstants.ts # Pixel budgets for every pane
│ └── types.ts # The Panel type
│─────────────────────────────────────────────────────────────
├── hooks/ # All page behaviour lives here
├── hooks/ # All page behavior lives here
│ ├── useCodeParsing.ts # Source text → AST → translation + source map
│ ├── useCodeDebugger.ts # Step-through debug state machine
│ ├── useProgramRunner.ts # Plain run that pauses on input() and resumes
Expand Down
Loading
Loading