@fugood/bricks-project 2.25.0-beta.42 → 2.25.0-beta.45

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.
@@ -0,0 +1,102 @@
1
+ import { readFile } from 'node:fs/promises'
2
+ import path from 'node:path'
3
+
4
+ // The compiled config artifact written by `bun compile` (see the generated
5
+ // project's `compile.ts`; bricks-project-generator/index.js:762).
6
+ export const BUILD_CONFIG_RELATIVE = '.bricks/build/application-config.json'
7
+
8
+ // `compile()` derives these top-level fields from `Date.now()`
9
+ // (compile/index.ts `title: \`${app.name}(${timestamp})\`` and `update_timestamp`),
10
+ // so they differ on every run regardless of source. Excluded from the comparison —
11
+ // only the *top-level* keys are dropped, so nested subspace/brick `title`s still diff.
12
+ const VOLATILE_TOP_LEVEL_FIELDS = ['title', 'update_timestamp']
13
+
14
+ // A minimal, path-keyed config change (Option A): a generic patch, not coupled to
15
+ // bricks-config-editor's action vocabulary. `path` is an array of object keys /
16
+ // array indices, ready for the editor's `setYValueAtPath` (or a delete) so applying
17
+ // the patch is a single Yjs `'local'` transaction == one undo/redo entry.
18
+ export type ConfigPatchOp =
19
+ | { op: 'set'; path: Array<string | number>; value: unknown }
20
+ | { op: 'unset'; path: Array<string | number> }
21
+
22
+ export type ConfigChange =
23
+ | { status: 'ok'; ops: ConfigPatchOp[]; opCount: number }
24
+ | { status: 'no_baseline' }
25
+ | { status: 'unavailable' }
26
+
27
+ const isRecord = (value: unknown): value is Record<string, unknown> =>
28
+ typeof value === 'object' && value !== null && !Array.isArray(value)
29
+
30
+ const deepEqual = (a: unknown, b: unknown): boolean => {
31
+ if (a === b) return true
32
+ if (Array.isArray(a) && Array.isArray(b)) {
33
+ return a.length === b.length && a.every((item, index) => deepEqual(item, b[index]))
34
+ }
35
+ if (isRecord(a) && isRecord(b)) {
36
+ const aKeys = Object.keys(a)
37
+ return (
38
+ aKeys.length === Object.keys(b).length &&
39
+ aKeys.every((key) => key in b && deepEqual(a[key], b[key]))
40
+ )
41
+ }
42
+ return false
43
+ }
44
+
45
+ const normalizeConfig = (config: unknown) => {
46
+ if (!isRecord(config)) return config
47
+ const normalized = { ...config }
48
+ for (const field of VOLATILE_TOP_LEVEL_FIELDS) delete normalized[field]
49
+ return normalized
50
+ }
51
+
52
+ // Objects recurse key-wise; equal-length arrays recurse element-wise; everything else
53
+ // (scalars, type changes, length-changed arrays) emits one whole-value `set` at that
54
+ // path. The editor's `applyJsonDiffToYType` minimizes the actual Yjs ops downstream,
55
+ // so a whole-array `set` on insert/remove still yields a minimal CRDT mutation.
56
+ const diffInto = (
57
+ before: unknown,
58
+ after: unknown,
59
+ currentPath: Array<string | number>,
60
+ ops: ConfigPatchOp[],
61
+ ) => {
62
+ if (deepEqual(before, after)) return
63
+
64
+ if (isRecord(before) && isRecord(after)) {
65
+ const keys = new Set([...Object.keys(before), ...Object.keys(after)])
66
+ for (const key of keys) {
67
+ const nextPath = [...currentPath, key]
68
+ if (!(key in after)) ops.push({ op: 'unset', path: nextPath })
69
+ else if (!(key in before)) ops.push({ op: 'set', path: nextPath, value: after[key] })
70
+ else diffInto(before[key], after[key], nextPath, ops)
71
+ }
72
+ return
73
+ }
74
+
75
+ if (Array.isArray(before) && Array.isArray(after) && before.length === after.length) {
76
+ for (let index = 0; index < after.length; index += 1) {
77
+ diffInto(before[index], after[index], [...currentPath, index], ops)
78
+ }
79
+ return
80
+ }
81
+
82
+ ops.push({ op: 'set', path: currentPath, value: after })
83
+ }
84
+
85
+ // Diff two compiled configs. `before == null` means there was no prior build to compare
86
+ // (first compile); `after == null` means the fresh artifact could not be read.
87
+ export const computeConfigChange = (before: unknown, after: unknown): ConfigChange => {
88
+ if (before == null) return { status: 'no_baseline' }
89
+ if (after == null) return { status: 'unavailable' }
90
+ const ops: ConfigPatchOp[] = []
91
+ diffInto(normalizeConfig(before), normalizeConfig(after), [], ops)
92
+ return { status: 'ok', ops, opCount: ops.length }
93
+ }
94
+
95
+ // Read the last-compiled config artifact. Returns null when it is absent or unreadable.
96
+ export const readBuildConfig = async (projectDir: string): Promise<unknown> => {
97
+ try {
98
+ return JSON.parse(await readFile(path.join(projectDir, BUILD_CONFIG_RELATIVE), 'utf8'))
99
+ } catch {
100
+ return null
101
+ }
102
+ }
package/compile/index.ts CHANGED
@@ -10,6 +10,10 @@ import { makeId } from '../utils/id'
10
10
  import { generateCalulationMap } from './util'
