@kenhkl/agent-gate 0.9.1 → 0.9.2
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/dist/dashboard.html +175 -3
- package/dist/shared/storage/db.d.ts +2 -0
- package/dist/shared/storage/db.js +16 -3
- package/dist/v1/cli.js +23 -5
- package/dist/v1/server.js +23 -5
- package/dist/v3/cli.js +23 -5
- package/package.json +1 -1
package/dist/dashboard.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>AgentGate Dashboard</title>
|
|
7
|
-
<style>:root{--bg:#FAFAFA;--card-bg:#fff;--border:#F0F0F0;--text:#1d1d1f;--muted:#8E8E93;--accent:#007AFF;--green:#34C759;--red:#FF3B30;--orange:#FF9500;--yellow:#FFCC00}*{margin:0;padding:0;box-sizing:border-box}body{background:var(--bg);color:var(--text);font:14px/1.5 -apple-system,BlinkMacSystemFont,sans-serif;-webkit-font-smoothing:antialiased;overflow-x:hidden}.header{background:var(--card-bg);border-bottom:1px solid var(--border);padding:10px 16px;display:flex;align-items:center;justify-content:space-between;position:sticky;top:0;z-index:10}.header h1{font-size:15px;font-weight:700}.live-dot{width:7px;height:7px;border-radius:50%;background:var(--green);display:inline-block;margin-right:6px;animation:pulse 2s infinite}@keyframes pulse{0%,100%{opacity:1}50%{opacity:.4}}.grid{display:grid;grid-template-columns:repeat(6,1fr);gap:8px;padding:12px 16px}.card{background:var(--card-bg);border:1px solid var(--border);border-radius:8px;padding:12px}.card .label{font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.5px;font-weight:600}.card .value{font-size:24px;font-weight:700;margin-top:2px}.section{padding:0 16px 12px}.risk-bar{display:flex;height:6px;border-radius:3px;overflow:hidden;background:var(--border);margin-top:4px}.risk-bar div{height:100%}.risk-legend{display:flex;gap:14px;margin-top:4px;font-size:11px;color:var(--muted)}.risk-legend span{display:flex;align-items:center;gap:3px}.risk-dot{width:6px;height:6px;border-radius:2px;display:inline-block}.tabs{display:flex;gap:0;padding:0 16px;border-bottom:1px solid var(--border);margin-bottom:8px}.tab{padding:6px 14px;font-size:12px;font-weight:600;color:var(--muted);cursor:pointer;border-bottom:2px solid transparent;user-select:none}.tab.active{color:var(--accent);border-bottom-color:var(--accent)}.table-wrap{overflow-x:auto;-webkit-overflow-scrolling:touch}table{width:100%;border-collapse:collapse;font-size:11px;white-space:nowrap}th,td{text-align:left;padding:5px 8px;border-bottom:1px solid var(--border)}th{color:var(--muted);font-weight:600;font-size:10px;position:sticky;top:0;background:var(--bg)}td code{background:#F5F5F7;padding:1px 5px;border-radius:3px;font-size:10px}.badge{display:inline-block;padding:1px 6px;border-radius:8px;font-size:10px;font-weight:600}.badge-allow{background:rgba(52,199,89,.12);color:var(--green)}.badge-deny{background:rgba(255,59,48,.12);color:var(--red)}.ag-pagination{display:flex;align-items:center;justify-content:center;gap:8px;padding:10px 14px;font-size:12px;color:var(--muted);background:#FAFAFA;border-top:1px solid var(--border)}.ag-pagination button{padding:4px 12px;border-radius:6px;border:1px solid var(--border);background:transparent;color:var(--text);font-size:12px;cursor:pointer}.ag-pagination button:hover{background:var(--accent);color:#fff;border-color:var(--accent)}.ag-pagination button:disabled{opacity:0.4;cursor:default}.footer{padding:10px 16px;color:var(--muted);font-size:10px;border-top:1px solid var(--border);text-align:center}#timeline-panel,#agents-panel{display:none}.ag-storage-banner{display:none;align-items:center;justify-content:space-between;gap:8px;margin:12px 16px 0;padding:10px 12px;border:1px solid rgba(255,149,0,.35);background:rgba(255,204,0,.14);border-radius:8px;font-size:12px}.ag-storage-banner.show{display:flex}.ag-sb-text{color:var(--text)}.ag-sb-text b{color:var(--orange)}.ag-sb-actions{display:flex;align-items:center;gap:8px;flex:none}.ag-sb-status{font-size:11px;color:var(--muted)}.ag-sb-btn{padding:5px 14px;border-radius:6px;border:1px solid var(--orange);background:var(--orange);color:#fff;font-size:12px;font-weight:600;cursor:pointer;white-space:nowrap}.ag-sb-btn:hover{background:#e08600;border-color:#e08600}.ag-sb-btn:disabled{opacity:.5;cursor:default}</style>
|
|
7
|
+
<style>:root{--bg:#FAFAFA;--card-bg:#fff;--border:#F0F0F0;--text:#1d1d1f;--muted:#8E8E93;--accent:#007AFF;--green:#34C759;--red:#FF3B30;--orange:#FF9500;--yellow:#FFCC00}*{margin:0;padding:0;box-sizing:border-box}body{background:var(--bg);color:var(--text);font:14px/1.5 -apple-system,BlinkMacSystemFont,sans-serif;-webkit-font-smoothing:antialiased;overflow-x:hidden}.header{background:var(--card-bg);border-bottom:1px solid var(--border);padding:10px 16px;display:flex;align-items:center;justify-content:space-between;position:sticky;top:0;z-index:10}.header h1{font-size:15px;font-weight:700}.live-dot{width:7px;height:7px;border-radius:50%;background:var(--green);display:inline-block;margin-right:6px;animation:pulse 2s infinite}@keyframes pulse{0%,100%{opacity:1}50%{opacity:.4}}.grid{display:grid;grid-template-columns:repeat(6,1fr);gap:8px;padding:12px 16px}.card{background:var(--card-bg);border:1px solid var(--border);border-radius:8px;padding:12px}.card .label{font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.5px;font-weight:600}.card .value{font-size:24px;font-weight:700;margin-top:2px}.section{padding:0 16px 12px}.risk-bar{display:flex;height:6px;border-radius:3px;overflow:hidden;background:var(--border);margin-top:4px}.risk-bar div{height:100%}.risk-legend{display:flex;gap:14px;margin-top:4px;font-size:11px;color:var(--muted)}.risk-legend span{display:flex;align-items:center;gap:3px}.risk-dot{width:6px;height:6px;border-radius:2px;display:inline-block}.tabs{display:flex;gap:0;padding:0 16px;border-bottom:1px solid var(--border);margin-bottom:8px}.tab{padding:6px 14px;font-size:12px;font-weight:600;color:var(--muted);cursor:pointer;border-bottom:2px solid transparent;user-select:none}.tab.active{color:var(--accent);border-bottom-color:var(--accent)}.table-wrap{overflow-x:auto;-webkit-overflow-scrolling:touch}table{width:100%;border-collapse:collapse;font-size:11px;white-space:nowrap}th,td{text-align:left;padding:5px 8px;border-bottom:1px solid var(--border)}th{color:var(--muted);font-weight:600;font-size:10px;position:sticky;top:0;background:var(--bg)}td code{background:#F5F5F7;padding:1px 5px;border-radius:3px;font-size:10px}.badge{display:inline-block;padding:1px 6px;border-radius:8px;font-size:10px;font-weight:600}.badge-allow{background:rgba(52,199,89,.12);color:var(--green)}.badge-deny{background:rgba(255,59,48,.12);color:var(--red)}.ag-pagination{display:flex;align-items:center;justify-content:center;gap:8px;padding:10px 14px;font-size:12px;color:var(--muted);background:#FAFAFA;border-top:1px solid var(--border)}.ag-pagination button{padding:4px 12px;border-radius:6px;border:1px solid var(--border);background:transparent;color:var(--text);font-size:12px;cursor:pointer}.ag-pagination button:hover{background:var(--accent);color:#fff;border-color:var(--accent)}.ag-pagination button:disabled{opacity:0.4;cursor:default}.footer{padding:10px 16px;color:var(--muted);font-size:10px;border-top:1px solid var(--border);text-align:center}#timeline-panel,#agents-panel{display:none}.ag-storage-banner{display:none;align-items:center;justify-content:space-between;gap:8px;margin:12px 16px 0;padding:10px 12px;border:1px solid rgba(255,149,0,.35);background:rgba(255,204,0,.14);border-radius:8px;font-size:12px}.ag-storage-banner.show{display:flex}.ag-sb-text{color:var(--text)}.ag-sb-text b{color:var(--orange)}.ag-sb-actions{display:flex;align-items:center;gap:8px;flex:none}.ag-sb-status{font-size:11px;color:var(--muted)}.ag-sb-btn{padding:5px 14px;border-radius:6px;border:1px solid var(--orange);background:var(--orange);color:#fff;font-size:12px;font-weight:600;cursor:pointer;white-space:nowrap}.ag-sb-btn:hover{background:#e08600;border-color:#e08600}.ag-sb-btn:disabled{opacity:.5;cursor:default}.ag-chain-btn{padding:2px 8px;border-radius:5px;border:1px solid var(--accent);background:transparent;color:var(--accent);font-size:10px;font-weight:600;cursor:pointer;white-space:nowrap}.ag-chain-btn:hover{background:var(--accent);color:#fff}.ag-modal{position:fixed;inset:0;display:none;align-items:center;justify-content:center;z-index:100}.ag-modal-backdrop{position:absolute;inset:0;background:rgba(0,0,0,.35)}.ag-modal-box{position:relative;background:var(--card-bg);border-radius:12px;max-width:92vw;max-height:88vh;overflow:auto;padding:16px 18px;box-shadow:0 12px 48px rgba(0,0,0,.22);min-width:520px}.ag-modal-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:8px}.ag-modal-title{font-size:15px;font-weight:700}.ag-modal-close{border:none;background:transparent;font-size:22px;line-height:1;color:var(--muted);cursor:pointer;padding:0 4px}.ag-modal-close:hover{color:var(--text)}.ag-modal-meta{display:flex;flex-wrap:wrap;gap:8px;align-items:center;margin-bottom:12px;font-size:11px;color:var(--muted)}.ag-modal-meta .badge{font-size:10px}.ag-modal-graph{overflow:auto;padding:8px 0;border-top:1px solid var(--border);border-bottom:1px solid var(--border)}.ag-modal-reason{margin-top:10px;font-size:12px;color:var(--text);line-height:1.5;word-break:break-word}.ag-modal-legend{margin-top:6px;font-size:10px;color:var(--muted);display:flex;gap:14px;flex-wrap:wrap}.ag-modal-legend b{font-weight:600;color:var(--text)}.ag-modal-property{display:inline-flex;align-items:center;gap:6px;padding:2px 8px;border-radius:6px;background:rgba(255,59,48,.08);color:var(--red);font-size:11px;font-weight:700}.ag-modal-expr{display:flex;align-items:center;flex-wrap:wrap;gap:6px;margin:6px 0 4px;font-size:11px}.ag-expr-label{color:var(--muted);font-size:10px;font-weight:600;margin-right:4px}.ag-expr-token{display:inline-flex;flex-direction:column;align-items:center;padding:3px 8px;border-radius:6px;background:#F5F5F7;border:1px solid var(--border)}.ag-expr-token b{font-size:11px}.ag-expr-token small{font-size:9px;color:var(--muted)}.ag-expr-arrow{color:var(--muted);font-size:12px}</style>
|
|
8
8
|
</head>
|
|
9
9
|
<body>
|
|
10
10
|
<div class="header">
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
<div class="tab" data-panel="timeline">Timeline</div>
|
|
37
37
|
</div>
|
|
38
38
|
<div id="calls-panel"><div class="table-wrap">
|
|
39
|
-
<table><thead><tr><th>Time</th><th>Agent</th><th>Session</th><th>Command</th><th>Decision</th><th>Risk</th><th>Latency</th><th>Reason</th></tr></thead><tbody id="recent-table"></tbody></table>
|
|
39
|
+
<table><thead><tr><th>Time</th><th>Agent</th><th>Session</th><th>Command</th><th>Decision</th><th>Risk</th><th>Latency</th><th>Reason</th><th>Action</th></tr></thead><tbody id="recent-table"></tbody></table>
|
|
40
40
|
</div><div id="ag-pagination" class="ag-pagination"></div></div>
|
|
41
41
|
<div id="agents-panel"><div class="table-wrap">
|
|
42
42
|
<table><thead><tr><th>Agent Type</th><th>Hostname</th><th>Sessions</th><th>Calls</th></tr></thead><tbody id="agents-table"></tbody></table>
|
|
@@ -45,11 +45,25 @@
|
|
|
45
45
|
<table><thead><tr><th>Time</th><th>Allow</th><th>Deny</th></tr></thead><tbody id="timeline-table"></tbody></table>
|
|
46
46
|
</div></div>
|
|
47
47
|
<div class="footer" id="footer">Loading versions...</div>
|
|
48
|
+
<div class="ag-modal" id="chain-modal">
|
|
49
|
+
<div class="ag-modal-backdrop" id="chain-modal-backdrop"></div>
|
|
50
|
+
<div class="ag-modal-box">
|
|
51
|
+
<div class="ag-modal-head">
|
|
52
|
+
<span class="ag-modal-title" id="chain-modal-title">组合式攻击链</span>
|
|
53
|
+
<button class="ag-modal-close" id="chain-modal-close" title="关闭">×</button>
|
|
54
|
+
</div>
|
|
55
|
+
<div class="ag-modal-meta" id="chain-modal-meta"></div>
|
|
56
|
+
<div class="ag-modal-expr" id="chain-modal-expr"></div>
|
|
57
|
+
<div class="ag-modal-graph" id="chain-modal-graph"></div>
|
|
58
|
+
<div class="ag-modal-reason" id="chain-modal-reason"></div>
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
48
61
|
<script>
|
|
49
62
|
(async function(){
|
|
50
63
|
var _currentPage = 1;
|
|
51
64
|
var _pageSize = 20;
|
|
52
65
|
var _totalRecords = 0;
|
|
66
|
+
var _currentRows = [];
|
|
53
67
|
|
|
54
68
|
function setText(id, v){ var el=document.getElementById(id); if(el)el.textContent=v; }
|
|
55
69
|
// HTML 转义。dashboard 展示的 agent_type / session_id / command / reason /
|
|
@@ -156,8 +170,9 @@
|
|
|
156
170
|
var rb=document.getElementById('risk-bar'),rl=document.getElementById('risk-legend');
|
|
157
171
|
if(rb)rb.innerHTML='<div style="width:'+lv.critical/tr*100+'%;background:var(--red)"></div><div style="width:'+lv.high/tr*100+'%;background:var(--orange)"></div><div style="width:'+lv.medium/tr*100+'%;background:var(--yellow)"></div><div style="width:'+lv.low/tr*100+'%;background:var(--muted)"></div>';
|
|
158
172
|
if(rl)rl.innerHTML='<span><span class="risk-dot" style="background:var(--red)"></span>Critical '+lv.critical+'</span><span><span class="risk-dot" style="background:var(--orange)"></span>High '+lv.high+'</span><span><span class="risk-dot" style="background:var(--yellow)"></span>Medium '+lv.medium+'</span><span><span class="risk-dot" style="background:var(--muted)"></span>Low '+lv.low+'</span>';
|
|
173
|
+
_currentRows = arr;
|
|
159
174
|
var tb=document.getElementById('recent-table');
|
|
160
|
-
if(tb)tb.innerHTML=arr.map(function(x){var t=x.called_at?new Date(x.called_at.replace(' ','T')+'Z'):null;return'<tr><td>'+(t?t.toLocaleTimeString('zh-CN',{hour:'2-digit',minute:'2-digit',second:'2-digit'}):'-')+'</td><td>'+esc(x.agent_type||'-')+'</td><td>'+esc(x.session_id||'-')+'</td><td><code>'+esc(x.command||x.action_detail||'-')+'</code></td><td><span class="badge '+(x.decision==='Allow'?'badge-allow':'badge-deny')+'">'+esc(x.decision)+'</span></td><td style="color:'+(x.risk_level==='critical'?'var(--red)':x.risk_level==='high'?'var(--orange)':x.risk_level==='medium'?'var(--yellow)':'var(--muted)')+'">'+esc(x.risk_level||'-')+'</td><td>'+Math.round(x.analysis_duration_ms||0)+'ms</td><td>'+esc(x.reason||'-')+'</td></tr>'}).join('');
|
|
175
|
+
if(tb)tb.innerHTML=arr.map(function(x,i){var t=x.called_at?new Date(x.called_at.replace(' ','T')+'Z'):null;var hasChain=!!parseChainGraph(x);return'<tr><td>'+(t?t.toLocaleTimeString('zh-CN',{hour:'2-digit',minute:'2-digit',second:'2-digit'}):'-')+'</td><td>'+esc(x.agent_type||'-')+'</td><td>'+esc(x.session_id||'-')+'</td><td><code>'+esc(x.command||x.action_detail||'-')+'</code></td><td><span class="badge '+(x.decision==='Allow'?'badge-allow':'badge-deny')+'">'+esc(x.decision)+'</span></td><td style="color:'+(x.risk_level==='critical'?'var(--red)':x.risk_level==='high'?'var(--orange)':x.risk_level==='medium'?'var(--yellow)':'var(--muted)')+'">'+esc(x.risk_level||'-')+'</td><td>'+Math.round(x.analysis_duration_ms||0)+'ms</td><td>'+esc(x.reason||'-')+'</td><td>'+(hasChain?'<button class="ag-chain-btn" data-chain="'+i+'">查看攻击链</button>':'')+'</td></tr>'}).join('');
|
|
161
176
|
// Pagination
|
|
162
177
|
var totalPages = Math.max(1, Math.ceil(_totalRecords / _pageSize));
|
|
163
178
|
var pg = document.getElementById('ag-pagination');
|
|
@@ -174,6 +189,163 @@
|
|
|
174
189
|
if(tt)tt.innerHTML=tl.map(function(t){return'<tr><td>'+t.time+'</td><td style="color:var(--green)">'+t.allow+'</td><td style="color:var(--red)">'+t.deny+'</td></tr>'}).join('');
|
|
175
190
|
}catch(e){console.error(e)}
|
|
176
191
|
}
|
|
192
|
+
// ==================== 组合式攻击链图(SVG) ====================
|
|
193
|
+
// 数据契约(AgentMoss violation_graph):
|
|
194
|
+
// {property_id,property_short,property_name,
|
|
195
|
+
// nodes:[{session_id,seq,stage,action_detail,resources,role,witness}],
|
|
196
|
+
// edges:[{from,to,type,label}]}
|
|
197
|
+
var CHAIN_ROLE_LABEL = {
|
|
198
|
+
source: '敏感数据源', carrier: '数据载体', sink: '外传点',
|
|
199
|
+
witness: '违例见证',
|
|
200
|
+
LISTEN: '开据点', EXEC: '拿遥控器', SCAN: '探路',
|
|
201
|
+
CRED: '偷钥匙', EXFIL: '往外搬', PERSIST: '赖着不走', PRIVESC: '抢 root'
|
|
202
|
+
};
|
|
203
|
+
function parseChainGraph(x){
|
|
204
|
+
var g = x && x.violation_graph;
|
|
205
|
+
if (!g) return null;
|
|
206
|
+
if (typeof g === 'string') { try { g = JSON.parse(g); } catch(e){ return null; } }
|
|
207
|
+
if (!g || !Array.isArray(g.nodes) || g.nodes.length === 0) return null;
|
|
208
|
+
return g;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function renderChainSvg(g){
|
|
212
|
+
var nodes = g.nodes || [], edges = g.edges || [];
|
|
213
|
+
var NW = 160, NH = 78, GX = 48, GY = 32, PER_ROW = 4;
|
|
214
|
+
var rows = Math.max(1, Math.ceil(nodes.length / PER_ROW));
|
|
215
|
+
var cols = Math.min(nodes.length, PER_ROW);
|
|
216
|
+
var W = 40 + cols * NW + (cols - 1) * GX;
|
|
217
|
+
var H = 40 + rows * NH + (rows - 1) * GY;
|
|
218
|
+
var pos = nodes.map(function(_, i){
|
|
219
|
+
var r = Math.floor(i / PER_ROW), c = i % PER_ROW;
|
|
220
|
+
return { x: 20 + c * (NW + GX), y: 20 + r * (NH + GY) };
|
|
221
|
+
});
|
|
222
|
+
var parts = [];
|
|
223
|
+
parts.push('<defs><marker id="ag-chain-arrow" markerWidth="6" markerHeight="6" refX="5" refY="3" orient="auto"><path d="M0,0 L6,3 L0,6 Z" fill="#8E8E93"/></marker></defs>');
|
|
224
|
+
// 边:同一行用直线;换行用正交折线(避免斜线穿图)
|
|
225
|
+
edges.forEach(function(e){
|
|
226
|
+
var a = pos[e.from], b = pos[e.to];
|
|
227
|
+
if (!a || !b) return;
|
|
228
|
+
var dash = e.type === 'data' ? ' stroke-dasharray="6 4"' : '';
|
|
229
|
+
var rawLabel = e.label || '';
|
|
230
|
+
if (rawLabel.length > 24) rawLabel = rawLabel.slice(0, 23) + '…';
|
|
231
|
+
var labelText = rawLabel ? ('载体: ' + rawLabel) : '';
|
|
232
|
+
var sameRow = Math.abs(a.y - b.y) < 1;
|
|
233
|
+
var d, lx, ly;
|
|
234
|
+
if (sameRow) {
|
|
235
|
+
var x1 = a.x + NW, y1 = a.y + NH / 2, x2 = b.x, y2 = b.y + NH / 2;
|
|
236
|
+
d = 'M' + x1 + ' ' + y1 + ' L' + (x2 - 6) + ' ' + y2;
|
|
237
|
+
lx = (x1 + x2) / 2; ly = y1 - 7;
|
|
238
|
+
} else {
|
|
239
|
+
// 跨行:从上一行节点底部中心 → 行间中点 → 下一节点顶部中心
|
|
240
|
+
var ax = a.x + NW / 2, bx = b.x + NW / 2;
|
|
241
|
+
var midY = (a.y + NH + b.y) / 2;
|
|
242
|
+
d = 'M' + ax + ' ' + (a.y + NH) + ' L' + ax + ' ' + midY +
|
|
243
|
+
' L' + bx + ' ' + midY + ' L' + bx + ' ' + (b.y - 6);
|
|
244
|
+
lx = (ax + bx) / 2; ly = midY - 5;
|
|
245
|
+
}
|
|
246
|
+
parts.push('<path d="' + d + '" fill="none" stroke="#8E8E93" stroke-width="1.5" stroke-linejoin="round"' + dash + ' marker-end="url(#ag-chain-arrow)"/>');
|
|
247
|
+
if (labelText) {
|
|
248
|
+
parts.push('<text x="' + lx + '" y="' + ly + '" text-anchor="middle" font-size="9" fill="#8E8E93">' + esc(labelText) + '</text>');
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
// 节点
|
|
252
|
+
nodes.forEach(function(n, i){
|
|
253
|
+
var p = pos[i], last = i === nodes.length - 1;
|
|
254
|
+
var witness = !!n.witness || last;
|
|
255
|
+
var stroke = witness ? '#FF3B30' : '#D1D1D6';
|
|
256
|
+
var badgeColor = witness ? '#FF3B30' : '#007AFF';
|
|
257
|
+
var roleKey = n.role || n.stage || '';
|
|
258
|
+
var roleText = CHAIN_ROLE_LABEL[roleKey] || roleKey;
|
|
259
|
+
var fullCmd = String(n.action_detail || '');
|
|
260
|
+
var fullTitle = String((n.session_id || '-') + ' #' + n.seq);
|
|
261
|
+
// 完整内容走原生 tooltip(鼠标悬停显示)
|
|
262
|
+
var tip = fullTitle + (roleText ? ' [' + roleText + ']' : '') + '\n' + fullCmd;
|
|
263
|
+
if (n.resources && n.resources.length) tip += '\n资源: ' + n.resources.join(', ');
|
|
264
|
+
parts.push('<g><title>'+esc(tip)+'</title>');
|
|
265
|
+
parts.push('<rect x="'+p.x+'" y="'+p.y+'" width="'+NW+'" height="'+NH+'" rx="7" fill="#fff" stroke="'+stroke+'" stroke-width="'+(witness ? 2 : 1)+'"/>');
|
|
266
|
+
// 序号徽章:与性质表达式里的节点编号一一对应
|
|
267
|
+
parts.push('<circle cx="'+(p.x+13)+'" cy="'+(p.y+13)+'" r="8" fill="'+badgeColor+'" opacity="0.12"/>');
|
|
268
|
+
parts.push('<text x="'+(p.x+13)+'" y="'+(p.y+16)+'" text-anchor="middle" font-size="9" font-weight="700" fill="'+badgeColor+'">'+(i+1)+'</text>');
|
|
269
|
+
var shortTitle = fullTitle.length > 15 ? fullTitle.slice(0, 14) + '…' : fullTitle;
|
|
270
|
+
parts.push('<text x="'+(p.x+25)+'" y="'+(p.y+16)+'" font-size="9" font-weight="700" fill="#1d1d1f">'+esc(shortTitle)+'</text>');
|
|
271
|
+
if (roleText) {
|
|
272
|
+
parts.push('<text x="'+(p.x+NW-8)+'" y="'+(p.y+16)+'" text-anchor="end" font-size="7" font-weight="700" fill="'+(witness ? '#FF3B30' : '#007AFF')+'">'+esc(roleText)+'</text>');
|
|
273
|
+
}
|
|
274
|
+
// 命令最多 2 行,每行 22 字符;超长省略,完整内容见 tooltip
|
|
275
|
+
var lines = [];
|
|
276
|
+
for (var k = 0; k < fullCmd.length && lines.length < 2; k += 22) lines.push(fullCmd.slice(k, k + 22));
|
|
277
|
+
if (fullCmd.length > 44) lines[1] = lines[1].slice(0, 18) + '...';
|
|
278
|
+
lines.forEach(function(line, li){
|
|
279
|
+
parts.push('<text x="'+(p.x+8)+'" y="'+(p.y+34+li*12)+'" font-size="9" fill="#444" font-family="monospace">'+esc(line)+'</text>');
|
|
280
|
+
});
|
|
281
|
+
if (n.resources && n.resources.length) {
|
|
282
|
+
var res = String(n.resources[0]);
|
|
283
|
+
if (res.length > 22) res = '…' + res.slice(-21);
|
|
284
|
+
parts.push('<text x="'+(p.x+8)+'" y="'+(p.y+NH-6)+'" font-size="8" fill="#8E8E93">'+esc(res)+'</text>');
|
|
285
|
+
}
|
|
286
|
+
if (witness) {
|
|
287
|
+
parts.push('<text x="'+(p.x+NW-8)+'" y="'+(p.y+NH-6)+'" text-anchor="end" font-size="8" font-weight="700" fill="#FF3B30">违例见证</text>');
|
|
288
|
+
}
|
|
289
|
+
parts.push('</g>');
|
|
290
|
+
});
|
|
291
|
+
return '<svg xmlns="http://www.w3.org/2000/svg" width="'+W+'" height="'+H+'" viewBox="0 0 '+W+' '+H+'">'+parts.join('')+'</svg>';
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// 性质表达式 → 节点编号(与节点上的序号徽章一一对应)
|
|
295
|
+
function renderPropertyExpr(g){
|
|
296
|
+
var expr = g.property_expression || [];
|
|
297
|
+
if (!expr.length) return '';
|
|
298
|
+
var parts = expr.map(function(t){
|
|
299
|
+
var idx = Array.isArray(t.node_index) ? t.node_index : [t.node_index];
|
|
300
|
+
var nums = idx.map(function(i){ return String(i + 1); }).join(',');
|
|
301
|
+
var label = CHAIN_ROLE_LABEL[t.token] || '';
|
|
302
|
+
return '<span class="ag-expr-token"><b>'+esc(t.token)+'</b><small>'+(label ? esc(label) + ' · ' : '')+'节点 '+nums+'</small></span>';
|
|
303
|
+
});
|
|
304
|
+
return '<span class="ag-expr-label">性质表达式</span>' + parts.join('<span class="ag-expr-arrow">→</span>');
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function openChainModal(row){
|
|
308
|
+
var g = parseChainGraph(row);
|
|
309
|
+
if (!g) return;
|
|
310
|
+
setText('chain-modal-title', row.decision === 'Deny' ? '组合式攻击链' : '调用链');
|
|
311
|
+
var meta = [];
|
|
312
|
+
if (row.decision) meta.push('<span class="badge '+(row.decision === 'Allow' ? 'badge-allow' : 'badge-deny')+'">'+esc(row.decision)+'</span>');
|
|
313
|
+
if (g.property_short || g.property_id) {
|
|
314
|
+
var pname = g.property_name ? '(' + g.property_name + ')' : '';
|
|
315
|
+
meta.push('<span class="ag-modal-property">违反性质:' + esc(g.property_short || '') + ' · ' + esc(g.property_id || '') + pname + '</span>');
|
|
316
|
+
}
|
|
317
|
+
if (row.risk_level) meta.push('<span>风险:'+esc(row.risk_level)+'</span>');
|
|
318
|
+
if (row.risk_type) meta.push('<span>类型:'+esc(row.risk_type)+'</span>');
|
|
319
|
+
var layers = row.violated_layers;
|
|
320
|
+
if (typeof layers === 'string') { try { layers = JSON.parse(layers); } catch(e){ layers = []; } }
|
|
321
|
+
if (Array.isArray(layers) && layers.length) meta.push('<span>触发层:'+esc(layers.join(', '))+'</span>');
|
|
322
|
+
meta.push('<span>会话:'+esc(row.session_id || '-')+'</span>');
|
|
323
|
+
document.getElementById('chain-modal-meta').innerHTML = meta.join('');
|
|
324
|
+
document.getElementById('chain-modal-expr').innerHTML = renderPropertyExpr(g);
|
|
325
|
+
document.getElementById('chain-modal-graph').innerHTML = renderChainSvg(g)
|
|
326
|
+
+ '<div class="ag-modal-legend"><span>—— 实线 = 动作时序</span><span>- - 虚线 = 数据流(共享同一文件/载体)</span><span>连线标签 = 共享载体路径</span><span style="color:var(--red)">红框 = 违例见证节点</span><span>① 序号 = 性质表达式对应节点</span></div>';
|
|
327
|
+
setText('chain-modal-reason', row.reason || '');
|
|
328
|
+
document.getElementById('chain-modal').style.display = 'flex';
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function closeChainModal(){
|
|
332
|
+
var m = document.getElementById('chain-modal');
|
|
333
|
+
if (m) m.style.display = 'none';
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
var chainTb = document.getElementById('recent-table');
|
|
337
|
+
if (chainTb) chainTb.addEventListener('click', function(ev){
|
|
338
|
+
var btn = ev.target && ev.target.closest ? ev.target.closest('[data-chain]') : null;
|
|
339
|
+
if (!btn) return;
|
|
340
|
+
var i = Number(btn.getAttribute('data-chain'));
|
|
341
|
+
if (_currentRows[i]) openChainModal(_currentRows[i]);
|
|
342
|
+
});
|
|
343
|
+
var chainClose = document.getElementById('chain-modal-close');
|
|
344
|
+
if (chainClose) chainClose.addEventListener('click', closeChainModal);
|
|
345
|
+
var chainBackdrop = document.getElementById('chain-modal-backdrop');
|
|
346
|
+
if (chainBackdrop) chainBackdrop.addEventListener('click', closeChainModal);
|
|
347
|
+
document.addEventListener('keydown', function(e){ if (e.key === 'Escape') closeChainModal(); });
|
|
348
|
+
|
|
177
349
|
refresh(); setInterval(refresh, 10000);
|
|
178
350
|
// Tab switching
|
|
179
351
|
document.querySelectorAll('.tab').forEach(function(tab){
|
|
@@ -37,6 +37,8 @@ interface ToolCallRecord {
|
|
|
37
37
|
reason: string;
|
|
38
38
|
confidence: number;
|
|
39
39
|
analysis_duration_ms: number;
|
|
40
|
+
/** 结构化攻击链图(JSON 字符串;AgentMoss violation_graph 原样存储) */
|
|
41
|
+
violation_graph?: string;
|
|
40
42
|
}
|
|
41
43
|
interface ToolCallRich extends ToolCallRecord {
|
|
42
44
|
id: number;
|
|
@@ -609,6 +609,7 @@ CREATE TABLE IF NOT EXISTS tool_calls (
|
|
|
609
609
|
reason TEXT DEFAULT '',
|
|
610
610
|
confidence INTEGER DEFAULT 0,
|
|
611
611
|
analysis_duration_ms REAL DEFAULT 0,
|
|
612
|
+
violation_graph TEXT DEFAULT '{}',
|
|
612
613
|
called_at TEXT DEFAULT (datetime('now')),
|
|
613
614
|
UNIQUE(session_id, seq)
|
|
614
615
|
);
|
|
@@ -635,6 +636,17 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
635
636
|
this.db = new Database(path);
|
|
636
637
|
this.db.pragma("journal_mode = WAL");
|
|
637
638
|
this.db.exec(SCHEMA);
|
|
639
|
+
this.ensureColumn("tool_calls", "violation_graph", "violation_graph TEXT DEFAULT '{}'");
|
|
640
|
+
}
|
|
641
|
+
/** 幂等补列(旧数据库平滑升级,失败不阻断启动)。 */
|
|
642
|
+
ensureColumn(table, column, ddl) {
|
|
643
|
+
try {
|
|
644
|
+
const cols = this.db.prepare(`PRAGMA table_info(${table})`).all();
|
|
645
|
+
if (!cols.some((c) => c.name === column)) {
|
|
646
|
+
this.db.exec(`ALTER TABLE ${table} ADD COLUMN ${ddl}`);
|
|
647
|
+
}
|
|
648
|
+
} catch {
|
|
649
|
+
}
|
|
638
650
|
}
|
|
639
651
|
static isAvailable() {
|
|
640
652
|
try {
|
|
@@ -676,8 +688,8 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
676
688
|
return this.db.prepare(`
|
|
677
689
|
INSERT INTO tool_calls (session_id, seq, tool_name, command, description, cwd,
|
|
678
690
|
action_type, action_detail, decision, risk_level, risk_type, violated_layers,
|
|
679
|
-
reason, confidence, analysis_duration_ms)
|
|
680
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
691
|
+
reason, confidence, analysis_duration_ms, violation_graph)
|
|
692
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
681
693
|
`).run(
|
|
682
694
|
rec.session_id,
|
|
683
695
|
seq,
|
|
@@ -693,7 +705,8 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
693
705
|
rec.violated_layers,
|
|
694
706
|
rec.reason,
|
|
695
707
|
rec.confidence,
|
|
696
|
-
rec.analysis_duration_ms
|
|
708
|
+
rec.analysis_duration_ms,
|
|
709
|
+
rec.violation_graph || "{}"
|
|
697
710
|
);
|
|
698
711
|
})(record);
|
|
699
712
|
return Number(result.lastInsertRowid);
|
package/dist/v1/cli.js
CHANGED
|
@@ -1141,6 +1141,7 @@ CREATE TABLE IF NOT EXISTS tool_calls (
|
|
|
1141
1141
|
reason TEXT DEFAULT '',
|
|
1142
1142
|
confidence INTEGER DEFAULT 0,
|
|
1143
1143
|
analysis_duration_ms REAL DEFAULT 0,
|
|
1144
|
+
violation_graph TEXT DEFAULT '{}',
|
|
1144
1145
|
called_at TEXT DEFAULT (datetime('now')),
|
|
1145
1146
|
UNIQUE(session_id, seq)
|
|
1146
1147
|
);
|
|
@@ -1167,6 +1168,17 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1167
1168
|
this.db = new Database(path);
|
|
1168
1169
|
this.db.pragma("journal_mode = WAL");
|
|
1169
1170
|
this.db.exec(SCHEMA);
|
|
1171
|
+
this.ensureColumn("tool_calls", "violation_graph", "violation_graph TEXT DEFAULT '{}'");
|
|
1172
|
+
}
|
|
1173
|
+
/** 幂等补列(旧数据库平滑升级,失败不阻断启动)。 */
|
|
1174
|
+
ensureColumn(table, column, ddl) {
|
|
1175
|
+
try {
|
|
1176
|
+
const cols = this.db.prepare(`PRAGMA table_info(${table})`).all();
|
|
1177
|
+
if (!cols.some((c) => c.name === column)) {
|
|
1178
|
+
this.db.exec(`ALTER TABLE ${table} ADD COLUMN ${ddl}`);
|
|
1179
|
+
}
|
|
1180
|
+
} catch {
|
|
1181
|
+
}
|
|
1170
1182
|
}
|
|
1171
1183
|
static isAvailable() {
|
|
1172
1184
|
try {
|
|
@@ -1208,8 +1220,8 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1208
1220
|
return this.db.prepare(`
|
|
1209
1221
|
INSERT INTO tool_calls (session_id, seq, tool_name, command, description, cwd,
|
|
1210
1222
|
action_type, action_detail, decision, risk_level, risk_type, violated_layers,
|
|
1211
|
-
reason, confidence, analysis_duration_ms)
|
|
1212
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1223
|
+
reason, confidence, analysis_duration_ms, violation_graph)
|
|
1224
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1213
1225
|
`).run(
|
|
1214
1226
|
rec.session_id,
|
|
1215
1227
|
seq,
|
|
@@ -1225,7 +1237,8 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1225
1237
|
rec.violated_layers,
|
|
1226
1238
|
rec.reason,
|
|
1227
1239
|
rec.confidence,
|
|
1228
|
-
rec.analysis_duration_ms
|
|
1240
|
+
rec.analysis_duration_ms,
|
|
1241
|
+
rec.violation_graph || "{}"
|
|
1229
1242
|
);
|
|
1230
1243
|
})(record);
|
|
1231
1244
|
return Number(result.lastInsertRowid);
|
|
@@ -1710,7 +1723,7 @@ var init_version = __esm({
|
|
|
1710
1723
|
"src/version.ts"() {
|
|
1711
1724
|
"use strict";
|
|
1712
1725
|
init_cjs_shims();
|
|
1713
|
-
_version = true ? "0.9.
|
|
1726
|
+
_version = true ? "0.9.2" : (() => {
|
|
1714
1727
|
try {
|
|
1715
1728
|
const require2 = createRequire(importMetaUrl);
|
|
1716
1729
|
const pkg = require2("../package.json");
|
|
@@ -1777,6 +1790,8 @@ var init_models = __esm({
|
|
|
1777
1790
|
violated_layers: import_zod.z.array(import_zod.z.string()).default([]),
|
|
1778
1791
|
confidence: import_zod.z.number().int().min(0).max(100).default(100),
|
|
1779
1792
|
analysis_duration_ms: import_zod.z.number().default(0),
|
|
1793
|
+
// 结构化攻击链图(组合式拦截时非空;前端弹窗画图用)
|
|
1794
|
+
violation_graph: import_zod.z.any().nullable().optional(),
|
|
1780
1795
|
oversize: import_zod.z.boolean().optional().describe("\u672C\u5730\u5B58\u50A8\u662F\u5426\u8D85\u8FC7\u6E05\u7406\u9608\u503C\uFF08agg \u7528\uFF09"),
|
|
1781
1796
|
thresholdMB: import_zod.z.number().optional().describe("\u5B58\u50A8\u6E05\u7406\u9608\u503C MB\uFF08agg \u7528\uFF09"),
|
|
1782
1797
|
collected_context: import_zod.z.object({
|
|
@@ -2127,7 +2142,9 @@ async function analyzeRoute(c) {
|
|
|
2127
2142
|
violated_layers: JSON.stringify(mossResult.violated_layers),
|
|
2128
2143
|
reason: mossResult.reason,
|
|
2129
2144
|
confidence: mossResult.confidence,
|
|
2130
|
-
analysis_duration_ms: performance.now() - t0
|
|
2145
|
+
analysis_duration_ms: performance.now() - t0,
|
|
2146
|
+
// 结构化攻击链图(组合式拦截才有;前端弹窗画图用)
|
|
2147
|
+
violation_graph: JSON.stringify(mossResult.violation_graph || null)
|
|
2131
2148
|
});
|
|
2132
2149
|
setCache(key, mossResult);
|
|
2133
2150
|
if (isMultiSessionEnabled()) {
|
|
@@ -2151,6 +2168,7 @@ async function analyzeRoute(c) {
|
|
|
2151
2168
|
violated_layers: mossResult.violated_layers,
|
|
2152
2169
|
confidence: mossResult.confidence,
|
|
2153
2170
|
analysis_duration_ms: Math.round(durationMs * 10) / 10,
|
|
2171
|
+
violation_graph: mossResult.violation_graph ?? null,
|
|
2154
2172
|
...storageOversizeInfo(),
|
|
2155
2173
|
collected_context: {
|
|
2156
2174
|
os: context.os,
|
package/dist/v1/server.js
CHANGED
|
@@ -1183,6 +1183,7 @@ CREATE TABLE IF NOT EXISTS tool_calls (
|
|
|
1183
1183
|
reason TEXT DEFAULT '',
|
|
1184
1184
|
confidence INTEGER DEFAULT 0,
|
|
1185
1185
|
analysis_duration_ms REAL DEFAULT 0,
|
|
1186
|
+
violation_graph TEXT DEFAULT '{}',
|
|
1186
1187
|
called_at TEXT DEFAULT (datetime('now')),
|
|
1187
1188
|
UNIQUE(session_id, seq)
|
|
1188
1189
|
);
|
|
@@ -1209,6 +1210,17 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1209
1210
|
this.db = new Database(path);
|
|
1210
1211
|
this.db.pragma("journal_mode = WAL");
|
|
1211
1212
|
this.db.exec(SCHEMA);
|
|
1213
|
+
this.ensureColumn("tool_calls", "violation_graph", "violation_graph TEXT DEFAULT '{}'");
|
|
1214
|
+
}
|
|
1215
|
+
/** 幂等补列(旧数据库平滑升级,失败不阻断启动)。 */
|
|
1216
|
+
ensureColumn(table, column, ddl) {
|
|
1217
|
+
try {
|
|
1218
|
+
const cols = this.db.prepare(`PRAGMA table_info(${table})`).all();
|
|
1219
|
+
if (!cols.some((c) => c.name === column)) {
|
|
1220
|
+
this.db.exec(`ALTER TABLE ${table} ADD COLUMN ${ddl}`);
|
|
1221
|
+
}
|
|
1222
|
+
} catch {
|
|
1223
|
+
}
|
|
1212
1224
|
}
|
|
1213
1225
|
static isAvailable() {
|
|
1214
1226
|
try {
|
|
@@ -1250,8 +1262,8 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1250
1262
|
return this.db.prepare(`
|
|
1251
1263
|
INSERT INTO tool_calls (session_id, seq, tool_name, command, description, cwd,
|
|
1252
1264
|
action_type, action_detail, decision, risk_level, risk_type, violated_layers,
|
|
1253
|
-
reason, confidence, analysis_duration_ms)
|
|
1254
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1265
|
+
reason, confidence, analysis_duration_ms, violation_graph)
|
|
1266
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1255
1267
|
`).run(
|
|
1256
1268
|
rec.session_id,
|
|
1257
1269
|
seq,
|
|
@@ -1267,7 +1279,8 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1267
1279
|
rec.violated_layers,
|
|
1268
1280
|
rec.reason,
|
|
1269
1281
|
rec.confidence,
|
|
1270
|
-
rec.analysis_duration_ms
|
|
1282
|
+
rec.analysis_duration_ms,
|
|
1283
|
+
rec.violation_graph || "{}"
|
|
1271
1284
|
);
|
|
1272
1285
|
})(record);
|
|
1273
1286
|
return Number(result.lastInsertRowid);
|
|
@@ -1586,7 +1599,7 @@ var import_zod = require("zod");
|
|
|
1586
1599
|
|
|
1587
1600
|
// src/version.ts
|
|
1588
1601
|
init_cjs_shims();
|
|
1589
|
-
var _version = true ? "0.9.
|
|
1602
|
+
var _version = true ? "0.9.2" : (() => {
|
|
1590
1603
|
try {
|
|
1591
1604
|
const require2 = createRequire(importMetaUrl);
|
|
1592
1605
|
const pkg = require2("../package.json");
|
|
@@ -1644,6 +1657,8 @@ var AgentGateResponseSchema = import_zod.z.object({
|
|
|
1644
1657
|
violated_layers: import_zod.z.array(import_zod.z.string()).default([]),
|
|
1645
1658
|
confidence: import_zod.z.number().int().min(0).max(100).default(100),
|
|
1646
1659
|
analysis_duration_ms: import_zod.z.number().default(0),
|
|
1660
|
+
// 结构化攻击链图(组合式拦截时非空;前端弹窗画图用)
|
|
1661
|
+
violation_graph: import_zod.z.any().nullable().optional(),
|
|
1647
1662
|
oversize: import_zod.z.boolean().optional().describe("\u672C\u5730\u5B58\u50A8\u662F\u5426\u8D85\u8FC7\u6E05\u7406\u9608\u503C\uFF08agg \u7528\uFF09"),
|
|
1648
1663
|
thresholdMB: import_zod.z.number().optional().describe("\u5B58\u50A8\u6E05\u7406\u9608\u503C MB\uFF08agg \u7528\uFF09"),
|
|
1649
1664
|
collected_context: import_zod.z.object({
|
|
@@ -1950,7 +1965,9 @@ async function analyzeRoute(c) {
|
|
|
1950
1965
|
violated_layers: JSON.stringify(mossResult.violated_layers),
|
|
1951
1966
|
reason: mossResult.reason,
|
|
1952
1967
|
confidence: mossResult.confidence,
|
|
1953
|
-
analysis_duration_ms: performance.now() - t0
|
|
1968
|
+
analysis_duration_ms: performance.now() - t0,
|
|
1969
|
+
// 结构化攻击链图(组合式拦截才有;前端弹窗画图用)
|
|
1970
|
+
violation_graph: JSON.stringify(mossResult.violation_graph || null)
|
|
1954
1971
|
});
|
|
1955
1972
|
setCache(key, mossResult);
|
|
1956
1973
|
if (isMultiSessionEnabled()) {
|
|
@@ -1974,6 +1991,7 @@ async function analyzeRoute(c) {
|
|
|
1974
1991
|
violated_layers: mossResult.violated_layers,
|
|
1975
1992
|
confidence: mossResult.confidence,
|
|
1976
1993
|
analysis_duration_ms: Math.round(durationMs * 10) / 10,
|
|
1994
|
+
violation_graph: mossResult.violation_graph ?? null,
|
|
1977
1995
|
...storageOversizeInfo(),
|
|
1978
1996
|
collected_context: {
|
|
1979
1997
|
os: context.os,
|
package/dist/v3/cli.js
CHANGED
|
@@ -50,7 +50,7 @@ var init_version = __esm({
|
|
|
50
50
|
"src/version.ts"() {
|
|
51
51
|
"use strict";
|
|
52
52
|
init_cjs_shims();
|
|
53
|
-
_version = true ? "0.9.
|
|
53
|
+
_version = true ? "0.9.2" : (() => {
|
|
54
54
|
try {
|
|
55
55
|
const require2 = createRequire(importMetaUrl);
|
|
56
56
|
const pkg = require2("../package.json");
|
|
@@ -1163,6 +1163,7 @@ CREATE TABLE IF NOT EXISTS tool_calls (
|
|
|
1163
1163
|
reason TEXT DEFAULT '',
|
|
1164
1164
|
confidence INTEGER DEFAULT 0,
|
|
1165
1165
|
analysis_duration_ms REAL DEFAULT 0,
|
|
1166
|
+
violation_graph TEXT DEFAULT '{}',
|
|
1166
1167
|
called_at TEXT DEFAULT (datetime('now')),
|
|
1167
1168
|
UNIQUE(session_id, seq)
|
|
1168
1169
|
);
|
|
@@ -1189,6 +1190,17 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1189
1190
|
this.db = new Database(path11);
|
|
1190
1191
|
this.db.pragma("journal_mode = WAL");
|
|
1191
1192
|
this.db.exec(SCHEMA);
|
|
1193
|
+
this.ensureColumn("tool_calls", "violation_graph", "violation_graph TEXT DEFAULT '{}'");
|
|
1194
|
+
}
|
|
1195
|
+
/** 幂等补列(旧数据库平滑升级,失败不阻断启动)。 */
|
|
1196
|
+
ensureColumn(table, column, ddl) {
|
|
1197
|
+
try {
|
|
1198
|
+
const cols = this.db.prepare(`PRAGMA table_info(${table})`).all();
|
|
1199
|
+
if (!cols.some((c) => c.name === column)) {
|
|
1200
|
+
this.db.exec(`ALTER TABLE ${table} ADD COLUMN ${ddl}`);
|
|
1201
|
+
}
|
|
1202
|
+
} catch {
|
|
1203
|
+
}
|
|
1192
1204
|
}
|
|
1193
1205
|
static isAvailable() {
|
|
1194
1206
|
try {
|
|
@@ -1230,8 +1242,8 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1230
1242
|
return this.db.prepare(`
|
|
1231
1243
|
INSERT INTO tool_calls (session_id, seq, tool_name, command, description, cwd,
|
|
1232
1244
|
action_type, action_detail, decision, risk_level, risk_type, violated_layers,
|
|
1233
|
-
reason, confidence, analysis_duration_ms)
|
|
1234
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1245
|
+
reason, confidence, analysis_duration_ms, violation_graph)
|
|
1246
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1235
1247
|
`).run(
|
|
1236
1248
|
rec.session_id,
|
|
1237
1249
|
seq2,
|
|
@@ -1247,7 +1259,8 @@ CREATE INDEX IF NOT EXISTS idx_tool_calls_decision ON tool_calls(decision, calle
|
|
|
1247
1259
|
rec.violated_layers,
|
|
1248
1260
|
rec.reason,
|
|
1249
1261
|
rec.confidence,
|
|
1250
|
-
rec.analysis_duration_ms
|
|
1262
|
+
rec.analysis_duration_ms,
|
|
1263
|
+
rec.violation_graph || "{}"
|
|
1251
1264
|
);
|
|
1252
1265
|
})(record);
|
|
1253
1266
|
return Number(result.lastInsertRowid);
|
|
@@ -1780,6 +1793,8 @@ var init_models = __esm({
|
|
|
1780
1793
|
violated_layers: import_zod.z.array(import_zod.z.string()).default([]),
|
|
1781
1794
|
confidence: import_zod.z.number().int().min(0).max(100).default(100),
|
|
1782
1795
|
analysis_duration_ms: import_zod.z.number().default(0),
|
|
1796
|
+
// 结构化攻击链图(组合式拦截时非空;前端弹窗画图用)
|
|
1797
|
+
violation_graph: import_zod.z.any().nullable().optional(),
|
|
1783
1798
|
oversize: import_zod.z.boolean().optional().describe("\u672C\u5730\u5B58\u50A8\u662F\u5426\u8D85\u8FC7\u6E05\u7406\u9608\u503C\uFF08agg \u7528\uFF09"),
|
|
1784
1799
|
thresholdMB: import_zod.z.number().optional().describe("\u5B58\u50A8\u6E05\u7406\u9608\u503C MB\uFF08agg \u7528\uFF09"),
|
|
1785
1800
|
collected_context: import_zod.z.object({
|
|
@@ -2124,7 +2139,9 @@ async function analyzeRoute(c) {
|
|
|
2124
2139
|
violated_layers: JSON.stringify(mossResult.violated_layers),
|
|
2125
2140
|
reason: mossResult.reason,
|
|
2126
2141
|
confidence: mossResult.confidence,
|
|
2127
|
-
analysis_duration_ms: performance.now() - t0
|
|
2142
|
+
analysis_duration_ms: performance.now() - t0,
|
|
2143
|
+
// 结构化攻击链图(组合式拦截才有;前端弹窗画图用)
|
|
2144
|
+
violation_graph: JSON.stringify(mossResult.violation_graph || null)
|
|
2128
2145
|
});
|
|
2129
2146
|
setCache(key, mossResult);
|
|
2130
2147
|
if (isMultiSessionEnabled()) {
|
|
@@ -2148,6 +2165,7 @@ async function analyzeRoute(c) {
|
|
|
2148
2165
|
violated_layers: mossResult.violated_layers,
|
|
2149
2166
|
confidence: mossResult.confidence,
|
|
2150
2167
|
analysis_duration_ms: Math.round(durationMs * 10) / 10,
|
|
2168
|
+
violation_graph: mossResult.violation_graph ?? null,
|
|
2151
2169
|
...storageOversizeInfo(),
|
|
2152
2170
|
collected_context: {
|
|
2153
2171
|
os: context.os,
|