create-merlin-brain 5.3.8 → 5.4.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.
Files changed (63) hide show
  1. package/bin/install-rtk.cjs +282 -0
  2. package/bin/install.cjs +9 -0
  3. package/dist/server/api/client.d.ts.map +1 -1
  4. package/dist/server/api/client.js +35 -6
  5. package/dist/server/api/client.js.map +1 -1
  6. package/dist/server/server.d.ts.map +1 -1
  7. package/dist/server/server.js +146 -42
  8. package/dist/server/server.js.map +1 -1
  9. package/dist/server/session-coach.d.ts.map +1 -1
  10. package/dist/server/session-coach.js +12 -0
  11. package/dist/server/session-coach.js.map +1 -1
  12. package/dist/server/session-guardian.d.ts +8 -1
  13. package/dist/server/session-guardian.d.ts.map +1 -1
  14. package/dist/server/session-guardian.js +26 -14
  15. package/dist/server/session-guardian.js.map +1 -1
  16. package/dist/server/tools/challenge.d.ts.map +1 -1
  17. package/dist/server/tools/challenge.js +7 -1
  18. package/dist/server/tools/challenge.js.map +1 -1
  19. package/dist/server/tools/computer-use.d.ts.map +1 -1
  20. package/dist/server/tools/computer-use.js +13 -6
  21. package/dist/server/tools/computer-use.js.map +1 -1
  22. package/dist/server/tools/index.d.ts +0 -1
  23. package/dist/server/tools/index.d.ts.map +1 -1
  24. package/dist/server/tools/index.js +0 -1
  25. package/dist/server/tools/index.js.map +1 -1
  26. package/dist/server/tools/project.d.ts.map +1 -1
  27. package/dist/server/tools/project.js +14 -12
  28. package/dist/server/tools/project.js.map +1 -1
  29. package/dist/server/tools/verification-runner.d.ts +45 -0
  30. package/dist/server/tools/verification-runner.d.ts.map +1 -0
  31. package/dist/server/tools/verification-runner.js +264 -0
  32. package/dist/server/tools/verification-runner.js.map +1 -0
  33. package/dist/server/tools/verification.d.ts +3 -0
  34. package/dist/server/tools/verification.d.ts.map +1 -1
  35. package/dist/server/tools/verification.js +8 -265
  36. package/dist/server/tools/verification.js.map +1 -1
  37. package/files/hooks/pre-edit-sights-check.sh +19 -3
  38. package/files/hooks/security-scanner.sh +3 -4
  39. package/files/hooks/session-end.sh +45 -32
  40. package/files/hooks/smart-approve.sh +11 -3
  41. package/files/hooks/user-prompt-router.sh +24 -3
  42. package/files/merlin/VERSION +1 -1
  43. package/package.json +2 -2
  44. package/dist/server/tools/context.d.ts +0 -7
  45. package/dist/server/tools/context.d.ts.map +0 -1
  46. package/dist/server/tools/context.js +0 -614
  47. package/dist/server/tools/context.js.map +0 -1
  48. package/dist/server/tools/hud.d.ts +0 -13
  49. package/dist/server/tools/hud.d.ts.map +0 -1
  50. package/dist/server/tools/hud.js +0 -295
  51. package/dist/server/tools/hud.js.map +0 -1
  52. package/dist/server/tools/provider-ask.d.ts +0 -10
  53. package/dist/server/tools/provider-ask.d.ts.map +0 -1
  54. package/dist/server/tools/provider-ask.js +0 -234
  55. package/dist/server/tools/provider-ask.js.map +0 -1
  56. package/dist/server/tools/rate-limit.d.ts +0 -8
  57. package/dist/server/tools/rate-limit.d.ts.map +0 -1
  58. package/dist/server/tools/rate-limit.js +0 -184
  59. package/dist/server/tools/rate-limit.js.map +0 -1
  60. package/dist/server/tools/team-workers.d.ts +0 -7
  61. package/dist/server/tools/team-workers.d.ts.map +0 -1
  62. package/dist/server/tools/team-workers.js +0 -271
  63. package/dist/server/tools/team-workers.js.map +0 -1
@@ -99,14 +99,29 @@ fi
99
99
 
100
100
  # ─────────────────────────────────────────────────────────────────────────────
101
101
  # 3. FILE-BASED FALLBACK — guardian unreachable, use timestamp file
