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
@@ -1,3 +1,4 @@
1
+ import { describeError } from '../describe-error'
1
2
  import type { KakaoTalkClient } from './kakaotalk'
2
3
 
3
4
  const DEFAULT_TTL_MS = 5 * 60 * 1000
@@ -50,7 +51,7 @@ export function createKakaoAuthorResolver(options: KakaoAuthorResolverOptions):
50
51
  .catch((err: unknown): null => {
51
52
  // Author resolution is best-effort. Failing here makes the message
52
53
  // render with the raw user_id, which is uglier but still routes.
53
- logger?.warn(`[kakaotalk] getMembers(${chatId}) failed: ${describe(err)}`)
54
+ logger?.warn(`[kakaotalk] getMembers(${chatId}) failed: ${describeError(err)}`)
54
55
  return null
55
56
  })
56
57
  .finally(() => {
@@ -72,7 +73,3 @@ export function createKakaoAuthorResolver(options: KakaoAuthorResolverOptions):
72
73
 
73
74
  return { resolve }
74
75
  }
75
-
76
- function describe(err: unknown): string {
77
- return err instanceof Error ? err.message : String(err)
78
- }
@@ -2,6 +2,8 @@ import { classifyKakaoChat, type KakaoChat, type KakaoChatKind, type KakaoTalkCl
2
2
 
3
3
  import type { ChannelKey, ChannelNameResolver, ResolvedChannelNames } from '@/channels/types'
4
4
 
5
+ import { describeError } from '../describe-error'
6
+
5
7
  const DEFAULT_TTL_MS = 5 * 60 * 1000
6
8
 
7
9
  export type KakaoWorkspace = '@kakao-dm' | '@kakao-group' | '@kakao-open'
@@ -78,7 +80,7 @@ export function createKakaoChannelResolver(options: KakaoChannelResolverOptions)
78
80
  const expiresAt = now() + ttlMs
79
81
  for (const chat of chats) ingest(chat, expiresAt)
80
82
  } catch (err) {
81
- options.logger?.warn(`[kakaotalk] channel resolver refresh failed: ${describe(err)}`)
83
+ options.logger?.warn(`[kakaotalk] channel resolver refresh failed: ${describeError(err)}`)
82
84
  }
83
85
  }
84
86
 
@@ -129,7 +131,3 @@ export function createKakaoChannelResolver(options: KakaoChannelResolverOptions)
129
131
 
130
132
  return { resolve, lookupChat, refresh, ingestProvisional }
131
133
  }
132
-
133
- function describe(err: unknown): string {
134
- return err instanceof Error ? err.message : String(err)
135
- }
@@ -5,6 +5,7 @@ import {
5
5
  } from '@/channels/fetch-attachment'
6
6
  import type { FetchAttachmentCallback } from '@/channels/types'
7
7
 
8
+ import { describeError } from '../describe-error'
8
9
  import type { KakaotalkAdapterLogger } from './kakaotalk'
9
10
 
10
11
  // KakaoCDN hosts that the LOCO push payload mints pre-signed URLs against.
@@ -68,7 +69,7 @@ export function createFetchAttachmentCallback(deps: {
68
69
  size: buffer.length,
69
70
  }
70
71
  } catch (err) {
71
- const message = err instanceof Error ? err.message : String(err)
72
+ const message = describeError(err)
72
73
  logger.error(`[kakaotalk] fetchAttachment failed for ${url.toString()}: ${message}`)
73
74
  return { ok: false, error: message }
74
75
  }
@@ -1,3 +1,4 @@
1
+ import { describeError } from '../describe-error'
1
2
  import type {
2
3
  MembershipCount,
3
4
  MembershipResolver,
@@ -56,12 +57,8 @@ export function createKakaoMembershipResolver(options: KakaoMembershipResolverOp
56
57
  humanMemberIds,
57
58
  } satisfies MembershipCount
58
59
  } catch (err) {
59
- options.logger.warn(`[kakaotalk] membership chat=${key.chat} failed: ${describe(err)}`)
60
+ options.logger.warn(`[kakaotalk] membership chat=${key.chat} failed: ${describeError(err)}`)
60
61
  return { kind: 'transient' } satisfies MembershipResolverFailure
61
62
  }
62
63
  }
63
64
  }
64
-
65
- function describe(err: unknown): string {
66
- return err instanceof Error ? err.message : String(err)
67
- }
@@ -2,7 +2,7 @@ import type { KakaoTypingResult } from 'agent-messenger/kakaotalk'
2
2
 
3
3
  import type { TypingCallback } from '@/channels/types'
4
4
 
5
- import { describeError } from './describe-error'
5
+ import { describeError } from '../describe-error'
6
6
 
