@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.
Files changed (174) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +308 -0
  3. package/dist/aahar/index.d.ts +179 -0
  4. package/dist/aahar/index.d.ts.map +1 -0
  5. package/dist/aahar/index.js +657 -0
  6. package/dist/aahar/index.js.map +1 -0
  7. package/dist/aahar/scoring.d.ts +85 -0
  8. package/dist/aahar/scoring.d.ts.map +1 -0
  9. package/dist/aahar/scoring.js +268 -0
  10. package/dist/aahar/scoring.js.map +1 -0
  11. package/dist/agni/index.d.ts +113 -0
  12. package/dist/agni/index.d.ts.map +1 -0
  13. package/dist/agni/index.js +328 -0
  14. package/dist/agni/index.js.map +1 -0
  15. package/dist/agni/model-router.d.ts +77 -0
  16. package/dist/agni/model-router.d.ts.map +1 -0
  17. package/dist/agni/model-router.js +163 -0
  18. package/dist/agni/model-router.js.map +1 -0
  19. package/dist/agni/response-distiller.d.ts +37 -0
  20. package/dist/agni/response-distiller.d.ts.map +1 -0
  21. package/dist/agni/response-distiller.js +193 -0
  22. package/dist/agni/response-distiller.js.map +1 -0
  23. package/dist/agni/tiktoken-adapter.d.ts +55 -0
  24. package/dist/agni/tiktoken-adapter.d.ts.map +1 -0
  25. package/dist/agni/tiktoken-adapter.js +113 -0
  26. package/dist/agni/tiktoken-adapter.js.map +1 -0
  27. package/dist/chikitsa/index.d.ts +130 -0
  28. package/dist/chikitsa/index.d.ts.map +1 -0
  29. package/dist/chikitsa/index.js +565 -0
  30. package/dist/chikitsa/index.js.map +1 -0
  31. package/dist/demo.d.ts +15 -0
  32. package/dist/demo.d.ts.map +1 -0
  33. package/dist/demo.js +278 -0
  34. package/dist/demo.js.map +1 -0
  35. package/dist/index.d.ts +201 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +588 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/mcp/audit.d.ts +39 -0
  40. package/dist/mcp/audit.d.ts.map +1 -0
  41. package/dist/mcp/audit.js +73 -0
  42. package/dist/mcp/audit.js.map +1 -0
  43. package/dist/mcp/contracts.d.ts +76 -0
  44. package/dist/mcp/contracts.d.ts.map +1 -0
  45. package/dist/mcp/contracts.js +44 -0
  46. package/dist/mcp/contracts.js.map +1 -0
  47. package/dist/mcp/envelope.d.ts +107 -0
  48. package/dist/mcp/envelope.d.ts.map +1 -0
  49. package/dist/mcp/envelope.js +162 -0
  50. package/dist/mcp/envelope.js.map +1 -0
  51. package/dist/mcp/registry.d.ts +110 -0
  52. package/dist/mcp/registry.d.ts.map +1 -0
  53. package/dist/mcp/registry.js +258 -0
  54. package/dist/mcp/registry.js.map +1 -0
  55. package/dist/mcp/server.d.ts +26 -0
  56. package/dist/mcp/server.d.ts.map +1 -0
  57. package/dist/mcp/server.js +107 -0
  58. package/dist/mcp/server.js.map +1 -0
  59. package/dist/mcp/tools/agent.d.ts +4 -0
  60. package/dist/mcp/tools/agent.d.ts.map +1 -0
  61. package/dist/mcp/tools/agent.js +300 -0
  62. package/dist/mcp/tools/agent.js.map +1 -0
  63. package/dist/mcp/tools/context.d.ts +4 -0
  64. package/dist/mcp/tools/context.d.ts.map +1 -0
  65. package/dist/mcp/tools/context.js +261 -0
  66. package/dist/mcp/tools/context.js.map +1 -0
  67. package/dist/mcp/tools/index.d.ts +5 -0
  68. package/dist/mcp/tools/index.d.ts.map +1 -0
  69. package/dist/mcp/tools/index.js +20 -0
  70. package/dist/mcp/tools/index.js.map +1 -0
  71. package/dist/mcp/tools/memory.d.ts +4 -0
  72. package/dist/mcp/tools/memory.d.ts.map +1 -0
  73. package/dist/mcp/tools/memory.js +220 -0
  74. package/dist/mcp/tools/memory.js.map +1 -0
  75. package/dist/mcp/tools/output.d.ts +4 -0
  76. package/dist/mcp/tools/output.d.ts.map +1 -0
  77. package/dist/mcp/tools/output.js +206 -0
  78. package/dist/mcp/tools/output.js.map +1 -0
  79. package/dist/mcp/tools/recovery.d.ts +4 -0
  80. package/dist/mcp/tools/recovery.d.ts.map +1 -0
  81. package/dist/mcp/tools/recovery.js +165 -0
  82. package/dist/mcp/tools/recovery.js.map +1 -0
  83. package/dist/mcp/tools/registrar.d.ts +4 -0
  84. package/dist/mcp/tools/registrar.d.ts.map +1 -0
  85. package/dist/mcp/tools/registrar.js +17 -0
  86. package/dist/mcp/tools/registrar.js.map +1 -0
  87. package/dist/mcp/tools/report.d.ts +4 -0
  88. package/dist/mcp/tools/report.d.ts.map +1 -0
  89. package/dist/mcp/tools/report.js +68 -0
  90. package/dist/mcp/tools/report.js.map +1 -0
  91. package/dist/mcp/tools/shared.d.ts +37 -0
  92. package/dist/mcp/tools/shared.d.ts.map +1 -0
  93. package/dist/mcp/tools/shared.js +214 -0
  94. package/dist/mcp/tools/shared.js.map +1 -0
  95. package/dist/mcp/trace.d.ts +47 -0
  96. package/dist/mcp/trace.d.ts.map +1 -0
  97. package/dist/mcp/trace.js +216 -0
  98. package/dist/mcp/trace.js.map +1 -0
  99. package/dist/nidra/index.d.ts +275 -0
  100. package/dist/nidra/index.d.ts.map +1 -0
  101. package/dist/nidra/index.js +889 -0
  102. package/dist/nidra/index.js.map +1 -0
  103. package/dist/persistence/migrations.d.ts +10 -0
  104. package/dist/persistence/migrations.d.ts.map +1 -0
  105. package/dist/persistence/migrations.js +77 -0
  106. package/dist/persistence/migrations.js.map +1 -0
  107. package/dist/persistence/sqlite.d.ts +30 -0
  108. package/dist/persistence/sqlite.d.ts.map +1 -0
  109. package/dist/persistence/sqlite.js +209 -0
  110. package/dist/persistence/sqlite.js.map +1 -0
  111. package/dist/persistence/types.d.ts +104 -0
  112. package/dist/persistence/types.d.ts.map +1 -0
  113. package/dist/persistence/types.js +5 -0
  114. package/dist/persistence/types.js.map +1 -0
  115. package/dist/pulse/index.d.ts +144 -0
  116. package/dist/pulse/index.d.ts.map +1 -0
  117. package/dist/pulse/index.js +453 -0
  118. package/dist/pulse/index.js.map +1 -0
  119. package/dist/raksha/classifiers/http-classifier.d.ts +26 -0
  120. package/dist/raksha/classifiers/http-classifier.d.ts.map +1 -0
  121. package/dist/raksha/classifiers/http-classifier.js +62 -0
  122. package/dist/raksha/classifiers/http-classifier.js.map +1 -0
  123. package/dist/raksha/classifiers/index.d.ts +5 -0
  124. package/dist/raksha/classifiers/index.d.ts.map +1 -0
  125. package/dist/raksha/classifiers/index.js +8 -0
  126. package/dist/raksha/classifiers/index.js.map +1 -0
  127. package/dist/raksha/classifiers/onnx-classifier.d.ts +41 -0
  128. package/dist/raksha/classifiers/onnx-classifier.d.ts.map +1 -0
  129. package/dist/raksha/classifiers/onnx-classifier.js +99 -0
  130. package/dist/raksha/classifiers/onnx-classifier.js.map +1 -0
  131. package/dist/raksha/hallucination-detectors.d.ts +106 -0
  132. package/dist/raksha/hallucination-detectors.d.ts.map +1 -0
  133. package/dist/raksha/hallucination-detectors.js +327 -0
  134. package/dist/raksha/hallucination-detectors.js.map +1 -0
  135. package/dist/raksha/index.d.ts +168 -0
  136. package/dist/raksha/index.d.ts.map +1 -0
  137. package/dist/raksha/index.js +597 -0
  138. package/dist/raksha/index.js.map +1 -0
  139. package/dist/raksha/prompt-injection-detectors.d.ts +30 -0
  140. package/dist/raksha/prompt-injection-detectors.d.ts.map +1 -0
  141. package/dist/raksha/prompt-injection-detectors.js +153 -0
  142. package/dist/raksha/prompt-injection-detectors.js.map +1 -0
  143. package/dist/types.d.ts +1115 -0
  144. package/dist/types.d.ts.map +1 -0
  145. package/dist/types.js +71 -0
  146. package/dist/types.js.map +1 -0
  147. package/dist/util/calibration.d.ts +32 -0
  148. package/dist/util/calibration.d.ts.map +1 -0
  149. package/dist/util/calibration.js +108 -0
  150. package/dist/util/calibration.js.map +1 -0
  151. package/dist/util/id.d.ts +2 -0
  152. package/dist/util/id.d.ts.map +1 -0
  153. package/dist/util/id.js +9 -0
  154. package/dist/util/id.js.map +1 -0
  155. package/dist/vyayam/index.d.ts +76 -0
  156. package/dist/vyayam/index.d.ts.map +1 -0
  157. package/dist/vyayam/index.js +528 -0
  158. package/dist/vyayam/index.js.map +1 -0
  159. package/dist/vyayam/tool-fault-proxy.d.ts +95 -0
  160. package/dist/vyayam/tool-fault-proxy.d.ts.map +1 -0
  161. package/dist/vyayam/tool-fault-proxy.js +170 -0
  162. package/dist/vyayam/tool-fault-proxy.js.map +1 -0
  163. package/docs/ARCHITECTURE.md +162 -0
  164. package/docs/BACKLOG.md +342 -0
  165. package/docs/CONFIGURATION.md +305 -0
  166. package/docs/EVIDENCE.md +232 -0
  167. package/docs/EVIDENCE_MATRIX.md +293 -0
  168. package/docs/KNOWN_FAILURES.md +367 -0
  169. package/docs/MCP.md +614 -0
  170. package/docs/MODULES.md +368 -0
  171. package/docs/SECURITY.md +251 -0
  172. package/docs/TRUST.md +88 -0
  173. package/docs/assets/ojas-hero.png +0 -0
  174. package/package.json +101 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../src/mcp/audit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEvC,MAAM,MAAM,cAAc,GACtB,gBAAgB,GAChB,kBAAkB,GAClB,cAAc,GACd,kBAAkB,GAClB,eAAe,GACf,mBAAmB,GACnB,cAAc,GACd,gBAAgB,GAChB,UAAU,CAAC;AAEf,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,cAAc,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;gBAE7B,MAAM,CAAC,EAAE,QAAQ,GAAG,IAAI;IAIpC,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,GAAG,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAa5B;;;OAGG;IACG,IAAI,CAAC,CAAC,EACV,SAAS,EAAE,cAAc,EACzB,IAAI,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,EAC9E,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC;CA4Bd"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ /**
