A self-organizing Obsidian vault that gives AI coding agents persistent memory.
TypeScript ai-agentsclaude-codecodex-cligemini-cliknowledge-managementobsidianobsidian-vaultpersistent-memorysecond-braintemplate
feat: classifier sub-hints — secondary discriminator on routing signals (#131)
Brenno Ferrari8e1ab042377b
diff --git a/.claude/scripts/lib/matcher.ts b/.claude/scripts/lib/matcher.tsindex 630c12c..6dd439d 100644--- a/.claude/scripts/lib/matcher.ts+++ b/.claude/scripts/lib/matcher.ts@@ -18,11 +18,17 @@ function compileMatcher(phrases: readonly string[]): RegExp {// Precomputed once per process. classify() runs on every UserPromptSubmit, so// avoiding per-call regex construction matters — 7 signals × ~20 patterns is// ~140 RegExp allocations saved per message.-const SIGNAL_MATCHERS: ReadonlyArray<{ message: string; regex: RegExp }> =- SIGNALS.map((s) => ({- message: s.message,- regex: compileMatcher(s.patterns),- }));+const SIGNAL_MATCHERS: ReadonlyArray<{+ message: string;+ regex: RegExp;+ subRegex: RegExp | null;+ subMessage: string | null;+}> = SIGNALS.map((s) => ({+ message: s.message,+ regex: compileMatcher(s.patterns),+ subRegex: s.subHint ? compileMatcher(s.subHint.patterns) : null,+ subMessage: s.subHint?.message ?? null,+}));export function anyWordMatch(phrases: readonly string[],@@ -35,8 +41,15 @@ export function anyWordMatch(export function classify(prompt: string): string[] {const lowered = prompt.toLowerCase();const messages: string[] = [];- for (const { message, regex } of SIGNAL_MATCHERS) {- if (regex.test(lowered)) messages.push(message);+ for (const { message, regex, subRegex, subMessage } of SIGNAL_MATCHERS) {+ if (!regex.test(lowered)) continue;+ messages.push(message);+ // Sub-hints (#111) evaluate only on a parent hit — two-pass and+ // cheap. Emitted as their own message so the once-per-session+ // dedupe keys parent and sub independently.+ if (subRegex !== null && subMessage !== null && subRegex.test(lowered)) {+ messages.push(subMessage);+ }}return messages;}diff --git a/.claude/scripts/lib/signals.ts b/.claude/scripts/lib/signals.tsindex e904942..665d1a8 100644--- a/.claude/scripts/lib/signals.ts+++ b/.claude/scripts/lib/signals.ts@@ -13,10 +13,22 @@* characters as word characters.*/+/**+ * Secondary discriminator on a signal (#111): evaluated only when the+ * parent signal matches, refining the routing hint within one class. The+ * sub-hint message is emitted IN ADDITION to the parent's; once-per-session+ * dedupe treats it as its own hint, so parent and sub fire independently.+ */+export type SubHint = {+ readonly patterns: readonly string[];+ readonly message: string;+};+export type Signal = {readonly name: string;readonly message: string;readonly patterns: readonly string[];+ readonly subHint?: SubHint;};export const SIGNALS: readonly Signal[] = [@@ -24,6 +36,18 @@ export const SIGNALS: readonly Signal[] = [name: "DECISION",message:"DECISION detected — consider creating a Decision Record in work/active/ and logging in work/Index.md Decisions Log",+ subHint: {+ message:+ "Looks like a decision REVERSAL — update the ORIGINAL Decision Record (status: superseded, link the new one) instead of only adding a second record; the correction-sweep rule applies to every note restating the old decision.",+ patterns: [+ "reversed",+ "superseded",+ "changed our mind",+ "rolled back the decision",+ "overturned",+ "un-decided",+ ],+ },patterns: [// English"decided",diff --git a/.claude/scripts/tests/matcher.test.ts b/.claude/scripts/tests/matcher.test.tsindex b983906..8e10aae 100644--- a/.claude/scripts/tests/matcher.test.ts+++ b/.claude/scripts/tests/matcher.test.ts@@ -5,7 +5,7 @@import { test, describe } from "node:test";import assert from "node:assert/strict";-import { anyWordMatch } from "../lib/matcher.ts";+import { anyWordMatch, classify } from "../lib/matcher.ts";describe("anyWordMatch", () => {test("basic match", () => {@@ -66,3 +66,21 @@ describe("anyWordMatch", () => {assert.equal(anyWordMatch(["hello"], ""), false);});});++describe("sub-hints (#111)", () => {+ test("sub-hint fires only alongside its parent signal", () => {+ const out = classify("we decided to reverse course — the old approach is superseded");+ assert.ok(out.some((m) => m.includes("DECISION detected")));+ assert.ok(out.some((m) => m.includes("REVERSAL")));+ });+ test("sub-hint patterns alone (no parent match) emit nothing", () => {+ const out = classify("the migration superseded the old pipeline");+ assert.ok(!out.some((m) => m.includes("DECISION detected")));+ assert.ok(!out.some((m) => m.includes("REVERSAL")));+ });+ test("parent without sub-hint patterns emits only the parent", () => {+ const out = classify("we decided to ship the feature");+ assert.ok(out.some((m) => m.includes("DECISION detected")));+ assert.ok(!out.some((m) => m.includes("REVERSAL")));+ });+});