@herjarsa/omo-meta-governor 0.9.8 → 0.10.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 +26 -5
- package/dist/closed-loop-learning.d.ts +32 -0
- package/dist/config-file.d.ts +71 -0
- package/dist/config.d.ts +83 -0
- package/dist/decision-handler.d.ts +35 -0
- package/dist/decision-store.d.ts +36 -0
- package/dist/file-logger.d.ts +1 -0
- package/dist/generate-schema.d.ts +45 -0
- package/dist/graph-sync.d.ts +90 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +25 -0
- package/dist/memory-aggregator.d.ts +124 -0
- package/dist/orchestrator.d.ts +33 -0
- package/dist/plugin.d.ts +14 -0
- package/dist/post-repair-recorder.d.ts +47 -0
- package/dist/protocol-enforcer.d.ts +33 -0
- package/dist/scoring-engine.d.ts +31 -0
- package/dist/token-predictor.d.ts +29 -0
- package/dist/types.d.ts +565 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,11 +38,28 @@ After every tool call, MetaGovernor:
|
|
|
38
38
|
|
|
39
39
|
See [docs/guide/meta-governor.md](docs/guide/meta-governor.md) for full docs.
|
|
40
40
|
|
|
41
|
-
## Intervention
|
|
41
|
+
## Intervention
|
|
42
42
|
|
|
43
43
|
MetaGovernor can inject its decisions into the active agent's context
|
|
44
44
|
so the agent is aware of governance warnings, escalations, or stop signals.
|
|
45
45
|
|
|
46
|
+
### v0.10.0 — Loop prevention
|
|
47
|
+
|
|
48
|
+
The plugin now self-disables intervention when the agent's task is verifiably
|
|
49
|
+
complete. This fixes the v0.3.0–v0.9.x bug where the plugin kept injecting
|
|
50
|
+
synthetic user messages indefinitely after the agent had finished.
|
|
51
|
+
|
|
52
|
+
Three mechanisms enforce the cap:
|
|
53
|
+
|
|
54
|
+
1. **`<promise>DONE</promise>` + Oracle verified** — the agent emits this signal
|
|
55
|
+
to mark the task complete. If Oracle has verified the work (the agent
|
|
56
|
+
invoked `task(subagent_type="oracle")` and got a PASS verdict), the plugin
|
|
57
|
+
disables intervention for that session.
|
|
58
|
+
2. **`maxInterventionsPerSession`** — hard cap (default `3`) on the number of
|
|
59
|
+
times a session can receive an injection. Once reached, no more injections.
|
|
60
|
+
3. **Cross-session scoping** — decisions are now scoped to the current
|
|
61
|
+
sessionID. The plugin no longer pulls decisions from unrelated sessions.
|
|
62
|
+
|
|
46
63
|
### Modes
|
|
47
64
|
|
|
48
65
|
| Mode | Mechanism | Effect |
|
|
@@ -61,20 +78,24 @@ so the agent is aware of governance warnings, escalations, or stop signals.
|
|
|
61
78
|
"mode": "message",
|
|
62
79
|
"includeDecisionHistory": true,
|
|
63
80
|
"maxHistoryMessages": 5,
|
|
64
|
-
"minActionForMessage": "
|
|
81
|
+
"minActionForMessage": "stop",
|
|
82
|
+
"maxInterventionsPerSession": 3,
|
|
83
|
+
"respectDoneSignal": true
|
|
65
84
|
}
|
|
66
85
|
}
|
|
67
86
|
}
|
|
68
|
-
|
|
69
87
|
```
|
|
70
88
|
|
|
89
|
+
### Fields
|
|
90
|
+
|
|
71
91
|
| Field | Default | Description |
|
|
72
92
|
|-------|---------|-------------|
|
|
73
93
|
| `mode` | `"silent"` | How to inject: `"silent"`, `"message"`, or `"system"` |
|
|
74
94
|
| `includeDecisionHistory` | `true` | Whether to include recent decision history |
|
|
75
95
|
| `maxHistoryMessages` | `5` | Max history entries when includeDecisionHistory is true |
|
|
76
|
-
| `minActionForMessage` | `"
|
|
77
|
-
|
|
96
|
+
| `minActionForMessage` | `"stop"` (v0.10.0) | Minimum action: `"warn"`, `"escalate"`, or `"stop"`. Default is now `"stop"` so warnings do not auto-trigger injection. Opt UP to `"warn"` explicitly. |
|
|
97
|
+
| `maxInterventionsPerSession` | `3` (v0.10.0) | Hard cap on injections per session. Once reached, no more injections until session restart. |
|
|
98
|
+
| `respectDoneSignal` | `true` (v0.10.0) | When true, the plugin stops injecting the moment the agent emits `<promise>DONE</promise>` AND Oracle has verified the work. |
|
|
78
99
|
### How it works
|
|
79
100
|
|
|
80
101
|
1. After every tool call, MetaGovernor runs the orchestrator pipeline.
|
|
@@ -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,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSONC config file loader for omo-meta-governor.
|
|
3
|
+
*
|
|
4
|
+
* Loads `omo-meta-governor.jsonc` from three layers (closer wins):
|
|
5
|
+
* 1. CLI inline options (opts object) — highest priority
|
|
6
|
+
* 2. Project config: `.opencode/omo-meta-governor.jsonc`
|
|
7
|
+
* 3. User config: `~/.config/opencode/omo-meta-governor.jsonc`
|
|
8
|
+
* 4. Defaults — lowest priority
|
|
9
|
+
*
|
|
10
|
+
* JSONC support: comments (//, /* * /) and trailing commas are stripped
|
|
11
|
+
* before parsing. The raw JSON object is then projected into
|
|
12
|
+
* `MetaGovernorPluginConfig` via `loadOrchestratorConfig()`.
|
|
13
|
+
*/
|
|
14
|
+
import type { MetaGovernorPluginConfig } from "./config";
|
|
15
|
+
/**
|
|
16
|
+
* Strip JSONC comments (single-line // style and multi-line bracket style)
|
|
17
|
+
* and trailing commas from a JSONC string so it can be parsed by JSON.parse.
|
|
18
|
+
*
|
|
19
|
+
* Handles:
|
|
20
|
+
* - // single-line comments
|
|
21
|
+
* - /asterisk ... asterisk/ multi-line comments
|
|
22
|
+
* - Trailing commas before ] or }
|
|
23
|
+
* - Strings containing comments (preserved)
|
|
24
|
+
*/
|
|
25
|
+
export declare function stripJsoncComments(jsonc: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Parse a JSONC string into a JavaScript object.
|
|
28
|
+
* Returns undefined on parse failure.
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseJsonc<T = Record<string, unknown>>(jsonc: string): T | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Get the user-level config file path.
|
|
33
|
+
*/
|
|
34
|
+
export declare function getUserConfigPath(): string;
|
|
35
|
+
/**
|
|
36
|
+
* Get the project-level config file path for a given project directory.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getProjectConfigPath(projectDir?: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Read and parse a single JSONC config file.
|
|
41
|
+
* Returns undefined if the file does not exist or is unparseable.
|
|
42
|
+
*/
|
|
43
|
+
export declare function loadJsoncFile<T = Record<string, unknown>>(filePath: string): Promise<T | undefined>;
|
|
44
|
+
/**
|
|
45
|
+
* Deep-merge two config objects. Arrays are replaced (not concatenated).
|
|
46
|
+
* The `source` values win when both exist.
|
|
47
|
+
* Mutually recursive with mergeArrays=false for sub-objects.
|
|
48
|
+
*/
|
|
49
|
+
export declare function deepMerge<T extends Record<string, unknown>>(target: T, source: Partial<T>): T;
|
|
50
|
+
export interface ConfigFileSources {
|
|
51
|
+
/** CLI inline options (highest priority) */
|
|
52
|
+
cliOptions?: Partial<MetaGovernorPluginConfig>;
|
|
53
|
+
/** Project directory for project-level config lookup */
|
|
54
|
+
projectDir?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface ConfigFileResult {
|
|
57
|
+
/** The merged MetaGovernorPluginConfig */
|
|
58
|
+
config: Partial<MetaGovernorPluginConfig>;
|
|
59
|
+
/** Which source files were loaded */
|
|
60
|
+
sources: string[];
|
|
61
|
+
/** Which source was the effective highest-priority non-empty source */
|
|
62
|
+
effectiveSource: "cli" | "project" | "user" | "defaults";
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Load the MetaGovernor config from all available sources with priority:
|
|
66
|
+
* CLI inline > project `.opencode/omo-meta-governor.jsonc` >
|
|
67
|
+
* user `~/.config/opencode/omo-meta-governor.jsonc` > defaults
|
|
68
|
+
*
|
|
69
|
+
* Higher-priority sources override lower-priority ones.
|
|
70
|
+
*/
|
|
71
|
+
export declare function loadMetaGovernorConfig(sources?: ConfigFileSources): Promise<ConfigFileResult>;
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { ModelOverrideConfig, OrchestratorConfig } from "./types";
|
|
2
|
+
import type { ConfigFileSources } from "./config-file";
|
|
3
|
+
/**
|
|
4
|
+
* MetaGovernor config schema exposed to users.
|
|
5
|
+
* This is a Zod-free config interface since Zod parsing is optional
|
|
6
|
+
* in the standalone plugin — the user provides JSON, we coerce with defaults.
|
|
7
|
+
*/
|
|
8
|
+
export interface MetaGovernorPluginConfig {
|
|
9
|
+
/** Master feature flag — must be true to run the orchestrator. */
|
|
10
|
+
enabled?: boolean;
|
|
11
|
+
/** Decision handler (PR 6) */
|
|
12
|
+
decision?: {
|
|
13
|
+
maxHistoryPerSession?: number;
|
|
14
|
+
forceContinueAfterStops?: number;
|
|
15
|
+
};
|
|
16
|
+
/** Memory aggregator (PR 2) */
|
|
17
|
+
memory?: {
|
|
18
|
+
agentmemoryTimeoutMs?: number;
|
|
19
|
+
magicContextTimeoutMs?: number;
|
|
20
|
+
boulderStateTimeoutMs?: number;
|
|
21
|
+
query?: string;
|
|
22
|
+
};
|
|
23
|
+
/** Token predictor (PR 4) */
|
|
24
|
+
tokenPredictor?: {
|
|
25
|
+
compactBurnRateThreshold?: number;
|
|
26
|
+
compactUsageThreshold?: number;
|
|
27
|
+
switchModelUsageThreshold?: number;
|
|
28
|
+
delegateConsecutiveHighBurn?: number;
|
|
29
|
+
};
|
|
30
|
+
/** Scoring engine (PR 5) */
|
|
31
|
+
scoring?: {
|
|
32
|
+
continueThreshold?: number;
|
|
33
|
+
warnThreshold?: number;
|
|
34
|
+
escalateThreshold?: number;
|
|
35
|
+
stopThreshold?: number;
|
|
36
|
+
};
|
|
37
|
+
/** Closed-loop learning (PR 3) */
|
|
38
|
+
closedLoop?: {
|
|
39
|
+
saveDecisions?: boolean;
|
|
40
|
+
saveLessons?: boolean;
|
|
41
|
+
};
|
|
42
|
+
/** Model override for MetaGovernor internal LLM usage. */
|
|
43
|
+
modelOverride?: ModelOverrideConfig;
|
|
44
|
+
/** Intervention config for visible decision injection. */
|
|
45
|
+
intervention?: {
|
|
46
|
+
mode?: "silent" | "message" | "system";
|
|
47
|
+
includeDecisionHistory?: boolean;
|
|
48
|
+
maxHistoryMessages?: number;
|
|
49
|
+
minActionForMessage?: "warn" | "escalate" | "stop";
|
|
50
|
+
/** v0.10.0: rate-limit interventions to break instruction loops. */
|
|
51
|
+
maxInterventionsPerSession?: number;
|
|
52
|
+
/** v0.10.0: stop injecting after <promise>DONE</promise> + Oracle verified. */
|
|
53
|
+
respectDoneSignal?: boolean;
|
|
54
|
+
};
|
|
55
|
+
/** Sisyphus protocol enforcement config. */
|
|
56
|
+
protocolEnforcement?: {
|
|
57
|
+
enabled?: boolean;
|
|
58
|
+
path?: string;
|
|
59
|
+
injectIntoSystem?: boolean;
|
|
60
|
+
auditToolCalls?: boolean;
|
|
61
|
+
};
|
|
62
|
+
/** Graph sync config for auto-initializing codegraph/graphify. */
|
|
63
|
+
graphSync?: {
|
|
64
|
+
enabled?: boolean;
|
|
65
|
+
watch?: boolean;
|
|
66
|
+
autoInstall?: boolean;
|
|
67
|
+
installTimeoutMs?: number;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Project the full MetaGovernorPluginConfig into OrchestratorConfig.
|
|
72
|
+
* Missing sub-configs fall back to module defaults.
|
|
73
|
+
*/
|
|
74
|
+
export declare function loadOrchestratorConfig(pluginConfig: Partial<MetaGovernorPluginConfig> | undefined): OrchestratorConfig;
|
|
75
|
+
/**
|
|
76
|
+
* Check whether the MetaGovernor is enabled. Returns false if config is undefined.
|
|
77
|
+
*/
|
|
78
|
+
export declare function isMetaGovernorEnabled(config: MetaGovernorPluginConfig | undefined): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Load orchestrator config from all available sources: config file (JSONC)
|
|
81
|
+
* with priority: CLI inline > project config > user config > defaults.
|
|
82
|
+
*/
|
|
83
|
+
export declare function loadOrchestratorConfigFromSources(sources?: ConfigFileSources): Promise<OrchestratorConfig>;
|
|
@@ -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,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MetaGovernor decision store — in-memory Map for intervention feature.
|
|
3
|
+
*
|
|
4
|
+
* Stores decisions produced by tool.execute.after so they can be
|
|
5
|
+
* consumed by experimental.chat.messages.transform and
|
|
6
|
+
* experimental.chat.system.transform hooks.
|
|
7
|
+
*
|
|
8
|
+
* The store is keyed by sessionID. For hooks that receive a sessionID
|
|
9
|
+
* (system.transform), use takeDecision(sessionID). For hooks that
|
|
10
|
+
* receive no sessionID (messages.transform), use takeAnyDecision().
|
|
11
|
+
*/
|
|
12
|
+
import type { DecisionHandlerOutput } from "./types";
|
|
13
|
+
/**
|
|
14
|
+
* Store a decision for a session.
|
|
15
|
+
* Overwrites any previous pending decision for the same session.
|
|
16
|
+
*/
|
|
17
|
+
export declare function storeDecision(sessionID: string, decision: DecisionHandlerOutput): void;
|
|
18
|
+
/**
|
|
19
|
+
* Take (retrieve and remove) the pending decision for a session.
|
|
20
|
+
* Returns undefined if no decision is pending.
|
|
21
|
+
*/
|
|
22
|
+
export declare function takeDecision(sessionID: string): DecisionHandlerOutput | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Check whether a session has a pending decision without consuming it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function hasDecision(sessionID: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Take any pending decision across all sessions.
|
|
29
|
+
* Useful for hooks that do not receive a sessionID.
|
|
30
|
+
* Returns the first pending decision found, or undefined if none.
|
|
31
|
+
*/
|
|
32
|
+
export declare function takeAnyDecision(): DecisionHandlerOutput | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Clear all stored decisions. Useful in tests or when a session ends.
|
|
35
|
+
*/
|
|
36
|
+
export declare function clearAll(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function logToFile(level: "info" | "warn" | "error", message: string, data?: unknown): void;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema generator for omo-meta-governor.jsonc.
|
|
3
|
+
*
|
|
4
|
+
* Generates a JSON Schema (draft-07) from the MetaGovernorPluginConfig
|
|
5
|
+
* interface definition. The schema is used for IDE autocompletion and
|
|
6
|
+
* validation when editing the .jsonc config file.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import { generateSchema } from "./generate-schema"
|
|
10
|
+
* const schema = generateSchema()
|
|
11
|
+
* await Bun.write("assets/omo-meta-governor.schema.json", JSON.stringify(schema, null, 2))
|
|
12
|
+
*/
|
|
13
|
+
export interface JsonSchema {
|
|
14
|
+
$schema: string;
|
|
15
|
+
$id: string;
|
|
16
|
+
title: string;
|
|
17
|
+
description: string;
|
|
18
|
+
type: "object";
|
|
19
|
+
properties: Record<string, JsonSchemaProperty>;
|
|
20
|
+
additionalProperties: boolean;
|
|
21
|
+
definitions?: Record<string, JsonSchemaProperty>;
|
|
22
|
+
}
|
|
23
|
+
export interface JsonSchemaProperty {
|
|
24
|
+
type?: string | string[];
|
|
25
|
+
description?: string;
|
|
26
|
+
default?: unknown;
|
|
27
|
+
properties?: Record<string, JsonSchemaProperty>;
|
|
28
|
+
items?: JsonSchemaProperty;
|
|
29
|
+
additionalProperties?: boolean;
|
|
30
|
+
required?: string[];
|
|
31
|
+
enum?: string[];
|
|
32
|
+
oneOf?: JsonSchemaProperty[];
|
|
33
|
+
anyOf?: JsonSchemaProperty[];
|
|
34
|
+
$ref?: string;
|
|
35
|
+
minimum?: number;
|
|
36
|
+
maximum?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Generate the full JSON Schema for the omo-meta-governor.jsonc config file.
|
|
40
|
+
*/
|
|
41
|
+
export declare function generateSchema(): JsonSchema;
|
|
42
|
+
/**
|
|
43
|
+
* Write the schema to a file.
|
|
44
|
+
*/
|
|
45
|
+
export declare function writeSchemaFile(outputPath: string): Promise<void>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* graphSync — Auto-initialize codegraph and graphify for a project.
|
|
3
|
+
*
|
|
4
|
+
* On first session in a project, checks whether:
|
|
5
|
+
* - `npx codegraph` is available on PATH (or node_modules)
|
|
6
|
+
* - `graphify` / `graphifyy` is available as a Python package
|
|
7
|
+
*
|
|
8
|
+
* If a tool is available but the project has no index yet, runs the
|
|
9
|
+
* initialization automatically. With `--watch` mode, spawns a background
|
|
10
|
+
* process that re-indexes on file changes.
|
|
11
|
+
*
|
|
12
|
+
* Architecture invariants:
|
|
13
|
+
* - Never blocks the session — init runs async, best-effort
|
|
14
|
+
* - Never throws — all errors are silently caught and logged
|
|
15
|
+
* - Tracks session init once per project via an in-memory Set
|
|
16
|
+
*/
|
|
17
|
+
export interface GraphSyncConfig {
|
|
18
|
+
/** Enable auto-initialization. Default: true */
|
|
19
|
+
enabled: boolean;
|
|
20
|
+
/** Enable watch mode (re-index on file changes). Default: false */
|
|
21
|
+
watch: boolean;
|
|
22
|
+
/** Project directory to initialize in. Default: cwd */
|
|
23
|
+
projectDir?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Auto-install missing backends. Default: true.
|
|
26
|
+
* - codegraph: installed via `npm i -D @colbymchenry/codegraph` in the project
|
|
27
|
+
* - graphify: installed via `pip install graphifyy --break-system-packages` (or `uv tool install graphifyy`)
|
|
28
|
+
*/
|
|
29
|
+
autoInstall: boolean;
|
|
30
|
+
/** Max ms to wait for each install. Default: 60_000 */
|
|
31
|
+
installTimeoutMs: number;
|
|
32
|
+
}
|
|
33
|
+
export type InstallCode = "codegraph-installed" | "codegraph-install-failed" | "codegraph-install-skipped" | "graphify-installed" | "graphify-install-failed" | "graphify-install-skipped";
|
|
34
|
+
/**
|
|
35
|
+
* Install codegraph via `npm i -D @colbymchenry/codegraph`.
|
|
36
|
+
* Best-effort, never throws.
|
|
37
|
+
*/
|
|
38
|
+
export declare function installCodegraph(projectDir: string, timeoutMs?: number): Promise<InstallCode>;
|
|
39
|
+
/**
|
|
40
|
+
* Install graphify via `pip install graphifyy --break-system-packages`.
|
|
41
|
+
* Falls back to `uv tool install graphifyy`.
|
|
42
|
+
* Best-effort, never throws.
|
|
43
|
+
*/
|
|
44
|
+
export declare function installGraphify(timeoutMs?: number): Promise<InstallCode>;
|
|
45
|
+
export declare function resetInitializedProjects(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Track a new session for a project. Increments reference count.
|
|
48
|
+
* Returns the new count.
|
|
49
|
+
*/
|
|
50
|
+
export declare function trackSession(projectDir: string): number;
|
|
51
|
+
/**
|
|
52
|
+
* Untrack a session for a project. Decrements reference count.
|
|
53
|
+
* When count drops to 0, all watch processes for that project
|
|
54
|
+
* are automatically stopped.
|
|
55
|
+
* Returns the remaining count.
|
|
56
|
+
*/
|
|
57
|
+
export declare function untrackSession(projectDir: string): number;
|
|
58
|
+
/** Get active session count for a project. */
|
|
59
|
+
export declare function getSessionCount(projectDir: string): number;
|
|
60
|
+
export interface ToolAvailability {
|
|
61
|
+
/** Whether codegraph is available (via npx or node_modules) */
|
|
62
|
+
codegraph: boolean;
|
|
63
|
+
/** Whether graphify/graphifyy is available (via pip) */
|
|
64
|
+
graphify: boolean;
|
|
65
|
+
/** Whether .codegraph/ directory already exists in the project */
|
|
66
|
+
codegraphIndexExists: boolean;
|
|
67
|
+
/** Whether graphify-out/ directory already exists in the project */
|
|
68
|
+
graphifyIndexExists: boolean;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Stop all active watch processes for a project.
|
|
72
|
+
*/
|
|
73
|
+
export declare function stopWatches(projectDir?: string): void;
|
|
74
|
+
/** Check if watches are active for a project. */
|
|
75
|
+
export declare function hasActiveWatcher(projectDir: string, tool?: "codegraph" | "graphify"): boolean;
|
|
76
|
+
export interface GraphSyncResult {
|
|
77
|
+
/** Whether synchronization was attempted */
|
|
78
|
+
attempted: boolean;
|
|
79
|
+
/** Codes that describe the outcome */
|
|
80
|
+
codes: GraphSyncCode[];
|
|
81
|
+
/** Tool availability before init */
|
|
82
|
+
availability: ToolAvailability;
|
|
83
|
+
/** Whether this project was already initialized this session */
|
|
84
|
+
alreadyInitialized: boolean;
|
|
85
|
+
}
|
|
86
|
+
export type GraphSyncCode = "codegraph-initialized" | "codegraph-already-exists" | "codegraph-unavailable" | "codegraph-install-failed" | "codegraph-install-skipped" | "graphify-initialized" | "graphify-already-exists" | "graphify-unavailable" | "graphify-install-failed" | "graphify-install-skipped" | "watch-started-codegraph" | "watch-started-graphify" | "disabled" | "error";
|
|
87
|
+
/**
|
|
88
|
+
* Run the graphSync pipeline. Best-effort, never throws.
|
|
89
|
+
*/
|
|
90
|
+
export declare function runGraphSync(config?: GraphSyncConfig): Promise<GraphSyncResult>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
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 { logToFile } from "./file-logger";
|
|
25
|
+
export { runMetaGovernor, buildDecisionContext, defaultOrchestratorConfig, } from "./orchestrator";
|
|
26
|
+
export { loadOrchestratorConfig, isMetaGovernorEnabled, type MetaGovernorPluginConfig, } from "./config";
|
|
27
|
+
export { score, defaultScoringConfig } from "./scoring-engine";
|
|
28
|
+
export { predict, defaultTokenPredictorConfig, calculateBurnRate } from "./token-predictor";
|
|
29
|
+
export { handleDecision, defaultDecisionHandlerConfig, trimHistory, countConsecutiveStops } from "./decision-handler";
|
|
30
|
+
export { observeAndLearn, defaultClosedLoopConfig } from "./closed-loop-learning";
|
|
31
|
+
export { aggregateRead } from "./memory-aggregator";
|
|
32
|
+
export { recordRecovery, type RecoveryOutcome } from "./post-repair-recorder";
|
|
33
|
+
export { storeDecision, takeDecision, hasDecision, takeAnyDecision, clearAll, } from "./decision-store";
|
|
34
|
+
export type { Decision, DecisionContext, DecisionHandlerConfig, DecisionHandlerInput, DecisionHandlerOutput, Deviation, Evidence, EvidenceContribution, InterventionConfig, InterventionMode, LearnFromOutcomeInput, LearnFromOutcomeOutput, MemoryRead, MemoryBackends, AgentmemoryWriteBackend, MetaGovernorInput, MetaGovernorOutput, OrchestratorConfig, ScoringConfig, ScoringResult, SlotMemory, TokenPredictorConfig, TokenPredictorInput, TokenPredictorOutput, ClosedLoopConfig, } from "./types";
|
|
35
|
+
export { loadProtocol, buildSystemInjection, auditToolCall, DEFAULT_PROTOCOL_PATH, } from "./protocol-enforcer";
|
|
36
|
+
export { stripJsoncComments, parseJsonc, loadJsoncFile, deepMerge, loadMetaGovernorConfig, getUserConfigPath, getProjectConfigPath, type ConfigFileSources, type ConfigFileResult, } from "./config-file";
|
|
37
|
+
export { runGraphSync, stopWatches, resetInitializedProjects, type GraphSyncConfig, type GraphSyncResult, type GraphSyncCode, type ToolAvailability, } from "./graph-sync";
|
|
38
|
+
export { generateSchema, writeSchemaFile, type JsonSchema, type JsonSchemaProperty } from "./generate-schema";
|
|
39
|
+
export { loadOrchestratorConfigFromSources } from "./config";
|
|
40
|
+
export type { ProtocolViolation, ProtocolEnforcementSessionState } from "./types";
|