Skip to content

fix(plugin): guard runs under the plugin's tool names and asks once; commands use tools that return what they ask for (2.1.0) - #1

Merged
chris-cpz merged 10 commits into
mainfrom
fix/sweep1118
Nov 25, 2026
Merged

chris-cpz merged 10 commits into
mainfrom
fix/sweep1118

Conversation

@chris-cpz

@chris-cpz chris-cpz commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the plugin side of CPZ-Lab/cpzai bug sweep 11-18 (plugin-accounts group). The server side is CPZ-Lab/cpzai#3197. Version 2.1.0, so installed copies pick it up.

Issue Verdict Verified real by Fix Test
cpzai#2908 pre-trade guard never runs, and would block a confirmed call FIXED Claude Code session transcripts on a machine with plugin 2.0.0 show 84 mutating calls named mcp__plugin_cpzai_cpzai__* (create_strategy, update_strategy, execute_strategy, delete_webhook...), the hooks match mcp__cpzai__*, and the plugin data folder holds no audit.log. The old guard always answered {"decision":"block"} and stored nothing Hooks match ^mcp__(plugin_cpzai_)?cpzai__(...)$. New scripts/pre_trade_guard.py answers permissionDecision: "ask" with an order summary (side, qty, symbol, type, price, account, default environment): Claude Code asks the user once and runs the call on approval. All allowed-tools, agent tools and disallowedTools use the plugin names (the agents could not reach any CPZAI tool before). Audit log no longer records ok: true for every call. execution-reviewer checks buying power with cash_summary and volume and ADV with get_bars tests/test_hooks.py (9 of 11 fail on main)
cpzai#2797 /backtest sends Claude to execute_strategy FIXED execute_strategy takes only strategy_id and code; CPZAI docs: it "runs code and can submit orders" and no tool launches a backtest; commands/backtest.md and 3 skills said to backtest with it /backtest reads saved runs (get_backtest_results, get_backtest_result) and says runs start in Strategy Lab; skills corrected; quant-researcher can no longer call execute_strategy tests/test_content.py
cpzai#2886 options and factor screen ask for IV, Greeks, P/E FIXED Live get_market_data refuses SPY261218P00600000 ("Alpaca has no stock under the symbol") and an AAPL quote carries no P/E or fundamentals Both commands say plainly those figures are not available from CPZAI; realized vol and price-based factors come from get_bars tests/test_content.py
cpzai#2906 equity and buying power from list_accounts FIXED Live list_accounts row: broker, environment, status, tradable, timestamps, no money fields; cash_summary has them 7 commands, 3 skills and 2 agents use cash_summary; /trade checks the account's environment against the paper default tests/test_content.py
cpzai#2909 figures no tool returns, history pointed at the quote FIXED Live quote has no 52-week range; compute_risk returns no per-holding beta, volatility or factor exposure; the reporter's positions have sector null (production SQL) History-based figures (52-week range, MAs, RSI, relative volume, per-holding beta and vol, covariance) come from get_bars; sector only where recorded; week and month P&L and margin used removed; every command carries the "not available from CPZAI, never from memory" rule; CONNECTORS.md lists what each tool returns tests/test_content.py

Limits, stated in CONNECTORS.md:

  • The paper default is a reminder in the approval prompt plus a list_accounts environment check in /trade and execution-reviewer. The hook cannot check the account's environment: place_order input carries the account id, not its environment. A hard check needs the MCP server to accept and verify an expected environment (CPZ-Lab/aquila-mcp-server).
  • permissionDecision: "ask" is the documented Claude Code PreToolUse decision. Whether Cowork honours it is not verified; /trade asks in chat when no session banner shows the guard running.

Tests: bash tests/run-all.sh --offline: structure validation OK, test_hooks.py 11 passed, test_content.py 10 passed. On origin/main the two new suites fail: test_hooks.py with 2 failures and 7 errors, test_content.py with 9 failures. The validator now also rejects the short mcp__cpzai__ names and knows the current 39-tool catalog.

Wave 2 (11-25): three more commits

