typeclaw 0.48.6 → 0.48.8

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 (105) 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/live-subagents.ts +14 -0
  8. package/src/agent/multimodal/read-redirect.ts +8 -9
  9. package/src/agent/plugin-tools.ts +283 -148
  10. package/src/agent/provider-error.ts +6 -1
  11. package/src/agent/reload-tool.ts +12 -5
  12. package/src/agent/retry-same-ref.ts +95 -36
  13. package/src/agent/session-origin.ts +13 -1
  14. package/src/agent/system-prompt.ts +14 -3
  15. package/src/agent/todo/continuation-policy.ts +3 -4
  16. package/src/agent/tool-file-safety.ts +36 -13
  17. package/src/agent/tools/channel-reply.ts +39 -2
  18. package/src/agent/tools/channel-send.ts +45 -2
  19. package/src/agent/tools/post-github-review.ts +31 -13
  20. package/src/agent/tools/spawn-subagent.ts +15 -0
  21. package/src/agent/tools/webfetch/inline-style-visibility.ts +2 -2
  22. package/src/agent/tools/webfetch/strategies/readability.ts +109 -10
  23. package/src/agent/turn-runner.ts +23 -19
  24. package/src/bundled-plugins/backup/git-auth.ts +7 -4
  25. package/src/bundled-plugins/backup/subagents.ts +1 -1
  26. package/src/bundled-plugins/bun-hygiene/README.md +23 -20
  27. package/src/bundled-plugins/bun-hygiene/index.ts +1 -7
  28. package/src/bundled-plugins/bun-hygiene/policy.ts +111 -35
  29. package/src/bundled-plugins/github-cli-auth/gh-review-detect.ts +44 -2
  30. package/src/bundled-plugins/github-cli-auth/gh-store.ts +733 -0
  31. package/src/bundled-plugins/github-cli-auth/git-askpass.ts +25 -0
  32. package/src/bundled-plugins/github-cli-auth/git-command.ts +231 -30
  33. package/src/bundled-plugins/github-cli-auth/git-credential-env.ts +151 -0
  34. package/src/bundled-plugins/github-cli-auth/index.ts +249 -42
  35. package/src/bundled-plugins/github-cli-auth/review-recorder.ts +5 -0
  36. package/src/bundled-plugins/guard/index.ts +2 -25
  37. package/src/bundled-plugins/guard/keys.ts +8 -0
  38. package/src/bundled-plugins/guard/policies/non-workspace-write.ts +7 -8
  39. package/src/bundled-plugins/guard/policy.ts +1 -7
  40. package/src/bundled-plugins/security/policies/git-exfil.ts +22 -30
  41. package/src/bundled-plugins/security/policies/outbound-secret-scan.ts +2 -4
  42. package/src/bundled-plugins/security/policies/private-surface-read.ts +8 -6
  43. package/src/bundled-plugins/security/policies/secret-exfil-bash.ts +2 -5
  44. package/src/bundled-plugins/security/policies/secret-exfil-read.ts +2 -4
  45. package/src/bundled-plugins/security/policies/session-search-secrets.ts +2 -4
  46. package/src/bundled-plugins/security/policies/system-prompt-leak.ts +2 -4
  47. package/src/bundled-plugins/security/policy.ts +0 -8
  48. package/src/channels/adapters/discord-bot-slash-commands.ts +22 -0
  49. package/src/channels/adapters/discord-bot.ts +2 -1
  50. package/src/channels/adapters/discord-classify.ts +16 -4
  51. package/src/channels/adapters/discord.ts +20 -8
  52. package/src/channels/adapters/github/dedup.ts +37 -8
  53. package/src/channels/adapters/github/inbound.ts +241 -46
  54. package/src/channels/adapters/github/review-state.ts +13 -9
  55. package/src/channels/adapters/github/review-thread-resolver.ts +52 -20
  56. package/src/channels/adapters/slack-classify.ts +40 -5
  57. package/src/channels/adapters/slack.ts +3 -9
  58. package/src/channels/adapters/webex-bot-classify.ts +4 -33
  59. package/src/channels/adapters/webex-bot.ts +2 -4
  60. package/src/channels/adapters/webex-classify.ts +4 -33
  61. package/src/channels/adapters/webex-format.ts +36 -0
  62. package/src/channels/adapters/webex.ts +2 -4
  63. package/src/channels/continuation-willingness.ts +64 -39
  64. package/src/channels/github-rereview-guard.ts +20 -0
  65. package/src/channels/github-review-turn-ledger.ts +11 -1
  66. package/src/channels/github-review-verdict-coordinator.ts +475 -41
  67. package/src/channels/github-verdict-activity.ts +14 -5
  68. package/src/channels/persistence.ts +89 -5
  69. package/src/channels/router.ts +1223 -225
  70. package/src/channels/types.ts +21 -5
  71. package/src/cli/compose-stats.ts +6 -7
  72. package/src/cli/compose-status.ts +6 -7
  73. package/src/cli/compose-usage.ts +6 -7
  74. package/src/cli/stats.ts +6 -7
  75. package/src/cli/status.ts +7 -8
  76. package/src/cli/ui.ts +4 -4
  77. package/src/container/start.ts +41 -1
  78. package/src/cron/consumer.ts +30 -9
  79. package/src/cron/scheduler.ts +24 -9
  80. package/src/doctor/channel-checks.ts +64 -0
  81. package/src/doctor/report.ts +8 -8
  82. package/src/dreams/render.ts +2 -2
  83. package/src/init/dockerfile.ts +8 -1
  84. package/src/inspect/render.ts +2 -2
  85. package/src/path-safety/real-intended-path.ts +14 -1
  86. package/src/permissions/permissions.ts +10 -2
  87. package/src/permissions/resolve.ts +8 -2
  88. package/src/plugin/core-tool-names.ts +15 -0
  89. package/src/plugin/hooks.ts +37 -3
  90. package/src/plugin/registry.ts +7 -3
  91. package/src/run/index.ts +35 -15
  92. package/src/sandbox/build.ts +19 -3
  93. package/src/sandbox/policy.ts +1 -0
  94. package/src/secrets/export-github-cli-store.ts +158 -0
  95. package/src/secrets/index.ts +19 -1
  96. package/src/secrets/provision-github-cli-store.ts +322 -0
  97. package/src/secrets/schema.ts +13 -7
  98. package/src/secrets/storage.ts +30 -0
  99. package/src/shared/index.ts +2 -0
  100. package/src/shared/style-text.ts +13 -0
  101. package/src/skills/typeclaw-channel-github/SKILL.md +24 -12
  102. package/src/skills/typeclaw-config/SKILL.md +3 -1
  103. package/src/skills/typeclaw-github-contributing/SKILL.md +6 -2
  104. package/src/skills/typeclaw-permissions/SKILL.md +11 -22
  105. package/src/usage/report.ts +3 -3