7
7
  export type KakaoTypingLogger = {
8
8
  info: (msg: string) => void
@@ -33,7 +33,7 @@ import type {
33
33
  InboundAttachment,
34
34
  } from '@/channels/types'
35
35
 
36
- import { describeError } from './describe-error'
36
+ import { describeError } from '../describe-error'
37
37
  import {
38
38
  emoticonEventToMessageEvent,
39
39
  splitEmoticonInbound,
@@ -2,6 +2,8 @@ import type { LineChat, LineClient } from 'agent-messenger/line'
2
2
 
3
3
  import type { ChannelKey, ChannelNameResolver, ResolvedChannelNames } from '@/channels/types'
4
4
 
5
+ import { describeError } from '../describe-error'
6
+
5
7
  const DEFAULT_TTL_MS = 5 * 60 * 1000
6
8
 
7
9
  // LINE's chat list is fetched in a bounded page; there is no `{ all: true }`
@@ -77,7 +79,7 @@ export function createLineChannelResolver(options: LineChannelResolverOptions):
77
79
  const expiresAt = now() + ttlMs
78
80
  for (const chat of chats) ingest(chat, expiresAt)
79
81
  } catch (err) {
80
- options.logger?.warn(`[line] channel resolver refresh failed: ${describe(err)}`)
82
+ options.logger?.warn(`[line] channel resolver refresh failed: ${describeError(err)}`)
81
83
  }
82
84
  }
83
85
 
@@ -123,7 +125,3 @@ export function createLineChannelResolver(options: LineChannelResolverOptions):
123
125
 
124
126
  return { resolve, lookupChat, refresh, ingestProvisional }
125
127
  }
126
-
127
- function describe(err: unknown): string {
128
- return err instanceof Error ? err.message : String(err)
129
- }
@@ -25,7 +25,7 @@ import type {
25
25
  SendResult,
26
26
  } from '@/channels/types'
27
27
 
28
- import { describeError } from './describe-error'
28
+ import { describeError } from '../describe-error'
29
29
  import { splitInboundLine } from './line-attachment'
30
30
  import { createLineChannelResolver } from './line-channel-resolver'
31
31
  import { classifyInbound } from './line-classify'
@@ -1,6 +1,6 @@
1
1
  import type { EditMessageCallback, EditMessageResult } from '@/channels/types'
2
2
 
3
- import { describeError } from './describe-error'
3
+ import { describeError } from '../describe-error'
4
4
 
5
5
  const SLACK_API_BASE = 'https://slack.com/api'
6
6
 
@@ -8,6 +8,8 @@ import type {
8
8
  RemoveReactionCallback,
9
9
  } from '@/channels/types'
10
10
 
11
+ import { describeError } from '../describe-error'
12
+
11
13
  // The reactable target on Slack: a message is addressed by its channel id plus
12
14
  // the message `ts`. The classifier stamps this because `ts` is the inbound's
13
15
  // own message timestamp — the same value that becomes `externalMessageId`
@@ -78,7 +80,7 @@ export function createSlackReactionCallback(deps: { client: Pick<SlackBotClient,
78
80
  if (code === 'already_reacted') {
79
81
  return { ok: true, reactionRef: encodeSlackRemovalRef({ ...target, emoji }) }
80
82
  }
81
- return { ok: false, error: withScopeHint(code, describe(err)), code: classifySlackError(code) }
83
+ return { ok: false, error: withScopeHint(code, describeError(err)), code: classifySlackError(code) }
82
84
  }
83
85
  return { ok: true, reactionRef: encodeSlackRemovalRef({ ...target, emoji }) }
84
86
  }
@@ -101,7 +103,7 @@ export function createSlackRemoveReactionCallback(deps: {
101
103
  // `already_reacted` handling on the add path.
102
104
  const code = slackErrorCode(err)
103
105
  if (code === 'no_reaction') return { ok: true }
104
- return { ok: false, error: describe(err), code: classifySlackError(code) }
106
+ return { ok: false, error: describeError(err), code: classifySlackError(code) }
105
107
  }
106
108
  return { ok: true }
107
109
  }
@@ -161,7 +163,3 @@ function parseRecord(value: string): Record<string, unknown> | null {
161
163
  ? (parsed as Record<string, unknown>)
162
164
  : null
163
165
  }
164
-
165
- function describe(err: unknown): string {
166
- return err instanceof Error ? err.message : String(err)
167
- }
@@ -40,7 +40,7 @@ import type {
40
40
  } from '@/channels/types'
41
41
  import { chunkMarkdown } from '@/markdown'
42
42
 
43
- import { describeError } from './describe-error'
43
+ import { describeError } from '../describe-error'
44
44
  import { addSlackMentionHints } from './mention-hints'
45
45
  import { downloadSlackAttachment, type SlackAttachmentFetch } from './slack-attachment-download'
