typeclaw 0.47.1 → 0.48.0
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 +167 -50
- package/src/agent/retry-same-ref.ts +89 -9
- package/src/agent/subagents.ts +88 -15
- package/src/agent/system-prompt.ts +1 -1
- package/src/agent/turn-runner.ts +60 -5
- package/src/bundled-plugins/agent-browser/index.ts +0 -35
- 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/operator/operator.ts +9 -2
- package/src/bundled-plugins/researcher/researcher.ts +4 -6
- 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/hostd.ts +56 -28
- package/src/config/config.ts +10 -0
- package/src/config/providers.ts +179 -0
- 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/init/dockerfile.ts +36 -18
- package/src/init/index.ts +1 -1
- package/src/init/models-dev.ts +17 -3
- 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/dependency-bins.ts +125 -0
- package/src/sandbox/errors.ts +32 -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 +88 -7
- 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/skills/typeclaw-monorepo/SKILL.md +1 -1
- package/src/skills/typeclaw-troubleshooting/SKILL.md +1 -1
- package/typeclaw.schema.json +35 -5
- package/src/bundled-plugins/agent-browser/shim-install.ts +0 -158
- 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',
|
|
@@ -2,7 +2,7 @@ import { chmod, lstat, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises
|
|
|
2
2
|
import { homedir, tmpdir } from 'node:os'
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
|
|
5
|
-
import { SandboxPolicyError } from './errors'
|
|
5
|
+
import { SandboxCredentialWithheldError, SandboxPolicyError } from './errors'
|
|
6
6
|
import type { SandboxMount } from './policy'
|
|
7
7
|
|
|
8
8
|
const SAFE_GIT_SUBCOMMANDS = new Set([
|
|
@@ -30,6 +30,49 @@ const SAFE_GIT_SUBCOMMANDS = new Set([
|
|
|
30
30
|
|
|
31
31
|
const SHELL_ACTIVE = new Set(['|', ';', '&', '\n', '\r', '(', ')', '{', '}', '<', '>', '`', '$', '\\'])
|
|
32
32
|
|
|
33
|
+
// The exact bins agent-messenger installs, kept in lockstep with the installed
|
|
34
|
+
// manifest by a test. Reserving the whole `agent-*` namespace instead would
|
|
35
|
+
// over-claim AND under-claim: an unrelated user-installed `agent-lint` would be
|
|
36
|
+
// refused with a false agent-messenger credential claim — the very class of
|
|
37
|
+
// false statement this refusal exists to prevent — while `amsg`, a real
|
|
38
|
+
// agent-messenger bin, carries no `agent-` prefix and would slip through.
|
|
39
|
+
export const AGENT_MESSENGER_BINS: ReadonlySet<string> = new Set([
|
|
40
|
+
'agent-channeltalk',
|
|
41
|
+
'agent-channeltalkbot',
|
|
42
|
+
'agent-discord',
|
|
43
|
+
'agent-discordbot',
|
|
44
|
+
'agent-imessage',
|
|
45
|
+
'agent-instagram',
|
|
46
|
+
'agent-kakaotalk',
|
|
47
|
+
'agent-line',
|
|
48
|
+
'agent-messenger',
|
|
49
|
+
'agent-slack',
|
|
50
|
+
'agent-slackbot',
|
|
51
|
+
'agent-teams',
|
|
52
|
+
'agent-telegram',
|
|
53
|
+
'agent-telegrambot',
|
|
54
|
+
'agent-webex',
|
|
55
|
+
'agent-webexbot',
|
|
56
|
+
'agent-wechatbot',
|
|
57
|
+
'agent-whatsapp',
|
|
58
|
+
'agent-whatsappbot',
|
|
59
|
+
'amsg',
|
|
60
|
+
])
|
|
61
|
+
|
|
62
|
+
// Ephemeral runners that execute a package bin named by their first operand.
|
|
63
|
+
// `bunx` is the bare-binary alias for `bun x` (see sandbox/package-install.ts);
|
|
64
|
+
// npx/pnpx are the non-bun spellings the bun-hygiene guard still permits.
|
|
65
|
+
const PACKAGE_RUNNERS = new Set(['bunx', 'npx', 'pnpx'])
|
|
66
|
+
const BUN_RUNNER_SUBCOMMANDS = new Set(['x', 'run'])
|
|
67
|
+
|
|
68
|
+
// Splits at the shell operators that begin a NEW simple command, mirroring
|
|
69
|
+
// `commandNeedsRealProc`. Deliberately coarse: it over-splits inside quotes and
|
|
70
|
+
// `$()`, but this feeds a DENY-ONLY decision, so a spurious extra segment can
|
|
71
|
+
// only make the refusal MORE likely — it can never grant a credential.
|
|
72
|
+
const SHELL_COMMAND_SEPARATOR = /(?:&&|\|\||[;|&\n()<>])+/
|
|
73
|
+
|
|
74
|
+
const ENV_ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/
|
|
75
|
+
|
|
33
76
|
export type PrivilegedSandboxRuntime = {
|
|
34
77
|
env: Record<string, string>
|
|
35
78
|
mounts: SandboxMount[]
|
|
@@ -46,6 +89,7 @@ export async function resolvePrivilegedSandboxRuntime(options: {
|
|
|
46
89
|
env?: NodeJS.ProcessEnv
|
|
47
90
|
homeDir?: string
|
|
48
91
|
}): Promise<PrivilegedSandboxRuntime> {
|
|
92
|
+
rejectAgentMessengerCommand(options.command)
|
|
49
93
|
const runtime = emptyRuntime()
|
|
50
94
|
// TYPECLAW_GIT_TOKEN is set only after the auth analyzer accepts a Git command.
|
|
51
95
|
// Trust that decision rather than reparsing its command with a less capable
|
|
@@ -62,15 +106,23 @@ export async function resolvePrivilegedSandboxRuntime(options: {
|
|
|
62
106
|
const executable = unwrapBunx(parsed)
|
|
63
107
|
if (executable === null) return runtime
|
|
64
108
|
|
|
109
|
+
// Re-checked here as well as in the deny-only scan: this path resolves quoted
|
|
110
|
+
// and `bunx`-wrapped executables the coarse segment split cannot.
|
|
111
|
+
if (AGENT_MESSENGER_BINS.has(path.basename(executable.executable))) {
|
|
112
|
+
throw new SandboxCredentialWithheldError(path.basename(executable.executable))
|
|
113
|
+
}
|
|
114
|
+
|
|
65
115
|
// These CLIs can print or upload arbitrary files. Supplying their reusable
|
|
66
116
|
// auth profile to a model-controlled child would therefore make the CLI a
|
|
67
117
|
// confused deputy even when the outer shell is syntactically standalone.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
118
|
+
//
|
|
119
|
+
// They stay executable-but-uncredentialed rather than refused outright: an
|
|
120
|
+
// operator CAN authenticate them from `.env`, which model bash does inherit,
|
|
121
|
+
// so refusing would break working setups. The agent-messenger family cannot —
|
|
122
|
+
// every platform reads a `<platform>-credentials.json` file under the
|
|
123
|
+
// unconditionally masked `workspace/.agent-messenger` — so it is a guaranteed
|
|
124
|
+
// dead end and is refused loudly above instead of failing misleadingly.
|
|
125
|
+
if (executable.executable === 'gws' || executable.executable === 'codex' || executable.executable === 'claude') {
|
|
74
126
|
return runtime
|
|
75
127
|
}
|
|
76
128
|
|
|
@@ -96,6 +148,35 @@ function containsGitInvocation(command: string): boolean {
|
|
|
96
148
|
return /(^|[;&|]\s*)git(?:\s|$)/.test(command.trim())
|
|
97
149
|
}
|
|
98
150
|
|
|
151
|
+
function rejectAgentMessengerCommand(command: string): void {
|
|
152
|
+
for (const segment of command.split(SHELL_COMMAND_SEPARATOR)) {
|
|
153
|
+
const bin = agentMessengerBinIn(segment)
|
|
154
|
+
if (bin !== undefined) throw new SandboxCredentialWithheldError(bin)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function agentMessengerBinIn(segment: string): string | undefined {
|
|
159
|
+
const words = segment
|
|
160
|
+
.trim()
|
|
161
|
+
.split(/\s+/)
|
|
162
|
+
.map((word) => word.replaceAll(/^["']|["']$/g, ''))
|
|
163
|
+
.filter((word) => word !== '' && !ENV_ASSIGNMENT.test(word))
|
|
164
|
+
const operand = unwrapPackageRunner(words).find((word) => !word.startsWith('-'))
|
|
165
|
+
if (operand === undefined) return undefined
|
|
166
|
+
const bin = path.basename(operand)
|
|
167
|
+
return AGENT_MESSENGER_BINS.has(bin) ? bin : undefined
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function unwrapPackageRunner(words: readonly string[]): readonly string[] {
|
|
171
|
+
const head = words[0]
|
|
172
|
+
if (head === undefined) return words
|
|
173
|
+
const runner = path.basename(head)
|
|
174
|
+
if (PACKAGE_RUNNERS.has(runner)) return words.slice(1)
|
|
175
|
+
const subcommand = words[1]
|
|
176
|
+
if (runner === 'bun' && subcommand !== undefined && BUN_RUNNER_SUBCOMMANDS.has(subcommand)) return words.slice(2)
|
|
177
|
+
return words
|
|
178
|
+
}
|
|
179
|
+
|
|
99
180
|
export async function verifyPrivilegedSandboxRuntime(runtime: PrivilegedSandboxRuntime): Promise<void> {
|
|
100
181
|
const identities = mountedIdentities.get(runtime) ?? new Map()
|
|
101
182
|
for (const mount of runtime.mounts) {
|
|
@@ -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 }
|
|
@@ -43,7 +43,7 @@ State the success condition as something operator can check with `bash` — file
|
|
|
43
43
|
|
|
44
44
|
Then stay responsive. When the completion `<system-reminder>` lands, weave operator's report into your next reply (in a channel session, surface it via `channel_reply`/`channel_send` — plain text is invisible there).
|
|
45
45
|
|
|
46
|
-
If the `subagent.spawn
|
|
46
|
+
If the spawn is denied (no `subagent.spawn` grant at all), you can't delegate — fall back to doing the loop yourself, but apply the mechanics below to do it cleanly.
|
|
47
47
|
|
|
48
48
|
## Mechanics operator should use (and you, if you can't delegate)
|
|
49
49
|
|
package/typeclaw.schema.json
CHANGED
|
@@ -64,7 +64,13 @@
|
|
|
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",
|
|
69
|
+
"opengateway/openai/gpt-5.5",
|
|
70
|
+
"opengateway/anthropic/claude-sonnet-5",
|
|
71
|
+
"opengateway/anthropic/claude-opus-4-8",
|
|
72
|
+
"opengateway/moonshotai/kimi-k2.6",
|
|
73
|
+
"opengateway/minimax/MiniMax-M3"
|
|
68
74
|
]
|
|
69
75
|
},
|
|
70
76
|
{
|
|
@@ -120,7 +126,13 @@
|
|
|
120
126
|
"moonshot/kimi-k2.7-code",
|
|
121
127
|
"moonshot/kimi-k2.6",
|
|
122
128
|
"moonshot/kimi-k2.5",
|
|
123
|
-
"moonshot-coding/kimi-for-coding"
|
|
129
|
+
"moonshot-coding/kimi-for-coding",
|
|
130
|
+
"opengateway/openai/gpt-5.4-nano",
|
|
131
|
+
"opengateway/openai/gpt-5.5",
|
|
132
|
+
"opengateway/anthropic/claude-sonnet-5",
|
|
133
|
+
"opengateway/anthropic/claude-opus-4-8",
|
|
134
|
+
"opengateway/moonshotai/kimi-k2.6",
|
|
135
|
+
"opengateway/minimax/MiniMax-M3"
|
|
124
136
|
]
|
|
125
137
|
},
|
|
126
138
|
{
|
|
@@ -177,7 +189,13 @@
|
|
|
177
189
|
"moonshot/kimi-k2.7-code",
|
|
178
190
|
"moonshot/kimi-k2.6",
|
|
179
191
|
"moonshot/kimi-k2.5",
|
|
180
|
-
"moonshot-coding/kimi-for-coding"
|
|
192
|
+
"moonshot-coding/kimi-for-coding",
|
|
193
|
+
"opengateway/openai/gpt-5.4-nano",
|
|
194
|
+
"opengateway/openai/gpt-5.5",
|
|
195
|
+
"opengateway/anthropic/claude-sonnet-5",
|
|
196
|
+
"opengateway/anthropic/claude-opus-4-8",
|
|
197
|
+
"opengateway/moonshotai/kimi-k2.6",
|
|
198
|
+
"opengateway/minimax/MiniMax-M3"
|
|
181
199
|
]
|
|
182
200
|
},
|
|
183
201
|
{
|
|
@@ -232,7 +250,13 @@
|
|
|
232
250
|
"moonshot/kimi-k2.7-code",
|
|
233
251
|
"moonshot/kimi-k2.6",
|
|
234
252
|
"moonshot/kimi-k2.5",
|
|
235
|
-
"moonshot-coding/kimi-for-coding"
|
|
253
|
+
"moonshot-coding/kimi-for-coding",
|
|
254
|
+
"opengateway/openai/gpt-5.4-nano",
|
|
255
|
+
"opengateway/openai/gpt-5.5",
|
|
256
|
+
"opengateway/anthropic/claude-sonnet-5",
|
|
257
|
+
"opengateway/anthropic/claude-opus-4-8",
|
|
258
|
+
"opengateway/moonshotai/kimi-k2.6",
|
|
259
|
+
"opengateway/minimax/MiniMax-M3"
|
|
236
260
|
]
|
|
237
261
|
},
|
|
238
262
|
{
|
|
@@ -288,7 +312,13 @@
|
|
|
288
312
|
"moonshot/kimi-k2.7-code",
|
|
289
313
|
"moonshot/kimi-k2.6",
|
|
290
314
|
"moonshot/kimi-k2.5",
|
|
291
|
-
"moonshot-coding/kimi-for-coding"
|
|
315
|
+
"moonshot-coding/kimi-for-coding",
|
|
316
|
+
"opengateway/openai/gpt-5.4-nano",
|
|
317
|
+
"opengateway/openai/gpt-5.5",
|
|
318
|
+
"opengateway/anthropic/claude-sonnet-5",
|
|
319
|
+
"opengateway/anthropic/claude-opus-4-8",
|
|
320
|
+
"opengateway/moonshotai/kimi-k2.6",
|
|
321
|
+
"opengateway/minimax/MiniMax-M3"
|
|
292
322
|
]
|
|
293
323
|
},
|
|
294
324
|
{
|
|
@@ -1,158 +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
|
-
|
|
20
|
-
export type InstallShimOptions = {
|
|
21
|
-
binPath?: string
|
|
22
|
-
stashDir?: string
|
|
23
|
-
shimEntry?: string
|
|
24
|
-
fs?: ShimFs
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type ShimFs = {
|
|
28
|
-
lstat: (path: string) => { isSymbolicLink: () => boolean } | null
|
|
29
|
-
// statExists follows symlinks: a broken symlink (link entry exists, target
|
|
30
|
-
// does not) returns false. This is the discriminator we need to skip
|
|
31
|
-
// installation when the host bind-mount surfaces dangling node_modules/.bin
|
|
32
|
-
// entries inside the container — see installShim's upstream guard.
|
|
33
|
-
statExists: (path: string) => boolean
|
|
34
|
-
readlink: (path: string) => string
|
|
35
|
-
readFile: (path: string) => string
|
|
36
|
-
rename: (from: string, to: string) => void
|
|
37
|
-
symlink: (target: string, path: string) => void
|
|
38
|
-
writeFile: (path: string, data: string, mode: number) => void
|
|
39
|
-
unlink: (path: string) => void
|
|
40
|
-
mkdirp: (path: string) => void
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type InstallShimResult =
|
|
44
|
-
| { kind: 'installed'; realBin: string; binPath: string; stashTarget: string }
|
|
45
|
-
| { kind: 'already-installed'; binPath: string }
|
|
46
|
-
| { kind: 'no-upstream'; binPath: string }
|
|
47
|
-
|
|
48
|
-
export function installShim(opts: InstallShimOptions = {}): InstallShimResult {
|
|
49
|
-
const binPath = opts.binPath ?? DEFAULT_GLOBAL_BIN_PATH
|
|
50
|
-
const shimEntry = opts.shimEntry ?? defaultShimEntry()
|
|
51
|
-
const fs = opts.fs ?? defaultFs()
|
|
52
|
-
const stashDir = opts.stashDir ?? defaultStashDir(binPath)
|
|
53
|
-
const stashTarget = join(stashDir, 'agent-browser-real')
|
|
54
|
-
|
|
55
|
-
const stat = fs.lstat(binPath)
|
|
56
|
-
if (stat === null) return { kind: 'no-upstream', binPath }
|
|
57
|
-
|
|
58
|
-
if (isAlreadyShim(binPath, fs)) {
|
|
59
|
-
if (fs.statExists(stashTarget)) return { kind: 'already-installed', binPath }
|
|
60
|
-
// Wrapper survived a container restart but the image-owned stash did not
|
|
61
|
-
// (STASH_ROOT lives outside the bind-mount). The wrapper now points at a
|
|
62
|
-
// non-existent stashTarget, so executing it would ENOENT. Drop it and
|
|
63
|
-
// report no-upstream — there is nothing valid here to preserve, and the
|
|
64
|
-
// global-path shim (if it exists) stands on its own.
|
|
65
|
-
fs.unlink(binPath)
|
|
66
|
-
return { kind: 'no-upstream', binPath }
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Bind-mounted node_modules/.bin entries can be dangling symlinks inside
|
|
70
|
-
// the container (host ran bun install; the container image did not). lstat
|
|
71
|
-
// alone passes for those. Follow the link with statExists before mutating
|
|
72
|
-
// anything — otherwise we'd stash a broken symlink and write a wrapper
|
|
73
|
-
// pointing at a target that never resolves.
|
|
74
|
-
if (!fs.statExists(binPath)) return { kind: 'no-upstream', binPath }
|
|
75
|
-
|
|
76
|
-
const realBin = resolveCurrentTarget(binPath, stat, fs)
|
|
77
|
-
fs.mkdirp(stashDir)
|
|
78
|
-
if (stat.isSymbolicLink()) {
|
|
79
|
-
fs.unlink(binPath)
|
|
80
|
-
if (fs.lstat(stashTarget) !== null) fs.unlink(stashTarget)
|
|
81
|
-
fs.symlink(realBin, stashTarget)
|
|
82
|
-
} else {
|
|
83
|
-
if (fs.lstat(stashTarget) !== null) fs.unlink(stashTarget)
|
|
84
|
-
fs.rename(binPath, stashTarget)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
fs.writeFile(binPath, renderWrapper(shimEntry, stashTarget), 0o755)
|
|
88
|
-
return { kind: 'installed', realBin, binPath, stashTarget }
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export const KNOWN_BIN_PATHS = {
|
|
92
|
-
global: DEFAULT_GLOBAL_BIN_PATH,
|
|
93
|
-
local: DEFAULT_LOCAL_BIN_PATH,
|
|
94
|
-
} as const
|
|
95
|
-
|
|
96
|
-
function defaultStashDir(binPath: string): string {
|
|
97
|
-
// Per-binPath subdirectory under the image-owned stash root. Lives outside
|
|
98
|
-
// every bind-mounted agent folder so a host-side `bun install` cannot
|
|
99
|
-
// touch it; the wrapper at the bind-mounted location can be clobbered by
|
|
100
|
-
// host-side installs but the stash and image-level real binary stay safe.
|
|
101
|
-
const slug = binPath.replace(/[^A-Za-z0-9]+/g, '-').replace(/^-+|-+$/g, '')
|
|
102
|
-
return join(STASH_ROOT, slug)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function isAlreadyShim(binPath: string, fs: ShimFs): boolean {
|
|
106
|
-
try {
|
|
107
|
-
return fs.readFile(binPath).includes(SHIM_MARKER)
|
|
108
|
-
} catch {
|
|
109
|
-
return false
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function resolveCurrentTarget(binPath: string, stat: { isSymbolicLink: () => boolean }, fs: ShimFs): string {
|
|
114
|
-
if (!stat.isSymbolicLink()) return binPath
|
|
115
|
-
const target = fs.readlink(binPath)
|
|
116
|
-
return resolvePath(dirname(binPath), target)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function renderWrapper(shimEntry: string, stashTarget: string): string {
|
|
120
|
-
return `#!/bin/sh
|
|
121
|
-
${SHIM_MARKER}
|
|
122
|
-
export ${REAL_BIN_ENV}="\${${REAL_BIN_ENV}:-${stashTarget}}"
|
|
123
|
-
exec bun run ${shimEntry} "$@"
|
|
124
|
-
`
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function defaultShimEntry(): string {
|
|
128
|
-
return resolvePath(import.meta.dir, 'shim.ts')
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function defaultFs(): ShimFs {
|
|
132
|
-
return {
|
|
133
|
-
lstat: (path) => {
|
|
134
|
-
try {
|
|
135
|
-
return lstatSync(path)
|
|
136
|
-
} catch {
|
|
137
|
-
return null
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
statExists: (path) => {
|
|
141
|
-
try {
|
|
142
|
-
statSync(path)
|
|
143
|
-
return true
|
|
144
|
-
} catch {
|
|
145
|
-
return false
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
readlink: readlinkSync,
|
|
149
|
-
readFile: (path) => readFileSync(path, 'utf-8'),
|
|
150
|
-
rename: renameSync,
|
|
151
|
-
symlink: symlinkSync,
|
|
152
|
-
writeFile: (path, data, mode) => writeFileSync(path, data, { mode }),
|
|
153
|
-
unlink: unlinkSync,
|
|
154
|
-
mkdirp: (path) => {
|
|
155
|
-
Bun.spawnSync(['mkdir', '-p', path])
|
|
156
|
-
},
|
|
157
|
-
}
|
|
158
|
-
}
|
|
@@ -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
|