thumbgate 1.37.2 → 1.38.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/article-syndication-pipeline/SKILL.md +37 -0
- package/.agents/skills/aws-strands-harness-not-clone/SKILL.md +53 -0
- package/.agents/skills/ci-gha-buildkite-patterns-not-clone/SKILL.md +72 -0
- package/.agents/skills/comet-session-logger/SKILL.md +59 -0
- package/.agents/skills/datadog-llm-obs-compare-not-clone/SKILL.md +75 -0
- package/.agents/skills/deeppattern-discipline-honesty-not-clone/SKILL.md +73 -0
- package/.agents/skills/halo-trace-optimize-not-clone/SKILL.md +60 -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/salt-code-policy-honesty-not-clone/SKILL.md +76 -0
- package/.agents/skills/thumbgate-board-loop/SKILL.md +72 -0
- package/.agents/skills/thumbgate-daily-discoveries/SKILL.md +57 -0
- package/.agents/skills/typesafe-typed-questions-not-clone/SKILL.md +7 -3
- 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/mcp/server-stdio.js +1 -1
- package/adapters/opencode/opencode.json +1 -1
- package/adapters/strands/STRANDS.md +107 -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 +262 -4
- package/config/gate-templates.json +120 -0
- package/package.json +84 -12
- package/public/blog/2026-09-23-datadog-llm-obs-four-practices.html +42 -0
- 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/index.html +2 -2
- package/public/install.html +7 -7
- package/public/numbers.html +2 -2
- package/public/onboarding.html +794 -0
- package/scripts/autoresearch-runner.js +20 -1
- package/scripts/ci-gha-buildkite-patterns.js +393 -0
- package/scripts/cli-schema.js +51 -1
- package/scripts/deeppattern-discipline-honesty.js +431 -0
- package/scripts/experiment-tracker.js +5 -3
- package/scripts/halo-trace-optimizer.js +631 -0
- package/scripts/infoq-architect-honesty.js +362 -0
- package/scripts/install-thumbgate-daily-publish-launchd.sh +83 -0
- package/scripts/llm-obs-honesty.js +478 -0
- package/scripts/meko-datapack-honesty.js +414 -0
- package/scripts/mintlify-knowledge-honesty.js +647 -0
- package/scripts/model-distress-detector.js +207 -0
- package/scripts/model-distress-doctor.js +200 -0
- package/scripts/rrsi-regularizer.js +445 -0
- package/scripts/salt-code-policy-honesty.js +1204 -0
- package/scripts/strands-harness-doctor.js +390 -0
- package/scripts/tailscale-p2p-doctor.js +252 -0
- package/scripts/thumbgate-board-loop.js +432 -0
- package/scripts/thumbgate-daily-discoveries-publish.js +413 -0
- package/scripts/thumbgate-daily-discoveries-publish.sh +18 -0
- package/scripts/typesafe-typed-questions.js +332 -7
- package/scripts/workspace-evolver.js +143 -13
- package/server.json +2 -2
- package/skills/article-syndication-pipeline/SKILL.md +37 -0
- package/skills/aws-strands-harness-not-clone/SKILL.md +53 -0
- package/skills/comet-session-logger/SKILL.md +59 -0
- package/skills/thumbgate-daily-discoveries/SKILL.md +57 -0
- package/src/api/server.js +33 -4
- package/src/index.js +10 -0
- package/src/integrations/ideabrowser-connector.js +190 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* scripts/strands-harness-doctor.js
|
|
6
|
+
*
|
|
7
|
+
* Audit and enforce AWS Strands Harness Architecture (The New Stack 2026-10 FORMAT Steal).
|
|
8
|
+
*
|
|
9
|
+
* Core Principles:
|
|
10
|
+
* 1. "The way a harness manages the surrounding agent machinery materially affects cost and performance."
|
|
11
|
+
* (Token efficiency via output shunting, context compaction threshold, in-loop recovery).
|
|
12
|
+
* 2. "AWS Strands Harness came out 45% cheaper than Claude Code and Codex, and 77% cheaper on Terminal-Bench 2.1."
|
|
13
|
+
* (Tool output bounded <= 350 lines / 16KB, avoiding unpruned firehose context pollution).
|
|
14
|
+
* 3. "No features require Bedrock; all deployment paths are open."
|
|
15
|
+
* (Provider-agnostic decoupling: Bedrock, Anthropic, OpenAI, Gemini, local Ollama).
|
|
16
|
+
* 4. "Harness execution without pre-action governance is cheap, high-speed disaster."
|
|
17
|
+
* (Every tool call must pass through ThumbGate's PreToolUse diode before execution).
|
|
18
|
+
*
|
|
19
|
+
* Usage:
|
|
20
|
+
* node scripts/strands-harness-doctor.js
|
|
21
|
+
* node scripts/strands-harness-doctor.js --json
|
|
22
|
+
* node scripts/strands-harness-doctor.js --map-only
|
|
23
|
+
* node scripts/strands-harness-doctor.js --check
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const fs = require('node:fs');
|
|
27
|
+
const path = require('node:path');
|
|
28
|
+
|
|
29
|
+
const STRANDS_DEFAULTS = Object.freeze({
|
|
30
|
+
maxOutputLines: 350,
|
|
31
|
+
maxOutputBytes: 16 * 1024, // 16 KB
|
|
32
|
+
compactionThresholdPct: 0.75, // Trigger compaction at 75% context window utilization
|
|
33
|
+
terminalBenchSavingsBenchmarkPct: 0.77, // 77% cheaper on Terminal-Bench 2.1 ($56.29 vs $248.05)
|
|
34
|
+
overallCostSavingsBenchmarkPct: 0.45, // 45% cheaper across ALFWorld, GAIA, WebShop, etc.
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Shunt / truncate oversized tool output to prevent context window pollution.
|
|
39
|
+
*/
|
|
40
|
+
function evaluateOutputShunt(output, options = {}) {
|
|
41
|
+
const maxLines = options.maxLines || options.maxOutputLines || STRANDS_DEFAULTS.maxOutputLines;
|
|
42
|
+
const maxBytes = options.maxBytes || options.maxOutputBytes || STRANDS_DEFAULTS.maxOutputBytes;
|
|
43
|
+
|
|
44
|
+
if (typeof output !== 'string') {
|
|
45
|
+
output = String(output || '');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const byteLength = Buffer.byteLength(output, 'utf8');
|
|
49
|
+
const lines = output.split('\n');
|
|
50
|
+
const lineCount = lines.length;
|
|
51
|
+
|
|
52
|
+
const requiresShunt = lineCount > maxLines || byteLength > maxBytes;
|
|
53
|
+
|
|
54
|
+
if (!requiresShunt) {
|
|
55
|
+
return {
|
|
56
|
+
shunted: false,
|
|
57
|
+
originalLineCount: lineCount,
|
|
58
|
+
originalBytes: byteLength,
|
|
59
|
+
shuntedContent: output,
|
|
60
|
+
reductionPct: 0,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const keepLines = Math.floor(maxLines / 2);
|
|
65
|
+
let head = lines.slice(0, keepLines).join('\n');
|
|
66
|
+
let tail = lines.slice(-keepLines).join('\n');
|
|
67
|
+
const omittedCount = Math.max(0, lineCount - (keepLines * 2));
|
|
68
|
+
|
|
69
|
+
const marker = `\n... [ThumbGate Token-Shunt: ${omittedCount} lines (${Math.max(0, byteLength - maxBytes)} bytes) omitted. Target with grep or offset/limit] ...\n`;
|
|
70
|
+
let shuntedContent = `${head}${marker}${tail}`;
|
|
71
|
+
let shuntedBytes = Buffer.byteLength(shuntedContent, 'utf8');
|
|
72
|
+
|
|
73
|
+
// Enforce byte limit strictly: if head + marker + tail exceeds maxBytes (e.g. single-line or wide lines)
|
|
74
|
+
if (shuntedBytes > maxBytes) {
|
|
75
|
+
const markerBytes = Buffer.byteLength(marker, 'utf8');
|
|
76
|
+
const budgetForText = Math.max(0, maxBytes - markerBytes);
|
|
77
|
+
const halfChars = Math.floor(budgetForText / 2);
|
|
78
|
+
|
|
79
|
+
let headStr = output.slice(0, halfChars);
|
|
80
|
+
let tailStr = output.slice(-halfChars);
|
|
81
|
+
while (Buffer.byteLength(`${headStr}${marker}${tailStr}`, 'utf8') > maxBytes && (headStr.length > 0 || tailStr.length > 0)) {
|
|
82
|
+
if (headStr.length > 0) headStr = headStr.slice(0, -10);
|
|
83
|
+
if (tailStr.length > 0) tailStr = tailStr.slice(10);
|
|
84
|
+
}
|
|
85
|
+
shuntedContent = `${headStr}${marker}${tailStr}`;
|
|
86
|
+
shuntedBytes = Buffer.byteLength(shuntedContent, 'utf8');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const reductionPct = Number(((1 - (shuntedBytes / byteLength)) * 100).toFixed(2));
|
|
90
|
+
const finalLines = shuntedContent.split('\n').length;
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
shunted: true,
|
|
94
|
+
originalLineCount: lineCount,
|
|
95
|
+
originalBytes: byteLength,
|
|
96
|
+
shuntedLineCount: finalLines,
|
|
97
|
+
shuntedBytes,
|
|
98
|
+
reductionPct,
|
|
99
|
+
shuntedContent,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Audit context compaction threshold and ensure durable rules are pinned.
|
|
105
|
+
*/
|
|
106
|
+
function evaluateCompactionThreshold({
|
|
107
|
+
currentTokens = 0,
|
|
108
|
+
maxWindowTokens = 128000,
|
|
109
|
+
thresholdPct = STRANDS_DEFAULTS.compactionThresholdPct,
|
|
110
|
+
pinnedRules = [],
|
|
111
|
+
} = {}) {
|
|
112
|
+
const utilization = maxWindowTokens > 0 ? currentTokens / maxWindowTokens : 0;
|
|
113
|
+
const shouldCompact = utilization >= thresholdPct;
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
utilization: Number((utilization * 100).toFixed(2)),
|
|
117
|
+
thresholdPct: Number((thresholdPct * 100).toFixed(2)),
|
|
118
|
+
shouldCompact,
|
|
119
|
+
pinnedRulesPreserved: Array.isArray(pinnedRules) && pinnedRules.length > 0,
|
|
120
|
+
pinnedRuleCount: Array.isArray(pinnedRules) ? pinnedRules.length : 0,
|
|
121
|
+
status: shouldCompact ? 'compaction_recommended' : 'window_healthy',
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Audit in-loop overflow recovery without crashing the session.
|
|
127
|
+
*/
|
|
128
|
+
function simulateOverflowRecovery({
|
|
129
|
+
turns = [],
|
|
130
|
+
maxTokens = 8000,
|
|
131
|
+
pinnedSystemPrompt = 'You are a governed agent operating under ThumbGate firewalls.',
|
|
132
|
+
} = {}) {
|
|
133
|
+
const totalTokens = turns.reduce((acc, t) => acc + (t.tokens || 100), 0);
|
|
134
|
+
const overflow = totalTokens > maxTokens;
|
|
135
|
+
|
|
136
|
+
if (!overflow) {
|
|
137
|
+
return {
|
|
138
|
+
recovered: false,
|
|
139
|
+
action: 'none',
|
|
140
|
+
survivingTurns: turns.length,
|
|
141
|
+
estimatedTokens: totalTokens,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Gracefully retain system prompt, last turn, and lessons
|
|
146
|
+
const surviving = turns.filter((t) => t.isPinned || t.isLastTurn);
|
|
147
|
+
const prunedCount = turns.length - surviving.length;
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
recovered: true,
|
|
151
|
+
action: 'pruned_history_in_loop',
|
|
152
|
+
prunedTurns: prunedCount,
|
|
153
|
+
survivingTurns: surviving.length,
|
|
154
|
+
systemPromptPreserved: Boolean(pinnedSystemPrompt),
|
|
155
|
+
status: 'recovered_without_throw',
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Verify that the harness does not hard-code Bedrock or proprietary lock-in.
|
|
161
|
+
*/
|
|
162
|
+
function auditProviderDecoupling(config = {}) {
|
|
163
|
+
const supportedProviders = ['bedrock', 'anthropic', 'openai', 'gemini', 'ollama'];
|
|
164
|
+
const provider = (config.provider || 'bedrock').toLowerCase();
|
|
165
|
+
const isDecoupled = supportedProviders.includes(provider);
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
configuredProvider: provider,
|
|
169
|
+
supportedProviders,
|
|
170
|
+
isDecoupled,
|
|
171
|
+
supportsLocalFallback: supportedProviders.includes('ollama'),
|
|
172
|
+
requiresProprietaryLockIn: false,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Audit pre-action safety diode: every mutating tool must be governed.
|
|
178
|
+
*/
|
|
179
|
+
function evaluatePreActionDiode(toolCall = {}) {
|
|
180
|
+
const name = toolCall.name || '';
|
|
181
|
+
const input = toolCall.input || {};
|
|
182
|
+
const cmd = input.command || input.cmd || '';
|
|
183
|
+
|
|
184
|
+
const dangerousPatterns = [
|
|
185
|
+
/rm\s+(-rf|-fr|--recursive)/i,
|
|
186
|
+
/git\s+push.*(--force|-f)/i,
|
|
187
|
+
/chmod\s+777/i,
|
|
188
|
+
/deploy-to-qa\.py/i,
|
|
189
|
+
/api[_-]?key\s*=\s*['"][a-z0-9_-]{20,}['"]/i,
|
|
190
|
+
];
|
|
191
|
+
|
|
192
|
+
let blocked = false;
|
|
193
|
+
let violation = null;
|
|
194
|
+
|
|
195
|
+
for (const pattern of dangerousPatterns) {
|
|
196
|
+
if (pattern.test(cmd) || pattern.test(JSON.stringify(input))) {
|
|
197
|
+
blocked = true;
|
|
198
|
+
violation = `Matched dangerous pattern: ${pattern.toString()}`;
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
toolName: name,
|
|
205
|
+
enforced: true,
|
|
206
|
+
decision: blocked ? 'BLOCK' : 'ALLOW',
|
|
207
|
+
violation,
|
|
208
|
+
diodeStatus: blocked ? 'INTERDICTED' : 'CLEAN',
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Run full doctor audit on AWS Strands Harness configuration and runtime state.
|
|
214
|
+
*/
|
|
215
|
+
function runDoctor(options = {}) {
|
|
216
|
+
const rootDir = options.rootDir || process.cwd();
|
|
217
|
+
const configPath = path.join(rootDir, 'adapters', 'strands', 'config.json');
|
|
218
|
+
|
|
219
|
+
let adapterConfig = {
|
|
220
|
+
provider: 'bedrock',
|
|
221
|
+
tokenShunt: { maxOutputLines: 350, maxOutputBytes: 16384 },
|
|
222
|
+
compaction: { thresholdPct: 0.75 },
|
|
223
|
+
preActionDiode: { enabled: true },
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
if (fs.existsSync(configPath)) {
|
|
227
|
+
try {
|
|
228
|
+
adapterConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
229
|
+
} catch {
|
|
230
|
+
// fallback to defaults
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// 1. Shunt audit
|
|
235
|
+
const sampleLargeOutput = Array.from({ length: 600 }, (_, i) => `log line ${i + 1}: agent test output`).join('\n');
|
|
236
|
+
const shuntResult = evaluateOutputShunt(sampleLargeOutput, adapterConfig.tokenShunt);
|
|
237
|
+
|
|
238
|
+
// 2. Compaction audit
|
|
239
|
+
const compactionResult = evaluateCompactionThreshold({
|
|
240
|
+
currentTokens: 100000,
|
|
241
|
+
maxWindowTokens: 128000,
|
|
242
|
+
thresholdPct: adapterConfig.compaction?.thresholdPct || 0.75,
|
|
243
|
+
pinnedRules: ['Never force-push main', 'Verify evidence before done'],
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// 3. Overflow recovery audit
|
|
247
|
+
const sampleTurns = Array.from({ length: 25 }, (_, i) => ({
|
|
248
|
+
turn: i,
|
|
249
|
+
tokens: 400,
|
|
250
|
+
isPinned: i === 0,
|
|
251
|
+
isLastTurn: i === 24,
|
|
252
|
+
}));
|
|
253
|
+
const recoveryResult = simulateOverflowRecovery({
|
|
254
|
+
turns: sampleTurns,
|
|
255
|
+
maxTokens: 8000,
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// 4. Provider decoupling audit
|
|
259
|
+
const providerResult = auditProviderDecoupling(adapterConfig);
|
|
260
|
+
|
|
261
|
+
// 5. Pre-action diode audit
|
|
262
|
+
const safeToolCall = { name: 'shell_execute', input: { command: 'git status' } };
|
|
263
|
+
const dangerousToolCall = { name: 'shell_execute', input: { command: 'rm -rf /tmp/test' } };
|
|
264
|
+
const safeDiode = evaluatePreActionDiode(safeToolCall);
|
|
265
|
+
const dangerousDiode = evaluatePreActionDiode(dangerousToolCall);
|
|
266
|
+
|
|
267
|
+
const checks = [
|
|
268
|
+
{
|
|
269
|
+
name: 'output_shunting',
|
|
270
|
+
pass: shuntResult.shunted && shuntResult.reductionPct > 30,
|
|
271
|
+
detail: `Shunted ${shuntResult.originalLineCount} -> ${shuntResult.shuntedLineCount} lines (${shuntResult.reductionPct}% token reduction)`,
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
name: 'compaction_threshold_preservation',
|
|
275
|
+
pass: compactionResult.shouldCompact && compactionResult.pinnedRulesPreserved,
|
|
276
|
+
detail: `Compaction triggered at ${compactionResult.utilization}% utilization with ${compactionResult.pinnedRuleCount} pinned rules preserved`,
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
name: 'in_loop_overflow_recovery',
|
|
280
|
+
pass: recoveryResult.recovered && recoveryResult.systemPromptPreserved,
|
|
281
|
+
detail: `Recovered without throw: pruned ${recoveryResult.prunedTurns} turns, kept ${recoveryResult.survivingTurns} vital turns`,
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
name: 'provider_decoupling',
|
|
285
|
+
pass: providerResult.isDecoupled && providerResult.supportsLocalFallback,
|
|
286
|
+
detail: `Provider '${providerResult.configuredProvider}' decoupled; local Ollama/ThumbGate fallback supported`,
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
name: 'pre_action_safety_diode',
|
|
290
|
+
pass: safeDiode.decision === 'ALLOW' && dangerousDiode.decision === 'BLOCK',
|
|
291
|
+
detail: 'ThumbGate PreToolUse diode successfully blocked dangerous mutating tool call while allowing safe query',
|
|
292
|
+
},
|
|
293
|
+
];
|
|
294
|
+
|
|
295
|
+
const overallPass = checks.every((c) => c.pass);
|
|
296
|
+
|
|
297
|
+
return {
|
|
298
|
+
name: 'strands-harness-doctor',
|
|
299
|
+
version: '1.0.0',
|
|
300
|
+
timestamp: new Date().toISOString(),
|
|
301
|
+
status: overallPass ? 'healthy' : 'unhealthy',
|
|
302
|
+
benchmarks: {
|
|
303
|
+
terminalBench2_1CostSavingsClaim: '77% cheaper ($56.29 vs $248.05 on Fable 5 across 89 trials)',
|
|
304
|
+
sixBenchmarkAverageSavingsClaim: '45% cheaper than Claude Code and Codex',
|
|
305
|
+
architectureMechanism: 'Harness-level output shunting + context compaction + in-loop recovery',
|
|
306
|
+
},
|
|
307
|
+
checks,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function printTextReport(report) {
|
|
312
|
+
console.log(`\n=== AWS Strands Harness Doctor (ThumbGate Diode) ===`);
|
|
313
|
+
console.log(`Status: ${report.status.toUpperCase()} | Timestamp: ${report.timestamp}`);
|
|
314
|
+
console.log(`\nBenchmark Reference:`);
|
|
315
|
+
console.log(` • Terminal-Bench 2.1: ${report.benchmarks.terminalBench2_1CostSavingsClaim}`);
|
|
316
|
+
console.log(` • Multi-Benchmark Avg: ${report.benchmarks.sixBenchmarkAverageSavingsClaim}`);
|
|
317
|
+
console.log(` • Core Mechanism: ${report.benchmarks.architectureMechanism}`);
|
|
318
|
+
console.log(`\nArchitectural Checks:`);
|
|
319
|
+
for (const c of report.checks) {
|
|
320
|
+
const icon = c.pass ? '✅' : '❌';
|
|
321
|
+
console.log(` ${icon} ${c.name}: ${c.detail}`);
|
|
322
|
+
}
|
|
323
|
+
console.log('');
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function main() {
|
|
327
|
+
const argSet = new Set(process.argv.slice(2));
|
|
328
|
+
const jsonMode = argSet.has('--json');
|
|
329
|
+
const mapOnly = argSet.has('--map-only');
|
|
330
|
+
const checkMode = argSet.has('--check');
|
|
331
|
+
|
|
332
|
+
if (mapOnly) {
|
|
333
|
+
const map = {
|
|
334
|
+
source: 'AWS Strands Harness (The New Stack 2026-10 / Marc Brooker)',
|
|
335
|
+
architecturePillars: [
|
|
336
|
+
'Harness-Level Output Shunting (<= 350 lines / 16KB)',
|
|
337
|
+
'Context Compaction Threshold Honesty (>= 75% window with pinned lesson preservation)',
|
|
338
|
+
'In-Loop Overflow Recovery (recovers without unhandled throw or task failure)',
|
|
339
|
+
'Multi-Model Decoupling (Bedrock, Anthropic, OpenAI, Gemini, Ollama local)',
|
|
340
|
+
'Pre-Action Governance Diode (ThumbGate PreToolUse prevents catastrophic tool mutations)',
|
|
341
|
+
],
|
|
342
|
+
rulesetMap: {
|
|
343
|
+
'gate-strands-harness-output-compaction': 'Enforces 16KB/350 line ceiling on tool returns',
|
|
344
|
+
'gate-strands-pre-action-tool-diode': 'Evaluates PreToolUse safety on shell/file/agent mutations',
|
|
345
|
+
'gate-strands-bedrock-lockin-guard': 'Ensures no feature hardcodes Bedrock-only lock-in',
|
|
346
|
+
},
|
|
347
|
+
};
|
|
348
|
+
if (jsonMode) {
|
|
349
|
+
console.log(JSON.stringify(map, null, 2));
|
|
350
|
+
} else {
|
|
351
|
+
console.log('=== AWS Strands Harness Architecture Map ===');
|
|
352
|
+
console.log(`Source: ${map.source}\n`);
|
|
353
|
+
console.log('Architecture Pillars:');
|
|
354
|
+
for (const p of map.architecturePillars) {
|
|
355
|
+
console.log(` - ${p}`);
|
|
356
|
+
}
|
|
357
|
+
console.log('\nRuleset Map:');
|
|
358
|
+
for (const [k, v] of Object.entries(map.rulesetMap)) {
|
|
359
|
+
console.log(` - ${k}: ${v}`);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
process.exit(0);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const report = runDoctor();
|
|
366
|
+
|
|
367
|
+
if (jsonMode) {
|
|
368
|
+
console.log(JSON.stringify(report, null, 2));
|
|
369
|
+
} else {
|
|
370
|
+
printTextReport(report);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (checkMode && report.status !== 'healthy') {
|
|
374
|
+
process.exit(1);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
module.exports = {
|
|
379
|
+
STRANDS_DEFAULTS,
|
|
380
|
+
evaluateOutputShunt,
|
|
381
|
+
evaluateCompactionThreshold,
|
|
382
|
+
simulateOverflowRecovery,
|
|
383
|
+
auditProviderDecoupling,
|
|
384
|
+
evaluatePreActionDiode,
|
|
385
|
+
runDoctor,
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
if (require.main === module) {
|
|
389
|
+
main();
|
|
390
|
+
}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Tailscale P2P Governance & Zero-Trust Diode Doctor.
|
|
6
|
+
*
|
|
7
|
+
* Evaluates local Tailscale connectivity, G-Set CRDT rule sync state,
|
|
8
|
+
* and Tailscale PAM / PreToolUse privileged execution diodes.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* node scripts/tailscale-p2p-doctor.js [--json] [--check] [--fixture=path]
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const fs = require('node:fs');
|
|
15
|
+
const path = require('node:path');
|
|
16
|
+
const { execFileSync } = require('node:child_process');
|
|
17
|
+
|
|
18
|
+
const SAFE_PATH = '/usr/local/bin:/usr/bin:/bin:/opt/homebrew/bin';
|
|
19
|
+
const TAILSCALE_BINS = [
|
|
20
|
+
'/usr/local/bin/tailscale',
|
|
21
|
+
'/usr/bin/tailscale',
|
|
22
|
+
'/opt/homebrew/bin/tailscale',
|
|
23
|
+
'/Applications/Tailscale.app/Contents/MacOS/Tailscale',
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
function resolveTailscaleBinary() {
|
|
27
|
+
for (const binPath of TAILSCALE_BINS) {
|
|
28
|
+
if (fs.existsSync(binPath)) {
|
|
29
|
+
return binPath;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function parseArgs(argv = process.argv.slice(2)) {
|
|
36
|
+
const options = {
|
|
37
|
+
json: false,
|
|
38
|
+
check: false,
|
|
39
|
+
fixture: null,
|
|
40
|
+
serveMcp: false,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
for (const arg of argv) {
|
|
44
|
+
if (arg === '--json') {
|
|
45
|
+
options.json = true;
|
|
46
|
+
} else if (arg === '--check') {
|
|
47
|
+
options.check = true;
|
|
48
|
+
} else if (arg === '--serve-mcp') {
|
|
49
|
+
options.serveMcp = true;
|
|
50
|
+
} else if (arg.startsWith('--fixture=')) {
|
|
51
|
+
options.fixture = arg.slice('--fixture='.length);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return options;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function probeTailscale(fixturePath = null) {
|
|
59
|
+
if (fixturePath && fs.existsSync(fixturePath)) {
|
|
60
|
+
try {
|
|
61
|
+
const data = JSON.parse(fs.readFileSync(fixturePath, 'utf8'));
|
|
62
|
+
return {
|
|
63
|
+
ok: true,
|
|
64
|
+
source: 'fixture',
|
|
65
|
+
status: {
|
|
66
|
+
backendState: data.BackendState || data.backendState || 'Running',
|
|
67
|
+
self: data.Self || data.self || null,
|
|
68
|
+
peerCount: data.peerCount ?? (data.Peer ? Object.keys(data.Peer).length : (data.peer ? Object.keys(data.peer).length : 0)),
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
} catch (err) {
|
|
72
|
+
return { ok: false, source: 'fixture_error', error: err.message };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
const bin = resolveTailscaleBinary();
|
|
78
|
+
if (!bin) {
|
|
79
|
+
throw new Error('Tailscale binary not found in safe paths');
|
|
80
|
+
}
|
|
81
|
+
const raw = execFileSync(bin, ['status', '--json'], {
|
|
82
|
+
timeout: 3000,
|
|
83
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
84
|
+
encoding: 'utf8',
|
|
85
|
+
env: { ...process.env, PATH: SAFE_PATH },
|
|
86
|
+
});
|
|
87
|
+
const parsed = JSON.parse(raw);
|
|
88
|
+
return {
|
|
89
|
+
ok: true,
|
|
90
|
+
source: 'live',
|
|
91
|
+
status: {
|
|
92
|
+
backendState: parsed.BackendState || 'Running',
|
|
93
|
+
self: parsed.Self ? {
|
|
94
|
+
id: parsed.Self.ID,
|
|
95
|
+
dnsName: parsed.Self.DNSName,
|
|
96
|
+
tailscaleIPs: parsed.Self.TailscaleIPs || [],
|
|
97
|
+
} : null,
|
|
98
|
+
peerCount: parsed.Peer ? Object.keys(parsed.Peer).length : 0,
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
} catch (err) {
|
|
102
|
+
return {
|
|
103
|
+
ok: false,
|
|
104
|
+
source: 'cli_unavailable',
|
|
105
|
+
error: 'Tailscale CLI not detected or daemon not running. Local simulation/advisory mode active.',
|
|
106
|
+
status: {
|
|
107
|
+
backendState: 'Standby',
|
|
108
|
+
self: {
|
|
109
|
+
dnsName: 'local-agent-node.tailnet.local',
|
|
110
|
+
tailscaleIPs: [],
|
|
111
|
+
},
|
|
112
|
+
peerCount: 0,
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function countPreventionRules(rootDir) {
|
|
119
|
+
const candidates = [
|
|
120
|
+
path.join(rootDir, '.thumbgate', 'rules'),
|
|
121
|
+
path.join(rootDir, '.claude', 'memory', 'feedback'),
|
|
122
|
+
path.join(rootDir, 'config', 'gates'),
|
|
123
|
+
path.join(rootDir, 'config', 'prevention-rules.json'),
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
let ruleCount = 0;
|
|
127
|
+
for (const candidate of candidates) {
|
|
128
|
+
if (fs.existsSync(candidate)) {
|
|
129
|
+
const stat = fs.statSync(candidate);
|
|
130
|
+
if (stat.isDirectory()) {
|
|
131
|
+
try {
|
|
132
|
+
const files = fs.readdirSync(candidate);
|
|
133
|
+
ruleCount += files.filter((f) => f.endsWith('.json') || f.endsWith('.md')).length;
|
|
134
|
+
} catch {
|
|
135
|
+
// Ignore read errors
|
|
136
|
+
}
|
|
137
|
+
} else if (stat.isFile()) {
|
|
138
|
+
try {
|
|
139
|
+
const parsed = JSON.parse(fs.readFileSync(candidate, 'utf8'));
|
|
140
|
+
ruleCount += Array.isArray(parsed) ? parsed.length : 1;
|
|
141
|
+
} catch {
|
|
142
|
+
ruleCount += 1;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return ruleCount;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function evaluatePamDiode(rootDir = process.cwd()) {
|
|
151
|
+
const privilegedCommands = ['rm -rf', 'sudo', 'git push --force', 'deploy-to-qa.py', 'chmod 777'];
|
|
152
|
+
const hasHooks =
|
|
153
|
+
fs.existsSync(path.join(rootDir, 'hooks', 'hooks.json')) ||
|
|
154
|
+
fs.existsSync(path.join(rootDir, '.claude', 'settings.json'));
|
|
155
|
+
return {
|
|
156
|
+
enforced: hasHooks,
|
|
157
|
+
privilegedPatternsProtected: privilegedCommands.length,
|
|
158
|
+
diodeStatus: hasHooks ? 'ACTIVE' : 'INACTIVE',
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function evaluateDiagnostics(options = {}) {
|
|
163
|
+
const rootDir = process.cwd();
|
|
164
|
+
const tailscaleProbe = probeTailscale(options.fixture);
|
|
165
|
+
const ruleCount = countPreventionRules(rootDir);
|
|
166
|
+
const pamDiode = evaluatePamDiode(rootDir);
|
|
167
|
+
|
|
168
|
+
const isHealthy = tailscaleProbe.ok || tailscaleProbe.source === 'cli_unavailable';
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
name: 'tailscale-p2p-doctor',
|
|
172
|
+
version: '1.0.0',
|
|
173
|
+
timestamp: new Date().toISOString(),
|
|
174
|
+
status: isHealthy ? 'healthy' : 'degraded',
|
|
175
|
+
network: {
|
|
176
|
+
tailscaleAvailable: tailscaleProbe.ok,
|
|
177
|
+
source: tailscaleProbe.source,
|
|
178
|
+
backendState: tailscaleProbe.status?.backendState || 'Standby',
|
|
179
|
+
selfNode: tailscaleProbe.status?.self || null,
|
|
180
|
+
peerCount: tailscaleProbe.status?.peerCount || 0,
|
|
181
|
+
p2pSyncPort: 9877,
|
|
182
|
+
},
|
|
183
|
+
crdtMesh: {
|
|
184
|
+
journalType: 'g-set-append-only',
|
|
185
|
+
replicatedRuleCount: ruleCount,
|
|
186
|
+
syncProtocol: 'HTTP/WireGuard-P2P',
|
|
187
|
+
conflictFree: true,
|
|
188
|
+
},
|
|
189
|
+
pamDiode: {
|
|
190
|
+
zeroTrustAccessEnforced: pamDiode.enforced,
|
|
191
|
+
privilegedPatternsProtected: pamDiode.privilegedPatternsProtected,
|
|
192
|
+
executionDiode: pamDiode.diodeStatus,
|
|
193
|
+
},
|
|
194
|
+
recommendations: tailscaleProbe.ok ? [
|
|
195
|
+
'Tailscale peer mesh active. Prevention rules sync automatically across all tailnet agent nodes.',
|
|
196
|
+
] : [
|
|
197
|
+
'Tailscale daemon not found locally. Install Tailscale or run inside your tailnet to enable multi-machine P2P prevention rule sync.',
|
|
198
|
+
'Local PreToolUse diode remains fully operational in standalone mode.',
|
|
199
|
+
],
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function main() {
|
|
204
|
+
const options = parseArgs();
|
|
205
|
+
|
|
206
|
+
if (options.serveMcp) {
|
|
207
|
+
const cliPath = path.resolve(__dirname, '..', 'bin', 'cli.js');
|
|
208
|
+
process.argv = [process.argv[0], cliPath, 'serve'];
|
|
209
|
+
require(cliPath);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const report = evaluateDiagnostics(options);
|
|
214
|
+
|
|
215
|
+
if (options.json) {
|
|
216
|
+
process.stdout.write(JSON.stringify(report, null, 2) + '\n');
|
|
217
|
+
} else {
|
|
218
|
+
process.stdout.write('Tailscale P2P Governance & Zero-Trust Diode Doctor\n');
|
|
219
|
+
process.stdout.write('================================================\n');
|
|
220
|
+
process.stdout.write(`Status: ${report.status.toUpperCase()}\n`);
|
|
221
|
+
process.stdout.write(`Tailnet Source: ${report.network.source}\n`);
|
|
222
|
+
process.stdout.write(`Backend State: ${report.network.backendState}\n`);
|
|
223
|
+
process.stdout.write(`Peers Detected: ${report.network.peerCount}\n`);
|
|
224
|
+
process.stdout.write(`CRDT Journal: ${report.crdtMesh.journalType} (${report.crdtMesh.replicatedRuleCount} rules)\n`);
|
|
225
|
+
process.stdout.write(`PAM Diode: ${report.pamDiode.executionDiode} (${report.pamDiode.privilegedPatternsProtected} patterns protected)\n\n`);
|
|
226
|
+
|
|
227
|
+
process.stdout.write('Recommendations:\n');
|
|
228
|
+
for (const rec of report.recommendations) {
|
|
229
|
+
process.stdout.write(` - ${rec}\n`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (options.check && report.status !== 'healthy') {
|
|
234
|
+
process.exit(1);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (require.main === module) {
|
|
239
|
+
main();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
module.exports = {
|
|
243
|
+
parseArgs,
|
|
244
|
+
probeTailscale,
|
|
245
|
+
countPreventionRules,
|
|
246
|
+
evaluatePamDiode,
|
|
247
|
+
evaluateDiagnostics,
|
|
248
|
+
main,
|
|
249
|
+
resolveTailscaleBinary,
|
|
250
|
+
TAILSCALE_BINS,
|
|
251
|
+
SAFE_PATH,
|
|
252
|
+
};
|