typeclaw 0.47.2 → 0.48.1

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 (129) hide show
  1. package/package.json +1 -1
  2. package/src/agent/index.ts +1 -2
  3. package/src/agent/loop-guard.ts +71 -41
  4. package/src/agent/plugin-tools.ts +234 -58
  5. package/src/agent/system-prompt.ts +1 -1
  6. package/src/agent/turn-runner.ts +12 -2
  7. package/src/agent-messenger/config-dir.ts +131 -0
  8. package/src/agent-messenger/host-config-dir.ts +121 -0
  9. package/src/bundled-plugins/agent-browser/index.ts +0 -38
  10. package/src/bundled-plugins/agent-browser/skills/agent-browser/SKILL.md +1 -1
  11. package/src/bundled-plugins/guard/policies/non-workspace-write.ts +16 -1
  12. package/src/bundled-plugins/memory/append-tool.ts +75 -2
  13. package/src/bundled-plugins/memory/frontmatter.ts +13 -2
  14. package/src/bundled-plugins/memory/load-memory.ts +1 -1
  15. package/src/bundled-plugins/memory/memory-logger.ts +5 -1
  16. package/src/bundled-plugins/memory/secret-detector.ts +7 -0
  17. package/src/bundled-plugins/memory/vector/hybrid.ts +3 -1
  18. package/src/bundled-plugins/memory/vector/passages.ts +5 -1
  19. package/src/bundled-plugins/security/index.ts +148 -98
  20. package/src/bundled-plugins/security/policies/private-surface-read.ts +43 -28
  21. package/src/channels/adapters/discord-bot-edit.ts +3 -5
  22. package/src/channels/adapters/discord-bot-reactions.ts +4 -6
  23. package/src/channels/adapters/discord-bot-slash-commands.ts +3 -1
  24. package/src/channels/adapters/discord-bot.ts +20 -23
  25. package/src/channels/adapters/discord-edit.ts +3 -5
  26. package/src/channels/adapters/discord-reactions.ts +4 -6
  27. package/src/channels/adapters/discord.ts +1 -1
  28. package/src/channels/adapters/github/decoy-reviewer.ts +2 -1
  29. package/src/channels/adapters/github/history.ts +2 -1
  30. package/src/channels/adapters/github/inbound.ts +4 -11
  31. package/src/channels/adapters/github/index.ts +6 -9
  32. package/src/channels/adapters/github/outbound.ts +3 -6
  33. package/src/channels/adapters/github/reactions.ts +3 -2
  34. package/src/channels/adapters/github/reconcile-cooldown-store.ts +4 -6
  35. package/src/channels/adapters/github/reconcile-open-prs.ts +5 -4
  36. package/src/channels/adapters/github/recover-failed-deliveries.ts +2 -5
  37. package/src/channels/adapters/github/review-state.ts +3 -2
  38. package/src/channels/adapters/github/review-thread-resolver.ts +3 -2
  39. package/src/channels/adapters/github/webhook-register.ts +5 -8
  40. package/src/channels/adapters/instagram-channel-resolver.ts +3 -5
  41. package/src/channels/adapters/instagram.ts +1 -1
  42. package/src/channels/adapters/kakaotalk-author-resolver.ts +2 -5
  43. package/src/channels/adapters/kakaotalk-channel-resolver.ts +3 -5
  44. package/src/channels/adapters/kakaotalk-fetch-attachment.ts +2 -1
  45. package/src/channels/adapters/kakaotalk-membership.ts +2 -5
  46. package/src/channels/adapters/kakaotalk-typing.ts +1 -1
  47. package/src/channels/adapters/kakaotalk.ts +1 -1
  48. package/src/channels/adapters/line-channel-resolver.ts +3 -5
  49. package/src/channels/adapters/line.ts +1 -1
  50. package/src/channels/adapters/slack-bot-edit.ts +1 -1
  51. package/src/channels/adapters/slack-bot-reactions.ts +4 -6
  52. package/src/channels/adapters/slack-bot.ts +8 -8
  53. package/src/channels/adapters/slack-edit.ts +3 -5
  54. package/src/channels/adapters/slack-reactions.ts +4 -6
  55. package/src/channels/adapters/slack.ts +1 -1
  56. package/src/channels/adapters/teams-edit.ts +2 -5
  57. package/src/channels/adapters/teams.ts +1 -1
  58. package/src/channels/adapters/telegram-bot-edit.ts +4 -7
  59. package/src/channels/adapters/telegram-bot.ts +1 -1
  60. package/src/channels/adapters/webex-bot.ts +1 -1
  61. package/src/channels/adapters/webex-edit.ts +3 -5
  62. package/src/channels/adapters/webex.ts +1 -1
  63. package/src/channels/github-review-claim.ts +89 -4
  64. package/src/channels/github-token-bridge.ts +2 -1
  65. package/src/channels/manager.ts +478 -64
  66. package/src/channels/membership-cache.ts +2 -5
  67. package/src/channels/persistence.ts +3 -6
  68. package/src/channels/reloadable.ts +23 -6
  69. package/src/channels/router.ts +134 -56
  70. package/src/channels/tunnel-bridge.ts +2 -1
  71. package/src/channels/types.ts +6 -3
  72. package/src/cli/channel.ts +15 -16
  73. package/src/cli/hostd.ts +61 -38
  74. package/src/cli/init.ts +21 -7
  75. package/src/cli/model.ts +6 -3
  76. package/src/cli/restart.ts +13 -15
  77. package/src/compose/restart.ts +14 -6
  78. package/src/config/config.ts +10 -0
  79. package/src/config/providers.ts +68 -0
  80. package/src/container/agent-operation-lock.ts +85 -0
  81. package/src/container/controller.ts +6 -0
  82. package/src/container/index.ts +8 -0
  83. package/src/container/restart.ts +55 -0
  84. package/src/container/shared.ts +5 -0
  85. package/src/container/start.ts +70 -4
  86. package/src/container/stop.ts +17 -1
  87. package/src/dependencies/bin-resolver.ts +88 -0
  88. package/src/dependencies/bins.ts +227 -0
  89. package/src/dependencies/index.ts +17 -0
  90. package/src/doctor/checks.ts +2 -0
  91. package/src/doctor/operational-incidents.ts +32 -0
  92. package/src/hostd/credential-rotation-apply.ts +94 -0
  93. package/src/hostd/daemon.ts +1 -1
  94. package/src/hostd/paths.ts +17 -0
  95. package/src/hostd/supervisor.ts +27 -10
  96. package/src/init/dockerfile.ts +6 -5
  97. package/src/init/env-file.ts +42 -18
  98. package/src/init/instagram-auth.ts +55 -31
  99. package/src/init/kakaotalk-auth.ts +1 -5
  100. package/src/init/line-auth.ts +45 -29
  101. package/src/init/models-dev.ts +131 -10
  102. package/src/init/opengateway-catalog.ts +120 -0
  103. package/src/init/validate-api-key.ts +26 -4
  104. package/src/operations/classify-tool-outcome.ts +151 -0
  105. package/src/operations/incidents.ts +274 -0
  106. package/src/operations/index.ts +3 -0
  107. package/src/operations/remediations.ts +41 -0
  108. package/src/reload/client.ts +8 -2
  109. package/src/reload/docker-exec-client.ts +10 -2
  110. package/src/reload/index.ts +1 -1
  111. package/src/reload/recover.ts +5 -3
  112. package/src/reload/registry.ts +5 -5
  113. package/src/reload/types.ts +9 -1
  114. package/src/run/index.ts +5 -0
  115. package/src/sandbox/canonical-secrets.ts +10 -1
  116. package/src/sandbox/dependency-bins.ts +125 -0
  117. package/src/sandbox/hidden-paths.ts +4 -1
  118. package/src/sandbox/index.ts +8 -0
  119. package/src/sandbox/policy.ts +1 -1
  120. package/src/sandbox/privileged-runtime.ts +7 -12
  121. package/src/sandbox/runtime-private.ts +4 -0
  122. package/src/sandbox/writable-zones.ts +4 -4
  123. package/src/server/index.ts +7 -5
  124. package/src/shared/protocol.ts +6 -1
  125. package/src/test-helpers/fake-agent-operation-lock.ts +66 -0
  126. package/typeclaw.schema.json +10 -5
  127. package/src/bundled-plugins/agent-browser/shim-install.ts +0 -179
  128. package/src/bundled-plugins/agent-browser/shim.ts +0 -108
  129. /package/src/channels/{adapters/describe-error.ts → describe-error.ts} +0 -0
