@herjarsa/omo-meta-governor 0.1.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/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # @herjarsa/omo-meta-governor
2
+
3
+ Self-judging agent orchestration layer for OpenCode. Observes tool executions,
4
+ reads session state, scores progress, and dispatches decisions.
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ npm install @herjarsa/omo-meta-governor
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ Add as a plugin in your OpenCode config:
15
+
16
+ ```jsonc
17
+ {
18
+ "plugins": ["@herjarsa/omo-meta-governor"]
19
+ }
20
+ ```
21
+
22
+ Configure:
23
+
24
+ ```jsonc
25
+ {
26
+ "meta_governor": {
27
+ "enabled": true
28
+ }
29
+ }
30
+ ```
31
+
32
+ ## How it works
33
+
34
+ After every tool call, MetaGovernor:
35
+ - Reads session signals (deviations, iteration budget, progress)
36
+ - Scores the session against weighted evidence
37
+ - Dispatches: `continue | warn | escalate | stop`
38
+
39
+ See [docs/guide/meta-governor.md](docs/guide/meta-governor.md) for full docs.
40
+
41
+ ## License
42
+
43
+ MIT
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Closed-loop learning for MetaGovernor.
3
+ *
4
+ * PR 3 of 8. After every repair/action cycle, observeAndLearn() decides
5
+ * whether to persist a lesson or decision record to agentmemory. Future
6
+ * sessions retrieve these via aggregateRead() (PR 2) and factor them into
7
+ * scoring (PR 5).
8
+ *
9
+ * Design:
10
+ * - Pure function with DI backend (no side effects without backend).
11
+ * - config.enabled=false → returns no-op with reason.
12
+ * - Severity threshold: minSeverityToLearn filters what gets saved.
13
+ * - Session cap: maxLessonsPerSession prevents flooding.
14
+ * - Lessons go to agentmemory_memory_save (type: "pattern").
15
+ * - Decisions go to agentmemory_memory_save (type: "fact").
16
+ * - No file I/O, no MCP calls — just decision logic + DI write.
17
+ */
18
+ import type { AgentmemoryWriteBackend, ClosedLoopConfig, LearnFromOutcomeInput, LearnFromOutcomeOutput } from "./types";
19
+ /** Severity ordering for threshold comparison. */
20
+ declare const SEVERITY_ORDER: Record<string, number>;
21
+ /**
22
+ * Core learning function. Decides whether to save a lesson and/or decision
23
+ * to agentmemory based on the outcome of a repair/action cycle.
24
+ *
25
+ * Returns LearnFromOutcomeOutput describing what was saved (or why nothing was saved).
26
+ */
27
+ export declare function observeAndLearn(input: LearnFromOutcomeInput, backend: AgentmemoryWriteBackend): Promise<LearnFromOutcomeOutput>;
28
+ /**
29
+ * Helper: create a default ClosedLoopConfig.
30
+ */
31
+ export declare function defaultClosedLoopConfig(): ClosedLoopConfig;
32
+ export { SEVERITY_ORDER };
@@ -0,0 +1,50 @@
1
+ import type { OrchestratorConfig } from "./types";
2
+ /**
3
+ * MetaGovernor config schema exposed to users.
4
+ * This is a Zod-free config interface since Zod parsing is optional
5
+ * in the standalone plugin — the user provides JSON, we coerce with defaults.
6
+ */
7
+ export interface MetaGovernorPluginConfig {
8
+ /** Master feature flag — must be true to run the orchestrator. */
9
+ enabled?: boolean;
10
+ /** Decision handler (PR 6) */
11
+ decision?: {
12
+ maxHistoryPerSession?: number;
13
+ forceContinueAfterStops?: number;
14
+ };
15
+ /** Memory aggregator (PR 2) */
16
+ memory?: {
17
+ agentmemoryTimeoutMs?: number;
18
+ magicContextTimeoutMs?: number;
19
+ boulderStateTimeoutMs?: number;
20
+ query?: string;
21
+ };
22
+ /** Token predictor (PR 4) */
23
+ tokenPredictor?: {
24
+ compactBurnRateThreshold?: number;
25
+ compactUsageThreshold?: number;
26
+ switchModelUsageThreshold?: number;
27
+ delegateConsecutiveHighBurn?: number;
28
+ };
29
+ /** Scoring engine (PR 5) */
30
+ scoring?: {
31
+ continueThreshold?: number;
32
+ warnThreshold?: number;
33
+ escalateThreshold?: number;
34
+ stopThreshold?: number;
35
+ };
36
+ /** Closed-loop learning (PR 3) */
37
+ closedLoop?: {
38
+ saveDecisions?: boolean;
39
+ saveLessons?: boolean;
40
+ };
41
+ }
42
+ /**
43
+ * Project the full MetaGovernorPluginConfig into OrchestratorConfig.
44
+ * Missing sub-configs fall back to module defaults.
45
+ */
46
+ export declare function loadOrchestratorConfig(pluginConfig: Partial<MetaGovernorPluginConfig> | undefined): OrchestratorConfig;
47
+ /**
48
+ * Check whether the MetaGovernor is enabled. Returns false if config is undefined.
49
+ */
50
+ export declare function isMetaGovernorEnabled(config: MetaGovernorPluginConfig | undefined): boolean;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * MetaGovernor Decision Handler — PR 6 of 8.
3
+ *
4
+ * Takes a ScoringResult from the scoring engine and dispatches to the
5
+ * appropriate action: continue, warn, escalate, or stop. This is the
6
+ * "executor" that translates scoring decisions into concrete outcomes.
7
+ *
8
+ * Architecture invariants:
9
+ * - Pure dispatch: no I/O, no MCP calls, no side effects
10
+ * - DI pattern: backends injected via DecisionHandlerConfig
11
+ * - Audit trail: every decision + outcome recorded in DecisionHistory
12
+ * - Configurable: all thresholds and behaviors overridable
13
+ */
14
+ import type { DecisionHandlerConfig, DecisionHandlerInput, DecisionHandlerOutput } from "./types";
15
+ export declare const defaultDecisionHandlerConfig: () => DecisionHandlerConfig;
16
+ /**
17
+ * Core decision handler. Takes a ScoringResult and dispatches to the
18
+ * appropriate action. Pure function — no side effects.
19
+ *
20
+ * @param input - ScoringResult + session context
21
+ * @param config - Handler configuration
22
+ * @returns DecisionHandlerOutput with action taken + message + history entry
23
+ */
24
+ export declare function handleDecision(input: DecisionHandlerInput, config?: Partial<DecisionHandlerConfig>): DecisionHandlerOutput;
25
+ /**
26
+ * Trim history to max size. Returns trimmed array + entries dropped count.
27
+ */
28
+ export declare function trimHistory(history: readonly DecisionHandlerOutput["historyEntry"][], maxSize: number): {
29
+ trimmed: DecisionHandlerOutput["historyEntry"][];
30
+ dropped: number;
31
+ };
32
+ /**
33
+ * Count consecutive stops in history (most recent first).
34
+ */
35
+ export declare function countConsecutiveStops(history: readonly DecisionHandlerOutput["historyEntry"][]): number;
@@ -0,0 +1,32 @@
1
+ import type { PluginModule } from "@opencode-ai/plugin";
2
+ /**
3
+ * @sisyphuslabs/omo-meta-governor — Self-judging agent orchestration layer.
4
+ *
5
+ * Default export is an OpenCode PluginModule that registers a
6
+ * `tool.execute.after` hook. The MetaGovernor reads session signals,
7
+ * scores them against weighted evidence, and dispatches decisions.
8
+ *
9
+ * Install:
10
+ * npm install @sisyphuslabs/omo-meta-governor
11
+ *
12
+ * Configure:
13
+ * ```jsonc
14
+ * {
15
+ * "meta_governor": {
16
+ * "enabled": true
17
+ * }
18
+ * }
19
+ * ```
20
+ */
21
+ declare const pluginModule: PluginModule;
22
+ export default pluginModule;
23
+ export { createMetaGovernorPlugin, type MetaGovernorPluginDeps, } from "./plugin";
24
+ export { runMetaGovernor, buildDecisionContext, defaultOrchestratorConfig, } from "./orchestrator";
25
+ export { loadOrchestratorConfig, isMetaGovernorEnabled, type MetaGovernorPluginConfig, } from "./config";
26
+ export { score, defaultScoringConfig } from "./scoring-engine";
27
+ export { predict, defaultTokenPredictorConfig, calculateBurnRate } from "./token-predictor";
28
+ export { handleDecision, defaultDecisionHandlerConfig, trimHistory, countConsecutiveStops } from "./decision-handler";
29
+ export { observeAndLearn, defaultClosedLoopConfig } from "./closed-loop-learning";
30
+ export { aggregateRead } from "./memory-aggregator";
31
+ export { recordRecovery, type RecoveryOutcome } from "./post-repair-recorder";
32
+ export type { Decision, DecisionContext, DecisionHandlerConfig, DecisionHandlerInput, DecisionHandlerOutput, Deviation, Evidence, EvidenceContribution, LearnFromOutcomeInput, LearnFromOutcomeOutput, MemoryRead, MemoryBackends, AgentmemoryWriteBackend, MetaGovernorInput, MetaGovernorOutput, OrchestratorConfig, ScoringConfig, ScoringResult, SlotMemory, TokenPredictorConfig, TokenPredictorInput, TokenPredictorOutput, ClosedLoopConfig, } from "./types";