@fugood/bricks-ctor 2.25.0-beta.41 → 2.25.0-beta.43

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,21 @@
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_MCP_ENABLE_EDITING_TOOLS: '0' })).toBe(false)
13
+ expect(shouldRegisterEditingTools({ BRICKS_CTOR_MCP_ENABLE_EDITING_TOOLS: 'false' })).toBe(
14
+ false,
15
+ )
16
+ })
17
+
18
+ test('enables editing tools when explicitly requested', () => {
19
+ expect(shouldRegisterEditingTools({ BRICKS_CTOR_MCP_ENABLE_EDITING_TOOLS: '1' })).toBe(true)
20
+ })
21
+ })
@@ -0,0 +1,45 @@
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
+ await sh`bun compile`.cwd(projectDir).env(noColorEnv).text()
21
+ } catch (err: any) {
22
+ const stdout = err.stdout?.toString() ?? ''
23
+ const stderr = err.stderr?.toString() ?? ''
24
+ const output = [stdout, stderr, err.message].filter(Boolean).join('\n').trim()
25
+ return { status: 'compile:failed', errors: output ? [output] : ['bun compile failed'] }
26
+ }
27
+ const after = await readBuildConfig(projectDir)
28
+ return { status: 'compile:ok', errors: [], configChange: computeConfigChange(before, after) }
29
+ }
30
+
31
+ const shouldVerify = (inputVerify?: boolean) => {
32
+ if (inputVerify !== undefined) return inputVerify
33
+ const value = process.env.BRICKS_CTOR_MCP_EDIT_VERIFY ?? 'true'
34
+ return !['0', 'false', 'no', 'off'].includes(value.toLowerCase())
35
+ }
36
+
37
+ // Compile verification shared by the source-editing tools: per-call `verify` wins,
38
+ // then the BRICKS_CTOR_MCP_EDIT_VERIFY env toggle, defaulting to on.
39
+ export const verifyProject = async (
40
+ projectDir: string,
41
+ verify?: boolean,
42
+ ): Promise<VerificationResult> => {
43
+ if (!shouldVerify(verify)) return { status: 'skipped', errors: [] }
44
+ return compileAndDiff(projectDir)
45
+ }
@@ -11,6 +11,8 @@ export function register(server: McpServer, projectDir: string) {
11
11
  const { dirname } = import.meta
12
12
 
13
13
  server.tool('compile', {}, async () => {
14
+ // The config-change report is printed by compile() itself (compile/config-diff.ts),
15
+ // so the spawned `bun compile` output below already carries it.
14
16
  let log = 'Type checking & Compiling...\n'
15
17
  try {
16
18
  log += await sh`bun compile`.cwd(projectDir).env(noColorEnv).text()