typeclaw 0.47.2 → 0.48.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/package.json +1 -1
- package/src/agent/index.ts +1 -2
- package/src/agent/loop-guard.ts +71 -41
- package/src/agent/plugin-tools.ts +234 -58
- package/src/agent/system-prompt.ts +1 -1
- package/src/agent/turn-runner.ts +12 -2
- package/src/agent-messenger/config-dir.ts +131 -0
- package/src/agent-messenger/host-config-dir.ts +121 -0
- package/src/bundled-plugins/agent-browser/index.ts +0 -38
- package/src/bundled-plugins/agent-browser/skills/agent-browser/SKILL.md +1 -1
- package/src/bundled-plugins/guard/policies/non-workspace-write.ts +16 -1
- package/src/bundled-plugins/memory/append-tool.ts +75 -2
- package/src/bundled-plugins/memory/frontmatter.ts +13 -2
- package/src/bundled-plugins/memory/load-memory.ts +1 -1
- package/src/bundled-plugins/memory/memory-logger.ts +5 -1
- package/src/bundled-plugins/memory/secret-detector.ts +7 -0
- package/src/bundled-plugins/memory/vector/hybrid.ts +3 -1
- package/src/bundled-plugins/memory/vector/passages.ts +5 -1
- package/src/bundled-plugins/security/index.ts +148 -98
- package/src/bundled-plugins/security/policies/private-surface-read.ts +43 -28
- package/src/channels/adapters/discord-bot-edit.ts +3 -5
- package/src/channels/adapters/discord-bot-reactions.ts +4 -6
- package/src/channels/adapters/discord-bot-slash-commands.ts +3 -1
- package/src/channels/adapters/discord-bot.ts +20 -23
- package/src/channels/adapters/discord-edit.ts +3 -5
- package/src/channels/adapters/discord-reactions.ts +4 -6
- package/src/channels/adapters/discord.ts +1 -1
- package/src/channels/adapters/github/decoy-reviewer.ts +2 -1
- package/src/channels/adapters/github/history.ts +2 -1
- package/src/channels/adapters/github/inbound.ts +4 -11
- package/src/channels/adapters/github/index.ts +6 -9
- package/src/channels/adapters/github/outbound.ts +3 -6
- package/src/channels/adapters/github/reactions.ts +3 -2
- package/src/channels/adapters/github/reconcile-cooldown-store.ts +4 -6
- package/src/channels/adapters/github/reconcile-open-prs.ts +5 -4
- package/src/channels/adapters/github/recover-failed-deliveries.ts +2 -5
- package/src/channels/adapters/github/review-state.ts +3 -2
- package/src/channels/adapters/github/review-thread-resolver.ts +3 -2
- package/src/channels/adapters/github/webhook-register.ts +5 -8
- package/src/channels/adapters/instagram-channel-resolver.ts +3 -5
- package/src/channels/adapters/instagram.ts +1 -1
- package/src/channels/adapters/kakaotalk-author-resolver.ts +2 -5
- package/src/channels/adapters/kakaotalk-channel-resolver.ts +3 -5
- package/src/channels/adapters/kakaotalk-fetch-attachment.ts +2 -1
- package/src/channels/adapters/kakaotalk-membership.ts +2 -5
- package/src/channels/adapters/kakaotalk-typing.ts +1 -1
- package/src/channels/adapters/kakaotalk.ts +1 -1
- package/src/channels/adapters/line-channel-resolver.ts +3 -5
- package/src/channels/adapters/line.ts +1 -1
- package/src/channels/adapters/slack-bot-edit.ts +1 -1
- package/src/channels/adapters/slack-bot-reactions.ts +4 -6
- package/src/channels/adapters/slack-bot.ts +8 -8
- package/src/channels/adapters/slack-edit.ts +3 -5
- package/src/channels/adapters/slack-reactions.ts +4 -6
- package/src/channels/adapters/slack.ts +1 -1
- package/src/channels/adapters/teams-edit.ts +2 -5
- package/src/channels/adapters/teams.ts +1 -1
- package/src/channels/adapters/telegram-bot-edit.ts +4 -7
- package/src/channels/adapters/telegram-bot.ts +1 -1
- package/src/channels/adapters/webex-bot.ts +1 -1
- package/src/channels/adapters/webex-edit.ts +3 -5
- package/src/channels/adapters/webex.ts +1 -1
- package/src/channels/github-review-claim.ts +89 -4
- package/src/channels/github-token-bridge.ts +2 -1
- package/src/channels/manager.ts +478 -64
- package/src/channels/membership-cache.ts +2 -5
- package/src/channels/persistence.ts +3 -6
- package/src/channels/reloadable.ts +23 -6
- package/src/channels/router.ts +134 -56
- package/src/channels/tunnel-bridge.ts +2 -1
- package/src/channels/types.ts +6 -3
- package/src/cli/channel.ts +15 -16
- package/src/cli/hostd.ts +61 -38
- package/src/cli/init.ts +21 -7
- package/src/cli/model.ts +6 -3
- package/src/cli/restart.ts +13 -15
- package/src/compose/restart.ts +14 -6
- package/src/config/config.ts +10 -0
- package/src/config/providers.ts +68 -0
- package/src/container/agent-operation-lock.ts +85 -0
- package/src/container/controller.ts +6 -0
- package/src/container/index.ts +8 -0
- package/src/container/restart.ts +55 -0
- package/src/container/shared.ts +5 -0
- package/src/container/start.ts +70 -4
- package/src/container/stop.ts +17 -1
- package/src/dependencies/bin-resolver.ts +88 -0
- package/src/dependencies/bins.ts +227 -0
- package/src/dependencies/index.ts +17 -0
- package/src/doctor/checks.ts +2 -0
- package/src/doctor/operational-incidents.ts +32 -0
- package/src/hostd/credential-rotation-apply.ts +94 -0
- package/src/hostd/daemon.ts +1 -1
- package/src/hostd/paths.ts +17 -0
- package/src/hostd/supervisor.ts +27 -10
- package/src/init/dockerfile.ts +6 -5
- package/src/init/env-file.ts +42 -18
- package/src/init/instagram-auth.ts +55 -31
- package/src/init/kakaotalk-auth.ts +1 -5
- package/src/init/line-auth.ts +45 -29
- package/src/init/models-dev.ts +131 -10
- package/src/init/opengateway-catalog.ts +120 -0
- package/src/init/validate-api-key.ts +26 -4
- package/src/operations/classify-tool-outcome.ts +151 -0
- package/src/operations/incidents.ts +274 -0
- package/src/operations/index.ts +3 -0
- package/src/operations/remediations.ts +41 -0
- package/src/reload/client.ts +8 -2
- package/src/reload/docker-exec-client.ts +10 -2
- package/src/reload/index.ts +1 -1
- package/src/reload/recover.ts +5 -3
- package/src/reload/registry.ts +5 -5
- package/src/reload/types.ts +9 -1
- package/src/run/index.ts +5 -0
- package/src/sandbox/canonical-secrets.ts +10 -1
- package/src/sandbox/dependency-bins.ts +125 -0
- package/src/sandbox/hidden-paths.ts +4 -1
- package/src/sandbox/index.ts +8 -0
- package/src/sandbox/policy.ts +1 -1
- package/src/sandbox/privileged-runtime.ts +7 -12
- package/src/sandbox/runtime-private.ts +4 -0
- package/src/sandbox/writable-zones.ts +4 -4
- package/src/server/index.ts +7 -5
- package/src/shared/protocol.ts +6 -1
- package/src/test-helpers/fake-agent-operation-lock.ts +66 -0
- package/typeclaw.schema.json +10 -5
- package/src/bundled-plugins/agent-browser/shim-install.ts +0 -179
- package/src/bundled-plugins/agent-browser/shim.ts +0 -108
- /package/src/channels/{adapters/describe-error.ts → describe-error.ts} +0 -0
|
@@ -7,6 +7,7 @@ import type { PermissionService } from '@/permissions/permissions'
|
|
|
7
7
|
|
|
8
8
|
import { CANONICAL_AGENT_SECRET_DIRS, CANONICAL_AGENT_SECRET_FILES } from './canonical-secrets'
|
|
9
9
|
import { SandboxMaskTargetError } from './errors'
|
|
10
|
+
import { CANONICAL_AGENT_RUNTIME_PRIVATE_FILES } from './runtime-private'
|
|
10
11
|
|
|
11
12
|
export type HiddenPaths = {
|
|
12
13
|
dirs: string[]
|
|
@@ -38,7 +39,9 @@ export function resolveHiddenPaths(
|
|
|
38
39
|
...CANONICAL_AGENT_SECRET_DIRS.map((dir) => join(agentDir, dir)),
|
|
39
40
|
...(seesPrivate ? [] : PRIVATE_DIRS.map((dir) => join(agentDir, dir))),
|
|
40
41
|
]
|
|
41
|
-
const files = CANONICAL_AGENT_SECRET_FILES.map((f) =>
|
|
42
|
+
const files = [...CANONICAL_AGENT_SECRET_FILES, ...CANONICAL_AGENT_RUNTIME_PRIVATE_FILES].map((f) =>
|
|
43
|
+
join(agentDir, f),
|
|
44
|
+
)
|
|
42
45
|
return { dirs, files }
|
|
43
46
|
}
|
|
44
47
|
|
package/src/sandbox/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export {
|
|
|
6
6
|
CANONICAL_HOME_SECRET_FILES,
|
|
7
7
|
CONTAINER_RUNTIME_HOME,
|
|
8
8
|
} from './canonical-secrets'
|
|
9
|
+
export { CANONICAL_AGENT_RUNTIME_PRIVATE_FILES } from './runtime-private'
|
|
9
10
|
export {
|
|
10
11
|
buildProcBindProbeScript,
|
|
11
12
|
canBindProcSafely,
|
|
@@ -44,6 +45,13 @@ export {
|
|
|
44
45
|
type PrivilegedSandboxRuntime,
|
|
45
46
|
} from './privileged-runtime'
|
|
46
47
|
export { ensureSessionTmpDir, isUnderTmp, mapVirtualTmpPath, SESSION_TMP_ROOT, sessionTmpDir } from './session-tmp'
|
|
48
|
+
export {
|
|
49
|
+
DEPENDENCY_BIN_SANDBOX_DIR,
|
|
50
|
+
DEPENDENCY_BIN_SANDBOX_PATH,
|
|
51
|
+
dependencyBinUnavailableHint,
|
|
52
|
+
reconcileDependencyBinWrappers,
|
|
53
|
+
type DependencyBinReconciliation,
|
|
54
|
+
} from './dependency-bins'
|
|
47
55
|
export { formatCommand, shellQuote } from './quote'
|
|
48
56
|
export {
|
|
49
57
|
SandboxDegradedProcError,
|
package/src/sandbox/policy.ts
CHANGED
|
@@ -153,7 +153,7 @@ export type SandboxPolicy = {
|
|
|
153
153
|
// these, every sandboxed bun invocation — the core subagent install path —
|
|
154
154
|
// fails before it starts.
|
|
155
155
|
export const DEFAULT_SANDBOX_ENV: Record<string, string> = {
|
|
156
|
-
PATH: '/usr/local/bin:/usr/bin:/bin',
|
|
156
|
+
PATH: '/tmp/typeclaw-dependency-bin:/usr/local/bin:/usr/bin:/bin',
|
|
157
157
|
HOME: '/tmp',
|
|
158
158
|
LANG: 'C.UTF-8',
|
|
159
159
|
BUN_TMPDIR: '/tmp',
|
|
@@ -62,18 +62,13 @@ export async function resolvePrivilegedSandboxRuntime(options: {
|
|
|
62
62
|
const executable = unwrapBunx(parsed)
|
|
63
63
|
if (executable === null) return runtime
|
|
64
64
|
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
// confused
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
executable.executable.startsWith('agent-')
|
|
73
|
-
) {
|
|
74
|
-
return runtime
|
|
75
|
-
}
|
|
76
|
-
|
|
65
|
+
// Credentials are default-deny: only an explicit broker below grants a
|
|
66
|
+
// profile, and `git` is the only broker. Do not add executable-name checks
|
|
67
|
+
// here. The confused-deputy argument belongs to the default, not to a list of
|
|
68
|
+
// names — it holds for every model-controlled child that can print or upload
|
|
69
|
+
// files, including ones not yet written. A name list is also where beliefs
|
|
70
|
+
// about a tool's credential layout accumulate; one such belief was wrong and
|
|
71
|
+
// refused a working CLI family outright. See this file's history.
|
|
77
72
|
if (executable.executable === 'git') {
|
|
78
73
|
runtime.env.GIT_CONFIG_GLOBAL = '/dev/null'
|
|
79
74
|
runtime.env.GIT_CONFIG_NOSYSTEM = '1'
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Runtime-owned operational state is private to TypeClaw, but is not a
|
|
2
|
+
// credential. Keep this category separate from canonical-secrets so security
|
|
3
|
+
// diagnostics never mislabel incident metadata as secret material.
|
|
4
|
+
export const CANONICAL_AGENT_RUNTIME_PRIVATE_FILES = ['.typeclaw/incidents.json'] as const
|
|
@@ -71,10 +71,10 @@ const FORBIDDEN_WRITABLE_ROOTS = [
|
|
|
71
71
|
// `echo … > cron.json` from bash and defeat the guard entirely. Keeping them off
|
|
72
72
|
// this list forces every mutation of a guarded file through the one guarded path
|
|
73
73
|
// (the write/edit tool), so a managed file has exactly one mutation boundary.
|
|
74
|
-
// `package.json`
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
const WRITABLE_ROOT_FILES = ['AGENTS.md', 'IDENTITY.md', 'SOUL.md', 'USER.md'
|
|
74
|
+
// `package.json` is operator-owned because direct dependencies define the
|
|
75
|
+
// executable surface exposed in the model sandbox. It must not receive an RW
|
|
76
|
+
// rebind that would let model-driven bash expand its own PATH capabilities.
|
|
77
|
+
const WRITABLE_ROOT_FILES = ['AGENTS.md', 'IDENTITY.md', 'SOUL.md', 'USER.md'] as const
|
|
78
78
|
|
|
79
79
|
// SECURITY: the symlink rejection is load-bearing. An RW bind follows symlinks,
|
|
80
80
|
// so a `workspace -> /etc` symlink at a zone root would grant write access to an
|
package/src/server/index.ts
CHANGED
|
@@ -41,7 +41,7 @@ import type { McpManager } from '@/mcp'
|
|
|
41
41
|
import type { PermissionService } from '@/permissions'
|
|
42
42
|
import type { HookBus } from '@/plugin'
|
|
43
43
|
import type { BrokerWsData, ContainerBroker } from '@/portbroker'
|
|
44
|
-
import type { ReloadAllResult, ReloadRegistry } from '@/reload'
|
|
44
|
+
import type { ReloadAllResult, ReloadCause, ReloadContext, ReloadRegistry } from '@/reload'
|
|
45
45
|
import type { ClaimController, ClaimResultEvent } from '@/role-claim'
|
|
46
46
|
import type { PluginRuntime, PluginRuntimeState } from '@/run/plugin-runtime'
|
|
47
47
|
import type { CommandOutbound, CommandRunner } from '@/server/command-runner'
|
|
@@ -64,7 +64,7 @@ import type {
|
|
|
64
64
|
import type { Stream, StreamMessage, StreamMessageId, Unsubscribe } from '@/stream'
|
|
65
65
|
import type { TunnelManager } from '@/tunnels'
|
|
66
66
|
|
|
67
|
-
export type ReloadAllFn = () => Promise<ReloadAllResult>
|
|
67
|
+
export type ReloadAllFn = (context?: ReloadContext) => Promise<ReloadAllResult>
|
|
68
68
|
export type CreateSessionFn = (options?: CreateSessionOptions) => Promise<AgentSession | CreateSessionResult>
|
|
69
69
|
|
|
70
70
|
export type ServerLogger = {
|
|
@@ -744,7 +744,7 @@ export function createServer({
|
|
|
744
744
|
}
|
|
745
745
|
|
|
746
746
|
if (msg.type === 'reload') {
|
|
747
|
-
await handleReload(ws, reloadAll, reloadRegistry, msg.scope)
|
|
747
|
+
await handleReload(ws, reloadAll, reloadRegistry, msg.scope, msg.cause)
|
|
748
748
|
return
|
|
749
749
|
}
|
|
750
750
|
|
|
@@ -1678,7 +1678,9 @@ async function handleReload(
|
|
|
1678
1678
|
reloadAll: ReloadAllFn | undefined,
|
|
1679
1679
|
reloadRegistry: ReloadRegistry | undefined,
|
|
1680
1680
|
scope: string | undefined,
|
|
1681
|
+
cause: ReloadCause | undefined,
|
|
1681
1682
|
): Promise<void> {
|
|
1683
|
+
const context = cause === undefined ? undefined : { cause }
|
|
1682
1684
|
if (scope !== undefined && scope.length > 0) {
|
|
1683
1685
|
if (!reloadRegistry) {
|
|
1684
1686
|
send(ws, {
|
|
@@ -1688,7 +1690,7 @@ async function handleReload(
|
|
|
1688
1690
|
return
|
|
1689
1691
|
}
|
|
1690
1692
|
try {
|
|
1691
|
-
const result = await reloadRegistry.reloadOne(scope)
|
|
1693
|
+
const result = await reloadRegistry.reloadOne(scope, context)
|
|
1692
1694
|
send(ws, { type: 'reload_result', results: [result] })
|
|
1693
1695
|
} catch (err) {
|
|
1694
1696
|
send(ws, {
|
|
@@ -1705,7 +1707,7 @@ async function handleReload(
|
|
|
1705
1707
|
return
|
|
1706
1708
|
}
|
|
1707
1709
|
try {
|
|
1708
|
-
const { results } = await reloadAll()
|
|
1710
|
+
const { results } = await reloadAll(context)
|
|
1709
1711
|
send(ws, { type: 'reload_result', results })
|
|
1710
1712
|
} catch (err) {
|
|
1711
1713
|
send(ws, {
|
package/src/shared/protocol.ts
CHANGED
|
@@ -2,6 +2,11 @@ export type ReloadResultPayload =
|
|
|
2
2
|
| { scope: string; ok: true; summary: string; details?: unknown }
|
|
3
3
|
| { scope: string; ok: false; reason: string }
|
|
4
4
|
|
|
5
|
+
// Structurally mirrors ReloadCause in src/reload/types.ts. Kept as its own
|
|
6
|
+
// declaration so the wire protocol stays free of subsystem imports, the same
|
|
7
|
+
// way ReloadResultPayload mirrors ReloadResult.
|
|
8
|
+
export type ReloadCausePayload = { kind: 'credential-rotation'; adapter: string }
|
|
9
|
+
|
|
5
10
|
export type PromptDelivery = 'queue' | 'steer' | 'interrupt'
|
|
6
11
|
|
|
7
12
|
export type DoctorRequestId = string
|
|
@@ -171,7 +176,7 @@ export type InspectServerMessage =
|
|
|
171
176
|
|
|
172
177
|
export type ClientMessage =
|
|
173
178
|
| { type: 'prompt'; text: string; delivery?: PromptDelivery }
|
|
174
|
-
| { type: 'reload'; scope?: string }
|
|
179
|
+
| { type: 'reload'; scope?: string; cause?: ReloadCausePayload }
|
|
175
180
|
| { type: 'restart' }
|
|
176
181
|
| { type: 'abort' }
|
|
177
182
|
| { type: 'queue_cancel'; messageId: string }
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { resolve } from 'node:path'
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
AgentOperation,
|
|
5
|
+
AgentOperationLease,
|
|
6
|
+
AgentOperationLockResult,
|
|
7
|
+
WithAgentOperationLock,
|
|
8
|
+
} from '@/container/agent-operation-lock'
|
|
9
|
+
import { containerNameFromCwd } from '@/container/shared'
|
|
10
|
+
|
|
11
|
+
export class FakeAgentOperationCoordinator {
|
|
12
|
+
readonly events: string[] = []
|
|
13
|
+
readonly operationLock: WithAgentOperationLock
|
|
14
|
+
|
|
15
|
+
private readonly active = new Set<string>()
|
|
16
|
+
|
|
17
|
+
constructor(private readonly contentionReason = 'contended') {
|
|
18
|
+
this.operationLock = async <T>(
|
|
19
|
+
input: { agentDir: string; operation: AgentOperation; lease?: AgentOperationLease },
|
|
20
|
+
run: (lease: AgentOperationLease) => Promise<T>,
|
|
21
|
+
): Promise<AgentOperationLockResult<T>> => {
|
|
22
|
+
const agentDir = resolve(input.agentDir)
|
|
23
|
+
const containerName = containerNameFromCwd(agentDir)
|
|
24
|
+
const lease = { containerName, agentDir }
|
|
25
|
+
if (input.lease !== undefined) {
|
|
26
|
+
if (input.lease.containerName !== containerName || resolve(input.lease.agentDir) !== agentDir) {
|
|
27
|
+
return { ok: false, reason: 'mismatched lease' }
|
|
28
|
+
}
|
|
29
|
+
return { ok: true, value: await run(input.lease) }
|
|
30
|
+
}
|
|
31
|
+
if (this.active.has(containerName)) {
|
|
32
|
+
this.events.push(`lock-contention:${input.operation}`)
|
|
33
|
+
return { ok: false, reason: this.contentionReason }
|
|
34
|
+
}
|
|
35
|
+
this.active.add(containerName)
|
|
36
|
+
this.events.push(`lock-enter:${input.operation}`)
|
|
37
|
+
try {
|
|
38
|
+
return { ok: true, value: await run(lease) }
|
|
39
|
+
} finally {
|
|
40
|
+
this.events.push(`lock-exit:${input.operation}`)
|
|
41
|
+
this.active.delete(containerName)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
park(): { entered: Promise<void>; wait: () => Promise<void>; release: () => void } {
|
|
47
|
+
const entered = deferred()
|
|
48
|
+
const released = deferred()
|
|
49
|
+
return {
|
|
50
|
+
entered: entered.promise,
|
|
51
|
+
wait: async () => {
|
|
52
|
+
entered.resolve()
|
|
53
|
+
await released.promise
|
|
54
|
+
},
|
|
55
|
+
release: () => released.resolve(),
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function deferred(): { promise: Promise<void>; resolve: () => void } {
|
|
61
|
+
let resolvePromise: () => void = () => {}
|
|
62
|
+
const promise = new Promise<void>((resolve) => {
|
|
63
|
+
resolvePromise = resolve
|
|
64
|
+
})
|
|
65
|
+
return { promise, resolve: resolvePromise }
|
|
66
|
+
}
|
package/typeclaw.schema.json
CHANGED
|
@@ -64,7 +64,8 @@
|
|
|
64
64
|
"moonshot/kimi-k2.7-code",
|
|
65
65
|
"moonshot/kimi-k2.6",
|
|
66
66
|
"moonshot/kimi-k2.5",
|
|
67
|
-
"moonshot-coding/kimi-for-coding"
|
|
67
|
+
"moonshot-coding/kimi-for-coding",
|
|
68
|
+
"opengateway/openai/gpt-5.4-nano"
|
|
68
69
|
]
|
|
69
70
|
},
|
|
70
71
|
{
|
|
@@ -120,7 +121,8 @@
|
|
|
120
121
|
"moonshot/kimi-k2.7-code",
|
|
121
122
|
"moonshot/kimi-k2.6",
|
|
122
123
|
"moonshot/kimi-k2.5",
|
|
123
|
-
"moonshot-coding/kimi-for-coding"
|
|
124
|
+
"moonshot-coding/kimi-for-coding",
|
|
125
|
+
"opengateway/openai/gpt-5.4-nano"
|
|
124
126
|
]
|
|
125
127
|
},
|
|
126
128
|
{
|
|
@@ -177,7 +179,8 @@
|
|
|
177
179
|
"moonshot/kimi-k2.7-code",
|
|
178
180
|
"moonshot/kimi-k2.6",
|
|
179
181
|
"moonshot/kimi-k2.5",
|
|
180
|
-
"moonshot-coding/kimi-for-coding"
|
|
182
|
+
"moonshot-coding/kimi-for-coding",
|
|
183
|
+
"opengateway/openai/gpt-5.4-nano"
|
|
181
184
|
]
|
|
182
185
|
},
|
|
183
186
|
{
|
|
@@ -232,7 +235,8 @@
|
|
|
232
235
|
"moonshot/kimi-k2.7-code",
|
|
233
236
|
"moonshot/kimi-k2.6",
|
|
234
237
|
"moonshot/kimi-k2.5",
|
|
235
|
-
"moonshot-coding/kimi-for-coding"
|
|
238
|
+
"moonshot-coding/kimi-for-coding",
|
|
239
|
+
"opengateway/openai/gpt-5.4-nano"
|
|
236
240
|
]
|
|
237
241
|
},
|
|
238
242
|
{
|
|
@@ -288,7 +292,8 @@
|
|
|
288
292
|
"moonshot/kimi-k2.7-code",
|
|
289
293
|
"moonshot/kimi-k2.6",
|
|
290
294
|
"moonshot/kimi-k2.5",
|
|
291
|
-
"moonshot-coding/kimi-for-coding"
|
|
295
|
+
"moonshot-coding/kimi-for-coding",
|
|
296
|
+
"opengateway/openai/gpt-5.4-nano"
|
|
292
297
|
]
|
|
293
298
|
},
|
|
294
299
|
{
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
lstatSync,
|
|
3
|
-
readFileSync,
|
|
4
|
-
readlinkSync,
|
|
5
|
-
renameSync,
|
|
6
|
-
statSync,
|
|
7
|
-
symlinkSync,
|
|
8
|
-
unlinkSync,
|
|
9
|
-
writeFileSync,
|
|
10
|
-
} from 'node:fs'
|
|
11
|
-
import { dirname, join, resolve as resolvePath } from 'node:path'
|
|
12
|
-
|
|
13
|
-
import { REAL_BIN_ENV } from './shim'
|
|
14
|
-
|
|
15
|
-
const DEFAULT_GLOBAL_BIN_PATH = '/usr/local/bin/agent-browser'
|
|
16
|
-
const DEFAULT_LOCAL_BIN_PATH = '/agent/node_modules/.bin/agent-browser'
|
|
17
|
-
const STASH_ROOT = '/usr/local/lib/typeclaw-agent-browser'
|
|
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'
|
|
21
|
-
|
|
22
|
-
export type InstallShimOptions = {
|
|
23
|
-
binPath?: string
|
|
24
|
-
stashDir?: string
|
|
25
|
-
shimEntry?: string
|
|
26
|
-
delegateTarget?: string
|
|
27
|
-
fs?: ShimFs
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type ShimFs = {
|
|
31
|
-
lstat: (path: string) => { isSymbolicLink: () => boolean } | null
|
|
32
|
-
// statExists follows symlinks: a broken symlink (link entry exists, target
|
|
33
|
-
// does not) returns false. This is the discriminator we need to skip
|
|
34
|
-
// installation when the host bind-mount surfaces dangling node_modules/.bin
|
|
35
|
-
// entries inside the container — see installShim's upstream guard.
|
|
36
|
-
statExists: (path: string) => boolean
|
|
37
|
-
readlink: (path: string) => string
|
|
38
|
-
readFile: (path: string) => string
|
|
39
|
-
rename: (from: string, to: string) => void
|
|
40
|
-
symlink: (target: string, path: string) => void
|
|
41
|
-
writeFile: (path: string, data: string, mode: number) => void
|
|
42
|
-
unlink: (path: string) => void
|
|
43
|
-
mkdirp: (path: string) => void
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export type InstallShimResult =
|
|
47
|
-
| { kind: 'installed'; realBin: string; binPath: string; stashTarget: string }
|
|
48
|
-
| { kind: 'delegated'; binPath: string; delegateTarget: string }
|
|
49
|
-
| { kind: 'already-installed'; binPath: string }
|
|
50
|
-
| { kind: 'no-upstream'; binPath: string }
|
|
51
|
-
|
|
52
|
-
export function installShim(opts: InstallShimOptions = {}): InstallShimResult {
|
|
53
|
-
const binPath = opts.binPath ?? DEFAULT_GLOBAL_BIN_PATH
|
|
54
|
-
const shimEntry = opts.shimEntry ?? defaultShimEntry()
|
|
55
|
-
const fs = opts.fs ?? defaultFs()
|
|
56
|
-
const stashDir = opts.stashDir ?? defaultStashDir(binPath)
|
|
57
|
-
const stashTarget = join(stashDir, 'agent-browser-real')
|
|
58
|
-
|
|
59
|
-
const stat = fs.lstat(binPath)
|
|
60
|
-
if (stat === null) return { kind: 'no-upstream', binPath }
|
|
61
|
-
|
|
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) {
|
|
67
|
-
if (fs.statExists(stashTarget)) return { kind: 'already-installed', binPath }
|
|
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.
|
|
71
|
-
fs.unlink(binPath)
|
|
72
|
-
return { kind: 'no-upstream', binPath }
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Bind-mounted node_modules/.bin entries can be dangling symlinks inside
|
|
76
|
-
// the container (host ran bun install; the container image did not). lstat
|
|
77
|
-
// alone passes for those. Follow the link with statExists before mutating
|
|
78
|
-
// anything — otherwise we'd stash a broken symlink and write a wrapper
|
|
79
|
-
// pointing at a target that never resolves.
|
|
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
|
-
}
|
|
86
|
-
|
|
87
|
-
const realBin = resolveCurrentTarget(binPath, stat, fs)
|
|
88
|
-
fs.mkdirp(stashDir)
|
|
89
|
-
if (stat.isSymbolicLink()) {
|
|
90
|
-
fs.unlink(binPath)
|
|
91
|
-
if (fs.lstat(stashTarget) !== null) fs.unlink(stashTarget)
|
|
92
|
-
fs.symlink(realBin, stashTarget)
|
|
93
|
-
} else {
|
|
94
|
-
if (fs.lstat(stashTarget) !== null) fs.unlink(stashTarget)
|
|
95
|
-
fs.rename(binPath, stashTarget)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
fs.writeFile(binPath, renderWrapper(shimEntry, stashTarget), 0o755)
|
|
99
|
-
return { kind: 'installed', realBin, binPath, stashTarget }
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export const KNOWN_BIN_PATHS = {
|
|
103
|
-
global: DEFAULT_GLOBAL_BIN_PATH,
|
|
104
|
-
local: DEFAULT_LOCAL_BIN_PATH,
|
|
105
|
-
} as const
|
|
106
|
-
|
|
107
|
-
function defaultStashDir(binPath: string): string {
|
|
108
|
-
// Per-binPath subdirectory under the image-owned stash root. Lives outside
|
|
109
|
-
// every bind-mounted agent folder so a host-side `bun install` cannot
|
|
110
|
-
// touch it; the wrapper at the bind-mounted location can be clobbered by
|
|
111
|
-
// host-side installs but the stash and image-level real binary stay safe.
|
|
112
|
-
const slug = binPath.replace(/[^A-Za-z0-9]+/g, '-').replace(/^-+|-+$/g, '')
|
|
113
|
-
return join(STASH_ROOT, slug)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function getWrapperKind(binPath: string, fs: ShimFs): 'image' | 'local-alias' | 'runtime' | null {
|
|
117
|
-
try {
|
|
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
|
|
122
|
-
} catch {
|
|
123
|
-
return null
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function resolveCurrentTarget(binPath: string, stat: { isSymbolicLink: () => boolean }, fs: ShimFs): string {
|
|
128
|
-
if (!stat.isSymbolicLink()) return binPath
|
|
129
|
-
const target = fs.readlink(binPath)
|
|
130
|
-
return resolvePath(dirname(binPath), target)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function renderWrapper(shimEntry: string, stashTarget: string): string {
|
|
134
|
-
return `#!/bin/sh
|
|
135
|
-
${SHIM_MARKER}
|
|
136
|
-
export ${REAL_BIN_ENV}="\${${REAL_BIN_ENV}:-${stashTarget}}"
|
|
137
|
-
exec bun run ${shimEntry} "$@"
|
|
138
|
-
`
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function renderDelegatingWrapper(delegateTarget: string): string {
|
|
142
|
-
return `#!/bin/sh
|
|
143
|
-
${LOCAL_ALIAS_MARKER}
|
|
144
|
-
exec "${delegateTarget}" "$@"
|
|
145
|
-
`
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function defaultShimEntry(): string {
|
|
149
|
-
return resolvePath(import.meta.dir, 'shim.ts')
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function defaultFs(): ShimFs {
|
|
153
|
-
return {
|
|
154
|
-
lstat: (path) => {
|
|
155
|
-
try {
|
|
156
|
-
return lstatSync(path)
|
|
157
|
-
} catch {
|
|
158
|
-
return null
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
statExists: (path) => {
|
|
162
|
-
try {
|
|
163
|
-
statSync(path)
|
|
164
|
-
return true
|
|
165
|
-
} catch {
|
|
166
|
-
return false
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
readlink: readlinkSync,
|
|
170
|
-
readFile: (path) => readFileSync(path, 'utf-8'),
|
|
171
|
-
rename: renameSync,
|
|
172
|
-
symlink: symlinkSync,
|
|
173
|
-
writeFile: (path, data, mode) => writeFileSync(path, data, { mode }),
|
|
174
|
-
unlink: unlinkSync,
|
|
175
|
-
mkdirp: (path) => {
|
|
176
|
-
Bun.spawnSync(['mkdir', '-p', path])
|
|
177
|
-
},
|
|
178
|
-
}
|
|
179
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
// PATH-shadow shim installed at the global bin path that `bun install -g
|
|
2
|
-
// agent-browser` previously occupied. Replaces the plugin's old prompt-nudge +
|
|
3
|
-
// bash-regex `tool.before` block, which was leaky (missed shell variations,
|
|
4
|
-
// bypassed by `typeclaw shell`, by spawned subprocesses, by the user typing
|
|
5
|
-
// it directly). Now ANY in-container `agent-browser` caller routes through
|
|
6
|
-
// here and gets the anti-fingerprint User-Agent default before execing the
|
|
7
|
-
// real upstream binary unchanged.
|
|
8
|
-
|
|
9
|
-
import { existsSync } from 'node:fs'
|
|
10
|
-
|
|
11
|
-
export const REAL_BIN_ENV = 'TYPECLAW_AGENT_BROWSER_REAL_BIN'
|
|
12
|
-
|
|
13
|
-
// Recent desktop Chrome on Linux x86_64. The shim runs inside the TypeClaw
|
|
14
|
-
// container (always Linux), so a macOS or Windows UA would mismatch the TCP
|
|
15
|
-
// fingerprint, Accept-Language, and JS-side platform — itself a bot signal on
|
|
16
|
-
// stricter sites (Cloudflare, Akamai, PerimeterX). `X11; Linux x86_64` is
|
|
17
|
-
// also correct on linux/arm64 hosts: Chrome on Linux does not expose ARM in
|
|
18
|
-
// the UA string at all (verified against current Chrome 131 releases).
|
|
19
|
-
// The upstream binary defaults to a UA that includes "HeadlessChrome" /
|
|
20
|
-
// a stale Chromium build, which is widely fingerprinted as a bot and
|
|
21
|
-
// silently triggers CAPTCHAs, 403s, blank pages, and A/B-test misrouting.
|
|
22
|
-
// Bump on Chrome major releases — same hygiene as the curl-impersonate pin
|
|
23
|
-
// in src/init/dockerfile.ts.
|
|
24
|
-
export const DEFAULT_USER_AGENT =
|
|
25
|
-
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
|
|
26
|
-
|
|
27
|
-
export const USER_AGENT_ENV = 'AGENT_BROWSER_USER_AGENT'
|
|
28
|
-
|
|
29
|
-
export function hasUserAgentFlag(argv: readonly string[]): boolean {
|
|
30
|
-
// Matches both `--user-agent <val>` and `--user-agent=<val>`. The upstream
|
|
31
|
-
// CLI does not document a short alias for --user-agent today (verified via
|
|
32
|
-
// `agent-browser --help`), so we only check the long form.
|
|
33
|
-
for (const arg of argv) {
|
|
34
|
-
if (arg === '--user-agent' || arg.startsWith('--user-agent=')) return true
|
|
35
|
-
}
|
|
36
|
-
return false
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function injectUserAgentEnv(
|
|
40
|
-
argv: readonly string[],
|
|
41
|
-
env: Record<string, string | undefined>,
|
|
42
|
-
defaultUa: string = DEFAULT_USER_AGENT,
|
|
43
|
-
): void {
|
|
44
|
-
// Upstream's precedence is CLI flag > env > default. We only inject the
|
|
45
|
-
// env when BOTH layers above it are absent so:
|
|
46
|
-
// - explicit `--user-agent foo` wins (mobile testing, intentional bot UA)
|
|
47
|
-
// - operator-set AGENT_BROWSER_USER_AGENT wins (per-shell override)
|
|
48
|
-
// - default UA fills the otherwise-empty slot
|
|
49
|
-
// `set device "iPhone 14"` is unaffected: it sets UA via CDP at runtime,
|
|
50
|
-
// not through this env var, so our injection doesn't fight device emulation.
|
|
51
|
-
if (env[USER_AGENT_ENV] !== undefined && env[USER_AGENT_ENV] !== '') return
|
|
52
|
-
if (hasUserAgentFlag(argv)) return
|
|
53
|
-
env[USER_AGENT_ENV] = defaultUa
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function resolveRealAgentBrowserBin(): string {
|
|
57
|
-
// Set by the installer when it moves the upstream symlink aside. Honored
|
|
58
|
-
// first so unit tests can point at a stub without touching the filesystem.
|
|
59
|
-
const fromEnv = process.env[REAL_BIN_ENV]
|
|
60
|
-
if (fromEnv && fromEnv.length > 0) return fromEnv
|
|
61
|
-
|
|
62
|
-
// Fallback: `bun install -g agent-browser` ships per-platform native bins
|
|
63
|
-
// under this stable path inside the bun image. The installer should have
|
|
64
|
-
// stashed a copy/symlink, but if the shim runs before the plugin's
|
|
65
|
-
// installer ever did (e.g. first agent boot), we can still find the real
|
|
66
|
-
// bin and the next plugin boot will install the shim properly.
|
|
67
|
-
const arch = process.arch === 'arm64' ? 'arm64' : process.arch === 'x64' ? 'x64' : null
|
|
68
|
-
const platform = process.platform === 'linux' ? 'linux' : process.platform === 'darwin' ? 'darwin' : null
|
|
69
|
-
if (arch !== null && platform !== null) {
|
|
70
|
-
const native = `/root/.bun/install/global/node_modules/agent-browser/bin/agent-browser-${platform}-${arch}`
|
|
71
|
-
if (existsSync(native)) return native
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
throw new Error(
|
|
75
|
-
`${REAL_BIN_ENV} is not set and no fallback agent-browser binary was found. ` +
|
|
76
|
-
`The shim cannot resolve the real upstream binary; refusing to exec to avoid an infinite loop.`,
|
|
77
|
-
)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export type ShimOptions = {
|
|
81
|
-
argv?: readonly string[]
|
|
82
|
-
realBin?: string
|
|
83
|
-
spawn?: (cmd: string[]) => { exited: Promise<number> }
|
|
84
|
-
env?: Record<string, string | undefined>
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export async function runShim(opts: ShimOptions = {}): Promise<number> {
|
|
88
|
-
const argv = opts.argv ?? process.argv.slice(2)
|
|
89
|
-
const realBin = opts.realBin ?? resolveRealAgentBrowserBin()
|
|
90
|
-
const spawn = opts.spawn ?? defaultSpawn
|
|
91
|
-
const env = opts.env ?? process.env
|
|
92
|
-
|
|
93
|
-
injectUserAgentEnv(argv, env)
|
|
94
|
-
return await spawn([realBin, ...argv]).exited
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function defaultSpawn(cmd: string[]): { exited: Promise<number> } {
|
|
98
|
-
// Inherit stdio so the upstream binary's TUI/spinner/colors work. The
|
|
99
|
-
// shim is meant to be invisible; intercepting stdio would make e.g.
|
|
100
|
-
// `agent-browser open` look broken to the caller.
|
|
101
|
-
const proc = Bun.spawn(cmd, { stdio: ['inherit', 'inherit', 'inherit'] })
|
|
102
|
-
return { exited: proc.exited }
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (import.meta.main) {
|
|
106
|
-
const code = await runShim()
|
|
107
|
-
process.exit(code)
|
|
108
|
-
}
|
|
File without changes
|