typeclaw 0.48.12 → 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.
Files changed (213) hide show
  1. package/package.json +6 -3
  2. package/scripts/dump-system-prompt.ts +52 -110
  3. package/src/agent/attention-escalation.ts +8 -5
  4. package/src/agent/auth-reloadable.ts +2 -3
  5. package/src/agent/auth.ts +59 -79
  6. package/src/agent/compaction.ts +2 -2
  7. package/src/agent/index.ts +173 -85
  8. package/src/agent/live-sessions.ts +2 -2
  9. package/src/agent/live-subagents.ts +1 -0
  10. package/src/agent/llm-replay-sanitizer.ts +1 -1
  11. package/src/agent/model-overrides.ts +1 -1
  12. package/src/agent/multimodal/look-at.ts +3 -3
  13. package/src/agent/multimodal/read-redirect.ts +1 -1
  14. package/src/agent/plugin-tools.ts +76 -39
  15. package/src/agent/prompt-cache-key.ts +42 -0
  16. package/src/agent/provider-error.ts +179 -10
  17. package/src/agent/reload-tool.ts +1 -1
  18. package/src/agent/restart-handoff/index.ts +7 -14
  19. package/src/agent/reviewer-activity.ts +68 -0
  20. package/src/agent/session-origin.ts +33 -0
  21. package/src/agent/subagents.ts +14 -2
  22. package/src/agent/system-prompt.ts +68 -202
  23. package/src/agent/todo/continuation-policy.ts +12 -4
  24. package/src/agent/tool-error-remediation.ts +1 -1
  25. package/src/agent/tool-file-safety.ts +113 -14
  26. package/src/agent/tool-not-found-nudge.ts +1 -1
  27. package/src/agent/tool-result-budget.ts +2 -2
  28. package/src/agent/tools/channel-disengage.ts +2 -2
  29. package/src/agent/tools/channel-edit.ts +2 -2
  30. package/src/agent/tools/channel-fetch-attachment.ts +2 -2
  31. package/src/agent/tools/channel-history-render.ts +2 -1
  32. package/src/agent/tools/channel-history.ts +2 -2
  33. package/src/agent/tools/channel-react.ts +2 -2
  34. package/src/agent/tools/channel-read.ts +2 -2
  35. package/src/agent/tools/channel-reply.ts +25 -7
  36. package/src/agent/tools/channel-send.ts +51 -9
  37. package/src/agent/tools/curl-impersonate.ts +11 -2
  38. package/src/agent/tools/grant-role.ts +2 -2
  39. package/src/agent/tools/post-github-review.ts +79 -17
  40. package/src/agent/tools/restart.ts +2 -2
  41. package/src/agent/tools/skip-response.ts +4 -4
  42. package/src/agent/tools/spawn-subagent.ts +165 -14
  43. package/src/agent/tools/stream-snapshot.ts +2 -2
  44. package/src/agent/tools/subagent-cancel.ts +2 -2
  45. package/src/agent/tools/subagent-output.ts +10 -2
  46. package/src/agent/tools/todo/index.ts +2 -2
  47. package/src/agent/tools/webfetch/tool.ts +2 -2
  48. package/src/agent/tools/websearch.ts +2 -2
  49. package/src/bundled-plugins/backup/README.md +10 -9
  50. package/src/bundled-plugins/backup/runner.ts +140 -58
  51. package/src/bundled-plugins/backup/subagents.ts +58 -26
  52. package/src/bundled-plugins/github-cli-auth/gh-command.ts +34 -2
  53. package/src/bundled-plugins/github-cli-auth/granted-push.ts +135 -0
  54. package/src/bundled-plugins/github-cli-auth/index.ts +83 -11
  55. package/src/bundled-plugins/github-cli-auth/review-account.ts +23 -0
  56. package/src/bundled-plugins/github-cli-auth/review-checkout.ts +9 -2
  57. package/src/bundled-plugins/github-cli-auth/review-recorder.ts +45 -7
  58. package/src/bundled-plugins/operator/operator.ts +15 -4
  59. package/src/bundled-plugins/reviewer/skills/code-review.ts +1 -1
  60. package/src/bundled-plugins/security/index.ts +50 -2
  61. package/src/bundled-plugins/security/policies/git-exfil.ts +24 -12
  62. package/src/channels/adapters/discord-bot-reactions.ts +18 -0
  63. package/src/channels/adapters/discord-bot.ts +122 -67
  64. package/src/channels/adapters/discord-reactions.ts +18 -0
  65. package/src/channels/adapters/discord.ts +114 -8
  66. package/src/channels/adapters/github/inbound.ts +103 -8
  67. package/src/channels/adapters/github/index.ts +251 -19
  68. package/src/channels/adapters/github/last-alive.ts +27 -0
  69. package/src/channels/adapters/github/outbound.ts +54 -18
  70. package/src/channels/adapters/github/pending-review-store.ts +141 -0
  71. package/src/channels/adapters/github/permission-guidance.ts +1 -0
  72. package/src/channels/adapters/github/reactions.ts +100 -0
  73. package/src/channels/adapters/github/reconcile-cooldown-store.ts +197 -67
  74. package/src/channels/adapters/github/reconcile-open-prs.ts +418 -33
  75. package/src/channels/adapters/github/recovery.ts +106 -0
  76. package/src/channels/adapters/github/review-check.ts +510 -0
  77. package/src/channels/adapters/github/review-submitter.ts +34 -2
  78. package/src/channels/adapters/instagram.ts +32 -14
  79. package/src/channels/adapters/kakaotalk.ts +22 -7
  80. package/src/channels/adapters/line.ts +18 -3
  81. package/src/channels/adapters/outbound-account.ts +20 -0
  82. package/src/channels/adapters/own-reactions.ts +66 -0
  83. package/src/channels/adapters/recovery-correlation.ts +214 -0
  84. package/src/channels/adapters/slack-bot-classify.ts +18 -11
  85. package/src/channels/adapters/slack-bot-dedupe.ts +111 -28
  86. package/src/channels/adapters/slack-bot-reactions.ts +18 -0
  87. package/src/channels/adapters/slack-bot.ts +125 -57
  88. package/src/channels/adapters/slack-classify.ts +25 -4
  89. package/src/channels/adapters/slack-inbound-revision.ts +96 -0
  90. package/src/channels/adapters/slack-reactions.ts +18 -0
  91. package/src/channels/adapters/slack-thread-ts.ts +6 -0
  92. package/src/channels/adapters/slack.ts +48 -3
  93. package/src/channels/adapters/teams.ts +14 -4
  94. package/src/channels/adapters/telegram-bot.ts +56 -10
  95. package/src/channels/adapters/webex-bot.ts +12 -2
  96. package/src/channels/adapters/webex.ts +12 -2
  97. package/src/channels/background-handoff.ts +434 -0
  98. package/src/channels/background-obligations.ts +893 -0
  99. package/src/channels/continuity-types.ts +271 -0
  100. package/src/channels/github-review-check.ts +598 -0
  101. package/src/channels/github-review-turn-ledger.ts +102 -28
  102. package/src/channels/github-review-verdict-coordinator.ts +96 -13
  103. package/src/channels/github-token-bridge.ts +11 -5
  104. package/src/channels/inbound-journal.ts +1738 -0
  105. package/src/channels/index.ts +6 -1
  106. package/src/channels/manager.ts +17 -7
  107. package/src/channels/recovery-dispatcher.ts +264 -0
  108. package/src/channels/recovery-notice.ts +94 -0
  109. package/src/channels/recovery-outbox.ts +459 -0
  110. package/src/channels/router.ts +2582 -633
  111. package/src/channels/schema.ts +8 -1
  112. package/src/channels/subagent-completion-bridge.ts +17 -14
  113. package/src/channels/types.ts +121 -16
  114. package/src/channels/waiting-reactions.ts +664 -0
  115. package/src/cli/compose.ts +7 -4
  116. package/src/cli/hostd.ts +49 -3
  117. package/src/cli/inspect.ts +11 -14
  118. package/src/cli/model.ts +7 -5
  119. package/src/cli/oauth-callbacks.ts +38 -23
  120. package/src/coding-agent/broker-body.ts +38 -0
  121. package/src/coding-agent/broker.ts +290 -0
  122. package/src/coding-agent/claude.ts +95 -0
  123. package/src/coding-agent/codex.ts +104 -0
  124. package/src/coding-agent/index.ts +506 -0
  125. package/src/coding-agent/omo-state.ts +69 -0
  126. package/src/coding-agent/omo-stream.ts +98 -0
  127. package/src/coding-agent/omo.ts +192 -0
  128. package/src/coding-agent/runner.ts +263 -0
  129. package/src/coding-agent/tool.ts +62 -0
  130. package/src/coding-agent/worktree.ts +355 -0
  131. package/src/compose/restart.ts +10 -3
  132. package/src/compose/start.ts +20 -3
  133. package/src/config/config.ts +70 -26
  134. package/src/config/providers.ts +278 -50
  135. package/src/container/exit-reason.ts +44 -0
  136. package/src/container/index.ts +5 -0
  137. package/src/container/log-archive.ts +51 -13
  138. package/src/container/memory-limit.ts +1 -1
  139. package/src/container/memory-oversubscription.ts +36 -6
  140. package/src/container/oom-events.ts +86 -0
  141. package/src/container/restart.ts +2 -0
  142. package/src/container/shared.ts +8 -1
  143. package/src/container/start.ts +25 -13
  144. package/src/container/stop.ts +6 -2
  145. package/src/container/tool-oom-priority.ts +32 -0
  146. package/src/cron/consumer.ts +10 -4
  147. package/src/cron/reloadable.ts +23 -2
  148. package/src/doctor/checks.ts +14 -2
  149. package/src/hostd/daemon.ts +20 -10
  150. package/src/hostd/spawn.ts +106 -5
  151. package/src/hostd/version.ts +20 -0
  152. package/src/hostd/watchdog.ts +241 -0
  153. package/src/init/dockerfile.ts +57 -592
  154. package/src/init/index.ts +6 -7
  155. package/src/init/oauth-login.ts +57 -17
  156. package/src/inspect/transcript-view.ts +6 -3
  157. package/src/mcp/client.ts +3 -1
  158. package/src/operations/classify-tool-outcome.ts +45 -1
  159. package/src/operations/incidents.ts +10 -5
  160. package/src/plugin/core-tool-names.ts +1 -1
  161. package/src/plugin/define.ts +1 -0
  162. package/src/plugin/index.ts +1 -0
  163. package/src/plugin/types.ts +6 -1
  164. package/src/run/background-handoff-boot.ts +86 -0
  165. package/src/run/channel-session-factory.ts +5 -4
  166. package/src/run/index.ts +93 -93
  167. package/src/run/resource-sample.ts +19 -0
  168. package/src/sandbox/build.ts +4 -0
  169. package/src/sandbox/coding-agent.ts +214 -0
  170. package/src/sandbox/policy.ts +1 -0
  171. package/src/sandbox/runtime-private.ts +4 -1
  172. package/src/secrets/coding-agent-auth.ts +97 -0
  173. package/src/secrets/index.ts +0 -16
  174. package/src/secrets/refresh-provider-oauth.ts +30 -76
  175. package/src/secrets/schema.ts +3 -4
  176. package/src/secrets/storage.ts +133 -234
  177. package/src/server/command-runner.ts +6 -2
  178. package/src/server/index.ts +102 -41
  179. package/src/sessions/index.ts +1 -1
  180. package/src/skills/typeclaw-channel-github/SKILL.md +7 -5
  181. package/src/skills/typeclaw-claude-code/SKILL.md +25 -260
  182. package/src/skills/typeclaw-claude-code/references/auth-flow.md +7 -23
  183. package/src/skills/typeclaw-claude-code/references/headless-sessions.md +11 -0
  184. package/src/skills/typeclaw-claude-code/references/results-and-worktrees.md +13 -0
  185. package/src/skills/typeclaw-codex-cli/SKILL.md +35 -270
  186. package/src/skills/typeclaw-codex-cli/references/auth-flow.md +13 -20
  187. package/src/skills/typeclaw-codex-cli/references/headless-sessions.md +26 -0
  188. package/src/skills/typeclaw-codex-cli/references/results-and-worktrees.md +28 -0
  189. package/src/skills/typeclaw-config/SKILL.md +24 -24
  190. package/src/skills/typeclaw-config/references/dockerfile.md +14 -13
  191. package/src/skills/typeclaw-cron/SKILL.md +1 -1
  192. package/src/skills/typeclaw-github-contributing/SKILL.md +2 -2
  193. package/src/skills/typeclaw-memory/SKILL.md +3 -3
  194. package/src/skills/typeclaw-omo-cli/SKILL.md +52 -0
  195. package/src/skills/typeclaw-omo-cli/references/auth-flow.md +11 -0
  196. package/src/skills/typeclaw-omo-cli/references/headless-sessions.md +11 -0
  197. package/src/skills/typeclaw-omo-cli/references/results-and-worktrees.md +23 -0
  198. package/src/skills/typeclaw-plugins/SKILL.md +20 -20
  199. package/src/skills/typeclaw-skills/SKILL.md +19 -2
  200. package/src/skills/typeclaw-troubleshooting/SKILL.md +15 -2
  201. package/src/tui/index.ts +5 -3
  202. package/src/tui/theme.ts +1 -1
  203. package/typeclaw.schema.json +44 -2
  204. package/src/agent/adaptive-thinking-compat.ts +0 -79
  205. package/src/secrets/claude-credentials-json.ts +0 -129
  206. package/src/secrets/codex-auth-json.ts +0 -102
  207. package/src/secrets/export-claude-credentials-file.ts +0 -270
  208. package/src/secrets/export-codex-auth-file.ts +0 -250
  209. package/src/secrets/oauth-xai.ts +0 -348
  210. package/src/skills/typeclaw-claude-code/references/stop-hook.md +0 -101
  211. package/src/skills/typeclaw-claude-code/references/tmux-driving.md +0 -243
  212. package/src/skills/typeclaw-codex-cli/references/stop-hook.md +0 -92
  213. package/src/skills/typeclaw-codex-cli/references/tmux-driving.md +0 -239