11
11
  import { templateActionNameMap } from './action-name-map'
12
12
  import { templateEventPropsMap } from '../utils/event-props'
13
+ import { sh } from '../tools/_shell'
14
+ import { computeConfigChange, readBuildConfig } from './config-diff'
15
+ import { appendEditRecord, editProvenance } from '../tools/_edits-log'
16
+ import { isTruthyEnv } from '../tools/mcp-env'
13
17
  import type {
14
18
  Application,
15
19
  Data,
@@ -700,8 +704,38 @@ const compileAutomation = (automationMap: AutomationMap) =>
700
704
  }),
701
705
  )
702
706
 
707
+ // Record the minimal compiled-config delta this compile produced to the shared audit
708
+ // log (`.bricks/edits.jsonl`), so editing files directly and running `bun compile`
709
+ // leaves the same trail as the MCP source-editing tools. Maintained only in the
710
+ // editing-tools context (`BRICKS_CTOR_ENABLE_EDITING_TOOLS`); the source-editing tools
711
+ // turn it off for their verify compiles (see _verify.ts) so a tool edit records one
712
+ // richer entry instead of an extra generic compile entry. Also silent when there is no
713
+ // prior build to diff against (fresh projects, package tests, tooling outside a project).
714
+ const recordConfigChange = async (previousConfig: unknown, config: unknown) => {
715
+ if (previousConfig == null) return
716
+ if (!isTruthyEnv(process.env.BRICKS_CTOR_ENABLE_EDITING_TOOLS)) return
717
+ // The baseline was parsed from JSON; round-trip the fresh config the same way so keys
718
+ // holding undefined (dropped by the artifact's JSON.stringify) don't diff as phantom sets.
719
+ const change = computeConfigChange(previousConfig, JSON.parse(JSON.stringify(config)))
720
+ if (change.status !== 'ok') return
721
+ await appendEditRecord(process.cwd(), {
722
+ ts: new Date().toISOString(),
723
+ tool: 'compile',
724
+ provenance: editProvenance(),
725
+ outcome: 'ok',
726
+ summary:
727
+ change.opCount === 0
728
+ ? 'compile: no config change'
729
+ : `compile: ${change.opCount} config op(s)`,
730
+ configChange: change,
731
+ }).catch(() => undefined)
732
+ }
733
+
703
734
  export const compile = async (app: Application) => {
704
735
  await new Promise((resolve) => setImmediate(resolve, 0))
736
+ // Snapshot the prior build artifact before the caller's compile.ts overwrites it, so
737
+ // the config change introduced by this compile can be recorded on return.
738
+ const previousConfig = await readBuildConfig(process.cwd())
705
739
  const timestamp = Date.now()
706
740
  // Pre-index subspace ids so the canvas-item validation below stays O(1).
707
741
  const subspaceIdSet = new Set(app.subspaces.map((s) => s.id))
@@ -1414,12 +1448,7 @@ export const compile = async (app: Application) => {
1414
1448
  : null,
1415
1449
  }
1416
1450
 
1417
- Object.assign(
1418
- calc,
1419
- generateCalulationMap(calc.script_config, {
1420
- snapshotMode: process.env.BRICKS_SNAPSHOT_MODE === '1',
1421
- }),
1422
- )
1451
+ Object.assign(calc, generateCalulationMap(calc.script_config, dataCalcId))
1423
1452
  }
