diff --git a/apps/fe/CLAUDE.md b/apps/fe/CLAUDE.md index 900d60f0..c1e13369 100644 --- a/apps/fe/CLAUDE.md +++ b/apps/fe/CLAUDE.md @@ -172,7 +172,7 @@ Builder (`/minds/[mindId]/autopilot/new` and `/autopilot/[workflowId]`, `src/mod - Stage 3, drag and drop (B1.7, Ancung asked for it, 9 Nov): blocks drag from the palette onto the canvas, and steps drag to a new place in the line (native HTML drag events, no new library). While dragging, the "Add the next step" card itself is where a block lands at the end ("Drop to add it here"), and a slim dashed line with a small + marks each place between steps (Ancung, 9 Nov: a separate "Drop here" box under the card was confusing); the hovered target gets a solid edge and a lighter surface, not a white fill. An If only lands at the end, one per job; `moveBlock` in `hooks/useDragDrop.ts` does the reordering. Taps still add at the end, for phones and screen readers (B1.8). The drop spots show a frame after `dragstart` (`startDrag`): a layout change during `dragstart` makes Chrome cancel the drag, which is why the first version didn't drag with a real mouse. Checked 9 Nov by Ancung with a mouse in Chrome (it works; the feel is still to be discussed), and before that by firing the drag events from the console. - If ways like n8n (Ancung, 10 Nov): a new If starts with both ways empty, each an "Add a step" slot to tap or drop a block onto (`EndingSlot`); an empty way means the job stops there, and a filled one shows an "End" mark under its block. A way takes Ask, Use a tool or Call a website, each with its own panel; only one way may ask the Mind (engine rule), and the picker says so. The engine needs a "then" step, so an empty Yes with a step on No is saved as the opposite check with that step on Yes (`engineBranch`, `INVERT`); "Swap Yes and No" in the If panel does the same by hand. With an If, there is no Add card above it: new steps go in through the + between blocks. Earlier results read as `{Balance}` in prompts and on cards (`promptToDisplay` / `promptFromDisplay`, a second one becomes `{Balance 2}`), saved as the engine's `{{steps.id.field}}`. A balance names its account (Ancung, 10 Nov: two "Balance (NEAR)" didn't say whose): `{Balance of Omaga}` for the Mind's own wallet, `{Balance of lin1er.testnet}` for another (`accountWho`, `stepSource`). Earlier results show as chips, in the prompt field and on block cards and the Autopilot timeline (`PromptText.tsx`: `PromptEditor`, a `contentEditable="plaintext-only"` box where a chip is a non-editable span carrying its `{{steps.id.field}}`, read back as that reference, Enter writes " "; `PromptPreview` for read-only places; `promptParts` splits a prompt; Ancung, 10 Nov: `{Balance of Omaga}` in the text read like code). Tool chips are blue, website chips purple. "Put in a result" puts the chip where the caret last was (at the end if the field wasn't used yet) and groups the chips under the step they come from, with its colour and icon, and the If's "Look at" list shows where each value comes from on a second line (`Choice.hint` in `ChoiceSelect`). `SelectItem` lets a long label wrap before the check mark instead of running under it. -- Ifs anywhere and End (#164, engine #165; Axel's call, 10 Nov): a job is a tree. `Draft.line` is a line of blocks (`Block`: a step, an `IfBlock` with its own `then` and `else` lines, or an `EndBlock`); Ifs can sit in the main line, inside a way, inside a way of a way, and End is a block the user places. Like n8n, the Builder adds nothing after an If (Ancung, 10 Nov: a third box under an If, for steps after both ways, read as strange): a path goes on only inside the If's Yes and No, which may hold more Ifs, and a way that runs out stops the job there. The engine (#165) also accepts steps after an If (a plain edge from the If), so a job saved that way still opens and shows them: the If's ways meet again in a join under it (the fork upside down) before those steps, and an empty way there reads "carries on after the If" (`carriesOn`; Axel, on #170) (`toCanvas` / `fromCanvas`; an empty Yes with steps on No is still saved as the opposite check, for the older engine shape). Rules, checked before Save and by `canPlace` for every drop and tap: End only at the end of a path, nothing after a path that ends (End, or an If whose ways both end, `closes`), an If only where something comparable came before, at most 19 blocks. A block reads only the steps before it on its own path (`stepsAt` / `stepsBefore`: an If's ways may not run, so blocks after it can't read inside them). Tree helpers in `data/draft.ts`: `allBlocks`, `locate`, `lineAt`, `withLine`, `insertBlock`, `updateBlock`, `removeBlock` (an If goes with its ways); the ones that visit the whole tree go through `walk` (depth first, with each block's path) and `mapTree` (rebuild bottom up). The canvas draws each If's Yes and No side by side, each a line of its own with an "Add the next step" slot under its last block (none under an If, which goes on in its own ways); it widens with the tree (`w-max`). Blocks (an If with its ways) drag to any allowed place; the palette, the phone sheet and an empty way's picker offer If and End where they fit and say why when they don't. Test run lights each If from the way that ran ("Carried on" when none did; `withIf` in `data/testRun.ts`). The lines light up too (Ancung, 10 Nov): the line into the block that is working carries a blue light down to it (`wire-flow` in `globals.css`) and that block glows softly (`node-glow`); lines into finished blocks turn green (red on a failure), and so do the If's fork and the way that ran. Reduced motion keeps the colours without movement. Autopilot reads the tree too (`jobTree`, `flatSteps`), and its timeline nests each If's ways. +- Ifs anywhere and End (#164, engine #165; Axel's call, 10 Nov): a job is a tree. `Draft.line` is a line of blocks (`Block`: a step, an `IfBlock` with its own `then` and `else` lines, or an `EndBlock`); Ifs can sit in the main line, inside a way, inside a way of a way, and End is a block the user places. Like n8n, the Builder adds nothing after an If (Ancung, 10 Nov: a third box under an If, for steps after both ways, read as strange): a path goes on only inside the If's Yes and No, which may hold more Ifs, and a way that runs out stops the job there. The engine (#165) also accepts steps after an If (a plain edge from the If), so a job saved that way still opens and shows them: the If's ways meet again in a join under it (the fork upside down) before those steps, and an empty way there reads "carries on after the If" (`carriesOn`; Axel, on #170) (`toCanvas` / `fromCanvas`; an empty Yes with steps on No is still saved as the opposite check, for the older engine shape). When an If can't go somewhere, the palette, the phone sheet and a way's picker say why (`ifLockedWhy`, Ancung, 11 Nov: "Add a check or a website first" read like a bug): nothing before it gives a number or a text, or the path already ends above. A list (events, emails, rows, slots, meetings, pages) is compared through its count (engine #265, for #264): every list tool in `data/tools.ts` also offers "Number of events" and so on, saved as `{{steps.id.count}}` (never `.length`, which the engine refuses), so "Read the calendar, then If number of events is more than 0" works. An If on an Ask step's answer isn't offered: the engine compares exact text only, and the Mind answered "Yes" where the If expected "yes" (Axel, #265). Rules, checked before Save and by `canPlace` for every drop and tap: End only at the end of a path, nothing after a path that ends (End, or an If whose ways both end, `closes`), an If only where something comparable came before, at most 19 blocks. A block reads only the steps before it on its own path (`stepsAt` / `stepsBefore`: an If's ways may not run, so blocks after it can't read inside them). Tree helpers in `data/draft.ts`: `allBlocks`, `locate`, `lineAt`, `withLine`, `insertBlock`, `updateBlock`, `removeBlock` (an If goes with its ways); the ones that visit the whole tree go through `walk` (depth first, with each block's path) and `mapTree` (rebuild bottom up). The canvas draws each If's Yes and No side by side, each a line of its own with an "Add the next step" slot under its last block (none under an If, which goes on in its own ways); it widens with the tree (`w-max`). Blocks (an If with its ways) drag to any allowed place; the palette, the phone sheet and an empty way's picker offer If and End where they fit and say why when they don't. Test run lights each If from the way that ran ("Carried on" when none did; `withIf` in `data/testRun.ts`). The lines light up too (Ancung, 10 Nov): the line into the block that is working carries a blue light down to it (`wire-flow` in `globals.css`) and that block glows softly (`node-glow`); lines into finished blocks turn green (red on a failure), and so do the If's fork and the way that ran. Reduced motion keeps the colours without movement. Autopilot reads the tree too (`jobTree`, `flatSteps`), and its timeline nests each If's ways. - Save is checked when pressed, not warned about all along (Ancung, 10 Nov: standing warnings in the header, the panel and a tooltip were too much): Save is on whenever there is something to save; with something missing it saves nothing, jumps to the first problem (`fix` in `hooks/useSave.ts`: the name field in the header, or the block) and says it once in a toast. Unfinished blocks turn amber only after a Save attempt (`tried`). The job's name is edited right in the header (as in n8n; the Start panel has the same field). The engine's own issues after a refused Save still list in red. - The picked block gets a 2 px outline a gap away from its card and a lifted shadow, apart from its edge colour, which keeps saying its state (Test run result, or amber when something is missing) (Ancung, 9 Nov: a 1 px edge didn't show the pick). - 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. diff --git a/apps/fe/next-env.d.ts b/apps/fe/next-env.d.ts index ce4e94a6..a419cbe4 100644 --- a/apps/fe/next-env.d.ts +++ b/apps/fe/next-env.d.ts @@ -1,7 +1,7 @@ /// /// -import "./.next/types/routes.d.ts"; -import "./.next/types/root-params.d.ts"; +import "./.next/dev/types/routes.d.ts"; +import "./.next/dev/types/root-params.d.ts"; // NOTE: This file should not be edited // see https://nextjs.org/docs/app/api-reference/config/typescript for more information. diff --git a/apps/fe/src/modules/builder/components/AddBlockSheet.tsx b/apps/fe/src/modules/builder/components/AddBlockSheet.tsx index 0206e220..a5d4a00a 100644 --- a/apps/fe/src/modules/builder/components/AddBlockSheet.tsx +++ b/apps/fe/src/modules/builder/components/AddBlockSheet.tsx @@ -5,7 +5,7 @@ import { cn } from "cn" import { Drawer, DrawerContent, DrawerDescription, DrawerHeader, DrawerTitle } from "@/components/ui/drawer" import { useBuilder } from "@/modules/builder/components/BuilderContext" import { ADD_KINDS, KIND_META, WHY_NOT, type Kind } from "@/modules/builder/data/blocks" -import { canPlace, lineAt, type Block } from "@/modules/builder/data/draft" +import { canPlace, ifLockedWhy, lineAt, type Block } from "@/modules/builder/data/draft" import type { Place } from "@/modules/builder/data/places" import { TONE } from "@/modules/builder/data/tone" import { toolInfo } from "@/modules/builder/data/tools" @@ -17,7 +17,7 @@ export function AddBlockSheet({ at, line, onClose, onPick }: { at: Place | null; const here = lineAt(line, place.path) const label = (x: Block) => (x.kind === "agent" ? `Ask ${name}` : x.kind === "tool" ? (toolInfo(x.tool)?.title ?? "a tool") : x.kind === "http" ? "Call a website" : x.kind === "if" ? "the If" : "End") const where = `${place.index === 0 ? (place.path.length ? "At the start of this way" : "After Start") : `After ${label(here[place.index - 1])}`}${place.index < here.length ? `, before ${label(here[place.index])}` : ""}` - const off = (kind: Kind) => (canPlace(line, place.path, place.index, kind, self) ? null : WHY_NOT[kind]) + const off = (kind: Kind) => (canPlace(line, place.path, place.index, kind, self) ? null : kind === "if" ? ifLockedWhy(line, place.path, place.index, self) : WHY_NOT[kind]) return ( // A drawer from the bottom you can swipe away, like the live view on phones (Ancung, 10 Nov). !open && onClose()} showSwipeHandle> diff --git a/apps/fe/src/modules/builder/components/BuilderScreen.tsx b/apps/fe/src/modules/builder/components/BuilderScreen.tsx index 341b4b29..7833f72e 100644 --- a/apps/fe/src/modules/builder/components/BuilderScreen.tsx +++ b/apps/fe/src/modules/builder/components/BuilderScreen.tsx @@ -24,7 +24,7 @@ import { PhoneBar } from "@/modules/builder/components/PhoneBar" import { ShortcutsDialog } from "@/modules/builder/components/ShortcutsDialog" import { SaveProblems, TestRunResult } from "@/modules/builder/components/StatusBanners" import { newBlock, type Kind } from "@/modules/builder/data/blocks" -import { canPlace, emptyDraft, findBlock, fromCanvas, insertBlock, removeBlock, updateBlock, type Block, type Draft } from "@/modules/builder/data/draft" +import { canPlace, emptyDraft, ifLockedWhy, findBlock, fromCanvas, insertBlock, removeBlock, updateBlock, type Block, type Draft } from "@/modules/builder/data/draft" import { mainEnd as mainEndOf, START, takesMore, type Place } from "@/modules/builder/data/places" import { useCanvasView, ZOOM_STEP } from "@/modules/builder/hooks/useCanvasView" import { DragContext, useDragDrop } from "@/modules/builder/hooks/useDragDrop" @@ -168,6 +168,7 @@ function Editor({ mindId, workflowId, initial }: { mindId: string; workflowId: s onToggle={fold.toggle} desktop={desktop} canIf={canPlace(draft.line, mainEnd.path, mainEnd.index, "if", self)} + ifWhy={ifLockedWhy(draft.line, mainEnd.path, mainEnd.index, self, true)} canEnd={canPlace(draft.line, mainEnd.path, mainEnd.index, "end", self)} onAdd={addStep} /> diff --git a/apps/fe/src/modules/builder/components/Palette.tsx b/apps/fe/src/modules/builder/components/Palette.tsx index b3468446..045e9203 100644 --- a/apps/fe/src/modules/builder/components/Palette.tsx +++ b/apps/fe/src/modules/builder/components/Palette.tsx @@ -19,6 +19,7 @@ export function BlocksPanel({ onToggle, desktop, canIf, + ifWhy, canEnd, onAdd, }: { @@ -28,11 +29,13 @@ export function BlocksPanel({ desktop: boolean /** Whether an If or End fits at the end of the main line, where a tap adds. */ canIf: boolean + /** Why the If can't go there, when it can't. */ + ifWhy: string canEnd: boolean /** A tap adds the block at the end of the main line. */ onAdd: (kind: Kind) => void }) { - const list = (compact: boolean) => + const list = (compact: boolean) => return (