@koda-sl/baker-bridge 0.194.0-dev.8f5bcdb0e → 0.195.0-dev.a2270c74d

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 (67) hide show
  1. package/README.md +66 -28
  2. package/dist/hono/agent.d.ts.map +1 -1
  3. package/dist/hono/agent.js +4 -1
  4. package/dist/hono/agent.js.map +1 -1
  5. package/dist/hono/bridge-job.d.ts +27 -0
  6. package/dist/hono/bridge-job.d.ts.map +1 -1
  7. package/dist/hono/bridge-job.js +93 -19
  8. package/dist/hono/bridge-job.js.map +1 -1
  9. package/dist/hono/bridge-job.test.js +99 -226
  10. package/dist/hono/bridge-job.test.js.map +1 -1
  11. package/dist/hono/chat-language.d.ts +34 -0
  12. package/dist/hono/chat-language.d.ts.map +1 -0
  13. package/dist/hono/chat-language.js +152 -0
  14. package/dist/hono/chat-language.js.map +1 -0
  15. package/dist/hono/chat-language.test.d.ts +2 -0
  16. package/dist/hono/chat-language.test.d.ts.map +1 -0
  17. package/dist/hono/chat-language.test.js +136 -0
  18. package/dist/hono/chat-language.test.js.map +1 -0
  19. package/dist/hono/jev.d.ts +16 -0
  20. package/dist/hono/jev.d.ts.map +1 -1
  21. package/dist/hono/jev.js +44 -21
  22. package/dist/hono/jev.js.map +1 -1
  23. package/dist/hono/model-capabilities.js +3 -3
  24. package/dist/hono/model-capabilities.js.map +1 -1
  25. package/dist/hono/progress-note.d.ts +0 -3
  26. package/dist/hono/progress-note.d.ts.map +1 -1
  27. package/dist/hono/progress-note.js +0 -8
  28. package/dist/hono/progress-note.js.map +1 -1
  29. package/dist/hono/publish-handoff.d.ts +6 -17
  30. package/dist/hono/publish-handoff.d.ts.map +1 -1
  31. package/dist/hono/publish-handoff.js +17 -67
  32. package/dist/hono/publish-handoff.js.map +1 -1
  33. package/dist/hono/publish-handoff.test.js +34 -63
  34. package/dist/hono/publish-handoff.test.js.map +1 -1
  35. package/dist/hono/scripted-publish.d.ts +19 -0
  36. package/dist/hono/scripted-publish.d.ts.map +1 -0
  37. package/dist/hono/scripted-publish.js +219 -0
  38. package/dist/hono/scripted-publish.js.map +1 -0
  39. package/dist/hono/scripted-publish.test.d.ts +2 -0
  40. package/dist/hono/scripted-publish.test.d.ts.map +1 -0
  41. package/dist/hono/scripted-publish.test.js +212 -0
  42. package/dist/hono/scripted-publish.test.js.map +1 -0
  43. package/dist/hono/skill-language.d.ts +16 -40
  44. package/dist/hono/skill-language.d.ts.map +1 -1
  45. package/dist/hono/skill-language.js +39 -168
  46. package/dist/hono/skill-language.js.map +1 -1
  47. package/dist/hono/skill-language.test.js +48 -50
  48. package/dist/hono/skill-language.test.js.map +1 -1
  49. package/dist/hono/subagent-route.test.js +29 -5
  50. package/dist/hono/subagent-route.test.js.map +1 -1
  51. package/dist/hono/types.d.ts +9 -0
  52. package/dist/hono/types.d.ts.map +1 -1
  53. package/dist/review/digest.d.ts +6 -5
  54. package/dist/review/digest.d.ts.map +1 -1
  55. package/dist/review/digest.js +34 -28
  56. package/dist/review/digest.js.map +1 -1
  57. package/dist/review/digest.test.js +42 -177
  58. package/dist/review/digest.test.js.map +1 -1
  59. package/dist/review/evidence-block.js +2 -2
  60. package/dist/review/evidence-block.js.map +1 -1
  61. package/dist/review/reply-language.d.ts +12 -30
  62. package/dist/review/reply-language.d.ts.map +1 -1
  63. package/dist/review/reply-language.js +97 -162
  64. package/dist/review/reply-language.js.map +1 -1
  65. package/dist/review/reply-language.test.js +67 -75
  66. package/dist/review/reply-language.test.js.map +1 -1
  67. package/package.json +1 -2