102
+ #
103
+ # IMPORTANT: Only block when a live Sights/guardian session genuinely existed
104
+ # (i.e. the timestamp file is present and non-empty, meaning a prior check
105
+ # happened this session) but is now stale.
106
+ #
107
+ # When there is NO guardian, NO API key, or the user is offline / running in
108
+ # Lite mode (timestamp file absent), fall through to ALLOW — we must not brick
109
+ # users who have no way to satisfy the "call merlin_get_context" instruction.
102
110
  # ─────────────────────────────────────────────────────────────────────────────
103
111
  if declare -f sights_was_checked_recently >/dev/null 2>&1; then
104
- if ! sights_was_checked_recently 120; then
112
+ # Determine whether a Sights timestamp file exists at all (proxy for "active session")
113
+ SIGHTS_TS_FILE="${HOME}/.claude/merlin/.sights-last-check"
114
+ _sights_session_active=false
115
+ if [ -f "${SIGHTS_TS_FILE}" ] && [ -s "${SIGHTS_TS_FILE}" ]; then
116
+ _sights_session_active=true
117
+ fi
118
+
119
+ if $_sights_session_active && ! sights_was_checked_recently 120; then
105
120
  if declare -f log_event >/dev/null 2>&1; then
106
121
  log_event "sights_skip_warning" "$(printf '{"file":"%s","source":"fallback"}' "${file_path:-unknown}")"
107
122
  fi
108
- # BLOCK the edit — stale context means the agent skipped merlin_get_context
109
- # This is the structural enforcement: you cannot edit without fresh Sights context
123
+ # BLOCK the edit — a prior Sights check existed but context is now stale.
124
+ # The user HAS a working Sights setup and can satisfy the requirement.
110
125
  _BADGE="$("${HOME}/.claude/scripts/duo-badge.sh" 2>/dev/null || echo "⟡🔮 MERLIN ›")"
111
126
  if command -v jq >/dev/null 2>&1; then
112
127
  jq -n --arg badge "$_BADGE" '{
@@ -121,6 +136,7 @@ if declare -f sights_was_checked_recently >/dev/null 2>&1; then
121
136
  fi
122
137
  exit 0
123
138
  fi
139
+ # No timestamp file → offline/Lite/no-API-key user — fall through and allow.
124
140
  fi
125
141
 
126
142
  # Log the pre-edit event
@@ -113,10 +113,9 @@ if echo "$content" | grep -qE 'sk-ant-[a-zA-Z0-9_\-]{90,}' 2>/dev/null; then
113
113
  fi
114
114
 
115
115
  # OpenAI key (sk- with 48+ chars, but not sk-ant-)
116
- if echo "$content" | grep -qE 'sk-(?!ant-)[a-zA-Z0-9]{48,}' 2>/dev/null; then
117
- _block "OpenAI API key" "sk-..."
118
- elif echo "$content" | grep -qE 'sk-[a-zA-Z0-9]{48,}' 2>/dev/null; then
119
- # Fallback for grep without PCRE: exclude sk-ant- manually
116
+ # Uses ERE only (no PCRE lookahead not portable across GNU and BSD grep).
117
+ # Anthropic keys (sk-ant-) are already caught by the rule above; exclude them here.
118
+ if echo "$content" | grep -qE 'sk-[a-zA-Z0-9_-]{48,}' 2>/dev/null; then
120
119
  if ! echo "$content" | grep -qE 'sk-ant-' 2>/dev/null; then
121
120
  _block "OpenAI API key" "sk-..."
122
121
  fi
@@ -140,36 +140,39 @@ COST_FILE="${HOME}/.claude/merlin/session-cost.json"
140
140
  if [ -f "${COST_FILE}" ]; then
141
141
  COST_SUMMARY=""
142
142
  if command -v node >/dev/null 2>&1; then
