tribunal-kit 9.2.6 → 9.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/.agent/ARCHITECTURE.md +2 -2
  2. package/.agent/history/architecture-intelligence.html +1487 -401
  3. package/.agent/history/architecture-model.json +9365 -5697
  4. package/.agent/history/architecture-verification.json +37 -9
  5. package/.agent/routing_index.json +2069 -3340
  6. package/.agent/rules/GEMINI.md +1 -1
  7. package/.agent/scripts/adaptive_execution.js +511 -0
  8. package/.agent/scripts/architecture_diff.js +303 -260
  9. package/.agent/scripts/architecture_extractor.js +792 -753
  10. package/.agent/scripts/architecture_health.js +293 -256
  11. package/.agent/scripts/architecture_intelligence.js +3100 -0
  12. package/.agent/scripts/architecture_verifier.js +303 -270
  13. package/.agent/scripts/architecture_visualizer.js +880 -873
  14. package/.agent/scripts/blast_radius_engine.js +274 -234
  15. package/.agent/scripts/capability_evolution.js +453 -0
  16. package/.agent/scripts/concept_extractor.js +240 -0
  17. package/.agent/scripts/consideration_engine.js +284 -0
  18. package/.agent/scripts/coverage_engine.js +102 -0
  19. package/.agent/scripts/cross_domain_engine.js +1883 -0
  20. package/.agent/scripts/engineering_memory.js +1313 -0
  21. package/.agent/scripts/integrity_manifest.js +1 -5
  22. package/.agent/scripts/judgment_engine.js +790 -0
  23. package/.agent/scripts/materiality_engine.js +251 -0
  24. package/.agent/scripts/outcome_engine.js +624 -0
  25. package/.agent/scripts/outcome_optimization_engine.js +1632 -0
  26. package/.agent/scripts/simulation_engine.js +1478 -0
  27. package/.agent/scripts/skill_intelligence.js +1371 -0
  28. package/.agent/scripts/validation_engine.js +236 -236
  29. package/.agent/scripts/verification_auditor.js +266 -0
  30. package/.agent/skill-intelligence/taxonomy/engineering-concepts.json +555 -0
  31. package/.agent/skill_topic_map.json +301 -341
  32. package/.agent/skills_inventory.json +4272 -6922
  33. package/.agent/workflows/arch.md +96 -80
  34. package/.agent/workflows/skill-intelligence.md +216 -0
  35. package/CONTRIBUTING.md +2 -2
  36. package/README.md +24 -24
  37. package/bin/adapter-install.js +1 -1
  38. package/package.json +8 -9
  39. package/plugins/core-plugin.json +1 -1
  40. package/plugins/gemini/extension.json +1 -1
  41. package/src/browser/index.js +2 -1
  42. package/src/browser/launcher.js +41 -1
  43. package/src/cli.js +3 -1
  44. package/src/commands/arch.js +261 -172
  45. package/src/commands/context.js +27 -8
  46. package/src/commands/learn.js +21 -6
  47. package/src/commands/memory.js +10 -1
  48. package/src/commands/native.js +12 -3
  49. package/src/commands/skill-intelligence.js +1165 -0
  50. package/src/commands/system1.js +105 -4
  51. package/src/context/ranker.js +337 -339
  52. package/src/evolution/engine.js +296 -295
  53. package/src/synthesis/claim_check_separator.js +294 -271
  54. package/src/system1/browser_intelligence.js +300 -0
  55. package/src/system1/constants.js +49 -0
  56. package/src/system1/decision_engine.js +498 -0
  57. package/src/system1/evidence_engine.js +602 -0
  58. package/src/system1/evolution_pipeline.js +581 -0
  59. package/src/system1/index.d.ts +114 -0
  60. package/src/system1/index.js +102 -0
  61. package/src/system1/reviewer_orchestrator.js +477 -0
  62. package/src/tui/banner.js +1 -1
  63. package/src/utils/fs.js +27 -0
