Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ members = [
]

[workspace.package]
version = "0.3.6"
version = "0.3.7"
edition = "2021"
license = "MIT"
repository = "https://github.com/DevVig/microbridge"
Expand Down
1 change: 1 addition & 0 deletions adapters/cursor/hooks/event.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function lifecycleMessages(event, now = Date.now()) {
title: event.title,
state,
updated_at_ms: now,
focus_uri: event.workspace ? `cursor://file${event.workspace}` : null,
},
ttl_ms: event.lifecycle === "session_end" ? 1_000 : 30 * 60 * 1_000,
},
Expand Down
105 changes: 105 additions & 0 deletions adapters/sdk/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// @microbridge/adapter-sdk
// Zero-dependency Node.js/JS SDK for building Microbridge adapters.

import net from "node:net";
import os from "node:os";
import path from "node:path";

export class MicrobridgeAdapter {
constructor({ id, version = "1.0.0", capabilities = {} }) {
this.id = id;
this.version = version;
this.capabilities = {
lifecycle_observation: true,
approval_acceptance: false,
approval_rejection: false,
interrupt: false,
new_session: false,
focus_open: false,
reasoning_effort: false,
tty_control: false,
mcp_native: false,
uri_focus: false,
...capabilities,
};

this.socketPath =
process.env.MICROBRIDGE_SOCKET ||
path.join(os.homedir(), ".microbridge", "microbridged.sock");
this.socket = null;
this.actionListeners = new Map();
}

connect() {
return new Promise((resolve, reject) => {
this.socket = net.createConnection(this.socketPath, () => {
const hello = {
type: "hello",
adapter: this.id,
protocol_version: 0,
adapter_version: this.version,
capabilities: this.capabilities,
};
this.socket.write(`${JSON.stringify(hello)}\n`);
resolve(true);
});

this.socket.on("error", (err) => {
reject(err);
});

let buffer = "";
this.socket.on("data", (chunk) => {
buffer += chunk.toString("utf8");
const lines = buffer.split("\n");
buffer = lines.pop();
for (const line of lines) {
if (!line.trim()) continue;
try {
const msg = JSON.parse(line);
if (msg.type === "action") {
const handler = this.actionListeners.get(msg.action);
if (handler) handler(msg.session_id);
}
} catch (_) {}
}
});
});
}

reportStatus({ id, app, title = "", state, focusUri }) {
if (!this.socket || !this.socket.writable) return;
const msg = {
type: "status",
session: {
id: `${this.id}:${id}`,
app: app || this.id,
title,
state,
updated_at_ms: Date.now(),
focus_uri: focusUri || null,
},
};
this.socket.write(`${JSON.stringify(msg)}\n`);
}

reportBye(id) {
if (!this.socket || !this.socket.writable) return;
const msg = {
type: "bye",
session_id: `${this.id}:${id}`,
};
this.socket.write(`${JSON.stringify(msg)}\n`);
}

onAction(actionName, callback) {
this.actionListeners.set(actionName, callback);
}

disconnect() {
if (this.socket) {
this.socket.end();
this.socket = null;
}
}
}
19 changes: 19 additions & 0 deletions adapters/sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@microbridge/adapter-sdk",
"version": "0.3.7",
"description": "Zero-dependency SDK for publishing AI agent session states to Microbridge",
"main": "index.mjs",
"type": "module",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/DevVig/microbridge.git"
},
"keywords": [
"microbridge",
"agent",
"macropad",
"codex-micro",
"adapter"
]
}
2 changes: 1 addition & 1 deletion apps/microbridge-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "microbridge-ui",
"private": true,
"version": "0.3.6",
"version": "0.3.7",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
Loading
Loading