143
- COST_SUMMARY="$(node -e "
143
+ # Pass COST_FILE as process.argv[1] — never interpolate paths inside the script body.
144
+ COST_SUMMARY="$(node -e '
144
145
  try {
145
- const d = JSON.parse(require('fs').readFileSync('${COST_FILE}', 'utf8'));
146
+ var f = process.argv[1];
147
+ var d = JSON.parse(require("fs").readFileSync(f, "utf8"));
146
148
  if (d.totalCalls > 0) {
147
- const tot = (d.totalEstimatedCost || 0).toFixed(4);
148
- const calls = d.totalCalls || 0;
149
- const tc = d.tokenCounts || {};
150
- const tokens = (tc.totalInput || 0) + (tc.totalOutput || 0);
151
- const tokStr = tokens > 0 ? ', ' + Math.round(tokens/1000) + 'K tokens' : '';
152
- process.stdout.write('Session cost: \$' + tot + ' (' + calls + ' call' + (calls !== 1 ? 's' : '') + tokStr + ')');
149
+ var tot = (d.totalEstimatedCost || 0).toFixed(4);
150
+ var calls = d.totalCalls || 0;
151
+ var tc = d.tokenCounts || {};
152
+ var tokens = (tc.totalInput || 0) + (tc.totalOutput || 0);
153
+ var tokStr = tokens > 0 ? ", " + Math.round(tokens/1000) + "K tokens" : "";
154
+ process.stdout.write("Session cost: $" + tot + " (" + calls + " call" + (calls !== 1 ? "s" : "") + tokStr + ")");
153
155
  }
154
156
  } catch(e) {}
155
- " 2>/dev/null || true)"
157
+ ' "$COST_FILE" 2>/dev/null || true)"
156
158
  elif command -v python3 >/dev/null 2>&1; then
157
- COST_SUMMARY="$(python3 -c "
159
+ # Pass COST_FILE as sys.argv[1] — never interpolate paths inside the script body.
160
+ COST_SUMMARY="$(python3 -c '
158
161
  import json, sys
159
162
  try:
160
- with open('${COST_FILE}') as f:
163
+ with open(sys.argv[1]) as f:
161
164
  d = json.load(f)
162
- if d.get('totalCalls', 0) > 0:
163
- tot = d.get('totalEstimatedCost', 0)
164
- calls = d.get('totalCalls', 0)
165
- tc = d.get('tokenCounts', {})
166
- tokens = tc.get('totalInput', 0) + tc.get('totalOutput', 0)
167
- tok_str = (', ' + str(round(tokens/1000)) + 'K tokens') if tokens > 0 else ''
168
- plural = '' if calls == 1 else 's'
169
- sys.stdout.write(f'Session cost: \${tot:.4f} ({calls} call{plural}{tok_str})')
165
+ if d.get("totalCalls", 0) > 0:
166
+ tot = d.get("totalEstimatedCost", 0)
167
+ calls = d.get("totalCalls", 0)
168
+ tc = d.get("tokenCounts", {})
169
+ tokens = tc.get("totalInput", 0) + tc.get("totalOutput", 0)
170
+ tok_str = (", " + str(round(tokens/1000)) + "K tokens") if tokens > 0 else ""
171
+ plural = "" if calls == 1 else "s"
172
+ sys.stdout.write("Session cost: ${:.4f} ({} call{}{})".format(tot, calls, plural, tok_str))
170
173
  except Exception:
171
174
  pass
172
- " 2>/dev/null || true)"
175
+ ' "$COST_FILE" 2>/dev/null || true)"
173
176
  fi
174
177
  if [ -n "${COST_SUMMARY}" ]; then
175
178
  echo "[merlin] ${COST_SUMMARY}" >&2
@@ -249,19 +252,29 @@ if command -v jq >/dev/null 2>&1 && command -v git >/dev/null 2>&1; then
249
252
  echo "${outcome_line}" >> "${OUTCOME_FILE}" 2>/dev/null || true
250
253
  fi
251
254
 
252
- # Keep outcomes.jsonl bounded — drop lines older than 90 days
255
+ # Keep outcomes.jsonl bounded — drop lines older than 90 days.
256
+ # Single awk pass: no per-line subprocess, ISO-8601 UTC strings sort lexicographically.
257
+ # On any parse uncertainty, the line is KEPT (never silently dropped).
253
258
  if [ -f "${OUTCOME_FILE}" ]; then