1424
1453
  map[dataCalcId] = calc
1425
1454
  return map
@@ -1456,12 +1485,15 @@ export const compile = async (app: Application) => {
1456
1485
  automation_map: compiledAutomationMap || app.metadata?.TEMP_automation_map || {},
1457
1486
  update_timestamp: timestamp,
1458
1487
  }
1488
+ await recordConfigChange(previousConfig, config)
1459
1489
  return config
1460
1490
  }
1461
1491
 
1462
1492
  export const checkConfig = async (configPath: string) => {
1463
- const { sh } = await import('../tools/_shell')
1464
1493
  // --validate-automation surfaces broken automation_map / test_map refs early,
1465
1494
  // which catches agent-authored automations that reference deleted bricks.
1466
1495
  await sh`bricks app check-config --validate-automation ${configPath}`
1496
+ // Doctor adds semantic lint checks after structural validation. Warnings are
1497
+ // surfaced in the compile log, but only errors fail by default.
1498
+ await sh`bricks app doctor --validate-automation ${configPath}`
1467
1499
  }
package/compile/util.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { makeId } from '../utils/id'
1
+ import { makeSeededId } from '../utils/id'
2
2
 
3
3
  type ScriptConfig = {
4
4
  title?: string
@@ -33,15 +33,18 @@ const padding = 15
33
33
  const layerXInterval = 300
34
34
  const layerYInterval = 150
35
35
 
36
- export const generateCalulationMap = (config: ScriptConfig, opts?: { snapshotMode?: boolean }) => {
36
+ // `calcId` (the owning script calc's stable id) seeds every derived command-node id, so an
37
+ // unchanged calc recompiles to identical ids and editing one calc never shifts another's —
38
+ // keeping the compiled config byte-stable for change detection. See makeSeededId in utils/id.
39
+ export const generateCalulationMap = (config: ScriptConfig, calcId: string) => {
37
40
  validateConfig(config)
38
- const sandboxId = makeId('property_bank_command', opts)
39
- const sandboxErrorId = makeId('property_bank_command', opts)
40
- const sandboxResultId = makeId('property_bank_command', opts)
41
+ const sandboxId = makeSeededId('property_bank_command', `${calcId}:sandbox-run`)
42
+ const sandboxErrorId = makeSeededId('property_bank_command', `${calcId}:sandbox-error`)
43
+ const sandboxResultId = makeSeededId('property_bank_command', `${calcId}:sandbox-result`)
41
44
 
42
45
  const inputs = Object.entries(config.inputs).reduce(
43
46
  (acc, [key, value], index) => {
44
- const commandId = makeId('property_bank_command', opts)
47
+ const commandId = makeSeededId('property_bank_command', `${calcId}:input:${key}`)
45
48
  acc.map[key] = {
46
49
  type: 'data-node',
47
50
  properties: {},
@@ -123,7 +126,7 @@ export const generateCalulationMap = (config: ScriptConfig, opts?: { snapshotMod
123
126
  let y = 0
124
127
  const outputs = Object.entries(config.outputs).reduce(
125
128
  (acc, [key, pbList], index) => {
126
- const commandId = makeId('property_bank_command', opts)
129
+ const commandId = makeSeededId('property_bank_command', `${calcId}:output:${key}`)
127
130
  acc.commandIdList.push(commandId)
128
131
  acc.map[commandId] = {
129
132
  type: 'command-node-object',
package/package.json CHANGED
@@ -1,13 +1,17 @@
1
1
  {
2
2
  "name": "@fugood/bricks-project",
3
- "version": "2.25.0-beta.42",
3
+ "version": "2.25.0-beta.45",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "typecheck": "tsc --noEmit",
7
7
  "build": "bun scripts/build.js"
8
8
  },
9
9
  "dependencies": {
10
- "@fugood/bricks-cli": "^2.25.0-beta.42",
10
+ "@babel/generator": "7.28.5",
11
+ "@babel/parser": "7.28.5",
12
+ "@babel/traverse": "7.28.5",
13
+ "@babel/types": "7.28.5",
14
+ "@fugood/bricks-cli": "^2.25.0-beta.45",
11
15
  "@huggingface/gguf": "^0.3.2",
12
16
  "@iarna/toml": "^3.0.0",
13
17
  "@modelcontextprotocol/sdk": "^1.15.0",
package/package.json.bak CHANGED
@@ -1,13 +1,17 @@
1
1
  {
2
2
  "name": "@fugood/bricks-ctor",
3
- "version": "2.25.0-beta.42",
3
+ "version": "2.25.0-beta.45",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "typecheck": "tsc --noEmit",
7
7
  "build": "bun scripts/build.js"
8
8
  },
9
9
  "dependencies": {
10
- "@fugood/bricks-cli": "^2.25.0-beta.42",
10
+ "@babel/generator": "7.28.5",
11
+ "@babel/parser": "7.28.5",
12
+ "@babel/traverse": "7.28.5",
13
+ "@babel/types": "7.28.5",
14
+ "@fugood/bricks-cli": "^2.25.0-beta.45",
11
15
  "@huggingface/gguf": "^0.3.2",
12
16
  "@iarna/toml": "^3.0.0",
13
17
  "@modelcontextprotocol/sdk": "^1.15.0",
@@ -12,6 +12,7 @@ This skill covers advanced BRICKS features not in the main project instructions.
12
12
  | Rule | Description |
13
13
  |------|-------------|
14
14
  | [Architecture Patterns](references/architecture-patterns.md) | **Read first** — decompose flows and select patterns |
15
+ | [Source-Editing Tools](references/source-editing-tools.md) | MCP tools for editing entries and data-calcs by AST (new/edit/remove, value grammar, verify) |
15
16
  | [Animation](references/animation.md) | Animation system for brick transforms and opacity |
16
17
  | [Standby Transition](references/standby-transition.md) | Canvas enter/exit animations |
17
18
  | [Automations](references/automations.md) | E2E testing and scheduled tasks |
@@ -26,6 +27,7 @@ This skill covers advanced BRICKS features not in the main project instructions.
26
27
  ## Quick Reference
27
28
 
28
29
  - **Complex flows**: See [Architecture Patterns](references/architecture-patterns.md) for decomposing multi-step workflows
30
+ - **Editing entries/data-calcs**: See [Source-Editing Tools](references/source-editing-tools.md) — prefer the MCP editing tools over hand-editing `subspaces/**`
29
31
  - **Multi-device**: See [Local Sync](references/local-sync.md) for LAN coordination
30
32
  - **Cloud data**: See [Remote Data Bank](references/remote-data-bank.md) for sync and API access
31
33
  - **Media assets**: See [Media Flow](references/media-flow.md) for centralized asset management
@@ -32,6 +32,12 @@ Sequential `PROPERTY_BANK` / `PROPERTY_BANK_EXPRESSION` actions in one chain rea
32
32
  Built-in commands for direct state and UI changes.
33
33
  - **PROPERTY_BANK**: set data value
34
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.
35
41
  - **CHANGE_CANVAS**: navigate to another canvas
36
42
  - **DYNAMIC_ANIMATION**: trigger animation
37
43
  - **ALERT / MESSAGE**: system feedback
@@ -0,0 +1,81 @@
1
+ # MCP Source-Editing Tools
2
+
3
+ The project-local `bricks-ctor` MCP server exposes tools that edit `subspaces/**` via
4
+ surgical AST edits, keeping files in the standard generated style. Prefer them over
5
+ hand-editing entry files; they validate references, manage imports, compile-verify, and
6
+ record every operation in `.bricks/edits.jsonl`.
7
+
8
+ ## Entry tools (bricks.ts / generators.ts / canvases.ts / data.ts / animations.ts)
9
+
10
+ | Tool | Purpose |
11
+ |------|---------|
12
+ | `new_entry` | Create a standard entry skeleton (`file`, `type`, `templateKey`, `alias`, optional initial `set`/`events`) |
13
+ | `edit_entry` | Set/unset dotted paths on an entry: `title`, `property.url`, `outlets.response`, `value`, `switches[0].property.text`, … |
14
+ | `edit_events` | Add/remove/replace/move/clear EventAction items in `events.<eventKey>` |
15
+ | `edit_canvas_items` | Add/replace/remove/move brick items on a Canvas `items` array (frames need numeric x/y/width/height) |
16
+ | `edit_switches` | Add/replace/remove/move switches (id, title, conds, override, disabled, break) |
17
+ | `remove_entry` | Delete an entry; cascades same-subspace references by default, `strict: true` refuses and lists sites |
18
+
19
+ Addressing: `{ file, entry }` (export const name) is primary; `id` works as a global
20
+ fallback (omit `file`). `edit_entry`/`edit_events` accept a `switch` parameter (switch id
21
+ or index) to edit the facets inside one switch — `edit_switches` owns only the array and
22
+ the conds/override shell.
23
+
24
+ ### Event actions
25
+
26
+ ```jsonc
27
+ {
28
+ "handler": "system", // or { "ref": "brickOrGeneratorRef" } or { "subspace": "SUBSPACE_id" }
29
+ "name": "CHANGE_CANVAS",
30
+ "params": { "canvasId": { "ref": "mainCanvas" } }, // template params, OR:
31
+ "dataParams": { "someData": 5 }, // PROPERTY_BANK-style params
32
+ "waitAsync": false
33
+ }
34
+ ```
35
+
36
+ System actions derive their `as SystemAction...` cast automatically; entity-action casts
37
+ are added only when passed via `cast`. The compiled source form
38
+ `{ handler, action: { name, params: [...], dataParams: [...] }, waitAsync }` is also
39
+ accepted, and `{ "expr": "<raw EventAction>" }` is the escape hatch for shapes the
40
+ structured form cannot express. Handler refs must resolve to a brick or generator.
41
+ `PROPERTY_BANK_EXPRESSION` expressions are validated against the runtime fold rules at
42
+ edit time: only expression statements, simple `const`/`let` declarations, and a final
43
+ return inside a zero-arg IIFE evaluate — no `if`/`for`/`while` (use ternaries, or a
44
+ DataCalculationScript for branching logic).
45
+
46
+ ## Data-calc tools (DataCalculationScript only)
47
+
48
+ | Tool | Purpose |
49
+ |------|---------|
50
+ | `new_data_calc` | Create `data-calc/data-calculation-{slug}.ts` + `.sandbox.js`, regenerate `data-calc/index.ts`, wire a minimal subspace root |
51
+ | `edit_data_calc` | Set/unset scalar fields, `output`/`error` refs, replace whole `inputs`/`outputs`, or rewrite the sandbox `code` |
52
+ | `edit_data_calc_io` | Add/remove/replace/clear single `inputs`/`outputs` items (input keys unique; output keys may repeat for fan-out) |
53
+ | `remove_data_calc` | Delete the calc `.ts` + its sandbox file and regenerate the index |
54
+
55
+ Addressing: `{ file }` or `{ subspace, calc }` where `calc` is alias, id, or filename
56
+ slug (subspace defaults to `subspace-0`). Code is canonicalized to the sandbox file form
57
+ (`export function main() { ... }` — wrapped automatically, `async` added when the body
58
+ uses top-level `await`). `DataCalculationMap` (visual node graph) is out of scope and
59
+ returns `fallback_recommended`.
60
+
61
+ ## Value grammar (everywhere a value appears)
62
+
63
+ | You pass | Emits |
64
+ |----------|-------|
65
+ | JSON scalar/array/object | literal |
66
+ | `{ "link": "dataRefOrAlias" }` | `linkData(() => data.dX)` (property data-links) |
67
+ | `{ "ref": "idOrAliasOrVarName", "subspace"?: 1 }` | `() => namespace.varName` getter |
68
+ | `{ "expr": "raw TypeScript" }` | spliced verbatim |
69
+
70
+ References resolve by var name, id, or alias within the target subspace and fail loudly
71
+ when missing or ambiguous — this doubles as reference validation.
72
+
73
+ ## Verification and audit
74
+
75
+ - Every call compile-verifies by default and returns `verify.configChange` — the minimal
76
+ compiled-config delta (path-keyed set/unset ops). Skip with per-call `verify: false`
77
+ or `BRICKS_CTOR_MCP_EDIT_VERIFY=0` when batching, then finish with the `compile` tool.
78
+ - All operations append to `.bricks/edits.jsonl` (gitignored) with inputs, outcomes, and
79
+ touched sites.
80
+ - Non-standard files or entries (hand-written shapes the AST editor cannot safely
81
+ rewrite) return `fallback_recommended` — use plain file edits for those cases only.
@@ -71,6 +71,8 @@ Useful flags:
71
71
 
72
72
  For ad-hoc CDP inspection against this local preview, connect any CDP client to `localhost:19852` — Chrome DevTools front-end works directly. For an agent-friendly CLI over CDP (screenshot, brick tree/query, input emulation, storage reads, runtime eval, network capture), the `bricks-cli` skill documents the `bricks devtools` command surface — read that skill if it is installed in this workspace. If it is not installed, run `bricks --help` and `bricks devtools --help`; the CLI's own help output is authoritative.
73
73
 
74
+ To inspect Data / Property Bank or storage state, prefer the dedicated `bricks devtools storage` subcommands — `storage data-bank get <S_xxxx>` (saved Data values), `storage system persist|memory`, `storage system get <key>` — over hand-written `runtime eval`. Reach for `runtime eval` only for *live* store internals that aren't persisted to a data bank (e.g. a current transient value: `runtime eval "system.data.property('S_xxxx', '<alias>')"`); don't reverse-engineer the `system.*` globals.
75
+
74
76
  ### Project Automations
75
77
 
76
78
  E2E tests authored in TypeScript inside the project (`AutomationTest` / `TestCase`). Test cases include:
@@ -0,0 +1,41 @@
1
+ import { appendFile, mkdir, readFile, writeFile } from 'node:fs/promises'
2
+ import path from 'node:path'
3
+
4
+ const auditLogIgnoreEntry = '.bricks/edits.jsonl'
5
+
6
+ // Ensure the project's .gitignore excludes the audit log. No-op when it is already
7
+ // ignored directly or via a broader `.bricks` rule.
8
+ const ensureAuditLogIgnored = async (projectDir: string) => {
9
+ const gitignorePath = path.join(projectDir, '.gitignore')
10
+ const content = await readFile(gitignorePath, 'utf8').catch((err: any) => {
11
+ if (err?.code === 'ENOENT') return ''
12
+ throw err
13
+ })
14
+ const ignored = content
15
+ .split(/\r?\n/)
16
+ .map((line) => line.trim())
17
+ .some((line) => line === auditLogIgnoreEntry || line === '.bricks/' || line === '.bricks')
18
+ if (ignored) return
19
+
20
+ const prefix = content && !content.endsWith('\n') ? '\n' : ''
21
+ await writeFile(
22
+ gitignorePath,
23
+ `${content}${prefix}\n# MCP entry-editing audit log\n${auditLogIgnoreEntry}\n`,
24
+ )
25
+ }
26
+
27
+ // Append one JSON record to `.bricks/edits.jsonl`, creating the directory and the
28
+ // gitignore entry as needed. Shared by the source-editing tools and `compile()` so
29
+ // every project mutation lands in the same audit log.
30
+ export const appendEditRecord = async (projectDir: string, record: Record<string, unknown>) => {
31
+ const bricksDir = path.join(projectDir, '.bricks')
32
+ await mkdir(bricksDir, { recursive: true })
33
+ await ensureAuditLogIgnored(projectDir)
34
+ await appendFile(path.join(bricksDir, 'edits.jsonl'), `${JSON.stringify(record)}\n`)
35
+ }
36
+
37
+ // Provenance stamped on every audit record: which agent/session produced the change.
38
+ export const editProvenance = () => ({
39
+ session: process.env.BRICKS_CTOR_SESSION_ID || process.env.CODEX_SESSION_ID,
40
+ agent: process.env.BRICKS_CTOR_AGENT_ID || process.env.USER,
41
+ })
@@ -0,0 +1,13 @@
1
+ const truthyEnvValues = new Set(['1', 'true', 'yes', 'on'])
2
+
3
+ export function isTruthyEnv(value: string | undefined) {
4
+ return truthyEnvValues.has(
5
+ String(value || '')
6
+ .trim()
7
+ .toLowerCase(),
8
+ )
9
+ }
10
+
11
+ export function shouldRegisterEditingTools(env: Record<string, string | undefined> = process.env) {
12
+ return isTruthyEnv(env.BRICKS_CTOR_ENABLE_EDITING_TOOLS)
13
+ }
@@ -6,6 +6,9 @@ import { register as registerLottie } from './mcp-tools/lottie'
6
6
  import { register as registerIcons } from './mcp-tools/icons'
7
7
  import { register as registerHuggingface } from './mcp-tools/huggingface'
8
8
  import { register as registerMedia } from './mcp-tools/media'
9
+ import { register as registerEntryEditing } from './mcp-tools/entry-editing'
10
+ import { register as registerDataCalcEditing } from './mcp-tools/data-calc-editing'
11
+ import { shouldRegisterEditingTools } from './mcp-env'
9
12
 
10
13
  const server = new McpServer({
11
14
  name: 'bricks-ctor',
@@ -24,5 +27,10 @@ registerIcons(server)
24
27
  registerHuggingface(server)
25
28
  registerMedia(server, projectDir)
26
29
 
30
+ if (shouldRegisterEditingTools()) {
31
+ registerEntryEditing(server, projectDir)
32
+ registerDataCalcEditing(server, projectDir)
33
+ }
34
+
27
35
  const transport = new StdioServerTransport()
28
36
  await server.connect(transport)
@@ -0,0 +1,50 @@
1
+ import { sh } from '../_shell'
2
+ import { computeConfigChange, readBuildConfig, type ConfigChange } from '../../compile/config-diff'
3
+
4
+ // Result of an editing tool's compile verification, carrying the config delta the
5
+ // compile produced. Shared by entry-editing and data-calc-editing.
6
+ export type VerificationResult = {
7
+ status: 'skipped' | 'compile:ok' | 'compile:failed'
8
+ errors: string[]
9
+ configChange?: ConfigChange
10
+ }
11
+
12
+ // Strip ANSI colors from the spawned compile so the captured output stays plain text.
13
+ const noColorEnv = { FORCE_COLOR: '0', NO_COLOR: '1' }
14
+
15
+ // Recompile the project and diff the result against the prior build artifact.
16
+ export const compileAndDiff = async (projectDir: string): Promise<VerificationResult> => {
17
+ // Snapshot the prior compiled config before recompiling (the new artifact overwrites it).
18
+ const before = await readBuildConfig(projectDir)
19
+ try {
20
+ // Turn off the editing-tools audit for this spawned compile so compile() doesn't write
21
+ // a duplicate generic entry — the calling editing tool records its own richer entry.
22
+ await sh`bun compile`
23
+ .cwd(projectDir)
24
+ .env({ ...noColorEnv, BRICKS_CTOR_ENABLE_EDITING_TOOLS: '0' })
25
+ .text()
26
+ } catch (err: any) {
27
+ const stdout = err.stdout?.toString() ?? ''
28
+ const stderr = err.stderr?.toString() ?? ''
29
+ const output = [stdout, stderr, err.message].filter(Boolean).join('\n').trim()
30
+ return { status: 'compile:failed', errors: output ? [output] : ['bun compile failed'] }
31
+ }
32
+ const after = await readBuildConfig(projectDir)
33
+ return { status: 'compile:ok', errors: [], configChange: computeConfigChange(before, after) }
34
+ }
35
+
36
+ const shouldVerify = (inputVerify?: boolean) => {
37
+ if (inputVerify !== undefined) return inputVerify
38
+ const value = process.env.BRICKS_CTOR_MCP_EDIT_VERIFY ?? 'true'
39
+ return !['0', 'false', 'no', 'off'].includes(value.toLowerCase())
40
+ }
41
+
42
+ // Compile verification shared by the source-editing tools: per-call `verify` wins,
43
+ // then the BRICKS_CTOR_MCP_EDIT_VERIFY env toggle, defaulting to on.
44
+ export const verifyProject = async (
45
+ projectDir: string,
46
+ verify?: boolean,
47
+ ): Promise<VerificationResult> => {
48
+ if (!shouldVerify(verify)) return { status: 'skipped', errors: [] }
49
+ return compileAndDiff(projectDir)
50
+ }
@@ -10,6 +10,8 @@ const noColorEnv = { FORCE_COLOR: '0', NO_COLOR: '1' }
10
10
  export function register(server: McpServer, projectDir: string) {
11
11
  const { dirname } = import.meta
12
12
 
13
+ // `bun compile` records the resulting config delta to `.bricks/edits.jsonl` itself
14
+ // (see compile() in compile/index.ts), so the spawned output below already reflects it.
13
15
  server.tool('compile', {}, async () => {
14
16
  let log = 'Type checking & Compiling...\n'
15
17
  try {