create-merlin-brain 3.11.0 → 3.13.0
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.
- package/bin/install.cjs +156 -32
- package/bin/runtime-adapters.cjs +396 -0
- package/dist/server/api/types.d.ts +7 -0
- package/dist/server/api/types.d.ts.map +1 -1
- package/dist/server/cost/tracker.d.ts +38 -2
- package/dist/server/cost/tracker.d.ts.map +1 -1
- package/dist/server/cost/tracker.js +87 -15
- package/dist/server/cost/tracker.js.map +1 -1
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +74 -30
- package/dist/server/server.js.map +1 -1
- package/dist/server/tools/__tests__/augmentation.test.d.ts +8 -0
- package/dist/server/tools/__tests__/augmentation.test.d.ts.map +1 -0
- package/dist/server/tools/__tests__/augmentation.test.js +76 -0
- package/dist/server/tools/__tests__/augmentation.test.js.map +1 -0
- package/dist/server/tools/__tests__/route-helpers.test.d.ts +5 -0
- package/dist/server/tools/__tests__/route-helpers.test.d.ts.map +1 -0
- package/dist/server/tools/__tests__/route-helpers.test.js +49 -0
- package/dist/server/tools/__tests__/route-helpers.test.js.map +1 -0
- package/dist/server/tools/adaptive.js +1 -1
- package/dist/server/tools/adaptive.js.map +1 -1
- package/dist/server/tools/agent-spawn.d.ts +25 -0
- package/dist/server/tools/agent-spawn.d.ts.map +1 -0
- package/dist/server/tools/agent-spawn.js +95 -0
- package/dist/server/tools/agent-spawn.js.map +1 -0
- package/dist/server/tools/agents-index.js +3 -3
- package/dist/server/tools/agents-index.js.map +1 -1
- package/dist/server/tools/agents.js +5 -5
- package/dist/server/tools/agents.js.map +1 -1
- package/dist/server/tools/augmentation.d.ts +45 -0
- package/dist/server/tools/augmentation.d.ts.map +1 -0
- package/dist/server/tools/augmentation.js +167 -0
- package/dist/server/tools/augmentation.js.map +1 -0
- package/dist/server/tools/behaviors.js +4 -4
- package/dist/server/tools/behaviors.js.map +1 -1
- package/dist/server/tools/context.js +7 -7
- package/dist/server/tools/context.js.map +1 -1
- package/dist/server/tools/cost.d.ts +3 -1
- package/dist/server/tools/cost.d.ts.map +1 -1
- package/dist/server/tools/cost.js +66 -13
- package/dist/server/tools/cost.js.map +1 -1
- package/dist/server/tools/discoveries.js +6 -6
- package/dist/server/tools/discoveries.js.map +1 -1
- package/dist/server/tools/index.d.ts +4 -0
- package/dist/server/tools/index.d.ts.map +1 -1
- package/dist/server/tools/index.js +4 -0
- package/dist/server/tools/index.js.map +1 -1
- package/dist/server/tools/learning.d.ts +12 -0
- package/dist/server/tools/learning.d.ts.map +1 -0
- package/dist/server/tools/learning.js +269 -0
- package/dist/server/tools/learning.js.map +1 -0
- package/dist/server/tools/project.js +7 -7
- package/dist/server/tools/project.js.map +1 -1
- package/dist/server/tools/promote.d.ts +11 -0
- package/dist/server/tools/promote.d.ts.map +1 -0
- package/dist/server/tools/promote.js +315 -0
- package/dist/server/tools/promote.js.map +1 -0
- package/dist/server/tools/route-helpers.d.ts +45 -0
- package/dist/server/tools/route-helpers.d.ts.map +1 -0
- package/dist/server/tools/route-helpers.js +93 -0
- package/dist/server/tools/route-helpers.js.map +1 -0
- package/dist/server/tools/route.d.ts +4 -3
- package/dist/server/tools/route.d.ts.map +1 -1
- package/dist/server/tools/route.js +80 -284
- package/dist/server/tools/route.js.map +1 -1
- package/dist/server/tools/session-restore.d.ts +18 -0
- package/dist/server/tools/session-restore.d.ts.map +1 -0
- package/dist/server/tools/session-restore.js +154 -0
- package/dist/server/tools/session-restore.js.map +1 -0
- package/dist/server/tools/session-search.d.ts +16 -0
- package/dist/server/tools/session-search.d.ts.map +1 -0
- package/dist/server/tools/session-search.js +240 -0
- package/dist/server/tools/session-search.js.map +1 -0
- package/dist/server/tools/sights-index.js +2 -2
- package/dist/server/tools/sights-index.js.map +1 -1
- package/dist/server/tools/smart-route.d.ts.map +1 -1
- package/dist/server/tools/smart-route.js +4 -5
- package/dist/server/tools/smart-route.js.map +1 -1
- package/dist/server/tools/verification.js +1 -1
- package/dist/server/tools/verification.js.map +1 -1
- package/files/agents/code-organization-supervisor.md +1 -0
- package/files/agents/context-guardian.md +1 -0
- package/files/agents/docs-keeper.md +1 -0
- package/files/agents/dry-refactor.md +1 -0
- package/files/agents/elite-code-refactorer.md +1 -0
- package/files/agents/hardening-guard.md +1 -0
- package/files/agents/implementation-dev.md +1 -0
- package/files/agents/merlin-access-control-reviewer.md +248 -0
- package/files/agents/merlin-codebase-mapper.md +1 -1
- package/files/agents/merlin-dependency-auditor.md +216 -0
- package/files/agents/merlin-executor.md +1 -0
- package/files/agents/merlin-input-validator.md +247 -0
- package/files/agents/merlin-reviewer.md +1 -0
- package/files/agents/merlin-sast-reviewer.md +182 -0
- package/files/agents/merlin-secret-scanner.md +203 -0
- package/files/agents/tests-qa.md +1 -0
- package/files/commands/merlin/execute-phase.md +94 -197
- package/files/commands/merlin/execute-plan.md +116 -180
- package/files/commands/merlin/health.md +385 -0
- package/files/commands/merlin/loop-recipes.md +93 -36
- package/files/commands/merlin/optimize-prompts.md +158 -0
- package/files/commands/merlin/profiles.md +215 -0
- package/files/commands/merlin/promote.md +176 -0
- package/files/commands/merlin/quick.md +229 -0
- package/files/commands/merlin/resume-work.md +27 -1
- package/files/commands/merlin/route.md +43 -1
- package/files/commands/merlin/sandbox.md +359 -0
- package/files/commands/merlin/usage.md +55 -0
- package/files/docker/Dockerfile.merlin +20 -0
- package/files/docker/docker-compose.merlin.yml +23 -0
- package/files/hook-templates/auto-commit.sh +64 -0
- package/files/hook-templates/auto-format.sh +95 -0
- package/files/hook-templates/auto-test.sh +117 -0
- package/files/hook-templates/branch-protection.sh +72 -0
- package/files/hook-templates/changelog-reminder.sh +76 -0
- package/files/hook-templates/complexity-check.sh +112 -0
- package/files/hook-templates/import-audit.sh +83 -0
- package/files/hook-templates/license-header.sh +84 -0
- package/files/hook-templates/pr-description.sh +100 -0
- package/files/hook-templates/todo-tracker.sh +80 -0
- package/files/hooks/check-file-size.sh +17 -4
- package/files/hooks/config-change.sh +44 -16
- package/files/hooks/instructions-loaded.sh +22 -5
- package/files/hooks/notify-desktop.sh +157 -0
- package/files/hooks/notify-webhook.sh +141 -0
- package/files/hooks/pre-edit-sights-check.sh +76 -9
- package/files/hooks/security-scanner.sh +153 -0
- package/files/hooks/session-end-memory-sync.sh +97 -0
- package/files/hooks/session-end.sh +274 -1
- package/files/hooks/session-start.sh +19 -6
- package/files/hooks/smart-approve.sh +270 -0
- package/files/hooks/teammate-idle-verify.sh +87 -12
- package/files/hooks/worktree-create.sh +20 -3
- package/files/hooks/worktree-remove.sh +21 -3
- package/files/merlin/references/plan-format.md +37 -9
- package/files/merlin/sandbox.json +9 -0
- package/files/merlin/security.json +11 -0
- package/files/merlin/templates/ci/docs-update.yml +81 -0
- package/files/merlin/templates/ci/pr-review.yml +50 -0
- package/files/merlin/templates/ci/security-audit.yml +74 -0
- package/files/merlin/templates/config.json +9 -1
- package/files/rules/api-rules.md +30 -0
- package/files/rules/frontend-rules.md +25 -0
- package/files/rules/hooks-rules.md +36 -0
- package/files/rules/mcp-rules.md +30 -0
- package/files/rules/worker-rules.md +29 -0
- package/package.json +5 -2
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Merlin PR Review
|
|
2
|
+
# Automatically reviews pull requests for code quality, security, and correctness.
|
|
3
|
+
#
|
|
4
|
+
# Setup:
|
|
5
|
+
# 1. Add ANTHROPIC_API_KEY to your repo secrets (Settings > Secrets > Actions)
|
|
6
|
+
# 2. Copy this file to .github/workflows/pr-review.yml
|
|
7
|
+
#
|
|
8
|
+
name: Merlin PR Review
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
pull_request:
|
|
12
|
+
types: [opened, synchronize, reopened]
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
review:
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
permissions:
|
|
18
|
+
contents: read
|
|
19
|
+
pull-requests: write
|
|
20
|
+
|
|
21
|
+
steps:
|
|
22
|
+
- name: Checkout
|
|
23
|
+
uses: actions/checkout@v4
|
|
24
|
+
with:
|
|
25
|
+
fetch-depth: 0
|
|
26
|
+
|
|
27
|
+
- name: Merlin PR Review
|
|
28
|
+
uses: anthropics/claude-code-action@v1
|
|
29
|
+
with:
|
|
30
|
+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
31
|
+
prompt: |
|
|
32
|
+
Review this pull request. Be concise and constructive.
|
|
33
|
+
|
|
34
|
+
Check for:
|
|
35
|
+
- Code quality and clarity
|
|
36
|
+
- Security issues (secrets, injections, auth gaps)
|
|
37
|
+
- Correctness (logic errors, edge cases, off-by-ones)
|
|
38
|
+
- Breaking changes or regressions
|
|
39
|
+
- Missing tests for critical paths
|
|
40
|
+
|
|
41
|
+
Format your review as:
|
|
42
|
+
**Summary:** [1-2 sentences]
|
|
43
|
+
|
|
44
|
+
**Issues:** (only list real problems, not style preferences)
|
|
45
|
+
- [file:line] [severity: critical/major/minor] [description]
|
|
46
|
+
|
|
47
|
+
**Suggestions:** (optional improvements, not blocking)
|
|
48
|
+
- [description]
|
|
49
|
+
|
|
50
|
+
If the PR looks good, say so clearly. Don't invent issues.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Merlin Security Audit
|
|
2
|
+
# Runs a weekly security scan across the codebase using Claude Code.
|
|
3
|
+
# Also runs on demand via workflow_dispatch.
|
|
4
|
+
#
|
|
5
|
+
# Setup:
|
|
6
|
+
# 1. Add ANTHROPIC_API_KEY to your repo secrets (Settings > Secrets > Actions)
|
|
7
|
+
# 2. Copy this file to .github/workflows/security-audit.yml
|
|
8
|
+
#
|
|
9
|
+
name: Merlin Security Audit
|
|
10
|
+
|
|
11
|
+
on:
|
|
12
|
+
schedule:
|
|
13
|
+
# Every Monday at 09:00 UTC
|
|
14
|
+
- cron: '0 9 * * 1'
|
|
15
|
+
workflow_dispatch:
|
|
16
|
+
inputs:
|
|
17
|
+
scope:
|
|
18
|
+
description: 'Audit scope (all, auth, api, deps)'
|
|
19
|
+
required: false
|
|
20
|
+
default: 'all'
|
|
21
|
+
|
|
22
|
+
jobs:
|
|
23
|
+
security-audit:
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
permissions:
|
|
26
|
+
contents: read
|
|
27
|
+
issues: write
|
|
28
|
+
|
|
29
|
+
steps:
|
|
30
|
+
- name: Checkout
|
|
31
|
+
uses: actions/checkout@v4
|
|
32
|
+
with:
|
|
33
|
+
fetch-depth: 0
|
|
34
|
+
|
|
35
|
+
- name: Run dependency vulnerability scan
|
|
36
|
+
run: |
|
|
37
|
+
if [ -f package.json ]; then npm audit --json > /tmp/npm-audit.json 2>&1 || true; fi
|
|
38
|
+
if [ -f requirements.txt ]; then pip install safety && safety check --json > /tmp/pip-audit.json 2>&1 || true; fi
|
|
39
|
+
|
|
40
|
+
- name: Merlin Security Analysis
|
|
41
|
+
uses: anthropics/claude-code-action@v1
|
|
42
|
+
with:
|
|
43
|
+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
44
|
+
prompt: |
|
|
45
|
+
Perform a security audit of this codebase. Scope: ${{ github.event.inputs.scope || 'all' }}.
|
|
46
|
+
|
|
47
|
+
Focus on:
|
|
48
|
+
1. **Secrets and credentials** — hardcoded API keys, tokens, passwords
|
|
49
|
+
2. **Injection vulnerabilities** — SQL, command, path traversal
|
|
50
|
+
3. **Authentication and authorization gaps** — missing auth checks, privilege escalation
|
|
51
|
+
4. **Dependency vulnerabilities** — check /tmp/npm-audit.json or /tmp/pip-audit.json if present
|
|
52
|
+
5. **Data exposure** — PII in logs, unencrypted sensitive data
|
|
53
|
+
|
|
54
|
+
For each finding:
|
|
55
|
+
- File and line number
|
|
56
|
+
- Severity: critical / high / medium / low
|
|
57
|
+
- Description of the vulnerability
|
|
58
|
+
- Recommended fix
|
|
59
|
+
|
|
60
|
+
Output a structured report. If no issues found in a category, say "None found."
|
|
61
|
+
Focus on real vulnerabilities, not theoretical ones.
|
|
62
|
+
|
|
63
|
+
- name: Create issue if critical findings
|
|
64
|
+
if: failure()
|
|
65
|
+
uses: actions/github-script@v7
|
|
66
|
+
with:
|
|
67
|
+
script: |
|
|
68
|
+
github.rest.issues.create({
|
|
69
|
+
owner: context.repo.owner,
|
|
70
|
+
repo: context.repo.repo,
|
|
71
|
+
title: 'Security audit found critical issues',
|
|
72
|
+
body: 'The weekly Merlin security audit found critical issues. See the workflow run for details.',
|
|
73
|
+
labels: ['security', 'automated']
|
|
74
|
+
})
|
|
@@ -29,5 +29,13 @@
|
|
|
29
29
|
"safety": {
|
|
30
30
|
"always_confirm_destructive": true,
|
|
31
31
|
"always_confirm_external_services": true
|
|
32
|
-
}
|
|
32
|
+
},
|
|
33
|
+
"notifications": {
|
|
34
|
+
"desktop": true,
|
|
35
|
+
"sound": false,
|
|
36
|
+
"slack_webhook": "",
|
|
37
|
+
"discord_webhook": "",
|
|
38
|
+
"notify_on": ["stop", "needs_input", "error"]
|
|
39
|
+
},
|
|
40
|
+
"voice_mode_concise": false
|
|
33
41
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
paths: ["apps/api/**"]
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# API Rules (apps/api)
|
|
6
|
+
|
|
7
|
+
## Route Patterns
|
|
8
|
+
- Use Express.js route patterns: `router.get('/path', middleware, handler)`
|
|
9
|
+
- Group related routes in dedicated router files under `src/routes/`
|
|
10
|
+
- Use route-level middleware for auth and validation before business logic
|
|
11
|
+
|
|
12
|
+
## Error Handling
|
|
13
|
+
- All routes must have error handling — either try/catch or a next(err) pattern
|
|
14
|
+
- Use a centralized error middleware at the app level (`src/middleware/error.ts`)
|
|
15
|
+
- Never let unhandled promise rejections reach the client
|
|
16
|
+
|
|
17
|
+
## Database Access
|
|
18
|
+
- All database access must go through the services layer (`src/services/`)
|
|
19
|
+
- No raw DB queries in route handlers
|
|
20
|
+
- Services are responsible for data mapping and business logic
|
|
21
|
+
|
|
22
|
+
## Authentication
|
|
23
|
+
- All non-public routes must verify auth via the auth middleware
|
|
24
|
+
- Public routes must be explicitly marked with a comment: `// public route`
|
|
25
|
+
- Never trust client-supplied user IDs — derive from verified session/token
|
|
26
|
+
|
|
27
|
+
## Validation
|
|
28
|
+
- Use Zod for request body, query param, and path param validation
|
|
29
|
+
- Define schemas alongside the route or in a shared `src/schemas/` folder
|
|
30
|
+
- Return 400 with structured errors on validation failure — never 500
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
paths: ["apps/web/**"]
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Frontend Rules (apps/web)
|
|
6
|
+
|
|
7
|
+
## Next.js App Router
|
|
8
|
+
- Use the App Router (`app/` directory) — not the Pages Router
|
|
9
|
+
- Prefer Server Components by default; add `'use client'` only when interactivity requires it
|
|
10
|
+
- Use `loading.tsx` and `error.tsx` conventions for async boundaries
|
|
11
|
+
|
|
12
|
+
## Component Boundaries
|
|
13
|
+
- Mark client components explicitly with `'use client'` at the top of the file
|
|
14
|
+
- Keep client components small and push data fetching to server components
|
|
15
|
+
- Shared UI primitives go in `components/ui/`; page-specific components stay co-located
|
|
16
|
+
|
|
17
|
+
## Styling
|
|
18
|
+
- Use Tailwind CSS for all styling — no inline styles, no CSS modules unless forced
|
|
19
|
+
- Follow the project's existing Tailwind class ordering convention
|
|
20
|
+
- Use `cn()` (clsx/tailwind-merge helper) for conditional class concatenation
|
|
21
|
+
|
|
22
|
+
## Data Fetching
|
|
23
|
+
- Never call backend APIs directly from components — use the api client module
|
|
24
|
+
- The api client lives in `lib/api/` — add new methods there, not ad-hoc fetch calls
|
|
25
|
+
- Server components can call services directly; client components must go through the api client
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
paths: ["**/hooks/**", "**/files/hooks/**"]
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Hook Rules (hooks/)
|
|
6
|
+
|
|
7
|
+
## Language Constraints
|
|
8
|
+
- Pure bash only — no Python, no Node.js, no Ruby or other runtimes
|
|
9
|
+
- No npm packages, no pip installs, no external dependencies beyond standard Unix tools
|
|
10
|
+
- Assume only: bash, jq (optional), curl, grep, sed, awk, cat, date are available
|
|
11
|
+
|
|
12
|
+
## Performance
|
|
13
|
+
- Hooks must complete in under 50ms — they run on every tool call
|
|
14
|
+
- No synchronous network calls — if you need network, fire-and-forget with `&` and move on
|
|
15
|
+
- Avoid spawning subshells in tight loops; process data with built-in bash constructs
|
|
16
|
+
|
|
17
|
+
## Exit Codes
|
|
18
|
+
- Exit 0: allow the action / pass (default for all advisory hooks)
|
|
19
|
+
- Exit 2: block the action with a reason — output `{"decision":"block","reason":"..."}` to stdout
|
|
20
|
+
- Any other exit code is treated as 0 (pass) — never exit 1 to block, it's reserved for errors
|
|
21
|
+
|
|
22
|
+
## Input Handling
|
|
23
|
+
- Read event data from stdin as JSON: `input=$(cat)`
|
|
24
|
+
- Use jq when available; always provide a grep/sed fallback for when jq is missing:
|
|
25
|
+
```bash
|
|
26
|
+
if command -v jq >/dev/null 2>&1; then
|
|
27
|
+
tool_name=$(echo "$input" | jq -r '.tool_name // empty')
|
|
28
|
+
else
|
|
29
|
+
tool_name=$(echo "$input" | grep -o '"tool_name":"[^"]*"' | cut -d'"' -f4)
|
|
30
|
+
fi
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Output
|
|
34
|
+
- Blocking hooks: output valid JSON to stdout (`{"decision":"block","reason":"..."}`)
|
|
35
|
+
- Non-blocking hooks: output `{}` to stdout; all messages go to stderr
|
|
36
|
+
- Never output plain text to stdout — it breaks JSON parsing by Claude Code
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
paths: ["**/src/server/**", "**/packages/create-merlin-brain/src/**"]
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# MCP Server Rules (src/server)
|
|
6
|
+
|
|
7
|
+
## TypeScript
|
|
8
|
+
- Strict mode is required — `"strict": true` in tsconfig, no exceptions
|
|
9
|
+
- No `any` types; use `unknown` and narrow with guards when type is truly dynamic
|
|
10
|
+
- All exported functions and types must have explicit type annotations
|
|
11
|
+
|
|
12
|
+
## Tool Descriptions
|
|
13
|
+
- MCP tool descriptions must be keyword-rich for LLM discoverability
|
|
14
|
+
- Include: what it does, when to use it, what it returns, example use cases
|
|
15
|
+
- Bad: `"Gets context"` — Good: `"Fetches codebase context for a task, returns relevant files, patterns, and architecture notes to guide implementation"`
|
|
16
|
+
|
|
17
|
+
## Tool Loading Strategy
|
|
18
|
+
- Core tools (5-6 maximum): always loaded at server startup — these are the must-haves
|
|
19
|
+
- All other tools: deferred — loaded only when the core tools route to them or are explicitly requested
|
|
20
|
+
- This keeps the MCP tool list small and the LLM's tool selection fast
|
|
21
|
+
|
|
22
|
+
## Input Validation
|
|
23
|
+
- Every MCP tool handler must validate its input with Zod before processing
|
|
24
|
+
- Define the Zod schema inline with the tool registration (co-location aids readability)
|
|
25
|
+
- On validation failure, return a user-friendly error message — not a stack trace
|
|
26
|
+
|
|
27
|
+
## Error Responses
|
|
28
|
+
- All errors returned to the caller must be user-friendly (English prose, actionable)
|
|
29
|
+
- Internal errors (unexpected exceptions) should be caught and returned as structured text
|
|
30
|
+
- Never let an unhandled exception crash the MCP server process
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
---
|
|
2
|
+
paths: ["workers/**"]
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Worker Rules (workers/)
|
|
6
|
+
|
|
7
|
+
## Idempotency
|
|
8
|
+
- All worker jobs must be idempotent — running the same job twice must not cause side effects
|
|
9
|
+
- Use job IDs or content hashes to detect and skip already-processed work
|
|
10
|
+
- Store processing state in the database, not in memory
|
|
11
|
+
|
|
12
|
+
## Shared Infrastructure
|
|
13
|
+
- Use shared utilities from `workers/src/shared/` — database, queue, logger, config
|
|
14
|
+
- Never duplicate database connection logic — import from the shared db module
|
|
15
|
+
- Worker-specific code stays in the worker's own directory; cross-cutting code goes in shared
|
|
16
|
+
|
|
17
|
+
## AI Call Cost Control
|
|
18
|
+
- Every AI/LLM call must include a cost estimate in the log before execution
|
|
19
|
+
- Use `estimateCost(model, inputTokens, outputTokens)` from the shared cost module
|
|
20
|
+
- Log: model name, estimated tokens, estimated cost — so runaway jobs are caught early
|
|
21
|
+
|
|
22
|
+
## Database Connections
|
|
23
|
+
- Use connection pooling — never open a new connection per job
|
|
24
|
+
- Import the shared pool from `workers/src/shared/database.ts`
|
|
25
|
+
- Always release connections back to the pool — use pool.connect() with try/finally
|
|
26
|
+
|
|
27
|
+
## Cleanup
|
|
28
|
+
- Wrap all job logic in try/finally — cleanup (connection release, temp files, locks) must run even on failure
|
|
29
|
+
- Log the final state (completed / failed / skipped) before exiting the job handler
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-merlin-brain",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.13.0",
|
|
4
4
|
"description": "Merlin - The Ultimate AI Brain for Claude Code. One install: workflows, agents, loop, and Sights MCP server.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/server/index.js",
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
"start": "node dist/server/index.js",
|
|
16
16
|
"clean": "rm -rf dist",
|
|
17
17
|
"typecheck": "tsc --noEmit",
|
|
18
|
+
"test": "vitest run",
|
|
19
|
+
"test:watch": "vitest",
|
|
18
20
|
"prepublishOnly": "npm run build",
|
|
19
21
|
"postinstall": "node bin/install.cjs"
|
|
20
22
|
},
|
|
@@ -55,6 +57,7 @@
|
|
|
55
57
|
"devDependencies": {
|
|
56
58
|
"@types/node": "^20.10.0",
|
|
57
59
|
"tsx": "^4.6.2",
|
|
58
|
-
"typescript": "^5.3.0"
|
|
60
|
+
"typescript": "^5.3.0",
|
|
61
|
+
"vitest": "^4.1.0"
|
|
59
62
|
}
|
|
60
63
|
}
|