@@ -40,6 +40,7 @@ import type { Stream } from '@/stream'
40
40
  import { extractMentionedUserIds } from './adapters/mention-hints'
41
41
  import { formatChannelCommandHelp } from './commands'
42
42
  import { detectContinuationWillingness } from './continuation-willingness'
43
+ import { describeError } from './describe-error'
43
44
  import {
44
45
  countEffectiveHumans,
45
46
  decideEngagement,
@@ -1119,6 +1120,29 @@ type LiveSession = {
1119
1120
  // EARLIER iteration than the fallback; resetting per-iteration (beside
1120
1121
  // resetReviewTurn) would recreate the bug.
1121
1122
  githubReviewOutputTurn: number | null
1123
+ // True once this LOGICAL turn executed any tool. Read only by
1124
+ // `maybePostDeferredProviderError`: the provider-error notice exists so a
1125
+ // dead turn doesn't leave the human with silence, and a turn that ran tools
1126
+ // was not silent — it may already have published a review, a review-thread
1127
+ // reply, or any other out-of-band write that never bumps
1128
+ // `successfulChannelSends`. Approximating "produced durable output" with
1129
+ // "executed a tool" deliberately over-suppresses: an operator log records
1130
+ // every suppressed notice, whereas a public "connection dropped" comment
1131
+ // stranded above the agent's own successful review cannot be taken back. A
1132
+ // boolean rather than a `turnSeq` stamp so it survives the reminder-only
1133
+ // retry iterations that end the turn. Reset ONLY on a real user batch,
1134
+ // beside `githubReviewOutputTurn`.
1135
+ toolExecutionThisLogicalTurn: boolean
1136
+ // True while a successful `channel_reply({ more_work_this_turn: true })`
1137
+ // promise remains unfulfilled in this LOGICAL turn. Unlike the per-iteration
1138
+ // `continueReplyTurn` stamp used by retry authorization and empty-stop
1139
+ // recovery, this survives reminder-only iterations so a provider failure
1140
+ // cannot mistake earlier tool activity for completed user-visible work after
1141
+ // the promise stamp is cleared before the next prompt. A successful terminal
1142
+ // `channel_reply` clears it authoritatively; a substantive tool-source send
1143
+ // also fulfills it, while a continuation-willingness/status send preserves
1144
+ // it. A real user batch resets it beside `toolExecutionThisLogicalTurn`.
1145
+ promisedWorkOutstandingThisLogicalTurn: boolean
1122
1146
  // Captured by drain() at batch dequeue; read+cleared by send() on the
1123
1147
  // first tool-source send of the turn. The anchor decision (delay
1124
1148
  // threshold + intervening-observed check) is evaluated at SEND time
@@ -1217,6 +1241,12 @@ export type SendSource = 'tool' | 'system'
1217
1241
 
1218
1242
  export type SendOptions = {
1219
1243
  source?: SendSource
1244
+ // Classifies what the human saw, independently of which router path sent it.
1245
+ // Tool calls omit this: substantive text is the default, while the shared
1246
+ // multilingual willingness detector recognizes status updates. System paths
1247
+ // set it explicitly because recovery prose fulfills promised work whereas
1248
+ // provider/fallback/control notices are meta output and must not.
1249
+ outputKind?: 'substantive' | 'status' | 'meta'
1220
1250
  }
1221
1251
 
1222
1252
  export const DUPLICATE_SEND_ERROR =
@@ -1861,7 +1891,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
1861
1891
  merged.workspaceName = result.workspaceName
1862
1892
  }
1863
1893
  } catch (err) {
1864
- logger.warn(`[channels] name resolver threw for ${channelKeyId(key)}: ${describe(err)}`)
1894
+ logger.warn(`[channels] name resolver threw for ${channelKeyId(key)}: ${describeError(err)}`)
1865
1895
  }