46
46
  import { createSlackAuthorResolver, type SlackAuthorResolver } from './slack-bot-author-resolver'
@@ -720,7 +720,7 @@ export function createSlackHistoryCallback(deps: {
720
720
  })
721
721
  raw = (await response.json()) as SlackHistoryResponse
722
722
  } catch (err) {
723
- const message = err instanceof Error ? err.message : String(err)
723
+ const message = describeError(err)
724
724
  logger.warn(`[slack-bot] history fetch failed: ${message}`)
725
725
  return { ok: false, error: message }
726
726
  }
@@ -800,7 +800,7 @@ export function createSlackMessageGetCallback(deps: {
800
800
  })
801
801
  raw = (await response.json()) as SlackHistoryResponse
802
802
  } catch (err) {
803
- const message = err instanceof Error ? err.message : String(err)
803
+ const message = describeError(err)
804
804
  logger.warn(`[slack-bot] message get failed: ${message}`)
805
805
  return { ok: false, error: message }
806
806
  }
@@ -847,7 +847,7 @@ export function createSlackListCallback(deps: {
847
847
  })
848
848
  raw = (await response.json()) as SlackConversationsListResponse
849
849
  } catch (err) {
850
- const message = err instanceof Error ? err.message : String(err)
850
+ const message = describeError(err)
851
851
  logger.warn(`[slack-bot] channel list failed: ${message}`)
852
852
  return { ok: false, error: message }
853
853
  }
