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
2 changes: 1 addition & 1 deletion apps/fe/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions apps/fe/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
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.
4 changes: 2 additions & 2 deletions apps/fe/src/modules/builder/components/AddBlockSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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).
<Drawer open={at !== null} onOpenChange={(open) => !open && onClose()} showSwipeHandle>
Expand Down
3 changes: 2 additions & 1 deletion apps/fe/src/modules/builder/components/BuilderScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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}
/>
Expand Down
9 changes: 6 additions & 3 deletions apps/fe/src/modules/builder/components/Palette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function BlocksPanel({
onToggle,
desktop,
canIf,
ifWhy,
canEnd,
onAdd,
}: {
Expand All @@ -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) => <PaletteList compact={compact} canIf={canIf} canEnd={canEnd} onAdd={onAdd} />
const list = (compact: boolean) => <PaletteList compact={compact} canIf={canIf} ifWhy={ifWhy} canEnd={canEnd} onAdd={onAdd} />
return (
<aside
className={cn(
Expand Down Expand Up @@ -73,7 +76,7 @@ export function BlocksPanel({
}

/** Start (every job has one), then each block to tap or drag onto the canvas. */
function PaletteList({ compact, canIf, canEnd, onAdd }: { compact: boolean; canIf: boolean; canEnd: boolean; onAdd: (kind: Kind) => void }) {
function PaletteList({ compact, canIf, ifWhy, canEnd, onAdd }: { compact: boolean; canIf: boolean; ifWhy: string; canEnd: boolean; onAdd: (kind: Kind) => void }) {
const { name } = useBuilder()
const { startDrag, endDrag } = useDrag()
const fits: Partial<Record<Kind, boolean>> = { if: canIf, end: canEnd }
Expand All @@ -87,7 +90,7 @@ function PaletteList({ compact, canIf, canEnd, onAdd }: { compact: boolean; canI
tone={tone}
icon={<Icon />}
title={title(name)}
line={fits[kind] === false ? (PALETTE_WHY_NOT[kind] ?? line(name)) : line(name)}
line={fits[kind] === false ? (kind === "if" ? ifWhy : (PALETTE_WHY_NOT[kind] ?? line(name))) : line(name)}
onClick={() => onAdd(kind)}
onDragStart={() => startDrag({ add: kind })}
onDragEnd={endDrag}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IfPanel } from "@/modules/builder/components/panels/IfPanel"
import { StartPanel } from "@/modules/builder/components/panels/StartPanel"
import { ToolPanel } from "@/modules/builder/components/panels/ToolPanel"
import type { Kind } from "@/modules/builder/data/blocks"
import { canPlace, carriesOn, isStep, notesBefore, resultsOf, stepsBefore, type Block, type Draft, type IfBlock } from "@/modules/builder/data/draft"
import { canPlace, carriesOn, ifLockedWhy, isStep, notesBefore, resultsOf, stepsBefore, type Block, type Draft, type IfBlock } from "@/modules/builder/data/draft"
import type { EngineIssue } from "@/modules/builder/data/issues"
import { slotPlace, type Place } from "@/modules/builder/data/places"
import { skillCopy } from "@/modules/skills/data/skills"
Expand Down Expand Up @@ -71,6 +71,7 @@ function PickedPanel({ draft, picked: b, slot, missingSkillFor, set, onPatch, on
more={slot.block[slot.h].length > 0}
goesOn={carriesOn(line, at.path)}
canIf={canPlace(line, at.path, at.index, "if", self)}
ifWhy={ifLockedWhy(line, at.path, at.index, self)}
canEnd={canPlace(line, at.path, at.index, "end", self)}
onPick={(kind) => onAdd(kind, at)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function EndingPanel({
more = false,
goesOn = false,
canIf,
ifWhy,
canEnd,
onPick,
}: {
Expand All @@ -22,11 +23,13 @@ export function EndingPanel({
/** Blocks follow its If, so an empty way carries on to them instead of stopping. */
goesOn?: boolean
canIf: boolean
/** Why the If can't go on this way, when it can't. */
ifWhy: string
canEnd: boolean
onPick: (kind: Kind) => void
}) {
const { name } = useBuilder()
const off = (kind: Kind) => (kind === "if" && !canIf) || (kind === "end" && !canEnd) ? WHY_NOT[kind] : undefined
const off = (kind: Kind) => (kind === "if" && !canIf ? ifWhy : kind === "end" && !canEnd ? WHY_NOT[kind] : undefined)
return (
<>
<PanelHead icon={<SquareIcon />} title={which === "then" ? "If yes" : "If no"} />
Expand Down
12 changes: 12 additions & 0 deletions apps/fe/src/modules/builder/data/draft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,18 @@ export function stepsBefore(line: Block[], id: string): Step[] {
return hit ? stepsAt(line, hit.path, hit.index) : []
}

/**
* Why an If can't go at a place, in the owner's words (Ancung, 11 Nov: "Add a check or a website
* first" read like a bug). An If compares a number or a text; a list (events, emails) is compared
* through its count (#264).
*/
export function ifLockedWhy(line: Block[], path: LinePath, index: number, self?: Self, short = false): string {
const steps = stepsAt(line, path, index)
// Something comparable came before, so it's the path that ends above.
if (resultsBefore(steps, steps.length, self).some(comparable)) return "The path already ends above"
return short ? "Add a step that gives a number or text first" : "Add a step before it that gives a number or a text, like Check the time, Read the calendar or Call a website."
}

/** Whether a new block of this kind may go at `index` of the line at `path` (#164 rules). */
export function canPlace(line: Block[], path: LinePath, index: number, kind: Block["kind"], self?: Self): boolean {
const here = lineAt(line, path)
Expand Down
Loading
Loading