254
- cutoff_epoch="$(date -u -v-90d +%s 2>/dev/null || date -u -d '90 days ago' +%s 2>/dev/null || echo 0)"
255
- if [ "${cutoff_epoch}" -gt 0 ] 2>/dev/null; then
256
- tmp_out="${OUTCOME_FILE}.tmp"
257
- while IFS= read -r line; do
258
- line_ts="$(echo "${line}" | jq -r '.timestamp // ""' 2>/dev/null || echo "")"
259
- if [ -z "${line_ts}" ]; then continue; fi
260
- line_epoch="$(date -u -d "${line_ts}" +%s 2>/dev/null || date -u -j -f "%Y-%m-%dT%H:%M:%SZ" "${line_ts}" +%s 2>/dev/null || echo 0)"
261
- if [ "${line_epoch}" -ge "${cutoff_epoch}" ] 2>/dev/null; then
262
- echo "${line}"
263
- fi
264
- done < "${OUTCOME_FILE}" > "${tmp_out}" 2>/dev/null && mv "${tmp_out}" "${OUTCOME_FILE}" 2>/dev/null || true
259
+ cutoff="$(date -u -v-90d +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -d '90 days ago' +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || echo "")"
260
+ if [ -n "${cutoff}" ]; then
261
+ tmp_out="${OUTCOME_FILE}.tmp.$$"
262
+ # 2-arg match() only portable to BSD awk (macOS default) AND gawk.
263
+ # The gawk-only 3-arg form `match($0, re, arr)` is a syntax error on BSD
264
+ # awk and would make the whole rotation a silent no-op.
265
+ awk -v cutoff="${cutoff}" '
266
+ {
267
+ ts = ""
268
+ # "timestamp":"<value>" → the literal prefix is 13 chars, trailing quote 1.
269
+ if (match($0, /"timestamp":"[^"]+"/)) {
270
+ ts = substr($0, RSTART + 13, RLENGTH - 14)
271
+ }
272
+ # Keep line if timestamp missing/unparseable OR >= cutoff (ISO string compare)
273
+ if (ts == "" || ts >= cutoff) print
274
+ }
275
+ ' "${OUTCOME_FILE}" > "${tmp_out}" 2>/dev/null \
276
+ && mv "${tmp_out}" "${OUTCOME_FILE}" 2>/dev/null \
277
+ || rm -f "${tmp_out}" 2>/dev/null || true
265
278
  fi
266
279
  fi
267
280
  fi
@@ -146,6 +146,8 @@ fi
146
146
  # ─────────────────────────────────────────────────────────────────────────────
147
147
 
148
148
  # Safe base command list (exact match on first word)
149
+ # NOTE: curl, wget, nc, scp, ssh, telnet are intentionally excluded — network egress
150
+ # must never be auto-approved; even a seemingly-safe command could pipe to a network tool.
149
151
  SAFE_CMDS="cat|head|tail|less|more|wc|file|stat|du|df|which|type|whereis|man|echo|printf|ls|find|tree|fd|grep|rg|ag|ack|fzf|jest|vitest|mocha|pytest|cargo|go|npm|yarn|pnpm|make|tsc|prettier|eslint|rustfmt|black|flake8|mypy|rubocop|uname|hostname|whoami|id|env|printenv|date|uptime|ps|top|git|node|python|python3"
150
152
 
151
153
  # Git read-only subcommands
@@ -244,16 +246,22 @@ _is_safe_segment() {
244
246
  return 0
245
247
  }
246
248
 
247
- # Split on pipe, semicolon, &&, || and check each segment
248
- # Replace separators with newlines, then iterate
249
+ # Split on shell operators (&&, ||, ;, |, &) treating two-char tokens first.
250
+ # Strategy: normalize && and || to newlines first (so they are not left as stray &/|),
251
+ # then normalize remaining ; | & to newlines. Each resulting segment is checked
252
+ # independently — the whole command is safe only when ALL segments are safe.
249
253
  all_safe=true
250
254
  while IFS= read -r segment; do
255
+ segment=$(echo "$segment" | xargs 2>/dev/null || echo "$segment") # trim whitespace
251
256
  [ -z "$segment" ] && continue
252
257
  if ! _is_safe_segment "$segment"; then
253
258
  all_safe=false
254
259
  break
255
260
  fi
