Skip to content

FE-1161: Petrinaut CLI#8975

Merged
kube merged 12 commits into
mainfrom
cf-petrinaut-python
Jul 15, 2026
Merged

FE-1161: Petrinaut CLI#8975
kube merged 12 commits into
mainfrom
cf-petrinaut-python

Conversation

@kube

@kube kube commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

🌟 What is the purpose of this PR?

Add an internal Petrinaut CLI for Python optimization services. The CLI loads and type-checks one model once, then runs repeated simulations with different parameters, initial markings, metrics, and seeds without restarting Node for every trial.

🔍 What does this change?

  • Adds the private @hashintel/petrinaut-cli workspace package.
  • Adds a reusable compilePetrinautModel facade in Petrinaut Core.
  • Supports JSON Lines over stdio by default, with Unix sockets as an alternative.
  • Exposes healthz, metadata, and run protocol methods.
  • Supports uncolored token counts and explicit colored-token records.
  • Adds a reusable Python stdio wrapper and Optuna integration examples.
  • Includes example models covering parameters, metrics, and multiple color schemas.

🚀 Quick usage

# Build the CLI once
turbo --filter @hashintel/petrinaut-cli build

# Run the bundled SIR model through the Python stdio wrapper
python3 libs/@hashintel/petrinaut-cli/examples/python_stdio.py --demo

See the Python and Optuna integration guide and the parameter, metric, and colored-token examples.

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:

  • require changes to docs which are made as part of this PR

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

The changes in this PR:

  • affected the execution graph, and the turbo.json's have been updated to reflect this

⚠️ Known issues

  • A CLI process executes simulation requests serially.
  • Metrics are evaluated on the final frame; full frame histories are not returned.

🛡 What tests cover this?

Core regression tests cover run-limit validation and generated seeds. The CLI is also verified through package type-checking, linting, building, and end-to-end protocol smoke tests.

  • yarn workspace @hashintel/petrinaut-core test:unit src/simulation/compiled-model.test.ts
  • yarn workspace @hashintel/petrinaut-cli lint:tsc
  • yarn workspace @hashintel/petrinaut-cli lint:eslint
  • yarn workspace @hashintel/petrinaut-cli build
  • Python stdio SIR demo
  • Unix-socket metadata and run smoke test
  • Colored-token and multi-color model smoke tests

❓ How to test this?

  1. Build the CLI:
    turbo --filter @hashintel/petrinaut-cli build
  2. Run the Python stdio demo:
    python3 libs/@hashintel/petrinaut-cli/examples/python_stdio.py --demo
  3. Confirm the result contains seed 4242, final place token counts, and the Infected Fraction metric.
  4. Optionally follow libs/@hashintel/petrinaut-cli/MODEL_EXAMPLES.md to try colored-token models.

@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
hash Ready Ready Preview, Comment Jul 15, 2026 12:51pm
petrinaut Ready Ready Preview Jul 15, 2026 12:51pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
hashdotdesign-tokens Ignored Ignored Preview Jul 15, 2026 12:51pm

@github-actions github-actions Bot added area/deps Relates to third-party dependencies (area) area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team labels Jul 8, 2026
Comment thread libs/@hashintel/petrinaut-core/src/simulation/compiled-model.ts Fixed
Comment thread libs/@hashintel/petrinaut-core/src/simulation/compiled-model.ts Outdated
@vercel vercel Bot temporarily deployed to Preview – petrinaut July 8, 2026 23:33 Inactive
@kube kube force-pushed the petrinaut-lang branch from 328afb2 to 43b98ea Compare July 14, 2026 12:51
@kube kube force-pushed the cf-petrinaut-python branch from 7ac9ad3 to db505a8 Compare July 14, 2026 12:54
@kube kube changed the base branch from petrinaut-lang to cf/fe-629-add-an-intermediate-representation-for-petrinaut July 14, 2026 14:29
Base automatically changed from cf/fe-629-add-an-intermediate-representation-for-petrinaut to main July 14, 2026 18:48
@github-actions github-actions Bot added the area/apps > hash.design Affects the `hash.design` design site (app) label Jul 14, 2026
@kube kube force-pushed the cf-petrinaut-python branch from db505a8 to 8017f0c Compare July 14, 2026 23:20
@github-actions github-actions Bot removed the area/apps > hash.design Affects the `hash.design` design site (app) label Jul 14, 2026
@vercel vercel Bot temporarily deployed to Preview – petrinaut July 15, 2026 10:18 Inactive
@kube kube marked this pull request as ready for review July 15, 2026 10:27
Copilot AI review requested due to automatic review settings July 15, 2026 10:27
@cursor