1866
1896
  }
1867
1897
  return merged
@@ -1934,7 +1964,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
1934
1964
  if (cached.kind === 'hit') return cached.membership
1935
1965
  if (cached.kind === 'stale') {
1936
1966
  void cache.warmUp(scoped).catch((err) => {
1937
- logger.warn(`[channels] membership refresh failed for ${live.keyId}: ${describe(err)}`)
1967
+ logger.warn(`[channels] membership refresh failed for ${live.keyId}: ${describeError(err)}`)
1938
1968
  })
1939
1969
  return cached.membership
1940
1970
  }
@@ -2269,6 +2299,8 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
2269
2299
  emptyTurnFallbackTurn: null,
2270
2300
  stagedFallbackCause: null,
2271
2301
  githubReviewOutputTurn: null,
2302
+ toolExecutionThisLogicalTurn: false,
2303
+ promisedWorkOutstandingThisLogicalTurn: false,
2272
2304
  pendingQuoteCandidate: null,
2273
2305
  recentEngagedPeerBotTurns: [],
2274
2306
  consecutiveEngagedPeerBotTurns: 0,
@@ -2306,7 +2338,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
2306
2338
  turnId: live.sessionId,
2307
2339
  stopReason: usage.stopReason,
2308
2340
  ...(usage.tokens !== undefined ? { tokens: usage.tokens } : {}),
2309
- }).catch((err) => logger.error(`[channels] ${live.keyId}: todo outcome capture failed: ${describe(err)}`))
2341
+ }).catch((err) => logger.error(`[channels] ${live.keyId}: todo outcome capture failed: ${describeError(err)}`))
2310
2342
  })
2311
2343
  live.unsubTypingActivity = subscribeTypingActivity(created.session, live)
2312
2344
  installChannelReplyTerminalHook(live)
@@ -2377,7 +2409,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
2377
2409
  // ensureLive will treat as a usable warm session — strictly better than
2378
2410
  // a permanent silent drop. The caller (route() in this file, ultimately
2379
2411
  // the adapter's outer catch) sees the timeout error and logs it.
2380
- logger.error(`[channels] ${keyId}: ensureLive failed: ${describe(err)}`)
2412
+ logger.error(`[channels] ${keyId}: ensureLive failed: ${describeError(err)}`)
2381
2413
  throw err
2382
2414
  } finally {
2383
2415
  // Owner-checked delete: only clear the in-flight marker if it still points
@@ -2524,7 +2556,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
2524
2556
  await Promise.all(
2525
2557
  snapshot.map((cb) =>
2526
2558
  cb(target).catch((err) => {
2527
- logger.warn(`[channels] typing callback threw for ${live.keyId}: ${describe(err)}`)
2559
+ logger.warn(`[channels] typing callback threw for ${live.keyId}: ${describeError(err)}`)
2528
2560
  }),
2529
2561
  ),
2530
2562
  )
@@ -2651,8 +2683,15 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
2651
2683
  const details = context.result.details as { ok?: unknown; more_work_this_turn?: unknown } | undefined
2652
2684
  const succeeded = context.toolCall.name === 'channel_reply' && !context.isError && details?.ok === true
2653
2685
  const keepTurnAlive = details?.more_work_this_turn === true
2654
- if (succeeded && keepTurnAlive) {
2655
- live.continueReplyTurn = { turnSeq: live.turnSeq, sendCount: live.successfulChannelSends }
2686
+ if (succeeded) {
2687
+ // This hook is authoritative for channel_reply semantics: the send path
2688
+ // cannot distinguish channel_reply from channel_send, but here the
2689
+ // explicit more_work_this_turn flag tells us whether the delivered reply
2690
+ // renewed the promise or terminally fulfilled it.
2691
+ live.promisedWorkOutstandingThisLogicalTurn = keepTurnAlive
2692
+ if (keepTurnAlive) {
2693
+ live.continueReplyTurn = { turnSeq: live.turnSeq, sendCount: live.successfulChannelSends }
2694
+ }
2656
2695
  }
2657
2696
  if (succeeded && !keepTurnAlive && agent.signal?.aborted !== true) {
2658
2697
  logger.info(`[channels] ${live.keyId} terminal_after_channel_reply`)
@@ -2753,7 +2792,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
2753
2792
  try {
2754
2793
  await raceWithTimeout(work, sessionIdleTimeoutMs, `[channels] ${live.keyId} session.idle`)
2755
2794
  } catch (err) {
2756
- logger.warn(`[channels] session.idle hook threw for ${live.keyId}: ${describe(err)}`)
2795
+ logger.warn(`[channels] session.idle hook threw for ${live.keyId}: ${describeError(err)}`)
2757
2796
  }
2758
2797
  }
2759
2798
 
@@ -2761,7 +2800,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
2761
2800
  try {
2762
2801
  await recordTurnStart({ agentDir: options.agentDir, origin: buildLiveOrigin(live), isRealUserTurn })
2763
2802
  } catch (err) {
2764
- logger.warn(`[channels] ${live.keyId}: todo turn-start failed: ${describe(err)}`)
2803
+ logger.warn(`[channels] ${live.keyId}: todo turn-start failed: ${describeError(err)}`)
2765
2804
  }
2766
2805
  }
2767
2806
 
@@ -2783,7 +2822,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
2783
2822
  },
2784
2823
  })
2785
2824
  } catch (err) {
2786
- logger.warn(`[channels] ${live.keyId}: todo continuation failed: ${describe(err)}`)
2825
+ logger.warn(`[channels] ${live.keyId}: todo continuation failed: ${describeError(err)}`)
2787
2826
  }
2788
2827
  }
2789
2828
 
@@ -2798,7 +2837,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
2798
2837
  thread: live.key.thread,
