Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(omp): look past a routes section that lists no routes

Kyle Elliottc3f3af6cd507
diff --git a/cli/beacon/internal/endpoint/hooks/assets/omp/beacon.ts b/cli/beacon/internal/endpoint/hooks/assets/omp/beacon.ts
index 0b5fabad..36355ef0 100644
--- a/cli/beacon/internal/endpoint/hooks/assets/omp/beacon.ts
+++ b/cli/beacon/internal/endpoint/hooks/assets/omp/beacon.ts
@@ -101,7 +101,7 @@ const skillsSection = /^# Skills & Rules\n(?:[^\n]*\n){0,3}?<skills>\n([\s\S]*?)
// tool's description when its server gave one -- Oh My Pi's summary of it, which is the text the
// model reads before deciding to call the tool. Anchored to the heading for the same reason as
// skillsSection.
-const mcpToolRoutesSection = /^## MCP Tool Routes\n(?:(?!- )[^\n]*\n){0,3}((?:- [^\n]*(?:\n|$))+)/m
+const mcpToolRoutesSection = /^## MCP Tool Routes\n(?:(?!- )[^\n]*\n){0,3}((?:- [^\n]*(?:\n|$))+)/gm
const mcpToolRouteRow = /^- "[^"]+" → `xd:\/\/(mcp__[^`]+)` — (.+)$/
// How many routes one listing carries. A session with more MCP tools than this has its first ones
@@ -151,17 +151,21 @@ function skillListing(prompt: string[]): string {
// The MCP tool routes the model was shown, each as the device name the model calls and the
// description its row carries. A route without a description is left out: it advertises nothing a
// rule could read.
+//
+// A section under the same heading that yields no routes -- operator text in a context file that
+// borrows the heading for its own bullet list -- does not end the search, so it cannot hide the
+// runtime's own section after it.
function mcpToolRoutes(prompt: string[]): MCPToolRoute[] {
for (const block of prompt) {
- const rows = mcpToolRoutesSection.exec(block)?.[1]
- if (!rows) continue
- const routes: MCPToolRoute[] = []
- for (const row of rows.split("\n")) {
- const [, name, description] = mcpToolRouteRow.exec(row) ?? []
- if (name && description?.trim()) routes.push({ name, description: description.trim() })
- if (routes.length === maxMCPToolRoutes) break
+ for (const [, rows = ""] of block.matchAll(mcpToolRoutesSection)) {
+ const routes: MCPToolRoute[] = []
+ for (const row of rows.split("\n")) {
+ const [, name, description] = mcpToolRouteRow.exec(row) ?? []
+ if (name && description?.trim()) routes.push({ name, description: description.trim() })
+ if (routes.length === maxMCPToolRoutes) break
+ }
+ if (routes.length > 0) return routes
}
- return routes
}
return []
}
diff --git a/plugins/omp-beacon/src/beacon.test.ts b/plugins/omp-beacon/src/beacon.test.ts
index 45ba06b3..cf46a0d2 100644
--- a/plugins/omp-beacon/src/beacon.test.ts
+++ b/plugins/omp-beacon/src/beacon.test.ts
@@ -329,6 +329,26 @@ describe("beacon oh my pi extension", () => {
expect(sent).toHaveLength(0)
})
+ // A context file that borrows the heading for a list of its own, in an earlier block or earlier in
+ // the same block, does not hide the runtime's routes after it.
+ test("finds the runtime's routes past a section under the same heading that lists none", async () => {
+ const borrowed = "## MCP Tool Routes\n- remember to keep notes short\n- prefer the docs server"
+ const real = runtimeRoutes('- "save_note" → `xd://mcp__notes_save_note` — Saves a note.')
+ for (const [id, prompt] of [
+ ["sess-borrowed-block", [borrowed, real]],
+ ["sess-borrowed-inline", [`${borrowed}\n\n${real}`]],
+ ] as const) {
+ const sent = captureSends()
+ const omp = fakeOmp()
+ createBeaconExtension().register(omp.api)
+
+ await omp.fire({ type: "context", messages: [] }, session(id, { getSystemPrompt: () => [...prompt] }))
+
+ expect(sent).toHaveLength(1)
+ expect(sent[0].mcpToolRoutes).toEqual([{ name: "mcp__notes_save_note", description: "Saves a note." }])
+ }
+ })
+
test("forwards the event with its type intact", async () => {
const sent = captureSends()
const omp = fakeOmp()
diff --git a/plugins/omp-beacon/src/beacon.ts b/plugins/omp-beacon/src/beacon.ts
index 0b5fabad..36355ef0 100644
--- a/plugins/omp-beacon/src/beacon.ts
+++ b/plugins/omp-beacon/src/beacon.ts
@@ -101,7 +101,7 @@ const skillsSection = /^# Skills & Rules\n(?:[^\n]*\n){0,3}?<skills>\n([\s\S]*?)
// tool's description when its server gave one -- Oh My Pi's summary of it, which is the text the
// model reads before deciding to call the tool. Anchored to the heading for the same reason as
// skillsSection.
-const mcpToolRoutesSection = /^## MCP Tool Routes\n(?:(?!- )[^\n]*\n){0,3}((?:- [^\n]*(?:\n|$))+)/m
+const mcpToolRoutesSection = /^## MCP Tool Routes\n(?:(?!- )[^\n]*\n){0,3}((?:- [^\n]*(?:\n|$))+)/gm
const mcpToolRouteRow = /^- "[^"]+" → `xd:\/\/(mcp__[^`]+)` — (.+)$/
// How many routes one listing carries. A session with more MCP tools than this has its first ones
@@ -151,17 +151,21 @@ function skillListing(prompt: string[]): string {
// The MCP tool routes the model was shown, each as the device name the model calls and the
// description its row carries. A route without a description is left out: it advertises nothing a
// rule could read.
+//
+// A section under the same heading that yields no routes -- operator text in a context file that
+// borrows the heading for its own bullet list -- does not end the search, so it cannot hide the
+// runtime's own section after it.
function mcpToolRoutes(prompt: string[]): MCPToolRoute[] {
for (const block of prompt) {
- const rows = mcpToolRoutesSection.exec(block)?.[1]
- if (!rows) continue
- const routes: MCPToolRoute[] = []
- for (const row of rows.split("\n")) {
- const [, name, description] = mcpToolRouteRow.exec(row) ?? []
- if (name && description?.trim()) routes.push({ name, description: description.trim() })
- if (routes.length === maxMCPToolRoutes) break
+ for (const [, rows = ""] of block.matchAll(mcpToolRoutesSection)) {
+ const routes: MCPToolRoute[] = []
+ for (const row of rows.split("\n")) {
+ const [, name, description] = mcpToolRouteRow.exec(row) ?? []
+ if (name && description?.trim()) routes.push({ name, description: description.trim() })
+ if (routes.length === maxMCPToolRoutes) break
+ }
+ if (routes.length > 0) return routes
}
- return routes
}
return []
}