@fugood/bricks-ctor 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,19 @@
1
+ import { isTruthyEnv, shouldRegisterEditingTools } from '../../mcp-env'
2
+
3
+ describe('mcp env helpers', () => {
4
+ test('recognizes explicit truthy env values', () => {
5
+ for (const value of ['1', 'true', 'TRUE', 'yes', 'on', ' on ']) {
6
+ expect(isTruthyEnv(value)).toBe(true)
7
+ }
8
+ })
9
+
10
+ test('does not enable editing tools by default', () => {
11
+ expect(shouldRegisterEditingTools({})).toBe(false)
12
+ expect(shouldRegisterEditingTools({ BRICKS_CTOR_ENABLE_EDITING_TOOLS: '0' })).toBe(false)
13
+ expect(shouldRegisterEditingTools({ BRICKS_CTOR_ENABLE_EDITING_TOOLS: 'false' })).toBe(false)
14
+ })
15
+
16
+ test('enables editing tools when explicitly requested', () => {
17
+ expect(shouldRegisterEditingTools({ BRICKS_CTOR_ENABLE_EDITING_TOOLS: '1' })).toBe(true)
18
+ })
19
+ })
@@ -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 {