Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/fe/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ New Mind (`/minds/new`, `NewMindFlow`): needs a session (else back to `/`) and h
Chat (`/minds/[mindId]/chat` and `/chat/[threadId]`, `src/modules/chat`, design "4 · Chat" C1):
- `ChatRunProvider` (in the Mind layout) holds the one run in progress per Mind, so the stream survives the move from `/chat` to `/chat/{threadId}` once `run.started` gives the new thread its id (`router.replace`). Until that move lands, `/chat` keeps showing the run it started (`ActiveRun.newThread`, newer than the page), even after the reply finished; a later "New chat" page doesn't show it (Ancung, 9 Nov: the empty first-chat screen flashed between the reply and the move). Approve/decline resumes go through it too, so the live view and the Approvals badge can read the same run.
- `api.ts` posts chat and approve/decline and reads the SSE answer with `eventsource-parser`; an error before the stream starts throws `ApiError` from the JSON body. Both send the browser's `timeZone` (`ownerTimeZone`, #112), so the engine's `get_time` uses the owner's clock (it was never sent before 9 Nov, so every run was UTC). Not fixed by this: a model that schedules without calling `get_time` can still write `+00:00` (seen 9 Nov, raised with Axel); the approval card shows the time on the owner's clock, so it shows.
- `runs/data/events.ts` `foldRun` turns one run's §3 events into what the chat shows (text, tool steps, TEE badge, error; thinking a model sends as text, up to a closing `</think>`, becomes a thought row, Ancung, 11 Nov); the same fold serves a live stream and `GET /runs/{runId}`. A paused run's stream still ends with `run.finished` and `run.verified` and the backend keeps it `awaiting_approval`, so only new work after the pause (step, text, another tool) counts as resumed; a resumed run with no result for the tool was declined (`engine/test/engine.test.ts`: decline never writes a `tool.result`). `send_payment` refusals come as `policy_denied` / `wallet_frozen`, as the event status or the result's own status. A `tool.called` with `approvedBy: "rule"` (#167) marks its step `approvedByRule`: the step row says "Approved by your rule" and a sent payment's receipt says it went without asking. A result that is really a failure, Mastra's `{ error: true, message }` (the arguments failed validation, nothing ran) or a tool's own `status: "refused"` (a Sheets change refused, #245), is an error step (it read "Changed cells ✓" before, 11 Nov). A `send_payment` result whose own status is `failed` (a try-out's demo limit, OutLayer erroring) is an error step and shows "not sent", never "Sent" (11 Nov). An approval that comes after a resume (a split bill's next person) starts a new pause: approvals from the earlier pause that never ran are declined, the new one waits with its card (11 Nov; before, it read "you declined" and had no card).
- `runs/data/events.ts` `foldRun` turns one run's §3 events into what the chat shows (text, tool steps, TEE badge, error; thinking a model sends as text, up to a closing `</think>`, becomes a thought row, Ancung, 11 Nov); the same fold serves a live stream and `GET /runs/{runId}`. A paused run's stream still ends with `run.finished` and `run.verified` and the backend keeps it `awaiting_approval`, so only new work after the pause (step, text, another tool) counts as resumed; a resumed run with no result for the tool was declined (`engine/test/engine.test.ts`: decline never writes a `tool.result`). `send_payment` refusals come as `policy_denied` / `wallet_frozen`, as the event status or the result's own status. A cross-chain quote (`crosschain_quote`, #273, #278: a dry NEAR Intents quote, nothing is sent) reads "Got a cross-chain quote" with what would arrive where ("49.98 USDC on Arbitrum": 1Click's chain ids named by `CHAIN_NAMES`, an unknown id shown as it is, and the amount cut to two decimals by `shortAmount`, Axel on #282; Ancung, 12 Nov: "signed by NEAR Intents" was cut off on a phone, and the Mind states the proof in its reply, #278). A `tool.called` with `approvedBy: "rule"` (#167) marks its step `approvedByRule`: the step row says "Approved by your rule" and a sent payment's receipt says it went without asking. A result that is really a failure, Mastra's `{ error: true, message }` (the arguments failed validation, nothing ran) or a tool's own `status: "refused"` (a Sheets change refused, #245), is an error step (it read "Changed cells ✓" before, 11 Nov). A `send_payment` result whose own status is `failed` (a try-out's demo limit, OutLayer erroring) is an error step and shows "not sent", never "Sent" (11 Nov). An approval that comes after a resume (a split bill's next person) starts a new pause: approvals from the earlier pause that never ran are declined, the new one waits with its card (11 Nov; before, it read "you declined" and had no card).
- `useThread` reads `…/messages` (pages of whole runs, "Show earlier messages") and each run's events, and pairs them per run.
- Cards: a receipt for a sent payment (limit from the stored policy, NearBlocks testnet link `testnet.nearblocks.io/txns/{hash}`, the explorer docs.near.org lists for testnet), a red card for a refused one (which limit, read against the policy; never a tx link), an approval card answered in place (decided 9 Nov with Ancung; the design sent "Review and approve" to Approvals): the same checks as Approvals and Approve only when nothing would refuse it, otherwise a button to the fix. Frozen wallets show a banner and a different composer note.
- Approval cards for things other than payments say what is being approved, from the tool's own arguments (`data/approvalDetails.ts`, `ApprovalDetailLines`, chat and Approvals): an event's title and time, a meeting's time, guests, whether it gets a Meet link, that it is added to the owner's Google Calendar, and that Google emails each guest an invite in the owner's name (`googlecalendar_create_meeting`, #97), a moved event's old and new time as From and To, saying nobody is emailed (`googlecalendar_move_event`, #247; the old time is what the Mind listed, and the engine refuses the move if the event has moved since), an email's subject and recipients (`mail_send`), "Email me" with its subject, only to the owner's own Gmail (`mail_send_to_owner`, in chat since #225), and for the track skills' apps (#211) a new Doc's title, text added at the end of an existing Doc with that Doc's title, length and the text (`googledocs_append_text`, #247), a Sheets row's values, a Notion page or row, a Notion row change (each property old → new, #247, same words as the backend's Telegram card), a Slack message with its channel, a Zoom meeting's topic, time on the owner's clock, length and "Nobody is invited" (`zoom_create_meeting`, #246), and what a Mind sells for how much (`sell_offer`). Times are shown on the owner's clock. The answer toast names the thing ("Declining the meeting", "Scheduled a meeting"), not the tool's progress words.
Expand Down Expand Up @@ -178,7 +178,7 @@ Builder (`/minds/[mindId]/autopilot/new` and `/autopilot/[workflowId]`, `src/mod
- Each kind of block has its own colour on its icon tile, in the palette, on the canvas and in its settings (`TONE` in `data/tone.ts`, through `KIND_META` in `data/blocks.ts`): Start neutral (`muted`), Ask the Mind's own (`node-mind`, inverse), Use a tool blue (`info`), If or else amber (`warning`), all from the design's B1.0, and Call a website purple (`node-app`; grey in the design, Ancung asked for every kind to differ, 9 Nov). Green and red stay for Test run results, lime stays the one brand accent.
- Full screen, and asks before you leave (Ancung, 9 Nov): the Builder has no sidebar (route group `(focus)`). Changes are saved only with Save; with unsaved changes (header "Unsaved changes"), `hooks/useLeaveGuard.ts` asks first: the back arrow and the browser's Back button open "You have unsaved changes" with two buttons, Discard changes on the left and Save on the right (Keep editing instead of Save when something blocks saving); X, Esc or a click outside keep editing (Ancung, 10 Nov: three buttons were too many), and closing the tab, reloading or typing another address get the browser's own "Leave site?" (`beforeunload`). Back is caught the way cia-web's `useDraftGuard` does it: while there are changes one extra history entry (`#unsaved`) sits on top, `popstate` puts it back and asks, and leaving goes back two, or to Autopilot when the Builder was the first page this tab loaded (`loadedFirst` in `src/lib/historyNav.ts`), so it never steps out of HelloNear. `beforeunload` is listened to only while there are changes (MDN: the listener can keep a page out of the back-forward cache). This replaced keeping drafts on the device (Ancung asked for plain saving). Not checked in a browser yet.
- Canvas like n8n (Ancung, 9 Nov; shortcuts read from docs.n8n.io/build/keyboard-shortcuts, the simple ones): the block column sits in a pan-and-zoom frame (`hooks/useCanvasView.ts`, a CSS transform, so the blocks stay normal DOM for clicks and drag and drop). The view is written to the DOM once per frame, never through React state, so moving doesn't re-render the Builder; the wheel and the buttons ease toward the target, dragging follows the pointer 1:1, and reduced motion jumps. Zoom is gentle: about 18% per mouse notch (`wheelZoomFactor`, capped so a fast wheel can't jump), line-based wheels are turned into pixels (`wheelPixels`); the dotted grid doubles whenever its dots would sit closer than 14 px on screen and fades a little when zoomed out (`gridOf`; zoomed far out the dots shimmered) (Ancung, 9 Nov: the first version stuttered and was too sensitive). Scroll or two fingers pan, Shift + scroll pans sideways (`wheelPan`, whether the browser sends it as deltaX or deltaY); Ctrl/Cmd + scroll or a pinch zooms around the pointer (25% to 200%); dragging empty canvas, Space + drag or the middle button pans. Controls at the bottom left (`canvas/ZoomControls.tsx`, one step is `ZOOM_STEP`): zoom out, the level (click for 100%), zoom in, Fit, shortcuts. Keys (`hooks/useEditorShortcuts.ts`, listed in `ShortcutsDialog`): + and -, 0 (100%), 1 (fit), Ctrl/Cmd + S (save), Ctrl/Cmd + Enter (test run), Ctrl/Cmd + Z and Shift + Z (undo and redo, `hooks/useHistory.ts`: up to 50 drafts, typing within a second counts once), Up and Down (pick a block), Delete (delete it), Esc (close the settings), [ (fold the Blocks panel to icons, remembered in `hellonear.builder.palette` by `hooks/usePaletteFold.ts`; it folds like the app's sidebar in `AppShell`: the width slides 240 <-> 72 px, ease-in-out 200 ms, and the full list crossfades with the icon rail, both clipped so no scrollbar shows; below 1024 px the list always sits open on top), ] (close or open the settings), ? (the list). Letters and arrows wait while you type; Save and Test run work anywhere. The settings panel shows only for a picked block and closes with X, Esc or a click on empty canvas. Not checked in a browser yet.
- Phones and tablets below 1024 px (design B1 mobile, B1.5, B1.8; Ancung, 9 Nov: the stacked desktop columns looked messy): no Blocks panel; the canvas fills the screen with zoom controls upright at the top right (+, -, fit); a round + sits between blocks (`canvas/TapSpot.tsx`) and the Add card opens "Add a block" (`AddBlockSheet.tsx`, a bottom sheet saying where it goes, "After Use a tool, before the If", with If or else off and why when it can't go there); a picked block's settings open in a bottom sheet with Done (`panels/SettingsFrame.tsx`; nothing is picked on open there); an "Add a block" button that is always there (`PhoneBar.tsx`) (it adds at the end, before the If; Ancung, 10 Nov: with an If the Add card is gone and the + was easy to miss), then Test run and Save, sit across the bottom. "Add a block" is a drawer you can swipe down (`Drawer`, like the live view on phones). One finger on empty canvas pans; two fingers pinch to zoom around the point between them and move the view with it, anywhere on the canvas, cards included (`pinchView` in `useCanvasView.ts`, touch pointers listened to in the capture phase; a pinch never counts as a tap that closes the settings; Ancung, 12 Nov: it only had the + and - buttons). Not checked on a phone yet. Money blocks refused on drop (B1.4) don't apply: the palette has no money blocks.
- Phones and tablets below 1024 px (design B1 mobile, B1.5, B1.8; Ancung, 9 Nov: the stacked desktop columns looked messy): no Blocks panel; the canvas fills the screen with zoom controls upright at the top right (+, -, fit); a round + sits between blocks (`canvas/TapSpot.tsx`) and the Add card opens "Add a block" (`AddBlockSheet.tsx`, a bottom sheet saying where it goes, "After Use a tool, before the If", with If or else off and why when it can't go there); a picked block's settings open in a bottom sheet with Done (`panels/SettingsFrame.tsx`; nothing is picked on open there); an "Add a block" button that is always there (`PhoneBar.tsx`) (it adds at the end, before the If; Ancung, 10 Nov: with an If the Add card is gone and the + was easy to miss), then Test run and Save, sit across the bottom. "Add a block" is a drawer you can swipe down (`Drawer`, like the live view on phones). One finger on empty canvas pans; two fingers pinch to zoom around the point between them and move the view with it, anywhere on the canvas, cards included (`pinchView` in `useCanvasView.ts`, touch pointers listened to in the capture phase; a pinch never counts as a tap that closes the settings; Ancung, 12 Nov: it only had the + and - buttons). After Axel's notes on #274: any new press, a mouse one too, forgets the last pinch; a pinch starts from the view on screen, not where an easing zoom was heading; the second finger and the pinch's moves don't reach the card under them; and a finger lifted outside the canvas is still let go (a `pointerup` on the window). Not checked on a phone yet. Money blocks refused on drop (B1.4) don't apply: the palette has no money blocks.
- Proven 9 Nov in Chrome (try-out Mind against the hosted API): opening Morning balance check, changing its If to under 1 NEAR, Save, Run now worked; a Calendar digest (Read the calendar, then Ask with the events put in) ran and listed the sample calendar's events in Jakarta time; the engine's refusal of two asking endings, before the FE checked it. Stage 1: New job, a weekly-or-daily Start and one Ask step, Save, back in Autopilot with the job selected, Run now from Running to Worked with the Mind's note in Jakarta time.
- Read steps for the track apps (#211; Ancung, 11 Nov): Read a Google Sheet (a sheet link, saved as its id by `sheetIdOf`, and optional cells like Sheet1!A1:D20), Read a Google Doc (a doc link) and Search Notion (words in the title), in `data/tools.ts`. Their rows, text and pages can go into an Ask step's prompt; a Doc's title can feed an If. Only reading: writing (a new Doc, a row, a Notion page, a Slack post) needs the owner's approval, which a job can't give. A tool arg can be `optional` (left out of the canvas when empty) and carry a `hint`, and a tool can turn what was typed into what it takes (`toArgs`). An Ask step can already use any of the Mind's skills that need no approval; these blocks make the reading explicit. Not checked with a real connected account.
- Read steps for #252's tools (Ancung, 11 Nov): Read a Notion database (a database link, saved as its id by `notionIdOf`), Find free time (no fields: the engine's tool takes numbers and a job's arguments are text, so it runs with its defaults, gaps of an hour or more from 09:00 to 18:00) and List Zoom meetings. Their rows, slots and meetings can go into an Ask step's prompt. Not checked with a real connected account.
Expand Down
15 changes: 13 additions & 2 deletions apps/fe/src/modules/builder/hooks/useCanvasView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,20 @@ export function useCanvasView() {
return { d: Math.hypot(b.x - a.x, b.y - a.y) || 1, x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 }
}
const down = (e: PointerEvent) => {
// Any new press starts fresh, a mouse one too (a touchscreen laptop: a click after a pinch
// still closes the settings; Axel, #274).
if (e.pointerType !== "touch" || touches.current.size === 0) pinched.current = false
if (e.pointerType !== "touch") return
if (touches.current.size === 0) pinched.current = false
touches.current.set(e.pointerId, local(e))
if (touches.current.size === 2) {
// A one-finger pan becomes the pinch.
pan.current = null
setPanning(false)
pinched.current = true
pinch.current = { view: { ...target.current }, ...between() }
// From where the view is on screen, not where an easing zoom was heading, so it doesn't jump (Axel, #274).
pinch.current = { view: { ...current.current }, ...between() }
// The second finger is the pinch's, not a press on the card under it (Axel, #274).
e.stopPropagation()
}
}
const move = (e: PointerEvent) => {
Expand All @@ -235,6 +240,7 @@ export function useCanvasView() {
const p = pinch.current
if (p && touches.current.size >= 2) {
e.preventDefault()
e.stopPropagation()
go(pinchView(p.view, p, between()), true)
}
}
Expand All @@ -246,7 +252,12 @@ export function useCanvasView() {
f.addEventListener("pointermove", move, true)
f.addEventListener("pointerup", up, true)
f.addEventListener("pointercancel", up, true)
// A finger lifted outside the canvas still ends there, so no stale touch starts a "pinch" later (Axel, #274).
window.addEventListener("pointerup", up)
window.addEventListener("pointercancel", up)
return () => {
window.removeEventListener("pointerup", up)
window.removeEventListener("pointercancel", up)
f.removeEventListener("pointerdown", down, true)
f.removeEventListener("pointermove", move, true)
f.removeEventListener("pointerup", up, true)
Expand Down
29 changes: 29 additions & 0 deletions apps/fe/src/modules/runs/data/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ export function stepOrb(step: Pick<ToolStep, "tool" | "status">): StepOrb {
return TOOLS[step.tool]?.orb ?? "working"
}

/**
* 1Click's chain ids in people's words (Axel, #282: "on Arb" read like a code). An id not listed
* shows as it is.
*/
export const CHAIN_NAMES: Record<string, string> = {
eth: "Ethereum", arb: "Arbitrum", base: "Base", sol: "Solana", pol: "Polygon", bsc: "BNB Chain", op: "Optimism",
avax: "Avalanche", tron: "Tron", ton: "TON", sui: "Sui", aptos: "Aptos", stellar: "Stellar", gnosis: "Gnosis",
scroll: "Scroll", monad: "Monad", xlayer: "X Layer", hypercore: "Hyperliquid",
}

/** A token amount cut (never rounded up) to two decimals, or to its first figures when smaller: "49.984601" -> "49.98", "0.004512" -> "0.0045". */
export function shortAmount(amount: string): string {
const m = amount.match(/^(\d+)(?:\.(\d+))?$/)
if (!m) return amount
const [, whole, frac = ""] = m
const two = frac.slice(0, 2).replace(/0+$/, "")
if (whole !== "0" || !frac) return two ? `${whole}.${two}` : whole
const lead = frac.search(/[1-9]/)
return lead < 0 ? "0" : `0.${frac.slice(0, Math.max(2, lead + 2))}`
}

export type StepText = { label: string; detail: string | null; tone: "doing" | "done" | "failed" | "stopped" }

export function stepText(step: ToolStep): StepText {
Expand Down Expand Up @@ -58,6 +79,14 @@ function summary(step: ToolStep): string | null {
}
case "split_amount":
return count(r.shares, "share", "shares")
// A cross-chain preview (#273): what would arrive, where. Kept short to fit a phone's line; the
// Mind states the quote's proof in its reply (#278) and the opened step shows it.
case "crosschain_quote": {
const to = r.to as { amount?: string; token?: string; chain?: string } | undefined
if (!to?.amount) return null
const chain = to.chain ? (CHAIN_NAMES[to.chain] ?? to.chain) : "the other chain"
return [shortAmount(to.amount), to.token, "on", chain].filter(Boolean).join(" ")
}
case "near_check_transfer":
return r.coversAmount === true ? "Paid in full" : r.status === "succeeded" ? "Paid, but not the full amount" : r.status === "failed" ? "Not paid" : null
case "near_view_account":
Expand Down
Loading
Loading