@fugood/bricks-ctor 2.25.0-beta.60 → 2.25.0-beta.61

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 (190) hide show
  1. package/package.json +4 -28
  2. package/tools/deploy.ts +19 -176
  3. package/tools/mcp-server.ts +16 -33
  4. package/tools/postinstall.ts +21 -292
  5. package/tools/pull.ts +15 -195
  6. package/tools/push-config.ts +18 -113
  7. package/tools/simulator.ts +19 -148
  8. package/compile/__tests__/config-diff.test.js +0 -100
  9. package/compile/__tests__/index.test.js +0 -461
  10. package/compile/__tests__/util.test.js +0 -450
  11. package/compile/action-name-map.ts +0 -1079
  12. package/compile/config-diff.ts +0 -155
  13. package/compile/index.ts +0 -1594
  14. package/compile/util.ts +0 -482
  15. package/index.ts +0 -6
  16. package/skills/bricks-ctor/SKILL.md +0 -38
  17. package/skills/bricks-ctor/references/animation.md +0 -160
  18. package/skills/bricks-ctor/references/architecture-patterns.md +0 -88
  19. package/skills/bricks-ctor/references/automations.md +0 -232
  20. package/skills/bricks-ctor/references/buttress.md +0 -245
  21. package/skills/bricks-ctor/references/data-calculation.md +0 -252
  22. package/skills/bricks-ctor/references/local-sync.md +0 -129
  23. package/skills/bricks-ctor/references/media-flow.md +0 -165
  24. package/skills/bricks-ctor/references/remote-data-bank.md +0 -196
  25. package/skills/bricks-ctor/references/simulator.md +0 -132
  26. package/skills/bricks-ctor/references/source-editing-tools.md +0 -81
  27. package/skills/bricks-ctor/references/standby-transition.md +0 -124
  28. package/skills/bricks-ctor/references/verification-toolchain.md +0 -200
  29. package/skills/bricks-design/SKILL.md +0 -171
  30. package/skills/bricks-design/references/architecture-truths.md +0 -132
  31. package/skills/bricks-design/references/avoiding-complexity.md +0 -91
  32. package/skills/bricks-design/references/design-critique.md +0 -195
  33. package/skills/bricks-design/references/design-languages.md +0 -265
  34. package/skills/bricks-design/references/performance.md +0 -116
  35. package/skills/bricks-design/references/presentation-and-slideshow.md +0 -137
  36. package/skills/bricks-design/references/translating-inputs.md +0 -152
  37. package/skills/bricks-design/references/variations-and-tweaks.md +0 -124
  38. package/skills/bricks-design/references/when-the-brief-is-branded.md +0 -284
  39. package/skills/bricks-design/references/when-the-brief-is-vague.md +0 -85
  40. package/skills/bricks-design/references/workflow.md +0 -134
  41. package/skills/bricks-ux/SKILL.md +0 -114
  42. package/skills/bricks-ux/references/accessibility.md +0 -162
  43. package/skills/bricks-ux/references/flow-states.md +0 -175
  44. package/skills/bricks-ux/references/interaction-archetypes.md +0 -189
  45. package/skills/bricks-ux/references/monitoring-screens.md +0 -153
  46. package/skills/bricks-ux/references/pressable-composition.md +0 -126
  47. package/skills/bricks-ux/references/user-journey.md +0 -168
  48. package/skills/bricks-ux/references/ux-critique.md +0 -256
  49. package/skills/rive-marketplace/SKILL.md +0 -99
  50. package/tools/__tests__/_cli-error.test.ts +0 -35
  51. package/tools/__tests__/_mcp-config.test.ts +0 -67
  52. package/tools/__tests__/pull.test.ts +0 -108
  53. package/tools/_cli-error.ts +0 -17
  54. package/tools/_edits-log.ts +0 -41
  55. package/tools/_git-author.ts +0 -37
  56. package/tools/_last-pushed-commit.ts +0 -28
  57. package/tools/_mcp-config.ts +0 -42
  58. package/tools/_shell.ts +0 -180
  59. package/tools/icons/.gitattributes +0 -1
  60. package/tools/icons/fa6pro-glyphmap.json +0 -4686
  61. package/tools/icons/fa6pro-meta.json +0 -1
  62. package/tools/mcp-env.ts +0 -13
  63. package/tools/mcp-tools/__tests__/data-calc-editing.test.js +0 -516
  64. package/tools/mcp-tools/__tests__/entry-editing.test.js +0 -866
  65. package/tools/mcp-tools/__tests__/huggingface.test.ts +0 -49
  66. package/tools/mcp-tools/__tests__/icons.test.ts +0 -21
  67. package/tools/mcp-tools/__tests__/mcp-env.test.js +0 -19
  68. package/tools/mcp-tools/_editing-helpers.ts +0 -98
  69. package/tools/mcp-tools/_verify.ts +0 -50
  70. package/tools/mcp-tools/compile.ts +0 -104
  71. package/tools/mcp-tools/data-calc-editing.ts +0 -1311
  72. package/tools/mcp-tools/entry-editing.ts +0 -2297
  73. package/tools/mcp-tools/huggingface.ts +0 -772
  74. package/tools/mcp-tools/icons.ts +0 -97
  75. package/tools/mcp-tools/lottie.ts +0 -102
  76. package/tools/mcp-tools/media.ts +0 -113
  77. package/tools/simulator-main.mjs +0 -488
  78. package/tools/simulator-preload.cjs +0 -16
  79. package/types/animation.d.ts +0 -116
  80. package/types/automation.d.ts +0 -231
  81. package/types/brick-base.d.ts +0 -80
  82. package/types/bricks/Camera.d.ts +0 -246
  83. package/types/bricks/Chart.d.ts +0 -372
  84. package/types/bricks/GenerativeMedia.d.ts +0 -290
  85. package/types/bricks/Icon.d.ts +0 -98
  86. package/types/bricks/Image.d.ts +0 -126
  87. package/types/bricks/Items.d.ts +0 -480
  88. package/types/bricks/Lottie.d.ts +0 -168
  89. package/types/bricks/Maps.d.ts +0 -262
  90. package/types/bricks/QrCode.d.ts +0 -117
  91. package/types/bricks/Rect.d.ts +0 -150
  92. package/types/bricks/RichText.d.ts +0 -131
  93. package/types/bricks/Rive.d.ts +0 -220
  94. package/types/bricks/Scene3D.d.ts +0 -676
  95. package/types/bricks/Sketch.d.ts +0 -256
  96. package/types/bricks/Slideshow.d.ts +0 -201
  97. package/types/bricks/Svg.d.ts +0 -99
  98. package/types/bricks/Text.d.ts +0 -148
  99. package/types/bricks/TextInput.d.ts +0 -242
  100. package/types/bricks/Video.d.ts +0 -242
  101. package/types/bricks/VideoStreaming.d.ts +0 -112
  102. package/types/bricks/WebRtcStream.d.ts +0 -65
  103. package/types/bricks/WebView.d.ts +0 -168
  104. package/types/bricks/index.d.ts +0 -23
  105. package/types/canvas.d.ts +0 -82
  106. package/types/common.d.ts +0 -141
  107. package/types/data-calc-command/base.d.ts +0 -57
  108. package/types/data-calc-command/collection.d.ts +0 -418
  109. package/types/data-calc-command/color.d.ts +0 -432
  110. package/types/data-calc-command/constant.d.ts +0 -50
  111. package/types/data-calc-command/datetime.d.ts +0 -147
  112. package/types/data-calc-command/file.d.ts +0 -129
  113. package/types/data-calc-command/index.d.ts +0 -13
  114. package/types/data-calc-command/iteratee.d.ts +0 -23
  115. package/types/data-calc-command/logictype.d.ts +0 -190
  116. package/types/data-calc-command/math.d.ts +0 -275
  117. package/types/data-calc-command/object.d.ts +0 -119
  118. package/types/data-calc-command/sandbox.d.ts +0 -66
  119. package/types/data-calc-command/string.d.ts +0 -407
  120. package/types/data-calc-script.d.ts +0 -21
  121. package/types/data-calc.d.ts +0 -12
  122. package/types/data.d.ts +0 -97
  123. package/types/generators/AlarmClock.d.ts +0 -110
  124. package/types/generators/Assistant.d.ts +0 -640
  125. package/types/generators/BleCentral.d.ts +0 -247
  126. package/types/generators/BlePeripheral.d.ts +0 -208
  127. package/types/generators/CanvasMap.d.ts +0 -74
  128. package/types/generators/CastlesPay.d.ts +0 -87
  129. package/types/generators/DataBank.d.ts +0 -160
  130. package/types/generators/File.d.ts +0 -432
  131. package/types/generators/GraphQl.d.ts +0 -132
  132. package/types/generators/Http.d.ts +0 -222
  133. package/types/generators/HttpServer.d.ts +0 -230
  134. package/types/generators/Information.d.ts +0 -103
  135. package/types/generators/Intent.d.ts +0 -168
  136. package/types/generators/Iterator.d.ts +0 -108
  137. package/types/generators/Keyboard.d.ts +0 -105
  138. package/types/generators/LlmAnthropicCompat.d.ts +0 -212
  139. package/types/generators/LlmAppleBuiltin.d.ts +0 -159
  140. package/types/generators/LlmGgml.d.ts +0 -903
  141. package/types/generators/LlmMediaTekNeuroPilot.d.ts +0 -235
  142. package/types/generators/LlmMlx.d.ts +0 -228
  143. package/types/generators/LlmOnnx.d.ts +0 -213
  144. package/types/generators/LlmOpenAiCompat.d.ts +0 -312
  145. package/types/generators/LlmQualcommAiEngine.d.ts +0 -247
  146. package/types/generators/Mcp.d.ts +0 -637
  147. package/types/generators/McpServer.d.ts +0 -289
  148. package/types/generators/MediaFlow.d.ts +0 -170
  149. package/types/generators/MqttBroker.d.ts +0 -141
  150. package/types/generators/MqttClient.d.ts +0 -141
  151. package/types/generators/Question.d.ts +0 -408
  152. package/types/generators/RealtimeTranscription.d.ts +0 -287
  153. package/types/generators/RerankerGgml.d.ts +0 -195
  154. package/types/generators/SerialPort.d.ts +0 -151
  155. package/types/generators/SoundPlayer.d.ts +0 -94
  156. package/types/generators/SoundRecorder.d.ts +0 -139
  157. package/types/generators/SpeechToTextGgml.d.ts +0 -424
  158. package/types/generators/SpeechToTextOnnx.d.ts +0 -236
  159. package/types/generators/SpeechToTextPlatform.d.ts +0 -85
  160. package/types/generators/SqLite.d.ts +0 -159
  161. package/types/generators/Step.d.ts +0 -107
  162. package/types/generators/SttAppleBuiltin.d.ts +0 -153
  163. package/types/generators/Tcp.d.ts +0 -126
  164. package/types/generators/TcpServer.d.ts +0 -147
  165. package/types/generators/TextToSpeechAppleBuiltin.d.ts +0 -127
  166. package/types/generators/TextToSpeechGgml.d.ts +0 -221
  167. package/types/generators/TextToSpeechOnnx.d.ts +0 -178
  168. package/types/generators/TextToSpeechOpenAiLike.d.ts +0 -121
  169. package/types/generators/ThermalPrinter.d.ts +0 -193
  170. package/types/generators/Tick.d.ts +0 -83
  171. package/types/generators/Udp.d.ts +0 -120
  172. package/types/generators/VadGgml.d.ts +0 -260
  173. package/types/generators/VadOnnx.d.ts +0 -231
  174. package/types/generators/VadTraditional.d.ts +0 -138
  175. package/types/generators/VectorStore.d.ts +0 -257
  176. package/types/generators/Watchdog.d.ts +0 -107
  177. package/types/generators/WebCrawler.d.ts +0 -103
  178. package/types/generators/WebRtc.d.ts +0 -181
  179. package/types/generators/WebSocket.d.ts +0 -148
  180. package/types/generators/index.d.ts +0 -57
  181. package/types/index.d.ts +0 -13
  182. package/types/subspace.d.ts +0 -60
  183. package/types/switch.d.ts +0 -51
  184. package/types/system.d.ts +0 -707
  185. package/utils/__tests__/calc.test.js +0 -25
  186. package/utils/__tests__/id.test.js +0 -154
  187. package/utils/calc.ts +0 -130
  188. package/utils/data.ts +0 -495
  189. package/utils/event-props.ts +0 -912
  190. package/utils/id.ts +0 -133
@@ -1,866 +0,0 @@
1
- import { mkdtemp, mkdir, readFile, rm, writeFile } from 'node:fs/promises'
2
- import os from 'node:os'
3
- import path from 'node:path'
4
-
5
- jest.mock('oxfmt', () => ({
6
- format: async (_file, source) => ({ code: source, errors: [] }),
7
- }))
8
-
9
- import { register, __test__ } from '../entry-editing'
10
-
11
- const writeFixtureProject = async () => {
12
- const projectDir = await mkdtemp(path.join(os.tmpdir(), 'bricks-entry-editing-'))
13
- const subspaceDir = path.join(projectDir, 'subspaces/subspace-0')
14
- await mkdir(subspaceDir, { recursive: true })
15
- await writeFile(
16
- path.join(subspaceDir, 'data.ts'),
17
- `import type { Data } from 'bricks-ctor'
18
- import { makeId } from 'bricks-ctor'
19
-
20
- export const dMessage: Data = {
21
- __typename: 'Data',
22
- id: makeId('data'),
23
- alias: 'message',
24
- title: 'Message',
25
- type: 'string',
26
- schema: {},
27
- events: {},
28
- value: 'Hello',
29
- }
30
-
31
- export const dCount: Data = {
32
- __typename: 'Data',
33
- id: makeId('data'),
34
- alias: 'count',
35
- title: 'Count',
36
- type: 'number',
37
- schema: {},
38
- events: {},
39
- value: 0,
40
- }
41
- `,
42
- )
43
- await writeFile(
44
- path.join(subspaceDir, 'bricks.ts'),
45
- `import type { BrickText } from 'bricks-ctor'
46
- import { linkData, makeId } from 'bricks-ctor'
47
- import * as data from './data'
48
-
49
- export const bWelcome: BrickText = {
50
- __typename: 'Brick',
51
- id: makeId('brick'),
52
- alias: 'welcome',
53
- templateKey: 'BRICK_TEXT',
54
- title: 'Welcome',
55
- property: {
56
- text: 'Hello',
57
- source: linkData(() => data.dMessage),
58
- },
59
- events: {},
60
- outlets: {
61
- response: () => data.dMessage,
62
- },
63
- animation: {},
64
- switches: [
65
- {
66
- id: makeId('switch'),
67
- title: 'When message matches',
68
- conds: [
69
- {
70
- method: '==',
71
- cond: {
72
- __typename: 'SwitchCondData',
73
- data: () => data.dMessage,
74
- value: 'Hello',
75
- },
76
- },
77
- ],
78
- property: {},
79
- events: {},
80
- outlets: {},
81
- animation: {},
82
- },
83
- ],
84
- }
85
-
86
- export const bButton: BrickText = {
87
- __typename: 'Brick',
88
- id: makeId('brick'),
89
- alias: 'button',
90
- templateKey: 'BRICK_TEXT',
91
- title: 'Button',
92
- property: {},
93
- events: {},
94
- outlets: {},
95
- animation: {},
96
- switches: [],
97
- }
98
- `,
99
- )
100
- await writeFile(
101
- path.join(subspaceDir, 'canvases.ts'),
102
- `import type { Canvas } from 'bricks-ctor'
103
- import { makeId } from 'bricks-ctor'
104
-
105
- export const cMain: Canvas = {
106
- __typename: 'Canvas',
107
- id: makeId('canvas'),
108
- alias: 'main',
109
- title: 'Main',
110
- property: {},
111
- events: {},
112
- switches: [],
113
- items: [],
114
- }
115
- `,
116
- )
117
- await writeFile(
118
- path.join(subspaceDir, 'generators.ts'),
119
- `import type { GeneratorHTTP } from 'bricks-ctor'
120
- import { makeId } from 'bricks-ctor'
121
-
122
- export const gApi: GeneratorHTTP = {
123
- __typename: 'Generator',
124
- id: makeId('generator'),
125
- alias: 'api',
126
- templateKey: 'GENERATOR_HTTP',
127
- title: 'API',
128
- property: {},
129
- events: {},
130
- outlets: {},
131
- switches: [],
132
- }
133
- `,
134
- )
135
- await writeFile(
136
- path.join(subspaceDir, 'animations.ts'),
137
- `import type { Animation } from 'bricks-ctor'
138
- import { makeId } from 'bricks-ctor'
139
-
140
- export const aFade: Animation = {
141
- __typename: 'Animation',
142
- id: makeId('animation'),
143
- alias: 'fade',
144
- title: 'Fade',
145
- runType: 'once',
146
- property: 'opacity',
147
- config: {
148
- __type: 'AnimationTimingConfig',
149
- toValue: 1,
150
- duration: 300,
151
- easing: '',
152
- delay: 0,
153
- isInteraction: true,
154
- },
155
- }
156
- `,
157
- )
158
- return projectDir
159
- }
160
-
161
- const readProjectFile = (projectDir, relPath) => readFile(path.join(projectDir, relPath), 'utf8')
162
-
163
- const readAudit = async (projectDir) =>
164
- (await readFile(path.join(projectDir, '.bricks/edits.jsonl'), 'utf8'))
165
- .trim()
166
- .split('\n')
167
- .map((line) => JSON.parse(line))
168
-
169
- describe('ctor MCP entry-editing tools', () => {
170
- let projectDir
171
-
172
- afterEach(async () => {
173
- if (projectDir) await rm(projectDir, { recursive: true, force: true })
174
- projectDir = null
175
- })
176
-
177
- test('registers the six entry-editing MCP tools', () => {
178
- const calls = []
179
- register(
180
- {
181
- tool(...args) {
182
- calls.push(args)
183
- },
184
- },
185
- '/tmp/project',
186
- )
187
-
188
- expect(calls.map(([name]) => name)).toEqual([
189
- 'edit_entry',
190
- 'edit_events',
191
- 'edit_canvas_items',
192
- 'edit_switches',
193
- 'new_entry',
194
- 'remove_entry',
195
- ])
196
- expect(
197
- calls.every(([, description]) => typeof description === 'string' && description.length > 20),
198
- ).toBe(true)
199
- const editEntrySchema = calls[0][2]
200
- expect(editEntrySchema.file.description).toContain('Project-relative')
201
- expect(editEntrySchema.set.description).toContain('dotted paths')
202
- expect(editEntrySchema.set.description).toContain('{ link')
203
- })
204
-
205
- test('edit_entry updates nested facets and resolves link/ref values', async () => {
206
- projectDir = await writeFixtureProject()
207
-
208
- const result = await __test__.editEntry(projectDir, {
209
- file: 'subspaces/subspace-0/bricks.ts',
210
- entry: 'bWelcome',
211
- set: {
212
- title: 'Updated Welcome',
213
- 'property.text': 'Hi',
214
- 'property.count': { link: 'count' },
215
- 'outlets.count': { ref: 'count' },
216
- },
217
- verify: false,
218
- })
219
-
220
- expect(result.outcome).toBe('ok')
221
- const source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
222
- expect(source).toMatch(/title: ['"]Updated Welcome['"]/)
223
- expect(source).toMatch(/text: ['"]Hi['"]/)
224
- expect(source).toContain('count: linkData(() => data.dCount)')
225
- expect(source).toContain('count: () => data.dCount')
226
- const audit = await readAudit(projectDir)
227
- expect(audit.at(-1).summary).toContain('edited bWelcome')
228
- const gitignore = await readProjectFile(projectDir, '.gitignore')
229
- expect(gitignore).toContain('.bricks/edits.jsonl')
230
- })
231
-
232
- test('edit_entry removes the correct elements when unsetting multiple array indices', async () => {
233
- // Regression: unset paths were applied in input order, but unsetPathValue
234
- // splices arrays in place — removing items[1] shifts items[2] down, so the
235
- // second unset hit the wrong element (or no-op'd). Both requested elements
236
- // must be removed regardless of order.
237
- projectDir = await writeFixtureProject()
238
- const target = { file: 'subspaces/subspace-0/bricks.ts', entry: 'bButton', verify: false }
239
-
240
- const built = await __test__.editEntry(projectDir, {
241
- ...target,
242
- set: {
243
- 'property.list[0]': 'ITEM_A',
244
- 'property.list[1]': 'ITEM_B',
245
- 'property.list[2]': 'ITEM_C',
246
- },
247
- })
248
- expect(built.outcome).toBe('ok')
249
-
250
- const unset = await __test__.editEntry(projectDir, {
251
- ...target,
252
- unset: ['property.list[1]', 'property.list[2]'],
253
- })
254
- expect(unset.outcome).toBe('ok')
255
-
256
- const source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
257
- expect(source).toContain('ITEM_A')
258
- expect(source).not.toContain('ITEM_B') // items[1] removed
259
- expect(source).not.toContain('ITEM_C') // items[2] removed (survived before the fix)
260
- })
261
-
262
- test('edit_events adds a typed system event action', async () => {
263
- projectDir = await writeFixtureProject()
264
-
265
- const result = await __test__.editEvents(projectDir, {
266
- file: 'subspaces/subspace-0/bricks.ts',
267
- entry: 'bButton',
268
- event: 'onPress',
269
- op: 'add',
270
- action: {
271
- handler: 'system',
272
- name: 'CHANGE_CANVAS',
273
- params: {
274
- canvasId: { ref: 'main' },
275
- },
276
- },
277
- verify: false,
278
- })
279
-
280
- expect(result.outcome).toBe('ok')
281
- const source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
282
- expect(source).toContain('SystemActionChangeCanvas')
283
- expect(source).toMatch(/handler: ['"]system['"]/)
284
- expect(source).toMatch(/__actionName: ['"]CHANGE_CANVAS['"]/)
285
- expect(source).toContain('value: () => canvases.cMain')
286
- expect(source).toMatch(/import \* as canvases from ['"]\.\/canvases['"]/)
287
- })
288
-
289
- test('edit_canvas_items places a brick on a canvas', async () => {
290
- projectDir = await writeFixtureProject()
291
-
292
- const result = await __test__.editCanvasItems(projectDir, {
293
- file: 'subspaces/subspace-0/canvases.ts',
294
- entry: 'cMain',
295
- op: 'add',
296
- item: {
297
- ref: 'welcome',
298
- frame: { x: 1, y: 2, width: 10, height: 5 },
299
- },
300
- verify: false,
301
- })
302
-
303
- expect(result.outcome).toBe('ok')
304
- const source = await readProjectFile(projectDir, 'subspaces/subspace-0/canvases.ts')
305
- expect(source).toMatch(/import \* as bricks from ['"]\.\/bricks['"]/)
306
- expect(source).toContain('item: () => bricks.bWelcome')
307
- expect(source).toContain('width: 10')
308
- })
309
-
310
- test('edit_switches adds a switch with a data condition', async () => {
311
- projectDir = await writeFixtureProject()
312
-
313
- const result = await __test__.editSwitches(projectDir, {
314
- file: 'subspaces/subspace-0/bricks.ts',
315
- entry: 'bButton',
316
- op: 'add',
317
- switch: {
318
- title: 'Count positive',
319
- conds: [
320
- {
321
- method: '>',
322
- cond: {
323
- type: 'property_bank',
324
- ref: 'count',
325
- value: 0,
326
- },
327
- },
328
- ],
329
- override: { property: true },
330
- },
331
- verify: false,
332
- })
333
-
334
- expect(result.outcome).toBe('ok')
335
- const source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
336
- expect(source).toMatch(/title: ['"]Count positive['"]/)
337
- expect(source).toMatch(/__typename: ['"]SwitchCondData['"]/)
338
- expect(source).toContain('data: () => data.dCount')
339
- expect(source).toMatch(/override:\s*{\s*property: true\s*}/)
340
- expect((source.match(/id:\s*makeId\(['"]switch['"]\)/g) || []).length).toBe(2)
341
- })
342
-
343
- test('new_entry creates a standard skeleton and applies initial values', async () => {
344
- projectDir = await writeFixtureProject()
345
-
346
- const result = await __test__.newEntry(projectDir, {
347
- file: 'subspaces/subspace-0/generators.ts',
348
- type: 'GeneratorHTTP',
349
- templateKey: 'GENERATOR_HTTP',
350
- alias: 'weatherApi',
351
- title: 'Weather API',
352
- set: {
353
- 'property.url': 'https://api.example.test',
354
- },
355
- verify: false,
356
- })
357
-
358
- expect(result.outcome).toBe('ok')
359
- expect(result.entry).toBe('weatherApi')
360
- const source = await readProjectFile(projectDir, 'subspaces/subspace-0/generators.ts')
361
- expect(source).toContain('export const weatherApi: GeneratorHTTP =')
362
- expect(source).toMatch(/id: makeId\(['"]generator['"], ['"]weatherApi['"]\)/)
363
- expect(source).toMatch(/templateKey: ['"]GENERATOR_HTTP['"]/)
364
- expect(source).toMatch(/url: ['"]https:\/\/api\.example\.test['"]/)
365
- })
366
-
367
- test('new_entry can be retried with the same alias in one server session', async () => {
368
- projectDir = await writeFixtureProject()
369
-
370
- const first = await __test__.newEntry(projectDir, {
371
- file: 'subspaces/subspace-0/generators.ts',
372
- type: 'GeneratorHTTP',
373
- templateKey: 'GENERATOR_HTTP',
374
- alias: 'retryApi',
375
- verify: false,
376
- })
377
- const second = await __test__.newEntry(projectDir, {
378
- file: 'subspaces/subspace-0/generators.ts',
379
- type: 'GeneratorHTTP',
380
- templateKey: 'GENERATOR_HTTP',
381
- alias: 'retryApi',
382
- verify: false,
383
- })
384
-
385
- expect(first.outcome).toBe('ok')
386
- expect(second.outcome).toBe('ok')
387
- expect(second.entry).toBe('retryApi1')
388
- expect(first.id).toBeUndefined()
389
- expect(second.id).toBeUndefined()
390
- // First use of the alias gets the order-stable aliased id; the duplicate falls
391
- // back to the counter form so compile does not hit a makeId alias collision.
392
- expect(first.idExpression).toBe("makeId('generator', 'retryApi')")
393
- expect(second.idExpression).toBe("makeId('generator')")
394
- const source = await readProjectFile(projectDir, 'subspaces/subspace-0/generators.ts')
395
- expect((source.match(/id:\s*makeId\(['"]generator['"]\)/g) || []).length).toBe(2)
396
- expect(source).toMatch(/makeId\(['"]generator['"], ['"]retryApi['"]\)/)
397
- })
398
-
399
- test('entry targeting falls back to entity aliases', async () => {
400
- projectDir = await writeFixtureProject()
401
-
402
- const result = await __test__.editEntry(projectDir, {
403
- file: 'subspaces/subspace-0/bricks.ts',
404
- entry: 'welcome',
405
- set: { title: 'Aliased Edit' },
406
- verify: false,
407
- })
408
-
409
- expect(result.outcome).toBe('ok')
410
- expect(result.entry).toBe('bWelcome')
411
- const source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
412
- expect(source).toMatch(/title: ['"]Aliased Edit['"]/)
413
- })
414
-
415
- test('parse failures tell the caller to use file tools', async () => {
416
- projectDir = await writeFixtureProject()
417
- await writeFile(path.join(projectDir, 'subspaces/subspace-0/bricks.ts'), 'export const =')
418
-
419
- const result = await __test__.editEntry(projectDir, {
420
- file: 'subspaces/subspace-0/bricks.ts',
421
- entry: 'bWelcome',
422
- set: { title: 'Nope' },
423
- verify: false,
424
- })
425
-
426
- expect(result.outcome).toBe('error')
427
- expect(result.isError).toBe(true)
428
- expect(result.error.message).toContain('Edit this file directly')
429
- })
430
-
431
- test('edit_events accepts the compiled EventAction shape, supports move, and casts stay editable', async () => {
432
- projectDir = await writeFixtureProject()
433
- const target = {
434
- file: 'subspaces/subspace-0/bricks.ts',
435
- entry: 'bButton',
436
- event: 'onPress',
437
- verify: false,
438
- }
439
-
440
- const added = await __test__.editEvents(projectDir, {
441
- ...target,
442
- op: 'add',
443
- action: { handler: 'system', name: 'CHANGE_CANVAS', params: { canvasId: { ref: 'main' } } },
444
- })
445
- expect(added.outcome).toBe('ok')
446
-
447
- // Replace using the compiled source shape ({ handler, action: {...}, waitAsync }).
448
- const replaced = await __test__.editEvents(projectDir, {
449
- ...target,
450
- op: 'replace',
451
- index: 0,
452
- action: {
453
- handler: 'system',
454
- action: {
455
- __actionName: 'PROPERTY_BANK',
456
- parent: 'System',
457
- name: 'PROPERTY_BANK',
458
- dataParams: [{ input: { ref: 'count' }, value: '1' }],
459
- },
460
- waitAsync: false,
461
- },
462
- })
463
- expect(replaced.outcome).toBe('ok')
464
- let source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
465
- expect(source).toMatch(/__actionName: ['"]PROPERTY_BANK['"]/)
466
- expect(source).toContain('input: () => data.dCount')
467
-
468
- // Deep edit_entry paths see through the `as SystemAction...` cast.
469
- const deepEdit = await __test__.editEntry(projectDir, {
470
- file: 'subspaces/subspace-0/bricks.ts',
471
- entry: 'bButton',
472
- set: { 'events.onPress[0].action.dataParams[0].value': '2' },
473
- verify: false,
474
- })
475
- expect(deepEdit.outcome).toBe('ok')
476
- source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
477
- expect(source).toMatch(/value: ['"]2['"]/)
478
- expect(source).toContain('as SystemActionPropertyBank')
479
-
480
- const addedSecond = await __test__.editEvents(projectDir, {
481
- ...target,
482
- op: 'add',
483
- action: { handler: 'system', name: 'CHANGE_CANVAS', params: { canvasId: { ref: 'main' } } },
484
- })
485
- expect(addedSecond.outcome).toBe('ok')
486
-
487
- const moved = await __test__.editEvents(projectDir, { ...target, op: 'move', index: 1, to: 0 })
488
- expect(moved.outcome).toBe('ok')
489
- source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
490
- expect(source.indexOf('CHANGE_CANVAS')).toBeLessThan(source.indexOf('PROPERTY_BANK'))
491
- })
492
-
493
- test('edit_canvas_items validates frames and accepts a top-level frame on add', async () => {
494
- projectDir = await writeFixtureProject()
495
- const target = { file: 'subspaces/subspace-0/canvases.ts', entry: 'cMain', verify: false }
496
-
497
- const missingFrame = await __test__.editCanvasItems(projectDir, {
498
- ...target,
499
- op: 'add',
500
- item: { ref: 'welcome' },
501
- })
502
- expect(missingFrame.outcome).toBe('error')
503
- expect(missingFrame.error.message).toContain('requires frame')
504
-
505
- const badFrame = await __test__.editCanvasItems(projectDir, {
506
- ...target,
507
- op: 'add',
508
- item: { ref: 'welcome', frame: { x: 1, y: 2, width: 10 } },
509
- })
510
- expect(badFrame.outcome).toBe('error')
511
- expect(badFrame.error.message).toContain('numeric height')
512
-
513
- const topLevelFrame = await __test__.editCanvasItems(projectDir, {
514
- ...target,
515
- op: 'add',
516
- item: { ref: 'welcome' },
517
- frame: { x: 1, y: 2, width: 10, height: 5 },
518
- })
519
- expect(topLevelFrame.outcome).toBe('ok')
520
- const source = await readProjectFile(projectDir, 'subspaces/subspace-0/canvases.ts')
521
- expect(source).toContain('item: () => bricks.bWelcome')
522
- expect(source).toContain('height: 5')
523
- })
524
-
525
- test('edit_canvas_items move requires a frame', async () => {
526
- projectDir = await writeFixtureProject()
527
-
528
- const result = await __test__.editCanvasItems(projectDir, {
529
- file: 'subspaces/subspace-0/canvases.ts',
530
- entry: 'cMain',
531
- op: 'move',
532
- index: 0,
533
- verify: false,
534
- })
535
-
536
- expect(result.outcome).toBe('error')
537
- expect(result.error.message).toContain('move requires frame')
538
- })
539
-
540
- test('inner-state outlet switch conditions require outlet or key', async () => {
541
- projectDir = await writeFixtureProject()
542
-
543
- const result = await __test__.editSwitches(projectDir, {
544
- file: 'subspaces/subspace-0/bricks.ts',
545
- entry: 'bButton',
546
- op: 'add',
547
- switch: {
548
- conds: [
549
- {
550
- cond: {
551
- type: 'inner_state',
552
- value: true,
553
- },
554
- },
555
- ],
556
- },
557
- verify: false,
558
- })
559
-
560
- expect(result.outcome).toBe('error')
561
- expect(result.error.message).toContain('requires outlet or key')
562
- })
563
-
564
- test('remove_entry cascades references and strict mode refuses referenced entries', async () => {
565
- projectDir = await writeFixtureProject()
566
-
567
- const strictResult = await __test__.removeEntry(projectDir, {
568
- file: 'subspaces/subspace-0/data.ts',
569
- entry: 'dMessage',
570
- strict: true,
571
- verify: false,
572
- })
573
- expect(strictResult.outcome).toBe('refused')
574
- expect(strictResult.touchedSites.length).toBeGreaterThan(0)
575
-
576
- const result = await __test__.removeEntry(projectDir, {
577
- file: 'subspaces/subspace-0/data.ts',
578
- entry: 'dMessage',
579
- verify: false,
580
- })
581
- expect(result.outcome).toBe('ok')
582
-
583
- const data = await readProjectFile(projectDir, 'subspaces/subspace-0/data.ts')
584
- const bricks = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
585
- expect(data).not.toContain('dMessage')
586
- expect(bricks).not.toContain('data.dMessage')
587
- expect(bricks).toContain('source: undefined')
588
- expect(bricks).not.toContain('response:')
589
- })
590
-
591
- test('remove_entry strict mode sees same-file references outside the target entry', async () => {
592
- projectDir = await writeFixtureProject()
593
- await __test__.editEntry(projectDir, {
594
- file: 'subspaces/subspace-0/bricks.ts',
595
- entry: 'bButton',
596
- set: {
597
- 'property.peer': { ref: 'welcome' },
598
- },
599
- verify: false,
600
- })
601
-
602
- const result = await __test__.removeEntry(projectDir, {
603
- file: 'subspaces/subspace-0/bricks.ts',
604
- entry: 'bWelcome',
605
- strict: true,
606
- verify: false,
607
- })
608
-
609
- expect(result.outcome).toBe('refused')
610
- expect(result.touchedSites.some((site) => site.file === 'subspaces/subspace-0/bricks.ts')).toBe(
611
- true,
612
- )
613
- })
614
-
615
- test('edit_events validates indices and drops emptied event keys', async () => {
616
- projectDir = await writeFixtureProject()
617
- const target = {
618
- file: 'subspaces/subspace-0/bricks.ts',
619
- entry: 'bButton',
620
- event: 'onPress',
621
- verify: false,
622
- }
623
-
624
- const added = await __test__.editEvents(projectDir, {
625
- ...target,
626
- op: 'add',
627
- action: { handler: 'system', name: 'CHANGE_CANVAS' },
628
- })
629
- expect(added.outcome).toBe('ok')
630
-
631
- const outOfRange = await __test__.editEvents(projectDir, { ...target, op: 'remove', index: 5 })
632
- expect(outOfRange.outcome).toBe('error')
633
- expect(outOfRange.error.message).toContain('remove index out of range')
634
-
635
- const removed = await __test__.editEvents(projectDir, { ...target, op: 'remove', index: 0 })
636
- expect(removed.outcome).toBe('ok')
637
- const source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
638
- expect(source).not.toContain('onPress')
639
-
640
- const cleared = await __test__.editEvents(projectDir, {
641
- ...target,
642
- event: 'neverExisted',
643
- op: 'clear',
644
- })
645
- expect(cleared.outcome).toBe('ok')
646
- const clearedSource = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
647
- expect(clearedSource).not.toContain('neverExisted')
648
- })
649
-
650
- test('edit_events validates PROPERTY_BANK_EXPRESSION against the runtime fold rules', async () => {
651
- projectDir = await writeFixtureProject()
652
- const target = {
653
- file: 'subspaces/subspace-0/bricks.ts',
654
- entry: 'bButton',
655
- event: 'onPress',
656
- op: 'add',
657
- verify: false,
658
- }
659
- const expressionAction = (expression) => ({
660
- handler: 'system',
661
- name: 'PROPERTY_BANK_EXPRESSION',
662
- params: { expression, variables: [], result: { expr: '() => data.dCount' } },
663
- })
664
-
665
- const ifStatement = await __test__.editEvents(projectDir, {
666
- ...target,
667
- action: expressionAction('if (count > 0) { count + 1 } else { 0 }'),
668
- })
669
- expect(ifStatement.outcome).toBe('error')
670
- expect(ifStatement.error.message).toContain('an if statement')
671
- expect(ifStatement.error.message).toContain('ternaries')
672
-
673
- const earlyReturn = await __test__.editEvents(projectDir, {
674
- ...target,
675
- action: expressionAction('(() => { if (count > 12) return count; return count + 1 })()'),
676
- })
677
- expect(earlyReturn.outcome).toBe('error')
678
-
679
- const iife = await __test__.editEvents(projectDir, {
680
- ...target,
681
- action: expressionAction(
682
- '(() => { const next = String(count); return next.length > 12 ? next.slice(0, 12) : next })()',
683
- ),
684
- })
685
- expect(iife.outcome).toBe('ok')
686
- })
687
-
688
- test('edit_events rejects non-brick/generator action handlers', async () => {
689
- projectDir = await writeFixtureProject()
690
-
691
- const result = await __test__.editEvents(projectDir, {
692
- file: 'subspaces/subspace-0/bricks.ts',
693
- entry: 'bButton',
694
- event: 'onPress',
695
- op: 'add',
696
- action: { handler: { ref: 'main' }, name: 'SHOW' },
697
- verify: false,
698
- })
699
-
700
- expect(result.outcome).toBe('error')
701
- expect(result.error.message).toContain('must be a brick or generator')
702
- })
703
-
704
- test('edit_switches accepts compiled __typename cond shapes and switch facets', async () => {
705
- projectDir = await writeFixtureProject()
706
-
707
- const result = await __test__.editSwitches(projectDir, {
708
- file: 'subspaces/subspace-0/bricks.ts',
709
- entry: 'bButton',
710
- op: 'add',
711
- switch: {
712
- title: 'Pressed shadow',
713
- conds: [
714
- {
715
- method: '==',
716
- cond: {
717
- __typename: 'SwitchCondInnerStateOutlet',
718
- outlet: 'brickPressing',
719
- value: true,
720
- },
721
- },
722
- ],
723
- property: { opacity: 0.92 },
724
- override: { property: false },
725
- },
726
- verify: false,
727
- })
728
-
729
- expect(result.outcome).toBe('ok')
730
- const source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
731
- expect(source).toMatch(/__typename: ['"]SwitchCondInnerStateOutlet['"]/)
732
- expect(source).toMatch(/outlet: ['"]brickPressing['"]/)
733
- expect(source).toMatch(/Pressed shadow[\s\S]*?property:\s*{\s*opacity: 0\.92\s*}/)
734
- })
735
-
736
- test('edit_switches validates explicit ids and rejects events/unknown fields', async () => {
737
- projectDir = await writeFixtureProject()
738
- const target = { file: 'subspaces/subspace-0/bricks.ts', entry: 'bButton', verify: false }
739
-
740
- const badId = await __test__.editSwitches(projectDir, {
741
- ...target,
742
- op: 'add',
743
- switch: { id: 'SWITCH_pressed_shadow' },
744
- })
745
- expect(badId.outcome).toBe('error')
746
- expect(badId.error.message).toContain('BRICK_STATE_GROUP_<uuid>')
747
-
748
- const events = await __test__.editSwitches(projectDir, {
749
- ...target,
750
- op: 'add',
751
- switch: { events: { onPress: [] } },
752
- })
753
- expect(events.outcome).toBe('error')
754
- expect(events.error.message).toContain('edit_events')
755
-
756
- const unknown = await __test__.editSwitches(projectDir, {
757
- ...target,
758
- op: 'add',
759
- switch: { titel: 'typo' },
760
- })
761
- expect(unknown.outcome).toBe('error')
762
- expect(unknown.error.message).toContain('Unknown switch field')
763
- expect(unknown.input).toBeDefined()
764
- })
765
-
766
- test('edit_switches move rejects out-of-range indices', async () => {
767
- projectDir = await writeFixtureProject()
768
-
769
- const result = await __test__.editSwitches(projectDir, {
770
- file: 'subspaces/subspace-0/bricks.ts',
771
- entry: 'bWelcome',
772
- op: 'move',
773
- index: 5,
774
- to: 0,
775
- verify: false,
776
- })
777
-
778
- expect(result.outcome).toBe('error')
779
- expect(result.error.message).toContain('valid switch id or index')
780
- })
781
-
782
- test('new_entry brick skeleton includes the animation facet', async () => {
783
- projectDir = await writeFixtureProject()
784
-
785
- const result = await __test__.newEntry(projectDir, {
786
- file: 'subspaces/subspace-0/bricks.ts',
787
- type: 'BrickText',
788
- templateKey: 'BRICK_TEXT',
789
- alias: 'newBrick',
790
- verify: false,
791
- })
792
-
793
- expect(result.outcome).toBe('ok')
794
- const source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
795
- expect(source).toMatch(/newBrick[\s\S]*animation: \{\}/)
796
- })
797
-
798
- test('remove_entry cleans data-calc IO references instead of breaking them', async () => {
799
- projectDir = await writeFixtureProject()
800
- const dataCalcDir = path.join(projectDir, 'subspaces/subspace-0/data-calc')
801
- await mkdir(dataCalcDir, { recursive: true })
802
- await writeFile(
803
- path.join(dataCalcDir, 'data-calculation-calc.ts'),
804
- `import type { DataCalculationScript } from 'bricks-ctor'
805
- import { makeId } from 'bricks-ctor'
806
- import * as data from '../data'
807
-
808
- export const dataCalculation: DataCalculationScript = {
809
- __typename: 'DataCalculationScript',
810
- id: makeId('property_bank_calc'),
811
- alias: 'calc',
812
- code: 'return inputs.message',
813
- enableAsync: false,
814
- inputs: [
815
- { key: 'message', data: () => data.dMessage, trigger: true },
816
- { key: 'count', data: () => data.dCount, trigger: true },
817
- ],
818
- output: () => data.dMessage,
819
- outputs: [{ key: 'copy', data: () => data.dMessage }],
820
- error: null,
821
- }
822
- `,
823
- )
824
-
825
- const result = await __test__.removeEntry(projectDir, {
826
- file: 'subspaces/subspace-0/data.ts',
827
- entry: 'dMessage',
828
- verify: false,
829
- })
830
-
831
- expect(result.outcome).toBe('ok')
832
- const calc = await readProjectFile(
833
- projectDir,
834
- 'subspaces/subspace-0/data-calc/data-calculation-calc.ts',
835
- )
836
- expect(calc).not.toContain('dMessage')
837
- expect(calc).toContain('output: null')
838
- expect(calc).toMatch(/key: ['"]count['"]/)
839
- expect(result.touchedSites.some((site) => site.action === 'remove_io_item')).toBe(true)
840
- expect(result.touchedSites.some((site) => site.action === 'null_output')).toBe(true)
841
- })
842
-
843
- test('non-standard entries return a fallback recommendation and are logged', async () => {
844
- projectDir = await writeFixtureProject()
845
- await writeFile(
846
- path.join(projectDir, 'subspaces/subspace-0/data.ts'),
847
- `import type { Data } from 'bricks-ctor'
848
- import { useSystemData } from 'bricks-ctor'
849
-
850
- export const dSystem: Data = useSystemData('currentTime')
851
- `,
852
- )
853
-
854
- const result = await __test__.editEntry(projectDir, {
855
- file: 'subspaces/subspace-0/data.ts',
856
- entry: 'dSystem',
857
- set: { title: 'Current Time' },
858
- verify: false,
859
- })
860
-
861
- expect(result.outcome).toBe('fallback_recommended')
862
- expect(result.error.message).toContain('not a top-level exported object literal')
863
- const audit = await readAudit(projectDir)
864
- expect(audit.at(-1).outcome).toBe('fallback_recommended')
865
- })
866
- })