argusqa-os 9.7.3 → 9.7.5

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/glama.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "$schema": "https://glama.ai/mcp/schemas/server.json",
3
3
  "name": "argus",
4
- "description": "AI-powered QA harness that audits web apps via Chrome DevTools Protocol. Catches JS errors, network failures, a11y violations, SEO issues, security headers, CSS regressions, and more — directly from Claude conversations. 9 MCP tools: argus_audit (fast 8-analyzer pass), argus_audit_full (Lighthouse + memory + responsive), argus_compare (dev vs staging diff), argus_last_report (retrieve last JSON report), argus_watch_snapshot (live tab snapshot without navigating), argus_get_context (LLM-optimized context + fix loop with snapshot_id diff), argus_design_audit (Figma design fidelity — 13 finding types), argus_visual_diff (screenshot baseline comparison, updateBaseline flag), argus_pr_validate (PR diff → affected routes → targeted audit → blocked flag). Every finding is post-processed with intelligent baseline filtering (cross-run noise classifier) and root cause linking (recent git commits mapped to new findings). 141 test blocks, 679 hard assertions, 67 detection categories.",
4
+ "description": "AI-powered QA harness that audits web apps via Chrome DevTools Protocol. Catches JS errors, network failures, a11y violations, SEO issues, security headers, CSS regressions, and more — directly from Claude conversations. 9 MCP tools: argus_audit (fast 8-analyzer pass), argus_audit_full (Lighthouse + memory + responsive), argus_compare (dev vs staging diff), argus_last_report (retrieve last JSON report), argus_watch_snapshot (live tab snapshot without navigating), argus_get_context (LLM-optimized context + fix loop with snapshot_id diff), argus_design_audit (Figma design fidelity — 13 finding types), argus_visual_diff (screenshot baseline comparison, updateBaseline flag), argus_pr_validate (PR diff → affected routes → targeted audit → blocked flag). Every finding is post-processed with intelligent baseline filtering (cross-run noise classifier) and root cause linking (recent git commits mapped to new findings). 144 test blocks, 738 hard assertions, 67 detection categories.",
5
5
  "maintainers": ["ironclawdevs27"],
