typeclaw 0.48.13 → 0.49.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.
- package/package.json +5 -5
- package/scripts/dump-system-prompt.ts +52 -110
- package/src/agent/index.ts +144 -72
- package/src/agent/live-sessions.ts +2 -2
- package/src/agent/live-subagents.ts +1 -0
- package/src/agent/plugin-tools.ts +53 -11
- package/src/agent/prompt-cache-key.ts +42 -0
- package/src/agent/provider-error.ts +179 -10
- package/src/agent/restart-handoff/index.ts +7 -14
- package/src/agent/reviewer-activity.ts +68 -0
- package/src/agent/session-origin.ts +33 -0
- package/src/agent/subagents.ts +13 -1
- package/src/agent/system-prompt.ts +68 -202
- package/src/agent/todo/continuation-policy.ts +12 -4
- package/src/agent/tool-file-safety.ts +113 -14
- package/src/agent/tool-not-found-nudge.ts +1 -1
- package/src/agent/tools/channel-history-render.ts +2 -1
- package/src/agent/tools/channel-reply.ts +23 -5
- package/src/agent/tools/channel-send.ts +49 -7
- package/src/agent/tools/curl-impersonate.ts +11 -2
- package/src/agent/tools/post-github-review.ts +77 -15
- package/src/agent/tools/skip-response.ts +2 -2
- package/src/agent/tools/spawn-subagent.ts +163 -12
- package/src/agent/tools/subagent-output.ts +8 -0
- package/src/bundled-plugins/backup/README.md +10 -9
- package/src/bundled-plugins/backup/runner.ts +140 -58
- package/src/bundled-plugins/backup/subagents.ts +58 -26
- package/src/bundled-plugins/github-cli-auth/gh-command.ts +34 -2
- package/src/bundled-plugins/github-cli-auth/granted-push.ts +135 -0
- package/src/bundled-plugins/github-cli-auth/index.ts +83 -11
- package/src/bundled-plugins/github-cli-auth/review-account.ts +23 -0
- package/src/bundled-plugins/github-cli-auth/review-checkout.ts +9 -2
- package/src/bundled-plugins/github-cli-auth/review-recorder.ts +45 -7
- package/src/bundled-plugins/operator/operator.ts +15 -4
- package/src/bundled-plugins/reviewer/skills/code-review.ts +1 -1
- package/src/bundled-plugins/security/index.ts +50 -2
- package/src/bundled-plugins/security/policies/git-exfil.ts +24 -12
- package/src/channels/adapters/discord-bot-reactions.ts +18 -0
- package/src/channels/adapters/discord-bot.ts +122 -67
- package/src/channels/adapters/discord-reactions.ts +18 -0
- package/src/channels/adapters/discord.ts +114 -8
- package/src/channels/adapters/github/inbound.ts +103 -8
- package/src/channels/adapters/github/index.ts +251 -19
- package/src/channels/adapters/github/last-alive.ts +27 -0
- package/src/channels/adapters/github/outbound.ts +54 -18
- package/src/channels/adapters/github/pending-review-store.ts +141 -0
- package/src/channels/adapters/github/permission-guidance.ts +1 -0
- package/src/channels/adapters/github/reactions.ts +100 -0
- package/src/channels/adapters/github/reconcile-cooldown-store.ts +197 -67
- package/src/channels/adapters/github/reconcile-open-prs.ts +418 -33
- package/src/channels/adapters/github/recovery.ts +106 -0
- package/src/channels/adapters/github/review-check.ts +510 -0
- package/src/channels/adapters/github/review-submitter.ts +34 -2
- package/src/channels/adapters/instagram.ts +32 -14
- package/src/channels/adapters/kakaotalk.ts +22 -7
- package/src/channels/adapters/line.ts +18 -3
- package/src/channels/adapters/outbound-account.ts +20 -0
- package/src/channels/adapters/own-reactions.ts +66 -0
- package/src/channels/adapters/recovery-correlation.ts +214 -0
- package/src/channels/adapters/slack-bot-classify.ts +18 -11
- package/src/channels/adapters/slack-bot-dedupe.ts +111 -28
- package/src/channels/adapters/slack-bot-reactions.ts +18 -0
- package/src/channels/adapters/slack-bot.ts +125 -57
- package/src/channels/adapters/slack-classify.ts +25 -4
- package/src/channels/adapters/slack-inbound-revision.ts +96 -0
- package/src/channels/adapters/slack-reactions.ts +18 -0
- package/src/channels/adapters/slack-thread-ts.ts +6 -0
- package/src/channels/adapters/slack.ts +48 -3
- package/src/channels/adapters/teams.ts +14 -4
- package/src/channels/adapters/telegram-bot.ts +56 -10
- package/src/channels/adapters/webex-bot.ts +12 -2
- package/src/channels/adapters/webex.ts +12 -2
- package/src/channels/background-handoff.ts +434 -0
- package/src/channels/background-obligations.ts +893 -0
- package/src/channels/continuity-types.ts +271 -0
- package/src/channels/github-review-check.ts +598 -0
- package/src/channels/github-review-turn-ledger.ts +102 -28
- package/src/channels/github-review-verdict-coordinator.ts +72 -12
- package/src/channels/github-token-bridge.ts +11 -5
- package/src/channels/inbound-journal.ts +1738 -0
- package/src/channels/index.ts +6 -1
- package/src/channels/manager.ts +17 -7
- package/src/channels/recovery-dispatcher.ts +264 -0
- package/src/channels/recovery-notice.ts +94 -0
- package/src/channels/recovery-outbox.ts +459 -0
- package/src/channels/router.ts +2539 -615
- package/src/channels/schema.ts +8 -1
- package/src/channels/subagent-completion-bridge.ts +17 -14
- package/src/channels/types.ts +121 -16
- package/src/channels/waiting-reactions.ts +664 -0
- package/src/cli/compose.ts +7 -4
- package/src/cli/hostd.ts +49 -3
- package/src/cli/inspect.ts +11 -14
- package/src/coding-agent/broker-body.ts +38 -0
- package/src/coding-agent/broker.ts +290 -0
- package/src/coding-agent/claude.ts +95 -0
- package/src/coding-agent/codex.ts +104 -0
- package/src/coding-agent/index.ts +506 -0
- package/src/coding-agent/omo-state.ts +69 -0
- package/src/coding-agent/omo-stream.ts +98 -0
- package/src/coding-agent/omo.ts +192 -0
- package/src/coding-agent/runner.ts +263 -0
- package/src/coding-agent/tool.ts +62 -0
- package/src/coding-agent/worktree.ts +355 -0
- package/src/compose/restart.ts +10 -3
- package/src/compose/start.ts +20 -3
- package/src/config/config.ts +10 -3
- package/src/config/providers.ts +12 -9
- package/src/container/exit-reason.ts +44 -0
- package/src/container/index.ts +5 -0
- package/src/container/log-archive.ts +51 -13
- package/src/container/memory-limit.ts +1 -1
- package/src/container/memory-oversubscription.ts +36 -6
- package/src/container/oom-events.ts +86 -0
- package/src/container/restart.ts +2 -0
- package/src/container/shared.ts +8 -1
- package/src/container/start.ts +25 -13
- package/src/container/stop.ts +6 -2
- package/src/container/tool-oom-priority.ts +32 -0
- package/src/cron/consumer.ts +10 -4
- package/src/cron/reloadable.ts +23 -2
- package/src/doctor/checks.ts +14 -2
- package/src/hostd/daemon.ts +20 -10
- package/src/hostd/spawn.ts +106 -5
- package/src/hostd/version.ts +20 -0
- package/src/hostd/watchdog.ts +241 -0
- package/src/init/dockerfile.ts +57 -592
- package/src/init/index.ts +2 -3
- package/src/mcp/client.ts +3 -1
- package/src/operations/classify-tool-outcome.ts +45 -1
- package/src/operations/incidents.ts +10 -5
- package/src/plugin/core-tool-names.ts +1 -1
- package/src/plugin/define.ts +1 -0
- package/src/plugin/index.ts +1 -0
- package/src/plugin/types.ts +6 -1
- package/src/run/background-handoff-boot.ts +86 -0
- package/src/run/index.ts +83 -83
- package/src/run/resource-sample.ts +19 -0
- package/src/sandbox/build.ts +4 -0
- package/src/sandbox/coding-agent.ts +214 -0
- package/src/sandbox/policy.ts +1 -0
- package/src/sandbox/runtime-private.ts +4 -1
- package/src/secrets/coding-agent-auth.ts +97 -0
- package/src/secrets/index.ts +0 -16
- package/src/server/command-runner.ts +6 -2
- package/src/server/index.ts +101 -40
- package/src/skills/typeclaw-channel-github/SKILL.md +7 -5
- package/src/skills/typeclaw-claude-code/SKILL.md +25 -260
- package/src/skills/typeclaw-claude-code/references/auth-flow.md +7 -23
- package/src/skills/typeclaw-claude-code/references/headless-sessions.md +11 -0
- package/src/skills/typeclaw-claude-code/references/results-and-worktrees.md +13 -0
- package/src/skills/typeclaw-codex-cli/SKILL.md +35 -270
- package/src/skills/typeclaw-codex-cli/references/auth-flow.md +13 -20
- package/src/skills/typeclaw-codex-cli/references/headless-sessions.md +26 -0
- package/src/skills/typeclaw-codex-cli/references/results-and-worktrees.md +28 -0
- package/src/skills/typeclaw-config/SKILL.md +21 -21
- package/src/skills/typeclaw-config/references/dockerfile.md +14 -13
- package/src/skills/typeclaw-cron/SKILL.md +1 -1
- package/src/skills/typeclaw-github-contributing/SKILL.md +2 -2
- package/src/skills/typeclaw-memory/SKILL.md +3 -3
- package/src/skills/typeclaw-omo-cli/SKILL.md +52 -0
- package/src/skills/typeclaw-omo-cli/references/auth-flow.md +11 -0
- package/src/skills/typeclaw-omo-cli/references/headless-sessions.md +11 -0
- package/src/skills/typeclaw-omo-cli/references/results-and-worktrees.md +23 -0
- package/src/skills/typeclaw-plugins/SKILL.md +15 -15
- package/src/skills/typeclaw-skills/SKILL.md +19 -2
- package/src/skills/typeclaw-troubleshooting/SKILL.md +15 -2
- package/typeclaw.schema.json +12 -1
- package/src/secrets/claude-credentials-json.ts +0 -129
- package/src/secrets/codex-auth-json.ts +0 -102
- package/src/secrets/export-claude-credentials-file.ts +0 -270
- package/src/secrets/export-codex-auth-file.ts +0 -250
- package/src/skills/typeclaw-claude-code/references/stop-hook.md +0 -101
- package/src/skills/typeclaw-claude-code/references/tmux-driving.md +0 -243
- package/src/skills/typeclaw-codex-cli/references/stop-hook.md +0 -92
- package/src/skills/typeclaw-codex-cli/references/tmux-driving.md +0 -239
|
@@ -11,15 +11,17 @@ import {
|
|
|
11
11
|
guardGithubReviewRoundDismissal,
|
|
12
12
|
releaseGithubReviewRoundDismissal,
|
|
13
13
|
} from '@/channels/github-review-verdict-coordinator'
|
|
14
|
+
import type { GithubTokenCredential } from '@/channels/github-token-bridge'
|
|
14
15
|
import { hasEnvKey, readEnvFile } from '@/init/env-file'
|
|
15
16
|
import { CORE_PERMISSIONS } from '@/permissions/builtins'
|
|
16
|
-
import { definePlugin } from '@/plugin'
|
|
17
|
+
import { definePlugin, type ToolBeforeEvent } from '@/plugin'
|
|
17
18
|
|
|
18
19
|
import { createGithubEffectiveApprovalResolver, createGithubHeadShaResolver } from './effective-approval'
|
|
19
20
|
import {
|
|
20
21
|
analyzeGhCommand,
|
|
21
22
|
canInjectPatIntoPassThroughGh,
|
|
22
23
|
effectiveGhTokensForAuthenticatedUserEndpoint,
|
|
24
|
+
effectiveGhTokensForCommand,
|
|
23
25
|
usesGhApiGraphqlEndpoint,
|
|
24
26
|
} from './gh-command'
|
|
25
27
|
import { detectReviewDismissal } from './gh-review-detect'
|
|
@@ -38,8 +40,17 @@ import {
|
|
|
38
40
|
resolveGhDefaultRepoFromCwd,
|
|
39
41
|
} from './git-command'
|
|
40
42
|
import { buildGitCredentialEnv, type GitRepoCredential } from './git-credential-env'
|
|
43
|
+
import { matchesGrantedPush, takeGrantedPush } from './granted-push'
|
|
41
44
|
import { checkGraphqlAuthNudge } from './graphql-auth-nudge'
|
|
42
|
-
import {
|
|
45
|
+
import { verifyReviewTokenAccount } from './review-account'
|
|
46
|
+
import {
|
|
47
|
+
capturedReviewAccountIdentity,
|
|
48
|
+
commitReviewIfSucceeded,
|
|
49
|
+
discardReviewCommand,
|
|
50
|
+
dismissalMutationSucceeded,
|
|
51
|
+
noteReviewCommand,
|
|
52
|
+
type NoteReviewResult,
|
|
53
|
+
} from './review-recorder'
|
|
43
54
|
import { classifyGhToken, shouldMintAppToken } from './token-class'
|
|
44
55
|
|
|
45
56
|
const REPO_LIST_RE = /\bgh\s+repo\s+list\b/
|
|
@@ -76,6 +87,7 @@ export default definePlugin({
|
|
|
76
87
|
const resolveTokenForRepo = ctx.github.resolveTokenForRepo
|
|
77
88
|
const hasAppTokenResolver = ctx.github.hasAppTokenResolver
|
|
78
89
|
const trustedGitTransportEnv: NodeJS.ProcessEnv = { ...process.env }
|
|
90
|
+
const reviewCredentials = new Map<string, GithubTokenCredential>()
|
|
79
91
|
|
|
80
92
|
// Every model-driven bash masks the canonical credential files. A role may
|
|
81
93
|
// still USE a PAT through this runtime-owned overlay, which injects one
|
|
@@ -176,6 +188,8 @@ export default definePlugin({
|
|
|
176
188
|
// names both remedies instead of guessing one. The closing lines exist because
|
|
177
189
|
// a mute refusal here is indistinguishable from broken auth, so the caller
|
|
178
190
|
// retries credential-management commands that are themselves blocked.
|
|
191
|
+
const grantedPushMismatchReason =
|
|
192
|
+
'This push was allowed for one configured channels.github.repos destination, but the credential broker resolved a different one (the remote may have changed). Re-run the push; if it repeats, check the remote with `git remote -v`.'
|
|
179
193
|
const missingAppAuthForPushReason =
|
|
180
194
|
'Pushing to github.com needs an eligible credential and validated destination, and TypeClaw has nothing it can give this git command. ' +
|
|
181
195
|
'Operator remedy: declare `GH_TOKEN` in the agent `.env` and restart, configure GitHub App auth under ' +
|
|
@@ -226,13 +240,17 @@ export default definePlugin({
|
|
|
226
240
|
selfLogin: ctx.github.getAppSelfLogin ?? (() => null),
|
|
227
241
|
isAppAuth: hasAppTokenResolver,
|
|
228
242
|
})
|
|
243
|
+
const resolveHeadSha = createGithubHeadShaResolver({ resolveToken })
|
|
229
244
|
configureReviewVerdictCoordinator({
|
|
230
245
|
resolveEffectiveApproval,
|
|
231
|
-
resolveHeadSha
|
|
246
|
+
resolveHeadSha,
|
|
232
247
|
logger: ctx.logger,
|
|
233
248
|
})
|
|
234
249
|
const verdictGuard = createSharedReviewVerdictGuard()
|
|
235
|
-
const pendingDismissals = new Map<
|
|
250
|
+
const pendingDismissals = new Map<
|
|
251
|
+
string,
|
|
252
|
+
{ workspace: string; prNumber: number; commitSha?: string; startedAt: number }
|
|
253
|
+
>()
|
|
236
254
|
|
|
237
255
|
type HookResult = void | { block: true; reason: string }
|
|
238
256
|
|
|
@@ -278,7 +296,7 @@ export default definePlugin({
|
|
|
278
296
|
// 'fall-through' means "not a repo-targeting gh command" so the caller can
|
|
279
297
|
// try the git path on the same command (e.g. `git ... # gh` substrings).
|
|
280
298
|
const handleGhCommand = async (params: {
|
|
281
|
-
event:
|
|
299
|
+
event: Pick<ToolBeforeEvent, 'callId' | 'args' | 'origin' | 'sessionId'>
|
|
282
300
|
command: string
|
|
283
301
|
}): Promise<HookResult | 'fall-through'> => {
|
|
284
302
|
const { event, command } = params
|
|
@@ -327,10 +345,12 @@ export default definePlugin({
|
|
|
327
345
|
if (leaseClaimed) await verdictGuard.release({ callId: event.callId, outcome: 'failed' })
|
|
328
346
|
if (dismissalLeaseClaimed) releaseGithubReviewRoundDismissal(event.callId, false)
|
|
329
347
|
pendingDismissals.delete(event.callId)
|
|
348
|
+
discardReviewCommand(event.callId)
|
|
330
349
|
return block
|
|
331
350
|
}
|
|
332
351
|
const dismissal = detectReviewDismissal(command)
|
|
333
352
|
if (dismissal !== null) {
|
|
353
|
+
const startedAt = Date.now()
|
|
334
354
|
const block = await guardGithubReviewRoundDismissal({
|
|
335
355
|
callId: event.callId,
|
|
336
356
|
workspace: dismissal.workspace,
|
|
@@ -341,9 +361,21 @@ export default definePlugin({
|
|
|
341
361
|
})
|
|
342
362
|
if (block !== null) return block
|
|
343
363
|
dismissalLeaseClaimed = event.origin?.kind === 'channel' && event.origin.githubReviewRound !== undefined
|
|
344
|
-
pendingDismissals.set(event.callId,
|
|
364
|
+
pendingDismissals.set(event.callId, {
|
|
365
|
+
...dismissal,
|
|
366
|
+
startedAt,
|
|
367
|
+
commitSha:
|
|
368
|
+
event.origin?.kind === 'channel' && event.origin.githubReviewRound !== undefined
|
|
369
|
+
? event.origin.githubReviewRound.headSha
|
|
370
|
+
: ((await resolveHeadSha(dismissal)) ?? undefined),
|
|
371
|
+
})
|
|
372
|
+
}
|
|
373
|
+
let review: NoteReviewResult
|
|
374
|
+
try {
|
|
375
|
+
review = await noteReviewCommand({ callId: event.callId, command, sessionId: event.sessionId })
|
|
376
|
+
} catch (error) {
|
|
377
|
+
return await blockAfterLease({ block: true, reason: `Cannot capture review coverage: ${String(error)}` })
|
|
345
378
|
}
|
|
346
|
-
const review = await noteReviewCommand({ callId: event.callId, command })
|
|
347
379
|
if (review.detected !== null) {
|
|
348
380
|
const block = await verdictGuard.guard({
|
|
349
381
|
callId: event.callId,
|
|
@@ -354,7 +386,7 @@ export default definePlugin({
|
|
|
354
386
|
? { round: event.origin.githubReviewRound, thread: event.origin.thread }
|
|
355
387
|
: {}),
|
|
356
388
|
})
|
|
357
|
-
if (block !== null) return block
|
|
389
|
+
if (block !== null) return blockAfterLease(block)
|
|
358
390
|
leaseClaimed = true
|
|
359
391
|
}
|
|
360
392
|
if (review.dump !== null) return blockAfterLease(review.dump)
|
|
@@ -471,6 +503,7 @@ export default definePlugin({
|
|
|
471
503
|
|
|
472
504
|
const result = await resolveTokenForRepo(decision.repoSlug)
|
|
473
505
|
if (result.kind === 'unavailable') return blockAfterLease({ block: true, reason: result.reason })
|
|
506
|
+
reviewCredentials.set(event.callId, result)
|
|
474
507
|
// Inject via the internal env overlay (delivered to the spawn / bwrap
|
|
475
508
|
// --setenv by the bash wrapper) so the token never enters the command
|
|
476
509
|
// string, where it could leak through logs or later hooks. When the repo
|
|
@@ -495,6 +528,10 @@ export default definePlugin({
|
|
|
495
528
|
cwd: agentDir,
|
|
496
529
|
resolvers: createSessionTmpGitResolvers(agentDir, sessionId),
|
|
497
530
|
})
|
|
531
|
+
const grantedPush = takeGrantedPush(event.callId)
|
|
532
|
+
if (grantedPush !== undefined && (!hasAppTokenResolver() || !matchesGrantedPush(decision, grantedPush))) {
|
|
533
|
+
return { block: true, reason: grantedPushMismatchReason }
|
|
534
|
+
}
|
|
498
535
|
if (decision.kind === 'pass-through') return
|
|
499
536
|
if (decision.kind === 'block') return { block: true, reason: decision.reason }
|
|
500
537
|
|
|
@@ -613,7 +650,8 @@ export default definePlugin({
|
|
|
613
650
|
trustedEnv: trustedGitTransportEnv,
|
|
614
651
|
},
|
|
615
652
|
)
|
|
616
|
-
if (
|
|
653
|
+
if (grantedPush !== undefined) event.args.command = grantedPush.command
|
|
654
|
+
else if (decision.rewrittenCommand !== undefined) event.args.command = decision.rewrittenCommand
|
|
617
655
|
return
|
|
618
656
|
}
|
|
619
657
|
|
|
@@ -626,6 +664,38 @@ export default definePlugin({
|
|
|
626
664
|
|
|
627
665
|
if (command.includes('gh')) {
|
|
628
666
|
const ghResult = await handleGhCommand({ event, command })
|
|
667
|
+
const minted = reviewCredentials.get(event.callId)
|
|
668
|
+
reviewCredentials.delete(event.callId)
|
|
669
|
+
const expectedAccountIdentity = capturedReviewAccountIdentity(event.callId)
|
|
670
|
+
const blocked = typeof ghResult === 'object' && ghResult?.block === true
|
|
671
|
+
if (!blocked && expectedAccountIdentity !== undefined) {
|
|
672
|
+
const inherited = sandboxInheritedGhToken()
|
|
673
|
+
const rawOverlay = event.args[TYPECLAW_INTERNAL_BASH_ENV]
|
|
674
|
+
const overlay =
|
|
675
|
+
rawOverlay !== null && typeof rawOverlay === 'object' ? (rawOverlay as Record<string, string>) : {}
|
|
676
|
+
const tokens = effectiveGhTokensForCommand(String(event.args.command), {
|
|
677
|
+
...(inherited !== undefined ? { [inherited.envName]: inherited.value } : {}),
|
|
678
|
+
...overlay,
|
|
679
|
+
})
|
|
680
|
+
try {
|
|
681
|
+
if (tokens.length === 0) throw new Error('No authenticated review invocation')
|
|
682
|
+
for (const token of tokens) {
|
|
683
|
+
if (
|
|
684
|
+
!(await verifyReviewTokenAccount({
|
|
685
|
+
token,
|
|
686
|
+
expectedAccountIdentity,
|
|
687
|
+
...(minted !== undefined ? { minted } : {}),
|
|
688
|
+
}))
|
|
689
|
+
) {
|
|
690
|
+
throw new Error('original GitHub review account identity changed')
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
} catch (error) {
|
|
694
|
+
discardReviewCommand(event.callId)
|
|
695
|
+
await verdictGuard.release({ callId: event.callId, outcome: 'failed' })
|
|
696
|
+
return { block: true, reason: `Cannot authorize review account: ${String(error)}` }
|
|
697
|
+
}
|
|
698
|
+
}
|
|
629
699
|
if (ghResult !== 'fall-through') return ghResult
|
|
630
700
|
}
|
|
631
701
|
|
|
@@ -651,10 +721,12 @@ export default definePlugin({
|
|
|
651
721
|
if (dismissalMutationSucceeded(event.result)) {
|
|
652
722
|
const effective = await resolveEffectiveApproval(dismissal)
|
|
653
723
|
if (effective.ok && effective.effective === 'DISMISSED') {
|
|
654
|
-
recordVerifiedDismissal({
|
|
724
|
+
await recordVerifiedDismissal({
|
|
655
725
|
sessionId: event.sessionId,
|
|
656
726
|
workspace: dismissal.workspace,
|
|
657
727
|
prNumber: dismissal.prNumber,
|
|
728
|
+
commitSha: dismissal.commitSha,
|
|
729
|
+
startedAt: dismissal.startedAt,
|
|
658
730
|
})
|
|
659
731
|
verified = true
|
|
660
732
|
}
|
|
@@ -663,7 +735,7 @@ export default definePlugin({
|
|
|
663
735
|
releaseGithubReviewRoundDismissal(event.callId, verified)
|
|
664
736
|
}
|
|
665
737
|
}
|
|
666
|
-
const review = commitReviewIfSucceeded({
|
|
738
|
+
const review = await commitReviewIfSucceeded({
|
|
667
739
|
sessionId: event.sessionId,
|
|
668
740
|
callId: event.callId,
|
|
669
741
|
result: event.result,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { GITHUB_API_BASE, githubJsonHeaders } from '@/channels/adapters/github/auth-pat'
|
|
2
|
+
import type { GithubTokenCredential } from '@/channels/github-token-bridge'
|
|
3
|
+
|
|
4
|
+
export type ReviewAccountFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>
|
|
5
|
+
export async function verifyReviewTokenAccount(options: {
|
|
6
|
+
token: string | undefined
|
|
7
|
+
expectedAccountIdentity: string
|
|
8
|
+
minted?: GithubTokenCredential
|
|
9
|
+
fetchImpl?: ReviewAccountFetch
|
|
10
|
+
}): Promise<boolean> {
|
|
11
|
+
if (!options.token) return false
|
|
12
|
+
if (options.minted?.token === options.token && options.minted.accountIdentity !== undefined) {
|
|
13
|
+
return options.minted.accountIdentity === options.expectedAccountIdentity
|
|
14
|
+
}
|
|
15
|
+
if (options.token.startsWith('ghs_')) return false
|
|
16
|
+
const response = await (options.fetchImpl ?? fetch)(`${GITHUB_API_BASE}/user`, {
|
|
17
|
+
headers: githubJsonHeaders(options.token),
|
|
18
|
+
signal: AbortSignal.timeout(10_000),
|
|
19
|
+
})
|
|
20
|
+
if (!response.ok) return false
|
|
21
|
+
const user = (await response.json()) as { id?: unknown }
|
|
22
|
+
return Number.isSafeInteger(user.id) && Number(user.id) > 0 && `github:${user.id}` === options.expectedAccountIdentity
|
|
23
|
+
}
|
|
@@ -22,6 +22,7 @@ type GithubFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Res
|
|
|
22
22
|
export async function prepareReviewerCheckout(options: {
|
|
23
23
|
repoSlug: string
|
|
24
24
|
headSha: string
|
|
25
|
+
baseSha?: string
|
|
25
26
|
sessionId: string
|
|
26
27
|
resolveTokenForRepo: ResolveGithubTokenForRepo
|
|
27
28
|
fetchImpl?: GithubFetch
|
|
@@ -30,6 +31,8 @@ export async function prepareReviewerCheckout(options: {
|
|
|
30
31
|
}): Promise<{ path: string; repoSlug: string; headSha: string }> {
|
|
31
32
|
if (!REPO_SLUG.test(options.repoSlug)) throw new Error('repository must be one owner/repo slug')
|
|
32
33
|
if (!FULL_SHA.test(options.headSha)) throw new Error('headSha must be a full 40-character commit SHA')
|
|
34
|
+
if (options.baseSha !== undefined && !FULL_SHA.test(options.baseSha))
|
|
35
|
+
throw new Error('baseSha must be a full 40-character commit SHA')
|
|
33
36
|
const tokenResult = await options.resolveTokenForRepo(options.repoSlug)
|
|
34
37
|
if (tokenResult.kind !== 'token') throw new Error(tokenResult.reason)
|
|
35
38
|
const token = tokenResult.token
|
|
@@ -61,6 +64,9 @@ export async function prepareReviewerCheckout(options: {
|
|
|
61
64
|
'--depth=1',
|
|
62
65
|
`https://github.com/${options.repoSlug}.git`,
|
|
63
66
|
options.headSha,
|
|
67
|
+
// Without the base commit, `git diff <base> <head>` fails with "bad
|
|
68
|
+
// object" and the reviewer falls back to truncated per-file API patches.
|
|
69
|
+
...(options.baseSha !== undefined ? [options.baseSha] : []),
|
|
64
70
|
],
|
|
65
71
|
{ env: { ...baseEnv, GIT_ASKPASS: askPass, TYPECLAW_GIT_TOKEN: token } },
|
|
66
72
|
)
|
|
@@ -99,19 +105,20 @@ export function createReviewerCheckoutTool(resolveTokenForRepo: ResolveGithubTok
|
|
|
99
105
|
return defineTool({
|
|
100
106
|
description:
|
|
101
107
|
'Prepare a runtime-owned token-safe scratch checkout of one allowlisted GitHub repository at an exact full commit SHA.',
|
|
102
|
-
parameters: z.object({ repoSlug: z.string(), headSha: z.string() }),
|
|
108
|
+
parameters: z.object({ repoSlug: z.string(), headSha: z.string(), baseSha: z.string().optional() }),
|
|
103
109
|
// `repoSlug` ("owner/repo") and `headSha` (40-hex) are remote GitHub
|
|
104
110
|
// coordinates, never local paths — repoSlug is only ever interpolated into
|
|
105
111
|
// `https://github.com/<slug>.git` and prepareReviewerCheckout rejects
|
|
106
112
|
// anything not matching /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/. Declared so the
|
|
107
113
|
// required "/" in a slug isn't misread as a path separator. Scoped to THIS
|
|
108
114
|
// tool: an undeclared reader passing a slug-shaped value still fails closed.
|
|
109
|
-
fileOperands: { nonFile: ['repoSlug', 'headSha'] },
|
|
115
|
+
fileOperands: { nonFile: ['repoSlug', 'headSha', 'baseSha'] },
|
|
110
116
|
async execute(args, ctx) {
|
|
111
117
|
try {
|
|
112
118
|
const receipt = await prepareReviewerCheckout({
|
|
113
119
|
repoSlug: args.repoSlug,
|
|
114
120
|
headSha: args.headSha,
|
|
121
|
+
...(args.baseSha !== undefined ? { baseSha: args.baseSha } : {}),
|
|
115
122
|
sessionId: ctx.sessionId,
|
|
116
123
|
resolveTokenForRepo,
|
|
117
124
|
})
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
captureReviewResultCoverage,
|
|
5
|
+
recordReview,
|
|
6
|
+
recordReviewOutput,
|
|
7
|
+
type ReviewResultCoverage,
|
|
8
|
+
} from '@/channels/github-review-turn-ledger'
|
|
4
9
|
import type { ContentPart, ToolResult } from '@/plugin'
|
|
5
10
|
|
|
6
11
|
import {
|
|
@@ -35,6 +40,18 @@ const submissionAttempts = new Map<string, ReviewSubmissionAttempt>()
|
|
|
35
40
|
// credited to the false-receipt ledger via recordReview (which also fans to the
|
|
36
41
|
// output observer), so only non-verdict COMMENTs need their own output credit.
|
|
37
42
|
const pendingCommentOutput = new Map<string, DetectedReviewOutput>()
|
|
43
|
+
const pendingCoverage = new Map<string, ReviewResultCoverage>()
|
|
44
|
+
|
|
45
|
+
export function capturedReviewAccountIdentity(callId: string): string | undefined {
|
|
46
|
+
return pendingCoverage.get(callId)?.expectedAccountIdentity
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function discardReviewCommand(callId: string): void {
|
|
50
|
+
pending.delete(callId)
|
|
51
|
+
pendingCommentOutput.delete(callId)
|
|
52
|
+
submissionAttempts.delete(callId)
|
|
53
|
+
pendingCoverage.delete(callId)
|
|
54
|
+
}
|
|
38
55
|
|
|
39
56
|
const MAX_INPUT_BYTES = 1_000_000
|
|
40
57
|
|
|
@@ -43,7 +60,12 @@ export type NoteReviewResult = {
|
|
|
43
60
|
detected: DetectedReview | null
|
|
44
61
|
}
|
|
45
62
|
|
|
46
|
-
export async function noteReviewCommand(args: {
|
|
63
|
+
export async function noteReviewCommand(args: {
|
|
64
|
+
callId: string
|
|
65
|
+
command: string
|
|
66
|
+
sessionId?: string
|
|
67
|
+
}): Promise<NoteReviewResult> {
|
|
68
|
+
discardReviewCommand(args.callId)
|
|
47
69
|
const inputFileContents = await readInputFile(args.command)
|
|
48
70
|
const detected = detectReviewSubmission({ command: args.command, inputFileContents })
|
|
49
71
|
if (detected !== null) pending.set(args.callId, detected)
|
|
@@ -65,6 +87,17 @@ export async function noteReviewCommand(args: { callId: string; command: string
|
|
|
65
87
|
if (attempt !== null) submissionAttempts.set(args.callId, attempt)
|
|
66
88
|
}
|
|
67
89
|
}
|
|
90
|
+
if (pending.has(args.callId) || pendingCommentOutput.has(args.callId) || submissionAttempts.has(args.callId)) {
|
|
91
|
+
try {
|
|
92
|
+
pendingCoverage.set(
|
|
93
|
+
args.callId,
|
|
94
|
+
args.sessionId === undefined ? {} : await captureReviewResultCoverage(args.sessionId),
|
|
95
|
+
)
|
|
96
|
+
} catch (error) {
|
|
97
|
+
discardReviewCommand(args.callId)
|
|
98
|
+
throw error
|
|
99
|
+
}
|
|
100
|
+
}
|
|
68
101
|
return { dump: detectReviewDump({ command: args.command, inputFileContents }), detected }
|
|
69
102
|
}
|
|
70
103
|
|
|
@@ -82,21 +115,24 @@ export function dismissalMutationSucceeded(result: ToolResult): boolean {
|
|
|
82
115
|
return !FAILURE_MARKERS.some((marker) => text.includes(marker)) && /"state"\s*:\s*"DISMISSED"/.test(text)
|
|
83
116
|
}
|
|
84
117
|
|
|
85
|
-
export function commitReviewIfSucceeded(args: {
|
|
118
|
+
export async function commitReviewIfSucceeded(args: {
|
|
86
119
|
sessionId: string
|
|
87
120
|
callId: string
|
|
88
121
|
result: ToolResult
|
|
89
|
-
}): CommitReviewResult {
|
|
122
|
+
}): Promise<CommitReviewResult> {
|
|
90
123
|
const text = collectText(args.result.content)
|
|
124
|
+
const coverage = pendingCoverage.get(args.callId) ?? {}
|
|
125
|
+
pendingCoverage.delete(args.callId)
|
|
91
126
|
const detected = pending.get(args.callId)
|
|
92
127
|
if (detected !== undefined) {
|
|
93
128
|
pending.delete(args.callId)
|
|
94
129
|
if (!looksSucceeded(detected, text)) return { committed: false, landedFromResult: null }
|
|
95
|
-
recordReview({
|
|
130
|
+
await recordReview({
|
|
96
131
|
sessionId: args.sessionId,
|
|
97
132
|
workspace: detected.workspace,
|
|
98
133
|
prNumber: detected.prNumber,
|
|
99
134
|
verdict: detected.verdict,
|
|
135
|
+
...coverage,
|
|
100
136
|
})
|
|
101
137
|
return { committed: true, landedFromResult: null }
|
|
102
138
|
}
|
|
@@ -107,11 +143,12 @@ export function commitReviewIfSucceeded(args: {
|
|
|
107
143
|
if (comment !== undefined) {
|
|
108
144
|
pendingCommentOutput.delete(args.callId)
|
|
109
145
|
if (commentReviewSucceeded(text)) {
|
|
110
|
-
recordReviewOutput({
|
|
146
|
+
await recordReviewOutput({
|
|
111
147
|
sessionId: args.sessionId,
|
|
112
148
|
workspace: comment.workspace,
|
|
113
149
|
prNumber: comment.prNumber,
|
|
114
150
|
state: 'COMMENT',
|
|
151
|
+
...coverage,
|
|
115
152
|
})
|
|
116
153
|
}
|
|
117
154
|
return { committed: false, landedFromResult: null }
|
|
@@ -130,11 +167,12 @@ export function commitReviewIfSucceeded(args: {
|
|
|
130
167
|
if (landed.workspace !== attempt.workspace || landed.prNumber !== attempt.prNumber) {
|
|
131
168
|
return { committed: false, landedFromResult: null }
|
|
132
169
|
}
|
|
133
|
-
recordReview({
|
|
170
|
+
await recordReview({
|
|
134
171
|
sessionId: args.sessionId,
|
|
135
172
|
workspace: landed.workspace,
|
|
136
173
|
prNumber: landed.prNumber,
|
|
137
174
|
verdict: landed.verdict,
|
|
175
|
+
...coverage,
|
|
138
176
|
})
|
|
139
177
|
return { committed: true, landedFromResult: landed }
|
|
140
178
|
}
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
bashTool,
|
|
5
|
+
codingAgentTool,
|
|
6
|
+
editTool,
|
|
7
|
+
findTool,
|
|
8
|
+
grepTool,
|
|
9
|
+
lsTool,
|
|
10
|
+
readTool,
|
|
11
|
+
type Subagent,
|
|
12
|
+
writeTool,
|
|
13
|
+
} from '@/plugin'
|
|
4
14
|
|
|
5
15
|
export const OPERATOR_SYSTEM_PROMPT = `You are an operator subagent running inside TypeClaw. Your job: execute a multi-step task on behalf of the main agent and report what happened.
|
|
6
16
|
|
|
@@ -17,6 +27,7 @@ You have a full tool set: read, write, edit, grep, find, ls, bash. You can:
|
|
|
17
27
|
- Modify files (write/edit)
|
|
18
28
|
- Run shell commands with side effects (bash without the read-only restriction)
|
|
19
29
|
- Use any tool available to a normal operator session
|
|
30
|
+
- Delegate Claude Code, Codex, or OmO Native through \`coding_agent\`: one foreground headless run, persistent isolated worktree, explicit task-ID resume. Review its complete diff before applying; never drive credentialed tmux sessions.
|
|
20
31
|
|
|
21
32
|
You CAN delegate, but rarely should:
|
|
22
33
|
- You may \`spawn_subagent\` to hand a clearly separable, context-heavy chunk to a fresh worker — e.g. a focused read-only investigation of a large area you don't want to load into your own context. Spawn only when delegation clearly pays for itself; doing the work yourself is the default. The delegation chain is depth-limited, so a worker you spawn cannot spawn again — keep your own tree flat.
|
|
@@ -67,11 +78,11 @@ export function createOperatorSubagent(): Subagent<OperatorPayload> {
|
|
|
67
78
|
return {
|
|
68
79
|
systemPrompt: OPERATOR_SYSTEM_PROMPT,
|
|
69
80
|
profile: 'default',
|
|
70
|
-
tools: [readTool, grepTool, findTool, lsTool, bashTool, writeTool, editTool],
|
|
81
|
+
tools: [readTool, grepTool, findTool, lsTool, bashTool, writeTool, editTool, codingAgentTool],
|
|
71
82
|
payloadSchema: operatorPayloadSchema,
|
|
72
83
|
visibility: 'public',
|
|
73
84
|
rosterDescription:
|
|
74
|
-
'write-capable: bash-with-side-effects, write, edit — for browser sessions, refactors, deploys, batch ops, and Claude Code
|
|
85
|
+
'write-capable: bash-with-side-effects, write, edit, coding_agent — for browser sessions, refactors, deploys, batch ops, and brokered Claude Code/Codex delegation; runs at YOUR role',
|
|
75
86
|
// No `requiresSpecificPermission`: a subagent inherits `spawnedByRole`, and
|
|
76
87
|
// main sessions are never narrowed to a subset of the builtin tools, so a
|
|
77
88
|
// caller already holds every tool listed above. Gating the spawn bought no
|
|
@@ -84,7 +95,7 @@ export function createOperatorSubagent(): Subagent<OperatorPayload> {
|
|
|
84
95
|
inFlightKey: (payload) => payload?.requestId ?? `anon-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
85
96
|
toolResultBudget: {
|
|
86
97
|
maxTotalBytes: 1_000_000,
|
|
87
|
-
toolNames: ['read', 'grep', 'find', 'ls', 'bash', 'write', 'edit'],
|
|
98
|
+
toolNames: ['read', 'grep', 'find', 'ls', 'bash', 'write', 'edit', 'coding_agent'],
|
|
88
99
|
},
|
|
89
100
|
}
|
|
90
101
|
}
|
|
@@ -35,7 +35,7 @@ gh api "/repos/<owner>/<repo>/contents/<path>?ref=<headSha>" -H "Accept: applica
|
|
|
35
35
|
|
|
36
36
|
That returns the file's raw bytes (no base64, no second stage). For the line numbers your \`location="path:line"\` anchors need, read them off the unified diff you already fetched (\`gh pr diff\` prints the new-side line numbers in its hunk headers, \`@@ -a,b +c,d @@\`), or escalate to Mode 2 where a real \`read\`/\`grep\` gives native line numbers. Fetch each file once and keep its output — do not re-fetch the same file to re-derive a line you already saw.
|
|
37
37
|
|
|
38
|
-
**Mode 2 — scratch checkout (escalate when navigation gets broad).** When navigation gets broad, call \`github_prepare_review_checkout({ repoSlug: "<owner>/<repo>", headSha: "<40-char headSha>" })\` once for initial acquisition. The runtime verifies that exact SHA in the one allowlisted repository and performs the authenticated fetch without exposing its token to model bash.
|
|
38
|
+
**Mode 2 — scratch checkout (escalate when navigation gets broad).** When navigation gets broad, call \`github_prepare_review_checkout({ repoSlug: "<owner>/<repo>", headSha: "<40-char headSha>", baseSha: "<40-char merge base>" })\` once for initial acquisition. Always pass \`baseSha\` so the checkout holds both commits and \`git -C <receipt-path> diff <baseSha> <headSha>\` gives the full untruncated PR diff; without it the base is missing and that diff fails with "bad object". Use the merge base GitHub diffs against (\`gh api /repos/<owner>/<repo>/compare/<baseRefOid>...<headSha> --jq .merge_base_commit.sha\`), not \`baseRefOid\` itself, which can include unrelated base-branch commits. The runtime verifies that exact head SHA in the one allowlisted repository and performs the authenticated fetch without exposing its token to model bash.
|
|
39
39
|
|
|
40
40
|
Then use the returned receipt path exactly with \`read\`, \`grep\`, \`find\`, and read-only \`git\` (\`git -C <receipt-path> log|diff|show|blame|grep|ls-files|cat-file\`) for correct line numbers and zero per-file round-trips. Trust the receipt: never guess, derive, or reconstruct a \`/tmp\` path. If and only if a read-only operation against that exact returned receipt path fails with \`ENOENT\` / \`No such file or directory\`, call the checkout tool one additional time with the same exact repo slug and 40-character head SHA, then use only the new returned receipt. This is a maximum two checkout tool calls; never retry generic command, tool, or provider failures, change coordinates, or recover by guessing a path. If recovery also fails, stop checkout attempts and fall back to remote reads where feasible or return an honest incomplete review. Do not use \`git clone\`, \`git fetch\`, \`git checkout\`, or \`gh pr checkout\` for acquisition.
|
|
41
41
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getConfig } from '@/config'
|
|
2
|
+
import { definePlugin, type PluginContext, type PluginLogger, type ToolBeforeEvent } from '@/plugin'
|
|
2
3
|
import { resolveHiddenPaths } from '@/sandbox'
|
|
3
4
|
|
|
5
|
+
import { analyzeGitCommand, createSessionTmpGitResolvers } from '../github-cli-auth/git-command'
|
|
6
|
+
import { recordGrantedPush, resolveGrantedPush } from '../github-cli-auth/granted-push'
|
|
4
7
|
import { HIGH_TIER_PER_GUARD_PERMISSIONS, SECURITY_PERMISSIONS, SEVERITY_PERMISSION } from './permissions'
|
|
5
8
|
import type { SecurityPermission, SecuritySeverity } from './permissions'
|
|
6
9
|
import { GUARD_CRON_PROMOTION_SEVERITY, checkCronPromotionGuard } from './policies/cron-promotion'
|
|
@@ -9,6 +12,7 @@ import {
|
|
|
9
12
|
GUARD_GIT_REMOTE_TAINTED_SEVERITY,
|
|
10
13
|
checkGitExfilGuard,
|
|
11
14
|
checkGitRemoteTaintedGuard,
|
|
15
|
+
isPushOnlyGitExfilMatch,
|
|
12
16
|
recordGitRemoteTaintIfAny,
|
|
13
17
|
} from './policies/git-exfil'
|
|
14
18
|
import { GUARD_OUTBOUND_SECRET_SEVERITY, checkOutboundSecretGuard } from './policies/outbound-secret-scan'
|
|
@@ -87,6 +91,47 @@ function withPermissionHint(
|
|
|
87
91
|
}
|
|
88
92
|
}
|
|
89
93
|
|
|
94
|
+
type PushGrantOutcome = { kind: 'allow' } | { kind: 'deny'; reason: string } | { kind: 'not-configured' }
|
|
95
|
+
|
|
96
|
+
// Only consulted for a command whose sole gitExfil finding is `git push`. The
|
|
97
|
+
// destination is decided from the broker's resolved remote identity, never
|
|
98
|
+
// from the command string or working-directory path; on allow, the resolved
|
|
99
|
+
// destination is handed to github-cli-auth, which refuses to fund any other.
|
|
100
|
+
async function evaluatePushGrant(
|
|
101
|
+
event: ToolBeforeEvent,
|
|
102
|
+
ctx: Pick<PluginContext, 'agentDir' | 'github'>,
|
|
103
|
+
): Promise<PushGrantOutcome> {
|
|
104
|
+
const command = event.args.command
|
|
105
|
+
if (typeof command !== 'string' || !isPushOnlyGitExfilMatch(command)) return { kind: 'not-configured' }
|
|
106
|
+
const github = getConfig().channels?.github
|
|
107
|
+
if (github === undefined || github.repos.length === 0) return { kind: 'not-configured' }
|
|
108
|
+
if (!ctx.github.hasAppTokenResolver()) {
|
|
109
|
+
return {
|
|
110
|
+
kind: 'deny',
|
|
111
|
+
reason: 'pushing to channels.github.repos without the bypass requires GitHub App auth for the github channel',
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const resolvers = createSessionTmpGitResolvers(ctx.agentDir, event.sessionId)
|
|
115
|
+
const decision = await analyzeGitCommand(command, { cwd: ctx.agentDir, resolvers })
|
|
116
|
+
const verdict = await resolveGrantedPush(decision, { repos: github.repos }, resolvers)
|
|
117
|
+
if (verdict.kind === 'deny') return verdict
|
|
118
|
+
recordGrantedPush(event.callId, verdict.push)
|
|
119
|
+
return { kind: 'allow' }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function withPushGrantHint(result: SecurityBlock, outcome: PushGrantOutcome): SecurityBlock {
|
|
123
|
+
if (outcome.kind === 'deny') {
|
|
124
|
+
return {
|
|
125
|
+
block: true,
|
|
126
|
+
reason: `${result.reason} Pushing to a configured channels.github.repos repo did not apply: ${outcome.reason}.`,
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
block: true,
|
|
131
|
+
reason: `${result.reason} Branch pushes are allowed without the bypass to repos listed in channels.github.repos when the github channel uses App auth.`,
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
90
135
|
const INTERNAL_SECURITY_GUARD_REASON =
|
|
91
136
|
'The tool call was blocked because an internal security guard error prevented safe evaluation.'
|
|
92
137
|
|
|
@@ -213,7 +258,10 @@ export default definePlugin({
|
|
|
213
258
|
SECURITY_PERMISSIONS.bypassGitExfil,
|
|
214
259
|
GUARD_GIT_EXFIL_SEVERITY,
|
|
215
260
|
)
|
|
216
|
-
if (gitExfilResult)
|
|
261
|
+
if (gitExfilResult) {
|
|
262
|
+
const pushGrant = await evaluatePushGrant(event, ctx)
|
|
263
|
+
if (pushGrant.kind !== 'allow') return withPushGrantHint(gitExfilResult, pushGrant)
|
|
264
|
+
}
|
|
217
265
|
|
|
218
266
|
const secretExfilReadResult = canBypass(
|
|
219
267
|
GUARD_SECRET_EXFIL_READ_SEVERITY,
|
|
@@ -11,8 +11,10 @@ export const GUARD_GIT_EXFIL = 'gitExfil'
|
|
|
11
11
|
// copied identity files or secrets into it, and the effective repository is
|
|
12
12
|
// unknowable from the string alone (`git -C`, `--git-dir`, `GIT_DIR`, `cd`,
|
|
13
13
|
// subshells, aliases). Do NOT re-introduce cwd/path scoping here: it would be
|
|
14
|
-
// a bypass, not a fix (Oracle-reviewed). Member-tier publishing
|
|
15
|
-
//
|
|
14
|
+
// a bypass, not a fix (Oracle-reviewed). Member-tier publishing is the
|
|
15
|
+
// configured GitHub channel repos (`channels.github.repos`), decided on the
|
|
16
|
+
// broker's resolved remote identity (see github-cli-auth/granted-push.ts) and
|
|
17
|
+
// applied only to the push finding — never a path heuristic.
|
|
16
18
|
//
|
|
17
19
|
// Classified `medium` (silent-attack axis). Originally `high`; reclassified
|
|
18
20
|
// because the one narrow retarget-then-push audience-leak shape (re-point
|
|
@@ -55,17 +57,19 @@ const SHELL_BOUNDARY = String.raw`[\s;|&(\`$]`
|
|
|
55
57
|
const GIT_INTER = String.raw`(?:\s+-{1,2}[A-Za-z][^\s]*(?:\s+[^-\s][^\s]*)?)*\s+`
|
|
56
58
|
const GIT_PREFIX = String.raw`(?:^|${SHELL_BOUNDARY})git${GIT_INTER}`
|
|
57
59
|
|
|
60
|
+
// The breach: agent obeyed a Slack DM saying `git push origin main` to an
|
|
61
|
+
// attacker-controlled remote. Pushing a repo is the exfil moment - once
|
|
62
|
+
// the working tree reaches a remote, every tracked file is leaked. We
|
|
63
|
+
// block all push variants by default; only the permission service or an
|
|
64
|
+
// configured GitHub channel repo (`channels.github.repos`, resolved by the
|
|
65
|
+
// github-cli-auth broker) can authorize publication.
|
|
66
|
+
const GIT_PUSH_PATTERN = {
|
|
67
|
+
pattern: new RegExp(`${GIT_PREFIX}push\\b`),
|
|
68
|
+
label: 'git push (sends tracked files to a remote - the canonical exfil step)',
|
|
69
|
+
}
|
|
70
|
+
|
|
58
71
|
const DANGEROUS_COMMAND_PATTERNS: ReadonlyArray<{ pattern: RegExp; label: string }> = [
|
|
59
|
-
|
|
60
|
-
// The breach: agent obeyed a Slack DM saying `git push origin main` to an
|
|
61
|
-
// attacker-controlled remote. Pushing a repo is the exfil moment - once
|
|
62
|
-
// the working tree reaches a remote, every tracked file is leaked. We
|
|
63
|
-
// block all push variants by default; only the permission service can
|
|
64
|
-
// authorize publication.
|
|
65
|
-
{
|
|
66
|
-
pattern: new RegExp(`${GIT_PREFIX}push\\b`),
|
|
67
|
-
label: 'git push (sends tracked files to a remote - the canonical exfil step)',
|
|
68
|
-
},
|
|
72
|
+
GIT_PUSH_PATTERN,
|
|
69
73
|
// `git push --mirror` and `--force` are strictly worse: mirror copies every
|
|
70
74
|
// ref, force-push overwrites remote history. Caught by the generic match
|
|
71
75
|
// above but worth noting in the label so the user sees the severity.
|
|
@@ -172,6 +176,14 @@ export function recordGitRemoteTaintIfAny(options: {
|
|
|
172
176
|
}
|
|
173
177
|
}
|
|
174
178
|
|
|
179
|
+
// True when the only gitExfil finding in `command` is `git push`, so a
|
|
180
|
+
// destination grant may be considered. Any co-occurring finding (force-add,
|
|
181
|
+
// bulk staging, remote re-pointing, uploads) keeps the whole command blocked.
|
|
182
|
+
export function isPushOnlyGitExfilMatch(command: string): boolean {
|
|
183
|
+
const matched = DANGEROUS_COMMAND_PATTERNS.filter(({ pattern }) => pattern.test(command))
|
|
184
|
+
return matched.length === 1 && matched[0] === GIT_PUSH_PATTERN
|
|
185
|
+
}
|
|
186
|
+
|
|
175
187
|
export function checkGitExfilGuard(options: {
|
|
176
188
|
tool: string
|
|
177
189
|
args: Record<string, unknown>
|
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
} from '@/channels/types'
|
|
10
10
|
|
|
11
11
|
import { describeError } from '../describe-error'
|
|
12
|
+
import { createOwnReactionCallbacks } from './own-reactions'
|
|
12
13
|
|
|
13
14
|
// The reactable target on Discord: a message is addressed by its channel id
|
|
14
15
|
// plus the message id. The classifier stamps this because both values are on
|
|
@@ -79,6 +80,7 @@ const EMOJI_UNICODE: Record<string, string> = {
|
|
|
79
80
|
raised_hands: '🙌',
|
|
80
81
|
zipper_mouth_face: '🤐',
|
|
81
82
|
hourglass_flowing_sand: '⏳',
|
|
83
|
+
warning: '⚠️',
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
function resolveEmoji(emoji: string): string | null {
|
|
@@ -162,3 +164,19 @@ function parseRecord(value: string): Record<string, unknown> | null {
|
|
|
162
164
|
? (parsed as Record<string, unknown>)
|
|
163
165
|
: null
|
|
164
166
|
}
|
|
167
|
+
|
|
168
|
+
export function createDiscordOwnReactionCallbacks(deps: {
|
|
169
|
+
client: Pick<DiscordBotClient, 'removeReaction'>
|
|
170
|
+
identity: () => string | null | Promise<string | null>
|
|
171
|
+
}) {
|
|
172
|
+
return createOwnReactionCallbacks({
|
|
173
|
+
adapter: 'discord-bot',
|
|
174
|
+
identity: deps.identity,
|
|
175
|
+
decode: decodeDiscordReactionRef,
|
|
176
|
+
encode: encodeDiscordReactionRef,
|
|
177
|
+
emoji: (emoji) => resolveEmoji(emoji) ?? (Object.values(EMOJI_UNICODE).includes(emoji) ? emoji : null),
|
|
178
|
+
remove: (target, emoji) => deps.client.removeReaction(target.channel, target.message, emoji),
|
|
179
|
+
classify: classifyDiscordError,
|
|
180
|
+
absent: (error) => classifyDiscordError(error) === 'not-found',
|
|
181
|
+
})
|
|
182
|
+
}
|