@@ -1,30 +1,78 @@
1
- import { ACKNOWLEDGE_GUARDS, type GuardBlock, isGuardAcknowledged } from '../guard/policy'
1
+ import type { InternalGuardResult } from '@/agent/guard-types'
2
2
 
3
- export const GUARD_GLOBAL_INSTALL = 'globalInstall'
4
- export const GUARD_NON_BUN_PACKAGE_MANAGER = 'nonBunPackageManager'
3
+ import { GUARD_GLOBAL_INSTALL, GUARD_NON_BUN_PACKAGE_MANAGER, GUARD_NON_BUN_PACKAGE_RUNNER } from '../guard/keys'
5
4
 
6
- // Only install managers are blocked. The ephemeral runners npx/pnpx (and bunx,
7
- // which is `bun`) are intentionally absent: they run a tool once without
8
- // touching the dependency tree or writing a competing lockfile, so they don't
9
- // undermine the bun-standardization this set protects. classify() skips any
10
- // command word not in here, so leaving them out is what allows them.
5
+ export { GUARD_GLOBAL_INSTALL, GUARD_NON_BUN_PACKAGE_MANAGER, GUARD_NON_BUN_PACKAGE_RUNNER } from '../guard/keys'
6
+
7
+ // Install managers write competing lockfiles and install trees, so they are
8
+ // steered to bun.
11
9
  const NON_BUN_MANAGERS = new Set(['npm', 'pnpm', 'yarn'])
