open-multi-agent-kit 0.78.1 → 0.78.2

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 (69) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/MATURITY.md +4 -0
  3. package/README.md +70 -1
  4. package/dist/cli/register-spec-agent-goal-commands.js +45 -0
  5. package/dist/cli/release-promotion-gate.d.ts +14 -0
  6. package/dist/cli/release-promotion-gate.js +71 -0
  7. package/dist/cli/v2/release-commands.d.ts +29 -0
  8. package/dist/cli/v2/release-commands.js +95 -0
  9. package/dist/commands/chat/native-root-loop.js +14 -1
  10. package/dist/commands/chat/slash/commands/session.js +19 -1
  11. package/dist/commands/goal-interview.d.ts +18 -0
  12. package/dist/commands/goal-interview.js +396 -0
  13. package/dist/contracts/interview.d.ts +106 -0
  14. package/dist/contracts/interview.js +9 -0
  15. package/dist/evidence/index.d.ts +4 -0
  16. package/dist/evidence/index.js +2 -0
  17. package/dist/evidence/proof-trust-cli.d.ts +8 -0
  18. package/dist/evidence/proof-trust-cli.js +27 -0
  19. package/dist/evidence/proof-trust.d.ts +14 -0
  20. package/dist/evidence/proof-trust.js +381 -0
  21. package/dist/evidence/regression-proof-matrix.d.ts +42 -0
  22. package/dist/evidence/regression-proof-matrix.js +72 -0
  23. package/dist/goal/intent-frame.d.ts +6 -0
  24. package/dist/goal/intent-frame.js +21 -9
  25. package/dist/goal/interview-assimilation.d.ts +13 -0
  26. package/dist/goal/interview-assimilation.js +383 -0
  27. package/dist/goal/interview-question-bank.d.ts +11 -0
  28. package/dist/goal/interview-question-bank.js +225 -0
  29. package/dist/goal/interview-scoring.d.ts +31 -0
  30. package/dist/goal/interview-scoring.js +187 -0
  31. package/dist/goal/interview-session.d.ts +25 -0
  32. package/dist/goal/interview-session.js +116 -0
  33. package/dist/input/input-envelope.d.ts +22 -0
  34. package/dist/input/input-envelope.js +1 -0
  35. package/dist/runtime/advanced-control-loop.d.ts +60 -0
  36. package/dist/runtime/advanced-control-loop.js +136 -0
  37. package/dist/runtime/agent-runtime.d.ts +10 -0
  38. package/dist/runtime/blast-radius.d.ts +10 -0
  39. package/dist/runtime/blast-radius.js +14 -0
  40. package/dist/runtime/contracts/evidence.d.ts +87 -0
  41. package/dist/runtime/contracts/evidence.js +7 -0
  42. package/dist/runtime/contracts/router-v2.d.ts +44 -0
  43. package/dist/runtime/contracts/router-v2.js +4 -0
  44. package/dist/runtime/contracts/weakness-remediation.d.ts +67 -0
  45. package/dist/runtime/contracts/weakness-remediation.js +36 -0
  46. package/dist/runtime/kimi-api-runtime.js +59 -1
  47. package/dist/runtime/proof-bundle-trust.d.ts +74 -0
  48. package/dist/runtime/proof-bundle-trust.js +100 -0
  49. package/dist/runtime/provider-maturity-gate.d.ts +41 -0
  50. package/dist/runtime/provider-maturity-gate.js +101 -0
  51. package/dist/runtime/public-surface.d.ts +93 -0
  52. package/dist/runtime/public-surface.js +146 -0
  53. package/dist/runtime/router-v2-scoring.d.ts +11 -0
  54. package/dist/runtime/router-v2-scoring.js +151 -0
  55. package/dist/runtime/weakness-remediation-index.d.ts +27 -0
  56. package/dist/runtime/weakness-remediation-index.js +37 -0
  57. package/dist/schema/proof-bundle.schema.d.ts +26 -26
  58. package/dist/util/clipboard-image.d.ts +49 -0
  59. package/dist/util/clipboard-image.js +263 -0
  60. package/docs/2026-06-09/critical-issues.md +20 -0
  61. package/docs/2026-06-09/improvements.md +14 -0
  62. package/docs/2026-06-09/init-checklist.md +25 -0
  63. package/docs/2026-06-09/plan.md +20 -0
  64. package/docs/github-organic-promotion.md +127 -0
  65. package/docs/native-root-runtime-algorithms.md +301 -0
  66. package/package.json +4 -3
  67. package/readmeasset/ASSET_INDEX.md +1 -0
  68. package/templates/skills/agents/omk-agent-reach-websearch/SKILL.md +55 -0
  69. package/templates/skills/kimi/omk-agent-reach-websearch/SKILL.md +55 -0
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Evidence contracts for OMK Weakness Remediation.
3
+ *
4
+ * Core interfaces that bridge reasoning traces, runtime decisions,
5
+ * provider maturity, and release gates into a verifiable evidence model.
6
+ */
7
+ /** Granularity of a single evidence artifact. */
8
+ export type EvidenceKind = "test" | "diff" | "command" | "screenshot" | "trace" | "metric" | "audit" | "review";
9
+ /** Verdict state of an evidence item. */
10
+ export type EvidenceVerdict = "pass" | "fail" | "partial" | "pending";
11
+ /** A single, auditable piece of evidence. */
12
+ export interface EvidenceItem {
13
+ readonly id: string;
14
+ readonly kind: EvidenceKind;
15
+ readonly source: string;
16
+ readonly description: string;
17
+ readonly verdict: EvidenceVerdict;
18
+ readonly timestamp: string;
19
+ readonly confidence: number;
20
+ readonly linkedTraceId?: string;
21
+ readonly linkedFilePaths: readonly string[];
22
+ readonly metadata?: Readonly<Record<string, unknown>>;
23
+ }
24
+ /** A curated bundle of evidence items with a collective verdict. */
25
+ export interface ProofBundle {
26
+ readonly id: string;
27
+ readonly name: string;
28
+ readonly items: readonly EvidenceItem[];
29
+ readonly createdAt: string;
30
+ readonly verdict: EvidenceVerdict;
31
+ readonly coveragePercent: number;
32
+ readonly summary: string;
33
+ }
34
+ /** Maturity tier for a provider or runtime surface. */
35
+ export type MaturityTier = "experimental" | "preview" | "stable" | "deprecated";
36
+ /** Maturity assessment for a provider/runtime. */
37
+ export interface ProviderMaturity {
38
+ readonly providerId: string;
39
+ readonly tier: MaturityTier;
40
+ readonly runCount: number;
41
+ readonly passRate: number;
42
+ readonly lastVerifiedAt: string;
43
+ readonly knownIssues: readonly string[];
44
+ readonly recommendedBudgetFactor: number;
45
+ }
46
+ /** Normalized record of a runtime routing decision. */
47
+ export interface RuntimeRouterDecision {
48
+ readonly decisionId: string;
49
+ readonly turnId: string;
50
+ readonly timestamp: string;
51
+ readonly intentCategory: string;
52
+ readonly selectedRuntimeId: string;
53
+ readonly candidatesConsidered: readonly string[];
54
+ readonly confidence: number;
55
+ readonly fallbackUsed: boolean;
56
+ readonly latencyMs: number;
57
+ }
58
+ /** Permission level derived from a proof bundle trust score. */
59
+ export type ClaimPermissionLevel = "strong-public-claim" | "qualified-public-claim" | "internal-claim-only" | "no-claim";
60
+ /** Authority class derived from provider maturity score and sub-scores. */
61
+ export type ProviderAuthorityClass = "merge-authority" | "write-authority" | "review-authority" | "read-only-advisory" | "disabled";
62
+ /** Kinds of adapter tests used in provider maturity assessment. */
63
+ export type AdapterTestKind = "auth" | "read" | "write" | "shell" | "mcp" | "merge" | "evidence" | "fallback";
64
+ /** Result of a single adapter test. */
65
+ export interface AdapterTestResult {
66
+ readonly kind: AdapterTestKind;
67
+ readonly passed: boolean;
68
+ readonly score: number;
69
+ readonly details?: string;
70
+ }
71
+ /** Per-gate check result. */
72
+ export interface GateCheck {
73
+ readonly gate: string;
74
+ readonly passed: boolean;
75
+ readonly message: string;
76
+ readonly evidenceIds: readonly string[];
77
+ }
78
+ /** Result of a full release gate evaluation. */
79
+ export interface ReleaseGateResult {
80
+ readonly runId: string;
81
+ readonly timestamp: string;
82
+ readonly overallPass: boolean;
83
+ readonly checks: readonly GateCheck[];
84
+ readonly requiredGates: readonly string[];
85
+ readonly optionalGates: readonly string[];
86
+ readonly summary: string;
87
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Evidence contracts for OMK Weakness Remediation.
3
+ *
4
+ * Core interfaces that bridge reasoning traces, runtime decisions,
5
+ * provider maturity, and release gates into a verifiable evidence model.
6
+ */
7
+ export {};
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Router v2 contracts — Evidence-Calibrated Runtime Router (Algorithm 6)
3
+ */
4
+ import type { AgentRuntime } from "../agent-runtime.js";
5
+ export type NodeIntent = "research" | "planning" | "coding" | "debugging" | "refactor" | "review" | "test-generation" | "documentation" | "shell-operation";
6
+ export interface EvidenceHistoryEntry {
7
+ readonly runtime: string;
8
+ readonly intent: string;
9
+ readonly passed: boolean;
10
+ readonly timestamp: string;
11
+ readonly nodeId: string;
12
+ }
13
+ export interface RuntimeScoreV2 {
14
+ readonly runtimeId: string;
15
+ readonly bayesianEvidenceScore: number;
16
+ readonly confidence: number;
17
+ readonly capabilityFit: number;
18
+ readonly maturityScore: number;
19
+ readonly latencyScore: number;
20
+ readonly costScore: number;
21
+ readonly recentFailurePenalty: number;
22
+ readonly blastRadiusPenalty: number;
23
+ readonly composite: number;
24
+ }
25
+ export interface RuntimeRouterDecisionV2 {
26
+ readonly runtime: AgentRuntime;
27
+ readonly reason: string;
28
+ readonly fallbacks: AgentRuntime[];
29
+ readonly intent: NodeIntent;
30
+ readonly scores: RuntimeScoreV2[];
31
+ }
32
+ export interface BlastRadiusParams {
33
+ readonly downstreamNodeCount: number;
34
+ readonly affectedFileCount: number;
35
+ readonly hasGlobalSideEffects: boolean;
36
+ }
37
+ export interface RouterV2Options {
38
+ readonly enableBlastRadius?: boolean;
39
+ readonly blastRadiusParams?: BlastRadiusParams;
40
+ }
41
+ export interface RouterV2ScoringEngine {
42
+ score(runtime: AgentRuntime, intent: NodeIntent, history: EvidenceHistoryEntry[]): RuntimeScoreV2;
43
+ select(candidates: AgentRuntime[], intent: NodeIntent, history: EvidenceHistoryEntry[]): RuntimeRouterDecisionV2;
44
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Router v2 contracts — Evidence-Calibrated Runtime Router (Algorithm 6)
3
+ */
4
+ export {};
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Weakness Remediation contracts — shared constants and Phase 5 types.
3
+ *
4
+ * - Phase 2 Proof Bundle Trust, Phase 3 Provider Maturity Gate,
5
+ * and Phase 1 Public Surface Compression share thresholds here.
6
+ * - Phase 5 Release Promotion Gate types live here as well.
7
+ */
8
+ /** Evidence trust threshold for standard claims. */
9
+ export declare const TAU_EVIDENCE = 0.75;
10
+ /** Evidence trust threshold for high-confidence claims. */
11
+ export declare const TAU_EVIDENCE_HIGH = 0.85;
12
+ /** Proof bundle trust threshold. */
13
+ export declare const TAU_PROOF = 0.85;
14
+ /** Stability/maturity threshold for fully-trusted surfaces. */
15
+ export declare const TAU_STABLE = 0.9;
16
+ /** Beta prior α₀ for Bayesian run-count scoring. */
17
+ export declare const BETA_PRIOR_ALPHA0 = 1;
18
+ /** Beta prior β₀ for Bayesian run-count scoring. */
19
+ export declare const BETA_PRIOR_BETA0 = 1;
20
+ /** Default public surface budget K (max items). */
21
+ export declare const SURFACE_BUDGET_K = 8;
22
+ /** Algorithm 8 release gate weights. */
23
+ export declare const RELEASE_GATE_WEIGHTS: {
24
+ readonly ci: 0.15;
25
+ readonly build: 0.1;
26
+ readonly types: 0.1;
27
+ readonly tests: 0.1;
28
+ readonly install: 0.1;
29
+ readonly demo: 0.15;
30
+ readonly proof: 0.15;
31
+ readonly maturity: 0.1;
32
+ readonly docs: 0.1;
33
+ readonly regression: 0.15;
34
+ };
35
+ export type ReleaseVerdict = "block" | "pre-release" | "stable";
36
+ export interface ReleasePromotionInputs {
37
+ readonly ci: number;
38
+ readonly docs: number;
39
+ readonly proofMedian: number;
40
+ readonly regressionSeverity: number;
41
+ readonly freshInstallSmoke: number;
42
+ /** Backward-compat: old callers may still pass schema. */
43
+ readonly schema?: number;
44
+ /** Backward-compat: old callers may still pass providerMinimum. */
45
+ readonly providerMinimum?: number;
46
+ /** Backward-compat: old callers may still pass semver. */
47
+ readonly semver?: number;
48
+ /** Algorithm 8 — build dimension (0–1). */
49
+ readonly build?: number;
50
+ /** Algorithm 8 — type-check dimension (0–1). */
51
+ readonly types?: number;
52
+ /** Algorithm 8 — test dimension (0–1). */
53
+ readonly tests?: number;
54
+ /** Algorithm 8 — maturity dimension (0–1). Falls back to providerMinimum. */
55
+ readonly maturity?: number;
56
+ /** Algorithm 8 — minimal verified demo run gate. Hard block when false/undefined. */
57
+ readonly demoRun?: boolean;
58
+ }
59
+ export interface ReleasePromotionResult {
60
+ readonly score: number;
61
+ readonly verdict: ReleaseVerdict;
62
+ readonly blocked: boolean;
63
+ readonly reasons: readonly string[];
64
+ }
65
+ export interface ReleasePromotionGate {
66
+ evaluate(inputs: ReleasePromotionInputs): ReleasePromotionResult;
67
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Weakness Remediation contracts — shared constants and Phase 5 types.
3
+ *
4
+ * - Phase 2 Proof Bundle Trust, Phase 3 Provider Maturity Gate,
5
+ * and Phase 1 Public Surface Compression share thresholds here.
6
+ * - Phase 5 Release Promotion Gate types live here as well.
7
+ */
8
+ // ── Shared constants (Phase 1–3) ────────────────────────────────
9
+ /** Evidence trust threshold for standard claims. */
10
+ export const TAU_EVIDENCE = 0.75;
11
+ /** Evidence trust threshold for high-confidence claims. */
12
+ export const TAU_EVIDENCE_HIGH = 0.85;
13
+ /** Proof bundle trust threshold. */
14
+ export const TAU_PROOF = 0.85;
15
+ /** Stability/maturity threshold for fully-trusted surfaces. */
16
+ export const TAU_STABLE = 0.90;
17
+ /** Beta prior α₀ for Bayesian run-count scoring. */
18
+ export const BETA_PRIOR_ALPHA0 = 1;
19
+ /** Beta prior β₀ for Bayesian run-count scoring. */
20
+ export const BETA_PRIOR_BETA0 = 1;
21
+ /** Default public surface budget K (max items). */
22
+ export const SURFACE_BUDGET_K = 8;
23
+ // ── Phase 5 Release Promotion Gate ──────────────────────────────
24
+ /** Algorithm 8 release gate weights. */
25
+ export const RELEASE_GATE_WEIGHTS = {
26
+ ci: 0.15,
27
+ build: 0.10,
28
+ types: 0.10,
29
+ tests: 0.10,
30
+ install: 0.10,
31
+ demo: 0.15,
32
+ proof: 0.15,
33
+ maturity: 0.10,
34
+ docs: 0.10,
35
+ regression: 0.15,
36
+ };
@@ -4,9 +4,47 @@
4
4
  *
5
5
  * Calls https://api.moonshot.cn/v1/chat/completions directly.
6
6
  */
7
+ import { readFileSync, existsSync } from "node:fs";
8
+ import { resolve } from "node:path";
7
9
  import { capsuleToTask } from "./context-broker-converter.js";
8
10
  import { buildProviderToolPayload } from "./provider-tool-contracts.js";
9
11
  import { repairToolCalls } from "./tool-call-repair.js";
12
+ /**
13
+ * Detect "Image file: <path>" patterns in the prompt text (inserted by /paste
14
+ * or Ctrl+V clipboard image) and load the referenced images as base64 data URIs
15
+ * for multimodal API calls.
16
+ */
17
+ function extractInlineImageParts(prompt) {
18
+ const results = [];
19
+ // Match "Image file: .omk/screenshots/.../screenshot-xxx.png" lines
20
+ const pattern = /^Image file:\s+(.+\.(?:png|jpg|jpeg|webp|gif))\s*$/gim;
21
+ let match;
22
+ while ((match = pattern.exec(prompt)) !== null) {
23
+ const filePath = match[1].trim();
24
+ const absPath = resolve(filePath);
25
+ if (!existsSync(absPath))
26
+ continue;
27
+ try {
28
+ const buf = readFileSync(absPath);
29
+ if (buf.length === 0 || buf.length > 20 * 1024 * 1024)
30
+ continue;
31
+ // Detect mime type from magic bytes
32
+ let mimeType = "image/png";
33
+ if (buf[0] === 0xff && buf[1] === 0xd8)
34
+ mimeType = "image/jpeg";
35
+ else if (buf[0] === 0x52 && buf[1] === 0x49)
36
+ mimeType = "image/webp";
37
+ else if (buf[0] === 0x47 && buf[1] === 0x49)
38
+ mimeType = "image/gif";
39
+ const base64 = buf.toString("base64");
40
+ results.push({ dataUri: `data:${mimeType};base64,${base64}` });
41
+ }
42
+ catch {
43
+ // Skip unreadable files
44
+ }
45
+ }
46
+ return results;
47
+ }
10
48
  function mapToolCalls(apiToolCalls, context) {
11
49
  const repaired = repairToolCalls({
12
50
  declaredCalls: (apiToolCalls ?? []).map((tc) => ({
@@ -155,7 +193,27 @@ export class KimiApiRuntime {
155
193
  if (task.context.system) {
156
194
  messages.push({ role: "system", content: task.context.system });
157
195
  }
158
- messages.push({ role: "user", content: task.prompt });
196
+ // Build multimodal content when attachments are present or when
197
+ // the prompt contains "Image file: <path>" references (from /paste or
198
+ // Ctrl+V clipboard image). This makes clipboard-pasted images send as
199
+ // image_url content parts to OpenAI-compatible multimodal endpoints.
200
+ const attachments = task.attachments ?? [];
201
+ const inlineImages = extractInlineImageParts(task.prompt);
202
+ if (attachments.length > 0 || inlineImages.length > 0) {
203
+ const parts = [{ type: "text", text: task.prompt }];
204
+ for (const attachment of attachments) {
205
+ if (attachment.dataUri) {
206
+ parts.push({ type: "image_url", image_url: { url: attachment.dataUri } });
207
+ }
208
+ }
209
+ for (const image of inlineImages) {
210
+ parts.push({ type: "image_url", image_url: { url: image.dataUri } });
211
+ }
212
+ messages.push({ role: "user", content: parts });
213
+ }
214
+ else {
215
+ messages.push({ role: "user", content: task.prompt });
216
+ }
159
217
  const providerTools = task.capabilities.toolCalling
160
218
  ? buildProviderToolPayload(task.tools.available)
161
219
  : buildProviderToolPayload([]);
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Proof Bundle Trust Score — Phase 2 of OMK Weakness Remediation.
3
+ *
4
+ * Evaluates a curated proof bundle across 8 dimensions and produces
5
+ * a trust score T_b, a permission level, and a pass/fail verdict
6
+ * against τ_proof.
7
+ */
8
+ import type { ClaimPermissionLevel, EvidenceVerdict } from "./contracts/evidence.js";
9
+ /** The 8 scored dimensions of a proof bundle. */
10
+ export interface ProofBundleScores {
11
+ /** Schema conformance of evidence items [0, 1]. */
12
+ readonly schema: number;
13
+ /** Hash integrity / tamper evidence [0, 1]. */
14
+ readonly hashes: number;
15
+ /** Command trace coverage and correctness [0, 1]. */
16
+ readonly commands: number;
17
+ /** Stdout / stderr capture completeness [0, 1]. */
18
+ readonly stdout: number;
19
+ /** Decision record quality and count [0, 1]. */
20
+ readonly decisions: number;
21
+ /** Evidence item confidence and verdict strength [0, 1]. */
22
+ readonly evidence: number;
23
+ /** Acknowledged limitations documented [0, 1]. */
24
+ readonly limitations: number;
25
+ /** Replay reproducibility score [0, 1]. */
26
+ readonly replay: number;
27
+ }
28
+ /** Result of evaluating a proof bundle. */
29
+ export interface TrustScoreResult {
30
+ /** Computed trust score T_b ∈ [0, 1]. */
31
+ readonly score: number;
32
+ /** Permission level derived from score thresholds. */
33
+ readonly permissionLevel: ClaimPermissionLevel;
34
+ /** Whether score meets τ_proof. */
35
+ readonly passed: boolean;
36
+ /** Individual dimension contributions. */
37
+ readonly breakdown: ProofBundleScores;
38
+ }
39
+ /** Engine that evaluates proof bundle trust. */
40
+ export interface ProofBundleTrustEngine {
41
+ /**
42
+ * Evaluate a proof bundle from its 8 dimension scores.
43
+ *
44
+ * Formula:
45
+ * T_b = 0.15·schema + 0.15·hashes + 0.15·commands + 0.10·stdout
46
+ * + 0.15·decisions + 0.15·evidence + 0.05·limitations + 0.10·replay
47
+ */
48
+ evaluate(scores: ProofBundleScores): TrustScoreResult;
49
+ /** Derive dimension scores from a raw evidence verdict and coverage. */
50
+ deriveScores(verdict: EvidenceVerdict, coveragePercent: number, options?: DeriveScoresOptions): ProofBundleScores;
51
+ }
52
+ /** Options for automatic score derivation. */
53
+ export interface DeriveScoresOptions {
54
+ /** Override schema conformance (default inferred from verdict). */
55
+ readonly schema?: number;
56
+ /** Override hash integrity (default 1.0). */
57
+ readonly hashes?: number;
58
+ /** Override command trace score (default inferred from coverage). */
59
+ readonly commands?: number;
60
+ /** Override stdout completeness (default inferred from coverage). */
61
+ readonly stdout?: number;
62
+ /** Override decision record score (default inferred from verdict). */
63
+ readonly decisions?: number;
64
+ /** Override evidence strength (default inferred from verdict). */
65
+ readonly evidence?: number;
66
+ /** Override limitations documentation (default 0.5). */
67
+ readonly limitations?: number;
68
+ /** Override replay score (default inferred from verdict). */
69
+ readonly replay?: number;
70
+ }
71
+ /**
72
+ * Create a ProofBundleTrustEngine with default weights and thresholds.
73
+ */
74
+ export declare function createProofBundleTrustEngine(): ProofBundleTrustEngine;
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Proof Bundle Trust Score — Phase 2 of OMK Weakness Remediation.
3
+ *
4
+ * Evaluates a curated proof bundle across 8 dimensions and produces
5
+ * a trust score T_b, a permission level, and a pass/fail verdict
6
+ * against τ_proof.
7
+ */
8
+ import { TAU_PROOF } from "./contracts/weakness-remediation.js";
9
+ // ── Constants ───────────────────────────────────────────────────
10
+ const WEIGHT_SCHEMA = 0.15;
11
+ const WEIGHT_HASHES = 0.15;
12
+ const WEIGHT_COMMANDS = 0.15;
13
+ const WEIGHT_STDOUT = 0.10;
14
+ const WEIGHT_DECISIONS = 0.15;
15
+ const WEIGHT_EVIDENCE = 0.15;
16
+ const WEIGHT_LIMITATIONS = 0.05;
17
+ const WEIGHT_REPLAY = 0.10;
18
+ const STRONG_PUBLIC_THRESHOLD = 0.90;
19
+ const QUALIFIED_PUBLIC_THRESHOLD = 0.75;
20
+ const INTERNAL_CLAIM_THRESHOLD = 0.60;
21
+ // ── Helpers ─────────────────────────────────────────────────────
22
+ function clamp01(n) {
23
+ return Math.max(0, Math.min(1, n));
24
+ }
25
+ function permissionLevelFromScore(score) {
26
+ if (score >= STRONG_PUBLIC_THRESHOLD) {
27
+ return "strong-public-claim";
28
+ }
29
+ if (score >= QUALIFIED_PUBLIC_THRESHOLD) {
30
+ return "qualified-public-claim";
31
+ }
32
+ if (score >= INTERNAL_CLAIM_THRESHOLD) {
33
+ return "internal-claim-only";
34
+ }
35
+ return "no-claim";
36
+ }
37
+ function verdictToBaseScore(verdict) {
38
+ switch (verdict) {
39
+ case "pass":
40
+ return 1.0;
41
+ case "partial":
42
+ return 0.65;
43
+ case "pending":
44
+ return 0.35;
45
+ case "fail":
46
+ return 0.0;
47
+ default:
48
+ return 0.0;
49
+ }
50
+ }
51
+ // ── Engine Factory ──────────────────────────────────────────────
52
+ /**
53
+ * Create a ProofBundleTrustEngine with default weights and thresholds.
54
+ */
55
+ export function createProofBundleTrustEngine() {
56
+ return {
57
+ evaluate(scores) {
58
+ const clamped = {
59
+ schema: clamp01(scores.schema),
60
+ hashes: clamp01(scores.hashes),
61
+ commands: clamp01(scores.commands),
62
+ stdout: clamp01(scores.stdout),
63
+ decisions: clamp01(scores.decisions),
64
+ evidence: clamp01(scores.evidence),
65
+ limitations: clamp01(scores.limitations),
66
+ replay: clamp01(scores.replay),
67
+ };
68
+ const score = WEIGHT_SCHEMA * clamped.schema +
69
+ WEIGHT_HASHES * clamped.hashes +
70
+ WEIGHT_COMMANDS * clamped.commands +
71
+ WEIGHT_STDOUT * clamped.stdout +
72
+ WEIGHT_DECISIONS * clamped.decisions +
73
+ WEIGHT_EVIDENCE * clamped.evidence +
74
+ WEIGHT_LIMITATIONS * clamped.limitations +
75
+ WEIGHT_REPLAY * clamped.replay;
76
+ const finalScore = clamp01(score);
77
+ const permissionLevel = permissionLevelFromScore(finalScore);
78
+ return Object.freeze({
79
+ score: finalScore,
80
+ permissionLevel,
81
+ passed: finalScore >= TAU_PROOF,
82
+ breakdown: clamped,
83
+ });
84
+ },
85
+ deriveScores(verdict, coveragePercent, options = {}) {
86
+ const base = verdictToBaseScore(verdict);
87
+ const cov = clamp01(coveragePercent / 100);
88
+ return Object.freeze({
89
+ schema: clamp01(options.schema ?? base),
90
+ hashes: clamp01(options.hashes ?? 1.0),
91
+ commands: clamp01(options.commands ?? cov),
92
+ stdout: clamp01(options.stdout ?? cov),
93
+ decisions: clamp01(options.decisions ?? base),
94
+ evidence: clamp01(options.evidence ?? base),
95
+ limitations: clamp01(options.limitations ?? 0.5),
96
+ replay: clamp01(options.replay ?? base),
97
+ });
98
+ },
99
+ };
100
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Provider Maturity Gate — Phase 3 of OMK Weakness Remediation.
3
+ *
4
+ * Evaluates a provider/runtime across 8 adapter test dimensions and
5
+ * produces a maturity score M_p, an authority class, and a pass/fail
6
+ * verdict.
7
+ */
8
+ import type { AdapterTestKind, AdapterTestResult, ProviderAuthorityClass } from "./contracts/evidence.js";
9
+ /** Maturity evaluation result for a single provider. */
10
+ export interface MaturityResult {
11
+ /** Computed maturity score M_p ∈ [0, 1]. */
12
+ readonly score: number;
13
+ /** Authority class derived from score and sub-score constraints. */
14
+ readonly authorityClass: ProviderAuthorityClass;
15
+ /** Whether the provider meets minimum viability. */
16
+ readonly passed: boolean;
17
+ /** Sub-scores keyed by adapter test kind. */
18
+ readonly subScores: Readonly<Record<AdapterTestKind, number>>;
19
+ }
20
+ /** Engine that evaluates provider maturity. */
21
+ export interface ProviderMaturityGate {
22
+ /**
23
+ * Evaluate provider maturity from adapter test results.
24
+ *
25
+ * Formula:
26
+ * M_p = 0.10·s_auth + 0.10·s_read + 0.15·s_write + 0.10·s_shell
27
+ * + 0.15·s_mcp + 0.15·s_merge + 0.15·s_evidence + 0.10·s_fallback
28
+ */
29
+ evaluate(results: readonly AdapterTestResult[]): MaturityResult;
30
+ /** Look up a single sub-score by test kind (defaults to 0). */
31
+ getSubScore(results: readonly AdapterTestResult[], kind: AdapterTestKind): number;
32
+ }
33
+ /**
34
+ * Create a ProviderMaturityGate with default weights and thresholds.
35
+ */
36
+ export interface ProviderMaturityTable {
37
+ lookup(providerId: string): MaturityResult | undefined;
38
+ register(providerId: string, result: MaturityResult): void;
39
+ }
40
+ export declare function createProviderMaturityTable(): ProviderMaturityTable;
41
+ export declare function createProviderMaturityGate(): ProviderMaturityGate;
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Provider Maturity Gate — Phase 3 of OMK Weakness Remediation.
3
+ *
4
+ * Evaluates a provider/runtime across 8 adapter test dimensions and
5
+ * produces a maturity score M_p, an authority class, and a pass/fail
6
+ * verdict.
7
+ */
8
+ // ── Constants ───────────────────────────────────────────────────
9
+ const WEIGHT_AUTH = 0.10;
10
+ const WEIGHT_READ = 0.10;
11
+ const WEIGHT_WRITE = 0.15;
12
+ const WEIGHT_SHELL = 0.10;
13
+ const WEIGHT_MCP = 0.15;
14
+ const WEIGHT_MERGE = 0.15;
15
+ const WEIGHT_EVIDENCE = 0.15;
16
+ const WEIGHT_FALLBACK = 0.10;
17
+ const MERGE_AUTHORITY_THRESHOLD = 0.90;
18
+ const MERGE_SUBSCORE_THRESHOLD = 0.90;
19
+ const EVIDENCE_SUBSCORE_THRESHOLD_FOR_MERGE = 0.85;
20
+ const WRITE_AUTHORITY_THRESHOLD = 0.80;
21
+ const WRITE_SUBSCORE_THRESHOLD = 0.85;
22
+ const REVIEW_AUTHORITY_THRESHOLD = 0.70;
23
+ const READ_SUBSCORE_THRESHOLD = 0.90;
24
+ const READ_ONLY_ADVISORY_THRESHOLD = 0.55;
25
+ // ── Helpers ─────────────────────────────────────────────────────
26
+ function clamp01(n) {
27
+ return Math.max(0, Math.min(1, n));
28
+ }
29
+ function computeAuthorityClass(score, subScores) {
30
+ if (score >= MERGE_AUTHORITY_THRESHOLD &&
31
+ subScores.merge >= MERGE_SUBSCORE_THRESHOLD &&
32
+ subScores.evidence >= EVIDENCE_SUBSCORE_THRESHOLD_FOR_MERGE) {
33
+ return "merge-authority";
34
+ }
35
+ if (score >= WRITE_AUTHORITY_THRESHOLD &&
36
+ subScores.write >= WRITE_SUBSCORE_THRESHOLD) {
37
+ return "write-authority";
38
+ }
39
+ if (score >= REVIEW_AUTHORITY_THRESHOLD &&
40
+ subScores.read >= READ_SUBSCORE_THRESHOLD) {
41
+ return "review-authority";
42
+ }
43
+ if (score >= READ_ONLY_ADVISORY_THRESHOLD) {
44
+ return "read-only-advisory";
45
+ }
46
+ return "disabled";
47
+ }
48
+ function buildSubScoreMap(results) {
49
+ const map = {
50
+ auth: 0,
51
+ read: 0,
52
+ write: 0,
53
+ shell: 0,
54
+ mcp: 0,
55
+ merge: 0,
56
+ evidence: 0,
57
+ fallback: 0,
58
+ };
59
+ for (const r of results) {
60
+ map[r.kind] = clamp01(r.score);
61
+ }
62
+ return map;
63
+ }
64
+ export function createProviderMaturityTable() {
65
+ const table = new Map();
66
+ return {
67
+ lookup(providerId) {
68
+ return table.get(providerId);
69
+ },
70
+ register(providerId, result) {
71
+ table.set(providerId, result);
72
+ },
73
+ };
74
+ }
75
+ export function createProviderMaturityGate() {
76
+ return {
77
+ evaluate(results) {
78
+ const subScores = Object.freeze(buildSubScoreMap(results));
79
+ const score = WEIGHT_AUTH * subScores.auth +
80
+ WEIGHT_READ * subScores.read +
81
+ WEIGHT_WRITE * subScores.write +
82
+ WEIGHT_SHELL * subScores.shell +
83
+ WEIGHT_MCP * subScores.mcp +
84
+ WEIGHT_MERGE * subScores.merge +
85
+ WEIGHT_EVIDENCE * subScores.evidence +
86
+ WEIGHT_FALLBACK * subScores.fallback;
87
+ const finalScore = clamp01(score);
88
+ const authorityClass = computeAuthorityClass(finalScore, subScores);
89
+ return Object.freeze({
90
+ score: finalScore,
91
+ authorityClass,
92
+ passed: authorityClass !== "disabled",
93
+ subScores,
94
+ });
95
+ },
96
+ getSubScore(results, kind) {
97
+ const found = results.find((r) => r.kind === kind);
98
+ return found ? clamp01(found.score) : 0;
99
+ },
100
+ };
101
+ }