typeclaw 0.48.6 → 0.48.7
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
CHANGED
|
@@ -38,6 +38,20 @@ export type LiveSubagent = {
|
|
|
38
38
|
export const MAX_EVENTS_PER_SUBAGENT = 100
|
|
39
39
|
export const MESSAGE_PREVIEW_CHARS = 200
|
|
40
40
|
|
|
41
|
+
// Newest — not oldest — so a long-running child that crossed a caller's backstop
|
|
42
|
+
// cannot unpin a parent while a more recently spawned sibling is still inside its
|
|
43
|
+
// window. Foreground children are excluded on purpose: they return inline, so a
|
|
44
|
+
// parent is never left waiting on one.
|
|
45
|
+
export function newestRunningBackgroundChildStartedAt(children: readonly LiveSubagent[]): number | null {
|
|
46
|
+
return children.reduce<number | null>(
|
|
47
|
+
(newest, child) =>
|
|
48
|
+
child.status === 'running' && child.background === true && (newest === null || child.startedAt > newest)
|
|
49
|
+
? child.startedAt
|
|
50
|
+
: newest,
|
|
51
|
+
null,
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
41
55
|
type AgentSessionEvent =
|
|
42
56
|
| { type: 'message_update'; assistantMessageEvent: { type: string; delta?: string } }
|
|
43
57
|
| { type: 'message_end'; message: unknown }
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Plain-`git` analog of analyzeGhCommand. Git names its target indirectly, so
|
|
2
2
|
// this analyzer resolves configured remotes before selecting a per-repo token.
|
|
3
3
|
|
|
4
|
+
import { mapVirtualTmpPath } from '@/sandbox'
|
|
5
|
+
|
|
4
6
|
export type GitCommandDecision =
|
|
5
7
|
| { kind: 'pass-through' }
|
|
6
8
|
| { kind: 'block'; reason: string }
|
|
@@ -41,6 +43,27 @@ export const defaultGitResolvers: GitResolvers = {
|
|
|
41
43
|
resolveCurrentBranch: (cwd) => runGit(cwd, ['symbolic-ref', '--short', 'HEAD']),
|
|
42
44
|
}
|
|
43
45
|
|
|
46
|
+
// Sandboxed bash sees the per-session scratch dir bound over `/tmp`
|
|
47
|
+
// (applyBashSandbox), but these resolvers spawn `git` from the runtime process
|
|
48
|
+
// against the REAL container `/tmp` — so a repo the model cloned to `/tmp/foo`
|
|
49
|
+
// resolves to nothing here and the command falls through UNBROKERED, leaving git
|
|
50
|
+
// to die on a credential prompt it can never answer. Same class of bug the file
|
|
51
|
+
// tools solve with TMP_REDIRECT_TOOLS. Only the filesystem probe is redirected:
|
|
52
|
+
// the analyzer must keep reasoning in model-facing paths so `rewrittenCommand`
|
|
53
|
+
// stays valid inside the sandbox.
|
|
54
|
+
export function createSessionTmpGitResolvers(
|
|
55
|
+
agentDir: string,
|
|
56
|
+
sessionId: string,
|
|
57
|
+
base: GitResolvers = defaultGitResolvers,
|
|
58
|
+
): GitResolvers {
|
|
59
|
+
const backing = (cwd: string): string => mapVirtualTmpPath(agentDir, sessionId, cwd) ?? cwd
|
|
60
|
+
return {
|
|
61
|
+
resolveRemoteUrl: (cwd, remote, forPush) => base.resolveRemoteUrl(backing(cwd), remote, forPush),
|
|
62
|
+
resolveConfig: (cwd, key) => base.resolveConfig(backing(cwd), key),
|
|
63
|
+
resolveCurrentBranch: (cwd) => base.resolveCurrentBranch(backing(cwd)),
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
44
67
|
const MULTI_OWNER_REASON =
|
|
45
68
|
'This git command targets more than one repository; a single minted GitHub App ' +
|
|
46
69
|
'token is scoped to one repo and cannot authenticate all of them. Split it into ' +
|
|
@@ -16,7 +16,12 @@ import {
|
|
|
16
16
|
usesGhApiGraphqlEndpoint,
|
|
17
17
|
} from './gh-command'
|
|
18
18
|
import { ensureGitAskPassHelper, resolveSandboxGitAskPassPath } from './git-askpass'
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
analyzeGitCommand,
|
|
21
|
+
createSessionTmpGitResolvers,
|
|
22
|
+
defaultGitResolvers,
|
|
23
|
+
resolveGhDefaultRepoFromCwd,
|
|
24
|
+
} from './git-command'
|
|
20
25
|
import { checkGraphqlAuthNudge } from './graphql-auth-nudge'
|
|
21
26
|
import { commitReviewIfSucceeded, noteReviewCommand } from './review-recorder'
|
|
22
27
|
import { classifyGhToken, shouldMintAppToken } from './token-class'
|
|
@@ -351,9 +356,13 @@ export default definePlugin({
|
|
|
351
356
|
event: { args: Record<string, unknown> }
|
|
352
357
|
command: string
|
|
353
358
|
agentDir: string
|
|
359
|
+
sessionId: string
|
|
354
360
|
}): Promise<HookResult> => {
|
|
355
|
-
const { event, command, agentDir } = params
|
|
356
|
-
const decision = await analyzeGitCommand(command, {
|
|
361
|
+
const { event, command, agentDir, sessionId } = params
|
|
362
|
+
const decision = await analyzeGitCommand(command, {
|
|
363
|
+
cwd: agentDir,
|
|
364
|
+
resolvers: createSessionTmpGitResolvers(agentDir, sessionId),
|
|
365
|
+
})
|
|
357
366
|
if (decision.kind === 'pass-through') return
|
|
358
367
|
if (decision.kind === 'block') return { block: true, reason: decision.reason }
|
|
359
368
|
|
|
@@ -410,7 +419,7 @@ export default definePlugin({
|
|
|
410
419
|
}
|
|
411
420
|
|
|
412
421
|
if (command.includes('git')) {
|
|
413
|
-
return await handleGitCommand({ event, command, agentDir: ctx.agentDir })
|
|
422
|
+
return await handleGitCommand({ event, command, agentDir: ctx.agentDir, sessionId: event.sessionId })
|
|
414
423
|
}
|
|
415
424
|
return
|
|
416
425
|
},
|
package/src/channels/router.ts
CHANGED
|
@@ -214,7 +214,12 @@ export function disengageReactionEmojiFor(adapter: AdapterId): string {
|
|
|
214
214
|
return DISENGAGE_REACTION_EMOJI_OVERRIDES[adapter] ?? DISENGAGE_REACTION_EMOJI
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
-
type SilentAckReason =
|
|
217
|
+
type SilentAckReason =
|
|
218
|
+
| 'skip_response'
|
|
219
|
+
| 'no_reply'
|
|
220
|
+
| 'skip_response_text_leak'
|
|
221
|
+
| 'github_review_output'
|
|
222
|
+
| 'awaiting_background_child'
|
|
218
223
|
|
|
219
224
|
// Wake nudge pushed into a resumed channel session at boot so drain() has a
|
|
220
225
|
// non-empty batch and fires a turn. The substantive instruction the model acts
|
|
@@ -1004,6 +1009,13 @@ type LiveSession = {
|
|
|
1004
1009
|
// counter is purely monotonic; the matching comparison is what protects
|
|
1005
1010
|
// against stale state.
|
|
1006
1011
|
turnSeq: number
|
|
1012
|
+
// Clock time the current LOGICAL turn opened — stamped only on a real user
|
|
1013
|
+
// batch, so the reminder-only iterations a retry queues stay inside the same
|
|
1014
|
+
// logical turn. Unlike `turnSeq` (which increments per drain iteration) this
|
|
1015
|
+
// gives background-child checks a boundary they can compare a child's
|
|
1016
|
+
// `startedAt` against, to tell "this turn spawned it" from "it was already
|
|
1017
|
+
// running when unrelated work arrived".
|
|
1018
|
+
logicalTurnStartedAt: number
|
|
1007
1019
|
// Snapshot of `successfulChannelSends` taken at turn start (same
|
|
1008
1020
|
// moment `turnSeq` increments). Lets `markTurnSkipped` detect "a
|
|
1009
1021
|
// channel send already landed in this turn" and reject the skip,
|
|
@@ -2050,6 +2062,23 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
|
|
|
2050
2062
|
return false
|
|
2051
2063
|
}
|
|
2052
2064
|
|
|
2065
|
+
// Same question as the GC/rollover pin, asked for a different decision: while a
|
|
2066
|
+
// background child is still working (and inside the stuck backstop), an empty
|
|
2067
|
+
// completion from the parent is the subagent contract being honored, not the
|
|
2068
|
+
// provider degeneration the turn-recovery ladder exists to repair.
|
|
2069
|
+
//
|
|
2070
|
+
// Turn-scoped, unlike the GC pin, which is deliberately session-scoped. Only
|
|
2071
|
+
// the logical turn that spawned the child is waiting on it; a later inbound is
|
|
2072
|
+
// unrelated work whose own recovery, todo continuation and staged fallback must
|
|
2073
|
+
// still run. Session scope would let one long-running child silence every
|
|
2074
|
+
// subsequent turn, and a wedged child would strand them with nothing to revisit
|
|
2075
|
+
// them after the backstop expires.
|
|
2076
|
+
const isAwaitingBackgroundChild = (live: LiveSession, label: string): boolean => {
|
|
2077
|
+
const childStartedAt = newestRunningChildSubagentStartedAt(live.sessionId)
|
|
2078
|
+
if (childStartedAt === null || childStartedAt < live.logicalTurnStartedAt) return false
|
|
2079
|
+
return isPinnedByRunningChild(live.sessionId, live.keyId, label)
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2053
2082
|
const shouldRolloverLive = (live: LiveSession, idleMs: number): boolean => {
|
|
2054
2083
|
// A session mid-prompt looks idle by lastInboundAt (only bumped on engaged
|
|
2055
2084
|
// inbounds) while session.prompt() is still in flight; rolling it over aborts
|
|
@@ -2337,6 +2366,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
|
|
|
2337
2366
|
sendTimestamps: new Map(),
|
|
2338
2367
|
successfulChannelSends: 0,
|
|
2339
2368
|
turnSeq: 0,
|
|
2369
|
+
logicalTurnStartedAt: now(),
|
|
2340
2370
|
successfulSendsAtTurnStart: 0,
|
|
2341
2371
|
inFlightToolSends: new Map(),
|
|
2342
2372
|
policyDeniedToolSendsThisTurn: new Map(),
|
|
@@ -3258,6 +3288,7 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
|
|
|
3258
3288
|
live.toolLeakRetries = 0
|
|
3259
3289
|
live.emptyStopAfterToolWorkArmed = false
|
|
3260
3290
|
live.willingnessNudges = 0
|
|
3291
|
+
live.logicalTurnStartedAt = now()
|
|
3261
3292
|
// A fresh batch supersedes a still-pending staged fallback. That staged
|
|
3262
3293
|
// turn produced no usable reply, so it must not leave the PRIOR turn's
|
|
3263
3294
|
// committed lastQuestionSignal behind — otherwise the new question would
|
|
@@ -3487,10 +3518,18 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
|
|
|
3487
3518
|
logger.warn(`[channels] ${live.keyId}: skipping todo continuation after failed outcome write`)
|
|
3488
3519
|
} else if (live.userStoppedTurnSeq === live.turnSeq) {
|
|
3489
3520
|
logger.info(`[channels] ${live.keyId}: skipping todo continuation after user stop`)
|
|
3521
|
+
} else if (isAwaitingBackgroundChild(live, 'todo-continuation')) {
|
|
3522
|
+
// The outstanding todo is usually the very work the running child was
|
|
3523
|
+
// spawned to do, so continuing here re-wakes a session that is
|
|
3524
|
+
// deliberately waiting and asks the model to report progress it does
|
|
3525
|
+
// not have yet. The child's completion reminder is the correct wake.
|
|
3526
|
+
logger.info(`[channels] ${live.keyId}: skipping todo continuation while background child runs`)
|
|
3490
3527
|
} else {
|
|
3491
3528
|
await maybeContinueTodosChannel(live)
|
|
3492
3529
|
}
|
|
3493
|
-
|
|
3530
|
+
if (!isAwaitingBackgroundChild(live, 'staged-fallback')) {
|
|
3531
|
+
await resolveStagedFallback(live)
|
|
3532
|
+
}
|
|
3494
3533
|
live.lastTurnAuthorIds = new Set(live.currentTurnAuthorIds)
|
|
3495
3534
|
if (live.currentTurnAuthorId !== null) {
|
|
3496
3535
|
live.lastTurnAuthorId = live.currentTurnAuthorId
|
|
@@ -4918,6 +4957,32 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
|
|
|
4918
4957
|
return
|
|
4919
4958
|
}
|
|
4920
4959
|
|
|
4960
|
+
// A background child spawned by this session is still running, and the turn
|
|
4961
|
+
// produced no user-facing output. That is `spawn_subagent`'s contract being
|
|
4962
|
+
// honored ("you will receive a system-reminder when it completes"), not the
|
|
4963
|
+
// empty-completion degeneration every branch below exists to repair — so the
|
|
4964
|
+
// recovery ladder must not manufacture the status prose the model
|
|
4965
|
+
// deliberately withheld. Each nudge re-enters with the child STILL running,
|
|
4966
|
+
// so the budgets stack (MAX_EMPTY_TURN_RETRIES + MAX_WILLINGNESS_NUDGES) into
|
|
4967
|
+
// several "still working…" messages for one request; on GitHub, where a
|
|
4968
|
+
// channel reply IS a public PR comment, that shipped as duplicate review
|
|
4969
|
+
// acknowledgements. The completion reminder re-wakes this session with the
|
|
4970
|
+
// real result, so silence here is delivery deferred, not delivery dropped.
|
|
4971
|
+
// Bounded by the same stuck-child backstop as GC/rollover: a wedged child
|
|
4972
|
+
// stops pinning and the normal ladder resumes. A leaf carrying real text is
|
|
4973
|
+
// deliberately NOT covered — recovering an answer the model already wrote is
|
|
4974
|
+
// still correct while a child runs.
|
|
4975
|
+
const awaitLeaf = recoverableAssistantText(live.session)
|
|
4976
|
+
if (
|
|
4977
|
+
live.currentTurnAuthorId !== null &&
|
|
4978
|
+
(awaitLeaf === null || endsWithNoReplySignal(awaitLeaf.text)) &&
|
|
4979
|
+
isAwaitingBackgroundChild(live, 'empty_turn_recovery')
|
|
4980
|
+
) {
|
|
4981
|
+
logger.info(`[channels] ${live.keyId} empty_turn_suppressed cause=awaiting_background_child`)
|
|
4982
|
+
armSilentTurnAck(live, 'awaiting_background_child')
|
|
4983
|
+
return
|
|
4984
|
+
}
|
|
4985
|
+
|
|
4921
4986
|
// Suppress a leaked tool call (never post the plumbing) and, while budget
|
|
4922
4987
|
// remains, push a self-correction reminder so the same logical turn
|
|
4923
4988
|
// re-prompts and the model can redo it with a real tool call. On exhaustion
|
package/src/run/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { SessionManager } from '@mariozechner/pi-coding-agent'
|
|
|
5
5
|
import { createSession, createSessionWithDispose } from '@/agent'
|
|
6
6
|
import { createProviderAuthReloadable } from '@/agent/auth-reloadable'
|
|
7
7
|
import { LiveSessionRegistry } from '@/agent/live-sessions'
|
|
8
|
-
import { LiveSubagentRegistry } from '@/agent/live-subagents'
|
|
8
|
+
import { LiveSubagentRegistry, newestRunningBackgroundChildStartedAt } from '@/agent/live-subagents'
|
|
9
9
|
import { requestContainerRestart } from '@/agent/restart'
|
|
10
10
|
import { consumeRestartHandoff } from '@/agent/restart-handoff'
|
|
11
11
|
import { sessionMetaPayload } from '@/agent/session-meta'
|
|
@@ -475,13 +475,7 @@ async function startAgentRuntime(
|
|
|
475
475
|
githubTokenBridge,
|
|
476
476
|
stream,
|
|
477
477
|
newestRunningChildSubagentStartedAt: (sessionId) =>
|
|
478
|
-
liveSubagentRegistry
|
|
479
|
-
.list({ parentSessionId: sessionId })
|
|
480
|
-
.reduce<number | null>(
|
|
481
|
-
(newest, child) =>
|
|
482
|
-
child.status === 'running' && (newest === null || child.startedAt > newest) ? child.startedAt : newest,
|
|
483
|
-
null,
|
|
484
|
-
),
|
|
478
|
+
newestRunningBackgroundChildStartedAt(liveSubagentRegistry.list({ parentSessionId: sessionId })),
|
|
485
479
|
listRunningBackgroundSubagentNames: (sessionId) =>
|
|
486
480
|
liveSubagentRegistry
|
|
487
481
|
.list({ parentSessionId: sessionId })
|