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,251 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * materiality_engine.js — Tribunal Kit Materiality & Proportionality Engine
5
+ * =========================================================================
6
+ * Implements Phase 3.2 & Section 5 / 11 of Outcome Optimization:
7
+ * - Materiality Classification (MATERIAL / NON_MATERIAL / OPTIONAL)
8
+ * - Materiality Rationale Generation
9
+ * - Minimum Sufficient Engineering Enforcement
10
+ * - Outcome Budget & Proportionality Checks
11
+ */
12
+
13
+ const LOW_COMPLEXITY_TRIGGERS = [
14
+ /(?:static|landing page|read-?only|documentation|readme|format|css|typo|rename|mock|demo|poc|prototype|internal tool|cli)/i,
15
+ ];
16
+
17
+ const HIGH_SCALE_OVERENGINEERING_FLAGS = [
18
+ {
19
+ match: /(?:kafka|rabbitmq|event-sourcing|cqrs)/i,
20
+ name: 'Event Streaming / CQRS',
21
+ threshold: 'Requires high-throughput async decoupling',
22
+ },
23
+ {
24
+ match: /(?:kubernetes|k8s|service-mesh|istio)/i,
25
+ name: 'Service Mesh / Container Orchestration',
26
+ threshold: 'Requires multi-container fleet governance',
27
+ },
28
+ {
29
+ match: /(?:multi-region|distributed-tracing|opentelemetry)/i,
30
+ name: 'Multi-Region Replication / APM Tracing',
31
+ threshold: 'Requires distributed enterprise architecture',
32
+ },
33
+ {
34
+ match: /(?:redis|memcached)/i,
35
+ name: 'Distributed In-Memory Caching',
36
+ threshold: 'Requires high-frequency query caching',
37
+ },
38
+ ];
39
+
40
+ /**
41
+ * Evaluate materiality for each engineering consideration.
42
+ *
43
+ * @param {Array<Object>} considerations - List of considerations from consideration_engine
44
+ * @param {string} taskQuery - User task query
45
+ * @param {Object} [conceptData] - Extracted concept metadata
46
+ * @returns {Object} Materiality evaluation summary and categorized lists
47
+ */
48
+ function evaluateMateriality(considerations = [], taskQuery = '', conceptData = {}) {
49
+ const q = (taskQuery || '').toLowerCase();
50
+ const isSimpleTask =
51
+ LOW_COMPLEXITY_TRIGGERS.some(r => r.test(q)) &&
52
+ !/(?:payment|auth|database|distributed|crypto|checkout)/i.test(q);
53
+ const risks = conceptData.risk_signals || [];
54
+
55
+ const evaluated = [];
56
+ const material = [];
57
+ const nonMaterial = [];
58
+ const optional = [];
59
+
60
+ for (const c of considerations) {
61
+ let status = 'MATERIAL';
62
+ let rationale = '';
63
+ const sev = (c.severity || 'MEDIUM').toUpperCase();
64
+ const title = c.title || '';
65
+ const cat = c.category || '';
66
+
67
+ // 1. Critical safety, financial, or auth issues are always MATERIAL
68
+ if (sev === 'CRITICAL') {
69
+ status = 'MATERIAL';
70
+ rationale = `Critical severity: failure directly compromises ${cat.toLowerCase()} (${title}).`;
71
+ }
72
+ // 2. High severity considerations mapped to active risk signals are MATERIAL
73
+ else if (sev === 'HIGH') {
74
+ const hasMatchingRisk = risks.some(
75
+ r =>
76
+ r.toLowerCase().includes(cat.toLowerCase()) ||
77
+ r.toLowerCase().includes(title.toLowerCase()),
78
+ );
79
+ if (hasMatchingRisk || !isSimpleTask) {
80
+ status = 'MATERIAL';
81
+ rationale = `High operational/integrity impact: unhandled condition causes ${title.toLowerCase()} failure under concurrent or fault conditions.`;
82
+ } else {
83
+ status = 'OPTIONAL';
84
+ rationale = `Task context indicates a lightweight/simple scope where ${title.toLowerCase()} provides hygiene but is not strictly blocking for MVP.`;
85
+ }
86
+ }
87
+ // 3. Medium severity considerations evaluated against scope
88
+ else if (sev === 'MEDIUM') {
89
+ if (isSimpleTask) {
90
+ status = 'NON_MATERIAL';
91
+ rationale = `Non-material for simple/lightweight task: implementing ${title.toLowerCase()} introduces unnecessary architectural complexity without commensurate risk reduction.`;
92
+ } else {
93
+ status = 'OPTIONAL';
94
+ rationale = `Recommended enhancement: ${title.toLowerCase()} improves observability/maintainability but does not block functional core.`;
95
+ }
96
+ }
97
+ // 4. Low severity is generally non-material or optional
98
+ else {
99
+ status = isSimpleTask ? 'NON_MATERIAL' : 'OPTIONAL';
100
+ rationale = `Discretionary consideration with minor risk impact.`;
101
+ }
102
+
103
+ const item = {
104
+ ...c,
105
+ materiality: status,
106
+ materiality_rationale: rationale,
107
+ };
108
+
109
+ evaluated.push(item);
110
+ if (status === 'MATERIAL') material.push(item);
111
+ else if (status === 'NON_MATERIAL') nonMaterial.push(item);
112
+ else optional.push(item);
113
+ }
114
+
115
+ return {
116
+ total_considerations: considerations.length,
117
+ material_count: material.length,
118
+ non_material_count: nonMaterial.length,
119
+ optional_count: optional.length,
120
+ material,
121
+ non_material: nonMaterial,
122
+ optional,
123
+ all_evaluated: evaluated,
124
+ };
125
+ }
126
+
127
+ /**
128
+ * Enforce the Minimum Sufficient Engineering principle.
129
+ * Detects both overengineering (introducing heavy infrastructure unnecessarily)
130
+ * and underengineering (omitting mandatory safeguards).
131
+ *
132
+ * @param {string} taskQuery - User task query
133
+ * @param {Array<string>} proposedSkillsOrComponents - Skills or components selected
134
+ * @param {Object} [context]
135
+ * @returns {Object} Proportionality evaluation
136
+ */
137
+ function checkMinimumSufficientEngineering(
138
+ taskQuery = '',
139
+ proposedSkillsOrComponents = [],
140
+ context = {},
141
+ ) {
142
+ const q = (taskQuery || '').toLowerCase();
143
+ const isSimpleTask =
144
+ LOW_COMPLEXITY_TRIGGERS.some(r => r.test(q)) &&
145
+ !/(?:payment|auth|database|distributed|crypto|checkout)/i.test(q);
146
+ const isFinancialOrCritical = /(?:payment|charge|checkout|billing|order|token|jwt)/i.test(q);
147
+
148
+ const proposed = proposedSkillsOrComponents.map(s => s.toLowerCase());
149
+ const unnecessaryComponents = [];
150
+ const missingEssentials = [];
151
+
152
+ // Overengineering check for simple tasks
153
+ if (isSimpleTask) {
154
+ for (const flag of HIGH_SCALE_OVERENGINEERING_FLAGS) {
155
+ if (proposed.some(p => flag.match.test(p))) {
156
+ unnecessaryComponents.push({
157
+ component: flag.name,
158
+ reason: `Violates minimum sufficient engineering: Task is a simple/lightweight request; ${flag.threshold}.`,
159
+ });
160
+ }
161
+ }
162
+ }
163
+
164
+ // Underengineering check for critical/financial tasks
165
+ if (isFinancialOrCritical) {
166
+ const hasIdempotencyOrResilience = proposed.some(
167
+ p => p.includes('idempotenc') || p.includes('resilience') || p.includes('error-resilience'),
168
+ );
169
+ const hasDataIntegrityOrDB = proposed.some(
170
+ p => p.includes('database') || p.includes('transaction') || p.includes('sql'),
171
+ );
172
+
173
+ if (!hasIdempotencyOrResilience) {
174
+ missingEssentials.push({
175
+ capability: 'Idempotency & Duplicate Request Protection',
176
+ reason: 'Financial operations require duplicate charge defense during retries.',
177
+ });
178
+ }
179
+ if (!hasDataIntegrityOrDB) {
180
+ missingEssentials.push({
181
+ capability: 'Transaction Integrity & Atomic Rollback',
182
+ reason:
183
+ 'Multi-step financial mutations must be scoped to atomic database transaction boundaries.',
184
+ });
185
+ }
186
+ }
187
+
188
+ const isOverengineered = unnecessaryComponents.length > 0;
189
+ const isUnderengineered = missingEssentials.length > 0;
190
+
191
+ let verdict = 'MINIMUM_SUFFICIENT';
192
+ if (isOverengineered && isUnderengineered) verdict = 'MISALIGNED';
193
+ else if (isOverengineered) verdict = 'OVERENGINEERED';
194
+ else if (isUnderengineered) verdict = 'UNDERENGINEERED';
195
+
196
+ return {
197
+ verdict,
198
+ is_proportional: !isOverengineered && !isUnderengineered,
199
+ unnecessary_components: unnecessaryComponents,
200
+ missing_essentials: missingEssentials,
201
+ rationale:
202
+ verdict === 'MINIMUM_SUFFICIENT'
203
+ ? 'Proposed engineering depth is proportional to task scope, risks, and outcome requirements.'
204
+ : verdict === 'OVERENGINEERED'
205
+ ? `Overengineering detected: ${unnecessaryComponents.map(u => u.component).join(', ')} exceed task requirements.`
206
+ : `Underengineering detected: Missing mandatory capabilities for ${missingEssentials.map(m => m.capability).join(', ')}.`,
207
+ };
208
+ }
209
+
210
+ /**
211
+ * Determine the outcome budget constraints for a given task.
212
+ *
213
+ * @param {string} taskQuery
214
+ * @param {Object} [conceptData]
215
+ * @returns {Object} Outcome budget
216
+ */
217
+ function determineOutcomeBudget(taskQuery = '', conceptData = {}) {
218
+ const q = (taskQuery || '').toLowerCase();
219
+ const isSimple =
220
+ LOW_COMPLEXITY_TRIGGERS.some(r => r.test(q)) &&
221
+ !/(?:payment|auth|database|distributed)/i.test(q);
222
+ const isDistributed =
223
+ /(?:distributed|microservice|cluster|multi-region|consensus|raft|paxos|partition)/i.test(q);
224
+
225
+ let complexityBudget = 'MEDIUM';
226
+ let dependencyBudget = 'STANDARD';
227
+ let operationalBurden = 'LOW';
228
+
229
+ if (isSimple) {
230
+ complexityBudget = 'LOW';
231
+ dependencyBudget = 'MINIMAL (Zero external infrastructure)';
232
+ operationalBurden = 'MINIMAL';
233
+ } else if (isDistributed) {
234
+ complexityBudget = 'HIGH';
235
+ dependencyBudget = 'MODULAR (Cloud/Infrastructure supported)';
236
+ operationalBurden = 'HIGH';
237
+ }
238
+
239
+ return {
240
+ complexity_budget: complexityBudget,
241
+ dependency_budget: dependencyBudget,
242
+ operational_burden: operationalBurden,
243
+ proportionality_principle: 'MINIMUM_SUFFICIENT_ENGINEERING',
244
+ };
245
+ }
246
+
247
+ module.exports = {
248
+ evaluateMateriality,
249
+ checkMinimumSufficientEngineering,
250
+ determineOutcomeBudget,
251
+ };