Issue Verdict Verified real by Fix
cpzai#3024 audit log marks a refused order ok FIXED The 2.0.0 script reads a success field PostToolUse does not send, never reads tool_response, registers no failure hook, and cuts input at 240 characters scripts/audit_log.py: refusals with their reason, broker order_id and status, PostToolUseFailure calls, the whole input with credential fields redacted
cpzai#3012 risk shares add to more than 100% FIXED The skill's MCTR_i = w_i (Σw)_i / σ and CR_i = w_i MCTR_i give Σ CR = 0.0657 against the claimed σ² = 0.0384 on a 4-asset book (test); portfolio-optimization's ERC sentence is the minimum-variance condition Correct MCTR, CR and percent contribution (sums to 100%, finite-difference check in the test); risk parity wording in portfolio-optimization, strategy-development and /optimize
cpzai#3022 six formulas and rules FIXED Each read against its own definition: RR = put minus call is positive for equities; breadth 125,000 vs 500 for the same book; NK + K(K+1)/2 + N = 5,555 not 1,055; scikit-learn's LedoitWolf target is the scaled identity; /backtest's >30 vs the skill's 100+; /trade-idea's EV left out the worst case All six corrected
cpzai#3023 17a-4 retention FIXED 17 CFR 240.17a-4(b)(1) puts 17a-3(a)(6) order memoranda at 3 years; 6 years in (a) is blotters and ledgers Both lines corrected
cpzai#3014 /trade has no stop price FIXED place_order schema: price, stop_price, positive share quantity, time_in_force day only; /trade had one price and offered $500 Stop price argument and confirmation line, shares only, day orders only; order-execution no longer offers GTC/IOC/FOK, extended hours, trailing or brackets through the tool
cpzai#3034 retry promise FIXED (partial, plugin side) MCP place_order says a resend returns the first order; cpzai://guides/tool-usage says there is no end-to-end idempotent retry guarantee; MCP list_orders has no client_order_id parameter though REST supports it /trade: never resend after a timeout, look for the client_order_id in list_orders first. Remaining (CPZ-Lab/aquila-mcp-server src/tools.ts): fix the place_order description and add client_order_id to list_orders
cpzai#3013 /strategy-builder format FIXED Strategy Lab's harness (src/lib/backtest-templates.ts) refuses code without a module-level generate_signal, generate_signals or on_bar ("No strategy interface function is available"); the command asked for generic numpy/pandas code Command states the format: literal SYMBOLS, one module-level signal function returning weights, polars frames, no live calls
cpzai#3037 first page of positions only FIXED Commands called list_positions / list_orders once; the tool and guide say to page until a short page /positions, /portfolio-review, /risk-report and /orders page and read account_errors

Tests: bash tests/run-all.sh --offline passes (validator OK, test_hooks.py 15 passed, test_content.py 18 passed). The new wave-2 tests fail on this branch's previous head (8 content failures, 6 hook errors).

Review fixes (independent review, plugin head 69bf885)

  • The guard fails closed. Empty stdin, {}, a missing or non-string tool_name, an unrecognised tool name, a non-object input and any exception inside the guard now answer ask (they used to exit 0, or exit 1 on a TypeError, which Claude Code treats as non-blocking). The user's own require_trade_confirmation=false still turns it off.
  • session-start.sh reads confirm= the way the guard does (only false, 0, no or off turn it off) and shows guard=OFF (python3 not found ...) with confirm=false when python3 is missing.
  • add_to_watchlist / remove_from_watchlist stay unguarded on purpose: they edit a 10-symbol watch list, move no money and are undone by the opposite call. Stated in CONNECTORS.md.
  • Failure counts above corrected (they were swapped).

Tests: bash tests/run-all.sh --offline passes (test_hooks.py 18 passed, test_content.py 18 passed). On the previous head 6f60701^ (e75003e), 4 of the new guard and banner tests fail.

Re-review fixes

  • "onFailure": "block" on the PreToolUse guard (Claude Code 2.1.295+): a guard that cannot start, exits with an error or times out blocks the call. session-start.sh now runs python3 (the /usr/bin/python3 stub on a Mac without developer tools passed command -v) and shows guard=OFF (no working python3 ...) with confirm=false.
  • Audit log: a state-changing call that fails without an answer is ok: null with outcome "unknown: reconcile with list_orders before any resubmission" (orders and strategy runs) or "check the resource", plus is_interrupt and duration_ms. Redaction widened (auth, credential, bearer, cookie, pass, pwd, pin, private, signature; identifiers ending in _id kept); create_connection configuration logged as field names only; audit.log created 0600.
  • /sync, /positions and /portfolio-review show paper and live balances on separate lines from totals.by_environment (cpzai#3120, server side in CPZ-Lab/cpzai#3206).

Tests: bash tests/run-all.sh --offline passes (test_hooks.py 24, test_content.py 19). On the previous head 6f60701 the new guard and banner tests fail (3), and on f3f0298 the new audit tests fail (5).

…e guard asks once instead of blocking a confirmed call (cpzai#2908)
…hey ask for (cpzai#2797, #2886, #2906, #2909)
…ailed calls and the whole input (cpzai#3024)
…tention and five more formula fixes (cpzai#3012, #3022, #3023)
…er writes Strategy Lab's format, book commands page (cpzai#3013, #3014, #3034, #3037)
…mes; the banner reads confirm like the guard and flags a missing python3 (review of #2908)
…, and the banner runs python3 instead of trusting command -v (re-review of #2908)
… with is_interrupt and duration; wider redaction; audit.log 0600 (re-review of #3024)
…ve balances apart, never one total (cpzai#3120)
@chris-cpz
chris-cpz merged commit efde1bd into main Nov 25, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant