typeclaw 0.48.9 → 0.48.11

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 (48) hide show
  1. package/package.json +1 -1
  2. package/scripts/apparmor/typeclaw-bwrap +43 -0
  3. package/scripts/verify-apparmor-signals.sh +161 -0
  4. package/scripts/verify-mask-fd-sandbox.sh +176 -0
  5. package/src/agent/index.ts +9 -0
  6. package/src/agent/live-subagents.ts +98 -0
  7. package/src/agent/session-origin.ts +5 -1
  8. package/src/agent/tools/channel-reply.ts +30 -2
  9. package/src/agent/tools/channel-send.ts +19 -2
  10. package/src/agent/tools/spawn-subagent.ts +37 -1
  11. package/src/agent/tools/subagent-cancel.ts +14 -2
  12. package/src/bundled-plugins/backup/README.md +4 -3
  13. package/src/bundled-plugins/backup/runner.ts +125 -32
  14. package/src/bundled-plugins/github-cli-auth/gh-command.ts +106 -9
  15. package/src/bundled-plugins/github-cli-auth/git-command.ts +94 -9
  16. package/src/bundled-plugins/github-cli-auth/index.ts +45 -5
  17. package/src/channels/adapters/github/inbound.ts +210 -27
  18. package/src/channels/adapters/github/index.ts +16 -18
  19. package/src/channels/adapters/github/reconcile-cooldown-store.ts +15 -1
  20. package/src/channels/adapters/github/recover-failed-deliveries.ts +7 -2
  21. package/src/channels/adapters/github/review-submitter.ts +28 -0
  22. package/src/channels/adapters/instagram-continuity-store.ts +141 -0
  23. package/src/channels/adapters/instagram.ts +149 -4
  24. package/src/channels/github-repo.ts +11 -0
  25. package/src/channels/github-review-verdict-coordinator.ts +179 -29
  26. package/src/channels/github-verdict-activity.ts +12 -6
  27. package/src/channels/manager.ts +10 -0
  28. package/src/channels/persistence.ts +28 -2
  29. package/src/channels/router.ts +371 -33
  30. package/src/channels/schema.ts +18 -0
  31. package/src/channels/types.ts +11 -0
  32. package/src/cli/compose.ts +7 -4
  33. package/src/compose/restart.ts +26 -16
  34. package/src/compose/start.ts +24 -14
  35. package/src/config/config.ts +9 -1
  36. package/src/container/restart.ts +4 -0
  37. package/src/container/shared.ts +30 -3
  38. package/src/container/start.ts +137 -56
  39. package/src/doctor/apparmor.ts +101 -0
  40. package/src/doctor/checks.ts +2 -0
  41. package/src/hostd/daemon.ts +40 -17
  42. package/src/init/dockerfile.ts +7 -6
  43. package/src/init/windows-dev-link.ts +34 -2
  44. package/src/run/channel-session-factory.ts +35 -15
  45. package/src/run/index.ts +1 -0
  46. package/src/sandbox/availability.ts +7 -5
  47. package/src/skills/typeclaw-channel-github/SKILL.md +4 -2
  48. package/typeclaw.schema.json +7 -0
