From 694585a2bb0995b7da957860737bafbccb63d7d5 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 19 May 2026 18:03:16 +0100 Subject: [PATCH] Make Bifrost intake direct --- docs/agent-transport.md | 28 +- .../bifrost-intake/.codex-plugin/plugin.json | 3 +- plugins/bifrost-intake/.mcp.json | 12 - .../bifrost-intake/scripts/intake-context.mjs | 135 ++++++ plugins/bifrost-intake/scripts/mcp-server.mjs | 423 ------------------ .../skills/bifrost-intake/SKILL.md | 24 +- 6 files changed, 170 insertions(+), 455 deletions(-) delete mode 100644 plugins/bifrost-intake/.mcp.json create mode 100644 plugins/bifrost-intake/scripts/intake-context.mjs delete mode 100644 plugins/bifrost-intake/scripts/mcp-server.mjs diff --git a/docs/agent-transport.md b/docs/agent-transport.md index 8fcd120..c9930c8 100644 --- a/docs/agent-transport.md +++ b/docs/agent-transport.md @@ -60,23 +60,27 @@ The `snapshot` command writes a MessagePack-encoded `cultnet.snapshot_response_r ## Codex Intake Plugin -`plugins/bifrost-intake` exposes this lane to Codex as an MCP plugin. It does not own a second queue. Its server wraps `tools/agent-transport.mjs`. +`plugins/bifrost-intake` exposes this lane to Codex through direct scripts. It does not own a second queue, and the intake hot path does not depend on MCP tool mounting. -Tools: +Hot path: -- `get_intake_context` -- `enqueue_update_request` -- `list_update_requests` -- `claim_update_request` -- `close_update_request` -- `format_claimed_request` -- `create_transport_snapshot` -- `apply_transport_snapshot` +```powershell +node E:\Projects\Bifrost\plugins\bifrost-intake\scripts\intake-context.mjs --repo AetheriaLore --agent nibu +``` + +That command claims the next matching request for the current repo and prints a context packet immediately. If nothing is queued, it prints a direct no-work message so the agent can stop worrying about intake and continue the live turn. + +Lower-level CLI commands: + +- `tools/agent-transport.mjs enqueue` +- `tools/agent-transport.mjs list` +- `tools/agent-transport.mjs claim` +- `tools/agent-transport.mjs close` +- `tools/agent-transport.mjs snapshot` +- `tools/agent-transport.mjs apply-snapshot` The plugin is listed in `.agents/plugins/marketplace.json` as `bifrost-intake`. -`get_intake_context` is the normal Codex-facing entry point. It claims the next matching request for the current repo and returns a context packet immediately. If nothing is queued, it returns a direct no-work message so the agent can stop worrying about intake and continue the live turn. - ## Next Integration Points - Teach the VoidBot consensus feeder to enqueue Bifrost update requests after it writes a packet. diff --git a/plugins/bifrost-intake/.codex-plugin/plugin.json b/plugins/bifrost-intake/.codex-plugin/plugin.json index e598f55..4e1fe9b 100644 --- a/plugins/bifrost-intake/.codex-plugin/plugin.json +++ b/plugins/bifrost-intake/.codex-plugin/plugin.json @@ -18,11 +18,10 @@ "codex" ], "skills": "./skills/", - "mcpServers": "./.mcp.json", "interface": { "displayName": "Bifrost Intake", "shortDescription": "Claim and route Bifrost agent update requests", - "longDescription": "Expose Bifrost's CultCache-backed, CultNet-syncable agent transport lane to Codex so repo agents can enqueue, list, claim, close, and package update requests.", + "longDescription": "Expose Bifrost's CultCache-backed, CultNet-syncable agent transport lane to Codex through direct local scripts so repo agents can claim or dismiss intake without waiting on mounted tools.", "developerName": "GameCult", "category": "Coding", "capabilities": [ diff --git a/plugins/bifrost-intake/.mcp.json b/plugins/bifrost-intake/.mcp.json deleted file mode 100644 index 3effc29..0000000 --- a/plugins/bifrost-intake/.mcp.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "mcpServers": { - "bifrost-intake": { - "command": "node", - "args": ["E:/Projects/Bifrost/plugins/bifrost-intake/scripts/mcp-server.mjs"], - "env": { - "BIFROST_ROOT": "E:/Projects/Bifrost" - }, - "note": "Local Bifrost intake MCP server. Wraps Bifrost's CultCache/CultNet agent transport CLI." - } - } -} diff --git a/plugins/bifrost-intake/scripts/intake-context.mjs b/plugins/bifrost-intake/scripts/intake-context.mjs new file mode 100644 index 0000000..c2a3b5b --- /dev/null +++ b/plugins/bifrost-intake/scripts/intake-context.mjs @@ -0,0 +1,135 @@ +#!/usr/bin/env node +import { spawn } from "node:child_process"; +import { dirname, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; + +const pluginRoot = resolve(dirname(fileURLToPath(import.meta.url)), ".."); +const bifrostRoot = process.env.BIFROST_ROOT + ? resolve(process.env.BIFROST_ROOT) + : resolve(pluginRoot, "..", ".."); +const transportCli = resolve(bifrostRoot, "tools", "agent-transport.mjs"); + +async function main() { + const options = parseArgs(process.argv.slice(2)); + const repo = requireOption(options, "repo"); + const agent = optionalString(options.agent); + const claimedBy = optionalString(options["claimed-by"]) ?? agent ?? "codex"; + const claimed = await runTransport([ + "claim", + "--repo", repo, + ...optionalArg("--agent", agent), + "--claimed-by", claimedBy, + ...optionalArg("--store", options.store), + ]); + + if (!claimed) { + const face = agent ? ` for ${agent}` : ""; + process.stdout.write( + `No Bifrost intake requests are queued for ${repo}${face}. Do not stall on intake for this turn; continue with the user's direct request or the repo's normal next action.\n`, + ); + return; + } + + process.stdout.write(formatClaimedRequest(claimed)); + process.stdout.write("\n"); +} + +function formatClaimedRequest(request) { + return `# Bifrost Update Request + +ID: ${request.id} +Status: ${request.status} +Target repo: ${request.targetRepoName} +Target Face: ${request.targetAgentIdentity ?? "any"} +Priority: ${request.priority} +Title: ${request.title} + +## Request + +${request.requestMarkdown} + +## Handling + +Work only if this request matches the current repository jurisdiction. When finished, close the request through Bifrost intake and include the PR, commit, or cancellation reason in the close note.`; +} + +function runTransport(args) { + return new Promise((resolvePromise, rejectPromise) => { + const child = spawn(process.execPath, [transportCli, ...args], { + cwd: bifrostRoot, + windowsHide: true, + stdio: ["ignore", "pipe", "pipe"], + }); + + let stdout = ""; + let stderr = ""; + child.stdout.on("data", (chunk) => { + stdout += chunk.toString("utf8"); + }); + child.stderr.on("data", (chunk) => { + stderr += chunk.toString("utf8"); + }); + child.on("error", rejectPromise); + child.on("close", (code) => { + if (code !== 0) { + rejectPromise(new Error(stderr.trim() || `agent-transport exited with code ${code}`)); + return; + } + + try { + resolvePromise(JSON.parse(stdout)); + } catch { + rejectPromise(new Error(`agent-transport returned non-JSON output: ${stdout || stderr}`)); + } + }); + }); +} + +function parseArgs(args) { + const options = {}; + for (let index = 0; index < args.length; index += 1) { + const token = args[index]; + if (!token.startsWith("--")) { + throw new Error(`Unexpected argument "${token}".`); + } + + const key = token.slice(2); + const next = args[index + 1]; + if (!next || next.startsWith("--")) { + options[key] = "true"; + continue; + } + + options[key] = next; + index += 1; + } + + return options; +} + +function requireOption(options, name) { + const value = optionalString(options[name]); + if (!value) { + throw new Error(`Missing required option --${name}.`); + } + + return value; +} + +function optionalString(value) { + if (typeof value !== "string") { + return undefined; + } + + const trimmed = value.trim(); + return trimmed.length > 0 ? trimmed : undefined; +} + +function optionalArg(flag, value) { + return optionalString(value) ? [flag, optionalString(value)] : []; +} + +main().catch((error) => { + process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`); + process.exitCode = 1; +}); diff --git a/plugins/bifrost-intake/scripts/mcp-server.mjs b/plugins/bifrost-intake/scripts/mcp-server.mjs deleted file mode 100644 index 011c136..0000000 --- a/plugins/bifrost-intake/scripts/mcp-server.mjs +++ /dev/null @@ -1,423 +0,0 @@ -#!/usr/bin/env node -import { spawn } from "node:child_process"; -import { existsSync } from "node:fs"; -import { dirname, resolve } from "node:path"; -import { fileURLToPath } from "node:url"; - -const pluginRoot = resolve(dirname(fileURLToPath(import.meta.url)), ".."); -const bifrostRoot = resolveBifrostRoot(); -const transportCli = resolve(bifrostRoot, "tools", "agent-transport.mjs"); -const serverInfo = { name: "bifrost-intake", version: "0.1.0" }; - -const tools = [ - { - name: "get_intake_context", - description: "Claim the next matching Bifrost request and return a Codex-ready context packet, or say there is no queued intake work.", - inputSchema: { - type: "object", - additionalProperties: false, - required: ["repo"], - properties: { - repo: { type: "string", description: "Current repository short name, such as AetheriaLore." }, - agent: { type: "string", description: "Optional current Face identity, such as nibu." }, - claimedBy: { type: "string" }, - store: { type: "string" } - } - } - }, - { - name: "enqueue_update_request", - description: "Enqueue a Bifrost agent update request in the CultCache-backed intake store.", - inputSchema: { - type: "object", - additionalProperties: false, - required: ["repo", "title", "requestMarkdown"], - properties: { - repo: { type: "string", description: "Target repository short name, such as AetheriaLore." }, - agent: { type: "string", description: "Optional target Face identity, such as nibu." }, - title: { type: "string" }, - requestMarkdown: { type: "string", description: "Consensus/task packet to inject when claimed." }, - priority: { type: "integer", default: 50 }, - repoFullName: { type: "string" }, - sourceKind: { type: "string", default: "codex" }, - sourceChannelId: { type: "string" }, - sourceMessageIds: { type: "array", items: { type: "string" } }, - sourcePacketPath: { type: "string" }, - sourcePromptPath: { type: "string" }, - createdBy: { type: "string" }, - store: { type: "string", description: "Optional override path for the .cc store." } - } - } - }, - { - name: "list_update_requests", - description: "List Bifrost agent update requests, optionally filtered by repo, Face, or status.", - inputSchema: { - type: "object", - additionalProperties: false, - properties: { - repo: { type: "string" }, - agent: { type: "string" }, - status: { type: "string", enum: ["queued", "claimed", "completed", "cancelled"] }, - store: { type: "string" } - } - } - }, - { - name: "claim_update_request", - description: "Claim the highest-priority queued request for a repository jurisdiction.", - inputSchema: { - type: "object", - additionalProperties: false, - required: ["repo"], - properties: { - repo: { type: "string" }, - agent: { type: "string" }, - claimedBy: { type: "string" }, - store: { type: "string" } - } - } - }, - { - name: "close_update_request", - description: "Mark a Bifrost update request completed or cancelled.", - inputSchema: { - type: "object", - additionalProperties: false, - required: ["id", "status"], - properties: { - id: { type: "string" }, - status: { type: "string", enum: ["completed", "cancelled"] }, - note: { type: "string" }, - store: { type: "string" } - } - } - }, - { - name: "format_claimed_request", - description: "Return a Codex-ready prompt packet for a claimed update request id.", - inputSchema: { - type: "object", - additionalProperties: false, - required: ["id"], - properties: { - id: { type: "string" }, - store: { type: "string" } - } - } - }, - { - name: "create_transport_snapshot", - description: "Write a CultNet raw snapshot of the Bifrost intake store.", - inputSchema: { - type: "object", - additionalProperties: false, - required: ["out"], - properties: { - out: { type: "string" }, - messageId: { type: "string" }, - store: { type: "string" } - } - } - }, - { - name: "apply_transport_snapshot", - description: "Apply a CultNet raw snapshot into the Bifrost intake store.", - inputSchema: { - type: "object", - additionalProperties: false, - required: ["in"], - properties: { - in: { type: "string" }, - store: { type: "string" } - } - } - } -]; - -let inputBuffer = Buffer.alloc(0); - -process.stdin.on("data", (chunk) => { - inputBuffer = Buffer.concat([inputBuffer, chunk]); - drainMessages().catch((error) => { - sendError(null, -32603, error.message); - }); -}); - -async function drainMessages() { - while (true) { - const headerEnd = inputBuffer.indexOf("\r\n\r\n"); - if (headerEnd === -1) { - return; - } - - const header = inputBuffer.subarray(0, headerEnd).toString("utf8"); - const lengthMatch = /^Content-Length:\s*(\d+)/imu.exec(header); - if (!lengthMatch) { - throw new Error("MCP message is missing Content-Length header."); - } - - const length = Number(lengthMatch[1]); - const bodyStart = headerEnd + 4; - const bodyEnd = bodyStart + length; - if (inputBuffer.length < bodyEnd) { - return; - } - - const rawBody = inputBuffer.subarray(bodyStart, bodyEnd).toString("utf8"); - inputBuffer = inputBuffer.subarray(bodyEnd); - await handleMessage(JSON.parse(rawBody)); - } -} - -async function handleMessage(message) { - if (!Object.prototype.hasOwnProperty.call(message, "id")) { - return; - } - - try { - switch (message.method) { - case "initialize": - sendResult(message.id, { - protocolVersion: message.params?.protocolVersion ?? "2024-11-05", - capabilities: { tools: {} }, - serverInfo, - }); - return; - case "tools/list": - sendResult(message.id, { tools }); - return; - case "tools/call": - sendResult(message.id, await callTool(message.params ?? {})); - return; - case "ping": - sendResult(message.id, {}); - return; - default: - sendError(message.id, -32601, `Unknown method "${message.method}".`); - } - } catch (error) { - sendError(message.id, -32603, error instanceof Error ? error.message : String(error)); - } -} - -async function callTool(params) { - const name = params.name; - const args = params.arguments ?? {}; - - switch (name) { - case "get_intake_context": - return textToolResult(await getIntakeContext(args)); - case "enqueue_update_request": - return jsonToolResult(await runTransport([ - "enqueue", - "--repo", requireString(args.repo, "repo"), - ...optionalArg("--agent", args.agent), - "--title", requireString(args.title, "title"), - "--request", requireString(args.requestMarkdown, "requestMarkdown"), - "--priority", String(args.priority ?? 50), - ...optionalArg("--repo-full-name", args.repoFullName), - ...optionalArg("--source-kind", args.sourceKind ?? "codex"), - ...optionalArg("--source-channel-id", args.sourceChannelId), - ...optionalArg("--source-message-ids", Array.isArray(args.sourceMessageIds) ? args.sourceMessageIds.join(",") : undefined), - ...optionalArg("--packet-path", args.sourcePacketPath), - ...optionalArg("--prompt-path", args.sourcePromptPath), - ...optionalArg("--created-by", args.createdBy), - ...storeArg(args.store), - ])); - case "list_update_requests": - return jsonToolResult(await runTransport([ - "list", - ...optionalArg("--repo", args.repo), - ...optionalArg("--agent", args.agent), - ...optionalArg("--status", args.status), - ...storeArg(args.store), - ])); - case "claim_update_request": - return jsonToolResult(await runTransport([ - "claim", - "--repo", requireString(args.repo, "repo"), - ...optionalArg("--agent", args.agent), - ...optionalArg("--claimed-by", args.claimedBy), - ...storeArg(args.store), - ])); - case "close_update_request": - return jsonToolResult(await runTransport([ - "close", - "--id", requireString(args.id, "id"), - "--status", requireString(args.status, "status"), - ...optionalArg("--note", args.note), - ...storeArg(args.store), - ])); - case "format_claimed_request": - return textToolResult(formatClaimedRequest(await requireRequestById(args))); - case "create_transport_snapshot": - return jsonToolResult(await runTransport([ - "snapshot", - "--out", requireString(args.out, "out"), - ...optionalArg("--message-id", args.messageId), - ...storeArg(args.store), - ])); - case "apply_transport_snapshot": - return jsonToolResult(await runTransport([ - "apply-snapshot", - "--in", requireString(args.in, "in"), - ...storeArg(args.store), - ])); - default: - throw new Error(`Unknown tool "${name}".`); - } -} - -async function getIntakeContext(args) { - const repo = requireString(args.repo, "repo"); - const claimed = await runTransport([ - "claim", - "--repo", repo, - ...optionalArg("--agent", args.agent), - ...optionalArg("--claimed-by", args.claimedBy ?? args.agent), - ...storeArg(args.store), - ]); - - if (!claimed) { - const face = typeof args.agent === "string" && args.agent.trim().length > 0 - ? ` for ${args.agent.trim()}` - : ""; - return `No Bifrost intake requests are queued for ${repo}${face}. Do not stall on intake for this turn; continue with the user's direct request or the repo's normal next action.`; - } - - return formatClaimedRequest(claimed); -} - -async function requireRequestById(args) { - const id = requireString(args.id, "id"); - const requests = await runTransport(["list", ...storeArg(args.store)]); - const request = requests.find((candidate) => candidate.id === id); - if (!request) { - throw new Error(`No Bifrost update request found for id "${id}".`); - } - return request; -} - -function formatClaimedRequest(request) { - return `# Bifrost Update Request - -ID: ${request.id} -Status: ${request.status} -Target repo: ${request.targetRepoName} -Target Face: ${request.targetAgentIdentity ?? "any"} -Priority: ${request.priority} -Title: ${request.title} - -## Request - -${request.requestMarkdown} - -## Handling - -Work only if this request matches the current repository jurisdiction. When finished, close the request through Bifrost intake and include the PR, commit, or cancellation reason in the close note.`; -} - -function runTransport(args) { - return new Promise((resolvePromise, rejectPromise) => { - const child = spawn(process.execPath, [transportCli, ...args], { - cwd: bifrostRoot, - windowsHide: true, - stdio: ["ignore", "pipe", "pipe"], - }); - let stdout = ""; - let stderr = ""; - child.stdout.on("data", (chunk) => { - stdout += chunk.toString("utf8"); - }); - child.stderr.on("data", (chunk) => { - stderr += chunk.toString("utf8"); - }); - child.on("error", rejectPromise); - child.on("close", (code) => { - if (code !== 0) { - rejectPromise(new Error(stderr.trim() || `agent-transport exited with code ${code}`)); - return; - } - - try { - resolvePromise(JSON.parse(stdout)); - } catch (error) { - rejectPromise(new Error(`agent-transport returned non-JSON output: ${stdout || stderr}`)); - } - }); - }); -} - -function jsonToolResult(value) { - return { - content: [ - { - type: "text", - text: JSON.stringify(value, null, 2), - }, - ], - }; -} - -function textToolResult(text) { - return { - content: [ - { - type: "text", - text, - }, - ], - }; -} - -function optionalArg(flag, value) { - if (typeof value !== "string" || value.trim().length === 0) { - return []; - } - return [flag, value.trim()]; -} - -function storeArg(value) { - return optionalArg("--store", value); -} - -function requireString(value, name) { - if (typeof value !== "string" || value.trim().length === 0) { - throw new Error(`Missing required argument "${name}".`); - } - return value.trim(); -} - -function sendResult(id, result) { - sendMessage({ jsonrpc: "2.0", id, result }); -} - -function sendError(id, code, message) { - sendMessage({ jsonrpc: "2.0", id, error: { code, message } }); -} - -function sendMessage(message) { - const body = Buffer.from(JSON.stringify(message), "utf8"); - process.stdout.write(`Content-Length: ${body.length}\r\n\r\n`); - process.stdout.write(body); -} - -function resolveBifrostRoot() { - const candidates = [ - process.env.BIFROST_ROOT, - resolve(pluginRoot, "..", ".."), - "E:/Projects/Bifrost", - ].filter((candidate) => typeof candidate === "string" && candidate.trim().length > 0); - - for (const candidate of candidates) { - const root = resolve(candidate); - if (existsSync(resolve(root, "tools", "agent-transport.mjs"))) { - return root; - } - } - - throw new Error( - "Could not find Bifrost root. Set BIFROST_ROOT to the repository that contains tools/agent-transport.mjs.", - ); -} diff --git a/plugins/bifrost-intake/skills/bifrost-intake/SKILL.md b/plugins/bifrost-intake/skills/bifrost-intake/SKILL.md index 4106a0f..5a520ec 100644 --- a/plugins/bifrost-intake/skills/bifrost-intake/SKILL.md +++ b/plugins/bifrost-intake/skills/bifrost-intake/SKILL.md @@ -1,19 +1,31 @@ --- name: bifrost-intake -description: Use when Codex should enqueue, list, claim, close, or package Bifrost agent update requests for repo Faces through the Bifrost intake MCP tools. +description: Use when Codex should instantly check Bifrost intake for repo Face update requests, inject any claimed request into context, or stand down when no request is queued. --- # Bifrost Intake -Bifrost owns agent update request semantics. CultCache stores the request documents. CultNet moves raw snapshots and document updates. This plugin exposes that lane to Codex through MCP tools. +Bifrost owns agent update request semantics. CultCache stores the request documents. CultNet moves raw snapshots and document updates. This plugin exposes the intake hot path to Codex through direct local scripts, not mounted MCP tools. -Use these tools when a user asks to feed a consensus packet to a repo Face, claim work for the current repo, inspect queued update requests, or close a request after work is handled. +Use this skill when a user asks to feed a consensus packet to a repo Face, claim work for the current repo, inspect queued update requests, or close a request after work is handled. + +Do not wait for MCP tool discovery. Do not tell the user the backend is unavailable merely because `tool_search` cannot find Bifrost tools. + +Hot path: + +```powershell +node E:\Projects\Bifrost\plugins\bifrost-intake\scripts\intake-context.mjs --repo --agent +``` + +That command claims the highest-priority queued Bifrost request matching the repo and Face, then prints a Codex-ready context packet. If nothing is queued, it prints an explicit no-work message telling the agent to continue the live turn without worrying about intake. + +Use `--claimed-by ` when the claiming identity should differ from `--agent`. Default flow: -1. Use `get_intake_context` at the start of a repo-agent turn when the agent should check Bifrost intake. -2. If it returns a request packet, treat that packet as live context for the turn. +1. Run `intake-context.mjs` at the start of a repo-agent turn when the agent should check Bifrost intake. +2. If it prints a request packet, treat that packet as live context for the turn. 3. If it says no request is queued, do not ask the user what to do because of intake; continue with the user's direct request or the repo's normal next action. -4. Use `close_update_request` when the claimed work is completed or cancelled. +4. Use `node E:\Projects\Bifrost\tools\agent-transport.mjs close --id --status completed --note ""` when the claimed work is completed, or `--status cancelled` with a reason when it should be dropped. Do not store a parallel queue in VoidBot or Codex session memory. If the request is intended to persist, put it in Bifrost intake.