@crewhaus/target-crew 0.5.8 → 0.7.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.
Files changed (2) hide show
  1. package/dist/index.js +28 -60
  2. package/package.json +7 -6
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ import { renderControlDrain, renderControlImports, renderControlPlaneBoot, rende
21
21
  import { escapeJsonString } from "@crewhaus/infra-utils";
22
22
  import { renderBundleReadme, } from "@crewhaus/ir";
23
23
  import { memoryFragmentFromIr } from "@crewhaus/memory-service";
24
+ import { renderModelWiringFields, renderSubAgentDef } from "@crewhaus/model-service";
24
25
  export class TargetEmitError extends CrewhausError {
25
26
  name = "TargetEmitError";
26
27
  constructor(message, cause) {
@@ -375,25 +376,6 @@ ${addLines}
375
376
  // ---------------------------------------------------------------------------
376
377
  // File: agent_<role>.ts — exports the role's RoleDefinition.
377
378
  // ---------------------------------------------------------------------------
378
- /** Render one IrSubAgentDefinition as a TS object literal — mirrors
379
- * target-cli + target-channel-bot; keep the three in sync. */
380
- function renderSubAgentDef(d) {
381
- const lines = [];
382
- lines.push(`name: ${escapeJsonString(d.name)}`);
383
- lines.push(`description: ${escapeJsonString(d.description)}`);
384
- lines.push(`instructions: ${escapeJsonString(d.instructions)}`);
385
- lines.push(`tools: ${JSON.stringify(d.tools)}`);
386
- if (d.model !== undefined)
387
- lines.push(`model: ${escapeJsonString(d.model)}`);
388
- if (typeof d.permissions === "string") {
389
- lines.push(`permissions: ${escapeJsonString(d.permissions)}`);
390
- }
391
- else {
392
- lines.push(`permissions: { allow: ${JSON.stringify(d.permissions.allow)}, deny: ${JSON.stringify(d.permissions.deny)} }`);
393
- }
394
- lines.push(`inherit_bypass: ${d.inheritBypass}`);
395
- return `{ ${lines.join(", ")} }`;
396
- }
397
379
  /**
398
380
  * Loop contract 0.4 (Batch A) — render the per-role tuning fields onto the
399
381
  * RoleDefinition literal, camelCase-mirroring the IR 1:1: `max_tokens` →
@@ -413,41 +395,10 @@ function renderRoleTuningFields(role) {
413
395
  if (role.thinking !== undefined) {
414
396
  pieces.push(`\n thinking: ${JSON.stringify(role.thinking)},`);
415
397
  }
416
- return pieces.join("");
417
- }
418
- /**
419
- * Loop contract 0.4 (Batch G, item 9 / G37) — render the per-role model-
420
- * routing fields onto the role's `RoleDefinition` literal. The pooled
421
- * pattern is adopted verbatim from the cli agent block
422
- * (`@crewhaus/target-cli`'s `renderModelFailoverFields`), so a PolicyRouter
423
- * decision per role shares the same `@crewhaus/routing-store` scoreboard the
424
- * cli/pipeline shapes use — runtime-core owns the router; the orchestrator
425
- * forwards the RoleDefinition's config into this role's `runChatLoop` turns
426
- * (primary activations AND inline A2A peer turns) exactly as it already
427
- * forwards `maxTokens`/`thinking`. The four fields are mutually exclusive in
428
- * the spec (`model_pool` ⊥ `model_tiers` ⊥ `model_fallbacks`, with
429
- * `circuit_breaker` riding `model_fallbacks`), so at most one clause fires
430
- * per role. Model strings pass through `escapeJsonString` (user-controlled
431
- * spec values in generated source); the breaker/tiers/pool blocks are
432
- * validated numbers/strings/closed-literal unions safe to `JSON.stringify`.
433
- * Empty when the role declares none, keeping pre-existing bundles
434
- * byte-identical. Mirror: target-cli + target-channel-bot + target-managed
435
- * render the same fields on their agent blocks — keep the four in sync.
436
- */
437
- function renderRoleModelFailoverFields(role) {
438
- const pieces = [];
439
- const fallbacks = role.modelFallbacks;
440
- if (fallbacks !== undefined && fallbacks.length > 0) {
441
- pieces.push(`\n modelFallbacks: [${fallbacks.map((m) => escapeJsonString(m)).join(", ")}],`);
442
- }
443
- if (role.circuitBreaker !== undefined) {
444
- pieces.push(`\n circuitBreaker: ${JSON.stringify(role.circuitBreaker)},`);
445
- }
446
- if (role.modelTiers !== undefined) {
447
- pieces.push(`\n modelTiers: ${JSON.stringify(role.modelTiers)},`);
448
- }
449
- if (role.modelPool !== undefined) {
450
- pieces.push(`\n modelPool: ${JSON.stringify(role.modelPool)},`);
398
+ // 0.6.0 §4.1 — role-level sampling temperature (a validated number); the
399
+ // orchestrator forwards it to the role's turns like `thinking`.
400
+ if (role.temperature !== undefined) {
401
+ pieces.push(`\n temperature: ${role.temperature},`);
451
402
  }
452
403
  return pieces.join("");
453
404
  }
@@ -483,6 +434,20 @@ ${subAgentEntries}
483
434
  : registrations;
484
435
  const toolsArrayLiteral = toolRegistrations.length > 0 ? `[${toolRegistrations.join(", ")}]` : "[]";
485
436
  const subAgentsField = hasSubAgents ? "\n subAgents: __subAgents," : "";
437
+ // Loop contract 0.4 (Batch G, item 9 / G37) + 0.6.0 PR 3 (design §7.7) —
438
+ // the role's model-routing quartet (`modelFallbacks` / `circuitBreaker` /
439
+ // `modelTiers` / `modelPool`) lands on the `RoleDefinition` literal, rendered
440
+ // by `@crewhaus/model-service`'s `renderModelWiringFields` (the one renderer
441
+ // every emitter shares). `RoleDefinition` types the four fields by indexing
442
+ // runtime-core's `RunChatLoopOptions`, so the literal is checked against
443
+ // what the loop accepts, and `composeLoopTuning` spreads them into every
444
+ // activation of this role. The field NAMES are the contract with the
445
+ // orchestrator — a rename on either side must move both.
446
+ // 0.6.0 §4.2 / §7.7 (PR 7b): `modelPool` is the WIDENED `IrModelPool`,
447
+ // carried whole — every per-candidate profile setting, the hybrid siblings
448
+ // and a declared `scope` reach the literal verbatim; the orchestrator's
449
+ // `RoleModelPool` accepts that shape (pinned in `@crewhaus/compiler`) and
450
+ // stamps `scope` with the role name at runtime when the spec declared none.
486
451
  return `// Generated by crewhaus. DO NOT EDIT.
487
452
  // Source spec: ${escapeJsonString(ir.name)} (target: crew, ir version: ${ir.version}, role: ${escapeJsonString(role.name)})
488
453
  ${importBlock}import type { RoleDefinition } from "@crewhaus/crew-orchestrator";
@@ -492,7 +457,7 @@ export const role: { name: string; def: RoleDefinition } = {
492
457
  name: ${escapeJsonString(role.name)},
493
458
  def: {
494
459
  model: ${escapeJsonString(role.model)},
495
- instructions: ${escapeJsonString(role.instructions)},${renderRoleTuningFields(role)}${renderRoleModelFailoverFields(role)}
460
+ instructions: ${escapeJsonString(role.instructions)},${renderRoleTuningFields(role)}${renderModelWiringFields(role, " ")}
496
461
  tools: ${toolsArrayLiteral},${subAgentsField}
497
462
  },
498
463
  };
@@ -522,10 +487,13 @@ function llmRouterDescription(instructions) {
522
487
  * name or DONE — the exact-token output contract is what keeps the
523
488
  * decision stable at any sampling temperature. DONE (or re-picking the
524
489
  * finishing role) terminates the crew; an unparseable reply falls back to
525
- * the entry role. The turn runs on the entry role's model in its own
526
- * session (`<name> (llm-router)`) so the crew transcript stays clean, and
527
- * it rides the run's session root + `_adapter` test seam via the
528
- * orchestrator's RouterArgs passthroughs.
490
+ * the entry role. The turn runs on `routing.model` — 0.6.0 §7.7, the
491
+ * router's own slot (a `$profile` resolves at lower time, `IrCrewRouting.
492
+ * model`) — or, when the spec names none, on the entry role's model, the
493
+ * byte-identical pre-0.6.0 default. It runs in its own session
494
+ * (`<name> (llm-router)`) so the crew transcript stays clean, and it rides
495
+ * the run's session root + `_adapter` test seam via the orchestrator's
496
+ * RouterArgs passthroughs.
529
497
  */
530
498
  function renderLlmRouter(ir, entryRole) {
531
499
  const rosterEntries = ir.roles
@@ -575,7 +543,7 @@ function __pickNextRole(reply: string, lastRole: string): string {
575
543
  ? \`…\${input.slice(-${LLM_ROUTER_INPUT_MAX_CHARS})}\`
576
544
  : input;
577
545
  const reply = await runChatLoop({
578
- model: ${escapeJsonString(entryRole.model)},
546
+ model: ${escapeJsonString(ir.routing?.model ?? entryRole.model)},
579
547
  instructions: ${escapeJsonString(classifierInstructions)},
580
548
  sessionName: ${escapeJsonString(`${ir.name} (llm-router)`)},
581
549
  sessionTarget: "crew",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewhaus/target-crew",
3
- "version": "0.5.8",
3
+ "version": "0.7.0",
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,12 @@
15
15
  "test": "bun test src"
16
16
  },
17
17
  "dependencies": {
18
- "@crewhaus/errors": "0.5.8",
19
- "@crewhaus/gateway-protocol": "0.5.8",
20
- "@crewhaus/infra-utils": "0.5.8",
21
- "@crewhaus/ir": "0.5.8",
22
- "@crewhaus/memory-service": "0.5.8"
18
+ "@crewhaus/errors": "0.7.0",
19
+ "@crewhaus/gateway-protocol": "0.7.0",
20
+ "@crewhaus/infra-utils": "0.7.0",
21
+ "@crewhaus/ir": "0.7.0",
22
+ "@crewhaus/memory-service": "0.7.0",
23
+ "@crewhaus/model-service": "0.7.0"
23
24
  },
24
25
  "license": "Apache-2.0",
25
26
  "author": {