@@ -1008,7 +1008,7 @@ export function createOutboundCallback(deps: {
1008
1008
  if (typingTracker) await typingTracker.clearAfterSend(msg.chat, msg.typingThread ?? msg.thread)
1009
1009
  return { ok: true, messageId: sentTs[0], messageIds: sentTs }
1010
1010
  } catch (err) {
1011
- const message = err instanceof Error ? err.message : String(err)
1011
+ const message = describeError(err)
1012
1012
  logger.error(`[slack-bot] postMessage failed: ${message}`)
1013
1013
  return { ok: false, error: message }
1014
1014
  }
@@ -1021,7 +1021,7 @@ export function createOutboundCallback(deps: {
1021
1021
  try {
1022
1022
  buffer = await readFile(attachment.path)
1023
1023
  } catch (err) {
1024
- const message = err instanceof Error ? err.message : String(err)
1024
+ const message = describeError(err)
1025
1025
  logger.error(`[slack-bot] readFile failed for ${attachment.path}: ${message}`)
1026
1026
  return { ok: false, error: `readFile failed: ${message}` }
1027
1027
  }
@@ -1037,7 +1037,7 @@ export function createOutboundCallback(deps: {
1037
1037
  const file = await client.uploadFile(msg.chat, buffer, filename, uploadOptions)
1038
1038
  logger.info(`[slack-bot] uploaded id=${file.id} filename=${file.name} size=${file.size} ${tag}`)
1039
1039
  } catch (err) {
1040
- const message = err instanceof Error ? err.message : String(err)
1040
+ const message = describeError(err)
1041
1041
  logger.error(`[slack-bot] uploadFile failed for ${attachment.path}: ${message}`)
1042
1042
  return { ok: false, error: `uploadFile failed: ${message}` }
1043
1043
  }
@@ -1085,7 +1085,7 @@ export function createFetchAttachmentCallback(deps: {
1085
1085
  size: buffer.length,
1086
1086
  }
1087
1087
  } catch (err) {
1088
- const message = err instanceof Error ? err.message : String(err)
1088
+ const message = describeError(err)
1089
1089
  logger.error(`[slack-bot] downloadFile failed for ${fileId}: ${message}`)
1090
1090
  return { ok: false, error: message }
1091
1091
  }
@@ -2,6 +2,8 @@ import type { SlackClient } from 'agent-messenger/slack'
2
2
 
3
3
  import type { EditMessageCallback, EditMessageResult } from '@/channels/types'
4
4
 
5
+ import { describeError } from '../describe-error'
6
+
5
7
  export function createSlackUserEditMessageCallback(deps: {
6
8
  client: Pick<SlackClient, 'updateMessage'>
7
9
  }): EditMessageCallback {
@@ -13,7 +15,7 @@ export function createSlackUserEditMessageCallback(deps: {
13
15
  await deps.client.updateMessage(req.chat, req.messageId, req.text)
14
16
  } catch (err) {
15
17
  const code = slackErrorCode(err)
16
- return { ok: false, error: describe(err), code: classifyEditError(code) }
18
+ return { ok: false, error: describeError(err), code: classifyEditError(code) }
17
19
  }
18
20
  return { ok: true }
19
21
  }
@@ -41,7 +43,3 @@ function classifyEditError(code: string | null): NonNullable<(EditMessageResult
41
43
  return 'not-found'
42
44
  }
43
45
  }
44
-
45
- function describe(err: unknown): string {
46
- return err instanceof Error ? err.message : String(err)
47
- }
@@ -8,6 +8,8 @@ import type {
8
8
  RemoveReactionCallback,
9
9
  } from '@/channels/types'
10
10
 
11
+ import { describeError } from '../describe-error'
12
+
11
13
  export type SlackReactionTarget = { channel: string; ts: string }
12
14
  export type SlackReactionRemovalTarget = { channel: string; ts: string; emoji: string }
13
15
 
@@ -51,7 +53,7 @@ export function createSlackReactionCallback(deps: { client: Pick<SlackClient, 'a
51
53
  } catch (err) {
52
54
  const code = slackErrorCode(err)
53
55
  if (code === 'already_reacted') return { ok: true, reactionRef: encodeSlackRemovalRef({ ...target, emoji }) }
54
- return { ok: false, error: describe(err), code: classifySlackError(code) }
56
+ return { ok: false, error: describeError(err), code: classifySlackError(code) }
55
57
  }
56
58
  return { ok: true, reactionRef: encodeSlackRemovalRef({ ...target, emoji }) }
57
59
  }
@@ -69,7 +71,7 @@ export function createSlackRemoveReactionCallback(deps: {
69
71
  } catch (err) {
70
72
  const code = slackErrorCode(err)
71
73
  if (code === 'no_reaction') return { ok: true }
72
- return { ok: false, error: describe(err), code: classifySlackError(code) }
74
+ return { ok: false, error: describeError(err), code: classifySlackError(code) }
73
75
  }
74
76
  return { ok: true }
75
77
  }
@@ -120,7 +122,3 @@ function parseRecord(value: string): Record<string, unknown> | null {
120
122
  ? (parsed as Record<string, unknown>)
121
123
  : null
122
124
  }
123
-
124
- function describe(err: unknown): string {
125
- return err instanceof Error ? err.message : String(err)
126
- }
@@ -33,7 +33,7 @@ import type {
33
33
  import { chunkMarkdown } from '@/markdown'
34
34
  import type { SlackAccountRecord } from '@/secrets/schema'
35
35
 
36
- import { describeError } from './describe-error'
36
+ import { describeError } from '../describe-error'
37
37
  import { downloadSlackAttachment, type SlackAttachmentFetch } from './slack-attachment-download'
38
38
  import { createSlackAuthorResolver } from './slack-author-resolver'
39
39
  import { slackTsToMillis } from './slack-bot-time'
@@ -2,6 +2,7 @@ import type { TeamsClient } from 'agent-messenger/teams'
2
2
 
3
3
  import type { EditMessageCallback, EditMessageResult } from '@/channels/types'
4
4
 
5
+ import { describeError } from '../describe-error'
5
6
  import { decodeTeamsConversationKey } from './teams-key'
6
7
 
7
8
  // The Teams user-account SDK only exposes an edit primitive for 1:1/group
@@ -25,7 +26,7 @@ export function createTeamsEditMessageCallback(deps: {
25
26
  try {
26
27
  await deps.client.editChatMessage(decoded.chatId, req.messageId, req.text)
27
28
  } catch (err) {
28
- return { ok: false, error: describe(err), code: classifyEditError(err) }
29
+ return { ok: false, error: describeError(err), code: classifyEditError(err) }
29
30
  }
30
31
  return { ok: true }
31
32
  }
@@ -55,7 +56,3 @@ function errorCode(err: unknown): string | null {
55
56
  }
56
57
  return null
57
58
  }
58
-
59
- function describe(err: unknown): string {
60
- return err instanceof Error ? err.message : String(err)
61
- }
@@ -15,7 +15,7 @@ import type {
15
15
  } from '@/channels/types'
16
16
  import type { TeamsAccountRecord } from '@/secrets/schema'
17
17
 
18
- import { describeError } from './describe-error'
18
+ import { describeError } from '../describe-error'
19
19
  import {
20
20
  classifyChannelInbound,
21
21
  classifyChatInbound,
@@ -2,6 +2,7 @@ import type { TelegramBotClient } from 'agent-messenger/telegrambot'
2
2
 
3
3
  import type { EditMessageCallback, EditMessageResult } from '@/channels/types'
4
4
 
5
+ import { describeError } from '../describe-error'
5
6
  import { toTelegramMarkdownV2 } from './telegram-bot-format'
6
7
 
7
8
  export function createTelegramEditMessageCallback(deps: {
@@ -31,8 +32,8 @@ export function createTelegramEditMessageCallback(deps: {
31
32
  // "message is not modified" fires when the new text equals the current
32
33
  // body — the desired end state already holds, so treat it as success
33
34
  // (idempotent), mirroring the reaction adapters' already-in-state handling.
34
- if (describe(err).toLowerCase().includes('message is not modified')) return { ok: true }
35
- return { ok: false, error: describe(err), code: classifyEditError(err) }
35
+ if (describeError(err).toLowerCase().includes('message is not modified')) return { ok: true }
36
+ return { ok: false, error: describeError(err), code: classifyEditError(err) }
36
37
  }
37
38
  return { ok: true }
38
39
  }
@@ -41,11 +42,7 @@ export function createTelegramEditMessageCallback(deps: {
41
42
  // "message to edit not found" / "message can't be edited" (too old) map to
42
43
  // not-found; a chat-permission error to permission-denied.
43
44
  function classifyEditError(err: unknown): NonNullable<(EditMessageResult & { ok: false })['code']> {
44
- const message = describe(err).toLowerCase()
45
+ const message = describeError(err).toLowerCase()
45
46
  if (message.includes('not enough rights') || message.includes('forbidden')) return 'permission-denied'
46
47
  return 'not-found'
47
48
  }
48
-
49
- function describe(err: unknown): string {
50
- return err instanceof Error ? err.message : String(err)
51
- }
@@ -22,7 +22,7 @@ import type {
22
22
  TypingTarget,
23
23
  } from '@/channels/types'
24
24
 
25
- import { describeError } from './describe-error'
25
+ import { describeError } from '../describe-error'
26
26
  import { classifyInbound, type InboundDropReason, TELEGRAM_WORKSPACE } from './telegram-bot-classify'
27
27
  import { createTelegramEditMessageCallback } from './telegram-bot-edit'
28
28
  import { toTelegramMarkdownV2 } from './telegram-bot-format'
@@ -34,7 +34,7 @@ import type {
34
34
  SendResult,
35
35
  } from '@/channels/types'
36
36
 
37
- import { describeError } from './describe-error'
37
+ import { describeError } from '../describe-error'
38
38
  import { createWebexChannelNameResolver } from './webex-bot-channel-resolver'
39
39
  import { classifyInbound, type InboundDropReason, type WebexInboundMessage } from './webex-bot-classify'
40
40
  import { enrichWebexMessageReference } from './webex-bot-reference'
@@ -1,6 +1,8 @@
1
1
  import type { AdapterId } from '@/channels/schema'
2
2
  import type { EditMessageCallback, EditMessageResult } from '@/channels/types'
3
3
 
4
+ import { describeError } from '../describe-error'
5
+
4
6
  // Both WebexClient and WebexBotClient expose the same edit primitive
5
7
  // (webex-bot delegates to webex), so one factory serves both adapters —
6
8
  // parameterized on the adapter id it guards against. Webex addresses an edit
@@ -20,7 +22,7 @@ export function createWebexEditMessageCallback(deps: {
20
22
  try {
21
23
  await deps.client.editMessage(req.messageId, req.chat, req.text)
22
24
  } catch (err) {
23
- return { ok: false, error: describe(err), code: classifyEditError(err) }
25
+ return { ok: false, error: describeError(err), code: classifyEditError(err) }
24
26
  }
25
27
  return { ok: true }
26
28
  }
@@ -41,7 +43,3 @@ function httpStatus(err: unknown): number | null {
41
43
  }
42
44
  return null
43
45
  }
44
-
45
- function describe(err: unknown): string {
46
- return err instanceof Error ? err.message : String(err)
47
- }
@@ -39,7 +39,7 @@ import type {
39
39
  } from '@/channels/types'
40
40
  import type { WebexAccountRecord } from '@/secrets/schema'
41
41
 
42
- import { describeError } from './describe-error'
42
+ import { describeError } from '../describe-error'
43
43
  import { createWebexChannelNameResolver } from './webex-channel-resolver'
44
44
  import { classifyInbound, type InboundDropReason, type WebexInboundMessage } from './webex-classify'
45
45
  import { createWebexEditMessageCallback } from './webex-edit'
@@ -94,6 +94,7 @@ const BLOCK_RESOLVE: readonly RegExp[] = [
94
94
  /\bthis resolves it\b/,
95
95
  /\b(that|this) closes it\b/,
96
96
  /\bclosing this out\b/,
97
+ /\bresolving (?:this|the) thread\b/,
97
98
  /\bconfirmed fixed\b/,
98
99
  // verify clause + a fix/resolve verb, allowing a short gap ("verified at <sha>, that fixes it").
99
100
  /\b(verified|confirmed)\b[^.!?]*\b(fix(es|ed)|resolv)/,
@@ -134,9 +135,84 @@ const WARN_POSITIVE_CLOSEOUT: readonly RegExp[] = [
134
135
  /\btampaknya (?:baik|oke)\b/, // id seems good
135
136
  ]
136
137
 
138
+ // A hold-open statement reverses neighbouring resolve-shaped prose. Blocking the
139
+ // whole reply in that case strands neither review state nor thread; it silences
140
+ // the new blocker the reply is trying to preserve (PR #1320). Keep these precise
141
+ // enough to assert unfinished work, not merely mention a blocker that was fixed.
142
+ const HOLD_OPEN: readonly RegExp[] = [
143
+ /\bkeep(?:ing)? (?:this |the )?(?:review )?thread open\b/,
144
+ /\bkeep(?:ing)? (?:this|it) open\b/,
145
+ /\bleav(?:e|ing) (?:(?:this|it) open|(?:this |the )?(?:review )?thread open)\b/,
146
+ /\bstill (?:blocks?|blocking)\b/,
147
+ /\bremaining\b[^.!?]{0,80}\bblockers?\b(?![^.!?]*\b(?:(?:is|are|was|were) (?:now )?|(?:has|have) (?:now )?been )(?:fixed|resolved|addressed)\b)/,
148
+ /\bblockers? remain(?:s|ing)?\b(?![^.!?]*\b(?:(?:is|are|was|were) (?:now )?|(?:has|have) (?:now )?been )(?:fixed|resolved|addressed)\b)/,
149
+ /\bstill (?:has|have) (?:an? )?blocking (?:issue|problem|concern)\b/,
150
+ /\bnot resolv(?:e|ed|ing)\b/,
151
+ /\b(?:can(?:not|'?t|\s+t)|unable to) resolve\b[^.!?]*\byet\b/,
152
+ /\b(?:(?:one|an?|the) )?(?:issue|problem|concern)s? remain(?:s|ing)?\b(?![^.!?]*\b(?:(?:is|are|was|were) (?:now )?|(?:has|have) (?:now )?been )(?:fixed|resolved|addressed)\b)/,
153
+ /\b(?:work|changes?|fix(?:es)?) remain(?:s|ing)?\b(?![^.!?]*\b(?:(?:is|are|was|were) (?:now )?|(?:has|have) (?:now )?been )(?:fixed|resolved|addressed)\b)/,
154
+ // es
155
+ /\b(?:dejo|dejando|mantengo|manteniendo) (?:este |el )?hilo abierto\b/,
156
+ /\b(?:todav[íi]a|a[úu]n) (?:bloquea|hay (?:un )?(?:problema|bloqueo))\b/,
157
+ /\b(?:queda|permanece) (?:un )?(?:bloqueo|problema)\b/,
158
+ // fr
159
+ /\b(?:je laisse|laissant|je garde) (?:ce |le )?fil ouvert\b/,
160
+ /\bbloque encore\b/,
161
+ /\bil reste (?:un )?(?:blocage|probl[èe]me)\b/,
162
+ // it
163
+ /\b(?:lascio|lasciando|mantengo) (?:questo |il )?(?:thread|filo) apert[oa]\b/,
164
+ /\bblocca ancora\b/,
165
+ /\brimane (?:un )?(?:blocco|problema)\b/,
166
+ // pt
167
+ /\b(?:deixo|deixando|mantenho|mantendo) (?:este |o )?(?:t[óo]pico|fio) aberto\b/,
168
+ /\bainda (?:bloqueia|h[áa] (?:um )?(?:bloqueio|problema))\b/,
169
+ /\b(?:resta|permanece) (?:um )?(?:bloqueio|problema)\b/,
170
+ // de
171
+ /\b(?:diesen |den )?thread offen (?:lassen|halten)\b/,
172
+ /\b(?:blockiert|sperrt) (?:noch|weiterhin|immer noch)\b/,
173
+ /\b(?:ein )?(?:blocker|problem) bleibt\b/,
174
+ // ru: оставляю ветку открытой / пока не могу решить / блокер или проблема остаётся
175
+ /\u043E\u0441\u0442\u0430\u0432\u043B\u044F\u044E[^.!?]*(?:\u0432\u0435\u0442\u043A\u0443|\u0442\u0435\u043C\u0443)[^.!?]*\u043E\u0442\u043A\u0440\u044B\u0442/,
176
+ /\u043F\u043E\u043A\u0430 \u043D\u0435 \u043C\u043E\u0433\u0443[^.!?]*(?:\u0440\u0435\u0448\u0438\u0442\u044C|\u0437\u0430\u043A\u0440\u044B\u0442\u044C)/,
177
+ /(?:\u0431\u043B\u043E\u043A\u0435\u0440|\u043F\u0440\u043E\u0431\u043B\u0435\u043C\u0430)[^.!?]*(?:\u043E\u0441\u0442\u0430\u0451\u0442\u0441\u044F|\u043E\u0441\u0442\u0430\u0435\u0442\u0441\u044F)/,
178
+ // ko: 스레드를 열어 둠 / 차단 문제가 남음 / 아직 해결할 수 없음
179
+ /\uC2A4\uB808\uB4DC(?:\uB97C|\uB294)?[^.!?]*(?:\uC5F4\uC5B4 \uB450|\uC5F4\uB9B0 \uCC44)/,
180
+ /(?:\uCC28\uB2E8 (?:\uBB38\uC81C|\uC774\uC288)|\uBE14\uB85C\uCEE4)[^.!?]*\uB0A8\uC544 \uC788(?:\uC5B4|\uC2B5\uB2C8\uB2E4|\uB2E4|\uB294|\uACE0|\uC9C0\uB9CC|\uC74C)/,
181
+ /\uC544\uC9C1[^.!?]*\uD574\uACB0\uD560 \uC218 \uC5C6/,
182
+ // zh: 保持线程开启 / 还不能解决 / 问题仍然存在
183
+ /\u4FDD\u6301[^.!?]*\u7EBF\u7A0B[^.!?]*\u5F00\u542F/,
184
+ /\u8FD8\u4E0D\u80FD[^.!?]*\u89E3\u51B3/,
185
+ /(?:\u95EE\u9898|\u963B\u585E)[^.!?]*\u4ECD\u7136[^.!?]*\u5B58\u5728/,
186
+ /\u4ECD\u6709[^.!?]*(?:\u95EE\u9898|\u963B\u585E)/,
187
+ // ja: スレッドを開いたまま / まだ解決できない / 問題が残っている
188
+ /\u30B9\u30EC\u30C3\u30C9[^.!?]*\u958B\u3044\u305F\u307E\u307E/,
189
+ /\u307E\u3060[^.!?]*\u89E3\u6C7A\u3067\u304D(?:\u306A\u3044|\u307E\u305B\u3093)/,
190
+ /(?:\u554F\u984C|\u30D6\u30ED\u30C3\u30AB\u30FC)[^.!?]*\u6B8B\u3063\u3066\u3044(?:\u308B|\u307E\u3059)/,
191
+ // ar: إبقاء النقاش مفتوحاً / لا يمكنني الحل بعد / لا تزال مشكلة
192
+ /\u0625\u0628\u0642\u0627\u0621[^.!?]*\u0645\u0641\u062A\u0648\u062D/,
193
+ /\u0644\u0627 \u064A\u0645\u0643\u0646\u0646\u064A[^.!?]*\u062D\u0644[^.!?]*\u0628\u0639\u062F/,
194
+ /\u0644\u0627 \u062A\u0632\u0627\u0644[^.!?]*\u0645\u0634\u0643\u0644\u0629/,
195
+ // hi: समस्या/अवरोधक अभी बाकी है / अभी हल नहीं हुआ
196
+ /(?:\u0938\u092E\u0938\u094D\u092F\u093E|\u0905\u0935\u0930\u094B\u0927\u0915)[^.!?]*\u092C\u093E\u0915\u0940 \u0939\u0948\u0902?/,
197
+ /\u0905\u092D\u0940[^.!?]*\u0939\u0932[^.!?]*\u0928\u0939\u0940\u0902/,
198
+ // tr
199
+ /\b(?:bu )?(?:konuyu|ba\u015Fl\u0131\u011F\u0131) a[çc]\u0131k (?:tutuyorum|b\u0131rak\u0131yorum)\b/,
200
+ /\bh[âa]l[âa] (?:engelliyor|bir (?:engel|sorun) var)\b/,
201
+ /\b(?:engel|sorun) devam ediyor\b/,
202
+ // vi — no \b after accented characters: JS boundaries are ASCII-only.
203
+ /gi\u1EEF lu\u1ED3ng n\u00E0y m\u1EDF/,
204
+ /v\u1EABn ch\u1EB7n/,
205
+ /v\u1EABn c\u00F2n[^.!?]*(?:v\u1EA5n \u0111\u1EC1|tr\u1EDF ng\u1EA1i)/,
206
+ // id
207
+ /\b(?:membiarkan|menjaga) utas ini tetap terbuka\b/,
208
+ /\bmasih memblokir\b/,
209
+ /\bmasalah masih ada\b/,
210
+ /\bpemblokir tersisa\b(?![^.!?]*\b(?:sudah|telah) (?:diperbaiki|diselesaikan|ditangani)\b)/,
211
+ ]
212
+
137
213
  // Negative warn phrases re-assert a block ("not done yet") instead of closing it
138
214
  // out, so they are NOT close-out attempts — the re-review guard must ignore them.
139
- const WARN_NEGATIVE: readonly RegExp[] = [/\bneeds changes\b/, /\bstill needs work\b/]
215
+ const WARN_NEGATIVE: readonly RegExp[] = [/\bneeds changes\b/, /\bstill needs work\b/, ...HOLD_OPEN]
140
216
 
141
217
  const WARN: readonly RegExp[] = [...WARN_POSITIVE_CLOSEOUT, ...WARN_NEGATIVE]
142
218
 
@@ -145,7 +221,7 @@ const WARN: readonly RegExp[] = [...WARN_POSITIVE_CLOSEOUT, ...WARN_NEGATIVE]
145
221
  // (answering a question) is the worst false-positive class, so it is checked first.
146
222
  const DEMOTE_TO_IGNORE: readonly RegExp[] = [
147
223
  /\b(haven'?t|have not|did ?n'?t|did not|not yet|never)\b[^.!?]*\b(approv|request|resolv|block|address)/,
148
- /\b(can'?t|cannot|won'?t|will not|wouldn'?t)\b[^.!?]*\b(approv|request|resolv|block|address)/,
224
+ /\b(can(?:not|'?t|\s+t)|won(?:'?t|\s+t)|will not|wouldn(?:'?t|\s+t))\b[^.!?]*\b(approv|request|resolv|block|address)/,
149
225
  /\bnot (approved|resolved|blocked|requesting|addressed)\b/,
150
226
  /\b(not|no longer|hardly|barely)\b[^.!?]*\b(lgtm|looks good|looks fine|seems fine|should be (fine|good)|looks resolved|seems resolved)\b/,
151
227
  /\b(i'?ll|i will|going to|gonna|about to|planning to)\b[^.!?]*\b(approv|review|request|resolv)/,
@@ -200,9 +276,12 @@ export function classifyReviewClaim(rawText: string): ReviewClaim {
200
276
 
201
277
  const claims = segments.map(classifySegment)
202
278
 
279
+ // Formal-verdict receipts remain load-bearing even in a mixed message; unlike
280
+ // resolve chatter, letting a fabricated APPROVE/REQUEST_CHANGES through can
281
+ // falsify GitHub state. The hold-open veto is therefore deliberately narrower.
203
282
  if (claims.includes('block-approve')) return 'block-approve'
204
283
  if (claims.includes('block-request-changes')) return 'block-request-changes'
205
- if (claims.includes('block-resolve')) return 'block-resolve'
284
+ if (claims.includes('block-resolve') && !hasHoldOpenClaim(segments)) return 'block-resolve'
206
285
  if (claims.includes('warn')) return 'warn'
207
286
  return 'ignore'
208
287
  }
@@ -213,7 +292,9 @@ export function classifyReviewClaim(rawText: string): ReviewClaim {
213
292
  // escalate just the stranding-shaped warns, not the whole warn bucket.
214
293
  export function isPositiveWarnCloseout(rawText: string): boolean {
215
294
  if (classifyReviewClaim(rawText) !== 'warn') return false
216
- return claimSegments(rawText).some((segment) => WARN_POSITIVE_CLOSEOUT.some((re) => re.test(segment)))
295
+ const segments = claimSegments(rawText)
296
+ if (hasHoldOpenClaim(segments)) return false
297
+ return segments.some((segment) => WARN_POSITIVE_CLOSEOUT.some((re) => re.test(segment)))
217
298
  }
218
299
 
219
300
  function classifySegment(text: string): ReviewClaim {
@@ -229,6 +310,10 @@ function classifySegment(text: string): ReviewClaim {
229
310
  return 'ignore'
230
311
  }
231
312
 
313
+ function hasHoldOpenClaim(segments: readonly string[]): boolean {
314
+ return segments.some((segment) => HOLD_OPEN.some((re) => re.test(segment)))
315
+ }
316
+
232
317
  function claimSegments(text: string): string[] {
233
318
  return redactQuotedAndCode(text)
234
319
  .split(/(?<=[.!?])\s+|\n+/)
@@ -1,3 +1,4 @@
1
+ import { describeError } from './describe-error'
1
2
  // Decoupled from ChannelRouter on purpose: minting a token for an arbitrary
2
3
  // bash `gh` command is adjacent to channels but is not routing, and a global
3
4
  // singleton would leak resolver state across tests. One instance is created in
@@ -34,7 +35,7 @@ export function createGithubTokenBridge(): GithubTokenBridge {
34
35
  const token = await resolver(repoSlug)
35
36
  return { kind: 'token', token }
36
37
  } catch (err) {
37
- return { kind: 'unavailable', reason: err instanceof Error ? err.message : String(err) }
38
+ return { kind: 'unavailable', reason: describeError(err) }
38
39
  }
39
40
  },
40
41
  hasAppTokenResolver: () => current !== null,