@beingmartinbmc/ojas 0.2.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/LICENSE +21 -0
- package/README.md +308 -0
- package/dist/aahar/index.d.ts +179 -0
- package/dist/aahar/index.d.ts.map +1 -0
- package/dist/aahar/index.js +657 -0
- package/dist/aahar/index.js.map +1 -0
- package/dist/aahar/scoring.d.ts +85 -0
- package/dist/aahar/scoring.d.ts.map +1 -0
- package/dist/aahar/scoring.js +268 -0
- package/dist/aahar/scoring.js.map +1 -0
- package/dist/agni/index.d.ts +113 -0
- package/dist/agni/index.d.ts.map +1 -0
- package/dist/agni/index.js +328 -0
- package/dist/agni/index.js.map +1 -0
- package/dist/agni/model-router.d.ts +77 -0
- package/dist/agni/model-router.d.ts.map +1 -0
- package/dist/agni/model-router.js +163 -0
- package/dist/agni/model-router.js.map +1 -0
- package/dist/agni/response-distiller.d.ts +37 -0
- package/dist/agni/response-distiller.d.ts.map +1 -0
- package/dist/agni/response-distiller.js +193 -0
- package/dist/agni/response-distiller.js.map +1 -0
- package/dist/agni/tiktoken-adapter.d.ts +55 -0
- package/dist/agni/tiktoken-adapter.d.ts.map +1 -0
- package/dist/agni/tiktoken-adapter.js +113 -0
- package/dist/agni/tiktoken-adapter.js.map +1 -0
- package/dist/chikitsa/index.d.ts +130 -0
- package/dist/chikitsa/index.d.ts.map +1 -0
- package/dist/chikitsa/index.js +565 -0
- package/dist/chikitsa/index.js.map +1 -0
- package/dist/demo.d.ts +15 -0
- package/dist/demo.d.ts.map +1 -0
- package/dist/demo.js +278 -0
- package/dist/demo.js.map +1 -0
- package/dist/index.d.ts +201 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +588 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/audit.d.ts +39 -0
- package/dist/mcp/audit.d.ts.map +1 -0
- package/dist/mcp/audit.js +73 -0
- package/dist/mcp/audit.js.map +1 -0
- package/dist/mcp/contracts.d.ts +76 -0
- package/dist/mcp/contracts.d.ts.map +1 -0
- package/dist/mcp/contracts.js +44 -0
- package/dist/mcp/contracts.js.map +1 -0
- package/dist/mcp/envelope.d.ts +107 -0
- package/dist/mcp/envelope.d.ts.map +1 -0
- package/dist/mcp/envelope.js +162 -0
- package/dist/mcp/envelope.js.map +1 -0
- package/dist/mcp/registry.d.ts +110 -0
- package/dist/mcp/registry.d.ts.map +1 -0
- package/dist/mcp/registry.js +258 -0
- package/dist/mcp/registry.js.map +1 -0
- package/dist/mcp/server.d.ts +26 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +107 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools/agent.d.ts +4 -0
- package/dist/mcp/tools/agent.d.ts.map +1 -0
- package/dist/mcp/tools/agent.js +300 -0
- package/dist/mcp/tools/agent.js.map +1 -0
- package/dist/mcp/tools/context.d.ts +4 -0
- package/dist/mcp/tools/context.d.ts.map +1 -0
- package/dist/mcp/tools/context.js +261 -0
- package/dist/mcp/tools/context.js.map +1 -0
- package/dist/mcp/tools/index.d.ts +5 -0
- package/dist/mcp/tools/index.d.ts.map +1 -0
- package/dist/mcp/tools/index.js +20 -0
- package/dist/mcp/tools/index.js.map +1 -0
- package/dist/mcp/tools/memory.d.ts +4 -0
- package/dist/mcp/tools/memory.d.ts.map +1 -0
- package/dist/mcp/tools/memory.js +220 -0
- package/dist/mcp/tools/memory.js.map +1 -0
- package/dist/mcp/tools/output.d.ts +4 -0
- package/dist/mcp/tools/output.d.ts.map +1 -0
- package/dist/mcp/tools/output.js +206 -0
- package/dist/mcp/tools/output.js.map +1 -0
- package/dist/mcp/tools/recovery.d.ts +4 -0
- package/dist/mcp/tools/recovery.d.ts.map +1 -0
- package/dist/mcp/tools/recovery.js +165 -0
- package/dist/mcp/tools/recovery.js.map +1 -0
- package/dist/mcp/tools/registrar.d.ts +4 -0
- package/dist/mcp/tools/registrar.d.ts.map +1 -0
- package/dist/mcp/tools/registrar.js +17 -0
- package/dist/mcp/tools/registrar.js.map +1 -0
- package/dist/mcp/tools/report.d.ts +4 -0
- package/dist/mcp/tools/report.d.ts.map +1 -0
- package/dist/mcp/tools/report.js +68 -0
- package/dist/mcp/tools/report.js.map +1 -0
- package/dist/mcp/tools/shared.d.ts +37 -0
- package/dist/mcp/tools/shared.d.ts.map +1 -0
- package/dist/mcp/tools/shared.js +214 -0
- package/dist/mcp/tools/shared.js.map +1 -0
- package/dist/mcp/trace.d.ts +47 -0
- package/dist/mcp/trace.d.ts.map +1 -0
- package/dist/mcp/trace.js +216 -0
- package/dist/mcp/trace.js.map +1 -0
- package/dist/nidra/index.d.ts +275 -0
- package/dist/nidra/index.d.ts.map +1 -0
- package/dist/nidra/index.js +889 -0
- package/dist/nidra/index.js.map +1 -0
- package/dist/persistence/migrations.d.ts +10 -0
- package/dist/persistence/migrations.d.ts.map +1 -0
- package/dist/persistence/migrations.js +77 -0
- package/dist/persistence/migrations.js.map +1 -0
- package/dist/persistence/sqlite.d.ts +30 -0
- package/dist/persistence/sqlite.d.ts.map +1 -0
- package/dist/persistence/sqlite.js +209 -0
- package/dist/persistence/sqlite.js.map +1 -0
- package/dist/persistence/types.d.ts +104 -0
- package/dist/persistence/types.d.ts.map +1 -0
- package/dist/persistence/types.js +5 -0
- package/dist/persistence/types.js.map +1 -0
- package/dist/pulse/index.d.ts +144 -0
- package/dist/pulse/index.d.ts.map +1 -0
- package/dist/pulse/index.js +453 -0
- package/dist/pulse/index.js.map +1 -0
- package/dist/raksha/classifiers/http-classifier.d.ts +26 -0
- package/dist/raksha/classifiers/http-classifier.d.ts.map +1 -0
- package/dist/raksha/classifiers/http-classifier.js +62 -0
- package/dist/raksha/classifiers/http-classifier.js.map +1 -0
- package/dist/raksha/classifiers/index.d.ts +5 -0
- package/dist/raksha/classifiers/index.d.ts.map +1 -0
- package/dist/raksha/classifiers/index.js +8 -0
- package/dist/raksha/classifiers/index.js.map +1 -0
- package/dist/raksha/classifiers/onnx-classifier.d.ts +41 -0
- package/dist/raksha/classifiers/onnx-classifier.d.ts.map +1 -0
- package/dist/raksha/classifiers/onnx-classifier.js +99 -0
- package/dist/raksha/classifiers/onnx-classifier.js.map +1 -0
- package/dist/raksha/hallucination-detectors.d.ts +106 -0
- package/dist/raksha/hallucination-detectors.d.ts.map +1 -0
- package/dist/raksha/hallucination-detectors.js +327 -0
- package/dist/raksha/hallucination-detectors.js.map +1 -0
- package/dist/raksha/index.d.ts +168 -0
- package/dist/raksha/index.d.ts.map +1 -0
- package/dist/raksha/index.js +597 -0
- package/dist/raksha/index.js.map +1 -0
- package/dist/raksha/prompt-injection-detectors.d.ts +30 -0
- package/dist/raksha/prompt-injection-detectors.d.ts.map +1 -0
- package/dist/raksha/prompt-injection-detectors.js +153 -0
- package/dist/raksha/prompt-injection-detectors.js.map +1 -0
- package/dist/types.d.ts +1115 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +71 -0
- package/dist/types.js.map +1 -0
- package/dist/util/calibration.d.ts +32 -0
- package/dist/util/calibration.d.ts.map +1 -0
- package/dist/util/calibration.js +108 -0
- package/dist/util/calibration.js.map +1 -0
- package/dist/util/id.d.ts +2 -0
- package/dist/util/id.d.ts.map +1 -0
- package/dist/util/id.js +9 -0
- package/dist/util/id.js.map +1 -0
- package/dist/vyayam/index.d.ts +76 -0
- package/dist/vyayam/index.d.ts.map +1 -0
- package/dist/vyayam/index.js +528 -0
- package/dist/vyayam/index.js.map +1 -0
- package/dist/vyayam/tool-fault-proxy.d.ts +95 -0
- package/dist/vyayam/tool-fault-proxy.d.ts.map +1 -0
- package/dist/vyayam/tool-fault-proxy.js +170 -0
- package/dist/vyayam/tool-fault-proxy.js.map +1 -0
- package/docs/ARCHITECTURE.md +162 -0
- package/docs/BACKLOG.md +342 -0
- package/docs/CONFIGURATION.md +305 -0
- package/docs/EVIDENCE.md +232 -0
- package/docs/EVIDENCE_MATRIX.md +293 -0
- package/docs/KNOWN_FAILURES.md +367 -0
- package/docs/MCP.md +614 -0
- package/docs/MODULES.md +368 -0
- package/docs/SECURITY.md +251 -0
- package/docs/TRUST.md +88 -0
- package/docs/assets/ojas-hero.png +0 -0
- package/package.json +101 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerRecoveryTools = registerRecoveryTools;
|
|
4
|
+
const v3_1 = require("zod/v3");
|
|
5
|
+
const envelope_1 = require("../envelope");
|
|
6
|
+
const id_1 = require("../../util/id");
|
|
7
|
+
const shared_1 = require("./shared");
|
|
8
|
+
function registerRecoveryTools(registerOjasTool, registry, _audit) {
|
|
9
|
+
// ── 11. ojas_diagnose_failure ────────────────────────────────────────────
|
|
10
|
+
registerOjasTool('ojas_diagnose_failure', {
|
|
11
|
+
title: 'Diagnose why an agent failed or degraded',
|
|
12
|
+
description: 'Chikitsa classifies an agent failure (bad context, weak planning, tool failure, retrieval error, ' +
|
|
13
|
+
'prompt injection, instruction conflict, model limitation, unclear objective, excessive cognitive load) ' +
|
|
14
|
+
'and emits a structured repair plan.',
|
|
15
|
+
inputSchema: {
|
|
16
|
+
agent_id: v3_1.z.string().min(1),
|
|
17
|
+
session_id: v3_1.z.string().optional(),
|
|
18
|
+
failure_description: v3_1.z.string().min(1),
|
|
19
|
+
failure_type: v3_1.z.enum(shared_1.FAILURE_TYPES).optional(),
|
|
20
|
+
severity: v3_1.z.enum(['low', 'medium', 'high', 'critical']).default('medium'),
|
|
21
|
+
include_trace: v3_1.z.boolean().default(true),
|
|
22
|
+
include_memory_events: v3_1.z.boolean().default(true),
|
|
23
|
+
include_tool_events: v3_1.z.boolean().default(true),
|
|
24
|
+
},
|
|
25
|
+
}, async ({ agent_id, failure_description, failure_type, severity, session_id, include_trace, include_memory_events, include_tool_events, }) => {
|
|
26
|
+
const entry = registry.getOrAutoRegisterSession(agent_id, session_id);
|
|
27
|
+
const inferredType = failure_type ?? (0, shared_1.inferFailureType)(failure_description);
|
|
28
|
+
const failure = {
|
|
29
|
+
type: inferredType,
|
|
30
|
+
message: failure_description,
|
|
31
|
+
severity,
|
|
32
|
+
};
|
|
33
|
+
const [protocol] = entry.ojas.chikitsa.diagnose([failure]);
|
|
34
|
+
const secondaryCauses = [];
|
|
35
|
+
const report = entry.ojas.healthCheck();
|
|
36
|
+
if (report.metabolism.costPressure > 0.7)
|
|
37
|
+
secondaryCauses.push('high_cost_pressure');
|
|
38
|
+
if (report.recovery.driftScore > 0.5)
|
|
39
|
+
secondaryCauses.push('cognitive_drift');
|
|
40
|
+
if (report.defense.quarantinedItems > 0)
|
|
41
|
+
secondaryCauses.push('contaminated_inputs');
|
|
42
|
+
if (report.resilience.weaknesses.length > 0)
|
|
43
|
+
secondaryCauses.push('known_resilience_weakness');
|
|
44
|
+
void include_trace;
|
|
45
|
+
void include_memory_events;
|
|
46
|
+
void include_tool_events;
|
|
47
|
+
return (0, envelope_1.mcpReply)({
|
|
48
|
+
diagnosis_id: protocol.id,
|
|
49
|
+
primary_cause: inferredType,
|
|
50
|
+
diagnosis: protocol.diagnosis,
|
|
51
|
+
secondary_causes: secondaryCauses,
|
|
52
|
+
severity: protocol.severity,
|
|
53
|
+
recommended_repair: protocol.actions,
|
|
54
|
+
...(0, envelope_1.sessionScopeFields)(session_id),
|
|
55
|
+
}, {
|
|
56
|
+
agent_id,
|
|
57
|
+
status: protocol.severity === 'critical' ? 'warning' : 'success',
|
|
58
|
+
affected_modules: ['chikitsa', 'pulse'],
|
|
59
|
+
recommended_next_actions: protocol.actions,
|
|
60
|
+
requires_human_review: protocol.severity === 'critical',
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
// ── 12. ojas_run_recovery ────────────────────────────────────────────────
|
|
64
|
+
registerOjasTool('ojas_run_recovery', {
|
|
65
|
+
title: 'Run a recovery protocol (observe / recommend / apply)',
|
|
66
|
+
description: 'Run a recovery protocol for a degraded agent. Modes: "observe" (no-op telemetry only), ' +
|
|
67
|
+
'"recommend" (return the action plan without executing — DEFAULT), or "apply" (execute the safe ' +
|
|
68
|
+
'subset of actions: enter_safe_mode, freeze_memory_writes, etc.).',
|
|
69
|
+
inputSchema: {
|
|
70
|
+
agent_id: v3_1.z.string().min(1),
|
|
71
|
+
session_id: v3_1.z.string().optional(),
|
|
72
|
+
recovery_type: v3_1.z
|
|
73
|
+
.enum([
|
|
74
|
+
'tool_failure_loop',
|
|
75
|
+
'context_overload',
|
|
76
|
+
'prompt_injection',
|
|
77
|
+
'memory_conflict',
|
|
78
|
+
'hallucination',
|
|
79
|
+
'high_cost_pressure',
|
|
80
|
+
'unknown',
|
|
81
|
+
])
|
|
82
|
+
.default('unknown'),
|
|
83
|
+
mode: v3_1.z.enum(shared_1.TOOL_MODES).default('recommend'),
|
|
84
|
+
allowed_actions: v3_1.z.array(v3_1.z.enum(shared_1.RECOVERY_ACTIONS)).optional(),
|
|
85
|
+
},
|
|
86
|
+
}, async ({ agent_id, session_id, recovery_type, mode, allowed_actions }) => {
|
|
87
|
+
const entry = registry.getOrAutoRegisterSession(agent_id, session_id);
|
|
88
|
+
// Snapshot health before applying so we can report a measured delta.
|
|
89
|
+
const before = Math.round(entry.ojas.healthCheck().overall.value * 100);
|
|
90
|
+
const plan = (0, shared_1.actionsForRecoveryType)(recovery_type, allowed_actions);
|
|
91
|
+
const mutatedActions = [];
|
|
92
|
+
const instructionActions = [];
|
|
93
|
+
const skippedActions = [];
|
|
94
|
+
if (mode === 'apply') {
|
|
95
|
+
for (const step of plan) {
|
|
96
|
+
switch (step.action) {
|
|
97
|
+
case 'enter_safe_mode':
|
|
98
|
+
registry.setSafeMode(entry, true, recovery_type, plan.map((s) => s.action));
|
|
99
|
+
mutatedActions.push(step.action);
|
|
100
|
+
break;
|
|
101
|
+
case 'freeze_memory_writes':
|
|
102
|
+
case 'quarantine_input':
|
|
103
|
+
case 'reset_plan':
|
|
104
|
+
case 'compress_context':
|
|
105
|
+
case 'generate_fallback_response':
|
|
106
|
+
case 'reduce_tool_calls':
|
|
107
|
+
case 'switch_to_cached_sources':
|
|
108
|
+
// These are instructions for the calling agent. Ojas cannot
|
|
109
|
+
// mutate external tools, contexts, or memory stores by itself.
|
|
110
|
+
instructionActions.push(step.action);
|
|
111
|
+
break;
|
|
112
|
+
case 'human_escalation':
|
|
113
|
+
// Don't auto-apply human_escalation — flag for review instead.
|
|
114
|
+
skippedActions.push(step.action);
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Measured score delta. In recommend / observe modes nothing was
|
|
120
|
+
// applied, so delta stays 0. In apply mode we re-run healthCheck.
|
|
121
|
+
let measuredDelta = 0;
|
|
122
|
+
if (mode === 'apply') {
|
|
123
|
+
const afterReport = entry.ojas.healthCheck();
|
|
124
|
+
const after = Math.round(afterReport.overall.value * 100);
|
|
125
|
+
measuredDelta = after - before;
|
|
126
|
+
registry.updateHealthSnapshot(entry, afterReport);
|
|
127
|
+
}
|
|
128
|
+
const outcome = mode !== 'apply'
|
|
129
|
+
? 'recommended'
|
|
130
|
+
: mutatedActions.length > 0
|
|
131
|
+
? 'applied'
|
|
132
|
+
: instructionActions.length > 0
|
|
133
|
+
? 'instructed'
|
|
134
|
+
: skippedActions.length > 0
|
|
135
|
+
? 'requires_human_review'
|
|
136
|
+
: 'no_effect';
|
|
137
|
+
const event = registry.recordEvent(entry, 'recovery_protocol_generated', recovery_type);
|
|
138
|
+
return (0, envelope_1.mcpReply)({
|
|
139
|
+
recovery_id: (0, id_1.newId)('recovery'),
|
|
140
|
+
recovery_type,
|
|
141
|
+
mode,
|
|
142
|
+
outcome,
|
|
143
|
+
actions: plan,
|
|
144
|
+
mutated_actions: mutatedActions,
|
|
145
|
+
instruction_actions: instructionActions,
|
|
146
|
+
skipped_actions: skippedActions,
|
|
147
|
+
// Deprecated compatibility alias: durable mutations only.
|
|
148
|
+
applied_actions: mutatedActions,
|
|
149
|
+
// Reports the actual pre/post scores from `apply` mode (both equal in
|
|
150
|
+
// `recommend` / `observe` since nothing was applied). No more
|
|
151
|
+
// hardcoded "+9" predictions.
|
|
152
|
+
ojas_score_before: before,
|
|
153
|
+
ojas_score_after: mode === 'apply' ? before + measuredDelta : before,
|
|
154
|
+
safe_mode: entry.safe_mode,
|
|
155
|
+
...(0, envelope_1.sessionScopeFields)(session_id),
|
|
156
|
+
}, {
|
|
157
|
+
agent_id,
|
|
158
|
+
affected_modules: ['chikitsa', 'pulse'],
|
|
159
|
+
events_created: [event.id],
|
|
160
|
+
ojas_score_delta: measuredDelta,
|
|
161
|
+
requires_human_review: plan.some((p) => p.action === 'human_escalation'),
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=recovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recovery.js","sourceRoot":"","sources":["../../../src/mcp/tools/recovery.ts"],"names":[],"mappings":";;AAiBA,sDAyLC;AA1MD,+BAA2B;AAO3B,0CAA2D;AAC3D,sCAAsC;AACtC,qCAMkB;AAElB,SAAgB,qBAAqB,CAAC,gBAAmC,EAAE,QAAuB,EAAE,MAAuC;IACzI,4EAA4E;IAC5E,gBAAgB,CACd,uBAAuB,EACvB;QACE,KAAK,EAAE,0CAA0C;QACjD,WAAW,EACT,mGAAmG;YACnG,yGAAyG;YACzG,qCAAqC;QACvC,WAAW,EAAE;YACX,QAAQ,EAAE,MAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;YAC3B,UAAU,EAAE,MAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;YACjC,mBAAmB,EAAE,MAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;YACtC,YAAY,EAAE,MAAC,CAAC,IAAI,CAAC,sBAAa,CAAC,CAAC,QAAQ,EAAE;YAC9C,QAAQ,EAAE,MAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,CAA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;YACJ,OAAO;YACP,OAAO,EAAE,IAAI;YACb,eAAe,EAAE,cAAc;YAC/B,mBAAmB,EAAE,kBAAkB;YACvC,eAAe,EAAE,cAAc;YAC/B,0DAA0D;YAC1D,eAAe,EAAE,cAAc;YAC/B,sEAAsE;YACtE,8DAA8D;YAC9D,8BAA8B;YAC9B,iBAAiB,EAAE,MAAM;YACzB,gBAAgB,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC,MAAM;YACpE,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,GAAG,IAAA,6BAAkB,EAAC,UAAU,CAAC;SAClC,EACD;YACE,QAAQ;YACR,gBAAgB,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC;YACvC,cAAc,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,gBAAgB,EAAE,aAAa;YAC/B,qBAAqB,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,kBAAkB,CAAC;SACzE,CACF,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/registrar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIzE,MAAM,MAAM,iBAAiB,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;AAE1D,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,GAAG,iBAAiB,CAW5E"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createOjasToolRegistrar = createOjasToolRegistrar;
|
|
4
|
+
const envelope_1 = require("../envelope");
|
|
5
|
+
function createOjasToolRegistrar(server) {
|
|
6
|
+
return ((...regArgs) => {
|
|
7
|
+
const handler = regArgs[regArgs.length - 1];
|
|
8
|
+
if (typeof handler === 'function') {
|
|
9
|
+
const name = String(regArgs[0]);
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
regArgs[regArgs.length - 1] = (0, envelope_1.safeHandler)(name, handler);
|
|
12
|
+
}
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
return server.registerTool(...regArgs);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=registrar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registrar.js","sourceRoot":"","sources":["../../../src/mcp/tools/registrar.ts"],"names":[],"mappings":";;AAMA,0DAWC;AAfD,0CAA0C;AAI1C,SAAgB,uBAAuB,CAAC,MAAiB;IACvD,OAAO,CAAC,CAAC,GAAG,OAAkB,EAAE,EAAE;QAChC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC5C,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;YAClC,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YAChC,8DAA8D;YAC9D,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,IAAA,sBAAW,EAAC,IAAI,EAAE,OAAc,CAAC,CAAC;QAClE,CAAC;QACD,8DAA8D;QAC9D,OAAQ,MAAM,CAAC,YAAoB,CAAC,GAAG,OAAO,CAAC,CAAC;IAClD,CAAC,CAAsB,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AgentRegistry } from '../registry';
|
|
2
|
+
import type { OjasToolRegistrar } from './registrar';
|
|
3
|
+
export declare function registerReportTools(registerOjasTool: OjasToolRegistrar, registry: AgentRegistry, _audit?: import('../audit').AuditLogger): void;
|
|
4
|
+
//# sourceMappingURL=report.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/report.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAOrD,wBAAgB,mBAAmB,CAAC,gBAAgB,EAAE,iBAAiB,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,OAAO,UAAU,EAAE,WAAW,GAAG,IAAI,CAoE/I"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerReportTools = registerReportTools;
|
|
4
|
+
const v3_1 = require("zod/v3");
|
|
5
|
+
const contracts_1 = require("../contracts");
|
|
6
|
+
const envelope_1 = require("../envelope");
|
|
7
|
+
const id_1 = require("../../util/id");
|
|
8
|
+
const shared_1 = require("./shared");
|
|
9
|
+
function registerReportTools(registerOjasTool, registry, _audit) {
|
|
10
|
+
// ── 18. ojas_generate_health_report ──────────────────────────────────────
|
|
11
|
+
registerOjasTool('ojas_generate_health_report', {
|
|
12
|
+
title: 'Generate an Ojas health report for a session or agent',
|
|
13
|
+
description: 'Produce a structured health report for an agent — overall Ojas score, narrative summary, ' +
|
|
14
|
+
'top operational risks, and concrete recommended next steps. Suitable for dashboards, ' +
|
|
15
|
+
'release gates, and human review.',
|
|
16
|
+
inputSchema: {
|
|
17
|
+
agent_id: v3_1.z.string().min(1),
|
|
18
|
+
session_id: v3_1.z.string().optional(),
|
|
19
|
+
scope: v3_1.z.enum(['current', 'session', 'last_24h']).default('current'),
|
|
20
|
+
report_type: v3_1.z.enum(['executive_summary', 'technical']).default('executive_summary'),
|
|
21
|
+
include_recommendations: v3_1.z.boolean().default(true),
|
|
22
|
+
},
|
|
23
|
+
}, async ({ agent_id, session_id, scope, report_type, include_recommendations }) => {
|
|
24
|
+
const entry = registry.getOrAutoRegisterSession(agent_id, session_id);
|
|
25
|
+
// Read-only tool: no snapshot mutation.
|
|
26
|
+
const report = entry.ojas.healthCheck();
|
|
27
|
+
const delta = 0;
|
|
28
|
+
const ojasScore = Math.round(report.overall.value * 100);
|
|
29
|
+
const healthState = (0, contracts_1.classifyHealthState)(ojasScore, entry.contract);
|
|
30
|
+
const topRisks = (0, shared_1.pickTopModulesBelow)(80, report.moduleScores).map((m) => `${m}_below_target`);
|
|
31
|
+
if (report.metabolism.costPressure > 0.8)
|
|
32
|
+
topRisks.push('over_retrieval');
|
|
33
|
+
if (report.recovery.driftScore > 0.5)
|
|
34
|
+
topRisks.push('cognitive_drift');
|
|
35
|
+
if (report.defense.quarantinedItems > 0)
|
|
36
|
+
topRisks.push('contaminated_inputs');
|
|
37
|
+
const nextSteps = include_recommendations
|
|
38
|
+
? report.recommendations
|
|
39
|
+
.filter((r) => r.severity !== 'info' && r.action)
|
|
40
|
+
.map((r) => r.action)
|
|
41
|
+
.slice(0, 6)
|
|
42
|
+
: [];
|
|
43
|
+
const summary = healthState === 'healthy'
|
|
44
|
+
? `${entry.contract.agent_name ?? entry.agent_id} is healthy (Ojas ${ojasScore}/100). No critical issues.`
|
|
45
|
+
: healthState === 'watch'
|
|
46
|
+
? `${entry.contract.agent_name ?? entry.agent_id} is operational at Ojas ${ojasScore}/100 with mild degradation under load.`
|
|
47
|
+
: `${entry.contract.agent_name ?? entry.agent_id} health is ${healthState} (Ojas ${ojasScore}/100). Recovery recommended before continued autonomous operation.`;
|
|
48
|
+
void scope;
|
|
49
|
+
return (0, envelope_1.mcpReply)({
|
|
50
|
+
report_id: (0, id_1.newId)('report'),
|
|
51
|
+
report_type,
|
|
52
|
+
overall_ojas_score: ojasScore,
|
|
53
|
+
health_state: healthState,
|
|
54
|
+
module_scores: report.moduleScores,
|
|
55
|
+
summary,
|
|
56
|
+
top_risks: [...new Set(topRisks)].slice(0, 6),
|
|
57
|
+
recommended_next_steps: nextSteps,
|
|
58
|
+
...(0, envelope_1.sessionScopeFields)(session_id),
|
|
59
|
+
}, {
|
|
60
|
+
agent_id,
|
|
61
|
+
ojas_score_delta: delta,
|
|
62
|
+
affected_modules: ['pulse'],
|
|
63
|
+
recommended_next_actions: nextSteps,
|
|
64
|
+
requires_human_review: healthState === 'degraded' || healthState === 'critical',
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=report.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report.js","sourceRoot":"","sources":["../../../src/mcp/tools/report.ts"],"names":[],"mappings":";;AAUA,kDAoEC;AA9ED,+BAA2B;AAK3B,4CAAmD;AACnD,0CAA2D;AAC3D,sCAAsC;AACtC,qCAA+C;AAE/C,SAAgB,mBAAmB,CAAC,gBAAmC,EAAE,QAAuB,EAAE,MAAuC;IACvI,4EAA4E;IAC5E,gBAAgB,CACd,6BAA6B,EAC7B;QACE,KAAK,EAAE,uDAAuD;QAC9D,WAAW,EACT,2FAA2F;YAC3F,uFAAuF;YACvF,kCAAkC;QACpC,WAAW,EAAE;YACX,QAAQ,EAAE,MAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;YAC3B,UAAU,EAAE,MAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;YACjC,KAAK,EAAE,MAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;YACpE,WAAW,EAAE,MAAC,CAAC,IAAI,CAAC,CAAC,mBAAmB,EAAE,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,mBAAmB,CAAC;YACpF,uBAAuB,EAAE,MAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;SACnD;KACF,EACD,KAAK,EAAE,EAAE,QAAQ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AAC,CAAC;YAChB,CAAC,CAAC,EAAE,CAAC;QAEP,MAAM,OAAO,GACX,WAAW,KAAK,SAAS;YACvB,CAAC,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,UAAU,IAAI,KAAK,CAAC,QAAQ,qBAAqB,SAAS,4BAA4B;YAC1G,CAAC,CAAC,WAAW,KAAK,OAAO;gBACvB,CAAC,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,UAAU,IAAI,KAAK,CAAC,QAAQ,2BAA2B,SAAS,wCAAwC;gBAC5H,CAAC,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,UAAU,IAAI,KAAK,CAAC,QAAQ,cAAc,WAAW,UAAU,SAAS,oEAAoE,CAAC;QAEvK,KAAK,KAAK,CAAC;QACX,OAAO,IAAA,mBAAQ,EACb;YACE,SAAS,EAAE,IAAA,UAAK,EAAC,QAAQ,CAAC;YAC1B,WAAW;YACX,kBAAkB,EAAE,SAAS;YAC7B,YAAY,EAAE,WAAW;YACzB,aAAa,EAAE,MAAM,CAAC,YAAY;YAClC,OAAO;YACP,SAAS,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;YAC7C,sBAAsB,EAAE,SAAS;YACjC,GAAG,IAAA,6BAAkB,EAAC,UAAU,CAAC;SAClC,EACD;YACE,QAAQ;YACR,gBAAgB,EAAE,KAAK;YACvB,gBAAgB,EAAE,CAAC,OAAO,CAAC;YAC3B,wBAAwB,EAAE,SAAS;YACnC,qBAAqB,EAAE,WAAW,KAAK,UAAU,IAAI,WAAW,KAAK,UAAU;SAChF,CACF,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { OjasModuleName, RuntimeFailureType } from '../../types';
|
|
2
|
+
import type { AgentRiskLevel, RecoveryActionId, ToolMode } from '../contracts';
|
|
3
|
+
import type { TraceEventType } from '../trace';
|
|
4
|
+
export declare const nowSec: () => number;
|
|
5
|
+
export declare const estimateTokens: (s: string) => number;
|
|
6
|
+
export type RelevanceSource = 'caller' | 'lexical_fallback';
|
|
7
|
+
export declare function resolveRelevance(supplied: number | undefined, task: string, content: string): {
|
|
8
|
+
score: number;
|
|
9
|
+
source: RelevanceSource;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Parse an optional ISO-8601 timestamp string from MCP input and return its
|
|
13
|
+
* epoch-seconds value. Returns `null` on invalid input so the caller can
|
|
14
|
+
* reject the request rather than silently producing NaN.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseCreatedAt(input: string | undefined): {
|
|
17
|
+
ok: true;
|
|
18
|
+
epochSec: number;
|
|
19
|
+
} | {
|
|
20
|
+
ok: false;
|
|
21
|
+
reason: string;
|
|
22
|
+
} | {
|
|
23
|
+
ok: 'absent';
|
|
24
|
+
};
|
|
25
|
+
export declare const RISK_LEVELS: [AgentRiskLevel, ...AgentRiskLevel[]];
|
|
26
|
+
export declare const TOOL_MODES: [ToolMode, ...ToolMode[]];
|
|
27
|
+
export declare const DISTILLER_INTENSITIES: readonly ["lite", "full", "ultra"];
|
|
28
|
+
export declare const TRACE_EVENT_TYPES: [TraceEventType, ...TraceEventType[]];
|
|
29
|
+
export declare const FAILURE_TYPES: [RuntimeFailureType, ...RuntimeFailureType[]];
|
|
30
|
+
export declare const RECOVERY_ACTIONS: [RecoveryActionId, ...RecoveryActionId[]];
|
|
31
|
+
export declare function pickTopModulesBelow(threshold: number, scores: object): OjasModuleName[];
|
|
32
|
+
export declare function inferFailureType(description: string): RuntimeFailureType;
|
|
33
|
+
export declare function actionsForRecoveryType(recoveryType: string, allowed?: RecoveryActionId[]): {
|
|
34
|
+
action: RecoveryActionId;
|
|
35
|
+
reason: string;
|
|
36
|
+
}[];
|
|
37
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","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,CASvE,CAAC;AACF,eAAO,MAAM,gBAAgB,EAAE,CAAC,gBAAgB,EAAE,GAAG,gBAAgB,EAAE,CAUtE,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,EAAE,CAOvF;AAED,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,kBAAkB,CAUxE;AAED,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,gBAAgB,EAAE,GAC3B;IAAE,MAAM,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,CAuDhD"}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RECOVERY_ACTIONS = exports.FAILURE_TYPES = exports.TRACE_EVENT_TYPES = exports.DISTILLER_INTENSITIES = exports.TOOL_MODES = exports.RISK_LEVELS = exports.estimateTokens = exports.nowSec = void 0;
|
|
4
|
+
exports.resolveRelevance = resolveRelevance;
|
|
5
|
+
exports.parseCreatedAt = parseCreatedAt;
|
|
6
|
+
exports.pickTopModulesBelow = pickTopModulesBelow;
|
|
7
|
+
exports.inferFailureType = inferFailureType;
|
|
8
|
+
exports.actionsForRecoveryType = actionsForRecoveryType;
|
|
9
|
+
const nowSec = () => Date.now() / 1000;
|
|
10
|
+
exports.nowSec = nowSec;
|
|
11
|
+
const estimateTokens = (s) => Math.max(1, Math.ceil(s.length / 4));
|
|
12
|
+
exports.estimateTokens = estimateTokens;
|
|
13
|
+
/**
|
|
14
|
+
* Lexical task-to-content relevance fallback. When a caller does not supply
|
|
15
|
+
* `relevance_score`, we compute Jaccard token overlap between the task and
|
|
16
|
+
* the item content. This is a baseline heuristic only — no semantics, no
|
|
17
|
+
* embeddings — and is gameable by keyword stuffing. Callers that can provide
|
|
18
|
+
* embedding-based or model-judged scores should pass `relevance_score`.
|
|
19
|
+
*/
|
|
20
|
+
const STOPWORDS = new Set([
|
|
21
|
+
'the', 'and', 'for', 'are', 'but', 'not', 'you', 'all', 'any', 'can',
|
|
22
|
+
'her', 'was', 'one', 'our', 'out', 'day', 'has', 'how', 'man', 'new',
|
|
23
|
+
'now', 'old', 'see', 'two', 'way', 'who', 'its', 'with', 'this', 'that',
|
|
24
|
+
'from', 'have', 'will', 'they', 'them', 'their', 'what', 'when', 'were',
|
|
25
|
+
'would', 'about', 'which', 'into', 'over', 'than', 'then', 'these',
|
|
26
|
+
'those', 'some', 'such', 'your', 'just', 'also',
|
|
27
|
+
]);
|
|
28
|
+
function tokenize(text) {
|
|
29
|
+
const tokens = new Set();
|
|
30
|
+
const words = text.toLowerCase().replace(/[^a-z0-9\s]/g, ' ').split(/\s+/);
|
|
31
|
+
for (const w of words) {
|
|
32
|
+
if (w.length >= 3 && !STOPWORDS.has(w))
|
|
33
|
+
tokens.add(w);
|
|
34
|
+
}
|
|
35
|
+
return tokens;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Lexical task-to-content relevance in [0, 1]. Uses Jaccard overlap of
|
|
39
|
+
* non-stopword tokens with a small floor (0.05) so completely-different
|
|
40
|
+
* content has a near-zero but defined score. Returns 0.5 when the task is
|
|
41
|
+
* unparseable (no meaningful tokens) so missing tasks don't bias scoring.
|
|
42
|
+
*/
|
|
43
|
+
function lexicalRelevance(task, content) {
|
|
44
|
+
const taskTokens = tokenize(task);
|
|
45
|
+
const contentTokens = tokenize(content);
|
|
46
|
+
if (taskTokens.size === 0)
|
|
47
|
+
return 0.5;
|
|
48
|
+
if (contentTokens.size === 0)
|
|
49
|
+
return 0.1;
|
|
50
|
+
let intersection = 0;
|
|
51
|
+
for (const t of taskTokens)
|
|
52
|
+
if (contentTokens.has(t))
|
|
53
|
+
intersection += 1;
|
|
54
|
+
const union = taskTokens.size + contentTokens.size - intersection;
|
|
55
|
+
if (union === 0)
|
|
56
|
+
return 0.5;
|
|
57
|
+
const jaccard = intersection / union;
|
|
58
|
+
// Map raw Jaccard (typically 0..0.4 even for relevant docs) to a usable
|
|
59
|
+
// 0..1 score: 0 → 0.05, 0.05 → ~0.3, 0.15 → ~0.6, 0.3+ → 0.85+.
|
|
60
|
+
return Math.min(1, 0.05 + jaccard * 2.7);
|
|
61
|
+
}
|
|
62
|
+
function resolveRelevance(supplied, task, content) {
|
|
63
|
+
if (typeof supplied === 'number' && Number.isFinite(supplied) && supplied >= 0 && supplied <= 1) {
|
|
64
|
+
return { score: supplied, source: 'caller' };
|
|
65
|
+
}
|
|
66
|
+
return { score: lexicalRelevance(task, content), source: 'lexical_fallback' };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Parse an optional ISO-8601 timestamp string from MCP input and return its
|
|
70
|
+
* epoch-seconds value. Returns `null` on invalid input so the caller can
|
|
71
|
+
* reject the request rather than silently producing NaN.
|
|
72
|
+
*/
|
|
73
|
+
function parseCreatedAt(input) {
|
|
74
|
+
if (input === undefined)
|
|
75
|
+
return { ok: 'absent' };
|
|
76
|
+
// Require an explicit ISO-8601 timestamp instead of relying on
|
|
77
|
+
// implementation-dependent Date.parse forms like "1/2/2020".
|
|
78
|
+
const isoLike = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
79
|
+
if (!isoLike.test(input))
|
|
80
|
+
return { ok: false, reason: `created_at must be ISO-8601: ${input}` };
|
|
81
|
+
const parsed = new Date(input).getTime();
|
|
82
|
+
if (!Number.isFinite(parsed))
|
|
83
|
+
return { ok: false, reason: `Invalid created_at: ${input}` };
|
|
84
|
+
if (parsed > Date.now() + 60_000) {
|
|
85
|
+
return { ok: false, reason: `created_at is in the future: ${input}` };
|
|
86
|
+
}
|
|
87
|
+
return { ok: true, epochSec: parsed / 1000 };
|
|
88
|
+
}
|
|
89
|
+
exports.RISK_LEVELS = ['low', 'medium', 'high', 'critical'];
|
|
90
|
+
exports.TOOL_MODES = ['observe', 'recommend', 'apply'];
|
|
91
|
+
exports.DISTILLER_INTENSITIES = ['lite', 'full', 'ultra'];
|
|
92
|
+
exports.TRACE_EVENT_TYPES = [
|
|
93
|
+
'agent_input',
|
|
94
|
+
'agent_output',
|
|
95
|
+
'tool_call_started',
|
|
96
|
+
'tool_call_succeeded',
|
|
97
|
+
'tool_call_failed',
|
|
98
|
+
'retrieval_result',
|
|
99
|
+
'memory_read',
|
|
100
|
+
'memory_write',
|
|
101
|
+
'failure',
|
|
102
|
+
'latency_measurement',
|
|
103
|
+
'token_usage',
|
|
104
|
+
'user_correction',
|
|
105
|
+
'planning_loop',
|
|
106
|
+
'fallback',
|
|
107
|
+
'policy_violation',
|
|
108
|
+
'prompt_injection_detected',
|
|
109
|
+
'context_overload_detected',
|
|
110
|
+
];
|
|
111
|
+
exports.FAILURE_TYPES = [
|
|
112
|
+
'tool_error',
|
|
113
|
+
'timeout',
|
|
114
|
+
'hallucination',
|
|
115
|
+
'policy_violation',
|
|
116
|
+
'retrieval_noise',
|
|
117
|
+
'loop',
|
|
118
|
+
'prompt_injection',
|
|
119
|
+
'unknown',
|
|
120
|
+
];
|
|
121
|
+
exports.RECOVERY_ACTIONS = [
|
|
122
|
+
'compress_context',
|
|
123
|
+
'reset_plan',
|
|
124
|
+
'freeze_memory_writes',
|
|
125
|
+
'quarantine_input',
|
|
126
|
+
'generate_fallback_response',
|
|
127
|
+
'enter_safe_mode',
|
|
128
|
+
'human_escalation',
|
|
129
|
+
'reduce_tool_calls',
|
|
130
|
+
'switch_to_cached_sources',
|
|
131
|
+
];
|
|
132
|
+
function pickTopModulesBelow(threshold, scores) {
|
|
133
|
+
const entries = Object.entries(scores);
|
|
134
|
+
return entries
|
|
135
|
+
.filter(([, v]) => v < threshold)
|
|
136
|
+
.sort((a, b) => a[1] - b[1])
|
|
137
|
+
.slice(0, 3)
|
|
138
|
+
.map(([k]) => k);
|
|
139
|
+
}
|
|
140
|
+
function inferFailureType(description) {
|
|
141
|
+
const d = description.toLowerCase();
|
|
142
|
+
if (/(loop|repeated|stuck)/.test(d))
|
|
143
|
+
return 'loop';
|
|
144
|
+
if (/(inject|ignore previous|system prompt)/.test(d))
|
|
145
|
+
return 'prompt_injection';
|
|
146
|
+
if (/(timeout|timed out)/.test(d))
|
|
147
|
+
return 'timeout';
|
|
148
|
+
if (/(hallucin|fabricat|cited.*non[- ]existent)/.test(d))
|
|
149
|
+
return 'hallucination';
|
|
150
|
+
if (/(policy|safety|unsafe)/.test(d))
|
|
151
|
+
return 'policy_violation';
|
|
152
|
+
if (/(retrieval|noisy context|irrelevant)/.test(d))
|
|
153
|
+
return 'retrieval_noise';
|
|
154
|
+
if (/(tool|api .*error|503|500)/.test(d))
|
|
155
|
+
return 'tool_error';
|
|
156
|
+
return 'unknown';
|
|
157
|
+
}
|
|
158
|
+
function actionsForRecoveryType(recoveryType, allowed) {
|
|
159
|
+
let recipe;
|
|
160
|
+
switch (recoveryType) {
|
|
161
|
+
case 'tool_failure_loop':
|
|
162
|
+
recipe = [
|
|
163
|
+
{ action: 'freeze_memory_writes', reason: 'avoid storing degraded loop behavior' },
|
|
164
|
+
{ action: 'reset_plan', reason: 'agent is stuck in repeated tool-call loop' },
|
|
165
|
+
{ action: 'generate_fallback_response', reason: 'underlying tool unavailable after repeated attempts' },
|
|
166
|
+
];
|
|
167
|
+
break;
|
|
168
|
+
case 'context_overload':
|
|
169
|
+
recipe = [
|
|
170
|
+
{ action: 'compress_context', reason: 'active context exceeds healthy budget' },
|
|
171
|
+
{ action: 'reduce_tool_calls', reason: 'prevent further intake until context settles' },
|
|
172
|
+
];
|
|
173
|
+
break;
|
|
174
|
+
case 'prompt_injection':
|
|
175
|
+
recipe = [
|
|
176
|
+
{ action: 'quarantine_input', reason: 'hostile instruction content detected' },
|
|
177
|
+
{ action: 'freeze_memory_writes', reason: 'prevent contamination of long-term memory' },
|
|
178
|
+
{ action: 'human_escalation', reason: 'verify safety boundary before resuming' },
|
|
179
|
+
];
|
|
180
|
+
break;
|
|
181
|
+
case 'memory_conflict':
|
|
182
|
+
recipe = [
|
|
183
|
+
{ action: 'freeze_memory_writes', reason: 'memory store is internally inconsistent' },
|
|
184
|
+
{ action: 'reset_plan', reason: 'replan with verified facts only' },
|
|
185
|
+
];
|
|
186
|
+
break;
|
|
187
|
+
case 'hallucination':
|
|
188
|
+
recipe = [
|
|
189
|
+
{ action: 'reset_plan', reason: 'reground from authoritative sources' },
|
|
190
|
+
{ action: 'switch_to_cached_sources', reason: 'avoid speculative generation under uncertainty' },
|
|
191
|
+
];
|
|
192
|
+
break;
|
|
193
|
+
case 'high_cost_pressure':
|
|
194
|
+
recipe = [
|
|
195
|
+
{ action: 'compress_context', reason: 'token / latency budget is critical' },
|
|
196
|
+
{ action: 'reduce_tool_calls', reason: 'cap fan-out to stay within budget' },
|
|
197
|
+
];
|
|
198
|
+
break;
|
|
199
|
+
default:
|
|
200
|
+
recipe = [
|
|
201
|
+
{ action: 'enter_safe_mode', reason: 'fallback recovery for unclassified degradation' },
|
|
202
|
+
{ action: 'human_escalation', reason: 'escalate for operator review' },
|
|
203
|
+
];
|
|
204
|
+
}
|
|
205
|
+
if (allowed && allowed.length > 0) {
|
|
206
|
+
const set = new Set(allowed);
|
|
207
|
+
recipe = recipe.filter((step) => set.has(step.action));
|
|
208
|
+
if (recipe.length === 0) {
|
|
209
|
+
recipe = allowed.map((a) => ({ action: a, reason: 'allowed-list fallback' }));
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return recipe;
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/mcp/tools/shared.ts"],"names":[],"mappings":";;;AAsDA,4CASC;AAOD,wCAYC;AA8CD,kDAOC;AAED,4CAUC;AAED,wDA0DC;AA3MM,MAAM,MAAM,GAAG,GAAW,EAAE,CAA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,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rich trace event taxonomy for the Ojas MCP `ojas_ingest_trace` tool.
|
|
3
|
+
*
|
|
4
|
+
* The on-disk Ojas runtime uses a single `ExecutionTrace` shape, but the
|
|
5
|
+
* MCP boundary accepts a richer event vocabulary so that agents can stream
|
|
6
|
+
* tool calls, retrievals, memory ops, fallbacks, and policy violations
|
|
7
|
+
* without flattening everything into a single action label.
|
|
8
|
+
*/
|
|
9
|
+
import type { OjasModuleName } from '../types';
|
|
10
|
+
export type TraceEventType = 'agent_input' | 'agent_output' | 'tool_call_started' | 'tool_call_succeeded' | 'tool_call_failed' | 'retrieval_result' | 'memory_read' | 'memory_write' | 'failure' | 'latency_measurement' | 'token_usage' | 'user_correction' | 'planning_loop' | 'fallback' | 'policy_violation' | 'prompt_injection_detected' | 'context_overload_detected';
|
|
11
|
+
export interface IngestedTraceMeta {
|
|
12
|
+
/** Logical action name to record in the Ojas trace store. */
|
|
13
|
+
action: string;
|
|
14
|
+
/** Whether the event indicates a successful step (true by default). */
|
|
15
|
+
success: boolean;
|
|
16
|
+
/** Duration of the step in ms; 0 if not measured. */
|
|
17
|
+
duration_ms: number;
|
|
18
|
+
/** Optional error string when success=false. */
|
|
19
|
+
error?: string;
|
|
20
|
+
/** Optional reasoning summary captured at the time of the event. */
|
|
21
|
+
reasoning?: string;
|
|
22
|
+
/** Total tokens consumed in this step, parsed from `data` when reported. */
|
|
23
|
+
tokens_used?: number;
|
|
24
|
+
/** Input/prompt tokens reported by the caller. */
|
|
25
|
+
input_tokens?: number;
|
|
26
|
+
/** Output/completion tokens reported by the caller. */
|
|
27
|
+
output_tokens?: number;
|
|
28
|
+
/** Number of tool calls invoked. */
|
|
29
|
+
tool_calls?: number;
|
|
30
|
+
/** Reported cost in USD if a model gateway provided it. */
|
|
31
|
+
cost_usd?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Map a `TraceEventType` + arbitrary payload to the canonical Ojas
|
|
35
|
+
* `ExecutionTrace` shape plus a set of modules whose state is touched.
|
|
36
|
+
*/
|
|
37
|
+
export declare function classifyEvent(eventType: TraceEventType, data?: Record<string, unknown>): {
|
|
38
|
+
meta: IngestedTraceMeta;
|
|
39
|
+
affected_modules: OjasModuleName[];
|
|
40
|
+
health_impact: boolean;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Recommend a follow-up Ojas action keyed off the event type. Returned
|
|
44
|
+
* verbatim in `ojas_ingest_trace`'s response.
|
|
45
|
+
*/
|
|
46
|
+
export declare function recommendActionFor(eventType: TraceEventType): string | undefined;
|
|
47
|
+
//# sourceMappingURL=trace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../src/mcp/trace.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,MAAM,cAAc,GACtB,aAAa,GACb,cAAc,GACd,mBAAmB,GACnB,qBAAqB,GACrB,kBAAkB,GAClB,kBAAkB,GAClB,aAAa,GACb,cAAc,GACd,SAAS,GACT,qBAAqB,GACrB,aAAa,GACb,iBAAiB,GACjB,eAAe,GACf,UAAU,GACV,kBAAkB,GAClB,2BAA2B,GAC3B,2BAA2B,CAAC;AAEhC,MAAM,WAAW,iBAAiB;IAChC,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,OAAO,EAAE,OAAO,CAAC;IACjB,qDAAqD;IACrD,WAAW,EAAE,MAAM,CAAC;IACpB,gDAAgD;IAChD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kDA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