3
+ * Structured JSONL audit logger for critical MCP operations.
4
+ *
5
+ * Emits one JSON line per audited event to a configurable writable stream
6
+ * (default: disabled). Each entry captures operation type, agent/session
7
+ * context, a summary of arguments and results, and wall-clock duration.
8
+ *
9
+ * Design constraints:
10
+ * - Zero overhead when disabled (no-op fast path).
11
+ * - Does not throw on write failures — audit is best-effort.
12
+ * - Does not buffer — each event is flushed immediately.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.AuditLogger = void 0;
16
+ class AuditLogger {
17
+ stream;
18
+ constructor(stream) {
19
+ this.stream = stream ?? null;
20
+ }
21
+ get enabled() {
22
+ return this.stream !== null;
23
+ }
24
+ log(entry) {
25
+ if (!this.stream)
26
+ return;
27
+ try {
28
+ const line = JSON.stringify({
29
+ ...entry,
30
+ timestamp: entry.timestamp || new Date().toISOString(),
31
+ });
32
+ this.stream.write(line + '\n');
33
+ }
34
+ catch {
35
+ // Best-effort — never crash the MCP server for audit failures.
36
+ }
37
+ }
38
+ /**
39
+ * Convenience: wraps an async handler, emitting an audit entry with
40
+ * timing around the call. Returns the handler's result transparently.
41
+ */
42
+ async wrap(operation, opts, fn) {
43
+ if (!this.stream)
44
+ return fn();
45
+ const start = Date.now();
46
+ try {
47
+ const result = await fn();
48
+ this.log({
49
+ timestamp: new Date().toISOString(),
50
+ operation,
51
+ agentId: opts.agentId,
52
+ sessionId: opts.sessionId,
53
+ args_summary: opts.args,
54
+ durationMs: Date.now() - start,
55
+ });
56
+ return result;
57
+ }
58
+ catch (err) {
59
+ this.log({
60
+ timestamp: new Date().toISOString(),
61
+ operation,
62
+ agentId: opts.agentId,
63
+ sessionId: opts.sessionId,
64
+ args_summary: opts.args,
65
+ result_summary: { error: err instanceof Error ? err.message : String(err) },
66
+ durationMs: Date.now() - start,
67
+ });
68
+ throw err;
69
+ }
70
+ }
71
+ }
72
+ exports.AuditLogger = AuditLogger;
73
+ //# sourceMappingURL=audit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.js","sourceRoot":"","sources":["../../src/mcp/audit.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAyBH,MAAa,WAAW;IACL,MAAM,CAAkB;IAEzC,YAAY,MAAwB;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC;IAC/B,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC;IAC9B,CAAC;IAED,GAAG,CAAC,KAAiB;QACnB,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO;QACzB,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;gBAC1B,GAAG,KAAK;gBACR,SAAS,EAAE,KAAK,CAAC,SAAS,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aACvD,CAAC,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;QACjC,CAAC;QAAC,MAAM,CAAC;YACP,+DAA+D;QACjE,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI,CACR,SAAyB,EACzB,IAA8E,EAC9E,EAAoB;QAEpB,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO,EAAE,EAAE,CAAC;QAE9B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,EAAE,EAAE,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC;gBACP,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;gBACnC,SAAS;gBACT,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,YAAY,EAAE,IAAI,CAAC,IAAI;gBACvB,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;aAC/B,CAAC,CAAC;YACH,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,GAAG,CAAC;gBACP,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;gBACnC,SAAS;gBACT,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,YAAY,EAAE,IAAI,CAAC,IAAI;gBACvB,cAAc,EAAE,EAAE,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;gBAC3E,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;aAC/B,CAAC,CAAC;YACH,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;CACF;AA5DD,kCA4DC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Health contracts, risk levels, and recovery policy types used by the
3
+ * Ojas MCP server.
4
+ *
5
+ * A health contract is the "service-level agreement" between Ojas and an
6
+ * agent: what counts as healthy, what risks the agent carries, what
7
+ * recovery actions apply when things go wrong.
8
+ */
9
+ import type { OjasModuleName } from '../types';
10
+ export type AgentRiskLevel = 'low' | 'medium' | 'high' | 'critical';
11
+ export type ToolMode = 'observe' | 'recommend' | 'apply';
12
+ export type RecoveryActionId = 'compress_context' | 'reset_plan' | 'freeze_memory_writes' | 'quarantine_input' | 'generate_fallback_response' | 'enter_safe_mode' | 'human_escalation' | 'reduce_tool_calls' | 'switch_to_cached_sources';
13
+ export interface HealthThresholds {
14
+ /** Minimum overall Ojas score (0–100) the agent must maintain. */
15
+ minimum_ojas_score?: number;
16
+ /** Minimum Aahar context-quality score (0–100). */
17
+ minimum_context_quality?: number;
18
+ /** Maximum tolerated hallucination risk (0–100 percent). */
19
+ maximum_hallucination_risk?: number;
20
+ }
21
+ export interface RecoveryPolicy {
22
+ on_context_overload?: RecoveryActionId;
23
+ on_prompt_injection?: RecoveryActionId;
24
+ on_repeated_failure?: RecoveryActionId;
25
+ on_memory_conflict?: RecoveryActionId;
26
+ on_tool_failure_loop?: RecoveryActionId;
27
+ }
28
+ export interface HealthContract {
29
+ agent_id: string;
30
+ agent_name?: string;
31
+ agent_type?: string;
32
+ risk_level: AgentRiskLevel;
33
+ description?: string;
34
+ allowed_tools?: string[];
35
+ health_thresholds: Required<Pick<HealthThresholds, 'minimum_ojas_score'>> & HealthThresholds;
36
+ recovery_policy: RecoveryPolicy;
37
+ /** ISO timestamp when the contract was created. */
38
+ created_at: string;
39
+ /** Stable id assigned to the contract. */
40
+ health_contract_id: string;
41
+ }
42
+ export interface AgentToolHealth {
43
+ tool_name: string;
44
+ total_calls: number;
45
+ successes: number;
46
+ failures: number;
47
+ timeouts: number;
48
+ latency_sum_ms: number;
49
+ last_seen_at: string;
50
+ }
51
+ export type HealthState = 'healthy' | 'watch' | 'degraded' | 'critical';
52
+ export interface ModuleScoresPercent {
53
+ aahar: number;
54
+ nidra: number;
55
+ vyayam: number;
56
+ raksha: number;
57
+ agni: number;
58
+ pulse: number;
59
+ chikitsa: number;
60
+ }
61
+ export interface AffectedModulesList {
62
+ modules: OjasModuleName[];
63
+ }
64
+ /**
65
+ * Defaults applied when an agent is auto-registered (i.e. a tool is called
66
+ * with an `agent_id` that has not yet been explicitly registered).
67
+ */
68
+ export declare const DEFAULT_HEALTH_THRESHOLDS: Required<HealthThresholds>;
69
+ export declare const DEFAULT_RECOVERY_POLICY: RecoveryPolicy;
70
+ /**
71
+ * Classify a 0–100 Ojas score into a human-readable health state.
72
+ * Thresholds are tuned to match the spec example ("Agent is healthy but
73
+ * shows mild degradation under broad research tasks" at 82, etc.).
74
+ */
75
+ export declare function classifyHealthState(score100: number, contract?: HealthContract): HealthState;
76
+ //# sourceMappingURL=contracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/mcp/contracts.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;AAEpE,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,WAAW,GAAG,OAAO,CAAC;AAEzD,MAAM,MAAM,gBAAgB,GACxB,kBAAkB,GAClB,YAAY,GACZ,sBAAsB,GACtB,kBAAkB,GAClB,4BAA4B,GAC5B,iBAAiB,GACjB,kBAAkB,GAClB,mBAAmB,GACnB,0BAA0B,CAAC;AAE/B,MAAM,WAAW,gBAAgB;IAC/B,kEAAkE;IAClE,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,mDAAmD;IACnD,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,4DAA4D;IAC5D,0BAA0B,CAAC,EAAE,MAAM,CAAC;CACrC;AAED,MAAM,WAAW,cAAc;IAC7B,mBAAmB,CAAC,EAAE,gBAAgB,CAAC;IACvC,mBAAmB,CAAC,EAAE,gBAAgB,CAAC;IACvC,mBAAmB,CAAC,EAAE,gBA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EAAE,QAAQ,CAAC,gBAAgB,CAIhE,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,cAMrC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,cAAc,GAAG,WAAW,CAM5F"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * Health contracts, risk levels, and recovery policy types used by the
4
+ * Ojas MCP server.
5
+ *
6
+ * A health contract is the "service-level agreement" between Ojas and an
7
+ * agent: what counts as healthy, what risks the agent carries, what
8
+ * recovery actions apply when things go wrong.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.DEFAULT_RECOVERY_POLICY = exports.DEFAULT_HEALTH_THRESHOLDS = void 0;
12
+ exports.classifyHealthState = classifyHealthState;
13
+ /**
14
+ * Defaults applied when an agent is auto-registered (i.e. a tool is called
15
+ * with an `agent_id` that has not yet been explicitly registered).
16
+ */
17
+ exports.DEFAULT_HEALTH_THRESHOLDS = {
18
+ minimum_ojas_score: 70,
19
+ minimum_context_quality: 65,
20
+ maximum_hallucination_risk: 20,
21
+ };
22
+ exports.DEFAULT_RECOVERY_POLICY = {
23
+ on_context_overload: 'compress_context',
24
+ on_prompt_injection: 'quarantine_input',
25
+ on_repeated_failure: 'enter_safe_mode',
26
+ on_memory_conflict: 'freeze_memory_writes',
27
+ on_tool_failure_loop: 'generate_fallback_response',
28
+ };
29
+ /**
30
+ * Classify a 0–100 Ojas score into a human-readable health state.
31
+ * Thresholds are tuned to match the spec example ("Agent is healthy but
32
+ * shows mild degradation under broad research tasks" at 82, etc.).
33
+ */
34
+ function classifyHealthState(score100, contract) {
35
+ const minimum = contract?.health_thresholds.minimum_ojas_score ?? exports.DEFAULT_HEALTH_THRESHOLDS.minimum_ojas_score;
36
+ if (score100 >= 90)
37
+ return 'healthy';
38
+ if (score100 >= minimum)
39
+ return 'watch';
40
+ if (score100 >= Math.max(40, minimum - 20))
41
+ return 'degraded';
42
+ return 'critical';
43
+ }
44
+ //# sourceMappingURL=contracts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../src/mcp/contracts.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAoGH,kDAMC;AA7BD;;;GAGG;AACU,QAAA,yBAAyB,GAA+B;IACnE,kBAAkB,EAAE,EAAE;IACtB,uBAAuB,EAAE,EAAE;IAC3B,0BAA0B,EAAE,EAAE;CAC/B,CAAC;AAEW,QAAA,uBAAuB,GAAmB;IACrD,mBAAmB,EAAE,kBAAkB;IACvC,mBAAmB,EAAE,kBAAkB;IACvC,mBAAmB,EAAE,iBAAiB;IACtC,kBAAkB,EAAE,sBAAsB;IAC1C,oBAAoB,EAAE,4BAA4B;CACnD,CAAC;AAEF;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,QAAgB,EAAE,QAAyB;IAC7E,MAAM,OAAO,GAAG,QAAQ,EAAE,iBAAiB,CAAC,kBAAkB,IAAI,iCAAyB,CAAC,kBAAkB,CAAC;IAC/G,IAAI,QAAQ,IAAI,EAAE;QAAE,OAAO,SAAS,CAAC;IACrC,IAAI,QAAQ,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC;IACxC,IAAI,QAAQ,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,CAAC;QAAE,OAAO,UAAU,CAAC;IAC9D,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Standard response envelope for every Ojas MCP tool.
3
+ *
4
+ * Per the Ojas tool-design contract, every tool returns a uniform set of
5
+ * meta fields (`status`, `ojas_score_delta`, `affected_modules`,
6
+ * `events_created`, `recommended_next_actions`, `requires_human_review`)
7
+ * plus a `correlation_id` and `agent_id`, with the tool-specific payload
8
+ * merged on top.
9
+ */
10
+ import type { OjasModuleName } from '../types';
11
+ export type EnvelopeStatus = 'success' | 'warning' | 'failed';
12
+ export interface EnvelopeMeta {
13
+ status?: EnvelopeStatus;
14
+ agent_id?: string;
15
+ correlation_id?: string;
16
+ ojas_score_delta?: number;
17
+ affected_modules?: OjasModuleName[];
18
+ events_created?: string[];
19
+ recommended_next_actions?: string[];
20
+ requires_human_review?: boolean;
21
+ }
22
+ /**
23
+ * Public envelope shape returned to clients. Tool-specific fields are
24
+ * merged in via `T`.
25
+ */
26
+ export type Envelope<T extends object = Record<string, unknown>> = T & {
27
+ status: EnvelopeStatus;
28
+ agent_id: string | null;
29
+ correlation_id: string;
30
+ ojas_score_delta: number;
31
+ affected_modules: OjasModuleName[];
32
+ events_created: string[];
33
+ recommended_next_actions: string[];
34
+ requires_human_review: boolean;
35
+ };
36
+ export declare function generateCorrelationId(): string;
37
+ export declare function envelope<T extends object>(data: T, meta?: EnvelopeMeta): Envelope<T>;
38
+ /** Convenience: wrap an envelope as an MCP `tools/call` text-content reply. */
39
+ export declare function mcpReply<T extends object>(data: T, meta?: EnvelopeMeta): {
40
+ content: {
41
+ type: "text";
42
+ text: string;
43
+ }[];
44
+ };
45
+ /**
46
+ * Payload for every tool that accepts a `session_id` input. Session
47
+ * isolation is implemented in the MCP registry: non-default session IDs
48
+ * receive their own Ojas runtime state and optional persistence row.
49
+ */
50
+ export declare function sessionScopeFields(session_id: string | undefined | null): {
51
+ session_id: string | null;
52
+ session_scope_supported: true;
53
+ };
54
+ /**
55
+ * Categories returned by `classifyError`, attached to every failed
56
+ * envelope as `error_code`. See the comment on `OjasError` for the
57
+ * canonical mapping.
58
+ */
59
+ export type ErrorCode = 'invalid_input' | 'policy_violation' | 'not_found' | 'internal_error';
60
+ /**
61
+ * Typed error thrown from internal Ojas boundaries (registry, schema
62
+ * validators, policy gates) so `safeHandler` can label the failed
63
+ * envelope without pattern-matching on the message string. Message
64
+ * heuristics in `classifyError` remain as a fallback for third-party
65
+ * throws and unexpected internal exceptions.
66
+ *
67
+ * Canonical category mapping:
68
+ *
69
+ * - `invalid_input` — schema validation, malformed dates, bad types.
70
+ * Caller bug, not a safety event.
71
+ * - `policy_violation` — health-contract or allowlist refusals
72
+ * (duplicate-register, replacement disabled,
73
+ * unknown agent on a strict allowlist).
74
+ * Caller asked for something the policy forbids.
75
+ * - `not_found` — agent or resource lookup failures.
76
+ * - `internal_error` — everything else. These are the only ones that
77
+ * require human review by default; everything
78
+ * else is a caller-side problem.
79
+ */
80
+ export declare class OjasError extends Error {
81
+ readonly code: ErrorCode;
82
+ readonly humanReview: boolean;
83
+ constructor(code: ErrorCode, message: string, humanReview?: boolean);
84
+ }
85
+ /**
86
+ * Classify any thrown value into an `ErrorCode`. Prefers a typed
87
+ * `OjasError.code` when available; otherwise falls back to message
88
+ * substring heuristics. The heuristics path is intentionally narrow —
89
+ * unknown messages are labelled `internal_error` so they still page a
90
+ * human and we get a signal to convert that throw site to `OjasError`.
91
+ */
92
+ export declare function classifyError(err: unknown): ErrorCode;
93
+ /**
94
+ * Wrap an Ojas tool handler so any thrown error is returned as a
95
+ * structured `status: 'failed'` envelope rather than escaping as an MCP
96
+ * protocol-level error. Variadic to preserve any extra args (context,
97
+ * request-id, cancellation handle) the MCP SDK may pass alongside the
98
+ * input arguments — dropping those would lock us out of future SDK
99
+ * features like per-call auth context.
100
+ *
101
+ * Errors are classified by message into `invalid_input`,
102
+ * `policy_violation`, `not_found`, or `internal_error`. Only internal
103
+ * errors set `requires_human_review: true` so dashboards aren't paged
104
+ * for routine validation failures.
105
+ */
106
+ export declare function safeHandler(toolName: string, handler: (...args: any[]) => Promise<ReturnType<typeof mcpReply>>): (...args: unknown[]) => Promise<ReturnType<typeof mcpReply>>;
107
+ //# sourceMappingURL=envelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/mcp/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG/C,MAAM,MAAM,cAAc,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,CAAC;IAC1B,uBAAuB,EAAE,IAAI,CAAC;CAC/B,CAKA;AAED;;;;GAIG;AACH,MAAM,MAAM,SAAS,GACjB,eAAe,GACf,kBAAkB,GAClB,WAAW,GACX,gBAAgB,CAAC;AAErB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;gBAClB,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,UAAQ;CAMlE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,CA2BrD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAEhB,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,GAChE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAgC9D"}
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ /**
3
+ * Standard response envelope for every Ojas MCP tool.
4
+ *
5
+ * Per the Ojas tool-design contract, every tool returns a uniform set of
6
+ * meta fields (`status`, `ojas_score_delta`, `affected_modules`,
7
+ * `events_created`, `recommended_next_actions`, `requires_human_review`)
8
+ * plus a `correlation_id` and `agent_id`, with the tool-specific payload
9
+ * merged on top.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OjasError = void 0;
13
+ exports.generateCorrelationId = generateCorrelationId;
14
+ exports.envelope = envelope;
15
+ exports.mcpReply = mcpReply;
16
+ exports.sessionScopeFields = sessionScopeFields;
17
+ exports.classifyError = classifyError;
18
+ exports.safeHandler = safeHandler;
19
+ const id_1 = require("../util/id");
20
+ function generateCorrelationId() {
21
+ return (0, id_1.newId)('cor');
22
+ }
23
+ function envelope(data, meta = {}) {
24
+ return {
25
+ status: meta.status ?? 'success',
26
+ agent_id: meta.agent_id ?? null,
27
+ correlation_id: meta.correlation_id ?? generateCorrelationId(),
28
+ ojas_score_delta: meta.ojas_score_delta ?? 0,
29
+ affected_modules: meta.affected_modules ?? [],
30
+ events_created: meta.events_created ?? [],
31
+ recommended_next_actions: meta.recommended_next_actions ?? [],
32
+ requires_human_review: meta.requires_human_review ?? false,
33
+ ...data,
34
+ };
35
+ }
36
+ /** Convenience: wrap an envelope as an MCP `tools/call` text-content reply. */
37
+ function mcpReply(data, meta = {}) {
38
+ const payload = envelope(data, meta);
39
+ return {
40
+ content: [
41
+ { type: 'text', text: JSON.stringify(payload, null, 2) },
42
+ ],
43
+ };
44
+ }
45
+ /**
46
+ * Payload for every tool that accepts a `session_id` input. Session
47
+ * isolation is implemented in the MCP registry: non-default session IDs
48
+ * receive their own Ojas runtime state and optional persistence row.
49
+ */
50
+ function sessionScopeFields(session_id) {
51
+ return {
52
+ session_id: session_id ?? null,
53
+ session_scope_supported: true,
54
+ };
55
+ }
56
+ /**
57
+ * Typed error thrown from internal Ojas boundaries (registry, schema
58
+ * validators, policy gates) so `safeHandler` can label the failed
59
+ * envelope without pattern-matching on the message string. Message
60
+ * heuristics in `classifyError` remain as a fallback for third-party
61
+ * throws and unexpected internal exceptions.
62
+ *
63
+ * Canonical category mapping:
64
+ *
65
+ * - `invalid_input` — schema validation, malformed dates, bad types.
66
+ * Caller bug, not a safety event.
67
+ * - `policy_violation` — health-contract or allowlist refusals
68
+ * (duplicate-register, replacement disabled,
69
+ * unknown agent on a strict allowlist).
70
+ * Caller asked for something the policy forbids.
71
+ * - `not_found` — agent or resource lookup failures.
72
+ * - `internal_error` — everything else. These are the only ones that
73
+ * require human review by default; everything
74
+ * else is a caller-side problem.
75
+ */
76
+ class OjasError extends Error {
77
+ code;
78
+ humanReview;
79
+ constructor(code, message, humanReview = false) {
80
+ super(message);
81
+ this.name = 'OjasError';
82
+ this.code = code;
83
+ this.humanReview = humanReview;
84
+ }
85
+ }
86
+ exports.OjasError = OjasError;
87
+ /**
88
+ * Classify any thrown value into an `ErrorCode`. Prefers a typed
89
+ * `OjasError.code` when available; otherwise falls back to message
90
+ * substring heuristics. The heuristics path is intentionally narrow —
91
+ * unknown messages are labelled `internal_error` so they still page a
92
+ * human and we get a signal to convert that throw site to `OjasError`.
93
+ */
94
+ function classifyError(err) {
95
+ if (err instanceof OjasError)
96
+ return err.code;
97
+ const message = err instanceof Error ? err.message : typeof err === 'string' ? err : String(err);
98
+ const m = message.toLowerCase();
99
+ if (m.includes('already registered') ||
100
+ m.includes('replacement is disabled') ||
101
+ m.includes('not allowed') ||
102
+ m.includes('auto-registration is disabled') ||
103
+ m.includes('maxagents')) {
104
+ return 'policy_violation';
105
+ }
106
+ if (m.includes('not found') || m.includes('unknown agent')) {
107
+ return 'not_found';
108
+ }
109
+ if (m.includes('must be') ||
110
+ m.includes('must include') ||
111
+ m.includes('invalid') ||
112
+ m.includes('is in the future') ||
113
+ m.includes('iso-8601')) {
114
+ return 'invalid_input';
115
+ }
116
+ return 'internal_error';
117
+ }
118
+ /**
119
+ * Wrap an Ojas tool handler so any thrown error is returned as a
120
+ * structured `status: 'failed'` envelope rather than escaping as an MCP
121
+ * protocol-level error. Variadic to preserve any extra args (context,
122
+ * request-id, cancellation handle) the MCP SDK may pass alongside the
123
+ * input arguments — dropping those would lock us out of future SDK
124
+ * features like per-call auth context.
125
+ *
126
+ * Errors are classified by message into `invalid_input`,
127
+ * `policy_violation`, `not_found`, or `internal_error`. Only internal
128
+ * errors set `requires_human_review: true` so dashboards aren't paged
129
+ * for routine validation failures.
130
+ */
131
+ function safeHandler(toolName,
132
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
+ handler) {
134
+ return async (...args) => {
135
+ try {
136
+ return await handler(...args);
137
+ }
138
+ catch (err) {
139
+ const message = err instanceof Error ? err.message : String(err);
140
+ const errorCode = classifyError(err);
141
+ const firstArg = args[0];
142
+ const agent_id = firstArg && typeof firstArg.agent_id === 'string' ? firstArg.agent_id : null;
143
+ // Only true internal crashes page a human by default. Validation /
144
+ // policy / not-found are caller-side problems and should show up
145
+ // in client logs, not the operator pager. A typed OjasError can
146
+ // override this when an internal boundary needs human attention
147
+ // even though the code itself is a validation / policy class.
148
+ const requires_human_review = err instanceof OjasError ? err.humanReview : errorCode === 'internal_error';
149
+ return mcpReply({
150
+ accepted: false,
151
+ error: message,
152
+ error_class: `${toolName}_error`,
153
+ error_code: errorCode,
154
+ }, {
155
+ status: 'failed',
156
+ agent_id: agent_id ?? undefined,
157
+ requires_human_review,
158
+ });
159
+ }
160
+ };
161
+ }
162
+ //# sourceMappingURL=envelope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../src/mcp/envelope.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAiCH,sDAEC;AAED,4BAYC;AAGD,4BAOC;AAOD,gDAQC;AAmDD,sCA2BC;AAeD,kCAoCC;AAxMD,mCAAmC;AA8BnC,SAAgB,qBAAqB;IACnC,OAAO,IAAA,UAAK,EAAC,KAAK,CAAC,CAAC;AACtB,CAAC;AAED,SAAgB,QAAQ,CAAmB,IAAO,EAAE,OAAqB,EAAE;IACzE,OAAO;QACL,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,SAAS;QAChC,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,IAAI;QAC/B,cAAc,EAAE,IAAI,CAAC,cAAc,IAAI,qBAAqB,EAAE;QAC9D,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,IAAI,CAAC;QAC5C,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,IAAI,EAAE;QAC7C,cAAc,EAAE,IAAI,CAAC,cAAc,IAAI,EAAE;QACzC,wBAAwB,EAAE,IAAI,CAAC,wBAAwB,IAAI,EAAE;QAC7D,qBAAqB,EA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,QAAQ,GACZ,QAAQ,IAAI,OAAO,QAAQ,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAE,QAAQ,CAAC,QAAmB,CAAC,CAAC,CAAC,IAAI,CAAC;YAC3F,mEAAmE;YACnE,iEAAiE;YACjE,gEAAgE;YAChE,gEAAgE;YAChE,8DAA8D;YAC9D,MAAM,qBAAqB,GACzB,GAAG,YAAY,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,KAAK,gBAAgB,CAAC;YAC9E,OAAO,QAAQ,CACb;gBACE,QAAQ,EAAE,KAAK;gBACf,KAAK,EAAE,OAAO;gBACd,WAAW,EAAE,GAAG,QAAQ,QAAQ;gBAChC,UAAU,EAAE,SAAS;aACtB,EACD;gBACE,MAAM,EAAE,QAAQ;gBAChB,QAAQ,EAAE,QAAQ,IAAI,SAAS;gBAC/B,qBAAqB;aACtB,CACF,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Multi-agent registry for the Ojas MCP server.
3
+ *
4
+ * Each registered agent gets its own `Ojas` instance plus a stored
5
+ * `HealthContract`, recent-history caches, and operational flags
6
+ * (e.g. safe mode). The MCP server proxies tool calls to the
7
+ * registry, which routes by `agent_id`.
8
+ */
9
+ import { Ojas } from '../index';
10
+ import type { AgentHealthReport } from '../types';
11
+ import type { PersistenceStore } from '../persistence/types';
12
+ import { AgentRiskLevel, AgentToolHealth, HealthContract, HealthThresholds, RecoveryPolicy } from './contracts';
13
+ export interface RegisterAgentInput {
14
+ agent_id: string;
15
+ agent_name?: string;
16
+ agent_type?: string;
17
+ risk_level?: AgentRiskLevel;
18
+ description?: string;
19
+ allowed_tools?: string[];
20
+ health_thresholds?: HealthThresholds;
21
+ recovery_policy?: RecoveryPolicy;
22
+ /** Explicitly replace an existing registration and all its runtime state. */
23
+ replace_existing?: boolean;
24
+ }
25
+ export interface RecentEvent {
26
+ id: string;
27
+ timestamp: string;
28
+ event_type: string;
29
+ description: string;
30
+ }
31
+ export interface AgentEntry {
32
+ agent_id: string;
33
+ session_id: string;
34
+ ojas: Ojas;
35
+ contract: HealthContract;
36
+ safe_mode: boolean;
37
+ safe_mode_reason?: string;
38
+ safe_mode_restrictions: string[];
39
+ tool_health: Map<string, AgentToolHealth>;
40
+ recent_events: RecentEvent[];
41
+ last_health_score: number;
42
+ last_health_report?: AgentHealthReport;
43
+ }
44
+ export interface AgentRegistryOptions {
45
+ /** Hard cap on simultaneously-tracked agents. Registration fails once full. */
46
+ maxAgents?: number;
47
+ /**
48
+ * Whether unknown `agent_id`s may be silently auto-registered when a tool
49
+ * is invoked. Defaults to true for developer-friendly local use; set to
50
+ * false (e.g. via the OJAS_DISABLE_AUTO_REGISTER env var on the MCP
51
+ * server) to require an explicit `ojas_register_agent` call.
52
+ */
53
+ autoRegister?: boolean;
54
+ /** Optional allowlist of agent IDs this registry will accept. */
55
+ allowedAgentIds?: string[];
56
+ /**
57
+ * Whether `register(replace_existing: true)` is honoured. **Defaults to
58
+ * false** — replacing an existing registration wipes its accumulated
59
+ * Ojas state (traces, memories, events, contract). Production
60
+ * deployments should leave this off and rely on operator action to
61
+ * reset state intentionally. The MCP server wires this from
62
+ * `OJAS_ALLOW_REPLACE_EXISTING=1`.
63
+ */
64
+ allowReplaceExisting?: boolean;
65
+ /** Optional durable store used to hydrate and persist session state. */
66
+ persistenceStore?: PersistenceStore;
67
+ }
68
+ export declare class AgentRegistry {
69
+ private agents;
70
+ private readonly maxAgents;
71
+ private readonly autoRegister;
72
+ private readonly allowedAgentIds?;
73
+ private readonly allowReplaceExisting;
74
+ private readonly persistenceStore?;
75
+ constructor(opts?: AgentRegistryOptions);
76
+ private getSessionMap;
77
+ private putEntry;
78
+ private buildEntry;
79
+ private hydrate;
80
+ private snapshot;
81
+ persist(entry: AgentEntry): void;
82
+ private assertAgentAllowed;
83
+ /** Register an agent. Existing registrations are protected unless replace_existing=true. */
84
+ register(input: RegisterAgentInput): AgentEntry;
85
+ /** Look up an existing agent (returns undefined if not registered). */
86
+ get(agentId: string, sessionId?: string): AgentEntry | undefined;
87
+ /**
88
+ * Look up an agent, auto-registering with conservative defaults if
89
+ * missing. Throws when auto-registration is disabled — production
90
+ * deployments should disable it and require an explicit register call.
91
+ */
92
+ getOrAutoRegister(agentId: string, fallbackRisk?: AgentRiskLevel): AgentEntry;
93
+ getOrAutoRegisterSession(agentId: string, sessionId: string | undefined, fallbackRisk?: AgentRiskLevel): AgentEntry;
94
+ list(): readonly Readonly<AgentEntry>[];
95
+ /** Add an event to the agent's recent-events ring buffer. */
96
+ recordEvent(entry: AgentEntry, eventType: string, description: string): RecentEvent;
97
+ /** Update tool-health stats for an agent. */
98
+ recordToolOutcome(entry: AgentEntry, toolName: string, outcome: {
99
+ success: boolean;
100
+ latencyMs: number;
101
+ timeout: boolean;
102
+ }): AgentToolHealth;
103
+ /**
104
+ * Replace the agent's stored health snapshot and return the score delta
105
+ * (new − previous) so the caller can include it in the envelope.
106
+ */
107
+ updateHealthSnapshot(entry: AgentEntry, report: AgentHealthReport): number;
108
+ setSafeMode(entry: AgentEntry, on: boolean, reason?: string, restrictions?: string[]): void;
109
+ }
110
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/mcp/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAA2B,MAAM,sBAAsB,CAAC;AAItF,OAAO,EACL,cAAc,EACd,eAAe,EAGf,cAAc,EACd,gBAAgB,EAChB,cAAc,EACf,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EA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