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
@@ -1,10 +1,17 @@
1
- import { TYPECLAW_INTERNAL_BASH_ENV } from '@/agent/plugin-tools'
1
+ import {
2
+ TYPECLAW_INTERNAL_BASH_ENV,
3
+ TYPECLAW_INTERNAL_BASH_PREPARE,
4
+ TYPECLAW_INTERNAL_BASH_WITHHOLD_ENV,
5
+ } from '@/agent/plugin-tools'
2
6
  import type { SessionOrigin } from '@/agent/session-origin'
7
+ import { recordVerifiedDismissal } from '@/channels/github-review-turn-ledger'
3
8
  import {
4
9
  configureReviewVerdictCoordinator,
5
10
  createSharedReviewVerdictGuard,
11
+ guardGithubReviewRoundDismissal,
12
+ releaseGithubReviewRoundDismissal,
6
13
  } from '@/channels/github-review-verdict-coordinator'
7
- import { hasEnvKey } from '@/init/env-file'
14
+ import { hasEnvKey, readEnvFile } from '@/init/env-file'
8
15
  import { CORE_PERMISSIONS } from '@/permissions/builtins'
9
16
  import { definePlugin } from '@/plugin'
10
17
 
@@ -15,6 +22,14 @@ import {
15
22
  effectiveGhTokensForAuthenticatedUserEndpoint,
16
23
  usesGhApiGraphqlEndpoint,
17
24
  } from './gh-command'
25
+ import { detectReviewDismissal } from './gh-review-detect'
26
+ import {
27
+ cleanupPreparedGithubStorePush,
28
+ GH_STORE_AMBIENT_AUTH_KEYS,
29
+ planGithubStorePush,
30
+ prepareGithubStorePush,
31
+ resolveGithubCliStoreToken,
32
+ } from './gh-store'
18
33
  import { ensureGitAskPassHelper, resolveSandboxGitAskPassPath } from './git-askpass'
