typeclaw 0.50.0 → 0.52.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/dist/types/agent/bash-sandbox-env.d.ts +17 -0
- package/dist/types/agent/bash-sandbox-proc.d.ts +8 -0
- package/dist/types/agent/bash-sandbox.d.ts +98 -0
- package/dist/types/agent/compaction.d.ts +4 -4
- package/dist/types/agent/idle-compaction.d.ts +1 -0
- package/dist/types/agent/index.d.ts +10 -17
- package/dist/types/agent/multimodal/look-at.d.ts +1 -1
- package/dist/types/agent/output-allowance.d.ts +4 -0
- package/dist/types/agent/plugin-tools.d.ts +8 -75
- package/dist/types/agent/prompt-cache-key.d.ts +1 -0
- package/dist/types/agent/session-tail.d.ts +12 -0
- package/dist/types/agent/subagents.d.ts +5 -0
- package/dist/types/agent/system-prompt-composition.d.ts +18 -0
- package/dist/types/agent/system-prompt.d.ts +2 -0
- package/dist/types/agent/tools/channel-disengage.d.ts +1 -1
- package/dist/types/agent/tools/channel-edit.d.ts +1 -1
- package/dist/types/agent/tools/channel-fetch-attachment.d.ts +1 -1
- package/dist/types/agent/tools/channel-handoff.d.ts +1 -1
- package/dist/types/agent/tools/channel-history.d.ts +1 -1
- package/dist/types/agent/tools/channel-react.d.ts +1 -1
- package/dist/types/agent/tools/channel-read.d.ts +10 -2
- package/dist/types/agent/tools/channel-reply.d.ts +1 -1
- package/dist/types/agent/tools/channel-send.d.ts +1 -1
- package/dist/types/agent/tools/channel-session-search.d.ts +1 -1
- package/dist/types/agent/tools/ddg.d.ts +9 -0
- package/dist/types/agent/tools/grant-role.d.ts +1 -1
- package/dist/types/agent/tools/post-github-review.d.ts +1 -1
- package/dist/types/agent/tools/restart.d.ts +1 -1
- package/dist/types/agent/tools/skip-response.d.ts +1 -1
- package/dist/types/agent/tools/spawn-subagent.d.ts +2 -1
- package/dist/types/agent/tools/stream-snapshot.d.ts +2 -2
- package/dist/types/agent/tools/subagent-cancel.d.ts +1 -1
- package/dist/types/agent/tools/subagent-output.d.ts +1 -1
- package/dist/types/agent/tools/todo/index.d.ts +1 -1
- package/dist/types/agent/tools/webfetch/adaptive-html.d.ts +3 -3
- package/dist/types/agent/tools/webfetch/strategies/readability-process.d.ts +48 -0
- package/dist/types/agent/tools/webfetch/tool.d.ts +2 -2
- package/dist/types/agent/tools/websearch.d.ts +1 -1
- package/dist/types/channels/adapters/github/auth-app.d.ts +25 -0
- package/dist/types/channels/adapters/github/auth-pat.d.ts +17 -0
- package/dist/types/channels/adapters/github/auth.d.ts +24 -0
- package/dist/types/channels/github-review-check.d.ts +1 -1
- package/dist/types/channels/github-token-bridge.d.ts +4 -0
- package/dist/types/channels/lost-background-context.d.ts +2 -0
- package/dist/types/channels/persistence.d.ts +1 -0
- package/dist/types/channels/router.d.ts +16 -50
- package/dist/types/channels/types.d.ts +1 -0
- package/dist/types/coding-agent/tool.d.ts +1 -1
- package/dist/types/config/config.d.ts +22 -0
- package/dist/types/config/providers.d.ts +50 -1
- package/dist/types/container/start.d.ts +1 -0
- package/dist/types/eval/cell.d.ts +26 -0
- package/dist/types/eval/config.d.ts +19 -0
- package/dist/types/eval/dispatch.d.ts +7 -0
- package/dist/types/eval/kernel.d.ts +28 -0
- package/dist/types/eval/process.d.ts +23 -0
- package/dist/types/eval/protocol.d.ts +34 -0
- package/dist/types/eval/sandbox.d.ts +12 -0
- package/dist/types/eval/tool.d.ts +17 -0
- package/dist/types/eval/wire.d.ts +33 -0
- package/dist/types/git/resolve-identity.d.ts +2 -0
- package/dist/types/init/dockerfile.d.ts +1 -0
- package/dist/types/init/gitignore.d.ts +1 -1
- package/dist/types/permissions/builtins.d.ts +1 -0
- package/dist/types/plugin/types.d.ts +3 -0
- package/dist/types/sandbox/canonical-secrets.d.ts +2 -2
- package/dist/types/sandbox/coding-agent.d.ts +1 -1
- package/dist/types/sandbox/dependency-bins.d.ts +1 -0
- package/dist/types/sandbox/dev-source.d.ts +2 -2
- package/dist/types/sandbox/env-exposure.d.ts +2 -0
- package/dist/types/sandbox/hidden-paths.d.ts +1 -0
- package/dist/types/sandbox/index.d.ts +1 -1
- package/dist/types/sandbox/policy.d.ts +3 -0
- package/dist/types/typevault/cli-path.d.ts +2 -0
- package/dist/types/typevault/envelope-store.d.ts +11 -0
- package/dist/types/typevault/lifecycle.d.ts +13 -0
- package/dist/types/typevault/vault.d.ts +27 -0
- package/package.json +8 -7
- package/scripts/test.ts +252 -0
- package/src/agent/bash-sandbox-env.ts +136 -0
- package/src/agent/bash-sandbox-proc.ts +70 -0
- package/src/agent/bash-sandbox.ts +239 -0
- package/src/agent/compaction.ts +22 -10
- package/src/agent/idle-compaction.ts +7 -3
- package/src/agent/index.ts +185 -187
- package/src/agent/multimodal/look-at.ts +1 -1
- package/src/agent/output-allowance.ts +7 -0
- package/src/agent/plugin-tools.ts +64 -380
- package/src/agent/prompt-cache-key.ts +26 -3
- package/src/agent/session-origin.ts +41 -19
- package/src/agent/session-tail.ts +28 -0
- package/src/agent/subagent-completion-reminder.ts +2 -2
- package/src/agent/subagents.ts +21 -2
- package/src/agent/system-prompt-composition.ts +159 -0
- package/src/agent/system-prompt.ts +43 -5
- package/src/agent/todo/scope.ts +1 -1
- package/src/agent/tool-error-remediation.ts +18 -3
- package/src/agent/tools/channel-disengage.ts +1 -1
- package/src/agent/tools/channel-edit.ts +1 -1
- package/src/agent/tools/channel-fetch-attachment.ts +1 -1
- package/src/agent/tools/channel-handoff.ts +3 -2
- package/src/agent/tools/channel-history.ts +2 -1
- package/src/agent/tools/channel-react.ts +1 -1
- package/src/agent/tools/channel-read.ts +36 -3
- package/src/agent/tools/channel-reply.ts +1 -1
- package/src/agent/tools/channel-send.ts +4 -3
- package/src/agent/tools/channel-session-search.ts +13 -4
- package/src/agent/tools/ddg.ts +71 -11
- package/src/agent/tools/grant-role.ts +1 -1
- package/src/agent/tools/post-github-review.ts +1 -1
- package/src/agent/tools/restart.ts +1 -1
- package/src/agent/tools/skip-response.ts +1 -1
- package/src/agent/tools/spawn-subagent.ts +15 -1
- package/src/agent/tools/stream-snapshot.ts +1 -1
- package/src/agent/tools/subagent-cancel.ts +1 -1
- package/src/agent/tools/subagent-output.ts +1 -1
- package/src/agent/tools/todo/index.ts +1 -1
- package/src/agent/tools/webfetch/adaptive-html.ts +6 -4
- package/src/agent/tools/webfetch/strategies/readability-child.ts +25 -0
- package/src/agent/tools/webfetch/strategies/readability-process.ts +185 -0
- package/src/agent/tools/webfetch/tool.ts +6 -5
- package/src/agent/tools/websearch.ts +1 -1
- package/src/agent/tools-without-local-file-operands.ts +4 -0
- package/src/browser/dockerfile.ts +1 -1
- package/src/browser/fill-secret.ts +364 -0
- package/src/browser/registry.ts +6 -6
- package/src/bundled-plugins/agent-messenger-cli-auth/command.ts +211 -0
- package/src/bundled-plugins/agent-messenger-cli-auth/index.ts +186 -0
- package/src/bundled-plugins/backup/index.ts +17 -2
- package/src/bundled-plugins/backup/runner.ts +37 -2
- package/src/bundled-plugins/browser-agent/browser-agent.ts +51 -14
- package/src/bundled-plugins/browser-agent/index.ts +12 -5
- package/src/bundled-plugins/explorer/explorer.ts +1 -1
- package/src/bundled-plugins/github-cli-auth/gh-review-detect.ts +40 -16
- package/src/bundled-plugins/github-cli-auth/graphql-auth-nudge.ts +12 -7
- package/src/bundled-plugins/github-cli-auth/index.ts +10 -1
- package/src/bundled-plugins/managed-browser/index.ts +130 -2
- package/src/bundled-plugins/managed-browser/skills/browserskill/browserskill/SKILL.md +13 -5
- package/src/bundled-plugins/managed-browser/skills/omowright/omowright/SKILL.md +56 -5
- package/src/bundled-plugins/memory/README.md +23 -2
- package/src/bundled-plugins/memory/append-fragment.ts +133 -0
- package/src/bundled-plugins/memory/append-tool.ts +80 -149
- package/src/bundled-plugins/memory/dreaming.ts +6 -1
- package/src/bundled-plugins/memory/index.ts +33 -6
- package/src/bundled-plugins/memory/load-memory.ts +2 -4
- package/src/bundled-plugins/memory/memory-logger.ts +200 -6
- package/src/bundled-plugins/memory/references/store-reference-tool.ts +56 -32
- package/src/bundled-plugins/memory/remember-tool.ts +81 -0
- package/src/bundled-plugins/memory/search-tool-hybrid.ts +91 -0
- package/src/bundled-plugins/memory/search-tool.ts +58 -12
- package/src/bundled-plugins/memory/stream-events.ts +2 -0
- package/src/bundled-plugins/memory/transcript-cursor.ts +30 -0
- package/src/bundled-plugins/memory/transcript-preload.ts +208 -0
- package/src/bundled-plugins/memory/transcript-view.ts +36 -0
- package/src/bundled-plugins/memory/vector/hybrid.ts +25 -14
- package/src/bundled-plugins/memory/watermark.ts +19 -10
- package/src/bundled-plugins/reviewer/reviewer.ts +20 -0
- package/src/bundled-plugins/security/policies/outbound-secret-scan.ts +3 -6
- package/src/bundled-plugins/security/policies/outbound-text.ts +20 -0
- package/src/bundled-plugins/security/policies/private-surface-read.ts +166 -201
- package/src/bundled-plugins/security/policies/system-prompt-leak.ts +2 -7
- package/src/bundled-plugins/typevault/grants.ts +119 -0
- package/src/bundled-plugins/typevault/index.ts +152 -0
- package/src/bundled-plugins/typevault/request.ts +87 -0
- package/src/bundled-plugins/typevault/runtime.ts +45 -0
- package/src/bundled-plugins/typevault/skills/typevault/SKILL.md +65 -0
- package/src/channels/adapter-halt.ts +17 -0
- package/src/channels/adapters/discord-bot-reference.ts +5 -4
- package/src/channels/adapters/discord-bot.ts +1 -0
- package/src/channels/adapters/discord-classify.ts +8 -3
- package/src/channels/adapters/discord.ts +29 -0
- package/src/channels/adapters/github/history.ts +23 -2
- package/src/channels/adapters/github/inbound.ts +60 -1
- package/src/channels/adapters/github/index.ts +27 -5
- package/src/channels/adapters/github/reconcile-open-prs.ts +7 -1
- package/src/channels/adapters/kakaotalk-author-resolver.ts +7 -5
- package/src/channels/adapters/kakaotalk-channel-resolver.ts +45 -15
- package/src/channels/adapters/kakaotalk-classify.ts +7 -9
- package/src/channels/adapters/kakaotalk-list.ts +62 -0
- package/src/channels/adapters/kakaotalk-member-cache.ts +67 -0
- package/src/channels/adapters/kakaotalk-membership.ts +27 -10
- package/src/channels/adapters/kakaotalk-mention.ts +61 -0
- package/src/channels/adapters/kakaotalk.ts +159 -125
- package/src/channels/adapters/teams-classify.ts +18 -8
- package/src/channels/github-review-check.ts +5 -1
- package/src/channels/github-review-verdict-coordinator.ts +68 -2
- package/src/channels/github-token-bridge.ts +13 -0
- package/src/channels/lost-background-context.ts +46 -0
- package/src/channels/manager.ts +52 -3
- package/src/channels/persistence.ts +5 -0
- package/src/channels/router.ts +208 -128
- package/src/channels/schema.ts +1 -1
- package/src/channels/subagent-completion-bridge.ts +3 -2
- package/src/channels/types.ts +3 -0
- package/src/cli/hostd.ts +3 -0
- package/src/coding-agent/tool.ts +1 -1
- package/src/config/config.ts +35 -1
- package/src/config/providers.ts +75 -4
- package/src/container/start.ts +52 -3
- package/src/doctor/channel-checks.ts +33 -0
- package/src/doctor/checks.ts +37 -18
- package/src/doctor/index.ts +48 -12
- package/src/doctor/operational-incidents.ts +16 -1
- package/src/doctor/plugin-bridge.ts +14 -1
- package/src/doctor/stage.ts +14 -0
- package/src/doctor/types.ts +6 -0
- package/src/eval/cell.ts +93 -0
- package/src/eval/config.ts +32 -0
- package/src/eval/dispatch.ts +67 -0
- package/src/eval/entry.ts +261 -0
- package/src/eval/kernel.ts +154 -0
- package/src/eval/process.ts +113 -0
- package/src/eval/protocol.ts +26 -0
- package/src/eval/redeclare.ts +174 -0
- package/src/eval/sandbox.ts +117 -0
- package/src/eval/tool.ts +99 -0
- package/src/eval/wire.ts +93 -0
- package/src/git/resolve-identity.ts +67 -2
- package/src/git/system-commit.ts +7 -0
- package/src/init/dockerfile.ts +5 -1
- package/src/init/gitignore.ts +3 -3
- package/src/init/index.ts +1 -0
- package/src/init/models-dev.ts +2 -0
- package/src/init/validate-api-key.ts +5 -0
- package/src/migrations/secrets-v1-to-v2.ts +2 -0
- package/src/operations/classify-tool-outcome.ts +1 -1
- package/src/permissions/builtins.ts +8 -0
- package/src/plugin/core-tool-names.ts +6 -1
- package/src/plugin/types.ts +6 -0
- package/src/run/bundled-plugins.ts +12 -0
- package/src/run/channel-session-factory.ts +3 -0
- package/src/run/index.ts +13 -2
- package/src/sandbox/build.ts +1 -0
- package/src/sandbox/canonical-secrets.ts +6 -0
- package/src/sandbox/dependency-bins.ts +13 -1
- package/src/sandbox/dev-source.ts +21 -12
- package/src/sandbox/env-exposure.ts +20 -0
- package/src/sandbox/hidden-paths.ts +1 -1
- package/src/sandbox/index.ts +1 -0
- package/src/sandbox/policy.ts +5 -0
- package/src/secrets/hydrate.ts +4 -1
- package/src/secrets/storage.ts +10 -1
- package/src/server/command-runner.ts +4 -0
- package/src/server/index.ts +54 -12
- package/src/skills/typeclaw-config/SKILL.md +36 -2
- package/src/skills/typeclaw-memory/SKILL.md +3 -1
- package/src/skills/typeclaw-permissions/SKILL.md +8 -8
- package/src/skills/typeclaw-troubleshooting/SKILL.md +18 -1
- package/src/tunnels/active.ts +14 -0
- package/src/typevault/bash-cli.ts +18 -0
- package/src/typevault/cli-path.ts +11 -0
- package/src/typevault/envelope-helper.ts +17 -0
- package/src/typevault/envelope-store.ts +98 -0
- package/src/typevault/lifecycle.ts +132 -0
- package/src/typevault/prompt-tunnel.ts +33 -0
- package/src/typevault/redaction.ts +37 -0
- package/src/typevault/vault.ts +283 -0
- package/typeclaw.schema.json +92 -10
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto'
|
|
2
2
|
|
|
3
|
+
import { githubReviewChecks } from './github-review-check'
|
|
3
4
|
import type { ReviewVerdict } from './github-review-turn-ledger'
|
|
4
5
|
import type { GithubReviewFollowupRound } from './types'
|
|
5
6
|
|
|
@@ -131,6 +132,11 @@ const ROUND_HEAD_MOVED_REASON =
|
|
|
131
132
|
'The pull request head moved past the commit this review round covers, so a verdict from this round would describe stale code. ' +
|
|
132
133
|
'Do not submit it; the new push starts its own review round.'
|
|
133
134
|
|
|
135
|
+
const ROUND_SUPERSEDED_REASON =
|
|
136
|
+
'A newer review round for this pull request replaced the one this session carries, at the same head commit. ' +
|
|
137
|
+
'Its designated session submits the formal verdict, so do not submit one from this session and do not reply now: call `skip_response`. ' +
|
|
138
|
+
'Once that verdict lands, close out only this thread with the technical outcome; never mention sessions, carriers, or review rounds on the PR.'
|
|
139
|
+
|
|
134
140
|
function reviewedHeadRequiredReason(currentHead: string): string {
|
|
135
141
|
return (
|
|
136
142
|
`The pull request head moved to ${currentHead} after this review round opened. ` +
|
|
@@ -234,6 +240,11 @@ let reviewRounds = new Map<string, ReviewRoundState>()
|
|
|
234
240
|
let expiredReviewRoundKeys = new Set<string>()
|
|
235
241
|
type ReplyReviewRoundGeneration = { round: GithubReviewFollowupRound; createdAt: number }
|
|
236
242
|
let replyReviewRoundGenerations = new Map<string, ReplyReviewRoundGeneration>()
|
|
243
|
+
// Round key -> key of the same-head counterpart it joined. Queued and persisted
|
|
244
|
+
// inbounds still carry the joiner's round and re-register it later; the alias
|
|
245
|
+
// keeps resolving to the canonical round after it completes, where the
|
|
246
|
+
// pending-only counterpart lookup would no longer find it.
|
|
247
|
+
let joinedRoundAliases = new Map<string, string>()
|
|
237
248
|
let tokenSeq = 0
|
|
238
249
|
|
|
239
250
|
export function githubReviewRoundKey(round: GithubReviewFollowupRound): string {
|
|
@@ -261,7 +272,7 @@ export function registerOrJoinReplyReviewRound(input: {
|
|
|
261
272
|
replyReviewRoundGenerations.delete(correlationKey)
|
|
262
273
|
}
|
|
263
274
|
|
|
264
|
-
const
|
|
275
|
+
const candidate: GithubReviewFollowupRound = {
|
|
265
276
|
kind: 'reply',
|
|
266
277
|
roundId: (input.generateRoundId ?? randomUUID)(),
|
|
267
278
|
workspace: input.workspace,
|
|
@@ -269,8 +280,8 @@ export function registerOrJoinReplyReviewRound(input: {
|
|
|
269
280
|
headSha: input.headSha,
|
|
270
281
|
carrierThread: input.thread,
|
|
271
282
|
}
|
|
283
|
+
const round = registerGithubReviewRound(candidate, currentTime, now) ?? candidate
|
|
272
284
|
replyReviewRoundGenerations.set(correlationKey, { round, createdAt: currentTime })
|
|
273
|
-
registerGithubReviewRound(round, currentTime, now)
|
|
274
285
|
return round
|
|
275
286
|
}
|
|
276
287
|
|
|
@@ -281,6 +292,25 @@ export function registerGithubReviewRound(
|
|
|
281
292
|
): GithubReviewFollowupRound | null {
|
|
282
293
|
const key = githubReviewRoundKey(round)
|
|
283
294
|
if (expiredReviewRoundKeys.has(key)) return null
|
|
295
|
+
// A push round and a reply round on the same head ask for the same fresh
|
|
296
|
+
// verdict. A push re-check and a reply to the blocking review routinely land
|
|
297
|
+
// together, and evicting one for the other split sibling threads across
|
|
298
|
+
// rounds: the evicted carrier's verdict was then refused as superseded while
|
|
299
|
+
// the surviving round's carrier never owned the blocking obligation. Join the
|
|
300
|
+
// pending counterpart instead so one carrier answers for the head.
|
|
301
|
+
if (activeReviewRoundState(key, now) === undefined) {
|
|
302
|
+
const aliasKey = joinedRoundAliases.get(key)
|
|
303
|
+
if (aliasKey !== undefined) {
|
|
304
|
+
const canonical = activeReviewRoundState(aliasKey, now)
|
|
305
|
+
if (canonical !== undefined) return canonical.round
|
|
306
|
+
joinedRoundAliases.delete(key)
|
|
307
|
+
}
|
|
308
|
+
const counterpart = pendingSameHeadCounterpart(round, now)
|
|
309
|
+
if (counterpart !== undefined) {
|
|
310
|
+
joinedRoundAliases.set(key, githubReviewRoundKey(counterpart.round))
|
|
311
|
+
return counterpart.round
|
|
312
|
+
}
|
|
313
|
+
}
|
|
284
314
|
for (const [candidateKey, state] of reviewRounds) {
|
|
285
315
|
if (activeReviewRoundState(candidateKey, now) === undefined) continue
|
|
286
316
|
if (candidateKey !== key && state.round.workspace === round.workspace && state.round.prNumber === round.prNumber) {
|
|
@@ -316,6 +346,9 @@ export function restoreGithubReviewRound(
|
|
|
316
346
|
const registered = registerGithubReviewRound(round, createdAt, now)
|
|
317
347
|
if (registered === null) return null
|
|
318
348
|
const key = githubReviewRoundKey(registered)
|
|
349
|
+
// Joined a same-head counterpart: its live state is authoritative, and this
|
|
350
|
+
// record's persisted status describes a different round.
|
|
351
|
+
if (key !== githubReviewRoundKey(round)) return registered
|
|
319
352
|
// Restoration is monotonic: a persisted `pending` record must never overwrite
|
|
320
353
|
// an unexpired round this process already completed. A sibling session that
|
|
321
354
|
// was idle-GC'd before completion still carries the stale status, and letting
|
|
@@ -459,6 +492,18 @@ export function isGithubReviewRoundSuperseded(round: GithubReviewFollowupRound,
|
|
|
459
492
|
)
|
|
460
493
|
}
|
|
461
494
|
|
|
495
|
+
function pendingSameHeadCounterpart(round: GithubReviewFollowupRound, now: () => number): ReviewRoundState | undefined {
|
|
496
|
+
expireReviewRounds(now)
|
|
497
|
+
return Array.from(reviewRounds.values()).find(
|
|
498
|
+
(state) =>
|
|
499
|
+
state.status === 'pending' &&
|
|
500
|
+
state.round.kind !== round.kind &&
|
|
501
|
+
state.round.workspace === round.workspace &&
|
|
502
|
+
state.round.prNumber === round.prNumber &&
|
|
503
|
+
state.round.headSha === round.headSha,
|
|
504
|
+
)
|
|
505
|
+
}
|
|
506
|
+
|
|
462
507
|
function pendingPushRoundForPr(
|
|
463
508
|
target: { workspace: string; prNumber: number },
|
|
464
509
|
now: () => number = Date.now,
|
|
@@ -596,6 +641,9 @@ export function abortGithubReviewStateForPr(
|
|
|
596
641
|
if (generation.round.workspace !== workspace || generation.round.prNumber !== prNumber) continue
|
|
597
642
|
replyReviewRoundGenerations.delete(generationKey)
|
|
598
643
|
}
|
|
644
|
+
for (const aliasKey of joinedRoundAliases.keys()) {
|
|
645
|
+
if (aliasKey.startsWith(`${key}#`)) joinedRoundAliases.delete(aliasKey)
|
|
646
|
+
}
|
|
599
647
|
|
|
600
648
|
// A draft abort abandons local work, not output already observed on GitHub.
|
|
601
649
|
// Keeping recentLandedByPr prevents a later ready event from duplicating it.
|
|
@@ -711,6 +759,17 @@ export function createApproveIdempotencyGuard(deps: {
|
|
|
711
759
|
remote.ok &&
|
|
712
760
|
remote.effective === 'CHANGES_REQUESTED'
|
|
713
761
|
|
|
762
|
+
const reviewedHeadSha = args.reviewedHeadSha ?? args.round?.headSha
|
|
763
|
+
if (
|
|
764
|
+
args.verdict === 'APPROVE' &&
|
|
765
|
+
remote.ok &&
|
|
766
|
+
remote.effective === 'APPROVED' &&
|
|
767
|
+
headSha !== null &&
|
|
768
|
+
(reviewedHeadSha === undefined || sameSha(reviewedHeadSha, headSha))
|
|
769
|
+
) {
|
|
770
|
+
void githubReviewChecks.completePostingReviews(args.workspace, args.prNumber, 'APPROVED', headSha)
|
|
771
|
+
}
|
|
772
|
+
|
|
714
773
|
// Layer 3 — duplicate-review cooldown. A recently-landed SAME verdict on the
|
|
715
774
|
// SAME (or uncertain) head blocks a redundant re-publication for the window. It
|
|
716
775
|
// fires on a bare NONE (read-after-write lag, the original shield) AND on the
|
|
@@ -869,6 +928,12 @@ async function evaluateRoundEligibility(
|
|
|
869
928
|
// Re-read ownership after the await: a round registered meanwhile evicted this
|
|
870
929
|
// one, and the registration below would evict it right back.
|
|
871
930
|
const superseded = isGithubReviewRoundSuperseded(activeRound, now)
|
|
931
|
+
if (superseded && currentRoundHead === activeRound.headSha) {
|
|
932
|
+
logger.warn(
|
|
933
|
+
`[github] review round superseded at unchanged head pr=${activeRound.workspace}#${activeRound.prNumber} round=${activeRound.roundId} head=${currentRoundHead}`,
|
|
934
|
+
)
|
|
935
|
+
return { block: true, kind: 'round-ineligible', reason: ROUND_SUPERSEDED_REASON }
|
|
936
|
+
}
|
|
872
937
|
if (superseded || (currentRoundHead !== activeRound.headSha && activeRound.kind === 'push')) {
|
|
873
938
|
logger.warn(
|
|
874
939
|
`[github] review round head moved pr=${activeRound.workspace}#${activeRound.prNumber} round=${activeRound.roundId} round_head=${activeRound.headSha} current_head=${currentRoundHead}${superseded ? ' superseded=true' : ''}`,
|
|
@@ -1022,6 +1087,7 @@ export function __resetReviewVerdictGuardForTest(): void {
|
|
|
1022
1087
|
reviewRounds = new Map<string, ReviewRoundState>()
|
|
1023
1088
|
expiredReviewRoundKeys = new Set<string>()
|
|
1024
1089
|
replyReviewRoundGenerations = new Map<string, ReplyReviewRoundGeneration>()
|
|
1090
|
+
joinedRoundAliases = new Map<string, string>()
|
|
1025
1091
|
tokenSeq = 0
|
|
1026
1092
|
processEffectiveResolver = async () => ({ ok: false })
|
|
1027
1093
|
processHeadShaResolver = async () => null
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { GithubSelfUser } from './adapters/github/auth'
|
|
1
2
|
import { describeError } from './describe-error'
|
|
2
3
|
// Decoupled from ChannelRouter on purpose: minting a token for an arbitrary
|
|
3
4
|
// bash `gh` command is adjacent to channels but is not routing, and a global
|
|
@@ -10,8 +11,11 @@ export type GithubTokenResolveResult =
|
|
|
10
11
|
| { kind: 'unavailable'; reason: string }
|
|
11
12
|
|
|
12
13
|
export type ResolveGithubTokenForRepo = (repoSlug: string) => Promise<GithubTokenResolveResult>
|
|
14
|
+
export type GetGithubSelf = () => GithubSelfUser | null
|
|
13
15
|
|
|
14
16
|
export type GithubTokenBridge = {
|
|
17
|
+
getSelf: GetGithubSelf
|
|
18
|
+
registerSelf: (self: GithubSelfUser) => () => void
|
|
15
19
|
resolveTokenForRepo: ResolveGithubTokenForRepo
|
|
16
20
|
// True when a per-repo App-token minter is registered (only the GitHub App
|
|
17
21
|
// adapter registers one). This is the non-secret "App auth with per-repo
|
|
@@ -38,11 +42,20 @@ const NO_PAT_RESOLVER_REASON =
|
|
|
38
42
|
'No GitHub channel PAT is available; the GitHub channel is not configured with PAT auth, or its adapter is not running.'
|
|
39
43
|
|
|
40
44
|
export function createGithubTokenBridge(): GithubTokenBridge {
|
|
45
|
+
let currentSelf: { readonly user: GithubSelfUser } | null = null
|
|
41
46
|
let current: ((repoSlug: string) => Promise<GithubTokenCredential>) | null = null
|
|
42
47
|
let currentSelfLogin: (() => string | null) | null = null
|
|
43
48
|
let currentPat: ((repoSlug: string) => Promise<GithubTokenCredential>) | null = null
|
|
44
49
|
|
|
45
50
|
return {
|
|
51
|
+
getSelf: () => currentSelf?.user ?? null,
|
|
52
|
+
registerSelf: (self) => {
|
|
53
|
+
const registration = { user: self }
|
|
54
|
+
currentSelf = registration
|
|
55
|
+
return () => {
|
|
56
|
+
if (currentSelf === registration) currentSelf = null
|
|
57
|
+
}
|
|
58
|
+
},
|
|
46
59
|
resolvePatForRepo: async (repoSlug) => {
|
|
47
60
|
const resolver = currentPat
|
|
48
61
|
if (resolver === null) return { kind: 'unavailable', reason: NO_PAT_RESOLVER_REASON }
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { mkdir, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
import type { BackgroundObligationStore } from './background-obligations'
|
|
5
|
+
|
|
6
|
+
export async function takeLostBackgroundContext(
|
|
7
|
+
agentDir: string,
|
|
8
|
+
obligations: BackgroundObligationStore,
|
|
9
|
+
sessionId: string,
|
|
10
|
+
): Promise<string[]> {
|
|
11
|
+
const lost = (await obligations.list()).filter(
|
|
12
|
+
(row) =>
|
|
13
|
+
row.parentSessionId === sessionId &&
|
|
14
|
+
row.epoch !== obligations.epoch &&
|
|
15
|
+
row.transfer?.cause !== 'live-turn-ended' &&
|
|
16
|
+
(row.outcome === undefined ||
|
|
17
|
+
(row.outcome.kind === 'intentionally-suppressed' &&
|
|
18
|
+
(row.outcome.reason === 'operator-log-only' || row.outcome.reason === 'adapter-redelivered'))),
|
|
19
|
+
)
|
|
20
|
+
if (lost.length === 0) return []
|
|
21
|
+
const directory = join(agentDir, 'channels', 'lost-background-context')
|
|
22
|
+
await mkdir(directory, { recursive: true })
|
|
23
|
+
const taskIds: string[] = []
|
|
24
|
+
for (const row of lost) {
|
|
25
|
+
try {
|
|
26
|
+
// A separate at-most-once issuance receipt leaves continuity authority untouched.
|
|
27
|
+
// Empty exclusive files also survive another process boot without schema migration.
|
|
28
|
+
await writeFile(join(directory, row.obligationId), '', { flag: 'wx', mode: 0o600 })
|
|
29
|
+
taskIds.push(row.taskId)
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (error instanceof Error && 'code' in error && error.code === 'EEXIST') continue
|
|
32
|
+
throw error
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (taskIds.length === 0) return []
|
|
36
|
+
return [
|
|
37
|
+
[
|
|
38
|
+
'---',
|
|
39
|
+
'**[SYSTEM MESSAGE — not from a human]**',
|
|
40
|
+
`Background tasks terminated by a process restart: ${taskIds.join(', ')}.`,
|
|
41
|
+
'Their results will never arrive. Redo their work if it is still needed.',
|
|
42
|
+
'Do not acknowledge or reply to this notice.',
|
|
43
|
+
'---',
|
|
44
|
+
].join('\n'),
|
|
45
|
+
]
|
|
46
|
+
}
|
package/src/channels/manager.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { SecretsTeamsCredentialStore } from '@/secrets/teams-store'
|
|
|
14
14
|
import { SecretsWebexCredentialStore } from '@/secrets/webex-store'
|
|
15
15
|
import type { Stream } from '@/stream'
|
|
16
16
|
|
|
17
|
+
import { isChannelAdapterHaltedError } from './adapter-halt'
|
|
17
18
|
import { createDiscordAdapter, type DiscordAdapter } from './adapters/discord'
|
|
18
19
|
import { createDiscordBotAdapter, type DiscordBotAdapter } from './adapters/discord-bot'
|
|
19
20
|
import { createGithubAdapter, type GithubAdapter } from './adapters/github'
|
|
@@ -211,7 +212,7 @@ type AdapterEntry = {
|
|
|
211
212
|
}
|
|
212
213
|
|
|
213
214
|
type FailedAdapter = {
|
|
214
|
-
kind: 'start-failed' | 'missing-credentials'
|
|
215
|
+
kind: 'start-failed' | 'missing-credentials' | 'halted'
|
|
215
216
|
attempts: number
|
|
216
217
|
failedSinceMs: number
|
|
217
218
|
nextAttemptAtMs: number
|
|
@@ -543,10 +544,11 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
|
|
|
543
544
|
} catch (err) {
|
|
544
545
|
await cleanupPartialStart(adapter)
|
|
545
546
|
if (!canCommit()) return { status: 'aborted' }
|
|
547
|
+
const halted = isChannelAdapterHaltedError(err)
|
|
546
548
|
return {
|
|
547
549
|
status: 'failed',
|
|
548
|
-
kind: 'start-failed',
|
|
549
|
-
detail: `failed to start: ${describeError(err)}`,
|
|
550
|
+
kind: halted ? 'halted' : 'start-failed',
|
|
551
|
+
detail: halted ? `halted: ${err.message}` : `failed to start: ${describeError(err)}`,
|
|
550
552
|
inputSignature: buildFailedInputSignature(name, cfg, credentials),
|
|
551
553
|
}
|
|
552
554
|
}
|
|
@@ -626,6 +628,17 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
|
|
|
626
628
|
entry.nextAttemptAtMs = now + delayMs
|
|
627
629
|
entry.retryQueued = false
|
|
628
630
|
|
|
631
|
+
if (failure.kind === 'halted') {
|
|
632
|
+
entry.nextAttemptAtMs = Number.POSITIVE_INFINITY
|
|
633
|
+
logger.error(
|
|
634
|
+
`[channels] adapter "${name}" ${failure.detail}; not retrying automatically. ` +
|
|
635
|
+
'It starts again when its credentials or config change, on `typeclaw restart`, or on an explicit adapter restart.',
|
|
636
|
+
)
|
|
637
|
+
failed.set(name, entry)
|
|
638
|
+
failedInputSignatures.set(entry, failure.inputSignature)
|
|
639
|
+
return entry
|
|
640
|
+
}
|
|
641
|
+
|
|
629
642
|
const reachedCap = nominalDelayMs === retryCapMs
|
|
630
643
|
const justReachedCap = reachedCap && previousNominalDelayMs < retryCapMs
|
|
631
644
|
if (justReachedCap) entry.nextLogAtMs = now + retryHeartbeatMs
|
|
@@ -741,10 +754,43 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
|
|
|
741
754
|
return applyStartResult(name, currentCfg, result, previousFailure) ? 'restarted' : 'recovery-pending'
|
|
742
755
|
}
|
|
743
756
|
|
|
757
|
+
// A live adapter that halted itself must leave `live`: the disconnected-restart
|
|
758
|
+
// path below would otherwise log in again every backoff interval forever.
|
|
759
|
+
const retireHaltedAdapter = (name: AdapterId, entry: AdapterEntry, haltReason: string): void => {
|
|
760
|
+
entry.recoveryRestartQueued = true
|
|
761
|
+
const queuedEpoch = lifecycleEpoch
|
|
762
|
+
void runSerially(name, async () => {
|
|
763
|
+
try {
|
|
764
|
+
if (!running || queuedEpoch !== lifecycleEpoch || live.get(name) !== entry) return
|
|
765
|
+
if (!(await stopAdapter(name))) return
|
|
766
|
+
const cfg = options.channelsConfigRef()[name]
|
|
767
|
+
if (cfg === undefined || cfg.enabled === false) return
|
|
768
|
+
// Record the credentials the halted session actually ran with. Re-reading
|
|
769
|
+
// them here would adopt a rotation that landed during stop() as already
|
|
770
|
+
// tried, and the reload carrying it would skip the restart it owes.
|
|
771
|
+
recordFailure(name, cfg, {
|
|
772
|
+
status: 'failed',
|
|
773
|
+
kind: 'halted',
|
|
774
|
+
detail: `halted: ${haltReason}`,
|
|
775
|
+
inputSignature: buildFailedInputSignature(name, cfg, { signature: entry.credentialSignature, missing: [] }),
|
|
776
|
+
})
|
|
777
|
+
} finally {
|
|
778
|
+
if (live.get(name) === entry) entry.recoveryRestartQueued = false
|
|
779
|
+
}
|
|
780
|
+
}).catch((err) => {
|
|
781
|
+
logger.error(`[channels] adapter "${name}" halt supervision failed: ${describeError(err)}`)
|
|
782
|
+
})
|
|
783
|
+
}
|
|
784
|
+
|
|
744
785
|
const superviseAdapters = (): void => {
|
|
745
786
|
if (!running) return
|
|
746
787
|
const now = recoveryNow()
|
|
747
788
|
for (const [name, entry] of live) {
|
|
789
|
+
const haltReason = 'haltReason' in entry.adapter ? (entry.adapter.haltReason?.() ?? null) : null
|
|
790
|
+
if (haltReason !== null) {
|
|
791
|
+
if (!entry.recoveryRestartQueued) retireHaltedAdapter(name, entry, haltReason)
|
|
792
|
+
continue
|
|
793
|
+
}
|
|
748
794
|
if (entry.adapter.isConnected()) {
|
|
749
795
|
void router
|
|
750
796
|
.recoverWaitingReactions(name)
|
|
@@ -1013,6 +1059,9 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
|
|
|
1013
1059
|
const changed =
|
|
1014
1060
|
failedInputSignatures.get(previousFailure) !== buildFailedInputSignature(name, latest, credentials)
|
|
1015
1061
|
if (changed) failed.delete(name)
|
|
1062
|
+
// A halted adapter only restarts on changed inputs; an unrelated
|
|
1063
|
+
// reload must not send another login to a platform that refused it.
|
|
1064
|
+
else if (previousFailure.kind === 'halted') return named ? 'skipped' : null
|
|
1016
1065
|
// A queued retry will read the new credential when it fires, so the
|
|
1017
1066
|
// rotation is on its way even though nothing happened right here.
|
|
1018
1067
|
else if (previousFailure.retryQueued) return named ? 'recovery-pending' : null
|
|
@@ -29,6 +29,10 @@ export type ChannelSessionRecord = {
|
|
|
29
29
|
sessionFile?: string
|
|
30
30
|
lastInboundAt?: number
|
|
31
31
|
participants: ChannelParticipant[]
|
|
32
|
+
// Set once the bot has delivered a message into this conversation. The live
|
|
33
|
+
// send counter resets on restart and rollover, so this is what keeps a
|
|
34
|
+
// thread the bot already joined from looking like an un-addressed intrusion.
|
|
35
|
+
botParticipated?: true
|
|
32
36
|
githubReviewRound?: GithubReviewFollowupRound & {
|
|
33
37
|
status: 'pending' | 'completed'
|
|
34
38
|
createdAt: number
|
|
@@ -247,6 +251,7 @@ function isValidRecord(v: unknown): v is ChannelSessionRecord {
|
|
|
247
251
|
(r.sessionFile === undefined || typeof r.sessionFile === 'string') &&
|
|
248
252
|
(r.lastInboundAt === undefined || typeof r.lastInboundAt === 'number') &&
|
|
249
253
|
Array.isArray(r.participants) &&
|
|
254
|
+
(r.botParticipated === undefined || r.botParticipated === true) &&
|
|
250
255
|
(r.githubReviewRound === undefined || isValidGithubReviewRound(r.githubReviewRound, r)) &&
|
|
251
256
|
(r.githubReviewThreadCloseout === undefined || isValidGithubReviewThreadCloseout(r.githubReviewThreadCloseout, r))
|
|
252
257
|
)
|