Skip to content

feat: syntax version validation, upgrade command, and unknown block detection#146

Merged
mrwogu merged 20 commits intomainfrom
feat/syntax-version-validation
Mar 22, 2026
Merged

feat: syntax version validation, upgrade command, and unknown block detection#146
mrwogu merged 20 commits intomainfrom
feat/syntax-version-validation

Conversation

@mrwogu
Copy link
Owner

@mrwogu mrwogu commented Mar 21, 2026

Summary

  • Central syntax version registry in @promptscript/core mapping versions to supported blocks (1.0.0 → 11 blocks, 1.1.0 → +agents, workflows, prompts)
  • PS018 syntax-version-compat — warns when declared syntax version is unknown or blocks require a higher version than declared
  • PS019 unknown-block-name — warns on unknown block types with Levenshtein fuzzy matching (e.g., @agenst → "Did you mean @agentS?")
  • prs validate --fix — auto-fixes syntax version to minimum required (conservative)
  • prs upgrade [--dry-run] — bumps all files to latest syntax version (aggressive)
  • Levenshtein distance utility in core for reuse
  • Documentation updates across core, validator, CLI READMEs, language reference, and SKILL.md

Motivation

Users could write syntax: "1.4.7" (confusing package version with syntax version) or syntax: "1.0.0" with @agents (a 1.1.0 feature) — both compiled silently. Typos like @agenst also went undetected.

Test plan

  • 12 tests for Levenshtein utility
  • 13 tests for syntax version registry (incl. BLOCK_TYPES consistency)
  • 10 tests for PS018 (unknown version, block mismatch, extends, edge cases)
  • 7 tests for PS019 (fuzzy match, full list fallback, extends, multiple unknowns)
  • 6 tests for fixSyntaxVersion (upgrade, no-downgrade, meta-scoped, string literals)
  • 3 tests for upgrade command
  • Full verification pipeline passes (format, lint, typecheck, test, validate, schema:check, skill:check, docs:formatters:check)

mrwogu added 14 commits March 20, 2026 22:51
Prevent future release-please breakage by adding a restriction
against manually editing CHANGELOG.md, which is managed by
release-please.
Address review findings:
- PS004 → PS018 (PS004 already taken by required-guards)
- Clarify cumulative block lists in registry
- Scope regex replace to @meta block only
- Add CLI registration details and file manifest
- Define preset severities and edge cases for custom blocks
- Use existing compareVersions from core
- Remove directives from interface (YAGNI)
Catches typos and invented block names with Levenshtein fuzzy
matching suggestions (e.g., @agenst → "Did you mean @agentS?").
- Add isValidSemver guard in PS018 to prevent compareVersions throw
- Specify meta block boundary finding for --fix implementation
- Use rule names (not IDs) as preset keys per convention
- PS019 uses walkBlocks + isBlockType from existing utilities
- Move Levenshtein to core/utils for reuse
- Add explicit no-downgrade rule for --fix
- Add documentation update plan
- Expand files modified with grouped sections
9 tasks across 7 chunks: Levenshtein utility, syntax registry,
PS018/PS019 rules, validate --fix, prs upgrade, verification, docs.

Reviewed and fixed: type discriminators, ExtendBlock.targetPath,
Block|ExtendBlock narrowing, readdir instead of glob, merged imports.
Introduces SYNTAX_VERSIONS registry mapping 1.0.0 and 1.1.0 to their
supported block types, plus helper functions getLatestSyntaxVersion,
isKnownSyntaxVersion, getBlocksForVersion, and getMinimumVersionForBlock.
- Validates that .prs files declare a known syntax version
- Warns when blocks are used that require a higher syntax version
- Checks both @blocks and @extends blocks via walkBlocks
- Skips unknown block names (deferred to PS019)
- Skips invalid semver, non-string syntax, and missing meta
- Registered in allRules after PS017 (skillContracts)
- Added to all 3 security presets: warning/warning/off
…-fix

