typeclaw 0.48.7 → 0.48.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.
Files changed (108) hide show
  1. package/auth.schema.json +15 -1
  2. package/package.json +1 -1
  3. package/secrets.schema.json +15 -1
  4. package/src/agent/guard-types.ts +25 -0
  5. package/src/agent/guards.ts +102 -0
  6. package/src/agent/index.ts +33 -3
  7. package/src/agent/multimodal/read-redirect.ts +8 -9
  8. package/src/agent/plugin-tools.ts +283 -148
  9. package/src/agent/provider-error.ts +6 -1
  10. package/src/agent/reload-tool.ts +12 -5
  11. package/src/agent/retry-same-ref.ts +95 -36
  12. package/src/agent/session-origin.ts +13 -1
  13. package/src/agent/system-prompt.ts +14 -3
  14. package/src/agent/todo/continuation-policy.ts +3 -4
  15. package/src/agent/tool-file-safety.ts +36 -13
  16. package/src/agent/tools/channel-reply.ts +39 -2
  17. package/src/agent/tools/channel-send.ts +45 -2
  18. package/src/agent/tools/post-github-review.ts +31 -13
  19. package/src/agent/tools/spawn-subagent.ts +15 -0
  20. package/src/agent/tools/webfetch/inline-style-visibility.ts +2 -2
  21. package/src/agent/tools/webfetch/strategies/readability.ts +109 -10
  22. package/src/agent/turn-runner.ts +23 -19
  23. package/src/bundled-plugins/backup/git-auth.ts +7 -4
  24. package/src/bundled-plugins/backup/subagents.ts +1 -1
  25. package/src/bundled-plugins/bun-hygiene/README.md +23 -20
  26. package/src/bundled-plugins/bun-hygiene/index.ts +1 -7
  27. package/src/bundled-plugins/bun-hygiene/policy.ts +111 -35
  28. package/src/bundled-plugins/github-cli-auth/gh-review-detect.ts +44 -2
  29. package/src/bundled-plugins/github-cli-auth/gh-store.ts +733 -0
  30. package/src/bundled-plugins/github-cli-auth/git-askpass.ts +25 -0
  31. package/src/bundled-plugins/github-cli-auth/git-command.ts +209 -31
  32. package/src/bundled-plugins/github-cli-auth/git-credential-env.ts +151 -0
  33. package/src/bundled-plugins/github-cli-auth/index.ts +236 -38
  34. package/src/bundled-plugins/github-cli-auth/review-recorder.ts +5 -0
  35. package/src/bundled-plugins/guard/index.ts +2 -25
  36. package/src/bundled-plugins/guard/keys.ts +8 -0
  37. package/src/bundled-plugins/guard/policies/non-workspace-write.ts +7 -8
  38. package/src/bundled-plugins/guard/policy.ts +1 -7
  39. package/src/bundled-plugins/security/policies/git-exfil.ts +22 -30
  40. package/src/bundled-plugins/security/policies/outbound-secret-scan.ts +2 -4
  41. package/src/bundled-plugins/security/policies/private-surface-read.ts +8 -6
  42. package/src/bundled-plugins/security/policies/secret-exfil-bash.ts +2 -5
  43. package/src/bundled-plugins/security/policies/secret-exfil-read.ts +2 -4
  44. package/src/bundled-plugins/security/policies/session-search-secrets.ts +2 -4
  45. package/src/bundled-plugins/security/policies/system-prompt-leak.ts +2 -4
  46. package/src/bundled-plugins/security/policy.ts +0 -8
  47. package/src/channels/adapters/discord-bot-slash-commands.ts +22 -0
  48. package/src/channels/adapters/discord-bot.ts +2 -1
  49. package/src/channels/adapters/discord-classify.ts +16 -4
  50. package/src/channels/adapters/discord.ts +20 -8
  51. package/src/channels/adapters/github/dedup.ts +37 -8
  52. package/src/channels/adapters/github/inbound.ts +241 -46
  53. package/src/channels/adapters/github/review-state.ts +13 -9
  54. package/src/channels/adapters/github/review-thread-resolver.ts +52 -20
  55. package/src/channels/adapters/slack-bot.ts +13 -3
  56. package/src/channels/adapters/slack-classify.ts +40 -5
  57. package/src/channels/adapters/slack.ts +3 -9
  58. package/src/channels/adapters/teams.ts +8 -6
  59. package/src/channels/adapters/webex-bot-classify.ts +4 -33
  60. package/src/channels/adapters/webex-bot.ts +2 -4
  61. package/src/channels/adapters/webex-classify.ts +4 -33
  62. package/src/channels/adapters/webex-format.ts +36 -0
  63. package/src/channels/adapters/webex.ts +2 -4
  64. package/src/channels/continuation-willingness.ts +64 -39
  65. package/src/channels/github-rereview-guard.ts +20 -0
  66. package/src/channels/github-review-turn-ledger.ts +11 -1
  67. package/src/channels/github-review-verdict-coordinator.ts +475 -41
  68. package/src/channels/github-verdict-activity.ts +14 -5
  69. package/src/channels/manager.ts +17 -1
  70. package/src/channels/persistence.ts +89 -5
  71. package/src/channels/router.ts +1187 -254
  72. package/src/channels/types.ts +21 -5
  73. package/src/cli/compose-stats.ts +6 -7
  74. package/src/cli/compose-status.ts +6 -7
  75. package/src/cli/compose-usage.ts +6 -7
  76. package/src/cli/stats.ts +6 -7
  77. package/src/cli/status.ts +7 -8
  78. package/src/cli/ui.ts +4 -4
  79. package/src/container/start.ts +41 -1
  80. package/src/container/stop.ts +2 -1
  81. package/src/cron/consumer.ts +30 -9
  82. package/src/cron/scheduler.ts +24 -9
  83. package/src/doctor/channel-checks.ts +64 -0
  84. package/src/doctor/report.ts +8 -8
  85. package/src/dreams/render.ts +2 -2
  86. package/src/init/dockerfile.ts +8 -1
  87. package/src/inspect/render.ts +2 -2
  88. package/src/path-safety/real-intended-path.ts +14 -1
  89. package/src/permissions/permissions.ts +10 -2
  90. package/src/permissions/resolve.ts +8 -2
  91. package/src/plugin/core-tool-names.ts +15 -0
  92. package/src/plugin/hooks.ts +37 -3
  93. package/src/plugin/registry.ts +7 -3
  94. package/src/run/index.ts +33 -7
  95. package/src/sandbox/build.ts +39 -10
  96. package/src/sandbox/policy.ts +6 -2
  97. package/src/secrets/export-github-cli-store.ts +158 -0
  98. package/src/secrets/index.ts +19 -1
  99. package/src/secrets/provision-github-cli-store.ts +322 -0
  100. package/src/secrets/schema.ts +13 -7
  101. package/src/secrets/storage.ts +30 -0
  102. package/src/shared/index.ts +2 -0
  103. package/src/shared/style-text.ts +13 -0
  104. package/src/skills/typeclaw-channel-github/SKILL.md +24 -12
  105. package/src/skills/typeclaw-config/SKILL.md +3 -1
  106. package/src/skills/typeclaw-github-contributing/SKILL.md +6 -2
  107. package/src/skills/typeclaw-permissions/SKILL.md +11 -22
  108. package/src/usage/report.ts +3 -3