2799
2838
  text: EMPTY_TURN_FALLBACK_TEXT,
2800
2839
  },
2801
- { source: 'system' },
2840
+ { source: 'system', outputKind: 'meta' },
2802
2841
  )
2803
2842
  if (!result.ok) {
2804
2843
  logger.warn(`[channels] ${live.keyId}: empty-turn fallback send failed: ${result.error}`)
@@ -2862,7 +2901,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
2862
2901
  retrievalContext,
2863
2902
  })
2864
2903
  } catch (err) {
2865
- logger.warn(`[channels] session.turn.start hook threw for ${live.keyId}: ${describe(err)}`)
2904
+ logger.warn(`[channels] session.turn.start hook threw for ${live.keyId}: ${describeError(err)}`)
2866
2905
  }
2867
2906
  return retrievalContext
2868
2907
  }
@@ -2876,7 +2915,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
2876
2915
  origin: buildLiveOrigin(live),
2877
2916
  })
2878
2917
  } catch (err) {
2879
- logger.warn(`[channels] session.turn.end hook threw for ${live.keyId}: ${describe(err)}`)
2918
+ logger.warn(`[channels] session.turn.end hook threw for ${live.keyId}: ${describeError(err)}`)
2880
2919
  }
2881
2920
  }
2882
2921
 
@@ -2919,7 +2958,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
2919
2958
  try {
2920
2959
  await live.hooks.runSessionEnd({ sessionId: live.sessionId })
2921
2960
  } catch (err) {
2922
- logger.warn(`[channels] session.end hook threw for ${live.keyId}: ${describe(err)}`)
2961
+ logger.warn(`[channels] session.end hook threw for ${live.keyId}: ${describeError(err)}`)
2923
2962
  }
2924
2963
  }
2925
2964
 
@@ -2935,7 +2974,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
2935
2974
  await live.session.abort()
2936
2975
  logger.info(`[channels] ${live.keyId}: command /stop aborted current turn`)
2937
2976
  } catch (err) {
2938
- logger.warn(`[channels] ${live.keyId}: command /stop abort failed: ${describe(err)}`)
2977
+ logger.warn(`[channels] ${live.keyId}: command /stop abort failed: ${describeError(err)}`)
2939
2978
  }
2940
2979
  }
2941
2980
 
@@ -2972,6 +3011,22 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
2972
3011
  live.pendingProviderError = null
2973
3012
  return
2974
3013
  }
3014
+ // The turn ran tools and promised nothing further, so it was not silent —
3015
+ // the very condition that makes recovery unsafe (`canAdvance` refuses to
3016
+ // fail over once `startedToolExecution` is set) also means a side effect
3017
+ // may already be public. Surfacing the notice here strands a "connection
3018
+ // dropped" warning above the agent's own successful work. A logical turn
3019
+ // holding an outstanding continue-reply promise is the opposite case: it
3020
+ // explicitly told the user more was coming, so dying silently WOULD leave
3021
+ // them waiting and the notice must still fire. Operators still get the
3022
+ // failure from the `LLM call failed` line plus this suppression record.
3023
+ if (live.toolExecutionThisLogicalTurn && !live.promisedWorkOutstandingThisLogicalTurn) {
3024
+ live.pendingProviderError = null
3025
+ logger.warn(
3026
+ `[channels] ${live.keyId}: provider_error_notice_suppressed reason=tool_activity_this_turn notice="${pending.safeMessage}"`,
3027
+ )
3028
+ return
3029
+ }
2975
3030
  // An empty-turn retry was queued (validateChannelTurn pushed
2976
3031
  // EMPTY_TURN_RETRY_NUDGE): the same logical turn re-prompts in the next
2977
3032
  // drain iteration and may yet recover. Carry the pending error forward,
@@ -2996,9 +3051,9 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
2996
3051
  thread: live.key.thread,
2997
3052
  text: `⚠️ ${pending.safeMessage}`,
2998
3053
  },
2999
- { source: 'system' },
3054
+ { source: 'system', outputKind: 'meta' },
3000
3055
  ).catch((sendErr) => {
3001
- logger.warn(`[channels] ${live.keyId}: provider-error notice send threw: ${describe(sendErr)}`)
3056
+ logger.warn(`[channels] ${live.keyId}: provider-error notice send threw: ${describeError(sendErr)}`)
3002
3057
  return null
3003
3058
  })
3004
3059
  if (result !== null && !result.ok) {
@@ -3086,6 +3141,8 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
3086
3141
  // review landed earlier in this logical turn keeps suppressing the
3087
3142
  // empty-turn fallback across the reminder-only retry iterations.
3088
3143
  live.githubReviewOutputTurn = null
3144
+ live.toolExecutionThisLogicalTurn = false
3145
+ live.promisedWorkOutstandingThisLogicalTurn = false
3089
3146
  } else if (live.lastTurnAuthorId !== null) {
3090
3147
  live.currentTurnEngageReactions = []
3091
3148
  // Reminder-only turn (batch.length === 0, reminders.length > 0):
@@ -3178,6 +3235,9 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
3178
3235
  `[channels] ${live.keyId}: ${attempt.outcome} failure on ${attempt.ref}: ${attempt.errorMessage ?? 'unknown'}; falling back`,
3179
3236
  )
3180
3237
  },
3238
+ onToolExecutionStarted: () => {
3239
+ live.toolExecutionThisLogicalTurn = true
3240
+ },
3181
3241
  })
3182
3242
  if (result.success) live.activeModelRef = result.refUsed
3183
3243
  await validateChannelTurn(live, successfulSendsBeforePrompt)
@@ -3218,7 +3278,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
3218
3278
  }
3219
3279
  logger.info(`[channels] ${live.keyId} prompted elapsed_ms=${now() - promptStart}`)
