@fugood/bricks-ctor 2.25.0-beta.5 → 2.25.0-beta.51

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.
Files changed (187) hide show
  1. package/compile/__tests__/config-diff.test.js +100 -0
  2. package/compile/__tests__/index.test.js +386 -0
  3. package/compile/__tests__/util.test.js +337 -0
  4. package/compile/action-name-map.ts +64 -0
  5. package/compile/config-diff.ts +155 -0
  6. package/compile/index.ts +278 -34
  7. package/compile/util.ts +34 -10
  8. package/package.json +7 -3
  9. package/skills/bricks-ctor/SKILL.md +23 -17
  10. package/skills/bricks-ctor/{rules → references}/animation.md +3 -2
  11. package/skills/bricks-ctor/{rules → references}/architecture-patterns.md +18 -0
  12. package/skills/bricks-ctor/{rules → references}/automations.md +11 -0
  13. package/skills/bricks-ctor/references/buttress.md +245 -0
  14. package/skills/bricks-ctor/references/data-calculation.md +239 -0
  15. package/skills/bricks-ctor/references/simulator.md +132 -0
  16. package/skills/bricks-ctor/references/source-editing-tools.md +81 -0
  17. package/skills/bricks-ctor/references/verification-toolchain.md +200 -0
  18. package/skills/bricks-design/SKILL.md +150 -45
  19. package/skills/bricks-design/references/architecture-truths.md +132 -0
  20. package/skills/bricks-design/references/avoiding-complexity.md +91 -0
  21. package/skills/bricks-design/references/design-critique.md +195 -0
  22. package/skills/bricks-design/references/design-languages.md +265 -0
  23. package/skills/bricks-design/references/performance.md +116 -0
  24. package/skills/bricks-design/references/presentation-and-slideshow.md +137 -0
  25. package/skills/bricks-design/references/translating-inputs.md +152 -0
  26. package/skills/bricks-design/references/variations-and-tweaks.md +124 -0
  27. package/skills/bricks-design/references/when-the-brief-is-branded.md +284 -0
  28. package/skills/bricks-design/references/when-the-brief-is-vague.md +85 -0
  29. package/skills/bricks-design/references/workflow.md +134 -0
  30. package/skills/bricks-ux/SKILL.md +114 -0
  31. package/skills/bricks-ux/references/accessibility.md +162 -0
  32. package/skills/bricks-ux/references/flow-states.md +175 -0
  33. package/skills/bricks-ux/references/interaction-archetypes.md +189 -0
  34. package/skills/bricks-ux/references/monitoring-screens.md +153 -0
  35. package/skills/bricks-ux/references/pressable-composition.md +126 -0
  36. package/skills/bricks-ux/references/user-journey.md +168 -0
  37. package/skills/bricks-ux/references/ux-critique.md +256 -0
  38. package/tools/__tests__/_cli-error.test.ts +35 -0
  39. package/tools/__tests__/_mcp-config.test.ts +67 -0
  40. package/tools/_cli-error.ts +17 -0
  41. package/tools/_edits-log.ts +41 -0
  42. package/tools/_git-author.ts +10 -2
  43. package/tools/_last-pushed-commit.ts +28 -0
  44. package/tools/_mcp-config.ts +42 -0
  45. package/tools/_shell.ts +8 -1
  46. package/tools/deploy.ts +17 -6
  47. package/tools/mcp-env.ts +13 -0
  48. package/tools/mcp-server.ts +8 -0
  49. package/tools/mcp-tools/__tests__/data-calc-editing.test.js +516 -0
  50. package/tools/mcp-tools/__tests__/entry-editing.test.js +866 -0
  51. package/tools/mcp-tools/__tests__/huggingface.test.ts +49 -0
  52. package/tools/mcp-tools/__tests__/icons.test.ts +21 -0
  53. package/tools/mcp-tools/__tests__/mcp-env.test.js +19 -0
  54. package/tools/mcp-tools/_editing-helpers.ts +58 -0
  55. package/tools/mcp-tools/_verify.ts +50 -0
  56. package/tools/mcp-tools/compile.ts +21 -9
  57. package/tools/mcp-tools/data-calc-editing.ts +1349 -0
  58. package/tools/mcp-tools/entry-editing.ts +2336 -0
  59. package/tools/mcp-tools/huggingface.ts +23 -13
  60. package/tools/mcp-tools/icons.ts +23 -7
  61. package/tools/mcp-tools/media.ts +4 -1
  62. package/tools/postinstall.ts +95 -38
  63. package/tools/pull.ts +93 -22
  64. package/tools/push-config.ts +114 -0
  65. package/tools/{preview-main.mjs → simulator-main.mjs} +207 -12
  66. package/tools/simulator-preload.cjs +16 -0
  67. package/tools/{preview.ts → simulator.ts} +4 -4
  68. package/types/{animation.ts → animation.d.ts} +24 -8
  69. package/types/{automation.ts → automation.d.ts} +16 -20
  70. package/types/{brick-base.ts → brick-base.d.ts} +1 -1
  71. package/types/bricks/{Camera.ts → Camera.d.ts} +8 -8
  72. package/types/bricks/{Chart.ts → Chart.d.ts} +4 -4
  73. package/types/bricks/{GenerativeMedia.ts → GenerativeMedia.d.ts} +15 -15
  74. package/types/bricks/{Icon.ts → Icon.d.ts} +7 -7
  75. package/types/bricks/{Image.ts → Image.d.ts} +21 -9
  76. package/types/bricks/{Items.ts → Items.d.ts} +7 -7
  77. package/types/bricks/{Lottie.ts → Lottie.d.ts} +10 -10
  78. package/types/bricks/{Maps.ts → Maps.d.ts} +11 -11
  79. package/types/bricks/{QrCode.ts → QrCode.d.ts} +7 -7
  80. package/types/bricks/{Rect.ts → Rect.d.ts} +7 -7
  81. package/types/bricks/{RichText.ts → RichText.d.ts} +12 -9
  82. package/types/bricks/{Rive.ts → Rive.d.ts} +9 -9
  83. package/types/bricks/Scene3D.d.ts +676 -0
  84. package/types/bricks/{Sketch.ts → Sketch.d.ts} +6 -6
  85. package/types/bricks/{Slideshow.ts → Slideshow.d.ts} +7 -7
  86. package/types/bricks/{Svg.ts → Svg.d.ts} +7 -7
  87. package/types/bricks/{Text.ts → Text.d.ts} +9 -9
  88. package/types/bricks/{TextInput.ts → TextInput.d.ts} +10 -10
  89. package/types/bricks/{Video.ts → Video.d.ts} +12 -12
  90. package/types/bricks/{VideoStreaming.ts → VideoStreaming.d.ts} +10 -10
  91. package/types/bricks/{WebRtcStream.ts → WebRtcStream.d.ts} +1 -1
  92. package/types/bricks/{WebView.ts → WebView.d.ts} +4 -4
  93. package/types/bricks/{index.ts → index.d.ts} +1 -0
  94. package/types/{common.ts → common.d.ts} +3 -6
  95. package/types/data-calc-command/base.d.ts +57 -0
  96. package/types/data-calc-command/collection.d.ts +418 -0
  97. package/types/data-calc-command/color.d.ts +432 -0
  98. package/types/data-calc-command/constant.d.ts +50 -0
  99. package/types/data-calc-command/datetime.d.ts +147 -0
  100. package/types/data-calc-command/file.d.ts +129 -0
  101. package/types/data-calc-command/index.d.ts +13 -0
  102. package/types/data-calc-command/iteratee.d.ts +23 -0
  103. package/types/data-calc-command/logictype.d.ts +190 -0
  104. package/types/data-calc-command/math.d.ts +275 -0
  105. package/types/data-calc-command/object.d.ts +119 -0
  106. package/types/data-calc-command/sandbox.d.ts +66 -0
  107. package/types/data-calc-command/string.d.ts +407 -0
  108. package/types/{data-calc.ts → data-calc.d.ts} +1 -0
  109. package/types/{data.ts → data.d.ts} +4 -2
  110. package/types/generators/{Assistant.ts → Assistant.d.ts} +19 -0
  111. package/types/generators/{LlmGgml.ts → LlmGgml.d.ts} +43 -1
  112. package/types/generators/{LlmMlx.ts → LlmMlx.d.ts} +1 -0
  113. package/types/generators/{RerankerGgml.ts → RerankerGgml.d.ts} +5 -1
  114. package/types/generators/{SoundRecorder.ts → SoundRecorder.d.ts} +10 -1
  115. package/types/generators/{SpeechToTextGgml.ts → SpeechToTextGgml.d.ts} +6 -1
  116. package/types/generators/{SttAppleBuiltin.ts → SttAppleBuiltin.d.ts} +27 -4
  117. package/types/generators/{ThermalPrinter.ts → ThermalPrinter.d.ts} +9 -7
  118. package/types/generators/{VadGgml.ts → VadGgml.d.ts} +12 -2
  119. package/types/{subspace.ts → subspace.d.ts} +1 -1
  120. package/utils/__tests__/calc.test.js +25 -0
  121. package/utils/__tests__/id.test.js +154 -0
  122. package/utils/calc.ts +5 -1
  123. package/utils/data.ts +5 -7
  124. package/utils/event-props.ts +17 -0
  125. package/utils/id.ts +109 -56
  126. package/skills/bricks-ctor/rules/buttress.md +0 -156
  127. package/skills/bricks-ctor/rules/data-calculation.md +0 -209
  128. package/skills/bricks-design/LICENSE.txt +0 -180
  129. package/types/data-calc-command.ts +0 -7005
  130. /package/skills/bricks-ctor/{rules → references}/local-sync.md +0 -0
  131. /package/skills/bricks-ctor/{rules → references}/media-flow.md +0 -0
  132. /package/skills/bricks-ctor/{rules → references}/remote-data-bank.md +0 -0
  133. /package/skills/bricks-ctor/{rules → references}/standby-transition.md +0 -0
  134. /package/types/{canvas.ts → canvas.d.ts} +0 -0
  135. /package/types/{data-calc-script.ts → data-calc-script.d.ts} +0 -0
  136. /package/types/generators/{AlarmClock.ts → AlarmClock.d.ts} +0 -0
  137. /package/types/generators/{BleCentral.ts → BleCentral.d.ts} +0 -0
  138. /package/types/generators/{BlePeripheral.ts → BlePeripheral.d.ts} +0 -0
  139. /package/types/generators/{CanvasMap.ts → CanvasMap.d.ts} +0 -0
  140. /package/types/generators/{CastlesPay.ts → CastlesPay.d.ts} +0 -0
  141. /package/types/generators/{DataBank.ts → DataBank.d.ts} +0 -0
  142. /package/types/generators/{File.ts → File.d.ts} +0 -0
  143. /package/types/generators/{GraphQl.ts → GraphQl.d.ts} +0 -0
  144. /package/types/generators/{Http.ts → Http.d.ts} +0 -0
  145. /package/types/generators/{HttpServer.ts → HttpServer.d.ts} +0 -0
  146. /package/types/generators/{Information.ts → Information.d.ts} +0 -0
  147. /package/types/generators/{Intent.ts → Intent.d.ts} +0 -0
  148. /package/types/generators/{Iterator.ts → Iterator.d.ts} +0 -0
  149. /package/types/generators/{Keyboard.ts → Keyboard.d.ts} +0 -0
  150. /package/types/generators/{LlmAnthropicCompat.ts → LlmAnthropicCompat.d.ts} +0 -0
  151. /package/types/generators/{LlmAppleBuiltin.ts → LlmAppleBuiltin.d.ts} +0 -0
  152. /package/types/generators/{LlmMediaTekNeuroPilot.ts → LlmMediaTekNeuroPilot.d.ts} +0 -0
  153. /package/types/generators/{LlmOnnx.ts → LlmOnnx.d.ts} +0 -0
  154. /package/types/generators/{LlmOpenAiCompat.ts → LlmOpenAiCompat.d.ts} +0 -0
  155. /package/types/generators/{LlmQualcommAiEngine.ts → LlmQualcommAiEngine.d.ts} +0 -0
  156. /package/types/generators/{Mcp.ts → Mcp.d.ts} +0 -0
  157. /package/types/generators/{McpServer.ts → McpServer.d.ts} +0 -0
  158. /package/types/generators/{MediaFlow.ts → MediaFlow.d.ts} +0 -0
  159. /package/types/generators/{MqttBroker.ts → MqttBroker.d.ts} +0 -0
  160. /package/types/generators/{MqttClient.ts → MqttClient.d.ts} +0 -0
  161. /package/types/generators/{Question.ts → Question.d.ts} +0 -0
  162. /package/types/generators/{RealtimeTranscription.ts → RealtimeTranscription.d.ts} +0 -0
  163. /package/types/generators/{SerialPort.ts → SerialPort.d.ts} +0 -0
  164. /package/types/generators/{SoundPlayer.ts → SoundPlayer.d.ts} +0 -0
  165. /package/types/generators/{SpeechToTextOnnx.ts → SpeechToTextOnnx.d.ts} +0 -0
  166. /package/types/generators/{SpeechToTextPlatform.ts → SpeechToTextPlatform.d.ts} +0 -0
  167. /package/types/generators/{SqLite.ts → SqLite.d.ts} +0 -0
  168. /package/types/generators/{Step.ts → Step.d.ts} +0 -0
  169. /package/types/generators/{Tcp.ts → Tcp.d.ts} +0 -0
  170. /package/types/generators/{TcpServer.ts → TcpServer.d.ts} +0 -0
  171. /package/types/generators/{TextToSpeechAppleBuiltin.ts → TextToSpeechAppleBuiltin.d.ts} +0 -0
  172. /package/types/generators/{TextToSpeechGgml.ts → TextToSpeechGgml.d.ts} +0 -0
  173. /package/types/generators/{TextToSpeechOnnx.ts → TextToSpeechOnnx.d.ts} +0 -0
  174. /package/types/generators/{TextToSpeechOpenAiLike.ts → TextToSpeechOpenAiLike.d.ts} +0 -0
  175. /package/types/generators/{Tick.ts → Tick.d.ts} +0 -0
  176. /package/types/generators/{Udp.ts → Udp.d.ts} +0 -0
  177. /package/types/generators/{VadOnnx.ts → VadOnnx.d.ts} +0 -0
  178. /package/types/generators/{VadTraditional.ts → VadTraditional.d.ts} +0 -0
  179. /package/types/generators/{VectorStore.ts → VectorStore.d.ts} +0 -0
  180. /package/types/generators/{Watchdog.ts → Watchdog.d.ts} +0 -0
  181. /package/types/generators/{WebCrawler.ts → WebCrawler.d.ts} +0 -0
  182. /package/types/generators/{WebRtc.ts → WebRtc.d.ts} +0 -0
  183. /package/types/generators/{WebSocket.ts → WebSocket.d.ts} +0 -0
  184. /package/types/generators/{index.ts → index.d.ts} +0 -0
  185. /package/types/{index.ts → index.d.ts} +0 -0
  186. /package/types/{switch.ts → switch.d.ts} +0 -0
  187. /package/types/{system.ts → system.d.ts} +0 -0