@@ -185,6 +185,7 @@ export const DEFAULT_GITHUB_EVENT_ALLOWLIST = [
185
185
  'discussion_comment.created',
186
186
  'issues.opened',
187
187
  'pull_request.opened',
188
+ 'pull_request.converted_to_draft',
188
189
  'pull_request.ready_for_review',
189
190
  'pull_request.review_requested',
190
191
  'pull_request.review_request_removed',
@@ -234,6 +235,22 @@ const GITHUB_EVENT_ALLOWLIST_V3 = [
234
235
  'discussion.created',
235
236
  'pull_request_review.submitted',
236
237
  ] as const
238
+ // - v4: added synchronize (the default just before converted_to_draft was
239
+ // added). Snapshotted here so configs seeded with the pre-draft-abort
240
+ // default unfreeze and re-track the new default.
241
+ const GITHUB_EVENT_ALLOWLIST_V4 = [
242
+ 'issue_comment.created',
243
+ 'pull_request_review_comment.created',
244
+ 'discussion_comment.created',
245
+ 'issues.opened',
246
+ 'pull_request.opened',
247
+ 'pull_request.ready_for_review',
248
+ 'pull_request.review_requested',
249
+ 'pull_request.review_request_removed',
250
+ 'pull_request.synchronize',
251
+ 'discussion.created',
252
+ 'pull_request_review.submitted',
253
+ ] as const
237
254
 
238
255
  // Every event-allowlist that `channel add` / `init` has ever seeded verbatim
239
256
  // into typeclaw.json, oldest first, current default last. The legacy-shape
@@ -246,6 +263,7 @@ export const SEEDED_GITHUB_EVENT_ALLOWLISTS: readonly (readonly string[])[] = [
246
263
  GITHUB_EVENT_ALLOWLIST_V1,
247
264
  GITHUB_EVENT_ALLOWLIST_V2,
248
265
  GITHUB_EVENT_ALLOWLIST_V3,
266
+ GITHUB_EVENT_ALLOWLIST_V4,
249
267
  DEFAULT_GITHUB_EVENT_ALLOWLIST,
250
268
  ]
251
269
 
@@ -55,12 +55,23 @@ export type GithubReviewFollowupRound = {
55
55
  carrierThread: string | null
56
56
  }
57
57
 
58
+ export type GithubReviewThreadCloseout = {
59
+ workspace: string
60
+ prNumber: number
61
+ rootCommentId: string
62
+ deferUntil?: { kind: 'review-state-unknown'; expiresAt: number }
63
+ }
64
+
58
65
  export type InboundMessage = {
59
66
  adapter: AdapterId
60
67
  workspace: string
61
68
  chat: string
62
69
  thread: string | null
63
70
  githubReviewRound?: GithubReviewFollowupRound
71
+ // Adapter-authoritative obligation created only for a non-self reply whose
72
+ // review-thread ROOT comment was authored by this agent. Kept separate from
73
+ // replyToBotMessageId, which describes only the immediate parent.
74
+ githubReviewThreadCloseout?: GithubReviewThreadCloseout
64
75
  // Structural "this message lives in a thread room" signal, kept SEPARATE
65
76
  // from `thread`. `thread` is a reply-routing field whose meaning differs per
66
77
  // platform: Slack puts the thread ts here (so `thread !== null` ⇒ thread
@@ -306,8 +306,11 @@ export const composeCommand = defineCommand({
306
306
  // Single clack spinner with a multi-line message body, one line per agent.
307
307
  // Concurrent clack spinners can't coexist: each one's render loop writes
308
308
  // cursor.to(0) + erase.down() to process.stdout, so they trample each other.
309
- // Multi-line redraw is safe — clack counts newlines in the previous message
310
- // and walks the cursor up before erasing (see @clack/prompts spinner.ts).
309
+ // Multi-line redraw is safe while this board owns the terminal — clack counts
310
+ // newlines in the previous message and walks the cursor up before erasing (see
311
+ // @clack/prompts spinner.ts). Compose start/restart therefore capture process
312
+ // output instead of letting child progress or warnings invalidate clack's
313
+ // cursor position.
311
314
  type Board = {
312
315
  add: (s: ReturnType<typeof spinner>, name: string, state: string) => void
313
316
  set: (s: ReturnType<typeof spinner>, name: string, state: string) => void
@@ -356,7 +359,7 @@ function makeBoard(header: string): Board {
356
359
  }
357
360
 
358
361
  function formatStartDone<T extends { alreadyRunning?: boolean; hostPort: number }>(result: AgentResult<T>): string {
359
- if (!result.ok) return `${c.red('✖')} ${c.red('failed:')} ${result.reason}`
362
+ if (!result.ok) return appendWarnings(`${c.red('✖')} ${c.red('failed:')} ${result.reason}`, result.warnings)
360
363
  const verb = result.data.alreadyRunning ? 'already running' : 'started'
361
364
  const head = `${c.green('✔')} ${verb} on host port ${c.cyan(String(result.data.hostPort))}`
362
365
  return appendWarnings(head, result.warnings)
@@ -369,7 +372,7 @@ function formatStopDone<T extends { running: boolean }>(result: AgentResult<T>):
369
372
  }
370
373
 
371
374
  function formatRestartDone<T extends { start: { hostPort: number } }>(result: AgentResult<T>): string {
372
- if (!result.ok) return `${c.red('✖')} ${c.red('failed:')} ${result.reason}`
375
+ if (!result.ok) return appendWarnings(`${c.red('✖')} ${c.red('failed:')} ${result.reason}`, result.warnings)
373
376
  const head = `${c.green('✔')} restarted on host port ${c.cyan(String(result.data.start.hostPort))}`
374
377
  return appendWarnings(head, result.warnings)
375
378
  }
@@ -1,5 +1,5 @@
1
1
  import { validateConfig } from '@/config'
2
- import { resolveController } from '@/container'
2
+ import { type Controller, resolveController } from '@/container'
3
3
 
4
4
  import { discoverAgents, type AgentEntry } from './discover'
5
5
  import type { AgentResult, StartSuccess } from './start'
@@ -20,25 +20,32 @@ export type ComposeRestartOptions = {
20
20
  onProgress?: (event: ComposeRestartEvent) => void
21
21
  }
22
22
 
23
+ export type ComposeRestartDeps = {
24
+ restart?: Controller['restart']
25
+ }
26
+
23
27
  export type ComposeRestartResult = {
24
28
  agents: AgentEntry[]
25
29
  results: AgentResult<RestartData>[]
26
30
  }
27
31
 
28
- export async function composeRestart({
29
- rootCwd,
30
- preferredHostPort,
31
- forceBuild = false,
32
- cliEntry,
33
- onProgress,
34
- }: ComposeRestartOptions): Promise<ComposeRestartResult> {
32
+ export async function composeRestart(
33
+ { rootCwd, preferredHostPort, forceBuild = false, cliEntry, onProgress }: ComposeRestartOptions,
34
+ { restart = (options) => resolveController().restart(options) }: ComposeRestartDeps = {},
35
+ ): Promise<ComposeRestartResult> {
35
36
  const agents = discoverAgents(rootCwd)
36
37
  const results = await Promise.all(
37
38
  agents.map(async (agent): Promise<AgentResult<RestartData>> => {
38
39
  onProgress?.({ kind: 'agent-start', name: agent.name })
39
- const result = await runOne(agent.name, agent.cwd, preferredHostPort, forceBuild, cliEntry, () => {
40
- onProgress?.({ kind: 'agent-stopped', name: agent.name })
41
- })
40
+ const result = await runOne(
41
+ agent.name,
42
+ agent.cwd,
43
+ preferredHostPort,
44
+ forceBuild,
45
+ cliEntry,
46
+ () => onProgress?.({ kind: 'agent-stopped', name: agent.name }),
47
+ restart,
48
+ )
42
49
  onProgress?.({ kind: 'agent-done', name: agent.name, result })
43
50
  return result
44
51
  }),
@@ -53,26 +60,29 @@ async function runOne(
53
60
  forceBuild: boolean,
54
61
  cliEntry: string | undefined,
55
62
  onStopped: () => void,
63
+ restart: Controller['restart'],
56
64
  ): Promise<AgentResult<RestartData>> {
57
65
  const validated = validateConfig(cwd)
58
66
  if (!validated.ok) return { name, ok: false, reason: validated.reason }
67
+ const warnings = [...(validated.warnings ?? [])]
59
68
  try {
60
- const controller = resolveController()
61
- const restarted = await controller.restart({
69
+ const restarted = await restart({
62
70
  cwd,
63
71
  preferredHostPort,
64
72
  forceBuild,
65
73
  cliEntry,
66
74
  onStopped,
75
+ streamOutput: false,
76
+ onWarning: (warning) => warnings.push(warning),
67
77
  })
68
- if (!restarted.ok) return { name, ok: false, reason: restarted.reason }
78
+ if (!restarted.ok) return { name, ok: false, reason: restarted.reason, warnings }
69
79
  return {
70
80
  name,
71
81
  ok: true,
72
82
  data: { stop: restarted.stop, start: restarted.start },
73
- warnings: validated.warnings,
83
+ warnings,
74
84
  }
75
85
  } catch (error) {
76
- return { name, ok: false, reason: error instanceof Error ? error.message : String(error) }
86
+ return { name, ok: false, reason: error instanceof Error ? error.message : String(error), warnings }
77
87
  }
78
88
  }
@@ -1,11 +1,11 @@
1
1
  import { validateConfig } from '@/config'
2
- import { resolveController, type StartResult } from '@/container'
2
+ import { type Controller, resolveController, type StartResult } from '@/container'
3
3
 
4
4
  import { discoverAgents, type AgentEntry } from './discover'
5
5
 
6
6
  export type AgentResult<T> =
7
7
  | { name: string; ok: true; data: T; warnings?: string[] }
8
- | { name: string; ok: false; reason: string }
8
+ | { name: string; ok: false; reason: string; warnings?: string[] }
9
9
 
10
10
  export type StartSuccess = Extract<StartResult, { ok: true }>
11
11
 
@@ -21,23 +21,24 @@ export type ComposeStartOptions = {
21
21
  onProgress?: (event: ComposeStartEvent) => void
22
22
  }
23
23
 
24
+ export type ComposeStartDeps = {
25
+ start?: Controller['start']
26
+ }
27
+
24
28
  export type ComposeStartResult = {
25
29
  agents: AgentEntry[]
26
30
  results: AgentResult<StartSuccess>[]
27
31
  }
28
32
 
29
- export async function composeStart({
30
- rootCwd,
31
- preferredHostPort,
32
- forceBuild = false,
33
- cliEntry,
34
- onProgress,
35
- }: ComposeStartOptions): Promise<ComposeStartResult> {
33
+ export async function composeStart(
34
+ { rootCwd, preferredHostPort, forceBuild = false, cliEntry, onProgress }: ComposeStartOptions,
35
+ { start = (options) => resolveController().start(options) }: ComposeStartDeps = {},
36
+ ): Promise<ComposeStartResult> {
36
37
  const agents = discoverAgents(rootCwd)
37
38
  const results = await Promise.all(
38
39
  agents.map(async (agent): Promise<AgentResult<StartSuccess>> => {
39
40
  onProgress?.({ kind: 'agent-start', name: agent.name })
40
- const result = await runOne(agent.name, agent.cwd, preferredHostPort, forceBuild, cliEntry)
41
+ const result = await runOne(agent.name, agent.cwd, preferredHostPort, forceBuild, cliEntry, start)
41
42
  onProgress?.({ kind: 'agent-done', name: agent.name, result })
42
43
  return result
43
44
  }),
@@ -51,14 +52,23 @@ async function runOne(
51
52
  preferredHostPort: number,
52
53
  forceBuild: boolean,
53
54
  cliEntry: string | undefined,
55
+ start: Controller['start'],
54
56
  ): Promise<AgentResult<StartSuccess>> {
55
57
  const validated = validateConfig(cwd)
56
58
  if (!validated.ok) return { name, ok: false, reason: validated.reason }
59
+ const warnings = [...(validated.warnings ?? [])]
57
60
  try {
58
- const data = await resolveController().start({ cwd, preferredHostPort, forceBuild, cliEntry })
59
- if (!data.ok) return { name, ok: false, reason: data.reason }
60
- return { name, ok: true, data, warnings: validated.warnings }
61
+ const data = await start({
62
+ cwd,
63
+ preferredHostPort,
64
+ forceBuild,
65
+ cliEntry,
66
+ streamOutput: false,
67
+ onWarning: (warning) => warnings.push(warning),
68
+ })
69
+ if (!data.ok) return { name, ok: false, reason: data.reason, warnings }
70
+ return { name, ok: true, data, warnings }
61
71
  } catch (error) {
62
- return { name, ok: false, reason: error instanceof Error ? error.message : String(error) }
72
+ return { name, ok: false, reason: error instanceof Error ? error.message : String(error), warnings }
63
73
  }
64
74
  }
@@ -480,13 +480,21 @@ export const symlinkSchema = z.object({
480
480
 
481
481
  export type SandboxSymlink = z.infer<typeof symlinkSchema>
482
482
 
483
+ // Docker treats the profile as one argument, but keeping the value to the
484
+ // kernel profile-name alphabet prevents whitespace or option-like text from
485
+ // turning a hand-edited config into ambiguous docker argv.
486
+ const apparmorProfileSchema = z
487
+ .string()
488
+ .regex(/^[A-Za-z0-9_.-]+$/, 'AppArmor profile must be non-empty and contain only letters, digits, _, ., or -')
489
+
483
490
  export const sandboxSchema = z
484
491
  .object({
492
+ apparmorProfile: apparmorProfileSchema.default('unconfined'),
485
493
  realProc: z.boolean().default(false),
486
494
  writablePaths: z.array(relativeAgentPathSchema).default([]),
487
495
  symlinks: z.array(symlinkSchema).default([]),
488
496
  })
489
- .default({ realProc: false, writablePaths: [], symlinks: [] })
497
+ .default({ apparmorProfile: 'unconfined', realProc: false, writablePaths: [], symlinks: [] })
490
498
 
491
499
  export type SandboxConfig = z.infer<typeof sandboxSchema>
492
500
 
@@ -6,6 +6,8 @@ export type RestartOptions = {
6
6
  cwd: string
7
7
  preferredHostPort: number
8
8
  forceBuild?: boolean
9
+ streamOutput?: boolean
10
+ onWarning?: (warning: string) => void
9
11
  cliEntry?: string
10
12
  reuseCurrentHostDaemon?: boolean
11
13
  currentHostDaemon?: CurrentHostDaemon
@@ -44,6 +46,8 @@ async function restartWithLease(
44
46
  cwd: options.cwd,
45
47
  preferredHostPort: options.preferredHostPort,
46
48
  forceBuild: options.forceBuild,
49
+ streamOutput: options.streamOutput,
50
+ onWarning: options.onWarning,
47
51
  cliEntry: options.cliEntry,
48
52
  reuseCurrentHostDaemon: options.reuseCurrentHostDaemon,
49
53
  currentHostDaemon: options.currentHostDaemon,
@@ -20,6 +20,10 @@ export type DockerExecOptions = {
20
20
  // stay visible to the user while start() still inspects stderr to detect the
21
21
  // missing-credential-helper failure and decide whether to retry.
22
22
  captureStderr?: boolean
23
+ // Piped commands normally retain complete output. Long-running callers can
24
+ // still drain without retaining stdout and keep only stderr's diagnostic tail.
25
+ captureStdout?: boolean
26
+ maxCapturedStderrBytes?: number
23
27
  }
24
28
 
25
29
  export type DockerExec = (args: string[], options?: DockerExecOptions) => Promise<DockerExecResult>
@@ -83,9 +87,9 @@ export const defaultDockerExec: DockerExec = async (args, options) => {
83
87
  signal: options?.signal,
84
88
  env,
85
89
  })
86
- const exitCode = await proc.exited
87
- const stdout = await new Response(proc.stdout).text()
88
- const stderr = await new Response(proc.stderr).text()
90
+ const stdoutPromise = readCapturedStream(proc.stdout, options?.captureStdout === false ? 0 : undefined)
91
+ const stderrPromise = readCapturedStream(proc.stderr, options?.maxCapturedStderrBytes)
92
+ const [exitCode, stdout, stderr] = await Promise.all([proc.exited, stdoutPromise, stderrPromise])
89
93
  return { exitCode, stdout, stderr }
90
94
  } catch (error) {
91
95
  if ((error as NodeJS.ErrnoException)?.code === 'ENOENT') {
@@ -95,6 +99,29 @@ export const defaultDockerExec: DockerExec = async (args, options) => {
95
99
  }
96
100
  }
97
101
 
102
+ export async function readCapturedStream(stream: ReadableStream<Uint8Array>, maxBytes?: number): Promise<string> {
103
+ if (maxBytes === undefined) return await new Response(stream).text()
104
+ if (!Number.isSafeInteger(maxBytes) || maxBytes < 0) throw new RangeError('maxBytes must be a non-negative integer')
105
+
106
+ const reader = stream.getReader()
107
+ let tail = Buffer.alloc(0)
108
+ try {
109
+ for (;;) {
110
+ const { done, value } = await reader.read()
111
+ if (done) break
112
+ if (maxBytes === 0) continue
113
+ const chunk = Buffer.from(value)
114
+ tail =
115
+ chunk.length >= maxBytes
116
+ ? chunk.subarray(chunk.length - maxBytes)
117
+ : Buffer.concat([tail, chunk]).subarray(-maxBytes)
118
+ }
119
+ } finally {
120
+ reader.releaseLock()
121
+ }
122
+ return tail.toString('utf8')
123
+ }
124
+
98
125
  // Streams a docker child's stdout straight to the parent terminal while teeing
99
126
  // stderr to BOTH the terminal and a buffer. A plain `stderr: 'inherit'` would
100
127
  // keep the build output live but leave start() blind to the failure reason;