3220
3280
  } catch (err) {
3221
- logger.error(`[channels] ${live.keyId}: prompt threw: ${describe(err)}`)
3281
+ logger.error(`[channels] ${live.keyId}: prompt threw: ${describeError(err)}`)
3222
3282
  // Fallback is exhausted by now (promptPersistentTurnWithFallback only
3223
3283
  // throws after rotating every eligible ref), so a recognizable provider
3224
3284
  // failure is terminal for this turn. Stage a redacted notice for the
@@ -3279,7 +3339,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
3279
3339
  live.willingnessNudges > willingnessNudgesBeforePrompt
3280
3340
  await maybePostDeferredProviderError(
3281
3341
  live,
3282
- sentReplyThisTurn && !hasPendingContinueReply(live),
3342
+ sentReplyThisTurn && !live.promisedWorkOutstandingThisLogicalTurn,
3283
3343
  retryQueuedThisTurn,
3284
3344
  )
3285
3345
  await fireSessionTurnEnd(live)
@@ -3354,7 +3414,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
3354
3414
  try {
3355
3415
  successor = await ensureLive(key)
3356
3416
  } catch (err) {
3357
- logger.warn(`[channels] ${channelKeyId(key)}: successor recreate after reload failed: ${describe(err)}`)
3417
+ logger.warn(`[channels] ${channelKeyId(key)}: successor recreate after reload failed: ${describeError(err)}`)
3358
3418
  return
3359
3419
  }
3360
3420
  if (successor.destroyed) return
@@ -3426,7 +3486,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
3426
3486
  },
3427
3487
  })
3428
3488
  } catch (err) {
3429
- logger.warn(`[channels] inbound stream publish failed: ${err instanceof Error ? err.message : String(err)}`)
3489
+ logger.warn(`[channels] inbound stream publish failed: ${describeError(err)}`)
3430
3490
  }
3431
3491
  }
3432
3492
 
@@ -3446,7 +3506,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
3446
3506
  thread: event.thread,
3447
3507
  text: result.reply,
3448
3508
  },
3449
- { source: 'system' },
3509
+ { source: 'system', outputKind: 'meta' },
3450
3510
  )
3451
3511
  }
3452
3512
  return result
@@ -3493,7 +3553,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
3493
3553
  thread: event.thread,
3494
3554
  text: outcome.reply,
3495
3555
  },
3496
- { source: 'system' },
3556
+ { source: 'system', outputKind: 'meta' },
3497
3557
  )
3498
3558
  return
3499
3559
  }
@@ -3592,7 +3652,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
3592
3652
  if (cache !== undefined) {
3593
3653
  cache.invalidate(scoped)
3594
3654
  void cache.warmUp(scoped).catch((err) => {
3595
- logger.warn(`[channels] membership warmup after new author failed for ${live.keyId}: ${describe(err)}`)
3655
+ logger.warn(`[channels] membership warmup after new author failed for ${live.keyId}: ${describeError(err)}`)
3596
3656
  })
3597
3657
  }
3598
3658
  }
@@ -3832,7 +3892,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
3832
3892
  // throw is converted to a transient failure result so every caller gets a
3833
3893
  // uniform { ok: false } instead of an exception.
3834
3894
  const result = await cb(req).catch(
3835
- (err): ReactionResult => ({ ok: false, error: describe(err), code: 'transient' }),
3895
+ (err): ReactionResult => ({ ok: false, error: describeError(err), code: 'transient' }),
3836
3896
  )
3837
3897
  if (result.ok) return result
3838
3898
  lastError = result
@@ -3870,7 +3930,9 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
3870
3930
  }
3871
3931
  })
3872
3932
  .catch((err) => {
3873
- logger.info(`[channels] react-after-reply threw adapter=${req.adapter} chat=${req.chat}: ${describe(err)}`)
3933
+ logger.info(
3934
+ `[channels] react-after-reply threw adapter=${req.adapter} chat=${req.chat}: ${describeError(err)}`,
3935
+ )
3874
3936
  })
3875
3937
  }
3876
3938
  }
@@ -3886,7 +3948,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
3886
3948
  let lastError: ReactionResult | undefined
3887
3949
  for (const cb of Array.from(callbacks)) {
3888
3950
  const result = await cb(req).catch(
3889
- (err): ReactionResult => ({ ok: false, error: describe(err), code: 'transient' }),
3951
+ (err): ReactionResult => ({ ok: false, error: describeError(err), code: 'transient' }),
3890
3952
  )
3891
3953
  if (result.ok) return result
3892
3954
  lastError = result
@@ -3923,7 +3985,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
3923
3985
  }
3924
3986
  })
3925
3987
  .catch((err) => {
3926
- logger.info(`[channels] engage-react threw adapter=${event.adapter} chat=${event.chat}: ${describe(err)}`)
3988
+ logger.info(`[channels] engage-react threw adapter=${event.adapter} chat=${event.chat}: ${describeError(err)}`)
3927
3989
  })
3928
3990
  return addReactionRef
3929
3991
  }
@@ -3969,7 +4031,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
3969
4031
  })
3970
4032
  .catch((err) => {
3971
4033
  logger.info(
3972
- `[channels] engage-unreact threw adapter=${live.key.adapter} chat=${live.key.chat}: ${describe(err)}`,
4034
+ `[channels] engage-unreact threw adapter=${live.key.adapter} chat=${live.key.chat}: ${describeError(err)}`,
3973
4035
  )
3974
4036
  })
3975
4037
  }
@@ -4080,6 +4142,14 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
4080
4142
  ? `${capability}-adapter-unavailable: the "${adapter}" adapter is configured but not currently running (it likely failed to start, e.g. an expired token or auth error — check the container logs and re-authenticate)`
4081
4143
  : `${capability}-not-supported`
4082
4144
 
4145
+ // A live callback that throws or times out is a FAILURE of a capability the
4146
+ // adapter has, not the absence of one. Collapsing it into `*-not-supported`
4147
+ // would tell the model the feature does not exist, and it will relay that to
4148
+ // a human as fact. The underlying error stays in the logs rather than the
4149
+ // model-facing string, matching `missingCallbackError`.
4150
+ const callbackFailureError = (adapter: ChannelKey['adapter'], capability: ReadCapability): string =>
4151
+ `${capability}-adapter-error: the "${adapter}" adapter supports ${capability} but the call failed or timed out. This is a live adapter failure, NOT an unsupported capability — check the container logs for the underlying error, then retry.`
4152
+
4083
4153
  const isWriteCapabilityUnavailable = (adapter: ChannelKey['adapter'], capability: WriteCapability): boolean =>
4084
4154
  configuredAdapters.has(adapter) && ADAPTER_WRITE_CAPABILITIES[adapter].includes(capability)
4085
4155
 
@@ -4098,8 +4168,8 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
4098
4168
  if (result.ok) return result
4099
4169
  lastError = result
4100
4170
  } catch (err) {
4101
- logger.warn(`[channels] history fetch threw for ${adapter}: ${describe(err)}`)
4102
- lastError = { ok: false, error: 'history-not-supported' }
4171
+ logger.warn(`[channels] history fetch threw for ${adapter}: ${describeError(err)}`)
4172
+ lastError = { ok: false, error: callbackFailureError(adapter, 'history') }
4103
4173
  }
4104
4174
  }
4105
4175
  return lastError
@@ -4122,8 +4192,8 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
4122
4192
  try {
4123
4193
  return await raceWithTimeout(cb(args), fetchHistoryTimeoutMs, `[channels] ${adapter} message get`)
4124
4194
  } catch (err) {
4125
- logger.warn(`[channels] message get threw for ${adapter}: ${describe(err)}`)
4126
- return { ok: false, error: 'message-get-not-supported', code: 'not-supported' }
4195
+ logger.warn(`[channels] message get threw for ${adapter}: ${describeError(err)}`)
4196
+ return { ok: false, error: callbackFailureError(adapter, 'message-get'), code: 'adapter-error' }
4127
4197
  }
4128
4198
  }
4129
4199
 
@@ -4144,8 +4214,8 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
4144
4214
  try {
4145
4215
  return await raceWithTimeout(cb(args), fetchHistoryTimeoutMs, `[channels] ${adapter} list channels`)
4146
4216
  } catch (err) {
4147
- logger.warn(`[channels] list channels threw for ${adapter}: ${describe(err)}`)
4148
- return { ok: false, error: 'list-not-supported', code: 'not-supported' }
4217
+ logger.warn(`[channels] list channels threw for ${adapter}: ${describeError(err)}`)
4218
+ return { ok: false, error: callbackFailureError(adapter, 'list'), code: 'adapter-error' }
4149
4219
  }
4150
4220
  }
4151
4221
 
@@ -4195,8 +4265,8 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
4195
4265
  if (result.ok) return result
4196
4266
  lastError = result
4197
4267
  } catch (err) {
4198
- logger.warn(`[channels] edit message threw for ${req.adapter}: ${describe(err)}`)
4199
- lastError = { ok: false, error: `edit message failed: ${describe(err)}` }
4268
+ logger.warn(`[channels] edit message threw for ${req.adapter}: ${describeError(err)}`)
4269
+ lastError = { ok: false, error: `edit message failed: ${describeError(err)}` }
4200
4270
  }
4201
4271
  }
4202
4272
  return lastError
@@ -4262,7 +4332,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
4262
4332
  }
4263
4333
  }
4264
4334
  return await resolver(req).catch(
4265
- (err): ReviewThreadResolveResult => ({ ok: false, error: describe(err), code: 'transient' }),
4335
+ (err): ReviewThreadResolveResult => ({ ok: false, error: describeError(err), code: 'transient' }),
4266
4336
  )
4267
4337
  }
4268
4338
 
@@ -4282,7 +4352,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
4282
4352
  return { ok: false, error: `adapter "${req.adapter}" does not support review-state lookup`, code: 'unsupported' }
4283
4353
  }
4284
4354
  return await resolver(req).catch(
4285
- (err): ReviewStateResult => ({ ok: false, error: describe(err), code: 'transient' }),
4355
+ (err): ReviewStateResult => ({ ok: false, error: describeError(err), code: 'transient' }),
4286
4356
  )
4287
4357
  }
4288
4358
 
@@ -4300,7 +4370,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
4300
4370
  return { ok: false, error: `adapter "${req.adapter}" does not support review submission`, code: 'unsupported' }
4301
4371
  }
4302
4372
  return await submitter(req).catch(
4303
- (err): SubmitReviewResult => ({ ok: false, error: describe(err), code: 'transient' }),
4373
+ (err): SubmitReviewResult => ({ ok: false, error: describeError(err), code: 'transient' }),
4304
4374
  )
4305
4375
  }
4306
4376
 
@@ -4421,6 +4491,8 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
4421
4491
  live.pendingQuoteCandidate = null
4422
4492
  }
4423
4493
  const text = normalizeSendText(msg.text)
4494
+ const outputKind =
4495
+ opts?.outputKind ?? (text !== undefined && detectContinuationWillingness(text) ? 'status' : 'substantive')
4424
4496
 
4425
4497
  // Central enforcement. Tool-initiated sends are subject to two policies:
4426
4498
  // a per-turn count cap (kills runaway loops regardless of content) and
@@ -4553,6 +4625,16 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
4553
4625
 
4554
4626
  if (live) {
4555
4627
  live.successfulChannelSends++
4628
+ // Promise fulfillment follows OUTPUT KIND, never source:
4629
+ // (a) ordinary substantive tool output clears;
4630
+ // (b) multilingual continuation-willingness/status output preserves;
4631
+ // (c) recovery prose explicitly marked substantive clears even though
4632
+ // it uses the system bypass;
4633
+ // (d) provider-error, empty-turn-fallback, and control notices are
4634
+ // explicitly meta and preserve, so a warning can never self-clear.
4635
+ // The channel_reply afterToolCall hook above remains authoritative for its
4636
+ // machine-readable more_work_this_turn flag.
4637
+ if (outputKind === 'substantive') live.promisedWorkOutstandingThisLogicalTurn = false
4556
4638
  live.lastSendLeafId = live.session.sessionManager.getLeafEntry()?.id ?? null
4557
4639
  live.policyDeniedToolSendsThisTurn.delete(sendKey)
4558
4640
  // Don't stop the heartbeat here: the agent may still be mid-turn and
@@ -5152,7 +5234,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
5152
5234
  thread: live.key.thread,
5153
5235
  text: assistantText,
5154
5236
  },