@@ -1,4 +1,4 @@
1
- import { SessionManager } from '@mariozechner/pi-coding-agent'
1
+ import { SessionManager } from '@earendil-works/pi-coding-agent'
2
2
  import type { Server as BunServer, ServerWebSocket } from 'bun'
3
3
 
4
4
  import {
@@ -144,6 +144,12 @@ export type ServerOptions = {
144
144
  // registry is fine — `/inspect` will report "session not live, replay
145
145
  // from JSONL only" when it can't resolve the id.
146
146
  liveSessionRegistry?: LiveSessionRegistry
147
+ // Test seam for holding an outcome write open and asserting drain ordering.
148
+ // Production always uses the real persistence function.
149
+ recordTurnOutcome?: typeof recordTurnOutcome
150
+ // Test seam: the idle/todo continuation driver invoked by the drain loop.
151
+ // Production always uses the real runIdleContinuation.
152
+ runIdleContinuation?: typeof runIdleContinuation
147
153
  }
148
154
 
149
155
  const consoleLogger: ServerLogger = {
@@ -215,6 +221,12 @@ type SessionState = {
215
221
  // not re-target this session's lifecycle hooks.
216
222
  runtimeSnapshot: PluginRuntimeState | null
217
223
  unsubTurnOutcome: Unsubscribe | null
224
+ // Serializes outcome persistence and the idle continuation decision. The
225
+ // tail always fulfills so one disk failure cannot poison every later turn;
226
+ // its value separately reports whether the latest write succeeded before
227
+ // continuation reads state.
228
+ todoOutcomeWrite: Promise<boolean>
229
+ todoContinuation: { recordTurnOutcome: typeof recordTurnOutcome; runIdleContinuation: typeof runIdleContinuation }
218
230
  // Latest turn's usage, captured from `message_end` by forwardSessionEvents and
219
231
  // read at the `done` send site (which lives outside that subscriber). Reset at
220
232
  // each turn start so a turn with no usage event sends a plain `done`.
@@ -297,6 +309,8 @@ export function createServer({
297
309
  subagentCoalescer,
298
310
  createSessionForSubagent,
299
311
  liveSessionRegistry,
312
+ recordTurnOutcome: todoOutcomeWriter = recordTurnOutcome,
313
+ runIdleContinuation: todoIdleContinuation = runIdleContinuation,
300
314
  }: ServerOptions) {
301
315
  const sessionStates = new WeakMap<Ws, SessionState>()
302
316
  const callIdToWs = new Map<string, AnyOwnerWs>()
@@ -563,6 +577,8 @@ export function createServer({
563
577
  activeClaimCode: null,
564
578
  runtimeSnapshot: runtimeSnapshot ?? null,
565
579
  unsubTurnOutcome: null,
580
+ todoOutcomeWrite: Promise.resolve(true),
581
+ todoContinuation: { recordTurnOutcome: todoOutcomeWriter, runIdleContinuation: todoIdleContinuation },
566
582
  lastUsage: null,
567
583
  dispose,
568
584
  }
@@ -573,7 +589,7 @@ export function createServer({
573
589
  }
574
590
 
575
591
  if (agentDir !== undefined) {
576
- state.unsubTurnOutcome = subscribeTurnOutcome(session, agentDir, origin, sessionFileId, logger)
592
+ state.unsubTurnOutcome = subscribeTurnOutcome(state, agentDir, logger)
577
593
  }
578
594
 
579
595
  liveSessionRegistry?.register({
@@ -976,28 +992,56 @@ function forwardSessionEvents(ws: Ws, state: SessionState, logger: ServerLogger,
976
992
  }
977
993
 
978
994
  // Record each completed turn's stopReason for the todo-continuation guard.
979
- // Ordering-independent by design: this writes the outcome from `message_end`,
980
- // and the idle path only reads the stored outcome — it never assumes the
981
- // event arrived before idle fired. An unrecognized stopReason classifies as
982
- // 'unknown', which the idle path treats as not-safe-to-continue (fail closed).
983
- function subscribeTurnOutcome(
984
- session: AgentSession,
985
- agentDir: string,
986
- origin: SessionOrigin,
987
- sessionFileId: string,
988
- logger: ServerLogger,
989
- ): Unsubscribe {
990
- return session.subscribe((event) => {
995
+ // Writes are serialized per session on `state.todoOutcomeWrite`, so an older
996
+ // outcome can never land after a newer one. Pi emits every assistant
997
+ // `message_end` before `prompt()` resolves, so by idle the turn's writes are
998
+ // all enqueued; the idle path awaits the latest tail before deciding. An
999
+ // unrecognized stopReason classifies as 'unknown', which the idle path treats
1000
+ // as not-safe-to-continue (fail closed).
1001
+ function subscribeTurnOutcome(state: SessionState, agentDir: string, logger: ServerLogger): Unsubscribe {
1002
+ return state.session.subscribe((event) => {
991
1003
  const usage = extractTurnUsage(event)
992
1004
  if (usage === null) return
993
- void recordTurnOutcome({
994
- agentDir,
995
- origin,
996
- turnId: sessionFileId,
997
- stopReason: usage.stopReason,
998
- ...(usage.tokens !== undefined ? { tokens: usage.tokens } : {}),
999
- }).catch((err) => logger.error(`[server] ${sessionFileId}: todo outcome capture failed: ${describeErr(err)}`))
1005
+ void enqueueTodoOutcomeWrite(
1006
+ state,
1007
+ {
1008
+ agentDir,
1009
+ origin: state.origin,
1010
+ turnId: state.sessionFileId,
1011
+ stopReason: usage.stopReason,
1012
+ ...(usage.tokens !== undefined ? { tokens: usage.tokens } : {}),
1013
+ },
1014
+ logger,
1015
+ )
1016
+ })
1017
+ }
1018
+
1019
+ function enqueueTodoOutcomeWrite(
1020
+ state: SessionState,
1021
+ args: Parameters<typeof recordTurnOutcome>[0],
1022
+ logger: ServerLogger,
1023
+ ): Promise<boolean> {
1024
+ const write = state.todoOutcomeWrite.then(async () => {
1025
+ try {
1026
+ await state.todoContinuation.recordTurnOutcome(args)
1027
+ return true
1028
+ } catch (err) {
1029
+ logger.error(`[server] ${state.sessionFileId}: todo outcome capture failed: ${describeErr(err)}`)
1030
+ return false
1031
+ }
1000
1032
  })
1033
+ state.todoOutcomeWrite = write
1034
+ return write
1035
+ }
1036
+
1037
+ // Resolves once the tail observed is still the latest, i.e. no write was
1038
+ // chained while awaiting. Returns whether that latest write succeeded.
1039
+ async function awaitLatestTodoOutcomeWrite(state: SessionState): Promise<boolean> {
1040
+ while (true) {
1041
+ const write = state.todoOutcomeWrite
1042
+ const succeeded = await write
1043
+ if (write === state.todoOutcomeWrite) return succeeded
1044
+ }
1001
1045
  }
1002
1046
 
1003
1047
  function forwardAssistantError(ws: Ws, message: unknown, logger: ServerLogger, sessionFileId: string): void {
@@ -1118,6 +1162,9 @@ async function drain(
1118
1162
  send(ws, { type: 'prompt_started', messageId: item.streamMessageId, text: item.text })
1119
1163
 
1120
1164
  if (agentDir !== undefined) {
1165
+ // recordTurnStart is a read-modify-write of the same state file; let
1166
+ // pending outcome writes land first so neither overwrites the other.
1167
+ await awaitLatestTodoOutcomeWrite(state)
1121
1168
  await recordTurnStart({
1122
1169
  agentDir,
1123
1170
  origin: state.origin,
@@ -1174,9 +1221,16 @@ async function drain(
1174
1221
  // the nested call would no-op and the continuation would stall until some
1175
1222
  // unrelated event woke the loop again. Enqueuing here lets the same `while`
1176
1223
  // consume it on the next iteration. Only fires when the queue is otherwise
1177
- // empty so a real user turn is never preempted by a continuation.
1224
+ // empty so a real user turn is never preempted by a continuation; the
1225
+ // queue is re-checked after awaiting this turn's outcome writes because a
1226
+ // user prompt can arrive meanwhile. A failed latest outcome write fails
1227
+ // closed: the stored outcome may be a stale earlier turn's.
1178
1228
  if (state.drainQueue.length === 0) {
1179
- await maybeContinueTodos(state, agentDir, logger)
1229
+ if (!(await awaitLatestTodoOutcomeWrite(state))) {
1230
+ logger.warn(`[server] ${state.sessionFileId}: skipping todo continuation after failed outcome write`)
1231
+ } else if (state.drainQueue.length === 0) {
1232
+ await maybeContinueTodos(state, agentDir, logger)
1233
+ }
1180
1234
  }
1181
1235
  }
1182
1236
  } finally {
@@ -1188,30 +1242,37 @@ async function drain(
1188
1242
  // prompt directly onto this session's drainQueue, tagged TODO_CONTINUATION_SOURCE
1189
1243
  // so the next drain iteration treats it as an injected (non-user) turn that does
1190
1244
  // not reset the episode budget. The enclosing drain loop consumes it; this never
1191
- // calls drain() itself.
1245
+ // calls drain() itself. The decision joins the outcome-write chain so a
1246
+ // concurrent abort's outcome write is ordered after the decision's own state
1247
+ // write instead of racing it.
1192
1248
  async function maybeContinueTodos(
1193
1249
  state: SessionState,
1194
1250
  agentDir: string | undefined,
1195
1251
  logger: ServerLogger,
1196
1252
  ): Promise<void> {
1197
1253
  if (agentDir === undefined) return
1198
- try {
1199
- await runIdleContinuation({
1200
- agentDir,
1201
- origin: state.origin,
1202
- deliver: (text) => {
1203
- state.drainQueue.push({
1204
- streamMessageId: `todo-continuation-${crypto.randomUUID()}` as StreamMessageId,
1205
- text,
1206
- delivery: 'queue',
1207
- ts: Date.now(),
1208
- source: TODO_CONTINUATION_SOURCE,
1209
- })
1210
- },
1211
- })
1212
- } catch (err) {
1213
- logger.error(`[server] ${state.sessionFileId}: todo continuation failed: ${describeErr(err)}`)
1214
- }
1254
+ const decision = state.todoOutcomeWrite.then(async () => {
1255
+ try {
1256
+ await state.todoContinuation.runIdleContinuation({
1257
+ agentDir,
1258
+ origin: state.origin,
1259
+ deliver: (text) => {
1260
+ state.drainQueue.push({
1261
+ streamMessageId: `todo-continuation-${crypto.randomUUID()}` as StreamMessageId,
1262
+ text,
1263
+ delivery: 'queue',
1264
+ ts: Date.now(),
1265
+ source: TODO_CONTINUATION_SOURCE,
1266
+ })
1267
+ },
1268
+ })
1269
+ } catch (err) {
1270
+ logger.error(`[server] ${state.sessionFileId}: todo continuation failed: ${describeErr(err)}`)
1271
+ }
1272
+ return true
1273
+ })
1274
+ state.todoOutcomeWrite = decision
1275
+ await decision
1215
1276
  }
1216
1277
 
1217
1278
  function describeErr(err: unknown): string {
@@ -1,7 +1,7 @@
1
1
  import { mkdirSync } from 'node:fs'
2
2
  import { join } from 'node:path'
3
3
 
4
- import { SessionManager } from '@mariozechner/pi-coding-agent'
4
+ import { SessionManager } from '@earendil-works/pi-coding-agent'
5
5
 
6
6
  export type SessionFactory = {
7
7
  createPersisted(): SessionManager
@@ -30,7 +30,7 @@ Before you pick an action, classify the inbound. Skipping this step is how a PR
30
30
  This gate is first because everything after it assumes the reviewer persona. "Address the review" sounds identical whether you wrote the PR or someone else did; only the author check disambiguates, and getting it wrong is what makes the agent review its own work.
31
31
 
32
32
  1. **(Someone else's PR.) Do I have an unresolved blocking obligation on it?** On any `pr:N` inbound, before anything else, check whether you owe this PR a verdict you have not yet landed. Check **both** signals below — checking only formal review state misses the very failure this gate exists to catch, because a prior block may never have become formal state:
33
- - **Formal review state.** Run the step-1 re-review query in the PR review flow (`gh api --paginate --slurp /repos/owner/repo/pulls/<N>/reviews --jq '…'` filtered to `{CHANGES_REQUESTED, APPROVED}`). If your latest **blocking decision** is `CHANGES_REQUESTED`, you have a live sticky block.
33
+ - **Formal review state.** Run the step-1 re-review query in the PR review flow (`gh api --paginate --slurp /repos/owner/repo/pulls/<N>/reviews | jq -r '…'` filtered to `{CHANGES_REQUESTED, APPROVED}`). If your latest **blocking decision** is `CHANGES_REQUESTED`, you have a live sticky block.
34
34
  - **Flat-comment blockers you authored.** A prior "request changes" may have been posted as a plain PR/issue comment instead of a formal review — in which case **no `CHANGES_REQUESTED` row exists** and the query above returns empty even though you blocked the PR in prose. So also scan your own recent comments (`gh api /repos/owner/repo/issues/<N>/comments --jq '[.[] | select(.user.login == "<your-login>")]'`) for one that requested changes / raised blockers and has not since been superseded by a formal review or a clear retraction. For routing, a blocking comment you wrote is as binding as a formal `CHANGES_REQUESTED`. **A courtesy acknowledgement is not a retraction.** A reply you posted like "nice, that closes the hole" / "thanks, looks good" / "✅" does **not** supersede or retract a blocker you raised — it is a chat ack, not a verdict, and it carries no review state. The blocker stays binding until you land a **formal** `APPROVE`/`REQUEST_CHANGES` (or dismiss your prior review). So when an earlier "✅ thanks" of yours is the only thing between your blocker and the author's address-comment, the blocker is **still live** and this inbound is a re-review — do not let your own ack downgrade it.
35
35
 
36
36
  If **either** signal shows an unresolved blocker you raised, this inbound is a **re-review** — go to the **PR review flow** regardless of how it is phrased. An author commenting "fixed both issues" / "addressed your feedback" / "pushed a fix" is a re-review trigger, **not** a thread-resolve trigger. A re-review is closed by re-deciding the verdict and landing a **formal** review via `POST /pulls/<N>/reviews`: `APPROVE` clears a sticky `CHANGES_REQUESTED`; a comment or a flat reply clears neither a formal block nor a flat-comment blocker — it just strands the verdict again, which is the original bug.
@@ -131,7 +131,7 @@ The `reviewer` subagent is the analyst; you are the integration layer between it
131
131
 
132
132
  ```sh
133
133
  # (a) formal review state
134
- gh api --paginate --slurp /repos/owner/repo/pulls/<N>/reviews --jq 'add | [.[] | select(.user.login == "<your-login>" and (.state == "CHANGES_REQUESTED" or .state == "APPROVED"))] | last | .state'
134
+ gh api --paginate --slurp /repos/owner/repo/pulls/<N>/reviews | jq -r 'add | [.[] | select(.user.login == "<your-login>" and (.state == "CHANGES_REQUESTED" or .state == "APPROVED"))] | last | .state // empty'
135
135
  # (b) flat-comment blocker you authored (when (a) is empty)
136
136
  gh api --paginate /repos/owner/repo/issues/<N>/comments --jq '[.[] | select(.user.login == "<your-login>")]'
137
137
  ```
@@ -140,7 +140,7 @@ The `reviewer` subagent is the analyst; you are the integration layer between it
140
140
 
141
141
  Two things make the formal-review query load-bearing — both are bugs if you simplify it:
142
142
  - **Filter to _decision_ states, not the latest review row.** GitHub's sticky block is cleared only by a later `APPROVED` (or a dismissal) from the same reviewer — a later `COMMENTED` review does **not** clear it. So a history of `CHANGES_REQUESTED` → `COMMENTED` is _still blocked_, even though the latest row is `COMMENTED`. Selecting `last` over the raw review list would misread that as "not a re-review". Filtering to `{CHANGES_REQUESTED, APPROVED}` first, then taking `last`, asks the right question: "what is my latest _blocking decision_, ignoring non-deciding comments?" (Dismissed reviews surface as `state: "DISMISSED"`, so they're correctly excluded from the decision set too.)
143
- - **`--paginate --slurp` is mandatory.** GitHub returns reviews 30 per page; a bot on a long-lived PR can have its blocking `CHANGES_REQUESTED` past the first page. Without paginating, that review is invisible and a genuine re-review silently falls back to the plain-comment path. `--slurp` collects every page into one array of arrays; the `add` concatenates them before filtering.
143
+ - **`--paginate --slurp` is mandatory.** GitHub returns reviews 30 per page; a bot on a long-lived PR can have its blocking `CHANGES_REQUESTED` past the first page. Without paginating, that review is invisible and a genuine re-review silently falls back to the plain-comment path. `--slurp` collects every page into one array of arrays; the `add` concatenates them before filtering. `gh` rejects `--slurp` combined with `--jq`, so the filter runs in a piped `jq` instead.
144
144
 
145
145
  2. **Spawn the `reviewer` subagent with the PR target immediately after minimal intake.** The reviewer runs on the deep profile, so it always runs in the background — you stay responsive while it works. Pass the repo, PR number, captured head SHA, captured base OID, any re-review context, and any requester focus. Also pass the exact typed identity from step 1 as `review_identity: { repo: "owner/repo", pull_request: N, head_sha: "<40-char headRefOid>", base_sha: "<40-char baseRefOid>", review_kind: "review" }`; use `review_kind: "re-review"` when step 1 found an unresolved blocking obligation. This is runtime coalescing metadata, not prose: identical repo/PR/head/base/kind jobs within this parent session share one in-flight analysis, while a new head, different base, different kind, or different parent session stays independent. Never guess or parse these fields from the request text — source both `headRefOid` and `baseRefOid` from the values returned by `gh pr view`. Do not use a base branch name as identity. Do not run `gh pr diff`, read changed files, or otherwise pre-analyze first. The reviewer acquires its own context, loads the `code-review` skill, and returns a `<review>` block whose code findings carry `location="path:line"`.
146
146
 
@@ -222,7 +222,7 @@ The `reviewer` subagent is the analyst; you are the integration layer between it
222
222
  })
223
223
  ```
224
224
 
225
- Anchor mechanics: `line` is a line number **in the file**, not a position in the diff. `side: RIGHT` is the new revision (default for additions); `side: LEFT` is the old revision (use for comments on removed lines). For multi-line comments, also set `start_line` and `start_side` (same semantics). The tool resolves the head SHA, validates anchors against the complete PR diff, moves out-of-diff findings into the top-level body, enforces approval policy, and verifies the exact returned review id/state. Its successful receipt is proof that the output landed. A receipt with `details.fallback === "comment"` means the prior `CHANGES_REQUESTED` remains live and the new review content landed as one root PR comment; treat that as complete and do not add a `channel_reply`. On failure, fix the payload or policy issue and retry; never post a flat comment claiming the review succeeded.
225
+ Anchor mechanics: `line` is a line number **in the file**, not a position in the diff. `side: RIGHT` is the new revision (default for additions); `side: LEFT` is the old revision (use for comments on removed lines). For multi-line comments, also set `start_line` and `start_side` (same semantics). Set `head_sha` to the full SHA the review covered (the `review_identity.head_sha` you gave the reviewer): the tool then refuses to post if the PR moved past that commit, and a follow-up round whose head moved requires it. If it is refused, re-review the current head before submitting. The tool resolves the head SHA, validates anchors against the complete PR diff, moves out-of-diff findings into the top-level body, enforces approval policy, and verifies the exact returned review id/state. Its successful receipt is proof that the output landed. A receipt with `details.fallback === "comment"` means the prior `CHANGES_REQUESTED` remains live and the new review content landed as one root PR comment; treat that as complete and do not add a `channel_reply`. On failure, fix the payload or policy issue and retry; never post a flat comment claiming the review succeeded.
226
226
 
227
227
  5. **The decoy reviewer is dropped for you — no action needed.** Under **GitHub App** auth, the adapter automatically removes the decoy reviewer from the PR's requested-reviewers list the moment your formal review lands (it reacts to your own `pull_request_review.submitted` webhook). Why this matters: GitHub auto-adds **you** (the App account) to the PR's reviewers when your review posts, but the **decoy** account would otherwise stay pinned as a perpetual "review requested", as if the review never happened. You do **not** need to issue a `DELETE /requested_reviewers` yourself — and you should not, since it would race the adapter's own cleanup. The removal is self-loop-safe: the adapter's `DELETE` is authenticated as the App, so the `review_request_removed` webhook carries your bot actor (`slug[bot]`) as `sender`, which the classifier drops (see "Self-loop safety" below). This is a no-op under **PAT** auth (no decoy) and for **plain-language**/**team** requests (no decoy user was placed). See [GitHub decoy reviewer](/docs/internals/github-decoy-reviewer).
228
228
 
@@ -321,7 +321,9 @@ git -C <checkout> push <remote> <branch>
321
321
 
322
322
  If the trusted store is unavailable, ask the operator to run `gh auth login --hostname github.com` on the host. The next real `typeclaw start` or `typeclaw restart` refreshes the stored account automatically; a start that finds the container already running does not.
323
323
 
324
- Then prepare the exact title, body, head branch and base branch and ask the operator to run `gh pr create --repo owner/repo --title 'Fix: ...' --head my-branch --base main --body '...'` at the host stage from that same checkout: `gh pr create` is host-stage only because it may execute local Git hooks with reusable credentials. Fix ordinary Git push errors yourself and retry; if the broker or your permissions refuse, surface the exact denial. For the PR-creation handoff, name the host-accessible `workspace/<repo>` checkout; never direct the operator to a per-session `/tmp` path.
324
+ Then open the PR yourself with every field explicit and inline: `gh pr create --repo owner/repo --title 'Fix: ...' --body '...' --head my-branch --base main` (add `--draft` if wanted). `--repo`, `--head`, `--base`, `--title` and `--body` are all required; `--fill`, `--body-file`, `--template`, `--editor`, `--web` and `--attach` are refused because they read local files or open an editor/browser while the credential is live. Without `--head`, gh would interrogate the checkout and offer to push, so always name the already-pushed branch.
325
+
326
+ Without the `gitExfil` bypass, you can still push to a repo listed in `channels.github.repos` when the github channel uses GitHub App auth, but only one plainly named branch through a configured remote — never `src:dst`, deletion, force, or tags. If `gitExfil` still refuses the push, your role can't publish to that repository. Surface the exact denial instead of retrying another way. Fix ordinary Git push errors yourself and retry. If you must hand off to the operator, name the host-accessible `workspace/<repo>` checkout; never direct the operator to a per-session `/tmp` path.
325
327
 
326
328
  For the supported issue form under App auth, TypeClaw mints a short-lived token for the explicit `--repo owner/repo` target and withholds it from sibling commands and shell expansions.
327
329