typeclaw 0.47.0 → 0.47.2

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.
@@ -27,9 +27,8 @@ let unsubscribeForwardResult: (() => void) | null = null
27
27
 
28
28
  export default definePlugin({
29
29
  plugin: async (ctx) => {
30
- for (const binPath of Object.values(KNOWN_BIN_PATHS)) {
31
- logInstallResult(ctx.logger, safeInstallShim(binPath))
32
- }
30
+ logInstallResult(ctx.logger, safeInstallShim(KNOWN_BIN_PATHS.global))
31
+ logInstallResult(ctx.logger, safeInstallShim(KNOWN_BIN_PATHS.local, KNOWN_BIN_PATHS.global))
33
32
 
34
33
  requestDashboardForward(ctx.logger)
35
34
 
@@ -86,9 +85,9 @@ async function recordProxyPort(contents: string, logger: { warn: (msg: string) =
86
85
  }
87
86
  }
88
87
 
89
- function safeInstallShim(binPath: string): SafeResult {
88
+ function safeInstallShim(binPath: string, delegateTarget?: string): SafeResult {
90
89
  try {
91
- return installShim({ binPath })
90
+ return installShim({ binPath, delegateTarget })
92
91
  } catch (error) {
93
92
  return { kind: 'error', binPath, error }
94
93
  }
@@ -102,6 +101,10 @@ function logInstallResult(
102
101
  logger.info(`installed agent-browser shim at ${result.binPath} (real bin stashed at ${result.stashTarget})`)
103
102
  return
104
103
  }
104
+ if (result.kind === 'delegated') {
105
+ logger.info(`installed agent-browser alias at ${result.binPath} (delegates to ${result.delegateTarget})`)
106
+ return
107
+ }
105
108
  if (result.kind === 'already-installed') {
106
109
  logger.info(`agent-browser shim already installed at ${result.binPath}`)
107
110
  return
@@ -16,11 +16,14 @@ const DEFAULT_GLOBAL_BIN_PATH = '/usr/local/bin/agent-browser'
16
16
  const DEFAULT_LOCAL_BIN_PATH = '/agent/node_modules/.bin/agent-browser'
17
17
  const STASH_ROOT = '/usr/local/lib/typeclaw-agent-browser'
18
18
  const SHIM_MARKER = '# typeclaw-agent-browser-shim'
19
+ const IMAGE_WRAPPER_MARKER = '# typeclaw-agent-browser-image-wrapper'
20
+ const LOCAL_ALIAS_MARKER = '# typeclaw-agent-browser-local-alias'
19
21
 
20
22
  export type InstallShimOptions = {
21
23
  binPath?: string
22
24
  stashDir?: string
23
25
  shimEntry?: string
26
+ delegateTarget?: string
24
27
  fs?: ShimFs
25
28
  }
26
29
 
@@ -42,6 +45,7 @@ export type ShimFs = {
42
45
 
43
46
  export type InstallShimResult =
44
47
  | { kind: 'installed'; realBin: string; binPath: string; stashTarget: string }
48
+ | { kind: 'delegated'; binPath: string; delegateTarget: string }
45
49
  | { kind: 'already-installed'; binPath: string }
46
50
  | { kind: 'no-upstream'; binPath: string }
47
51
 
@@ -55,13 +59,15 @@ export function installShim(opts: InstallShimOptions = {}): InstallShimResult {
55
59
  const stat = fs.lstat(binPath)
56
60
  if (stat === null) return { kind: 'no-upstream', binPath }
57
61
 
58
- if (isAlreadyShim(binPath, fs)) {
62
+ const wrapperKind = getWrapperKind(binPath, fs)
63
+ if (wrapperKind === 'image' || wrapperKind === 'local-alias') {
64
+ return { kind: 'already-installed', binPath }
65
+ }
66
+ if (wrapperKind === 'runtime' && opts.delegateTarget === undefined) {
59
67
  if (fs.statExists(stashTarget)) return { kind: 'already-installed', binPath }
60
- // Wrapper survived a container restart but the image-owned stash did not
61
- // (STASH_ROOT lives outside the bind-mount). The wrapper now points at a
62
- // non-existent stashTarget, so executing it would ENOENT. Drop it and
63
- // report no-upstream — there is nothing valid here to preserve, and the
64
- // global-path shim (if it exists) stands on its own.
68
+ // The stash this wrapper points at is gone (STASH_ROOT lives outside the
69
+ // bind-mount), so executing it would ENOENT. Nothing here is worth
70
+ // preserving; drop it and report no-upstream.
65
71
  fs.unlink(binPath)
66
72
  return { kind: 'no-upstream', binPath }
67
73
  }
@@ -72,6 +78,11 @@ export function installShim(opts: InstallShimOptions = {}): InstallShimResult {
72
78
  // anything — otherwise we'd stash a broken symlink and write a wrapper
73
79
  // pointing at a target that never resolves.
74
80
  if (!fs.statExists(binPath)) return { kind: 'no-upstream', binPath }
81
+ if (opts.delegateTarget !== undefined) {
82
+ fs.unlink(binPath)
83
+ fs.writeFile(binPath, renderDelegatingWrapper(opts.delegateTarget), 0o755)
84
+ return { kind: 'delegated', binPath, delegateTarget: opts.delegateTarget }
85
+ }
75
86
 
76
87
  const realBin = resolveCurrentTarget(binPath, stat, fs)
77
88
  fs.mkdirp(stashDir)
@@ -102,11 +113,14 @@ function defaultStashDir(binPath: string): string {
102
113
  return join(STASH_ROOT, slug)
103
114
  }
104
115
 
105
- function isAlreadyShim(binPath: string, fs: ShimFs): boolean {
116
+ function getWrapperKind(binPath: string, fs: ShimFs): 'image' | 'local-alias' | 'runtime' | null {
106
117
  try {
107
- return fs.readFile(binPath).includes(SHIM_MARKER)
118
+ const contents = fs.readFile(binPath)
119
+ if (contents.includes(IMAGE_WRAPPER_MARKER)) return 'image'
120
+ if (contents.includes(LOCAL_ALIAS_MARKER)) return 'local-alias'
121
+ return contents.includes(SHIM_MARKER) ? 'runtime' : null
108
122
  } catch {
109
- return false
123
+ return null
110
124
  }
111
125
  }
112
126
 
@@ -124,6 +138,13 @@ exec bun run ${shimEntry} "$@"
124
138
  `
125
139
  }
126
140
 
141
+ function renderDelegatingWrapper(delegateTarget: string): string {
142
+ return `#!/bin/sh
143
+ ${LOCAL_ALIAS_MARKER}
144
+ exec "${delegateTarget}" "$@"
145
+ `
146
+ }
147
+
127
148
  function defaultShimEntry(): string {
128
149
  return resolvePath(import.meta.dir, 'shim.ts')
129
150
  }
@@ -1,5 +1,5 @@
1
- import { hooklessGitArgs } from '@/git/hookless'
2
1
  import { resolveAgentGit } from '@/git/resolve-agent-git'
2
+ import { runGit } from '@/git/run'
3
3
  import type { ContentPart, ToolResult } from '@/plugin'
4
4
 
5
5
  export const GUARD_UNCOMMITTED_CHANGES = 'uncommittedChanges'
@@ -63,16 +63,9 @@ const defaultDeps: UncommittedChangesDeps = {
63
63
  const bun = getBun()
64
64
  if (!bun) return null
65
65
  try {
66
- const proc = bun.spawn({
67
- cmd: ['git', ...hooklessGitArgs([...gitArgs, 'status', '--porcelain=v1'])],
68
- cwd: agentDir,
69
- stdout: 'pipe',
70
- stderr: 'pipe',
71
- })
72
- const exit = await proc.exited
73
- if (exit !== 0) return null
74
- const text = await new Response(proc.stdout).text()
75
- return parsePorcelain(text)
66
+ const { exitCode, stdout } = await runGit(bun, agentDir, [...gitArgs, 'status', '--porcelain=v1'])
67
+ if (exitCode !== 0) return null
68
+ return parsePorcelain(stdout)
76
69
  } catch {
77
70
  return null
78
71
  }
@@ -5,9 +5,9 @@ import { basename, join } from 'node:path'
5
5
 
6
6
  import { z } from 'zod'
7
7
 
8
- import { hooklessGitArgs } from '@/git/hookless'
9
8
  import { withGitLock } from '@/git/mutex'
10
9
  import { type AgentGit, resolveAgentGit } from '@/git/resolve-agent-git'
10
+ import { runGit } from '@/git/run'
11
11
  import { defineTool, lsTool, readTool, type Subagent, writeTool } from '@/plugin'
12
12
  import { formatLocalDate, formatLocalDateTime } from '@/shared'
13
13
 
@@ -774,13 +774,8 @@ async function commitMemorySnapshotUnlocked(cwd: string): Promise<void> {
774
774
  return
775
775
  }
776
776
 
777
- const add = bun.spawn({
778
- cmd: ['git', ...hooklessGitArgs([...repo.gitArgs, 'add', '-f', '--', ...presentPaths])],
779
- cwd,
780
- stdout: 'pipe',
781
- stderr: 'pipe',
782
- })
783
- if ((await add.exited) !== 0) {
777
+ const add = await runGit(bun, cwd, [...repo.gitArgs, 'add', '-f', '--', ...presentPaths])
778
+ if (add.exitCode !== 0) {
784
779
  await applySkipWorktree(bun, cwd, repo)
785
780
  return
786
781
  }
@@ -789,21 +784,20 @@ async function commitMemorySnapshotUnlocked(cwd: string): Promise<void> {
789
784
  // pathspec only references files git knows about. `git commit -- foo bar/`
790
785
  // fails outright when `bar/` matches no tracked file, even if `foo` is
791
786
  // staged.
792
- const stagedNames = bun.spawn({
793
- cmd: [
794
- 'git',
795
- ...hooklessGitArgs([...repo.gitArgs, 'diff', '--cached', '--name-only', '-z', '--', ...SNAPSHOT_PATHS]),
796
- ],
797
- cwd,
798
- stdout: 'pipe',
799
- stderr: 'pipe',
800
- })
801
- const stagedRaw = await new Response(stagedNames.stdout).text()
802
- if ((await stagedNames.exited) !== 0) {
787
+ const stagedNames = await runGit(bun, cwd, [
788
+ ...repo.gitArgs,
789
+ 'diff',
790
+ '--cached',
791
+ '--name-only',
792
+ '-z',
793
+ '--',
794
+ ...SNAPSHOT_PATHS,
795
+ ])
796
+ if (stagedNames.exitCode !== 0) {
803
797
  await applySkipWorktree(bun, cwd, repo)
804
798
  return
805
799
  }
806
- const staged = stagedRaw.split('\0').filter((p) => p.length > 0)
800
+ const staged = stagedNames.stdout.split('\0').filter((p) => p.length > 0)
807
801
  if (staged.length === 0) {
808
802
  await applySkipWorktree(bun, cwd, repo)
809
803
  return
@@ -811,13 +805,7 @@ async function commitMemorySnapshotUnlocked(cwd: string): Promise<void> {
811
805
 
812
806
  const message = await buildCommitMessage(bun, cwd, staged, undefined, repo.gitArgs)
813
807
 
814
- const commit = bun.spawn({
815
- cmd: ['git', ...hooklessGitArgs([...repo.gitArgs, 'commit', '-m', message, '--only', '--', ...staged])],
816
- cwd,
817
- stdout: 'pipe',
818
- stderr: 'pipe',
819
- })
820
- await commit.exited
808
+ await runGit(bun, cwd, [...repo.gitArgs, 'commit', '-m', message, '--only', '--', ...staged])
821
809
 
822
810
  await applySkipWorktree(bun, cwd, repo)
823
811
  }
@@ -868,14 +856,9 @@ async function buildDreamSummary(
868
856
  ): Promise<string> {
869
857
  // numstat: `<added>\t<deleted>\t<path>` per line. Use NUL-terminated so paths
870
858
  // with whitespace round-trip; -z switches the record separator to NUL.
871
- const numstat = bun.spawn({
872
- cmd: ['git', ...hooklessGitArgs([...gitArgs, 'diff', '--cached', '--numstat', '-z', '--', ...staged])],
873
- cwd,
874
- stdout: 'pipe',
875
- stderr: 'pipe',
876
- })
877
- const raw = await new Response(numstat.stdout).text()
878
- if ((await numstat.exited) !== 0) return 'snapshot'
859
+ const numstat = await runGit(bun, cwd, [...gitArgs, 'diff', '--cached', '--numstat', '-z', '--', ...staged])
860
+ if (numstat.exitCode !== 0) return 'snapshot'
861
+ const raw = numstat.stdout
879
862
 
880
863
  let fragmentLines = 0
881
864
  const streamPaths = new Set<string>()
@@ -925,14 +908,9 @@ async function listNewlyAddedSkills(
925
908
  staged: string[],
926
909
  gitArgs: readonly string[] = [],
927
910
  ): Promise<string[]> {
928
- const proc = bun.spawn({
929
- cmd: ['git', ...hooklessGitArgs([...gitArgs, 'diff', '--cached', '--name-status', '-z', '--', ...staged])],
930
- cwd,
931
- stdout: 'pipe',
932
- stderr: 'pipe',
933
- })
934
- const raw = await new Response(proc.stdout).text()
935
- if ((await proc.exited) !== 0) return []
911
+ const proc = await runGit(bun, cwd, [...gitArgs, 'diff', '--cached', '--name-status', '-z', '--', ...staged])
912
+ if (proc.exitCode !== 0) return []
913
+ const raw = proc.stdout
936
914
 
937
915
  // `--name-status -z` interleaves status and path as separate NUL records:
938
916
  // `A\0path\0M\0other\0...`. Pair them up.
@@ -953,39 +931,21 @@ async function listTrackedSnapshotFiles(
953
931
  cwd: string,
954
932
  repo: AgentGit,
955
933
  ): Promise<string[]> {
956
- const ls = bun.spawn({
957
- cmd: ['git', ...hooklessGitArgs([...repo.gitArgs, 'ls-files', '-z', '--', ...SNAPSHOT_PATHS])],
958
- cwd,
959
- stdout: 'pipe',
960
- stderr: 'pipe',
961
- })
962
- if ((await ls.exited) !== 0) return []
963
- const raw = await new Response(ls.stdout).text()
964
- return raw.split('\0').filter((p) => p.length > 0)
934
+ const ls = await runGit(bun, cwd, [...repo.gitArgs, 'ls-files', '-z', '--', ...SNAPSHOT_PATHS])
935
+ if (ls.exitCode !== 0) return []
936
+ return ls.stdout.split('\0').filter((p) => p.length > 0)
965
937
  }
966
938
 
967
939
  async function clearSkipWorktree(bun: { spawn: typeof Bun.spawn }, cwd: string, repo: AgentGit): Promise<void> {
968
940
  const files = await listTrackedSnapshotFiles(bun, cwd, repo)
969
941
  if (files.length === 0) return
970
- const proc = bun.spawn({
971
- cmd: ['git', ...hooklessGitArgs([...repo.gitArgs, 'update-index', '--no-skip-worktree', '--', ...files])],
972
- cwd,
973
- stdout: 'pipe',
974
- stderr: 'pipe',
975
- })
976
- await proc.exited
942
+ await runGit(bun, cwd, [...repo.gitArgs, 'update-index', '--no-skip-worktree', '--', ...files])
977
943
  }
978
944
 
979
945
  async function applySkipWorktree(bun: { spawn: typeof Bun.spawn }, cwd: string, repo: AgentGit): Promise<void> {
980
946
  const files = await listTrackedSnapshotFiles(bun, cwd, repo)
981
947
  if (files.length === 0) return
982
- const proc = bun.spawn({
983
- cmd: ['git', ...hooklessGitArgs([...repo.gitArgs, 'update-index', '--skip-worktree', '--', ...files])],
984
- cwd,
985
- stdout: 'pipe',
986
- stderr: 'pipe',
987
- })
988
- await proc.exited
948
+ await runGit(bun, cwd, [...repo.gitArgs, 'update-index', '--skip-worktree', '--', ...files])
989
949
  }
990
950
 
991
951
  export const DREAMING_SYSTEM_PROMPT = `You are typeclaw's dreaming subagent.
@@ -71,8 +71,15 @@ export function createOperatorSubagent(): Subagent<OperatorPayload> {
71
71
  payloadSchema: operatorPayloadSchema,
72
72
  visibility: 'public',
73
73
  rosterDescription:
74
- 'write-capable: bash-with-side-effects, write, edit — for browser sessions, refactors, deploys, batch ops, and Claude Code / Codex CLI driving; gated by `subagent.spawn.operator`, owner/trusted only — on denial, do the work yourself',
75
- requiresSpecificPermission: true,
74
+ 'write-capable: bash-with-side-effects, write, edit — for browser sessions, refactors, deploys, batch ops, and Claude Code / Codex CLI driving; runs at YOUR role, so it can do nothing here you could not already do inline',
75
+ // No `requiresSpecificPermission`: a subagent inherits `spawnedByRole`, and
76
+ // main sessions are never narrowed to a subset of the builtin tools, so a
77
+ // caller already holds every tool listed above. Gating the spawn bought no
78
+ // authorization — it only forced the same mutations to happen inline, in a
79
+ // dirtier context, and (unlike this subagent) with `channel_reply` in reach.
80
+ // The real boundaries are the non-ackable escalation guards, hidden-path
81
+ // masking, and the github-cli-auth token overlay, all of which bind parent
82
+ // and child identically.
76
83
  canSpawnSubagents: true,
77
84
  inFlightKey: (payload) => payload?.requestId ?? `anon-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
78
85
  toolResultBudget: {
@@ -212,12 +212,10 @@ If none of the listed skills fit the question, load \`general\`. Keep the skill-
212
212
  visibility: 'public',
213
213
  rosterDescription:
214
214
  'deep multi-source investigation in a fresh context — decomposes a fuzzy question, gathers from many sources, cross-validates, and returns a citation-backed report; the quality-over-speed counterpart to `scout`, for any research that needs more than one lookup',
215
- // No `requiresSpecificPermission`: unlike `operator` (generic write/edit +
216
- // side-effecting bash), the researcher's only write goes through the
217
- // `write_report` tool, which enforces "one report file under
218
- // workspace/public" in code. That narrow, code-enforced capability does not
219
- // warrant operator's owner/trusted-only gate; any caller that can spawn a
220
- // subagent can spawn the researcher.
215
+ // No `requiresSpecificPermission`: the researcher's only write goes through
216
+ // the `write_report` tool, which enforces "one report file under
217
+ // workspace/public" in code. Any caller that can spawn a subagent can spawn
218
+ // the researcher.
221
219
  canSpawnSubagents: true,
222
220
  canBackgroundSpawnSubagents: true,
223
221
  timeoutMs: RESEARCHER_SPAWN_TIMEOUT_MS,
@@ -1,7 +1,7 @@
1
1
  // A channel turn ends after a successful `channel_reply` (the terminal-reply
2
2
  // abort in router.ts). When the model's reply PROMISES to keep working this
3
3
  // turn ("바로 확인해볼게요", "let me check", "I'll continue now") but it forgot
4
- // to set `channel_reply({ continue: true })`, the turn aborts and the promised
4
+ // to set `channel_reply({ more_work_this_turn: true })`, the turn aborts and the promised
5
5
  // follow-up never runs. The router uses this detector to inject ONE bounded
6
6
  // reminder nudge so the model gets a second chance. See the empty-turn retry
7
7
  // (router.ts) for the sibling mechanism this mirrors.
@@ -73,7 +73,7 @@ const EN_PHRASES: readonly string[] = [
73
73
  // Action/config verb family. The retrieval verbs above ("check/look/look up")
74
74
  // miss the much larger class of "I'll DO X" promises — update/configure/set up/
75
75
  // schedule/fix/apply/create — which is exactly the class that silently truncates
76
- // when the model forgets `continue: true` (the cron-update production miss).
76
+ // when the model forgets `more_work_this_turn: true` (the cron-update production miss).
77
77
  "i'll update",
78
78
  "i'll set up",
79
79
  "i'll set it up",
@@ -19,7 +19,7 @@ export type FalseReceiptInput = {
19
19
  chat: string
20
20
  thread: string | null
21
21
  text: string | undefined
22
- isContinue: boolean
22
+ moreWorkThisTurn: boolean
23
23
  resolveReviewThread: boolean
24
24
  }
25
25
 
@@ -32,9 +32,9 @@ export function checkFalseReceipt(input: FalseReceiptInput): FalseReceiptDecisio
32
32
  if (claim === 'ignore') return { kind: 'allow' }
33
33
  if (claim === 'warn') return { kind: 'warn', notice: SOFT_NOTICE }
34
34
 
35
- // A turn the agent explicitly keeps alive (continue:true) is not yet a receipt
36
- // — the real action may still be coming. Never block; nudge instead.
37
- if (input.isContinue) return { kind: 'warn', notice: SOFT_NOTICE }
35
+ // A turn the agent explicitly keeps alive (more_work_this_turn:true) is not yet
36
+ // a receipt — the real action may still be coming. Never block; nudge instead.
37
+ if (input.moreWorkThisTurn) return { kind: 'warn', notice: SOFT_NOTICE }
38
38
 
39
39
  if (claim === 'block-resolve') {
40
40
  if (input.thread === null) return { kind: 'allow' }
@@ -17,10 +17,10 @@ export type RereviewGuardInput = {
17
17
  thread: string | null
18
18
  text: string | undefined
19
19
  wantsResolve: boolean
20
- // A mid-turn status reply (continue:true) is not the turn's receipt, so it
21
- // suppresses the warn-tier escalation below — but never the explicit resolve,
22
- // which is a real mutation. Mirrors the false-receipt guard's continue rule.
23
- isContinue: boolean
20
+ // A mid-turn status reply (more_work_this_turn:true) is not the turn's receipt,
21
+ // so it suppresses the warn-tier escalation below — but never the explicit
22
+ // resolve, which is a real mutation. Mirrors the false-receipt guard's rule.
23
+ moreWorkThisTurn: boolean
24
24
  getReviewState: (req: { adapter: 'github'; workspace: string; chat: string }) => Promise<ReviewStateResult>
25
25
  workspace: string
26
26
  }
@@ -62,14 +62,14 @@ export async function evaluateRereviewGuard(input: RereviewGuardInput): Promise<
62
62
  // live CHANGES_REQUESTED, so casual approval-shaped chatter on an unblocked PR
63
63
  // still posts. Only POSITIVE warn phrases escalate — negative ones ("needs
64
64
  // changes", "still needs work") re-assert a block rather than strand it, so they
65
- // stay non-firing. `continue:true` exempts the warn escalation (mid-turn
66
- // planning, not the receipt), but never the explicit resolve action. Plain
67
- // `ignore` text never fires.
65
+ // stay non-firing. `more_work_this_turn:true` exempts the warn escalation
66
+ // (mid-turn planning, not the receipt), but never the explicit resolve action.
67
+ // Plain `ignore` text never fires.
68
68
  function isCloseoutAttempt(input: RereviewGuardInput): boolean {
69
69
  if (input.wantsResolve && input.thread !== null) return true
70
70
  const claim = classifyReviewClaim(input.text ?? '')
71
71
  if (claim === 'block-resolve' || claim === 'block-approve') return true
72
- return !input.isContinue && isPositiveWarnCloseout(input.text ?? '')
72
+ return !input.moreWorkThisTurn && isPositiveWarnCloseout(input.text ?? '')
73
73
  }
74
74
 
75
75
  function unverifiableReason(error: string): string {