5155
- { source: 'system' },
5237
+ { source: 'system', outputKind: 'substantive' },
5156
5238
  )
5157
5239
  if (!result.ok) {
5158
5240
  logger.warn(`[channels] ${live.keyId}: recovery send failed: ${result.error}`)
@@ -5252,13 +5334,13 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
5252
5334
  try {
5253
5335
  await live.session.abort()
5254
5336
  } catch (err) {
5255
- logger.warn(`[channels] abort failed for ${live.keyId}: ${describe(err)}`)
5337
+ logger.warn(`[channels] abort failed for ${live.keyId}: ${describeError(err)}`)
5256
5338
  }
5257
5339
  await fireSessionEnd(live)
5258
5340
  try {
5259
5341
  await live.dispose()
5260
5342
  } catch (err) {
5261
- logger.warn(`[channels] dispose failed for ${live.keyId}: ${describe(err)}`)
5343
+ logger.warn(`[channels] dispose failed for ${live.keyId}: ${describeError(err)}`)
5262
5344
  }
5263
5345
  }
5264
5346
 
@@ -5364,11 +5446,11 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
5364
5446
  for (const live of Array.from(liveSessions.values())) {
5365
5447
  const origin = buildLiveOrigin(live)
5366
5448
  await markRestartAbortPendingForOrigin(options.agentDir, origin).catch((err) =>
5367
- logger.error(`[channels] graceful-restart mark abort failed: ${describe(err)}`),
5449
+ logger.error(`[channels] graceful-restart mark abort failed: ${describeError(err)}`),
5368
5450
  )
5369
5451
  await live.session
5370
5452
  .abort()
5371
- .catch((err) => logger.error(`[channels] graceful-restart abort failed: ${describe(err)}`))
5453
+ .catch((err) => logger.error(`[channels] graceful-restart abort failed: ${describeError(err)}`))
5372
5454
  }
5373
5455
  }
5374
5456
 
@@ -5515,7 +5597,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
5515
5597
  sessionFile: handoff.originatingSessionFile,
5516
5598
  })
5517
5599
  } catch (err) {
5518
- logger.warn(`[channels] ${keyId}: restart-resume ensureLive failed: ${describe(err)}`)
5600
+ logger.warn(`[channels] ${keyId}: restart-resume ensureLive failed: ${describeError(err)}`)
5519
5601
  rejectGate(err)
5520
5602
  return
5521
5603
  }
@@ -5555,13 +5637,13 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
5555
5637
  }
5556
5638
 
5557
5639
  await armRestartKickForOrigin(options.agentDir, buildLiveOrigin(live)).catch((err) =>
5558
- logger.error(`[channels] ${keyId}: restart-resume arm restart-kick failed: ${describe(err)}`),
5640
+ logger.error(`[channels] ${keyId}: restart-resume arm restart-kick failed: ${describeError(err)}`),
5559
5641
  )
5560
5642
  // A restart-aborted turn arms the durable user-abort block; this resume
5561
5643
  // IS the restart, so clear it or the resumed session never auto-resumes
5562
5644
  // its incomplete todos. Gated to this restart-handoff path.
5563
5645
  await clearAbortSuppressionForOrigin(options.agentDir, buildLiveOrigin(live)).catch((err) =>
5564
- logger.error(`[channels] ${keyId}: restart-resume clear abort suppression failed: ${describe(err)}`),
5646
+ logger.error(`[channels] ${keyId}: restart-resume clear abort suppression failed: ${describeError(err)}`),
5565
5647
  )
5566
5648
 
5567
5649
  live.pendingSystemReminders.push(buildRestartResumeWakeReminder(handoff.interruptedSubagents))
@@ -5838,7 +5920,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
5838
5920
  })
5839
5921
  .catch((err) => {
5840
5922
  logger.info(
5841
- `[channels] disengage-react threw adapter=${live.key.adapter} chat=${live.key.chat}: ${describe(err)}`,
5923
+ `[channels] disengage-react threw adapter=${live.key.adapter} chat=${live.key.chat}: ${describeError(err)}`,
5842
5924
  )
5843
5925
  })
5844
5926
  }
@@ -5879,7 +5961,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
5879
5961
  })
5880
5962
  .catch((err) => {
5881
5963
  logger.info(
5882
- `[channels] silent-ack-react threw reason=${reason} adapter=${live.key.adapter} chat=${live.key.chat}: ${describe(err)}`,
5964
+ `[channels] silent-ack-react threw reason=${reason} adapter=${live.key.adapter} chat=${live.key.chat}: ${describeError(err)}`,
5883
5965
  )
5884
5966
  })
5885
5967
  // Register the add promise (not its resolved ref) SYNCHRONOUSLY, so a later
@@ -5920,7 +6002,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
5920
6002
  })
5921
6003
  .catch((err) => {
5922
6004
  logger.info(
5923
- `[channels] silent-ack-unreact threw adapter=${live.key.adapter} chat=${live.key.chat}: ${describe(err)}`,
6005
+ `[channels] silent-ack-unreact threw adapter=${live.key.adapter} chat=${live.key.chat}: ${describeError(err)}`,
5924
6006
  )
5925
6007
  }),
5926
6008
  ),
@@ -6692,7 +6774,7 @@ function tryOpenSessionManager(
6692
6774
  return SessionManager.open(path)
6693
6775
  } catch (err) {
6694
6776
  logger.warn(
6695
- `[channels] could not rehydrate session ${existingSessionId} from ${existingSessionFile}: ${describe(err)}; creating new`,
6777
+ `[channels] could not rehydrate session ${existingSessionId} from ${existingSessionFile}: ${describeError(err)}; creating new`,
6696
6778
  )
6697
6779
  return SessionManager.create(agentDir, sessionDir)
6698
6780
  }