Add --fix option to `prs validate` that auto-fixes syntax version
declarations in .prs files. When a file uses blocks requiring a higher
syntax version than declared, --fix updates the @meta syntax field.

Exports fixSyntaxVersion and discoverPrsFiles helpers for reuse by the
upcoming upgrade command.
- core: add utils/levenshtein and syntax-versions to modules table; add
  API reference section documenting SYNTAX_VERSIONS, SyntaxVersionDef,
  LATEST_SYNTAX_VERSION, getLatestSyntaxVersion, isKnownSyntaxVersion,
  getBlocksForVersion, getMinimumVersionForBlock, levenshteinDistance,
  and findClosestMatch
- validator: add full validation rules table (PS001-PS019) including new
  PS018 syntax-version-compat and PS019 unknown-block-name
- cli: document prs validate --fix and prs upgrade [--dry-run] in both
  the commands table and the detailed command usage section
- Fix brace scanner to respect string literals in fixSyntaxVersion
- Extract duplicated getBlockName helper to walker.ts
- Add syntax version docs to language reference and SKILL.md
@codecov
Copy link

codecov bot commented Mar 21, 2026

Codecov Report

❌ Patch coverage is 96.27329% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/cli/src/commands/validate.ts 94.02% 3 Missing and 1 partial ⚠️
packages/cli/src/commands/upgrade.ts 92.85% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codecov
Copy link

codecov bot commented Mar 21, 2026

Bundle Report

Changes will increase total bundle size by 14.07kB (1.35%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
promptscript-cli 1.06MB 14.07kB (1.35%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: promptscript-cli

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.js 10.24kB 947.93kB 1.09%
skills/promptscript/SKILL.md 1.54kB 19.51kB 8.57% ⚠️
README.md 1.1kB 12.19kB 9.91% ⚠️
src/types.d.ts 61 bytes 3.65kB 1.7%
src/types.d.ts.map 43 bytes 2.46kB 1.78%
src/commands/validate.d.ts 374 bytes 612 bytes 157.14% ⚠️
src/commands/validate.d.ts.map 192 bytes 462 bytes 71.11% ⚠️
src/commands/upgrade.d.ts.map (New) 278 bytes 278 bytes 100.0% 🚀
src/commands/upgrade.d.ts (New) 239 bytes 239 bytes 100.0% 🚀

mrwogu added 6 commits March 21, 2026 12:05
prs init was writing syntax: "1.4.7" (package version) instead of
syntax: "1.1.0" (latest syntax version). This caused PS018 to warn
on freshly initialized projects.
Snapshot directories were renamed when language.md gained the syntax
versions section (line numbers shifted), but the claude.md files
were not regenerated at the new paths.
- Add discoverPrsFiles tests: find files, subdirectories, non-existent
  dir, no .prs files
- Add upgradeCommand integration tests using temp directories:
  upgrade, skip-at-latest, dry-run, skip-no-meta, empty dir
- Update doc snapshots
Cover runFix function through validateCommand({ fix: true }):
- Fix syntax when blocks require higher version
- No fixes needed when syntax is correct
- Handle empty .promptscript directory
- Skip files without syntax field
- Reject --fix with --format json
…flows/@prompts

Documentation incorrectly listed @skills as a 1.1.0 addition and
omitted @workflows and @prompts. Fixed to match the code registry:
- 1.0.0: includes @skills along with other core blocks
- 1.1.0: adds @agentS, @workflows, @prompts
**/CLAUDE.md in .gitignore matches lowercase claude.md on macOS
(case-insensitive FS), preventing doc snapshot files from being
committed. Added negation rule for docs/__snapshots__/**/claude.md.
@mrwogu mrwogu merged commit a0cfd99 into main Mar 22, 2026
14 of 15 checks passed
@mrwogu mrwogu deleted the feat/syntax-version-validation branch March 22, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant