Repository navigation
feat(studio): add Project 0 scenario support - #28
92Infinitus92 wants to merge 10 commits into
Conversation
There was a problem hiding this comment.
Summary
Adds Project 0 to Studio: a protocol entry and icon, a featured-account picker in the scenario editor (SOL/USDC banks and price accounts, or any typed address), Project 0 context in the AI prompt, a "Project 0 Liquidation" example chip, and stricter scenario-id extraction from AI tool results. toScenarioNumber now sends integers beyond the 64-bit range as decimal strings.
The PR is well scoped and comes with tests. I found one likely correctness bug and a few smaller issues:
- Stale account data when the picked account changes (main concern). Account data is fetched once, in
handleActionSelect, for the template's default address (or the saved pubkey). Picking a different bank in the new selector only updatesselectedAccountPubkey. It does not re-fetch. As a result:- The editor shows and edits another account's fields.
flattenOverrideValuessends every top-level scalar ofaccountData, not just edited fields. So fields likemint,mint_decimalsorgroupfrom the originally fetched account would be written into the picked bank.- If the template has no address,
handleActionSelectreturns early. No fields load at all, even after an address is picked.
- Layering.
lib/scenarios-api.tsnow imports fromcomponents/svm/token-selector-options.ts. The featured-account and AI-context registry would fit better underlib/, next toproject0-banks.ts. - i128 range edge.
toScenarioNumberstill sends values between i64::MAX and u64::MAX as JSON numbers. That matches the stated surfnet rule (anything that fits u64 is readable). Still, it's worth confirming surfnet accepts a u64-sized JSON number for ani128field. Sending every out-of-i64-range integer as a string might be the simpler contract.
| ? currentValue !== '' | ||
| : modifiedFields.has(fieldPath); | ||
| const onValueChange = prop.isAccountSelector | ||
| ? (pubkey: string) => setSelectedAccountPubkey(pubkey) |
There was a problem hiding this comment.
Changing the selected account only updates selectedAccountPubkey; it doesn't re-fetch account data. accountData still holds the account loaded in handleActionSelect: the template default, or nothing if the template has no address.
This matters because flattenOverrideValues sends every top-level scalar in overrides, not only modified ones. Picking the USDC bank after the editor loaded another bank could write the other bank's mint, mint_decimals, etc. into the USDC bank. Suggestion: re-run the account fetch with the new pubkey (for example handleActionSelect(selectedAction, pubkey)) once it's a valid address, and reset accountData and modifiedFields.
| ['project0-bank-shares', project0Banks], | ||
| ['project0-account-balance', project0Accounts], | ||
| ['project0-account-authority', project0Accounts], | ||
| ['pyth-pro-price-feed-v2', project0PriceAccounts], |
There was a problem hiding this comment.
pyth-pro-price-feed-v2 looks like a generic Pyth Pro template, not a Project 0 one. If so, registering it here means:
- every Pyth Pro override, even outside Project 0, now requires an explicitly picked account;
- the template's own
addressis ignored; - the picker shows the label "Price account the SOL bank reads".
If the template is shared, scope the picker to Project 0 or give it a neutral label and description.
| if (result?.scenarioId || result?.scenario_id || result?.id) { | ||
| const scenarioId = result.scenarioId || result.scenario_id || result.id; | ||
| const scenarioId = | ||
| ['create_scenario', 'create_pump_graduation_scenario'].includes(event.content.name) |
There was a problem hiding this comment.
Two concerns with the hardcoded tool-name list:
- Any other tool that creates a scenario (or one added later) will no longer navigate.
- Together with removing
onRefreshfromdone(line 267), tools that update or delete scenarios no longer refresh the list.
Consider keeping onRefresh?.() on done, and moving the tool-name list next to the MCP tool names in scenarios-api.ts.
| @@ -1,4 +1,5 @@ | |||
| import type { ScenarioBentoItem } from '@/components/svm/scenarios-bento.types'; | |||
| import { getProtocolAiContext } from '@/components/svm/token-selector-options'; | |||
There was a problem hiding this comment.
This makes a lib module depend on a components module. Consider moving getProtocolAiContext and the featured-account registry into lib/ (for example into project0-banks.ts) and importing them from the component instead.
There was a problem hiding this comment.
Summary
This PR adds Project 0 to Studio:
- a protocol entry and icon
- a bank/account picker for "featured-account" templates, which offers the SOL and USDC banks or takes any typed address
- extra AI prompt context and a "Project 0 Liquidation" chip
- integers wider than 64 bits are sent as decimal strings
- a stricter way to find the created scenario id after the AI tool calls return
The changes are well organised and come with tests. My main concern is in the editor: picking a different bank does not reload that bank's data, so the fields shown, and the overrides sent, still come from whichever account was loaded first. That needs fixing or an explanation before merging.
Other notes
- Layering:
lib/scenarios-api.tsnow importsgetProtocolAiContextfromcomponents/svm/token-selector-options.ts. That makes alib/module depend on a component module. The AI-context code (and arguably theFEATURED_ACCOUNTSmap) belongs inlib/, for example next toproject0-banks.ts. - The CI workflow
.github/workflows/claude-review.ymlhas nothing to do with Project 0 support. It's better placed in its own PR. - Large integers: values in the i64-min to u64-max range still go out as
LosslessNumber, and anything outside it as a string. This works only if surfnet accepts either form for i128 fields. Worth confirming against LimeChain/surfpool#34, and adding a test for a negative i128 below i64::MIN.
| ? currentValue !== '' | ||
| : modifiedFields.has(fieldPath); | ||
| const onValueChange = prop.isAccountSelector | ||
| ? (pubkey: string) => setSelectedAccountPubkey(pubkey) |
There was a problem hiding this comment.
Changing the selected account only updates selectedAccountPubkey. handleActionSelect is not called again, so accountData still holds the account loaded from template.address (or the saved pubkey). The fields therefore show the current values of the wrong bank. On save, overrides: accountData (line 808/848) also sends that other account's decoded values for the newly picked bank. If the backend applies more than modifiedFields, it will copy one bank's state onto another. Re-fetch when the pubkey changes (debounced, and only for valid addresses), or clear the field data until a fetch completes.
| @@ -263,7 +269,6 @@ export default function AIHeader({ onRefresh, onScenarioNavigate }: AIHeaderProp | |||
| setAiError(event.content); | |||
| break; | |||
| case 'done': | |||
There was a problem hiding this comment.
Removing onRefresh?.() from done means the list now refreshes only when one of the three hard-coded creation tools returns an id. Any other tool that changes scenarios (updating or deleting one, adding overrides) will leave the list stale. Consider keeping the refresh on done and only limiting navigation to creation tools.
| const scenarioId = result.scenarioId || result.scenario_id || result.id; | ||
| const scenarioId = | ||
| [ | ||
| 'create_scenario', |
There was a problem hiding this comment.
This hard-coded list of tool names will silently stop navigating to new scenarios when the backend adds a new create_*_scenario tool (for example a Project 0 one). A pattern such as /^create_.*scenario$/ or a shared constant would hold up better.
| // Convert to string for comparison (handles numbers like config_index) | ||
| const currentValue = rawValue != null ? String(rawValue) : ''; | ||
| const isModified = modifiedFields.has(fieldPath); | ||
| const isModified = prop.isAccountSelector |
There was a problem hiding this comment.
isModified is true whenever an account is selected. As a result, an action reopened for editing shows the selector highlighted as modified even when the user has changed nothing. You could compare against the pubkey that was originally loaded instead.
| ['project0-bank-shares', project0Banks], | ||
| ['project0-account-balance', project0Accounts], | ||
| ['project0-account-authority', project0Accounts], | ||
| ['pyth-pro-price-feed-v2', project0PriceAccounts], |
There was a problem hiding this comment.
pyth-pro-price-feed-v2 looks like a generic Pyth template, but it is now marked as a featured-account template and only offers Project 0 price accounts. This forces an explicit account choice (and the 'Project 0' wording) in every Pyth scenario, not just Project 0 ones. Is that intended?
There was a problem hiding this comment.
Summary
This PR adds Project 0 to Studio:
- a protocol entry and icon
- featured SOL and USDC bank and price-account pickers, plus typed-address entry, for the Project 0 and Pyth Pro templates
- extra Project 0 context in the AI prompt and a new example chip
- tighter rules for when the scenarios page refreshes after AI generation (it now needs a parsed scenario id instead of refreshing on every
done) - integers wider than 64 bits sent as decimal strings
Overall the change is well scoped and has good tests. Most of the points below are robustness or layering issues, not blockers.
General notes
-
Wide integers are only converted in one place.
toScenarioNumberonly runs on the scalarnumberinput (scenario-editor.tsx:2364). Three other paths still turn wide integers intoLosslessNumber, which serialises as a bare JSON number that surfnet can't read:- array/object fields parsed with
parseScenariosJson - values fetched from the account and left in
accountData, which is sent whole asoverrides - imported scenarios
If any Project 0 fixed-point field arrives through one of these paths (for example inside a nested struct), surfnet will still reject it. Consider doing the u64/i64 range check in the serialiser, or in one normalisation pass before the payload is sent, rather than per input.
- array/object fields parsed with
-
Layering.
lib/scenarios-api.tsnow importsgetProtocolAiContextfromcomponents/svm/token-selector-options.ts. AI prompt context isn't token-selector logic, andlibshouldn't depend oncomponents. MovinggetProtocolAiContextand the Project 0 context intolib/project0-banks.ts(or a newlib/protocol-ai-context.ts) would fix the dependency direction. -
Workflow (
claude-review.yml). The PR title and body are inserted directly into the prompt. Skipping fork PRs and the read-only tool allowlist limit the risk, so this is acceptable. Worth keeping in mind if the trigger is ever widened.
| const scenarioId = result.scenarioId || result.scenario_id || result.id; | ||
| const scenarioId = | ||
| [ | ||
| 'create_scenario', |
There was a problem hiding this comment.
The list of scenario-creating tools is hardcoded, and the unconditional onRefresh() on done was removed. Any other creating tool the backend exposes now or later will no longer refresh the list or navigate to the new scenario. Suggestions:
- Export the tool names from
scenarios-api.tsas a constant, next tocreateScenarioWithMcp. - Or match on
/^create_.*scenario$/. - Or keep a fallback refresh on
donewhen a create tool ran but no id was parsed.
| // Surfnet reads JSON numbers as 64-bit at most and asks for wider integers (an i128) as decimal strings. | ||
| if ( | ||
| /^-?\d+$/.test(input) && | ||
| (BigInt(input) > BigInt('18446744073709551615') || BigInt(input) < BigInt('-9223372036854775808')) |
There was a problem hiding this comment.
Minor: the bounds are rebuilt as BigInts on every call, and BigInt(input) is parsed twice. Hoist U64_MAX and I64_MIN to module constants and parse input once. Note also that an i128 field with a value inside the u64/i64 range still goes out as a number. That's fine if surfnet accepts both forms for i128 fields, but it's worth confirming against LimeChain/surfpool#34.
| @@ -1,4 +1,5 @@ | |||
| import type { ScenarioBentoItem } from '@/components/svm/scenarios-bento.types'; | |||
| import { getProtocolAiContext } from '@/components/svm/token-selector-options'; | |||
There was a problem hiding this comment.
lib now imports from components/svm/token-selector-options, which reverses the dependency direction. getProtocolAiContext and getProject0AiContext aren't token-selector concerns; consider moving them to lib/project0-banks.ts or a new lib/protocol-ai-context.ts.
| for (const candidate of candidates) { | ||
| if (!candidate || typeof candidate !== 'object') continue; | ||
| const record = candidate as Record<string, unknown>; | ||
| if (record.error) continue; |
There was a problem hiding this comment.
Generic id and url keys are accepted from any JSON in content[].text. This is safe today only because the caller filters by tool name. If the helper is reused elsewhere, a non-creating tool that returns { id } would trigger navigation. Consider documenting that callers must filter by tool name, or move the name check inside the helper.
| const currentValue = rawValue != null ? String(rawValue) : ''; | ||
| const isModified = modifiedFields.has(fieldPath); | ||
| const isModified = prop.isAccountSelector | ||
| ? currentValue !== '' |
There was a problem hiding this comment.
For the account selector, isModified is true whenever any value is set, including when editing a saved override that was loaded with its existing pubkey. The field then shows the yellow "modified" styling even though nothing changed. Compare against the pubkey the action was loaded with instead.
| typeof templateId === 'string' ? FEATURED_ACCOUNTS.get(templateId) : undefined; | ||
|
|
||
| // A featured-account template saves the picked account; any other template keeps its own address. | ||
| export const resolveFeaturedAccount = (templateId: unknown, templateAddress: unknown, selectedPubkey: string) => { |
There was a problem hiding this comment.
For featured templates this returns undefined when no account is picked. Saving is blocked in the UI by isAddressSelectionMissing, but nothing else stops an action with no account from being saved (for example a future code path, or an imported scenario that is then re-saved). A short comment noting that the UI guard is required would help, or an explicit validation error when the account is missing.
# Conflicts: # apps/studio/src/components/svm/scenario-editor.tsx # apps/studio/src/lib/scenarios-api.test.ts
There was a problem hiding this comment.
Summary
This PR adds Project 0 to Studio:
- a protocol entry and icon
- a featured or typed account picker for the
project0-*templates and the Pyth Core Compatible price template - Project 0 context added to the AI prompt, plus the "Project 0 Liquidation" chip
- integers wider than 64 bits sent as decimal strings
- a stricter way of reading the created scenario id from tool results
The scope is clear and the new helpers have tests. Four things are worth a look.
- The account picker only changes where the override is saved.
handleActionSelectfetches account data once, when the action is selected, and uses the template address to do it. Picking or typing a bank afterwards does not fetch that bank's data. For an address-less template, the fields therefore show empty or default values instead of the chosen bank's current state. Re-fetching whenselectedAccountPubkeychanges would make the editor show real values. - Every use of the Pyth price template now needs a picked account.
pyth-core-compatible-price-feed-v2is mapped to the Project 0 picker, and the selection is required. If that template is used outside Project 0, or has its own address, Add is now blocked until something is picked, and the address the template carries is ignored. - The scenario list no longer refreshes after other AI tool calls. The
onRefresh()call ondonewas removed, so the list now refreshes only after one of three hard-coded create tools. Updates and deletes made by the AI, or a newcreate_*tool, will leave the list stale. - Layering.
lib/scenarios-api.tsnow imports fromcomponents/svm/token-selector-options.ts. The AI-context and featured-account data are not UI code; moving them tolib/(next toproject0-banks.ts) would avoid a lib-to-components dependency.
| ? currentValue !== '' | ||
| : modifiedFields.has(fieldPath); | ||
| const onValueChange = prop.isAccountSelector | ||
| ? (pubkey: string) => setSelectedAccountPubkey(pubkey) |
There was a problem hiding this comment.
Changing the selected account only updates state; it does not re-run the account fetch. The editor keeps showing whatever was loaded when the action was selected: the template address, or nothing for address-less templates. So the user edits bank fields without seeing that bank's current values. Consider re-fetching account data when a valid pubkey is selected.
| ['project0-bank-shares', project0Banks], | ||
| ['project0-account-balance', project0Accounts], | ||
| ['project0-account-authority', project0Accounts], | ||
| ['pyth-core-compatible-price-feed-v2', project0PriceAccounts], |
There was a problem hiding this comment.
This makes the generic pyth-core-compatible-price-feed-v2 template require a picked account everywhere, with Project 0 wording. resolveFeaturedAccount also drops any address the template carries. If the template is used outside Project 0, this is a regression. Consider falling back to templateAddress when it holds a concrete pubkey, or only requiring a selection when the template has none.
| @@ -263,7 +269,6 @@ export default function AIHeader({ onRefresh, onScenarioNavigate }: AIHeaderProp | |||
| setAiError(event.content); | |||
| break; | |||
| case 'done': | |||
There was a problem hiding this comment.
Removing onRefresh?.() here means the list refreshes only after the three create tools listed above. AI calls that update or delete scenarios, or a future create_* tool, will leave the list stale. Consider keeping the refresh on done and gating only the navigation on the created id. Matching on a create_ prefix would also avoid hard-coding tool names.
| @@ -1,4 +1,5 @@ | |||
| import type { ScenarioBentoItem } from '@/components/svm/scenarios-bento.types'; | |||
| import { getProtocolAiContext } from '@/components/svm/token-selector-options'; | |||
There was a problem hiding this comment.
This makes a lib module depend on a components module. getProtocolAiContext and the featured-account maps are plain data, not UI code; consider moving them to lib/ (for example next to project0-banks.ts).
| // Surfnet reads JSON numbers as 64-bit at most and asks for wider integers (an i128) as decimal strings. | ||
| if ( | ||
| /^-?\d+$/.test(input) && | ||
| (BigInt(input) > BigInt('18446744073709551615') || BigInt(input) < BigInt('-9223372036854775808')) |
There was a problem hiding this comment.
Minor: BigInt(input) is computed twice, and both bound literals are rebuilt on every call. Hoist the bounds to module constants (const U64_MAX = 2n ** 64n - 1n etc.) and compute BigInt(input) once.
There was a problem hiding this comment.
Summary
Adds Project 0 to Studio: the protocol entry and icon, a featured-account picker (SOL/USDC banks, their price accounts, or any typed address) for a set of template ids, Project 0 context in the AI prompt, and a new example chip. It also sends integers wider than 64 bits as decimal strings, and changes how AI tool results trigger refresh and navigation (they now go through createdScenarioIdFromToolResult).
The feature is well scoped and has tests. A few points need attention:
- Unrelated file: the PR also adds
.github/workflows/claude-review.yml. That has nothing to do with Project 0 and should be reviewed or merged separately. - Refresh regression in the AI header: the list no longer refreshes when the AI stream ends (see inline comment).
- Picking a bank clears edits: choosing a different account wipes field edits without warning (see inline comment).
- Inconsistent wide-integer handling: only top-level number inputs get the new decimal-string encoding. Values parsed from array, vec or object fields with
parseScenariosJsonstill go out as wideLosslessNumberJSON numbers, which surfnet rejects per the PR description. This matters if any Project 0 i128 fields sit inside structs or arrays. - Layering:
lib/scenarios-api.tsnow imports fromcomponents/svm/token-selector-options. The AI-context helper (getProtocolAiContext) has nothing to do with token selectors and would sit better inlib/(for example next toproject0-banks.ts). - Hardcoded template ids: featured-account templates are a hardcoded map in the frontend (
FEATURED_ACCOUNTS). If the backend renames a template id or adds a new one, the picker silently disappears. Consider having the template declare this itself, for example with a flag on the template. - Pyth template, possible issue:
pyth-core-compatible-price-feed-v2now requires a picked account. I couldn't check the backend template. If it has a concrete pubkey address,handleActionSelectfetches that template address rather than the picked one (it only falls back toaccountPubkeywhen the address is empty), so the editor would show the wrong account's data. And for non-Project 0 uses of this template, the picker only lists Project 0 price accounts.
| @@ -263,7 +269,6 @@ export default function AIHeader({ onRefresh, onScenarioNavigate }: AIHeaderProp | |||
| setAiError(event.content); | |||
| break; | |||
| case 'done': | |||
There was a problem hiding this comment.
Removing onRefresh() from done means the scenarios list no longer refreshes after an AI run unless one of the three hardcoded create tools returned an id. Runs that only call update or override tools, or a future create_*_scenario tool, now leave a stale list. Consider keeping the refresh on done and using the tool check only for navigation.
| [ | ||
| 'create_scenario', | ||
| 'create_pump_graduation_scenario', | ||
| 'create_phoenix_collateral_scenario', |
There was a problem hiding this comment.
This allowlist of create-tool names has to be updated by hand for every new preset tool, and create_project0_* isn't in it. Matching on a pattern such as /^create_.*scenario$/ would avoid that.
| }; | ||
|
|
||
| // Reading the picked account fills its fields and pulls it into the local VM, as a saved one does | ||
| const handleAccountPick = (pubkey: string) => { |
There was a problem hiding this comment.
handleAccountPick reruns handleActionSelect, which clears accountData, modifiedFields, arrayEntryIndex and fetchBeforeUse. Choosing or changing the bank after editing fields, including when editing a saved override, silently throws away the user's changes. Either warn first, or keep modifiedFields and their values and apply them on top of the newly fetched data.
| // Surfnet reads JSON numbers as 64-bit at most and asks for wider integers (an i128) as decimal strings. | ||
| if ( | ||
| /^-?\d+$/.test(input) && | ||
| (BigInt(input) > BigInt('18446744073709551615') || BigInt(input) < BigInt('-9223372036854775808')) |
There was a problem hiding this comment.
Values between i64::MAX and u64::MAX stay LosslessNumber, which is right. But this conversion only covers the top-level number input. Array, vec and object fields parsed with parseScenariosJson can still contain wider-than-64-bit LosslessNumbers, and those are serialized as JSON numbers that surfnet will reject. Consider applying the same conversion in a reviver or stringify step so nested values are handled too.
| @@ -1,4 +1,5 @@ | |||
| import type { ScenarioBentoItem } from '@/components/svm/scenarios-bento.types'; | |||
| import { getProtocolAiContext } from '@/components/svm/token-selector-options'; | |||
There was a problem hiding this comment.
lib/ now depends on components/. getProtocolAiContext isn't a token-selector concern; it would fit better in lib/project0-banks.ts or a small lib/protocol-ai-context.ts.
… the editor's account picker, drop the featured accounts
There was a problem hiding this comment.
Summary
This PR adds Project 0 as a protocol: icon, PROTOCOLS entry, ENABLED_PROTOCOLS entry and an example chip for the AI prompt. It also changes two other things:
toScenarioNumbernow returns integers outside the 64-bit range as decimal strings.- The AI header now refreshes the scenarios list only when a known create tool returns a scenario id. It used to refresh on every
doneevent.
The tests cover the new helpers and the refresh behaviour well.
Issues
- The description promises more than the diff contains. It mentions bank selection in the editor (featured SOL and USDC banks, or any bank by address) and account templates by typed address. None of that UI is in this PR. If it all comes from backend templates (LimeChain/surfpool#34), please say so in the description.
- The string conversion covers only one input path.
toScenarioNumberis called only from the editor's number input (scenario-editor.tsx:2533). Values wider than 64 bits that come in through import, AI-created scenarios, or a load-then-save round trip stay asLosslessNumberand are still written as JSON numbers, which surfnet rejects. The u64/i64 bounds check probably belongs in the serializer (serializeScenarioJson/buildUpdatePayload), so every path benefits. - Removing the refresh on
doneis a behaviour change. Tools outside the hard-coded list no longer refresh the scenarios page. That includes any tool that edits an existing scenario and any future Project 0 create tool. See the inline comment.
| if (result?.scenarioId || result?.scenario_id || result?.id) { | ||
| const scenarioId = result.scenarioId || result.scenario_id || result.id; | ||
| const scenarioId = | ||
| [ |
There was a problem hiding this comment.
This hard-coded list of tool names will drift from the backend. Any new create_*_scenario tool, such as one for Project 0 from surfpool#34, will silently stop triggering refresh and navigation. Tools that edit an existing scenario never refresh now either, because the done refresh was removed. Two options:
- Match on a
/^create_.*scenario$/pattern. - Keep a fallback
onRefreshondonewhen any create/update tool succeeded.
Either way, it's worth hoisting this into a named constant.
| return isSafeNumber(input) ? Number(input) : new LosslessNumber(input); | ||
| if (isSafeNumber(input)) return Number(input); | ||
| // Surfnet reads JSON numbers as 64-bit at most and asks for wider integers (an i128) as decimal strings. | ||
| if ( |
There was a problem hiding this comment.
Some inputs that need to become strings will fall through to LosslessNumber, and surfnet will reject them as JSON numbers:
- Values with leading or trailing whitespace or a
+sign, e.g.' 5427949582765380709301894'. - Exponent notation such as
1e30.Number()accepts it, but the^-?\d+$regex does not.
Trim first, and either reject or normalise non-integer forms. Also, BigInt(input) is computed twice. Hoist it, and the two bounds, into constants.
| // Ignore malformed URLs returned by a tool. | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
The raw result is the first candidate, so a top-level id field is treated as the scenario id. A JSON-RPC envelope id or the id of some other object would count as a created scenario. Since the URL in the text content is what create tools actually return, consider skipping the bare-id key on the top-level candidate or putting the parsed text and structuredContent candidates first.
There was a problem hiding this comment.
Summary
This PR adds Project 0 to Studio:
- a protocol entry and icon
'Project 0'inENABLED_PROTOCOLS- a "Project 0 Liquidation" chip in the AI header
It also makes two cross-cutting changes:
toScenarioNumbernow sends integers that don't fit in 64 bits as decimal strings.- AI generation refreshes the scenario list and navigates to a scenario only when a known create tool returns an id. Before, it also refreshed on every
doneevent. The newcreatedScenarioIdFromToolResultreads that id from the MCP result.
Overall the change is small and looks correct, and the tests cover the new parsing paths.
Notes
- Description doesn't match the diff. The PR body mentions bank selection in the editor (featured SOL/USDC banks or any bank by address) and account templates by typed address. None of that UI is in this diff. If it comes from the backend templates (LimeChain/surfpool#34) or from the merged
editor-account-inputbranch, please say so in the description. Otherwise it is missing. - Behaviour change not mentioned in the description. The PR drops the unconditional
onRefreshondoneand adds a fixed allowlist of tool names. This is a fix in its own right, and it isn't Project 0-specific. If the AI changes scenarios through any tool not on the list, the list will no longer refresh.
| // Surfnet reads JSON numbers as 64-bit at most and asks for wider integers (an i128) as decimal strings. | ||
| if ( | ||
| /^-?\d+$/.test(input) && | ||
| (BigInt(input) > BigInt('18446744073709551615') || BigInt(input) < BigInt('-9223372036854775808')) |
There was a problem hiding this comment.
Consider hoisting BigInt(input) and the two bounds into module constants, e.g. const U64_MAX = 2n ** 64n - 1n; const I64_MIN = -(2n ** 63n);. As written, BigInt(input) is built twice and the bounds are re-parsed from strings on every keystroke.
The asymmetric range is also worth a comment. Positive values up to u64::MAX stay as LosslessNumber, but negative values only down to i64::MIN do. That matches what surfnet accepts, but it isn't obvious to a reader.
| 'create_scenario', | ||
| 'create_pump_graduation_scenario', | ||
| 'create_phoenix_collateral_scenario', | ||
| ].includes(event.content.name) |
There was a problem hiding this comment.
This allowlist is hard-coded inline and has to stay in sync with the MCP tools the backend exposes (and with createScenarioWithMcp in scenarios-api.ts). Any new protocol-specific create tool will silently stop triggering refresh and navigation.
Two options:
- Pull the list into a named constant next to
createdScenarioIdFromToolResult. - Match on a pattern such as
/^create_.*scenario$/.
Also, since the unconditional onRefresh on done was removed, tools that change scenarios without returning an id (e.g. update or delete, if exposed) no longer refresh the list.
| const record = candidate as Record<string, unknown>; | ||
| if (record.error) continue; | ||
| for (const key of ['scenarioId', 'scenario_id', 'id']) { | ||
| if (typeof record[key] === 'string' && record[key]) return record[key] as string; |
There was a problem hiding this comment.
The top-level result and structuredContent candidates also match a bare id key. That is safe today only because the caller gates on tool name. If this helper is reused without that gate, any tool returning an id (e.g. a template id) would be treated as a created scenario. Consider either documenting that callers must gate on tool name, or only accepting id from the parsed content[].text payload or a url.
Adds Project 0 to Studio: icon, protocol entry and the "Project 0 Liquidation" chip. Banks, accounts and price accounts are picked in the editor's "Account selection" field from #42, which this PR is stacked on: paste any address. No bank list is bundled; the AI finds banks with the lookup in the templates'
llm_context(LimeChain/surfpool#34).Integers beyond 64 bits typed into the editor's number fields are now sent as decimal strings: surfnet reads JSON numbers as 64-bit at most, and Project 0's fixed-point fields exceed that. Reopened overrides keep such values as the strings they were saved as.
The AI header now refreshes the scenario list and opens the new scenario only when a create tool returned a scenario id, instead of on every finished run. Only the create tools change the scenario list.
The engine bundles Project 0's published IDL, where a fixed-point value is
[u8; 16]. For a[u8; N]field inside a struct named for a fixed-point format, such asWrappedI80F48.value, the editor shows the bytes as a decimal and takes a decimal: it keeps the typed text while the field is edited and stores the 16 bytes when the field is left, rounding to the nearest step of 2^-48. Text that is not a decimal, or does not fit, shows an error under the field and is not saved. The format comes from the type name in the template's IDL, so there is no list of protocols or fields.create_scenarioarguments from the AI go through the same conversion when they carry a decimal; a byte array passes as it is.Checked against a forked surfnet:
0.85typed in the editor reached the bank as its 16 bytes and read back as0.85, and two AI prompts produced the correct bytes for 20 and 0.37.Backend: LimeChain/surfpool#34