@herjarsa/omo-meta-governor 0.52.0 → 0.54.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.
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Adherence tracking — detects when the agent IGNORES an already-injected
3
+ * directive (same rule violated again after the injection was drained).
4
+ *
5
+ * Why this exists: protocol violations are injected into the agent context
6
+ * (system.transform drain, FASE 11 11e), but nothing measured whether the
7
+ * agent actually complied afterwards. A repeat violation of the same rule
8
+ * AFTER the agent saw the directive is evidence of non-adherence, not of a
9
+ * missing directive — so it is counted separately (`directives_ignored`)
10
+ * instead of re-injecting louder each time.
11
+ *
12
+ * Lifecycle (per session):
13
+ * 1. tool.execute.before detects violation of rule R.
14
+ * 2. If R was already injected (drained) in this session → reincidencia:
15
+ * `directives_ignored` + `adherence_ignored` log. Never escalates by
16
+ * itself for leve/media (counting only — explicit below).
17
+ * 3. system.transform drains pendingViolations → each distinct rule R in
18
+ * the drained items is recorded via `recordInjection` (injected = the
19
+ * agent saw it; detection alone does NOT mark — the agent may never
20
+ * have seen an undrained queue).
21
+ * 4. Scoring: ONLY grave reincidence with repeatCount >= 2 (third strike
22
+ * counting the original) floors the decision to `stop`. The
23
+ * stop → paralysis → continue loop stays supreme: a persistent false
24
+ * positive still resolves via paralysisOverride forcing continue after
25
+ * N consecutive stops, so adherence can never deadlock a session.
26
+ *
27
+ * Severity policy (explicit):
28
+ * - leve / media reincidence: counted in `directives_ignored`, NEVER
29
+ * escalates on its own. See `adherenceFloor` — it returns null for
30
+ * non-grave severities unconditionally.
31
+ * - grave reincidence: counted; escalates to `stop` ONLY at repeatCount
32
+ * >= ADHERENCE_STOP_REPEAT_THRESHOLD (2). Below that, the Wave B grave
33
+ * floor (continue/warn → escalate) still applies as before.
34
+ *
35
+ * All helpers here are pure (no I/O, no Date.now, no globals) so they are
36
+ * unit-testable without the plugin factory.
37
+ */
38
+ /** Rule -> times the rule's directive was drained (seen by the agent). */
39
+ export type InjectedRules = Record<string, number>;
40
+ /**
41
+ * How many times a rule's directive was already injected when a new
42
+ * violation arrives. repeatCount >= ADHERENCE_STOP_REPEAT_THRESHOLD means
43
+ * the third strike (original + 2 repeats).
44
+ */
45
+ export declare const ADHERENCE_STOP_REPEAT_THRESHOLD = 2;
46
+ /** Cap of distinct rules tracked per session (bounds per-session memory). */
47
+ export declare const ADHERENCE_MAX_RULES = 50;
48
+ /**
49
+ * Record that rule `rule` was injected (drained into agent context).
50
+ * Returns a NEW record (input is not mutated). When the record already
51
+ * holds ADHERENCE_MAX_RULES distinct rules, the new rule is dropped so a
52
+ * noisy session cannot grow memory unboundedly.
53
+ */
54
+ export declare function recordInjection(rules: Readonly<InjectedRules>, rule: string): InjectedRules;
55
+ /**
56
+ * How many times `rule` was already injected in this session (0 = never —
57
+ * the current violation is the first occurrence, NOT a reincidencia).
58
+ */
59
+ export declare function countRepeat(rules: Readonly<InjectedRules>, rule: string): number;
60
+ /**
61
+ * Adherence escalation floor. Returns "stop" ONLY for grave reincidence at
62
+ * or above the repeat threshold. leve/media ALWAYS return null (counted,
63
+ * never escalated — see module docstring). Unknown severities return null.
64
+ */
65
+ export declare function adherenceFloor(severity: string, repeatCount: number): "stop" | null;
66
+ /**
67
+ * Extract distinct rule names from drained violation entry strings.
68
+ * Entries are formatted as `[SEVERITY] rule: detail` (see plugin.ts queue
69
+ * site). Returns distinct rules in first-seen order; unparseable entries
70
+ * are skipped (never throw — drain is best-effort).
71
+ */
72
+ export declare function parseInjectedRules(items: readonly string[]): string[];
@@ -37,6 +37,17 @@ export declare function lessonConfidenceForDecision(decision: Decision): number;
37
37
  export declare function isNeutralContinueDecision(decision: Decision): boolean;
38
38
  /** Severity ordering for threshold comparison. */
39
39
  declare const SEVERITY_ORDER: Record<string, number>;