cursor Bot commented Jul 15, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
New long-lived CLI and protocol surface on top of the simulation engine; mistakes in run parsing or compilation could affect optimization jobs, but there is no HTTP/auth exposure and the package is private with solid unit and transport tests.

Overview
Introduces the private @hashintel/petrinaut-cli package so scripts and Python optimization loops can run one Petrinaut model many times without restarting Node. petrinaut serve --model <path> loads and compiles the model once (via a new @hashintel/petrinaut-core/compiled-model export), then serves healthz, metadata, and run over JSON Lines on stdio (default) or a Unix socket.

run accepts parameters, initial markings (integer counts or colored token objects), metrics, maxSteps / maxTime, dt, and seed, and returns summary results (final-frame metrics, completion reason, root-place token counts). Request parsing validates markings and resolves parameter/place keys by id, variable name, or display name.

Also adds bundled example models, examples/python_stdio.py (stdlib PetrinautClient), and integration docs for Optuna-style workflows.

Reviewed by Cursor Bugbot for commit 47a4f11. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread libs/@hashintel/petrinaut-cli/src/runtime/run-request.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1d89519. Configure here.

Comment thread libs/@hashintel/petrinaut-cli/src/runtime/protocol.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 36 out of 37 changed files in this pull request and generated 7 comments.

Comment thread libs/@hashintel/petrinaut-core/src/simulation/compiled-model.ts
Comment thread libs/@hashintel/petrinaut-core/src/simulation/compiled-model.ts Outdated
Comment thread libs/@hashintel/petrinaut-core/src/simulation/compiled-model.ts Outdated
Comment thread libs/@hashintel/petrinaut-cli/src/commands/serve.ts Outdated
Comment thread libs/@hashintel/petrinaut-core/src/simulation/compiled-model.ts Outdated
Comment thread libs/@hashintel/petrinaut-core/src/simulation/compiled-model.ts
Comment thread libs/@hashintel/petrinaut-cli/src/runtime/run-request.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 36 out of 37 changed files in this pull request and generated 5 comments.

Comment thread libs/@hashintel/petrinaut-core/src/parameter-values.ts Outdated
Comment thread libs/@hashintel/petrinaut-core/src/simulation/compiled-model.ts
Comment thread libs/@hashintel/petrinaut-cli/src/commands/serve.ts Outdated
Comment thread libs/@hashintel/petrinaut-core/src/simulation/compiled-model.ts Outdated
Comment thread libs/@hashintel/petrinaut-core/src/schemas/entity-schemas.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 37 out of 38 changed files in this pull request and generated 8 comments.

Comment thread libs/@hashintel/petrinaut-cli/package.json
Comment thread libs/@hashintel/petrinaut-core/src/parameter-values.ts Outdated
Comment thread libs/@hashintel/petrinaut-cli/src/commands/serve.ts Outdated
Comment thread libs/@hashintel/petrinaut-core/src/simulation/compiled-model.ts
Comment thread libs/@hashintel/petrinaut-core/src/simulation/compiled-model.ts
Comment thread libs/@hashintel/petrinaut-core/src/simulation/compiled-model.ts Outdated
Comment thread libs/@hashintel/petrinaut-core/src/schemas/entity-schemas.ts Outdated
Comment thread libs/@hashintel/petrinaut-core/src/parameter-values.ts Outdated
Copilot AI review requested due to automatic review settings July 15, 2026 12:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@kube kube added this pull request to the merge queue Jul 15, 2026
Merged via the queue into main with commit f4bcb55 Jul 15, 2026
50 of 52 checks passed
@kube kube deleted the cf-petrinaut-python branch July 15, 2026 13:39
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/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team type/legal Owned by the @legal team

Development

Successfully merging this pull request may close these issues.

5 participants