@@ -7761,10 +7843,6 @@ function readStringValue(s: string, from: number, quote: string): string | null
7761
7843
 
7762
7844
  const ESCAPE_REPLACEMENTS: Record<string, string> = { n: '\n', r: '\r', t: '\t' }
7763
7845
 
7764
- function describe(err: unknown): string {
7765
- return err instanceof Error ? err.message : String(err)
7766
- }
7767
-
7768
7846
  // Used by tests / external diagnostics.
7769
7847
  export type { ChannelSessionRecord }
7770
7848
  export { channelsSessionsPath }
@@ -1,6 +1,7 @@
1
1
  import type { Stream } from '@/stream'
2
2
  import { isTunnelUrlChangedPayload } from '@/tunnels'
3
3
 
4
+ import { describeError } from './describe-error'
4
5
  import type { AdapterId } from './schema'
5
6
 
6
7
  export type TunnelBridgeLogger = {
@@ -41,7 +42,7 @@ export function createTunnelBridge(options: TunnelBridgeOptions): TunnelBridge {
41
42
  if (typeof name !== 'string') return
42
43
  logger.info(`[tunnels] ${name} URL → restarting adapter`)
43
44
  void options.channelManager.restartAdapter(name as AdapterId).catch((err: unknown) => {
44
- logger.error(`[tunnels] failed to restart ${name} adapter: ${err instanceof Error ? err.message : String(err)}`)
45
+ logger.error(`[tunnels] failed to restart ${name} adapter: ${describeError(err)}`)
45
46
  })
46
47
  })
47
48
 
@@ -430,8 +430,11 @@ export type GetMessageResult =
430
430
  // as a soft error; `code: 'not-supported'` means the adapter is not configured
431
431
  // at all; `code: 'adapter-unavailable'` means it IS configured but currently
432
432
  // has no live callback (e.g. failed to start), mirroring `fetchHistory`'s
433
- // 'message-get-adapter-unavailable' string contract.
434
- | { ok: false; error: string; code?: 'not-found' | 'not-supported' | 'adapter-unavailable' }
433
+ // 'message-get-adapter-unavailable' string contract; `code: 'adapter-error'`
434
+ // means a live callback threw or timed out. That last one must never collapse
435
+ // into 'not-supported' — a thrown 401 reported as "unsupported" teaches the
436
+ // model the capability does not exist, and it will say so to a human.
437
+ | { ok: false; error: string; code?: 'not-found' | 'not-supported' | 'adapter-unavailable' | 'adapter-error' }
435
438
 
436
439
  export type MessageGetCallback = (args: GetMessageArgs) => Promise<GetMessageResult>
437
440
 
@@ -454,7 +457,7 @@ export type ListChannelsArgs = {
454
457
 
455
458
  export type ListChannelsResult =
456
459
  | { ok: true; entries: ChannelListEntry[]; nextCursor?: string }
457
- | { ok: false; error: string; code?: 'not-supported' | 'adapter-unavailable' }
460
+ | { ok: false; error: string; code?: 'not-supported' | 'adapter-unavailable' | 'adapter-error' }
458
461
 
459
462
  // Backs the `channel_read` tool's `mode: "list"`. Opt-in per adapter like
460
463
  // history; the router answers 'list-not-supported' when none is registered.
@@ -654,16 +654,12 @@ async function maybePromptCredentialRefresh(
654
654
  return
655
655
  }
656
656
 
657
- const stopped = await controller.stop({ cwd })
658
- if (!stopped.ok) {
659
- console.error(errorLine(`Restart failed during stop: ${stopped.reason}`))
660
- process.exit(1)
661
- }
662
- const started = await controller.start({ cwd, preferredHostPort: config.port, cliEntry: process.argv[1] })
663
- if (!started.ok) {
664
- console.error(errorLine(`Restart failed during start: ${started.reason}`))
657
+ const restarted = await controller.restart({ cwd, preferredHostPort: config.port, cliEntry: process.argv[1] })
658
+ if (!restarted.ok) {
659
+ console.error(errorLine(formatRestartFailure(restarted.reason)))
665
660
  process.exit(1)
666
661
  }
662
+ const started = restarted.start
667
663
  done({
668
664
  title: c.green(`${label} ${verbPast}. Restarted ${started.plan.containerName} on host port ${started.hostPort}.`),
669
665
  hints: [
@@ -2002,16 +1998,12 @@ async function maybePromptRestart(
2002
1998
  return
2003
1999
  }
2004
2000
 
2005
- const stopped = await controller.stop({ cwd })
2006
- if (!stopped.ok) {
2007
- console.error(errorLine(`Restart failed during stop: ${stopped.reason}`))
2008
- process.exit(1)
2009
- }
2010
- const started = await controller.start({ cwd, preferredHostPort: config.port, cliEntry: process.argv[1] })
2011
- if (!started.ok) {
2012
- console.error(errorLine(`Restart failed during start: ${started.reason}`))
2001
+ const restarted = await controller.restart({ cwd, preferredHostPort: config.port, cliEntry: process.argv[1] })
2002
+ if (!restarted.ok) {
2003
+ console.error(errorLine(formatRestartFailure(restarted.reason)))
2013
2004
  process.exit(1)
2014
2005
  }
2006
+ const started = restarted.start
2015
2007
  done({
2016
2008
  title: c.green(
2017
2009
  `${label} channel ${verb}. Restarted ${started.plan.containerName} on host port ${started.hostPort}.`,
@@ -2022,3 +2014,10 @@ async function maybePromptRestart(
2022
2014
  ],
2023
2015
  })
2024
2016
  }
2017
+
2018
+ function formatRestartFailure(reason: string): string {
2019
+ if (reason.startsWith('stop failed: ')) return `Restart failed during stop: ${reason.slice('stop failed: '.length)}`
2020
+ if (reason.startsWith('start failed: '))
2021
+ return `Restart failed during start: ${reason.slice('start failed: '.length)}`
2022
+ return `Restart failed: ${reason}`
2023
+ }