40
+ /**
41
+ * Extract concepts from deviations for the lesson. Optionally include file
42
+ * basenames from the broader filePaths list so FTS indexing covers all
43
+ * recently changed files (Gap Q completeness, v0.17.2).
44
+ *
45
+ * v0.53.1 (conscience-content fix): exported for reuse by the auto-remember
46
+ * path so concepts derive from REAL rule deviations (categories + basenames)
47
+ * instead of the generic ['conscience','media'] pair. Generic concepts
48
+ * pollute FTS recall with noise; real categories keep recall precise.
49
+ */
50
+ export declare function extractConcepts(deviations: readonly Deviation[], filesChanged?: readonly string[]): string[];
40
51
  /**
41
52
  * Core learning function. Decides whether to save a lesson and/or decision
42
53
  * to agentmemory based on the outcome of a repair/action cycle.
@@ -78,19 +89,62 @@ export interface ConscienceDedupeKeyInput {
78
89
  readonly deviationCategories: readonly string[];
79
90
  }
80
91
  export declare function conscienceDedupeKey(input: ConscienceDedupeKeyInput): string;
92
+ /**
93
+ * Basename for FTS indexing — handles POSIX and Windows separators.
94
+ * Keeps whereToGo/concepts as real PLACES (file names) instead of
95
+ * meta-instructions about which tool to call.
96
+ */
97
+ export declare function basenameOf(filePath: string): string;
98
+ /**
99
+ * Derive the conscience `mistake` from REAL rule deviations — never the raw
100
+ * scoring reasoning. A raw dump like 'Stop (score: -0.552): primary concern:
101
+ * Iteration ratio...' describes the JUDGE ('the session is long'), not a
102
+ * learnable rule violation. The learnable unit is `${category}: ${detail}`
103
+ * from the first non-conscience deviation; when several exist they are joined
104
+ * with '; ' and truncated to ~300 chars so the saved lesson stays scannable.
105
+ */
106
+ export declare function conscienceMistakeFromDeviations(deviations: readonly Deviation[]): string;
107
+ /**
108
+ * Derive conscience `whereToGo` as a PLACE — basenames of changed files —
109
+ * never meta-instructions. The old value ('Persist via omo_remember; recall
110
+ * via omo_recall...') told the agent WHERE in tool-space, not where in the
111
+ * repo the rule applies. When no files exist, `session:<id>` scopes the
112
+ * lesson to the session instead of inventing a location.
113
+ */
114
+ export declare function conscienceWhereToGo(files: readonly string[], sessionID: string): string;
81
115
  /**
82
116
  * Structured conscience memory content (D4/D6). Built via buildLessonContent
83
117
  * + extractConcepts — never a raw dump. Delivery route is always the
84
118
  * Zod-validated omo_remember tool.
119
+ *
120
+ * v0.53.1 (conscience-content fix): content is pure lesson — no `ToolRoute:`
121
+ * self-reference. The agent already knows the tool from the preamble
122
+ * ('Conscience lesson — persist it via omo_remember'); persisting the route
123
+ * inside the lesson pollutes recall with meta-instructions. `toolRoute` is
124
+ * kept as an optional deprecated passthrough so old callers still compile,
125
+ * but it is NEVER rendered. Concepts derive from REAL deviations via
126
+ * extractConcepts, not the generic ['conscience','media'] pair.
85
127
  */
86
128
  export interface BuildConscienceMemoryContentInput {
87
129
  readonly action: "escalate" | "stop";
88
130
  readonly mistake: string;
89
131
  readonly whatToDo: string;
90
132
  readonly whereToGo: string;
91
- readonly toolRoute: "omo_remember";
133
+ /**
134
+ * Deprecated self-reference — accepted for compat but never rendered.
135
+ * The preamble already names omo_remember; the saved CONTENT must be
136
+ * pure lesson (mistake/whatToDo/whereToGo) without tool routing noise.
137
+ */
138
+ readonly toolRoute?: "omo_remember";
92
139
  readonly score: number;
93
140
  readonly files: readonly string[];
141
+ /**
142
+ * Real rule deviations (category !== 'conscience'). Used for the lesson
143
+ * base + concepts so recall indexes violated rules, not the synthetic
144
+ * conscience wrapper. When omitted, falls back to the legacy synthetic
145
+ * single-deviation for backward compat with direct unit callers.
146
+ */
147
+ readonly deviations?: readonly Deviation[];
94
148
  }
95
149
  export interface ConscienceMemoryContent {
96
150
  readonly content: string;
package/dist/config.d.ts CHANGED
@@ -90,11 +90,13 @@ export interface MetaGovernorPluginConfig {
90
90
  * Even stop-level decisions log without injecting an Oracle prompt.
91
91
  * Zero mid-work interruptions.
92
92
  *
93
- * - `"per-stop"`: Oracle is invoked ONLY at the final-gate
94
- * (`<promise>DONE</promise>`) AND when score crosses the stop
95
- * threshold (`≤ -stopThreshold`). warn/escalate decisions log but do
96
- * NOT inject an Oracle prompt mid-work. Brake on emergencies,
97
- * mandatory at done.
93
+ * - `"per-stop"`: Oracle is invoked at the final-gate
94
+ * (`<promise>DONE</promise>`) AND when the scoring engine reaches the
95
+ * stop band (action === "stop"). warn/escalate decisions log but do
96
+ * NOT invoke Oracle mid-work. Brake on emergencies, mandatory at done.
97
+ * (B3: wording copied from enforcement-resources.ts buildOracleRule;
98
+ * the previous text said "ONLY at the final-gate ... AND when",
99
+ * which is self-contradictory.)
98
100
  *
99
101
  * - `"off"`: Oracle is never invoked. The post-wave gate still requires
100
102
  * `oracleVerified` — set it manually via `omo_recall` if you need it.
package/dist/health.d.ts CHANGED
@@ -32,6 +32,7 @@ export interface PluginHealth {
32
32
  /** v0.35.0 (Tier 3 watcher): count of new SKILL.md files detected under
33
33
  * cwd/.agents/skills/. Increments per create/write event from chokidar. */
34
34
  tier3SkillsCreated: number;
35
+ directivesIgnored: number;
35
36
  lastDecisionISO: string | null;
36
37
  lastInterventionISO: string | null;
37
38
  };