@@ -0,0 +1,266 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * verification_auditor.js — Tribunal Kit Verification & Post-Execution Auditor
5
+ * ============================================================================
6
+ * Implements Phase 8 & Phase 9 of the Skill Intelligence Engine:
7
+ * - Post-Execution Coverage Recheck
8
+ * - Failure Mode Recheck
9
+ * - Implementation Verification (Concept detected vs implemented)
10
+ * - Dynamic Coverage Downgrade upon verification failure
11
+ * - Unexpected Implementation Risk & New Capability Gap Detection
12
+ * - Closed-Loop Corrective Action Generation
13
+ * - Skill Telemetry & Improvement Proposals
14
+ */
15
+
16
+ const fs = require('fs');
17
+ const path = require('path');
18
+
19
+ /**
20
+ * Audit post-execution evidence against discovered task intelligence.
21
+ *
22
+ * @param {Object|string} taskIntelligenceOrQuery - Pre-execution analysis or task query
23
+ * @param {Object} executionEvidence - Evidence from implementation & verification
24
+ * - code_diff: string (diff or modified code)
25
+ * - changed_files: string[] (list of files modified)
26
+ * - tests_executed: Array<{ name: string, target?: string, passed: boolean, error?: string }>
27
+ * - runtime_observations: string[]
28
+ * @param {Object} [options]
29
+ * @returns {Object} Post-execution audit report
30
+ */
31
+ function auditPostExecution(taskIntelligenceOrQuery, executionEvidence, options = {}) {
32
+ let taskIntelligence;
33
+ const agentDir = options.agentDir || path.resolve(__dirname, '..', '.agent');
34
+
35
+ if (typeof taskIntelligenceOrQuery === 'string') {
36
+ const { analyzeTask } = require('./skill_intelligence');
37
+ taskIntelligence = analyzeTask(taskIntelligenceOrQuery, agentDir);
38
+ } else {
39
+ taskIntelligence = taskIntelligenceOrQuery;
40
+ }
41
+
42
+ const evidence = executionEvidence || {};
43
+ const codeDiff = (evidence.code_diff || '').toLowerCase();
44
+ const changedFiles = (evidence.changed_files || []).map(f => f.toLowerCase());
45
+ const tests = evidence.tests_executed || [];
46
+ const runtimeObs = (evidence.runtime_observations || []).map(o => o.toLowerCase());
47
+
48
+ const auditFindings = [];
49
+ const downgradedConcepts = [];
50
+ const verifiedConcepts = [];
51
+ const unverifiedFailureModes = [];
52
+ const newCapabilityGaps = [];
53
+ const correctiveActions = [];
54
+
55
+ // Extract concept list from task intelligence
56
+ const allConcepts = Array.isArray(taskIntelligence.concepts)
57
+ ? taskIntelligence.concepts
58
+ : taskIntelligence.concepts && taskIntelligence.concepts.all
59
+ ? taskIntelligence.concepts.all.map(name => ({
60
+ name,
61
+ id: name.toLowerCase().replace(/[^a-z0-9]+/g, '-'),
62
+ }))
63
+ : (taskIntelligence.coverage || []).map(c => ({ id: c.concept_id, name: c.concept_name }));
64
+
65
+ // 1. Implementation Verification (Was each discovered concept addressed in code or files?)
66
+ for (const concept of allConcepts) {
67
+ const cId = (concept.id || concept.name || '').toLowerCase().replace(/[^a-z0-9]+/g, '-');
68
+ const cName = (concept.name || concept.id || '').toLowerCase();
69
+ const tokens = cName.split(/\s+/).filter(t => t.length > 3);
70
+
71
+ // Look for traces of concept in diff, changed filenames, or tests
72
+ let hasCodeTrace = false;
73
+ if (codeDiff.includes(cId) || codeDiff.includes(cName)) {
74
+ hasCodeTrace = true;
75
+ } else {
76
+ hasCodeTrace = tokens.some(
77
+ tok => codeDiff.includes(tok) || changedFiles.some(f => f.includes(tok)),
78
+ );
79
+ }
80
+
81
+ const testForConcept = tests.find(
82
+ t =>
83
+ (t.target && (t.target.toLowerCase() === cId || t.target.toLowerCase().includes(cId))) ||
84
+ (t.name &&
85
+ (t.name.toLowerCase().includes(cName) ||
86
+ tokens.some(tok => t.name.toLowerCase().includes(tok)))),
87
+ );
88
+
89
+ if (!hasCodeTrace && !testForConcept) {
90
+ auditFindings.push({
91
+ type: 'UNIMPLEMENTED_CONCEPT',
92
+ severity: 'HIGH',
93
+ concept: concept.name || concept.id,
94
+ detail: `Discovered concept '${concept.name || concept.id}' had no identifiable code changes or tests in execution evidence.`,
95
+ });
96
+ correctiveActions.push(`Implement missing capability for '${concept.name || concept.id}'.`);
97
+ } else if (testForConcept) {
98
+ if (!testForConcept.passed) {
99
+ // Concept was implemented but verification failed!
100
+ downgradedConcepts.push({
101
+ concept: concept.name || concept.id,
102
+ previous_coverage: 'PARTIAL',
103
+ current_coverage: 'DOWNGRADED_FAILED',
104
+ reason: testForConcept.error || `Verification test '${testForConcept.name}' failed.`,
105
+ });
106
+ auditFindings.push({
107
+ type: 'VERIFICATION_FAILURE',
108
+ severity: 'CRITICAL',
109
+ concept: concept.name || concept.id,
110
+ detail: `Verification for '${concept.name || concept.id}' failed: ${testForConcept.error || 'Test assertion failed.'}`,
111
+ });
112
+ correctiveActions.push(
113
+ `Fix verification failure in '${concept.name || concept.id}' (${testForConcept.name}): ${testForConcept.error || 'Assertion failed'} and re-verify.`,
114
+ );
115
+ } else {
116
+ verifiedConcepts.push({
117
+ concept: concept.name || concept.id,
118
+ test: testForConcept.name,
119
+ status: 'VERIFIED',
120
+ });
121
+ }
122
+ } else {
123
+ // Code exists but no explicit test ran
124
+ auditFindings.push({
125
+ type: 'UNVERIFIED_IMPLEMENTATION',
126
+ severity: 'MEDIUM',
127
+ concept: concept.name || concept.id,
128
+ detail: `Code trace exists for '${concept.name || concept.id}', but no targeted verification test was executed.`,
129
+ });
130
+ correctiveActions.push(`Add targeted verification test for '${concept.name || concept.id}'.`);
131
+ }
132
+ }
133
+
134
+ // 2. Failure Mode Recheck
135
+ const failureModes = taskIntelligence.failure_modes || [];
136
+ for (const fm of failureModes) {
137
+ const fmNormalized = fm.toLowerCase().replace(/[^a-z0-9]+/g, ' ');
138
+ const testAddressed = tests.some(
139
+ t =>
140
+ (t.name && t.name.toLowerCase().includes(fmNormalized)) ||
141
+ (t.target && t.target.toLowerCase().includes(fmNormalized)),
142
+ );
143
+ const obsAddressed = runtimeObs.some(o => o.includes(fmNormalized));
144
+
145
+ if (!testAddressed && !obsAddressed) {
146
+ unverifiedFailureModes.push(fm);
147
+ }
148
+ }
149
+
150
+ if (unverifiedFailureModes.length > 0) {
151
+ auditFindings.push({
152
+ type: 'UNVERIFIED_FAILURE_MODES',
153
+ severity: 'MEDIUM',
154
+ count: unverifiedFailureModes.length,
155
+ failure_modes: unverifiedFailureModes,
156
+ detail: `${unverifiedFailureModes.length} identified failure modes were not explicitly verified in the test run.`,
157
+ });
158
+ }
159
+
160
+ // 3. Unexpected Implementation Risk & New Capability Gap Detection
161
+ // Check if codeDiff introduced risky anti-patterns
162
+ const riskPatterns = [
163
+ {
164
+ regex: /(?:SELECT\s+.*\s+FROM\s+.*\s+WHERE\s+.*['"]\s*\+)|(?:\$\{[^}]*\}\s*WHERE)/i,
165
+ risk: 'SQL Injection Vulnerability',
166
+ gapSkill: 'agentshield-security',
167
+ recommendation: 'Use parameterized queries or ORM bindings instead of string interpolation.',
168
+ },
169
+ {
170
+ regex: /(?:password|secret|api_key|token)\s*=\s*['"][a-zA-Z0-9_\-]{8,}['"]/i,
171
+ risk: 'Hardcoded Secret / Credential',
172
+ gapSkill: 'agentshield-security',
173
+ recommendation: 'Extract secrets to environment variables.',
174
+ },
175
+ {
176
+ regex: /(?:Promise\.all\(\s*.*\.map\()/i,
177
+ risk: 'Unbounded Concurrency Spike',
178
+ gapSkill: 'error-resilience',
179
+ recommendation: 'Use p-limit or p-queue to throttle parallel execution.',
180
+ },
181
+ ];
182
+
183
+ const activePipeline =
184
+ (taskIntelligence.composition && taskIntelligence.composition.pipeline) || [];
185
+
186
+ for (const rp of riskPatterns) {
187
+ if (rp.regex.test(codeDiff)) {
188
+ const isCovered = activePipeline.includes(rp.gapSkill);
189
+ newCapabilityGaps.push({
190
+ risk: rp.risk,
191
+ recommended_skill: rp.gapSkill,
192
+ covered_by_active_pipeline: isCovered,
193
+ recommendation: rp.recommendation,
194
+ });
195
+ auditFindings.push({
196
+ type: 'NEW_IMPLEMENTATION_RISK',
197
+ severity: 'CRITICAL',
198
+ risk: rp.risk,
199
+ detail: `New code diff introduces risk: ${rp.risk}. ${rp.recommendation}`,
200
+ });
201
+ if (!isCovered) {
202
+ correctiveActions.push(`Activate capability '${rp.gapSkill}' to remediate ${rp.risk}.`);
203
+ }
204
+ }
205
+ }
206
+
207
+ const criticalIssues = auditFindings.filter(f => f.severity === 'CRITICAL');
208
+ const highIssues = auditFindings.filter(f => f.severity === 'HIGH');
209
+ const isComplete =
210
+ criticalIssues.length === 0 && highIssues.length === 0 && downgradedConcepts.length === 0;
211
+
212
+ return {
213
+ status: isComplete ? 'VERIFIED' : 'ACTION_REQUIRED',
214
+ is_complete: isComplete,
215
+ findings_count: auditFindings.length,
216
+ findings: auditFindings,
217
+ verified_concepts: verifiedConcepts,
218
+ downgraded_concepts: downgradedConcepts,
219
+ unverified_failure_modes: unverifiedFailureModes,
220
+ new_capability_gaps: newCapabilityGaps,
221
+ corrective_actions: correctiveActions,
222
+ audit_summary: {
223
+ total_concepts_checked: allConcepts.length,
224
+ verified_count: verifiedConcepts.length,
225
+ downgraded_count: downgradedConcepts.length,
226
+ unimplemented_count: auditFindings.filter(f => f.type === 'UNIMPLEMENTED_CONCEPT').length,
227
+ new_risks_detected: newCapabilityGaps.length,
228
+ },
229
+ };
230
+ }
231
+
232
+ /**
233
+ * Generate a structured Skill Improvement Proposal when gaps or partial coverage are discovered.
234
+ *
235
+ * @param {string} targetSkillOrGap - Name of existing skill or capability gap
236
+ * @param {Object} context - Evidence context
237
+ * @param {string} [agentDir] - Agent directory
238
+ * @returns {Object} Skill improvement proposal
239
+ */
240
+ function generateImprovementProposal(targetSkillOrGap, context = {}, agentDir) {
241
+ const isExistingSkill = Boolean(context.existingSkill);
242
+ const gapName = context.gap || targetSkillOrGap;
243
+
244
+ return {
245
+ proposal_id: `prop-${(targetSkillOrGap || 'skill').replace(/[^a-z0-9]+/g, '-')}-${Date.now().toString(36)}`,
246
+ target: targetSkillOrGap,
247
+ type: isExistingSkill ? 'ENHANCE_EXISTING_SKILL' : 'EVALUATE_NEW_CAPABILITY',
248
+ rationale: isExistingSkill
249
+ ? `Extending existing skill '${targetSkillOrGap}' preserves cohesion and satisfies 11-check gate without proliferating duplicate skills.`
250
+ : `Addressing confirmed capability gap '${gapName}' with a modular, highly focused engineering capability.`,
251
+ gap_addressed: gapName,
252
+ failure_modes_covered: context.failure_modes || [],
253
+ proposed_enhancements: [
254
+ `Add explicit engineering guidelines for '${gapName}' to SKILL.md.`,
255
+ `Incorporate verification checklist tests targeting failure modes: ${(context.failure_modes || ['edge-case-regression']).join(', ')}.`,
256
+ `Update skill triggers and taxonomy mappings.`,
257
+ ],
258
+ validation_gate_passed: false,
259
+ status: 'PROPOSED_PENDING_APPROVAL',
260
+ };
261
+ }
262
+
263
+ module.exports = {
264
+ auditPostExecution,
265
+ generateImprovementProposal,
266
+ };