@crewhaus/target-crew 0.5.3 → 0.5.5

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.
Files changed (2) hide show
  1. package/dist/index.js +35 -8
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -326,26 +326,49 @@ function renderMcpServers(ir) {
326
326
  if (entries.length === 0) {
327
327
  return { imports: [], bootBlock: "", hasAny: false };
328
328
  }
329
+ // #406 — servers the spec marked `required: false` degrade at boot instead
330
+ // of exiting. The crew's tool list (`__mcpTools`) is frozen at wire-once
331
+ // boot, so the optional path is degrade-only (`retry: false`): tools absent
332
+ // until restart, no background banner mid-run.
333
+ const requiredEntries = entries.filter(([, cfg]) => cfg.required !== false);
334
+ const optionalEntries = entries.filter(([, cfg]) => cfg.required === false);
329
335
  const imports = [
330
336
  `import { McpHost, resolveMcpServerConfig } from "@crewhaus/mcp-host";`,
331
- `import { registerMcpServer } from "@crewhaus/tool-mcp";`,
337
+ `import { ${[
338
+ ...(requiredEntries.length > 0 ? ["registerMcpServer"] : []),
339
+ ...(optionalEntries.length > 0 ? ["registerOptionalMcpServer"] : []),
340
+ ].join(", ")} } from "@crewhaus/tool-mcp";`,
332
341
  ];
333
- const addLines = entries
342
+ // Optional entries are NOT added here: their config resolution + addServer
343
+ // run inside registerOptionalMcpServer's never-throw boundary (an unset env
344
+ // var on an optional peer must degrade, not kill the boot).
345
+ const addLines = requiredEntries
334
346
  .map(([name, cfg]) => ` mcpHost.addServer(${escapeJsonString(name)}, resolveMcpServerConfig(${JSON.stringify(cfg)}, { name: ${escapeJsonString(name)} }));`)
335
347
  .join("\n");
336
- const registerLines = entries
348
+ const registerLines = requiredEntries
337
349
  .map(([name]) => ` registerMcpServer(mcpHost, ${escapeJsonString(name)}, __mcpCatalog, { onRegister: ({ fullName }) => process.stderr.write(\`[mcp] registered \${fullName}\\n\`) }),`)
338
350
  .join("\n");
351
+ const optionalLines = optionalEntries
352
+ .map(([name, cfg]) => {
353
+ // The wire config only — `required` is an EMIT-time decision (which
354
+ // registration call), not something mcp-host's config knows.
355
+ const { required: _requiredFlag, ...wireCfg } = cfg;
356
+ return `\n await registerOptionalMcpServer(mcpHost, ${escapeJsonString(name)}, __mcpCatalog, { retry: false, config: () => resolveMcpServerConfig(${JSON.stringify(wireCfg)}, { name: ${escapeJsonString(name)} }), log: (line) => process.stderr.write(line), onRegister: ({ fullName }) => process.stderr.write(\`[mcp] registered \${fullName}\\n\`) }).firstAttempt;`;
357
+ })
358
+ .join("");
359
+ const registerBlock = requiredEntries.length > 0
360
+ ? `
361
+ await Promise.all([
362
+ ${registerLines}
363
+ ]);`
364
+ : "";
339
365
  const bootBlock = `
340
366
  // Loop contract 0.4 (Batch A, G05) — MCP servers, wired ONCE: every
341
367
  // role's turns see the remote tools through the orchestrator's crew-wide
342
368
  // extraTools; the daemon disconnects the shared host on shutdown.
343
369
  const mcpHost = new McpHost();
344
370
  ${addLines}
345
- const __mcpCatalog = new ToolCatalog();
346
- await Promise.all([
347
- ${registerLines}
348
- ]);
371
+ const __mcpCatalog = new ToolCatalog();${registerBlock}${optionalLines}
349
372
  const __mcpTools = __mcpCatalog.list();`;
350
373
  return { imports, bootBlock, hasAny: true };
351
374
  }
@@ -697,9 +720,13 @@ function renderRoleThredz(ir) {
697
720
  const connectLines = [...servers].map(([name, r]) => {
698
721
  const id = ident(name);
699
722
  const agent = r.thredz?.agentName;
723
+ // Item 5 (G44) / #401 — per-role messaging opt-in. A crew role that owns
724
+ // its own Thredz key is exactly the case A2A messaging exists for, and
725
+ // the flag is per-role because the keys are.
726
+ const messaging = r.thredz?.messaging === true;
700
727
  return ` const __thredzCat_${id} = new ToolCatalog();
701
728
  const __thredz_${id} = await connectThredz(mcpHost, __thredzCat_${id}, {
702
- serverName: ${escapeJsonString(name)},${agent !== undefined ? `\n agentName: ${escapeJsonString(agent)},` : ""}
729
+ serverName: ${escapeJsonString(name)},${agent !== undefined ? `\n agentName: ${escapeJsonString(agent)},` : ""}${messaging ? "\n messaging: true," : ""}
703
730
  log: (line) => process.stderr.write(line),
704
731
  });`;
705
732
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewhaus/target-crew",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "type": "module",
5
5
  "description": "Codegen for the CRW target — emits a daemon + per-role agent files driven by crew-orchestrator (Section 22)",
6
6
  "main": "dist/index.js",
@@ -15,11 +15,11 @@
15
15
  "test": "bun test src"
16
16
  },
17
17
  "dependencies": {
18
- "@crewhaus/errors": "0.5.3",
19
- "@crewhaus/gateway-protocol": "0.5.3",
20
- "@crewhaus/infra-utils": "0.5.3",
21
- "@crewhaus/ir": "0.5.3",
22
- "@crewhaus/memory-service": "0.5.3"
18
+ "@crewhaus/errors": "0.5.5",
19
+ "@crewhaus/gateway-protocol": "0.5.5",
20
+ "@crewhaus/infra-utils": "0.5.5",
21
+ "@crewhaus/ir": "0.5.5",
22
+ "@crewhaus/memory-service": "0.5.5"
23
23
  },
24
24
  "license": "Apache-2.0",
25
25
  "author": {