anvil-engineering-workbench 1.0.5 → 1.0.7

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.
@@ -31,8 +31,12 @@ import { buildExperimentHistory } from "./experiment-history.js";
31
31
  import { createReplayRun, createTaskRetryRun } from "./run-replay.js";
32
32
  import { diagnoseProvider } from "./provider-diagnostics.js";
33
33
  import { createRunFromWorkflow, listWorkflows, loadWorkflow, saveWorkflow } from "./workflow-store.js";
34
+ import { advanceRun, DemoAgentProvider } from "./orchestrator.js";
34
35
  import { cleanProject, undoLastClean } from "./project-cleaner.js";
35
36
  import { runDoctorChecks } from "./doctor.js";
37
+ import { listProjectMemory, addProjectMemory, removeProjectMemory } from "./project-memory.js";
38
+ import { listAdrs, createAdr, syncMemoryToAdrs } from "./adr-engine.js";
39
+ import { scanProjectSecurity, applySecurityFixes } from "./security-scanner.js";
36
40
  // --- SSE broadcast state ---
37
41
  const sseClients = new Set();
38
42
  let heartbeatInterval = null;
@@ -361,13 +365,13 @@ body{
361
365
  <div class="mark">A.</div>
362
366
  <div>
363
367
  <strong>ANVIL</strong>
364
- <small>THE AI ENGINEERING WORKBENCH · v1.0.5</small>
368
+ <small>THE AI ENGINEERING WORKBENCH · v1.0.7</small>
365
369
  </div>
366
370
  </div>
367
371
  <div class="header-actions">
368
372
  <label class="showcase-pill" title="Toggle between pre-populated showcase simulation and raw local project data">
369
- <input type="checkbox" id="showcaseToggle" checked>
370
- <span>✨ Showcase Telemetry</span>
373
+ <input type="checkbox" id="showcaseToggle">
374
+ <span>✨ Showcase Telemetry (Demo)</span>
371
375
  </label>
372
376
  <button class="btn btn-cyan" id="quickDoctorBtn">⚡ Doctor Check</button>
373
377
  <button class="btn btn-primary" id="quickCleanBtn">🧹 Self-Healing Scan</button>
@@ -377,16 +381,16 @@ body{
377
381
 
378
382
  <nav class="tab-nav">
379
383
  <button class="tab-btn active" data-tab="tab-overview">📊 Overview & Health</button>
380
- <button class="tab-btn" data-tab="tab-cleaner">⚡ Self-Healing & Cleaner (v1.0.5)</button>
384
+ <button class="tab-btn" data-tab="tab-cleaner">⚡ Self-Healing & Security (v1.0.7)</button>
381
385
  <button class="tab-btn" data-tab="tab-agents">🤖 Agents & Workflow Studio</button>
382
386
  <button class="tab-btn" data-tab="tab-architecture">🗺️ Architecture & Graph</button>
383
387
  <button class="tab-btn" data-tab="tab-benchmarks">🔬 Benchmarks & Evaluation</button>
384
388
  <button class="tab-btn" data-tab="tab-workspace">🔍 Workspace & Search</button>
385
389
  </nav>
386
390
 
387
- <div id="showcaseNotice" class="showcase-banner">
391
+ <div id="showcaseNotice" class="showcase-banner" style="display:none">
388
392
  <div>
389
- <b>✨ Showcase Telemetry Mode Active:</b> <span>Displaying realistic multi-agent execution runs, benchmark matrices, token budgets, and verification trails so you can explore ANVIL without waiting to collect runs. Toggle switch above to see only raw local data.</span>
393
+ <b>⚠️ DEMO MODE — Synthetic Showcase Telemetry:</b> <span>Displaying simulated multi-agent execution runs, benchmark matrices, token budgets, and verification trails for demonstration. Toggle switch above off to view only raw local workspace data.</span>
390
394
  </div>
391
395
  </div>
392
396
 
@@ -452,12 +456,37 @@ body{
452
456
  <div id="verificationPanel" class="list"><div class="loading">Loading verification history…</div></div>
453
457
  </div>
454
458
  </section>
459
+
460
+ <section class="section card">
461
+ <div class="section-head">
462
+ <h2>Project Memory & Architectural Decisions</h2>
463
+ <div class="actions">
464
+ <span class="pill pill-cyan">CONTEXT STORE</span>
465
+ <button class="btn btn-cyan" id="syncMemoryToAdrBtn">⚡ Sync to ADRs</button>
466
+ <button class="btn" id="refreshMemory">Refresh memory</button>
467
+ </div>
468
+ </div>
469
+ <p class="run-meta">Durable project constraints, architectural decisions, and preferences that guide specialist agents and IDE harness assistants.</p>
470
+ <div style="display:flex;gap:8px;margin:12px 0;flex-wrap:wrap">
471
+ <select id="newMemoryKind" class="btn" style="padding:6px 12px">
472
+ <option value="decision">Decision</option>
473
+ <option value="architecture">Architecture</option>
474
+ <option value="constraint">Constraint</option>
475
+ <option value="preference">Preference</option>
476
+ <option value="fact">Fact</option>
477
+ </select>
478
+ <input type="text" id="newMemoryContent" placeholder="e.g. Always use Vitest for unit tests; require --verify on clean." style="flex:1;min-width:260px;background:var(--bg-card);border:1px solid var(--border);border-radius:6px;padding:6px 12px;color:var(--text);font-family:inherit;font-size:13px">
479
+ <input type="text" id="newMemoryTags" placeholder="tags (comma separated)" style="width:180px;background:var(--bg-card);border:1px solid var(--border);border-radius:6px;padding:6px 12px;color:var(--text);font-family:inherit;font-size:13px">
480
+ <button class="btn btn-primary" id="saveMemoryBtn">+ Save Decision</button>
481
+ </div>
482
+ <div id="memoryList" class="list"><div class="loading">Loading project memory…</div></div>
483
+ </section>
455
484
  </div>
456
485
 
457
- <!-- ==================== TAB 2: SELF-HEALING & CLEANER (v1.0.5) ==================== -->
486
+ <!-- ==================== TAB 2: SELF-HEALING, CLEANER & SECURITY (v1.0.7) ==================== -->
458
487
  <div id="tab-cleaner" class="tab-pane">
459
488
  <section class="hero">
460
- <div class="eyebrow">ANVIL v1.0.5 SELF-HEALING ENGINE</div>
489
+ <div class="eyebrow">ANVIL v1.0.7 SELF-HEALING & SECURITY ENGINE</div>
461
490
  <h1>Zero-Fear Workspace Cleaner & Rollback</h1>
462
491
  <p>Automatically eliminates junk clutter and fixes unused imports across TypeScript, JavaScript and Python with deterministic self-healing rollback verification.</p>
463
492
  </section>
@@ -519,6 +548,20 @@ body{
519
548
  </div>
520
549
  </div>
521
550
  </section>
551
+
552
+ <section class="section card">
553
+ <div class="section-head">
554
+ <h2>Repository Security & Secret Scanner</h2>
555
+ <div class="actions">
556
+ <span class="pill pill-emerald" id="securityStatusPill">SECURE</span>
557
+ <button class="btn btn-primary" id="autoFixSecurityBtn">🛡️ Auto-Fix Exclusions</button>
558
+ <button class="btn" id="refreshSecurityBtn">Refresh Audit</button>
559
+ </div>
560
+ </div>
561
+ <p class="run-meta">Local-first deep scan for leaked secrets, API keys, risky shell scripts, unencrypted dependencies, and unignored .env files.</p>
562
+ <div id="securitySummary" class="grid" style="margin:12px 0"></div>
563
+ <div id="securityFindings" class="list"><div class="loading">Scanning repository for secrets…</div></div>
564
+ </section>
522
565
  </div>
523
566
 
524
567
  <!-- ==================== TAB 3: AGENTS & WORKFLOW STUDIO ==================== -->
@@ -599,7 +642,7 @@ body{
599
642
  <div class="section-head"><h3 style="margin:0">Pipeline canvas</h3><span class="pill" id="workflowTaskCount">0 TASKS</span></div>
600
643
  <div id="workflowCanvas" class="activity"><div class="empty">Add a specialist task to start composing your pipeline.</div></div>
601
644
  <div class="actions"><button class="btn" id="applyWorkflowLinks">Apply selected links</button></div>
602
- <div class="actions"><button class="btn btn-primary" id="saveWorkflow">Save workflow</button><button class="btn btn-cyan" id="createWorkflowRun">Create draft run</button></div>
645
+ <div class="actions"><button class="btn btn-primary" id="saveWorkflow">Save workflow</button><button class="btn btn-cyan" id="createWorkflowRun">Create draft run</button><button class="btn btn-emerald" id="executeWorkflowRun">⚡ Simulate Pipeline Execution</button></div>
603
646
  <div id="workflowMessage" class="run-meta" aria-live="polite"></div>
604
647
  <div class="section-head" style="margin-top:18px"><h3 style="margin:0">Saved workflows</h3><button class="btn" id="refreshWorkflows">Refresh</button></div>
605
648
  <div id="savedWorkflows" class="activity"><div class="loading">Loading reusable workflows…</div></div>
@@ -754,6 +797,27 @@ body{
754
797
  <div id="timelineHistory" class="activity"></div>
755
798
  <div id="timelineNotes" class="run-meta"></div>
756
799
  </section>
800
+
801
+ <section class="section card">
802
+ <div class="section-head">
803
+ <h2>Architecture Decision Records (ADR Engine)</h2>
804
+ <div class="actions">
805
+ <span class="pill pill-cyan">DOCS/ADR</span>
806
+ <button class="btn btn-cyan" id="syncAdrBtn">⚡ Sync Memory to ADRs</button>
807
+ <button class="btn" id="refreshAdrBtn">Refresh ADRs</button>
808
+ </div>
809
+ </div>
810
+ <p class="run-meta">Version-controlled Architectural Decision Records stored locally in <code>docs/adr/</code>. Kept in sync with ANVIL project memory.</p>
811
+ <div style="display:flex;gap:8px;margin:12px 0;flex-wrap:wrap">
812
+ <input type="text" id="newAdrTitle" placeholder="e.g. Adopt Vitest for Unit and Integration Testing" style="flex:1;min-width:260px;background:var(--bg-card);border:1px solid var(--border);border-radius:6px;padding:6px 12px;color:var(--text);font-family:inherit;font-size:13px">
813
+ <select id="newAdrStatus" class="btn" style="padding:6px 12px">
814
+ <option value="Accepted">Accepted</option>
815
+ <option value="Proposed">Proposed</option>
816
+ </select>
817
+ <button class="btn btn-primary" id="createAdrBtn">+ New ADR</button>
818
+ </div>
819
+ <div id="adrList" class="list"><div class="loading">Loading Architecture Decision Records…</div></div>
820
+ </section>
757
821
  </div>
758
822
 
759
823
  <!-- ==================== TAB 5: BENCHMARKS & EVALUATION LAB ==================== -->
@@ -965,7 +1029,7 @@ body{
965
1029
  </div>
966
1030
 
967
1031
  <footer class="footer">
968
- <span>ANVIL v1.0.5 · THE AI ENGINEERING WORKBENCH</span>
1032
+ <span>ANVIL v1.0.7 · THE AI ENGINEERING WORKBENCH</span>
969
1033
  <span>Read-only local dashboard · Telemetry stays on your machine</span>
970
1034
  </footer>
971
1035
 
@@ -976,7 +1040,7 @@ const el=id=>document.getElementById(id);
976
1040
  const on=(id,event,handler)=>{const node=el(id);if(node)node.addEventListener(event,handler);};
977
1041
  const esc=value=>String(value??"").replace(/[&<>"']/g,c=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[c]));
978
1042
 
979
- let isShowcase = true;
1043
+ let isShowcase = false;
980
1044
  const showcaseToggle = el("showcaseToggle");
981
1045
  const showcaseNotice = el("showcaseNotice");
982
1046
  if(showcaseToggle){
@@ -1494,6 +1558,115 @@ async function runCleanerPreview(){
1494
1558
  }catch(err){output.innerHTML = '<div class="error">'+esc(err.message)+'</div>';}
1495
1559
  }
1496
1560
 
1561
+ async function loadMemory(){
1562
+ try{
1563
+ const res=await api("/api/memory");
1564
+ let entries = res.entries || [];
1565
+ if(!entries.length && isShowcase){
1566
+ entries = [
1567
+ { id: "mem-showcase-1", kind: "architecture", content: "ANVIL uses local-first AST parsing for polyglot module mapping across 6 languages.", tags: ["ast", "polyglot"], updatedAt: new Date().toISOString() },
1568
+ { id: "mem-showcase-2", kind: "decision", content: "Every code fix and cleaner run requires automated test gate verification (--verify) with instant rollback.", tags: ["safety", "rollback"], updatedAt: new Date().toISOString() },
1569
+ { id: "mem-showcase-3", kind: "constraint", content: "Never forward arbitrary environment secrets or credentials to third-party providers or tools.", tags: ["security"], updatedAt: new Date().toISOString() }
1570
+ ];
1571
+ }
1572
+ el("memoryList").innerHTML = entries.length ? entries.map(item => {
1573
+ const kindClass = item.kind === "decision" ? "pill-emerald" : item.kind === "constraint" ? "pill-accent" : "pill-cyan";
1574
+ return '<div class="rowitem" style="align-items:flex-start"><div><div style="display:flex;gap:6px;align-items:center;margin-bottom:4px"><span class="pill ' + kindClass + '">' + esc(item.kind.toUpperCase()) + '</span>' + (item.tags||[]).map(t => '<span class="pill" style="font-size:10px">#' + esc(t) + '</span>').join('') + '<span class="run-meta" style="margin-left:8px">' + esc(item.id) + '</span></div><div style="font-size:13px;line-height:1.4">' + esc(item.content) + '</div></div>' + (!item.id.startsWith("mem-showcase") ? '<button class="btn" style="padding:4px 8px;font-size:11px" onclick="deleteMemoryEntry(\'' + esc(item.id) + '\')">Remove</button>' : '') + '</div>';
1575
+ }).join("") : '<div class="empty">No project memory entries saved yet. Add a decision or constraint above to guide your agents!</div>';
1576
+ }catch(e){el("memoryList").innerHTML='<div class="error">'+esc(e.message)+'</div>';}
1577
+ }
1578
+
1579
+ async function deleteMemoryEntry(id){
1580
+ try{
1581
+ await fetch("/api/memory/delete",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({id})});
1582
+ loadMemory();
1583
+ }catch(e){alert("Failed to remove memory: "+e.message);}
1584
+ }
1585
+
1586
+ async function loadAdrs(){
1587
+ try{
1588
+ const res = await api("/api/adrs");
1589
+ let adrs = res.adrs || [];
1590
+ if(!adrs.length && isShowcase){
1591
+ adrs = [
1592
+ { id: "0001", number: 1, title: "Record architecture decisions", status: "Accepted", date: new Date().toISOString().slice(0, 10), filename: "0001-record-architecture-decisions.md" },
1593
+ { id: "0002", number: 2, title: "Local-first AST analysis for zero-telemetry polyglot code intelligence", status: "Accepted", date: new Date().toISOString().slice(0, 10), filename: "0002-local-first-ast-analysis.md" },
1594
+ { id: "0003", number: 3, title: "Deterministic automated test gate with instant rollback on clean", status: "Accepted", date: new Date().toISOString().slice(0, 10), filename: "0003-deterministic-test-gate.md" }
1595
+ ];
1596
+ }
1597
+ const container = el("adrList");
1598
+ if(!container) return;
1599
+ container.innerHTML = adrs.length ? adrs.map(item => {
1600
+ const statusPill = item.status === "Accepted" ? "pill-emerald" : item.status === "Proposed" ? "pill-cyan" : "pill-accent";
1601
+ return '<div class="rowitem"><div><div style="display:flex;gap:6px;align-items:center;margin-bottom:4px"><span class="pill ' + statusPill + '">' + esc(item.status.toUpperCase()) + '</span><span class="pill" style="font-size:10px">ADR-' + esc(item.id) + '</span><span class="run-meta">' + esc(item.date) + '</span></div><div style="font-size:13px;font-weight:600">' + esc(item.title) + '</div><div class="run-meta" style="font-size:11px">' + esc(item.filename) + '</div></div></div>';
1602
+ }).join("") : '<div class="empty">No Architecture Decision Records found. Click "+ New ADR" or "Sync Memory to ADRs" to initialize docs/adr/</div>';
1603
+ }catch(e){
1604
+ const container = el("adrList");
1605
+ if(container) container.innerHTML = '<div class="error">' + esc(e.message) + '</div>';
1606
+ }
1607
+ }
1608
+
1609
+ async function handleCreateAdr(){
1610
+ const titleEl = el("newAdrTitle");
1611
+ const statusEl = el("newAdrStatus");
1612
+ const title = titleEl ? titleEl.value.trim() : "";
1613
+ if(!title) return alert("Please enter an ADR title.");
1614
+ const status = statusEl ? statusEl.value : "Accepted";
1615
+ try{
1616
+ await fetch("/api/adrs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({title,status})});
1617
+ if(titleEl) titleEl.value = "";
1618
+ loadAdrs();
1619
+ }catch(e){alert("Failed to create ADR: "+e.message);}
1620
+ }
1621
+
1622
+ async function handleSyncAdrs(){
1623
+ try{
1624
+ const res = await fetch("/api/adrs/sync",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({})});
1625
+ const data = await res.json();
1626
+ alert(data.syncedCount > 0 ? "Synced " + data.syncedCount + " decisions to docs/adr/!" : "All project memory decisions already synced!");
1627
+ loadAdrs();
1628
+ }catch(e){alert("Failed to sync ADRs: "+e.message);}
1629
+ }
1630
+
1631
+ async function loadSecurityAudit(){
1632
+ try{
1633
+ const res = await api("/api/security");
1634
+ const summaryEl = el("securitySummary");
1635
+ const findingsEl = el("securityFindings");
1636
+ const pill = el("securityStatusPill");
1637
+ if(!summaryEl || !findingsEl) return;
1638
+
1639
+ if(pill){
1640
+ if(res.passed){
1641
+ pill.className = "pill pill-emerald";
1642
+ pill.textContent = "SECURE";
1643
+ }else{
1644
+ pill.className = "pill pill-accent";
1645
+ pill.textContent = res.summary.critical > 0 ? "CRITICAL RISK" : "HIGH RISK";
1646
+ }
1647
+ }
1648
+
1649
+ summaryEl.innerHTML = '<div class="card card-highlight"><div class="metric-label">Security Status</div><div class="metric" style="color:' + (res.passed ? 'var(--emerald)' : 'var(--accent)') + '">' + (res.passed ? 'SECURE' : 'ACTION REQUIRED') + '</div><div class="metric-sub">' + res.findings.length + ' total findings</div></div><div class="card"><div class="metric-label">Critical Secrets</div><div class="metric" style="color:var(--accent)">' + res.summary.critical + '</div><div class="metric-sub">API keys, tokens, keys</div></div><div class="card"><div class="metric-label">High Severity</div><div class="metric" style="color:var(--amber,#f59e0b)">' + res.summary.high + '</div><div class="metric-sub">Scripts, unencrypted deps</div></div><div class="card"><div class="metric-label">Scanned Scope</div><div class="metric" style="color:var(--cyan)">' + res.scannedFiles + '</div><div class="metric-sub">Files in ' + res.durationMs + 'ms</div></div>';
1650
+
1651
+ findingsEl.innerHTML = res.findings.length ? res.findings.map(f => {
1652
+ const sevClass = f.severity === "critical" ? "pill-accent" : f.severity === "high" ? "pill-amber" : "pill-cyan";
1653
+ return '<div class="rowitem"><div><div style="display:flex;gap:6px;align-items:center;margin-bottom:4px"><span class="pill ' + sevClass + '">' + esc(f.severity.toUpperCase()) + '</span><span class="pill" style="font-size:10px">' + esc(f.category) + '</span><span class="run-meta">' + esc(f.file + (f.line ? ':' + f.line : '')) + '</span></div><div style="font-size:13px;font-weight:600">' + esc(f.description) + '</div>' + (f.snippet ? '<div class="run-meta" style="font-family:monospace;font-size:11px">Snippet: ' + esc(f.snippet) + '</div>' : '') + '<div class="run-meta" style="font-size:11px;color:var(--text-muted)">Remediation: ' + esc(f.remediation) + '</div></div></div>';
1654
+ }).join("") : '<div class="empty" style="color:var(--emerald)">✓ Clean audit: No hardcoded secrets, dangerous scripts, or exposed credentials detected.</div>';
1655
+ }catch(e){
1656
+ const findingsEl = el("securityFindings");
1657
+ if(findingsEl) findingsEl.innerHTML = '<div class="error">' + esc(e.message) + '</div>';
1658
+ }
1659
+ }
1660
+
1661
+ async function handleAutoFixSecurity(){
1662
+ try{
1663
+ const res = await fetch("/api/security/fix",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({})});
1664
+ const data = await res.json();
1665
+ alert(data.fixedCount > 0 ? "Applied " + data.fixedCount + " security fixes:\n" + data.details.join("\n") : "No pending auto-fixable exclusions.");
1666
+ loadSecurityAudit();
1667
+ }catch(e){alert("Failed to apply security fixes: "+e.message);}
1668
+ }
1669
+
1497
1670
  on("runCleanDryRunBtn","click",runCleanerPreview);
1498
1671
  on("quickCleanBtn","click",()=>{
1499
1672
  document.querySelectorAll(".tab-btn").forEach(b=>b.classList.remove("active"));
@@ -1713,10 +1886,31 @@ on("createWorkflowRun","click",async()=>{
1713
1886
  try{await fetch("/api/workflows/"+encodeURIComponent(id)+"/run",{method:"POST",headers:{"content-type":"application/json"},body:"{}"});el("workflowMessage").textContent="Created draft run from "+name;loadRuns();}catch(e){el("workflowMessage").textContent=e.message;}
1714
1887
  });
1715
1888
 
1889
+ async function executeWorkflowById(id){
1890
+ const msgEl = el("workflowMessage");
1891
+ if(msgEl) msgEl.innerHTML = '<span style="color:var(--cyan)">⚡ Simulating multi-agent pipeline execution (DemoAgentProvider)...</span>';
1892
+ try{
1893
+ const res = await fetch("/api/workflows/"+encodeURIComponent(id)+"/execute",{method:"POST",headers:{"content-type":"application/json"},body:"{}"});
1894
+ const run = await res.json();
1895
+ if(msgEl) msgEl.innerHTML = '<span style="color:var(--emerald)">✓ Pipeline simulated: ' + esc(run.id) + ' (' + esc(run.status) + ')</span>';
1896
+ loadRuns();
1897
+ loadActivity();
1898
+ if(run.id) inspectRun(run.id);
1899
+ }catch(e){
1900
+ if(msgEl) msgEl.innerHTML = '<span style="color:var(--accent)">Execution failed: ' + esc(e.message) + '</span>';
1901
+ }
1902
+ }
1903
+
1904
+ on("executeWorkflowRun","click",async()=>{
1905
+ const name=el("workflowName").value.trim();if(!name)return alert("Please enter or load a workflow first.");
1906
+ const id=workflowSlug(name);
1907
+ await executeWorkflowById(id);
1908
+ });
1909
+
1716
1910
  async function refreshWorkflows(){
1717
1911
  try{
1718
1912
  const workflows=await api("/api/workflows");
1719
- el("savedWorkflows").innerHTML=workflows.length?workflows.map(w=>'<div class="run"><div class="run-title"><b>'+esc(w.name)+'</b><span class="pill">'+esc(w.tasks.length)+' TASKS</span></div><div class="run-meta">'+esc(w.id)+'</div></div>').join(""):'<div class="empty">No saved workflows yet.</div>';
1913
+ el("savedWorkflows").innerHTML=workflows.length?workflows.map(w=>'<div class="run"><div class="run-title"><b>'+esc(w.name)+'</b><span class="pill">'+esc(w.tasks.length)+' TASKS</span></div><div class="run-meta" style="display:flex;justify-content:space-between;align-items:center"><span>'+esc(w.id)+'</span><button class="btn btn-emerald" style="padding:3px 8px;font-size:11px" onclick="executeWorkflowById(\''+esc(w.id)+'\')">⚡ Simulate Execution</button></div></div>').join(""):'<div class="empty">No saved workflows yet.</div>';
1720
1914
  }catch(e){el("savedWorkflows").innerHTML='<div class="error">'+esc(e.message)+'</div>';}
1721
1915
  }
1722
1916
 
@@ -1785,12 +1979,33 @@ on("exportExperimentHistory","click",()=>{
1785
1979
  }
1786
1980
  });
1787
1981
 
1982
+ on("refreshMemory","click",loadMemory);
1983
+ on("saveMemoryBtn","click",async()=>{
1984
+ const kind=el("newMemoryKind").value;
1985
+ const content=el("newMemoryContent").value.trim();
1986
+ const tags=el("newMemoryTags").value.split(",").map(t=>t.trim()).filter(Boolean);
1987
+ if(!content)return;
1988
+ try{
1989
+ await fetch("/api/memory",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({kind,content,tags})});
1990
+ el("newMemoryContent").value="";
1991
+ el("newMemoryTags").value="";
1992
+ loadMemory();
1993
+ }catch(e){alert("Failed to save decision: "+e.message);}
1994
+ });
1995
+
1996
+ on("syncMemoryToAdrBtn","click",handleSyncAdrs);
1997
+ on("refreshAdrBtn","click",loadAdrs);
1998
+ on("syncAdrBtn","click",handleSyncAdrs);
1999
+ on("createAdrBtn","click",handleCreateAdr);
2000
+ on("autoFixSecurityBtn","click",handleAutoFixSecurity);
2001
+ on("refreshSecurityBtn","click",loadSecurityAudit);
2002
+
1788
2003
  function reloadAllViews(){
1789
2004
  loadOverview();loadAgents();loadRuns();loadActivity();loadObservability();
1790
2005
  loadEvaluationHistory();loadBenchmarkHistory();loadBenchmarkRegression();loadAgentPerformance();
1791
2006
  loadSkillExperiments();loadExperimentHistory();loadAgentOptimization();loadAgentIntelligence();
1792
2007
  loadHealth();loadRegression();loadReviews();loadQuality();loadVerifications();
1793
- loadCleanerBackups();
2008
+ loadCleanerBackups();loadMemory();loadAdrs();loadSecurityAudit();
1794
2009
  }
1795
2010
 
1796
2011
  reloadAllViews();
@@ -1824,7 +2039,7 @@ export async function startDashboard(options) {
1824
2039
  response.writeHead(405, { "content-type": "application/json" }).end(JSON.stringify({ error: "Method not allowed." }));
1825
2040
  return;
1826
2041
  }
1827
- if (request.method === "POST" && (requestUrl.pathname === "/api/workflows" || requestUrl.pathname === "/api/clean/run" || requestUrl.pathname === "/api/clean/undo" || requestUrl.pathname === "/api/config-files" || requestUrl.pathname === "/api/config-snapshots" || /^\/api\/providers\/(?:openai|anthropic|google|ollama)\/diagnose$/.test(requestUrl.pathname) || requestUrl.pathname === "/api/config-releases" || /^\/api\/config-releases\/rel-[a-f0-9]{12}\/(?:approve|reject)$/.test(requestUrl.pathname) || requestUrl.pathname.endsWith("/run") && requestUrl.pathname.startsWith("/api/workflows/") || /^\/api\/runs\/[^/]+\/(?:replay|cancel)$/.test(requestUrl.pathname) || /^\/api\/runs\/[^/]+\/tasks\/[^/]+\/retry$/.test(requestUrl.pathname))) {
2042
+ if (request.method === "POST" && (requestUrl.pathname === "/api/memory" || requestUrl.pathname === "/api/memory/delete" || requestUrl.pathname === "/api/adrs" || requestUrl.pathname === "/api/adrs/sync" || requestUrl.pathname === "/api/security/fix" || requestUrl.pathname === "/api/workflows" || requestUrl.pathname === "/api/clean/run" || requestUrl.pathname === "/api/clean/undo" || requestUrl.pathname === "/api/config-files" || requestUrl.pathname === "/api/config-snapshots" || /^\/api\/providers\/(?:openai|anthropic|google|ollama)\/diagnose$/.test(requestUrl.pathname) || requestUrl.pathname === "/api/config-releases" || /^\/api\/config-releases\/rel-[a-f0-9]{12}\/(?:approve|reject)$/.test(requestUrl.pathname) || requestUrl.pathname.endsWith("/run") && requestUrl.pathname.startsWith("/api/workflows/") || requestUrl.pathname.endsWith("/execute") && requestUrl.pathname.startsWith("/api/workflows/") || /^\/api\/runs\/[^/]+\/(?:replay|cancel)$/.test(requestUrl.pathname) || /^\/api\/runs\/[^/]+\/tasks\/[^/]+\/retry$/.test(requestUrl.pathname))) {
1828
2043
  const origin = request.headers.origin;
1829
2044
  if (origin && new URL(origin).host !== request.headers.host) {
1830
2045
  response.writeHead(403, { "content-type": "application/json" }).end(JSON.stringify({ error: "Cross-origin requests are not allowed." }));
@@ -1949,6 +2164,69 @@ export async function startDashboard(options) {
1949
2164
  response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(result));
1950
2165
  return;
1951
2166
  }
2167
+ if (requestUrl.pathname === "/api/memory") {
2168
+ const record = (body && typeof body === "object" ? body : {});
2169
+ const kind = record.kind || "decision";
2170
+ const content = String(record.content || "");
2171
+ const tags = Array.isArray(record.tags) ? record.tags.map(String) : [];
2172
+ const entry = await addProjectMemory(projectPath, { kind: kind, content, tags });
2173
+ response.writeHead(201, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(entry));
2174
+ return;
2175
+ }
2176
+ if (requestUrl.pathname === "/api/memory/delete") {
2177
+ const record = (body && typeof body === "object" ? body : {});
2178
+ const id = String(record.id || "");
2179
+ const success = await removeProjectMemory(projectPath, id);
2180
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ success }));
2181
+ return;
2182
+ }
2183
+ if (requestUrl.pathname === "/api/adrs") {
2184
+ const record = (body && typeof body === "object" ? body : {});
2185
+ const title = String(record.title || "").trim();
2186
+ if (!title)
2187
+ throw new Error("ADR title is required.");
2188
+ const status = record.status || "Accepted";
2189
+ const context = record.context ? String(record.context) : undefined;
2190
+ const decision = record.decision ? String(record.decision) : undefined;
2191
+ const adr = await createAdr(projectPath, title, { status, context, decision });
2192
+ response.writeHead(201, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(adr));
2193
+ return;
2194
+ }
2195
+ if (requestUrl.pathname === "/api/adrs/sync") {
2196
+ const result = await syncMemoryToAdrs(projectPath);
2197
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(result));
2198
+ return;
2199
+ }
2200
+ if (requestUrl.pathname === "/api/security/fix") {
2201
+ const scan = await scanProjectSecurity(projectPath);
2202
+ const result = await applySecurityFixes(projectPath, scan.findings);
2203
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(result));
2204
+ return;
2205
+ }
2206
+ if (requestUrl.pathname.endsWith("/execute") && requestUrl.pathname.startsWith("/api/workflows/")) {
2207
+ const workflowId = requestUrl.pathname.slice("/api/workflows/".length, -"/execute".length);
2208
+ const workflow = await loadWorkflow(projectPath, decodeURIComponent(workflowId));
2209
+ const run = createRunFromWorkflow(workflow);
2210
+ await saveRun(projectPath, run);
2211
+ broadcastEvent("workflow_started", { runId: run.id, workflowName: workflow.name, taskCount: run.tasks.length });
2212
+ const provider = new DemoAgentProvider();
2213
+ const completed = await advanceRun(run, provider, new Set(), {
2214
+ maxConcurrency: 4,
2215
+ onUpdate: async (updatedRun) => {
2216
+ await saveRun(projectPath, updatedRun);
2217
+ broadcastEvent("workflow_update", { runId: updatedRun.id, status: updatedRun.status, tasks: updatedRun.tasks });
2218
+ },
2219
+ onTaskSettled: async (updatedRun, settledTaskId) => {
2220
+ await saveRun(projectPath, updatedRun);
2221
+ const taskRecord = updatedRun.tasks.find(t => t.task.id === settledTaskId);
2222
+ broadcastEvent("workflow_task_settled", { runId: updatedRun.id, taskId: settledTaskId, status: taskRecord?.status, result: taskRecord?.result });
2223
+ }
2224
+ });
2225
+ await saveRun(projectPath, completed);
2226
+ broadcastEvent("workflow_completed", { runId: completed.id, status: completed.status });
2227
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ id: completed.id, status: completed.status, taskCount: completed.tasks.length, tasks: completed.tasks }));
2228
+ return;
2229
+ }
1952
2230
  if (requestUrl.pathname === "/api/workflows") {
1953
2231
  const workflow = await saveWorkflow(projectPath, body);
1954
2232
  response.writeHead(201, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(workflow));
@@ -2447,6 +2725,21 @@ export async function startDashboard(options) {
2447
2725
  response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ snapshots: snapshots.sort((a, b) => b.at.localeCompare(a.at)) }));
2448
2726
  return;
2449
2727
  }
2728
+ if (requestUrl.pathname === "/api/memory") {
2729
+ const entries = await listProjectMemory(projectPath);
2730
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ entries }));
2731
+ return;
2732
+ }
2733
+ if (requestUrl.pathname === "/api/adrs") {
2734
+ const adrs = await listAdrs(projectPath);
2735
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ adrs }));
2736
+ return;
2737
+ }
2738
+ if (requestUrl.pathname === "/api/security") {
2739
+ const report = await scanProjectSecurity(projectPath);
2740
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(report));
2741
+ return;
2742
+ }
2450
2743
  if (requestUrl.pathname === "/api/architecture") {
2451
2744
  const map = await mapArchitecture(projectPath);
2452
2745
  response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(map));