@@ -13,13 +13,14 @@ import { avatarAwaitingItsFace, avatarCreatedInAssistantMessage, avatarHandleFro
13
13
  import { accentContradictsUser } from "./avatar-accent.js";
14
14
  import { AVATAR_CASTING_TOOL_NAME, normalizeAvatarCastingToolInput, } from "./avatar-casting.js";
15
15
  import { asksForAvatarFace, FACE_QUESTION_MESSAGE } from "./avatar-face-question.js";
16
+ import { jevChatLanguage } from "./chat-language.js";
16
17
  import { CONNECTION_INPUT_TOOL_NAME, CONNECTION_PLATFORMS, connectedButNotLoaded, normalizeConnectionInputToolInput, toolsConnected, } from "./connection-input.js";
17
18
  import { messageContextTokens, pickContextWindow, streamEventContextUsage, turnContextUsage, } from "./context-usage.js";
18
19
  import { CREDENTIAL_INPUT_TOOL_NAME, normalizeCredentialInputToolInput, } from "./credential-input.js";
19
20
  import { credentialScrubHooks } from "./credential-scrub.js";
20
21
  import { agentStatedFlowMessage, FLOW_INPUT_TOOL_NAME, nodeTargetRefusals, normalizeFlowInputToolInput, readRawFlowTree, sanitizeFlowRequests, unknownFlowPrefillMessage, } from "./flow-input.js";
21
22
  import { writesInventedLogo } from "./invented-logo.js";
22
- import { jevJudge } from "./jev.js";
23
+ import { jevChooser, jevJudge } from "./jev.js";
23
24
  import { mainSyncReminder } from "./main-sync.js";
24
25
  import { composioScopesToInvalidate, failedCustomServers, reportMcpInvalid, serversConnectedWithNoTools, } from "./mcp-servers.js";
25
26
  import { agentModelOverride, autoCompactWindowForModel, betasForModel, contextWindowForModel, } from "./model-capabilities.js";
@@ -34,7 +35,7 @@ import { alignServedModels, readConversationModel } from "./served-model.js";
34
35
  import { applyCurrentSenderAttribution, buildCancelBoundary, buildCleanBoundary, buildRehydratedPrompt, compactionRetryAttempt, emptyInProgressSession, interruptedResumeAttempt, isCliResumeRefusal, isContextOverflowError, isResumeSessionError, observeInProgressSession, prepareSessionAttempt, stallContinuationAttempt, } from "./session-continuity.js";
35
36
  import { readSessionSkills } from "./session-skills.js";
36
37
  import { ownQueryUsage, readUsageBaseline, savedTotalsReading } from "./session-usage-baseline.js";
37
- import { RelayedLines, skillLanguageHooks } from "./skill-language.js";
38
+ import { skillLanguageHooks } from "./skill-language.js";
38
39
  import { BridgeSlashCommands, leadingSkillCommand, verbatimSlashCommand } from "./slash-commands.js";
39
40
  import { readAgentDefinitions, subagentHooks } from "./subagent-route.js";
40
41
  import { createBakerUiServer, normalizeTagInputToolInput, sanitizeTagChanges, TAG_INPUT_TOOL_NAME, unknownPrefillMessage, } from "./tag-input.js";
@@ -310,13 +311,12 @@ export function agentFeature(job) {
310
311
  /**
311
312
  * Every job's tool results pass through the credential scrub, appended after
312
313
  * any other PostToolUse hook so its rewrite is the one the SDK keeps. A chat
313
- * turn also restates the marketer's language after a skill loads, by tool call
314
- * or by a command they typed, after a subagent reports, and after a line to
315
- * them drifted out of their language.
314
+ * turn also restates the marketer's language the first time a skill loads, by
315
+ * tool call or by a command they typed.
316
316
  */
317
- function withCredentialScrub(options, job, state) {
317
+ function withCredentialScrub(options, job, readLanguage) {
318
318
  const scrub = credentialScrubHooks();
319
- const language = job.review ? {} : skillLanguageHooks(job, state.relayedLines);
319
+ const language = job.review ? {} : skillLanguageHooks(job, readLanguage);
320
320
  const hooks = { ...(options.hooks ?? {}) };
321
321
  hooks.PostToolUse = [...(hooks.PostToolUse ?? []), ...(language.PostToolUse ?? []), ...(scrub.PostToolUse ?? [])];
322
322
  if (language.UserPromptExpansion) {
@@ -482,7 +482,6 @@ function createBridgeJobState() {
482
482
  queryModelUsage: new Map(),
483
483
  toolResults: new ToolResultLedger(),
484
484
  agentSpend: new AgentSpendLedger(),
485
- relayedLines: new RelayedLines(),
486
485
  };
487
486
  }
488
487
  /** What a finished turn reports about its spend: per-model usage and per-tool result sizes. */
@@ -604,6 +603,10 @@ function sharedInstructionOptions(sharedInstructions) {
604
603
  function bridgeJudge(feature) {
605
604
  return jevJudge(process.env.OPENROUTER_API_KEY, runtimeOpenRouterTags(process.env, { service: "bridge", feature }));
606
605
  }
606
+ function bridgeChatLanguage() {
607
+ const tags = runtimeOpenRouterTags(process.env, { service: "bridge", feature: "bridge.chatLanguage" });
608
+ return jevChatLanguage(jevChooser(process.env.OPENROUTER_API_KEY, tags));
609
+ }
607
610
  function judgesOf(dependencies) {
608
611
  return {
609
612
  judge: dependencies.judge ?? bridgeJudge("bridge.toolCallGuard"),
@@ -1337,9 +1340,11 @@ export class BridgeJobExecutor {
1337
1340
  catchUpWithMain;
1338
1341
  holdsNoWork;
1339
1342
  settleAfterPublish;
1343
+ scriptedPublish;
1340
1344
  keepCliInStep;
1341
1345
  judge;
1342
1346
  routeJudge;
1347
+ readLanguage;
1343
1348
  routeModels;
1344
1349
  constructor(dependencies) {
1345
1350
  this.sdk = dependencies.sdk;
@@ -1366,10 +1371,12 @@ export class BridgeJobExecutor {
1366
1371
  this.catchUpWithMain = dependencies.catchUpWithMain;
1367
1372
  this.holdsNoWork = dependencies.holdsNoWork;
1368
1373
  this.settleAfterPublish = dependencies.settleAfterPublish;
1374
+ this.scriptedPublish = dependencies.scriptedPublish;
1369
1375
  this.keepCliInStep = dependencies.keepCliInStep;
1370
1376
  this.readFlowTree =
1371
1377
  dependencies.readFlowTree ?? ((flowSlug) => readRawFlowTree(bridgeRuntimeFiles.flowsDir(), flowSlug));
1372
1378
  ({ judge: this.judge, routeJudge: this.routeJudge } = judgesOf(dependencies));
1379
+ this.readLanguage = dependencies.readLanguage ?? bridgeChatLanguage();
1373
1380
  this.routeModels = dependencies.routeModels === true;
1374
1381
  }
1375
1382
  async execute(job, controls) {
@@ -1447,6 +1454,9 @@ export class BridgeJobExecutor {
1447
1454
  if (!request?.prompt || !controls.isActive()) {
1448
1455
  return { kind: "cancelled", costUsd: 0, model: state.model };
1449
1456
  }
1457
+ if (await this.publishedWithoutAgent(job, controls, request)) {
1458
+ return controls.isActive() ? { kind: "completed", costUsd: 0 } : { kind: "cancelled", costUsd: 0 };
1459
+ }
1450
1460
  // Asked while the boundary loads, so the answer (~0.3 s) costs the turn no time.
1451
1461
  const signals = this.askSignals(job, request);
1452
1462
  const loaded = await this.loadTrustedBoundary(job, controls);
@@ -1563,7 +1573,7 @@ export class BridgeJobExecutor {
1563
1573
  let requestPrompt = verbatim ?? applyCurrentSenderAttribution(job.prompt, job.currentSender);
1564
1574
  // A command must stay the leading token, so it carries no note: the news waits for the next turn.
1565
1575
  const syncNote = verbatim === null ? mainSyncReminder(mainSync) : undefined;
1566
- const reminder = turnReminder(job, verbatim, syncNote);
1576
+ const reminder = await turnReminder(job, verbatim, syncNote, this.readLanguage);
1567
1577
  if (job.attachments && job.attachments.length > 0) {
1568
1578
  requestPrompt += await this.prepareAttachments(job.attachments, "message");
1569
1579
  }
@@ -1578,6 +1588,39 @@ export class BridgeJobExecutor {
1578
1588
  ...(mainSync && syncNote ? { mainSync: { reminder: syncNote, delivered: mainSync.told } } : {}),
1579
1589
  };
1580
1590
  }
1591
+ /**
1592
+ * A publish Auto publish asked for runs as the publish skill's scripts, with no
1593
+ * agent session and so no SessionStart, no model turn and no closing line
1594
+ * (BAKER-231). True once Baker was told how it ended; false hands it to the
1595
+ * agent, which publishes as a person's press does.
1596
+ */
1597
+ async publishedWithoutAgent(job, controls, request) {
1598
+ if (!job.autoPublish ||
1599
+ !this.scriptedPublish ||
1600
+ verbatimSlashCommand(request.prompt) !== BridgeSlashCommands.Publish) {
1601
+ return false;
1602
+ }
1603
+ // No SDK event arrives while the steps run, and together they outlast the
1604
+ // watchdog's idle window: the turn is working, as a long command's is.
1605
+ controls.markEvent?.();
1606
+ controls.setWorkInFlight?.(true);
1607
+ const result = await this.scriptedPublish({
1608
+ // As the agent's commands get it: step 1 scopes the publish to this turn.
1609
+ env: { ...process.env, BAKER_THREAD_ID: job.threadId, BAKER_TURN_ID: job.turnId },
1610
+ signal: controls.abortSignal,
1611
+ }).finally(() => {
1612
+ controls.setWorkInFlight?.(false);
1613
+ controls.markEvent?.();
1614
+ });
1615
+ if (result.kind === "handOff") {
1616
+ console.warn(`[BridgeJob] Auto publish of ${job.threadId} stopped at ${result.step}; the agent publishes it`);
1617
+ return false;
1618
+ }
1619
+ await this.settleAfterPublish?.().catch((error) => {
1620
+ console.error(`[BridgeJob] could not settle the publish for ${job.threadId}`, error);
1621
+ });
1622
+ return true;
1623
+ }
1581
1624
  /**
1582
1625
  * The reviewer's prompt: the brief Convex wrote, with the evidence block this
1583
1626
  * Runtime can answer prepended.
@@ -1697,6 +1740,10 @@ export class BridgeJobExecutor {
1697
1740
  if (state.refusedWithoutFallback) {
1698
1741
  return { kind: "errored", costUsd, model: state.model, ...usage, errors: [MODEL_REFUSAL_MESSAGE] };
1699
1742
  }
1743
+ if (state.heldOutcome) {
1744
+ state.postedAssistantEvent = true;
1745
+ await this.relay.assistantEvent({ threadId: job.threadId, turnId: job.turnId }, state.heldOutcome, state.model);
1746
+ }
1700
1747
  if (!state.postedAssistantEvent && state.turnText.length > 0) {
1701
1748
  await this.postSyntheticAssistantEvent(job, state);
1702
1749
  }
@@ -2181,7 +2228,7 @@ export class BridgeJobExecutor {
2181
2228
  // the workspace could not be read; omit rather than allowlist nothing.
2182
2229
  ...(skills ? { skills } : {}),
2183
2230
  disallowedTools: disallowedToolsFor(job),
2184
- ...withSubagentHooks(withSubagentHooks(withCredentialScrub(answerOptions(job), job, state), await this.subagentHooksFor(job, state, sharedInstructions, model)), subagentSpendHooks(state)),
2231
+ ...withSubagentHooks(withSubagentHooks(withCredentialScrub(answerOptions(job), job, this.readLanguage), await this.subagentHooksFor(job, state, sharedInstructions, model)), subagentSpendHooks(state)),
2185
2232
  // Never omitted: since SDK 0.3.286 an omitted mode starts a third-party-provider
2186
2233
  // session (OpenRouter) in auto mode, where a classifier rather than `canUseTool`
2187
2234
  // decides tool calls.
@@ -2209,6 +2256,12 @@ export class BridgeJobExecutor {
2209
2256
  // system-reminder repeatedly pushed the agent toward that ephemeral
2210
2257
  // backlog instead of the product's own Tasks (`baker actions`).
2211
2258
  CLAUDE_CODE_ENABLE_TASKS: "0",
2259
+ // The CLI's English "The user hasn't heard from you in a while" nudge: the
2260
+ // lines written to it went out in English to a Spanish chat (BAKER-545).
2261
+ CLAUDE_CODE_SILENT_TURN_REMINDER: "0",
2262
+ // Without it, the CLI's WebSearch description demands a "Sources:" list and the
2263
+ // model wrote one in English under Spanish replies (BAKER-2094).
2264
+ CLAUDE_CODE_WEBSEARCH_CITATIONS: "1",
2212
2265
  // Every Bash command runs through a wrapper that makes it, not the agent
2213
2266
  // or the credential broker, what the OOM killer takes first (oom-priority.ts).
2214
2267
  ...agentShellPrefixEnv(killFirstWrapper(), process.env),
@@ -2324,7 +2377,6 @@ export class BridgeJobExecutor {
2324
2377
  // results) are real verdicts and must surface as-is; only errors from the
2325
2378
  // stream itself may be reinterpreted as a stall.
2326
2379
  let consumeError = false;
2327
- state.relayedLines.open();
2328
2380
  try {
2329
2381
  for await (const msg of query) {
2330
2382
  stallDetector.observeMessage(msg);
@@ -2354,7 +2406,6 @@ export class BridgeJobExecutor {
2354
2406
  }
2355
2407
  finally {
2356
2408
  drained = true;
2357
- state.relayedLines.close();
2358
2409
  controls.setWorkInFlight?.(false);
2359
2410
  stallDetector.dispose();
2360
2411
  turnEnd.dispose();
@@ -2446,8 +2497,6 @@ export class BridgeJobExecutor {
2446
2497
  if (this.droppedBeforeRelay(job, state, msg)) {
2447
2498
  return costUsd;
2448
2499
  }
2449
- // Before any await, so a tool's PostToolUse hook finds the call that made it.
2450
- state.relayedLines.observe(msg);
2451
2500
  state.inProgressSession = observeInProgressSession(state.inProgressSession, msg);
2452
2501
  this.recordInFlightSession(job, state);
2453
2502
  this.reportMcpFailures(job, msg);
@@ -2550,8 +2599,11 @@ export class BridgeJobExecutor {
2550
2599
  }
2551
2600
  if (msg.type === "assistant") {
2552
2601
  state.currentTurnTools = [];
2553
- state.postedAssistantEvent = true;
2554
- await this.relay.assistantEvent(target, msg, state.model);
2602
+ const relayed = state.detachedSession && !msg.parent_tool_use_id ? this.holdPublishWords(state, msg) : msg;
2603
+ if (relayed) {
2604
+ state.postedAssistantEvent = true;
2605
+ await this.relay.assistantEvent(target, relayed, state.model);
2606
+ }
2555
2607
  return;
2556
2608
  }
2557
2609
  const outcomes = toolOutcomesInMessage(msg);
@@ -2559,6 +2611,25 @@ export class BridgeJobExecutor {
2559
2611
  await this.relay.toolOutcomes(target, outcomes);
2560
2612
  }
2561
2613
  }
2614
+ /**
2615
+ * A publish turn's words wait for the turn to end: the marketer reads one message, the outcome, and a
2616
+ * note written between its steps went out in English and in git's words (BAKER-4674). Words followed by
2617
+ * a step were such a note and are dropped; the steps are relayed without them.
2618
+ */
2619
+ holdPublishWords(state, msg) {
2620
+ const content = msg.message.content;
2621
+ const steps = content.filter((block) => block.type !== "text" && block.type !== "thinking");
2622
+ const words = content.filter((block) => block.type === "text");
2623
+ const only = (blocks) => ({
2624
+ ...msg,
2625
+ message: { ...msg.message, content: blocks },
2626
+ });
2627
+ if (steps.some((block) => block.type === "tool_use"))
2628
+ state.heldOutcome = undefined;
2629
+ else if (words.length > 0)
2630
+ state.heldOutcome = only(words);
2631
+ return steps.length > 0 ? only(steps) : undefined;
2632
+ }
2562
2633
  /**
2563
2634
  * A message consumed here and never relayed or counted as the agent's work:
2564
2635
  * a provider refusal for size, the CLI's report of a failed model request, or
@@ -2702,7 +2773,9 @@ export class BridgeJobExecutor {
2702
2773
  const delta = event.delta;
2703
2774
  if (delta?.type === "text_delta" && typeof delta.text === "string") {
2704
2775
  state.turnText += delta.text;
2705
- this.relay.previewText(target, delta.text);
2776
+ // A publish turn's words wait for its end (`holdPublishWords`).
2777
+ if (!state.detachedSession)
2778
+ this.relay.previewText(target, delta.text);
2706
2779
  }
2707
2780
  // A progress note between tool calls (`progress-note.ts`). Previewed only: the
2708
2781
  // stored message carries it as a thinking block, which the transcript renders.
@@ -2710,6 +2783,7 @@ export class BridgeJobExecutor {
2710
2783
  if (delta?.type === "thinking_delta" &&
2711
2784
  typeof delta.thinking === "string" &&
2712
2785
  delta.thinking.length > 0 &&
2786
+ !state.detachedSession &&
2713
2787
  writesProgressNotes(state.model)) {
2714
2788
  this.relay.previewText(target, delta.thinking);
2715
2789
  }
@@ -3252,12 +3326,12 @@ function withMcpLoadNote(reminder, mcp) {
3252
3326
  return reminder ? `${reminder}\n\n${note}` : note;
3253
3327
  }
3254
3328
  /** Baker's notes for the turn, sent as their own block beside the prompt (see `SessionAttempt.reminder`). */
3255
- function turnReminder(job, verbatim, mainSync) {
3329
+ async function turnReminder(job, verbatim, mainSync, readLanguage) {
3256
3330
  const reminders = [
3257
3331
  mainSync,
3258
3332
  verbatim === null ? kickoffBriefReminder(job.kickoffBrief) : undefined,
3259
3333
  verbatim === null ? currentReferenceReminder(job.currentReference) : undefined,
3260
- verbatim === BridgeSlashCommands.Publish ? publishLanguageReminder(job.history) : undefined,
3334
+ verbatim === BridgeSlashCommands.Publish ? await publishLanguageReminder(job.history, readLanguage) : undefined,
3261
3335
  verbatim === null ? publishRunReminder(job.history) : undefined,
3262
3336
  verbatim === null ? publishStandingReminder(job) : undefined,
3263
3337
  credentialReminder(job.credentials ?? [], credentialsEnabled()),