256
- done < <(echo "$command_str" | tr '|;&' '\n')
261
+ done < <(echo "$command_str" | sed -E 's/\|\|/\
262
+ /g; s/&&/\
263
+ /g; s/[;|&]/\
264
+ /g')
257
265
 
258
266
  if $all_safe; then
259
267
  if declare -f log_event >/dev/null 2>&1; then
@@ -82,15 +82,36 @@ fi
82
82
  [ -z "$suggestion" ] && echo "{}" && exit 0
83
83
 
84
84
  # ── Emit routing hint ─────────────────────────────────────────────────────────
85
- _BADGE="$("${HOME}/.claude/scripts/duo-badge.sh" 2>/dev/null || echo "⟡🔮 MERLIN ›")"
85
+ # Cache the badge for the session to avoid spawning duo-badge.sh on every prompt.
86
+ # Cache key: the Claude Code session_id (stable for the whole session) parsed
87
+ # from the stdin JSON we already captured. $$ is a FRESH pid per hook spawn —
88
+ # it would never hit and would leak a temp file every prompt — so fall back to
89
+ # $PPID (stable across prompts in one session), never $$.
90
+ _SESSION_KEY=""
91
+ if command -v jq >/dev/null 2>&1; then
92
+ _SESSION_KEY=$(printf '%s' "$input" | jq -r '.session_id // empty' 2>/dev/null || true)
93
+ else
94
+ _SESSION_KEY=$(printf '%s' "$input" | grep -o '"session_id"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | sed 's/.*"\([^"]*\)"$/\1/' 2>/dev/null || true)
95
+ fi
96
+ [ -z "${_SESSION_KEY}" ] && _SESSION_KEY="ppid-${PPID}"
97
+ # Sanitize the key so it is safe as a filename fragment.
98
+ _SESSION_KEY=$(printf '%s' "${_SESSION_KEY}" | tr -c 'A-Za-z0-9._-' '_')
99
+ _BADGE_CACHE="${TMPDIR:-/tmp}/.merlin-badge-${_SESSION_KEY}"
100
+ if [ -f "${_BADGE_CACHE}" ]; then
101
+ _BADGE="$(cat "${_BADGE_CACHE}" 2>/dev/null || echo "⟡🔮 MERLIN ›")"
102
+ else
103
+ _BADGE="$("${HOME}/.claude/scripts/duo-badge.sh" 2>/dev/null || echo "⟡🔮 MERLIN ›")"
104
+ printf '%s' "${_BADGE}" > "${_BADGE_CACHE}" 2>/dev/null || true
105
+ fi
106
+
86
107
  _ctx="${_BADGE} ROUTING: ${suggestion}. Remember: YOU are the orchestrator. Answer codebase questions via Sights. Route implementation to agents. Badge every action."
87
108
 
88
109
  if command -v jq >/dev/null 2>&1; then
89
110
  jq -n --arg ctx "$_ctx" \
90
111
  '{hookSpecificOutput:{hookEventName:"UserPromptSubmit",additionalContext:$ctx}}'
91
112
  else
92
- # jq not available — emit via printf, escaping the double-quotes in suggestion
93
- _ctx_escaped=$(printf '%s' "$_ctx" | sed 's/"/\\"/g')
113
+ # jq not available — escape backslashes first, then quotes, then strip control chars
114
+ _ctx_escaped=$(printf '%s' "$_ctx" | sed 's/\\/\\\\/g; s/"/\\"/g' | tr -d '\000-\037')
94
115
  printf '{"hookSpecificOutput":{"hookEventName":"UserPromptSubmit","additionalContext":"%s"}}\n' "$_ctx_escaped"
95
116
  fi
96
117
 
@@ -1 +1 @@
1
- 3.22.0
1
+ 5.4.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-merlin-brain",
3
- "version": "5.3.8",
3
+ "version": "5.4.0",
4
4
  "description": "Merlin - The Ultimate AI Brain for Claude Code, Codex, and other AI CLIs. One install: workflows, agents, loop, and Sights MCP server.",
5
5
  "type": "module",
6
6
  "main": "./dist/server/index.js",
@@ -51,7 +51,7 @@
51
51
  "README.md"
52
52
  ],
53
53
  "dependencies": {
54
- "@modelcontextprotocol/sdk": "^1.0.0",
54
+ "@modelcontextprotocol/sdk": "^1.27.1",
55
55
  "simple-git": "^3.21.0",
56
56
  "zod": "^3.25.0"
57
57
  },
@@ -1,7 +0,0 @@
1
- /**
2
- * Context and Search Tools
3
- * Tools for getting codebase context, searching, and asking questions
4
- */
5
- import type { ToolContext } from './types.js';
6
- export declare function registerContextTools(ctx: ToolContext): void;
7
- //# sourceMappingURL=context.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/server/tools/context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAyC9C,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI,CAsoB3D"}