bridge-agent 0.4.7 → 0.4.9

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
  }
@@ -22260,9 +22260,11 @@ var StdioServerTransport = class {
22260
22260
  };
22261
22261
 
22262
22262
  // ../mcp-server/src/api.ts
22263
- function projectPath(ctx, suffix = "") {
22263
+ function projectPath(ctx, suffix = "", projectIdOverride) {
22264
22264
  const base = ctx.serverUrl.replace(/\/$/, "");
22265
- return `${base}/api/workspaces/${ctx.workspaceId}/projects/${ctx.projectId}${suffix}`;
22265
+ const trimmed = projectIdOverride?.trim();
22266
+ const pid = trimmed || ctx.projectId;
22267
+ return `${base}/api/workspaces/${ctx.workspaceId}/projects/${pid}${suffix}`;
22266
22268
  }
22267
22269
  function workspacePath(ctx, suffix = "") {
22268
22270
  const base = ctx.serverUrl.replace(/\/$/, "");
@@ -22388,7 +22390,13 @@ async function getAgentIdle(ctx, agentId) {
22388
22390
  return request(ctx, "GET", projectPath(ctx, `/agents/${agentId}/idle`));
22389
22391
  }
22390
22392
  async function recordProjectEvent(ctx, params) {
22391
- return request(ctx, "POST", projectPath(ctx, "/events"), { ...params, agentId: ctx.agentId });
22393
+ const { projectId, ...body } = params;
22394
+ return request(
22395
+ ctx,
22396
+ "POST",
22397
+ projectPath(ctx, "/events", projectId),
22398
+ { ...body, agentId: ctx.agentId }
22399
+ );
22392
22400
  }
22393
22401
  async function getProjectEvents(ctx, opts) {
22394
22402
  const params = new URLSearchParams();
@@ -22400,7 +22408,45 @@ async function getProjectEvents(ctx, opts) {
22400
22408
  if (opts?.limit) params.set("limit", String(opts.limit));
22401
22409
  if (opts?.includeArchived) params.set("includeArchived", "true");
22402
22410
  const qs = params.toString();
22403
- return request(ctx, "GET", projectPath(ctx, `/events${qs ? "?" + qs : ""}`));
22411
+ return request(
22412
+ ctx,
22413
+ "GET",
22414
+ projectPath(ctx, `/events${qs ? "?" + qs : ""}`, opts?.projectId)
22415
+ );
22416
+ }
22417
+ async function listPersonas(ctx, opts) {
22418
+ const params = new URLSearchParams();
22419
+ if (opts.projectId) params.set("projectId", opts.projectId);
22420
+ if (opts.scope) params.set("scope", opts.scope);
22421
+ if (opts.includeArchived) params.set("includeArchived", "true");
22422
+ if (opts.agentKey) params.set("agentKey", opts.agentKey);
22423
+ if (opts.role) params.set("role", opts.role);
22424
+ if (opts.tag) params.set("tag", opts.tag);
22425
+ if (opts.q) params.set("q", opts.q);
22426
+ if (opts.limit) params.set("pageSize", String(opts.limit));
22427
+ const qs = params.toString();
22428
+ return request(ctx, "GET", workspacePath(ctx, `/personas${qs ? "?" + qs : ""}`));
22429
+ }
22430
+ async function getPersona(ctx, params) {
22431
+ return request(ctx, "GET", workspacePath(ctx, `/personas/${encodeURIComponent(params.id)}`));
22432
+ }
22433
+ async function createPersona(ctx, params) {
22434
+ const body = { ...params, scope: params.projectId ? "project" : "workspace" };
22435
+ return request(ctx, "POST", workspacePath(ctx, "/personas"), body);
22436
+ }
22437
+ async function updatePersona(ctx, params) {
22438
+ const { id, ...body } = params;
22439
+ return request(ctx, "PATCH", workspacePath(ctx, `/personas/${encodeURIComponent(id)}`), body);
22440
+ }
22441
+ async function archivePersona(ctx, id) {
22442
+ return request(ctx, "POST", workspacePath(ctx, `/personas/${encodeURIComponent(id)}/archive`));
22443
+ }
22444
+ async function launchPersona(ctx, params) {
22445
+ const { id, projectId, ...rest } = params;
22446
+ const trimmed = projectId?.trim();
22447
+ const pid = trimmed || ctx.projectId;
22448
+ const body = pid ? { ...rest, projectId: pid } : rest;
22449
+ return request(ctx, "POST", workspacePath(ctx, `/personas/${encodeURIComponent(id)}/launch`), body);
22404
22450
  }
22405
22451
 
22406
22452
  // ../mcp-server/src/tools/plan.ts
@@ -22530,6 +22576,31 @@ function registerTodoTools(server, ctx) {
22530
22576
  );
22531
22577
  }
22532
22578
 
22579
+ // ../shared/dist/types.js
22580
+ var ALL_AGENT_KEYS = [
22581
+ "sh",
22582
+ "claude",
22583
+ "codex",
22584
+ "qwen",
22585
+ "kimi",
22586
+ "gemini",
22587
+ "ollama",
22588
+ "aider",
22589
+ "forge",
22590
+ "sim_ios"
22591
+ ];
22592
+ var AGENT_ROLES = [
22593
+ "developer",
22594
+ "reviewer",
22595
+ "planner",
22596
+ "executor",
22597
+ "shell",
22598
+ "runner",
22599
+ "orchestrator"
22600
+ ];
22601
+ var USER_ASSIGNABLE_ROLES = AGENT_ROLES.filter((r) => r !== "orchestrator");
22602
+ var EVENT_ROLES = [...AGENT_ROLES, "system"];
22603
+
22533
22604
  // ../mcp-server/src/tools/orchestration.ts
22534
22605
  function ok(data) {
22535
22606
  return { content: [{ type: "text", text: JSON.stringify(data) }] };
@@ -22600,7 +22671,7 @@ function registerOrchestrationTools(server, ctx) {
22600
22671
  {
22601
22672
  agentKey: external_exports.string().describe("Agent type: claude, codex, sh, qwen, gemini, ollama, aider"),
22602
22673
  daemonId: external_exports.string().optional().describe("Target machine ID. Omit to use the workspace default machine."),
22603
- role: external_exports.string().optional().describe("Panel role: developer, reviewer, planner, executor, shell, runner"),
22674
+ role: external_exports.enum(USER_ASSIGNABLE_ROLES).optional().describe(`Panel role: ${USER_ASSIGNABLE_ROLES.join(", ")}`),
22604
22675
  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.')
22605
22676
  },
22606
22677
  ({ agentKey, daemonId, role, cmd }) => safe(() => spawnAgent(ctx, agentKey, daemonId, role, cmd))
@@ -22654,10 +22725,11 @@ function registerOrchestrationTools(server, ctx) {
22654
22725
  );
22655
22726
  server.tool(
22656
22727
  "bridge_record_event",
22657
- "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.",
22728
+ "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).",
22658
22729
  {
22659
22730
  eventType: external_exports.string().min(1).max(64).describe("Free-form event type slug (e.g. decision, blocker, phase_complete)"),
22660
22731
  summary: external_exports.string().min(1).max(512).describe("Human-readable event summary (max 512 chars)"),
22732
+ projectId: external_exports.string().min(1).optional().describe("Target project ID. Defaults to caller panel's project. Required when called from the orchestrator (workspace scope)."),
22661
22733
  sessionId: external_exports.string().optional().describe("Orchestration session ID this event belongs to, if any"),
22662
22734
  payload: external_exports.record(external_exports.unknown()).optional().describe("Optional structured data attached to the event"),
22663
22735
  tags: external_exports.array(external_exports.string()).optional().describe('Free-form tags for filtering (e.g. ["auth", "security"])'),
@@ -22667,8 +22739,9 @@ function registerOrchestrationTools(server, ctx) {
22667
22739
  );
22668
22740
  server.tool(
22669
22741
  "bridge_get_project_events",
22670
- "Query the project event log. Returns events newest-first. Use to recall decisions, discoveries, and blockers recorded by prior agents before starting new work. Filter by role or eventType to narrow results; use search for keyword lookup in summaries.",
22742
+ "Query the project event log. Returns events newest-first. Use to recall decisions, discoveries, and blockers recorded by prior agents before starting new work. Filter by role or eventType to narrow results; use search for keyword lookup in summaries. Pass projectId to query a specific project (orchestrator must always pass it; per-project workers can omit).",
22671
22743
  {
22744
+ projectId: external_exports.string().min(1).optional().describe("Target project ID. Defaults to caller panel's project. Required when called from the orchestrator (workspace scope)."),
22672
22745
  role: external_exports.string().optional().describe("Filter by role (e.g. reviewer, developer)"),
22673
22746
  eventType: external_exports.string().optional().describe("Filter by eventType slug"),
22674
22747
  tags: external_exports.string().optional().describe('Comma-separated tag list \u2014 only events containing ALL listed tags (e.g. "auth,security")'),
@@ -22783,6 +22856,113 @@ function registerWorkspaceTools(server, ctx) {
22783
22856
  );
22784
22857
  }
22785
22858
 
22859
+ // ../mcp-server/src/tools/personas.ts
22860
+ function ok3(data) {
22861
+ return { content: [{ type: "text", text: JSON.stringify(data) }] };
22862
+ }
22863
+ function err3(message) {
22864
+ return { content: [{ type: "text", text: JSON.stringify({ ok: false, error: message }) }] };
22865
+ }
22866
+ async function safe3(fn) {
22867
+ try {
22868
+ return ok3(await fn());
22869
+ } catch (e) {
22870
+ const message = e instanceof Error ? e.message : String(e);
22871
+ if (e instanceof Error && (e.name === "TypeError" || e.name === "ReferenceError")) {
22872
+ console.error("[mcp-bridge] unexpected error in persona tool handler", { name: e.name, message, stack: e.stack });
22873
+ }
22874
+ return err3(message);
22875
+ }
22876
+ }
22877
+ var ListPersonasSchema = external_exports.object({
22878
+ projectId: external_exports.string().min(1).optional().describe("Filter to project scope. Defaults to caller panel's project."),
22879
+ scope: external_exports.enum(["personal", "workspace", "project", "all"]).optional().describe("Scope filter (default: all)"),
22880
+ includeArchived: external_exports.boolean().optional(),
22881
+ agentKey: external_exports.enum(ALL_AGENT_KEYS).optional(),
22882
+ role: external_exports.enum(USER_ASSIGNABLE_ROLES).optional(),
22883
+ tag: external_exports.string().optional(),
22884
+ q: external_exports.string().optional().describe("Substring search on name+description"),
22885
+ limit: external_exports.number().int().min(1).max(200).optional()
22886
+ });
22887
+ var GetPersonaSchema = external_exports.object({
22888
+ id: external_exports.string().min(1).describe("Persona id (UUID)"),
22889
+ projectId: external_exports.string().min(1).optional()
22890
+ });
22891
+ var CreatePersonaSchema = external_exports.object({
22892
+ name: external_exports.string().min(1).max(80),
22893
+ slug: external_exports.string().min(1).max(63).regex(/^[a-z][a-z0-9_]*$/),
22894
+ description: external_exports.string().max(200).optional(),
22895
+ agentKey: external_exports.enum(ALL_AGENT_KEYS),
22896
+ role: external_exports.enum(USER_ASSIGNABLE_ROLES),
22897
+ systemPrompt: external_exports.string().max(4e3).optional(),
22898
+ defaultCwd: external_exports.string().optional(),
22899
+ defaultDaemonId: external_exports.string().optional(),
22900
+ color: external_exports.string().regex(/^#[0-9a-f]{6}$/i).optional(),
22901
+ emoji: external_exports.string().optional(),
22902
+ tags: external_exports.array(external_exports.string()).max(10).optional(),
22903
+ projectId: external_exports.string().min(1).optional().describe("Make this a project-scoped persona. Omit for workspace-scoped.")
22904
+ });
22905
+ var UpdatePersonaSchema = external_exports.object({
22906
+ id: external_exports.string().min(1),
22907
+ name: external_exports.string().min(1).max(80).optional(),
22908
+ description: external_exports.string().max(200).optional(),
22909
+ systemPrompt: external_exports.string().max(4e3).optional(),
22910
+ defaultCwd: external_exports.string().optional(),
22911
+ defaultDaemonId: external_exports.string().optional(),
22912
+ color: external_exports.string().regex(/^#[0-9a-f]{6}$/i).optional(),
22913
+ emoji: external_exports.string().optional(),
22914
+ tags: external_exports.array(external_exports.string()).max(10).optional()
22915
+ });
22916
+ var ArchivePersonaSchema = external_exports.object({
22917
+ id: external_exports.string().min(1)
22918
+ });
22919
+ var LaunchPersonaSchema = external_exports.object({
22920
+ id: external_exports.string().min(1).describe("Persona id"),
22921
+ projectId: external_exports.string().min(1).optional().describe("Target project for the spawned panel. Required from orchestrator."),
22922
+ daemonId: external_exports.string().min(1).optional(),
22923
+ cwd: external_exports.string().optional(),
22924
+ cols: external_exports.number().int().optional(),
22925
+ rows: external_exports.number().int().optional()
22926
+ });
22927
+ function registerPersonaTools(server, ctx) {
22928
+ server.tool(
22929
+ "bridge_list_personas",
22930
+ "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.",
22931
+ ListPersonasSchema.shape,
22932
+ (opts) => safe3(() => listPersonas(ctx, opts))
22933
+ );
22934
+ server.tool(
22935
+ "bridge_get_persona",
22936
+ "Fetch a single persona by id. Returns full systemPrompt and all fields.",
22937
+ GetPersonaSchema.shape,
22938
+ (params) => safe3(() => getPersona(ctx, params))
22939
+ );
22940
+ server.tool(
22941
+ "bridge_create_persona",
22942
+ "Create a new persona. Required from the orchestrator: pass projectId if creating a project-scoped persona; omit for workspace-scoped.",
22943
+ CreatePersonaSchema.shape,
22944
+ (params) => safe3(() => createPersona(ctx, params))
22945
+ );
22946
+ server.tool(
22947
+ "bridge_update_persona",
22948
+ "Update fields of an existing persona. Pass only the fields you want to change.",
22949
+ UpdatePersonaSchema.shape,
22950
+ (params) => safe3(() => updatePersona(ctx, params))
22951
+ );
22952
+ server.tool(
22953
+ "bridge_archive_persona",
22954
+ "Soft-archive a persona. Removes it from the active list but preserves audit trail.",
22955
+ ArchivePersonaSchema.shape,
22956
+ ({ id }) => safe3(() => archivePersona(ctx, id))
22957
+ );
22958
+ server.tool(
22959
+ "bridge_launch_persona",
22960
+ "Spawn a live panel from a persona. Returns the new agentId.",
22961
+ LaunchPersonaSchema.shape,
22962
+ (params) => safe3(() => launchPersona(ctx, params))
22963
+ );
22964
+ }
22965
+
22786
22966
  // ../mcp-server/src/index.ts
22787
22967
  var sessions = /* @__PURE__ */ new Map();
22788
22968
  function buildMcpServer(ctx) {
@@ -22792,6 +22972,7 @@ function buildMcpServer(ctx) {
22792
22972
  registerOrchestrationTools(srv, ctx);
22793
22973
  registerMessagingTools(srv, ctx);
22794
22974
  registerWorkspaceTools(srv, ctx);
22975
+ registerPersonaTools(srv, ctx);
22795
22976
  return srv;
22796
22977
  }
22797
22978
  async function parseBody(req) {
@@ -22895,8 +23076,8 @@ function startHttpServer() {
22895
23076
  const mcpServer = buildMcpServer(ctx);
22896
23077
  await mcpServer.connect(transport);
22897
23078
  await transport.handleRequest(req, res, body);
22898
- } catch (err3) {
22899
- console.error("[bridge-mcp] request error:", err3);
23079
+ } catch (err4) {
23080
+ console.error("[bridge-mcp] request error:", err4);
22900
23081
  if (!res.headersSent) {
22901
23082
  res.writeHead(500, { "Content-Type": "application/json" });
22902
23083
  res.end(JSON.stringify({ error: "Internal server error" }));
@@ -22930,8 +23111,8 @@ async function startStdioServer() {
22930
23111
  if (process.env["HTTP_MODE"] !== "false") {
22931
23112
  startHttpServer();
22932
23113
  } else {
22933
- startStdioServer().catch((err3) => {
22934
- console.error("[bridge-mcp] fatal:", err3);
23114
+ startStdioServer().catch((err4) => {
23115
+ console.error("[bridge-mcp] fatal:", err4);
22935
23116
  process.exit(1);
22936
23117
  });
22937
23118
  }