typeclaw 0.39.0 → 0.39.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.
- package/README.md +1 -0
- package/package.json +2 -2
- package/src/agent/attention-escalation.ts +154 -4
- package/src/agent/git-nudge.ts +7 -7
- package/src/agent/session-origin.ts +21 -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/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 +112 -13
- package/src/cli/hostd.ts +40 -0
- package/src/compose/logs.ts +20 -6
- package/src/config/config.ts +7 -5
- package/src/container/logs.ts +19 -4
- package/src/container/shared.ts +222 -18
- package/src/container/shell.ts +12 -2
- package/src/container/start.ts +191 -30
- 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/webex-renewal-manager.ts +216 -0
- package/src/init/auto-upgrade.ts +38 -4
- package/src/init/cli-version.ts +30 -1
- package/src/init/dockerfile.ts +31 -9
- package/src/init/gitignore.ts +4 -2
- package/src/init/index.ts +47 -39
- package/src/init/windows-dev-link.ts +64 -0
- package/src/secrets/schema.ts +1 -0
- package/src/secrets/webex-renewal.ts +215 -0
- package/src/server/index.ts +25 -3
- package/typeclaw.schema.json +6 -1
package/src/container/start.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto'
|
|
2
2
|
import { existsSync } from 'node:fs'
|
|
3
|
-
import { readFile, writeFile } from 'node:fs/promises'
|
|
3
|
+
import { cp, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
|
4
|
+
import { tmpdir } from 'node:os'
|
|
4
5
|
import { isAbsolute, join, resolve } from 'node:path'
|
|
5
6
|
|
|
6
7
|
import { agentUsesVector } from '@/bundled-plugins/memory/vector/config'
|
|
@@ -17,15 +18,17 @@ import {
|
|
|
17
18
|
type AutoUpgradeOutcome,
|
|
18
19
|
expectedInstalledAfterUpgrade,
|
|
19
20
|
outcomeForcesInstall,
|
|
21
|
+
outcomeRequiresForceInstall,
|
|
20
22
|
readInstalledTypeclawVersionFromAgent,
|
|
21
23
|
} from '@/init/auto-upgrade'
|
|
22
|
-
import { resolveBaseImageVersion } from '@/init/cli-version'
|
|
24
|
+
import { resolveBaseImageVersion, resolveTypeclawSpec, typeclawCheckoutRoot } from '@/init/cli-version'
|
|
23
25
|
import { buildDockerfile, classifyDockerfileAppend, DOCKERFILE } from '@/init/dockerfile'
|
|
24
26
|
import { ensureDepsInstalled, type EnsureDepsResult } from '@/init/ensure-deps'
|
|
25
27
|
import { buildGitignore, GITIGNORE_FILE } from '@/init/gitignore'
|
|
26
28
|
import { refreshPackageJson } from '@/init/packagejson'
|
|
27
29
|
import { reconcilePluginDeps } from '@/init/reconcile-plugin-deps'
|
|
28
30
|
import { runBunUpdate, type UpdateRunner } from '@/init/run-bun-install'
|
|
31
|
+
import { linkWindowsDevTypeclaw, resolveBunLinkedPackage, type RunBunLink } from '@/init/windows-dev-link'
|
|
29
32
|
import { isWindows } from '@/shared'
|
|
30
33
|
import { hostLocaleIsCjk } from '@/shared/host-locale'
|
|
31
34
|
|
|
@@ -39,14 +42,19 @@ import {
|
|
|
39
42
|
type DockerExec,
|
|
40
43
|
type DockerExecResult,
|
|
41
44
|
dockerBindMount,
|
|
45
|
+
dockerConfigDir,
|
|
42
46
|
imageTagFromCwd,
|
|
43
47
|
isContainerNameConflict,
|
|
48
|
+
isMissingDockerCredentialHelper,
|
|
49
|
+
sanitizeDockerConfigJson,
|
|
44
50
|
sanitizeDockerStderr,
|
|
45
51
|
waitForRemoval,
|
|
46
52
|
} from './shared'
|
|
47
53
|
import { buildCrashReason, createVerifyRunning, type VerifyRunningFn } from './verify-running'
|
|
48
54
|
|
|
49
55
|
const PACKAGE_FILE = 'package.json'
|
|
56
|
+
const TYPECLAW_PACKAGE = 'typeclaw'
|
|
57
|
+
const DEV_SOURCE_CONTAINER_PATH = '/agent/node_modules/typeclaw'
|
|
50
58
|
const BUN_LOCK_FILE = 'bun.lock'
|
|
51
59
|
const DEPENDENCY_FILES = [PACKAGE_FILE, BUN_LOCK_FILE] as const
|
|
52
60
|
const ENV_FILE = '.env'
|
|
@@ -75,6 +83,9 @@ export type PlanStartOptions = {
|
|
|
75
83
|
hostdControl?: HostDaemonControl
|
|
76
84
|
publishHost?: string
|
|
77
85
|
tuiToken?: string | null
|
|
86
|
+
// Defaults to `process.platform`; tests inject it to exercise the native-
|
|
87
|
+
// Windows dev-source mount branch without running on a Windows host.
|
|
88
|
+
platform?: NodeJS.Platform
|
|
78
89
|
}
|
|
79
90
|
|
|
80
91
|
export type HostDaemonControl = {
|
|
@@ -123,6 +134,13 @@ export type StartOptions = {
|
|
|
123
134
|
// function to override the wait window or to bypass verification entirely
|
|
124
135
|
// (e.g. a no-op `async () => ({ ok: true })` for unit tests that don't care).
|
|
125
136
|
verifyRunning?: VerifyRunningFn
|
|
137
|
+
// Test seam for the native-Windows dev-link step run before ensureDeps when a
|
|
138
|
+
// local-checkout reconcile emits `link:typeclaw`. Defaults to `bun link` in
|
|
139
|
+
// the checkout. Mirrors init's `runBunLink` seam.
|
|
140
|
+
runBunLink?: RunBunLink
|
|
141
|
+
// Defaults to `process.platform`; tests inject it to exercise the
|
|
142
|
+
// native-Windows dev-link reconcile path off a non-Windows runner.
|
|
143
|
+
platform?: NodeJS.Platform
|
|
126
144
|
}
|
|
127
145
|
|
|
128
146
|
export type HostDaemonStatus =
|
|
@@ -166,10 +184,12 @@ export async function start({
|
|
|
166
184
|
cliEntry,
|
|
167
185
|
reuseCurrentHostDaemon = false,
|
|
168
186
|
ensureDeps = (dir, opts) => ensureDepsInstalled({ cwd: dir, ...opts }),
|
|
169
|
-
autoUpgrade = (dir) => autoUpgradeTypeclawDep({ cwd: dir }),
|
|
187
|
+
autoUpgrade = (dir) => autoUpgradeTypeclawDep({ cwd: dir, localSpec: resolveTypeclawSpec(dir) }),
|
|
170
188
|
forceBunUpdate = runBunUpdate,
|
|
171
189
|
readInstalledVersion = readInstalledTypeclawVersionFromAgent,
|
|
172
190
|
verifyRunning = createVerifyRunning({ exec }),
|
|
191
|
+
runBunLink,
|
|
192
|
+
platform = process.platform,
|
|
173
193
|
}: StartOptions): Promise<StartResult> {
|
|
174
194
|
try {
|
|
175
195
|
const containerName = containerNameFromCwd(cwd)
|
|
@@ -234,6 +254,32 @@ export async function start({
|
|
|
234
254
|
// image to a fresh container build.
|
|
235
255
|
const upgrade = await autoUpgrade(cwd)
|
|
236
256
|
const upgradeCommitMessage = commitMessageForAutoUpgrade(upgrade)
|
|
257
|
+
// Any agent on a `link:typeclaw` spec (native-Windows dev) needs the
|
|
258
|
+
// checkout registered with `bun link` BEFORE ensureDeps, exactly as init's
|
|
259
|
+
// maybeLinkWindowsDevTypeclaw does — otherwise bun can't resolve the link:
|
|
260
|
+
// spec. We gate on the EFFECTIVE on-disk spec, not the transition outcome:
|
|
261
|
+
// a prior start that wrote `link:` but failed/interrupted before
|
|
262
|
+
// registering would otherwise leave the next start (which sees the spec
|
|
263
|
+
// already local → skipped-dev-mode) reaching ensureDeps unregistered.
|
|
264
|
+
// `bun link` is idempotent, so re-running it on every link: start is safe
|
|
265
|
+
// and self-heals that gap. No-op off Windows (linkWindowsDevTypeclaw → null).
|
|
266
|
+
// True when this is a native-Windows agent on a `link:typeclaw` spec, after
|
|
267
|
+
// (re)registering its checkout. Forces ensureDeps below: ensureDeps' drift
|
|
268
|
+
// detector only looks for MISSING dep names, so a stale npm-installed
|
|
269
|
+
// node_modules/typeclaw left by an interrupted relink would make it skip the
|
|
270
|
+
// install and leave the agent on the old runtime. Forcing materializes the
|
|
271
|
+
// link. Off Windows / non-link specs this stays false.
|
|
272
|
+
let registeredWindowsLink = false
|
|
273
|
+
if ((await readTypeclawDepSpec(cwd))?.startsWith('link:') === true) {
|
|
274
|
+
const checkout = typeclawCheckoutRoot()
|
|
275
|
+
if (checkout !== null) {
|
|
276
|
+
const linked = await linkWindowsDevTypeclaw(checkout, {
|
|
277
|
+
platform,
|
|
278
|
+
...(runBunLink !== undefined ? { runBunLink } : {}),
|
|
279
|
+
})
|
|
280
|
+
registeredWindowsLink = linked !== null
|
|
281
|
+
}
|
|
282
|
+
}
|
|
237
283
|
if (outcomeForcesInstall(upgrade)) {
|
|
238
284
|
const forced = await forceBunUpdate(cwd, 'typeclaw')
|
|
239
285
|
if (!forced.ok) {
|
|
@@ -284,7 +330,11 @@ export async function start({
|
|
|
284
330
|
// version bump (dir already present) or a removal (stale dir left behind)
|
|
285
331
|
// would otherwise leave bun.lock/node_modules out of sync with the
|
|
286
332
|
// reconciled package.json.
|
|
287
|
-
const forceDepsReinstall =
|
|
333
|
+
const forceDepsReinstall =
|
|
334
|
+
(forceBuild && (await hasLocallyLinkedTypeclawDep(cwd))) ||
|
|
335
|
+
pluginReconcile.changed ||
|
|
336
|
+
outcomeRequiresForceInstall(upgrade) ||
|
|
337
|
+
registeredWindowsLink
|
|
288
338
|
const deps = await ensureDeps(cwd, { force: forceDepsReinstall })
|
|
289
339
|
if (!deps.ok) {
|
|
290
340
|
return { ok: false, reason: `dependency install failed: ${deps.reason}` }
|
|
@@ -388,6 +438,7 @@ export async function start({
|
|
|
388
438
|
hostdControl,
|
|
389
439
|
publishHost,
|
|
390
440
|
tuiToken,
|
|
441
|
+
platform,
|
|
391
442
|
})
|
|
392
443
|
|
|
393
444
|
let built = false
|
|
@@ -463,6 +514,7 @@ export async function start({
|
|
|
463
514
|
hostdControl,
|
|
464
515
|
publishHost,
|
|
465
516
|
tuiToken,
|
|
517
|
+
platform,
|
|
466
518
|
})
|
|
467
519
|
run = await execRunWithConflictRetry(exec, plan.runArgs, cwd, containerName)
|
|
468
520
|
}
|
|
@@ -501,6 +553,7 @@ export async function start({
|
|
|
501
553
|
function commitMessageForAutoUpgrade(outcome: AutoUpgradeOutcome): string | null {
|
|
502
554
|
if (outcome.kind === 'spec-rewritten') return `Upgrade typeclaw to ${outcome.to}`
|
|
503
555
|
if (outcome.kind === 'reinstall-needed') return `Upgrade typeclaw to ${outcome.to}`
|
|
556
|
+
if (outcome.kind === 'relinked-to-local') return `Link typeclaw to local checkout (${outcome.to})`
|
|
504
557
|
return null
|
|
505
558
|
}
|
|
506
559
|
|
|
@@ -524,6 +577,7 @@ export async function planStart({
|
|
|
524
577
|
hostdControl,
|
|
525
578
|
publishHost = '127.0.0.1',
|
|
526
579
|
tuiToken = null,
|
|
580
|
+
platform = process.platform,
|
|
527
581
|
}: PlanStartOptions): Promise<StartPlan> {
|
|
528
582
|
const containerName = containerNameFromCwd(cwd)
|
|
529
583
|
const imageTag = imageTagFromCwd(cwd)
|
|
@@ -660,8 +714,10 @@ export async function planStart({
|
|
|
660
714
|
|
|
661
715
|
runArgs.push(...dockerBindMount({ src: cwd, dst: '/agent' }))
|
|
662
716
|
|
|
663
|
-
if (shouldMirrorDevSource(devSourcePath, cwd)) {
|
|
717
|
+
if (shouldMirrorDevSource(devSourcePath, cwd, platform)) {
|
|
664
718
|
runArgs.push(...dockerBindMount({ src: devSourcePath, dst: devSourcePath, readonly: true }))
|
|
719
|
+
} else if (shouldMountWindowsDevSource(devSourcePath, platform)) {
|
|
720
|
+
runArgs.push(...dockerBindMount({ src: devSourcePath, dst: DEV_SOURCE_CONTAINER_PATH, readonly: true }))
|
|
665
721
|
}
|
|
666
722
|
|
|
667
723
|
for (const mount of mounts) {
|
|
@@ -733,6 +789,16 @@ export async function refreshDockerfile(
|
|
|
733
789
|
// `docker build`. The user sees one successful `typeclaw start` instead of a
|
|
734
790
|
// buildx-specific dead end. A genuine Dockerfile error fails both paths, so the
|
|
735
791
|
// retry costs at most one extra attempt before the real error surfaces.
|
|
792
|
+
//
|
|
793
|
+
// Layered on top is a credential-helper recovery: typeclaw only pulls PUBLIC
|
|
794
|
+
// images (the BuildKit syntax frontend + the typeclaw-base FROM), but a broken
|
|
795
|
+
// `credsStore`/`credHelpers` in ~/.docker/config.json makes docker abort the
|
|
796
|
+
// pull trying to exec a helper binary that isn't on PATH (the canonical Windows
|
|
797
|
+
// Docker Desktop failure). When a build fails with exactly that signature we
|
|
798
|
+
// retry the SAME build under a sanitized DOCKER_CONFIG that strips only the
|
|
799
|
+
// broken helper hooks — anonymous pulls then succeed and the user's real config
|
|
800
|
+
// is left untouched. This is checked BEFORE the buildx->legacy strip so a
|
|
801
|
+
// cred-helper failure doesn't get misdiagnosed as a buildx problem.
|
|
736
802
|
async function runImageBuild(args: {
|
|
737
803
|
exec: DockerExec
|
|
738
804
|
cwd: string
|
|
@@ -741,19 +807,93 @@ async function runImageBuild(args: {
|
|
|
741
807
|
hasBuildx: boolean
|
|
742
808
|
}): Promise<boolean> {
|
|
743
809
|
const { exec, cwd, imageTag, buildContext, hasBuildx } = args
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
810
|
+
const buildArgv = (frontend: 'buildx' | 'legacy'): string[] =>
|
|
811
|
+
frontend === 'buildx'
|
|
812
|
+
? ['buildx', 'build', '--load', '-t', imageTag, buildContext]
|
|
813
|
+
: ['build', '-t', imageTag, buildContext]
|
|
814
|
+
|
|
815
|
+
let sanitizedConfig: SanitizedDockerConfig | null = null
|
|
816
|
+
const attempt = async (frontend: 'buildx' | 'legacy'): Promise<DockerExecResult> =>
|
|
817
|
+
exec(buildArgv(frontend), { cwd, inheritStdio: true, captureStderr: true, env: sanitizedConfig?.env })
|
|
818
|
+
|
|
819
|
+
try {
|
|
820
|
+
let frontend: 'buildx' | 'legacy' = hasBuildx ? 'buildx' : 'legacy'
|
|
821
|
+
let result = await attempt(frontend)
|
|
822
|
+
if (result.exitCode === 0) return true
|
|
823
|
+
|
|
824
|
+
// Same-frontend retry: a broken credential helper aborts the pull before
|
|
825
|
+
// the builder ever matters, so strip it and retry the identical build.
|
|
826
|
+
if (sanitizedConfig === null && isMissingDockerCredentialHelper(result.stderr)) {
|
|
827
|
+
sanitizedConfig = await createSanitizedDockerConfig()
|
|
828
|
+
if (sanitizedConfig) {
|
|
829
|
+
result = await attempt(frontend)
|
|
830
|
+
if (result.exitCode === 0) return true
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
if (frontend === 'buildx') {
|
|
835
|
+
// buildx failed for a non-cred reason — fall back to the legacy builder
|
|
836
|
+
// against a stripped Dockerfile so a misconfigured-buildx host still ends
|
|
837
|
+
// up with an image. The sanitized config (if any) carries into the retry.
|
|
838
|
+
await refreshDockerfile(cwd, { buildKit: false })
|
|
839
|
+
frontend = 'legacy'
|
|
840
|
+
result = await attempt(frontend)
|
|
841
|
+
if (result.exitCode === 0) return true
|
|
842
|
+
if (sanitizedConfig === null && isMissingDockerCredentialHelper(result.stderr)) {
|
|
843
|
+
sanitizedConfig = await createSanitizedDockerConfig()
|
|
844
|
+
if (sanitizedConfig) {
|
|
845
|
+
result = await attempt(frontend)
|
|
846
|
+
if (result.exitCode === 0) return true
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
if (sanitizedConfig !== null) {
|
|
852
|
+
process.stderr.write(
|
|
853
|
+
'typeclaw: docker build still failed after retrying public image pulls without the configured ' +
|
|
854
|
+
'credential helper. Your ~/.docker/config.json credsStore/credHelpers may be broken.\n',
|
|
855
|
+
)
|
|
856
|
+
}
|
|
857
|
+
return false
|
|
858
|
+
} finally {
|
|
859
|
+
await sanitizedConfig?.cleanup()
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
type SanitizedDockerConfig = { env: { DOCKER_CONFIG: string }; cleanup: () => Promise<void> }
|
|
864
|
+
|
|
865
|
+
// Materializes a temp DOCKER_CONFIG dir that is a full DEEP COPY of the user's
|
|
866
|
+
// ~/.docker tree with only the broken credential-helper hooks stripped from the
|
|
867
|
+
// copied config.json. Returns null when there's nothing to strip (no creds
|
|
868
|
+
// hooks present), so the caller skips a pointless retry. Cleanup removes the dir
|
|
869
|
+
// on every build outcome.
|
|
870
|
+
//
|
|
871
|
+
// DOCKER_CONFIG is not just credentials: `contexts/` maps the current docker
|
|
872
|
+
// context (e.g. Docker Desktop's `desktop-linux`) to the daemon endpoint, and
|
|
873
|
+
// `buildx/` holds builder instance state. A relocated config missing those
|
|
874
|
+
// makes `docker buildx build` (and `docker build`, which Docker Desktop forwards
|
|
875
|
+
// to `buildx build --builder <currentContext>`) fail with `no builder
|
|
876
|
+
// "desktop-linux" found` — the exact second failure this replaces. The earlier
|
|
877
|
+
// approach symlinked those subdirs, but Windows `fs.symlink` throws EPERM
|
|
878
|
+
// without Developer Mode/admin, so the catch silently produced a config dir with
|
|
879
|
+
// the context/builder state ABSENT. A recursive copy is portable and preserves
|
|
880
|
+
// the full topology; only config.json is overwritten with the sanitized form.
|
|
881
|
+
async function createSanitizedDockerConfig(): Promise<SanitizedDockerConfig | null> {
|
|
882
|
+
const srcDir = dockerConfigDir()
|
|
883
|
+
const raw = await readFile(join(srcDir, 'config.json'), 'utf8').catch(() => null)
|
|
884
|
+
const sanitized = sanitizeDockerConfigJson(raw)
|
|
885
|
+
if (sanitized === null) return null
|
|
886
|
+
|
|
887
|
+
const dir = await mkdtemp(join(tmpdir(), 'typeclaw-dockercfg-'))
|
|
888
|
+
const cleanup = (): Promise<void> => rm(dir, { recursive: true, force: true })
|
|
889
|
+
try {
|
|
890
|
+
if (existsSync(srcDir)) await cp(srcDir, dir, { recursive: true, dereference: false })
|
|
891
|
+
await writeFile(join(dir, 'config.json'), sanitized)
|
|
892
|
+
} catch {
|
|
893
|
+
await cleanup()
|
|
894
|
+
return null
|
|
754
895
|
}
|
|
755
|
-
|
|
756
|
-
return legacy.exitCode === 0
|
|
896
|
+
return { env: { DOCKER_CONFIG: dir }, cleanup }
|
|
757
897
|
}
|
|
758
898
|
|
|
759
899
|
export async function refreshGitignore(cwd: string): Promise<void> {
|
|
@@ -907,7 +1047,12 @@ async function detectDevSource(cwd: string): Promise<string | null> {
|
|
|
907
1047
|
const raw = await readFile(join(cwd, PACKAGE_FILE), 'utf8')
|
|
908
1048
|
const pkg = JSON.parse(raw) as { dependencies?: Record<string, string> }
|
|
909
1049
|
const spec = pkg.dependencies?.typeclaw
|
|
910
|
-
if (
|
|
1050
|
+
if (typeof spec !== 'string') return null
|
|
1051
|
+
// Windows dev-mode declares `link:typeclaw` (a `bun link` registration);
|
|
1052
|
+
// the checkout path isn't in the spec, so resolve it from bun's global
|
|
1053
|
+
// link target. POSIX dev-mode declares `file:<rel>` and encodes the path.
|
|
1054
|
+
if (spec.startsWith('link:')) return resolveBunLinkedPackage(TYPECLAW_PACKAGE)
|
|
1055
|
+
if (!spec.startsWith('file:')) return null
|
|
911
1056
|
const target = spec.slice('file:'.length)
|
|
912
1057
|
return isAbsolute(target) ? resolve(target) : resolve(cwd, target)
|
|
913
1058
|
} catch {
|
|
@@ -915,16 +1060,15 @@ async function detectDevSource(cwd: string): Promise<string | null> {
|
|
|
915
1060
|
}
|
|
916
1061
|
}
|
|
917
1062
|
|
|
918
|
-
//
|
|
919
|
-
// /agent. The mirror mount bind-mounts that path at the SAME path inside
|
|
920
|
-
// (Linux) container so the symlink resolves. That only works when the host
|
|
921
|
-
// is itself a valid Linux container path — true on POSIX, false on native
|
|
1063
|
+
// POSIX dev mode: node_modules/typeclaw is a symlink to an absolute host path
|
|
1064
|
+
// outside /agent. The mirror mount bind-mounts that path at the SAME path inside
|
|
1065
|
+
// the (Linux) container so the symlink resolves. That only works when the host
|
|
1066
|
+
// path is itself a valid Linux container path — true on POSIX, false on native
|
|
922
1067
|
// Windows where devSourcePath is `C:\...` (not an absolute Linux path, so it
|
|
923
|
-
// cannot be a container mount `dst
|
|
924
|
-
//
|
|
925
|
-
//
|
|
926
|
-
//
|
|
927
|
-
// from npm (a registry spec, not file:), so they never hit this path.
|
|
1068
|
+
// cannot be a same-path container mount `dst`). Native Windows takes the
|
|
1069
|
+
// `shouldMountWindowsDevSource` branch instead (mount the checkout directly over
|
|
1070
|
+
// the in-container node_modules path). End users install typeclaw from npm (a
|
|
1071
|
+
// registry spec, not file:), so they never hit either dev path.
|
|
928
1072
|
export function shouldMirrorDevSource(
|
|
929
1073
|
devSourcePath: string | null,
|
|
930
1074
|
cwd: string,
|
|
@@ -933,6 +1077,19 @@ export function shouldMirrorDevSource(
|
|
|
933
1077
|
return devSourcePath !== null && !devSourcePath.startsWith(cwd) && !isWindows(platform)
|
|
934
1078
|
}
|
|
935
1079
|
|
|
1080
|
+
// Native-Windows dev mode (#899): the host's `C:\...` checkout cannot be
|
|
1081
|
+
// same-path mirror-mounted into a Linux container. Instead, bind-mount the
|
|
1082
|
+
// checkout directly over the standard resolution path `/agent/node_modules/
|
|
1083
|
+
// typeclaw` inside the container, so Node/Bun resolve typeclaw from source
|
|
1084
|
+
// regardless of how the host materialized node_modules/typeclaw (a junction,
|
|
1085
|
+
// per prepareWindowsDevJunction).
|
|
1086
|
+
export function shouldMountWindowsDevSource(
|
|
1087
|
+
devSourcePath: string | null,
|
|
1088
|
+
platform: NodeJS.Platform = process.platform,
|
|
1089
|
+
): devSourcePath is string {
|
|
1090
|
+
return devSourcePath !== null && isWindows(platform)
|
|
1091
|
+
}
|
|
1092
|
+
|
|
936
1093
|
// True when the agent's package.json declares typeclaw via `file:` or
|
|
937
1094
|
// `link:` — i.e. a developer is iterating on the typeclaw source via a
|
|
938
1095
|
// locally-linked checkout. `bun install` keys its file-dep cache on
|
|
@@ -942,14 +1099,18 @@ export function shouldMirrorDevSource(
|
|
|
942
1099
|
// users (`^X.Y.Z`, `~X.Y.Z`, exact pins) pay nothing because their
|
|
943
1100
|
// install path is already cache-correct.
|
|
944
1101
|
async function hasLocallyLinkedTypeclawDep(cwd: string): Promise<boolean> {
|
|
1102
|
+
const spec = await readTypeclawDepSpec(cwd)
|
|
1103
|
+
return spec !== null && (spec.startsWith('file:') || spec.startsWith('link:'))
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
async function readTypeclawDepSpec(cwd: string): Promise<string | null> {
|
|
945
1107
|
try {
|
|
946
1108
|
const raw = await readFile(join(cwd, PACKAGE_FILE), 'utf8')
|
|
947
1109
|
const pkg = JSON.parse(raw) as { dependencies?: Record<string, string> }
|
|
948
1110
|
const spec = pkg.dependencies?.typeclaw
|
|
949
|
-
|
|
950
|
-
return spec.startsWith('file:') || spec.startsWith('link:')
|
|
1111
|
+
return typeof spec === 'string' ? spec : null
|
|
951
1112
|
} catch {
|
|
952
|
-
return
|
|
1113
|
+
return null
|
|
953
1114
|
}
|
|
954
1115
|
}
|
|
955
1116
|
|
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
|
}
|