typeclaw 0.38.1 → 0.39.1
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/README.md +5 -0
- package/package.json +2 -2
- package/src/agent/attention-escalation.ts +158 -7
- package/src/agent/auth.ts +2 -2
- package/src/agent/git-nudge.ts +7 -7
- package/src/agent/index.ts +25 -2
- package/src/agent/restart/index.ts +17 -8
- package/src/agent/session-origin.ts +21 -0
- package/src/agent/subagents.ts +29 -1
- package/src/agent/system-prompt.ts +18 -5
- package/src/agent/tools/restart.ts +0 -3
- package/src/agent/tools/spawn-subagent.ts +7 -0
- package/src/bundled-plugins/backup/index.ts +5 -2
- package/src/bundled-plugins/backup/runner.ts +55 -23
- package/src/bundled-plugins/guard/policies/uncommitted-changes.ts +7 -8
- package/src/bundled-plugins/memory/dreaming.ts +37 -24
- package/src/bundled-plugins/memory/index.ts +24 -6
- package/src/bundled-plugins/memory/memory-logger.ts +14 -10
- package/src/bundled-plugins/operator/operator.ts +1 -0
- package/src/channels/adapters/kakaotalk-membership.ts +67 -0
- package/src/channels/adapters/kakaotalk.ts +8 -0
- package/src/channels/adapters/line-token.ts +55 -0
- package/src/channels/adapters/line.ts +74 -0
- package/src/channels/adapters/webex-bot-classify.ts +14 -1
- package/src/channels/adapters/webex-bot.ts +24 -1
- package/src/channels/adapters/webex-classify.ts +16 -1
- package/src/channels/adapters/webex.ts +27 -1
- package/src/channels/router.ts +55 -2
- package/src/cli/hostd.ts +40 -0
- package/src/cli/model.ts +143 -3
- package/src/config/config.ts +101 -36
- package/src/config/index.ts +3 -0
- package/src/config/models-mutation.ts +105 -15
- package/src/config/providers-mutation.ts +4 -4
- package/src/config/providers.ts +6 -14
- package/src/container/shared.ts +136 -14
- package/src/container/shell.ts +12 -2
- package/src/container/start.ts +25 -7
- package/src/doctor/commit.ts +10 -10
- package/src/dreams/git.ts +20 -7
- package/src/dreams/index.ts +22 -7
- package/src/git/reconcile-ignored.ts +56 -27
- package/src/git/resolve-agent-git.ts +12 -0
- package/src/git/system-commit.ts +16 -10
- package/src/hostd/daemon.ts +16 -0
- package/src/hostd/index.ts +1 -11
- package/src/hostd/paths.ts +0 -16
- package/src/hostd/webex-renewal-manager.ts +216 -0
- package/src/init/dockerfile.ts +13 -4
- package/src/init/gitignore.ts +4 -2
- package/src/run/index.ts +4 -1
- package/src/secrets/schema.ts +1 -0
- package/src/secrets/webex-renewal.ts +215 -0
- package/src/server/index.ts +25 -3
- package/src/skills/typeclaw-config/SKILL.md +18 -16
- package/typeclaw.schema.json +172 -1
package/src/container/shared.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto'
|
|
2
|
-
import {
|
|
2
|
+
import { existsSync } from 'node:fs'
|
|
3
|
+
import { basename, resolve, win32 } from 'node:path'
|
|
4
|
+
|
|
5
|
+
import { isWindows } from '@/shared'
|
|
3
6
|
|
|
4
7
|
export type DockerExecResult = { exitCode: number; stdout: string; stderr: string }
|
|
5
8
|
|
|
@@ -11,16 +14,27 @@ export type DockerExec = (
|
|
|
11
14
|
export const defaultDockerExec: DockerExec = async (args, options) => {
|
|
12
15
|
const bun = getBun()
|
|
13
16
|
if (!bun) return { exitCode: -1, stdout: '', stderr: 'bun runtime not available' }
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
17
|
+
// Resolve `docker` to an absolute path before spawning. Bun.spawn() resolves
|
|
18
|
+
// a bare command name through Bun.which() internally, but Windows PATH/PATHEXT
|
|
19
|
+
// resolution has a string of historical bugs (oven-sh/bun#16070, #11182,
|
|
20
|
+
// #29636) that make `cmd: ['docker', …]` throw ENOENT even when Docker
|
|
21
|
+
// Desktop is installed and docker.exe is on %PATH% — surfacing as the
|
|
22
|
+
// misleading "Docker is not installed." on a machine that has Docker.
|
|
23
|
+
// dockerCmd() goes through Bun.which(), which reliably honors PATHEXT and
|
|
24
|
+
// returns the full docker.exe path; it returns null only when docker is
|
|
25
|
+
// genuinely absent from PATH, which maps to the binary-missing sentinel.
|
|
26
|
+
const cmd = dockerCmd(args)
|
|
27
|
+
if (cmd === null) return { exitCode: -1, stdout: '', stderr: DOCKER_NOT_FOUND_STDERR }
|
|
28
|
+
// Two overloads (pipe vs inherit) so each spawn call site has the literal
|
|
29
|
+
// stdout/stderr type attached — that's what lets `new Response(proc.stdout)`
|
|
30
|
+
// typecheck on the piped path. `signal` is forwarded to Bun.spawn so callers
|
|
31
|
+
// can bound long-running docker subcommands (e.g. `docker logs` on a stuck
|
|
32
|
+
// daemon). The ENOENT catch stays as a safety net for the race where the
|
|
33
|
+
// binary disappears between resolution and spawn.
|
|
20
34
|
if (options?.inheritStdio) {
|
|
21
35
|
try {
|
|
22
36
|
const proc = bun.spawn({
|
|
23
|
-
cmd
|
|
37
|
+
cmd,
|
|
24
38
|
cwd: options.cwd,
|
|
25
39
|
stdout: 'inherit',
|
|
26
40
|
stderr: 'inherit',
|
|
@@ -36,7 +50,7 @@ export const defaultDockerExec: DockerExec = async (args, options) => {
|
|
|
36
50
|
}
|
|
37
51
|
try {
|
|
38
52
|
const proc = bun.spawn({
|
|
39
|
-
cmd
|
|
53
|
+
cmd,
|
|
40
54
|
cwd: options?.cwd,
|
|
41
55
|
stdout: 'pipe',
|
|
42
56
|
stderr: 'pipe',
|
|
@@ -54,11 +68,94 @@ export const defaultDockerExec: DockerExec = async (args, options) => {
|
|
|
54
68
|
}
|
|
55
69
|
}
|
|
56
70
|
|
|
57
|
-
// Sentinel stderr from defaultDockerExec when
|
|
71
|
+
// Sentinel stderr from defaultDockerExec when docker can't be resolved/spawned.
|
|
58
72
|
// checkDockerAvailable matches on this exact string to distinguish
|
|
59
73
|
// "binary missing" from "daemon down".
|
|
60
74
|
export const DOCKER_NOT_FOUND_STDERR = 'docker: command not found in $PATH'
|
|
61
75
|
|
|
76
|
+
export type DockerBinaryProbes = {
|
|
77
|
+
which?: (command: string) => string | null
|
|
78
|
+
platform?: NodeJS.Platform
|
|
79
|
+
env?: NodeJS.ProcessEnv
|
|
80
|
+
exists?: (path: string) => boolean
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Resolves the `docker` binary to an absolute path. First via Bun.which(),
|
|
84
|
+
// which — unlike a bare `cmd: ['docker']` handed to Bun.spawn() — reliably
|
|
85
|
+
// honors Windows PATHEXT and returns e.g. C:\…\docker.exe. On POSIX the
|
|
86
|
+
// resolved path equals what the bare name would have found.
|
|
87
|
+
//
|
|
88
|
+
// When Bun.which() finds nothing on Windows we fall back to Docker Desktop's
|
|
89
|
+
// known install locations: its installer registers docker.exe on the SYSTEM
|
|
90
|
+
// PATH, so a shell/process started before the install (or with a customized
|
|
91
|
+
// PATH) inherits a stale PATH where Bun.which can't see docker even though the
|
|
92
|
+
// binary exists and the engine is running — the real-world "Docker is not
|
|
93
|
+
// installed" report on a machine with a working Docker. Probing these paths
|
|
94
|
+
// fixes detection without a reinstall or PATH edit. The MS-Store packaged
|
|
95
|
+
// build is deliberately NOT probed: its binary lives in ACL-locked
|
|
96
|
+
// WindowsApps and can't be executed by a child process anyway.
|
|
97
|
+
//
|
|
98
|
+
// Returns null when docker is genuinely absent, which callers translate into
|
|
99
|
+
// the binary-missing sentinel. Probes are injectable so tests stay
|
|
100
|
+
// deterministic without depending on a real docker install or host platform.
|
|
101
|
+
export function resolveDockerBinary(probes: DockerBinaryProbes = {}): string | null {
|
|
102
|
+
const which = probes.which ?? ((command: string) => getBun()?.which(command) ?? null)
|
|
103
|
+
const fromPath = which('docker')
|
|
104
|
+
if (fromPath !== null) return fromPath
|
|
105
|
+
|
|
106
|
+
const platform = probes.platform ?? process.platform
|
|
107
|
+
if (!isWindows(platform)) return null
|
|
108
|
+
|
|
109
|
+
const exists = probes.exists ?? existsSync
|
|
110
|
+
for (const candidate of windowsDockerCandidates(probes.env ?? process.env)) {
|
|
111
|
+
if (exists(candidate)) return candidate
|
|
112
|
+
}
|
|
113
|
+
return null
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Real, child-process-executable docker.exe locations across the common
|
|
117
|
+
// Windows install methods, most-canonical first. All are confirmed real
|
|
118
|
+
// binaries or executable shims (not ACL-locked WindowsApps Store stubs).
|
|
119
|
+
// Probe order prefers Docker Desktop, then package-manager Docker, then the
|
|
120
|
+
// standalone CLI, then the Rancher Desktop alternative runtime. An
|
|
121
|
+
// arbitrary `--installation-dir` install can't be enumerated and is left to
|
|
122
|
+
// Bun.which/PATH.
|
|
123
|
+
function windowsDockerCandidates(env: NodeJS.ProcessEnv): string[] {
|
|
124
|
+
const candidates: string[] = []
|
|
125
|
+
// win32.join (not the host-default join) so the probe builds backslash paths
|
|
126
|
+
// regardless of the host the resolver runs/tests on.
|
|
127
|
+
const add = (root: string | undefined, ...segments: string[]): void => {
|
|
128
|
+
if (root) candidates.push(win32.join(root, ...segments))
|
|
129
|
+
}
|
|
130
|
+
// ProgramW6432 covers a 32-bit Bun seeing the WOW64-redirected ProgramFiles.
|
|
131
|
+
const programFiles = env.ProgramW6432 ?? env.ProgramFiles ?? 'C:\\Program Files'
|
|
132
|
+
const programData = env.ProgramData ?? 'C:\\ProgramData'
|
|
133
|
+
|
|
134
|
+
// Docker Desktop: all-users, per-user, and the installer symlink dir.
|
|
135
|
+
add(programFiles, 'Docker', 'Docker', 'resources', 'bin', 'docker.exe')
|
|
136
|
+
add(env.LOCALAPPDATA, 'Programs', 'DockerDesktop', 'resources', 'bin', 'docker.exe')
|
|
137
|
+
add(programData, 'DockerDesktop', 'version-bin', 'docker.exe')
|
|
138
|
+
// Docker Desktop pre-3.3.1 layout (resources\docker.exe, no \bin).
|
|
139
|
+
add(programFiles, 'Docker', 'Docker', 'resources', 'docker.exe')
|
|
140
|
+
// Chocolatey and Scoop shims (executable redirectors, on PATH after install).
|
|
141
|
+
add(programData, 'chocolatey', 'bin', 'docker.exe')
|
|
142
|
+
add(env.USERPROFILE, 'scoop', 'shims', 'docker.exe')
|
|
143
|
+
// Standalone Docker CLI binary (Windows Server / manual `Expand-Archive`).
|
|
144
|
+
add(programFiles, 'Docker', 'docker.exe')
|
|
145
|
+
// Rancher Desktop's bundled Moby docker CLI (note the doubled `resources`).
|
|
146
|
+
add(programFiles, 'Rancher Desktop', 'resources', 'resources', 'win32', 'bin', 'docker.exe')
|
|
147
|
+
return candidates
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Builds the argv for a docker invocation with the binary resolved to an
|
|
151
|
+
// absolute path (see resolveDockerBinary). Returns null when docker is absent
|
|
152
|
+
// from PATH. The resolver is injectable so callers and tests stay deterministic
|
|
153
|
+
// without depending on a real docker install.
|
|
154
|
+
export function dockerCmd(args: string[], resolveBinary: () => string | null = resolveDockerBinary): string[] | null {
|
|
155
|
+
const binary = resolveBinary()
|
|
156
|
+
return binary === null ? null : [binary, ...args]
|
|
157
|
+
}
|
|
158
|
+
|
|
62
159
|
// Collapse a multi-line `docker` CLI stderr into a single readable clause
|
|
63
160
|
// suitable for inline `reason:` strings. The motivating case is `compose
|
|
64
161
|
// restart`, which prints one row per agent — raw stderr from a failed
|
|
@@ -108,6 +205,27 @@ export async function buildxAvailable(exec: DockerExec = defaultDockerExec): Pro
|
|
|
108
205
|
return (await exec(['buildx', 'version'])).exitCode === 0
|
|
109
206
|
}
|
|
110
207
|
|
|
208
|
+
export type BindMountSpec = { src: string; dst: string; readonly?: boolean }
|
|
209
|
+
|
|
210
|
+
// Emits `--mount type=bind,...` argv for a host->container bind mount, used in
|
|
211
|
+
// place of the legacy `-v src:dst[:ro]` form. The `-v` short form splits on
|
|
212
|
+
// `:`, which collides with a Windows drive letter (`C:\agent` parses as host
|
|
213
|
+
// `C` + path `\agent`); `--mount`'s `key=value` CSV has no such ambiguity and
|
|
214
|
+
// fails loud on an unknown/missing key instead of silently creating a phantom
|
|
215
|
+
// host dir. Src is resolved to an absolute path because `--mount` (unlike `-v`)
|
|
216
|
+
// rejects relative sources. A literal comma in a path would break the CSV;
|
|
217
|
+
// it's rejected here rather than silently mis-parsed (paths with commas are
|
|
218
|
+
// pathological and were never supported by the `-v` form either).
|
|
219
|
+
export function dockerBindMount({ src, dst, readonly }: BindMountSpec): [string, string] {
|
|
220
|
+
const absSrc = resolve(src)
|
|
221
|
+
if (absSrc.includes(',') || dst.includes(',')) {
|
|
222
|
+
throw new Error(`bind mount path contains a comma, which docker --mount cannot express: ${absSrc} -> ${dst}`)
|
|
223
|
+
}
|
|
224
|
+
const fields = [`type=bind`, `src=${absSrc}`, `dst=${dst}`]
|
|
225
|
+
if (readonly) fields.push('readonly')
|
|
226
|
+
return ['--mount', fields.join(',')]
|
|
227
|
+
}
|
|
228
|
+
|
|
111
229
|
export function containerNameFromCwd(cwd: string): string {
|
|
112
230
|
return sanitizeContainerName(basename(resolve(cwd)))
|
|
113
231
|
}
|
|
@@ -278,8 +396,10 @@ function sanitizeContainerName(name: string): string {
|
|
|
278
396
|
export async function imageExists(tag: string): Promise<boolean> {
|
|
279
397
|
const bun = getBun()
|
|
280
398
|
if (!bun) return false
|
|
399
|
+
const cmd = dockerCmd(['image', 'inspect', tag])
|
|
400
|
+
if (cmd === null) return false
|
|
281
401
|
const proc = bun.spawn({
|
|
282
|
-
cmd
|
|
402
|
+
cmd,
|
|
283
403
|
stdout: 'pipe',
|
|
284
404
|
stderr: 'pipe',
|
|
285
405
|
})
|
|
@@ -302,8 +422,10 @@ export type ContainerState = { exists: false } | { exists: true; running: boolea
|
|
|
302
422
|
export async function inspectContainer(name: string): Promise<ContainerState> {
|
|
303
423
|
const bun = getBun()
|
|
304
424
|
if (!bun) return { exists: false }
|
|
425
|
+
const cmd = dockerCmd(['inspect', '--format', '{{.State.Running}}', name])
|
|
426
|
+
if (cmd === null) return { exists: false }
|
|
305
427
|
const proc = bun.spawn({
|
|
306
|
-
cmd
|
|
428
|
+
cmd,
|
|
307
429
|
stdout: 'pipe',
|
|
308
430
|
stderr: 'pipe',
|
|
309
431
|
})
|
|
@@ -312,6 +434,6 @@ export async function inspectContainer(name: string): Promise<ContainerState> {
|
|
|
312
434
|
return { exists: true, running: out === 'true' }
|
|
313
435
|
}
|
|
314
436
|
|
|
315
|
-
export function getBun(): { spawn: typeof Bun.spawn } | undefined {
|
|
316
|
-
return (globalThis as { Bun?: { spawn: typeof Bun.spawn } }).Bun
|
|
437
|
+
export function getBun(): { spawn: typeof Bun.spawn; which: typeof Bun.which } | undefined {
|
|
438
|
+
return (globalThis as { Bun?: { spawn: typeof Bun.spawn; which: typeof Bun.which } }).Bun
|
|
317
439
|
}
|
package/src/container/shell.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { containerNameFromCwd, getBun, inspectContainer, type ContainerState } from './shared'
|
|
1
|
+
import { containerNameFromCwd, dockerCmd, getBun, inspectContainer, type ContainerState } from './shared'
|
|
2
2
|
|
|
3
3
|
export type ShellPlan = {
|
|
4
4
|
containerName: string
|
|
@@ -10,6 +10,7 @@ export type ShellResult = { ok: true; containerName: string; exitCode: number }
|
|
|
10
10
|
type ShellDeps = {
|
|
11
11
|
inspect?: (name: string) => Promise<ContainerState>
|
|
12
12
|
spawn?: InteractiveSpawn
|
|
13
|
+
resolveDocker?: () => string | null
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
type InteractiveSpawn = (options: {
|
|
@@ -30,6 +31,15 @@ export async function shell(
|
|
|
30
31
|
|
|
31
32
|
const { containerName, shell: plannedShell } = planShell(cwd, { shell: shellPath })
|
|
32
33
|
|
|
34
|
+
// Resolve docker before inspecting: inspectContainer collapses a missing
|
|
35
|
+
// docker binary into { exists: false }, so deferring this check would
|
|
36
|
+
// surface the misleading "Container … not found" instead of the real
|
|
37
|
+
// "Docker is not installed" on a host without docker on PATH.
|
|
38
|
+
const cmd = dockerCmd(['exec', '-it', containerName, plannedShell], deps.resolveDocker)
|
|
39
|
+
if (cmd === null) {
|
|
40
|
+
return { ok: false, reason: 'Docker is not installed (docker not found on PATH).' }
|
|
41
|
+
}
|
|
42
|
+
|
|
33
43
|
try {
|
|
34
44
|
const state = await (deps.inspect ?? inspectContainer)(containerName)
|
|
35
45
|
if (!state.exists) {
|
|
@@ -40,7 +50,7 @@ export async function shell(
|
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
const proc = spawn({
|
|
43
|
-
cmd
|
|
53
|
+
cmd,
|
|
44
54
|
cwd,
|
|
45
55
|
stdin: 'inherit',
|
|
46
56
|
stdout: 'inherit',
|
package/src/container/start.ts
CHANGED
|
@@ -26,6 +26,7 @@ import { buildGitignore, GITIGNORE_FILE } from '@/init/gitignore'
|
|
|
26
26
|
import { refreshPackageJson } from '@/init/packagejson'
|
|
27
27
|
import { reconcilePluginDeps } from '@/init/reconcile-plugin-deps'
|
|
28
28
|
import { runBunUpdate, type UpdateRunner } from '@/init/run-bun-install'
|
|
29
|
+
import { isWindows } from '@/shared'
|
|
29
30
|
import { hostLocaleIsCjk } from '@/shared/host-locale'
|
|
30
31
|
|
|
31
32
|
import { CONTAINER_PORT, TUI_TOKEN_LABEL, findFreePort, isPortAllocatedError, resolveTuiToken } from './port'
|
|
@@ -37,6 +38,7 @@ import {
|
|
|
37
38
|
defaultDockerExec,
|
|
38
39
|
type DockerExec,
|
|
39
40
|
type DockerExecResult,
|
|
41
|
+
dockerBindMount,
|
|
40
42
|
imageTagFromCwd,
|
|
41
43
|
isContainerNameConflict,
|
|
42
44
|
sanitizeDockerStderr,
|
|
@@ -656,18 +658,16 @@ export async function planStart({
|
|
|
656
658
|
runArgs.push('-e', `TYPECLAW_HOSTD_BROKER_TOKEN=${hostdControl.brokerToken}`)
|
|
657
659
|
}
|
|
658
660
|
|
|
659
|
-
runArgs.push('
|
|
661
|
+
runArgs.push(...dockerBindMount({ src: cwd, dst: '/agent' }))
|
|
660
662
|
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
if (devSourcePath && !devSourcePath.startsWith(cwd)) {
|
|
664
|
-
runArgs.push('-v', `${devSourcePath}:${devSourcePath}:ro`)
|
|
663
|
+
if (shouldMirrorDevSource(devSourcePath, cwd)) {
|
|
664
|
+
runArgs.push(...dockerBindMount({ src: devSourcePath, dst: devSourcePath, readonly: true }))
|
|
665
665
|
}
|
|
666
666
|
|
|
667
667
|
for (const mount of mounts) {
|
|
668
668
|
const hostPath = expandMountPath(mount.path, cwd)
|
|
669
669
|
const target = `${MOUNT_TARGET_PREFIX}/${mount.name}`
|
|
670
|
-
runArgs.push(
|
|
670
|
+
runArgs.push(...dockerBindMount({ src: hostPath, dst: target, readonly: mount.readOnly }))
|
|
671
671
|
}
|
|
672
672
|
|
|
673
673
|
// Shared model cache mount for embeddings. Gated on vector opt-in: a
|
|
@@ -676,7 +676,7 @@ export async function planStart({
|
|
|
676
676
|
// so mounting an empty cache would only invite a confusing local_files_only
|
|
677
677
|
// miss if something inside the container reached for the model anyway.
|
|
678
678
|
if (agentUsesVector(cwd)) {
|
|
679
|
-
runArgs.push(
|
|
679
|
+
runArgs.push(...dockerBindMount({ src: join(homeRoot(), 'models'), dst: '/opt/models', readonly: true }))
|
|
680
680
|
runArgs.push('-e', 'TYPECLAW_MODEL_CACHE=/opt/models')
|
|
681
681
|
}
|
|
682
682
|
|
|
@@ -915,6 +915,24 @@ async function detectDevSource(cwd: string): Promise<string | null> {
|
|
|
915
915
|
}
|
|
916
916
|
}
|
|
917
917
|
|
|
918
|
+
// Dev mode: node_modules/typeclaw is a symlink to an absolute host path outside
|
|
919
|
+
// /agent. The mirror mount bind-mounts that path at the SAME path inside the
|
|
920
|
+
// (Linux) container so the symlink resolves. That only works when the host path
|
|
921
|
+
// is itself a valid Linux container path — true on POSIX, false on native
|
|
922
|
+
// Windows where devSourcePath is `C:\...` (not an absolute Linux path, so it
|
|
923
|
+
// cannot be a container mount `dst`, and the in-container symlink would point at
|
|
924
|
+
// a Windows path regardless). Native-Windows dev-mode (file:/link: typeclaw dep)
|
|
925
|
+
// needs the deferred symlink/junction translation in #899; until then we skip
|
|
926
|
+
// the mirror mount rather than emit an invalid `dst`. End users install typeclaw
|
|
927
|
+
// from npm (a registry spec, not file:), so they never hit this path.
|
|
928
|
+
export function shouldMirrorDevSource(
|
|
929
|
+
devSourcePath: string | null,
|
|
930
|
+
cwd: string,
|
|
931
|
+
platform: NodeJS.Platform = process.platform,
|
|
932
|
+
): devSourcePath is string {
|
|
933
|
+
return devSourcePath !== null && !devSourcePath.startsWith(cwd) && !isWindows(platform)
|
|
934
|
+
}
|
|
935
|
+
|
|
918
936
|
// True when the agent's package.json declares typeclaw via `file:` or
|
|
919
937
|
// `link:` — i.e. a developer is iterating on the typeclaw source via a
|
|
920
938
|
// locally-linked checkout. `bun install` keys its file-dep cache on
|
package/src/doctor/commit.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { join } from 'node:path'
|
|
1
|
+
import { resolveAgentGit } from '@/git/resolve-agent-git'
|
|
3
2
|
|
|
4
3
|
import type { CommitOutcome, FixAttempt } from './types'
|
|
5
4
|
|
|
@@ -23,13 +22,15 @@ export async function commitAutoFixes(opts: CommitOptions): Promise<CommitOutcom
|
|
|
23
22
|
return { kind: 'skipped', reason: 'auto-fixes reported no changed paths' }
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
const repo = resolveAgentGit(opts.cwd)
|
|
26
|
+
if (!repo) {
|
|
27
27
|
return { kind: 'skipped', reason: 'agent folder is not a git repo (.git missing)' }
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const spawnGit = opts.spawnGit ?? defaultSpawnGit
|
|
31
|
+
const git = (args: string[]): Promise<GitResult> => spawnGit([...repo.gitArgs, ...args], opts.cwd)
|
|
31
32
|
|
|
32
|
-
const filter = await filterCommittable(
|
|
33
|
+
const filter = await filterCommittable(git, requested)
|
|
33
34
|
if (filter.kind === 'failed') return filter
|
|
34
35
|
const pathsStaged = filter.paths
|
|
35
36
|
if (pathsStaged.length === 0) {
|
|
@@ -39,18 +40,18 @@ export async function commitAutoFixes(opts: CommitOptions): Promise<CommitOutcom
|
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
const add = await
|
|
43
|
+
const add = await git(['add', '--', ...pathsStaged])
|
|
43
44
|
if (add.exitCode !== 0) {
|
|
44
45
|
return { kind: 'failed', reason: `git add failed: ${add.stderr.trim() || `exit ${add.exitCode}`}` }
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
const message = buildCommitMessage(opts.attempts)
|
|
48
|
-
const commit = await
|
|
49
|
+
const commit = await git(['commit', '-m', message, '--only', '--', ...pathsStaged])
|
|
49
50
|
if (commit.exitCode !== 0) {
|
|
50
51
|
return { kind: 'failed', reason: `git commit failed: ${commit.stderr.trim() || `exit ${commit.exitCode}`}` }
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
const sha = await
|
|
54
|
+
const sha = await git(['rev-parse', 'HEAD'])
|
|
54
55
|
const commitSha = sha.exitCode === 0 ? sha.stdout.trim() : ''
|
|
55
56
|
return { kind: 'committed', commitSha, pathsStaged }
|
|
56
57
|
}
|
|
@@ -68,13 +69,12 @@ export async function commitAutoFixes(opts: CommitOptions): Promise<CommitOutcom
|
|
|
68
69
|
// Surface that as { kind: 'failed' } so the user sees the real cause instead
|
|
69
70
|
// of a misleading 'all paths are gitignored' message.
|
|
70
71
|
async function filterCommittable(
|
|
71
|
-
spawnGit:
|
|
72
|
-
cwd: string,
|
|
72
|
+
spawnGit: (args: string[]) => Promise<GitResult>,
|
|
73
73
|
paths: string[],
|
|
74
74
|
): Promise<{ kind: 'ok'; paths: string[] } | { kind: 'failed'; reason: string }> {
|
|
75
75
|
const out: string[] = []
|
|
76
76
|
for (const p of paths) {
|
|
77
|
-
const status = await spawnGit(['status', '--porcelain', '--', p]
|
|
77
|
+
const status = await spawnGit(['status', '--porcelain', '--', p])
|
|
78
78
|
if (status.exitCode !== 0) {
|
|
79
79
|
return {
|
|
80
80
|
kind: 'failed',
|
package/src/dreams/git.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { resolveAgentGit } from '@/git/resolve-agent-git'
|
|
2
|
+
|
|
1
3
|
export type GitResult = { exitCode: number; stdout: string; stderr: string }
|
|
2
|
-
export type SpawnGit = (args: string[], cwd: string) => Promise<GitResult>
|
|
4
|
+
export type SpawnGit = (args: readonly string[], cwd: string) => Promise<GitResult>
|
|
3
5
|
|
|
4
6
|
export type RawCommit = {
|
|
5
7
|
sha: string
|
|
@@ -8,16 +10,22 @@ export type RawCommit = {
|
|
|
8
10
|
subject: string
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
export type ResolveRepoResult =
|
|
13
|
+
export type ResolveRepoResult =
|
|
14
|
+
| { ok: true; root: string; gitArgs: readonly string[] }
|
|
15
|
+
| { ok: false; reason: 'not-a-repo' | 'git-failed' }
|
|
12
16
|
|
|
13
17
|
const FIELD_SEP = '\x1f'
|
|
14
18
|
const RECORD_SEP = '\x1e'
|
|
15
19
|
|
|
16
20
|
export async function resolveGitRepo(cwd: string, spawnGit: SpawnGit = defaultSpawnGit): Promise<ResolveRepoResult> {
|
|
17
|
-
const
|
|
21
|
+
const repo = resolveAgentGit(cwd)
|
|
22
|
+
if (!repo) return { ok: false, reason: 'not-a-repo' }
|
|
23
|
+
if (repo.kind === 'gitstore') return { ok: true, root: cwd, gitArgs: repo.gitArgs }
|
|
24
|
+
|
|
25
|
+
const res = await spawnGit([...repo.gitArgs, 'rev-parse', '--show-toplevel'], cwd)
|
|
18
26
|
if (res.exitCode === 0) {
|
|
19
27
|
const root = res.stdout.trim()
|
|
20
|
-
if (root.length > 0) return { ok: true, root }
|
|
28
|
+
if (root.length > 0) return { ok: true, root, gitArgs: repo.gitArgs }
|
|
21
29
|
return { ok: false, reason: 'git-failed' }
|
|
22
30
|
}
|
|
23
31
|
if (/not a git repository/i.test(res.stderr)) return { ok: false, reason: 'not-a-repo' }
|
|
@@ -30,6 +38,7 @@ export async function readDreamCommitLog(
|
|
|
30
38
|
root: string,
|
|
31
39
|
opts: { limit?: number } = {},
|
|
32
40
|
spawnGit: SpawnGit = defaultSpawnGit,
|
|
41
|
+
gitArgs: readonly string[] = [],
|
|
33
42
|
): Promise<RawCommit[]> {
|
|
34
43
|
// --grep is only a cheap pre-filter: it matches ANY line of the commit
|
|
35
44
|
// message, so a non-dream commit with a `dream: ...` body line slips
|
|
@@ -39,7 +48,7 @@ export async function readDreamCommitLog(
|
|
|
39
48
|
// result below the requested count.
|
|
40
49
|
const args = ['log', '--grep=^dream: ', `--format=%H${FIELD_SEP}%h${FIELD_SEP}%cI${FIELD_SEP}%s${RECORD_SEP}`]
|
|
41
50
|
|
|
42
|
-
const res = await spawnGit(args, root)
|
|
51
|
+
const res = await spawnGit([...gitArgs, ...args], root)
|
|
43
52
|
if (res.exitCode !== 0) return []
|
|
44
53
|
const dreams = parseLogOutput(res.stdout).filter((c) => c.subject.startsWith(DREAM_SUBJECT_PREFIX))
|
|
45
54
|
if (opts.limit !== undefined && opts.limit > 0) return dreams.slice(0, opts.limit)
|
|
@@ -62,10 +71,14 @@ export async function readDreamCommitShow(
|
|
|
62
71
|
root: string,
|
|
63
72
|
sha: string,
|
|
64
73
|
spawnGit: SpawnGit = defaultSpawnGit,
|
|
74
|
+
gitArgs: readonly string[] = [],
|
|
65
75
|
): Promise<{ nameStatus: string; patch: string } | null> {
|
|
66
|
-
const nameStatus = await spawnGit(
|
|
76
|
+
const nameStatus = await spawnGit(
|
|
77
|
+
[...gitArgs, 'show', '--no-color', '--find-renames', '--format=', '--name-status', sha],
|
|
78
|
+
root,
|
|
79
|
+
)
|
|
67
80
|
if (nameStatus.exitCode !== 0) return null
|
|
68
|
-
const patch = await spawnGit(['show', '--no-color', '--format=', '--unified=0', sha], root)
|
|
81
|
+
const patch = await spawnGit([...gitArgs, 'show', '--no-color', '--format=', '--unified=0', sha], root)
|
|
69
82
|
if (patch.exitCode !== 0) return null
|
|
70
83
|
return { nameStatus: nameStatus.stdout, patch: patch.stdout }
|
|
71
84
|
}
|
package/src/dreams/index.ts
CHANGED
|
@@ -39,7 +39,12 @@ export async function listDreams(
|
|
|
39
39
|
): Promise<DreamEntry[]> {
|
|
40
40
|
const repo = await resolveGitRepo(agentDir, spawnGit)
|
|
41
41
|
if (!repo.ok) return []
|
|
42
|
-
const commits = await readDreamCommitLog(
|
|
42
|
+
const commits = await readDreamCommitLog(
|
|
43
|
+
repo.root,
|
|
44
|
+
opts.limit !== undefined ? { limit: opts.limit } : {},
|
|
45
|
+
spawnGit,
|
|
46
|
+
repo.gitArgs,
|
|
47
|
+
)
|
|
43
48
|
return commits.map((commit) => {
|
|
44
49
|
const subject = parseDreamSubject(commit.subject)
|
|
45
50
|
return {
|
|
@@ -58,7 +63,7 @@ export async function listDreams(
|
|
|
58
63
|
export async function hydrateDream(agentDir: string, entry: DreamEntry, spawnGit?: SpawnGit): Promise<DreamEntry> {
|
|
59
64
|
const repo = await resolveGitRepo(agentDir, spawnGit)
|
|
60
65
|
if (!repo.ok) return entry
|
|
61
|
-
const show = await readDreamCommitShow(repo.root, entry.sha, spawnGit)
|
|
66
|
+
const show = await readDreamCommitShow(repo.root, entry.sha, spawnGit, repo.gitArgs)
|
|
62
67
|
if (show === null) return entry
|
|
63
68
|
return { ...entry, detail: parseDreamDetail(show.nameStatus, show.patch) }
|
|
64
69
|
}
|
|
@@ -80,7 +85,7 @@ export async function runDreams(opts: RunDreamsOptions): Promise<RunDreamsResult
|
|
|
80
85
|
const entries = await listDreams(opts.agentDir, opts.limit !== undefined ? { limit: opts.limit } : {}, opts.spawnGit)
|
|
81
86
|
const renderOpts: RenderOptions = { color: opts.color }
|
|
82
87
|
|
|
83
|
-
if (opts.json) return runJson(opts, repo.root, entries)
|
|
88
|
+
if (opts.json) return runJson(opts, repo.root, repo.gitArgs, entries)
|
|
84
89
|
|
|
85
90
|
if (entries.length === 0) {
|
|
86
91
|
opts.stdout('No dreams yet. The dreaming subagent commits here after it consolidates memory.')
|
|
@@ -115,16 +120,26 @@ async function runInteractiveLoop(
|
|
|
115
120
|
}
|
|
116
121
|
}
|
|
117
122
|
|
|
118
|
-
async function runJson(
|
|
123
|
+
async function runJson(
|
|
124
|
+
opts: RunDreamsOptions,
|
|
125
|
+
root: string,
|
|
126
|
+
gitArgs: readonly string[],
|
|
127
|
+
entries: DreamEntry[],
|
|
128
|
+
): Promise<RunDreamsResult> {
|
|
119
129
|
for (const entry of entries) {
|
|
120
|
-
const final = opts.details ? await hydrateEntryFromRoot(root, entry, opts.spawnGit) : entry
|
|
130
|
+
const final = opts.details ? await hydrateEntryFromRoot(root, gitArgs, entry, opts.spawnGit) : entry
|
|
121
131
|
opts.stdout(JSON.stringify(toJsonShape(final)))
|
|
122
132
|
}
|
|
123
133
|
return { ok: true, exitCode: 0 }
|
|
124
134
|
}
|
|
125
135
|
|
|
126
|
-
async function hydrateEntryFromRoot(
|
|
127
|
-
|
|
136
|
+
async function hydrateEntryFromRoot(
|
|
137
|
+
root: string,
|
|
138
|
+
gitArgs: readonly string[],
|
|
139
|
+
entry: DreamEntry,
|
|
140
|
+
spawnGit?: SpawnGit,
|
|
141
|
+
): Promise<DreamEntry> {
|
|
142
|
+
const show = await readDreamCommitShow(root, entry.sha, spawnGit, gitArgs)
|
|
128
143
|
if (show === null) return entry
|
|
129
144
|
return { ...entry, detail: parseDreamDetail(show.nameStatus, show.patch) }
|
|
130
145
|
}
|