diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index cd0d9a9..7b99187 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -31,6 +31,15 @@ Core streaming modes: * `events(input)`: full enter/exit/text event stream * `parseChunked(chunks)`: progressive completed block nodes +## Writing and explanation style + +* Use familiar language that a reasonably experienced JavaScript or TypeScript developer would understand without pausing. +* Do not swap one hard word for another and call that plain English. +* If you need a technical term, explain the concrete behavior first, then introduce the term if it still helps. +* Ground abstract explanations in something the reader can picture here: a code path, a marker sequence, a bug, a performance cost, or a downstream benefit. +* When using a technical term such as `lexical`, `invariant`, or `delimiter`, explain what that means in this codebase, not just in theory. +* Diagrams must match real behavior in the implementation or spec. Do not simplify them into something that teaches the wrong thing. + ## Non-negotiable parser contracts * Event well-formedness: every `enter(X)` has a matching `exit(X)` with proper nesting. @@ -46,7 +55,12 @@ Core streaming modes: * If something is unclear, state the assumption and give a concrete verification step. * Prefer established standards and conventions when they fit the problem. * Call out trade-offs when multiple valid approaches exist. -* Optimize for maintainability, clarity, and reproducibility. +* Optimize for maintainability, clarity, reproducibility, and educational value. +* Use plain English in docs, comments, TSDoc, PR prose, and explanations. +* When technical or abstract terms are necessary, define them in grounded language that starts from something concrete the unfamiliar reader can picture. +* Do not replace one abstract phrase with another abstract phrase and call it clarity. +* Tie abstractions to real behavior, cost, failure mode, or downstream benefit. +* Verify diagrams, examples, and explanatory claims against the implementation before presenting them as fact. * Avoid em dashes in prose. ## Safety and correctness diff --git a/.github/instructions/docs-writing.instructions.md b/.github/instructions/docs-writing.instructions.md index 5f53576..2231d54 100644 --- a/.github/instructions/docs-writing.instructions.md +++ b/.github/instructions/docs-writing.instructions.md @@ -23,6 +23,9 @@ Use this as a default shape, not a rigid template. - Use plain English. - Define technical terms the first time they matter. +- Ground abstract ideas in something concrete before or while naming them. +- Do not stop at a simpler rewording when the reader still cannot picture the idea. +- Tie explanations to a real behavior, cost, failure mode, example, or downstream benefit. - Keep a steady narrative flow. - Prefer transition sentences over unnecessary headers. - Use active voice. @@ -31,6 +34,36 @@ Use this as a default shape, not a rigid template. - Expand acronyms on first use. - Avoid em dashes. +When a term is unfamiliar or domain-specific, explain it in a way a new reader can picture. + +Good: +- `Lexical means we are still looking at the raw text shapes, like [[ or ==, before later stages decide what those characters mean in context.` +- `Idempotent means you can run the same cleanup step again and nothing changes after the first successful pass.` + +Weak: +- `Lexical means about raw text shapes before meaning is known.` +- `Idempotent means the operation is idempotent.` + +The goal is not just to swap jargon for simpler jargon. The goal is to help the reader build a working mental model. + +## Grounding abstract concepts + +Abstract explanations need an anchor. + +Before using a specialized term, or immediately after introducing it, connect it to at least one of these: +- a concrete input or output +- a real user or caller problem +- a visible behavior in the system +- a cost such as allocation, latency, or complexity +- a failure mode or edge case +- a downstream benefit for maintainers or consumers + +Examples: +- Instead of `Tokens preserve source fidelity`, explain that consumers can reconstruct the exact original text because each token points at offsets in the source instead of storing a rewritten value. +- Instead of `This uses structural validation`, explain that the check looks at the shape of the value at runtime, such as whether it has a known `type` string and numeric offsets, without caring which class created it. + +If the reader would reasonably ask `So what does that mean here?`, answer that question in the prose. + ## Header rules Add a header only when it improves navigation more than a transition sentence would. @@ -63,6 +96,27 @@ Weak: If the next paragraph continues the same idea, do not add a header. +## Grounding abstract ideas + +Do not stop at a shorter definition if the reader still cannot picture what is happening. + +Bad: +- `Lexical means about raw text shapes before meaning is known.` +- `This function preserves an invariant.` +- `The parser reads delimiters.` + +Better: +- `This stage only notices text patterns such as `[[`, `{{`, or `==`. It does not decide what they mean yet. For example, it can see `[[Category:Foo]]`, but a later stage decides whether that becomes a normal link or a category assignment. That early text-only stage is called lexical parsing.` +- `This function keeps one rule true from start to finish: every token starts where the previous token ended, so the token stream covers the whole input with no gaps.` +- `The parser reads marker characters such as `[[`, `]]`, `{{`, and `|`. These markers open, close, or split parts of wiki syntax. Many parser docs call those markers delimiters.` + +When explaining a hard idea, try this order: +1. Say what happens in concrete terms. +2. Say why that matters here. +3. Introduce the technical name only if it helps the reader later. + +If the reader would likely ask `what does that look like here?`, answer that question immediately. + ## Examples and visual aids Use examples when they materially improve understanding. @@ -77,6 +131,9 @@ Use ASCII diagrams when they clarify: Do not add diagrams just to decorate the prose. Always explain what the reader is looking at before or after the diagram. +Diagrams must match real behavior in the code or spec. Do not simplify them into something that teaches the wrong thing. + +Diagrams must match the real behavior, naming, and invariants of the code. If a diagram would force you to guess, verify the code first or omit the diagram. ## Specs and design notes @@ -100,4 +157,6 @@ Keep decisions concrete. Make trade-offs explicit. State assumptions plainly. - Do not list features before explaining the problem they solve. - Do not create many tiny headers that simply label the next paragraph. - Do not hedge with soft filler language when the point can be stated directly. -- Do not explain implementation details before the reader understands why they matter. \ No newline at end of file +- Do not explain implementation details before the reader understands why they matter. +- Do not replace one abstract phrase with another abstract phrase and call it clarity. +- Do not use diagrams or examples that overstate certainty beyond what the implementation actually guarantees. diff --git a/.github/instructions/tsdoc-comments.instructions.md b/.github/instructions/tsdoc-comments.instructions.md index e0075d8..b3af196 100644 --- a/.github/instructions/tsdoc-comments.instructions.md +++ b/.github/instructions/tsdoc-comments.instructions.md @@ -10,10 +10,10 @@ applyTo: "**/*.ts,**/*.tsx" Comments and TSDoc should explain: - intent - constraints -- invariants - assumptions - edge cases - reasoning behind tricky choices +- the concrete rule that must stay true, when that matters Do not use comments to restate obvious code. @@ -29,6 +29,19 @@ Then explain the high-level approach if the implementation model matters. Prefer compact, flowing prose unless the API is conceptually deep. +Use plain English by default. When a technical term is worth keeping, define it in grounded language the first time it matters. + +Do not stop at a shorter or softer paraphrase if the reader still cannot picture what the concept means in this codebase. + +Good: +- `This scanner is lexical, which means it only recognizes raw delimiter shapes like [[, {{, or ==. It does not decide the final meaning of those characters yet.` +- `This invariant says adjacent token ranges meet exactly at the boundary, so rebuilding the source does not lose or duplicate characters.` + +Weak: +- `This scanner is lexical.` +- `This preserves source fidelity.` +- `This maintains an invariant.` + ## Section and header discipline in TSDoc Do not add section headers inside a doc block unless they improve navigation. @@ -49,9 +62,9 @@ Avoid: If the prose naturally continues the same idea, use a transition sentence instead of a header. -## Complex logic comments +## Grounding complex and abstract ideas -When code is non-obvious, explain it in plain English. +When code is non-obvious, explain it in plain English and anchor the explanation in something concrete. This especially applies to: - parser recovery @@ -61,13 +74,19 @@ This especially applies to: - state machines - performance-sensitive code - tricky boolean conditions +- domain-specific parsing terms When useful, include: - the problem being handled -- the key invariant +- the key invariant and what it protects against - the step-by-step logic -- a short example +- a short example with real input or output - an ASCII diagram if it makes the logic easier to follow +- the practical meaning of any jargon that remains + +A good explanation answers both of these: +- `What does this term mean?` +- `What does it mean here, in this code?` ## Examples @@ -79,10 +98,20 @@ Use examples for: Prefer examples that show a real caller scenario, not a toy snippet with no context. +## Diagrams and accuracy + +Use diagrams only when they make the code easier to understand. + +Every diagram and example must match the real behavior of the implementation. Do not let a simplified explanation teach the wrong contract. + +If a name, boundary, or token kind is uncertain, verify it before documenting it. + ## Anti-patterns - Do not write essay-length doc blocks for simple APIs. - Do not invent generic section labels. - Do not restate parameter names without adding meaning. - Do not explain obvious syntax while skipping the real reasoning. -- Do not use comments to compensate for poor naming when renaming would be clearer. \ No newline at end of file +- Do not use comments to compensate for poor naming when renaming would be clearer. +- Do not replace domain jargon with different jargon and call it plain English. +- Do not write comments that sound more certain than the implementation really is. diff --git a/.github/instructions/typescript.instructions.md b/.github/instructions/typescript.instructions.md index dd87cd0..ddd7eae 100644 --- a/.github/instructions/typescript.instructions.md +++ b/.github/instructions/typescript.instructions.md @@ -65,9 +65,12 @@ Examples: For every exported function, interface, type alias, and constant: -- Write TSDoc in plain English. +- Write TSDoc in familiar language that a reasonably experienced JavaScript or TypeScript developer would understand without pausing. - Explain why it exists, not just what it is. - Ground the explanation in the problem being solved, the approach taken, and the assumptions or edge cases. +- If you need a technical term, explain the concrete behavior first, then introduce the term if it is still useful. +- When using technical or abstract terms, define them in concrete language the reader can picture in this codebase. +- Tie abstractions to a real behavior, cost, failure mode, or downstream benefit. - Every field of an exported interface or public type needs its own JSDoc comment. - Any type referenced in a public signature must itself be exported. @@ -118,6 +121,7 @@ When needed, include: * the key assumptions * a step-by-step walkthrough * clarification of abstract codes or markers +* a grounded explanation of technical terms * an ASCII diagram if it materially improves understanding ## Error handling