@fugood/bricks-project 2.25.0-beta.21 → 2.25.0-beta.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/compile/index.ts CHANGED
@@ -1194,7 +1194,7 @@ export const compile = async (app: Application) => {
1194
1194
  ...compileRemoteUpdate(data.remoteUpdate),
1195
1195
  routing: data.routing,
1196
1196
  schema: data.schema,
1197
- type: data.type,
1197
+ type: data.type === 'boolean' ? 'bool' : data.type,
1198
1198
  ...compileKind(data.kind),
1199
1199
  value: compileProperty(data.value, `(data: ${dataId}, subspace ${subspaceId})`),
1200
1200
  event_map: compileEvents('PROPERTY_BANK', data.events || {}, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fugood/bricks-project",
3
- "version": "2.25.0-beta.21",
3
+ "version": "2.25.0-beta.23",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "typecheck": "tsc --noEmit",
package/package.json.bak CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fugood/bricks-ctor",
3
- "version": "2.25.0-beta.21",
3
+ "version": "2.25.0-beta.23",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "typecheck": "tsc --noEmit",
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: bricks-ctor
3
- description: Advanced BRICKS configuration knowledge. Covers Standby Transition, Automations (E2E testing), Data Calculation (JS sandbox libraries), Local Sync, Remote Data Bank, Media Flow, Buttress (remote inference), and the verification toolchain (compile/preview MCP, on-device DevTools, definition-of-done gate). Triggers on multi-device sync, cloud data, media assets, AI offloading, E2E testing, canvas transitions, or verifying project work before declaring done.
3
+ description: Advanced BRICKS configuration knowledge. Covers Standby Transition, Automations (E2E testing), Data Calculation (JS sandbox libraries), Local Sync, Remote Data Bank, Media Flow, Buttress (remote inference), and the verification toolchain (compile, harness-specific preview tool, on-device DevTools, definition-of-done gate). Triggers on multi-device sync, cloud data, media assets, AI offloading, E2E testing, canvas transitions, or verifying project work before declaring done.
4
4
  ---
5
5
 
6
6
  # BRICKS Ctor - Advanced Features
@@ -20,7 +20,7 @@ This skill covers advanced BRICKS features not in the main project instructions.
20
20
  | [Remote Data Bank](rules/remote-data-bank.md) | Cloud data sync and API access |
21
21
  | [Media Flow](rules/media-flow.md) | Media asset management |
22
22
  | [Buttress](rules/buttress.md) | Remote inference for AI generators |
23
- | [Verification Toolchain](rules/verification-toolchain.md) | Definition of done, compile/preview MCP, on-device DevTools, Path 1/2/3 decision rule |
23
+ | [Verification Toolchain](rules/verification-toolchain.md) | Definition of done, compile, preview tool selection, on-device DevTools, Path 1/2/3 decision rule |
24
24
 
25
25
  ## Quick Reference
26
26
 
@@ -26,6 +26,8 @@ The primary way to orchestrate multi-step flows. A single event can contain an a
26
26
  - Use `dataParams` + `mapping` to pass event data downstream
27
27
  - This is the "glue" that wires generators, state, and UI together
28
28
 
29
+ Sequential `PROPERTY_BANK` / `PROPERTY_BANK_EXPRESSION` actions in one chain read the data values that existed when the chain started. If a later action needs to read what an earlier action wrote, set `waitAsync: true` on the earlier action.
30
+
29
31
  ### System Actions (Priority 3)
30
32
  Built-in commands for direct state and UI changes.
31
33
  - **PROPERTY_BANK**: set data value
@@ -67,3 +69,13 @@ Only actual data derivation maps to Data Calculation:
67
69
 
68
70
  ### Step 4: Wire with Event Action Chains
69
71
  Connect the pieces through events on generators and bricks.
72
+
73
+ ## Recipe: user-driven state machine (calculator, form wizard, picker)
74
+
75
+ A brief like "state vars X, Y, Z; button A updates X from X+Y; button B resets" is a state machine. The shape:
76
+
77
+ - Each state variable is its own `Data` entity. Displays read it via `linkData(() => data.dFoo)`.
78
+ - Each button's `onPress` is an Event Action Chain. For every state var that changes, append one `PROPERTY_BANK_EXPRESSION` whose `expression` reads the current state and returns the new value.
79
+ - Use `Data Calculation` only for reusable pure derivations referenced as inputs to those expressions.
80
+
81
+ A 10-button calculator with 4 state vars is ~10 small chains of 1–4 inline expressions. If you find yourself writing a single auto-mode `DataCalculationScript` that consumes all state vars and emits all-new state through mirror `dFooResult` data — or pinging a `dLastInput` field to force an auto calc to re-run — the chain shape was the right answer.
@@ -167,7 +167,7 @@ code: `
167
167
 
168
168
  ## Triggering Manually
169
169
 
170
- Use `PROPERTY_BANK_COMMAND` system action to trigger a manual calculation:
170
+ Use `PROPERTY_BANK_COMMAND` system action to trigger a manual calculation. `input` references a Data that is a trigger input (`trigger: true`) of the target calc — the system runs the calc(s) that data feeds into. It does NOT reference the DataCalculation itself.
171
171
 
172
172
  ```typescript
173
173
  const triggerCalc: EventAction = {
@@ -176,12 +176,14 @@ const triggerCalc: EventAction = {
176
176
  __actionName: 'PROPERTY_BANK_COMMAND',
177
177
  parent: 'System',
178
178
  dataParams: [
179
- { input: () => computeTotalCalc }, // Reference to DataCalculation
179
+ { input: () => priceData }, // Reference to a trigger Data input of the calc
180
180
  ],
181
181
  },
182
182
  }
183
183
  ```
184
184
 
185
+ When the same chain writes a calc input (e.g. `PROPERTY_BANK` setting `dLastButton`) then issues `PROPERTY_BANK_COMMAND`, set `waitAsync: true` on the write so the calc reads the new value rather than the pre-chain snapshot. See [Event Action Chains](architecture-patterns.md#event-action-chains-priority-2).
186
+
185
187
  ## Best Practices
186
188
 
187
189
  1. **Avoid circular deps**: Set non-triggering inputs (`trigger: false`) or use `manual` mode
@@ -194,9 +196,7 @@ const triggerCalc: EventAction = {
194
196
  See [Architecture Patterns](architecture-patterns.md) for the full pattern selection guide.
195
197
 
196
198
  ### Using Data Calc as an orchestrator
197
- Scripts that manage state machines, control UI flow, or coordinate multi-step processes belong in Event Action Chains, not here.
198
-
199
- **Symptom**: Script has if/else branches deciding "what happens next" or tracks "current step".
199
+ Scripts that manage state machines, control UI flow, or coordinate multi-step processes belong in Event Action Chains. Symptoms: if/else on "what happens next", mirror `dFooResult` outputs that copy back to `dFoo` via `valueChange`, or a `dLastInput` field set-then-cleared to force an auto calc. See the "user-driven state machine" recipe in [Architecture Patterns](architecture-patterns.md).
200
200
 
201
201
  ### Quick reference
202
202
 
@@ -7,7 +7,7 @@ Three runtime targets, one decision rule. Verify against the cheapest path that
7
7
  Before the agent is allowed to claim work is complete, **all** of the following must be true:
8
8
 
9
9
  1. **Compile clean.** Latest source passes `compile` with no errors.
10
- 2. **Every Canvas screenshot captured.** A rendered screenshot of every Canvas in the deliverable, captured via `preview` MCP (`responseImage: true`) at the target hardware resolution and orientation. Canvases gated behind events are reached via Automation runs (`testId` / `testTitleLike` with `brick_press` / `wait_until_canvas_change` cases). Single-Canvas Subspaces still require a captured screenshot.
10
+ 2. **Every Canvas screenshot captured.** A rendered screenshot of every Canvas in the deliverable, captured via the available preview tool (`responseImage: true` when the selected model supports vision) at the target hardware resolution and orientation. Canvases gated behind events are reached via Automation runs (`testId` / `testTitleLike` with `brick_press` / `wait_until_canvas_change` cases). Single-Canvas Subspaces still require a captured screenshot.
11
11
  3. **Every screenshot reviewed by the agent.** The agent must read each captured screenshot back through the host's image-reading capability — saving the file is not the same as seeing it. The model that produced the Canvas must also have seen the rendered result, or the verification gate has not passed.
12
12
  4. **Reference comparison report.** If the user supplied any reference material (Figma / website / HTML / screenshot / PDF / brand book / competitor), produce a short delta report per Canvas:
13
13
  - What matches the reference.
@@ -30,23 +30,30 @@ If any item is unmet, the work is mid-iteration. Say so explicitly to the user;
30
30
 
31
31
  The default loop. Always available; deterministic; no device wear; safe for side-effecting flows because nothing real fires.
32
32
 
33
- ### `bricks-ctor` MCP `compile`
33
+ `bun update-app` and `bun deploy-app` publish to the BRICKS portal. The local preview reads `.bricks/build/application-config.json` (produced by `compile`) directly.
34
+
35
+ ### Compile tool
34
36
 
35
37
  Typecheck + compile the project. Gate every iteration on this; everything below assumes a clean compile.
36
38
 
37
39
  Agent invocation: call the MCP tool `compile` exposed by the `bricks-ctor` MCP server registered for the project. No arguments.
38
40
 
39
- ### `bricks-ctor` MCP — `preview`
41
+ ### Preview tool
42
+
43
+ Use the preview implementation exposed by the current harness:
44
+
45
+ - **CTOR Desktop agent session:** use `preview_invoke`. CTOR Desktop disables the `bricks-ctor` MCP `preview` tool and routes screenshots/automation through the desktop preview pane instead. If the user already opened the simulator pane, `preview_invoke` should reuse it rather than start a separate preview.
46
+ - **Pure `bricks-ctor` project / other agent harness:** use the `bricks-ctor` MCP `preview` tool when `preview_invoke` is not available.
40
47
 
41
- Launches headless Electron, takes a screenshot, optionally runs a named Automation test by id or partial title.
48
+ Both forms are the same verification primitive: launch or reuse Electron preview, take a screenshot, and optionally run a named Automation test by id or partial title. Do not hard-code one tool name into the workflow; choose the available preview tool for the environment.
42
49
 
43
- Arguments:
44
- - `delay` (ms before screenshot) — default 3000. Increase if Standby Transitions are still in flight.
50
+ Common arguments:
51
+ - `delay` (ms before screenshot) — default is harness-specific: usually 3000 for a fresh/standalone preview; CTOR Desktop may capture immediately when its preview already has a settled latest config. Increase if Standby Transitions are still in flight.
45
52
  - `width`, `height` — screenshot dimensions in px.
46
- - `responseImage: true` — return base64 jpeg as MCP image content (recommended for visual sanity).
53
+ - `responseImage: true` — return the screenshot as image content when the selected model supports vision. If vision is unavailable, save the screenshot and report the path.
47
54
  - `testId` or `testTitleLike` — run a project Automation before the screenshot. Use `testTitleLike` for fuzzy matches (case-insensitive partial title).
48
55
 
49
- Returns text log + (if `responseImage`) base64 image content.
56
+ Returns text log + saved screenshot path + image content when supported.
50
57
 
51
58
  ### `bun preview` (project script)
52
59
 
@@ -76,7 +83,7 @@ Trigger types: `launch` (runs on app start), `anytime` (manual), `cron` (schedul
76
83
 
77
84
  Important: the automation map id must be `'AUTOMATION_MAP_DEFAULT'` (not a generated id) — the preview test runner reads from `automationMap['AUTOMATION_MAP_DEFAULT']?.map`.
78
85
 
79
- Run a single test from the agent: `bricks-ctor` MCP `preview` with `testId` or `testTitleLike`.
86
+ Run a single test from the agent: call the available preview tool (`preview_invoke` in CTOR Desktop, otherwise `bricks-ctor` MCP `preview`) with `testId` or `testTitleLike`.
80
87
 
81
88
  ## Path 2 — Real device with DevTools enabled
82
89
 
@@ -23,7 +23,7 @@ description: >-
23
23
  Encodes architecture truths, performance and complexity guardrails,
24
24
  input-translation rules, visual languages library, Direction
25
25
  Advisor for vague briefs, Media Flow protocol for branded work.
26
- Verification toolchain (compile/preview MCP, on-device DevTools,
26
+ Verification toolchain (compile, preview tool selection, on-device DevTools,
27
27
  Path 1/2/3) lives in the bricks-ctor skill.
28
28
  ---
29
29
 
@@ -57,7 +57,7 @@ Use when variations share most of the Brick tree but differ on a chunk that can'
57
57
  - Each variant Subspace imports the shared module and overrides only the variant-specific chunk.
58
58
  - Bricks reused by reference, not duplicated.
59
59
 
60
- **Comparison surface:** screenshot per variant via preview MCP, assembled in chat.
60
+ **Comparison surface:** screenshot per variant via the available preview tool, assembled in chat.
61
61
 
62
62
  **Token cost:** 1 shared module + N small variant Subspaces.
63
63
 
package/tools/_shell.ts CHANGED
@@ -29,6 +29,7 @@ class Sh implements PromiseLike<ShResult> {
29
29
  private _cwd: string | undefined
30
30
  private _mode: Mode = 'default'
31
31
  private _throw = true
32
+ private _env: NodeJS.ProcessEnv | undefined
32
33
  private _promise: Promise<ShResult> | null = null
33
34
 
34
35
  constructor(private readonly args: string[]) {}
@@ -48,6 +49,11 @@ class Sh implements PromiseLike<ShResult> {
48
49
  return this
49
50
  }
50
51
 
52
+ env(extra: NodeJS.ProcessEnv): this {
53
+ this._env = { ...this._env, ...extra }
54
+ return this
55
+ }
56
+
51
57
  async text(): Promise<string> {
52
58
  // If no explicit quiet was requested, capture stdout/stderr without
53
59
  // forwarding them to the parent's streams (matches Bun's `.text()`).
@@ -79,7 +85,8 @@ class Sh implements PromiseLike<ShResult> {
79
85
  ? ['ignore', 'pipe', 'pipe']
80
86
  : ['inherit', 'pipe', 'pipe']
81
87
 
82
- const proc = spawn(cmd, rest, { cwd: this._cwd, stdio })
88
+ const env = this._env ? { ...process.env, ...this._env } : undefined
89
+ const proc = spawn(cmd, rest, { cwd: this._cwd, stdio, env })
83
90
 
84
91
  const outChunks: Buffer[] = []
85
92
  const errChunks: Buffer[] = []
@@ -3,16 +3,21 @@ import { readFile } from 'node:fs/promises'
3
3
  import { z } from 'zod'
4
4
  import { sh } from '../_shell'
5
5
 
6
+ // Disable ANSI color codes from spawned tools so MCP text output stays readable
7
+ // (the host renders raw text; escape sequences leak into the result otherwise).
8
+ const noColorEnv = { FORCE_COLOR: '0', NO_COLOR: '1' }
9
+
6
10
  export function register(server: McpServer, projectDir: string) {
7
11
  const { dirname } = import.meta
8
12
 
9
13
  server.tool('compile', {}, async () => {
10
- let log = ''
14
+ let log = 'Type checking & Compiling...\n'
11
15
  try {
12
- log += 'Type checking & Compiling...'
13
- log += await sh`bun compile`.cwd(projectDir).text()
14
- } catch (err) {
15
- log += `${err.stdout.toString()}\n${err.stderr.toString()}`
16
+ log += await sh`bun compile`.cwd(projectDir).env(noColorEnv).text()
17
+ } catch (err: any) {
18
+ const stdout = err.stdout?.toString() ?? ''
19
+ const stderr = err.stderr?.toString() ?? ''
20
+ log += [stdout, stderr].filter(Boolean).join('\n')
16
21
  }
17
22
  return {
18
23
  content: [{ type: 'text', text: log }],
@@ -65,9 +70,12 @@ export function register(server: McpServer, projectDir: string) {
65
70
  if (testTitleLike) args.push('--test-title-like', testTitleLike)
66
71
  log = await sh`bunx --bun electron ${toolsDir}/preview-main.mjs ${args}`
67
72
  .cwd(projectDir)
73
+ .env(noColorEnv)
68
74
  .text()
69
- } catch (err) {
70
- log = `${err.stdout.toString()}\n${err.stderr.toString()}`
75
+ } catch (err: any) {
76
+ const stdout = err.stdout?.toString() ?? ''
77
+ const stderr = err.stderr?.toString() ?? ''
78
+ log = [stdout, stderr].filter(Boolean).join('\n')
71
79
  error = true
72
80
  }
73
81
  let screenshotBase64: string | null = null
@@ -2,9 +2,12 @@ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
2
2
  import { z } from 'zod'
3
3
  import { sh } from '../_shell'
4
4
 
5
+ // MCP results are rendered as raw text — disable ANSI colors from the child.
6
+ const noColorEnv = { FORCE_COLOR: '0', NO_COLOR: '1' }
7
+
5
8
  const runBricks = async (projectDir: string, ...args: string[]) => {
6
9
  try {
7
- return await sh`bunx bricks ${args}`.cwd(projectDir).text()
10
+ return await sh`bunx bricks ${args}`.cwd(projectDir).env(noColorEnv).text()
8
11
  } catch (err: any) {
9
12
  throw new Error(err.stderr?.toString() || err.message)
10
13
  }
package/types/common.ts CHANGED
@@ -12,7 +12,7 @@ export interface Brick {
12
12
  description?: string
13
13
  hideShortRef?: boolean
14
14
  property?: {}
15
- events: {}
15
+ events?: {}
16
16
  outlets?: {}
17
17
  animation?: {}
18
18
  switches?: Array<SwitchDef>
@@ -33,7 +33,7 @@ export interface Generator {
33
33
  hideShortRef?: boolean
34
34
  localSyncRunMode?: LocalSyncStrategy
35
35
  property?: {}
36
- events: {}
36
+ events?: {}
37
37
  outlets?: {}
38
38
  switches?: Array<SwitchDef>
39
39
  }
@@ -0,0 +1,57 @@
1
+ /* Auto generated by build script */
2
+ import type { Data } from '../data'
3
+ import type { DataCalculation } from '../data-calc'
4
+
5
+ // Shared helpers — every generated DataCommand{Name} reuses these to describe
6
+ // its narrowed inputs/outputs, so the per-command files stay short.
7
+ export type DataCalcInput<K extends string = string, T = any> = {
8
+ key: K
9
+ source: (() => DataCalculationData | DataCommand) | T
10
+ sourceKey: string
11
+ trigger?: boolean
12
+ }
13
+
14
+ export type DataCalcOutput<K extends string = string> = {
15
+ key: K
16
+ target: () => DataCalculationData | DataCommand
17
+ targetKey: string
18
+ }
19
+
20
+ export interface DataCalculationData {
21
+ __typename: 'DataCalculationData'
22
+ title?: string
23
+ description?: string
24
+ hideShortRef?: boolean
25
+ data: () => Data
26
+ // 'change' is the only valid input port on a data node; the source must be
27
+ // another node (no inline literals), hence `never` for the second type arg.
28
+ inputs: Array<DataCalcInput<'change', never>>
29
+ outputs: Array<DataCalcOutput<'value'>>
30
+ }
31
+
32
+ export interface DataCommand {
33
+ __typename: 'DataCommand'
34
+ __commandName: string
35
+ id: string
36
+ title?: string
37
+ description?: string
38
+ hideShortRef?: boolean
39
+ inputs: Array<DataCalcInput>
40
+ outputs: Array<DataCalcOutput>
41
+ }
42
+
43
+ export type DataCalculationMap = DataCalculation & {
44
+ __typename: 'DataCalculationMap'
45
+ nodes: Array<DataCalculationData | DataCommand>
46
+ editorInfo: Array<{
47
+ node: DataCalculationData | DataCommand
48
+ position: { x: number; y: number }
49
+ points: Array<{
50
+ source: DataCalculationData | DataCommand
51
+ sourceOutputKey: string
52
+ target: DataCalculationData | DataCommand
53
+ targetInputKey: string
54
+ positions: Array<{ x: number; y: number }>
55
+ }>
56
+ }>
57
+ }