Skip to content

H-6323: Add Python language support in Petrinaut#8544

Draft
kube wants to merge 1 commit intomainfrom
cf/h-6323-add-python-language-support-in-petrinaut
Draft

H-6323: Add Python language support in Petrinaut#8544
kube wants to merge 1 commit intomainfrom
cf/h-6323-add-python-language-support-in-petrinaut

Conversation

@kube
Copy link
Collaborator

@kube kube commented Mar 13, 2026

🌟 What is the purpose of this PR?

Adds Python as a supported code language in Petrinaut alongside TypeScript. Users can now write transition/place logic in Python with full language intelligence (completions, diagnostics, hover, signature help) powered by Pyright running in a WebWorker.

🔗 Related links

🔍 What does this change?

  • Language model: Add language?: "typescript" | "python" field to the SDCPN type, with getSDCPNLanguage() helper defaulting to TypeScript
  • Settings UI: New "Settings" tab (first position in BottomPanel) with a language selector that updates the SDCPN definition
  • Python virtual files: Generate .py/.pyi stubs (TypedDict definitions, import prefixes) from the SDCPN model, mirroring the existing TypeScript virtual file system
  • Pyright integration: New usePyrightClient hook managing a Pyright WebWorker via monaco-pyright-lsp, exposing the same LanguageClientApi interface as the TypeScript client. The provider automatically switches between TS and Pyright based on SDCPN language
  • URI mapping: Bidirectional PyrightUriMap class to correctly translate between Pyright filesystem paths (which strip hyphens from UUIDs for Python import compatibility) and Monaco/internal URIs
  • Python example: Satellites example ported to Python
  • Monaco providers: Completion, hover, and signature help providers now register for both typescript and python language IDs

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph

🛡 What tests cover this?

  • Existing unit tests for document URI handling and file path utilities (extended for .py/.pyi)
  • All 277 petrinaut tests pass

❓ How to test this?

  1. Checkout the branch
  2. Open Petrinaut, go to the Settings tab and switch language to Python
  3. Confirm diagnostics, completions, hover, and signature help work in Python code editors
  4. Load the "Satellites (Python)" example and verify it functions correctly

- Add language field to SDCPN type with TypeScript/Python options
- Create Settings tab in BottomPanel with language selector
- Add Python default code templates and virtual file generation
- Integrate Pyright language server via monaco-pyright-lsp for
  completions, diagnostics, hover, and signature help
- Add Satellites (Python) example
- Fix URI mapping between Pyright/Monaco with bidirectional PyrightUriMap
  to correctly resolve sanitized Python paths back to SDCPN entity IDs
- Register Monaco language providers for both TypeScript and Python

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Mar 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hash Error Error Mar 13, 2026 3:05am
petrinaut Ready Ready Preview Mar 13, 2026 3:05am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
hashdotdesign Ignored Ignored Preview Mar 13, 2026 3:05am
hashdotdesign-tokens Ignored Ignored Preview Mar 13, 2026 3:05am

@github-actions github-actions bot added area/deps Relates to third-party dependencies (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team labels Mar 13, 2026
Copy link
Collaborator Author

kube commented Mar 13, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

if (!(part in current) || typeof current[part] === "string") {
current[part] = {};
}
current = current[part] as UserFolder;

Check warning

Code scanning / Semgrep PRO

Semgrep Finding: javascript.lang.security.audit.prototype-pollution.prototype-pollution-loop.prototype-pollution-loop Warning

Possibility of prototype polluting function detected. By adding or modifying attributes of an object prototype, it is possible to create attributes that exist on every object, or replace critical attributes with malicious ones. This can be problematic if the software depends on existence or non-existence of certain attributes, or uses pre-defined attributes of object prototype (such as hasOwnProperty, toString or valueOf). Possible mitigations might be: freezing the object prototype, using an object without prototypes (via Object.create(null) ), blocking modifications of attributes that resolve to object prototype, using Map instead of object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/deps Relates to third-party dependencies (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team

Development

Successfully merging this pull request may close these issues.

1 participant