19
34
  import {
20
35
  analyzeGitCommand,
@@ -22,14 +37,16 @@ import {
22
37
  defaultGitResolvers,
23
38
  resolveGhDefaultRepoFromCwd,
24
39
  } from './git-command'
40
+ import { buildGitCredentialEnv, type GitRepoCredential } from './git-credential-env'
25
41
  import { checkGraphqlAuthNudge } from './graphql-auth-nudge'
26
- import { commitReviewIfSucceeded, noteReviewCommand } from './review-recorder'
42
+ import { commitReviewIfSucceeded, dismissalMutationSucceeded, noteReviewCommand } from './review-recorder'
27
43
  import { classifyGhToken, shouldMintAppToken } from './token-class'
28
44
 
29
45
  export default definePlugin({
30
46
  plugin: async (ctx) => {
31
47
  const resolveTokenForRepo = ctx.github.resolveTokenForRepo
32
48
  const hasAppTokenResolver = ctx.github.hasAppTokenResolver
49
+ const trustedGitTransportEnv: NodeJS.ProcessEnv = { ...process.env }
33
50
 
34
51
  // Every model-driven bash masks the canonical credential files. A role may
35
52
  // still USE a PAT through this runtime-owned overlay, which injects one
@@ -77,6 +94,39 @@ export default definePlugin({
77
94
  return undefined
78
95
  }
79
96
 
97
+ // Stricter than sandboxInheritedGhToken(), and deliberately not merged with it.
98
+ // `gh` only needs to know WHICH token the sandbox will hand it, so the live
99
+ // value is the right answer there. Brokering to git asserts something stronger
100
+ // — that the operator deliberately exposed THIS value — and a declared NAME
101
+ // does not authenticate a live VALUE: PAT-mode channel auth overwrites
102
+ // process.env.GH_TOKEN at runtime (channels/adapters/github/index.ts), so a
103
+ // declared name can carry a credential the operator never wrote to `.env`.
104
+ // Compare against the same literal `readEnvFile` parse Docker's --env-file
105
+ // injects, and fail closed on any mismatch.
106
+ const declaredGhTokenForGitBroker = (): { envName: 'GH_TOKEN' | 'GITHUB_TOKEN'; value: string } | undefined => {
107
+ const inherited = sandboxInheritedGhToken()
108
+ if (inherited === undefined) return undefined
109
+ const declared = readEnvFile(ctx.agentDir).get(inherited.envName)
110
+ if (declared === undefined || declared === '' || declared !== inherited.value) return undefined
111
+ return inherited
112
+ }
113
+
114
+ const declaredGitCredentialState = ():
115
+ | { kind: 'absent' }
116
+ | { kind: 'invalid' }
117
+ | { kind: 'pat'; envName: 'GH_TOKEN' | 'GITHUB_TOKEN'; value: string } => {
118
+ const inherited = declaredGhTokenForGitBroker()
119
+ if (inherited === undefined) {
120
+ return hasEnvKey(ctx.agentDir, 'GH_TOKEN') || hasEnvKey(ctx.agentDir, 'GITHUB_TOKEN')
121
+ ? { kind: 'invalid' }
122
+ : { kind: 'absent' }
123
+ }
124
+ const tokenClass = classifyGhToken(inherited.value)
125
+ return tokenClass === 'cross-owner' || tokenClass === 'fine-grained-pat'
126
+ ? { kind: 'pat', ...inherited }
127
+ : { kind: 'invalid' }
128
+ }
129
+
80
130
  // A process-only PAT (runtime/App-seeded process.env, NOT declared in `.env`)
81
131
  // is stripped by --clearenv for this role, and a PAT is not re-mintable per
82
132
  // repo, so there is no token to inject. Tell the AGENT (model-visible block)
@@ -92,6 +142,26 @@ export default definePlugin({
92
142
  'sandbox. Configure GitHub App auth (channels.github) for per-repo, short-lived tokens that work ' +
93
143
  'for sandboxed roles, or declare the PAT in `.env` to deliberately expose it to model bash.'
94
144
 
145
+ // Deliberately claims only what this process can prove: a resolver is absent.
146
+ // It cannot tell PAT-configured from App-configured-but-adapter-down, so it
147
+ // names both remedies instead of guessing one. The closing lines exist because
148
+ // a mute refusal here is indistinguishable from broken auth, so the caller
149
+ // retries credential-management commands that are themselves blocked.
150
+ const missingAppAuthForPushReason =
151
+ 'Pushing to github.com needs an eligible credential and validated destination, and TypeClaw has nothing it can give this git command. ' +
152
+ 'Operator remedy: declare `GH_TOKEN` in the agent `.env` and restart, configure GitHub App auth under ' +
153
+ '`channels.github` for per-repo short-lived tokens, or authenticate host `gh` with ' +
154
+ '`gh auth login --hostname github.com`; the next real `typeclaw start` or `typeclaw restart` automatically captures ' +
155
+ 'that active account into the trusted-runtime store (a start against an already-running container is a no-op). ' +
156
+ 'If App auth is already configured, the adapter failed to start — check ' +
157
+ '`typeclaw logs`. Do not retry with ' +
158
+ '`gh auth setup-git`, a credential helper, or a tokenized remote URL: those are blocked and the ' +
159
+ 'credential files are masked in this sandbox.'
160
+ const multiPushStoreReason =
161
+ 'The trusted GitHub CLI credential store can fund exactly one configured push repository. ' +
162
+ 'This remote has multiple GitHub push destinations; use an authoritative declared PAT or GitHub App auth, ' +
163
+ 'or configure exactly one push URL.'
164
+
95
165
  let warnedSandboxedPatWithheld = false
96
166
  const warnSandboxedPatWithheldOnce = (): void => {
97
167
  if (warnedSandboxedPatWithheld) return
@@ -122,15 +192,17 @@ export default definePlugin({
122
192
  const result = await resolveTokenForRepo(workspace)
123
193
  return result.kind === 'token' ? result.token : null
124
194
  }
195
+ const resolveEffectiveApproval = createGithubEffectiveApprovalResolver({
196
+ resolveToken,
197
+ selfLogin: ctx.github.getAppSelfLogin ?? (() => null),
198
+ isAppAuth: hasAppTokenResolver,
199
+ })
125
200
  configureReviewVerdictCoordinator({
126
- resolveEffectiveApproval: createGithubEffectiveApprovalResolver({
127
- resolveToken,
128
- selfLogin: ctx.github.getAppSelfLogin ?? (() => null),
129
- isAppAuth: hasAppTokenResolver,
130
- }),
201
+ resolveEffectiveApproval,
131
202
  resolveHeadSha: createGithubHeadShaResolver({ resolveToken }),
132
203
  })
133
204
  const verdictGuard = createSharedReviewVerdictGuard()
205
+ const pendingDismissals = new Map<string, { workspace: string; prNumber: number }>()
134
206
 
135
207
  type HookResult = void | { block: true; reason: string }
136
208
 
@@ -205,22 +277,42 @@ export default definePlugin({
205
277
  }
206
278
  }
207
279
 
208
- const review = await noteReviewCommand({ callId: event.callId, command })
209
280
  // guard() holds the lease expecting tool.after to release it. A later
210
281
  // tool.before block means tool.after never fires, so blockAfterLease()
211
282
  // releases the lease with succeeded:false. The static command analyzer runs
212
283
  // above and never claims a lease for a command it will reject.
213
284
  let leaseClaimed = false
285
+ let dismissalLeaseClaimed = false
214
286
  const blockAfterLease = async (block: HookResult & { block: true }): Promise<HookResult> => {
215
- if (leaseClaimed) await verdictGuard.release({ callId: event.callId, succeeded: false })
287
+ if (leaseClaimed) await verdictGuard.release({ callId: event.callId, outcome: 'failed' })
288
+ if (dismissalLeaseClaimed) releaseGithubReviewRoundDismissal(event.callId, false)
289
+ pendingDismissals.delete(event.callId)
216
290
  return block
217
291
  }
292
+ const dismissal = detectReviewDismissal(command)
293
+ if (dismissal !== null) {
294
+ const block = await guardGithubReviewRoundDismissal({
295
+ callId: event.callId,
296
+ workspace: dismissal.workspace,
297
+ prNumber: dismissal.prNumber,
298
+ ...(event.origin?.kind === 'channel' && event.origin.githubReviewRound !== undefined
299
+ ? { round: event.origin.githubReviewRound, thread: event.origin.thread }
300
+ : {}),
301
+ })
302
+ if (block !== null) return block
303
+ dismissalLeaseClaimed = event.origin?.kind === 'channel' && event.origin.githubReviewRound !== undefined
304
+ pendingDismissals.set(event.callId, dismissal)
305
+ }
306
+ const review = await noteReviewCommand({ callId: event.callId, command })
218
307
  if (review.detected !== null) {
219
308
  const block = await verdictGuard.guard({
220
309
  callId: event.callId,
221
310
  workspace: review.detected.workspace,
222
311
  prNumber: review.detected.prNumber,
223
312
  verdict: review.detected.verdict,
313
+ ...(event.origin?.kind === 'channel' && event.origin.githubReviewRound !== undefined
314
+ ? { round: event.origin.githubReviewRound, thread: event.origin.thread }
315
+ : {}),
224
316
  })
225
317
  if (block !== null) return block
226
318
  leaseClaimed = true
@@ -353,7 +445,7 @@ export default definePlugin({
353
445
  }
354
446
 
355
447
  const handleGitCommand = async (params: {
356
- event: { args: Record<string, unknown> }
448
+ event: { callId: string; args: Record<string, unknown>; origin?: SessionOrigin }
357
449
  command: string
358
450
  agentDir: string
359
451
  sessionId: string
@@ -366,12 +458,100 @@ export default definePlugin({
366
458
  if (decision.kind === 'pass-through') return
367
459
  if (decision.kind === 'block') return { block: true, reason: decision.reason }
368
460
 
369
- // Only a per-repo GitHub App token is brokered to git — never a PAT (git,
370
- // unlike gh, runs repo-local hooks/helpers, and a PAT is not repo-confined).
371
- // With no App minter, pass through so git fails honestly.
372
- if (!hasAppTokenResolver()) return
373
- const result = await resolveTokenForRepo(decision.repoSlug)
374
- if (result.kind === 'unavailable') return { block: true, reason: result.reason }
461
+ const buildGitCredentialOverlay = async (
462
+ credentials: readonly GitRepoCredential[],
463
+ existing: unknown,
464
+ options: { expectedRemote?: string; pushUrls?: readonly string[]; trustedEnv?: NodeJS.ProcessEnv } = {},
465
+ ): Promise<Record<string, string>> => {
466
+ const askpass = await ensureGitAskPassHelper(resolveSandboxGitAskPassPath())
467
+ const overlay = existing !== null && typeof existing === 'object' ? (existing as Record<string, string>) : {}
468
+ return {
469
+ ...overlay,
470
+ ...buildGitCredentialEnv(credentials, askpass, options),
471
+ }
472
+ }
473
+ const destinationRepos =
474
+ decision.pushProvenance?.kind === 'configured-remote'
475
+ ? decision.pushProvenance.repoSlugs
476
+ : [decision.repoSlug.toLocaleLowerCase()]
477
+
478
+ if (!hasAppTokenResolver()) {
479
+ const declared = declaredGitCredentialState()
480
+ if (
481
+ // The analyzer emits write access only for its push subcommand grammar.
482
+ decision.access === 'write' &&
483
+ declared.kind === 'pat' &&
484
+ canUsePat(event.origin)
485
+ ) {
486
+ event.args[TYPECLAW_INTERNAL_BASH_ENV] = await buildGitCredentialOverlay(
487
+ destinationRepos.map((repoSlug) => ({ repoSlug, token: declared.value })),
488
+ event.args[TYPECLAW_INTERNAL_BASH_ENV],
489
+ {
490
+ expectedRemote:
491
+ decision.pushProvenance?.kind === 'configured-remote' ? decision.pushProvenance.remote : undefined,
492
+ pushUrls:
493
+ decision.pushProvenance?.kind === 'configured-remote' ? decision.pushProvenance.pushUrls : undefined,
494
+ trustedEnv: trustedGitTransportEnv,
495
+ },
496
+ )
497
+ // Withhold wins only when the same ambient names are absent from the overlay.
498
+ event.args[TYPECLAW_INTERNAL_BASH_WITHHOLD_ENV] = ['GH_TOKEN', 'GITHUB_TOKEN']
499
+ if (decision.rewrittenCommand !== undefined) event.args.command = decision.rewrittenCommand
500
+ return
501
+ }
502
+ if (decision.access !== 'write') return
503
+ if (declared.kind !== 'absent') return { block: true, reason: missingAppAuthForPushReason }
504
+ if (destinationRepos.length !== 1) return { block: true, reason: multiPushStoreReason }
505
+
506
+ const askpass = await ensureGitAskPassHelper(resolveSandboxGitAskPassPath())
507
+ const plan = await planGithubStorePush(decision, { agentDir, sessionId, askpassPath: askpass })
508
+ if (plan === null) return { block: true, reason: missingAppAuthForPushReason }
509
+ const storeToken = await resolveGithubCliStoreToken()
510
+ if (storeToken === null) return { block: true, reason: missingAppAuthForPushReason }
511
+ const credentialEnv = await buildGitCredentialOverlay(
512
+ [{ repoSlug: plan.repo, token: storeToken }],
513
+ event.args[TYPECLAW_INTERNAL_BASH_ENV],
514
+ { expectedRemote: plan.remote, trustedEnv: {} },
515
+ )
516
+ event.args[TYPECLAW_INTERNAL_BASH_ENV] = credentialEnv
517
+ const inheritedNames = [
518
+ ...Object.keys(process.env),
519
+ ...Object.keys(credentialEnv),
520
+ 'SSH_ASKPASS',
521
+ 'SSH_AUTH_SOCK',
522
+ 'HTTP_PROXY',
523
+ 'HTTPS_PROXY',
524
+ 'ALL_PROXY',
525
+ 'http_proxy',
526
+ 'https_proxy',
527
+ 'all_proxy',
528
+ ]
529
+ event.args[TYPECLAW_INTERNAL_BASH_WITHHOLD_ENV] = [
530
+ ...new Set([
531
+ ...GH_STORE_AMBIENT_AUTH_KEYS,
532
+ ...inheritedNames.filter(
533
+ (name) => name.startsWith('GIT_') || name.startsWith('SSH_') || /proxy/i.test(name),
534
+ ),
535
+ ]),
536
+ ]
537
+ event.args[TYPECLAW_INTERNAL_BASH_PREPARE] = async () => {
538
+ const prepared = await prepareGithubStorePush(plan)
539
+ if (prepared === null) throw new Error(missingAppAuthForPushReason)
540
+ return {
541
+ command: prepared.command,
542
+ env: prepared.env,
543
+ mount: prepared.mount,
544
+ cleanup: async () => await cleanupPreparedGithubStorePush(prepared.backingGitDir),
545
+ }
546
+ }
547
+ return
548
+ }
549
+ const credentials: GitRepoCredential[] = []
550
+ for (const repoSlug of destinationRepos) {
551
+ const result = await resolveTokenForRepo(repoSlug)
552
+ if (result.kind === 'unavailable') return { block: true, reason: result.reason }
553
+ credentials.push({ repoSlug, token: result.token })
554
+ }
375
555
 
376
556
  // Deliver the token via GIT_ASKPASS (env, never argv/config). The analyzer
377
557
  // already constrained this to a single bare github git command, so the token
@@ -382,26 +562,17 @@ export default definePlugin({
382
562
  // belong in a separate agent (see docs/internals/sandbox.mdx).
383
563
  // Sandboxed bash: the helper must be on a sandbox-visible path (baked /usr),
384
564
  // not the unsandboxed /tmp default the tmpfs would hide.
385
- const askpass = await ensureGitAskPassHelper(resolveSandboxGitAskPassPath())
386
- const existing = event.args[TYPECLAW_INTERNAL_BASH_ENV]
387
- const overlay = existing !== null && typeof existing === 'object' ? (existing as Record<string, string>) : {}
388
- event.args[TYPECLAW_INTERNAL_BASH_ENV] = {
389
- ...overlay,
390
- GIT_ASKPASS: askpass,
391
- TYPECLAW_GIT_TOKEN: result.token,
392
- GIT_TERMINAL_PROMPT: '0',
393
- GIT_CONFIG_COUNT: '4',
394
- GIT_CONFIG_KEY_0: 'core.hooksPath',
395
- GIT_CONFIG_VALUE_0: '/dev/null',
396
- GIT_CONFIG_KEY_1: 'credential.helper',
397
- GIT_CONFIG_VALUE_1: '',
398
- // Both ssh remote spellings fold to https so the askpass credential applies:
399
- // the scp short form (git@github.com:owner/repo) and the ssh:// URL form.
400
- GIT_CONFIG_KEY_2: 'url.https://github.com/.insteadOf',
401
- GIT_CONFIG_VALUE_2: 'git@github.com:',
402
- GIT_CONFIG_KEY_3: 'url.https://github.com/.insteadOf',
403
- GIT_CONFIG_VALUE_3: 'ssh://git@github.com/',
404
- }
565
+ event.args[TYPECLAW_INTERNAL_BASH_ENV] = await buildGitCredentialOverlay(
566
+ credentials,
567
+ event.args[TYPECLAW_INTERNAL_BASH_ENV],
568
+ {
569
+ expectedRemote:
570
+ decision.pushProvenance?.kind === 'configured-remote' ? decision.pushProvenance.remote : undefined,
571
+ pushUrls:
572
+ decision.pushProvenance?.kind === 'configured-remote' ? decision.pushProvenance.pushUrls : undefined,
573
+ trustedEnv: trustedGitTransportEnv,
574
+ },
575
+ )
405
576
  if (decision.rewrittenCommand !== undefined) event.args.command = decision.rewrittenCommand
406
577
  return
407
578
  }
@@ -425,12 +596,39 @@ export default definePlugin({
425
596
  },
426
597
  'tool.after': async (event) => {
427
598
  checkGraphqlAuthNudge({ tool: event.tool, result: event.result })
599
+ const dismissal = pendingDismissals.get(event.callId)
600
+ pendingDismissals.delete(event.callId)
601
+ if (dismissal !== undefined) {
602
+ // Only an AUTHORITATIVELY verified dismissal may latch the round's
603
+ // one-attempt marker. Latching on a failed mutation — or on a
604
+ // succeeded mutation whose verifying read errored, where we cannot
605
+ // tell whether the block cleared — bars every retry AND suppresses
606
+ // carrier failover, stranding the round with all siblings gated
607
+ // forever. Unverified therefore releases the latch so the next
608
+ // attempt can re-read authoritative state.
609
+ let verified = false
610
+ try {
611
+ if (dismissalMutationSucceeded(event.result)) {
612
+ const effective = await resolveEffectiveApproval(dismissal)
613
+ if (effective.ok && effective.effective === 'DISMISSED') {
614
+ recordVerifiedDismissal({
615
+ sessionId: event.sessionId,
616
+ workspace: dismissal.workspace,
617
+ prNumber: dismissal.prNumber,
618
+ })
619
+ verified = true
620
+ }
621
+ }
622
+ } finally {
623
+ releaseGithubReviewRoundDismissal(event.callId, verified)
624
+ }
625
+ }
428
626
  const review = commitReviewIfSucceeded({
429
627
  sessionId: event.sessionId,
430
628
  callId: event.callId,
431
629
  result: event.result,
432
630
  })
433
- await verdictGuard.release({ callId: event.callId, succeeded: review.committed })
631
+ await verdictGuard.release({ callId: event.callId, outcome: review.committed ? 'formal-landed' : 'failed' })
434
632
  // A backstop-recovered verdict had no guard() reservation, so release()
435
633
  // could not arm the lag shield — do it explicitly here so the next
436
634
  // same-commit submission is deduped.
@@ -77,6 +77,11 @@ export type CommitReviewResult = {
77
77
  landedFromResult: DetectedReview | null
78
78
  }
79
79
 
80
+ export function dismissalMutationSucceeded(result: ToolResult): boolean {
81
+ const text = collectText(result.content)
82
+ return !FAILURE_MARKERS.some((marker) => text.includes(marker)) && /"state"\s*:\s*"DISMISSED"/.test(text)
83
+ }
84
+
80
85
  export function commitReviewIfSucceeded(args: {
81
86
  sessionId: string
82
87
  callId: string
@@ -1,29 +1,11 @@
1
1
  import { definePlugin } from '@/plugin'
2
2
 
3
- import {
4
- checkManagedConfigGuard,
5
- checkMemoryTopicsDeleteGuard,
6
- checkNonWorkspaceWriteGuard,
7
- checkSkillAuthoringGuard,
8
- checkUncommittedChangesAdvice,
9
- } from './policy'
3
+ import { checkMemoryTopicsDeleteGuard, checkUncommittedChangesAdvice } from './policy'
10
4
 
11
5
  export default definePlugin({
12
6
  plugin: async () => ({
13
7
  hooks: {
14
8
  'tool.before': async (event, ctx) => {
15
- const managedConfigResult = await checkManagedConfigGuard({
16
- tool: event.tool,
17
- args: event.args,
18
- agentDir: ctx.agentDir,
19
- })
20
- if (managedConfigResult) return managedConfigResult
21
- const skillResult = await checkSkillAuthoringGuard({
22
- tool: event.tool,
23
- args: event.args,
24
- agentDir: ctx.agentDir,
25
- })
26
- if (skillResult) return skillResult
27
9
  const memoryTopicsDeleteResult = checkMemoryTopicsDeleteGuard({
28
10
  tool: event.tool,
29
11
  args: event.args,
@@ -31,12 +13,7 @@ export default definePlugin({
31
13
  origin: event.origin,
32
14
  })
33
15
  if (memoryTopicsDeleteResult) return memoryTopicsDeleteResult
34
- return checkNonWorkspaceWriteGuard({
35
- tool: event.tool,
36
- args: event.args,
37
- agentDir: ctx.agentDir,
38
- origin: event.origin,
39
- })
16
+ return undefined
40
17
  },
41
18
  'tool.after': async (event, ctx) => {
42
19
  await checkUncommittedChangesAdvice({
@@ -0,0 +1,8 @@
1
+ // Keep this module import-free: acknowledgement folding runs during module
2
+ // evaluation, and cycles through key owners can throw a temporal-dead-zone ReferenceError.
3
+ export const ACKNOWLEDGE_GUARDS = 'acknowledgeGuards'
4
+ export const GUARD_IMAGE_READ_REDIRECT = 'imageReadRedirect'
5
+ export const GUARD_NON_WORKSPACE_WRITE = 'nonWorkspaceWrite'
6
+ export const GUARD_GLOBAL_INSTALL = 'globalInstall'
7
+ export const GUARD_NON_BUN_PACKAGE_MANAGER = 'nonBunPackageManager'
8
+ export const GUARD_NON_BUN_PACKAGE_RUNNER = 'nonBunPackageRunner'
@@ -1,14 +1,15 @@
1
1
  import { realpath } from 'node:fs/promises'
2
2
  import path from 'node:path'
3
3
 
4
+ import type { InternalGuardResult } from '@/agent/guard-types'
4
5
  import type { SessionOrigin } from '@/agent/session-origin'
5
6
  import { RECOVER_MISSING, realIntendedPath } from '@/path-safety/real-intended-path'
6
7
 
7
- import { ACKNOWLEDGE_GUARDS, type GuardBlock, isGuardAcknowledged } from '../policy'
8
+ import { GUARD_NON_WORKSPACE_WRITE } from '../keys'
8
9
  import { isMemoryTopicsWriteAllowed } from './memory-topics-write'
9
10
  import { isSkillAuthoringAllowed } from './skill-authoring'
10
11
 
11
- export const GUARD_NON_WORKSPACE_WRITE = 'nonWorkspaceWrite'
12
+ export { GUARD_NON_WORKSPACE_WRITE } from '../keys'
12
13
 
13
14
  const AGENT_ROOT_WRITE_ALLOWLIST = new Set([
14
15
  'AGENTS.md',
@@ -33,7 +34,7 @@ export async function checkNonWorkspaceWriteGuard(options: {
33
34
  args: Record<string, unknown>
34
35
  agentDir: string
35
36
  origin?: SessionOrigin
36
- }): Promise<GuardBlock | undefined> {
37
+ }): Promise<InternalGuardResult> {
37
38
  const { tool, args, agentDir, origin } = options
38
39
  if (tool !== 'write' && tool !== 'edit') return undefined
39
40
 
@@ -50,7 +51,7 @@ export async function checkNonWorkspaceWriteGuard(options: {
50
51
  ])
51
52
  if (await isOperatorOwnedPackageManifest(agentDir, targetPath, realTargetPath)) {
52
53
  return {
53
- block: true,
54
+ kind: 'block',
54
55
  reason: `Guard \`${GUARD_NON_WORKSPACE_WRITE}\` blocked a model write to operator-owned package manifest ${targetPath}.`,
55
56
  }
56
57
  }
@@ -68,14 +69,12 @@ export async function checkNonWorkspaceWriteGuard(options: {
68
69
  // and a `/tmp/link -> /agent/.env`) and must not land inside the agent dir
69
70
  // (a container/test agent dir can itself sit under /tmp).
70
71
  if (isTmpScratchWrite(rawPath, realTargetPath, realAgentDir, realTmpRoot)) return undefined
71
- if (isGuardAcknowledged(args, GUARD_NON_WORKSPACE_WRITE)) return undefined
72
-
73
72
  return {
74
- block: true,
73
+ kind: 'acknowledgement-required',
75
74
  reason: [
76
75
  `Guard \`${GUARD_NON_WORKSPACE_WRITE}\` blocked ${tool} outside the workspace: ${targetPath}.`,
77
76
  `The free-write zone is ${workspacePath}.`,
78
- `Retry with \`${ACKNOWLEDGE_GUARDS}.${GUARD_NON_WORKSPACE_WRITE}: true\` only if this write is intentional.`,
77
+ `Retry with \`acknowledgeGuards.guard.${GUARD_NON_WORKSPACE_WRITE}: true\` only if this write is intentional.`,
79
78
  ].join(' '),
80
79
  }
81
80
  }
@@ -1,13 +1,7 @@
1
- export const ACKNOWLEDGE_GUARDS = 'acknowledgeGuards'
1
+ export { ACKNOWLEDGE_GUARDS } from './keys'
2
2
 
3
3
  export type GuardBlock = { block: true; reason: string }
4
4
 
5
- export function isGuardAcknowledged(args: Record<string, unknown>, guard: string): boolean {
6
- const acknowledgements = args[ACKNOWLEDGE_GUARDS]
7
- if (!acknowledgements || typeof acknowledgements !== 'object') return false
8
- return (acknowledgements as Record<string, unknown>)[guard] === true
9
- }
10
-
11
5
  export { GUARD_MANAGED_CONFIG, checkManagedConfigGuard } from './policies/managed-config'
12
6
  export { GUARD_NON_WORKSPACE_WRITE, checkNonWorkspaceWriteGuard } from './policies/non-workspace-write'
13
7
  export {