typeclaw 0.34.1 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/package.json +3 -1
  2. package/src/agent/plugin-tools.ts +53 -5
  3. package/src/agent/provider-error.ts +10 -0
  4. package/src/agent/session-origin.ts +26 -0
  5. package/src/agent/tools/channel-disengage.ts +13 -9
  6. package/src/bundled-plugins/github-cli-auth/gh-command.ts +124 -6
  7. package/src/bundled-plugins/github-cli-auth/git-command.ts +172 -26
  8. package/src/bundled-plugins/github-cli-auth/index.ts +46 -7
  9. package/src/bundled-plugins/github-cli-auth/token-class.ts +13 -0
  10. package/src/bundled-plugins/security/policies/prompt-injection.ts +33 -2
  11. package/src/channels/adapters/github/inbound.ts +41 -3
  12. package/src/channels/adapters/slack-bot.ts +17 -9
  13. package/src/channels/continuation-willingness.ts +331 -0
  14. package/src/channels/github-review-claim.ts +105 -0
  15. package/src/channels/github-token-bridge.ts +7 -0
  16. package/src/channels/router.ts +103 -24
  17. package/src/cli/channel.ts +102 -11
  18. package/src/cli/qr.ts +130 -0
  19. package/src/config/config.ts +98 -2
  20. package/src/container/start.ts +12 -0
  21. package/src/init/dockerfile.ts +64 -0
  22. package/src/init/line-auth.ts +8 -3
  23. package/src/plugin/context.ts +5 -1
  24. package/src/plugin/manager.ts +2 -0
  25. package/src/plugin/types.ts +1 -0
  26. package/src/run/index.ts +1 -0
  27. package/src/sandbox/build.ts +27 -0
  28. package/src/sandbox/index.ts +6 -0
  29. package/src/sandbox/package-install.ts +23 -0
  30. package/src/sandbox/policy.ts +31 -0
  31. package/src/sandbox/symlinks.ts +34 -0
  32. package/src/sandbox/writable-zones.ts +164 -4
  33. package/src/skills/typeclaw-channel-github/SKILL.md +4 -2
  34. package/src/skills/typeclaw-github-contributing/SKILL.md +124 -0
  35. package/typeclaw.schema.json +32 -1
@@ -3,16 +3,28 @@ import { definePlugin } from '@/plugin'
3
3
 
4
4
  import { createApproveIdempotencyGuard } from './approve-idempotency'
5
5
  import { createGithubEffectiveApprovalResolver, createGithubHeadShaResolver } from './effective-approval'
6
- import { analyzeGhCommand } from './gh-command'
6
+ import { analyzeGhCommand, effectiveGhTokensForAuthenticatedUserEndpoint } from './gh-command'
7
7
  import { ensureGitAskPassHelper } from './git-askpass'
8
8
  import { analyzeGitCommand, defaultGitResolvers } from './git-command'
9
9
  import { checkGraphqlAuthNudge } from './graphql-auth-nudge'
10
10
  import { commitReviewIfSucceeded, noteReviewCommand } from './review-recorder'
11
- import { classifyGhToken } from './token-class'
11
+ import { classifyGhToken, shouldMintAppToken } from './token-class'
12
12
 