6
6
  "tools": [
7
7
  {
8
8
  "name": "argus_audit",
9
- "description": "Fast QA audit — JS errors, network failures (4xx/5xx), API frequency loops, CSS cascade issues, SEO violations, security headers, accessibility, and content. Returns { findings, summary }. Supports cache: true to skip re-crawl on repeat calls."
9
+ "description": "Fast QA audit — JS errors, network failures (4xx/5xx), CORS, API frequency loops, slow/blocking third-party requests, API contract violations, SEO violations, security headers, content quality, DevTools Issues panel, and HTTPS enforcement. Returns { findings, summary }. Supports cache: true to skip re-crawl on repeat calls."
10
10
  },
11
11
  {
12
12
  "name": "argus_audit_full",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "argusqa-os",
3
- "version": "9.7.3",
3
+ "version": "9.7.5",
4
4
  "mcpName": "io.github.ironclawdevs27/argus",
5
5
  "description": "Argus — AI-powered automated dev-testing platform using Chrome DevTools MCP and Claude Code",
6
6
  "keywords": [
@@ -48,7 +48,7 @@
48
48
  "watch": "node src/orchestration/watch-mode.js",
49
49
  "server": "node src/server/index.js",
50
50
  "harness": "node test-harness/server.js",
51
- "harness:staging": "PORT=3101 node test-harness/server.js",
51
+ "harness:staging": "node test-harness/server.js --port=3101 --staging",
52
52
  "test:harness": "node --env-file=test-harness/.env.harness test-harness/validate.js",
53
53
  "test:harness:log": "node test-harness/run-with-log.mjs",
54
54
  "test:unit": "vitest run test/unit",
@@ -21,7 +21,24 @@ export class CdpBrowserAdapter {
21
21
  constructor(mcp) { this._mcp = mcp; }
22
22
 
23
23
  // ── Navigation ──────────────────────────────────────────────────────────────
24
- navigate(url) { return withRetry(() => this._mcp.navigate_page({ url }), { label: `navigate(${url})` }); }
24
+ // navigate_page reports failures as RESOLVED text ("Unable to navigate ...
25
+ // net::ERR_CONNECTION_REFUSED", "Could not connect to Chrome ..."), never as a
26
+ // thrown error. Unchecked, a dead target or dead browser produced a "clean"
27
+ // audit: analyzers ran against chrome-error://chromewebdata and emitted bogus
28
+ // findings (or none), and CI gates passed with Chrome down. Throw so failures
29
+ // propagate through the existing crawl error path.
30
+ navigate(url) {
31
+ return withRetry(async () => {
32
+ const resp = await this._mcp.navigate_page({ url });
33
+ if (typeof resp === 'string' &&
34
+ (resp.includes('Unable to navigate') ||
35
+ resp.includes('Could not connect to Chrome') ||
36
+ resp.includes('A dialog is open'))) {
37
+ throw new Error(`navigate(${url}) failed: ${resp.split('\n')[0].slice(0, 200)}`);
38
+ }
39
+ return resp;
40
+ }, { label: `navigate(${url})` });
41
+ }
25
42
 
26
43
  // ── Evaluation & snapshots ──────────────────────────────────────────────────
27
44
  evaluate(fn) { return this._mcp.evaluate_script({ function: fn }); }
@@ -41,26 +58,71 @@ export class CdpBrowserAdapter {
41
58
  hover(uid) { return this._mcp.hover({ uid }); }
42
59
  drag(src, tgt) { return this._mcp.drag({ from_uid: src, to_uid: tgt }); }
43
60
  uploadFile(uid, filePath) { return this._mcp.upload_file({ uid, filePath }); }
44
- handleDialog(accept, promptText = '') { return this._mcp.handle_dialog({ accept, promptText }); }
45
- waitFor(opts) { return this._mcp.wait_for(opts); }
61
+ // handle_dialog wire schema is { action: 'accept'|'dismiss', promptText? } — sending
62
+ // { accept: bool } is rejected by the tool's input validation (and the rejection comes
63
+ // back as a resolved error-text response, so the failure was silent in production).
64
+ handleDialog(accept, promptText = '') {
65
+ const args = { action: accept ? 'accept' : 'dismiss' };
66
+ if (promptText) args.promptText = promptText;
67
+ return this._mcp.handle_dialog(args);
68
+ }
69
+ // wait_for requires text as a non-empty string ARRAY. A bare string is rejected by
70
+ // input validation, and { state: 'networkidle' } is not part of the tool's schema at
71
+ // all — both shapes used to resolve to error text and silently wait for nothing.
72
+ waitFor(opts = {}) {
73
+ if (typeof opts.text === 'string') opts = { ...opts, text: [opts.text] };
74
+ if (opts.state === 'networkidle') return this.#waitForNetworkIdle();
75
+ return this._mcp.wait_for(opts);
76
+ }
77
+
78
+ // Bounded network-quiet poll: resolves once the page's resource-timing entry count
79
+ // is stable across two consecutive 250 ms polls, or after 3 s — whichever is first.
80
+ async #waitForNetworkIdle() {
81
+ let prev = -1;
82
+ for (let i = 0; i < 12; i++) {
83
+ const raw = await this.evaluate(`() => performance.getEntriesByType('resource').length`);
84
+ const count = Number(typeof raw === 'object' ? raw?.result ?? 0 : raw) || 0;
85
+ if (count === prev) return;
86
+ prev = count;
87
+ await new Promise(r => setTimeout(r, 250));
88
+ }
89
+ }
46
90
 
47
91
  // ── Viewport ────────────────────────────────────────────────────────────────
48
92
  emulate(viewport) { return this._mcp.emulate({ viewport }); }
49
93
  emulateCpu(rate) { return this._mcp.emulate({ cpuThrottlingRate: rate }); }
50
94
  emulateColorScheme(scheme) { return this._mcp.emulate({ colorScheme: scheme }); }
51
- emulateReducedMotion(pref) { return this._mcp.emulate({ reducedMotion: pref }); }
95
+ // chrome-devtools-mcp@1.1.1's emulate tool has no reduced-motion capability — the
96
+ // unsupported argument comes back as RESOLVED error text ("Unknown argument"), not a
97
+ // thrown error, so callers' graceful-skip catch paths (motion-analyzer) never ran and
98
+ // analysis proceeded unemulated. Surface it as a real error; if a future upstream
99
+ // version adds the argument, the call succeeds and emulation lights up automatically.
100
+ async emulateReducedMotion(pref) {
101
+ const resp = await this._mcp.emulate({ reducedMotion: pref });
102
+ if (typeof resp === 'string' && resp.includes('Unknown argument')) {
103
+ throw new Error(`emulate does not support reducedMotion in this chrome-devtools-mcp version: ${resp.slice(0, 120)}`);
104
+ }
105
+ return resp;
106
+ }
52
107
  resize(w, h) { return this._mcp.resize_page({ width: w, height: h }); }
53
108
 
54
109
  // ── Network & performance ───────────────────────────────────────────────────
55
- getNetworkRequest(reqId) { return this._mcp.get_network_request({ requestId: reqId }); }
110
+ // chrome-devtools-mcp expects the wire parameter "reqid" (sending "requestId"
111
+ // is rejected with an Unknown-argument error). Callers still pass the numeric
112
+ // requestId parsed from list_network_requests.
113
+ getNetworkRequest(reqId) { return this._mcp.get_network_request({ reqid: reqId }); }
56
114
  lighthouse(url, opts = {}) { return this._mcp.lighthouse_audit({ url, ...opts }); }
57
115
  startTrace() { return this._mcp.performance_start_trace({}); }
58
116
  stopTrace() { return this._mcp.performance_stop_trace({}); }
59
117
  analyzeInsight(opts) { return this._mcp.performance_analyze_insight(opts); }
60
118
 
61
119
  // ── Tab management ─────────────────────────────────────────────────────────
120
+ // list_pages returns markdown text ("## Pages\n1: <url> [selected]") like all
121
+ // MCP responses — callers parse with parseListPagesResponse (mcp-parsers.js).
62
122
  listPages() { return this._mcp.list_pages({}); }
63
- selectPage(tabId) { return this._mcp.select_page({ pageId: tabId }); }
123
+ // select_page validates pageId as a number — coerce so callers may pass the
124
+ // string tabId they received from an MCP tool argument.
125
+ selectPage(tabId) { return this._mcp.select_page({ pageId: Number(tabId) }); }
64
126
 
65
127
  // ── Lifecycle ───────────────────────────────────────────────────────────────
66
128
  close() { return this._mcp.close(); }
package/src/cli/doctor.js CHANGED
@@ -47,7 +47,7 @@ export function checkMcpConfig(filePath = '.mcp.json') {
47
47
  if (!fs.existsSync(filePath)) {
48
48
  return {
49
49
  ok: false,
50
- detail: `${path.basename(filePath)} not found — run \`argus init\` or copy .mcp.json from the Argus repo`,
50
+ detail: `${path.basename(filePath)} not found — create it with: {"mcpServers":{"chrome-devtools":{"command":"npx","args":["-y","chrome-devtools-mcp@1.1.1"]}}}`,
51
51
  };
52
52
  }
53
53
  let parsed;
@@ -63,7 +63,7 @@ export function checkMcpConfig(filePath = '.mcp.json') {
63
63
  return cmd.includes('chrome-devtools') || args.some(a => a.includes('chrome-devtools'));
64
64
  });
65
65
  if (!hasCdp) {
66
- return { ok: false, detail: 'No chrome-devtools MCP server entry found in mcpServers' };
66
+ return { ok: false, detail: 'No chrome-devtools entry in mcpServers add: "chrome-devtools": {"command":"npx","args":["-y","chrome-devtools-mcp@1.1.1"]}' };
67
67
  }
68
68
  return { ok: true, detail: `${Object.keys(servers).length} server(s) configured` };
69
69
  }
@@ -230,6 +230,11 @@ async function main() {
230
230
  const files = await fetchPrFiles(prUrl, token);
231
231
  changedFiles.push(...files);
232
232
  console.log(`[argus] ${files.length} changed file(s)`);
233
+ if (files.length >= 300) {
234
+ // CI annotation lives here (CLI owns stdout) — fetchPrFiles itself only
235
+ // logs to stderr so the MCP server's JSON-RPC stdout stays clean.
236
+ console.log('::warning::PR has 300+ changed files — Argus analyzed the first 300. Routes affected by later files may be missed.');
237
+ }
233
238
 
234
239
  // Step 2: Map changed files to affected routes
235
240
  const routes = await loadRoutes();
package/src/mcp-server.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * Argus MCP Server (v9.6.6)
3
+ * Argus MCP Server
4
4
  *
5
5
  * Exposes Argus as an MCP server so Claude (or any MCP client) can call
6
6
  * argus_audit, argus_audit_full, argus_compare, argus_last_report, and
@@ -24,8 +24,11 @@ import {
24
24
  } from '@modelcontextprotocol/sdk/types.js';
25
25
  import fs from 'fs';
26
26
  import path from 'path';
27
+ import { createRequire } from 'module';
27
28
 
28
29
  import { createMcpClient } from './utils/mcp-client.js';
30
+ import { childLogger } from './utils/logger.js';
31
+ import { parseListPagesResponse } from './utils/mcp-parsers.js';
29
32
  import { crawlRouteCheap, runCrawl } from './orchestration/crawl-and-report.js';
30
33
  import { runComparison } from './orchestration/env-comparison.js';
31
34
  import { WatchSession } from './orchestration/watch-mode.js';
@@ -35,6 +38,13 @@ import { analyzeDesignFidelity } from './utils/design-fidelity-analy
35
38
  import { analyzeVisualRegression } from './utils/visual-diff-analyzer.js';
36
39
  import { fetchPrFiles, mapFilesToRoutes } from './utils/pr-diff-analyzer.js';
37
40
 
41
+ const logger = childLogger('mcp-server');
42
+
43
+ // Read version from package.json so the MCP server always self-reports the
44
+ // published package version (a hardcoded string here drifted in the past).
45
+ const require_ = createRequire(import.meta.url);
46
+ const pkg = require_('../package.json');
47
+
38
48
  const REPORTS_DIR = path.resolve(process.cwd(), 'reports');
39
49
 
40
50
  // Fix loop: stores up to 20 snapshots keyed by snapshot_id so argus_get_context
@@ -65,7 +75,7 @@ function cacheAudit(url, result) {
65
75
  const TOOLS = [
66
76
  {
67
77
  name: 'argus_audit',
68
- description: 'Fast QA audit on a URL via Chrome DevTools Protocol. Runs 8 analyzers in one pass: JS errors, unhandled rejections, network failures (4xx/5xx), API frequency loops, CSS cascade issues, SEO violations, security header checks, and accessibility. Returns { findings: [{severity, type, message, url}], summary: {critical, warning, info} }. Use for CI smoke tests and pre-deploy gates. Pass cache: true to skip re-crawl on repeat calls to the same URL within a session — useful in tight fix loops. For Lighthouse scoring and memory leak detection, use argus_audit_full. Requires Chrome running with --remote-debugging-port=9222.',
78
+ description: 'Fast QA audit on a URL via Chrome DevTools Protocol. One-pass detection sweep: JS errors, unhandled rejections, network failures (4xx/5xx), CORS errors, API frequency loops, slow APIs and blocking third-party requests, API contract violations, sync XHR, document.write, long tasks, service worker failures, debugger statements, duplicate IDs, SEO violations, security header checks, content quality, Chrome DevTools Issues panel, and HTTPS enforcement. Returns { findings: [{severity, type, message, url}], summary: {critical, warning, info} }. Use for CI smoke tests and pre-deploy gates. Pass cache: true to skip re-crawl on repeat calls to the same URL within a session — useful in tight fix loops. For Lighthouse scoring, CSS analysis, responsive checks, and memory leak detection, use argus_audit_full. Requires Chrome running with --remote-debugging-port=9222.',
69
79
  inputSchema: {
70
80
  type: 'object',
71
81
  properties: {
@@ -181,6 +191,9 @@ async function withMcp(fn) {
181
191
  async function handleAudit({ url, critical = false, cache = false }) {
182
192
  if (cache && auditCache.has(url)) {
183
193
  const { result, ts } = auditCache.get(url);
194
+ // Refresh recency on read so eviction is true LRU, not insertion-order FIFO.
195
+ auditCache.delete(url);
196
+ auditCache.set(url, { result, ts });
184
197
  return { content: [{ type: 'text', text: JSON.stringify({ ...result, _cached: true, _cachedAt: new Date(ts).toISOString() }, null, 2) }] };
185
198
  }
186
199
  return withMcp(async (mcp) => {
@@ -243,12 +256,13 @@ async function handleGetContext({ url, snapshot_id: prevId, tabId } = {}) {
243
256
  const { findings, newConsole, newNetwork } = await session.poll();
244
257
 
245
258
  // List all open tabs so the caller can target a specific tab on the next call.
259
+ // list_pages returns markdown text ("## Pages\n1: <url> [selected]") — parse
260
+ // it like every other MCP response; treating it as a structured array left
261
+ // open_tabs permanently empty.
246
262
  let open_tabs = [];
247
263
  try {
248
- const pages = await browser.listPages();
249
- if (Array.isArray(pages)) {
250
- open_tabs = pages.map(p => ({ id: p.id ?? p.pageId, url: p.url, title: p.title }));
251
- }
264
+ const pages = parseListPagesResponse(await browser.listPages());
265
+ open_tabs = pages.map(p => ({ id: p.id, url: p.url, selected: p.selected }));
252
266
  } catch { /* list_pages not available in all Chrome configs — degrade gracefully */ }
253
267
 
254
268
  const newId = Date.now().toString(36) + Math.random().toString(36).slice(2, 6);
@@ -397,8 +411,12 @@ async function handlePrValidate({ prUrl, targetUrl, githubToken, blockOn } = {})
397
411
  const allFindings = [];
398
412
  const perRoute = [];
399
413
 
414
+ // Preserve any path prefix in the target URL (e.g. http://host/app) — new URL()
415
+ // with a leading-slash path would drop it. Mirrors src/cli/pr-validate.js.
416
+ const baseUrl = String(base).replace(/\/$/, '');
400
417
  for (const route of affectedRoutes) {
401
- const url = new URL(route.path, base).href;
418
+ const routePath = String(route.path ?? '/').startsWith('/') ? route.path : `/${route.path}`;
419
+ const url = `${baseUrl}${routePath}`;
402
420
  const res = await handleAudit({ url, critical: route.critical ?? false });
403
421
  const data = JSON.parse(res.content[0].text);
404
422
  allFindings.push(...(data.findings ?? []));
@@ -447,7 +465,7 @@ async function handleLastReport() {
447
465
  // ── Server bootstrap ──────────────────────────────────────────────────────────
448
466
 
449
467
  const server = new Server(
450
- { name: 'argus', version: '9.6.6' },
468
+ { name: 'argus', version: pkg.version },
451
469
  { capabilities: { tools: {} } },
452
470
  );
453
471
 
@@ -370,54 +370,13 @@ function analyzeNetworkPerformance(perfEntries, pageUrl) {
370
370
  return bugs;
371
371
  }
372
372
 
373
- // ── Performance Budgets ────────────────────────────────────────────────────────
374
-
375
- async function checkPerformanceBudgets(browser, url) {
376
- const violations = [];
377
-
378
- try {
379
- await browser.startTrace();
380
- await new Promise(r => setTimeout(r, 3000));
381
- const trace = await browser.stopTrace();
382
- const insights = await browser.analyzeInsight({ insightSetId: trace?.insightSetId ?? trace?.id ?? trace });
383
-
384
- const metrics = insights?.metrics ?? insights?.performanceMetrics ?? {};
385
-
386
- const checks = [
387
- { key: 'LCP', value: metrics.largestContentfulPaint ?? metrics.LCP, budget: thresholds.perf.LCP, unit: 'ms' },
388
- { key: 'CLS', value: metrics.cumulativeLayoutShift ?? metrics.CLS, budget: thresholds.perf.CLS, unit: '' },
389
- { key: 'FID', value: metrics.totalBlockingTime ?? metrics.TBT ?? metrics.FID, budget: thresholds.perf.FID, unit: 'ms' },
390
- { key: 'TTFB', value: metrics.timeToFirstByte ?? metrics.TTFB, budget: thresholds.perf.TTFB, unit: 'ms' },
391
- ];
392
-
393
- for (const { key, value, budget, unit } of checks) {
394
- if (value == null) continue;
395
- if (value > budget) {
396
- violations.push({
397
- type: 'performance_budget',
398
- metric: key,
399
- value: `${value}${unit}`,
400
- budget: `${budget}${unit}`,
401
- message: `Performance budget exceeded: ${key} = ${value}${unit} (budget: ${budget}${unit})`,
402
- severity: 'warning',
403
- url,
404
- });
405
- }
406
- }
407
- } catch (err) {
408
- logger.warn(`[ARGUS] Performance trace skipped for ${url}: ${err.message}`);
409
- }
410
-
411
- return violations;
412
- }
413
-
414
373
  // ── Cheap Crawl (called ×2 for flakiness detection) ───────────────────────────
415
374
 
416
375
  /**
417
376
  * Cheap detections for one route.
418
377
  * Runs: console, network, JS errors, blank page, API frequency, contracts,
419
378
  * SEO, security, content, CSS, debugger statements, duplicate ids, screenshot.
420
- * Does NOT run: Lighthouse, perf budgets, network perf, redirect chain, broken links, cache headers.
379
+ * Does NOT run: Lighthouse, network perf, redirect chain, broken links, cache headers.
421
380
  */
422
381
  export async function crawlRouteCheap(route, baseUrl, mcp) {
423
382
  const browser = new CdpBrowserAdapter(mcp);
@@ -757,8 +716,11 @@ export async function crawlRouteCheap(route, baseUrl, mcp) {
757
716
 
758
717
  /**
759
718
  * Expensive/deterministic analyzers for one route — called ONCE per route.
760
- * Runs: network perf, redirect chain, perf budgets, Lighthouse,
719
+ * Runs: network perf, redirect chain, Lighthouse,
761
720
  * broken internal links, cache headers.
721
+ * (Core Web Vitals — LCP/CLS/TTFB — are emitted by the web-vitals-analyzer
722
+ * registerExpensive plugin, which is headless-compatible; the old trace-based
723
+ * perf-budget path was removed as dead + redundant.)
762
724
  */
763
725
  export async function crawlRouteExpensive(route, baseUrl, mcp) {
764
726
  const browser = new CdpBrowserAdapter(mcp);
@@ -805,9 +767,6 @@ export async function crawlRouteExpensive(route, baseUrl, mcp) {
805
767
  logger.warn(`[ARGUS] Redirect chain check skipped for ${url}: ${err.message}`);
806
768
  }
807
769
 
808
- // Performance budget check
809
- errors.push(...(await checkPerformanceBudgets(browser, url)));
810
-
811
770
  // Full Lighthouse audit (capped at LIGHTHOUSE_TIMEOUT_MS to prevent indefinite hang)
812
771
  errors.push(...(await Promise.race([
813
772
  checkLighthouse(browser, url),
@@ -298,6 +298,13 @@ function classifyNetworkReq(req, url) {
298
298
  * the interval-based runWatchMode() entry point.
299
299
  */
300
300
  export class WatchSession {
301
+ // Long-run safety caps: a watch session left running for hours against an app
302
+ // with cache-busted polling URLs would otherwise grow the dedup sets without
303
+ // bound. When a set exceeds its cap the oldest fifth is evicted (Sets iterate
304
+ // in insertion order) — worst case a very old message is re-reported once.
305
+ static MAX_SEEN_KEYS = 5000;
306
+ static MAX_ALL_FINDINGS = 2000;
307
+
301
308
  constructor(browser, baseUrl) {
302
309
  this._browser = browser;
303
310
  this._baseUrl = baseUrl;
@@ -306,6 +313,14 @@ export class WatchSession {
306
313
  this._allFindings = [];
307
314
  }
308
315
 
316
+ /** Evict the oldest 20% of a dedup set once it exceeds the cap. */
317
+ static _trimSeen(set) {
318
+ if (set.size <= WatchSession.MAX_SEEN_KEYS) return;
319
+ const drop = Math.floor(WatchSession.MAX_SEEN_KEYS / 5);
320
+ const it = set.values();
321
+ for (let i = 0; i < drop; i++) set.delete(it.next().value);
322
+ }
323
+
309
324
  /**
310
325
  * Run one poll cycle.
311
326
  *
@@ -350,6 +365,11 @@ export class WatchSession {
350
365
  findings.push(...analyzeSecurityNetwork(newNetwork, this._baseUrl));
351
366
 
352
367
  this._allFindings.push(...findings);
368
+ if (this._allFindings.length > WatchSession.MAX_ALL_FINDINGS) {
369
+ this._allFindings = this._allFindings.slice(-WatchSession.MAX_ALL_FINDINGS);
370
+ }
371
+ WatchSession._trimSeen(this._seenConsole);
372
+ WatchSession._trimSeen(this._seenNetwork);
353
373
  return { findings, newConsole, newNetwork };
354
374
  }
355
375
 
@@ -125,6 +125,32 @@ function loadSchema(contract) {
125
125
  return null;
126
126
  }
127
127
 
128
+ /**
129
+ * Extract and JSON-parse the response body from a get_network_request result.
130
+ *
131
+ * chrome-devtools-mcp returns the request detail as markdown text with the
132
+ * body under a "### Response Body" section — the dominant production shape.
133
+ * Structured shapes ({ responseBody } / { body }) are kept for legacy clients.
134
+ *
135
+ * @param {any} raw - Raw value returned by browser.getNetworkRequest()
136
+ * @returns {any|null} Parsed JSON body, or null when absent
137
+ * @throws {SyntaxError} when a body section exists but is not valid JSON
138
+ */
139
+ export function extractResponseBody(raw) {
140
+ if (raw == null) return null;
141
+ if (typeof raw === 'object') {
142
+ const text = raw.responseBody ?? raw.body ?? null;
143
+ if (text == null) return null;
144
+ return typeof text === 'string' ? JSON.parse(text) : text;
145
+ }
146
+ const text = String(raw);
147
+ const m = text.match(/### Response Body\s*\n([\s\S]*?)(?=\n###? |$)/);
148
+ if (!m) return null;
149
+ const section = m[1].trim();
150
+ if (!section) return null;
151
+ return JSON.parse(section);
152
+ }
153
+
128
154
  /**
129
155
  * Validate captured network requests against apiContracts[].
130
156
  * For each request that matches a contract, fetches the response body via
@@ -153,8 +179,7 @@ export async function validateApiContracts(networkReqs, browser, contracts, page
153
179
  let body = null;
154
180
  try {
155
181
  const raw = await browser.getNetworkRequest(req.id ?? req.requestId);
156
- const text = raw?.responseBody ?? raw?.body ?? null;
157
- if (text) body = JSON.parse(text);
182
+ body = extractResponseBody(raw);
158
183
  } catch {
159
184
  continue; // body unavailable — skip validation for this request
160
185
  }
@@ -181,11 +181,14 @@ export async function createMcpClient() {
181
181
  // MCP returns { content: [{ type, text|data }] } — extract the value
182
182
  const content = result?.content;
183
183
  if (Array.isArray(content) && content.length > 0) {
184
- const item = content[0];
185
- if (item.type === 'image') {
186
- // take_screenshot returns base64 image data return in a shape callers expect
187
- return { data: item.data, mimeType: item.mimeType ?? 'image/png' };
184
+ // take_screenshot returns [text caption, image] — the image is NOT content[0],
185
+ // so scan the whole array for it. Reading only content[0] returned the caption
186
+ // string and starved every screenshot consumer of image data.
187
+ const img = content.find(c => c.type === 'image');
188
+ if (img) {
189
+ return { data: img.data, mimeType: img.mimeType ?? 'image/png' };
188
190
  }
191
+ const item = content[0];
189
192
  if (item.type === 'text') {
190
193
  const text = item.text;
191
194
  // chrome-devtools-mcp wraps evaluate_script results in a markdown code block:
@@ -55,3 +55,23 @@ export function parseNetworkReqResponse(raw) {
55
55
  }
56
56
  return reqs;
57
57
  }
58
+
59
+ /**
60
+ * Parse the text response from list_pages.
61
+ * Format: "## Pages\n1: http://host/page.html [selected]\n2: about:blank"
62
+ * The numeric prefix is the pageId that select_page expects (as a number).
63
+ * @param {any} raw - Raw value returned by the MCP tool
64
+ * @returns {Array<{ id: number, url: string, selected: boolean }>}
65
+ */
66
+ export function parseListPagesResponse(raw) {
67
+ if (!raw) return [];
68
+ if (Array.isArray(raw)) return raw;
69
+ if (typeof raw !== 'string') return [];
70
+ const pages = [];
71
+ const re = /^(\d+):\s+(\S+)(\s+\[selected\])?\s*$/gm;
72
+ let m;
73
+ while ((m = re.exec(raw)) !== null) {
74
+ pages.push({ id: Number(m[1]), url: m[2], selected: Boolean(m[3]) });
75
+ }
76
+ return pages;
77
+ }
@@ -7,8 +7,16 @@
7
7
  *
8
8
  * Pure functions + one async fetch — no Chrome, no MCP, no AI verdict.
9
9
  * AI verdict logic ships separately in the private argus-pro repo.
10
+ *
11
+ * This module is imported by the MCP server — nothing here may write to
12
+ * stdout (reserved for JSON-RPC). CI annotations are emitted by the CLI
13
+ * entry point (src/cli/pr-validate.js), which owns stdout.
10
14
  */
11
15
 
16
+ import { childLogger } from './logger.js';
17
+
18
+ const logger = childLogger('pr-diff-analyzer');
19
+
12
20
  /**
13
21
  * Parse a GitHub PR URL into its owner/repo/prNumber components.
14
22
  *
@@ -59,7 +67,7 @@ export async function fetchPrFiles(prUrl, githubToken) {
59
67
  }
60
68
 
61
69
  if (allFiles.length >= 300) {
62
- console.log('::warning::PR has 300+ changed files — Argus analyzed the first 300. Routes affected by later files may be missed.');
70
+ logger.warn('[ARGUS] PR has 300+ changed files — Argus analyzed the first 300. Routes affected by later files may be missed.');
63
71
  }
64
72
 
65
73
  return allFiles;
@@ -56,13 +56,19 @@ export function getRecentChanges(repoDir = process.env.ARGUS_SOURCE_DIR || proce
56
56
  const changes = [];
57
57
  let current = null;
58
58
  for (const line of out.split('\n')) {
59
- const trimmed = line.trimEnd();
60
- if (!trimmed) continue;
61
- if (trimmed.includes('\t')) {
62
- const [hash, ...subjectParts] = trimmed.split('\t');
59
+ // Detect commit lines on the RAW line — an empty commit subject leaves a
60
+ // trailing tab ("abc1234\t") that trimEnd() would strip, misclassifying
61
+ // the hash as a file path. File lines never contain raw tabs: git quotes
62
+ // paths with special characters (core.quotePath octal escapes).
63
+ if (line.includes('\t')) {
64
+ const [hash, ...subjectParts] = line.trimEnd().split('\t');
63
65
  current = { hash, subject: subjectParts.join('\t'), files: [] };
64
66
  changes.push(current);
65
- } else if (current) {
67
+ continue;
68
+ }
69
+ const trimmed = line.trimEnd();
70
+ if (!trimmed) continue;
71
+ if (current) {
66
72
  // Git emits paths with forward slashes on every platform
67
73
  current.files.push(trimmed);
68
74
  }