@@ -26,10 +26,18 @@ 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
32
34
  - **PROPERTY_BANK_EXPRESSION**: inline JS expression for simple compute
35
+ - The expression engine folds statements into a single expression: only expression
36
+ statements, simple `const`/`let` declarations, and a final return/expression are
37
+ supported — **no `if`/`for`/`while`/`switch`** (use ternaries). The same limit
38
+ applies inside a zero-arg IIFE body. Unsupported statements fail at runtime with
39
+ the error visible only in a DevTools session, so prefer ternary chains or move the
40
+ logic to a DataCalculationScript.
33
41
  - **CHANGE_CANVAS**: navigate to another canvas
34
42
  - **DYNAMIC_ANIMATION**: trigger animation
35
43
  - **ALERT / MESSAGE**: system feedback
@@ -67,3 +75,13 @@ Only actual data derivation maps to Data Calculation:
67
75
 
68
76
  ### Step 4: Wire with Event Action Chains
69
77
  Connect the pieces through events on generators and bricks.
78
+
79
+ ## Recipe: user-driven state machine (calculator, form wizard, picker)
80
+
81
+ A brief like "state vars X, Y, Z; button A updates X from X+Y; button B resets" is a state machine. The shape:
82
+
83
+ - Each state variable is its own `Data` entity. Displays read it via `linkData(() => data.dFoo)`.
84
+ - 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.
85
+ - Use `Data Calculation` only for reusable pure derivations referenced as inputs to those expressions.
86
+
87
+ 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.
@@ -118,6 +118,16 @@ const testLoginFlow: AutomationTest = {
118
118
  | `match_screenshot` | `[name, threshold?, maxRetry?]` | Screenshot compare |
119
119
  | `delay` | `[subspace?, property?, defaultValue?]` | Delay execution |
120
120
 
121
+ In project TypeScript source, pass entity getters for BRICKS entities:
122
+
123
+ ```typescript
124
+ run: ['brick_press', () => mainSubspace, () => bricks.bSubmitButton]
125
+ run: ['wait_until_canvas_change', () => mainSubspace, () => canvases.cDone, 5000]
126
+ run: ['assert_property', () => mainSubspace, () => data.dStep, 'done']
127
+ ```
128
+
129
+ The compiler resolves these getters to the current generated IDs.
130
+
121
131
  ### execute_action Params
122
132
 
123
133
  The `params` object in `execute_action` uses **runtime event property keys** from `event-props.ts`, NOT the action config `input` names from type definitions.
@@ -208,6 +218,7 @@ Automations work with Modules. Use Manual Run in Preview mode for module testing
208
218
 
209
219
  - **Automation map key**: Always use `'AUTOMATION_MAP_DEFAULT'` as the automation map ID (not `makeId()`). The preview test runner reads from `automationMap['AUTOMATION_MAP_DEFAULT']?.map`.
210
220
  - **Valid makeId types**: Use `'test'` for AutomationTest, `'test_case'` for TestCase, `'test_var'` for TestVariable. Do NOT use `'automation_test'` or `'automation_test_map'`.
221
+ - **Entity references in run arrays**: Use getter references (`() => subspace`, `() => bricks.bButton`, `() => data.dValue`) in TypeScript source so compile resolves fresh IDs.
211
222
  - **handler in execute_action**: Pass the entity's `.id` string (e.g., `bricks.bInput.id`), not a getter function.
212
223
 
213
224
  ## Best Practices
@@ -0,0 +1,245 @@
1
+ # Buttress (Remote Inference)
2
+
3
+ Backend system for offloading compute-intensive AI generator tasks from BRICKS devices to more powerful machines.
4
+
5
+ ## Purpose
6
+
7
+ When mobile devices or embedded systems lack hardware for local AI inference (LLM, speech-to-text), Buttress transparently delegates work to a server with appropriate resources (GPU).
8
+
9
+ ## How It Works
10
+
11
+ 1. **Capability Exchange**: Client and server share hardware capabilities
12
+ 2. **Strategy Selection**: System decides local vs. remote execution
13
+ 3. **Transparent Offloading**: Generator operates same way, execution happens remotely
14
+
15
+ ## Supported Generators
16
+
17
+ - LLM (GGML) (LlmMlx.ts) - Local Large Language Model inference with GGML
18
+ - LLM (MLX) (LlmGgml.ts) - Local Large Language Model inference with MLX
19
+ - Speech-to-Text (GGML) (SpeechToTextGgml.ts) - Local Speech-to-Text inference with GGML
20
+
21
+ ## Client Configuration
22
+
23
+ In generator properties, configure `buttressConnectionSettings`:
24
+
25
+ | Setting | Description |
26
+ |---------|-------------|
27
+ | `enabled` | Toggle Buttress offloading |
28
+ | `autoDiscoverType` | `auto` (LAN auto-discovery, recommended) or `manual` (typed URL) |
29
+ | `url` | Server URL (`manual` mode only — leave empty for `auto`) |
30
+ | `fallbackType` | If Buttress is unreachable: `use-local` runs locally, `no-op` blocks the load |
31
+ | `strategy` | Execution preference (see below) |
32
+
33
+ The launcher provides the access token automatically — there is **no user-facing access-token setting**. In `auto` mode the launcher discovers servers bound to the device's workspace and uses its workspace-scoped JWT; in `manual` mode it sends the same JWT only when the typed URL belongs to a server bound to the same workspace (verified against the server's `/buttress/info`).
34
+
35
+ ### `autoDiscoverType` options
36
+
37
+ | Mode | When to use | What the device does |
38
+ |------|-------------|----------------------|
39
+ | `auto` | LAN deployment with a workspace-bound buttress-server | Listens for UDP announcements and picks the strongest server bound to its workspace; reconnects automatically when the workspace flips |
40
+ | `manual` | Internet-reachable server, mixed networks, or a public/unbound server | Connects to the typed `url` directly; sends a token only when the server is bound to the same workspace |
41
+
42
+ ### Strategy options
43
+
44
+ | Strategy | Description |
45
+ |----------|-------------|
46
+ | `prefer-local` | Use local if capable, fallback to Buttress |
47
+ | `prefer-buttress` | Use Buttress if available, fallback to local |
48
+ | `prefer-best` | Auto-select based on capability comparison |
49
+
50
+ ## Generator Configuration Examples
51
+
52
+ ### Auto-discovery (recommended)
53
+
54
+ Workspace-bound launcher + workspace-bound buttress-server on the same LAN. No URL needed — discovery picks the highest-scoring server that runs the requested backend.
55
+
56
+ ```typescript
57
+ import { makeId } from 'bricks-ctor'
58
+
59
+ const llmGenerator: GeneratorLLM = {
60
+ __typename: 'Generator',
61
+ templateKey: 'GENERATOR_LLM',
62
+ id: makeId('generator'),
63
+ title: 'Chat LLM',
64
+ description: '',
65
+ property: {
66
+ modelUrl: 'https://huggingface.co/ggml-org/gemma-3-12b-it-qat-GGUF/resolve/main/gemma-3-12b-it-qat-q4_0.gguf',
67
+ contextSize: 8192,
68
+ buttressConnectionSettings: {
69
+ enabled: true,
70
+ autoDiscoverType: 'auto',
71
+ fallbackType: 'use-local',
72
+ strategy: 'prefer-best',
73
+ },
74
+ },
75
+ events: {},
76
+ switches: [],
77
+ }
78
+ ```
79
+
80
+ ### Manual URL
81
+
82
+ Use when the server isn't on the launcher's broadcast domain (cross-subnet, internet, behind a reverse proxy) or you want to point at a specific public/unbound server.
83
+
84
+ ```typescript
85
+ buttressConnectionSettings: {
86
+ enabled: true,
87
+ autoDiscoverType: 'manual',
88
+ url: 'http://192.168.1.100:2080',
89
+ fallbackType: 'use-local',
90
+ strategy: 'prefer-best',
91
+ }
92
+ ```
93
+
94
+ > ⚠️ With `fallbackType: 'no-op'` the generator refuses to load locally if Buttress is unreachable. Use `'use-local'` whenever the device can also run the model standalone.
95
+
96
+ ## Integrating a discovered buttress-server
97
+
98
+ The ctor-desktop "Local Devices" panel (and the `bricks buttress scan` CLI) can hand you a server's identity, workspace, and announced generator caps. When the user asks to integrate one:
99
+
100
+ 1. **Confirm workspace match.** The discovery message says whether the server's workspace matches this project's. If it doesn't, do NOT add the integration — instruct the user to run `bricks buttress unbind && bricks buttress bind` from this workspace's owner CLI on the server host. The launcher won't trust a cross-workspace server.
101
+
102
+ 2. **Map announced types to generator templates.** For each `generators[].type` in the announce, target the matching templateKey (create the generator if absent):
103
+
104
+ | Announced type | templateKey | Default model |
105
+ |----------------|------------------------------|---------------|
106
+ | `ggml-llm` | `GENERATOR_LLM` | `ggml-org/gemma-3-12b-it-qat-GGUF` (≥20 GB usable) or `ggml-org/gpt-oss-20b-GGUF` (~12 GB usable) |
107
+ | `mlx-llm` | `GENERATOR_MLX_LLM` | `mlx-community/Qwen3-4B-4bit` (or a larger 4-bit quant if `usableBytes` allows) |
108
+ | `ggml-stt` | `GENERATOR_SPEECH_INFERENCE` | `BricksDisplay/whisper-ggml` (filename `ggml-small-q8_0.bin`) |
109
+
110
+ Pick a model that fits the announced `usableBytes`. Set `contextSize` to match.
111
+
112
+ 3. **Use the canonical auto-discovery config** from "Auto-discovery (recommended)" above. Don't switch to manual mode just because the server is on the LAN — auto mode picks the workspace-bound server automatically and rebinds when the device's workspace flips.
113
+
114
+ ### Real-device caveat
115
+
116
+ Buttress LAN auto-discovery uses native UDP via `react-native-jsi-udp`. The iOS Simulator silently fails to bind UDP, so auto mode is a no-op there. With `fallbackType: 'use-local'` the generator falls back to local inference in the simulator — dev/test stays functional. **Validate the buttress path itself only when deploying to a real Foundation device; don't gate the build on simulator validation.**
117
+
118
+ ## Server Setup
119
+
120
+ ### Requirements
121
+ - [Bun](https://bun.sh) v1.3+
122
+ - GPU recommended for LLM/STT
123
+
124
+ ### Installation
125
+
126
+ ```bash
127
+ bun add -g @fugood/buttress-server
128
+ ```
129
+
130
+ ### Start Server
131
+
132
+ ```bash
133
+ bricks-buttress
134
+ # or with config
135
+ bricks-buttress --config ./config.toml
136
+ ```
137
+
138
+ ### CLI Options
139
+
140
+ | Option | Description |
141
+ |--------|-------------|
142
+ | `-p, --port` | Port (default: 2080) |
143
+ | `-c, --config` | TOML config file path |
144
+ | `-v, --version` | Show version |
145
+ | `-h, --help` | Show help |
146
+
147
+ ### Environment Variables
148
+
149
+ | Variable | Description |
150
+ |----------|-------------|
151
+ | `HF_TOKEN` | Hugging Face token for model downloads |
152
+ | `ENABLE_OPENAI_COMPAT_ENDPOINT` | Set to `1` for OpenAI-compatible API |
153
+ | `BRICKS_BUTTRESS_STATE_DIR` | Override the workspace state directory (default `~/.bricks-cli/buttress`) |
154
+
155
+ ## Bind the Server to a Workspace
156
+
157
+ To use `autoDiscoverType: 'auto'` — and to require workspace-scoped JWT auth — pair the buttress-server with a BRICKS workspace using the `bricks buttress` CLI commands. An unbound server stays in legacy public mode and accepts any LAN client.
158
+
159
+ ### One-time bind
160
+
161
+ ```bash
162
+ # Log into the cloud bricks-server with the workspace owner's account
163
+ bricks auth login
164
+
165
+ # Pair the buttress-server running on this machine with the active workspace
166
+ bricks buttress bind
167
+
168
+ # Restart bricks-buttress so it picks up the new state.json
169
+ ```
170
+
171
+ `bricks buttress bind` writes `~/.bricks-cli/buttress/state.json` containing the workspace id, the issuer's Ed25519 public key, and a stable `serverId` (defaults to `buttress-<machineId>`). Override location with `--state-dir` or `$BRICKS_BUTTRESS_STATE_DIR`. For headless setups, use `bricks buttress bind --print` to emit state.json to stdout.
172
+
173
+ ### Verify and manage
174
+
175
+ ```bash
176
+ # Show local binding + workspace-side bound list
177
+ bricks buttress status
178
+
179
+ # Discover buttress-servers on the LAN (with version, auth state, generator caps)
180
+ bricks buttress scan
181
+
182
+ # Issue a long-lived workspace access token (CI / ctor agents that already hold a workspace token)
183
+ bricks buttress issue-token --ttl 86400
184
+
185
+ # Detach this server from the workspace
186
+ bricks buttress unbind
187
+ ```
188
+
189
+ After binding, launchers in the same workspace will auto-discover this server; manual-mode generators will only send their access token if the server's reported workspace matches their own.
190
+
191
+ ## Server Configuration (TOML)
192
+
193
+ ```toml
194
+ [server]
195
+ port = 2080
196
+
197
+ [runtime]
198
+ cache_dir = "./.buttress-cache"
199
+ n_threads = 6
200
+ flash_attn_type = "on"
201
+ cache_type_k = "q8_0"
202
+ cache_type_v = "q8_0"
203
+
204
+ # LLM Generator
205
+ [[generators]]
206
+ type = "ggml-llm"
207
+ [generators.backend]
208
+ variant_preference = ["cuda", "vulkan", "default"]
209
+ gpu_memory_fraction = 0.95
210
+ [generators.model]
211
+ repo_id = "ggml-org/gemma-3-12b-it-qat-GGUF"
212
+ download = true
213
+ n_ctx = 8192
214
+
215
+ # STT Generator
216
+ [[generators]]
217
+ type = "ggml-stt"
218
+ [generators.backend]
219
+ variant_preference = ["cuda", "vulkan", "default"]
220
+ [generators.model]
221
+ repo_id = "BricksDisplay/whisper-ggml"
222
+ filename = "ggml-small-q8_0.bin"
223
+ download = true
224
+ use_gpu = true
225
+ ```
226
+
227
+ ## Use Cases
228
+
229
+ ### Resource-Constrained Devices
230
+ Digital signage with basic hardware offloads LLM to powerful server.
231
+
232
+ ### Shared GPU Resources
233
+ Multiple devices share single GPU server for inference.
234
+
235
+ ### Development Testing
236
+ Test AI features on lightweight dev machines by connecting to beefy server.
237
+
238
+ ## Best Practices
239
+
240
+ 1. **Network reliability**: Ensure stable LAN connection to Buttress server
241
+ 2. **Fallback strategy**: Configure appropriate fallback for critical features
242
+ 3. **Server monitoring**: Monitor Buttress server resource usage
243
+ 4. **Model consistency**: Ensure client and server use compatible models
244
+ 5. **Security**: Run Buttress on private network, not public internet
245
+ 6. **Latency awareness**: Account for network latency in UX design
@@ -0,0 +1,239 @@
1
+ # Data Calculation (JS Sandbox)
2
+
3
+ Transform and compute Data Bank values using JavaScript scripts. Calcs are for **pure data transformation only** — see [Architecture Patterns](architecture-patterns.md) for the pattern selection guide.
4
+
5
+ | If you need to... | Use instead |
6
+ |---|---|
7
+ | Call an LLM / AI model | Generator (Assistant, LLM, HTTP) |
8
+ | Sequence multiple actions | Event Action Chain |
9
+ | Set a data value directly | PROPERTY_BANK system action |
10
+ | Compute a simple expression | PROPERTY_BANK_EXPRESSION |
11
+ | Transform/format/parse data | Data Calculation (correct use) |
12
+
13
+ ## Authoring Contract
14
+
15
+ ```typescript
16
+ import { makeId } from 'bricks-ctor'
17
+ import { readFile } from 'node:fs/promises'
18
+
19
+ const calculation: DataCalculationScript = {
20
+ __typename: 'DataCalculationScript',
21
+ id: makeId('property_bank_calc'),
22
+ title: 'Format Price',
23
+ description: 'Formats price with currency symbol',
24
+ note: '',
25
+ triggerMode: 'auto', // 'auto' (default) | 'manual'
26
+ enableAsync: false,
27
+ // Inline code for short scripts...
28
+ code: `
29
+ const price = inputs.price || 0
30
+ const currency = inputs.currency || 'USD'
31
+ return new Intl.NumberFormat('en-US', {
32
+ style: 'currency',
33
+ currency,
34
+ }).format(price)
35
+ `,
36
+ // ...or load from a file (preferred for longer scripts):
37
+ // code: await readFile(new URL('./format-price.sandbox.js', import.meta.url), 'utf8'),
38
+ inputs: [
39
+ { key: 'price', data: () => priceData, trigger: true },
40
+ { key: 'currency', data: () => currencyData, trigger: false },
41
+ ],
42
+ output: () => formattedPriceData,
43
+ outputs: [], // Additional named outputs (see Multiple Outputs)
44
+ error: null, // or () => errorData for error handling
45
+ }
46
+ ```
47
+
48
+ ### Field Rules (defaults and constraints)
49
+
50
+ - `trigger` **defaults to `false` when omitted** — always set it explicitly. A calc whose inputs are all non-trigger never auto-runs.
51
+ - `triggerMode` defaults to `'auto'` when omitted.
52
+ - `output` receives the **whole return value**. `outputs` entries extract fields by key from a returned object — `key` is a lodash-get path, so deep paths like `'user.name'` work. `output`, `outputs`, and `error` can be combined.
53
+ - `error` receives the error **message string** when the script throws. Both extraction steps run on every execution: a success overwrites the error Data, a failure overwrites the output Data(s) — don't expect stale values to persist.
54
+ - **Auto mode rejects the same Data in both `inputs` and `output`/`outputs`/`error`** — compile fails with `Not allow duplicate set property id between inputs / outputs / output / error`. Manual mode allows the overlap (self-referential updates, see Recipes).
55
+ - `.sandbox.js` files use an `export function main() { ... }` wrapper — compile unwraps it. Raw statements also work, but the wrapper keeps linters happy since script bodies use top-level `return`.
56
+
57
+ ## Trigger Modes
58
+
59
+ | Mode | Description |
60
+ |------|-------------|
61
+ | `auto` | Run on every write to a `trigger: true` input (even if the value is unchanged) |
62
+ | `manual` | Never auto-runs; only via `PROPERTY_BANK_COMMAND` action. Allows the same Data as both input and output |
63
+
64
+ Use `manual` to prevent circular dependencies, for explicit control, or when an output must feed back into an input.
65
+
66
+ ## Triggering via PROPERTY_BANK_COMMAND
67
+
68
+ `input` references a Data that is an input of the target calc — the system runs the calc(s) that data feeds into. It does NOT reference the DataCalculation itself.
69
+
70
+ - **Manual calc**: ANY input works — `trigger` flags are ignored for manual-mode calcs.
71
+ - **Auto calc**: only `trigger: true` inputs work; commanding a `trigger: false` input is a silent no-op.
72
+
73
+ ```typescript
74
+ const triggerCalc: EventAction = {
75
+ handler: 'system',
76
+ action: {
77
+ __actionName: 'PROPERTY_BANK_COMMAND',
78
+ parent: 'System',
79
+ dataParams: [
80
+ { input: () => priceData }, // Reference to an input Data of the calc
81
+ ],
82
+ },
83
+ }
84
+ ```
85
+
86
+ - When the same chain **writes a calc input first** (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).
87
+ - When a **later action reads the calc's outputs**, set `waitAsync: true` on the `PROPERTY_BANK_COMMAND` action itself — it awaits the full calc chain including output writes.
88
+ - A dataParam's `value` acts as an execution gate: `{ input: () => d, value: false }` skips that trigger (combine with `mapping` for conditional runs).
89
+
90
+ ## Script Sandbox
91
+
92
+ Scripts run in `use strict` mode as a function body — top-level `return` returns the calc result. No `fetch`, `XMLHttpRequest`, or `require` in any mode: I/O belongs to Generators.
93
+
94
+ ### Built-in Globals
95
+
96
+ | Global | Description |
97
+ |--------|-------------|
98
+ | `inputs` | Object with input values (keyed by input `key`) |
99
+ | `console` | `{ log, error, warn, info }` — output is only visible in DevTools debug sessions; production is a no-op |
100
+ | `Platform` | `{ OS, isTV, isPad, isVision, isElectron }` |
101
+ | `TextEncoder`, `TextDecoder` | Text encoding/decoding |
102
+ | `Buffer` | Node.js Buffer (without `allocUnsafe`/`allocUnsafeSlow`) |
103
+ | `btoa`, `atob` | Base64 encoding/decoding |
104
+
105
+ ### Async Mode
106
+
107
+ Sync mode (default) has **no `Promise`, timers, or `await`**. Enable `enableAsync: true` to unlock:
108
+
109
+ - `Promise`, `setTimeout`, `setInterval`, `setImmediate`, `clearTimeout`, `clearInterval`, `clearImmediate`, `requestAnimationFrame`
110
+ - Full lodash (sync mode omits `debounce`, `delay`, `defer`)
111
+ - `await` at the top level of the script
112
+
113
+ ```typescript
114
+ code: `
115
+ const result = await new Promise((resolve) => {
116
+ setTimeout(() => resolve(inputs.value * 2), 100)
117
+ })
118
+ return result
119
+ `,
120
+ enableAsync: true,
121
+ ```
122
+
123
+ ### Runtime Environment
124
+
125
+ | Platform | Engine |
126
+ |----------|--------|
127
+ | Android | Hermes engine sandbox |
128
+ | iOS | JavaScriptCore sandbox |
129
+ | Electron desktop | Web Worker (V8) |
130
+ | Web preview / Simulator | Web Worker (V8) |
131
+
132
+ Simulator (Path 1) runs scripts on V8 while devices run Hermes/JSC — engine-sensitive code (date parsing, Intl, regex features) can pass in the Simulator and fail on device.
133
+
134
+ ### Available Libraries
135
+
136
+ All exposed as globals. No network/file-download capability in any of them.
137
+
138
+ | Global | Library | Notes |
139
+ |--------|---------|-------|
140
+ | `_`, `lodash` | lodash | Sync mode omits `debounce`/`delay`/`defer` |
141
+ | `voca` | voca | String manipulation |
142
+ | `invariant` | invariant | Assertions |
143
+ | `json5` | json5 | JSON5 parsing |
144
+ | `qs` | qs | Query string parsing |
145
+ | `url` | node-url | URL parsing |
146
+ | `bytes` | bytes | Byte parsing/formatting |
147
+ | `ms` | ms | Millisecond conversion |
148
+ | `base45` | base45 | Base45 encoding |
149
+ | `iconv` | iconv-lite | Character encoding |
150
+ | `math`, `mathjs` | mathjs | Math library |
151
+ | `chroma` | chroma-js | Color manipulation |
152
+ | `moment` | moment | Date/time; auto parseFormat for string args |
153
+ | `nanoid` | nanoid | Unique ID generation |
154
+ | `md5` | md5 | MD5 hashing |
155
+ | `crypto` | crypto-browserify | Crypto functions |
156
+ | `kjurJWS` | jsrsasign | JWT/JWS signing (`KJUR.jws.JWS`) |
157
+ | `coseVerify` | cose-js | COSE verification (sync) |
158
+ | `fflate` | fflate | `{ zlibSync, unzlibSync, gzipSync, gunzipSync, compressSync, decompressSync, strFromU8 }` |
159
+ | `cbor` | cbor | `{ encode, decode, decodeFirstSync, decodeAllSync, addSemanticType }` |
160
+ | `fs` | (in-repo fs-compat) | File system; no download/upload methods |
161
+ | `parseDocument` | officeparser (in-repo fork) | Office document parsing (async) |
162
+ | `TurndownService` | turndown | HTML to Markdown |
163
+ | `OpenCC` | opencc-js | Chinese conversion `{ Converter, ConverterFactory, CustomConverter, Locale }` |
164
+ | `TOON` | @toon-format/toon | TOON format parsing |
165
+
166
+ ## Recipes
167
+
168
+ ### Multiple Outputs
169
+
170
+ Return an object; each `outputs` entry extracts its `key`:
171
+
172
+ ```typescript
173
+ outputs: [
174
+ { key: 'total', data: () => totalData },
175
+ { key: 'tax', data: () => taxData },
176
+ { key: 'subtotal', data: () => subtotalData },
177
+ ],
178
+ output: null,
179
+ error: null,
180
+ code: `
181
+ const subtotal = inputs.price * inputs.quantity
182
+ const tax = subtotal * 0.1
183
+ const total = subtotal + tax
184
+ return { total, tax, subtotal }
185
+ `,
186
+ ```
187
+
188
+ ### Manual Self-Referential Update
189
+
190
+ When an update is too complex for `PROPERTY_BANK_EXPRESSION` and must read its own previous value — manual mode allows the same Data as input and output:
191
+
192
+ ```typescript
193
+ const appendHistory: DataCalculationScript = {
194
+ __typename: 'DataCalculationScript',
195
+ id: makeId('property_bank_calc'),
196
+ title: 'Append History Entry',
197
+ triggerMode: 'manual',
198
+ enableAsync: false,
199
+ code: `
200
+ const history = Array.isArray(inputs.history) ? inputs.history : []
201
+ return [...history, { entry: inputs.entry, at: moment().toISOString() }].slice(-50)
202
+ `,
203
+ inputs: [
204
+ { key: 'history', data: () => historyData, trigger: true },
205
+ { key: 'entry', data: () => entryData, trigger: true },
206
+ ],
207
+ output: () => historyData, // same Data as input — manual mode only
208
+ outputs: [],
209
+ error: null,
210
+ }
211
+ // Run it from an event chain: PROPERTY_BANK writes entryData (waitAsync: true),
212
+ // then PROPERTY_BANK_COMMAND with input: () => entryData.
213
+ ```
214
+
215
+ ## Failure Modes
216
+
217
+ | Symptom | Cause | Fix |
218
+ |---------|-------|-----|
219
+ | Calc never auto-runs | `trigger` omitted on inputs (defaults to `false`) | Set `trigger: true` explicitly |
220
+ | `PROPERTY_BANK_COMMAND` does nothing | Auto calc + `trigger: false` input, or `input` doesn't reference an input Data of the calc | Command a `trigger: true` input (auto) or any input (manual) |
221
+ | Compile error `Not allow duplicate set property id...` | Auto mode with same Data as input and output | Use `triggerMode: 'manual'`, or split into separate Data |
222
+ | Calc reads stale value written earlier in the same chain | Missing `waitAsync: true` on the preceding write | Set `waitAsync: true` on the write action |
223
+ | Works in Simulator, fails on device | V8 vs Hermes/JSC engine difference | Verify on device (Path 2); avoid engine-sensitive parsing |
224
+ | `console.log` shows nothing | Console only emits during DevTools debug sessions | Attach DevTools, or write debug values to an output Data |
225
+ | `Promise`/`setTimeout` undefined, or `Async mode is required` error | `enableAsync: false` | Set `enableAsync: true` |
226
+
227
+ ## Best Practices
228
+
229
+ 1. **Avoid circular deps**: Set non-triggering inputs (`trigger: false`) or use `manual` mode
230
+ 2. **Error handling**: Always set `error` output for scripts that might fail
231
+ 3. **Keep scripts pure**: Avoid side effects, return computed values
232
+ 4. **Debounce rapid updates**: Use `manual` mode + timer for high-frequency inputs (auto calcs re-run on every write, even unchanged)
233
+
234
+ ## Anti-Patterns (AVOID)
235
+
236
+ See [Architecture Patterns](architecture-patterns.md) for the full pattern selection guide.
237
+
238
+ ### Using Data Calc as an orchestrator
239
+ 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).