bridge-agent 0.4.8 → 0.5.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.
@@ -1299,21 +1299,21 @@ var require_errors = __commonJS({
1299
1299
  function extendErrors({ gen, keyword, schemaValue, data, errsCount, it }) {
1300
1300
  if (errsCount === void 0)
1301
1301
  throw new Error("ajv implementation error");
1302
- const err3 = gen.name("err");
1302
+ const err4 = gen.name("err");
1303
1303
  gen.forRange("i", errsCount, names_1.default.errors, (i) => {
1304
- gen.const(err3, (0, codegen_1._)`${names_1.default.vErrors}[${i}]`);
1305
- gen.if((0, codegen_1._)`${err3}.instancePath === undefined`, () => gen.assign((0, codegen_1._)`${err3}.instancePath`, (0, codegen_1.strConcat)(names_1.default.instancePath, it.errorPath)));
1306
- gen.assign((0, codegen_1._)`${err3}.schemaPath`, (0, codegen_1.str)`${it.errSchemaPath}/${keyword}`);
1304
+ gen.const(err4, (0, codegen_1._)`${names_1.default.vErrors}[${i}]`);
1305
+ gen.if((0, codegen_1._)`${err4}.instancePath === undefined`, () => gen.assign((0, codegen_1._)`${err4}.instancePath`, (0, codegen_1.strConcat)(names_1.default.instancePath, it.errorPath)));
1306
+ gen.assign((0, codegen_1._)`${err4}.schemaPath`, (0, codegen_1.str)`${it.errSchemaPath}/${keyword}`);
1307
1307
  if (it.opts.verbose) {
1308
- gen.assign((0, codegen_1._)`${err3}.schema`, schemaValue);
1309
- gen.assign((0, codegen_1._)`${err3}.data`, data);
1308
+ gen.assign((0, codegen_1._)`${err4}.schema`, schemaValue);
1309
+ gen.assign((0, codegen_1._)`${err4}.data`, data);
1310
1310
  }
1311
1311
  });
1312
1312
  }
1313
1313
  exports2.extendErrors = extendErrors;
1314
1314
  function addError(gen, errObj) {
1315
- const err3 = gen.const("err", errObj);
1316
- gen.if((0, codegen_1._)`${names_1.default.vErrors} === null`, () => gen.assign(names_1.default.vErrors, (0, codegen_1._)`[${err3}]`), (0, codegen_1._)`${names_1.default.vErrors}.push(${err3})`);
1315
+ const err4 = gen.const("err", errObj);
1316
+ gen.if((0, codegen_1._)`${names_1.default.vErrors} === null`, () => gen.assign(names_1.default.vErrors, (0, codegen_1._)`[${err4}]`), (0, codegen_1._)`${names_1.default.vErrors}.push(${err4})`);
1317
1317
  gen.code((0, codegen_1._)`${names_1.default.errors}++`);
1318
1318
  }
1319
1319
  function returnErrors(it, errs) {
@@ -7541,8 +7541,8 @@ var ZodType = class {
7541
7541
  } : {
7542
7542
  issues: ctx.common.issues
7543
7543
  };
7544
- } catch (err3) {
7545
- if (err3?.message?.toLowerCase()?.includes("encountered")) {
7544
+ } catch (err4) {
7545
+ if (err4?.message?.toLowerCase()?.includes("encountered")) {
7546
7546
  this["~standard"].async = true;
7547
7547
  }
7548
7548
  ctx.common = {
@@ -21243,16 +21243,16 @@ var handleFetchError = (e) => new Response(null, {
21243
21243
  status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500
21244
21244
  });
21245
21245
  var handleResponseError = (e, outgoing) => {
21246
- const err3 = e instanceof Error ? e : new Error("unknown error", { cause: e });
21247
- if (err3.code === "ERR_STREAM_PREMATURE_CLOSE") {
21246
+ const err4 = e instanceof Error ? e : new Error("unknown error", { cause: e });
21247
+ if (err4.code === "ERR_STREAM_PREMATURE_CLOSE") {
21248
21248
  console.info("The user aborted a request.");
21249
21249
  } else {
21250
21250
  console.error(e);
21251
21251
  if (!outgoing.headersSent) {
21252
21252
  outgoing.writeHead(500, { "Content-Type": "text/plain" });
21253
21253
  }
21254
- outgoing.end(`Error: ${err3.message}`);
21255
- outgoing.destroy(err3);
21254
+ outgoing.end(`Error: ${err4.message}`);
21255
+ outgoing.destroy(err4);
21256
21256
  }
21257
21257
  };
21258
21258
  var flushHeaders = (outgoing) => {
@@ -21309,8 +21309,8 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
21309
21309
  if (options.errorHandler) {
21310
21310
  try {
21311
21311
  res = await res;
21312
- } catch (err3) {
21313
- const errRes = await options.errorHandler(err3);
21312
+ } catch (err4) {
21313
+ const errRes = await options.errorHandler(err4);
21314
21314
  if (!errRes) {
21315
21315
  return;
21316
21316
  }
@@ -22391,10 +22391,13 @@ async function getAgentIdle(ctx, agentId) {
22391
22391
  }
22392
22392
  async function recordProjectEvent(ctx, params) {
22393
22393
  const { projectId, ...body } = params;
22394
+ const explicitProjectId = projectId?.trim();
22395
+ const isWorkspaceScope = ctx.projectId === "workspace" && !explicitProjectId;
22396
+ const url = isWorkspaceScope ? workspacePath(ctx, "/events") : projectPath(ctx, "/events", explicitProjectId);
22394
22397
  return request(
22395
22398
  ctx,
22396
22399
  "POST",
22397
- projectPath(ctx, "/events", projectId),
22400
+ url,
22398
22401
  { ...body, agentId: ctx.agentId }
22399
22402
  );
22400
22403
  }
@@ -22414,6 +22417,44 @@ async function getProjectEvents(ctx, opts) {
22414
22417
  projectPath(ctx, `/events${qs ? "?" + qs : ""}`, opts?.projectId)
22415
22418
  );
22416
22419
  }
22420
+ async function listPersonas(ctx, opts) {
22421
+ const params = new URLSearchParams();
22422
+ if (opts.projectId) params.set("projectId", opts.projectId);
22423
+ if (opts.scope) params.set("scope", opts.scope);
22424
+ if (opts.includeArchived) params.set("includeArchived", "true");
22425
+ if (opts.excludePersonal) params.set("excludePersonal", "true");
22426
+ if (opts.agentKey) params.set("agentKey", opts.agentKey);
22427
+ if (opts.role) params.set("role", opts.role);
22428
+ if (opts.tag) params.set("tag", opts.tag);
22429
+ if (opts.q) params.set("q", opts.q);
22430
+ if (opts.limit) params.set("pageSize", String(opts.limit));
22431
+ const qs = params.toString();
22432
+ return request(ctx, "GET", workspacePath(ctx, `/personas${qs ? "?" + qs : ""}`));
22433
+ }
22434
+ async function getPersona(ctx, params) {
22435
+ return request(ctx, "GET", workspacePath(ctx, `/personas/${encodeURIComponent(params.id)}`));
22436
+ }
22437
+ async function createPersona(ctx, params) {
22438
+ const body = { ...params, scope: params.projectId ? "project" : "workspace" };
22439
+ return request(ctx, "POST", workspacePath(ctx, "/personas"), body);
22440
+ }
22441
+ async function updatePersona(ctx, params) {
22442
+ const { id, ...body } = params;
22443
+ return request(ctx, "PATCH", workspacePath(ctx, `/personas/${encodeURIComponent(id)}`), body);
22444
+ }
22445
+ async function archivePersona(ctx, id) {
22446
+ return request(ctx, "POST", workspacePath(ctx, `/personas/${encodeURIComponent(id)}/archive`));
22447
+ }
22448
+ async function launchPersona(ctx, params) {
22449
+ const { id, projectId, ...rest } = params;
22450
+ const trimmed = projectId?.trim();
22451
+ const pid = trimmed || ctx.projectId;
22452
+ if (pid === "workspace") {
22453
+ throw new Error("launchPersona requires a real projectId \u2014 cannot launch into workspace scope");
22454
+ }
22455
+ const body = pid ? { ...rest, projectId: pid } : rest;
22456
+ return request(ctx, "POST", workspacePath(ctx, `/personas/${encodeURIComponent(id)}/launch`), body);
22457
+ }
22417
22458
 
22418
22459
  // ../mcp-server/src/tools/plan.ts
22419
22460
  function registerPlanTools(server, ctx) {
@@ -22542,6 +22583,31 @@ function registerTodoTools(server, ctx) {
22542
22583
  );
22543
22584
  }
22544
22585
 
22586
+ // ../shared/dist/types.js
22587
+ var ALL_AGENT_KEYS = [
22588
+ "sh",
22589
+ "claude",
22590
+ "codex",
22591
+ "qwen",
22592
+ "kimi",
22593
+ "gemini",
22594
+ "ollama",
22595
+ "aider",
22596
+ "forge",
22597
+ "sim_ios"
22598
+ ];
22599
+ var AGENT_ROLES = [
22600
+ "developer",
22601
+ "reviewer",
22602
+ "planner",
22603
+ "executor",
22604
+ "shell",
22605
+ "runner",
22606
+ "orchestrator"
22607
+ ];
22608
+ var USER_ASSIGNABLE_ROLES = AGENT_ROLES.filter((r) => r !== "orchestrator");
22609
+ var EVENT_ROLES = [...AGENT_ROLES, "system"];
22610
+
22545
22611
  // ../mcp-server/src/tools/orchestration.ts
22546
22612
  function ok(data) {
22547
22613
  return { content: [{ type: "text", text: JSON.stringify(data) }] };
@@ -22612,7 +22678,7 @@ function registerOrchestrationTools(server, ctx) {
22612
22678
  {
22613
22679
  agentKey: external_exports.string().describe("Agent type: claude, codex, sh, qwen, gemini, ollama, aider"),
22614
22680
  daemonId: external_exports.string().optional().describe("Target machine ID. Omit to use the workspace default machine."),
22615
- role: external_exports.string().optional().describe("Panel role: developer, reviewer, planner, executor, shell, runner"),
22681
+ role: external_exports.enum(USER_ASSIGNABLE_ROLES).optional().describe(`Panel role: ${USER_ASSIGNABLE_ROLES.join(", ")}`),
22616
22682
  cmd: external_exports.string().max(512).optional().describe('Command to run after spawn (sh panels only, e.g. "npm run dev"). Sets role to runner automatically.')
22617
22683
  },
22618
22684
  ({ agentKey, daemonId, role, cmd }) => safe(() => spawnAgent(ctx, agentKey, daemonId, role, cmd))
@@ -22666,7 +22732,7 @@ function registerOrchestrationTools(server, ctx) {
22666
22732
  );
22667
22733
  server.tool(
22668
22734
  "bridge_record_event",
22669
- "Append an event to the project event log. Use to record decisions, discoveries, phase completions, or blockers so future agents and runs have durable context. Events are separate from run history \u2014 they persist across runs and are queryable by role/type/tag. Suggested eventTypes: decision, discovery, blocker, phase_complete, note, warning. Pass projectId to target a specific project (orchestrator must always pass it; per-project workers can omit).",
22735
+ "Append an event to the project event log. Use to record decisions, discoveries, phase completions, or blockers so future agents and runs have durable context. Events are separate from run history \u2014 they persist across runs and are queryable by role/type/tag. Suggested eventTypes: decision, discovery, blocker, phase_complete, note, warning. Pass projectId to target a specific project (orchestrator must always pass it for project events; without projectId the event lands in the workspace log and is not tied to a specific project).",
22670
22736
  {
22671
22737
  eventType: external_exports.string().min(1).max(64).describe("Free-form event type slug (e.g. decision, blocker, phase_complete)"),
22672
22738
  summary: external_exports.string().min(1).max(512).describe("Human-readable event summary (max 512 chars)"),
@@ -22768,6 +22834,12 @@ function registerWorkspaceTools(server, ctx) {
22768
22834
  {},
22769
22835
  () => safe2(() => request(ctx, "GET", workspacePath(ctx, "/projects")))
22770
22836
  );
22837
+ server.tool(
22838
+ "bridge_get_project",
22839
+ "Get the current project details: id, name, description, cwd, machineId. Use this to confirm which project context the caller is operating in.",
22840
+ {},
22841
+ () => safe2(() => getProject(ctx))
22842
+ );
22771
22843
  server.tool(
22772
22844
  "bridge_query_workspace",
22773
22845
  "Natural-language query about orchestration state (runs, todos, failures). No LLM involved \u2014 deterministic answer.",
@@ -22797,6 +22869,114 @@ function registerWorkspaceTools(server, ctx) {
22797
22869
  );
22798
22870
  }
22799
22871
 
22872
+ // ../mcp-server/src/tools/personas.ts
22873
+ function ok3(data) {
22874
+ return { content: [{ type: "text", text: JSON.stringify(data) }] };
22875
+ }
22876
+ function err3(message) {
22877
+ return { content: [{ type: "text", text: JSON.stringify({ ok: false, error: message }) }] };
22878
+ }
22879
+ async function safe3(fn) {
22880
+ try {
22881
+ return ok3(await fn());
22882
+ } catch (e) {
22883
+ const message = e instanceof Error ? e.message : String(e);
22884
+ if (e instanceof Error && (e.name === "TypeError" || e.name === "ReferenceError")) {
22885
+ console.error("[mcp-bridge] unexpected error in persona tool handler", { name: e.name, message, stack: e.stack });
22886
+ }
22887
+ return err3(message);
22888
+ }
22889
+ }
22890
+ var ListPersonasSchema = external_exports.object({
22891
+ projectId: external_exports.string().min(1).optional().describe("Filter to project scope. Defaults to caller panel's project."),
22892
+ scope: external_exports.enum(["personal", "workspace", "project", "all"]).optional().describe("Scope filter (default: all)"),
22893
+ includeArchived: external_exports.boolean().optional(),
22894
+ excludePersonal: external_exports.boolean().optional().describe("Exclude personal-scoped personas from results (useful for orchestrator workspace-wide queries)"),
22895
+ agentKey: external_exports.enum(ALL_AGENT_KEYS).optional(),
22896
+ role: external_exports.enum(USER_ASSIGNABLE_ROLES).optional(),
22897
+ tag: external_exports.string().optional(),
22898
+ q: external_exports.string().optional().describe("Substring search on name+description"),
22899
+ limit: external_exports.number().int().min(1).max(200).optional()
22900
+ });
22901
+ var GetPersonaSchema = external_exports.object({
22902
+ id: external_exports.string().min(1).describe("Persona id (UUID)"),
22903
+ projectId: external_exports.string().min(1).optional()
22904
+ });
22905
+ var CreatePersonaSchema = external_exports.object({
22906
+ name: external_exports.string().min(1).max(80),
22907
+ slug: external_exports.string().min(1).max(63).regex(/^[a-z][a-z0-9_]*$/),
22908
+ description: external_exports.string().max(200).optional(),
22909
+ agentKey: external_exports.enum(ALL_AGENT_KEYS),
22910
+ role: external_exports.enum(USER_ASSIGNABLE_ROLES),
22911
+ systemPrompt: external_exports.string().max(4e3).optional(),
22912
+ defaultCwd: external_exports.string().optional(),
22913
+ defaultDaemonId: external_exports.string().optional(),
22914
+ color: external_exports.string().regex(/^#[0-9a-f]{6}$/i).optional(),
22915
+ icon: external_exports.string().optional(),
22916
+ tags: external_exports.array(external_exports.string()).max(10).optional(),
22917
+ projectId: external_exports.string().min(1).optional().describe("Make this a project-scoped persona. Omit for workspace-scoped.")
22918
+ });
22919
+ var UpdatePersonaSchema = external_exports.object({
22920
+ id: external_exports.string().min(1),
22921
+ name: external_exports.string().min(1).max(80).optional(),
22922
+ description: external_exports.string().max(200).optional(),
22923
+ systemPrompt: external_exports.string().max(4e3).optional(),
22924
+ defaultCwd: external_exports.string().optional(),
22925
+ defaultDaemonId: external_exports.string().optional(),
22926
+ color: external_exports.string().regex(/^#[0-9a-f]{6}$/i).optional(),
22927
+ icon: external_exports.string().optional(),
22928
+ tags: external_exports.array(external_exports.string()).max(10).optional()
22929
+ });
22930
+ var ArchivePersonaSchema = external_exports.object({
22931
+ id: external_exports.string().min(1)
22932
+ });
22933
+ var LaunchPersonaSchema = external_exports.object({
22934
+ id: external_exports.string().min(1).describe("Persona id"),
22935
+ projectId: external_exports.string().min(1).optional().describe("Target project for the spawned panel. Required from orchestrator."),
22936
+ daemonId: external_exports.string().min(1).optional(),
22937
+ cwd: external_exports.string().optional(),
22938
+ cols: external_exports.number().int().optional(),
22939
+ rows: external_exports.number().int().optional()
22940
+ });
22941
+ function registerPersonaTools(server, ctx) {
22942
+ server.tool(
22943
+ "bridge_list_personas",
22944
+ "Query personas in the workspace. Returns lightweight list \u2014 call bridge_get_persona for full systemPrompt. Pass projectId to filter to a specific project. From the orchestrator (workspace scope) optionally pass projectId; per-project workers default to ctx.projectId. Set excludePersonal:true to filter out personal-scoped personas (useful for orchestrator workspace-wide queries).",
22945
+ ListPersonasSchema.shape,
22946
+ (opts) => safe3(() => listPersonas(ctx, opts))
22947
+ );
22948
+ server.tool(
22949
+ "bridge_get_persona",
22950
+ "Fetch a single persona by id. Returns full systemPrompt and all fields.",
22951
+ GetPersonaSchema.shape,
22952
+ (params) => safe3(() => getPersona(ctx, params))
22953
+ );
22954
+ server.tool(
22955
+ "bridge_create_persona",
22956
+ "Create a new persona. Required from the orchestrator: pass projectId if creating a project-scoped persona; omit for workspace-scoped.",
22957
+ CreatePersonaSchema.shape,
22958
+ (params) => safe3(() => createPersona(ctx, params))
22959
+ );
22960
+ server.tool(
22961
+ "bridge_update_persona",
22962
+ "Update fields of an existing persona. Pass only the fields you want to change.",
22963
+ UpdatePersonaSchema.shape,
22964
+ (params) => safe3(() => updatePersona(ctx, params))
22965
+ );
22966
+ server.tool(
22967
+ "bridge_archive_persona",
22968
+ "Soft-archive a persona. Removes it from the active list but preserves audit trail.",
22969
+ ArchivePersonaSchema.shape,
22970
+ ({ id }) => safe3(() => archivePersona(ctx, id))
22971
+ );
22972
+ server.tool(
22973
+ "bridge_launch_persona",
22974
+ "Spawn a live panel from a persona. Returns the new agentId.",
22975
+ LaunchPersonaSchema.shape,
22976
+ (params) => safe3(() => launchPersona(ctx, params))
22977
+ );
22978
+ }
22979
+
22800
22980
  // ../mcp-server/src/index.ts
22801
22981
  var sessions = /* @__PURE__ */ new Map();
22802
22982
  function buildMcpServer(ctx) {
@@ -22806,6 +22986,7 @@ function buildMcpServer(ctx) {
22806
22986
  registerOrchestrationTools(srv, ctx);
22807
22987
  registerMessagingTools(srv, ctx);
22808
22988
  registerWorkspaceTools(srv, ctx);
22989
+ registerPersonaTools(srv, ctx);
22809
22990
  return srv;
22810
22991
  }
22811
22992
  async function parseBody(req) {
@@ -22895,7 +23076,8 @@ function startHttpServer() {
22895
23076
  }
22896
23077
  }
22897
23078
  const agentId = (req.headers["x-panel-id"] ?? "") || void 0;
22898
- const ctx = { serverUrl: bridgeServerUrl, token, workspaceId, projectId, agentId };
23079
+ const personaId = (req.headers["x-panel-persona-id"] ?? "") || void 0;
23080
+ const ctx = { serverUrl: bridgeServerUrl, token, workspaceId, projectId, agentId, personaId };
22899
23081
  const sid = (0, import_node_crypto.randomUUID)();
22900
23082
  const transport = new StreamableHTTPServerTransport({
22901
23083
  sessionIdGenerator: () => sid,
@@ -22909,8 +23091,8 @@ function startHttpServer() {
22909
23091
  const mcpServer = buildMcpServer(ctx);
22910
23092
  await mcpServer.connect(transport);
22911
23093
  await transport.handleRequest(req, res, body);
22912
- } catch (err3) {
22913
- console.error("[bridge-mcp] request error:", err3);
23094
+ } catch (err4) {
23095
+ console.error("[bridge-mcp] request error:", err4);
22914
23096
  if (!res.headersSent) {
22915
23097
  res.writeHead(500, { "Content-Type": "application/json" });
22916
23098
  res.end(JSON.stringify({ error: "Internal server error" }));
@@ -22934,7 +23116,8 @@ async function startStdioServer() {
22934
23116
  token: process.env["BRIDGE_TOKEN"],
22935
23117
  workspaceId: process.env["BRIDGE_WORKSPACE_ID"],
22936
23118
  projectId: process.env["BRIDGE_PROJECT_ID"],
22937
- agentId: process.env["BRIDGE_PANEL_ID"] || void 0
23119
+ agentId: process.env["BRIDGE_PANEL_ID"] || void 0,
23120
+ personaId: process.env["BRIDGE_PERSONA_ID"] || void 0
22938
23121
  };
22939
23122
  const srv = buildMcpServer(ctx);
22940
23123
  const transport = new StdioServerTransport();
@@ -22944,8 +23127,8 @@ async function startStdioServer() {
22944
23127
  if (process.env["HTTP_MODE"] !== "false") {
22945
23128
  startHttpServer();
22946
23129
  } else {
22947
- startStdioServer().catch((err3) => {
22948
- console.error("[bridge-mcp] fatal:", err3);
23130
+ startStdioServer().catch((err4) => {
23131
+ console.error("[bridge-mcp] fatal:", err4);
22949
23132
  process.exit(1);
22950
23133
  });
22951
23134
  }