13
13
  export default definePlugin({
14
14
  plugin: async (ctx) => {
15
15
  const resolveTokenForRepo = ctx.github.resolveTokenForRepo
16
+ const hasAppTokenResolver = ctx.github.hasAppTokenResolver
17
+ // `/user` resolves the caller's USER identity. An App installation token is not
18
+ // a user, so GitHub rejects it on a token-class basis (403, or no-token error in
19
+ // the sandbox) no matter how valid the token is. We block-and-guide so the agent
20
+ // does not misread this as "I have no auth" — it does, for repo-scoped calls.
21
+ const appUserEndpointReason =
22
+ '`gh api /user` (and `/user/...`) resolves the calling USER. This agent authenticates ' +
23
+ 'as a GitHub App with a per-repo installation token, which is not a user identity — so ' +
24
+ '`/user` cannot work here, and this failure is NOT a sign that auth is missing (repo-' +
25
+ 'scoped calls still work). It is not a valid auth/login check. For repo data use ' +
26
+ '`gh <cmd> -R owner/repo` or `gh api /repos/owner/repo/...`; for the actor, read the ' +
27
+ 'PR/issue/comment context you were given instead of `gh api /user`.'
16
28
  const resolveToken = async (workspace: string) => {
17
29
  const result = await resolveTokenForRepo(workspace)
18
30
  return result.kind === 'token' ? result.token : null
@@ -44,8 +56,32 @@ export default definePlugin({
44
56
  if (review.dump !== null) return review.dump
45
57
 
46
58
  const decision = analyzeGhCommand(command)
59
+
60
+ // `/user` classifies as pass-through (no repo to mint for), so this block
61
+ // must run BEFORE the pass-through return. Resolve the EFFECTIVE token per
62
+ // `/user` invocation (a command-local `GH_TOKEN=…`/`GITHUB_TOKEN=…` overrides
63
+ // process env, matching gh) and block only when that token is App / none-with-
64
+ // minter — a command-local PAT override carries a user identity, so `/user`
65
+ // works for it and must not be blocked.
66
+ const userEndpointTokens = effectiveGhTokensForAuthenticatedUserEndpoint(command, {
67
+ GH_TOKEN: process.env.GH_TOKEN,
68
+ GITHUB_TOKEN: process.env.GITHUB_TOKEN,
69
+ })
70
+ if (userEndpointTokens.some((token) => shouldMintAppToken(token, hasAppTokenResolver()))) {
71
+ return { block: true, reason: appUserEndpointReason }
72
+ }
73
+
47
74
  if (decision.kind === 'pass-through') return 'fall-through'
48
75
 
76
+ // The `-R` strip is a pure syntax fix (`gh api` rejects `-R`), independent
77
+ // of token minting, so apply it for EVERY token class — including the PAT
78
+ // paths below that return without injecting. Only `inject` decisions carry
79
+ // `rewrittenCommand`, and only after the single-bare/safe-pipeline gate in
80
+ // analyzeGhCommand, so this never rewrites a blocked or unsafe shape.
81
+ if (decision.kind === 'inject' && decision.rewrittenCommand !== undefined) {
82
+ event.args.command = decision.rewrittenCommand
83
+ }
84
+
49
85
  const tokenClass = classifyGhToken(process.env.GH_TOKEN)
50
86
  // Classic PATs reach every owner; nothing to inject or enforce.
51
87
  if (tokenClass === 'cross-owner') return
@@ -57,15 +93,16 @@ export default definePlugin({
57
93
  // `gh` fails honestly if the named repo is under a different owner.
58
94
  if (tokenClass === 'fine-grained-pat') return
59
95
 
96
+ // No App auth (no App-class GH_TOKEN and no live minter): leave whatever
97
+ // is seeded so `gh` fails honestly rather than us guessing a token.
98
+ if (!shouldMintAppToken(process.env.GH_TOKEN, hasAppTokenResolver())) return
99
+
60
100
  const result = await resolveTokenForRepo(decision.repoSlug)
61
101
  if (result.kind === 'unavailable') return { block: true, reason: result.reason }
62
102
  // Inject via the internal env overlay (delivered to the spawn / bwrap
63
103
  // --setenv by the bash wrapper) so the token never enters the command
64
104
  // string, where it could leak through logs or later hooks.
65
105
  event.args[TYPECLAW_INTERNAL_BASH_ENV] = { GH_TOKEN: result.token }
66
- // graphql consumed `-R/--repo` as a mint hint; `gh api` rejects it, so
67
- // run the command with the flag stripped (token still rides in env).
68
- if (decision.rewrittenCommand !== undefined) event.args.command = decision.rewrittenCommand
69
106
  return
70
107
  }
71
108
 
@@ -76,8 +113,10 @@ export default definePlugin({
76
113
  }): Promise<HookResult> => {
77
114
  const { event, command, agentDir } = params
78
115
  // Only App auth re-mints per repo. Classic/fine-grained PATs and absent
79
- // tokens are left untouched, exactly as the gh path treats them.
80
- if (classifyGhToken(process.env.GH_TOKEN) !== 'app') return
116
+ // tokens are left untouched, exactly as the gh path treats them. App auth
117
+ // is detected by the live minter too, not just an App-class GH_TOKEN:
118
+ // multi-owner / no-repos App configs never seed GH_TOKEN yet can mint.
119
+ if (!shouldMintAppToken(process.env.GH_TOKEN, hasAppTokenResolver())) return
81
120
 
82
121
  const decision = await analyzeGitCommand(command, { cwd: agentDir, resolvers: defaultGitResolvers })
83
122
  if (decision.kind === 'pass-through') return
@@ -9,3 +9,16 @@ export function classifyGhToken(token: string | undefined): GhTokenClass {
9
9
  // a per-repo token rather than silently using a possibly-wrong global one.
10
10
  return 'app'
11
11
  }
12
+
13
+ // Whether the per-repo App minter should fire for a repo-targeting command.
14
+ // App auth is detected via EITHER a seeded App-class GH_TOKEN OR a live App
15
+ // token resolver — the latter is the authority because multi-owner / no-repos
16
+ // App configs intentionally leave GH_TOKEN unseeded (the prefix would read
17
+ // 'none'), yet the per-repo minter is still registered and able to mint. Classic
18
+ // and fine-grained PATs are never re-minted: they pass through with whatever
19
+ // GH_TOKEN is seeded, exactly as before.
20
+ export function shouldMintAppToken(token: string | undefined, hasAppTokenResolver: boolean): boolean {
21
+ const tokenClass = classifyGhToken(token)
22
+ if (tokenClass === 'cross-owner' || tokenClass === 'fine-grained-pat') return false
23
+ return tokenClass === 'app' || hasAppTokenResolver
24
+ }
@@ -427,6 +427,37 @@ const GIT_EXFIL_VERBS = [
427
427
  'hub\\s+(?:create|push)',
428
428
  ].join('|')
429
429
 
430
+ // "backup" framing across the same major-language set the rest of this file
431
+ // covers. The narrow English+Korean-only version let "백업 해줘 to my repo"
432
+ // framings phrased in any other channel language slip the standalone-backup
433
+ // catch (the SECRET_DEMAND patterns still fire when a credential is named; this
434
+ // is only the no-secret-named "push to my backup repo" idiom). Entries are the
435
+ // noun/verb for "backup"/"back up" — kept tight so they only matter within the
436
+ // 80-char proximity-to-git-push window below, never on their own.
437
+ const BACKUP_NOUNS = [
438
+ 'backup',
439
+ 'back[-\\s]?up',
440
+ '\u{BC31}\u{C5C5}', // ko 백업
441
+ '\u30D0\u30C3\u30AF\u30A2\u30C3\u30D7', // ja バックアップ
442
+ '\u5907\u4EFD', // zh-hans 备份
443
+ '\u5099\u4EFD', // zh-hant 備份
444
+ 'copia\\s*de\\s*seguridad', // es
445
+ 'respald(?:o|ar|a)', // es respaldo/respaldar
446
+ 'sauvegard(?:e|er)', // fr
447
+ 'sicherungskopie', // de
448
+ 'sicher(?:n|ung)', // de Sicherung/sichern
449
+ 'c[\u00F3o]pia\\s*de\\s*seguran[\u00E7c]a', // pt
450
+ 'fazer\\s*backup', // pt
451
+ '\u0440\u0435\u0437\u0435\u0440\u0432\u043D(?:\u0430\u044F|\u0443\u044E)\\s*\u043A\u043E\u043F\u0438\u044F', // ru резервная копия
452
+ 'sao\\s*l\u01B0u', // vi sao lưu
453
+ 'cadang(?:an)?', // id cadangan/mencadangkan
454
+ '\u0646\u0633\u062E(?:\u0629)?\\s*\u0627\u062D\u062A\u064A\u0627\u0637\u064A(?:\u0629)?', // ar نسخة احتياطية
455
+ '\u092C\u0948\u0915\u0905\u092A', // hi बैकअप
456
+ 'yede(?:k|kle)', // tr yedek/yedekle
457
+ 'copia\\s*di\\s*sicurezza', // it
458
+ 'backup', // it (loanword, same token)
459
+ ].join('|')
460
+
430
461
  const GIT_EXFIL_PATTERNS: ReadonlyArray<RegExp> = [
431
462
  new RegExp(`(?:${GIT_EXFIL_VERBS})`, 'i'),
432
463
  // Urgency shorthand ("do it" / "go ahead" / "now") right after a git command,
@@ -440,8 +471,8 @@ const GIT_EXFIL_PATTERNS: ReadonlyArray<RegExp> = [
440
471
  // request - if the same message also names a credential or `.env`, the
441
472
  // SECRET_DEMAND_PATTERNS already fires; this catches the standalone
442
473
  // "push to my backup repo" framing that doesn't mention secrets.
443
- /(?:backup|back[-\s]?up|\u{BC31}\u{C5C5})[\s\S]{0,80}(?:git\s+push|github\.com|gitlab\.com|bitbucket\.org)/iu,
444
- /(?:git\s+push|github\.com|gitlab\.com|bitbucket\.org)[\s\S]{0,80}(?:backup|back[-\s]?up|\u{BC31}\u{C5C5})/iu,
474
+ new RegExp(`(?:${BACKUP_NOUNS})[\\s\\S]{0,80}(?:git\\s+push|github\\.com|gitlab\\.com|bitbucket\\.org)`, 'iu'),
475
+ new RegExp(`(?:git\\s+push|github\\.com|gitlab\\.com|bitbucket\\.org)[\\s\\S]{0,80}(?:${BACKUP_NOUNS})`, 'iu'),
445
476
  ]
446
477
 
447
478
  export type InjectionMatch = {
@@ -396,17 +396,24 @@ export function classifyGithubInbound(
396
396
  const root = parentId ?? id
397
397
  const parent =
398
398
  parentId !== null && options?.reviewCommentParent?.parentId === parentId ? options.reviewCommentParent : null
399
+ const commenter = readUser(comment.user)
400
+ const directedAtBot =
401
+ parentId === null &&
402
+ isSelfPr(readUser(pr.user), selfLogin, options?.authType ?? 'pat') &&
403
+ commenter !== null &&
404
+ !isSelfAuthor(commenter, null, selfLogin)
399
405
  return buildInbound(
400
406
  { ...base, chat: `pr:${number}`, thread: String(root) },
401
407
  comment.body,
402
408
  id,
403
- readUser(comment.user),
409
+ commenter,
404
410
  mention,
405
411
  comment.created_at,
406
412
  { kind: 'pr-review-comment', owner: repository.owner, repo: repository.name, commentId: id },
407
413
  false,
408
414
  {
409
415
  suppressSticky: true,
416
+ ...(directedAtBot ? { forceBotMention: true } : {}),
410
417
  replyToBotMessageId: parent?.isSelf === true ? String(parent.parentId) : null,
411
418
  replyToOtherMessageId: parent?.isSelf === false ? String(parent.parentId) : null,
412
419
  },
@@ -533,6 +540,11 @@ export function classifyGithubInbound(
533
540
  : reviewer !== null
534
541
  ? synthesizeReviewStateText(reviewer.login, number, readString(pr, 'title'), readString(review, 'state'))
535
542
  : ''
543
+ const directedAtBot =
544
+ isSelfPr(readUser(pr.user), selfLogin, options?.authType ?? 'pat') &&
545
+ reviewer !== null &&
546
+ !isSelfAuthor(reviewer, null, selfLogin) &&
547
+ isActionableReviewState(readString(review, 'state'))
536
548
  return buildInbound(
537
549
  { ...base, chat: `pr:${number}`, thread: null },
538
550
  text,
@@ -542,7 +554,7 @@ export function classifyGithubInbound(
542
554
  review.submitted_at,
543
555
  null,
544
556
  !hasBody,
545
- { suppressSticky: true },
557
+ { suppressSticky: true, ...(directedAtBot ? { forceBotMention: true } : {}) },
546
558
  )
547
559
  }
548
560
 
@@ -591,6 +603,12 @@ type BuildInboundOptions = {
591
603
  suppressSticky?: boolean
592
604
  replyToBotMessageId?: string | null
593
605
  replyToOtherMessageId?: string | null
606
+ // Forces isBotMention=true with no @-handle in the body. A review (or
607
+ // top-level review comment) on a PR the agent ITSELF authored is directed at
608
+ // the bot — the inverse of review_requested — so it engages even though the
609
+ // reviewer never types `@bot`. Paired with suppressSticky so reviews on OTHER
610
+ // people's PRs still observe-only (preserving the PR #672 fix).
611
+ forceBotMention?: boolean
594
612
  }
595
613
 
596
614
  // A GitHub App can never be a `requested_reviewer` — that field only holds
@@ -799,7 +817,7 @@ function buildInbound(
799
817
  // Synthesized awareness lines carry an `@author` prefix describing who acted;
800
818
  // that handle is the author, never a third-party mention of the bot, so the
801
819
  // body-text mention heuristic must not fire on it.
802
- const isBotMention = !synthesizedAwareness && textMentionsBot(text, mention)
820
+ const isBotMention = options?.forceBotMention === true || (!synthesizedAwareness && textMentionsBot(text, mention))
803
821
  const replyToBotMessageId = options?.replyToBotMessageId ?? null
804
822
  const replyToOtherMessageId = options?.replyToOtherMessageId ?? key.replyToOtherMessageId
805
823
  return {
@@ -854,6 +872,15 @@ function synthesizeReviewStateText(
854
872
  return `@${reviewer} ${verb} PR #${number}${label}.`
855
873
  }
856
874
 
875
+ // A review on the agent's own PR engages it only when there is something to act
876
+ // on. APPROVED clears the PR and needs no reply, so engaging would just produce
877
+ // "thanks" churn; it stays awareness-only. COMMENTED and CHANGES_REQUESTED (and
878
+ // any non-approval state) carry feedback the agent should address. State case
879
+ // varies by payload source (webhook vs REST), so normalize before matching.
880
+ function isActionableReviewState(state: string | null): boolean {
881
+ return state?.toLowerCase() !== 'approved'
882
+ }
883
+
857
884
  async function resolveTeamMembership(
858
885
  event: string,
859
886
  payload: Record<string, unknown>,
@@ -981,6 +1008,17 @@ function isSelfAuthor(author: GithubUser, selfId: string | null, selfLogin: stri
981
1008
  return false
982
1009
  }
983
1010
 
1011
+ // Whether the PR's OPENER is this agent. Distinct from isSelfAuthor (which
1012
+ // guards self-loops on the event ACTOR by id/login): here we have only the
1013
+ // `pull_request.user` from a review payload, no id to compare, and under App
1014
+ // auth the bot opens PRs as the decoy account (login = slug, e.g. `typeey`),
1015
+ // not the actor login `typeey[bot]`. So this matches selfLogin AND the decoy
1016
+ // slug — mirroring resolveBotMentionLogins.
1017
+ function isSelfPr(prUser: GithubUser | null, selfLogin: string | null, authType: 'pat' | 'app'): boolean {
1018
+ if (prUser === null || selfLogin === null) return false
1019
+ return resolveBotMentionLogins(selfLogin, authType).includes(prUser.login)
1020
+ }
1021
+
984
1022
  type GithubUser = { login: string; id: number; type?: string }
985
1023
 
986
1024
  function readUser(value: unknown): GithubUser | null {
@@ -359,18 +359,26 @@ export function createTypingCallback(deps: {
359
359
  // threads keep using `thread`. Either way the status is keyed on one ts.
360
360
  const statusThread =
361
361
  target.typingThread !== undefined && target.typingThread !== '' ? target.typingThread : target.thread
362
- const tag = formatChannelTag
363
- ? await formatChannelTag(target.workspace, statusThread ?? target.chat)
364
- : `channel=${statusThread ?? target.chat}`
365
362
  if (statusThread === undefined || statusThread === null || statusThread === '') {
366
- if (target.phase === 'tick') logger.info(`[slack-bot] typing (no-op, top-level chat) ${tag}`)
367
- return
368
- }
369
- if (target.phase === 'stop') {
370
- await typingTracker.clearAfterSend(target.chat, statusThread)
363
+ if (target.phase === 'tick') {
364
+ const tag = formatChannelTag
365
+ ? await formatChannelTag(target.workspace, statusThread ?? target.chat)
366
+ : `channel=${statusThread ?? target.chat}`
367
+ logger.info(`[slack-bot] typing (no-op, top-level chat) ${tag}`)
368
+ }
371
369
  return
372
370
  }
373
- await typingTracker.setStatus(target.chat, statusThread, 'is typing...')
371
+ // Append to the per-(chat,thread) FIFO BEFORE awaiting anything: the FIFO
372
+ // only orders calls once setStatus/clearAfterSend is reached, so awaiting
373
+ // `formatChannelTag` first opens an unordered gap where a fire-and-forget
374
+ // re-arm 'tick' (router send() after a reply) can enqueue "is typing..."
375
+ // AFTER the turn-end 'stop' clear. Flat DMs have no threaded-reply
376
+ // auto-clear, so that strands the indicator until Slack's ~2-min timeout.
377
+ const enqueued =
378
+ target.phase === 'stop'
379
+ ? typingTracker.clearAfterSend(target.chat, statusThread)
380
+ : typingTracker.setStatus(target.chat, statusThread, 'is typing...')
381
+ await enqueued
374
382
  }
375
383
  }
376
384
 
@@ -0,0 +1,331 @@
1
+ // A channel turn ends after a successful `channel_reply` (the terminal-reply
2
+ // abort in router.ts). When the model's reply PROMISES to keep working this
3
+ // turn ("바로 확인해볼게요", "let me check", "I'll continue now") but it forgot
4
+ // to set `channel_reply({ continue: true })`, the turn aborts and the promised
5
+ // follow-up never runs. The router uses this detector to inject ONE bounded
6
+ // reminder nudge so the model gets a second chance. See the empty-turn retry
7
+ // (router.ts) for the sibling mechanism this mirrors.
8
+ //
9
+ // Design bias: PREFER FALSE NEGATIVES. A miss leaves the status quo (turn ends,
10
+ // recoverable by a later user message); a false positive costs one wasted
11
+ // reminder-only turn that the model ends with NO_REPLY. So the phrase tables are
12
+ // deliberately narrow — only self-directed FUTURE intent to act THIS turn, never
13
+ // descriptive ("I checked and it's fine") or other-directed ("you can continue")
14
+ // usage. This is a HINT, not a control-flow authority: the abort still fires
15
+ // regardless; only the optional nudge is gated on it.
16
+
17
+ // Strip markdown emphasis/code fences before matching so an inline `gh` span
18
+ // inside "바로 `gh`로 확인할게요" does not split the phrase.
19
+ function normalize(text: string): string {
20
+ return text
21
+ .toLowerCase()
22
+ .replace(/[`*_~]/g, ' ')
23
+ .replace(/\s+/g, ' ')
24
+ .trim()
25
+ }
26
+
27
+ // Self-directed future-intent phrases. Each asserts the SPEAKER will do more
28
+ // work imminently. The leading "i" / "let me" anchors self-direction so
29
+ // "you can continue" never matches.
30
+ const EN_PHRASES: readonly string[] = [
31
+ "i'll continue",
32
+ 'i will continue',
33
+ "i'll keep going",
34
+ "i'll keep checking",
35
+ "i'll keep looking",
36
+ "i'll take a look",
37
+ "i'll check",
38
+ "i'll look into",
39
+ "i'll dig in",
40
+ "i'll go ahead and",
41
+ 'let me check',
42
+ 'let me look',
43
+ 'let me take a look',
44
+ 'let me dig',
45
+ 'let me continue',
46
+ 'let me verify',
47
+ 'checking now',
48
+ 'looking into it now',
49
+ 'working on it now',
50
+ 'on it now',
51
+ 'give me a moment',
52
+ 'give me a sec',
53
+ ]
54
+
55
+ // Korean: -ㄹ게요 / -겠습니다 future-volitional endings on check/look/continue/
56
+ // proceed verbs. These endings are first-person volitional in Korean — they
57
+ // cannot address the listener, so they are safe self-direction anchors that
58
+ // descriptive or other-directed sentences do not produce. Bare "계속" is
59
+ // excluded ("계속 진행하세요" = "you go ahead", terminal).
60
+ const KO_PHRASES: readonly string[] = [
61
+ '확인해볼게요',
62
+ '확인해 볼게요',
63
+ '확인할게요',
64
+ '확인하겠습니다',
65
+ '확인해보겠습니다',
66
+ '확인해 보겠습니다',
67
+ '다시 확인하겠습니다',
68
+ '다시 확인해보겠습니다',
69
+ '이어서 확인',
70
+ '계속 확인',
71
+ '계속 진행할게요',
72
+ '계속 진행하겠습니다',
73
+ '계속하겠습니다',
74
+ '계속할게요',
75
+ '바로 확인',
76
+ '바로 볼게요',
77
+ '바로 진행',
78
+ '살펴볼게요',
79
+ '살펴보겠습니다',
80
+ '진행하겠습니다',
81
+ '잠시만요',
82
+ '잠깐만요',
83
+ '곧 알려',
84
+ ]
85
+
86
+ // The remaining languages mirror the precision-first selection above: every
87
+ // entry pairs a FIRST-PERSON future/volitional anchor with a work verb
88
+ // (check/look/continue/proceed/verify) or is an immediate-work idiom ("on it
89
+ // now"). The same false-negative bias holds — bare verbs, bare acknowledgments
90
+ // ("ok", "sí", "好"), second-person imperatives ("you continue"), and
91
+ // descriptive past forms ("I checked") are deliberately excluded because a
92
+ // substring match on those would mis-fire. Latin/Cyrillic/Arabic/Indic entries
93
+ // are inflected first-person-future forms (or multi-word) so they cannot
94
+ // collide with a bare common word; CJK entries are full 4+ character
95
+ // intent phrases, never a lone noun.
96
+
97
+ // Spanish: "voy a" / "déjame" + work verb; "enseguida" (right away) idioms.
98
+ const ES_PHRASES: readonly string[] = [
99
+ 'voy a revisar',
100
+ 'voy a comprobar',
101
+ 'voy a verificar',
102
+ 'voy a mirar',
103
+ 'voy a continuar',
104
+ 'voy a seguir',
105
+ 'déjame revisar',
106
+ 'déjame comprobar',
107
+ 'déjame verificar',
108
+ 'déjame mirar',
109
+ 'lo reviso enseguida',
110
+ 'lo verifico enseguida',
111
+ 'enseguida lo reviso',
112
+ 'enseguida reviso',
113
+ 'un momento',
114
+ 'dame un momento',
115
+ 'dame un segundo',
116
+ ]
117
+
118
+ // French: "je vais" + work verb; "laisse-moi" idioms.
119
+ const FR_PHRASES: readonly string[] = [
120
+ 'je vais vérifier',
121
+ 'je vais regarder',
122
+ 'je vais continuer',
123
+ 'je vais poursuivre',
124
+ 'je vais voir',
125
+ 'je vais contrôler',
126
+ 'laisse-moi vérifier',
127
+ 'laisse-moi regarder',
128
+ 'je vérifie tout de suite',
129
+ 'je regarde tout de suite',
130
+ 'un instant',
131
+ 'donne-moi un instant',
132
+ 'donne-moi une seconde',
133
+ ]
134
+
135
+ // Italian: "vado a" / "fammi" + work verb; "controllo subito" idioms.
136
+ const IT_PHRASES: readonly string[] = [
137
+ 'vado a controllare',
138
+ 'vado a verificare',
139
+ 'vado a guardare',
140
+ 'fammi controllare',
141
+ 'fammi verificare',
142
+ 'fammi guardare',
143
+ 'controllo subito',
144
+ 'verifico subito',
145
+ 'continuo subito',
146
+ 'un momento',
147
+ 'dammi un momento',
148
+ 'dammi un secondo',
149
+ ]
150
+
151
+ // Portuguese: "vou" + work verb; "deixa eu" idioms.
152
+ const PT_PHRASES: readonly string[] = [
153
+ 'vou verificar',
154
+ 'vou checar',
155
+ 'vou conferir',
156
+ 'vou olhar',
157
+ 'vou continuar',
158
+ 'vou prosseguir',
159
+ 'deixa eu verificar',
160
+ 'deixa eu conferir',
161
+ 'deixa eu olhar',
162
+ 'verifico já',
163
+ 'já verifico',
164
+ 'um momento',
165
+ 'me dê um momento',
166
+ 'me dá um segundo',
167
+ ]
168
+
169
+ // German: "ich werde" / "lass mich" + work verb; "ich schaue gleich" idioms.
170
+ const DE_PHRASES: readonly string[] = [
171
+ 'ich werde prüfen',
172
+ 'ich werde überprüfen',
173
+ 'ich werde nachsehen',
174
+ 'ich werde weitermachen',
175
+ 'ich werde fortfahren',
176
+ 'lass mich prüfen',
177
+ 'lass mich nachsehen',
178
+ 'ich schaue gleich',
179
+ 'ich prüfe gleich',
180
+ 'gleich prüfen',
181
+ 'gleich überprüfen',
182
+ 'gleich nachsehen',
183
+ 'einen moment',
184
+ 'einen augenblick',
185
+ 'gib mir eine sekunde',
186
+ ]
187
+
188
+ // Russian: first-person-future verbs (проверю/посмотрю/продолжу) — the -ю/-у
189
+ // inflection is unambiguously "I will", so it is a safe self-anchor.
190
+ const RU_PHRASES: readonly string[] = [
191
+ 'сейчас проверю',
192
+ 'я проверю',
193
+ 'я посмотрю',
194
+ 'я продолжу',
195
+ 'продолжу проверку',
196
+ 'сейчас посмотрю',
197
+ 'дайте мне минуту',
198
+ 'одну секунду',
199
+ 'минутку',
200
+ ]
201
+
202
+ // Chinese: 我会/我来/我再 + work verb. Full multi-character intent phrases only;
203
+ // no bare nouns. 继续 alone is excluded (could be "you continue").
204
+ const ZH_PHRASES: readonly string[] = [
205
+ '我来确认',
206
+ '我来检查',
207
+ '我来看看',
208
+ '我会确认',
209
+ '我会检查',
210
+ '我会继续',
211
+ '我再确认',
212
+ '我再检查',
213
+ '我继续确认',
214
+ '我马上确认',
215
+ '我马上检查',
216
+ '我马上看',
217
+ '稍等一下',
218
+ '我看一下',
219
+ ]
220
+
221
+ // Japanese: -てみます / -します first-person volitional on check/look/continue.
222
+ // Bare nouns (確認) are excluded; the verb ending carries the self-direction.
223
+ const JA_PHRASES: readonly string[] = [
224
+ '確認します',
225
+ '確認してみます',
226
+ '確認いたします',
227
+ '調べてみます',
228
+ '調べます',
229
+ '見てみます',
230
+ '続けます',
231
+ '引き続き確認します',
232
+ 'すぐ確認します',
233
+ '少々お待ちください',
234
+ 'ちょっと待ってください',
235
+ ]
236
+
237
+ // Arabic: future particle سـ prefixed first-person verb (سأتحقق = "I will
238
+ // verify"). The سأ prefix is unambiguously first-person-future.
239
+ const AR_PHRASES: readonly string[] = [
240
+ 'سأتحقق',
241
+ 'سأتأكد',
242
+ 'سأراجع',
243
+ 'سأطلع',
244
+ 'سأكمل',
245
+ 'سأواصل',
246
+ 'دعني أتحقق',
247
+ 'دعني أراجع',
248
+ 'لحظة من فضلك',
249
+ ]
250
+
251
+ // Hindi: first-person-future "मैं … करूँगा/देखूँगा" forms (multi-word so they
252
+ // cannot collide with a bare common word).
253
+ const HI_PHRASES: readonly string[] = [
254
+ 'जाँच करूँगा',
255
+ 'जांच करूंगा',
256
+ 'देख लूँगा',
257
+ 'देख लूंगा',
258
+ 'जारी रखूँगा',
259
+ 'जारी रखूंगा',
260
+ 'एक मिनट रुकिए',
261
+ ]
262
+
263
+ // Turkish: first-person-future "-eceğim/-acağım" on check/look/continue verbs.
264
+ const TR_PHRASES: readonly string[] = [
265
+ 'kontrol edeceğim',
266
+ 'kontrol ediyorum',
267
+ 'bakacağım',
268
+ 'inceleyeceğim',
269
+ 'devam edeceğim',
270
+ 'hemen kontrol ediyorum',
271
+ 'hemen bakıyorum',
272
+ 'bir saniye',
273
+ 'bir dakika',
274
+ ]
275
+
276
+ // Vietnamese: "tôi sẽ" / "để tôi" (I will / let me) + work verb.
277
+ const VI_PHRASES: readonly string[] = [
278
+ 'tôi sẽ kiểm tra',
279
+ 'tôi sẽ xem',
280
+ 'tôi sẽ tiếp tục',
281
+ 'để tôi kiểm tra',
282
+ 'để tôi xem',
283
+ 'tôi kiểm tra ngay',
284
+ 'tôi xem ngay',
285
+ 'chờ một chút',
286
+ 'đợi một chút',
287
+ ]
288
+
289
+ // Indonesian: "saya akan" / "biar saya" (I will / let me) + work verb.
290
+ const ID_PHRASES: readonly string[] = [
291
+ 'saya akan periksa',
292
+ 'saya akan cek',
293
+ 'saya akan lihat',
294
+ 'saya akan lanjutkan',
295
+ 'biar saya periksa',
296
+ 'biar saya cek',
297
+ 'saya cek dulu',
298
+ 'saya periksa dulu',
299
+ 'tunggu sebentar',
300
+ 'sebentar ya',
301
+ ]
302
+
303
+ const ALL_PHRASES: readonly string[] = [
304
+ ...EN_PHRASES,
305
+ ...KO_PHRASES,
306
+ ...ES_PHRASES,
307
+ ...FR_PHRASES,
308
+ ...IT_PHRASES,
309
+ ...PT_PHRASES,
310
+ ...DE_PHRASES,
311
+ ...RU_PHRASES,
312
+ ...ZH_PHRASES,
313
+ ...JA_PHRASES,
314
+ ...AR_PHRASES,
315
+ ...HI_PHRASES,
316
+ ...TR_PHRASES,
317
+ ...VI_PHRASES,
318
+ ...ID_PHRASES,
319
+ ]
320
+
321
+ // Reply texts shorter than this are almost always a complete final answer
322
+ // ("네", "ok", "done") where a partial match would be noise. The shortest
323
+ // legitimate intent phrases ("on it now", "확인할게요") clear this floor.
324
+ const MIN_LENGTH = 4
325
+
326
+ export function detectContinuationWillingness(text: string): boolean {
327
+ if (text.length < MIN_LENGTH) return false
328
+ const normalized = normalize(text)
329
+ if (normalized.length < MIN_LENGTH) return false
330
+ return ALL_PHRASES.some((phrase) => normalized.includes(phrase))
331
+ }