@herjarsa/omo-meta-governor 0.12.1 → 0.14.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/dist/codegraph-tools.d.ts +100 -0
- package/dist/custom-tools.d.ts +218 -0
- package/dist/file-logger.d.ts +46 -0
- package/dist/graph-retrieval.d.ts +120 -0
- package/dist/health.d.ts +62 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +180 -16
- package/dist/index.js.map +81 -7
- package/dist/mcp-client.d.ts +101 -0
- package/dist/memory-aggregator.d.ts +4 -3
- package/dist/metrics.d.ts +45 -0
- package/dist/session-bridge.d.ts +105 -0
- package/dist/sqlite-backend.d.ts +69 -0
- package/package.json +1 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* codegraph-tools — high-level wrappers around codegraph's sub-commands
|
|
3
|
+
* (node, callers, impact, files) for use in custom tools.
|
|
4
|
+
*
|
|
5
|
+
* codegraph is invoked via the `codegraph` CLI (not via MCP). Available
|
|
6
|
+
* sub-commands we wrap here:
|
|
7
|
+
* - codegraph node <symbol> → get source + callers of a symbol
|
|
8
|
+
* - codegraph callers <symbol> → list call sites of a symbol
|
|
9
|
+
* - codegraph impact <symbol> → full impact analysis (callers + tests + docs)
|
|
10
|
+
* - codegraph files → list indexed files
|
|
11
|
+
*
|
|
12
|
+
* v0.14.0 adds these on top of the v0.13.0 `omo_search` (which uses
|
|
13
|
+
* `codegraph explore`). Together they give the LLM a full codegraph
|
|
14
|
+
* toolkit: search, find, callers, impact, files.
|
|
15
|
+
*
|
|
16
|
+
* Design:
|
|
17
|
+
* - Pure CLI invocation via GraphRetrieval (which already handles
|
|
18
|
+
* timeout, error catching, and graceful degradation)
|
|
19
|
+
* - Each function returns null when the tool is unavailable — the
|
|
20
|
+
* caller decides what to do (e.g., suggest a fallback)
|
|
21
|
+
* - All functions take cwd + optional cli path override
|
|
22
|
+
*/
|
|
23
|
+
import { type GraphRetrieval } from "./graph-retrieval";
|
|
24
|
+
export interface OmoFindResult {
|
|
25
|
+
/** The symbol that was searched */
|
|
26
|
+
symbol: string;
|
|
27
|
+
/** Source code of the definition (formatted) */
|
|
28
|
+
source: string | null;
|
|
29
|
+
/** List of call sites (file:line format) */
|
|
30
|
+
callers: Array<{
|
|
31
|
+
file: string;
|
|
32
|
+
line: number;
|
|
33
|
+
context: string;
|
|
34
|
+
}>;
|
|
35
|
+
/** True if the symbol was found */
|
|
36
|
+
found: boolean;
|
|
37
|
+
/** Tool that produced the result */
|
|
38
|
+
kind: "codegraph" | "graphify" | null;
|
|
39
|
+
/** Total time taken */
|
|
40
|
+
durationMs: number;
|
|
41
|
+
}
|
|
42
|
+
export interface OmoImpactResult {
|
|
43
|
+
/** The symbol being analyzed */
|
|
44
|
+
symbol: string;
|
|
45
|
+
/** Direct callers (file:line) */
|
|
46
|
+
directCallers: Array<{
|
|
47
|
+
file: string;
|
|
48
|
+
line: number;
|
|
49
|
+
context: string;
|
|
50
|
+
}>;
|
|
51
|
+
/** Transitive callers (if available from the tool) */
|
|
52
|
+
transitiveCallers: Array<{
|
|
53
|
+
file: string;
|
|
54
|
+
line: number;
|
|
55
|
+
context: string;
|
|
56
|
+
}>;
|
|
57
|
+
/** Test files affected (if available) */
|
|
58
|
+
testFiles: string[];
|
|
59
|
+
/** Documentation files affected (if available) */
|
|
60
|
+
docFiles: string[];
|
|
61
|
+
/** Total affected file count */
|
|
62
|
+
totalAffectedFiles: number;
|
|
63
|
+
/** Tool that produced the result */
|
|
64
|
+
kind: "codegraph" | "graphify" | null;
|
|
65
|
+
/** Total time taken */
|
|
66
|
+
durationMs: number;
|
|
67
|
+
/** Whether the analysis timed out */
|
|
68
|
+
timedOut: boolean;
|
|
69
|
+
}
|
|
70
|
+
export interface OmoFilesResult {
|
|
71
|
+
files: string[];
|
|
72
|
+
count: number;
|
|
73
|
+
kind: "codegraph" | "graphify" | null;
|
|
74
|
+
durationMs: number;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Default entry point: use the singleton GraphRetrieval.
|
|
78
|
+
* Tests can construct their own CodeGraphTools with a custom instance.
|
|
79
|
+
*/
|
|
80
|
+
export declare class CodeGraphTools {
|
|
81
|
+
private retrieval;
|
|
82
|
+
constructor(retrieval?: GraphRetrieval);
|
|
83
|
+
/**
|
|
84
|
+
* Find a symbol's definition and direct callers.
|
|
85
|
+
* Uses `codegraph node <symbol>` for codegraph, `graphify query <symbol>` for graphify.
|
|
86
|
+
*/
|
|
87
|
+
find(symbol: string, cwd: string, timeoutMs?: number): Promise<OmoFindResult>;
|
|
88
|
+
/**
|
|
89
|
+
* Analyze the impact of changing a symbol. Lists direct callers,
|
|
90
|
+
* transitive callers, and affected test/doc files.
|
|
91
|
+
* Uses `codegraph impact <symbol>` if available, else `codegraph callers`.
|
|
92
|
+
*/
|
|
93
|
+
impact(symbol: string, cwd: string, timeoutMs?: number): Promise<OmoImpactResult>;
|
|
94
|
+
/**
|
|
95
|
+
* List indexed files. Uses `codegraph files`.
|
|
96
|
+
*/
|
|
97
|
+
listFiles(cwd: string, timeoutMs?: number): Promise<OmoFilesResult>;
|
|
98
|
+
}
|
|
99
|
+
/** Returns the process-wide CodeGraphTools singleton. */
|
|
100
|
+
export declare function getDefaultCodeGraphTools(): CodeGraphTools;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom tools that omo-meta-governor registers for the LLM to invoke
|
|
3
|
+
* explicitly. v0.13.1 upgrade.
|
|
4
|
+
*
|
|
5
|
+
* Three tools:
|
|
6
|
+
* - `omo_search` — semantic code search via codegraph/graphify
|
|
7
|
+
* - `omo_recall` — search past lessons learned in this project's history
|
|
8
|
+
* - `omo_health` — show plugin runtime status + metrics
|
|
9
|
+
*
|
|
10
|
+
* Design:
|
|
11
|
+
* - Tools are registered via the `tool` field in the returned Hooks object
|
|
12
|
+
* - All tools have Zod-validated args (typed at compile time)
|
|
13
|
+
* - Each tool calls into the modules we already built (GraphRetrieval, SqliteBackend)
|
|
14
|
+
* - Failure modes return a friendly string so the LLM can recover
|
|
15
|
+
*
|
|
16
|
+
* The key insight: instead of fire-and-forget invocations in tool.execute.before
|
|
17
|
+
* (v0.13.0), the LLM now EXPLICITLY chooses when to call these tools via its
|
|
18
|
+
* tool schema. This makes governance visible and intentional rather than
|
|
19
|
+
* ambient and invisible.
|
|
20
|
+
*/
|
|
21
|
+
import { type ToolContext, type ToolResult } from "@opencode-ai/plugin";
|
|
22
|
+
import type { SqliteBackend } from "./sqlite-backend";
|
|
23
|
+
import type { GraphRetrieval } from "./graph-retrieval";
|
|
24
|
+
import type { MetricsCollector } from "./metrics";
|
|
25
|
+
import { type CodeGraphTools } from "./codegraph-tools";
|
|
26
|
+
export interface OmoSearchDeps {
|
|
27
|
+
graphRetrieval: GraphRetrieval;
|
|
28
|
+
cwd: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Build the `omo_search` tool. The LLM sees it in its tool schema with a
|
|
32
|
+
* description that biases it toward graph-first queries.
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildOmoSearchTool(deps: OmoSearchDeps): {
|
|
35
|
+
description: string;
|
|
36
|
+
args: {
|
|
37
|
+
query: import("zod").ZodString;
|
|
38
|
+
maxResults: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
39
|
+
};
|
|
40
|
+
execute(args: {
|
|
41
|
+
query: string;
|
|
42
|
+
maxResults?: number | undefined;
|
|
43
|
+
}, context: ToolContext): Promise<ToolResult>;
|
|
44
|
+
};
|
|
45
|
+
export interface OmoRecallDeps {
|
|
46
|
+
sqlite: SqliteBackend;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Build the `omo_recall` tool. The LLM uses this to retrieve lessons learned
|
|
50
|
+
* in past sessions, enabling genuine cross-session learning.
|
|
51
|
+
*/
|
|
52
|
+
export declare function buildOmoRecallTool(deps: OmoRecallDeps): {
|
|
53
|
+
description: string;
|
|
54
|
+
args: {
|
|
55
|
+
query: import("zod").ZodString;
|
|
56
|
+
limit: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
57
|
+
};
|
|
58
|
+
execute(args: {
|
|
59
|
+
query: string;
|
|
60
|
+
limit?: number | undefined;
|
|
61
|
+
}, context: ToolContext): Promise<ToolResult>;
|
|
62
|
+
};
|
|
63
|
+
export interface OmoHealthDeps {
|
|
64
|
+
metrics: MetricsCollector;
|
|
65
|
+
logFilePath: string;
|
|
66
|
+
healthFilePath: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Build the `omo_health` tool. Lets the agent (and the user) see exactly
|
|
70
|
+
* what the plugin is doing — closes the v0.10.0 "silent governance" complaint.
|
|
71
|
+
*/
|
|
72
|
+
export declare function buildOmoHealthTool(deps: OmoHealthDeps): {
|
|
73
|
+
description: string;
|
|
74
|
+
args: {};
|
|
75
|
+
execute(args: Record<string, never>, context: ToolContext): Promise<ToolResult>;
|
|
76
|
+
};
|
|
77
|
+
export interface OmoFindDeps {
|
|
78
|
+
codeGraph?: CodeGraphTools;
|
|
79
|
+
cwd: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Build the `omo_find` tool. Resolves a symbol to its source code location
|
|
83
|
+
* and lists direct call sites. Uses `codegraph node <symbol>` (with
|
|
84
|
+
* `graphify query <symbol>` as fallback when codegraph is unavailable).
|
|
85
|
+
*/
|
|
86
|
+
export declare function buildOmoFindTool(deps: OmoFindDeps): {
|
|
87
|
+
description: string;
|
|
88
|
+
args: {
|
|
89
|
+
symbol: import("zod").ZodString;
|
|
90
|
+
};
|
|
91
|
+
execute(args: {
|
|
92
|
+
symbol: string;
|
|
93
|
+
}, context: ToolContext): Promise<ToolResult>;
|
|
94
|
+
};
|
|
95
|
+
export interface OmoImpactDeps {
|
|
96
|
+
codeGraph?: CodeGraphTools;
|
|
97
|
+
cwd: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Build the `omo_impact` tool. Lists all call sites of a symbol plus
|
|
101
|
+
* affected test and doc files. Uses `codegraph impact <symbol>` (falls
|
|
102
|
+
* back to `codegraph callers` when impact is unavailable).
|
|
103
|
+
*/
|
|
104
|
+
export declare function buildOmoImpactTool(deps: OmoImpactDeps): {
|
|
105
|
+
description: string;
|
|
106
|
+
args: {
|
|
107
|
+
symbol: import("zod").ZodString;
|
|
108
|
+
};
|
|
109
|
+
execute(args: {
|
|
110
|
+
symbol: string;
|
|
111
|
+
}, context: ToolContext): Promise<ToolResult>;
|
|
112
|
+
};
|
|
113
|
+
export interface OmoRememberDeps {
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Build the `omo_remember` tool. Persists a fact/observation/lesson to
|
|
117
|
+
* AgentMemory by instructing the LLM to call `agentmemory_memory_save`.
|
|
118
|
+
*/
|
|
119
|
+
export declare function buildOmoRememberTool(deps: OmoRememberDeps): {
|
|
120
|
+
description: string;
|
|
121
|
+
args: {
|
|
122
|
+
content: import("zod").ZodString;
|
|
123
|
+
concepts: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
124
|
+
type: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
125
|
+
pattern: "pattern";
|
|
126
|
+
fact: "fact";
|
|
127
|
+
observation: "observation";
|
|
128
|
+
}>>;
|
|
129
|
+
};
|
|
130
|
+
execute(args: {
|
|
131
|
+
content: string;
|
|
132
|
+
concepts?: string[] | undefined;
|
|
133
|
+
type?: "pattern" | "fact" | "observation" | undefined;
|
|
134
|
+
}, context: ToolContext): Promise<ToolResult>;
|
|
135
|
+
};
|
|
136
|
+
export interface OmoRecallMcpDeps {
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Build the `omo_recall_mcp` tool. Searches AgentMemory by sending a
|
|
140
|
+
* query to the LLM that triggers `agentmemory_memory_smart_search`.
|
|
141
|
+
*
|
|
142
|
+
* Note: prefer `omo_recall` (which queries SQLite FTS5 locally) for fast
|
|
143
|
+
* local recall. Use `omo_recall_mcp` when you specifically need to search
|
|
144
|
+
* AgentMemory's persistent cross-session memory.
|
|
145
|
+
*/
|
|
146
|
+
export declare function buildOmoRecallMcpTool(deps: OmoRecallMcpDeps): {
|
|
147
|
+
description: string;
|
|
148
|
+
args: {
|
|
149
|
+
query: import("zod").ZodString;
|
|
150
|
+
limit: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
151
|
+
};
|
|
152
|
+
execute(args: {
|
|
153
|
+
query: string;
|
|
154
|
+
limit?: number | undefined;
|
|
155
|
+
}, context: ToolContext): Promise<ToolResult>;
|
|
156
|
+
};
|
|
157
|
+
export interface OmoRuleDeps {
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Build the `omo_rule` tool. Saves a durable rule to Magic Context that
|
|
161
|
+
* persists across sessions. Categorized by type (PROJECT_RULES, ARCHITECTURE,
|
|
162
|
+
* CONSTRAINTS, CONFIG_VALUES, NAMING). Uses `ctx_memory(action="write")`.
|
|
163
|
+
*/
|
|
164
|
+
export declare function buildOmoRuleTool(deps: OmoRuleDeps): {
|
|
165
|
+
description: string;
|
|
166
|
+
args: {
|
|
167
|
+
category: import("zod").ZodEnum<{
|
|
168
|
+
PROJECT_RULES: "PROJECT_RULES";
|
|
169
|
+
ARCHITECTURE: "ARCHITECTURE";
|
|
170
|
+
CONSTRAINTS: "CONSTRAINTS";
|
|
171
|
+
CONFIG_VALUES: "CONFIG_VALUES";
|
|
172
|
+
NAMING: "NAMING";
|
|
173
|
+
}>;
|
|
174
|
+
content: import("zod").ZodString;
|
|
175
|
+
};
|
|
176
|
+
execute(args: {
|
|
177
|
+
category: "PROJECT_RULES" | "ARCHITECTURE" | "CONSTRAINTS" | "CONFIG_VALUES" | "NAMING";
|
|
178
|
+
content: string;
|
|
179
|
+
}, context: ToolContext): Promise<ToolResult>;
|
|
180
|
+
};
|
|
181
|
+
export interface OmoHistoryDeps {
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Build the `omo_history` tool. Searches git commit history and prior
|
|
185
|
+
* conversations via Magic Context. Uses `ctx_search` with sources=["git_commit", "message"].
|
|
186
|
+
*/
|
|
187
|
+
export declare function buildOmoHistoryTool(deps: OmoHistoryDeps): {
|
|
188
|
+
description: string;
|
|
189
|
+
args: {
|
|
190
|
+
query: import("zod").ZodString;
|
|
191
|
+
sources: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodEnum<{
|
|
192
|
+
message: "message";
|
|
193
|
+
git_commit: "git_commit";
|
|
194
|
+
}>>>;
|
|
195
|
+
};
|
|
196
|
+
execute(args: {
|
|
197
|
+
query: string;
|
|
198
|
+
sources?: ("message" | "git_commit")[] | undefined;
|
|
199
|
+
}, context: ToolContext): Promise<ToolResult>;
|
|
200
|
+
};
|
|
201
|
+
export interface OmoNoteDeps {
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Build the `omo_note` tool. Writes a session-scoped working note via
|
|
205
|
+
* Magic Context. Notes are for the current task only (ephemeral context).
|
|
206
|
+
* Uses `ctx_note(action="write")`.
|
|
207
|
+
*/
|
|
208
|
+
export declare function buildOmoNoteTool(deps: OmoNoteDeps): {
|
|
209
|
+
description: string;
|
|
210
|
+
args: {
|
|
211
|
+
content: import("zod").ZodString;
|
|
212
|
+
surfaceCondition: import("zod").ZodOptional<import("zod").ZodString>;
|
|
213
|
+
};
|
|
214
|
+
execute(args: {
|
|
215
|
+
content: string;
|
|
216
|
+
surfaceCondition?: string | undefined;
|
|
217
|
+
}, context: ToolContext): Promise<ToolResult>;
|
|
218
|
+
};
|
package/dist/file-logger.d.ts
CHANGED
|
@@ -1 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSONL structured file logger with size-based rotation. v0.13.0 upgrade
|
|
3
|
+
* of the original text-based logger.
|
|
4
|
+
*
|
|
5
|
+
* Output format: one JSON object per line, with fields:
|
|
6
|
+
* { timestamp, level, event, message, sessionID?, data? }
|
|
7
|
+
*
|
|
8
|
+
* Rotation: when the active log file exceeds MAX_FILE_SIZE_BYTES (10MB),
|
|
9
|
+
* the current file is renamed to .1, .1 to .2, etc. Files past MAX_ROTATED_FILES
|
|
10
|
+
* are deleted. Atomic on POSIX (rename is atomic for same-filesystem moves).
|
|
11
|
+
*
|
|
12
|
+
* Backwards compatibility: the existing `logToFile(level, message, data?)`
|
|
13
|
+
* API is preserved with 14 existing call sites. New code can use
|
|
14
|
+
* `logStructured({ level, event, message, ... })` for structured fields.
|
|
15
|
+
*/
|
|
16
|
+
declare const LOG_PATH: string;
|
|
17
|
+
export type LogLevel = "info" | "warn" | "error";
|
|
18
|
+
export interface LogEntry {
|
|
19
|
+
/** ISO 8601 timestamp. Auto-filled if omitted. */
|
|
20
|
+
timestamp?: string;
|
|
21
|
+
level: LogLevel;
|
|
22
|
+
/** Optional structured event name (e.g. "plugin_loaded", "intervention_delivered"). */
|
|
23
|
+
event?: string;
|
|
24
|
+
message: string;
|
|
25
|
+
/** Optional sessionID for correlation across logs. */
|
|
26
|
+
sessionID?: string;
|
|
27
|
+
/** Optional structured data (JSON-serializable). */
|
|
28
|
+
data?: unknown;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Legacy API — preserves the signature of the pre-0.13.0 logger so all 14
|
|
32
|
+
* existing call sites in src/plugin.ts continue to work unchanged.
|
|
33
|
+
*/
|
|
1
34
|
export declare function logToFile(level: "info" | "warn" | "error", message: string, data?: unknown): void;
|
|
35
|
+
/**
|
|
36
|
+
* Structured API for new code. Adds `event` and `sessionID` fields.
|
|
37
|
+
*/
|
|
38
|
+
export declare function logStructured(entry: LogEntry): void;
|
|
39
|
+
/**
|
|
40
|
+
* Returns the current log file size in bytes (for health monitoring).
|
|
41
|
+
*/
|
|
42
|
+
export declare function getLogFileSize(): number;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the number of rotated log files (e.g. 0-5).
|
|
45
|
+
*/
|
|
46
|
+
export declare function getRotatedLogCount(): number;
|
|
47
|
+
export { LOG_PATH };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GraphRetrieval — invokes codegraph/graphify and caches results for
|
|
3
|
+
* injection into the agent's context. v0.13.0 fix for C2: the plugin
|
|
4
|
+
* previously only told the agent to use graph tools via prompt text; now
|
|
5
|
+
* it actually invokes them and injects the results.
|
|
6
|
+
*
|
|
7
|
+
* Design:
|
|
8
|
+
* - Re-detects graph directories on EVERY call (fixes the race condition
|
|
9
|
+
* in src/plugin.ts:74-81 where static booleans were set once at load time
|
|
10
|
+
* before async `runGraphSync()` could create the directories).
|
|
11
|
+
* - Async with timeout (5s default) — never blocks tool.execute.before.
|
|
12
|
+
* - Per-session cache keyed by (sessionID, queryHash) with 5min TTL.
|
|
13
|
+
* - LRU eviction at 10 entries per session.
|
|
14
|
+
* - Graceful degradation: missing CLI → null result, errors are swallowed.
|
|
15
|
+
*
|
|
16
|
+
* Invocation strategy:
|
|
17
|
+
* - If `.codegraph/` exists and `codegraph` CLI is available: invoke `codegraph explore <query>`
|
|
18
|
+
* - Else if `graphify-out/` exists and `graphify` is available: invoke `graphify query <query>`
|
|
19
|
+
* - Else: return null
|
|
20
|
+
*
|
|
21
|
+
* The plugin can override CLI paths via the `invoke()` options for testing
|
|
22
|
+
* and for users who have the tools in non-standard locations.
|
|
23
|
+
*/
|
|
24
|
+
import { existsSync } from "node:fs";
|
|
25
|
+
export type GraphToolKind = "codegraph" | "graphify" | null;
|
|
26
|
+
export interface GraphInvocationResult {
|
|
27
|
+
/** Which tool was actually invoked. */
|
|
28
|
+
kind: GraphToolKind;
|
|
29
|
+
/** The query that was executed. */
|
|
30
|
+
query: string;
|
|
31
|
+
/** Result text from the tool, or null on failure / no-tool. */
|
|
32
|
+
result: string | null;
|
|
33
|
+
/** True if the subprocess was killed by timeout. */
|
|
34
|
+
timedOut: boolean;
|
|
35
|
+
/** Wall-clock duration in ms. */
|
|
36
|
+
durationMs: number;
|
|
37
|
+
}
|
|
38
|
+
export interface GraphRetrievalConfig {
|
|
39
|
+
/** Subprocess timeout in ms. Default: 5000. */
|
|
40
|
+
timeoutMs?: number;
|
|
41
|
+
/** Cache entry TTL in ms. Default: 300000 (5min). */
|
|
42
|
+
cacheTtlMs?: number;
|
|
43
|
+
/** Max cache entries per session. Default: 10. */
|
|
44
|
+
maxEntriesPerSession?: number;
|
|
45
|
+
}
|
|
46
|
+
export interface InvokeOptions {
|
|
47
|
+
/** Override codegraph CLI path (default: lookup in PATH). */
|
|
48
|
+
codegraphBin?: string;
|
|
49
|
+
/** Override graphify CLI path (default: lookup in PATH). */
|
|
50
|
+
graphifyBin?: string;
|
|
51
|
+
/** Override timeout for this call. */
|
|
52
|
+
timeoutMs?: number;
|
|
53
|
+
}
|
|
54
|
+
/** Deterministic hash for a query string. Used as cache key suffix. */
|
|
55
|
+
export declare function hashQuery(query: string): string;
|
|
56
|
+
export declare class GraphRetrieval {
|
|
57
|
+
private readonly timeoutMs;
|
|
58
|
+
private readonly cacheTtlMs;
|
|
59
|
+
private readonly maxEntriesPerSession;
|
|
60
|
+
private readonly cache;
|
|
61
|
+
constructor(config?: GraphRetrievalConfig);
|
|
62
|
+
/** Returns true if .codegraph/ exists in the project dir. */
|
|
63
|
+
hasCodegraphDir(projectDir: string): boolean;
|
|
64
|
+
/** Returns true if graphify-out/ exists in the project dir. */
|
|
65
|
+
hasGraphifyDir(projectDir: string): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Cache graph context for a session. The most recent entry per session is
|
|
68
|
+
* returned by `getCachedContext()` with no query arg (used by
|
|
69
|
+
* system.transform to inject the latest graph context).
|
|
70
|
+
*/
|
|
71
|
+
cacheContext(sessionID: string, query: string, content: string): void;
|
|
72
|
+
/**
|
|
73
|
+
* Get cached context for a session.
|
|
74
|
+
* - If `query` is provided, returns the exact match (or null).
|
|
75
|
+
* - If `query` is omitted, returns the most recent non-expired entry.
|
|
76
|
+
*/
|
|
77
|
+
getCachedContext(sessionID: string, query?: string): string | null;
|
|
78
|
+
clear(): void;
|
|
79
|
+
clearSession(sessionID: string): void;
|
|
80
|
+
/**
|
|
81
|
+
* Invoke a graph tool for the given query. Returns structured result.
|
|
82
|
+
* Never throws — all errors are caught and returned as `result: null`.
|
|
83
|
+
*
|
|
84
|
+
* Selection logic:
|
|
85
|
+
* 1. If `.codegraph/` exists and `codegraph` CLI is found → invoke codegraph
|
|
86
|
+
* 2. Else if `graphify-out/` exists and `graphify` CLI is found → invoke graphify
|
|
87
|
+
* 3. Else → return null result
|
|
88
|
+
*/
|
|
89
|
+
invoke(projectDir: string, query: string, options?: InvokeOptions): Promise<GraphInvocationResult>;
|
|
90
|
+
private spawnWithTimeout;
|
|
91
|
+
/**
|
|
92
|
+
* Get the source code and direct callers of a symbol.
|
|
93
|
+
* Runs `codegraph node <symbol> --project-path <cwd>`.
|
|
94
|
+
*/
|
|
95
|
+
invokeNode(symbol: string, projectDir: string, options?: InvokeOptions): Promise<GraphInvocationResult>;
|
|
96
|
+
/**
|
|
97
|
+
* List all call sites of a symbol.
|
|
98
|
+
* Runs `codegraph callers <symbol> --project-path <cwd>`.
|
|
99
|
+
*/
|
|
100
|
+
invokeCallers(symbol: string, projectDir: string, options?: InvokeOptions): Promise<GraphInvocationResult>;
|
|
101
|
+
/**
|
|
102
|
+
* Full impact analysis: direct callers, transitive callers,
|
|
103
|
+
* affected test files, affected doc files.
|
|
104
|
+
* Runs `codegraph impact <symbol> --project-path <cwd>`.
|
|
105
|
+
*/
|
|
106
|
+
invokeImpact(symbol: string, projectDir: string, options?: InvokeOptions): Promise<GraphInvocationResult>;
|
|
107
|
+
/**
|
|
108
|
+
* List all indexed files.
|
|
109
|
+
* Runs `codegraph files --project-path <cwd>`.
|
|
110
|
+
*/
|
|
111
|
+
invokeFiles(projectDir: string, options?: InvokeOptions): Promise<GraphInvocationResult>;
|
|
112
|
+
/**
|
|
113
|
+
* Run a codegraph sub-command and return the result.
|
|
114
|
+
* Returns null result if codegraph is not available.
|
|
115
|
+
*/
|
|
116
|
+
private invokeCodegraphSubcommand;
|
|
117
|
+
}
|
|
118
|
+
/** Returns the process-wide singleton, creating it on first use. */
|
|
119
|
+
export declare function getDefaultGraphRetrieval(): GraphRetrieval;
|
|
120
|
+
export { existsSync };
|
package/dist/health.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin health state — observable proof that omo-meta-governor is doing work.
|
|
3
|
+
* Closes the C3/C4 invisibility gap: the user can `cat` the health JSON to
|
|
4
|
+
* see exactly what the plugin is doing, instead of wondering "is this thing
|
|
5
|
+
* alive?".
|
|
6
|
+
*
|
|
7
|
+
* Design:
|
|
8
|
+
* - Atomic writes (write to .tmp, then rename) — never produces partial reads
|
|
9
|
+
* - Pure functions: writeHealthToFile() and readHealthFromFile() take an
|
|
10
|
+
* explicit path so they're testable without environment setup
|
|
11
|
+
* - Returns null on missing/malformed file (not throwing) — the health file
|
|
12
|
+
* is observability, not a control plane; failure is non-fatal
|
|
13
|
+
*/
|
|
14
|
+
export interface PluginHealth {
|
|
15
|
+
version: string;
|
|
16
|
+
status: "healthy" | "degraded" | "error";
|
|
17
|
+
enabled: boolean;
|
|
18
|
+
startedAtISO: string;
|
|
19
|
+
uptimeMs: number;
|
|
20
|
+
metrics: {
|
|
21
|
+
decisionsTaken: number;
|
|
22
|
+
decisionsStored: number;
|
|
23
|
+
interventionsDelivered: number;
|
|
24
|
+
orchestratorRuns: number;
|
|
25
|
+
orchestratorErrors: number;
|
|
26
|
+
lastDecisionISO: string | null;
|
|
27
|
+
lastInterventionISO: string | null;
|
|
28
|
+
};
|
|
29
|
+
logFile: {
|
|
30
|
+
path: string;
|
|
31
|
+
sizeBytes: number;
|
|
32
|
+
rotatedFiles: number;
|
|
33
|
+
};
|
|
34
|
+
session: {
|
|
35
|
+
id: string;
|
|
36
|
+
toolCallsObserved: number;
|
|
37
|
+
violationsDetected: number;
|
|
38
|
+
interventionsSkipped: number;
|
|
39
|
+
firstSeenISO: string;
|
|
40
|
+
lastSeenISO: string;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Atomically write the health state to the given path. Writes to a
|
|
45
|
+
* .tmp sibling first, then renames. Creates parent directory if needed.
|
|
46
|
+
*/
|
|
47
|
+
export declare function writeHealthToFile(health: PluginHealth, path: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Read the health state from the given path. Returns null on missing or
|
|
50
|
+
* malformed file. Never throws — the health file is observability, not
|
|
51
|
+
* a control plane.
|
|
52
|
+
*/
|
|
53
|
+
export declare function readHealthFromFile(path: string): PluginHealth | null;
|
|
54
|
+
/**
|
|
55
|
+
* Compute the current log file size and rotated file count. Used to
|
|
56
|
+
* populate the `logFile` field in PluginHealth.
|
|
57
|
+
*/
|
|
58
|
+
export declare function describeLogFile(logPath: string): {
|
|
59
|
+
path: string;
|
|
60
|
+
sizeBytes: number;
|
|
61
|
+
rotatedFiles: number;
|
|
62
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -36,5 +36,7 @@ export { loadProtocol, buildSystemInjection, auditToolCall, DEFAULT_PROTOCOL_PAT
|
|
|
36
36
|
export { stripJsoncComments, parseJsonc, loadJsoncFile, deepMerge, loadMetaGovernorConfig, getUserConfigPath, getProjectConfigPath, type ConfigFileSources, type ConfigFileResult, } from "./config-file";
|
|
37
37
|
export { runGraphSync, stopWatches, resetInitializedProjects, type GraphSyncConfig, type GraphSyncResult, type GraphSyncCode, type ToolAvailability, } from "./graph-sync";
|
|
38
38
|
export { generateSchema, writeSchemaFile, type JsonSchema, type JsonSchemaProperty } from "./generate-schema";
|
|
39
|
+
export { SqliteBackend, getDefaultSqliteBackend } from "./sqlite-backend";
|
|
40
|
+
export { GraphRetrieval, getDefaultGraphRetrieval, hashQuery, type GraphToolKind, type GraphInvocationResult, type GraphRetrievalConfig, type InvokeOptions } from "./graph-retrieval";
|
|
39
41
|
export { loadOrchestratorConfigFromSources } from "./config";
|
|
40
42
|
export type { ProtocolViolation, ProtocolEnforcementSessionState } from "./types";
|