@@ -46,11 +46,21 @@ export type InboundAttachment = {
46
46
  sizeBytes?: number
47
47
  }
48
48
 
49
+ export type GithubReviewFollowupRound = {
50
+ kind: 'push' | 'reply'
51
+ roundId: string
52
+ workspace: string
53
+ prNumber: number
54
+ headSha: string
55
+ carrierThread: string | null
56
+ }
57
+
49
58
  export type InboundMessage = {
50
59
  adapter: AdapterId
51
60
  workspace: string
52
61
  chat: string
53
62
  thread: string | null
63
+ githubReviewRound?: GithubReviewFollowupRound
54
64
  // Structural "this message lives in a thread room" signal, kept SEPARATE
55
65
  // from `thread`. `thread` is a reply-routing field whose meaning differs per
56
66
  // platform: Slack puts the thread ts here (so `thread !== null` ⇒ thread
@@ -494,10 +504,10 @@ export type ReviewThreadResolveRequest = {
494
504
  rootCommentId: string
495
505
  }
496
506
 
497
- // `already-resolved` is a success-shaped no-op: the thread was closed before we
498
- // got here (a duplicate turn, a manual resolve), so the desired end state holds
499
- // and the caller should treat it like `ok: true`. `not-author` is a hard
500
- // refusal: the root comment is not the bot's, so resolving would erase a
507
+ // `alreadyResolved` is a success-shaped no-op: the thread was closed before we
508
+ // got here (a duplicate turn, a manual resolve), so the desired end state holds,
509
+ // but the caller MUST NOT post a second close-out receipt. `not-author` is a
510
+ // hard refusal: the root comment is not the bot's, so resolving would erase a
501
511
  // human's open question — the caller must NOT proceed as if it closed the loop.
502
512
  //
503
513
  // `no-match` is the ONLY non-blocking failure: the PR's threads listed cleanly
@@ -546,7 +556,13 @@ export type ReviewStateRequest = {
546
556
  // treated like a live block, so the bot never claims close-out when the runtime
547
557
  // could not confirm the platform-side verdict.
548
558
  export type ReviewStateResult =
549
- | { ok: true; selfBlocking: boolean; approve: boolean; reviewDecision?: GithubReviewDecision }
559
+ | {
560
+ ok: true
561
+ selfBlocking: boolean
562
+ selfBlockingReviewId: number | null
563
+ approve: boolean
564
+ reviewDecision?: GithubReviewDecision
565
+ }
550
566
  | { ok: false; error: string; code?: 'unsupported' | 'not-found' | 'permission-denied' | 'transient' }
551
567
 
552
568
  export type GithubReviewDecision = 'APPROVED' | 'CHANGES_REQUESTED' | 'REVIEW_REQUIRED'
@@ -1,6 +1,5 @@
1
- import { styleText } from 'node:util'
2
-
3
1
  import type { AgentStatsState, ComposeStatsResult } from '@/compose'
2
+ import { styled } from '@/shared'
4
3
 
5
4
  export type FormatComposeStatsOptions = { useColor?: boolean }
6
5
 
@@ -23,11 +22,11 @@ const NO_PALETTE: Palette = {
23
22
  }
24
23
 
25
24
  const COLOR_PALETTE: Palette = {
26
- bold: (s) => styleText('bold', s),
27
- dim: (s) => styleText('dim', s),
28
- green: (s) => styleText('green', s),
29
- yellow: (s) => styleText('yellow', s),
30
- cyan: (s) => styleText('cyan', s),
25
+ bold: (s) => styled('bold', s),
26
+ dim: (s) => styled('dim', s),
27
+ green: (s) => styled('green', s),
28
+ yellow: (s) => styled('yellow', s),
29
+ cyan: (s) => styled('cyan', s),
31
30
  }
32
31
 
33
32
  const STATE_LABELS: Record<AgentStatsState, string> = {
@@ -1,6 +1,5 @@
1
- import { styleText } from 'node:util'
2
-
3
1
  import type { AgentRuntimeState, ComposeStatusResult } from '@/compose'
2
+ import { styled } from '@/shared'
4
3
 
5
4
  export type FormatComposeStatusOptions = { useColor?: boolean }
6
5
 
@@ -23,11 +22,11 @@ const NO_PALETTE: Palette = {
23
22
  }
24
23
 
25
24
  const COLOR_PALETTE: Palette = {
26
- bold: (s) => styleText('bold', s),
27
- dim: (s) => styleText('dim', s),
28
- green: (s) => styleText('green', s),
29
- yellow: (s) => styleText('yellow', s),
30
- cyan: (s) => styleText('cyan', s),
25
+ bold: (s) => styled('bold', s),
26
+ dim: (s) => styled('dim', s),
27
+ green: (s) => styled('green', s),
28
+ yellow: (s) => styled('yellow', s),
29
+ cyan: (s) => styled('cyan', s),
31
30
  }
32
31
 
33
32
  const STATE_LABELS: Record<AgentRuntimeState, string> = {
@@ -1,6 +1,5 @@
1
- import { styleText } from 'node:util'
2
-
3
1
  import type { ComposeUsageResult } from '@/compose'
2
+ import { styled } from '@/shared'
4
3
  import type { UsageReport, UsageTotals } from '@/usage'
5
4
  import { formatCacheHitRate, formatCost, formatTokens } from '@/usage/format'
6
5
 
@@ -20,11 +19,11 @@ type Palette = {
20
19
  const identity: ColorFn = (s) => s
21
20
  const NO_PALETTE: Palette = { bold: identity, dim: identity, cyan: identity, yellow: identity, red: identity }
22
21
  const COLOR_PALETTE: Palette = {
23
- bold: (s) => styleText('bold', s),
24
- dim: (s) => styleText('dim', s),
25
- cyan: (s) => styleText('cyan', s),
26
- yellow: (s) => styleText('yellow', s),
27
- red: (s) => styleText('red', s),
22
+ bold: (s) => styled('bold', s),
23
+ dim: (s) => styled('dim', s),
24
+ cyan: (s) => styled('cyan', s),
25
+ yellow: (s) => styled('yellow', s),
26
+ red: (s) => styled('red', s),
28
27
  }
29
28
 
30
29
  export function formatComposeUsage(result: ComposeUsageResult, opts: FormatComposeUsageOptions = {}): string {
package/src/cli/stats.ts CHANGED
@@ -1,9 +1,8 @@
1
- import { styleText } from 'node:util'
2
-
3
1
  import { defineCommand } from 'citty'
4
2
 
5
3
  import { type ContainerStats, type DockerExec, resolveController } from '@/container'
6
4
  import { findAgentDir } from '@/init'
5
+ import { styled } from '@/shared'
7
6
 
8
7
  import { type DockerPreflightResult, preflightDocker, printDockerGuidance } from './docker-preflight'
9
8
 
@@ -72,11 +71,11 @@ const NO_PALETTE: Palette = {
72
71
  }
73
72
 
74
73
  const COLOR_PALETTE: Palette = {
75
- bold: (s) => styleText('bold', s),
76
- dim: (s) => styleText('dim', s),
77
- green: (s) => styleText('green', s),
78
- yellow: (s) => styleText('yellow', s),
79
- cyan: (s) => styleText('cyan', s),
74
+ bold: (s) => styled('bold', s),
75
+ dim: (s) => styled('dim', s),
76
+ green: (s) => styled('green', s),
77
+ yellow: (s) => styled('yellow', s),
78
+ cyan: (s) => styled('cyan', s),
80
79
  }
81
80
 
82
81
  export function formatStats(report: StatsReport, opts: FormatOptions = {}): string {
package/src/cli/status.ts CHANGED
@@ -1,11 +1,10 @@
1
- import { styleText } from 'node:util'
2
-
3
1
  import { defineCommand } from 'citty'
4
2
 
5
3
  import { type ContainerStatus, type DockerExec, resolveController } from '@/container'
6
4
  import { isDaemonReachable, send } from '@/hostd'
7
5
  import type { StatusResult } from '@/hostd'
8
6
  import { findAgentDir } from '@/init'
7
+ import { styled } from '@/shared'
9
8
 
10
9
  import { type DockerPreflightResult, preflightDocker, printDockerGuidance } from './docker-preflight'
11
10
 
@@ -113,12 +112,12 @@ const NO_PALETTE: Palette = {
113
112
  }
114
113
 
115
114
  const COLOR_PALETTE: Palette = {
116
- bold: (s) => styleText('bold', s),
117
- dim: (s) => styleText('dim', s),
118
- green: (s) => styleText('green', s),
119
- yellow: (s) => styleText('yellow', s),
120
- red: (s) => styleText('red', s),
121
- cyan: (s) => styleText('cyan', s),
115
+ bold: (s) => styled('bold', s),
116
+ dim: (s) => styled('dim', s),
117
+ green: (s) => styled('green', s),
118
+ yellow: (s) => styled('yellow', s),
119
+ red: (s) => styled('red', s),
120
+ cyan: (s) => styled('cyan', s),
122
121
  }
123
122
 
124
123
  export function formatStatus(report: StatusReport, opts: FormatOptions = {}): string {
package/src/cli/ui.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { emitKeypressEvents as nodeEmitKeypressEvents } from 'node:readline'
2
- import { styleText } from 'node:util'
3
2
 
4
3
  import { cancel, intro, isCancel, log, note, outro, spinner as clackSpinner } from '@clack/prompts'
5
4
 
6
5
  import { buildDiscordInviteUrl, deriveAppIdFromBotToken } from '@/channels/adapters/discord-bot-invite'
7
6
  import { type AutoUpgradeOutcome, describeAutoUpgrade } from '@/init/auto-upgrade'
7
+ import { styled, type StyleFormat } from '@/shared'
8
8
  import { COMPACT_WORDMARK, WORDMARK_LINES, WORDMARK_WIDTH } from '@/shared/wordmark'
9
9
 
10
10
  export { cancel, intro, isCancel, log, note, outro }
@@ -44,9 +44,9 @@ export function prepareStdinForClack(input: ClackInput = process.stdin, deps: Pr
44
44
  input.resume()
45
45
  }
46
46
 
47
- function colorize(modifier: Parameters<typeof styleText>[0], s: string): string {
47
+ function colorize(modifier: StyleFormat, s: string): string {
48
48
  if (!colorsEnabled()) return s
49
- return styleText(modifier, s)
49
+ return styled(modifier, s)
50
50
  }
51
51
 
52
52
  // Re-evaluated per call so tests can mutate NO_COLOR / FORCE_COLOR between
@@ -77,7 +77,7 @@ export function link(text: string, url: string): string {
77
77
  }
78
78
 
79
79
  // Brand truecolor sampled from the typeey mascot, matching src/tui/theme.ts.
80
- // `c`/styleText only carry the 16 named colors, so the cornflower/amber accents
80
+ // `c`/styled only carry the 16 named colors, so the cornflower/amber accents
81
81
  // are emitted as raw 24-bit SGR — gated on colorsEnabled() so NO_COLOR and
82
82
  // piped output never see an escape.
83
83
  const CORNFLOWER_FG = '\x1b[38;2;91;127;212m'
@@ -1,5 +1,5 @@
1
1
  import { randomBytes } from 'node:crypto'
2
- import { accessSync, constants as fsConstants, existsSync } from 'node:fs'
2
+ import { accessSync, constants as fsConstants, existsSync, realpathSync } from 'node:fs'
3
3
  import { cp, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
4
4
  import { tmpdir } from 'node:os'
5
5
  import { isAbsolute, join, relative, resolve } from 'node:path'
@@ -31,6 +31,11 @@ import { refreshPackageJson } from '@/init/packagejson'
31
31
  import { reconcilePluginDeps } from '@/init/reconcile-plugin-deps'
32
32
  import { runBunUpdate, type UpdateRunner } from '@/init/run-bun-install'
33
33
  import { linkWindowsDevTypeclaw, resolveBunLinkedPackage, type RunBunLink } from '@/init/windows-dev-link'
34
+ import {
35
+ provisionGithubCliStore,
36
+ type GithubCliProvisionResult,
37
+ type ProvisionGithubCliStoreOptions,
38
+ } from '@/secrets/provision-github-cli-store'
34
39
  import { isWindows } from '@/shared'
35
40
  import { hostLocaleIsCjk } from '@/shared/host-locale'
36
41
 
@@ -180,6 +185,9 @@ export type StartOptions = {
180
185
  hostIdentity?: { uid: number; gid: number } | null
181
186
  // Test seam for the host-stage writable-config preflight.
182
187
  assertConfigWritable?: (cwd: string) => void
188
+ provisionGithubCliStore?: (
189
+ options: ProvisionGithubCliStoreOptions,
190
+ ) => GithubCliProvisionResult | Promise<GithubCliProvisionResult>
183
191
  archiveLogs?: DockerLogArchiver
184
192
  operationLock?: WithAgentOperationLock
185
193
  operationLease?: AgentOperationLease
@@ -249,6 +257,7 @@ async function runStart({
249
257
  platform = process.platform,
250
258
  hostIdentity = currentHostIdentity(),
251
259
  assertConfigWritable = assertAgentConfigWritable,
260
+ provisionGithubCliStore: provisionGithubCliStoreForAgent = provisionGithubCliStore,
252
261
  archiveLogs = archiveContainerLogs,
253
262
  }: StartOptions): Promise<StartResult> {
254
263
  try {
@@ -316,6 +325,10 @@ async function runStart({
316
325
  reason: `Container ${containerName} became running during start preflight; refusing to migrate agent-messenger credentials or launch a replacement.`,
317
326
  }
318
327
  }
328
+
329
+ const githubCliDeniedRoots = resolveGithubCliDeniedRoots(cwd, await loadTypeclawConfig(cwd))
330
+ await refreshGithubCliStore(cwd, githubCliDeniedRoots, provisionGithubCliStoreForAgent)
331
+
319
332
  if (agentMessengerPolicy.migrate) {
320
333
  const agentMessengerMigration = await migrateAgentMessengerConfigDir(cwd)
321
334
  if (!agentMessengerMigration.ok) return { ok: false, reason: agentMessengerMigration.reason }
@@ -657,6 +670,33 @@ async function runStart({
657
670
  }
658
671
  }
659
672
 
673
+ async function refreshGithubCliStore(
674
+ agentDir: string,
675
+ deniedRoots: readonly string[],
676
+ provision: (options: ProvisionGithubCliStoreOptions) => GithubCliProvisionResult | Promise<GithubCliProvisionResult>,
677
+ ): Promise<void> {
678
+ let refreshed = false
679
+ try {
680
+ refreshed = (await provision({ agentDir, deniedRoots })).ok
681
+ } catch {
682
+ refreshed = false
683
+ }
684
+ if (refreshed) return
685
+
686
+ process.stderr.write(
687
+ 'typeclaw: warning: Could not refresh GitHub CLI credentials from the host. ' +
688
+ 'Keeping the previously persisted credential store. Run `gh auth login --hostname github.com` on the host, ' +
689
+ 'then restart TypeClaw.\n',
690
+ )
691
+ }
692
+
693
+ function resolveGithubCliDeniedRoots(cwd: string, config: Config): string[] {
694
+ return [
695
+ realpathSync(cwd),
696
+ ...config.mounts.filter((mount) => !mount.readOnly).map((mount) => expandMountPath(mount.path, cwd)),
697
+ ]
698
+ }
699
+
660
700
  function commitMessageForAutoUpgrade(outcome: AutoUpgradeOutcome): string | null {
661
701
  if (outcome.kind === 'spec-rewritten') return `Upgrade typeclaw to ${outcome.to}`
662
702
  if (outcome.kind === 'reinstall-needed') return `Upgrade typeclaw to ${outcome.to}`
@@ -8,6 +8,7 @@ import {
8
8
  containerNameFromCwd,
9
9
  defaultDockerExec,
10
10
  type DockerExec,
11
+ isGenuineMissingContainer,
11
12
  parseContainerInspectOutput,
12
13
  sanitizeDockerStderr,
13
14
  waitForRemoval,
@@ -58,7 +59,7 @@ async function runStop({
58
59
  // `docker inspect` exits non-zero both when the container does not
59
60
  // exist AND when it exists but is in a transient state docker cannot
60
61
  // inspect (Removal In Progress, Dead, daemon hiccup). Discriminate by
61
- if (inspect.stderr.toLowerCase().includes('no such container')) {
62
+ if (isGenuineMissingContainer(inspect.stderr)) {
62
63
  return { ok: true, containerName, running: false }
63
64
  }
64
65
  return {
@@ -63,6 +63,7 @@ export type CreateCronConsumerOptions = {
63
63
  // count. Optional so test fakes that don't exercise counts stay one-liners.
64
64
  countStore?: ConsumerCountStore
65
65
  now?: () => number
66
+ intervalNow?: () => number
66
67
  logger?: CronConsumerLogger
67
68
  }
68
69
 
@@ -92,9 +93,10 @@ export function createCronConsumer({
92
93
  invokeHandler,
93
94
  countStore,
94
95
  now = Date.now,
96
+ intervalNow = () => performance.now(),
95
97
  logger = consoleLogger,
96
98
  }: CreateCronConsumerOptions): CronConsumer {
97
- const inFlight = new Set<string>()
99
+ const inFlight = new Map<string, { fireId: string; activeSince: number }>()
98
100
  let unsubscribe: Unsubscribe | null = null
99
101
 
100
102
  return {
@@ -106,13 +108,19 @@ export function createCronConsumer({
106
108
  logger.warn(`[cron-consumer] received message ${msg.id} with invalid payload, ignoring`)
107
109
  return
108
110
  }
109
- if (inFlight.has(job.id)) {
110
- logger.warn(`[cron] ${job.id}: previous run still in progress, skipping`)
111
+ const blockingFire = inFlight.get(job.id)
112
+ if (blockingFire !== undefined) {
113
+ logger.warn(
114
+ `[cron] ${job.id}: previous run still in progress, skipping blocking_fire_id=${blockingFire.fireId} active_for_ms=${elapsedMs(blockingFire.activeSince, intervalNow())}`,
115
+ )
111
116
  return
112
117
  }
113
118
  // Reserve before the count gate so two close occurrences can't both
114
119
  // pass the `firedCount < count` check before either increment lands.
115
- inFlight.add(job.id)
120
+ const fireId = msg.id
121
+ inFlight.set(job.id, { fireId, activeSince: intervalNow() })
122
+ let runStartedAt: number | undefined
123
+ let outcome: 'success' | 'failed' = 'success'
116
124
  try {
117
125
  if (job.count !== undefined && countStore !== undefined) {
118
126
  if (countStore.get(job.id, job) >= job.count) {
@@ -130,8 +138,10 @@ export function createCronConsumer({
130
138
  return
131
139
  }
132
140
  }
141
+ runStartedAt = intervalNow()
142
+ logger.info(`[cron] ${job.id}: run started fire_id=${fireId}`)
133
143
  if (job.kind === 'prompt') {
134
- await runPrompt(job, createSessionForCron, stream, logger)
144
+ if (!(await runPrompt(job, createSessionForCron, stream, logger))) outcome = 'failed'
135
145
  } else if (job.kind === 'exec') {
136
146
  await runExec(job, cwd)
137
147
  } else {
@@ -143,10 +153,16 @@ export function createCronConsumer({
143
153
  await invokeHandler(job)
144
154
  }
145
155
  } catch (err) {
156
+ outcome = 'failed'
146
157
  const message = err instanceof Error ? err.message : String(err)
147
158
  logger.error(`[cron] ${job.id} failed: ${message}`)
148
159
  } finally {
149
160
  inFlight.delete(job.id)
161
+ if (runStartedAt !== undefined) {
162
+ logger.info(
163
+ `[cron] ${job.id}: run ended fire_id=${fireId} outcome=${outcome} elapsed_ms=${elapsedMs(runStartedAt, intervalNow())}`,
164
+ )
165
+ }
150
166
  }
151
167
  })
152
168
  },
@@ -160,12 +176,16 @@ export function createCronConsumer({
160
176
  }
161
177
  }
162
178
 
179
+ function elapsedMs(startedAt: number, endedAt: number): number {
180
+ return Math.max(0, Math.round(endedAt - startedAt))
181
+ }
182
+
163
183
  async function runPrompt(
164
184
  job: PromptJob,
165
185
  createSessionForCron: (job: PromptJob, refOverride?: ModelRef) => Promise<CronSession>,
166
186
  stream: Stream,
167
187
  logger: CronConsumerLogger,
168
- ): Promise<void> {
188
+ ): Promise<boolean> {
169
189
  if (job.subagent !== undefined) {
170
190
  // Propagate the cron job's role and origin into the spawned subagent.
171
191
  // Without this, every cron-triggered subagent (e.g. memory dreaming)
@@ -187,14 +207,14 @@ async function runPrompt(
187
207
  },
188
208
  payload: job.payload,
189
209
  })
190
- return
210
+ return true
191
211
  }
192
212
  // Resolve the model fallback chain for the cron profile (cron jobs run
193
213
  // under the `default` profile today). Single-ref configs produce a length-1
194
214
  // chain; multi-ref configs (e.g. `"default": ["openai/...", "fireworks/..."]`)
195
215
  // drive the retry-on-failure loop inside `runPromptOnce`.
196
216
  const refs = resolveFallbackChain(getConfig().models, undefined)
197
- await runPromptOnce(job, refs, createSessionForCron, logger)
217
+ return runPromptOnce(job, refs, createSessionForCron, logger)
198
218
  }
199
219
 
200
220
  async function runPromptOnce(
@@ -202,7 +222,7 @@ async function runPromptOnce(
202
222
  refs: ModelRef[],
203
223
  createSessionForCron: (job: PromptJob, refOverride?: ModelRef) => Promise<CronSession>,
204
224
  logger: CronConsumerLogger,
205
- ): Promise<void> {
225
+ ): Promise<boolean> {
206
226
  // Per-attempt lifecycle: every session we create gets full
207
227
  // turn-start → turn-end → session-end → dispose bracketing, regardless of
208
228
  // whether the helper chose it as the final session or disposed it as a
@@ -320,6 +340,7 @@ async function runPromptOnce(
320
340
  }
321
341
  await result.dispose()
322
342
  }
343
+ return result.success
323
344
  }
324
345
 
325
346
  function describe(err: unknown): string {
@@ -58,6 +58,10 @@ const consoleLogger: SchedulerLogger = {
58
58
  error: (m) => console.error(m),
59
59
  }
60
60
 
61
+ // Node clamps delays greater than this to 1ms. Re-arm long waits instead of
62
+ // allowing an early callback to dispatch a future occurrence.
63
+ const maxTimeoutMs = 2 ** 31 - 1
64
+
61
65
  export function createScheduler({
62
66
  jobs,
63
67
  onFire,
@@ -95,17 +99,28 @@ export function createScheduler({
95
99
  return
96
100
  }
97
101
 
102
+ arm(id, result.nextFire)
103
+ }
104
+
105
+ function arm(id: string, nextFire: number): void {
98
106
  cancel(id)
99
107
 
100
- const delay = Math.max(0, result.nextFire - clock.now())
101
- const handle = clock.setTimeout(() => {
102
- handles.delete(id)
103
- if (!started) return
104
- const live = currentEnabled(id)
105
- if (!live) return
106
- fire(live)
107
- scheduleNext(id)
108
- }, delay)
108
+ const delay = Math.max(0, nextFire - clock.now())
109
+ const handle = clock.setTimeout(
110
+ () => {
111
+ handles.delete(id)
112
+ if (!started) return
113
+ const live = currentEnabled(id)
114
+ if (!live) return
115
+ if (clock.now() < nextFire) {
116
+ arm(id, nextFire)
117
+ return
118
+ }
119
+ fire(live)
120
+ scheduleNext(id)
121
+ },
122
+ Math.min(delay, maxTimeoutMs),
123
+ )
109
124
  handles.set(id, handle)
110
125
  }
111
126
 
@@ -1,6 +1,8 @@
1
+ import { readFileSync } from 'node:fs'
1
2
  import { join } from 'node:path'
2
3
 
3
4
  import { type AdapterId, type ChannelsConfig } from '@/channels'
5
+ import { isGithubEventAllowed } from '@/channels/adapters/github/event-allowlist'
4
6
  import { loadConfigSync, validateConfig } from '@/config'
5
7
  import { readEnvFile } from '@/init'
6
8
  import { SecretsBackend } from '@/secrets'
@@ -38,6 +40,7 @@ export function buildChannelChecks(): DoctorCheck[] {
38
40
  kakaotalkCredentials(),
39
41
  githubCredentials(),
40
42
  githubWebhookDelivery(),
43
+ githubEventAllowlist(),
41
44
  ]
42
45
  }
43
46
 
@@ -361,6 +364,47 @@ function githubWebhookDelivery(): DoctorCheck {
361
364
  }
362
365
  }
363
366
 
367
+ function githubEventAllowlist(): DoctorCheck {
368
+ return {
369
+ name: 'channel.github.event-allowlist',
370
+ category: 'channels',
371
+ description: 'github eventAllowlist preserves push-triggered review followups',
372
+ applies: (ctx) => ctx.hasAgentFolder,
373
+ async run(ctx) {
374
+ const cfg = safeLoadConfig(ctx)
375
+ if (cfg === null) return configInvalidResult()
376
+ const github = cfg.channels.github
377
+ if (github === undefined || github.enabled === false) {
378
+ return { status: 'skipped', message: 'github not configured' }
379
+ }
380
+
381
+ const pinned = readPinnedGithubEventAllowlist(ctx)
382
+ if (pinned === null) {
383
+ return { status: 'ok', message: 'github eventAllowlist tracks the shipped defaults' }
384
+ }
385
+ // Match the runtime predicate, not the literal string: the adapter admits
386
+ // an event when the allowlist holds either the fully qualified key or the
387
+ // bare base event, so a pinned `["pull_request"]` still enables push
388
+ // rechecks and must not be reported as an omission.
389
+ if (isGithubEventAllowed(pinned, 'pull_request', 'synchronize')) {
390
+ return { status: 'ok', message: 'github pinned eventAllowlist admits pull_request.synchronize' }
391
+ }
392
+ return {
393
+ status: 'warning',
394
+ message: 'github pinned eventAllowlist omits pull_request.synchronize',
395
+ details: [
396
+ 'An explicitly pinned array will not inherit future default events.',
397
+ 'With this omission, open review threads will never be rechecked on push.',
398
+ ],
399
+ fix: {
400
+ description:
401
+ 'Remove channels.github.eventAllowlist to track defaults, or add `pull_request.synchronize` explicitly.',
402
+ },
403
+ }
404
+ },
405
+ }
406
+ }
407
+
364
408
  async function runTokenAdapterCheck(
365
409
  ctx: CheckContext,
366
410
  adapter: Extract<AdapterId, 'slack-bot' | 'discord-bot' | 'telegram-bot' | 'webex-bot'>,
@@ -483,6 +527,26 @@ function readDeclaredChannels(ctx: CheckContext): ChannelsConfig | null {
483
527
  return cfg?.channels ?? null
484
528
  }
485
529
 
530
+ function readPinnedGithubEventAllowlist(ctx: CheckContext): string[] | null {
531
+ // The parsed config always contains the schema default, so it cannot tell an
532
+ // operator-pinned array from an omitted key that tracks shipped defaults.
533
+ // Re-read the raw host-stage file to preserve that distinction for this check.
534
+ try {
535
+ const parsed = JSON.parse(readFileSync(join(ctx.cwd, 'typeclaw.json'), 'utf8')) as unknown
536
+ if (!isObjectRecord(parsed)) return null
537
+ const channels = parsed.channels
538
+ if (!isObjectRecord(channels)) return null
539
+ const github = channels.github
540
+ if (!isObjectRecord(github) || !Object.hasOwn(github, 'eventAllowlist')) return null
541
+ const allowlist = github.eventAllowlist
542
+ if (!Array.isArray(allowlist) || !allowlist.every((event): event is string => typeof event === 'string'))
543
+ return null
544
+ return allowlist
545
+ } catch {
546
+ return null
547
+ }
548
+ }
549
+
486
550
  function safeLoadConfig(ctx: CheckContext): ReturnType<typeof loadConfigSync> | null {
487
551
  const result = validateConfig(ctx.cwd)
488
552
  if (!result.ok) return null
@@ -1,4 +1,4 @@
1
- import { styleText } from 'node:util'
1
+ import { styled } from '@/shared'
2
2
 
3
3
  import type { DoctorReport, ReportEntry, Severity } from './types'
4
4
 
@@ -27,13 +27,13 @@ const NO_PALETTE: Palette = {
27
27
  }
28
28
 
29
29
  const COLOR_PALETTE: Palette = {
30
- bold: (s) => styleText('bold', s),
31
- dim: (s) => styleText('dim', s),
32
- green: (s) => styleText('green', s),
33
- yellow: (s) => styleText('yellow', s),
34
- red: (s) => styleText('red', s),
35
- cyan: (s) => styleText('cyan', s),
36
- gray: (s) => styleText('gray', s),
30
+ bold: (s) => styled('bold', s),
31
+ dim: (s) => styled('dim', s),
32
+ green: (s) => styled('green', s),
33
+ yellow: (s) => styled('yellow', s),
34
+ red: (s) => styled('red', s),
35
+ cyan: (s) => styled('cyan', s),
36
+ gray: (s) => styled('gray', s),
37
37
  }
38
38
 
39
39
  export function formatReport(report: DoctorReport, opts: FormatOptions = {}): string {
@@ -1,4 +1,4 @@
1
- import { styleText } from 'node:util'
1
+ import { styled } from '@/shared'
2
2
 
3
3
  import type { DreamCategory, DreamEntry, DreamEntryDetail } from './types'
4
4
 
@@ -8,7 +8,7 @@ type ColorName = 'dim' | 'cyan' | 'green' | 'yellow' | 'magenta' | 'gray'
8
8
 
9
9
  function tint(opts: RenderOptions, color: ColorName, text: string): string {
10
10
  if (!opts.color) return text
11
- return styleText(color, text)
11
+ return styled(color, text)
12
12
  }
13
13
 
14
14
  const CATEGORY_LABELS: Record<DreamCategory, string> = {
@@ -1596,7 +1596,14 @@ const BUN_CACHE_MOUNT = '--mount=type=cache,target=/root/.bun/install/cache,shar
1596
1596
  const aptCacheMount = (buildKit: boolean): string => (buildKit ? APT_CACHE_MOUNT : '')
1597
1597
  const bunCacheMount = (buildKit: boolean): string => (buildKit ? BUN_CACHE_MOUNT : '')
1598
1598
 
1599
- const FROM_AND_WORKDIR = `FROM oven/bun:1-slim
1599
+ // Pinned rather than the floating `oven/bun:1-slim`, which silently started
1600
+ // resolving to Bun 1.4.0 the day it shipped — that would put an unvalidated
1601
+ // runtime in every container while CI still tested 1.3.14. Bump this in the
1602
+ // same change as the `bun-version:` pins in .github/workflows/*.yml so the
1603
+ // host-stage checks and the container-stage runtime never disagree.
1604
+ export const BUN_BASE_IMAGE = 'oven/bun:1.4.0-slim'
1605
+
1606
+ const FROM_AND_WORKDIR = `FROM ${BUN_BASE_IMAGE}
1600
1607
 
1601
1608
  WORKDIR /agent
1602
1609
 
@@ -1,4 +1,4 @@
1
- import { styleText } from 'node:util'
1
+ import { styled } from '@/shared'
2
2
 
3
3
  import { originLabel, readableId } from './label'
4
4
  import type { InspectEvent } from './types'
@@ -226,5 +226,5 @@ type ColorName = 'dim' | 'magenta' | 'cyan' | 'green' | 'yellow' | 'red' | 'gray
226
226
 
227
227
  function tint(opts: RenderOptions, color: ColorName, text: string): string {
228
228
  if (!opts.color) return text
229
- return styleText(color, text)
229
+ return styled(color, text)
230
230
  }