10
+ // The runners were previously allowed on the argument that they leave no
11
+ // lockfile or install tree behind. True, but that argument only covers
12
+ // dependency-tree pollution — it says nothing about which command word runs,
13
+ // and in practice "allowed" became "default": the vendored agent-messenger
14
+ // skills instruct the agent to use `npx -y` and explicitly not to deliberate
15
+ // about the runner, so nothing downstream ever got to prefer bunx. They stay
16
+ // reachable through their own acknowledgement rather than being allowed
17
+ // outright. `pnpm dlx` and `bun x` are two-word forms: the former already
18
+ // blocks as a manager, the latter is bun and is fine.
19
+ const NON_BUN_RUNNERS = new Set(['npx', 'pnpx'])
12
20
  const INSTALL_SUBCOMMANDS = new Set(['install', 'i', 'add'])
13
21
 
14
- export function checkBunHygieneGuard(options: { tool: string; args: Record<string, unknown> }): GuardBlock | undefined {
22
+ export function checkBunHygieneGuard(options: {
23
+ tool: string
24
+ args: Readonly<Record<string, unknown>>
25
+ }): InternalGuardResult {
15
26
  const { tool, args } = options
16
27
  if (tool !== 'bash') return undefined
17
28
 
18
29
  const command = args.command
19
30
  if (typeof command !== 'string') return undefined
20
31
 
21
- const verdict = classify(command)
22
- if (verdict === undefined) return undefined
23
- if (verdict.kind === 'global-install') return blockGlobalInstall(verdict.label, args)
24
- return blockNonBunManager(verdict.manager, args)
32
+ const verdict = classify(command)[0]
33
+ return verdict === undefined ? undefined : blockFor(verdict)
34
+ }
35
+
36
+ export function checkGlobalInstallGuard(options: {
37
+ tool: string
38
+ args: Readonly<Record<string, unknown>>
39
+ }): InternalGuardResult {
40
+ return checkVerdict(options, 'global-install')
41
+ }
42
+
43
+ export function checkNonBunPackageManagerGuard(options: {
44
+ tool: string
45
+ args: Readonly<Record<string, unknown>>
46
+ }): InternalGuardResult {
47
+ return checkVerdict(options, 'non-bun')
48
+ }
49
+
50
+ export function checkNonBunPackageRunnerGuard(options: {
51
+ tool: string
52
+ args: Readonly<Record<string, unknown>>
53
+ }): InternalGuardResult {
54
+ return checkVerdict(options, 'non-bun-runner')
55
+ }
56
+
57
+ function checkVerdict(
58
+ options: { tool: string; args: Readonly<Record<string, unknown>> },
59
+ kind: Verdict['kind'],
60
+ ): InternalGuardResult {
61
+ if (options.tool !== 'bash' || typeof options.args.command !== 'string') return undefined
62
+ const verdict = classify(options.args.command).find((candidate) => candidate.kind === kind)
63
+ return verdict === undefined ? undefined : blockFor(verdict)
25
64
  }
26
65
 
27
- type Verdict = { kind: 'global-install'; label: string } | { kind: 'non-bun'; manager: string }
66
+ function blockFor(verdict: Verdict): Exclude<InternalGuardResult, undefined> {
67
+ if (verdict.kind === 'global-install') return blockGlobalInstall(verdict.label)
68
+ if (verdict.kind === 'non-bun') return blockNonBunManager(verdict.manager)
69
+ return blockNonBunRunner(verdict.runner)
70
+ }
71
+
72
+ type Verdict =
73
+ | { kind: 'global-install'; label: string }
74
+ | { kind: 'non-bun'; manager: string }
75
+ | { kind: 'non-bun-runner'; runner: string }
28
76
 
29
77
  // Why a segment model instead of one big regex: every gap in a raw-string match
30
78
  // is a shell-structure gap. Splitting into segments first means a global flag on
@@ -33,24 +81,44 @@ type Verdict = { kind: 'global-install'; label: string } | { kind: 'non-bun'; ma
33
81
  // stripped uniformly, and `--global=false` is inspected as a real token. The
34
82
  // global-install verdict wins over the plain non-bun verdict (it's the more
35
83
  // specific violation, and acknowledging it is meant to let the whole thing run).
36
- function classify(command: string): Verdict | undefined {
37
- let fallback: Verdict | undefined
84
+ // Verdicts come back in precedence order and the caller stops at the first one
85
+ // that is not acknowledged. Falling through matters: `npm install && npx tsc`
86
+ // has two independent problems, so acknowledging the manager must still leave
87
+ // the runner blocked rather than clearing the whole command.
88
+ function classify(command: string): Verdict[] {
89
+ let globalVerdict: Verdict | undefined
90
+ let managerVerdict: Verdict | undefined
91
+ let runnerVerdict: Verdict | undefined
38
92
  for (const segment of splitSegments(command)) {
39
93
  const words = segment.map(normalizeWord)
40
- const manager = leadingCommandWord(words)
41
- if (manager === undefined) continue
94
+ const commandWord = leadingCommandWord(words)
95
+ if (commandWord === undefined) continue
96
+
97
+ if (NON_BUN_RUNNERS.has(commandWord)) {
98
+ runnerVerdict ??= { kind: 'non-bun-runner', runner: commandWord }
99
+ continue
100
+ }
42
101
 
43
102
  // `bun` is the allowed manager, but a `bun add -g` still installs to ~/.bun
44
103
  // (outside /agent) and is wiped on restart, so it is a global install too —
45
104
  // just never a plain non-bun violation.
46
- const isBun = manager === 'bun'
47
- if (!isBun && !NON_BUN_MANAGERS.has(manager)) continue
105
+ const isBun = commandWord === 'bun'
106
+ if (!isBun && !NON_BUN_MANAGERS.has(commandWord)) continue
48
107
 
49
- const label = globalInstallLabel(manager, words)
50
- if (label !== undefined) return { kind: 'global-install', label }
51
- if (!isBun) fallback ??= { kind: 'non-bun', manager }
108
+ // A global install subsumes the manager verdict for ITS OWN segment only:
109
+ // acknowledging `npm install -g x` is meant to let that install run without
110
+ // demanding a second acknowledgement for the same words. Scoping it to the
111
+ // segment is what stops it from clearing violations elsewhere in the
112
+ // command — an early return here let `bun add -g foo && npx tsc` through on
113
+ // a lone globalInstall acknowledgement.
114
+ const label = globalInstallLabel(commandWord, words)
115
+ if (label !== undefined) {
116
+ globalVerdict ??= { kind: 'global-install', label }
117
+ continue
118
+ }
119
+ if (!isBun) managerVerdict ??= { kind: 'non-bun', manager: commandWord }
52
120
  }
53
- return fallback
121
+ return [globalVerdict, managerVerdict, runnerVerdict].filter((verdict): verdict is Verdict => verdict !== undefined)
54
122
  }
55
123
 
56
124
  // Split on real command separators (`;`, `&&`, `||`, `|`, `&`, newline, `\r`)
@@ -295,29 +363,37 @@ function isGlobalFlag(word: string): boolean {
295
363
  return /^-[A-Za-z]*g[A-Za-z]*$/.test(word)
296
364
  }
297
365
 
298
- function blockGlobalInstall(label: string, args: Record<string, unknown>): GuardBlock | undefined {
299
- if (isGuardAcknowledged(args, GUARD_GLOBAL_INSTALL)) return undefined
300
-
366
+ function blockGlobalInstall(label: string): Exclude<InternalGuardResult, undefined> {
301
367
  return {
302
- block: true,
368
+ kind: 'acknowledgement-required',
303
369
  reason: [
304
370
  `Guard \`${GUARD_GLOBAL_INSTALL}\` blocked a global install: ${label}.`,
305
371
  'Global installs live outside the bind-mounted /agent folder and are wiped on every container restart, so they never persist.',
306
372
  'Use `bun add <pkg>` to add a dependency that survives restarts (it writes package.json), or `bunx <pkg>` to run a tool once without installing.',
307
- `Retry with \`${ACKNOWLEDGE_GUARDS}.${GUARD_GLOBAL_INSTALL}: true\` only if a throwaway global install is genuinely what you want.`,
373
+ `Retry with \`acknowledgeGuards.bun-hygiene.${GUARD_GLOBAL_INSTALL}: true\` only if a throwaway global install is genuinely what you want.`,
308
374
  ].join(' '),
309
375
  }
310
376
  }
311
377
 
312
- function blockNonBunManager(manager: string, args: Record<string, unknown>): GuardBlock | undefined {
313
- if (isGuardAcknowledged(args, GUARD_NON_BUN_PACKAGE_MANAGER)) return undefined
314
-
378
+ function blockNonBunManager(manager: string): Exclude<InternalGuardResult, undefined> {
315
379
  return {
316
- block: true,
380
+ kind: 'acknowledgement-required',
317
381
  reason: [
318
382
  `Guard \`${GUARD_NON_BUN_PACKAGE_MANAGER}\` blocked \`${manager}\`. This container standardizes on bun for dependency management.`,
319
- 'Use `bun install` / `bun add <pkg>` instead of npm/pnpm/yarn. Ephemeral runners (`bunx`, `npx`, `pnpx`) are allowed for one-off tool execution.',
320
- `Retry with \`${ACKNOWLEDGE_GUARDS}.${GUARD_NON_BUN_PACKAGE_MANAGER}: true\` if this package manager is genuinely required (e.g. a project pinned to a different lockfile).`,
383
+ 'Use `bun install` / `bun add <pkg>` instead of npm/pnpm/yarn, and use `bunx <pkg>` for one-off tool execution.',
384
+ `Retry with \`acknowledgeGuards.bun-hygiene.${GUARD_NON_BUN_PACKAGE_MANAGER}: true\` if this package manager is genuinely required (e.g. a project pinned to a different lockfile).`,
385
+ ].join(' '),
386
+ }
387
+ }
388
+
389
+ function blockNonBunRunner(runner: string): Exclude<InternalGuardResult, undefined> {
390
+ return {
391
+ kind: 'acknowledgement-required',
392
+ reason: [
393
+ `Guard \`${GUARD_NON_BUN_PACKAGE_RUNNER}\` blocked \`${runner}\`.`,
394
+ 'This container standardizes on bun for package execution: `bunx` is the Bun-native equivalent and the package runner the image actually ships. `npx`/`pnpx` are absent from the default image, and where a custom image supplies them they carry npm/pnpm semantics rather than bun ones.',
395
+ 'Use `bunx <pkg>` for one-off package binaries.',
396
+ `Retry with \`acknowledgeGuards.bun-hygiene.${GUARD_NON_BUN_PACKAGE_RUNNER}: true\` only if this non-bun runner is genuinely required.`,
321
397
  ].join(' '),
322
398
  }
323
399
  }
@@ -39,6 +39,7 @@ export type GhReviewDetectInput = {
39
39
  // `cd /agent && gh api -X POST repos/o/r/pulls/224/reviews …` used the
40
40
  // slash-less form and was missed by the slash-anchored pattern.
41
41
  const REVIEWS_ENDPOINT = /(?:^|\/)repos\/([^/\s]+)\/([^/\s]+)\/pulls\/(\d+)\/reviews\b/
42
+ const DISMISSAL_ENDPOINT = /(?:^|\/)repos\/([^/\s]+)\/([^/\s]+)\/pulls\/(\d+)\/reviews\/\d+\/dismissals\b/
42
43
 
43
44
  export function detectReviewSubmission(input: GhReviewDetectInput): DetectedReview | null {
44
45
  const fileContents = input.inputFileContents ?? null
@@ -49,6 +50,20 @@ export function detectReviewSubmission(input: GhReviewDetectInput): DetectedRevi
49
50
  return null
50
51
  }
51
52
 
53
+ export function detectReviewDismissal(command: string): ReviewSubmissionAttempt | null {
54
+ for (const args of ghSegments(command)) {
55
+ if (args[1] !== 'api' || !isPutMethod(args)) continue
56
+ const endpoint = args.find((arg) => DISMISSAL_ENDPOINT.test(arg))
57
+ if (endpoint === undefined) continue
58
+ const match = DISMISSAL_ENDPOINT.exec(endpoint)
59
+ if (match === null) continue
60
+ const prNumber = Number(match[3])
61
+ if (!Number.isSafeInteger(prNumber)) return null
62
+ return { workspace: `${match[1]}/${match[2]}`, prNumber }
63
+ }
64
+ return null
65
+ }
66
+
52
67
  // A landed review of ANY state — the two decisive verdicts PLUS a COMMENT. Feeds
53
68
  // the router's empty-turn guard (a COMMENT is real user-facing output, so an empty
54
69
  // completion afterward must not fire the "I got stuck" fallback). Deliberately
@@ -207,6 +222,21 @@ function isPostMethod(args: readonly string[]): boolean {
207
222
  return false
208
223
  }
209
224
 
225
+ function isPutMethod(args: readonly string[]): boolean {
226
+ for (let i = 0; i < args.length; i++) {
227
+ const arg = args[i]
228
+ if (arg === undefined) continue
229
+ if ((arg === '-X' || arg === '--method') && (args[i + 1] ?? '').toUpperCase() === 'PUT') return true
230
+ if (
231
+ (arg.startsWith('-X=') || arg.startsWith('--method=')) &&
232
+ arg.slice(arg.indexOf('=') + 1).toUpperCase() === 'PUT'
233
+ ) {
234
+ return true
235
+ }
236
+ }
237
+ return false
238
+ }
239
+
210
240
  function detectApiReview(args: readonly string[], fileContents: string | null): DetectedReview | null {
211
241
  const endpoint = args.find((a) => REVIEWS_ENDPOINT.test(a))
212
242
  if (endpoint === undefined) return null
@@ -267,12 +297,24 @@ function detectPrReview(args: readonly string[]): DetectedReview | null {
267
297
  ? 'REQUEST_CHANGES'
268
298
  : null
269
299
  if (verdict === null) return null
270
- const workspace = repoFromFlag(args)
271
- const prNumber = prNumberArg(args)
300
+ const urlTarget = prUrlTarget(args)
301
+ const workspace = repoFromFlag(args) ?? urlTarget?.workspace ?? null
302
+ const prNumber = prNumberArg(args) ?? urlTarget?.prNumber ?? null
272
303
  if (workspace === null || prNumber === null) return null
273
304
  return { workspace, prNumber, verdict, source: 'pr-review' }
274
305
  }
275
306
 
307
+ function prUrlTarget(args: readonly string[]): { workspace: string; prNumber: number } | null {
308
+ for (const arg of args) {
309
+ const match = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/pull\/(\d+)(?:[/?#].*)?$/.exec(arg)
310
+ if (match === null) continue
311
+ const prNumber = Number(match[3])
312
+ if (!Number.isSafeInteger(prNumber)) return null
313
+ return { workspace: `${match[1]}/${match[2]}`, prNumber }
314
+ }
315
+ return null
316
+ }
317
+
276
318
  function repoFromFlag(args: readonly string[]): string | null {
277
319
  for (let i = 0; i < args.length; i++) {
278
320
  const a = args[i]