typeclaw 0.45.0 → 0.46.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/README.md +1 -1
- package/package.json +3 -2
- package/src/agent/git-nudge.ts +2 -1
- package/src/agent/index.ts +67 -25
- package/src/agent/live-subagents.ts +18 -0
- package/src/agent/loop-guard.ts +208 -10
- package/src/agent/multimodal/index.ts +1 -1
- package/src/agent/multimodal/look-at.ts +78 -44
- package/src/agent/multimodal/looker.ts +151 -39
- package/src/agent/network/response-body.ts +26 -0
- package/src/agent/network/safe-http.ts +198 -0
- package/src/agent/plugin-tools.ts +438 -162
- package/src/agent/provider-error.ts +62 -4
- package/src/agent/restart/index.ts +61 -40
- package/src/agent/restart-handoff/index.ts +73 -4
- package/src/agent/retry-same-ref.ts +66 -0
- package/src/agent/reviewer-bash-policy.ts +42 -1
- package/src/agent/session-origin.ts +2 -0
- package/src/agent/subagent-drain.ts +117 -7
- package/src/agent/subagents.ts +77 -18
- package/src/agent/throttle-circuit.ts +25 -5
- package/src/agent/tool-error-remediation.ts +72 -0
- package/src/agent/tool-file-safety.ts +1050 -0
- package/src/agent/tools/channel-fetch-attachment.ts +10 -3
- package/src/agent/tools/channel-reply.ts +15 -1
- package/src/agent/tools/channel-send.ts +17 -1
- package/src/agent/tools/ddg.ts +16 -2
- package/src/agent/tools/post-github-review.ts +199 -0
- package/src/agent/tools/spawn-subagent.ts +21 -18
- package/src/agent/tools/webfetch/fetch.ts +143 -183
- package/src/agent/tools/webfetch/tool.ts +2 -3
- package/src/agent/tools/websearch.ts +23 -2
- package/src/agent/tools-without-local-file-operands.ts +27 -0
- package/src/agent/turn-runner.ts +109 -15
- package/src/bundled-plugins/backup/index.ts +2 -1
- package/src/bundled-plugins/backup/runner.ts +2 -1
- package/src/bundled-plugins/doc-render/render.ts +93 -12
- package/src/bundled-plugins/doc-render/skills/typeclaw-render-pdf/SKILL.md +13 -13
- package/src/bundled-plugins/github-cli-auth/effective-approval.ts +16 -6
- package/src/bundled-plugins/github-cli-auth/gh-command.ts +555 -15
- package/src/bundled-plugins/github-cli-auth/index.ts +131 -135
- package/src/bundled-plugins/github-cli-auth/review-checkout.ts +138 -0
- package/src/bundled-plugins/guard/policies/uncommitted-changes.ts +2 -1
- package/src/bundled-plugins/memory/README.md +23 -11
- package/src/bundled-plugins/memory/append-tool.ts +15 -8
- package/src/bundled-plugins/memory/citations.ts +22 -9
- package/src/bundled-plugins/memory/dreaming.ts +13 -8
- package/src/bundled-plugins/memory/find-entry-tool.ts +4 -0
- package/src/bundled-plugins/memory/index.ts +0 -4
- package/src/bundled-plugins/memory/load-memory.ts +8 -3
- package/src/bundled-plugins/memory/provenance-index.ts +717 -0
- package/src/bundled-plugins/memory/provenance-sanitize.ts +40 -0
- package/src/bundled-plugins/memory/references/store-reference-tool.ts +4 -0
- package/src/bundled-plugins/memory/search-tool.ts +163 -60
- package/src/bundled-plugins/memory/stream-events.ts +2 -0
- package/src/bundled-plugins/memory/vector/hybrid.ts +126 -13
- package/src/bundled-plugins/researcher/write-report.ts +6 -3
- package/src/bundled-plugins/reviewer/index.ts +2 -2
- package/src/bundled-plugins/reviewer/reviewer.ts +10 -3
- package/src/bundled-plugins/reviewer/skills/code-review.ts +24 -9
- package/src/bundled-plugins/scout/scout.ts +8 -0
- package/src/bundled-plugins/security/index.ts +4 -4
- package/src/bundled-plugins/security/policies/outbound-secret-scan.ts +1 -0
- package/src/bundled-plugins/security/policies/private-surface-read.ts +220 -29
- package/src/bundled-plugins/security/policies/secret-exfil-read.ts +1 -0
- package/src/bundled-plugins/security/policies/ssrf.ts +29 -9
- package/src/channels/adapters/discord-bot-channel-resolver.ts +26 -14
- package/src/channels/adapters/discord-bot-thread-room.ts +44 -12
- package/src/channels/adapters/discord-bot.ts +91 -10
- package/src/channels/adapters/discord-channel-resolver.ts +91 -23
- package/src/channels/adapters/discord-id.ts +4 -0
- package/src/channels/adapters/discord-resolver-cache.ts +41 -0
- package/src/channels/adapters/discord.ts +57 -7
- package/src/channels/adapters/github/auth-app.ts +41 -12
- package/src/channels/adapters/github/index.ts +23 -11
- package/src/channels/adapters/github/review-submitter.ts +302 -0
- package/src/channels/adapters/kakaotalk-channel-resolver.ts +12 -1
- package/src/channels/adapters/kakaotalk-fetch-attachment.ts +8 -4
- package/src/channels/adapters/kakaotalk-typing.ts +127 -0
- package/src/channels/adapters/kakaotalk.ts +19 -0
- package/src/channels/adapters/slack-attachment-download.ts +71 -0
- package/src/channels/adapters/slack-bot.ts +19 -8
- package/src/channels/adapters/slack-classify.ts +21 -2
- package/src/channels/adapters/slack.ts +59 -7
- package/src/channels/adapters/telegram-bot.ts +18 -5
- package/src/channels/adapters/webex-bot.ts +8 -3
- package/src/channels/adapters/webex.ts +8 -3
- package/src/channels/fetch-attachment.ts +43 -0
- package/src/{bundled-plugins/github-cli-auth/approve-idempotency.ts → channels/github-review-verdict-coordinator.ts} +25 -1
- package/src/channels/github-token-bridge.ts +10 -3
- package/src/channels/manager.ts +9 -0
- package/src/channels/router.ts +568 -12
- package/src/channels/types.ts +28 -1
- package/src/cli/channel.ts +1 -1
- package/src/cli/init.ts +1 -1
- package/src/cli/model.ts +57 -7
- package/src/compose/stop.ts +17 -5
- package/src/config/config.ts +6 -6
- package/src/config/models-mutation.ts +13 -1
- package/src/config/providers.ts +176 -0
- package/src/container/start.ts +49 -10
- package/src/doctor/checks.ts +3 -1
- package/src/doctor/commit.ts +2 -1
- package/src/doctor/file-ownership.ts +52 -0
- package/src/dreams/git.ts +2 -1
- package/src/git/hookless.ts +5 -0
- package/src/git/reconcile-ignored.ts +18 -5
- package/src/git/secret-history.ts +371 -0
- package/src/git/system-commit.ts +12 -6
- package/src/init/dockerfile.ts +86 -5
- package/src/init/index.ts +17 -5
- package/src/init/models-dev.ts +4 -0
- package/src/init/validate-api-key.ts +2 -0
- package/src/mcp/tools.ts +16 -3
- package/src/permissions/builtins.ts +3 -1
- package/src/plugin/context.ts +2 -0
- package/src/plugin/index.ts +1 -0
- package/src/plugin/manager.ts +4 -0
- package/src/plugin/types.ts +21 -0
- package/src/run/index.ts +40 -0
- package/src/run/llm-fetch-observer.ts +188 -13
- package/src/sandbox/build.ts +37 -15
- package/src/sandbox/canonical-secrets.ts +18 -0
- package/src/sandbox/env-exposure.ts +80 -0
- package/src/sandbox/errors.ts +13 -6
- package/src/sandbox/hidden-paths.ts +102 -44
- package/src/sandbox/index.ts +22 -4
- package/src/sandbox/package-install.ts +3 -27
- package/src/sandbox/policy.ts +11 -25
- package/src/sandbox/privileged-runtime.ts +255 -0
- package/src/sandbox/session-tmp.ts +8 -2
- package/src/sandbox/writable-zones.ts +204 -140
- package/src/secrets/index.ts +8 -0
- package/src/secrets/refresh-provider-oauth.ts +128 -0
- package/src/server/command-runner.ts +48 -4
- package/src/server/index.ts +4 -0
- package/src/skills/typeclaw-channel-github/SKILL.md +49 -56
- package/src/skills/typeclaw-claude-code/SKILL.md +24 -60
- package/src/skills/typeclaw-claude-code/references/auth-flow.md +17 -158
- package/src/skills/typeclaw-codex-cli/SKILL.md +19 -49
- package/src/skills/typeclaw-codex-cli/references/auth-flow.md +17 -154
- package/src/skills/typeclaw-config/SKILL.md +5 -5
- package/src/skills/typeclaw-config/references/recommended-mounts.md +24 -24
- package/src/skills/typeclaw-github-contributing/SKILL.md +23 -26
- package/src/skills/typeclaw-memory/SKILL.md +9 -3
- package/src/skills/typeclaw-permissions/SKILL.md +19 -15
- package/typeclaw.schema.json +20 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { chmod, lstat, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { homedir, tmpdir } from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
|
|
5
|
+
import { SandboxPolicyError } from './errors'
|
|
6
|
+
import type { SandboxMount } from './policy'
|
|
7
|
+
|
|
8
|
+
const SAFE_GIT_SUBCOMMANDS = new Set([
|
|
9
|
+
'add',
|
|
10
|
+
'branch',
|
|
11
|
+
'checkout',
|
|
12
|
+
'cherry-pick',
|
|
13
|
+
'commit',
|
|
14
|
+
'diff',
|
|
15
|
+
'log',
|
|
16
|
+
'merge',
|
|
17
|
+
'rebase',
|
|
18
|
+
'remote',
|
|
19
|
+
'reset',
|
|
20
|
+
'restore',
|
|
21
|
+
'rev-parse',
|
|
22
|
+
'show',
|
|
23
|
+
'status',
|
|
24
|
+
'switch',
|
|
25
|
+
'symbolic-ref',
|
|
26
|
+
'tag',
|
|
27
|
+
'worktree',
|
|
28
|
+
])
|
|
29
|
+
|
|
30
|
+
const SHELL_ACTIVE = new Set(['|', ';', '&', '\n', '\r', '(', ')', '{', '}', '<', '>', '`', '$', '\\'])
|
|
31
|
+
|
|
32
|
+
export type PrivilegedSandboxRuntime = {
|
|
33
|
+
env: Record<string, string>
|
|
34
|
+
mounts: SandboxMount[]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type StandaloneCommand = { executable: string; args: string[] }
|
|
38
|
+
type MountedIdentity = { birthtimeNs: bigint; ctimeNs: bigint; dev: bigint; ino: bigint }
|
|
39
|
+
const mountedIdentities = new WeakMap<PrivilegedSandboxRuntime, Map<string, MountedIdentity>>()
|
|
40
|
+
const cleanupDirs = new WeakMap<PrivilegedSandboxRuntime, Set<string>>()
|
|
41
|
+
|
|
42
|
+
export async function resolvePrivilegedSandboxRuntime(options: {
|
|
43
|
+
agentDir: string
|
|
44
|
+
command: string
|
|
45
|
+
env?: NodeJS.ProcessEnv
|
|
46
|
+
homeDir?: string
|
|
47
|
+
}): Promise<PrivilegedSandboxRuntime> {
|
|
48
|
+
const runtime = emptyRuntime()
|
|
49
|
+
// TYPECLAW_GIT_TOKEN is set only after the auth analyzer accepts a Git command.
|
|
50
|
+
// Trust that decision rather than reparsing its command with a less capable
|
|
51
|
+
// detector (notably, the analyzer accepts quoted `git` executables).
|
|
52
|
+
if (options.env?.TYPECLAW_GIT_TOKEN !== undefined || containsGitInvocation(options.command)) {
|
|
53
|
+
runtime.env.HOME = options.agentDir
|
|
54
|
+
runtime.env.GIT_CONFIG_GLOBAL = '/dev/null'
|
|
55
|
+
runtime.env.GIT_CONFIG_NOSYSTEM = '1'
|
|
56
|
+
}
|
|
57
|
+
const parsed = parseStandaloneCommand(options.command)
|
|
58
|
+
if (parsed === null) return runtime
|
|
59
|
+
|
|
60
|
+
const homeDir = options.homeDir ?? homedir()
|
|
61
|
+
const executable = unwrapBunx(parsed)
|
|
62
|
+
if (executable === null) return runtime
|
|
63
|
+
|
|
64
|
+
// These CLIs can print or upload arbitrary files. Supplying their reusable
|
|
65
|
+
// auth profile to a model-controlled child would therefore make the CLI a
|
|
66
|
+
// confused deputy even when the outer shell is syntactically standalone.
|
|
67
|
+
if (
|
|
68
|
+
executable.executable === 'gws' ||
|
|
69
|
+
executable.executable === 'codex' ||
|
|
70
|
+
executable.executable === 'claude' ||
|
|
71
|
+
executable.executable.startsWith('agent-')
|
|
72
|
+
) {
|
|
73
|
+
return runtime
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (executable.executable === 'git') {
|
|
77
|
+
runtime.env.GIT_CONFIG_GLOBAL = '/dev/null'
|
|
78
|
+
runtime.env.GIT_CONFIG_NOSYSTEM = '1'
|
|
79
|
+
const subcommand = gitSubcommand(executable.args)
|
|
80
|
+
if (subcommand === null) return runtime
|
|
81
|
+
rejectNamedSubcommand(subcommand, new Set(['config', 'credential', 'credential-cache', 'credential-store']))
|
|
82
|
+
if (!SAFE_GIT_SUBCOMMANDS.has(subcommand)) return runtime
|
|
83
|
+
try {
|
|
84
|
+
await addSanitizedGitIdentity(runtime, path.join(homeDir, '.gitconfig'))
|
|
85
|
+
} catch (error) {
|
|
86
|
+
await cleanupPrivilegedSandboxRuntime(runtime)
|
|
87
|
+
throw error
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return runtime
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function containsGitInvocation(command: string): boolean {
|
|
95
|
+
return /(^|[;&|]\s*)git(?:\s|$)/.test(command.trim())
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function verifyPrivilegedSandboxRuntime(runtime: PrivilegedSandboxRuntime): Promise<void> {
|
|
99
|
+
const identities = mountedIdentities.get(runtime) ?? new Map()
|
|
100
|
+
for (const mount of runtime.mounts) {
|
|
101
|
+
if (mount.type !== 'ro-bind') continue
|
|
102
|
+
const safe = await lstat(mount.source, { bigint: true })
|
|
103
|
+
.then(async (stats) => {
|
|
104
|
+
if (stats.isSymbolicLink()) return false
|
|
105
|
+
const expected = identities.get(mount.source)
|
|
106
|
+
return (
|
|
107
|
+
stats.isFile() &&
|
|
108
|
+
stats.nlink === 1n &&
|
|
109
|
+
expected !== undefined &&
|
|
110
|
+
stats.dev === expected.dev &&
|
|
111
|
+
stats.ino === expected.ino &&
|
|
112
|
+
stats.ctimeNs === expected.ctimeNs &&
|
|
113
|
+
stats.birthtimeNs === expected.birthtimeNs
|
|
114
|
+
)
|
|
115
|
+
})
|
|
116
|
+
.catch(() => false)
|
|
117
|
+
if (!safe) {
|
|
118
|
+
throw new SandboxPolicyError(`credential profile changed after validation: ${mount.source}. Refusing to run.`)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export async function cleanupPrivilegedSandboxRuntime(runtime: PrivilegedSandboxRuntime): Promise<void> {
|
|
124
|
+
const dirs = cleanupDirs.get(runtime) ?? new Set()
|
|
125
|
+
const outcomes = await Promise.allSettled([...dirs].map((dir) => rm(dir, { recursive: true, force: true })))
|
|
126
|
+
dirs.clear()
|
|
127
|
+
const failed = outcomes.find((outcome) => outcome.status === 'rejected')
|
|
128
|
+
if (failed?.status === 'rejected') throw failed.reason
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function emptyRuntime(): PrivilegedSandboxRuntime {
|
|
132
|
+
const runtime = { env: {}, mounts: [] }
|
|
133
|
+
mountedIdentities.set(runtime, new Map())
|
|
134
|
+
cleanupDirs.set(runtime, new Set())
|
|
135
|
+
return runtime
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function unwrapBunx(command: StandaloneCommand): StandaloneCommand | null {
|
|
139
|
+
if (command.executable !== 'bunx') return command
|
|
140
|
+
const args = [...command.args]
|
|
141
|
+
if (args[0] === '--bun') args.shift()
|
|
142
|
+
const executable = args.shift()
|
|
143
|
+
return executable === undefined ? null : { executable, args }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function rejectNamedSubcommand(subcommand: string, denied: ReadonlySet<string>): void {
|
|
147
|
+
if (denied.has(subcommand)) {
|
|
148
|
+
throw new SandboxPolicyError(
|
|
149
|
+
`credential or token management command \`${subcommand}\` is unavailable to model-driven bash; use a host-side login or redacted status command instead.`,
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function gitSubcommand(args: readonly string[]): string | null {
|
|
155
|
+
for (let i = 0; i < args.length; i++) {
|
|
156
|
+
const arg = args[i] as string
|
|
157
|
+
if (arg === '-C') {
|
|
158
|
+
i += 1
|
|
159
|
+
continue
|
|
160
|
+
}
|
|
161
|
+
if (arg === '-c' || arg === '--config-env' || arg.startsWith('--config-env=')) return null
|
|
162
|
+
if (arg.startsWith('-')) continue
|
|
163
|
+
return arg
|
|
164
|
+
}
|
|
165
|
+
return null
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function addSanitizedGitIdentity(runtime: PrivilegedSandboxRuntime, source: string): Promise<void> {
|
|
169
|
+
const raw = await readFile(source, 'utf8').catch((error) => {
|
|
170
|
+
if (isNotFoundError(error)) return ''
|
|
171
|
+
throw error
|
|
172
|
+
})
|
|
173
|
+
if (raw === '') return
|
|
174
|
+
const values = parseGitUserIdentity(raw)
|
|
175
|
+
if (values.length === 0) return
|
|
176
|
+
const dir = await mkdtemp(path.join(tmpdir(), 'typeclaw-git-identity-'))
|
|
177
|
+
cleanupDirs.get(runtime)?.add(dir)
|
|
178
|
+
const generated = path.join(dir, 'config')
|
|
179
|
+
await writeFile(generated, `[user]\n${values.map(([key, value]) => `\t${key} = ${value}`).join('\n')}\n`, {
|
|
180
|
+
flag: 'wx',
|
|
181
|
+
})
|
|
182
|
+
await chmod(generated, 0o600)
|
|
183
|
+
const stats = await lstat(generated, { bigint: true })
|
|
184
|
+
mountedIdentities.get(runtime)?.set(generated, {
|
|
185
|
+
birthtimeNs: stats.birthtimeNs,
|
|
186
|
+
ctimeNs: stats.ctimeNs,
|
|
187
|
+
dev: stats.dev,
|
|
188
|
+
ino: stats.ino,
|
|
189
|
+
})
|
|
190
|
+
runtime.mounts.push({ type: 'ro-bind', source: generated, dest: '/tmp/.gitconfig' })
|
|
191
|
+
runtime.env.GIT_CONFIG_GLOBAL = '/tmp/.gitconfig'
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function parseGitUserIdentity(raw: string): Array<['name' | 'email', string]> {
|
|
195
|
+
const values = new Map<'name' | 'email', string>()
|
|
196
|
+
let inUser = false
|
|
197
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
198
|
+
const section = line.match(/^\s*\[([^\]]+)]\s*$/)
|
|
199
|
+
if (section !== null) {
|
|
200
|
+
inUser = section[1]?.trim().toLocaleLowerCase() === 'user'
|
|
201
|
+
continue
|
|
202
|
+
}
|
|
203
|
+
if (!inUser) continue
|
|
204
|
+
const entry = line.match(/^\s*(name|email)\s*=\s*(.*?)\s*$/i)
|
|
205
|
+
if (entry === null || entry[2] === undefined) continue
|
|
206
|
+
const key = entry[1]?.toLocaleLowerCase() as 'name' | 'email'
|
|
207
|
+
const value = entry[2].replaceAll('\r', '').replaceAll('\n', '').replaceAll('\0', '')
|
|
208
|
+
if (value !== '') values.set(key, value)
|
|
209
|
+
}
|
|
210
|
+
return [...values.entries()]
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function parseStandaloneCommand(command: string): StandaloneCommand | null {
|
|
214
|
+
const words: string[] = []
|
|
215
|
+
let word = ''
|
|
216
|
+
let quote: "'" | '"' | null = null
|
|
217
|
+
let active = false
|
|
218
|
+
for (const ch of command.trim()) {
|
|
219
|
+
if (quote === "'") {
|
|
220
|
+
if (ch === "'") quote = null
|
|
221
|
+
else word += ch
|
|
222
|
+
continue
|
|
223
|
+
}
|
|
224
|
+
if (quote === '"') {
|
|
225
|
+
if (ch === '"') quote = null
|
|
226
|
+
else if (ch === '$' || ch === '`' || ch === '\\') return null
|
|
227
|
+
else word += ch
|
|
228
|
+
continue
|
|
229
|
+
}
|
|
230
|
+
if (ch === "'" || ch === '"') {
|
|
231
|
+
quote = ch
|
|
232
|
+
active = true
|
|
233
|
+
continue
|
|
234
|
+
}
|
|
235
|
+
if (SHELL_ACTIVE.has(ch)) return null
|
|
236
|
+
if (/\s/.test(ch)) {
|
|
237
|
+
if (active) {
|
|
238
|
+
words.push(word)
|
|
239
|
+
word = ''
|
|
240
|
+
active = false
|
|
241
|
+
}
|
|
242
|
+
continue
|
|
243
|
+
}
|
|
244
|
+
word += ch
|
|
245
|
+
active = true
|
|
246
|
+
}
|
|
247
|
+
if (quote !== null) return null
|
|
248
|
+
if (active) words.push(word)
|
|
249
|
+
const executable = words.shift()
|
|
250
|
+
return executable === undefined ? null : { executable, args: words }
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function isNotFoundError(error: unknown): boolean {
|
|
254
|
+
return error instanceof Error && 'code' in error && error.code === 'ENOENT'
|
|
255
|
+
}
|
|
@@ -27,7 +27,7 @@ export async function ensureSessionTmpDir(sessionId: string): Promise<string> {
|
|
|
27
27
|
|
|
28
28
|
export function isUnderTmp(agentDir: string, rawPath: string): boolean {
|
|
29
29
|
const resolved = resolve(agentDir, rawPath)
|
|
30
|
-
return
|
|
30
|
+
return isVirtualTmpPath(agentDir, resolved)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// Maps a model-facing /tmp path to its per-session backing path. Returns
|
|
@@ -37,11 +37,17 @@ export function isUnderTmp(agentDir: string, rawPath: string): boolean {
|
|
|
37
37
|
// for the sandboxed bash that reads it back.
|
|
38
38
|
export function mapVirtualTmpPath(agentDir: string, sessionId: string, rawPath: string): string | undefined {
|
|
39
39
|
const resolved = resolve(agentDir, rawPath)
|
|
40
|
-
if (
|
|
40
|
+
if (!isVirtualTmpPath(agentDir, resolved)) return undefined
|
|
41
41
|
const rel = relative('/tmp', resolved)
|
|
42
42
|
return rel === '' ? sessionTmpDir(sessionId) : join(sessionTmpDir(sessionId), rel)
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
function isVirtualTmpPath(agentDir: string, resolved: string): boolean {
|
|
46
|
+
const resolvedAgentDir = resolve(agentDir)
|
|
47
|
+
if (resolved === resolvedAgentDir || isInside(resolvedAgentDir, resolved)) return false
|
|
48
|
+
return resolved === '/tmp' || isInside('/tmp', resolved)
|
|
49
|
+
}
|
|
50
|
+
|
|
45
51
|
function isInside(parent: string, child: string): boolean {
|
|
46
52
|
const rel = relative(parent, child)
|
|
47
53
|
return rel !== '' && !rel.startsWith('..') && !isAbsolute(rel)
|