Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
| tookLetters ||= wordCharacter.test( | ||
| transaction.startState.sliceDoc(from, to), | ||
| ); |
There was a problem hiding this comment.
🟡 Medium severity issue identified in your code:
Ensure that the regex used to compare with user supplied input is safe from regular expression denial of service.
🎈 Fixed in commit 956e8ed 🎈
| const assistant = anthropicAssistant( | ||
| anthropicApiKey, | ||
| "Add an Anthropic API key in Settings, under Labs, to have Claude write the expression.", | ||
| ); |
There was a problem hiding this comment.
🟠 High severity issue identified in your code:
A hardcoded API Key is identified. Store it properly in an environment variable.
🌟 Fixed in commit 157aa08 🌟
| anthropicAssistant( | ||
| apiKey, | ||
| "Type an Anthropic API key under Assistant, on the left, to have Claude write the expression.", | ||
| ); |
There was a problem hiding this comment.
🟠 High severity issue identified in your code:
A hardcoded API Key is identified. Store it properly in an environment variable.
To resolve this comment:
🔧 No guidance has been designated for this issue. Fix according to your organization's approved methods.
💬 Ignore this finding
Reply with Semgrep commands to ignore this finding.
/fp <comment>for false positive/ar <comment>for acceptable risk/other <comment>for all other reasons
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by node_api_key.
You can view more details about this finding in the Semgrep AppSec Platform.
| anthropicAssistant( | ||
| apiKey, | ||
| "Type an Anthropic API key under Assistant, on the left, to have Claude write the expression.", | ||
| ); |
| tookLetters ||= wordCharacter.test( | ||
| transaction.startState.sliceDoc(from, to), | ||
| ); |
One language for both, in a formula style and a fluent style: a tokenizer, a parser, a check that reports each error with a fix where it has one, a formatter, an evaluator over a state or a run, and the form a metric is stored in. A loop asks a model for an expression and feeds the check back until one passes; core holds no model and no key.
A CodeMirror field for a metric or a constraint: names of the model as chips, function calls as lightly coloured frames, completion, an argument hint, and the value or the first error under the field. A sparkles button turns the field into a request that Claude answers through the Anthropic SDK, and only an expression that passes the check replaces the text. Stories cover both styles, constraints and the assistant with a scripted model.
With Metric expressions on in Labs, the metric properties panel shows the expression field in place of the code editor for a metric written as an expression. An Anthropic API key in the same section lets the field be asked in words. Off by default; the user guide describes both.
Language: a fluent call at the end of the text no longer throws; a named condition in a constraint, a double minus and a negative percentile share lower to what they evaluate to; metrics that read metrics are checked and evaluated in linear time; converting between styles keeps the meaning of a let used as a list and refuses a name the other style would capture; the innermost binding of a name wins; a line terminator in the text cannot end the comment a metric stores it in. The assistant loop makes no call once stopped, reports an empty reply as a failed attempt, and leaves names it cannot write out of its instructions. Field: the text stays visible when the field turns read-only under an open request; completion keeps names with an underscore; a change from outside is not written back, is not undoable from the field, and leaving an untouched field changes nothing; the error row is linked to the text for assistive technology; switching Metric expressions off forgets the API key. The CodeMirror extensions are split by concern, the function table and the lowering share their tables with evaluation, unused exports are gone, and the stories keep one per behaviour.
…nly authoring Constraints become entities of the model, written in the expression language: `SDCPN.constraints`, add/update/remove actions, a `constraint` selection kind, a Constraints group in the Entities pane and a properties panel. This changes the file format: a net gains an optional `constraints` list. `metrics.<name>` reads a model metric in TypeScript metrics, lambdas and kernels. It lowers to a `metricRef` node, and `hir/link-metrics.ts` binds each metric read once at the top of the reader, with cycle detection. Lambdas and kernels take the frame's place counts and offsets, so the stepped, Monte Carlo and event-driven engines give the value at the instant a transition is evaluated. Differential equations and transitions of a component read none. Metrics and constraints are written as expressions only, in the properties panel and in the Simulate view's metric drawer. A metric written in TypeScript, from a model saved before, is shown read-only and can be deleted. An expression can read such a metric by name. The net-wide check reports metrics and constraints that do not check. Their errors never stop a run. The expression field has four versions, chosen by the `expressionField` user setting that replaces the Labs flag: the first one, text that breaks between arguments, text laid out by the formatter, and slots on the tree. Every version undoes and redoes. The named-token function form and the Storybook model editors are removed.
… editor The constraint panel edits the id through the rename engine, the metric drawer's test and the mutation test move to ids, Brunch and the website label a renamed constraint, and the guide says ID where it said name.
157aa08 to
53d0b5d
Compare
The flag was a `let` set inside the mapping callback, which TypeScript narrows to its initial value at the read, so lint reported the condition as always falsy. It is now read off the mapped list.
A list of tokens written where a number is needed is how many tokens it holds, in the check, in evaluation and in lowering, so `Infected / Population` needs no `.count`. `.count` stays valid and gives the same body. SUM, AVERAGE, MIN and MAX given a list are over its tokens where the next argument reads the token, and take numbers otherwise: `MAX(Queue, Served)` is the larger of two counts. The check decides, and evaluation and lowering read its answer, so `evaluateExpression` takes the checked names in place of the references. A method that reads no token is an error, because the same tree written as a function would mean something else.
Benchmark results
|
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| resolve_policies_for_actor | user: empty, selectivity: high, policies: 2002 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: medium, policies: 1002 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: high, policies: 3314 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: medium, policies: 1527 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: high, policies: 2078 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: medium, policies: 1033 | Flame Graph |
policy_resolution_medium
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| resolve_policies_for_actor | user: empty, selectivity: high, policies: 102 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: medium, policies: 52 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: high, policies: 269 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: medium, policies: 108 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: high, policies: 133 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: medium, policies: 63 | Flame Graph |
policy_resolution_none
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| resolve_policies_for_actor | user: empty, selectivity: high, policies: 2 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: medium, policies: 2 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: high, policies: 8 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: medium, policies: 3 | Flame Graph |
policy_resolution_small
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| resolve_policies_for_actor | user: empty, selectivity: high, policies: 52 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: medium, policies: 26 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: high, policies: 94 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: medium, policies: 27 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: high, policies: 66 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: medium, policies: 29 | Flame Graph |
read_scaling_complete
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_id;one_depth | 1 entities | Flame Graph | |
| entity_by_id;one_depth | 10 entities | Flame Graph | |
| entity_by_id;one_depth | 25 entities | Flame Graph | |
| entity_by_id;one_depth | 5 entities | Flame Graph | |
| entity_by_id;one_depth | 50 entities | Flame Graph | |
| entity_by_id;two_depth | 1 entities | Flame Graph | |
| entity_by_id;two_depth | 10 entities | Flame Graph | |
| entity_by_id;two_depth | 25 entities | Flame Graph | |
| entity_by_id;two_depth | 5 entities | Flame Graph | |
| entity_by_id;two_depth | 50 entities | Flame Graph | |
| entity_by_id;zero_depth | 1 entities | Flame Graph | |
| entity_by_id;zero_depth | 10 entities | Flame Graph | |
| entity_by_id;zero_depth | 25 entities | Flame Graph | |
| entity_by_id;zero_depth | 5 entities | Flame Graph | |
| entity_by_id;zero_depth | 50 entities | Flame Graph |
read_scaling_linkless
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_id | 1 entities | Flame Graph | |
| entity_by_id | 10 entities | Flame Graph | |
| entity_by_id | 100 entities | Flame Graph | |
| entity_by_id | 1000 entities | Flame Graph | |
| entity_by_id | 10000 entities | Flame Graph |
representative_read_entity
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/block/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/book/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/building/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/organization/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/page/v/2
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/person/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/playlist/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/song/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/uk-address/v/1
|
Flame Graph |
representative_read_entity_type
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| get_entity_type_by_id | Account ID: bf5a9ef5-dc3b-43cf-a291-6210c0321eba
|
Flame Graph |
representative_read_multiple_entities
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_property | traversal_paths=0 | 0 | |
| entity_by_property | traversal_paths=255 | 1,resolve_depths=inherit:1;values:255;properties:255;links:127;link_dests:126;type:true | |
| entity_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:0;properties:0;links:0;link_dests:0;type:false | |
| entity_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:0;properties:0;links:1;link_dests:0;type:true | |
| entity_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:0;properties:2;links:1;link_dests:0;type:true | |
| entity_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:2;properties:2;links:1;link_dests:0;type:true | |
| link_by_source_by_property | traversal_paths=0 | 0 | |
| link_by_source_by_property | traversal_paths=255 | 1,resolve_depths=inherit:1;values:255;properties:255;links:127;link_dests:126;type:true | |
| link_by_source_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:0;properties:0;links:0;link_dests:0;type:false | |
| link_by_source_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:0;properties:0;links:1;link_dests:0;type:true | |
| link_by_source_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:0;properties:2;links:1;link_dests:0;type:true | |
| link_by_source_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:2;properties:2;links:1;link_dests:0;type:true |
scenarios
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| full_test | query-limited | Flame Graph | |
| full_test | query-unlimited | Flame Graph | |
| linked_queries | query-limited | Flame Graph | |
| linked_queries | query-unlimited | Flame Graph |
Warning
File format change
Net takes an optional
constraintslist, and code can readmetrics.Existing files load unchanged.
A build without this PR drops the list without a warning, and does not compile code that reads
metrics.Warning
Stored settings change
Stored user settings take two keys,
expressionFieldandanthropicApiKey.Settings stored without them load with both at their defaults.
A build without this PR reads neither key.
Summary
Before this PR, a metric is a TypeScript function body, a model holds no constraints, and no code reads the value of a metric.
This PR adds an expression language for metrics and constraints, and a field to write it in. A metric reads
SUM(FILTER(Queue, .urgent), .wait)and a constraintALWAYS(Infected < 500, 0, 50). The field draws names as chips and calls as frames, completes while typing, and shows the value or the first error. Constraints are saved with the model and listed in the Entities pane. Lambdas and kernels read a metric asmetrics.backlog.File format
Net takes an optional
constraintslist, written aftermetricsand beforescenarios. A constraint has anid, anexpression, an optionaldescriptionand an optionaldialect. A metric written as an expression keeps the text in comment lines that open itscode.Example and loading: existing files load unchanged, a build without this PR drops constraints
metrics: - id: infected_fraction description: Share of the population currently infected. code: |- … + - id: twice_infected + code: |- + // expression: Infected.count * 2 + return (state.places["Infected"].count * 2); +constraints: + - id: outbreak_stays_small + description: Never more than 500 infected in the first 50 time units. + expression: ALWAYS(Infected.count < 500, 0, 50) scenarios:constraintswithout a warningmetricsdoes not compile in a build without this PRdialectother thanformulaorfluentis rejectedStored settings
petrinaut:user-settingsinlocalStoragetakes two keys.expressionFieldis one ofclassic,inline,blockandslots.{ … + "expressionField": "classic", + "anthropicApiKey": "" }Loading: defaults where the keys are absent, both left in storage by a build without this PR
Links
More docs: metric reads, the Labs settings, the buffer ABI
Changes
Language: one grammar in two written styles, checked against the net, lowered to TypeScript
SUM,AVERAGE,MINandMAXgiven a list are read by the next argumentALWAYS,EVENTUALLYandUNTILread a whole runlet name = value in bodynames a valueConstraintProgramassistExpressionasks a language model for an expressionModel and simulation: constraints saved with the net, metrics read from code
constraintsmetrics.<id>reads a metric in a lambda, a kernel and a TypeScript metriccodeEditor: an expression field with chips, frames and completion, in four versions
Brunch and website: the assistant creates, updates and removes constraints
petrinaut_create_constraint,petrinaut_update_constraintandpetrinaut_remove_constraintconstraintjoins the kinds a query and a Ledger address nameKnown issues
More: components, percentiles, version C, a guide screenshot
Test coverage
Core tests: language, assistant loop, metric reads, IDs, file checks
expression.test.ts:assist.test.ts:link-metrics.test.ts:entity-ids.test.ts,check-entity-ids.test.ts,migrate-legacy-entity-ids.test.ts:actions.test.ts:checker.test.ts:language-client.test.ts:artifacts.test.ts,surface-context.test.ts,generate-virtual-files.test.ts:Editor tests and checks by hand: drawer, version C, preview walk, loading between two builds
metric-drawer.test.tsx:use-petrinaut-mutations.test.tsx:history.test.ts,operations.test.ts:hash-agent-mounting.test.ts:How to test
Metric: an expression with its value under the field
Infected * 2.countafterInfectedinfected_fractionConstraint: a condition over a run, and an ID the net has
ALWAYS(Infected < 500, 0, 50)infected_fractionin ID, press TabVersions and metric reads: the version menu, and a rate that reads a metric
Infection, set its rate code toreturn metrics.infected_fraction + 1;