thumbgate 1.37.3 → 1.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/aws-strands-harness-not-clone/SKILL.md +53 -0
- package/.agents/skills/bolt-forge-opt-in-not-clone/SKILL.md +72 -0
- package/.agents/skills/decisive-step-evaluator/SKILL.md +47 -0
- package/.agents/skills/fiddler-control-plane-honesty/SKILL.md +61 -0
- package/.agents/skills/halo-trace-optimize-not-clone/SKILL.md +60 -0
- package/.agents/skills/harness-evolution-ceiling/SKILL.md +52 -0
- package/.agents/skills/infoq-architect-honesty-not-clone/SKILL.md +37 -0
- package/.agents/skills/meko-datapack-honesty-not-clone/SKILL.md +45 -0
- package/.agents/skills/mintlify-knowledge-honesty-not-clone/SKILL.md +49 -0
- package/.agents/skills/model-distress-governance/SKILL.md +56 -0
- package/.agents/skills/omp-coordination-honesty-not-clone/SKILL.md +94 -0
- package/.agents/skills/saas-moat-honesty-not-clone/SKILL.md +22 -0
- package/.agents/skills/salt-code-policy-honesty-not-clone/SKILL.md +76 -0
- package/.agents/skills/siren-mcp-governance/SKILL.md +50 -0
- package/.agents/skills/vs-coverage-gap-not-clone/SKILL.md +69 -0
- package/.agents/skills/wisdom-context-artifact-not-clone/SKILL.md +67 -0
- package/.claude-plugin/plugin.json +1 -1
- package/.well-known/mcp/server-card.json +1 -1
- package/adapters/claude/.mcp.json +2 -2
- package/adapters/forge/forge.yaml +3 -3
- package/adapters/future-agi/.mcp.json +1 -1
- package/adapters/future-agi/config.toml +1 -1
- package/adapters/future-agi/opencode.json +1 -1
- package/adapters/herdr/herdr-plugin.toml +2 -2
- package/adapters/hotdata/hotdata-vector-store.js +575 -0
- package/adapters/mcp/server-stdio.js +1 -1
- package/adapters/opencode/opencode.json +1 -1
- package/adapters/strands/STRANDS.md +107 -0
- package/adapters/strands/strands-box-diode.js +344 -0
- package/adapters/strands/strands-decider-adapter.js +445 -0
- package/adapters/strands/strands-middleware.js +192 -0
- package/adapters/tailscale/.mcp.json +15 -0
- package/adapters/tailscale/TAILSCALE.md +117 -0
- package/adapters/tailscale/config.toml +16 -0
- package/bin/cli.js +602 -21
- package/config/gate-templates.json +109 -0
- package/config/gates/default.json +13 -0
- package/config/schemas/task-outcome-receipt.schema.json +12 -0
- package/package.json +150 -21
- package/public/blog/2026-09-28-pretool-secret-deny.html +83 -0
- package/public/blog/2026-10-01-aws-strands-harness-token-firewall.html +77 -0
- package/public/blog/2026-10-01-model-distress-relief-seeking-firewall.html +71 -0
- package/public/blog/2026-10-02-salt-code-honest-steal-40-guardrails.html +106 -0
- package/public/blog/2026-10-05-why-3-days-of-triage-wont-save-ai-speed-code.html +119 -0
- package/public/blog/2026-10-09-your-code-got-a-third-author-governance.html +141 -0
- package/public/connectors.html +329 -0
- package/public/enterprise-governance.html +311 -0
- package/public/gaming-playbook.html +732 -0
- package/public/index.html +77 -51
- package/public/install.html +7 -7
- package/public/learn.html +14 -0
- package/public/numbers.html +2 -2
- package/public/onboarding.html +794 -0
- package/public/operator-framework.html +385 -0
- package/public/pricing.html +14 -10
- package/scripts/activesaddler-curriculum-doctor.js +357 -0
- package/scripts/agent-context-artifact.js +325 -0
- package/scripts/agent-egress-policy.js +2 -2
- package/scripts/agent-operations-planner.js +1 -1
- package/scripts/agent-outcome-eval.js +1 -1
- package/scripts/agent-reliability-client.js +148 -0
- package/scripts/apple-minions-idle-compute-steal.js +428 -0
- package/scripts/autoresearch-runner.js +20 -1
- package/scripts/billing.js +0 -1
- package/scripts/cli-demo.js +505 -1
- package/scripts/cli-schema.js +36 -0
- package/scripts/colab-compute-honesty.js +93 -0
- package/scripts/corporate-email-isolation-diode.js +299 -0
- package/scripts/coverage-gap.js +396 -0
- package/scripts/dashboard-chat.js +3 -3
- package/scripts/dashboard.js +2 -2
- package/scripts/decisive-step-doctor.js +256 -0
- package/scripts/decisive-step-evaluator.js +390 -0
- package/scripts/entitlement.js +18 -7
- package/scripts/experiment-tracker.js +5 -3
- package/scripts/feedback-loop.js +26 -3
- package/scripts/fiddler-control-plane-honesty.js +303 -0
- package/scripts/financial-control-plane.js +10 -2
- package/scripts/gates-engine.js +3 -1
- package/scripts/github-license-compliance-diode.js +378 -0
- package/scripts/halo-trace-optimizer.js +631 -0
- package/scripts/harness-ceiling-doctor.js +326 -0
- package/scripts/hf-papers.js +1 -1
- package/scripts/human-escalation.js +7 -1
- package/scripts/hybrid-feedback-context.js +53 -7
- package/scripts/infoq-architect-honesty.js +362 -0
- package/scripts/lesson-graph.js +785 -0
- package/scripts/lesson-inference.js +1 -1
- package/scripts/lesson-retrieval.js +26 -18
- package/scripts/license.js +122 -21
- package/scripts/llm-behavior-monitor.js +1 -1
- package/scripts/llm-obs-honesty.js +52 -0
- package/scripts/local-model-profile.js +11 -7
- package/scripts/mailer/resend-mailer.js +6 -3
- package/scripts/mcp-transport-strategy.js +1 -1
- package/scripts/meko-datapack-honesty.js +414 -0
- package/scripts/migrate-lesson-graph.js +442 -0
- package/scripts/mintlify-knowledge-honesty.js +647 -0
- package/scripts/model-distress-detector.js +207 -0
- package/scripts/model-distress-doctor.js +368 -0
- package/scripts/multi-harness-invariants.js +305 -0
- package/scripts/omp-coordination-honesty.js +488 -0
- package/scripts/pro-local-dashboard.js +20 -3
- package/scripts/prompt-eval.js +1 -1
- package/scripts/prove-herdr-adapter.js +367 -3
- package/scripts/rag-embedding-identity.js +1 -1
- package/scripts/rrsi-regularizer.js +531 -0
- package/scripts/saas-moat-honesty.js +443 -0
- package/scripts/salt-code-policy-honesty.js +1204 -0
- package/scripts/secret-redaction.js +58 -0
- package/scripts/session-export-gate.js +368 -0
- package/scripts/siren-mcp-governance.js +539 -0
- package/scripts/strands-box-doctor.js +130 -0
- package/scripts/strands-harness-doctor.js +390 -0
- package/scripts/stripe-revenue-catalog-audit.js +12 -0
- package/scripts/stripe-revenue-catalog.js +40 -0
- package/scripts/switchyard-router.js +153 -0
- package/scripts/tailscale-p2p-doctor.js +252 -0
- package/scripts/task-outcomes.js +148 -3
- package/scripts/thumbgate-board-loop.js +4 -2
- package/scripts/thumbgate-daily-discoveries-publish.js +86 -38
- package/scripts/triage-savings-calculator.js +181 -0
- package/scripts/vector-store.js +41 -2
- package/scripts/vulnerability-pre-action-diode.js +319 -0
- package/scripts/windbg-evidence-diagnostics.js +241 -0
- package/scripts/workflow-intake-queue.js +1 -1
- package/scripts/workspace-agent-routines.js +534 -6
- package/scripts/workspace-evolver.js +143 -13
- package/server.json +2 -2
- package/skills/aws-strands-harness-not-clone/SKILL.md +53 -0
- package/skills/siren-mcp-governance/SKILL.md +50 -0
- package/src/api/server.js +191 -5
- package/src/mcp-writeguard.js +1 -1
- package/src/session-interactivity.js +284 -0
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* HALO Trace Optimization FORMAT steal — not a product clone.
|
|
6
|
+
*
|
|
7
|
+
* Source: https://inference.net/products/halo/
|
|
8
|
+
*
|
|
9
|
+
* Core Concept:
|
|
10
|
+
* Analyze agent trace logs -> identify repeated failure modes (redundant tool calls,
|
|
11
|
+
* retry thrash, expensive spans, unhandled denies) -> rank failure modes by impact ->
|
|
12
|
+
* synthesize concrete pre-action gates & executable evals.
|
|
13
|
+
*
|
|
14
|
+
* Maps onto existing ThumbGate rails:
|
|
15
|
+
* - scripts/auto-promote-gates.js
|
|
16
|
+
* - scripts/agent-action-inventory.js
|
|
17
|
+
* - scripts/gates-engine.js
|
|
18
|
+
* - scripts/silent-failure-cluster.js
|
|
19
|
+
* - .thumbgate/auto-promoted-gates.json
|
|
20
|
+
*
|
|
21
|
+
* Anti-Clone Safeguards:
|
|
22
|
+
* - Never install Inference.net catalyst SDK or cloud OTLP exporter.
|
|
23
|
+
* - Pure local analysis over local audit-trail.jsonl and trace logs.
|
|
24
|
+
* - Fail closed if --clone-halo or third-party cloud SDK attempted.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const fs = require('node:fs');
|
|
28
|
+
const path = require('node:path');
|
|
29
|
+
const os = require('node:os');
|
|
30
|
+
const crypto = require('node:crypto');
|
|
31
|
+
const { getAutoGatesPath, getRuleTtlMs } = require('./auto-promote-gates');
|
|
32
|
+
|
|
33
|
+
const SOURCE_URL = 'https://inference.net/products/halo/';
|
|
34
|
+
|
|
35
|
+
const CLONE_PATTERNS = Object.freeze([
|
|
36
|
+
{ id: 'halo_engine_import', re: /\bfrom\s+engine\.(agents|models|engine_config)\b/i },
|
|
37
|
+
{ id: 'inference_net_api', re: /\b(api\.inference\.net|inference-app-icon|catalyst\.inference\.net)\b/i },
|
|
38
|
+
{ id: 'clone_sku', re: /\b(clone|install|vendor)\b.{0,40}\bhalo (agent )?optimization\b/i },
|
|
39
|
+
{ id: 'cloud_trace_export', re: /\b(stream_engine_output_async|otlp_catalyst_export)\b/i },
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
const FAILURE_MODE_WEIGHTS = Object.freeze({
|
|
43
|
+
redundant_tool_calls: 3,
|
|
44
|
+
retry_stall: 4,
|
|
45
|
+
expensive_span: 2,
|
|
46
|
+
unhandled_denies: 5,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
function detectCloneAttempt(text) {
|
|
50
|
+
const t = String(text || '');
|
|
51
|
+
return CLONE_PATTERNS.filter((p) => p.re.test(t)).map((p) => p.id);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function resolveTraceLogPaths(customTracePath) {
|
|
55
|
+
if (customTracePath) {
|
|
56
|
+
const resolved = path.resolve(customTracePath);
|
|
57
|
+
return fs.existsSync(resolved) ? [resolved] : [];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const paths = [
|
|
61
|
+
path.join(process.cwd(), '.thumbgate', 'audit-trail.jsonl'),
|
|
62
|
+
path.join(process.cwd(), '.thumbgate', 'action-log.jsonl'),
|
|
63
|
+
path.join(os.homedir(), '.thumbgate', 'audit-trail.jsonl'),
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
return paths.filter((p) => fs.existsSync(p));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function parseJsonlFile(filePath) {
|
|
70
|
+
try {
|
|
71
|
+
const content = fs.readFileSync(filePath, 'utf8').trim();
|
|
72
|
+
if (!content) return [];
|
|
73
|
+
return content
|
|
74
|
+
.split('\n')
|
|
75
|
+
.map((line) => {
|
|
76
|
+
try {
|
|
77
|
+
return JSON.parse(line.trim());
|
|
78
|
+
} catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
.filter(Boolean);
|
|
83
|
+
} catch {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function extractActionString(entry) {
|
|
89
|
+
if (!entry || typeof entry !== 'object') return '';
|
|
90
|
+
if (entry.toolInput) {
|
|
91
|
+
if (typeof entry.toolInput === 'string') return entry.toolInput;
|
|
92
|
+
if (entry.toolInput.command) return String(entry.toolInput.command);
|
|
93
|
+
if (entry.toolInput.file_path) return String(entry.toolInput.file_path);
|
|
94
|
+
if (entry.toolInput.query) return String(entry.toolInput.query);
|
|
95
|
+
try {
|
|
96
|
+
return JSON.stringify(entry.toolInput);
|
|
97
|
+
} catch {
|
|
98
|
+
return '';
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (entry.command) return String(entry.command);
|
|
102
|
+
if (entry.input) return String(entry.input);
|
|
103
|
+
return '';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function normalizeActionString(str) {
|
|
107
|
+
return String(str || '')
|
|
108
|
+
.toLowerCase()
|
|
109
|
+
.trim()
|
|
110
|
+
.replace(/\s+/g, ' ');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function groupEntriesBySession(entries) {
|
|
114
|
+
const sessionBuckets = new Map();
|
|
115
|
+
for (const entry of entries) {
|
|
116
|
+
const sId = entry.sessionId || entry.session_id || 'default';
|
|
117
|
+
if (!sessionBuckets.has(sId)) sessionBuckets.set(sId, []);
|
|
118
|
+
sessionBuckets.get(sId).push(entry);
|
|
119
|
+
}
|
|
120
|
+
return sessionBuckets;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function countToolActions(sessionEntries) {
|
|
124
|
+
const runCounts = new Map();
|
|
125
|
+
for (const entry of sessionEntries) {
|
|
126
|
+
const tool = entry.toolName || entry.tool_name || 'unknown';
|
|
127
|
+
const rawAction = extractActionString(entry).trim();
|
|
128
|
+
if (!rawAction || rawAction.length < 3) continue;
|
|
129
|
+
|
|
130
|
+
const normAction = rawAction.replace(/\s+/g, ' ');
|
|
131
|
+
const lookupKey = JSON.stringify({ tool, action: normAction.toLowerCase() });
|
|
132
|
+
const existing = runCounts.get(lookupKey);
|
|
133
|
+
if (existing) {
|
|
134
|
+
existing.count += 1;
|
|
135
|
+
} else {
|
|
136
|
+
runCounts.set(lookupKey, {
|
|
137
|
+
tool,
|
|
138
|
+
action: normAction,
|
|
139
|
+
count: 1,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return runCounts;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* 1. Redundant Tool Thrashing Detection
|
|
148
|
+
* Identifies 3+ repeated calls to the same tool with identical or near-identical action.
|
|
149
|
+
*/
|
|
150
|
+
function detectRedundantToolCalls(entries) {
|
|
151
|
+
const findings = [];
|
|
152
|
+
const sessionBuckets = groupEntriesBySession(entries);
|
|
153
|
+
|
|
154
|
+
for (const [sessionId, sessionEntries] of sessionBuckets.entries()) {
|
|
155
|
+
const runCounts = countToolActions(sessionEntries);
|
|
156
|
+
|
|
157
|
+
for (const record of runCounts.values()) {
|
|
158
|
+
if (record.count >= 3) {
|
|
159
|
+
findings.push({
|
|
160
|
+
type: 'redundant_tool_calls',
|
|
161
|
+
sessionId,
|
|
162
|
+
tool: record.tool,
|
|
163
|
+
action: record.action,
|
|
164
|
+
occurrences: record.count,
|
|
165
|
+
severity: record.count >= 5 ? 'high' : 'medium',
|
|
166
|
+
summary: `Tool "${record.tool}" called ${record.count} times with identical action: "${record.action.slice(0, 80)}"`,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return findings;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* 2. Cascading Retry Stalls Detection
|
|
177
|
+
* Identifies a failing tool call (exit != 0, deny, error) followed immediately by identical retry.
|
|
178
|
+
*/
|
|
179
|
+
function detectRetryStalls(entries) {
|
|
180
|
+
const findings = [];
|
|
181
|
+
let prevEntry = null;
|
|
182
|
+
|
|
183
|
+
for (const entry of entries) {
|
|
184
|
+
if (!prevEntry) {
|
|
185
|
+
prevEntry = entry;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const prevFailed =
|
|
190
|
+
prevEntry.decision === 'deny' ||
|
|
191
|
+
prevEntry.exitCode > 0 ||
|
|
192
|
+
Boolean(prevEntry.error) ||
|
|
193
|
+
prevEntry.status === 'failure';
|
|
194
|
+
|
|
195
|
+
if (prevFailed) {
|
|
196
|
+
const prevTool = prevEntry.toolName || prevEntry.tool_name || '';
|
|
197
|
+
const currTool = entry.toolName || entry.tool_name || '';
|
|
198
|
+
const rawPrevAction = extractActionString(prevEntry).trim().replace(/\s+/g, ' ');
|
|
199
|
+
const rawCurrAction = extractActionString(entry).trim().replace(/\s+/g, ' ');
|
|
200
|
+
|
|
201
|
+
if (prevTool === currTool && rawPrevAction && rawPrevAction.toLowerCase() === rawCurrAction.toLowerCase()) {
|
|
202
|
+
findings.push({
|
|
203
|
+
type: 'retry_stall',
|
|
204
|
+
sessionId: entry.sessionId || entry.session_id || 'default',
|
|
205
|
+
tool: currTool,
|
|
206
|
+
action: rawCurrAction,
|
|
207
|
+
occurrences: 2,
|
|
208
|
+
severity: 'high',
|
|
209
|
+
summary: `Immediate duplicate retry of failed tool "${currTool}": "${rawCurrAction.slice(0, 80)}"`,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
prevEntry = entry;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return findings;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* 3. Token / Span Blowout Detection
|
|
222
|
+
* Identifies tool executions exceeding latency budgets (>10s) or generating huge dumps (>1000 lines).
|
|
223
|
+
*/
|
|
224
|
+
function detectExpensiveSpans(entries) {
|
|
225
|
+
const findings = [];
|
|
226
|
+
|
|
227
|
+
for (const entry of entries) {
|
|
228
|
+
const latency = Number(entry.latencyMs || entry.duration_ms || 0);
|
|
229
|
+
const lines = Number(entry.lineCount ?? entry.toolInput?.lines ?? 0);
|
|
230
|
+
const action = extractActionString(entry);
|
|
231
|
+
|
|
232
|
+
if (latency >= 10000) {
|
|
233
|
+
findings.push({
|
|
234
|
+
type: 'expensive_span',
|
|
235
|
+
sessionId: entry.sessionId || entry.session_id || 'default',
|
|
236
|
+
tool: entry.toolName || entry.tool_name || 'unknown',
|
|
237
|
+
action,
|
|
238
|
+
metric: `${Math.round(latency / 1000)}s latency`,
|
|
239
|
+
occurrences: 1,
|
|
240
|
+
severity: latency >= 30000 ? 'high' : 'medium',
|
|
241
|
+
summary: `Span exceeded 10s latency threshold (${latency}ms): "${action.slice(0, 80)}"`,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (lines >= 500) {
|
|
246
|
+
findings.push({
|
|
247
|
+
type: 'expensive_span',
|
|
248
|
+
sessionId: entry.sessionId || entry.session_id || 'default',
|
|
249
|
+
tool: entry.toolName || entry.tool_name || 'unknown',
|
|
250
|
+
action,
|
|
251
|
+
metric: `${lines} lines output`,
|
|
252
|
+
occurrences: 1,
|
|
253
|
+
severity: lines >= 1000 ? 'high' : 'medium',
|
|
254
|
+
summary: `Span output exceeded 500 lines (${lines} lines, token-shunt risk): "${action.slice(0, 80)}"`,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return findings;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function aggregateGateDenies(entries) {
|
|
263
|
+
const gateMap = new Map();
|
|
264
|
+
for (const entry of entries) {
|
|
265
|
+
if (entry.decision === 'deny' || entry.shadowDecision === 'block') {
|
|
266
|
+
const gateId = entry.gateId || entry.gate_id || 'unknown-gate';
|
|
267
|
+
const action = extractActionString(entry);
|
|
268
|
+
if (!gateMap.has(gateId)) {
|
|
269
|
+
gateMap.set(gateId, { count: 0, action });
|
|
270
|
+
}
|
|
271
|
+
const data = gateMap.get(gateId);
|
|
272
|
+
data.count += 1;
|
|
273
|
+
if (!data.action && action) {
|
|
274
|
+
data.action = action;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return gateMap;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* 4. Unhandled Denies Detection
|
|
283
|
+
* Identifies repeated triggers of the same gate ID and captures representative action.
|
|
284
|
+
*/
|
|
285
|
+
function detectUnhandledDenies(entries) {
|
|
286
|
+
const findings = [];
|
|
287
|
+
const gateMap = aggregateGateDenies(entries);
|
|
288
|
+
|
|
289
|
+
for (const [gateId, { count, action }] of gateMap.entries()) {
|
|
290
|
+
if (count >= 2) {
|
|
291
|
+
findings.push({
|
|
292
|
+
type: 'unhandled_denies',
|
|
293
|
+
gateId,
|
|
294
|
+
action: action || gateId,
|
|
295
|
+
occurrences: count,
|
|
296
|
+
severity: count >= 5 ? 'critical' : 'high',
|
|
297
|
+
summary: `Gate "${gateId}" was triggered ${count} times without automated resolution`,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return findings;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Rank failure modes by impact score: occurrences * severity_weight
|
|
307
|
+
*/
|
|
308
|
+
function rankFailureModes(findings) {
|
|
309
|
+
return findings
|
|
310
|
+
.map((f) => {
|
|
311
|
+
const weight = FAILURE_MODE_WEIGHTS[f.type] || 1;
|
|
312
|
+
const count = Number(f.occurrences || 1);
|
|
313
|
+
let sevMultiplier = 1;
|
|
314
|
+
if (f.severity === 'critical') {
|
|
315
|
+
sevMultiplier = 3;
|
|
316
|
+
} else if (f.severity === 'high') {
|
|
317
|
+
sevMultiplier = 2;
|
|
318
|
+
}
|
|
319
|
+
const impactScore = count * weight * sevMultiplier;
|
|
320
|
+
return { ...f, impactScore };
|
|
321
|
+
})
|
|
322
|
+
.sort((a, b) => b.impactScore - a.impactScore);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function buildGatePattern(type, actionText, cleanToken) {
|
|
326
|
+
if (type === 'redundant_tool_calls' || type === 'retry_stall' || type === 'unhandled_denies') {
|
|
327
|
+
const truncated = (actionText || '').slice(0, 60);
|
|
328
|
+
const escaped = truncated.replace(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`);
|
|
329
|
+
return escaped.length > 0 ? `^${escaped}` : '.*';
|
|
330
|
+
}
|
|
331
|
+
if (type === 'expensive_span') {
|
|
332
|
+
if (actionText && actionText !== 'expensive_span' && actionText !== 'repeated_action') {
|
|
333
|
+
const truncated = actionText.slice(0, 60);
|
|
334
|
+
const escaped = truncated.replace(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`);
|
|
335
|
+
return escaped.length > 0 ? `^${escaped}` : String.raw`cat\s+.*|head\s+-[0-9]{4,}|tail\s+-[0-9]{4,}`;
|
|
336
|
+
}
|
|
337
|
+
return String.raw`cat\s+.*|head\s+-[0-9]{4,}|tail\s+-[0-9]{4,}`;
|
|
338
|
+
}
|
|
339
|
+
return `.*${cleanToken}.*`;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function getRemediationForFailureMode(type) {
|
|
343
|
+
switch (type) {
|
|
344
|
+
case 'retry_stall':
|
|
345
|
+
return 'Do not retry the exact failed command without modifying input or environment state.';
|
|
346
|
+
case 'redundant_tool_calls':
|
|
347
|
+
return 'Cached state is unchanged; proceed with the next task step instead of repeating the query.';
|
|
348
|
+
case 'expensive_span':
|
|
349
|
+
return 'Use targeted line ranges or token-shunt instead of full file dumps.';
|
|
350
|
+
default:
|
|
351
|
+
return 'Review active gate requirements before invoking.';
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Synthesize concrete pre-action gate fix from a failure mode
|
|
357
|
+
*/
|
|
358
|
+
function synthesizeGateFix(failureMode) {
|
|
359
|
+
const actionText = failureMode.action || failureMode.gateId || 'repeated_action';
|
|
360
|
+
const cleanToken = actionText.replace(/[^a-zA-Z0-9_-]/g, '_').slice(0, 30);
|
|
361
|
+
const hash = crypto.createHash('sha256').update(actionText).digest('hex').slice(0, 8);
|
|
362
|
+
const gateId = `auto-promoted-halo-${cleanToken}-${hash}`.toLowerCase();
|
|
363
|
+
const pattern = buildGatePattern(failureMode.type, actionText, cleanToken);
|
|
364
|
+
const suggestedAction = failureMode.severity === 'critical' ? 'block' : 'warn';
|
|
365
|
+
const remediation = getRemediationForFailureMode(failureMode.type);
|
|
366
|
+
|
|
367
|
+
return {
|
|
368
|
+
id: gateId,
|
|
369
|
+
pattern,
|
|
370
|
+
action: suggestedAction,
|
|
371
|
+
severity: failureMode.severity,
|
|
372
|
+
reason: `HALO trace optimizer detected ${failureMode.type} (${failureMode.occurrences}x): ${failureMode.summary}`,
|
|
373
|
+
remediation,
|
|
374
|
+
source: 'halo-trace-optimizer',
|
|
375
|
+
evalFixture: {
|
|
376
|
+
input: { command: actionText },
|
|
377
|
+
expectedAction: suggestedAction,
|
|
378
|
+
expectedGate: gateId,
|
|
379
|
+
},
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Apply synthesized fixes to .thumbgate/auto-promoted-gates.json
|
|
385
|
+
*/
|
|
386
|
+
function applyFixes(fixes, options = {}) {
|
|
387
|
+
const autoGatesPath =
|
|
388
|
+
options.autoGatesPath ||
|
|
389
|
+
(typeof getAutoGatesPath === 'function'
|
|
390
|
+
? getAutoGatesPath()
|
|
391
|
+
: path.join(process.cwd(), '.thumbgate', 'auto-promoted-gates.json'));
|
|
392
|
+
|
|
393
|
+
let currentConfig = { version: 1, gates: [], promotionLog: [] };
|
|
394
|
+
if (fs.existsSync(autoGatesPath)) {
|
|
395
|
+
try {
|
|
396
|
+
currentConfig = JSON.parse(fs.readFileSync(autoGatesPath, 'utf8'));
|
|
397
|
+
} catch (err) {
|
|
398
|
+
process.stderr.write(`[HALO] Warning: failed to parse ${autoGatesPath}: ${err.message}. Aborting apply to prevent corruption.\n`);
|
|
399
|
+
return [];
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
currentConfig.gates = Array.isArray(currentConfig.gates) ? currentConfig.gates : [];
|
|
404
|
+
currentConfig.promotionLog = Array.isArray(currentConfig.promotionLog) ? currentConfig.promotionLog : [];
|
|
405
|
+
|
|
406
|
+
const existingIds = new Set(currentConfig.gates.map((g) => g.id));
|
|
407
|
+
const applied = [];
|
|
408
|
+
const nowMs = Date.now();
|
|
409
|
+
const ttlMs = typeof getRuleTtlMs === 'function' ? getRuleTtlMs() : 90 * 24 * 60 * 60 * 1000;
|
|
410
|
+
|
|
411
|
+
for (const fix of fixes) {
|
|
412
|
+
if (!existingIds.has(fix.id)) {
|
|
413
|
+
const newGate = {
|
|
414
|
+
id: fix.id,
|
|
415
|
+
pattern: fix.pattern,
|
|
416
|
+
action: fix.action,
|
|
417
|
+
message: fix.reason,
|
|
418
|
+
remediation: fix.remediation,
|
|
419
|
+
severity: fix.severity,
|
|
420
|
+
source: fix.source,
|
|
421
|
+
promotedAt: new Date(nowMs).toISOString(),
|
|
422
|
+
expiresAt: new Date(nowMs + ttlMs).toISOString(),
|
|
423
|
+
};
|
|
424
|
+
currentConfig.gates.push(newGate);
|
|
425
|
+
currentConfig.promotionLog.push({
|
|
426
|
+
id: fix.id,
|
|
427
|
+
promotedAt: newGate.promotedAt,
|
|
428
|
+
source: 'halo-trace-optimizer',
|
|
429
|
+
});
|
|
430
|
+
existingIds.add(fix.id);
|
|
431
|
+
applied.push(fix.id);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (applied.length > 0) {
|
|
436
|
+
const dir = path.dirname(autoGatesPath);
|
|
437
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
438
|
+
const tmpPath = `${autoGatesPath}.tmp.${Date.now()}.${crypto.randomBytes(4).toString('hex')}`;
|
|
439
|
+
fs.writeFileSync(tmpPath, JSON.stringify(currentConfig, null, 2) + '\n', 'utf8');
|
|
440
|
+
fs.renameSync(tmpPath, autoGatesPath);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
return applied;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function buildHaloTraceOptimizerReport(options = {}) {
|
|
447
|
+
// 1. Anti-clone check
|
|
448
|
+
const cloneDetected = detectCloneAttempt(options.cloneTarget || process.env.HALO_CLONE_MODE);
|
|
449
|
+
if (cloneDetected.length > 0 || options['clone-halo'] || options.cloneHalo) {
|
|
450
|
+
return {
|
|
451
|
+
ok: false,
|
|
452
|
+
name: 'halo-trace-optimizer',
|
|
453
|
+
status: 'fail',
|
|
454
|
+
source: SOURCE_URL,
|
|
455
|
+
refusal: 'halo_clone_refused',
|
|
456
|
+
reason: 'ThumbGate steals the HALO Trace-to-Fix FORMAT onto existing rails. We do not clone Inference.net catalyst or cloud OTLP dependencies.',
|
|
457
|
+
cloneSignals: cloneDetected,
|
|
458
|
+
rankedFailureModes: [],
|
|
459
|
+
synthesizedFixes: [],
|
|
460
|
+
applied: [],
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (options['map-only'] || options.mapOnly) {
|
|
465
|
+
return {
|
|
466
|
+
ok: true,
|
|
467
|
+
name: 'halo-trace-optimizer',
|
|
468
|
+
status: 'ready',
|
|
469
|
+
source: SOURCE_URL,
|
|
470
|
+
refusal: null,
|
|
471
|
+
mapping: {
|
|
472
|
+
haloConcept: 'Analyze OpenTelemetry traces -> rank failure modes -> ship concrete fixes',
|
|
473
|
+
thumbGateRail: 'Analyze local audit-trail.jsonl -> detect loops/stalls -> synthesize auto-promoted gates & evals',
|
|
474
|
+
traceInputs: ['~/.thumbgate/audit-trail.jsonl', '.thumbgate/action-log.jsonl'],
|
|
475
|
+
targetGateStore: '.thumbgate/auto-promoted-gates.json',
|
|
476
|
+
},
|
|
477
|
+
rankedFailureModes: [],
|
|
478
|
+
synthesizedFixes: [],
|
|
479
|
+
applied: [],
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// 2. Load trace entries
|
|
484
|
+
const tracePaths = resolveTraceLogPaths(options.trace || options.tracePath);
|
|
485
|
+
let entries = [];
|
|
486
|
+
if (Array.isArray(options.entries)) {
|
|
487
|
+
entries = options.entries;
|
|
488
|
+
} else {
|
|
489
|
+
for (const p of tracePaths) {
|
|
490
|
+
entries.push(...parseJsonlFile(p));
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// 3. Detect failure modes
|
|
495
|
+
const rawFindings = [
|
|
496
|
+
...detectRedundantToolCalls(entries),
|
|
497
|
+
...detectRetryStalls(entries),
|
|
498
|
+
...detectExpensiveSpans(entries),
|
|
499
|
+
...detectUnhandledDenies(entries),
|
|
500
|
+
];
|
|
501
|
+
|
|
502
|
+
// 4. Rank failure modes
|
|
503
|
+
const minOccurrences = Number(options['min-occurrences'] || options.minOccurrences || 1);
|
|
504
|
+
const rankedFailureModes = rankFailureModes(rawFindings).filter((f) => f.occurrences >= minOccurrences);
|
|
505
|
+
|
|
506
|
+
// 5. Synthesize concrete gate fixes
|
|
507
|
+
const synthesizedFixes = rankedFailureModes.map(synthesizeGateFix);
|
|
508
|
+
|
|
509
|
+
// 6. Apply if requested
|
|
510
|
+
let applied = [];
|
|
511
|
+
if (options.apply && synthesizedFixes.length > 0) {
|
|
512
|
+
applied = applyFixes(synthesizedFixes, { autoGatesPath: options.autoGatesPath });
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
return {
|
|
516
|
+
ok: true,
|
|
517
|
+
name: 'halo-trace-optimizer',
|
|
518
|
+
status: 'ready',
|
|
519
|
+
source: SOURCE_URL,
|
|
520
|
+
refusal: null,
|
|
521
|
+
summary: {
|
|
522
|
+
tracePaths,
|
|
523
|
+
tracesAnalyzed: entries.length,
|
|
524
|
+
failureModesFound: rankedFailureModes.length,
|
|
525
|
+
appliedCount: applied.length,
|
|
526
|
+
},
|
|
527
|
+
rankedFailureModes,
|
|
528
|
+
synthesizedFixes,
|
|
529
|
+
applied,
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function formatHaloTraceOptimizerReport(report) {
|
|
534
|
+
const lines = [
|
|
535
|
+
'=== HALO Trace Optimizer (ThumbGate FORMAT Steal) ===',
|
|
536
|
+
`source: ${report.source}`,
|
|
537
|
+
`status: ${report.status}`,
|
|
538
|
+
];
|
|
539
|
+
|
|
540
|
+
if (report.refusal) {
|
|
541
|
+
lines.push(
|
|
542
|
+
`refusal: ${report.refusal}`,
|
|
543
|
+
`reason: ${report.reason}`
|
|
544
|
+
);
|
|
545
|
+
return lines.join('\n') + '\n';
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
if (report.mapping) {
|
|
549
|
+
lines.push(
|
|
550
|
+
'Architecture Mapping:',
|
|
551
|
+
` HALO Concept : ${report.mapping.haloConcept}`,
|
|
552
|
+
` ThumbGate Rail : ${report.mapping.thumbGateRail}`,
|
|
553
|
+
` Gate Store : ${report.mapping.targetGateStore}`
|
|
554
|
+
);
|
|
555
|
+
return lines.join('\n') + '\n';
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
lines.push(
|
|
559
|
+
`traces analyzed : ${report.summary.tracesAnalyzed}`,
|
|
560
|
+
`failure modes : ${report.summary.failureModesFound}`,
|
|
561
|
+
`fixes applied : ${report.summary.appliedCount}`,
|
|
562
|
+
''
|
|
563
|
+
);
|
|
564
|
+
|
|
565
|
+
if (report.rankedFailureModes.length === 0) {
|
|
566
|
+
lines.push('✓ No agent trace thrashing, retry stalls, or unhandled denies detected.');
|
|
567
|
+
} else {
|
|
568
|
+
lines.push('Top Ranked Failure Modes:');
|
|
569
|
+
report.rankedFailureModes.slice(0, 5).forEach((m, idx) => {
|
|
570
|
+
lines.push(
|
|
571
|
+
` [#${idx + 1}] (${m.type}) impact: ${m.impactScore} | severity: ${m.severity}`,
|
|
572
|
+
` ${m.summary}`
|
|
573
|
+
);
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
lines.push('', 'Synthesized Gate Fixes:');
|
|
577
|
+
report.synthesizedFixes.slice(0, 3).forEach((f, idx) => {
|
|
578
|
+
lines.push(
|
|
579
|
+
` [Fix #${idx + 1}] ${f.id} [${f.action}]`,
|
|
580
|
+
` pattern : ${f.pattern}`,
|
|
581
|
+
` remediation: ${f.remediation}`
|
|
582
|
+
);
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
return lines.join('\n') + '\n';
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
function main() {
|
|
590
|
+
const args = process.argv.slice(2);
|
|
591
|
+
const options = {};
|
|
592
|
+
for (const arg of args) {
|
|
593
|
+
if (arg === '--json') options.json = true;
|
|
594
|
+
else if (arg === '--map-only') options.mapOnly = true;
|
|
595
|
+
else if (arg === '--apply') options.apply = true;
|
|
596
|
+
else if (arg.startsWith('--trace=')) options.trace = arg.slice(8);
|
|
597
|
+
else if (arg.startsWith('--min-occurrences=')) options.minOccurrences = Number(arg.slice(18));
|
|
598
|
+
else if (arg === '--clone-halo') options.cloneHalo = true;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const report = buildHaloTraceOptimizerReport(options);
|
|
602
|
+
if (options.json) {
|
|
603
|
+
console.log(JSON.stringify(report, null, 2));
|
|
604
|
+
} else {
|
|
605
|
+
process.stdout.write(formatHaloTraceOptimizerReport(report));
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
if (report.status === 'fail') process.exitCode = 1;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
if (require.main === module) {
|
|
612
|
+
main();
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
module.exports = {
|
|
616
|
+
SOURCE_URL,
|
|
617
|
+
CLONE_PATTERNS,
|
|
618
|
+
detectCloneAttempt,
|
|
619
|
+
resolveTraceLogPaths,
|
|
620
|
+
parseJsonlFile,
|
|
621
|
+
extractActionString,
|
|
622
|
+
detectRedundantToolCalls,
|
|
623
|
+
detectRetryStalls,
|
|
624
|
+
detectExpensiveSpans,
|
|
625
|
+
detectUnhandledDenies,
|
|
626
|
+
rankFailureModes,
|
|
627
|
+
synthesizeGateFix,
|
|
628
|
+
applyFixes,
|
|
629
|
+
buildHaloTraceOptimizerReport,
|
|
630
|
+
formatHaloTraceOptimizerReport,
|
|
631
|
+
};
|